As a heavy Spotify user, I wanted to replicate iTunes' Smart Playlists feature in Spotify, specifically Recently Added, Top 25 Most Played, and Top 25 Least Played since I add music to my Spotify library/playlists all the time. Because my playlists are rather large at this point (1,000+ tracks), recent tracks don't get played very often and get lost in the sauce. This script running periodically keeps an automatically updated playlist of recently added tracks to my library in the last month as well as my top 25 most and least played tracks based on my last.fm scrobbles, since Spotify holds user plays in a vault until December of each year.
I also added a script to get new releases from artists I follow to a playlist, since Spotify's What's New feed sometimes delays showing new releases by a few days to a week.
There's also a script to find tracks that are in my Spotify library but not scrobbled at all on last.fm and add them to a playlist. The Top 25 playlists only work if everything in my library has scrobbles. I started scrobbling on last.fm in February of 2021, and my Spotify library was also quite large at that time, so there were plenty of tracks that I hadn't scrobbled yet. This script is probaly just a one-off, but will keep around in case scrobbles get missed for whatever reason.
This was more-or-less completely vibe-coded with DeepSeek when it first became publically available and later edited and expanded with Claude. I wanted to try out the newest AI chatbot and also try out actual vibe coding and see how it goes for an inconsequential project. Generally, I'm pleasantly surprised with how well this turned out, functions just as intended.
- Spotify Developer account
- An app created in the Spotify Developer Dashboard
- Enable
Web APIin the settings - You shouldn't have any quota issues as long as you aren't running these scripts several times a day
- Enable
- last.fm API account
-
Create a Python Virtual Environment
python -m venv venv source venv/bin/activate -
Install Python packages:
pip install -r requirements.txt -
Create
.envtouch .env -
Add info for
CLIENT_IDandCLIENT_SECRETfrom the Spotify Developer App Settings A good default forREDIRECT_URIishttp://127.0.0.1:8888/callback, make sure it matches in the Spotify Developer App settingsSOURCE_PLAYLIST_IDis from your public Spotify playlist share linkTARGET_PLAYLIST_NAMEis the name of your new playlistLASTFM_API_KEYis from last.fm to get track scrobblesLASTFM_USERNAMEis your last.fm usernameTOP_25_PLAYLIST_NAMEis the name of your top 25 playlistBOTTOM_25_PLAYLIST_NAMEis the name of your bottom 25 playlist
Once you fill out your .env, you can run either Python file to test it out
Use either a cronjob or Windows Task Scheduler to run the scripts periodically
- @Noahffiliation - Idea & Initial work
- iTunes