fallback language for captions

This commit is contained in:
Toni Förster
2024-05-20 14:40:25 +02:00
parent c9125644ed
commit 4fa5a15ad4
3 changed files with 65 additions and 10 deletions

View File

@@ -219,10 +219,17 @@ final class MPVBackend: PlayerBackend {
var captions: Captions?
if Defaults[.captionsAutoShow] == true {
let captionsLanguageCode = Defaults[.captionsDefaultLanguageCode]
if !captionsLanguageCode.isEmpty {
captions = video.captions.first { $0.code == captionsLanguageCode } ??
video.captions.first { $0.code.contains(captionsLanguageCode) }
let captionsDefaultLanguageCode = Defaults[.captionsDefaultLanguageCode],
captionsFallbackLanguageCode = Defaults[.captionsFallbackLanguageCode]
// Try to get captions with the default language code first
captions = video.captions.first { $0.code == captionsDefaultLanguageCode } ??
video.captions.first { $0.code.contains(captionsDefaultLanguageCode) }
// If there are still no captions, try to get captions with the fallback language code
if captions.isNil && !captionsFallbackLanguageCode.isEmpty {
captions = video.captions.first { $0.code == captionsFallbackLanguageCode } ??
video.captions.first { $0.code.contains(captionsFallbackLanguageCode) }
}
} else {
captions = nil