116 lines
3.9 KiB
JavaScript
116 lines
3.9 KiB
JavaScript
'use strict';
|
|
|
|
// Constants
|
|
const DEVICE_ID = '031_04'; // Found in the APK as the resource @string/device_id. (Default: "001")
|
|
const BRAND_ID = '011'; // Selected from the function mapBrandCode(), which is found in embed.min.js (a script loaded by the website). (Default: "004")
|
|
|
|
// Lock the reported app name and version to a known working value. (The reported app name and version can determine the video stream format.)
|
|
const APP_NAME = 'webplayer-dc';
|
|
const APP_VERSION = '1.2.7.49';
|
|
|
|
// Target File
|
|
const TARGET_FILE = 'playmanifest_secure.json';
|
|
|
|
// Patch XMLHttpRequest.open
|
|
const oldOpen = XMLHttpRequest.prototype.open;
|
|
Object.defineProperty(XMLHttpRequest.prototype, 'open', {
|
|
value: function (method, url, ...args) {
|
|
// Flag
|
|
this._isTargetUrl = (new URL(url)).pathname.endsWith('/' + TARGET_FILE);
|
|
|
|
// Call Original Method
|
|
oldOpen.call(this, method, url, ...args);
|
|
},
|
|
enumerable: false,
|
|
configurable: false,
|
|
writable: false
|
|
});
|
|
|
|
// Patch XMLHttpRequest.setRequestHeader
|
|
const oldSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
|
|
Object.defineProperty(XMLHttpRequest.prototype, 'setRequestHeader', {
|
|
value: function (name, value) {
|
|
// Lock App Version
|
|
if (this._isTargetUrl && name.toLowerCase() === 'appversion') {
|
|
value = APP_VERSION;
|
|
}
|
|
|
|
// Call Original Method
|
|
oldSetRequestHeader.call(this, name, value);
|
|
},
|
|
enumerable: false,
|
|
configurable: false,
|
|
writable: false
|
|
});
|
|
|
|
// Add resolution info to video player.
|
|
function addResolutionInfo(player) {
|
|
// Remove existing <p> element (if possible).
|
|
const id = '__disneynow_resolution_info__';
|
|
let p = document.getElementById(id);
|
|
if (p) {
|
|
p.remove();
|
|
}
|
|
|
|
// Create <p> element
|
|
p = document.createElement('P');
|
|
p.id = id;
|
|
|
|
// Add <p> element to DOM.
|
|
player.parentElement.insertBefore(p, player);
|
|
|
|
// Set initial resolution text.
|
|
function setResolutionText(resolution) {
|
|
p.innerText = `Video Quality: ${resolution}`;
|
|
}
|
|
setResolutionText('N/A');
|
|
|
|
// Hook into <video> element.
|
|
const video = player.getElementsByTagName('VIDEO')[0];
|
|
video.addEventListener("resize", e => setResolutionText(`${e.target.videoWidth}x${e.target.videoHeight}`), false);
|
|
}
|
|
|
|
// Patch XMLHttpRequest.send
|
|
const oldSend = XMLHttpRequest.prototype.send;
|
|
Object.defineProperty(XMLHttpRequest.prototype, 'send', {
|
|
value: function (body, ...args) {
|
|
// Check
|
|
if (this._isTargetUrl && body) {
|
|
// Parse Request Body
|
|
const params = new URLSearchParams(body);
|
|
|
|
// Pretend to be an Android device.
|
|
params.set('device', DEVICE_ID);
|
|
// Switch brand ID to one without ads.
|
|
params.set('brand', BRAND_ID);
|
|
// Set recommended video player size to current screen resolution.
|
|
params.set('vps', `${window.screen.width * window.devicePixelRatio}x${window.screen.height * window.devicePixelRatio}`);
|
|
// Ensure other miscellaneous parameters are correct.
|
|
params.set('hdcp_level', '2.3');
|
|
params.set('hlsver', '6');
|
|
params.set('app_name', APP_NAME);
|
|
|
|
// Apply Patch
|
|
body = params.toString();
|
|
|
|
// Log Video Stream URL
|
|
this.addEventListener("load", function () {
|
|
const obj = JSON.parse(this.responseText);
|
|
const video = obj.video ? obj.video : obj.channels.channel[0];
|
|
const assetUrl = new URL(video.assets.asset[0].value);
|
|
console.log('Video Stream URL: ' + assetUrl);
|
|
});
|
|
|
|
// Find video player and add resolution info.
|
|
const player = document.getElementsByClassName('VideoPlayer')[0];
|
|
addResolutionInfo(player);
|
|
}
|
|
|
|
// Call Original Method
|
|
oldSend.call(this, body, ...args);
|
|
},
|
|
enumerable: false,
|
|
configurable: false,
|
|
writable: false
|
|
});
|