Browse Source

- Support more episode naming schemes
- Display when we are going to fetch from a single URL (@http://...)
- Display a warning when a series looks to have no episodes
- Make a backup of the .crpersistent before changing it

Godzil 7 years ago
parent
commit
6bc39083b9
3 changed files with 16 additions and 5 deletions
  1. 1 0
      package.json
  2. 1 1
      src/episode.ts
  3. 14 4
      src/series.ts

+ 1 - 0
package.json

@@ -21,6 +21,7 @@
     "cheerio": "^0.22.0",
     "cloudscraper": "^1.4.1",
     "commander": "^2.6.0",
+    "fs-extra": "^2.0.0",
     "mkdirp": "^0.5.0",
     "request": "^2.74.0",
     "xml2js": "^0.4.5"

+ 1 - 1
src/episode.ts

@@ -235,7 +235,7 @@ function scrapePage(config: IConfig, address: string, done: (err: Error, page?:
 
     const $ = cheerio.load(result);
     const swf = /^([^?]+)/.exec($('link[rel=video_src]').attr('href'));
-    const regexp = /\s*([^\n\r\t\f]+)\n?\s*[^0-9]*([0-9][0-9.]*)?,?\n?\s\s*[^0-9]*((PV )?[S0-9][P0-9.]*[a-fA-F]?)/;
+    const regexp = /\s*([^\n\r\t\f]+)\n?\s*[^0-9]*([0-9][\-0-9.]*)?,?\n?\s\s*[^0-9]*((PV )?[S0-9][P0-9.]*[a-fA-F]?)/;
     const look = $('#showmedia_about_media').text();
     const seasonTitle = $('span[itemprop="title"]').text();
     const data = regexp.exec(look);

+ 14 - 4
src/series.ts

@@ -2,6 +2,7 @@
 import cheerio = require('cheerio');
 import episode from './episode';
 import fs = require('fs');
+const fse = require('fs-extra');
 import request = require('./request');
 import path = require('path');
 import url = require('url');
@@ -15,7 +16,10 @@ export default function(config: IConfig, address: string, done: (err: Error) =>
 {
   const persistentPath = path.join(config.output || process.cwd(), persistent);
 
-  fs.readFile(persistentPath, 'utf8', (err, contents) =>
+  /* Make a backup of the persistent file in case of */
+  fse.copySync(persistentPath, persistentPath + '.backup');
+
+  fs.readFile(persistentPath, 'utf8', (err: Error, contents: string) =>
   {
     const cache = config.cache ? {} : JSON.parse(contents || '{}');
 
@@ -40,7 +44,7 @@ export default function(config: IConfig, address: string, done: (err: Error) =>
           if ((ignored === false) || (ignored === undefined))
           {
             const newCache = JSON.stringify(cache, null, '  ');
-            fs.writeFile(persistentPath, newCache, (errW) =>
+            fs.writeFile(persistentPath, newCache, (errW: Error) =>
             {
               if (errW)
               {
@@ -124,6 +128,7 @@ function page(config: IConfig, address: string, done: (err: Error, result?: ISer
 {
   if (address[0] === '@')
   {
+    log.info('Trying to fetch from ' + address.substr(1));
     const episodes: ISeriesEpisode[] = [];
     episodes.push({
       address: address.substr(1),
@@ -134,6 +139,7 @@ function page(config: IConfig, address: string, done: (err: Error, result?: ISer
   }
   else
   {
+    let episodeCount = 0;
     request.get(config, address, (err, result) => {
       if (err) {
         return done(err);
@@ -155,20 +161,24 @@ function page(config: IConfig, address: string, done: (err: Error, result?: ISer
         }
 
         const volume = /([0-9]+)\s*$/.exec($(el).closest('ul').prev('a').text());
-        const regexp = /Episode\s+((PV )?[S0-9][P0-9.]*[a-fA-F]?)\s*$/i;
+        const regexp = /Episode\s+((PV )?[S0-9][\-P0-9.]*[a-fA-F]?)\s*$/i;
         const episode = regexp.exec($(el).children('.series-title').text());
         const url = $(el).attr('href');
 
         if ((!url) || (!episode)) {
           return;
         }
+        episodeCount += 1;
         episodes.push({
           address: url,
           episode: episode[1],
           volume: volume ? parseInt(volume[0], 10) : 1,
         });
       });
-
+      if (episodeCount === 0)
+      {
+        log.warn("No episodes found for " + title + ". Could it be a movie?");
+      }
       done(null, {episodes: episodes.reverse(), series: title});
     });
   }