Add a similar mechanism for episodes downloads.

If it can't fetch it after a couple of retry (5 by default, can be changed on the command line) it will just ignore it and go to the next episode.
This commit is contained in:
Godzil 2018-06-11 21:33:31 +01:00
parent 7d6f762f59
commit 67735fb52a
2 changed files with 36 additions and 15 deletions

View File

@ -2,4 +2,5 @@ interface ISeriesEpisode {
address: string; address: string;
episode: string; episode: string;
volume: number; volume: number;
retry: number;
} }

View File

@ -56,9 +56,26 @@ export default function(config: IConfig, address: string, done: (err: Error) =>
{ {
if (errD) if (errD)
{ {
return done(errD); if (page.episodes[i].retry <= 0)
{
console.error(err.stack || err);
console.error('Cannot fetch episode "s' + page.episodes[i].volume + 'e' + page.episodes[i].episode +
'", please rerun later');
} }
else
{
if (config.verbose)
{
console.error(errD.stack || errD);
}
console.warn('Retrying to fetch episode "s' + page.episodes[i].volume + 'e' + page.episodes[i].episode +
'" - Retry ' + page.episodes[i].retry + ' / ' + config.retry);
page.episodes[i].retry -= 1;
}
next();
}
else
{
if ((ignored === false) || (ignored === undefined)) if ((ignored === false) || (ignored === undefined))
{ {
const newCache = JSON.stringify(cache, null, ' '); const newCache = JSON.stringify(cache, null, ' ');
@ -78,6 +95,7 @@ export default function(config: IConfig, address: string, done: (err: Error) =>
i += 1; i += 1;
next(); next();
} }
}
}); });
})(); })();
}); });
@ -152,6 +170,7 @@ function page(config: IConfig, address: string, done: (err: Error, result?: ISer
address: address.substr(1), address: address.substr(1),
episode: '', episode: '',
volume: 0, volume: 0,
retry: config.retry,
}); });
done(null, {episodes: episodes.reverse(), series: ''}); done(null, {episodes: episodes.reverse(), series: ''});
} }
@ -191,6 +210,7 @@ function page(config: IConfig, address: string, done: (err: Error, result?: ISer
address: url, address: url,
episode: episode[1], episode: episode[1],
volume: volume ? parseInt(volume[0], 10) : 1, volume: volume ? parseInt(volume[0], 10) : 1,
retry: config.retry,
}); });
}); });
if (episodeCount === 0) if (episodeCount === 0)