Add an episode filter.
This commit is contained in:
parent
66f62d3aa1
commit
4b0c993969
@ -3,7 +3,7 @@
|
|||||||
*CrunchyRoll.js* is capable of saving *anime* episodes from the popular *CrunchyRoll*
|
*CrunchyRoll.js* is capable of saving *anime* episodes from the popular *CrunchyRoll*
|
||||||
streaming service. An episode is stored in the original video format (often
|
streaming service. An episode is stored in the original video format (often
|
||||||
H.264 in a MP4 container) and the configured subtitle format (ASS or SRT). The
|
H.264 in a MP4 container) and the configured subtitle format (ASS or SRT). The
|
||||||
two output files are optionally muxed into a single MKV file.
|
two output files are then merged into a single MKV file.
|
||||||
|
|
||||||
## Motivation
|
## Motivation
|
||||||
|
|
||||||
|
|||||||
@ -67,6 +67,8 @@ function _parse(args) {
|
|||||||
// Disables
|
// Disables
|
||||||
.option('-c, --cache', 'Disables the cache.')
|
.option('-c, --cache', 'Disables the cache.')
|
||||||
.option('-m, --merge', 'Disables merging subtitles and videos.')
|
.option('-m, --merge', 'Disables merging subtitles and videos.')
|
||||||
|
// Filters
|
||||||
|
.option('-e, --episode <i>', 'The episode filter.')
|
||||||
// Settings
|
// Settings
|
||||||
.option('-f, --format <s>', 'The subtitle format. (Default: ass)')
|
.option('-f, --format <s>', 'The subtitle format. (Default: ass)')
|
||||||
.option('-o, --output <s>', 'The output path.')
|
.option('-o, --output <s>', 'The output path.')
|
||||||
|
|||||||
@ -22,9 +22,7 @@ module.exports = function (config, address, done) {
|
|||||||
var i = 0;
|
var i = 0;
|
||||||
(function next() {
|
(function next() {
|
||||||
if (i >= page.episodes.length) return done();
|
if (i >= page.episodes.length) return done();
|
||||||
var episode = page.episodes[i];
|
_download(cache, config, address, page.episodes[i], function(err) {
|
||||||
var episodeAddress = url.resolve(address, episode.address);
|
|
||||||
_download(cache, config, episodeAddress, function(err) {
|
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
var newCache = JSON.stringify(cache, null, ' ');
|
var newCache = JSON.stringify(cache, null, ' ');
|
||||||
fs.writeFile(persistentPath, newCache, function(err) {
|
fs.writeFile(persistentPath, newCache, function(err) {
|
||||||
@ -42,10 +40,16 @@ module.exports = function (config, address, done) {
|
|||||||
* Downloads the episode.
|
* Downloads the episode.
|
||||||
* @param {Object.<string, string>} cache
|
* @param {Object.<string, string>} cache
|
||||||
* @param {Object} config
|
* @param {Object} config
|
||||||
* @param {string} address
|
* @param {string} baseAddress
|
||||||
|
* @param {Object} data
|
||||||
* @param {function(Error)} done
|
* @param {function(Error)} done
|
||||||
*/
|
*/
|
||||||
function _download(cache, config, address, done) {
|
function _download(cache, config, baseAddress, data, done) {
|
||||||
|
if (typeof config.episode === 'number') {
|
||||||
|
if (config.episode > 0 && data.number < config.episode) return done();
|
||||||
|
if (config.episode < 0 && -config.episode < data.number) return done();
|
||||||
|
}
|
||||||
|
var address = url.resolve(baseAddress, data.address);
|
||||||
if (cache[address]) return done();
|
if (cache[address]) return done();
|
||||||
episode(config, address, function(err) {
|
episode(config, address, function(err) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
@ -73,7 +77,7 @@ function _page(address, done) {
|
|||||||
var title = ($(el).children('.series-title').text() || '').trim();
|
var title = ($(el).children('.series-title').text() || '').trim();
|
||||||
var match = /([0-9]+)$/.exec(title);
|
var match = /([0-9]+)$/.exec(title);
|
||||||
if (!address || !match) return;
|
if (!address || !match) return;
|
||||||
episodes.push({address: address, episode: parseInt(match[0], 10)});
|
episodes.push({address: address, number: parseInt(match[0], 10)});
|
||||||
});
|
});
|
||||||
done(undefined, {episodes: episodes.reverse(), series: title});
|
done(undefined, {episodes: episodes.reverse(), series: title});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user