By Eric Xu
A tool supporting the shuffling, unscrambling, and reversal of songs in a spotify playlist while maintaining the "date added" property for each song.
A short overview on how to use the code, my rationale behind the project, and final learnings.
- Shuffle a playlist while preserving date-added order
- Restore a playlist back to its original order while preserving date-added order
- Reverse playlist order
I used the official spotify documentation for developers and made a local web app using link. I simply named my app and used "http://127.0.0.1:8888/callback" for the redirect URI, while leaving everything else blank. This creates a local app, with its own unique client id and client secret. These can be accessed through the spotify dashboard. Copy and pasting your unique client id and client secret as well as the redirect uri into ".env.example" should allow the code to run without issues, although I have not tested it yet. More detailed instructions can be found here.
*Note the program runs even if you can not see the songs moving in the spotify app. It moves the songs in the spotify database, which takes time to update on your app.
- Install dependencies
Make sure you have Python 3.10+ installed, then run:
pip install spotipy python-dotenv python-dateutil- Set up your Spotify credentials
Create or use the .env file in the project directory and add:
SPOTIPY_CLIENT_ID=your_client_id_here
SPOTIPY_CLIENT_SECRET=your_client_secret_here
SPOTIPY_REDIRECT_URI=http://127.0.0.1:8888/callback
You can find these values in your Spotify Developer Dashboard under your app settings from Set Up.
- Run Main.Py and Follow the Prompts
I was initial inspired by this spotify shuffler I found online, as I found myself feeling similarly towards spotify's shuffle, but after using their shuffler on one of my main playlists, I felt like it looked kind of bad with all the dates mixed up. As they provided no way to unscramble your playlist, I decided to try and figure out a way to revert my playlist to how it was before.
This was my first unguided coding project, so it was interesting implementing theory I learned in my computer science classes like mergesort and api calls into something actually useful and practical. I was also introduced to the chore that is reading through code documentation. Throughout this project, I struggled a lot with the correctness of my code, as I would be using the spotify application to see if it was working. The problem was that spotify application stops showing updates in real time after a few iterations of song shuffling, but I did not know that, which made me question the correctness of my code, as well as if my api calls were being limited. I would eventually find out that the playlist would update even without the playlist being updated visually, but I wasted a lot of time debugging correct code.
- Python 3.10+
- spotipy
- python-dotenv
- python-dateutil
- First completed implementation