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

View file

@ -68,7 +68,6 @@ Playlist.prototype.queueAction = function(data) {
pl.alter_queue.unshift(data); pl.alter_queue.unshift(data);
return; return;
} }
//pl[data.fn].apply(pl, data.args);
data.fn(); data.fn();
if(pl.alter_queue.length == 0) { if(pl.alter_queue.length == 0) {
clearInterval(pl._qaInterval); clearInterval(pl._qaInterval);
@ -154,6 +153,12 @@ Playlist.prototype.add = function(item, pos) {
} }
Playlist.prototype.addMedia = function(data, callback) { Playlist.prototype.addMedia = function(data, callback) {
if(data.type == "yp") {
this.addYouTubePlaylist(data, callback);
return;
}
var pos = "append"; var pos = "append";
if(data.pos == "next") { if(data.pos == "next") {
if(!this.current) 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) { Playlist.prototype.remove = function(uid, callback) {
var pl = this; var pl = this;
this.queueAction({ this.queueAction({

View file

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

View file

@ -968,6 +968,40 @@ function addLibraryButtons(li, id, type) {
/* queue stuff */ /* 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) { function playlistMove(from, after) {
var lifrom = $(".pluid-" + from); var lifrom = $(".pluid-" + from);
if(lifrom.length == 0) if(lifrom.length == 0)