0

I've found related questions (like this one), but nothing that directly answers my question: I need a direct way to turn artist name and track name into a spotify link. Just like spotify does for the local file list (some are links, some are not, I assume because spotify doesn't have those tracks.

How can I turn something like artist:'Francolin' and track name:'Hospital Song' into a Spotify uri without searching for it (which will return multiple results, and I don't know which one to use). How does the Spotify local files list do it?

Community
  • 1
  • 1
cofiem
  • 1,384
  • 1
  • 17
  • 29

2 Answers2

1

The local files list in the Spotify client makes URLs like this:

spotify:local:Coldplay:Mylo+Xyloto:Paradise:277 (spotify:local:ARTIST:ALBUM:TRACK:LENGTH_IN_SECONDS). You can verify this by right-clicking a local file in your list that hasn't been linked to a Spotify track and choosing "Copy Spotify URI".

When playing the track, the client resolves it without using the backend at all - it searches its own local list of known files and plays whichever matches it closest.

When linking to a "real" Spotify track, the client asks the backend to do the dirty work. There isn't a web API for this (it's in libSpotify though), but basically the backend does a few heuristics to the data* then chooses the track that matches the given data (including length) the closest.

*Basically, the track metadata is stripped to a simpler form when searching, and the album has less weighting since an artist may release the same track on multiple albums.

iKenndac
  • 18,730
  • 3
  • 35
  • 51
  • I've tried creating links as local files, and it seems to work ok, but what about the white-vs-grey colour for tracks that spotify has and those that it doesn't? – cofiem Aug 19 '12 at 11:34
0

I ran into the same problem as you but I don't think there's a direct way to convert it. Instead I just run for a search with "artist:'$artist' title:'$title'", which should be very accurate, and just use the first result in the array of results.

riggspc
  • 612
  • 3
  • 7
  • 15
  • I'm starting to think this is the only real way to do it - but that means I'll be making an api call for each link. That seems like overkill? – cofiem Aug 19 '12 at 11:36
  • That's exactly what I thought too and the guidelines strongly discourage that amount of searches. However, it's been working really well for me in my app. So, until there's some sort of way to convert titles to URIs then this seems like the best alternative – riggspc Aug 19 '12 at 18:41