Skip to content

Instantly share code, notes, and snippets.

@djsegal
Last active April 15, 2024 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djsegal/f3301b198cdee8c7457c7713de1c47bd to your computer and use it in GitHub Desktop.
Save djsegal/f3301b198cdee8c7457c7713de1c47bd to your computer and use it in GitHub Desktop.
File for robustly loading language reactor with german subtitles
let isRepairingTracks = false;
let wasPlaying = false;
let videoLoaded = false;
let isWaiting = false;
function setTracks() {
if (!document.querySelector('video')) {
return;
}
videoLoaded = true;
let isGoodTrack = (
(window.lln.setMan.sourceLanguageCode === "de") &&
(window.lln.setMan.translationLanguageCode === "en")
);
if (!isGoodTrack) {
wasPlaying = !document.querySelector('video').paused;
window.lln.vidMan.setAudioTrack("A:2:1;2;de;0;0;");
window.lln.vidMan.setSubtitleTrack("ASR_A:2:1;2;de;0;0;");
if (wasPlaying) {
document.querySelector('video').pause();
}
isRepairingTracks = true;
return;
}
if (!isRepairingTracks) {
return;
}
let thisMessage = $("#lln-subs-content").text().trim();
let thatMessage = "- Loading subtitles, please wait... -";
if (thisMessage === thatMessage) {
if (!document.querySelector('video').paused) {
document.querySelector('video').pause();
}
return;
}
console.log(thisMessage);
if (wasPlaying) {
console.log("custom video play.");
document.querySelector('video').play();
wasPlaying = false;
isRepairingTracks = false;
}
}
function waitForLLN(tries = 0) {
console.log([111, tries, isWaiting])
if (isWaiting) {
if (tries == 0) {
return;
}
} else {
isWaiting = true;
}
let isLoaded = (
document.querySelector('video') &&
(window.lln && window.lln.vidMan)
)
console.log("doh.")
if (isLoaded) {
console.log("Loaded custom language connector successfully.")
setInterval(setTracks, 1000);
return
}
if (tries > 30) {
isWaiting = false;
console.log("Custom language connector failed.");
return
}
setTimeout(function() {
waitForLLN(tries + 1);
}, 500);
}
waitForLLN();
document.addEventListener('pointerdown', (event) => {
if (!videoLoaded) {
console.log(404, isWaiting);
waitForLLN();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment