Browse Source

Add a way to select the resolution. Use 1080p by default

Fix #58
Godzil 6 years ago
parent
commit
547fdc4aa0
4 changed files with 48 additions and 4 deletions
  1. 32 0
      src/batch.ts
  2. 9 4
      src/episode.ts
  3. 3 0
      src/interface/IConfig.d.ts
  4. 4 0
      src/interface/IResolData.d.ts

+ 32 - 0
src/batch.ts

@@ -3,6 +3,15 @@ import commander = require('commander');
 import fs = require('fs');
 import path = require('path');
 import series from './series';
+import log = require('./log');
+
+/* correspondances between resolution and value CR excpect */
+let resol_table: { [id: string]: IResolData; } = {
+    '360':  {quality:'60', format:'106'},
+    '480':  {quality:'61', format:'106'},
+    '720':  {quality:'62', format:'106'},
+    '1080': {quality:'80', format:'108'},
+};
 
 /**
  * Streams the batch of series to disk.
@@ -12,6 +21,28 @@ export default function(args: string[], done: (err?: Error) => void)
   const config = parse(args);
   const batchPath = path.join(config.output || process.cwd(), 'CrunchyRoll.txt');
 
+  // set resolution
+  if (config.resolution)
+  {
+    try
+    {
+      config.video_format = resol_table[config.resolution]['format'];
+      config.video_quality = resol_table[config.resolution]['quality'];
+    }
+    catch(e)
+    {
+      log.warn("Invalid resolution " + config.resolution + "p. Setting to 1080p")
+      config.video_format = resol_table['1080']['format'];
+      config.video_quality = resol_table['1080']['quality'];
+    }
+  }
+  else
+  {
+    /* 1080 by default */
+    config.video_format = resol_table['1080']['format'];
+    config.video_quality = resol_table['1080']['quality'];
+  }
+
   tasks(config, batchPath, (err, tasks) =>
   {
     if (err)
@@ -151,5 +182,6 @@ function parse(args: string[]): IConfigLine
     .option('-s, --series <s>', 'The series override.')
     .option('-n, --filename <s>', 'The name override.')
     .option('-t, --tag <s>', 'The subgroup. (Default: CrunchyRoll)')
+    .option('-r, --resolution <s>', 'The video resolution. (Default: 1080 (360, 480, 720, 1080))')
     .parse(args);
 }

+ 9 - 4
src/episode.ts

@@ -303,7 +303,12 @@ function scrapePlayer(config: IConfig, address: string, id: number, done: (err:
   }
 
   my_request.post(config, {
-    form: {current_page: address},
+    form: {
+      current_page: address,
+      video_format: config.video_format,
+      video_quality: config.video_quality,
+      media_id: id
+    },
     url: url[1] + '/xml/?req=RpcApiVideoPlayer_GetStandardConfig&media_id=' + id,
   }, (err, result) =>
   {
@@ -328,9 +333,9 @@ function scrapePlayer(config: IConfig, address: string, id: number, done: (err:
         let streamMode = 'RTMP';
 
         if (player['default:preload'].stream_info.host === '')
-		{
-			streamMode = 'HLS';
-		}
+        {
+          streamMode = 'HLS';
+        }
 
         done(null, {
           subtitle: isSubtitled ? {

+ 3 - 0
src/interface/IConfig.d.ts

@@ -14,4 +14,7 @@ interface IConfig {
   series?: string;
   filename?: string;
   tag?: string;
+  resolution?: string;
+  video_format?: string;
+  video_quality?: string;
 }

+ 4 - 0
src/interface/IResolData.d.ts

@@ -0,0 +1,4 @@
+interface IResolData {
+  quality: string;
+  format: string;
+}