Adapted primary save function to handle single streams and non-item saves (e.g. profiles).
This commit is contained in:
parent
e752667be7
commit
0313b291da
|
@ -42,10 +42,10 @@ module.exports = function(posts, user) {
|
|||
return Promise.resolve().then(() => {
|
||||
return fs.ensureDir(path.dirname(filepath));
|
||||
}).then(() => {
|
||||
return save(filepath, item);
|
||||
return save(filepath, item.streams, item);
|
||||
}).then(sourcePaths => {
|
||||
if(item.mux) {
|
||||
return mux(sourcePaths, filepath, item);
|
||||
return mux(filepath, sourcePaths, item);
|
||||
}
|
||||
}).then(() => {
|
||||
const meta = Object.entries(config.library.meta).reduce((acc, [key, value]) => {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
const ffmpeg = require('fluent-ffmpeg');
|
||||
const fs = require('fs-extra');
|
||||
|
||||
function mux(sources, target, item) {
|
||||
function mux(target, sources, item) {
|
||||
return new Promise((resolve, reject) => {
|
||||
return sources.reduce((acc, source) => {
|
||||
return acc.input(source);
|
||||
|
|
|
@ -4,21 +4,24 @@ const fs = require('fs-extra');
|
|||
const path = require('path');
|
||||
const ffmpeg = require('fluent-ffmpeg');
|
||||
|
||||
function save(filepath, item) {
|
||||
function save(filepath, streams, item) {
|
||||
const pathComponents = path.parse(filepath);
|
||||
|
||||
// allow for single stream argument
|
||||
streams = [].concat(streams);
|
||||
|
||||
return Promise.resolve().then(() => {
|
||||
return fs.ensureDir(path.dirname(pathComponents.dir));
|
||||
}).then(() => {
|
||||
return Promise.all(item.streams.map((stream, index) => {
|
||||
const target = item.streams.length > 1 ? path.join(pathComponents.dir, `${pathComponents.name}-${index}${pathComponents.ext}`) : filepath;
|
||||
return Promise.all(streams.map((stream, index) => {
|
||||
const target = streams.length > 1 ? path.join(pathComponents.dir, `${pathComponents.name}-${index}${pathComponents.ext}`) : filepath;
|
||||
const file = fs.createWriteStream(target);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
stream.pipe(file).on('error', error => {
|
||||
reject(error);
|
||||
}).on('finish', () => {
|
||||
if(item.mux) {
|
||||
if(item && item.mux) {
|
||||
console.log(`Temporarily saved '${target}', queued for muxing`);
|
||||
} else {
|
||||
console.log('\x1b[32m%s\x1b[0m', `Saved '${target}'`);
|
||||
|
|
Loading…
Reference in New Issue