mirror of https://github.com/calzoneman/sync.git
Better error handling, add support for mp3/ogg-vorbis
This commit is contained in:
parent
1d1630fb50
commit
6dde745784
|
@ -885,7 +885,8 @@ PlaylistModule.prototype._addItem = function (media, data, user, cb) {
|
|||
}
|
||||
|
||||
/* Warn about possibly unsupported formats */
|
||||
if (media.type === "fi" && media.meta.codec !== "mov/h264" &&
|
||||
if (media.type === "fi" && media.meta.codec.indexOf("/") !== -1 &&
|
||||
media.meta.codec !== "mov/h264" &&
|
||||
media.meta.codec !== "flv/h264") {
|
||||
user.socket.emit("queueWarn", {
|
||||
msg: "The codec <code>" + media.meta.codec + "</code> is not supported " +
|
||||
|
|
|
@ -24,6 +24,11 @@ var acceptedCodecs = {
|
|||
"ogg/theora": true,
|
||||
};
|
||||
|
||||
var acceptedAudioCodecs = {
|
||||
"mp3": true,
|
||||
"vorbis": true
|
||||
};
|
||||
|
||||
exports.query = function (filename, cb) {
|
||||
if (!Metadata) {
|
||||
init();
|
||||
|
@ -38,11 +43,8 @@ exports.query = function (filename, cb) {
|
|||
return cb(err);
|
||||
}
|
||||
|
||||
if (isVideo(meta)) {
|
||||
var video = meta.video;
|
||||
if (!video) {
|
||||
return cb("File has no video stream");
|
||||
}
|
||||
|
||||
var codec = video.container + "/" + video.codec;
|
||||
|
||||
if (!(codec in acceptedCodecs)) {
|
||||
|
@ -57,5 +59,34 @@ exports.query = function (filename, cb) {
|
|||
};
|
||||
|
||||
cb(null, data);
|
||||
} else if (isAudio(meta)) {
|
||||
var audio = meta.audio;
|
||||
var codec = audio.codec;
|
||||
|
||||
if (!(codec in acceptedAudioCodecs)) {
|
||||
return cb("Unsupported audio codec " + codec);
|
||||
}
|
||||
|
||||
var data = {
|
||||
title: meta.title || "Raw Audio",
|
||||
duration: meta.durationsec,
|
||||
bitrate: audio.bitrate,
|
||||
codec: codec
|
||||
};
|
||||
|
||||
cb(null, data);
|
||||
} 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 " +
|
||||
"this server's version of ffmpeg.");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function isVideo(meta) {
|
||||
return meta.video && meta.video.bitrate > 0 && meta.video.container && meta.video.codec;
|
||||
}
|
||||
|
||||
function isAudio(meta) {
|
||||
return meta.audio && meta.audio.bitrate > 0 && meta.audio.codec;
|
||||
}
|
||||
|
|
|
@ -846,7 +846,7 @@ Callbacks = {
|
|||
}
|
||||
|
||||
if (data.type === "fi") {
|
||||
if (USEROPTS.no_h264 && data.meta.codec !== "matroska/vp8") {
|
||||
if (USEROPTS.no_h264 && data.meta.codec === "mov/h264") {
|
||||
data.forceFlash = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1155,7 +1155,14 @@ function FilePlayer(data) {
|
|||
self.init = function (data) {
|
||||
self.videoId = data.id;
|
||||
self.videoURL = data.url;
|
||||
var video = $("<video/>")
|
||||
var isAudio = data.meta.codec && data.meta.codec.match(/^mp3$|^vorbis$/);
|
||||
var video;
|
||||
if (isAudio) {
|
||||
video = $("<audio/>");
|
||||
} else {
|
||||
video = $("<video/>")
|
||||
}
|
||||
video
|
||||
.attr("src", self.videoURL)
|
||||
.attr("controls", "controls")
|
||||
.attr("id", "#ytapiplayer")
|
||||
|
@ -1175,7 +1182,11 @@ function FilePlayer(data) {
|
|||
};
|
||||
|
||||
self.load = function (data) {
|
||||
if (data.forceFlash) {
|
||||
self.initFlash(data);
|
||||
} else {
|
||||
self.init(data);
|
||||
}
|
||||
};
|
||||
|
||||
self.pause = function () {
|
||||
|
|
|
@ -398,7 +398,7 @@ $("#mediaurl").keyup(function(ev) {
|
|||
}
|
||||
|
||||
var url = $("#mediaurl").val().split("?")[0];
|
||||
if (url.match(/^https?:\/\/(.*)?\.(flv|mp4|ogg|webm)$/)) {
|
||||
if (url.match(/^https?:\/\/(.*)?\.(flv|mp4|og[gv]|webm|mp3)$/)) {
|
||||
var title = $("#addfromurl-title");
|
||||
if (title.length === 0) {
|
||||
title = $("<div/>")
|
||||
|
|
|
@ -1289,7 +1289,7 @@ function parseMediaLink(url) {
|
|||
/* Raw file */
|
||||
var tmp = url.split("?")[0];
|
||||
if (tmp.match(/^https?:\/\//)) {
|
||||
if (tmp.match(/\.(mp4|flv|webm|ogg)$/)) {
|
||||
if (tmp.match(/\.(mp4|flv|webm|og[gv]|mp3)$/)) {
|
||||
return {
|
||||
id: url,
|
||||
type: "fi"
|
||||
|
@ -1298,7 +1298,7 @@ function parseMediaLink(url) {
|
|||
Callbacks.queueFail({
|
||||
link: url,
|
||||
msg: "The file you are attempting to queue does not match the supported " +
|
||||
"file extensions mp4, flv, webm, ogg."
|
||||
"file extensions mp4, flv, webm, ogg, ogv, mp3."
|
||||
});
|
||||
throw new Error("ERROR_QUEUE_UNSUPPORTED_EXTENSION");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue