Getting there

This commit is contained in:
calzoneman 2013-07-03 11:26:10 -04:00
parent fc5034d26a
commit f6b02a166a
4 changed files with 134 additions and 41 deletions

View file

@ -326,7 +326,7 @@ exports.getMedia = function(id, type, callback) {
}
try {
var vids = [];
for(var i = 0; i < data.feed.entry.length; i++) {
try {
var item = data.feed.entry[i];
@ -335,13 +335,15 @@ exports.getMedia = function(id, type, callback) {
var title = item.title.$t;
var seconds = item.media$group.yt$duration.seconds;
var media = new Media(id, title, seconds, "yt");
callback(false, media);
vids.push(media);
}
catch(e) {
Logger.errlog.log("getMedia failed: ");
Logger.errlog.log(e);
}
}
callback(false, vids);
var links = data.feed.link;
for(var i = 0; i < links.length; i++) {
@ -357,6 +359,7 @@ exports.getMedia = function(id, type, callback) {
}
}
exports.getYTPlaylist(id, cback);
break;
case "li":
case "tw":
case "jt":

View file

@ -68,7 +68,6 @@ Playlist.prototype.queueAction = function(data) {
pl.alter_queue.unshift(data);
return;
}
//pl[data.fn].apply(pl, data.args);
data.fn();
if(pl.alter_queue.length == 0) {
clearInterval(pl._qaInterval);
@ -154,6 +153,12 @@ Playlist.prototype.add = function(item, pos) {
}
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)
@ -198,6 +203,37 @@ Playlist.prototype.addMediaList = function(data, callback) {
});
}
Playlist.prototype.addYouTubePlaylist = function(data, callback) {
var pos = "append";
if(data.pos == "next") {
if(!this.current)
pos = "prepend";
else
pos = this.current.uid;
}
var pl = this;
InfoGetter.getMedia(data.id, data.type, function(err, vids) {
console.log(vids.length);
if(err) {
callback(err, null);
return;
}
vids.forEach(function(media) {
var it = pl.makeItem(media);
it.temp = data.temp;
it.queueby = data.queueby;
pl.queueAction({
fn: function() {
if(pl.add(it, pos))
callback(false, it);
},
});
});
});
}
Playlist.prototype.remove = function(uid, callback) {
var pl = this;
this.queueAction({

View file

@ -649,28 +649,35 @@ Callbacks = {
},
queue: function(data) {
var li = makeQueueEntry(data.item, true);
li.hide();
var q = $("#queue");
li.attr("title", data.item.queueby
? ("Added by: " + data.item.queueby)
: "Added by: Unknown");
if(data.after === "prepend") {
li.prependTo(q);
li.show("blind");
return;
}
else if(data.after === "append") {
li.appendTo(q);
li.show("blind");
}
else {
var liafter = $(".pluid-" + data.after);
if(liafter.length == 0)
return false;
li.insertAfter(liafter);
li.show("blind");
}
queueAction({
fn: function () {
var li = makeQueueEntry(data.item, true);
li.hide();
var q = $("#queue");
li.attr("title", data.item.queueby
? ("Added by: " + data.item.queueby)
: "Added by: Unknown");
if(data.after === "prepend") {
li.prependTo(q);
li.show("blind");
return true;
}
else if(data.after === "append") {
li.appendTo(q);
li.show("blind");
return true;
}
else {
var liafter = playlistFind(data.after);
if(!liafter) {
return false;
}
li.insertAfter(liafter);
li.show("blind");
return true;
}
}
});
},
queueFail: function(data) {
@ -707,30 +714,43 @@ Callbacks = {
},
"delete": function(data) {
var li = $(".pluid-" + data.uid);
li.hide("blind", function() {
li.remove();
queueAction({
fn: function () {
var li = $(".pluid-" + data.uid);
li.hide("blind", function() {
li.remove();
});
}
});
},
moveVideo: function(data) {
if(data.moveby != CLIENT.name)
playlistMove(data.from, data.after);
if(data.moveby != CLIENT.name) {
queueAction({
fn: function () {
playlistMove(data.from, data.after);
}
});
}
},
setCurrent: function(uid) {
PL_CURRENT = uid;
var qli = $("#queue li");
qli.removeClass("queue_active");
var li = $(".pluid-" + uid);
if(li.length == 0) {
return false;
}
queueAction({
fn: function () {
PL_CURRENT = uid;
var qli = $("#queue li");
qli.removeClass("queue_active");
var li = $(".pluid-" + uid);
if(li.length == 0) {
return false;
}
li.addClass("queue_active");
$("#queue").scrollTop(0);
var scroll = li.position().top - $("#queue").position().top;
$("#queue").scrollTop(scroll);
li.addClass("queue_active");
$("#queue").scrollTop(0);
var scroll = li.position().top - $("#queue").position().top;
$("#queue").scrollTop(scroll);
}
});
},
changeMedia: function(data) {

View file

@ -968,6 +968,40 @@ function addLibraryButtons(li, id, type) {
/* queue stuff */
var PL_QUEUED_ACTIONS = [];
var PL_ACTION_INTERVAL = false;
function queueAction(data) {
PL_QUEUED_ACTIONS.push(data);
if(PL_ACTION_INTERVAL)
return;
PL_ACTION_INTERVAL = setInterval(function () {
var data = PL_QUEUED_ACTIONS.shift();
if(!("expire" in data))
data.expire = Date.now() + 5000;
if(!data.fn()) {
if(Date.now() < data.expire)
PL_QUEUED_ACTIONS.unshift(data);
}
if(PL_QUEUED_ACTIONS.length == 0) {
clearInterval(PL_ACTION_INTERVAL);
PL_ACTION_INTERVAL = false;
}
}, 100);
}
// Because jQuery UI does weird things
function playlistFind(uid) {
var children = document.getElementById("queue").children;
for(var i in children) {
if(typeof children[i].getAttribute != "function")
continue;
if(children[i].getAttribute("class").indexOf("pluid-" + uid) != -1)
return children[i];
}
return false;
}
function playlistMove(from, after) {
var lifrom = $(".pluid-" + from);
if(lifrom.length == 0)