You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

iTunes Music - Import From Spotify

There are a lot of questions like this around the place, they all basically centre around "how can I (automatically) import my playlists from Spotify to iTunes Music"


I find it strange that Apple didn't release/include a tool for this, as it would be a good way to get people to switch. I personally wouldn't want to commit to iTunes Music (in preference to Spotify) without testing how well my Spotify playlists work.


One solution has been S.T.A.M.P (https://stampapp.io/) My understanding is it uses Automator and it is rather slow.


Another solution I have seen is Move To Apple Music By Ramon Frtisch (http://movetoapplemusic.ramonfritsch.com/) I have not tried this, so can't give you any details on it, or how good it is.


But, here is how I do it! I haven't built an app yet, planning on doing it, but haven't got around to it (and I just figured this out tonight!)


I will be working with a demo playlist, called iTunesSpotifyTest which I have created in Spotify, and contains one song - Midnight Oil's Blue Sky Mine from the album Blue Sky Mining. The Spotify URI for this track is: spotify:track:6z9ehfxE973fOlKJKNJL2x


Step 1: Export the list of tracks from Spotify. One way to do this (without the Spotify API) is to highlight all the tracks, and drag them to a text doc. You will get a bunch of Spotify URIs like http://open.spotify.com/track/6z9ehfxE973fOlKJKNJL2x

Step 2: Lookup the Spotify Track to get the track details: The basic URL to use is:

http://ws.spotify.com/lookup/1/.json?uri=spotify:track:<ID>

Where <ID> is the Spotify ID (6z9ehfxE973fOlKJKNJL2x) in this case


This will return a JSON reply like:


{"track": {"available": true, "album": {"released": "1990", "href": "spotify:album:4C3raKL0dzfTitM3YtqN1S", "name": "Blue Sky Mining (Remastered)"}, "name": "Blue Sky Mine - 2011 Remaster", "popularity": "0.31000", "external-ids": [{"type": "isrc", "id": "AUBM01100280"}], "length": 255.6, "href": "spotify:track:6z9ehfxE973fOlKJKNJL2x", "artists": [{"href": "spotify:artist:72KyoXzp0NOQij6OcmZUxk", "name": "Midnight Oil"}], "availability": {"territories": "AD AR AT AU BE BG BO BR CA CH CL CO CR CY CZ DE DK DO EC EE ES FI FR GB GR GT HK HN HR HU IE IS IT LI LT LU LV MC MT MX MY NI NL NO NZ PA PE PH PL PT PY RO SE SG SI SK SV TR TW US UY"}, "track-number": "1"}, "info": {"type": "track"}}


You could also use XML, but I think JSON is easier.


The fields we are interested in are:

track:album:name (Blue Sky Mining (Remastered))

track:name (Blue Sky Mine - 2011 Remaster)

track:artist:name (Midnight Oil)

Step 3: Lookup the track in iTunes

Use the URL Scheme found here : https://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web -service-search-api.htmlto build a search string. I am looking for artist+track+album of type musicTrack and media=music.

This URL needs to be encoded properly. I have found that it is easier to drop things like "Remastered" from the strings, thus our search terms become

Artist: Midnight Oil

Track: Blue Sky Mine

Album Blue Sky Mining


The final URL will be:

https://itunes.apple.com/search?term=Midnight+Oil+Blue+Sky+Mine+Blue+Sky+Mining& entity=musicTrack&media=mus…


This will give a result (or number of results), such as this:

{ "resultCount":1, "results": [ {"wrapperType":"track", "kind":"song", "artistId":18747421, "collectionId":885256737, "trackId":885256765, "artistName":"Midnight Oil", "collectionName":"Blue Sky Mining (Remastered)", "trackName":"Blue Sky Mine", "collectionCensoredName":"Blue Sky Mining (Remastered)", "trackCensoredName":"Blue Sky Mine (2011 Remaster)", "artistViewUrl":"https://itunes.apple.com/us/artist/midnight-oil/id18747421?uo=4", "collectionViewUrl":"https://itunes.apple.com/us/album/blue-sky-mine-2011-remaster/id885256737?i=885256765&uo=4", "trackViewUrl":"https://itunes.apple.com/us/album/blue-sky-mine-2011-remaster/id885256737?i=885256765&uo=4", "previewUrl":"http://a1700.phobos.apple.com/us/r1000/024/Music4/v4/75/8b/9f/758b9fa4-fa2a-8187-3022-6c3978a309ec/mzaf_3480134139760267184.plus.aac.p.m4a", "artworkUrl30":"http://is3.mzstatic.com/image/pf/us/r30/Music2/v4/7b/26/7d/7b267d55-de38-f1af-ebd1-da8a986b2223/886444672726.30x30-50.jpg", "artworkUrl60":"http://is2.mzstatic.com/image/pf/us/r30/Music2/v4/7b/26/7d/7b267d55-de38-f1af-ebd1-da8a986b2223/886444672726.60x60-50.jpg", "artworkUrl100":"http://is1.mzstatic.com/image/pf/us/r30/Music2/v4/7b/26/7d/7b267d55-de38-f1af-ebd1-da8a986b2223/886444672726.100x100-75.jpg", "collectionPrice":8.99, "trackPrice":0.99, "releaseDate":"2014-06-10T07:00:00Z", "collectionExplicitness":"notExplicit", "trackExplicitness":"notExplicit", "discCount":1, "discNumber":1, "trackCount":10, "trackNumber":1, "trackTimeMillis":255600, "country":"USA", "currency":"USD", "primaryGenreName":"Rock", "radioStationUrl":"https://itunes.apple.com/station/idra.885256765", "isStreamable":true}] }


Brilliant! We have found the song in iTunes.


Step 4: Build an iTunes Playlist file

If you want to see how this works, grab a playlist in iTunes, hit File->Library->Export Playlist, save it and open in a text editor. Turns out, not much is required to make a valid playlist file. The format we need is this:


Name Artist Composer Album Grouping Genre Size Time Disc Number Disc Count Track Number Track Count Year Date Modified Date Added Bit Rate Sample Rate Volume Adjustment Kind Equalizer Comments Plays Last Played Skips Last Skipped My Rating Location

trackName<tab>artistName<tab><tab>collectionCensoredName<tab><tab><tab><tab>255<tab><tab><tab><tab><tab><tab><tab><tab><tab><tab><tab>AACaudio file<tab><tab><tab><tab><tab><tab><tab><nl>

This, from my experiments seems to be the requirements. Of course you can add more fields, but some are harder to work out than others, so why bother if they aren't required, right?

The first line is the header required, the fields are all tab delimited. It seems a "Time" value of 255 denotes a streaming file. Apart from that insert the right trackName, artistName and album (collectionCensoredName seems to work best), and type "AACaudio file" and your good to go. End the file with a new line. Then save the file as a .txt file with the file name equal to the playlist name.

In this case: iTunesSpotifyTest.txt


Name Artist Composer Album Grouping Genre Size Time Disc Number Disc Count Track Number Track Count Year Date Modified Date Added Bit Rate Sample Rate Volume Adjustment Kind Equalizer Comments Plays Last Played Skips Last Skipped My Rating Location
Blue Sky Mine Midnight Oil Blue Sky Mining (Remastered) 255 AAC audio file


Step 5: Import playlist to iTunes

File -> Library -> import and then select the file. Done!


This has worked brilliantly in my case, some things to think about


1) you might need to do some trial and error on removing words like "Remaster" etc

2) if you get multiple hits on the iTunes lookup, you will need to determine how to handle this (I just grab the first result for now, to do this in the URL lookup just add limit=1)

