Hey I think it works for single videos CZTEROOKI DON'T PULL THIS I SWEAR TO GOD

This commit is contained in:
calzoneman 2013-07-02 15:01:12 -04:00
parent e3afacd415
commit c3b782b04a
2 changed files with 43 additions and 26 deletions

View file

@ -782,6 +782,7 @@ Channel.prototype.broadcastPlaylistMeta = function() {
var total = 0;
var iter = this.playlist.items.first;
while(iter !== null) {
if(iter.media !== null)
total += iter.media.seconds;
iter = iter.next;
}
@ -1225,29 +1226,23 @@ Channel.prototype.addMedia = function(data, user, callback) {
Channel.prototype.enqueueList = function(data, user) {
var pl = data.list;
var chan = this;
// Queue in reverse order for qnext
if(data.pos == "next") {
var i = pl.length;
var cback = function() {
i--;
if(i > 0) {
pl[i].pos = "next";
chan.enqueue(pl[i], user, cback);
}
}
this.enqueue(pl[0], user, cback);
this.playlist.addMediaList(data, function(err, item) {
if(err) {
if(err === true)
err = false;
if(user)
user.socket.emit("queueFail", err);
return;
}
else {
var i = 0;
var cback = function() {
i++;
if(i < pl.length) {
pl[i].pos = "end";
chan.enqueue(pl[i], user, cback);
}
}
this.enqueue(pl[i], user, cback);
chan.sendAll("queue", {
item: item.pack(),
after: item.prev ? item.prev.uid : "prepend"
});
chan.broadcastPlaylistMeta();
chan.cacheMedia(item.media);
}
});
}
Channel.prototype.tryQueuePlaylist = function(user, data) {

View file

@ -71,9 +71,13 @@ Playlist.prototype.queueAction = function(data) {
Playlist.prototype.dump = function() {
var arr = this.items.toArray();
var pos = arr.indexOf(this.current);
if(pos < 0)
pos = 0;
var pos = 0;
for(var i in arr) {
if(arr[i].uid == this.current.uid) {
pos = i;
break;
}
}
var time = 0;
if(this.current)
@ -133,6 +137,14 @@ Playlist.prototype.add = function(item, pos) {
}
Playlist.prototype.addMedia = function(data, callback) {
if(this.lock) {
this.queueAction({
fn: "addMedia",
args: arguments
});
return;
}
this.lock = true;
var pos = "append";
if(data.pos == "next") {
if(!this.current)
@ -145,6 +157,7 @@ Playlist.prototype.addMedia = function(data, callback) {
InfoGetter.getMedia(data.id, data.type, function(err, media) {
if(err) {
callback(err, null);
pl.lock = false;
return;
}
@ -155,10 +168,19 @@ Playlist.prototype.addMedia = function(data, callback) {
callback(true, null);
else
callback(false, it);
pl.lock = false;
});
}
Playlist.prototype.remove = function(uid, callback) {
if(this.lock) {
this.queueAction({
fn: "remove",
args: arguments
});
return;
}
this.lock = true;
var item = this.items.find(uid);
if(this.items.remove(uid)) {
if(item == this.current)
@ -166,6 +188,7 @@ Playlist.prototype.remove = function(uid, callback) {
if(callback)
callback();
}
this.lock = false;
}
Playlist.prototype.move = function(from, after, callback) {
@ -179,7 +202,6 @@ Playlist.prototype.move = function(from, after, callback) {
this.lock = true;
this._move(from, after, callback);
this.lock = false;
this.lock = false;
}
Playlist.prototype._move = function(from, after, callback) {