This commit is contained in:
Izuco 2022-02-26 11:11:21 +01:00
parent 9d8488ff24
commit fed44e1cea
No known key found for this signature in database
GPG key ID: E9CBE9E4EF3A1BFA
5 changed files with 60 additions and 9 deletions

View file

@ -1,7 +1,6 @@
declare module 'sei-helper' {
export async function question(qStr: string): Promise<string>;
export function cleanupFilename(str: string): string;
export function exec(str: string, str1: string, str2: string);
export const cookie: {
parse: (data: Record<string, string>) => Record<string, {
value: string;

View file

@ -1273,12 +1273,10 @@ export default class Crunchy implements ServiceClass {
// mergers
let isMuxed = false;
if (bin.MKVmerge) {
const command = merger.MkvMerge();
shlp.exec('mkvmerge', `"${bin.MKVmerge}"`, command);
await merger.merge('mkvmerge', bin.MKVmerge);
isMuxed = true;
} else if (bin.FFmpeg) {
const command = merger.FFmpeg();
shlp.exec('ffmpeg', `"${bin.FFmpeg}"`, command);
await merger.merge('ffmpeg', bin.FFmpeg);
isMuxed = true;
} else{
console.log('\n[INFO] Done!\n');

View file

@ -798,12 +798,10 @@ export default class Funi implements ServiceClass {
});
if(mergerBin.MKVmerge){
const command = mergeInstance.MkvMerge();
shlp.exec('mkvmerge', `"${mergerBin.MKVmerge}"`, command);
await mergeInstance.merge('mkvmerge', mergerBin.MKVmerge);
}
else if(mergerBin.FFmpeg){
const command = mergeInstance.FFmpeg();
shlp.exec('ffmpeg',`"${mergerBin.FFmpeg}"`,command);
await mergeInstance.merge('ffmpeg', mergerBin.FFmpeg);
}
else{
if (log)

View file

@ -4,6 +4,8 @@ import path from 'path';
import fs from 'fs';
import { LanguageItem } from './module.langsData';
import { AvailableMuxer } from './module.args';
import { exec } from './sei-helper-fixes';
import { PromiseWithChild } from 'child_process';
export type MergerInput = {
path: string,
@ -277,6 +279,32 @@ class Merger {
return fontsList;
}
public async merge(type: 'ffmpeg'|'mkvmerge', bin: string) {
let command: string|undefined = undefined;
switch (type) {
case 'ffmpeg':
command = this.FFmpeg();
break;
case 'mkvmerge':
command = this.MkvMerge();
break;
}
if (command === undefined) {
console.log('[WARN] Unable to merge files.');
return;
}
console.log(`[INFO][${type}] Started merging`);
const res = exec(type, `"${bin}"`, command);
if (!res.isOk && type === 'mkvmerge' && res.err.code === 1) {
console.log(`[INFO][${type}] Mkvmerge finished with at least one warning`);
} else if (!res.isOk) {
console.log(res.err);
console.log(`[ERROR][${type}] Merging failed with exit code ${res.err.code}`);
} else {
console.log(`[INFO][${type} Done]`);
}
}
public cleanUp() {
this.options.onlyAudio.concat(this.options.onlyVid).concat(this.options.videoAndAudio).forEach(a => fs.unlinkSync(a.path));
this.options.subtitles.forEach(a => fs.unlinkSync(a.file));

View file

@ -0,0 +1,28 @@
import childProcess from 'child_process';
const exec = (pname: string, fpath: string, pargs: string, spc = false): {
isOk: true
} | {
isOk: false,
err: Error & { code: number }
} => {
pargs = pargs ? ' ' + pargs : '';
console.log(`\n> "${pname}"${pargs}${spc ? '\n' : ''}`);
try {
childProcess.execSync((fpath + pargs), { stdio: 'inherit' });
return {
isOk: true
};
} catch (er) {
const err = er as Error & { status: number };
return {
isOk: false,
err: {
...err,
code: err.status
}
};
}
};
export { exec };