Using Workflow for export Spotify playlist to Apple Music

It’s almost a year since Apple introduced its streaming service. Initially I welcomed it with hope but soon after had a lot of mixed feelings. Inconsistencies in UI and weird engine choices (“Why I cannot add song to a playlist without turning iCloud Music Library first?”) only increased that attitude. To make things worse Apple haven’t provided no sort of API for 3rd party developers, a move that create great question for all of music lovers — “How the hell I am gonna transfer my Spotify playlist?”

This quickly become non-trivial issue that caused frustration both on average user and developer side. Some solution emerged — Stamp being notable example — but they were at least hacky or non-elegant ways that utilized e.g. AppleScript to automate boring and tedious job. Fortunately, things are getting better when Apple finally relased some sort of API and with recent 1.5 update of Workflow app that introduced some iTunes/Apple Music action added to its core. For those of you unaware of what exactly Workflow is short explanation — it’s one of the best apps on iOS market allowing user to automate stuff using several draggable actions and chaining them together. So when my twitter friend Marta(@martystka) shared to me some nice tunes on YouTube I started to think how to automate import process and began to fiddle with Workflow actions.


First attempt — save single track

If you get link to any song in Spotify and try to open it in browser you will end in something like this:

Because we are in Safari, our workflow can be run as action extension and with this approach fortunately we can use “Get Details of Safari Web Page” and choose “Name” as an option. After that following steps are done:

  1. “on Spotify” is removed from string
  2. Artist and title of the song are matched from string using regexp and saved as separate groups
  3. Groups are extracted from matched text and saved to variables
  4. Search iTunes Store for songs using [Artist] [Title] criteria and return only 1 relevant result.
  5. If result is not empty add it to playlist — in my case I called it “Spotify”

You may grab this workflow here (change iTunes country approprietly)

Second attempt — batch link processing

If we have small playlist method above may work but it’s time consuming. And what when our playlist contains dozens or even hundreds of tracks? Different approach is needed. But again things become harder on iOS client that offers no way to select multi tracks in single playlist and what I wanted is to keep things as simple as possible and avoid advanced scripting in Pythonista. So it’s better to start on desktop client, go to any playlist we need to transfer and select all the tracks by CMD-A (CTRL-A on Windows) and copy-paste it to text file in place where we have access to from our iPhone/iPad. Dropbox seems to be simple solution for the job, remember only to add “txt” extension to file otherwise it may not be visible by apps like Drafts. And this is another moment when things get complicated. Because we have to batch process bunch of links we cannot use Workflow as extension and therefore “Get details of Safari Web Page” is not available. Name of the actions can be little confusing, so by trial and error I figured that “Get details of Articles” is unnessecary and I should use “Get URL’s from input” — “Get contents of URL” — “Get text from input” combo. So this time procedure will include additional steps:

  1. Every track link needs to be in separate line in clipboard
  2. We need to split clipboard content into separate lines, every line assigned to variable.
  3. Because this time variable will hold multi-line string I need to find correct pattern to match artist and title using regular expressions.
  4. There is additional variable called PublishedBy, that holds translation for “published by”, you should modify it according to your needs.

Of course with large number of track in playlist you must be patient and let Workflow do this job, but after all that’s why computers are for :) You can grab this script here. Workflow in action is presented in movie below:

How to export Spotify playlist to Apple Music tutorial [in polish]

I’ve started to use Spotify lately again, mainly because of its wonderfull “Discover Weekly” feature which (suprisingly) I find a lot better than Apple Music’s “For You”. With this IFTTT receipe, every Monday new text file will be created in Dropbox and it will include URL of every track in that playlist so with this workaround you may have best of both worlds. I hope this helps someone and encourage you to your own experiments with automation :)