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,
link: link,
temp: temp,
shouldAddToLibrary: temp,
shouldAddToLibrary: !temp,
queueby: queueby,
duration: duration,
maxlength: maxlength

View File

@ -21,7 +21,7 @@ var acceptedCodecs = {
"flv/h264": true,
"matroska/vp8": true,
"matroska/vp9": true,
"ogg/theora": true,
"ogg/theora": true
};
var acceptedAudioCodecs = {
@ -29,6 +29,10 @@ var acceptedAudioCodecs = {
"vorbis": true
};
var audioOnlyContainers = {
"mp3": true
};
exports.query = function (filename, cb) {
if (!Metadata) {
init();
@ -38,6 +42,11 @@ exports.query = function (filename, cb) {
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) {
if (err) {
return cb(err);
@ -53,7 +62,7 @@ exports.query = function (filename, cb) {
var data = {
title: meta.title || "Raw Video",
duration: meta.durationsec,
duration: Math.ceil(meta.durationsec),
bitrate: video.bitrate,
codec: codec
};
@ -69,12 +78,15 @@ exports.query = function (filename, cb) {
var data = {
title: meta.title || "Raw Audio",
duration: meta.durationsec,
duration: Math.ceil(meta.durationsec),
bitrate: audio.bitrate,
codec: codec
};
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 {
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 " +
@ -84,7 +96,11 @@ exports.query = function (filename, cb) {
};
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) {