tecuts commited on
Commit
930d2f7
·
verified ·
1 Parent(s): 9ba111b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -1
app.py CHANGED
@@ -332,7 +332,45 @@ async def get_playlist_info(
332
  detail=repr(e),
333
  headers={"Cache-Control": "no-store, max-age=0"},
334
  )
335
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
 
337
  @app.get("/api/rate-limit-status")
338
  async def get_rate_limit_status(request: Request):
 
332
  detail=repr(e),
333
  headers={"Cache-Control": "no-store, max-age=0"},
334
  )
335
+
336
+ import httpx
337
+
338
+ SOUNDCLOUD_CLIENT_ID = "khI8ciOiYPX6UVGInQY5zA0zvTkfzuuC" # sniff from browser network tab on soundcloud.com
339
+
340
+ @app.get("/api/list")
341
+ async def get_playlist_info(request: Request, url: str, start: int = 1, end: int = 50):
342
+
343
+ # 1. Resolve the URL to get playlist ID
344
+ resolve = await httpx.AsyncClient().get(
345
+ "https://api-v2.soundcloud.com/resolve",
346
+ params={"url": url, "client_id": SOUNDCLOUD_CLIENT_ID}
347
+ )
348
+ data = resolve.json()
349
+ playlist_id = data["id"]
350
+
351
+ # 2. Fetch tracks directly
352
+ offset = start - 1
353
+ limit = min(end - start + 1, 50)
354
+
355
+ tracks_res = await httpx.AsyncClient().get(
356
+ f"https://api-v2.soundcloud.com/playlists/{playlist_id}/tracks",
357
+ params={"client_id": SOUNDCLOUD_CLIENT_ID, "limit": limit, "offset": offset}
358
+ )
359
+ tracks = tracks_res.json()
360
+
361
+ entries = [
362
+ {
363
+ "id": t.get("id"),
364
+ "title": t.get("title"),
365
+ "url": t.get("permalink_url"),
366
+ "duration": t.get("duration"),
367
+ "uploader": t.get("user", {}).get("username"),
368
+ }
369
+ for t in tracks
370
+ ]
371
+
372
+ return JSONResponse({"entries": entries, "items_returned": len(entries)})
373
+
374
 
375
  @app.get("/api/rate-limit-status")
376
  async def get_rate_limit_status(request: Request):