Add support for multiple caption languages

This commit is contained in:
Brahim Hadriche committed 2023-01-29 20:27:24 -05:00
1 parent d91411b740
commit 5aac07d36c
3 files changed
+198 -16

No files matched your search

@@ -1,24 +1,19 @@
function SetCaptions(metadata as object, videoPlayer as object, contentNode as object) as void
' TODO: check if we have caption settings ON
' TODO: read favorate language from system settings
' TODO: populate list of caption tracks
if metadata.captions.Count() = 0
return
end if
videoPlayer.globalCaptionMode = "ON"
contentNode.ClosedCaptions = True
selectedCaption = metadata.captions[0]
isoLanguageList = ParseJson(ReadAsciiFile("libpkg:/config/ISO-639-1-to-ISO-639-2T.json"))
instance = InvidiousSettings.GetSelectedInstance()
subtitleTracks = []
' Use favorite caption langauage, or the first one
for each caption in metadata.captions
if caption.language_code = "en"
selectedCaption = caption
exit for
end if
subtitleTracks.Push({
Description: caption.label,
Language: isoLanguageList[caption.language_code] ?? caption.language_code,
TrackName: instance + caption.url
})
end for
contentNode.SubtitleConfig = {
ShowSubtitle: 1,
TrackName: InvidiousSettings.GetSelectedInstance() + selectedCaption.url
}
contentNode.ClosedCaptions = True
contentNode.SubtitleTracks = subtitleTracks
end function