• Stars
    star
    1,457
  • Rank 32,069 (Top 0.7 %)
  • Language
    Python
  • License
    Creative Commons ...
  • Created 9 months ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Copy playlists and liked music from Spotify to YTMusic

Tools for moving from Spotify to YTMusic

Overview

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

Thanks to @RadicalArti and Meet Vora for their generous financial contributions to this project.

Getting Started

Install Python (you may already have it)

You will need a somewhat recent version of Python 3.10 and above are known to work, 3.8-3.10 might work.

For Windows

Download Python for Windows from: https://www.python.org/downloads/windows/

You can also use choco to install it: choco install python

For MacOS

Run:

brew install python
brew install python-tk

For Linux

You probably already have it installed. See your package manager of choice to install it.

Install spotify2ytmusic (via pip)

This package is available on pip, so you can install it using:

pip install spotify2ytmusic

or:

python3 -m pip install spotify2ytmusic

(Or) Running From Source

(Not recommended)

Another option, instead of pip, is to just clone this repo and run directly from the source. However, you will need the "ytmusicapi" package installed, so you'll probably want to use pip to install that at the very least.

To run directly from source:

git clone [email protected]:linsomniac/spotify_to_ytmusic.git
cd spotify_to_ytmusic
pip install ytmusicapi
pip install tk  # If using the GUI

Then you can prefix the command you want to run with python3 -m spotify2ytmusic, for example:

python3 -m spotify2ytmusic gui
python3 -m spotify2ytmusic list_playlists
python3 -m spotify2ytmusic load_liked
[etc...]

Graphical UI

If you have installed via PIP, you should be able to run: s2yt_gui

Otherwise, if running from source:

On Windows: python -m spotify2ytmusic gui

Or on Linux: python3 -m spotify2ytmusic gui

Login to YTMusic - Tab 0

Click the login button on the first tab

OR

Run ytmusicapi oauth in a console.

OR

Run s2yt_ytoauth

OR

Run python -m spotify2ytmusic ytoauth

This will give you a URL, visit that URL and authorize the application. When you are done with the import you can remove the authorization for this app.

This will write a file "oauth.json". Keep this file secret while the app is authorized. This file includes a logged in session token.

ytmusicapi is a dependency of this software and should be installed as part of the "pip install".

Backup Your Spotify Playlists - Tab 1

Click the Backup button, and wait until it finished and switched to the next tab.

OR do all the steps below

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".

Reverse your playlists - Tab 2

As mentionned below, the original program adds the songs in the 'wrong' order. That's a feature I don't like, so I created a script to reverse them. It seems to be reliable, but if you find anything weird, please open an issue. It creates a backup of the original file just in case anyway.

Example: python3 .\reverse_playlist.py ./playlists.json -r

Import Your Liked Songs - Tab 3

Click the import button, and wait until it finished and switched to the next tab.

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 hundread songs, but more esoteric titles it may have issues with.

List Your Playlists - Tab 4

Click the list button, and wait until it finished and switched to the next tab.

This will list the playlists you have on both Spotify and YTMusic, so you can individually copy them.

Copy Your Playlists - Tab 5

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).

Copy specific Playlist - Tab 6

In the list output, find the "playlist id" (the first column) of the Spotify playlist and of the YTMusic playlist.

Then fill both input fields and click the copy button.

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.

Command Line Usage

Login to YTMusic

ytmusicapi oauth or s2yt_ytoauth or python -m spotify2ytmusic ytoauth

This will give you a URL, visit that URL and authorize the application. When you are done with the import you can remove the authorization for this app.

This will write a file "oauth.json". Keep this file secret while the app is authorized. This file includes a logged in session token.

ytmusicapi is a dependency of this software and should be installed as part of the "pip install".

Backup Your Spotify Playlists

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".

Import Your Liked Songs

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.

Import Your Liked Albums

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.

List Your Playlists

Run s2yt_list_playlists

This will list the playlists you have on both Spotify and YTMusic. You will need to individually copy them.

Copy Your Playlists

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.

Searching for YTMusic Tracks

This is mostly for debugging, but there is a command to search for tracks in YTMusic:

s2yt_search --artist <ARTIST> --album <ALBUM> <TRACK_NAME>

Details About Search Algorithms

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.

FAQ

  • 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.

License

Creative Commons Zero v1.0 Universal

spotify-backup.py licensed under MIT License. See https://github.com/caseychu/spotify-backup for more information.

More Repositories

1

python-memcached

A python memcached client library.
Python
455
star
2

python-unittest-skeleton

A skeleton Python unit test to boot-strap projects.
Python
50
star
3

python-bottle-skeleton

A skeleton with examples for creating a bottle application.
Python
42
star
4

bottlesession

Session code for bottle microframework.
Python
37
star
5

nanomon

Extremely lightweight monitoring system.
Python
27
star
6

python-movingaverage

Function for computing a moving average of data.
Python
20
star
7

tumgreyspf

A no-dependence external policy checker for Postfix that does SPF and greylisting.
Python
17
star
8

ztproxy

A user-space stdin-to-ZeroTier proxy
Python
14
star
9

vim-omnipy-template

Vim Omnicompletion Template using Python
Vim Script
13
star
10

jafo3pro

My Upgrades to Ender 3 Pro
10
star
11

MarlinSKRMiniE3v2.0Files

Files related to the SKR Mini E3 v2.0
10
star
12

uplaybook

A python-centric IT automation system.
Python
8
star
13

drbdlinks

A helper for DRBD which makes/reverts links into DRBD volumes.
Python
8
star
14

python-memcached2

A 100% python memcached client library.
Python
7
star
15

pmacct

Fork of pmacct-upstream, this is where I put my changes.
C
6
star
16

python-ctypescracklib

Python ctypes wrapper for cracklib.
Python
5
star
17

symbolicmode

Code to handle symbolic permissions as used in GNU chmod ("a=rx,u+w")
Python
4
star
18

python-psycopgwrap

A helper wrapper for psycopg to make database coding easier in Python.
Python
4
star
19

pmacct-upstream

git clone of CVS upstream pmacct (passive IP traffic accounting daemon)
C
3
star
20

ineedpy2

Library which will detect and swap to newer installed python version on a multi-version system.
Python
3
star
21

uplaybook1

A minimal ansible-inspired playbook runner.
Python
3
star
22

ansible-skeleton

Fully-featured Ansible example configuration and tasks set.
Python
3
star
23

toothpyk

A small tool for doing things at the command-line.
Python
3
star
24

rgca

Experiment in SSL CA management.
Python
2
star
25

python-makepath

Python implementation of makepath by jsh.
Python
2
star
26

network-attached-backup

Networked backup server software.
Python
2
star
27

askgpt

A tool to submit questions to OpenAI.
Python
2
star
28

btrfs-progs

My branch of the btrfs-progs project.
C
2
star
29

ssh_signed_hostkeys

Using Ansible to sign SSH host keys
1
star
30

flask-publisher

Use type annotations to bring GET/POST values into Flask functions (similar to mod_python Publisher)
Python
1
star
31

checknagiosnotifications

Look for nagios services that have notifications disabled.
Python
1
star
32

lazrgit

Lazier lazygit, a customized "git commit" for my workflow
Python
1
star
33

spawk

Text processing library for Python
Python
1
star
34

sign1

Home information display.
Python
1
star
35

munin-pdns_recursor

Munin plugins for graphing pdns_recursor.
1
star
36

vpostmaster

vPostMaster e-mail server system.
PHP
1
star
37

rdiffharness

Simple backup script with reasonable features, using rdiff for storing history.
1
star
38

fernetcrypt

Fernet encryption tools
Python
1
star