From 76785a4eaa79b357fc764b4be018279a16ae2bef Mon Sep 17 00:00:00 2001 From: Honey Date: Wed, 13 May 2026 01:21:19 +0200 Subject: [PATCH] debug: wrap Song init in try-except, log Public methods before any Song attempts Co-Authored-By: Claude Sonnet 4.6 --- backend/spotify_resolve.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/backend/spotify_resolve.py b/backend/spotify_resolve.py index 681a9da..783d501 100644 --- a/backend/spotify_resolve.py +++ b/backend/spotify_resolve.py @@ -64,25 +64,26 @@ def resolve(sp_type, sp_id): url = f'https://open.spotify.com/{sp_type}/{sp_id}' if sp_type == 'track': - # Song(url) stores url as the client object, then get_song_info() or init - # tries to call url.login which fails. Try: Song(url) + get_song_info(url), - # then Song(url) + get_song_info(), log methods as last resort. - song = sp_mod.Song(url) - song_methods = [m for m in dir(song) if not m.startswith('_')] - eprint(f'[spotapi] Song methods: {song_methods}') + # Log Public methods first so we always see them regardless of Song failures + pub = sp_mod.Public() + eprint(f'[spotapi] Public methods: {[m for m in dir(pub) if not m.startswith("_")]}') raw = None - for attempt in [ - lambda: song.get_song_info(url), - lambda: song.get_song_info(), - ]: + # Try every plausible call pattern — Song requires a Login session, not a URL, + # so we also try Public directly in case it exposes track methods. + attempts = [ + ('Public(url).get_song_info()', lambda: sp_mod.Public(url).get_song_info()), + ('Public().get_song_info(url)', lambda: sp_mod.Public().get_song_info(url)), + ('Song(url).get_song_info(url)', lambda: sp_mod.Song(url).get_song_info(url)), + ('Song(url).get_song_info()', lambda: sp_mod.Song(url).get_song_info()), + ] + for label, fn in attempts: try: - raw = attempt() + raw = fn() + eprint(f'[spotapi] track: {label} succeeded') break except Exception as e: - eprint(f'[spotapi] track attempt failed: {type(e).__name__}: {e}') + eprint(f'[spotapi] track [{label}] 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 "?"}') if isinstance(raw, dict):