Skip to content

Commit

Permalink
fix: season number
Browse files Browse the repository at this point in the history
  • Loading branch information
a1mersnow committed Nov 18, 2023
1 parent 04923fb commit c0669b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
5 changes: 4 additions & 1 deletion src/utils/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down

0 comments on commit c0669b1

Please sign in to comment.