Created
June 16, 2013 20:30
-
-
Save bonhag/5793309 to your computer and use it in GitHub Desktop.
Shuffle your Turntable playlist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var shuffle = function() { | |
| var playlistLength = $('#playlist .song').length; | |
| for (var i = 1; i < playlistLength; i = i + 1) { | |
| setTimeout(function() { | |
| var s = Math.floor(Math.random() * playlistLength); | |
| console.log('moving song ' + s + ' to bottom'); | |
| $($('#playlist .song .playlist-open-options')[s]).click(); | |
| $('.move-bottom').click(); | |
| }, 500 * i); | |
| } | |
| } |
Author
Ok, so a little longer code-wise, but much faster... here's the problem though, it's very picky and I don't know why. Maybe you can check it out. If it doesn't work for you, try picking the playlist from the dropdown menu again. Paste this into Web Console and then call shufflePL();
function doreorder(plname,from,to,last){
var i={
api:"playlist.reorder",
playlist_name:plname,
index_from:from,
index_to:to
};
// function uqFjkH below seems to need queue editing to be locked
turntable.playlist.lockQueueEdits();
turntable.uqFjkH(i,function(){console.log('Moving from ' +from+ ' to ' +to); turntable.playlist.unlockQueueEdits()});
}
function shufflePL() {
var playlistname = this.playlist.activePlaylist;
var playlistlength = this.playlist.fileids.length;
// number of times we go through and shuffle
var iter = 2;
console.log('Shuffling your playlist ' +playlistname+ ' (' +playlistlength+ ' songs)');
for (var i = iter * playlistlength; i >= 0; i--)
{
var from = 0;
var to = 0;
while (from == 0)
from = Math.floor(Math.random() * playlistlength);
while (to == 0 || to == from)
to = Math.floor(Math.random() * playlistlength);
doreorder(playlistname, from, to, i);
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice, @benw54! Yeah, it definitely choked without setTimeout, so I was probably being a little conservative.
@LucasMadar I'm inclined to give the function a name for a couple of reasons