3) be careful with the playlist format, the right number of tabs, and finishing the file with an extra new line are required.


I have this at the moment in some crappy PHP code, I might (if there is enough interest) clean it up and release it on GitHub or something, but other than that, I hope this helps someone!


cheers!

Mac mini, OS X Mavericks (10.9.2), null

Posted on Jul 19, 2015 1:20 PM

Reply
Question marked as Top-ranking reply

Posted on Jul 19, 2015 2:30 PM

Here's a quick and dirty shell script you can use.


Notes:


1) it's very quick and dirty, but seems to work (I am aware that it is terrible shell coding!)

2) there are not catches for "Remastered" keyword etc


#! /bin/bash


IN_FILE=$1

PLAYLIST_NAME="$2.txt"


echo "Name Artist Composer Album Grouping Genre Size Time Disc Number Disc Count Track Number Track Count Year Date Modified Date Added Bit Rate Sample Rate Volume Adjustment Kind Equalizer Comments Plays Last Played Skips Last Skipped My Rating Location

" > $PLAYLIST_NAME


while read line; do

track_id=`echo $line | sed 's|http://open.spotify.com/track/||'`

spotify_lu_url="http://ws.spotify.com/lookup/1/?uri=spotify:track:$track_id"

track_artist_album=`curl --silent $spotify_lu_url | grep "<name>" | awk -F">" '{print $2}' | awk -F"<" '{print $1}'`

