[CR] Add Switch Stream

This commit is contained in:
AnimeDL 2024-04-03 08:41:49 -07:00
parent 80c7f5ba77
commit 90100a077d
3 changed files with 87 additions and 19 deletions

42
@types/crunchyPlayStreams.d.ts vendored Normal file
View file

@ -0,0 +1,42 @@
export interface CrunchyPlayStream {
assetId: string;
audioLocale: string;
bifs: string;
burnedInLocale: string;
captions: { [key: string]: Caption };
hardSubs: { [key: string]: HardSub };
playbackType: string;
session: Session;
subtitles: { [key: string]: Subtitle };
token: string;
url: string;
versions: any[];
}
export interface Caption {
format: string;
language: string;
url: string;
}
export interface HardSub {
hlang: string;
url: string;
quality: string;
}
export interface Session {
renewSeconds: number;
noNetworkRetryIntervalSeconds: number;
noNetworkTimeoutSeconds: number;
maximumPauseSeconds: number;
endOfVideoUnloadSeconds: number;
sessionExpirationSeconds: number;
usesStreamLimits: boolean;
}
export interface Subtitle {
format: string;
language: string;
url: string;
}

View file

@ -6,24 +6,24 @@ export interface PlaybackData {
} }
export interface StreamList { export interface StreamList {
download_hls: Streams; download_hls: CrunchyStreams;
drm_adaptive_hls: Streams; drm_adaptive_hls: CrunchyStreams;
multitrack_adaptive_hls_v2: Streams; multitrack_adaptive_hls_v2: CrunchyStreams;
vo_adaptive_hls: Streams; vo_adaptive_hls: CrunchyStreams;
vo_drm_adaptive_hls: Streams; vo_drm_adaptive_hls: CrunchyStreams;
adaptive_hls: Streams; adaptive_hls: CrunchyStreams;
drm_download_dash: Streams; drm_download_dash: CrunchyStreams;
drm_download_hls: Streams; drm_download_hls: CrunchyStreams;
drm_multitrack_adaptive_hls_v2: Streams; drm_multitrack_adaptive_hls_v2: CrunchyStreams;
vo_drm_adaptive_dash: Streams; vo_drm_adaptive_dash: CrunchyStreams;
adaptive_dash: Streams; adaptive_dash: CrunchyStreams;
urls: Streams; urls: CrunchyStreams;
vo_adaptive_dash: Streams; vo_adaptive_dash: CrunchyStreams;
download_dash: Streams; download_dash: CrunchyStreams;
drm_adaptive_dash: Streams; drm_adaptive_dash: CrunchyStreams;
} }
export interface Streams { export interface CrunchyStreams {
'': StreamDetails; '': StreamDetails;
'en-US'?: StreamDetails; 'en-US'?: StreamDetails;
'es-LA'?: StreamDetails; 'es-LA'?: StreamDetails;
@ -41,10 +41,12 @@ export interface Streams {
'zh-CN'?: StreamDetails; 'zh-CN'?: StreamDetails;
'ko-KR'?: StreamDetails; 'ko-KR'?: StreamDetails;
'ja-JP'?: StreamDetails; 'ja-JP'?: StreamDetails;
[string: string]: StreamDetails;
} }
export interface StreamDetails { export interface StreamDetails {
hardsub_locale: Locale; //hardsub_locale: Locale;
hardsub_locale: string;
url: string; url: string;
hardsub_lang?: string; hardsub_lang?: string;
audio_lang?: string; audio_lang?: string;

View file

@ -31,7 +31,7 @@ import { CrunchyEpisodeList, CrunchyEpisode } from './@types/crunchyEpisodeList'
import { CrunchyDownloadOptions, CrunchyEpMeta, CrunchyMuxOptions, CrunchyMultiDownload, DownloadedMedia, ParseItem, SeriesSearch, SeriesSearchItem } from './@types/crunchyTypes'; import { CrunchyDownloadOptions, CrunchyEpMeta, CrunchyMuxOptions, CrunchyMultiDownload, DownloadedMedia, ParseItem, SeriesSearch, SeriesSearchItem } from './@types/crunchyTypes';
import { ObjectInfo } from './@types/objectInfo'; import { ObjectInfo } from './@types/objectInfo';
import parseFileName, { Variable } from './modules/module.filename'; import parseFileName, { Variable } from './modules/module.filename';
import { PlaybackData } from './@types/playbackData'; import { CrunchyStreams, PlaybackData } from './@types/playbackData';
import { downloaded } from './modules/module.downloadArchive'; import { downloaded } from './modules/module.downloadArchive';
import parseSelect from './modules/module.parseSelect'; import parseSelect from './modules/module.parseSelect';
import { AvailableFilenameVars, getDefault } from './modules/module.args'; import { AvailableFilenameVars, getDefault } from './modules/module.args';
@ -43,6 +43,7 @@ import { parse } from './modules/module.transform-mpd';
import { CrunchyAndroidObject } from './@types/crunchyAndroidObject'; import { CrunchyAndroidObject } from './@types/crunchyAndroidObject';
import { CrunchyChapters, CrunchyChapter, CrunchyOldChapter } from './@types/crunchyChapters'; import { CrunchyChapters, CrunchyChapter, CrunchyOldChapter } from './@types/crunchyChapters';
import vtt2ass from './modules/module.vtt2ass'; import vtt2ass from './modules/module.vtt2ass';
import { CrunchyPlayStream } from './@types/crunchyPlayStreams';
export type sxItem = { export type sxItem = {
language: langsData.LanguageItem, language: langsData.LanguageItem,
@ -1207,6 +1208,7 @@ export default class Crunchy implements ServiceClass {
const AuthHeaders = { const AuthHeaders = {
headers: { headers: {
Authorization: `Bearer ${this.token.access_token}`, Authorization: `Bearer ${this.token.access_token}`,
'X-Cr-Disable-Drm': 'true'
}, },
useProxy: true useProxy: true
}; };
@ -1395,6 +1397,28 @@ export default class Crunchy implements ServiceClass {
pbData = JSON.parse(playbackReq.res.body) as PlaybackData; pbData = JSON.parse(playbackReq.res.body) as PlaybackData;
} }
const playbackReq = await this.req.getData(`https://cr-play-service.prd.crunchyrollsvc.com/v1/${mMeta.mediaId}/console/switch/play`, AuthHeaders);
if(!playbackReq.ok || !playbackReq.res){
console.error('Non-DRM Request Stream URLs FAILED!');
} else {
const playStream = JSON.parse(playbackReq.res.body) as CrunchyPlayStream;
const derivedPlaystreams = {} as CrunchyStreams;
for (const hardsub in playStream.hardSubs) {
const stream = playStream.hardSubs[hardsub];
derivedPlaystreams[hardsub] = {
url: stream.url,
'hardsub_locale': stream.hlang
};
}
derivedPlaystreams[''] = {
url: playStream.url,
hardsub_locale: ''
};
pbData.data[0]['adaptive_switch_dash'] = {
...derivedPlaystreams
};
}
variables.push(...([ variables.push(...([
['title', medias.episodeTitle, true], ['title', medias.episodeTitle, true],
['episode', isNaN(parseFloat(medias.episodeNumber)) ? medias.episodeNumber : parseFloat(medias.episodeNumber), false], ['episode', isNaN(parseFloat(medias.episodeNumber)) ? medias.episodeNumber : parseFloat(medias.episodeNumber), false],
@ -1520,7 +1544,7 @@ export default class Crunchy implements ServiceClass {
let tsFile = undefined; let tsFile = undefined;
if(!dlFailed && curStream !== undefined && !(options.novids && options.noaudio)){ if(!dlFailed && curStream !== undefined && !(options.novids && options.noaudio)){
const streamPlaylistsReq = await this.req.getData(curStream.url); const streamPlaylistsReq = await this.req.getData(curStream.url, AuthHeaders);
if(!streamPlaylistsReq.ok || !streamPlaylistsReq.res){ if(!streamPlaylistsReq.ok || !streamPlaylistsReq.res){
console.error('CAN\'T FETCH VIDEO PLAYLISTS!'); console.error('CAN\'T FETCH VIDEO PLAYLISTS!');
dlFailed = true; dlFailed = true;