diff --git a/README.md b/README.md index 66c00cb..4820c01 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ The [command-line interface](http://en.wikipedia.org/wiki/Command-line_interface -u, --user The e-mail address or username. -c, --cache Disables the cache. -m, --merge Disables merging subtitles and videos. + -e, --episodes Episode list. Read documentation on how to use -f, --format The subtitle format. (Default: ass) -o, --output The output path. -s, --series The series override. @@ -85,7 +86,7 @@ The [command-line interface](http://en.wikipedia.org/wiki/Command-line_interface #### Batch-mode -When no sequence of series addresses is provided, the batch-mode source file will be read (which is *CrunchyRoll.txt* in the current work directory. Each line in this file is processed as a seperate command-line statement. This makes it ideal to manage a large sequence of series addresses with variating command-line options or incremental episode updates. +When no sequence of series addresses is provided, the batch-mode source file will be read (which is *CrunchyRoll.txt* in the current work directory. Each line in this file is processed contain the URL of a series and can support some of the command line paramter (like *-e*). This makes it ideal to manage a large sequence of series addresses. #### Examples @@ -100,12 +101,29 @@ Download *Fairy Tail* to the current work directory: Download *Fairy Tail* to `C:\Anime`: crunchy --output C:\Anime http://www.crunchyroll.com/fairy-tail - + Download episode 42 of *Fairy Tail* to `C:\Anime`: crunchy --output C:\Anime @http://www.crunchyroll.com/fairy-tail/episode-46-the-silver-labyrinth-662721 - Notice the '@' in front of the URL, it is there to tell Crunchy that the URL is an episode URL and not a series URL. + *Notice the '@' in front of the URL, it is there to tell Crunchy that the URL is an episode URL and not a series URL.* + + or + crunchy --output C:\Anime http://www.crunchyroll.com/fairy-tail -e 42 + +Download episode 10 to 42 (both included) of *Fairy Tail*: + + crunchy http://www.crunchyroll.com/fairy-tail -e 10-42 + +Download episode up to 42 (included) of *Fairy Tail*: + + crunchy http://www.crunchyroll.com/fairy-tail -e -42 + +Download episodes starting from 42 to the last available of *Fairy Tail*: + + crunchy http://www.crunchyroll.com/fairy-tail -e 42- + + #### Command line parameters @@ -123,6 +141,7 @@ Download episode 42 of *Fairy Tail* to `C:\Anime`: ##### Settings +* `-e or --episodes ` set an episode * `-f or --format ` sets the subtitle format. (Default: ass) * `-o or --output ` sets the output path. * `-s or --series ` sets the series override. diff --git a/src/batch.ts b/src/batch.ts index 4171c12..1d24360 100644 --- a/src/batch.ts +++ b/src/batch.ts @@ -149,6 +149,52 @@ function split(value: string): string[] return pieces; } +function get_min_filter(filter: string): number +{ + if (filter !== undefined) + { + const tok = filter.split('-'); + + if (tok.length > 2) + { + log.error('Invalid episode filter \'' + filter + '\''); + process.exit(-1); + } + + if (tok[0] !== '') + { + return parseInt(tok[0], 10); + } + } + return 0; +} + +function get_max_filter(filter: string): number +{ + if (filter !== undefined) + { + const tok = filter.split('-'); + + if (tok.length > 2) + { + log.error('Invalid episode filter \'' + filter + '\''); + process.exit(-1); + } + + if ((tok.length > 1) && (tok[1] !== '')) + { + /* We have a max value */ + return parseInt(tok[1], 10); + } + else if ((tok.length === 1) && (tok[0] !== '')) + { + /* A single episode has been requested */ + return parseInt(tok[0], 10); + } + } + return +Infinity; +} + /** * Parses the configuration or reads the batch-mode file for tasks. */ @@ -156,11 +202,10 @@ function tasks(config: IConfigLine, batchPath: string, done: (err: Error, tasks? { if (config.args.length) { - const configIn = config; - return done(null, config.args.map((addressIn) => { - return {address: addressIn, config: configIn, retry: config.retry}; + return {address: addressIn, retry: config.retry, + episode_min: get_min_filter(config.episodes), episode_max: get_max_filter(config.episodes)}; })); } @@ -196,7 +241,8 @@ function tasks(config: IConfigLine, batchPath: string, done: (err: Error, tasks? return; } - map.push({address: addressIn, config: lineConfig, retry: config.retry}); + map.push({address: addressIn, retry: lineConfig.retry, + episode_min: get_min_filter(lineConfig.episodes), episode_max: get_max_filter(lineConfig.episodes)}); }); }); done(null, map); @@ -216,6 +262,8 @@ function parse(args: string[]): IConfigLine // Disables .option('-c, --cache', 'Disables the cache.') .option('-m, --merge', 'Disables merging subtitles and videos.') + // Episode filter + .option('-e, --episodes ', 'Episode list. Read documentation on how to use') // Settings .option('-f, --format ', 'The subtitle format. (Default: ass)') .option('-o, --output ', 'The output path.') diff --git a/src/interface/IConfig.d.ts b/src/interface/IConfig.d.ts index beec3ee..ed9b697 100644 --- a/src/interface/IConfig.d.ts +++ b/src/interface/IConfig.d.ts @@ -5,6 +5,7 @@ interface IConfig { // Disables cache?: boolean; merge?: boolean; + episodes?: string; // Settings format?: string; output?: string; diff --git a/src/interface/IConfigTask.d.ts b/src/interface/IConfigTask.d.ts index adbde3b..a0bf423 100644 --- a/src/interface/IConfigTask.d.ts +++ b/src/interface/IConfigTask.d.ts @@ -1,5 +1,6 @@ interface IConfigTask { address: string; - config: IConfigLine; retry: number; + episode_min: number; + episode_max: number; } diff --git a/src/series.ts b/src/series.ts index c9a9d9c..450ad76 100644 --- a/src/series.ts +++ b/src/series.ts @@ -124,6 +124,14 @@ function download(cache: {[address: string]: number}, config: IConfig, task: IConfigTask, item: ISeriesEpisode, done: (err: Error, ign: boolean) => void) { + const episodeNumber = parseInt(item.episode, 10); + + if ( (episodeNumber < task.episode_min) || + (episodeNumber > task.episode_max) ) + { + return done(null, false); + } + const address = url.resolve(task.address, item.address); if (cache[address])