diff options
| author | alex <[email protected]> | 2026-07-22 11:43:13 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-22 11:43:13 +0200 |
| commit | add5304ab45bcf52ab63d96d32b511756ef30c80 (patch) | |
| tree | 69dfb29a347c051d6f995484d3f86786cc7e95d4 /bot.py | |
| parent | ba2df9450b9409634e3e271a606b39a73392dc54 (diff) | |
| download | spotify-discord-widget-add5304ab45bcf52ab63d96d32b511756ef30c80.tar.xz spotify-discord-widget-add5304ab45bcf52ab63d96d32b511756ef30c80.zip | |
swapped currently listening to for last liked
Diffstat (limited to 'bot.py')
| -rw-r--r-- | bot.py | 29 |
1 files changed, 24 insertions, 5 deletions
@@ -183,7 +183,27 @@ class SpotifyAPI: "album_art": None, "url": None, } + @staticmethod + def get_last_liked_track(sp: spotipy.Spotify) -> dict | None: + res = sp.current_user_saved_tracks(limit=1) + items = res.get("items", []) + + if not items: + return None + track = items[0].get("track") + if not track: + return None + + return { + "title": track["name"], + "artist": track["artists"][0]["name"], + # Renamed key to 'album_art' to match payload builder expectations + "album_art": track["album"]["images"][0]["url"] + if track["album"].get("images") + else None, + "url": track["external_urls"]["spotify"], + } # ============================================================================== # 4. DISCORD PAYLOAD BUILDER & DISCORD IDENTITY API UPDATER @@ -257,15 +277,14 @@ def build_discord_profile_payload( "type": 3, "name": "current_song_picture", "value": { - "url": current_track.get("album_art") or DEFAULT_IMAGE - }, + "url": (current_track.get("album_art") if current_track else None) or DEFAULT_IMAGE }, }, { "type": 1, "name": "current_song_name", "value": current_track.get("title", "None"), }, - {"type": 1, "name": "status", "value": status_label}, + {"type": 1, "name": "status", "value": "recently liked"}, {"type": 1, "name": "range", "value": time_range_label}, ] } @@ -303,7 +322,7 @@ async def process_user_widget_update(discord_user_id: str) -> bool: top_song = SpotifyAPI.get_top_track(sp, time_range="short_term") top_album = SpotifyAPI.get_top_album(sp, time_range="short_term") top_artist = SpotifyAPI.get_top_artist(sp, time_range="short_term") - current_track = SpotifyAPI.get_currently_playing(sp) + last_liked = SpotifyAPI.get_last_liked_track(sp) payload = build_discord_profile_payload( spotify_username=spotify_username, @@ -311,7 +330,7 @@ async def process_user_widget_update(discord_user_id: str) -> bool: top_song=top_song, top_album=top_album, top_artist=top_artist, - current_track=current_track, + current_track=last_liked, time_range_label="4 weeks", ) |
