Fix playlist queue issues

This commit is contained in:
calzoneman 2013-06-19 23:08:57 -04:00
parent 6353638115
commit 4c38276f14
1 changed files with 36 additions and 7 deletions

View File

@ -1015,7 +1015,7 @@ Channel.prototype.autoTemp = function(media, user) {
} }
} }
Channel.prototype.enqueue = function(data, user) { Channel.prototype.enqueue = function(data, user, callback) {
var idx = data.pos == "next" ? this.position + 1 : this.queue.length; var idx = data.pos == "next" ? this.position + 1 : this.queue.length;
if(isLive(data.type) && !this.hasPermission(user, "playlistaddlive")) { if(isLive(data.type) && !this.hasPermission(user, "playlistaddlive")) {
@ -1030,6 +1030,8 @@ Channel.prototype.enqueue = function(data, user) {
this.autoTemp(media, user); this.autoTemp(media, user);
this.queueAdd(media, idx); this.queueAdd(media, idx);
this.logger.log("*** Queued from cache: id=" + data.id); this.logger.log("*** Queued from cache: id=" + data.id);
if(callback)
callback();
} }
else { else {
switch(data.type) { switch(data.type) {
@ -1049,6 +1051,8 @@ Channel.prototype.enqueue = function(data, user) {
this.cacheMedia(media); this.cacheMedia(media);
if(data.type == "yp") if(data.type == "yp")
idx++; idx++;
if(callback)
callback();
}.bind(this)); }.bind(this));
break; break;
case "li": case "li":
@ -1056,18 +1060,24 @@ Channel.prototype.enqueue = function(data, user) {
media.queueby = user ? user.name : ""; media.queueby = user ? user.name : "";
this.autoTemp(media, user); this.autoTemp(media, user);
this.queueAdd(media, idx); this.queueAdd(media, idx);
if(callback)
callback();
break; break;
case "tw": case "tw":
var media = new Media(data.id, "Twitch - " + data.id, "--:--", "tw"); var media = new Media(data.id, "Twitch - " + data.id, "--:--", "tw");
media.queueby = user ? user.name : ""; media.queueby = user ? user.name : "";
this.autoTemp(media, user); this.autoTemp(media, user);
this.queueAdd(media, idx); this.queueAdd(media, idx);
if(callback)
callback();
break; break;
case "jt": case "jt":
var media = new Media(data.id, "JustinTV - " + data.id, "--:--", "jt"); var media = new Media(data.id, "JustinTV - " + data.id, "--:--", "jt");
media.queueby = user ? user.name : ""; media.queueby = user ? user.name : "";
this.autoTemp(media, user); this.autoTemp(media, user);
this.queueAdd(media, idx); this.queueAdd(media, idx);
if(callback)
callback();
break; break;
case "us": case "us":
InfoGetter.getUstream(data.id, function(id) { InfoGetter.getUstream(data.id, function(id) {
@ -1075,6 +1085,8 @@ Channel.prototype.enqueue = function(data, user) {
media.queueby = user ? user.name : ""; media.queueby = user ? user.name : "";
this.autoTemp(media, user); this.autoTemp(media, user);
this.queueAdd(media, idx); this.queueAdd(media, idx);
if(callback)
callback();
}.bind(this)); }.bind(this));
break; break;
case "rt": case "rt":
@ -1082,18 +1094,24 @@ Channel.prototype.enqueue = function(data, user) {
media.queueby = user ? user.name : ""; media.queueby = user ? user.name : "";
this.autoTemp(media, user); this.autoTemp(media, user);
this.queueAdd(media, idx); this.queueAdd(media, idx);
if(callback)
callback();
break; break;
case "jw": case "jw":
var media = new Media(data.id, "JWPlayer Stream - " + data.id, "--:--", "jw"); var media = new Media(data.id, "JWPlayer Stream - " + data.id, "--:--", "jw");
media.queueby = user ? user.name : ""; media.queueby = user ? user.name : "";
this.autoTemp(media, user); this.autoTemp(media, user);
this.queueAdd(media, idx); this.queueAdd(media, idx);
if(callback)
callback();
break; break;
case "im": case "im":
var media = new Media(data.id, "Imgur Album", "--:--", "im"); var media = new Media(data.id, "Imgur Album", "--:--", "im");
media.queueby = user ? user.name : ""; media.queueby = user ? user.name : "";
this.autoTemp(media, user); this.autoTemp(media, user);
this.queueAdd(media, idx); this.queueAdd(media, idx);
if(callback)
callback();
break; break;
default: default:
break; break;
@ -1140,19 +1158,30 @@ Channel.prototype.tryQueuePlaylist = function(user, data) {
} }
var pl = Database.loadUserPlaylist(user.name, data.name); var pl = Database.loadUserPlaylist(user.name, data.name);
var chan = this;
// Queue in reverse order for qnext // Queue in reverse order for qnext
if(data.pos == "next") { if(data.pos == "next") {
for(var i = pl.length - 1; i >= 0; i--) { var i = pl.length;
var cback = function() {
i--;
if(i > 0) {
pl[i].pos = "next"; pl[i].pos = "next";
this.enqueue(pl[i], user); chan.enqueue(pl[i], user, cback);
} }
} }
this.enqueue(pl[0], user, cback);
}
else { else {
for(var i = 0; i < pl.length; i++) { var i = 0;
var cback = function() {
i++;
if(i < pl.length) {
pl[i].pos = "end"; pl[i].pos = "end";
this.enqueue(pl[i], user); chan.enqueue(pl[i], user, cback);
} }
} }
this.enqueue(pl[i], user, cback);
}
} }
Channel.prototype.setTemp = function(idx, temp) { Channel.prototype.setTemp = function(idx, temp) {