Migrate youtube playlists and user playlists, comma lists sometimes break still

This commit is contained in:
calzoneman 2013-09-29 22:32:37 -05:00
parent a371ca6440
commit 2fc8349daf
2 changed files with 60 additions and 212 deletions

View File

@ -1315,7 +1315,7 @@ Channel.prototype.tryQueue = function(user, data) {
return;
}
if(data.pos == "next" && !this.hasPermission(user, "playlistnext")) {
if (data.pos === "next" && !this.hasPermission(user, "playlistnext")) {
return;
}
@ -1336,17 +1336,21 @@ Channel.prototype.tryQueue = function(user, data) {
return;
}
if(typeof data.title !== "string")
if (typeof data.title !== "string" || data.type !== "cu")
data.title = false;
data.queueby = user ? user.name : "";
data.temp = !this.hasPermission(user, "addnontemp");
if(data.list)
this.addMediaList(data, user);
else
if (data.list) {
for (var i = 0; i < data.list.length; i++) {
data.list[i].pos = data.pos;
this.tryQueue(user, data.list[i]);
}
} else {
this.addMedia(data, user);
}
}
Channel.prototype.addMedia = function(data, user) {
var self = this;
@ -1396,6 +1400,7 @@ Channel.prototype.addMedia = function(data, user) {
m.temp = data.temp;
var res = self.playlist.addMedia(m);
if (res.error) {
console.log(res);
user.socket.emit("queueFail", res.error);
q.release();
return;
@ -1414,6 +1419,36 @@ Channel.prototype.addMedia = function(data, user) {
q.release();
};
// special case for youtube playlists
if (data.type === "yp") {
self.plqueue.queue(function (q) {
if (self.dead)
return;
self.server.infogetter.getMedia(data.id, data.type,
function (e, vids) {
if (e) {
user.socket.emit("queueFail", e);
q.release();
return;
}
if (data.pos === "next") {
vids.reverse();
if (self.playlist.length === 0)
vids.unshift(vids.pop());
}
var fake = { release: function () { } };
var cb = afterData.bind(self, fake, false);
for (var i = 0; i < vids.length; i++) {
cb(vids[i]);
}
q.release();
});
});
return;
}
// Don't check library for livestreams or if the channel is
// unregistered
if (!self.registered || isLive(data.type)) {
@ -1476,44 +1511,16 @@ Channel.prototype.addMedia = function(data, user) {
}
});
}
}
Channel.prototype.addMediaList = function(data, user) {
var chan = this;
this.playlist.addMediaList(data, function(err, item) {
if (chan.dead)
return;
if(err) {
if(err === true)
err = false;
if(user)
user.socket.emit("queueFail", err);
return;
}
else {
chan.logger.log("### " + user.name + " queued " + item.media.title);
item.temp = data.temp;
item.queueby = data.queueby;
chan.sendAll("queue", {
item: item.pack(),
after: item.prev ? item.prev.uid : "prepend"
});
chan.broadcastPlaylistMeta();
if(!item.temp)
chan.cacheMedia(item.media);
}
});
}
};
Channel.prototype.tryQueuePlaylist = function(user, data) {
var self = this;
if(!this.hasPermission(user, "playlistaddlist")) {
if (!self.hasPermission(user, "playlistaddlist")) {
return;
}
if(typeof data.name != "string" ||
typeof data.pos != "string") {
if(typeof data.name !== "string" ||
typeof data.pos !== "string") {
return;
}
@ -1532,10 +1539,18 @@ Channel.prototype.tryQueuePlaylist = function(user, data) {
});
return;
}
data.list = pl;
data.queueby = user.name;
data.temp = !self.hasPermission(user, "addnontemp");
self.addMediaList(data, user);
if (data.pos === "next") {
pl.reverse();
if (self.playlist.items.length === 0)
pl.unshift(pl.pop());
}
for (var i = 0; i < pl.length; i++) {
pl[i].pos = data.pos;
pl[i].temp = !self.hasPermission(user, "addnontemp");
self.addMedia(pl[i], user);
}
});
}

