How to match different Spotify URI formats

I’m working with the Spotify Apps API and running into an issue with URI formats. I need to check if the currently playing track belongs to a specific playlist that was added to my application.

The problem is that I’m seeing two different URI formats for the same playlist:

  1. http://open.spotify.com/user/[username]/playlist/[playlist_id]
  2. spotify:user:@:playlist:[playlist_id]

I think the @ symbol in the second format represents the current user, but I’m not completely sure. Should I create a custom function to normalize these URIs before comparing them, or is there a built-in way to handle this? I want to make sure I’m not reinventing the wheel here.

Had this exact problem a few months ago while building a playlist analyzer. Yeah, the @ symbol is the current user in the newer URI format. I just used a simple regex to extract the playlist ID from both formats - that’s all you really need for comparison anyway. The playlist ID stays the same in both formats, so you can match playlists no matter what the API throws at you. Just heads up - the API’s inconsistent and might give you the old http format sometimes and the newer spotify protocol other times.

yeah, the uri thing’s annoying lol. i just split on colons and grab the last part - that’s your playlist id. works for both formats without dealing with regex.

Yeah, Spotify’s API is inconsistent like that - ran into the same thing building a music app last year. I’d make a utility function that checks the URI format first, then grabs the playlist ID. For HTTP URLs, split on forward slashes and take the last part. For spotify: URIs, split on colons and grab the end. Also cache those normalized IDs so you’re not parsing them over and over, especially with big playlists. Trust me, the performance hit adds up fast.

totally get it! that @ symbol has tripped me up too. i just made a lil function to strip the playlist_id from both formats - way less messy than those long links. def saves time!

You’re spot on about the @ symbol being the current user in Spotify’s protocol format. There’s no built-in method to handle this inconsistency, so I wrote a simple parser that just extracts the playlist ID from both formats for comparisons. The playlist ID stays the same across both URI formats, so once you’ve got that, matching is easy. I’d store the normalized format internally in your app - saves you from converting every time you need to compare. The API docs don’t cover this inconsistency well, but it’s common enough that most of us end up rolling our own solution.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.