Inspiration
The inspiration for this project came from us having to manually search for songs and add them to Spotify playlists. As people who frequently listen to music across both platforms, we wanted a quick solution to transfer our YouTube playlists to Spotify, where I could listen to them without interruptions. The concept was inspired by the growing demand for cross-platform music synchronization tools and the ease of automation provided by Python.
What it does
This project is designed to take a YouTube playlist URL, extract the song titles from the playlist, search for corresponding tracks on Spotify, and then create a new Spotify playlist with those songs.
How we built it
The script uses yt-dlp to extract video titles from a given YouTube playlist URL. It pulls up to 50 titles from the playlist. This tool allows us to get the title of each song without downloading the video. The titles are cleaned up to remove unnecessary text (for example: "official music video," "lyrics," "remix"). It then searches for the songs on Spotify using the cleaned-up titles. To interact with Spotify, we used the Spotipy library. After authenticating with the Spotify API, we were able to search for songs based on the YouTube title and add them to a newly created Spotify playlist. The script searches multiple variations of the song name (with and without the artist name) to find the best match for each YouTube song. To ensure the best match, we also used fuzzy matching (with the rapidfuzz library) to compare the song title and artist names from YouTube with those on Spotify. If a good match is found for a song, it adds it to a new Spotify playlist that it creates. It makes sure that no duplicates are added by using a set of track IDs. We also made sure that the program handles errors appropriately, like missing YouTube titles, no matching Spotify tracks, or API rate limits.
Challenges we ran into
One of the major challenges was that the song titles on YouTube and Spotify were often not exactly the same. For example, YouTube titles may include extra text like "official music video," "lyrics," or even additional details like "remix" or "live performance," which made it difficult to match songs accurately. This difference in song naming conventions meant that the script couldn’t easily find a match and resulted in songs being missed or not added to the playlist. Another challenge was that before this project, we didn’t have experience using fuzzy matching to compare strings, which is crucial when titles don’t match exactly. Once we learned how to use the rapidfuzz library, we were able to implement fuzzy string matching. This allowed us to compare YouTube song titles with Spotify’s, even when they had small variations in spelling, formatting, or additional words.
Accomplishments that we're proud of
We successfully created a system that extracts songs from a YouTube playlist and adds them to a Spotify playlist. Learning how to use fuzzy matching (via the rapidfuzz library) to compare song titles was a major accomplishment. Initially, the differences in how songs were titled on YouTube versus Spotify made it difficult to match them accurately. With fuzzy logic, we were able to overcome this challenge and significantly improved the accuracy of the song transfers, even when titles didn’t exactly match.
What we learned
We gained experience integrating the YouTube and Spotify APIs. We learned how to authenticate, make API calls, and handle the responses to gather song data and create playlists on Spotify. We learned to used RapidFuzz for fuzzy matching between YouTube and Spotify song titles to improve the accuracy of the song match. This project taught us how to handle edge cases, like non-exact matches between YouTube and Spotify titles, and how to deal with API rate limits and other exceptions.
What's next for Converting YouTube Playlist to Spotify Playlist
We plan to create a user-friendly web or desktop interface for the tool, where users can just input their YouTube playlist link, and the app handles everything from extracting the songs to creating the Spotify playlist. This would make the tool more accessible to non-technical users.
Log in or sign up for Devpost to join the conversation.