feat: implemented unified downloading
This commit is contained in:
@@ -102,7 +102,7 @@ def extract_tracks(embed_data, sp_type, sp_id):
|
||||
else:
|
||||
artist = entity.get("subtitle", "")
|
||||
if title:
|
||||
return [{"title": title, "artist": artist}]
|
||||
return [{"title": title, "artist": artist, "sp_id": sp_id, "duration": entity.get("duration")}]
|
||||
|
||||
elif sp_type in ("album", "playlist"):
|
||||
track_list = entity.get("trackList", [])
|
||||
@@ -111,8 +111,15 @@ def extract_tracks(embed_data, sp_type, sp_id):
|
||||
for t in track_list:
|
||||
title = t.get("title", "")
|
||||
artist = t.get("subtitle", "")
|
||||
# Prefer uri (contains real Spotify track ID) over uid (internal hex UID)
|
||||
track_uid = None
|
||||
uri = t.get("uri", "")
|
||||
if uri.startswith("spotify:track:"):
|
||||
track_uid = uri.split(":")[-1]
|
||||
if not track_uid:
|
||||
track_uid = t.get("uid")
|
||||
if title:
|
||||
tracks.append({"title": title, "artist": artist})
|
||||
tracks.append({"title": title, "artist": artist, "sp_id": track_uid, "duration": t.get("duration")})
|
||||
if tracks:
|
||||
return tracks
|
||||
except (KeyError, TypeError, IndexError):
|
||||
@@ -123,7 +130,7 @@ def extract_tracks(embed_data, sp_type, sp_id):
|
||||
oembed_title = fetch_spotify_oembed(sp_type, sp_id)
|
||||
if oembed_title:
|
||||
print(f'[*] Using oEmbed fallback: "{oembed_title}"', file=sys.stderr)
|
||||
return [{"title": oembed_title, "artist": ""}]
|
||||
return [{"title": oembed_title, "artist": "", "sp_id": sp_id, "duration": None}]
|
||||
|
||||
return []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user