Various fixes for raw file playback

This commit is contained in:
Calvin Montgomery 2014-06-07 10:45:52 -07:00
parent 14c13f845e
commit 5d5bdfc069
2 changed files with 21 additions and 5 deletions

View file

@ -406,7 +406,7 @@ PlaylistModule.prototype.handleQueue = function (user, data) {
title: data.title, title: data.title,
link: link, link: link,
temp: temp, temp: temp,
shouldAddToLibrary: temp, shouldAddToLibrary: !temp,
queueby: queueby, queueby: queueby,
duration: duration, duration: duration,
maxlength: maxlength maxlength: maxlength

View file

@ -21,7 +21,7 @@ var acceptedCodecs = {
"flv/h264": true, "flv/h264": true,
"matroska/vp8": true, "matroska/vp8": true,
"matroska/vp9": true, "matroska/vp9": true,
"ogg/theora": true, "ogg/theora": true
}; };
var acceptedAudioCodecs = { var acceptedAudioCodecs = {
@ -29,6 +29,10 @@ var acceptedAudioCodecs = {
"vorbis": true "vorbis": true
}; };
var audioOnlyContainers = {
"mp3": true
};
exports.query = function (filename, cb) { exports.query = function (filename, cb) {
if (!Metadata) { if (!Metadata) {
init(); init();
@ -38,6 +42,11 @@ exports.query = function (filename, cb) {
return cb("Raw file playback is not enabled on this server"); return cb("Raw file playback is not enabled on this server");
} }
if (!filename.match(/^https?:\/\//)) {
return cb("Raw file playback is only supported for links accessible via HTTP " +
"or HTTPS");
}
new Metadata(filename, function (meta, err) { new Metadata(filename, function (meta, err) {
if (err) { if (err) {
return cb(err); return cb(err);
@ -53,7 +62,7 @@ exports.query = function (filename, cb) {
var data = { var data = {
title: meta.title || "Raw Video", title: meta.title || "Raw Video",
duration: meta.durationsec, duration: Math.ceil(meta.durationsec),
bitrate: video.bitrate, bitrate: video.bitrate,
codec: codec codec: codec
}; };
@ -69,12 +78,15 @@ exports.query = function (filename, cb) {
var data = { var data = {
title: meta.title || "Raw Audio", title: meta.title || "Raw Audio",
duration: meta.durationsec, duration: Math.ceil(meta.durationsec),
bitrate: audio.bitrate, bitrate: audio.bitrate,
codec: codec codec: codec
}; };
cb(null, data); cb(null, data);
} else if (data.ffmpegErr.match(/Protocol not found/)) {
return cb("This server is unable to load videos over the " +
filename.split(":")[0] + " protocol.");
} else { } else {
return cb("Parsed metadata did not contain a valid video or audio stream. " + return cb("Parsed metadata did not contain a valid video or audio stream. " +
"Either the file is invalid or it has a format unsupported by " + "Either the file is invalid or it has a format unsupported by " +
@ -84,7 +96,11 @@ exports.query = function (filename, cb) {
}; };
function isVideo(meta) { function isVideo(meta) {
return meta.video && meta.video.bitrate > 0 && meta.video.container && meta.video.codec; return meta.video &&
meta.video.bitrate > 0 &&
meta.video.container &&
meta.video.codec &&
!(meta.video.container in audioOnlyContainers);
} }
function isAudio(meta) { function isAudio(meta) {