TrackName=`echo "$track_artist_album" | head -1 | tr " " "+"`

Artist=`echo "$track_artist_album" | head -2 | tail -1 | tr " " "+"`

Album=`echo "$track_artist_album" | head -3 | tail -1 | tr " " "+"`

itunes_lu_url="https://itunes.apple.com/search?term=$Artist+$Album+$TrackName&entity=musicTrack &media=music&limit=1"

curl --silent --output curl_out.txt "$itunes_lu_url"

itrackName=`cat curl_out.txt | perl -pe 's/, /\n/g' | grep trackName | awk -F":" '{print $2}' | sed 's/\"//g'`

iartistName=`cat curl_out.txt | perl -pe 's/, /\n/g' | grep artistName | awk -F":" '{print $2}' | sed 's/\"//g'`

ialbumName=`cat curl_out.txt | perl -pe 's/, /\n/g' | grep collectionCensoredName | awk -F":" '{print $2}' | sed 's/\"//g'`

if [[ "$itrackName" == "" || "$iartistName" == "" || "$ialbumName" == "" ]]; then

echo "--ERROR-- `echo $TrackName by $Artist on $Album | tr "+" " "` Not Added"

else

echo "-- OK -- `echo $TrackName by $Artist on $Album | tr "+" " "` Added"

echo "$ialbumName\t$iartistName\t $ialbumName 255 AACaudio file

" >> $PLAYLIST_NAME

fi

done < $IN_FILE


echo "

" >> $PLAYLIST_NAME

22 replies
Sort By: 
Question marked as Top-ranking reply

Jul 19, 2015 2:30 PM in response to clubmanplus850

Here's a quick and dirty shell script you can use.


Notes:


1) it's very quick and dirty, but seems to work (I am aware that it is terrible shell coding!)

2) there are not catches for "Remastered" keyword etc


#! /bin/bash


IN_FILE=$1

PLAYLIST_NAME="$2.txt"


echo "Name Artist Composer Album Grouping Genre Size Time Disc Number Disc Count Track Number Track Count Year Date Modified Date Added Bit Rate Sample Rate Volume Adjustment Kind Equalizer Comments Plays Last Played Skips Last Skipped My Rating Location

" > $PLAYLIST_NAME


while read line; do

track_id=`echo $line | sed 's|http://open.spotify.com/track/||'`

spotify_lu_url="http://ws.spotify.com/lookup/1/?uri=spotify:track:$track_id"

track_artist_album=`curl --silent $spotify_lu_url | grep "<name>" | awk -F">" '{print $2}' | awk -F"<" '{print $1}'`

