Allow set subtitle language from url parameter (#2935)

* allow set subtitle language from url parameter

As user,
I want to set subtitles language from url parameters,
So i do not need to subtitle language each time i switch instances

for now you can set `subtitles=xx` (example: `subtitles=en`) on url
parameter to set video subtitle language.

full url example: https://piped.video/watch?v=6stlCkUDG_s&subtitles=en

i choose query `subtitles` so it's compatible with [invidious url
parameter](https://docs.invidious.io/url-parameters/)

this is especially useful when you have addons like redirector

improvement over https://github.com/TeamPiped/Piped/issues/2669 and
https://github.com/TeamPiped/Piped/issues/223

* cleaning code

* looks simpler and more self-explaining

fix suggested on
https://github.com/TeamPiped/Piped/pull/2937#discussion_r1325072807
This commit is contained in:
Andry Yosua 2023-09-14 13:51:50 +07:00 committed by GitHub
parent a2e2c74a38
commit 5b4fb38c85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -594,6 +594,16 @@ export default {
const autoDisplayCaptions = this.getPreferenceBoolean("autoDisplayCaptions", false); const autoDisplayCaptions = this.getPreferenceBoolean("autoDisplayCaptions", false);
this.$player.setTextTrackVisibility(autoDisplayCaptions); this.$player.setTextTrackVisibility(autoDisplayCaptions);
const prefSubtitles = this.getPreferenceString("subtitles", "");
if (prefSubtitles !== "") {
const textTracks = this.$player.getTextTracks();
const subtitleIdx = textTracks.findIndex(textTrack => textTrack.language == prefSubtitles);
if (subtitleIdx != -1) {
this.$player.setTextTrackVisibility(true);
this.$player.selectTextTrack(textTracks[subtitleIdx]);
}
}
}) })
.catch(e => { .catch(e => {
console.error(e); console.error(e);