From c0669b1af0ce6827ddbe4a11475f62c2cd146990 Mon Sep 17 00:00:00 2001 From: a1mer Date: Sat, 18 Nov 2023 21:28:10 +0800 Subject: [PATCH] fix: season number --- package.json | 2 +- src/utils/rename.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7d61426..c80aca9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "aliyundrive-rename", "type": "module", - "version": "0.2.1", + "version": "0.2.2", "private": true, "packageManager": "pnpm@8.10.5", "description": "Batch rename files of aliyundrive.", diff --git a/src/utils/rename.ts b/src/utils/rename.ts index dbda399..f585565 100644 --- a/src/utils/rename.ts +++ b/src/utils/rename.ts @@ -12,7 +12,10 @@ export const SeasonEpisodeExtract = /S(?:eason)?[._\- ]?([0-9]{1,3})(?![0-9])(?: export function getNewNameByExtract(oldName: string, prefix: string, season: string) { const [_, _s, epm1, epm2, epm3, epm4] = oldName.match(SeasonEpisodeExtract) || [] let episode = epm1 || epm2 || epm3 || epm4 - season = String(+season).padStart(2, '0') + season ||= '1' + const seasonNumber = Number.parseInt(season) + const seasonNumberIsValid = Number.isNaN(seasonNumber) && seasonNumber < 100 + season = String(seasonNumberIsValid ? seasonNumber : 1).padStart(2, '0') episode = String(+episode).padStart(3, '0') if (!episode || !season) return ''