TrackName=`echo "$track_artist_album" | head -1 | tr " " "+"`

Artist=`echo "$track_artist_album" | head -2 | tail -1 | tr " " "+"`

Album=`echo "$track_artist_album" | head -3 | tail -1 | tr " " "+"`

itunes_lu_url="https://itunes.apple.com/search?term=$Artist+$Album+$TrackName&entity=musicTrack &media=music&limit=1"

curl --silent --output curl_out.txt "$itunes_lu_url"

itrackName=`cat curl_out.txt | perl -pe 's/, /\n/g' | grep trackName | awk -F":" '{print $2}' | sed 's/\"//g'`

iartistName=`cat curl_out.txt | perl -pe 's/, /\n/g' | grep artistName | awk -F":" '{print $2}' | sed 's/\"//g'`

ialbumName=`cat curl_out.txt | perl -pe 's/, /\n/g' | grep collectionCensoredName | awk -F":" '{print $2}' | sed 's/\"//g'`

if [[ "$itrackName" == "" || "$iartistName" == "" || "$ialbumName" == "" ]]; then

echo "--ERROR-- `echo $TrackName by $Artist on $Album | tr "+" " "` Not Added"

else

echo "-- OK -- `echo $TrackName by $Artist on $Album | tr "+" " "` Added"

echo "$ialbumName\t$iartistName\t $ialbumName 255 AACaudio file

" >> $PLAYLIST_NAME

fi

done < $IN_FILE


echo "

" >> $PLAYLIST_NAME

Reply

Jul 19, 2015 3:29 PM in response to clubmanplus850

***THIS POST ABOVE HAS ERRORS!***


Here's a quick and dirty shell script you can use.


Notes:


1) it's very quick and dirty, but seems to work (I am aware that it is terrible shell coding!)

2) there are not catches for "Remastered" keyword etc

3) there are bugs (which I am working on)

4) this script contains some updated findings on searching for tracks in iTunes (country code, and the correction of my assumption on the Time field)


#! /bin/bash


IN_FILE=$1

PLAYLIST_NAME="$2.txt"

COUNTRY=$3


echo "Name Artist Composer Album Grouping Genre Size Time Disc Number Disc Count Track Number Track Count Year Date Modified Date Added Bit Rate Sample Rate Volume Adjustment Kind Equalizer Comments Plays Last Played Skips Last Skipped My Rating Location" > $PLAYLIST_NAME


while read line; do

track_id=`echo $line | sed 's|http://open.spotify.com/track/||'`

spotify_lu_url="http://ws.spotify.com/lookup/1/?uri=spotify:track:$track_id"

track_artist_album=`curl --silent $spotify_lu_url | grep "<name>" | awk -F">" '{print $2}' | awk -F"<" '{print $1}'`

TrackName=`echo "$track_artist_album" | head -1 | tr " " "+"`

Artist=`echo "$track_artist_album" | head -2 | tail -1 | tr " " "+"`

Album=`echo "$track_artist_album" | head -3 | tail -1 | tr " " "+"`

itunes_lu_url="https://itunes.apple.com/search?term=$Artist+$Album+$TrackName&entity=musicTrack &media=music&limit=1&country=$COUNTRY"

curl --silent --output curl_out.txt "$itunes_lu_url"

itrackName=`cat curl_out.txt | perl -pe 's/, /\n/g' | grep trackName | awk -F":" '{print $2}' | sed 's/\"//g'`

iartistName=`cat curl_out.txt | perl -pe 's/, /\n/g' | grep artistName | awk -F":" '{print $2}' | sed 's/\"//g'`

ialbumName=`cat curl_out.txt | perl -pe 's/, /\n/g' | grep collectionCensoredName | awk -F":" '{print $2}' | sed 's/\"//g'`

itime=`cat curl_out.txt | perl -pe 's/, /\n/g' | grep trackTimeMillis | awk -F":" '{print $2}' | sed 's/\"//g'`

