diff --git a/channel.js b/channel.js index 896cb623..9e2abf55 100644 --- a/channel.js +++ b/channel.js @@ -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": diff --git a/get-info.js b/get-info.js index c26c6601..0fb9dd65 100644 --- a/get-info.js +++ b/get-info.js @@ -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; }