From 037f7403fb3d7b472858f8419555f5f6b56f6bf1 Mon Sep 17 00:00:00 2001 From: walcutt Date: Wed, 25 Jun 2025 13:38:58 -0400 Subject: [PATCH] Added command to change season number --- src/command-config.js | 7 +++++++ src/commands/change-season.js | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/commands/change-season.js diff --git a/src/command-config.js b/src/command-config.js index 4556c4a..6e003eb 100644 --- a/src/command-config.js +++ b/src/command-config.js @@ -1,4 +1,5 @@ import { addSubtitleTrack } from "./commands/add-subs.js"; +import { changeSeason } from "./commands/change-season.js"; import { encodeX265 } from "./commands/encode-265.js"; import { extractToEpisodeNumber } from "./commands/extract-to-se.js"; import { finalizeFileNames } from "./commands/finalize-filenames.js"; @@ -24,6 +25,12 @@ export const CommandConfig = [ params: [], func: extractToEpisodeNumber, }, + { + name: 'Change Season Number', + commands: ['-se', '-season', '-change-season-number'], + params: ['SeasonNumber'], + func: changeSeason, + }, { name: 'Finalize File Names', commands: ['-o', '-output-as', '-rename-series'], diff --git a/src/commands/change-season.js b/src/commands/change-season.js new file mode 100644 index 0000000..f6ff153 --- /dev/null +++ b/src/commands/change-season.js @@ -0,0 +1,22 @@ +import fs from "fs"; +import { getFilenameObject } from "../parsing/parse-filename.js"; + +const seasonEpisodePattern = /[Ss][0-9]+[Ee]([0-9]+)/; + +export function changeSeason(inputDir, inputFile, outputDir, { SeasonNumber }) { + const match = inputFile.match(seasonEpisodePattern); + + if(match) { + const episodeNumber = match[1]; + + const newSeasonEpisode = `S${SeasonNumber}E${episodeNumber}`; + const filenameObject = getFilenameObject(inputFile); + + const toWrite = `${outputDir}${newSeasonEpisode}${filenameObject.extension}`; + + fs.cpSync(`${inputDir}${inputFile}`, `${toWrite}`); + return true; + } + + return false; +} \ No newline at end of file