tecuts commited on
Commit
9ba111b
·
verified ·
1 Parent(s): 180646b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
app.py CHANGED
@@ -280,28 +280,20 @@ async def get_playlist_info(
280
 
281
  entry = dict(e)
282
 
283
- if entry.get("ie_key") == "Soundcloud" and entry.get("id"):
284
- current_url = entry.get("url", "")
285
-
286
- # If the track has a proper permalink, always prefer it
287
- if entry.get("permalink_url"):
288
- entry["url"] = entry["permalink_url"]
289
-
290
- # If it's still an internal API link, reconstruct from permalink_url
291
- # or fall back to the web-resolvable /tracks/ path
292
- elif "api-v2.soundcloud.com" in current_url or "api.soundcloud.com" in current_url:
293
- track_id = entry["id"]
294
- uploader_permalink = entry.get("uploader_id") or entry.get("channel_id")
295
-
296
- if uploader_permalink and entry.get("title"):
297
- # Reconstruct a proper permalink from known metadata
298
- track_slug = entry.get("webpage_url_basename") or entry["title"].lower().replace(" ", "-")
299
- entry["url"] = f"https://soundcloud.com/{uploader_permalink}/{track_slug}"
300
- else:
301
- # Last resort: use the resolve API endpoint
302
- entry["url"] = f"https://api.soundcloud.com/tracks/{track_id}/stream"
303
 
304
- valid_entries.append(entry)
 
 
 
 
 
 
305
 
306
  # 3. Determine if there is a next page
307
  next_page_url = None
 
280
 
281
  entry = dict(e)
282
 
283
+ # Always prefer permalink_url (the proper soundcloud.com/artist/track URL)
284
+ url = (
285
+ entry.get("permalink_url")
286
+ or entry.get("webpage_url")
287
+ or entry.get("url")
288
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
 
290
+ valid_entries.append({
291
+ "id": entry.get("id"),
292
+ "title": entry.get("title"),
293
+ "url": url,
294
+ "duration": entry.get("duration"),
295
+ "uploader": entry.get("uploader"),
296
+ })
297
 
298
  # 3. Determine if there is a next page
299
  next_page_url = None