alaingilbert / Turntable-API

Allows you to create bots for turntable.fm
http://alaingilbert.github.com/Turntable-API/
MIT License
317 stars 97 forks source link

bot.snag() question #149

Closed samuri51 closed 11 years ago

samuri51 commented 11 years ago

does anyone know how to have bot.snag() gives the heart animation only when the song is not already in the bot's playlist? i notice itll give the snag animation but no new songs have been added, yes i know it doesn't add songs.

samuri51 commented 11 years ago

heres an example of what i'm currently trying


 if (upVotes >= howManyVotesToSnag)
    {
        bot.playlistAll(function (playlist)
        {
            bot.playlistAdd(songId, playlist.list.length, function (call)
            {
                if (call.success === true)
                {
                    bot.snag();
                }
            });
        });
    }
alaingilbert commented 11 years ago

Something like this could work :

var snagIfNotInPlaylist = function() {
  bot.playlistAll(function(data) {
    var found = false;
    for (var i = 0; i < data.list.length; i++) {
      if (data.list[i]._id == bot.currentSongId) {
        found = true;
        break;
      }
    }
    if (!found) {
      bot.snag();
    }
  });
};

It looks in your playlist. If it find the current song, it'll not snag it.

MikeWills commented 11 years ago

You may also want to check song name and artist. As there are some duplicates out there.

samuri51 commented 11 years ago

thanks, just tested it and it works :+1: