From 5098649f42e00509d518eac454f9c6725d98b7d6 Mon Sep 17 00:00:00 2001 From: Ted Wood Date: Sun, 5 Jul 2015 15:42:29 -0700 Subject: [PATCH 1/2] correct spelling of "successfully"; some trailing whitespace removed automatically by my editor --- insert-songs.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/insert-songs.py b/insert-songs.py index b9c9bb5..9e2b9f9 100644 --- a/insert-songs.py +++ b/insert-songs.py @@ -4,7 +4,7 @@ def construct_request_body(timestamp, itunes_identifier): - hex = "61 6a 43 41 00 00 00 45 6d 73 74 63 00 00 00 04 55 94 17 a3 6d 6c 69 64 00 00 00 04 00 00 00 00 6d 75 73 72 00 00 00 04 00 00 00 81 6d 69 6b 64 00 00 00 01 02 6d 69 64 61 00 00 00 10 61 65 41 69 00 00 00 08 00 00 00 00 11 8c d9 2c 00" + hex = "61 6a 43 41 00 00 00 45 6d 73 74 63 00 00 00 04 55 94 17 a3 6d 6c 69 64 00 00 00 04 00 00 00 00 6d 75 73 72 00 00 00 04 00 00 00 81 6d 69 6b 64 00 00 00 01 02 6d 69 64 61 00 00 00 10 61 65 41 69 00 00 00 08 00 00 00 00 11 8c d9 2c 00" body = bytearray.fromhex(hex); body[16:20] = struct.pack('>I', timestamp) @@ -28,7 +28,7 @@ def add_song(itunes_identifier): "Content-Type" : "application/x-dmap-tagged", # Replace the values of the next three headers with the values you intercepted "X-Dsid" : "**REPLACE THIS**", - "Cookie" : "**REPLACE THIS**", + "Cookie" : "**REPLACE THIS**", "X-Guid" : "**REPLACE THIS**", "Content-Length" : "77" } @@ -40,10 +40,10 @@ def add_song(itunes_identifier): with open('itunes.csv') as itunes_identifiers_file: for line in itunes_identifiers_file: itunes_identifier = int(line) - + try: add_song(itunes_identifier) - print("Successfuly inserted a song!") + print("Successfully inserted a song!") # Try playing with the interval here to circumvent the API rate limit time.sleep(30) except Exception as e: From 73aaee04c8bf3af3d8065acfe6bf4e5132364990 Mon Sep 17 00:00:00 2001 From: Ted Wood Date: Sun, 5 Jul 2015 15:53:33 -0700 Subject: [PATCH 2/2] fix typos, correct wording; and my editor stripped more trailing whitespace --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2f6470e..b758d0f 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,20 @@ Some simple Python 3 scripts to help you into importing your existing Spotify li ### 1. Export the Spotify songs to an CSV File The first step is getting the songs you want to import into Apple Music into a CSV file. The simplest way to do this is using [Exportify](https://rawgit.com/watsonbox/exportify/master/exportify.html). -If you want to export you whole Spotify library, simply create a new playlist called *All* and drag your whole library into it using the Spotify desktop app. You can then export the playlist *All* using *Exportify*. Save the resulting file as *spotify.csv* in the same directory as the directory you cloned this repo into. +If you want to export your whole Spotify library, simply create a new playlist called *All* and drag your whole library into it using the Spotify desktop app. You can then export the playlist *All* using *Exportify*. Save the resulting file as *spotify.csv* in the same directory as the directory you cloned this repo into. ### 2. Match the Spotify songs with their Apple Music identifier In order to add songs to our Apple Music library, we need their Apple Music identifier. Running `python3 retrieve-identifiers.py` will use the *spotify.csv* file to create a new file *itunes.csv* with each line consisting of the Apple Music identifier of a song in your Spotify library. ### 3. Use an intercepting proxy to retrieve the Apple Music request headers -Start iTunes and [Charles](http://www.charlesproxy.com) (or another intercepting proxy you like). Make sure SSL Proxying is enabled and working correctly. Next, select a random song on Apple Music you don't have in your library yet, right click and choose 'Add to library'. If everything went well, you're now able to view all the request headers in Charles of a request to `https://ld-4.itunes.apple.com/WebObjects/MZDaap.woa/daap/databases/1/cloud-add`. We're only interested in `Cookie`, `X-Dsid` and `X-Guid`. Copy the value of these header and paste them in the appropriate place in `insert-songs.py` (line 29 and further). +Start iTunes and [Charles](http://www.charlesproxy.com) (or another intercepting proxy you like). Make sure SSL Proxying is enabled and working correctly. Next, select a random song on Apple Music you don't have in your library yet, right click and choose 'Add to My Music'. If everything went well, you're now able to view all the request headers in Charles of a request to `https://ld-4.itunes.apple.com/WebObjects/MZDaap.woa/daap/databases/1/cloud-add`. We're only interested in `Cookie`, `X-Dsid` and `X-Guid`. Copy the value of these header and paste them in the appropriate place in `insert-songs.py` (line 29 and further). Next, run `python3 insert-songs.py` and go grab a coffee. You're songs are now being imported into Apple Music. ## Current issues ### API limit rate -Apple Music doesn't like it when we're adding a lot of songs in a small amount of time. If we do so, the API responds to all further request with `403 Too many requests`. After this, you're blocked from the API for an undetermined amount of time. We're currently trying to avoid this by waiting after each request. A delay of 30 seconds seems fine to import large libraries into Apple Music. If you're library is smaller, feel free to decrease the delay in `inserts-songs.py`. +Apple Music doesn't like it when we're adding a lot of songs in a small amount of time. If we do so, the API responds to all further request with `403 Too many requests`. After this, you're blocked from the API for an undetermined amount of time. We're currently trying to avoid this by waiting after each request. A delay of 30 seconds seems fine to import large libraries into Apple Music. If your library is smaller, feel free to decrease the delay in `inserts-songs.py`. ### Missing songs The script I'm using to retrieve the Apple Music identifier for a Spotify song is quite basic. It simply compares the title and artist to find out if a Spotify and Apple Music song match. Some songs don't have the exact same title (extraneous spacing for example) in both services. This results in the script failing to retrieve an identifier for some songs.