A simple script to add all songs from a YouTube playlist to a Spotify playlist.
- Faster: Uses YouTube API to get song info instead of Selenium.
- Convenient: No need to refresh token after every hour.
- Reliable: Adds 85-95% of the songs from popular YouTube playlists.
Works only for public YouTube playlists.
Added 142 songs to Spotify playlist out of 150 songs from YouTube playlist.
- Python 3.8 or higher
- pip (Python package installer)
- Spotify Developer Account
- YouTube API Key
-
Clone the repository:
git clone https://github.com/edgarh92/Youtube-to-Spotify-Archiver.git cd Youtube-to-Spotify-Archiver
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
Create a
.env
file in the root directory and add the following variables:SPOTIFY_USER_ID=your_user_id SPOTIFY_CLIENT_ID=your_spotify_client_id SPOTIFY_CLIENT_SECRET=your_spotify_client_secret SPOTIFY_REDIRECT_URI=http://localhost:8888/callback YOUTUBE_API_KEY=your_youtube_api_key
Note: Spotify user id can be obtained from the following Profile Link
-
Create an app: Spotify Developer Dashboard
-
Copy the Client ID and Client Secret:
-
Set redirect URI to
http://localhost:8888/callback
:
Click here to see how to create YouTube API key
-
Rename the file
.env.sample
to.env
-
Edit the file by adding your credentials
-
Run the following command to set your environment variable:
source .env
set SPOTIFY_USER_ID=<your_user_id>
set SPOTIFY_CLIENT_ID=<your_client_id>
set SPOTIFY_CLIENT_SECRET=<your_client_secret>
set SPOTIFY_REDIRECT_URI='http://localhost:8888/callback'
set YOUTUBE_API_KEY=<your_youtube_api_key>
python app/main.py --url "https://www.youtube.com/playlist?list=#######" --cookies "/path/to/youtube/cookies/file"
--url
,-u
: Link to Video or Song URL (required)-o
,--output
: Destination location of JSON files (default:~/Music/JSON
)--dryrun
: Do not add to Spotify.-playlist
,--playlist
: Save to specific Spotify Playlist (default: YouTube Playlist Name)--store_json
: Download JSON metadata of the video.--archive
,--a
: Location of archive reference file (default:~/Music/JSON/archive.log
)--cookies
: Path to cookies file (required)--loglevel
: Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
Logs are output to /tmp/youtube.log
.
Enter YouTube playlist ID: PLgzTt0k8mXzEpH7-dOCHqRZOsakqXmzmG
Enter a name for your Spotify playlist: youtube_chill_songs
The Chainsmokers - Takeaway was added to playlist.
KIRBY-Don't Leave Your Girl was not found!
Lauv - There's No Way was added to playlist.
...
Usher - Crash was added to playlist.
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License.