[Not directly LLN Related] Shortcuts to switch audio/sub language

Hey, I wrote a code for a hotkey [u] to automatically select audio/subtitles language for me, it simulates clicking on the subs icon, then clicking on a preferred audio lang and a preferred subtitles lang.

function changeLang(){
   // click on the subtitles icon to open it
	document.getElementsByClassName("button-nfplayerSubtitles")[0].click();
	
	setTimeout(function(){ // delay to give the subs menu time to show up
	    
       // order of preffered langs
	    var prefAudioLangs = [
	      "ruso [Original]",
	      "ruso",
	      "español de España - Audio descriptivo",
	      "español - Audio descriptivo",
	      "español de España [Original]",
	      "español [Original]",
	      "español de España",
	      "español"
	    ];
	
	
// get available audio langs
	var audioLangs = document.querySelectorAll("div.track-list-audio > ul > li");
	    var found = false;
	    for (let io = 0; io < prefAudioLangs.length; io++) {
	
	        for (let i = 0; i < audioLangs.length; i++) {
	            if (audioLangs[i].innerText == prefAudioLangs[io]){
	                audioLangs[i].click();
	                var chosenAudio = audioLangs[i].innerText;
	                found = true;
	                break;
	            }
	        }
	
	        if(found){ break; }
	    }
	
         // define preffered subtitle langs
		if ( chosenAudio.includes("ruso") ){
			
			var prefSubtLangs = [
		      "ruso [CC]",
		      "ruso"
		    ];
			
		} else {
	
		    var prefSubtLangs = [
		      "español de España [CC]",
		      "español de España",
		      "español [CC]",
		      "español"
		    ];
		}
	
		var subtLangs = document.querySelectorAll("div.track-list-subtitles > ul > li");
	
	    var found = false;
	    for (let io = 0; io < prefSubtLangs.length; io++) {
	
	        for (let i = 0; i < subtLangs.length; i++) {
	            if (subtLangs[i].innerText == prefSubtLangs[io]){
	                subtLangs[i].click();
	                found = true;
	                break;
	            }
	        }
	
	        if(found){ break; }
	    }
	
	     // click subs icon to hide the menu
		setTimeout(function(){ 
		document.getElementsByClassName("button-nfplayerSubtitles")[0].click();
		}, 2000 );
		
	
	}, 1000 );
	
}


function mylistener(e) {
    if ( e.keyCode == 85) { // U 
        changeLang();
    }
}
document.addEventListener('keyup', mylistener, false);

The problem is that when the UI is hidden the subs icon doesn’t exist ( document.getElementsByClassName(“button-nfplayerSubtitles”) returns nothing ), so every time before clicking the shortcut i have to move the mouse on the screen to show the UI.

Would you have any idea how to show the netflix UI using JS so i can use this shortcut even when the UI is hidden without having to move the mouse before?

I have a set of 3 shortcuts like these, for each english,russian and spannish allowing me to quickly switch between then, as the list of langs is quite long and not sorted so its a pain to do it manually.

1 Like

Hey, I can expose an API to do this for you, we communicate with the Netflix player directly. Gimme
 15 mins.

1 Like

Ok, you can call window.setSubtitleLang(“ru”) and window.setAudioLang(“ru”). Just, be careful not to call them in a loop or something (too often), every change might be making new requests to Netflix’s servers and they might not like it. :slight_smile:

You feed it google translate style language codes (“ru”, “es”). The function returns false if it can’t find a suitable track. It will try to set regular subs first, then CC
 and regular audio first, then ‘for the blind’ audio second. Huh, ok, you might want this in the other order.

Maybe this is good enough: Force Original Tracks (now a setting) ? Shouldn’t be studying instead of writing JS? :slight_smile:

1 Like

Oh my god! It will be amazing to have this!! :heart_eyes: Thanks soooo much!:clap:

edited response above. Are you getting email notifications from the forum btw? I think that is broken still.

Yeah, “audio description” is my priority for learning langs as it describes what you can see on the screen, so much easier to comprehend and also fills in the empty gaps. Will it be possible to change that order?

Ps. this function will become available with the next extension update, its not available already right?

Yup the email notifications seam to work fine.

Oh, so its been LLN thats been switching my audio to original all this time?!:sweat_smile:

Well, im trying to learn some JS as im a complete noobie!

:slight_smile: Check ‘Modern Russian’ I and II (Clayton). It’s actually from 1960s, but no matter, great course. About thirty something hours of audio drills. https://www.abebooks.co.uk/book-search/title/modern-russian-1/author/dawson-clayton-l-bidwell-charles-e-humesky-assya/

“MP3 audio files are freely available via Indiana University’s CeLt website.” Some more info here: https://forum.language-learners.org/viewtopic.php?t=5568

Minsk State Linguistic University is a great place to study Russian, the courses and accomodation used to be very inexpensive.

Thanks so much for this man!

btw. What languages do you know / learn / are currently interested in?:thinking: