I recently decided to take my Windows Media Player (WMP) playlist full of my favorite MP3s and add them to Spotify. The WMP playlist was an auto playlist based on the star rating of the mp3 files. Any files with a rating of ‘4 stars or higher’ would be automatically added to this playlist. Now, how to get that into Spotify?
Well, WMP allows me to export a Winamp-style playlist with an M3U extension. There are a bunch of sites that allow you to take this M3U and automatically generate a list of Spotify track URIs (looking a bit like
spotify:track:340597345) which I could drag and drop into Spotify. The problem with these sites, though, is that they can only parse the M3U for relevant song information. The site has no access to the ID3 tags within your MP3 files. This means the filename of all your MP3s needs to contain correct artist and title information. Additionally, since the site cannot determine the length of the MP3, it may retrieve album or remix versions of the song, where you originally had the single version.
So, I whipped up a quick C# application that uses the Spotify Web API to generate a list of track URIs. It does the following:
- It opens a file called playlist.m3u in the current folder.
- It uses TagLib# to extract title information from the ID3 tag in the MP3. If it cannot determine the Title from there, it will look at the filename (using the convention that the files are called Artist - SongTitle.mp3.
- It then extracts the Performer from the MP3. If that is empty, it looks at the Album Artist. If that is not found either, it again tries to just parse the filename.
- Any files that cannot be identified are shown in the console.
- For every file found, it uses the Spotify API and Json.NET to do a Track search.
- Since the API may return a large amount of results, it then tries to find the best matching song by finding the song with the artist that has the shortest Levenshtein distance to the artist we seek.
- This list is then additionally ordered by length, so that the track that most closely matches the length of your MP3 is selected.
- An output.txt is generated containing a list of Spotify URIs. If you open this file in a web browser, select all the text, and then drag and drop this into a Spotify playlist, your files should show up!
- Files that could not be found on Spotify are listed in the console and added to invalid.txt.
It works pretty well, although you still end up with some sound-alike versions and so on. Maybe they need to be filtered out by looking for certain keywords (
in the style,
You can find the executable here. It needs the .NET 4.5 runtime and will probably break in a lot of scenarios, since it was basically only designed to run once on my PC :). The code is available here.
I hope it’s useful to someone!