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