diff --git a/src/command-config.js b/src/command-config.js index 7ff9716..6010eef 100644 --- a/src/command-config.js +++ b/src/command-config.js @@ -1,31 +1,73 @@ import { addSubtitleTrack } from "./commands/add-subs.js"; +import { encodeX265 } from "./commands/encode-265.js"; import { extractToEpisodeNumber } from "./commands/extract-to-se.js"; import { finalizeFileNames } from "./commands/finalize-filenames.js"; +import { preferAudio } from "./commands/prefer-audio.js"; +import { preferSubtitles } from "./commands/prefer-subs.js"; +import { removeSubtitles } from "./commands/remove-subs.js"; +import { saveSubtitlesToFile } from "./commands/save-subtitles-to-file.js"; import { convertToMkv } from "./commands/to-mkv.js"; +import { convertToMp4 } from "./commands/to-mp4.js"; export const CommandConfig = [ { name: 'Extract To Episode Number', - commands: ['-x'], + commands: ['-x', '-extract', '-extract-episode-number'], params: [], func: extractToEpisodeNumber, }, { name: 'Finalize File Names', - commands: ['-o'], + commands: ['-o', '-output-as', '-rename'], params: ['ShowName'], func: finalizeFileNames, }, { name: 'Add Subtitle Track', - commands: ['-s'], + commands: ['-s', '-subtitle', '-add-subtitles'], params: ['SubtitleDirectory'], func: addSubtitleTrack, }, { name: 'Repackage to Mkv', - commands: ['-m'], + commands: ['-mkv', '-to-mkv'], params: [], func: convertToMkv, + }, + { + name: 'Repackage to Mp4', + commands: ['-mp4', '-to-mp4'], + params: [], + func: convertToMp4, + }, + { + name: 'Re-encode as x265', + commands: ['-e', '-encode-x265'], + params: ['Crf', 'Preset'], + func: encodeX265, + }, + { + name: 'Change preferred audio', + commands: ['-pa', '-prefer-audio'], + params: ['TrackNumber'], + func: preferAudio, + }, + { + name: 'Change preferred subtitle track', + commands: ['-ps', '-prefer-subtitles'], + params: ['TrackNumber'], + func: preferSubtitles, + }, + { + name: 'Generate subtitle files', + commands: ['-save-subs'], + params: ['TrackNumber', 'FileType'], + func: saveSubtitlesToFile, + }, + { + name: 'Remove subtitles', + commands: ['-rs', '-remove-subtitles'], + params: [], + func: removeSubtitles, } ]; \ No newline at end of file diff --git a/src/commands/encode-265.js b/src/commands/encode-265.js new file mode 100644 index 0000000..db4191e --- /dev/null +++ b/src/commands/encode-265.js @@ -0,0 +1,15 @@ +import { getFilenameObject } from "../parsing/parse-filename.js"; +import { exec } from "../shell/exec.js"; + +export async function encodeX265(inputDir, inputFile, outputDir, { Crf, Preset }) { + const filenameObject = getFilenameObject(inputFile); + if(filenameObject.extension !== '.mkv') { + return false; + } + + await exec( + `ffmpeg -i ${inputDir}${inputFile} -map 0 -c copy -c:v libx265 -crf ${Crf} -preset ${Preset} ${outputDir}${inputFile}` + ); + + return true; +} \ No newline at end of file diff --git a/src/commands/prefer-audio.js b/src/commands/prefer-audio.js new file mode 100644 index 0000000..b890d1a --- /dev/null +++ b/src/commands/prefer-audio.js @@ -0,0 +1,15 @@ +import { getFilenameObject } from "../parsing/parse-filename.js"; +import { exec } from "../shell/exec.js"; + +export async function preferAudio(inputDir, inputFile, outputDir, { TrackNumber }) { + const filenameObject = getFilenameObject(inputFile); + if(filenameObject.extension !== '.mkv') { + return false; + } + + await exec( + `ffmpeg -i ${inputDir}${inputFile} -map 0 -c copy -disposition:a 0 -disposition:a:${TrackNumber} default ${outputDir}${inputFile}` + ); + + return true; +} \ No newline at end of file diff --git a/src/commands/prefer-subs.js b/src/commands/prefer-subs.js new file mode 100644 index 0000000..329ff68 --- /dev/null +++ b/src/commands/prefer-subs.js @@ -0,0 +1,15 @@ +import { getFilenameObject } from "../parsing/parse-filename.js"; +import { exec } from "../shell/exec.js"; + +export async function preferSubtitles(inputDir, inputFile, outputDir, { TrackNumber }) { + const filenameObject = getFilenameObject(inputFile); + if(filenameObject.extension !== '.mkv') { + return false; + } + + await exec( + `ffmpeg -i ${inputDir}${inputFile} -map 0 -c copy -disposition:s 0 -disposition:s:${TrackNumber} default ${outputDir}${inputFile}` + ); + + return true; +} \ No newline at end of file diff --git a/src/commands/remove-subs.js b/src/commands/remove-subs.js new file mode 100644 index 0000000..57b4c57 --- /dev/null +++ b/src/commands/remove-subs.js @@ -0,0 +1,9 @@ +import { exec } from "../shell/exec.js"; + +export async function removeSubtitles(inputDir, inputFile, outputDir, options) { + await exec( + `ffmpeg -i ${inputDir}${inputFile} -map 0:v -map 0:a -c copy ${outputDir}${inputFile}` + ); + + return true; +} \ No newline at end of file diff --git a/src/commands/save-subtitles-to-file.js b/src/commands/save-subtitles-to-file.js new file mode 100644 index 0000000..70028ac --- /dev/null +++ b/src/commands/save-subtitles-to-file.js @@ -0,0 +1,12 @@ +import { getFilenameObject } from "../parsing/parse-filename.js"; +import { exec } from "../shell/exec.js"; + +export async function saveSubtitlesToFile(inputDir, inputFile, outputDir, { TrackNumber, FileType }) { + const filenameObject = getFilenameObject(inputFile); + + await exec( + `ffmpeg -i ${inputDir}${inputFile} -map 0:s:${TrackNumber} ${outputDir}${filenameObject.prefix}.${FileType}` + ); + + return true; +} \ No newline at end of file diff --git a/src/commands/to-mkv.js b/src/commands/to-mkv.js index 988c3f2..d4bafef 100644 --- a/src/commands/to-mkv.js +++ b/src/commands/to-mkv.js @@ -1,13 +1,6 @@ import { getFilenameObject } from "../parsing/parse-filename.js"; import { exec } from "../shell/exec.js"; - -const AcceptedMovieExtensions = [ - '.mp4', - '.avi', - '.mkv', - '.mov', - '.webm' -]; +import { AcceptedMovieExtensions } from "../constants/movie-extensions.js"; export async function convertToMkv(inputDir, inputFile, outputDir, options) { const filenameObject = getFilenameObject(inputFile); diff --git a/src/commands/to-mp4.js b/src/commands/to-mp4.js new file mode 100644 index 0000000..2b063df --- /dev/null +++ b/src/commands/to-mp4.js @@ -0,0 +1,16 @@ +import { getFilenameObject } from "../parsing/parse-filename.js"; +import { exec } from "../shell/exec.js"; +import { AcceptedMovieExtensions } from "../constants/movie-extensions.js"; + +export async function convertToMp4(inputDir, inputFile, outputDir, options) { + const filenameObject = getFilenameObject(inputFile); + if(!AcceptedMovieExtensions.includes(filenameObject.extension)) { + return false; + } + + await exec( + `ffmpeg -i ${inputDir}${inputFile} -map 0 -c copy ${outputDir}${filenameObject.prefix}.mp4` + ); + + return true; +} \ No newline at end of file diff --git a/src/constants/movie-extensions.js b/src/constants/movie-extensions.js new file mode 100644 index 0000000..c825fb3 --- /dev/null +++ b/src/constants/movie-extensions.js @@ -0,0 +1,7 @@ +export const AcceptedMovieExtensions = [ + '.mp4', + '.avi', + '.mkv', + '.mov', + '.webm' +]; \ No newline at end of file