Code Monkey home page Code Monkey logo

ytmusic-to-spotify's Introduction

ytmusic-to-spotify

A small Python program to migrate a YouTube Music library across to Spotify.

Setup

Dependencies

  • Python 3.x
  • pip
  • venv

(Recommended) create virtual environment

python3 -m venv venv

Install dependencies

python3 -m pip install -r requirements.txt

Spotify auth

Copy config.ini.example to a new file called config.ini. Replace the placeholders with the values from the Spotify developer console. You will need to add a redirect URI to your app of http://localhost:8080 (as set in the template config file). This allows the included Spotify library spotipy to receive the authorization code from Spotify and complete the OAuth exchange.

YouTube Music auth

Copy headers_auth.json.example to a new file called headers_auth.json. Head to YouTube Music and inspect the headers of any request to that domain (e.g. get-search-suggestions) using your browser's developer tools. You will need to copy the Cookie, User-Agent and X-Goog-AuthUser header values into the placeholders in the headers_auth.json file.

YouTube Music does not have an official API, so the included library ytmusicapi mimics a browser accessing the site and uses the 'unofficial' API exposed to the internet that way.

Running

Calling python3 migrate.py will start the migration process. The first time a connection is made to Spotify you will need to allow the app access to your Spotify account. When access is granted, the browser will attempt to redirect to your app's redirect_uri, which if set properly as above will be handled by spotipy, which will then store a local copy of an access and refresh token, so this step is not necessary on future executions.

Not all songs will be found, so the program will log to the console if it cannot find any results for a given song in the YouTube Music library.

The Spotify API has a rate limit, so the migration is done in batches with a pause between to avoid hitting the limit. This program does not currently handle being rate limited gracefully.

Note: while the public parameter has been set to False when creating the playlist on Spotify, manual testing has shown that the playlist still shows as public. You may need to manually change this.

Post-execution

Unfortunately it is not possible to guarantee perfect matches for each song. This program will use artist/album information when possible to narrow down the possible search results, but it is recommended to manually look through the resultant playlist on Spotify's side to ensure there isn't any unexpected in there (or, e.g. undesired live versions). You will also need to manually search for and add any songs that weren't found automatically.

Future work

  • TODO: Add work and words around check.py.
  • TODO: Add migration handling for custom playlists. In particular, refactor the code to make it less nasty (liked songs passthrough).
  • TODO: Logging in a nicer way as a report to make misses more obvious.
  • TODO: Mode selector at entrypoint.

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.