It started as just a way to fix subtitles download. It ended in a complete new way to get info about video stream AND subtitles. Lots of things have change on CR since the last major update, and on some pages, the old subtitle fetch fail. They changed the player on the page from the old flash one to a HTML based one and albeit most scrapped info are still valid, some are no longer working on some new releases. It should be more reliable, but there are some drawback. I'm currently unable to select the resolution, it is 1080 by default. It will probably not work for non premium account, but, you know, I ask clearly for you to only use that tool if you have a premium account, so well, I'm not going to try to support non premium account if it does not work. Oh, and it add the possibility to download subtitles in the languages of your choice! The old mechanism is still there as fallback, but may be removed in the futur to clean up the code.
71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
'use strict';
|
|
|
|
export default {getMedia};
|
|
|
|
function getMedia(vlosScript: string, seasonTitle: string, seasonNumber: string): IEpisodePage
|
|
{
|
|
let vlosMedia: IVlosScript;
|
|
|
|
function f(script: string) {
|
|
/* We need to scope things */
|
|
|
|
/* This is what will give us the medias */
|
|
function VilosPlayer() {
|
|
this.load = function(a: string, b: any, c: any)
|
|
{
|
|
vlosMedia = this.config.media;
|
|
vlosMedia.series = this.config.analytics.media_reporting_parent;
|
|
};
|
|
this.config = {};
|
|
this.config.player = {};
|
|
this.config.player.pause_screen = {};
|
|
this.config.language = '';
|
|
}
|
|
|
|
/* Let's stub what the script need */
|
|
const window = {
|
|
WM: {
|
|
UserConsent: {
|
|
getUserConsentAdvertisingState(): string { return ''; }
|
|
}
|
|
}
|
|
};
|
|
const document = {
|
|
getElementsByClassName(a: any): any { return {length: 0}; },
|
|
};
|
|
const localStorage = {
|
|
getItem(a: any): any { return null; },
|
|
};
|
|
const $ = {
|
|
cookie(a: any) { /* nothing */ },
|
|
};
|
|
|
|
/*
|
|
Evil ugly things. Need to run the script from a somewhat untrusted source.
|
|
Need to find a better way of doing.
|
|
*/
|
|
// tslint:disable-next-line:no-eval
|
|
eval(script);
|
|
|
|
}
|
|
f(vlosScript);
|
|
|
|
if (vlosMedia === undefined)
|
|
{
|
|
console.error('Error fetching vlos data - aborting - Please report the error if happen again.');
|
|
process.exit(-1);
|
|
}
|
|
|
|
return {
|
|
episode: vlosMedia.metadata.episode_number,
|
|
id: vlosMedia.metadata.id,
|
|
series: vlosMedia.series.title,
|
|
season: seasonTitle,
|
|
title: vlosMedia.metadata.title,
|
|
swf: '',
|
|
volume: seasonNumber,
|
|
filename: '',
|
|
media: vlosMedia,
|
|
};
|
|
}
|