fix: album track wrapping + try multiple Song() call patterns for tracks
- Album: wrap item.get('track') as {itemV2: ...} so _parse_track navigates trackUnion correctly
- Track: try get_song_info(url) then get_song_info(); log Song/Public methods on failure
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
bbe4412f42
commit
5d0c5ec6eb
1 file changed
+24
-7
@@ -64,10 +64,26 @@ def resolve(sp_type, sp_id):
|
|||||||
url = f'https://open.spotify.com/{sp_type}/{sp_id}'
|
url = f'https://open.spotify.com/{sp_type}/{sp_id}'
|
||||||
|
|
||||||
if sp_type == 'track':
|
if sp_type == 'track':
|
||||||
# Song requires a client instance as first arg; Public() is the unauthenticated client
|
# Song(url) stores url as the client object, then get_song_info() or init
|
||||||
public = sp_mod.Public()
|
# tries to call url.login which fails. Try: Song(url) + get_song_info(url),
|
||||||
song = sp_mod.Song(public, url)
|
# then Song(url) + get_song_info(), log methods as last resort.
|
||||||
raw = song.get_song_info()
|
song = sp_mod.Song(url)
|
||||||
|
song_methods = [m for m in dir(song) if not m.startswith('_')]
|
||||||
|
eprint(f'[spotapi] Song methods: {song_methods}')
|
||||||
|
raw = None
|
||||||
|
for attempt in [
|
||||||
|
lambda: song.get_song_info(url),
|
||||||
|
lambda: song.get_song_info(),
|
||||||
|
]:
|
||||||
|
try:
|
||||||
|
raw = attempt()
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
eprint(f'[spotapi] track attempt failed: {type(e).__name__}: {e}')
|
||||||
|
if raw is None:
|
||||||
|
pub = sp_mod.Public()
|
||||||
|
eprint(f'[spotapi] Public methods: {[m for m in dir(pub) if not m.startswith("_")]}')
|
||||||
|
raise Exception('Song resolution: all attempts failed')
|
||||||
eprint(f'[spotapi] track raw type={type(raw).__name__} keys={list(raw.keys()) if isinstance(raw, dict) else "?"}')
|
eprint(f'[spotapi] track raw type={type(raw).__name__} keys={list(raw.keys()) if isinstance(raw, dict) else "?"}')
|
||||||
if isinstance(raw, dict):
|
if isinstance(raw, dict):
|
||||||
for k, v in raw.items():
|
for k, v in raw.items():
|
||||||
@@ -113,10 +129,11 @@ def resolve(sp_type, sp_id):
|
|||||||
art = cover_items[0].get('url', '') if cover_items else ''
|
art = cover_items[0].get('url', '') if cover_items else ''
|
||||||
# tracks
|
# tracks
|
||||||
raw_tracks = (au.get('tracks') or {}).get('items') or []
|
raw_tracks = (au.get('tracks') or {}).get('items') or []
|
||||||
# album track items look like {uid, track: {data: {trackUnion: {...}}}}
|
# album track items: {uid, track: {__typename, data: {trackUnion: {...}}}}
|
||||||
|
# wrap as {itemV2: track_obj} so _parse_track can navigate itemV2.data.trackUnion
|
||||||
def _alb_track(item):
|
def _alb_track(item):
|
||||||
inner = item.get('track') or item
|
track_obj = item.get('track') or item
|
||||||
return _parse_track(inner,
|
return _parse_track({'itemV2': track_obj},
|
||||||
default_album=name, default_art=art,
|
default_album=name, default_art=art,
|
||||||
default_artist=artist)
|
default_artist=artist)
|
||||||
tracks = [t for t in (_alb_track(i) for i in raw_tracks) if t]
|
tracks = [t for t in (_alb_track(i) for i in raw_tracks) if t]
|
||||||
|
|||||||
Reference in new issue
Block a user