A Python system that converts Spotify song links to YouTube video links.
- Extracts track information from Spotify URLs (open.spotify.com, spotify: URIs)
- Searches YouTube for matching videos
- Returns the most relevant YouTube video URL
- Comprehensive test suite included
pip install requestsfrom spotify_to_youtube import convert_spotify_to_youtube
spotify_url = "https://open.spotify.com/track/3n3Ppam7vgaVa1iaRUc9Lp"
youtube_url = convert_spotify_to_youtube(spotify_url)
if youtube_url:
print(f"YouTube URL: {youtube_url}")
else:
print("Conversion failed")python spotify_to_youtube.pyThen enter your Spotify track URL when prompted.
from spotify_to_youtube import SpotifyToYouTubeConverter
converter = SpotifyToYouTubeConverter()
result = converter.convert("https://open.spotify.com/track/3n3Ppam7vgaVa1iaRUc9Lp")
print(result) # https://www.youtube.com/watch?v=...https://open.spotify.com/track/{id}https://play.spotify.com/track/{id}spotify:track:{id}
python -m unittest test_spotify_to_youtube -v- Extract Track ID: Parses the Spotify URL to extract the track ID
- Get Track Info: Uses Spotify's oEmbed API or page scraping to get artist and title
- Search YouTube: Searches YouTube for the song using the artist and title
- Return Result: Returns the first matching YouTube video URL
- Requires internet connection
- May not work if Spotify or YouTube changes their API/page structure
- Search results depend on YouTube's search algorithm
MIT License