aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralex <[email protected]>2026-07-22 11:43:13 +0200
committeralex <[email protected]>2026-07-22 11:43:13 +0200
commitadd5304ab45bcf52ab63d96d32b511756ef30c80 (patch)
tree69dfb29a347c051d6f995484d3f86786cc7e95d4
parentba2df9450b9409634e3e271a606b39a73392dc54 (diff)
downloadspotify-discord-widget-add5304ab45bcf52ab63d96d32b511756ef30c80.tar.xz
spotify-discord-widget-add5304ab45bcf52ab63d96d32b511756ef30c80.zip
swapped currently listening to for last liked
-rw-r--r--.gitignore4
-rw-r--r--.idea/encodings.xml4
-rw-r--r--.idea/inspectionProfiles/profiles_settings.xml6
-rw-r--r--.idea/misc.xml7
-rw-r--r--.idea/modules.xml8
-rw-r--r--.idea/spotify-discord-widget.iml10
-rw-r--r--bot.py29
7 files changed, 62 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 3052eef..2d124cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
.env
-.venv \ No newline at end of file
+.venv
+tokens.db
+.cache \ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..df87cf9
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
+</project> \ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+<component name="InspectionProjectProfileManager">
+ <settings>
+ <option name="USE_PROJECT_PROFILE" value="false" />
+ <version value="1.0" />
+ </settings>
+</component> \ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..a174615
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="Black">
+ <option name="sdkName" value="uv (spotify-discord-widget)" />
+ </component>
+ <component name="ProjectRootManager" version="2" project-jdk-name="uv (spotify-discord-widget)" project-jdk-type="Python SDK" />
+</project> \ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..489486d
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/.idea/spotify-discord-widget.iml" filepath="$PROJECT_DIR$/.idea/spotify-discord-widget.iml" />
+ </modules>
+ </component>
+</project> \ No newline at end of file
diff --git a/.idea/spotify-discord-widget.iml b/.idea/spotify-discord-widget.iml
new file mode 100644
index 0000000..ee11dbc
--- /dev/null
+++ b/.idea/spotify-discord-widget.iml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+ <component name="NewModuleRootManager">
+ <content url="file://$MODULE_DIR$">
+ <excludeFolder url="file://$MODULE_DIR$/.venv" />
+ </content>
+ <orderEntry type="jdk" jdkName="uv (spotify-discord-widget)" jdkType="Python SDK" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+</module> \ No newline at end of file
diff --git a/bot.py b/bot.py
index 17bed8a..b6aa67c 100644
--- a/bot.py
+++ b/bot.py
@@ -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",
)