Skip to content

Instantly share code, notes, and snippets.

@nickzelei
Last active May 20, 2023 18:07
Show Gist options
  • Select an option

  • Save nickzelei/965a86a82bbe9876e26f4948a6ed991d to your computer and use it in GitHub Desktop.

Select an option

Save nickzelei/965a86a82bbe9876e26f4948a6ed991d to your computer and use it in GitHub Desktop.
DragonBall Subbed File Rename Script
/*
* Quick and dirty script to rename files downloaded from: https://archive.org/details/dragon-ball-remastered-bluray-complete-e-1-e-153-eng-dub
* I only downloaded the mkv files but this will rename them well enough for Sonarr to be able to properly organize.
*/
import fs from 'fs';
const matcher = /Dragonball\sS01[E|e](\d+)(.+)/i;
(async () => {
const rootDir = `/Volumes/media/tvshows/Dragon Ball`;
const filenames = (await fs.promises.readdir(rootDir)).filter((fn) => fn !== '.DS_Store');
const results = filenames.map((fn) => {
const group = fn.match(matcher);
if (!group) {
return;
}
const [,oldEpisodeNum, episodeName] = group;
const episodeNum = parseInt(oldEpisodeNum, 10);
if (episodeNum >= 14 && episodeNum <= 28) {
const newEpisodeNum = episodeNum - 13;
return {old: fn, new: `Dragonball S02E${newEpisodeNum}${episodeName}`}
} else if (episodeNum >= 29 && episodeNum <= 68) {
const newEpisodeNum = episodeNum - (28);
return {old: fn, new: `Dragonball S03E${newEpisodeNum}${episodeName}`}
} else if (episodeNum >= 69 && episodeNum <= 101) {
const newEpisodeNum = episodeNum - (68);
return {old: fn, new: `Dragonball S04E${newEpisodeNum}${episodeName}`}
} else if (episodeNum >= 102 && episodeNum <= 132) {
const newEpisodeNum = episodeNum - (101);
return {old: fn, new: `Dragonball S05E${newEpisodeNum}${episodeName}`}
} else if (episodeNum >= 133) {
const newEpisodeNum = episodeNum - (132);
return {old: fn, new: `Dragonball S06E${newEpisodeNum}${episodeName}`}
} else {
return {old: fn, new: `Dragonball S01E${episodeNum}${episodeName}`}
}
});
await Promise.all(
results.filter(x => x).map((result) => {
return fs.promises.rename(`${rootDir}/${result.old}`, `${rootDir}/${result.new}`)
})
)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment