Browse Source

Fix for #78 (and a bit of cleanup)

Godzil 5 years ago
parent
commit
cee53fb113
3 changed files with 10 additions and 14 deletions
  1. 1 1
      src/batch.ts
  2. 8 12
      src/episode.ts
  3. 1 1
      src/interface/IConfig.d.ts

+ 1 - 1
src/batch.ts

@@ -268,11 +268,11 @@ function parse(args: string[]): IConfigLine
     .option('-f, --format <s>', 'The subtitle format. (Default: ass)')
     .option('-o, --output <s>', 'The output path.')
     .option('-s, --series <s>', 'The series override.')
-    .option('-n, --filename <s>', 'The name override.')
     .option('-t, --tag <s>', 'The subgroup. (Default: CrunchyRoll)', 'CrunchyRoll')
     .option('-r, --resolution <s>', 'The video resolution. (Default: 1080 (360, 480, 720, 1080))',
             '1080')
     .option('-g, --rebuildcrp', 'Rebuild the crpersistant file.')
+    .option('-n, --nametmpl <s>', 'Output name template', '{SERIES_TITLE} - s{SEASON_NUMBER}e{EPISODE_NUMBER} - [{TAG}]')
     .option('-b, --batch <s>', 'Batch file', 'CrunchyRoll.txt')
     .option('--verbose', 'Make tool verbose')
     .option('--debug', 'Create a debug file. Use only if requested!')

+ 8 - 12
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)

+ 1 - 1
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;