Skip to content
Snippets Groups Projects
Commit e2e0cbc3 authored by ale's avatar ale
Browse files

make random work

parent 5905b382
Branches
No related tags found
No related merge requests found
...@@ -199,13 +199,14 @@ djr.Backend.prototype.lastPlaylist = function(num, callback ,ctx) { ...@@ -199,13 +199,14 @@ djr.Backend.prototype.lastPlaylist = function(num, callback ,ctx) {
}; };
/** /**
* Request N most played songs * Return N pseudo-random songs based on the current playlist.
* *
* @param {integer} n Number of songs requested * @param {integer} n Number of songs requested
* @param {Array[string]} uuids SHA1 hashes of the current playlist
* *
*/ */
djr.Backend.prototype.randomPlaylist = function(num, uuids, callback ,ctx) { djr.Backend.prototype.markovPlaylist = function(num, uuids, callback ,ctx) {
$.ajax({url: '/json/random', $.ajax({url: '/json/markov',
data: {'h': uuids.join(','), data: {'h': uuids.join(','),
'n': num }, 'n': num },
dataType: 'json', dataType: 'json',
...@@ -217,3 +218,21 @@ djr.Backend.prototype.randomPlaylist = function(num, uuids, callback ,ctx) { ...@@ -217,3 +218,21 @@ djr.Backend.prototype.randomPlaylist = function(num, uuids, callback ,ctx) {
}); });
}; };
/**
* Return N completely random songs.
*
* @param {integer} n Number of songs requested
*
*/
djr.Backend.prototype.randomPlaylist = function(num, callback ,ctx) {
$.ajax({url: '/json/random',
data: {'n': num },
dataType: 'json',
type: 'GET',
context: ctx || this,
success: function(data, status, jqxhr) {
callback(data.results);
}
});
};
...@@ -118,8 +118,8 @@ djr.Player.prototype.lastPlaylist = function(num) { ...@@ -118,8 +118,8 @@ djr.Player.prototype.lastPlaylist = function(num) {
djr.Player.prototype.randomPlaylist = function(num) { djr.Player.prototype.randomPlaylist = function(num) {
var player = this; var player = this;
var title = "Last " + num + " Random Songs "; var title = "" + num + " Random Songs ";
this.backend.randomPlaylist(num, this.playlist.allSongs(), function(results) { this.backend.randomPlaylist(num, function(results) {
var songs = results; var songs = results;
if (songs.length == 0) { if (songs.length == 0) {
djr.debug('No results found.'); djr.debug('No results found.');
...@@ -133,7 +133,7 @@ djr.Player.prototype.randomPlaylist = function(num) { ...@@ -133,7 +133,7 @@ djr.Player.prototype.randomPlaylist = function(num) {
djr.Player.prototype.mostPlayedPlaylist = function(num) { djr.Player.prototype.mostPlayedPlaylist = function(num) {
var player = this; var player = this;
var title = "Most " + num + " Played Songs"; var title = "" + num + " Most Played Songs";
this.backend.mostPlayedPlaylist(num, function(results) { this.backend.mostPlayedPlaylist(num, function(results) {
var songs = []; var songs = [];
$.each(results, function(idx, item) { $.each(results, function(idx, item) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment