diff --git a/get-info.js b/get-info.js index 75a4b204..b8440618 100644 --- a/get-info.js +++ b/get-info.js @@ -30,6 +30,10 @@ function getJSON(options, callback) { catch(e) { Logger.errlog.log("JSON fail: " + options.path); var m = buffer.match(/([^<]+)<\/internalReason>/); + if(m === null) + m = buffer.match(/([^<]+)<\/code>/); + if(m === null) + m = buffer.match(/([0-9]+ not found)/); if(m) { callback(m[1], res.statusCode, null); } @@ -60,6 +64,10 @@ function getJSONHTTPS(options, callback) { catch(e) { Logger.errlog.log("JSON fail: " + options.path); var m = buffer.match(/([^<]+)<\/internalReason>/); + if(m === null) + m = buffer.match(/([^<]+)<\/code>/); + if(m === null) + m = buffer.match(/([0-9]+ not found)/); if(m) { callback(m[1], res.statusCode, null); } @@ -259,7 +267,7 @@ exports.getMedia = function(id, type, callback) { case "vi": exports.getVIInfo(id, function(err, res, data) { if(err || res != 200) { - callback(true, null); + callback(err || true, null); return; } diff --git a/playlist.js b/playlist.js index 11a4b3da..cb56fa36 100644 --- a/playlist.js +++ b/playlist.js @@ -49,16 +49,29 @@ function Playlist(chan) { this._qaInterval = false; if(chan) { + this.channel = chan; var pl = this; this.on("mediaUpdate", function(m) { + if(chan != pl.channel) { + pl.die(); + return; + } chan.sendAll("mediaUpdate", m.timeupdate()); }); this.on("changeMedia", function(m) { + if(chan != pl.channel) { + pl.die(); + return; + } chan.onVideoChange(); chan.sendAll("setCurrent", pl.current.uid); chan.sendAll("changeMedia", m.fullupdate()); }); this.on("remove", function(item) { + if(chan != pl.channel) { + pl.die(); + return; + } chan.broadcastPlaylistMeta(); chan.sendAll("delete", { uid: item.uid @@ -254,25 +267,30 @@ Playlist.prototype.addMediaList = function(data, callback) { start = false; var pl = this; - data.list.forEach(function(x) { - x.queueby = data.queueby; - x.pos = data.pos; - if(start && x == start) { - pl.addMedia(x, function (err, item) { - if(err) { - callback(err, item); + for(var i = 0; i < data.list.length; i++) { + var x = data.list[i]; + (function(i, x) { + setTimeout(function() { + x.queueby = data.queueby; + x.pos = data.pos; + if(start && x == start) { + pl.addMedia(x, function (err, item) { + if(err) { + callback(err, item); + } + else { + callback(err, item); + pl.current = item; + pl.startPlayback(); + } + }); } else { - callback(err, item); - pl.current = item; - pl.startPlayback(); + pl.addMedia(x, callback); } - }); - } - else { - pl.addMedia(x, callback); - } - }); + }, 500 * i); + })(i, x); + } } Playlist.prototype.addYouTubePlaylist = function(data, callback) {