Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct spelling of "successfully" #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions insert-songs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
}
Expand All @@ -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:
Expand Down