0

Spotify Apps API v1

Trying to determine if the song currently playing is from the playlist that was dropped into my app. However there seems to be two forms of a playlist uri.

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

I assume @ in the second form means 'current user'. Before I start making a uri comparison function that might be redundant, I thought I'd check to see if I'm missing something.

Thomas
  • 3,348
  • 4
  • 35
  • 49

1 Answers1

0

If you're allowing users to drop playlists into your application, they'll be of the first format. As you've noticed, there's no method in the API that does exactly what you're requesting, but you could do something like

var currentlyPlayingIsInPlaylist = function(playlistURI, callback) {
  models.player.load("track").done(function() {
    if (models.player.track) {
      var currentlyPlayingTrack = models.player.track;
      models.Playlist.fromURI(playlistURI).load("tracks").done(function(playlist) {
        playlist.tracks.snapshot().done(function(snapshot) {
          var matchingTrack = snapshot.find(currentlyPlayingTrack);
          if (matchingTrack) {
            callback(true);
          } else {
            callback(false);
          }
        });
      });
    } else {
      callback(null, { "message" : "No track is playing" });
    }
  });
}

Given that models is available in the function. Side note: Even if the currently playing track property was loaded on the Player, and the given playlist had its tracks property loaded, the function would still be asynchronous since it's getting the current snapshot.

Hope this helps!

Michael Thelin
  • 4,710
  • 3
  • 23
  • 29
  • Thanks. Format #1 comes from dragging from a playlist from within spotify to my app within spotify, though. At least on 0.9.4. But this could be because I'm using html drag/drop instead of the dropped event. – Thomas Oct 17 '13 at 13:36