From f6b02a166a69edfbe773a10c6d92d58a050a28b5 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 3 Jul 2013 11:26:10 -0400 Subject: [PATCH] Getting there --- get-info.js | 7 ++- playlist.js | 38 ++++++++++++++- www/assets/js/callbacks.js | 96 +++++++++++++++++++++++--------------- www/assets/js/util.js | 34 ++++++++++++++ 4 files changed, 134 insertions(+), 41 deletions(-) diff --git a/get-info.js b/get-info.js index 06a1b27b..31819d55 100644 --- a/get-info.js +++ b/get-info.js @@ -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": diff --git a/playlist.js b/playlist.js index c2d528ab..9ec73078 100644 --- a/playlist.js +++ b/playlist.js @@ -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({ diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 7a34cb19..8b7c9d74 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -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) { diff --git a/www/assets/js/util.js b/www/assets/js/util.js index bbaac9ba..4ebeada0 100644 --- a/www/assets/js/util.js +++ b/www/assets/js/util.js @@ -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)