Tools for moving from Spotify to YTMusic
This is a set of scripts for copying "liked" songs and playlists from Spotify to YTMusic. It provides both CLI tools and a GUI (implemented by Yoween, formerly called spotify_to_ytmusic_gui).
Thanks to @RadicalArti and Meet Vora for their generous financial contributions to this project.
You will need a somewhat recent version of Python 3.10 and above are known to work, 3.8-3.10 might work.
Download Python for Windows from: https://www.python.org/downloads/windows/
You can also use choco to install it: choco install python
Run:
brew install python
brew install python-tk
Install certificates by doing:
Macintosh HD > Applications > Python Folder > double click on "Install Certificates.command" file.
Start by creating and activating a Python virtual environment to isolate dependencies.
git clone https://github.com/AmidelEst/spotify_to_ytmusic.git
cd spotify_to_ytmusic
python -m venv .venv
.venv\Scripts\activate
pip install ytmusicapi tk
To use the YouTube Music API, you need to generate valid credentials. Follow these steps:
-
Log in to YouTube Music: Open YouTube Music in Firefox and ensure you are logged in.
-
Open the Inspection Tool: Press
F12
to open the browser’s inspection tool. -
Access the Network Tab: Navigate to the Network tab and filter by
/browse
. -
Select a Request: Click on one of the requests under the filtered results and locate the Request Headers section.
-
Toggle RAW View: Click on the RAW toggle button to view the headers in raw format.
-
Copy Headers: Right-click, choose Select All, and then copy the content.
-
Paste into
raw_headers.txt
: Open theraw_headers.txt
file located in the main directory of this project and paste the copied content into it. -
Run the Script:
Execute the following command to generate the credentials file:
python spotify2ytmusic/ytmusic_credentials.py
-
Done:
Your YouTube Music credentials are now ready.
Now you can use the graphical user interface (GUI) Tab 2 -> Tab 6 to migrate your playlists and liked songs to YouTube Music.
Start the GUI with the following command:
On Windows:
python -m spotify2ytmusic gui
Or on Linux:
python3 -m spotify2ytmusic gui
Once the GUI is running, you can:
- Backup Your Spotify Playlists: will save your playlists and liked songs into the file "playlists.json".
- Load Liked Songs: Migrate your Spotify liked songs to YouTube Music.
- List Playlists: View your playlists and their details.
- Copy All Playlists: Migrate all Spotify playlists to YouTube Music.
- Copy a Specific Playlist: Select and migrate a specific Spotify playlist to YouTube Music.
It will go through your Spotify liked songs, and like them on YTMusic. It will display the song from Spotify and then the song that it found on YTMusic that it is liking. I've spot-checked my songs and it seems to be doing a good job of matching YTMusic songs with Spotify. So far I haven't seen a single failure across a couple hundred songs, but more esoteric titles it may have issues with.
This will list the playlists you have on both Spotify and YTMusic, so you can individually copy them.
You can either copy all playlists, or do a more surgical copy of individual playlists. Copying all playlists will use the name of the Spotify playlist as the destination playlist name on YTMusic.
To copy all the playlists click the copy
button, and wait until it finished and switched to the next tab
NOTE: This does not copy the Liked playlist (see above to do that).
In the list output, find the "playlist id" (the first column) of the Spotify playlist and of the YTMusic playlist.
The copy playlist will take the name of the YTMusic playlist and will create the playlist if it does not exist, if you start the YTMusic playlist with a "+":
Re-running "copy_playlist" or "load_liked" in the event that it fails should be safe, it will not duplicate entries on the playlist.
Download spotify-backup.
Run spotify-backup.py
and it will help you authorize access to your spotify account.
Run: python3 spotify-backup.py playlists.json --dump=liked,playlists --format=json
This will save your playlists and liked songs into the file "playlists.json".
Run: s2yt_load_liked
It will go through your Spotify liked songs, and like them on YTMusic. It will display the song from Spotify and then the song that it found on YTMusic that it is liking. I've spot-checked my songs and it seems to be doing a good job of matching YTMusic songs with Spotify. So far I haven't seen a single failure across a couple thousand songs, but more esoteric titles it may have issues with.
Run: s2yt_load_liked_albums
Spotify stores liked albums outside of the "Liked Songs" playlist. This is the command to load your liked albums into YTMusic liked songs.
Run s2yt_list_playlists
This will list the playlists you have on both Spotify and YTMusic. You will need to individually copy them.
You can either copy all playlists, or do a more surgical copy of individual playlists. Copying all playlists will use the name of the Spotify playlist as the destination playlist name on YTMusic. To copy all playlists, run:
s2yt_copy_all_playlists
NOTE: This does not copy the Liked playlist (see above to do that).
In the list output above, find the "playlist id" (the first column) of the Spotify playlist, and of the YTMusic playlist, and then run:
s2yt_copy_playlist <SPOTIFY_PLAYLIST_ID> <YTMUSIC_PLAYLIST_ID>
If you need to create a playlist, you can run:
s2yt_create_playlist "<PLAYLIST_NAME>"
Or the copy playlist can take the name of the YTMusic playlist and will create the playlist if it does not exist, if you start the YTMusic playlist with a "+":
s2yt_copy_playlist <SPOTIFY_PLAYLIST_ID> +<YTMUSIC_PLAYLIST_NAME>
For example:
s2yt_copy_playlist SPOTIFY_PLAYLIST_ID "+Feeling Like a PUNK"
Re-running "copy_playlist" or "load_liked" in the event that it fails should be safe, it will not duplicate entries on the playlist.
This is mostly for debugging, but there is a command to search for tracks in YTMusic:
s2yt_search --artist <ARTIST> --album <ALBUM> <TRACK_NAME>
The function first searches for albums by the given artist name on YTMusic.
It then iterates over the first three album results and tries to find a track with the exact same name as the given track name. If it finds a match, it returns the track information.
If the function can't find the track in the albums, it then searches for songs by the given track name and artist name.
Depending on the yt_search_algo parameter, it performs one of the following actions:
If yt_search_algo is 0, it simply returns the first song result.
If yt_search_algo is 1, it iterates over the song results and returns the first song that matches the track name, artist name, and album name exactly. If it can't find a match, it raises a ValueError.
If yt_search_algo is 2, it performs a fuzzy match. It removes everything in brackets in the song title and checks for a match with the track name, artist name, and album name. If it can't find a match, it then searches for videos with the track name and artist name. If it still can't find a match, it raises a ValueError.
If the function can't find the track using any of the above methods, it raises a ValueError.
- Does this run on mobile?
No, this runs on Linux/Windows/MacOS.
-
I get "No matching distribution found for spotify2ytmusic".
This has been reported in Issue #39 and it seems like a mismatch between python versions. Users there, on MacOS, needed to install a specific version of Python, and then use the matching version of PIP:
brew install [email protected] brew install [email protected] pip3.10 install spotify2ytmusic
-
How does the lookup algorithm work?
Given the Spotify track information, it does a lookup for the album by the same artist on YTMusic, then looks at the first 3 hits looking for a track with exactly the same name. In the event that it can't find that exact track, it then does a search of songs for the track name by the same artist and simply returns the first hit.
The idea is that finding the album and artist and then looking for the exact track match will be more likely to be accurate than searching for the song and artist and relying on the YTMusic algorithm to figure things out, especially for short tracks that might be have many contradictory hits like "Survival by Yes".
-
My copy is failing with repeated "ERROR: (Retrying) Server returned HTTP 400: Bad Request".
Try running with "--track-sleep=3" argument to do a 3 second sleep between tracks. This will take much longer, but may succeed where faster rates have failed.
Creative Commons Zero v1.0 Universal
spotify-backup.py licensed under MIT License. See https://github.com/caseychu/spotify-backup for more information.