Add new MPL profiles, add option to disable HPL

This commit is contained in:
shirt 2023-01-16 18:40:34 -05:00
parent 0c6844c4bb
commit 96856b02e0
Signed by: shirt
GPG key ID: A5D61AB2D5489EE1
9 changed files with 94 additions and 64 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
*.zip *.zip
_metadata

View file

@ -9,3 +9,4 @@ Contact me on discord: shirt#1337
# Based on the following extensions # Based on the following extensions
- https://github.com/DavidBuchanan314/Turbo-Recadmiumator - https://github.com/DavidBuchanan314/Turbo-Recadmiumator
- https://github.com/truedread/netflix-1080p - https://github.com/truedread/netflix-1080p
- https://github.com/lkmvip/netflix-4K-DDplus

View file

@ -14,11 +14,6 @@ function getBrowser() {
chrome.webRequest.onBeforeRequest.addListener( chrome.webRequest.onBeforeRequest.addListener(
function (details) { function (details) {
/* Allow our shim to load an untouched copy */
if (details.url.endsWith("?no_filter")) {
return {};
}
if (getBrowser() == "Chrome") { if (getBrowser() == "Chrome") {
return { redirectUrl: chrome.runtime.getURL("cadmium-playercore-shim.js") }; return { redirectUrl: chrome.runtime.getURL("cadmium-playercore-shim.js") };
} }
@ -46,6 +41,7 @@ chrome.webRequest.onBeforeRequest.addListener(
urls: [ urls: [
"*://assets.nflxext.com/*/ffe/player/html/*", "*://assets.nflxext.com/*/ffe/player/html/*",
"*://www.assets.nflxext.com/*/ffe/player/html/*" "*://www.assets.nflxext.com/*/ffe/player/html/*"
] ],
types: ["script"]
}, ["blocking"] }, ["blocking"]
); );

View file

@ -2,6 +2,14 @@
// This script runs as a drop-in replacement of the original cadmium-playercore. This is not a content script. // This script runs as a drop-in replacement of the original cadmium-playercore. This is not a content script.
console.log("Netflix International script active!"); console.log("Netflix International script active!");
if (window.globalOptions === undefined) {
try {
window.globalOptions = JSON.parse(document.getElementById("netflix-intl-settings").innerText);
} catch(e) {
console.error("Could not load settings:", e);
}
}
/* eslint-disable no-undef */ /* eslint-disable no-undef */
// https://stackoverflow.com/a/45985333 // https://stackoverflow.com/a/45985333
function getBrowser() { function getBrowser() {
@ -47,23 +55,29 @@ function get_profile_list(original_profiles) {
"playready-h264mpl30-dash", "playready-h264mpl30-dash",
"playready-h264mpl31-dash", "playready-h264mpl31-dash",
"playready-h264mpl40-dash", "playready-h264mpl40-dash",
"h264mpl30-dash-playready-prk-qc",
"h264mpl31-dash-playready-prk-qc",
"h264mpl40-dash-playready-prk-qc",
]); ]);
} }
if (original_profiles.includes("playready-h264hpl30-dash")) { if (!globalOptions.disableHPL) {
profiles = profiles.concat([ if (original_profiles.includes("playready-h264hpl30-dash")) {
"playready-h264hpl30-dash", profiles = profiles.concat([
"playready-h264hpl31-dash", "playready-h264hpl30-dash",
"playready-h264hpl40-dash", "playready-h264hpl31-dash",
]); "playready-h264hpl40-dash",
} ]);
}
if (original_profiles.includes("h264hpl30-dash-playready-live")) { if (original_profiles.includes("h264hpl30-dash-playready-live")) {
profiles = profiles.concat([ profiles = profiles.concat([
"h264hpl30-dash-playready-live", "h264hpl30-dash-playready-live",
"h264hpl31-dash-playready-live", "h264hpl31-dash-playready-live",
"h264hpl40-dash-playready-live", "h264hpl40-dash-playready-live",
]); ]);
}
} else {
profiles = profiles.filter(val => !val.includes("h264hpl"));
} }
if (!globalOptions.disableVP9 && original_profiles.includes("vp9-profile0-L30-dash-cenc")) { if (!globalOptions.disableVP9 && original_profiles.includes("vp9-profile0-L30-dash-cenc")) {

View file

@ -31,44 +31,32 @@ function chromeStorageGet(opts) {
} }
} }
function attachScript(resp) {
let xhr = resp.target;
let mainScript = document.createElement("script");
mainScript.type = "application/javascript";
if (xhr.status == 200) {
mainScript.text = xhr.responseText;
document.documentElement.appendChild(mainScript);
}
}
chromeStorageGet({ chromeStorageGet({
use6Channels: true, use6Channels: true,
showAllTracks: true, showAllTracks: true,
setMaxBitrate: false, setMaxBitrate: false,
disableVP9: false, disableVP9: false,
disableAV1: true, disableAV1: true,
disableHPL: false,
useDDPlus: false, useDDPlus: false,
preferredLocale: null, preferredLocale: null,
preferredTextLocale: null, preferredTextLocale: null,
}).then(items => { }).then(items => {
// very messy workaround for accessing chrome storage outside of background / content scripts // very messy workaround for accessing chrome storage outside of background / content scripts
let mainScript = document.createElement("script"); let mainScript = document.createElement("script");
mainScript.type = "application/javascript"; mainScript.type = "application/json";
mainScript.text = `var globalOptions = JSON.parse('${JSON.stringify(items)}');`; mainScript.id = "netflix-intl-settings";
mainScript.text = JSON.stringify(items);
document.documentElement.appendChild(mainScript); document.documentElement.appendChild(mainScript);
}).then(() => { }).then(() => {
// attach and include additional scripts after we have loaded the main configuration // attach and include additional scripts after we have loaded the main configuration
for (let i = 0; i < script_urls.length; i++) {
let script = document.createElement("script");
script.src = script_urls[i];
document.documentElement.appendChild(script);
}
for (let i = 0; i < urls.length; i++) { for (let i = 0; i < urls.length; i++) {
let mainScriptUrl = chrome.extension.getURL(urls[i]); const mainScriptUrl = chrome.runtime.getURL(urls[i]);
let xhr = new XMLHttpRequest();
xhr.open("GET", mainScriptUrl, true); const mainScript = document.createElement('script');
xhr.onload = attachScript; mainScript.type = 'application/javascript';
xhr.send(); mainScript.src = mainScriptUrl;
document.documentElement.appendChild(mainScript);
} }
}); });

