audiobookshelf/server/libs/nodeFfprobe/index.js

34 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-07-07 00:07:08 +02:00
//
// node-ffprobe modified for audiobookshelf
// SOURCE: https://github.com/ListenerApproved/node-ffprobe
//
const spawn = require('child_process').spawn
module.exports = (function () {
function doProbe(file) {
return new Promise((resolve, reject) => {
let proc = spawn(module.exports.FFPROBE_PATH || 'ffprobe', ['-hide_banner', '-loglevel', 'fatal', '-show_error', '-show_format', '-show_streams', '-show_programs', '-show_chapters', '-show_private_data', '-print_format', 'json', file])
let probeData = []
let errData = []
proc.stdout.setEncoding('utf8')
proc.stderr.setEncoding('utf8')
proc.stdout.on('data', function (data) { probeData.push(data) })
proc.stderr.on('data', function (data) { errData.push(data) })
proc.on('exit', code => { exitCode = code })
proc.on('error', err => reject(err))
2022-09-24 23:50:21 +02:00
proc.on('close', () => {
2022-09-24 23:51:17 +02:00
try {
resolve(JSON.parse(probeData.join('')))
2022-09-24 23:51:17 +02:00
} catch (err) {
reject(err);
}
})
2022-07-07 00:07:08 +02:00
})
}
return doProbe
})()