Prevent quota overflow

This commit is contained in:
Calvin Montgomery 2013-07-09 22:55:40 -04:00
parent d4d6fb6686
commit 53c1655894
2 changed files with 43 additions and 17 deletions

View File

@ -30,6 +30,10 @@ function getJSON(options, callback) {
catch(e) { catch(e) {
Logger.errlog.log("JSON fail: " + options.path); Logger.errlog.log("JSON fail: " + options.path);
var m = buffer.match(/<internalReason>([^<]+)<\/internalReason>/); var m = buffer.match(/<internalReason>([^<]+)<\/internalReason>/);
if(m === null)
m = buffer.match(/<code>([^<]+)<\/code>/);
if(m === null)
m = buffer.match(/([0-9]+ not found)/);
if(m) { if(m) {
callback(m[1], res.statusCode, null); callback(m[1], res.statusCode, null);
} }
@ -60,6 +64,10 @@ function getJSONHTTPS(options, callback) {
catch(e) { catch(e) {
Logger.errlog.log("JSON fail: " + options.path); Logger.errlog.log("JSON fail: " + options.path);
var m = buffer.match(/<internalReason>([^<]+)<\/internalReason>/); var m = buffer.match(/<internalReason>([^<]+)<\/internalReason>/);
if(m === null)
m = buffer.match(/<code>([^<]+)<\/code>/);
if(m === null)
m = buffer.match(/([0-9]+ not found)/);
if(m) { if(m) {
callback(m[1], res.statusCode, null); callback(m[1], res.statusCode, null);
} }
@ -259,7 +267,7 @@ exports.getMedia = function(id, type, callback) {
case "vi": case "vi":
exports.getVIInfo(id, function(err, res, data) { exports.getVIInfo(id, function(err, res, data) {
if(err || res != 200) { if(err || res != 200) {
callback(true, null); callback(err || true, null);
return; return;
} }

View File

@ -49,16 +49,29 @@ function Playlist(chan) {
this._qaInterval = false; this._qaInterval = false;
if(chan) { if(chan) {
this.channel = chan;
var pl = this; var pl = this;
this.on("mediaUpdate", function(m) { this.on("mediaUpdate", function(m) {
if(chan != pl.channel) {
pl.die();
return;
}
chan.sendAll("mediaUpdate", m.timeupdate()); chan.sendAll("mediaUpdate", m.timeupdate());
}); });
this.on("changeMedia", function(m) { this.on("changeMedia", function(m) {
if(chan != pl.channel) {
pl.die();
return;
}
chan.onVideoChange(); chan.onVideoChange();
chan.sendAll("setCurrent", pl.current.uid); chan.sendAll("setCurrent", pl.current.uid);
chan.sendAll("changeMedia", m.fullupdate()); chan.sendAll("changeMedia", m.fullupdate());
}); });
this.on("remove", function(item) { this.on("remove", function(item) {
if(chan != pl.channel) {
pl.die();
return;
}
chan.broadcastPlaylistMeta(); chan.broadcastPlaylistMeta();
chan.sendAll("delete", { chan.sendAll("delete", {
uid: item.uid uid: item.uid
@ -254,25 +267,30 @@ Playlist.prototype.addMediaList = function(data, callback) {
start = false; start = false;
var pl = this; var pl = this;
data.list.forEach(function(x) { for(var i = 0; i < data.list.length; i++) {
x.queueby = data.queueby; var x = data.list[i];
x.pos = data.pos; (function(i, x) {
if(start && x == start) { setTimeout(function() {
pl.addMedia(x, function (err, item) { x.queueby = data.queueby;
if(err) { x.pos = data.pos;
callback(err, item); 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 { else {
callback(err, item); pl.addMedia(x, callback);
pl.current = item;
pl.startPlayback();
} }
}); }, 500 * i);
} })(i, x);
else { }
pl.addMedia(x, callback);
}
});
} }
Playlist.prototype.addYouTubePlaylist = function(data, callback) { Playlist.prototype.addYouTubePlaylist = function(data, callback) {