From d66fd985941209c814a7b1485522dfb60a465281 Mon Sep 17 00:00:00 2001 From: vanhci Date: Sun, 24 May 2026 20:03:54 +0800 Subject: [PATCH] fix: handle missing 'popularity' field in Spotify API response (issue #36) The Spotify API deprecated the 'popularity' field in track responses. This caused a KeyError when trying to access track['item']['popularity']. Use .get() to safely handle missing field, defaulting to -1. --- aw_watcher_spotify/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aw_watcher_spotify/main.py b/aw_watcher_spotify/main.py index fb92b43..3382a2f 100644 --- a/aw_watcher_spotify/main.py +++ b/aw_watcher_spotify/main.py @@ -44,7 +44,7 @@ def data_from_track(track: dict, sp) -> dict: if track["item"]["type"] == "track": artist_name = track["item"]["artists"][0]["name"] album_name = track["item"]["album"]["name"] - data["popularity"] = track["item"]["popularity"] or -1 + data["popularity"] = track["item"].get("popularity") or -1 data["album"] = album_name data["artist"] = artist_name logging.debug("TRACK: {} - {} ({})".format(song_name, artist_name, album_name))