tecuts commited on
Commit
0da18ba
·
verified ·
1 Parent(s): 94196f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -16
app.py CHANGED
@@ -223,20 +223,16 @@ async def get_playlist_info(
223
  Fetches paginated items from a playlist or user profile.
224
  Strictly enforces a maximum of 50 items per request and provides a next_page URL.
225
  """
226
- # 1. Validate inputs
227
  if start < 1:
228
  raise HTTPException(status_code=400, detail="'start' must be 1 or greater.")
229
  if end < start:
230
  raise HTTPException(status_code=400, detail="'end' must be greater than or equal to 'start'.")
231
 
232
- # 2. Enforce a hard limit of 50 items per request
233
- # If a client requests start=51 & end=1000, we force end=100.
234
  requested_count = end - start + 1
235
  if requested_count > 50:
236
  end = start + 49
237
  requested_count = 50
238
 
239
- # Rate Limiting
240
  client_ip = get_client_ip(request)
241
  is_allowed, remaining = check_rate_limit(client_ip)
242
 
@@ -260,7 +256,6 @@ async def get_playlist_info(
260
  "ignoreerrors": True,
261
  "cachedir": "/tmp/yt-dlp-cache",
262
  "js-runtimes": "node",
263
- # Pass the strictly clamped pagination settings to yt-dlp
264
  "playliststart": start,
265
  "playlistend": end
266
  }
@@ -271,26 +266,15 @@ async def get_playlist_info(
271
  if not response:
272
  raise HTTPException(status_code=404, detail="Playlist or profile not found.")
273
 
274
- # Extract entries. yt-dlp might omit 'entries' if out of bounds, so default to empty list.
275
  raw_entries = response.get("entries") or []
276
-
277
- # Filter out 'None' entries (yt-dlp sometimes returns None for deleted/private videos in a playlist)
278
  valid_entries = [e for e in raw_entries if e is not None]
279
 
280
- # 3. Determine if there is a next page
281
  next_page_url = None
282
-
283
- # If yt-dlp found enough items to fill our requested quota, there is likely a next page.
284
- # (Note: we check the length of raw_entries because deleted videos still consume an index slot)
285
  if len(raw_entries) >= requested_count:
286
  next_start = end + 1
287
  next_end = next_start + 49
288
-
289
- # Safely encode the target URL
290
  encoded_url = urllib.parse.quote(url)
291
  base_url = str(request.base_url).rstrip('/')
292
-
293
- # Construct the ready-to-use next_page URL for the client
294
  next_page_url = f"{base_url}/api/playlist?url={encoded_url}&start={next_start}&end={next_end}"
295
 
296
  clean_response = {
 
223
  Fetches paginated items from a playlist or user profile.
224
  Strictly enforces a maximum of 50 items per request and provides a next_page URL.
225
  """
 
226
  if start < 1:
227
  raise HTTPException(status_code=400, detail="'start' must be 1 or greater.")
228
  if end < start:
229
  raise HTTPException(status_code=400, detail="'end' must be greater than or equal to 'start'.")
230
 
 
 
231
  requested_count = end - start + 1
232
  if requested_count > 50:
233
  end = start + 49
234
  requested_count = 50
235
 
 
236
  client_ip = get_client_ip(request)
237
  is_allowed, remaining = check_rate_limit(client_ip)
238
 
 
256
  "ignoreerrors": True,
257
  "cachedir": "/tmp/yt-dlp-cache",
258
  "js-runtimes": "node",
 
259
  "playliststart": start,
260
  "playlistend": end
261
  }
 
266
  if not response:
267
  raise HTTPException(status_code=404, detail="Playlist or profile not found.")
268
 
 
269
  raw_entries = response.get("entries") or []
 
 
270
  valid_entries = [e for e in raw_entries if e is not None]
271
 
 
272
  next_page_url = None
 
 
 
273
  if len(raw_entries) >= requested_count:
274
  next_start = end + 1
275
  next_end = next_start + 49
 
 
276
  encoded_url = urllib.parse.quote(url)
277
  base_url = str(request.base_url).rstrip('/')
 
 
278
  next_page_url = f"{base_url}/api/playlist?url={encoded_url}&start={next_start}&end={next_end}"
279
 
280
  clean_response = {