Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions out/Converter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion out/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 15 additions & 17 deletions src/Converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as child_process from 'child_process';
import * as fs from 'fs';
import * as log from './log';

export function convert(inFilename: string, outFilename: string, encoder: string, args: Array<string> = null): Promise<boolean> {
export function convert(inFilename: string, outFilename: string, encoder: string, args: Array<string> = []): Promise<boolean> {
return new Promise((resolve, reject) => {
if (fs.existsSync(outFilename.toString()) && fs.statSync(outFilename.toString()).mtime.getTime() > fs.statSync(inFilename.toString()).mtime.getTime()) {
resolve(true);
Expand All @@ -18,27 +18,25 @@ export function convert(inFilename: string, outFilename: string, encoder: string
let firstspace = encoder.indexOf(' ', dirend);
let exe = encoder.substr(0, firstspace);
let parts = encoder.substr(firstspace + 1).split(' ');
let options: string[] = [];
for (let i = 0; i < parts.length; ++i) {
let foundarg = false;
if (args !== null) {
for (let arg in args) {
if (parts[i] === '{' + arg + '}') {
options.push(args[arg]);
foundarg = true;
break;
}
}
let options: string[] = parts.map(part => {
// finds {i} in encoder parts and replaces with args[i] if they are specified
for (let i = 0; i < args.length; i++) {
if (part === '{' + i + '}') return args[i];
}
if (foundarg) continue;

if (parts[i] === '{in}') options.push(inFilename.toString());
else if (parts[i] === '{out}') options.push(outFilename.toString());
else options.push(parts[i]);
}
if (part == '{ffmpeg_ogg_options}') {
return ['-c:a', 'libvorbis', '-vn'];
}
if (part === '{in}') return inFilename.toString();
if (part === '{out}') return outFilename.toString();

return part;
}).flat().filter(option => option != undefined);

if (fs.existsSync(outFilename.toString())) {
fs.unlinkSync(outFilename.toString());
}

// About stdio ignore: https://stackoverflow.com/a/20792428
let process = child_process.spawn(exe, options, {
stdio: ['ignore', 'ignore', 'pipe'] // don't ignore stderr
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ export async function run(options: Options, loglog: any): Promise<string> {
}

if (!options.ogg && options.ffmpeg) {
options.ogg = options.ffmpeg + ' -nostdin -i {in} {out} -y';
options.ogg = options.ffmpeg + ' -nostdin -i {in} {ffmpeg_ogg_options} {out} -y';
}

if (!options.mp3 && options.ffmpeg) {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es2017",
"target": "es2019",
"module": "commonjs",
"sourceMap": true,
"outDir": "out",
Expand Down