From 547fdc4aa0c1c39f9d26f3c3c82d828d98218798 Mon Sep 17 00:00:00 2001 From: Godzil Date: Thu, 29 Mar 2018 22:29:01 +0100 Subject: [PATCH] Add a way to select the resolution. Use 1080p by default Fix #58 --- src/batch.ts | 32 ++++++++++++++++++++++++++++++++ src/episode.ts | 13 +++++++++---- src/interface/IConfig.d.ts | 3 +++ src/interface/IResolData.d.ts | 4 ++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/interface/IResolData.d.ts diff --git a/src/batch.ts b/src/batch.ts index e82dc2f..ebb710b 100644 --- a/src/batch.ts +++ b/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 ', 'The series override.') .option('-n, --filename ', 'The name override.') .option('-t, --tag ', 'The subgroup. (Default: CrunchyRoll)') + .option('-r, --resolution ', 'The video resolution. (Default: 1080 (360, 480, 720, 1080))') .parse(args); } diff --git a/src/episode.ts b/src/episode.ts index 25a47e4..f2789f4 100644 --- a/src/episode.ts +++ b/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 ? { diff --git a/src/interface/IConfig.d.ts b/src/interface/IConfig.d.ts index 1de47e4..b2ec101 100644 --- a/src/interface/IConfig.d.ts +++ b/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; } diff --git a/src/interface/IResolData.d.ts b/src/interface/IResolData.d.ts new file mode 100644 index 0000000..404580e --- /dev/null +++ b/src/interface/IResolData.d.ts @@ -0,0 +1,4 @@ +interface IResolData { + quality: string; + format: string; +}