View File

@ -230,7 +230,7 @@ Playlist.prototype.addMedia = function (data) {
if (this.current !== null)
pos = this.current.uid;
else
pos = "append"
pos = "append";
}
var m = new Media(data.id, data.title, data.seconds, data.type);
@ -239,177 +239,10 @@ Playlist.prototype.addMedia = function (data) {
item.temp = data.temp;
return {
item: item,
error: this.add(item, data.pos)
error: this.add(item, pos)
};
};
Playlist.prototype.addCachedMedia = function(data, callback) {
var pos = "append";
if(data.pos == "next") {
if(!this.current)
pos = "prepend";
else
pos = this.current.uid;
}
var it = this.makeItem(data.media);
it.temp = data.temp;
it.queueby = data.queueby;
var pl = this;
var action = {
fn: function() {
var err = pl.add(it, pos);
callback(err, err ? null : it);
},
waiting: false
};
this.queueAction(action);
}
Playlist.prototype.__addMedia = function (data, cb) {
var self = this;
if (data.type === "yp") {
this.addYouTubePlaylist(data, cb);
return;
}
this.fnqueue.queue(function (q) {
var afterData = function (m) {
if (data.maxlength && data.seconds > m.maxlength) {
setImmediate(function () {
cb("Media is too long!", null);
});
q.release();
return;
}
var it = self.makeItem(m);
it.queueby = data.queueby;
it.temp = data.temp;
var pos = "append";
if(data.pos == "next") {
if (!self.current)
pos = "prepend";
else
pos = self.current.uid;
}
var err = self.add(it, pos);
setImmediate(function () {
cb(err, err ? null : it);
});
q.release();
};
if (typeof data.title === "string") {
afterData(new Media(data.id, data.title, data.seconds, data.type));
} else {
self.server.infogetter.getMedia(data.id, data.type,
function (e, m) {
if (e) {
setImmediate(function () { cb(e, null); });
q.release();
return;
}
afterData(m);
});
}
});
};
Playlist.prototype._addMedia = function(data, callback) {
if(data.type == "yp") {
this.addYouTubePlaylist(data, callback);
return;
}
var pos = "append";
if(data.pos == "next") {
if(!this.current)
pos = "prepend";
else
pos = this.current.uid;
}
var it = this.makeItem(null);
var pl = this;
var action = {
fn: function() {
var err = pl.add(it, pos);
callback(err, err ? null : it);
},
waiting: true
};
this.queueAction(action);
// Pre-cached data
if(typeof data.title === "string" &&
typeof data.seconds === "number") {
if(data.maxlength && data.seconds > data.maxlength) {
action.expire = 0;
callback("Media is too long!", null);
return;
}
it.media = new Media(data.id, data.title, data.seconds, data.type);
action.waiting = false;
return;
}
this.server.infogetter.getMedia(data.id, data.type, function(err, media) {
if(err) {
action.expire = 0;
callback(err, null);
return;
}
if(data.maxlength && media.seconds > data.maxlength) {
action.expire = 0;
callback("Media is too long!", null);
return;
}
it.media = media;
it.temp = data.temp;
it.queueby = data.queueby;
action.waiting = false;
});
}
Playlist.prototype.addMediaList = function(data, callback) {
var start = false;
if(data.pos == "next") {
data.list = data.list.reverse();
start = data.list[data.list.length - 1];
}
if(this.items.length != 0)
start = false;
var pl = this;
for(var i = 0; i < data.list.length; i++) {
var x = data.list[i];
x.pos = data.pos;
if(start && x == start) {
pl.addMedia(x, function (err, item) {
if(err) {
callback(err, item);
}
else {
callback(err, item);
pl.current = item;
pl.startPlayback();
}
});
}
else {
pl.addMedia(x, callback);
}
}
}
Playlist.prototype.addYouTubePlaylist = function(data, callback) {
var pos = "append";
if(data.pos == "next") {