[CR] Add crunchy play streams selector

This commit is contained in:
AnimeDL 2024-06-18 21:29:45 -07:00
parent 16dbc4f1eb
commit f38dbf197e
5 changed files with 62 additions and 24 deletions

View file

@ -1,11 +1,12 @@
import { HLSCallback } from 'hls-download'; import { HLSCallback } from 'hls-download';
import { sxItem } from '../crunchy'; import { CrunchyPlayStreams, sxItem } from '../crunchy';
import { LanguageItem } from '../modules/module.langsData'; import { LanguageItem } from '../modules/module.langsData';
import { DownloadInfo } from './messageHandler'; import { DownloadInfo } from './messageHandler';
export type CrunchyDownloadOptions = { export type CrunchyDownloadOptions = {
hslang: string, hslang: string,
kstream: number, kstream: number,
cpstream: keyof typeof CrunchyPlayStreams | 'none',
novids?: boolean, novids?: boolean,
noaudio?: boolean, noaudio?: boolean,
x: number, x: number,

View file

@ -53,6 +53,23 @@ export type sxItem = {
fonts: Font[] fonts: Font[]
} }
export enum CrunchyPlayStreams {
'chrome' = 'web/chrome',
'firefox' = 'web/firefox',
'safari' = 'web/safari',
'edge' = 'web/edge',
'fallback' = 'web/fallback',
'ps4' = 'console/ps4',
'ps5' = 'console/ps5',
'switch' = 'console/switch',
'samsungtv' = 'tv/samsung',
'lgtv' = 'tv/lg',
'rokutv' = 'tv/roku',
'android' = 'android/phone',
'iphone' = 'ios/iphone',
'ipad' = 'ios/ipad',
}
export default class Crunchy implements ServiceClass { export default class Crunchy implements ServiceClass {
public cfg: yamlCfg.ConfigObject; public cfg: yamlCfg.ConfigObject;
public api: 'android' | 'web'; public api: 'android' | 'web';
@ -1414,27 +1431,30 @@ export default class Crunchy implements ServiceClass {
pbData = await playbackReq.res.json() as PlaybackData; pbData = await playbackReq.res.json() as PlaybackData;
} }
let switchStream: CrunchyPlayStream | null = null;
const playbackReq = await this.req.getData(`https://cr-play-service.prd.crunchyrollsvc.com/v1/${currentVersion ? currentVersion.guid : currentMediaId}/console/switch/play`, AuthHeaders); let playStream: CrunchyPlayStream | null = null;
if(!playbackReq.ok || !playbackReq.res) { if (options.cpstream !== 'none') {
console.error('Non-DRM Request Stream URLs FAILED!'); const playbackReq = await this.req.getData(`https://cr-play-service.prd.crunchyrollsvc.com/v1/${currentVersion ? currentVersion.guid : currentMediaId}/${CrunchyPlayStreams[options.cpstream]}/play`, AuthHeaders);
} else { if (!playbackReq.ok || !playbackReq.res) {
switchStream = await playbackReq.res.json() as CrunchyPlayStream; console.error('Non-DRM Request Stream URLs FAILED!');
const derivedPlaystreams = {} as CrunchyStreams; } else {
for (const hardsub in switchStream.hardSubs) { playStream = await playbackReq.res.json() as CrunchyPlayStream;
const stream = switchStream.hardSubs[hardsub]; const derivedPlaystreams = {} as CrunchyStreams;
derivedPlaystreams[hardsub] = { for (const hardsub in playStream.hardSubs) {
url: stream.url, const stream = playStream.hardSubs[hardsub];
'hardsub_locale': stream.hlang derivedPlaystreams[hardsub] = {
url: stream.url,
'hardsub_locale': stream.hlang
};
}
derivedPlaystreams[''] = {
url: playStream.url,
hardsub_locale: ''
};
pbData.data[0][`adaptive_${options.cpstream}_${playStream.url.includes('m3u8') ? 'hls' : 'dash'}_drm`] = {
...derivedPlaystreams
}; };
} }
derivedPlaystreams[''] = {
url: switchStream.url,
hardsub_locale: ''
};
pbData.data[0]['adaptive_switch_dash'] = {
...derivedPlaystreams
};
} }
variables.push(...([ variables.push(...([
@ -2131,9 +2151,9 @@ export default class Crunchy implements ServiceClass {
console.info('Subtitles downloading skipped!'); console.info('Subtitles downloading skipped!');
} }
if (switchStream) { if (playStream) {
await this.refreshToken(true, true); await this.refreshToken(true, true);
await this.req.getData(`https://cr-play-service.prd.crunchyrollsvc.com/v1/token/${currentVersion ? currentVersion.guid : currentMediaId}/${switchStream.token}`, {...{method: 'DELETE'}, ...AuthHeaders}); await this.req.getData(`https://cr-play-service.prd.crunchyrollsvc.com/v1/token/${currentVersion ? currentVersion.guid : currentMediaId}/${playStream.token}`, {...{method: 'DELETE'}, ...AuthHeaders});
} }
await this.sleep(options.waittime); await this.sleep(options.waittime);

View file

@ -5,6 +5,7 @@ import { DownloadInfo } from '../@types/messageHandler';
import { HLSCallback } from './hls-download'; import { HLSCallback } from './hls-download';
import leven from 'leven'; import leven from 'leven';
import { console } from './log'; import { console } from './log';
import { CrunchyPlayStreams } from '../crunchy';
let argvC: { let argvC: {
[x: string]: unknown; [x: string]: unknown;
@ -43,6 +44,7 @@ let argvC: {
q: number; q: number;
x: number; x: number;
kstream: number; kstream: number;
cpstream: keyof typeof CrunchyPlayStreams | 'none';
partsize: number; partsize: number;
hslang: string; hslang: string;
dlsubs: string[]; dlsubs: string[];

View file

@ -1,4 +1,5 @@
import { aoSearchLocales, dubLanguageCodes, languages, searchLocales, subtitleLanguagesFilter } from './module.langsData'; import { aoSearchLocales, dubLanguageCodes, languages, searchLocales, subtitleLanguagesFilter } from './module.langsData';
import { CrunchyPlayStreams } from '../crunchy';
const groups = { const groups = {
'auth': 'Authentication:', 'auth': 'Authentication:',
@ -283,6 +284,20 @@ const args: TAppArg<boolean|number|string|unknown[]>[] = [
type: 'number', type: 'number',
usage: '${stream}' usage: '${stream}'
}, },
{
name: 'cpstream',
group: 'dl',
alias: 'cps',
service: ['crunchy'],
type: 'string',
describe: 'Select specific crunchy play stream by device, or disable stream with "none"',
choices: [...Object.keys(CrunchyPlayStreams), 'none'],
default: {
default: 'chrome'
},
docDescribe: true,
usage: '${device}'
},
{ {
name: 'hslang', name: 'hslang',
group: 'dl', group: 'dl',

View file

@ -1,7 +1,7 @@
{ {
"name": "multi-downloader-nx", "name": "multi-downloader-nx",
"short_name": "aniDL", "short_name": "aniDL",
"version": "5.0.4b1", "version": "5.0.4b2",
"description": "Downloader for Crunchyroll, Hidive, AnimeOnegai, and AnimationDigitalNetwork with CLI and GUI", "description": "Downloader for Crunchyroll, Hidive, AnimeOnegai, and AnimationDigitalNetwork with CLI and GUI",
"keywords": [ "keywords": [
"download", "download",