瀏覽代碼

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.
Godzil 6 年之前
父節點
當前提交
72b6dd6978
共有 2 個文件被更改,包括 36 次插入15 次删除
  1. 1 0
      src/interface/ISeriesEpisode.d.ts
  2. 35 15
      src/series.ts

+ 1 - 0
src/interface/ISeriesEpisode.d.ts

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

+ 35 - 15
src/series.ts

@@ -56,27 +56,45 @@ export default function(config: IConfig, address: string, done: (err: Error) =>
         {
           if (errD)
           {
-            return done(errD);
-          }
-
-          if ((ignored === false) || (ignored === undefined))
-          {
-            const newCache = JSON.stringify(cache, null, '  ');
-            fs.writeFile(persistentPath, newCache, (errW: Error) =>
+            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 (errW)
+              if (config.verbose)
               {
-                return done(errW);
+                console.error(errD.stack || errD);
               }
-
-              i += 1;
-              next();
-            });
+              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
           {
-            i += 1;
-            next();
+            if ((ignored === false) || (ignored === undefined))
+            {
+              const newCache = JSON.stringify(cache, null, '  ');
+              fs.writeFile(persistentPath, newCache, (errW: Error) =>
+              {
+                if (errW)
+                {
+                  return done(errW);
+                }
+
+                i += 1;
+                next();
+              });
+            }
+            else
+            {
+              i += 1;
+              next();
+            }
           }
         });
       })();
@@ -152,6 +170,7 @@ function page(config: IConfig, address: string, done: (err: Error, result?: ISer
       address: address.substr(1),
       episode: '',
       volume: 0,
+      retry: config.retry,
     });
     done(null, {episodes: episodes.reverse(), series: ''});
   }
@@ -191,6 +210,7 @@ function page(config: IConfig, address: string, done: (err: Error, result?: ISer
           address: url,
           episode: episode[1],
           volume: volume ? parseInt(volume[0], 10) : 1,
+          retry: config.retry,
         });
       });
       if (episodeCount === 0)