Sync iTunes playlists to Spotify

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:

  1. CRON job runs AppleScript periodically
  2. Applescript queries iTunes for playlist information and saves each playlist and its songs to a .txt file
  3. Python script compares .txt files to Spotify playlists – information retreived via API calls
  4. 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:

  1. Allow deletion of playlists and songs from playlists
  2. Check a song’s popularity before adding it — this should increase accuracy in song adding
  3. Load client_id and client_secret key from environmental variables
  4. Hook Python component into AppleScript (oAuth makes this difficult…..)
  5. Allow Spotify -> iTunes sync. Currently only goes one way.
  6. Set up CRON service to periodically call the AppleScript
  7. Add comments to code. (yes, i am bad programmer)


Leave a Reply

Your email address will not be published. Required fields are marked *