From cee53fb113150c8a4277155f80556c578181f7cd Mon Sep 17 00:00:00 2001 From: Godzil Date: Fri, 20 Jul 2018 22:22:35 +0100 Subject: [PATCH] Fix for #78 (and a bit of cleanup) --- src/batch.ts | 2 +- src/episode.ts | 20 ++++++++------------ src/interface/IConfig.d.ts | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/batch.ts b/src/batch.ts index 1d24360..817d65c 100644 --- a/src/batch.ts +++ b/src/batch.ts @@ -268,11 +268,11 @@ function parse(args: string[]): IConfigLine .option('-f, --format ', 'The subtitle format. (Default: ass)') .option('-o, --output ', 'The output path.') .option('-s, --series ', 'The series override.') - .option('-n, --filename ', 'The name override.') .option('-t, --tag ', 'The subgroup. (Default: CrunchyRoll)', 'CrunchyRoll') .option('-r, --resolution ', 'The video resolution. (Default: 1080 (360, 480, 720, 1080))', '1080') .option('-g, --rebuildcrp', 'Rebuild the crpersistant file.') + .option('-n, --nametmpl ', 'Output name template', '{SERIES_TITLE} - s{SEASON_NUMBER}e{EPISODE_NUMBER} - [{TAG}]') .option('-b, --batch ', 'Batch file', 'CrunchyRoll.txt') .option('--verbose', 'Make tool verbose') .option('--debug', 'Create a debug file. Use only if requested!') diff --git a/src/episode.ts b/src/episode.ts index f889591..512dd47 100644 --- a/src/episode.ts +++ b/src/episode.ts @@ -74,11 +74,10 @@ function sanitiseFileName(str: string) */ function download(config: IConfig, page: IEpisodePage, player: IEpisodePlayer, done: (err: Error, ign: boolean) => void) { - let series = config.series || page.series; + const serieFolder = sanitiseFileName(config.series || page.series); - series = sanitiseFileName(series); - let fileName = sanitiseFileName(name(config, page, series, '')); - let filePath = path.join(config.output || process.cwd(), series, fileName); + let fileName = sanitiseFileName(generateName(config, page)); + let filePath = path.join(config.output || process.cwd(), serieFolder, fileName); if (fileExist(filePath + '.mkv')) { @@ -95,8 +94,8 @@ function download(config: IConfig, page: IEpisodePage, player: IEpisodePlayer, d do { count = count + 1; - fileName = sanitiseFileName(name(config, page, series, '-' + count)); - filePath = path.join(config.output || process.cwd(), series, fileName); + fileName = sanitiseFileName(generateName(config, page, '-' + count)); + filePath = path.join(config.output || process.cwd(), serieFolder, fileName); } while (fileExist(filePath + '.mkv')); log.warn('Renaming to \'' + fileName + '\'...'); @@ -215,19 +214,16 @@ function downloadVideo(config: IConfig, page: IEpisodePage, player: IEpisodePla /** * Names the file based on the config, page, series and tag. */ -function name(config: IConfig, page: IEpisodePage, series: string, extra: string) +function generateName(config: IConfig, page: IEpisodePage, extra = '') { const episodeNum = parseInt(page.episode, 10); const volumeNum = parseInt(page.volume, 10); const episode = (episodeNum < 10 ? '0' : '') + page.episode; const volume = (volumeNum < 10 ? '0' : '') + page.volume; const tag = config.tag || 'CrunchyRoll'; + const series = config.series || page.series; - if (!page.filename) { - return page.series + ' - s' + volume + 'e' + episode + ' - [' + tag + ']' + extra; - } - - return page.filename + return config.nametmpl .replace(/{EPISODE_ID}/g, page.id.toString()) .replace(/{EPISODE_NUMBER}/g, episode) .replace(/{SEASON_NUMBER}/g, volume) diff --git a/src/interface/IConfig.d.ts b/src/interface/IConfig.d.ts index ed9b697..798d2ce 100644 --- a/src/interface/IConfig.d.ts +++ b/src/interface/IConfig.d.ts @@ -10,7 +10,7 @@ interface IConfig { format?: string; output?: string; series?: string; - filename?: string; + nametmpl?: string; tag?: string; resolution?: string; video_format?: string;