View file

@ -2,7 +2,7 @@
"manifest_version": 2, "manifest_version": 2,
"name": "Netflix International", "name": "Netflix International",
"description": "Displays all available Netflix audio and subtitle tracks.", "description": "Displays all available Netflix audio and subtitle tracks.",
"version": "2.0.16", "version": "2.0.17",
"author": "shirt", "author": "shirt",
"browser_action": { "browser_action": {
"default_icon": "img/icon128.png", "default_icon": "img/icon128.png",

View file

@ -5,18 +5,33 @@ let getElementByXPath = function (xpath) {
).singleNodeValue; ).singleNodeValue;
}; };
const fn = function () { let fn = function () {
window.dispatchEvent(new KeyboardEvent("keydown", { const VIDEO_SELECT = getElementByXPath("//div[text()='Video Bitrate']");
const AUDIO_SELECT = getElementByXPath("//div[text()='Audio Bitrate']");
const BUTTON = getElementByXPath("//button[text()='Override']");
const videoPlayer = netflix.appContext.state.playerApp.getAPI().videoPlayer;
if(!videoPlayer) {
console.log("API Not Loading!");
return false;
}
const player = videoPlayer.getVideoPlayerBySessionId(videoPlayer.getAllPlayerSessionIds()[0]);
if(!player) {
console.log("Video Not Loading!");
return false;
}
if(!player.isPlaying()) {
console.log("Video Not Playing!");
return false;
}
window.dispatchEvent(new KeyboardEvent('keydown', {
keyCode: 83, keyCode: 83,
ctrlKey: true, ctrlKey: true,
altKey: true, altKey: true,
shiftKey: true, shiftKey: true,
})); }));
const VIDEO_SELECT = getElementByXPath("//div[text()='Video Bitrate']");
const AUDIO_SELECT = getElementByXPath("//div[text()='Audio Bitrate']");
const BUTTON = getElementByXPath("//button[text()='Override']");
if (!(VIDEO_SELECT && AUDIO_SELECT && BUTTON)){ if (!(VIDEO_SELECT && AUDIO_SELECT && BUTTON)){
return false; return false;
} }
@ -24,40 +39,46 @@ const fn = function () {
[VIDEO_SELECT, AUDIO_SELECT].forEach(function (el) { [VIDEO_SELECT, AUDIO_SELECT].forEach(function (el) {
let parent = el.parentElement; let parent = el.parentElement;
let options = parent.querySelectorAll("select > option"); let options = parent.querySelectorAll('select > option');
for (var i = 0; i < options.length - 1; i++) { for (var i = 0; i < options.length - 1; i++) {
options[i].removeAttribute("selected"); options[i].removeAttribute('selected');
} }
options[options.length - 1].setAttribute("selected", "selected"); options[options.length - 1].setAttribute('selected', 'selected');
}); });
console.log("Video Playing!");
BUTTON.click(); BUTTON.click();
return true; return true;
}; };
let run = function () { let run = function () {
if (!fn()) { fn() || setTimeout(run, 100)
setTimeout(run, 100);
}
}; };
const WATCH_REGEXP = /netflix.com\/watch\/.*/; const WATCH_REGEXP = /netflix.com\/watch\/.*/;
let oldLocation; let oldLocation;
if(globalOptions.setMaxBitrate) { if (window.globalOptions === undefined) {
try {
window.globalOptions = JSON.parse(document.getElementById("netflix-intl-settings").innerText);
} catch(e) {
console.error("Could not load settings:", e);
}
}
if(window.globalOptions.setMaxBitrate ) {
console.log("netflix_max_bitrate.js enabled"); console.log("netflix_max_bitrate.js enabled");
//setInterval(test, 500);
setInterval(function () { setInterval(function () {
let newLocation = window.location.toString(); let newLocation = window.location.toString();
if (newLocation !== oldLocation) { if (newLocation !== oldLocation) {
oldLocation = newLocation; oldLocation = newLocation;
if (WATCH_REGEXP.test(newLocation)) { WATCH_REGEXP.test(newLocation) && run();
run();
}
} }
}, 500); }, 500);
} }

View file

@ -6,6 +6,7 @@
<style> <style>
body { body {
min-width: 300px; min-width: 300px;
font-family: Sans-Serif;
} }
</style> </style>
</head> </head>
@ -17,11 +18,13 @@
<br> <br>
<input type="checkbox" id="setMaxBitrate"><label for="setMaxBitrate">Automatically select best bitrate available</label> <input type="checkbox" id="setMaxBitrate"><label for="setMaxBitrate">Automatically select best bitrate available</label>
<br> <br>
<input type="checkbox" id="disableVP9"><label for="disableVP9">Disable VP9 codec (Chrome/Firefox)</label> <input type="checkbox" id="disableVP9"><label for="disableVP9">Disable VP9 codec</label>
<br> <br>
<input type="checkbox" id="disableAV1"><label for="disableAV1">Disable AV1 codec (Chrome/Firefox)</label> <input type="checkbox" id="disableAV1"><label for="disableAV1">Disable AV1 codec</label>
<br> <br>
<input type="checkbox" id="useDDPlus"><label for="useDDPlus">Use Dolby Digital Plus (Chromium Edge)</label> <input type="checkbox" id="disableHPL"><label for="disableHPL">Disable H264 HPL profile</label>
<br>
<input type="checkbox" id="useDDPlus"><label for="useDDPlus">Use Dolby Digital Plus (Edge)</label>
<br> <br>
<label for="preferredLocale">Preferred audio language</label> <label for="preferredLocale">Preferred audio language</label>
<input list="locales" id="preferredLocale" maxlength="5"> <input list="locales" id="preferredLocale" maxlength="5">

View file

@ -5,6 +5,7 @@ function save_options() {
const setMaxBitrate = document.getElementById("setMaxBitrate").checked; const setMaxBitrate = document.getElementById("setMaxBitrate").checked;
const disableVP9 = document.getElementById("disableVP9").checked; const disableVP9 = document.getElementById("disableVP9").checked;
const disableAV1 = document.getElementById("disableAV1").checked; const disableAV1 = document.getElementById("disableAV1").checked;
const disableHPL = document.getElementById("disableHPL").checked;
const useDDPlus = document.getElementById("useDDPlus").checked; const useDDPlus = document.getElementById("useDDPlus").checked;
const preferredLocale = document.getElementById("preferredLocale").value; const preferredLocale = document.getElementById("preferredLocale").value;
const preferredTextLocale = document.getElementById("preferredTextLocale").value; const preferredTextLocale = document.getElementById("preferredTextLocale").value;
@ -15,6 +16,7 @@ function save_options() {
setMaxBitrate: setMaxBitrate, setMaxBitrate: setMaxBitrate,
disableVP9: disableVP9, disableVP9: disableVP9,
disableAV1: disableAV1, disableAV1: disableAV1,
disableHPL: disableHPL,
useDDPlus: useDDPlus, useDDPlus: useDDPlus,
preferredLocale: preferredLocale, preferredLocale: preferredLocale,
preferredTextLocale: preferredTextLocale, preferredTextLocale: preferredTextLocale,
@ -33,6 +35,7 @@ function reset_options() {
document.getElementById("setMaxBitrate").checked = false; document.getElementById("setMaxBitrate").checked = false;
document.getElementById("disableVP9").checked = false; document.getElementById("disableVP9").checked = false;
document.getElementById("disableAV1").checked = true; document.getElementById("disableAV1").checked = true;
document.getElementById("disableHPL").checked = false;
document.getElementById("useDDPlus").checked = false; document.getElementById("useDDPlus").checked = false;
document.getElementById("preferredLocale").value = null; document.getElementById("preferredLocale").value = null;
document.getElementById("preferredTextLocale").value = null; document.getElementById("preferredTextLocale").value = null;
@ -43,6 +46,7 @@ function reset_options() {
setMaxBitrate: false, setMaxBitrate: false,
disableVP9: false, disableVP9: false,
disableAV1: true, disableAV1: true,
disableHPL: false,
useDDPlus: false, useDDPlus: false,
preferredLocale: null, preferredLocale: null,
preferredTextLocale: null, preferredTextLocale: null,
@ -62,6 +66,7 @@ function restore_options() {
setMaxBitrate: false, setMaxBitrate: false,
disableVP9: false, disableVP9: false,
disableAV1: true, disableAV1: true,
disableHPL: false,
useDDPlus: false, useDDPlus: false,
preferredLocale: null, preferredLocale: null,
preferredTextLocale: null, preferredTextLocale: null,
@ -71,6 +76,7 @@ function restore_options() {
document.getElementById("setMaxBitrate").checked = items.setMaxBitrate; document.getElementById("setMaxBitrate").checked = items.setMaxBitrate;
document.getElementById("disableVP9").checked = items.disableVP9; document.getElementById("disableVP9").checked = items.disableVP9;
document.getElementById("disableAV1").checked = items.disableAV1; document.getElementById("disableAV1").checked = items.disableAV1;
document.getElementById("disableHPL").checked = items.disableHPL;
document.getElementById("useDDPlus").checked = items.useDDPlus; document.getElementById("useDDPlus").checked = items.useDDPlus;
document.getElementById("preferredLocale").value = items.preferredLocale; document.getElementById("preferredLocale").value = items.preferredLocale;
document.getElementById("preferredTextLocale").value = items.preferredTextLocale; document.getElementById("preferredTextLocale").value = items.preferredTextLocale;