Advertisement
jille_Jr

[Dubtrack] [Compressed] Search in playlists

Feb 25th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. !function(){if(void 0==Dubtrack.user.playlist)return void alert("Please open the playlists at least once!");var e=window.prompt("Enter your search terms","needle");if(void 0==e||0==e.length)return void alert("Invalid search terms.");var t=e.toLowerCase().split(/[^a-zA-Z0-9]/),n=[],r=0;fetch=function(e,t,n){var a="https://api.dubtrack.fm/playlist/"+t._id+"/songs";r++,"function"==typeof console.time&&console.time("[fetch] "+e),$.getJSON(a,function(a,o){r--;var s,c,i;"function"==typeof console.timeEnd&&console.timeEnd("[fetch] "+e),"success"!==o||200!==a.code?(s=a,c=s.code,i=s.message,a=s.data,errorHandler("Error #"+c+" fetching "+e+": "+i+". "+a.message+".")):n(t,a.data)})},search=function(e){if(void 0==e)return!1;for(var n=0;n<t.length;n++)if(-1==e.toLowerCase().indexOf(t[n]))return!1;return!0},writeout=function(){var t="";if(0==n.length)t='Found no matches on searching "'+e+'"! :(';else{t="Found "+n.length+" matches!\n\n";for(var r=0;r<n.length;r++){var a=n[r];t+="["+a.playlist+"] "+a.name+"\n"}}alert(t)},callback=function(e,t){try{for(var a=0;a<t.length;a++){var o=t[a]._song;(search(o.name)||search(o.description)||search(o.genre)||search(o.songArtist))&&(o.playlist=e.name,n.push(o))}}catch(s){console.log("couldn't parse song data ("+s+")")}0==r&&writeout()},Dubtrack.user.playlist.forEach(function(e,t){var n=e.attributes;fetch("songs ("+n.name+")",n,callback)})}();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement