This Python script transfers your liked videos from YouTube to Spotify by adding the songs to your Spotify liked songs or a new playlist based on your choice.
- OAuth 2.0 Authentication: Secure authentication with both YouTube Data API and Spotify Web API
- Complete Video Retrieval: Fetches all liked videos from your YouTube account
- Smart Song Detection: Extracts song and artist information from video titles using advanced regex patterns
- Intelligent Spotify Search: Uses multiple search query formats to maximize track matching accuracy
- User Choice: Choose between adding songs to your liked songs or creating a custom playlist
- Batch Processing: Efficiently handles large numbers of songs with API-compliant batch operations
- Comprehensive Reporting: Detailed progress updates and final transfer summary
- Error Handling: Robust error handling for API rate limits and network issues
- Python 3.7 or higher
- Google Cloud project with YouTube Data API enabled
- Spotify Developer account with an app created
- Active internet connection for API calls
- Navigate to the Google Cloud Console
- Click on the project dropdown at the top of the page
- Click "New Project"
- Enter a project name (e.g., "YouTube to Spotify Transfer")
- Click "Create"
- In your project dashboard, go to "APIs & Services" β "Library"
- Search for "YouTube Data API v3"
- Click on it and press "Enable"
- Go to "APIs & Services" β "OAuth consent screen"
- Choose "External" user type
- Fill in the required information:
- App name: "YouTube to Spotify Transfer"
- User support email: Your email address
- Developer contact information: Your email address
- Click "Save and Continue"
- On the "Scopes" page, click "Save and Continue" (no additional scopes needed)
- On the "Test users" page:
- Click "Add users"
- Enter your email address
- Click "Save and Continue"
- Go to "APIs & Services" β "Credentials"
- Click "Create Credentials" β "OAuth client ID"
- Choose "Desktop application"
- Enter a name (e.g., "YouTube to Spotify Desktop App")
- Click "Create"
- Download the JSON file and save it as
youtube_client_secrets.json
in your project directory
- Go to the Spotify Developer Dashboard
- Log in with your Spotify account
- Click "Create an App"
- Fill in the details:
- App name: "YouTube to Spotify Transfer"
- App description: "Transfer liked videos from YouTube to Spotify"
- Check the boxes for terms of service
- Click "Create"
- In your newly created app, click "Settings"
- In the "Redirect URIs" section:
- Click "Edit"
- Add:
http://127.0.0.1:8080
- Click "Add"
- Click "Save"
- Copy your Client ID and Client Secret (you'll need these for the script)
pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client spotipy requests
- Open the Python script in your preferred editor
- Update the following variables in the
main()
function:
YOUTUBE_CLIENT_SECRETS_FILE = "youtube_client_secrets.json" # Path to your downloaded JSON file
SPOTIFY_CLIENT_ID = "your_actual_spotify_client_id" # Replace with your Spotify Client ID
SPOTIFY_CLIENT_SECRET = "your_actual_spotify_client_secret" # Replace with your Spotify Client Secret
SPOTIFY_REDIRECT_URI = "http://127.0.0.1:8080" # Keep this as is
- YouTube Authentication: Opens a browser window for Google OAuth 2.0 login
- Spotify Authentication: Opens a browser window for Spotify OAuth 2.0 login
- Token Management: Automatically handles access tokens and refresh tokens
- Fetch Liked Videos: Retrieves all videos from your YouTube "Liked Videos" playlist
- Song Extraction: Analyzes video titles using multiple regex patterns:
Artist - Song
Artist: Song
Artist "Song"
Song by Artist
- Spotify Search: Uses multiple search strategies for better matching:
- Exact track and artist search
- Quoted search terms
- General keyword search
- Track-specific and artist-specific searches
- Choice Prompt: After processing, you choose between:
- Adding songs to your Spotify liked songs
- Creating a new playlist with a custom name
- Batch Processing: Songs are added in optimal batch sizes (50 for liked songs, 100 for playlists)
- Total videos processed
- Successfully matched songs
- Failed matches with reasons
- Overall success rate percentage
- Run the script:
python youtube_to_spotify.py
- Follow the authentication prompts:
- Browser windows will open for YouTube and Spotify login
- Grant the requested permissions
- Wait for processing:
- The script will fetch and analyze your liked videos
- Progress updates will be displayed in real-time
- Make your choice:
- Choose option 1 to add songs to your liked songs
- Choose option 2 to create a new playlist and enter a name
- Review the summary:
- Check the final report for successful transfers and any issues
- API Quotas: YouTube Data API has daily quotas; the script handles rate limiting automatically
- Playlist Privacy: Created playlists are set to private by default
- Test User Requirement: You must add your email as a test user in Google Cloud Console if the app is in testing mode
- Redirect URI: The redirect URI must exactly match between your script and Spotify app settings
- Song Matching: Not all YouTube videos can be matched to Spotify tracks due to:
- Different song titles or artist names
- Songs not available on Spotify
- Videos that aren't actually music
- Solution: Add your email address as a test user in Google Cloud Console OAuth consent screen
- Solution: Ensure the redirect URI in Spotify Developer Dashboard is exactly
http://127.0.0.1:8080
- Solution: Make sure the
youtube_client_secrets.json
file is in the same directory as your script
- Solution: Replace the placeholder values with your actual Spotify Client ID and Client Secret
- Possible causes:
- Many non-music videos in your liked videos
- Songs with unusual titles or formatting
- Regional availability differences between YouTube and Spotify
To see more detailed error messages, you can modify the script to include more verbose logging.
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
For issues, questions, or feature requests:
- Create an issue on the GitHub repository
- Check the troubleshooting section above
- Ensure all setup steps have been completed correctly
- Data Handling: The script only accesses your liked videos list and does not store any personal data
- Credentials: Your API credentials are used only for authentication and are not transmitted anywhere except to Google and Spotify
- Permissions: The script requests minimal necessary permissions for YouTube (read-only) and Spotify (playlist modification)