if [[ "$itrackName" == "" || "$iartistName" == "" || "$ialbumName" == "" ]]; then

echo "--ERROR-- `echo $TrackName by $Artist on $Album | tr "+" " "` Not Added"

else

echo "-- OK -- `echo $TrackName by $Artist on $Album | tr "+" " "` Added"

itime=$(($itime / 1000))

printf "$itrackName\t$iartistName\t\t$ialbumName\t\t\t\t$itime\t\t\t\t\t\t\t\t\t\t\tAA C audio file\t\t\t\t\t\t\t\n" >> $PLAYLIST_NAME

fi

done < $IN_FILE


echo "

" >> $PLAYLIST_NAME

Reply

Jul 23, 2015 10:45 AM in response to sirjosephoh

hey! @sirjosephoh


this is a bash script which you run in the terminal. You need to copy+paste the code into a file, chmod 755 to make it executable and then run it with a few options 🙂


Ok, so that's the short answer, and I realise that you were after a longer more detailed answer and some step by step instructions - don't worry, they will come! however, there are still some bugs I am working out; the playlist format can be a little bit picky at times.


in addition to the fixes in the last post, i have made some more updates - specifically I've now discovered that the playlist file uses carriage-returns and not new-lines after each record, and that there is a the field "isStreamable" to know if a file exists in the iTunes repository but can not be streamed using iTunes Music; i've added these in.


I'm also trying to move this to a web based system, but im having some mac crash issues at the moment which is delaying me slightly.


be back soon!

Reply

Aug 23, 2015 6:30 PM in response to clubmanplus850

I've written a Ruby script to do this based on your Spotify playlists. Source code available at https://gist.github.com/moneypenny/69844669fe791beed2fa It requires you have a Spotify API application, which is free to create: https://developer.spotify.com/my-applications/#!/applications


However, while the iTunes playlist file my script creates seems to be in the right format, every time I try to import one into iTunes, I get an error about some of the tracks couldn't be added because they couldn't be found. I don't have the actual songs locally, I'm an Apple Music user and I want to create playlists for songs I have streaming access to. :/

Reply

Aug 25, 2015 3:59 PM in response to clubmanplus850

clubmanplus850, can you be more specific about what you mean by the "isStreamable" column?


The issue I'm running into is that I can only create playlists containing Apple Music songs I've already previously added to my library. If the song isn't yet in the library, iTunes skips the song during playlist import. (I'm basically having the same problem as cheshire137). Did you find some way around this problem?


I've considered whether it might be possible to update the iTunes library.xml file directly, but it seems to require more information about each track than the simple playlist import process.

Reply

Sep 9, 2015 2:21 AM in response to beevik

I created a site that creates output as mentioned in your original post: abcdeo.com(abcdeo.com)


It also creates blank mp3 files so that imports can work even when file is not in existing library.


However, I've not tested it as I don't use imusic yet.

Give it a go and let me know if it manages to import/convert your playlists!


Bill

Reply

Oct 10, 2015 7:15 AM in response to clubmanplus850

No streaming music service that I'm aware of makes it easy to export playlists and conversely if exports aren't available they also don't offer playlist import capability for competing services. This is their lock in to maintain subscribers. It therefore fall upon third party sites and intrepid users like yourself to develop alternative solutions.

Reply

Oct 11, 2015 1:28 PM in response to clubmanplus850

Hi all


sorry for the big delay!


1. I moved house

2. I renovated (bad idea)

3. The renovations went totally haywire (don't the always?)

4. My Mac is STILL crashing (dodgy RAM requiring a warranty replacement)

5. I injured my back and can't sit over a PC for more than 5 minutes without losing feeling in my legs... (no comment)


yeah, bad year! I've updated some comments where applicable


thanks for all the kind words and work people have done!

Reply

iTunes Music - Import From Spotify

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.