iTunes is dumb and has a super restrictive API. Spotify is awesome, and has an API for all my things, like my PS4 and Amazon Echo. But I like the iTunes UI, and it plays better with my local library than Spotify. As a result, I subscribe to both services, but it’s such a pain managing playlists between the two.
I present to you, the super not janky at all sync script/setup that I wrote up in a 3 hour burst of inspiration last night. The main flow of the idea is this:
- CRON job runs AppleScript periodically
- Applescript queries iTunes for playlist information and saves each playlist and its songs to a .txt file
- Python script compares .txt files to Spotify playlists – information retreived via API calls
- Python script updates Spotify playlists with differences found between the two services
AppleScript is a very interesting programming language, where the code is incredibly human readable at the cost of ease of use when coding. Here’s what I wrote for extracting playlist information out of iTunes:
This extracts playlist information and saves each playlist as a .txt file to a specified directory. The Python component does most of the legwork in terms of finding which tracks needed to be added to Spotify. You’ll need to create a new application at the Spotify Developers page to get a client_id and client_secret_key.
I’m going to make that prettier… Next steps:
- Allow deletion of playlists and songs from playlists
- Check a song’s popularity before adding it — this should increase accuracy in song adding
- Load client_id and client_secret key from environmental variables
- Hook Python component into AppleScript (oAuth makes this difficult…..)
- Allow Spotify -> iTunes sync. Currently only goes one way.
- Set up CRON service to periodically call the AppleScript
- Add comments to code. (yes, i am bad programmer)
-Sophie