mirror of https://github.com/calzoneman/sync.git
Refactor get-info module to be a Server property
This commit is contained in:
parent
aa3234eb6a
commit
1aeec527f6
127
channel.js
127
channel.js
|
@ -15,7 +15,6 @@ var Poll = require("./poll.js").Poll;
|
|||
var Media = require("./media.js").Media;
|
||||
var formatTime = require("./media.js").formatTime;
|
||||
var Logger = require("./logger.js");
|
||||
var InfoGetter = require("./get-info.js");
|
||||
var Rank = require("./rank.js");
|
||||
var Auth = require("./auth.js");
|
||||
var ChatCommand = require("./chatcommand.js");
|
||||
|
@ -527,7 +526,7 @@ Channel.prototype.search = function(query, callback) {
|
|||
if(query.trim() == "") {
|
||||
return;
|
||||
}
|
||||
InfoGetter.Getters["ytSearch"](query, function(err, vids) {
|
||||
this.server.infogetter.Getters["ytSearch"](query, function(err, vids) {
|
||||
if(!err) {
|
||||
callback(vids);
|
||||
}
|
||||
|
@ -1056,130 +1055,6 @@ Channel.prototype.autoTemp = function(item, user) {
|
|||
}
|
||||
}
|
||||
|
||||
Channel.prototype.enqueue = function(data, user, callback) {
|
||||
var after = "";
|
||||
var current = this.playlist.current;
|
||||
if(data.pos == "next") {
|
||||
after = current ? current.uid : "prepend";
|
||||
}
|
||||
else if(data.pos == "end") {
|
||||
after = "append";
|
||||
}
|
||||
|
||||
if(isLive(data.type) && !this.hasPermission(user, "playlistaddlive")) {
|
||||
user.socket.emit("queueFail", "You don't have permission to queue livestreams");
|
||||
return;
|
||||
}
|
||||
|
||||
// Prefer cache over looking up new data
|
||||
if(data.id in this.library) {
|
||||
var media = this.library[data.id].dup();
|
||||
var item = this.playlist.makeItem(media);
|
||||
item.queueby = user ? user.name : "";
|
||||
this.autoTemp(item, user);
|
||||
this.queueAdd(item, after);
|
||||
this.logger.log("*** Queued from cache: id=" + data.id);
|
||||
if(callback)
|
||||
callback();
|
||||
}
|
||||
else {
|
||||
switch(data.type) {
|
||||
case "yt":
|
||||
case "yp":
|
||||
case "vi":
|
||||
case "dm":
|
||||
case "sc":
|
||||
InfoGetter.getMedia(data.id, data.type, function(err, media) {
|
||||
if(err) {
|
||||
if(callback)
|
||||
callback();
|
||||
if(err === true)
|
||||
err = false;
|
||||
user.socket.emit("queueFail", err);
|
||||
return;
|
||||
}
|
||||
var item = this.playlist.makeItem(media);
|
||||
item.queueby = user ? user.name : "";
|
||||
this.autoTemp(item, user);
|
||||
this.queueAdd(item, after);
|
||||
this.cacheMedia(media);
|
||||
if(data.type == "yp")
|
||||
after = item.uid;
|
||||
if(callback)
|
||||
callback();
|
||||
}.bind(this));
|
||||
break;
|
||||
case "li":
|
||||
var media = new Media(data.id, "Livestream.com - " + data.id, "--:--", "li");
|
||||
var item = this.playlist.makeItem(media);
|
||||
item.queueby = user ? user.name : "";
|
||||
this.autoTemp(item, user);
|
||||
this.queueAdd(item, after);
|
||||
if(callback)
|
||||
callback();
|
||||
break;
|
||||
case "tw":
|
||||
var media = new Media(data.id, "Twitch.tv - " + data.id, "--:--", "tw");
|
||||
var item = this.playlist.makeItem(media);
|
||||
item.queueby = user ? user.name : "";
|
||||
this.autoTemp(item, user);
|
||||
this.queueAdd(item, after);
|
||||
if(callback)
|
||||
callback();
|
||||
break;
|
||||
case "jt":
|
||||
var media = new Media(data.id, "Justin.tv - " + data.id, "--:--", "jt");
|
||||
var item = this.playlist.makeItem(media);
|
||||
item.queueby = user ? user.name : "";
|
||||
this.autoTemp(item, user);
|
||||
this.queueAdd(item, after);
|
||||
if(callback)
|
||||
callback();
|
||||
break;
|
||||
case "us":
|
||||
InfoGetter.getUstream(data.id, function(id) {
|
||||
var media = new Media(id, "Ustream.tv - " + data.id, "--:--", "us");
|
||||
var item = this.playlist.makeItem(media);
|
||||
item.queueby = user ? user.name : "";
|
||||
this.autoTemp(item, user);
|
||||
this.queueAdd(item, after);
|
||||
if(callback)
|
||||
callback();
|
||||
}.bind(this));
|
||||
break;
|
||||
case "rt":
|
||||
var media = new Media(data.id, "Livestream", "--:--", "rt");
|
||||
var item = this.playlist.makeItem(media);
|
||||
item.queueby = user ? user.name : "";
|
||||
this.autoTemp(item, user);
|
||||
this.queueAdd(item, after);
|
||||
if(callback)
|
||||
callback();
|
||||
break;
|
||||
case "jw":
|
||||
var media = new Media(data.id, "JWPlayer Stream - " + data.id, "--:--", "jw");
|
||||
var item = this.playlist.makeItem(media);
|
||||
item.queueby = user ? user.name : "";
|
||||
this.autoTemp(item, user);
|
||||
this.queueAdd(item, after);
|
||||
if(callback)
|
||||
callback();
|
||||
break;
|
||||
case "im":
|
||||
var media = new Media(data.id, "Imgur Album", "--:--", "im");
|
||||
var item = this.playlist.makeItem(media);
|
||||
item.queueby = user ? user.name : "";
|
||||
this.autoTemp(item, user);
|
||||
this.queueAdd(item, after);
|
||||
if(callback)
|
||||
callback();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Channel.prototype.tryQueue = function(user, data) {
|
||||
if(!this.hasPermission(user, "playlistadd")) {
|
||||
return;
|
||||
|
|
21
get-info.js
21
get-info.js
|
@ -14,12 +14,7 @@ var https = require("https");
|
|||
var Logger = require("./logger.js");
|
||||
var Media = require("./media.js").Media;
|
||||
|
||||
var Server = false;
|
||||
function init(srv) {
|
||||
Server = srv;
|
||||
}
|
||||
exports.init = init;
|
||||
|
||||
module.exports = function (Server) {
|
||||
function urlRetrieve(transport, options, callback) {
|
||||
var req = transport.request(options, function (res) {
|
||||
var buffer = "";
|
||||
|
@ -463,12 +458,14 @@ var Getters = {
|
|||
var media = new Media(id, title, "--:--", "im");
|
||||
callback(false, media);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.Getters = Getters;
|
||||
|
||||
exports.getMedia = function(id, type, callback) {
|
||||
if(type in Getters) {
|
||||
Getters[type](id, callback);
|
||||
return {
|
||||
Getters: Getters,
|
||||
getMedia: function (id, type, callback) {
|
||||
if(type in this.Getters) {
|
||||
this.Getters[type](id, callback);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||
|
||||
ULList = require("./ullist").ULList;
|
||||
var Media = require("./media").Media;
|
||||
var InfoGetter = require("./get-info");
|
||||
var AllPlaylists = {};
|
||||
|
||||
function PlaylistItem(media, uid) {
|
||||
|
@ -56,8 +55,8 @@ function Playlist(chan) {
|
|||
this._qaInterval = false;
|
||||
AllPlaylists[name] = this;
|
||||
|
||||
if(chan) {
|
||||
this.channel = chan;
|
||||
this.server = chan.server;
|
||||
var pl = this;
|
||||
this.on("mediaUpdate", function(m) {
|
||||
chan.sendAll("mediaUpdate", m.timeupdate());
|
||||
|
@ -74,7 +73,6 @@ function Playlist(chan) {
|
|||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Playlist.prototype.queueAction = function(data) {
|
||||
this.action_queue.push(data);
|
||||
|
@ -252,7 +250,7 @@ Playlist.prototype.addMedia = function(data, callback) {
|
|||
return;
|
||||
}
|
||||
|
||||
InfoGetter.getMedia(data.id, data.type, function(err, media) {
|
||||
this.server.infogetter.getMedia(data.id, data.type, function(err, media) {
|
||||
if(err) {
|
||||
action.expire = 0;
|
||||
callback(err, null);
|
||||
|
@ -321,7 +319,7 @@ Playlist.prototype.addYouTubePlaylist = function(data, callback) {
|
|||
}
|
||||
|
||||
var pl = this;
|
||||
InfoGetter.getMedia(data.id, data.type, function(err, vids) {
|
||||
this.server.infogetter.getMedia(data.id, data.type, function(err, vids) {
|
||||
if(err) {
|
||||
callback(err, null);
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue