Integrate ffmpeg
This commit is contained in:
parent
3c885a0c21
commit
f073419ac9
4
.gitignore
vendored
4
.gitignore
vendored
@ -2,6 +2,10 @@
|
|||||||
inputs/*
|
inputs/*
|
||||||
outputs/*
|
outputs/*
|
||||||
temp/*
|
temp/*
|
||||||
|
subs/*
|
||||||
|
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
#---> Node
|
#---> Node
|
||||||
# Logs
|
# Logs
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { addSubtitleTrack } from "./commands/add-subs.js";
|
||||||
import { extractToEpisodeNumber } from "./commands/extract-to-se.js";
|
import { extractToEpisodeNumber } from "./commands/extract-to-se.js";
|
||||||
import { finalizeFileNames } from "./commands/finalize-filenames.js";
|
import { finalizeFileNames } from "./commands/finalize-filenames.js";
|
||||||
|
|
||||||
@ -13,5 +14,11 @@ export const CommandConfig = [
|
|||||||
commands: ['-o'],
|
commands: ['-o'],
|
||||||
params: ['ShowName'],
|
params: ['ShowName'],
|
||||||
func: finalizeFileNames,
|
func: finalizeFileNames,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Add Subtitle Track',
|
||||||
|
commands: ['-s'],
|
||||||
|
params: ['SubtitleDirectory'],
|
||||||
|
func: addSubtitleTrack,
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
36
src/commands/add-subs.js
Normal file
36
src/commands/add-subs.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { getFilenameObject } from "../parsing/parse-filename.js";
|
||||||
|
import fs from 'fs';
|
||||||
|
import { exec } from "../shell/exec.js";
|
||||||
|
|
||||||
|
const AcceptedSubtitleExtensions = [
|
||||||
|
'.srt',
|
||||||
|
'.ass',
|
||||||
|
];
|
||||||
|
|
||||||
|
export async function addSubtitleTrack(inputDir, inputFile, outputDir, { SubtitleDirectory }) {
|
||||||
|
const filenameObject = getFilenameObject(inputFile);
|
||||||
|
const subFileEntries = fs.readdirSync(SubtitleDirectory, { encoding: 'utf-8', withFileTypes: true });
|
||||||
|
const subFilenameObjects = subFileEntries.filter(
|
||||||
|
ent => ent.isFile
|
||||||
|
).map(
|
||||||
|
ent => getFilenameObject(ent.name)
|
||||||
|
);
|
||||||
|
|
||||||
|
const validSubFilenameObjects = subFilenameObjects.filter(
|
||||||
|
fno => AcceptedSubtitleExtensions.includes(fno.extension)
|
||||||
|
);
|
||||||
|
|
||||||
|
const match = validSubFilenameObjects.find(
|
||||||
|
fno => fno.prefix === filenameObject.prefix
|
||||||
|
);
|
||||||
|
|
||||||
|
if(match) {
|
||||||
|
await exec(
|
||||||
|
`ffmpeg -i ${inputDir}${inputFile} -i ${SubtitleDirectory}${match.fullName} -map 0 -map 1:s -c copy -metadata:s:s:0 language=eng -disposition:s:0 default ${outputDir}${filenameObject.prefix}.mkv`
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import { getFilenameObject } from '../parsing/parse-filename.js';
|
||||||
|
|
||||||
const acceptedPatternMappings = [
|
const acceptedPatternMappings = [
|
||||||
{
|
{
|
||||||
@ -33,19 +34,15 @@ const acceptedPatternMappings = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const extensionPattern = /(\..*)$/;
|
|
||||||
|
|
||||||
export async function extractToEpisodeNumber(inputDir, inputFile, outputDir, options) {
|
export async function extractToEpisodeNumber(inputDir, inputFile, outputDir, options) {
|
||||||
for(let i = 0; i < acceptedPatternMappings.length; i++) {
|
for(let i = 0; i < acceptedPatternMappings.length; i++) {
|
||||||
const matches = inputFile.match(acceptedPatternMappings[i].pattern);
|
const matches = inputFile.match(acceptedPatternMappings[i].pattern);
|
||||||
if(matches?.length > 0) {
|
if(matches?.length > 0) {
|
||||||
const outputFileName = acceptedPatternMappings[i].mapper(matches);
|
const outputFileName = acceptedPatternMappings[i].mapper(matches);
|
||||||
|
|
||||||
const extensionMatches = inputFile.match(extensionPattern);
|
const filenameObject = getFilenameObject(inputFile);
|
||||||
|
|
||||||
const extension = extensionMatches ? extensionMatches[1] : '';
|
const toWrite = `${outputDir}${outputFileName}${filenameObject.extension}`;
|
||||||
|
|
||||||
const toWrite = `${outputDir}${outputFileName}${extension}`;
|
|
||||||
|
|
||||||
fs.cpSync(`${inputDir}${inputFile}`, `${toWrite}`);
|
fs.cpSync(`${inputDir}${inputFile}`, `${toWrite}`);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
24
src/parsing/parse-filename.js
Normal file
24
src/parsing/parse-filename.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
const extensionPattern = /(\..*)$/;
|
||||||
|
|
||||||
|
export function getFilenameObject(filenameString) {
|
||||||
|
const extensionMatches = filenameString.match(extensionPattern);
|
||||||
|
|
||||||
|
if(extensionMatches?.length > 0) {
|
||||||
|
const extension = extensionMatches[1];
|
||||||
|
|
||||||
|
const len = extension.length;
|
||||||
|
const prefix = filenameString.slice(0, -1 * len);
|
||||||
|
|
||||||
|
return {
|
||||||
|
prefix: prefix,
|
||||||
|
extension: extension,
|
||||||
|
fullName: filenameString,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
prefix: filenameString,
|
||||||
|
extension: '',
|
||||||
|
fullName: filenameString,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/shell/exec.js
Normal file
8
src/shell/exec.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import child_process from 'node:child_process';
|
||||||
|
import { promisify } from 'node:util';
|
||||||
|
|
||||||
|
const execPromise = promisify(child_process.exec);
|
||||||
|
|
||||||
|
export async function exec(commandString) {
|
||||||
|
return await execPromise(commandString);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user