The podcast “Uhh Yeah Dude” has interesting musical intros and outros, I wanted to have all these songs in a Spotify playlist. A fan of the show had maintained such a playlist until 2016, but more recent picks were missing. What to do?

Getting and transforming the data

The first step was scraping the UYD website to build a list of episodes–not too difficult! The code for this is kind of boring, but it’s on GitHub if you’re interested.

An episode of UYD:

{
  "date": "October 2nd 2010",
  "number": "Episode 238",
  "linkToNotes": "https://uhhyeahdude.com/index.php/show_notes/episode_238",
  "intro": "Collage // The Three Degrees",
  "outro": "John Cale and Terry Riley"
 },
 ...

The next step was transforming the list of episodes to a list of songs.

{ "title": "Collage", "artist": "The Three Degrees" },
{
  "title": "The Worst Band In The World",
  "artist": "10cc",
  "album": "Sheet Music"
},
...

Authenticating with the Spotify API

This would have been a lot more frustrating if I had not found Ari V’s implicit grant template.

Songs to URIs

Accomplishing this required writing some JS: songs-to-uris.

Spotify’s Web API can add songs to a playlist, but the method in question requires “track URIs”. So somehow, the list of songs must be converted to a list of URIs. The search api can be used to locate songs in Spotify’s catalogue, but the api returns a lot of unrelated songs. There does not seem to be any way of narrowing a search to a particular artist, culling unrelated results must be done manually.

Finding URIs for songs is the messiest part of all this. There are a number of reasons songs may end up missing:

  • Spotify does not have the song.
  • The song has a slightly different title or artist (I only considered exact matches).
  • The song has multiple artists (I didn’t bother handling this).

It is also possible for false positives to sneak in (although this is not so likely due to the strict matching).

It didn’t work all that well, to be honest. Of the 600 songs fed into it, only about 250 URIs came out.

Adding songs to a playlist

More JS: uris-to-playlist.

If you have a list of URIs, this is simple. The only complication is that the add track api method only allows 100 songs to be added per call.

Minimum polish

The previously linked tools worked for me, but they are not polished.

Improvements that could be made:

  • An “authenticate” button. Current behaviour is to auto-redirect if a token is unavailable. This looks super sketchy as the user hasn’t even seen the app they’re being asked to give permissions to. It would be better to show users the app and have a button they could click to authenticate if they want to use it.
  • Improved matching of songs to URI. There are several deficits with the current script (mentioned above). Potential improvements: fuzzy matching, support for multiple artists, interactive selection if there are multiple candidate matches.
  • Playlist selection. Currently users must get the playlist URI from a Spotify client and paste it into an input. It would be nice to retrieve the users list of playlists and allow them to select the destination playlist from that list.
  • Smarter rate-limiting. The current scripts impose a hardcoded, additive delay of 500 ms to each request. Spotify is nice enough to return a retry-after header with a 402 response if the rate is exceeded; this header includes a time (in seconds) to wait until retrying the request. The scripts could be modified to use this.

Seatbelts…

For what it’s worth, the playlist is here and the data is here.