mirror of https://github.com/calzoneman/sync.git
Fixes
This commit is contained in:
parent
5f1f985dd0
commit
54f2ad7c5c
|
@ -2,7 +2,7 @@ var Logger = require("./logger");
|
||||||
var Config = require("./config");
|
var Config = require("./config");
|
||||||
var spawn = require("child_process").spawn;
|
var spawn = require("child_process").spawn;
|
||||||
|
|
||||||
var SUPPORTS_JSON = true;
|
var USE_JSON = true;
|
||||||
|
|
||||||
var acceptedCodecs = {
|
var acceptedCodecs = {
|
||||||
"mov/h264": true,
|
"mov/h264": true,
|
||||||
|
@ -62,13 +62,13 @@ function reformatData(data) {
|
||||||
if (isNaN(bitrate)) bitrate = 0;
|
if (isNaN(bitrate)) bitrate = 0;
|
||||||
reformatted.bitrate = bitrate;
|
reformatted.bitrate = bitrate;
|
||||||
|
|
||||||
reformatted.title = data.format.tags.title;
|
reformatted.title = data.format.tags ? data.format.tags.title : null;
|
||||||
var container = data.format.format_name.split(",")[0];
|
var container = data.format.format_name.split(",")[0];
|
||||||
|
|
||||||
data.streams.forEach(function (stream) {
|
data.streams.forEach(function (stream) {
|
||||||
if (stream.codec_type === "video") {
|
if (stream.codec_type === "video") {
|
||||||
reformatted.vcodec = stream.codec_name;
|
reformatted.vcodec = stream.codec_name;
|
||||||
if (!reformatted.title) {
|
if (!reformatted.title && stream.tags) {
|
||||||
reformatted.title = stream.tags.title;
|
reformatted.title = stream.tags.title;
|
||||||
}
|
}
|
||||||
} else if (stream.codec_type === "audio") {
|
} else if (stream.codec_type === "audio") {
|
||||||
|
@ -90,7 +90,7 @@ function reformatData(data) {
|
||||||
exports.ffprobe = function ffprobe(filename, cb) {
|
exports.ffprobe = function ffprobe(filename, cb) {
|
||||||
var childErr;
|
var childErr;
|
||||||
var args = ["-show_streams", "-show_format", filename];
|
var args = ["-show_streams", "-show_format", filename];
|
||||||
if (SUPPORTS_JSON) args = ["-of", "json"].concat(args);
|
if (USE_JSON) args = ["-of", "json"].concat(args);
|
||||||
var child = spawn(Config.get("ffmpeg.ffprobe-exec"), args);
|
var child = spawn(Config.get("ffmpeg.ffprobe-exec"), args);
|
||||||
var stdout = "";
|
var stdout = "";
|
||||||
var stderr = "";
|
var stderr = "";
|
||||||
|
@ -109,10 +109,10 @@ exports.ffprobe = function ffprobe(filename, cb) {
|
||||||
|
|
||||||
child.on("close", function (code) {
|
child.on("close", function (code) {
|
||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
if (stderr.match(/-of/)) {
|
if (stderr.match(/unrecognized option|json/i) && USE_JSON) {
|
||||||
Logger.errlog.log("Warning: ffprobe does not support -of json. " +
|
Logger.errlog.log("Warning: ffprobe does not support -of json. " +
|
||||||
"Assuming it will have old output format.");
|
"Assuming it will have old output format.");
|
||||||
SUPPORTS_JSON = false;
|
USE_JSON = false;
|
||||||
return ffprobe(filename, cb);
|
return ffprobe(filename, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ exports.ffprobe = function ffprobe(filename, cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var result;
|
var result;
|
||||||
if (SUPPORTS_JSON) {
|
if (USE_JSON) {
|
||||||
try {
|
try {
|
||||||
result = JSON.parse(stdout);
|
result = JSON.parse(stdout);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -166,7 +166,7 @@ exports.query = function (filename, cb) {
|
||||||
try {
|
try {
|
||||||
data = reformatData(data);
|
data = reformatData(data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logger.errlog.log(err.stack || err);
|
Logger.errlog.log(e.stack || e);
|
||||||
return cb("Unable to query file data with ffmpeg");
|
return cb("Unable to query file data with ffmpeg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,17 +184,15 @@ exports.query = function (filename, cb) {
|
||||||
|
|
||||||
cb(null, data);
|
cb(null, data);
|
||||||
} else if (data.medium === "audio") {
|
} else if (data.medium === "audio") {
|
||||||
var codec = meta.acodec;
|
if (!acceptedAudioCodecs.hasOwnProperty(data.acodec)) {
|
||||||
|
return cb("Unsupported audio codec " + data.acodec);
|
||||||
if (!acceptedAudioCodecs.hasOwnProperty(data.type)) {
|
|
||||||
return cb("Unsupported audio codec " + data.type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
title: data.title || "Raw Audio",
|
title: data.title || "Raw Audio",
|
||||||
duration: data.duration,
|
duration: data.duration,
|
||||||
bitrate: data.bitrate,
|
bitrate: data.bitrate,
|
||||||
codec: codec
|
codec: data.acodec
|
||||||
};
|
};
|
||||||
|
|
||||||
cb(null, data);
|
cb(null, data);
|
||||||
|
|
Loading…
Reference in New Issue