Add YouTube playlist support

This commit is contained in:
calzoneman 2013-04-03 13:18:10 -05:00
parent 7e9907ebdc
commit 42a76c4632
2 changed files with 46 additions and 2 deletions

View file

@ -510,6 +510,7 @@ Channel.prototype.enqueue = function(data) {
else {
switch(data.type) {
case "yt":
case "yp":
case "vi":
case "dm":
case "sc":
@ -520,6 +521,8 @@ Channel.prototype.enqueue = function(data) {
pos: idx
});
this.cacheMedia(media);
if(data.type == "yp")
idx++;
}.bind(this));
break;
case "li":

View file

@ -73,11 +73,15 @@ exports.getYTInfo = function(id, callback) {
timeout: 1000}, callback);
}
exports.getYTPlaylist = function(id, callback) {
exports.getYTPlaylist = function(id, callback, url) {
var path = "/feeds/api/playlists/" + id + "?v=2&alt=json";
if(url) {
path = "/" + url.split("gdata.youtube.com")[1];
}
getJSON({
host: "gdata.youtube.com",
port: 80,
path: "/feeds/api/playlists/" + id + "?v=2&alt=json",
path: path,
method: "GET",
dataType: "jsonp",
timeout: 1000}, callback);
@ -209,6 +213,43 @@ exports.getMedia = function(id, type, callback) {
}
});
break;
case "yp":
var cback = function(res, data) {
if(res != 200) {
return;
}
try {
for(var i = 0; i < data.feed.entry.length; i++) {
try {
var item = data.feed.entry[i];
var id = item.media$group.yt$videoid.$t;
var title = item.title.$t;
var seconds = item.media$group.yt$duration.seconds;
var media = new Media(id, title, seconds, "yt");
callback(media);
}
catch(e) {
Logger.errlog.log("getMedia failed: ");
Logger.errlog.log(e);
}
}
var links = data.feed.link;
for(var i = 0; i < links.length; i++) {
if(links[i].rel == "next") {
exports.getYTPlaylist(id, cback, links[i].href);
}
}
}
catch(e) {
Logger.errlog.log("getMedia failed: ");
Logger.errlog.log(e);
}
}
exports.getYTPlaylist(id, cback);
default:
break;
}