custom-media: implement queueing and playback changes
This commit is contained in:
parent
a6de8731b3
commit
04c9d48779
10 changed files with 93 additions and 21 deletions
|
|
@ -386,7 +386,7 @@ PlaylistModule.prototype.handleQueue = function (user, data) {
|
|||
id: id
|
||||
});
|
||||
return;
|
||||
} else if (type === "fi" && !perms.canAddRawFile(user)) {
|
||||
} else if ((type === "fi" || type === "cm") && !perms.canAddRawFile(user)) {
|
||||
user.socket.emit("queueFail", {
|
||||
msg: "You don't have permission to add raw video files",
|
||||
link: link,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ import net from 'net';
|
|||
import Media from './media';
|
||||
import { hash } from './util/hash';
|
||||
import { get as httpGet } from 'http';
|
||||
import { get as httpsGet } from 'https';
|
||||
|
||||
const LOGGER = require('@calzoneman/jsli')('custom-media');
|
||||
|
||||
const SOURCE_QUALITIES = new Set([
|
||||
240,
|
||||
|
|
@ -39,7 +42,20 @@ export function lookup(url, opts) {
|
|||
|
||||
Object.assign(options, parseURL(url));
|
||||
|
||||
const req = httpGet(options);
|
||||
if (!/^https?:$/.test(options.protocol)) {
|
||||
reject(new ValidationError(
|
||||
`Unacceptable protocol "${options.protocol}". Custom metadata must be`
|
||||
+ ' retrieved by HTTP or HTTPS'
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.info('Looking up %s', url);
|
||||
|
||||
// this is fucking stupid
|
||||
const get = options.protocol === 'https:' ? httpsGet : httpGet;
|
||||
const req = get(options);
|
||||
|
||||
req.setTimeout(opts.timeout, () => {
|
||||
const error = new Error('Request timed out');
|
||||
|
|
@ -48,6 +64,7 @@ export function lookup(url, opts) {
|
|||
});
|
||||
|
||||
req.on('error', error => {
|
||||
LOGGER.warn('Request for %s failed: %s', url, error);
|
||||
reject(error);
|
||||
});
|
||||
|
||||
|
|
@ -89,11 +106,11 @@ export function lookup(url, opts) {
|
|||
});
|
||||
});
|
||||
}).then(body => {
|
||||
return convert(JSON.parse(body));
|
||||
return convert(url, JSON.parse(body));
|
||||
});
|
||||
}
|
||||
|
||||
export function convert(data) {
|
||||
export function convert(id, data) {
|
||||
validate(data);
|
||||
|
||||
if (data.live) data.duration = 0;
|
||||
|
|
@ -118,12 +135,6 @@ export function convert(data) {
|
|||
live: !!data.live // Currently ignored by Media
|
||||
};
|
||||
|
||||
const id = hash('sha256', JSON.stringify([
|
||||
data.title,
|
||||
data.duration,
|
||||
meta
|
||||
]), 'base64');
|
||||
|
||||
return new Media(id, data.title, data.duration, 'cm', meta);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ var GoogleDrive = require("cytube-mediaquery/lib/provider/googledrive");
|
|||
var TwitchVOD = require("cytube-mediaquery/lib/provider/twitch-vod");
|
||||
var TwitchClip = require("cytube-mediaquery/lib/provider/twitch-clip");
|
||||
import { Counter } from 'prom-client';
|
||||
import { lookup as lookupCustomMetadata } from './custom-media';
|
||||
|
||||
const LOGGER = require('@calzoneman/jsli')('get-info');
|
||||
const lookupCounter = new Counter({
|
||||
|
|
@ -539,6 +540,16 @@ var Getters = {
|
|||
}).catch(function (err) {
|
||||
callback(err.message || err, null);
|
||||
});
|
||||
},
|
||||
|
||||
/* custom media - https://github.com/calzoneman/sync/issues/655 */
|
||||
cm: async function (id, callback) {
|
||||
try {
|
||||
const media = await lookupCustomMetadata(id);
|
||||
process.nextTick(callback, false, media);
|
||||
} catch (error) {
|
||||
process.nextTick(callback, error.message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -246,6 +246,8 @@
|
|||
return "https://streamable.com/" + id;
|
||||
case "tc":
|
||||
return "https://clips.twitch.tv/" + id;
|
||||
case "cm":
|
||||
return id;
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue