Add a new episode filter and completely remove some dependencies on the config object.
This commit is contained in:
parent
8c1e0f2e0c
commit
6765b517ec
23
README.md
23
README.md
@ -71,6 +71,7 @@ The [command-line interface](http://en.wikipedia.org/wiki/Command-line_interface
|
||||
-u, --user <s> The e-mail address or username.
|
||||
-c, --cache Disables the cache.
|
||||
-m, --merge Disables merging subtitles and videos.
|
||||
-e, --episodes <s> Episode list. Read documentation on how to use
|
||||
-f, --format <s> The subtitle format. (Default: ass)
|
||||
-o, --output <s> The output path.
|
||||
-s, --series <s> 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
|
||||
|
||||
@ -105,7 +106,24 @@ 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 <s>` set an episode
|
||||
* `-f or --format <s>` sets the subtitle format. (Default: ass)
|
||||
* `-o or --output <s>` sets the output path.
|
||||
* `-s or --series <s>` sets the series override.
|
||||
|
||||
56
src/batch.ts
56
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 <s>', 'Episode list. Read documentation on how to use')
|
||||
// Settings
|
||||
.option('-f, --format <s>', 'The subtitle format. (Default: ass)')
|
||||
.option('-o, --output <s>', 'The output path.')
|
||||
|
||||
1
src/interface/IConfig.d.ts
vendored
1
src/interface/IConfig.d.ts
vendored
@ -5,6 +5,7 @@ interface IConfig {
|
||||
// Disables
|
||||
cache?: boolean;
|
||||
merge?: boolean;
|
||||
episodes?: string;
|
||||
// Settings
|
||||
format?: string;
|
||||
output?: string;
|
||||
|
||||
3
src/interface/IConfigTask.d.ts
vendored
3
src/interface/IConfigTask.d.ts
vendored
@ -1,5 +1,6 @@
|
||||
interface IConfigTask {
|
||||
address: string;
|
||||
config: IConfigLine;
|
||||
retry: number;
|
||||
episode_min: number;
|
||||
episode_max: number;
|
||||
}
|
||||
|
||||
@ -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])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user