Giter Site home page Giter Site logo

spotify_to_ytmusic's Introduction

Tools for moving from Spotify to YTMusic

Code Refactoring Note

We are currently refactoring the code and integrating the GUI. There may be some bugs as this work is being done, if you experience problems please go back to a version previous to this work, for example 0.9.12. To use pip to install a specific version, do: pip install spotify2ytmusic==0.9.12

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

Getting Started

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

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

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

Graphical UI

On Windows: python gui.py

Or on Linux: python3 gui.py

Login to YTMusic - Tab 0

Click the login button on the first tab

OR

Enter ytmusicapi oauth in a console.

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.

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

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>

FAQ

  • 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

spotify_to_ytmusic's People

Contributors

dependabot[bot] avatar linsomniac avatar yoween avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

spotify_to_ytmusic's Issues

s2yt_copy_playlist Exception: Server returned HTTP 404: Not Found.

When I enter s2yt_copy_playlist i get these errors:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Schurkee\AppData\Local\Programs\Python\Python312\Scripts\s2yt_copy_playlist.exe\__main__.py", line 7, in <module>
  File "C:\Users\Schurkee\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotify2ytmusic\cli.py", line 153, in copy_playlist
    copier(src_pl_id, dst_pl_id, args.dry_run, args.track_sleep)
  File "C:\Users\Schurkee\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotify2ytmusic\cli.py", line 166, in copier
    yt_pl = yt.get_playlist(playlistId=dst_pl_id)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Schurkee\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmusicapi\mixins\playlists.py", line 108, in get_playlist
    response = self._send_request(endpoint, body)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Schurkee\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmusicapi\ytmusic.py", line 238, in _send_request
    raise Exception(message + error)
Exception: Server returned HTTP 404: Not Found.
Requested entity was not found.

Setup instructions not clear to me

Hello, I'm new to python and I'm stuck at one of the very first steps in the README file. I've installed the package via pip and wanted to run python gui.py but I'm getting "[Errno 2] No such file or directory". I've moved to the directory and tried again and got the same message. What am I doing wrong?

"Requested entity was not found"

Hi, I get this error from time to time which causes the copying to stop, I don't know if that's a known issue but I wanted to bring it to your attention:

Traceback (most recent call last):
  File "C:\path_to_file\load_liked", line 60, in <module>
    dst_track = lookup_song(yt, src_track_name, src_track_artist, src_album_name)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\path_to_file\load_liked", line 22, in lookup_song
    for track in yt.get_album(album["browseId"])["tracks"]:
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\ytmusicapi\mixins\browsing.py", line 429, in get_album
    response = self._send_request(endpoint, body)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\ytmusicapi\ytmusic.py", line 238, in _send_request
    raise Exception(message + error)
Exception: Server returned HTTP 404: Not Found.
Requested entity was not found.

Error

When i use the load liked command i get errors saying that something isn't correct in some lines

Creating playlist when copying

It'd be nice to be able to make the ytmusic_playlist_id in the copy_playlist() function optional, with it being able to create a new playlist if no existing ID is given. It annoyed me always having to create a playlist before copying into it:D

I tried implementing that myself but I can't create a pull request (that might be on me tho, it's my first time working on GitHub and I'm fairly new to programming). Please be nice if this is too messy:D

 if args.ytmusic_playlist_id is None:
        pl_name = input("What is the name of the new playlist?\n")
        dst_pl_id = YTMusic("oauth.json").create_playlist(title=pl_name, description=pl_name)
    else:
        dst_pl_id = args.ytmusic_playlist_id

Instructions Confusion

I am very bad with understanding python, I haven't yet began to learn how python works, and almost every instruction on the page is difficult for me to understand due to that, I hate to report this as an issue, but I need some help setting this up, and don't know where to ask about the topic of help on using this other than here, I'm primarily trying to get a grasp on PIP and how to use that, but I'm also trying to do the "run from source" method to try to use the GUI version, but that is a bit disconnected from this topic specifically, I just need some help either getting this or the GUI version set up, because I really want to leave Spotify, their pushing of premium is just very annoying, but I don't know how to do it myself, and need help using this, which seems to be the overall best option, because moving over a thousand songs from Spotify to Youtube music would take literal weeks of my life, thank you for the help, anyone who does help, and I'm very sorry to have to add this issue to the spotify_to_ytmusic project linsomniac.

Invalid value for header, must be of type str or bytes, not 'int'

Hi, I was testing my version on a VM running Ubuntu Cinnamon and stumbled across this error message when trying to copy my liked songs to YTMusic.
I then tried on your original program and got the same one. It works fine on windows and linux lite, which are the 2 others I tested.
Any idea why ?
image

copy_playlist.py does not copy every song in playlist and doesn't report an error either

I made a script (that is, ChatGPT did) to count the number of songs in the playlist to verify spotify-backup.py is counting correctly, and the number is correct (906 in my case). The script has only copied 863 songs and has not once reported not being able to find a song.

Counting script for reference:

import json

# Function to count songs in each playlist
def count_songs_in_playlists(file_path):
    with open(file_path, 'r') as file:
        data = json.load(file)
        
        # Dictionary to store the count of songs for each playlist
        song_counts = {}

        # Iterate through each playlist and count the songs
        for playlist in data['playlists']:
            playlist_name = playlist['name']
            number_of_songs = len(playlist['tracks'])
            song_counts[playlist_name] = number_of_songs

        return song_counts

# Path to the JSON file
file_path = 'playlists.json'

# Counting songs in each playlist
song_counts = count_songs_in_playlists(file_path)
print(song_counts)```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.