mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
Fix subtitle smart mode to check chosen audio language (#420)
Fixes how the smart subtitle mode logic works Fixes #406
This commit is contained in:
parent
319b46983f
commit
c5c0dff705
3 changed files with 50 additions and 25 deletions
|
|
@ -59,6 +59,7 @@ class ItemPlaybackRepository
|
|||
)
|
||||
val subtitleStream =
|
||||
streamChoiceService.chooseSubtitleStream(
|
||||
audioStream = audioStream,
|
||||
candidates =
|
||||
source.mediaStreams
|
||||
?.filter { it.type == MediaStreamType.SUBTITLE }
|
||||
|
|
|
|||
|
|
@ -91,22 +91,17 @@ class StreamChoiceService
|
|||
result
|
||||
}
|
||||
|
||||
suspend fun chooseStream(
|
||||
suspend fun chooseAudioStream(
|
||||
source: MediaSourceInfo,
|
||||
seriesId: UUID?,
|
||||
itemPlayback: ItemPlayback?,
|
||||
plc: PlaybackLanguageChoice?,
|
||||
type: MediaStreamType,
|
||||
prefs: UserPreferences,
|
||||
): MediaStream? {
|
||||
val plc = plc ?: seriesId?.let { playbackLanguageChoiceDao.get(serverRepository.currentUser.value!!.rowId, it) }
|
||||
return source.mediaStreams?.letNotEmpty { streams ->
|
||||
val candidates = streams.filter { it.type == type }
|
||||
when (type) {
|
||||
MediaStreamType.AUDIO -> chooseAudioStream(candidates, itemPlayback, plc, prefs)
|
||||
MediaStreamType.SUBTITLE -> chooseSubtitleStream(candidates, itemPlayback, plc, prefs)
|
||||
else -> candidates.firstOrNull()
|
||||
}
|
||||
val candidates = streams.filter { it.type == MediaStreamType.AUDIO }
|
||||
chooseAudioStream(candidates, itemPlayback, plc, prefs)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +137,35 @@ class StreamChoiceService
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun chooseSubtitleStream(
|
||||
source: MediaSourceInfo,
|
||||
audioStream: MediaStream?,
|
||||
seriesId: UUID?,
|
||||
itemPlayback: ItemPlayback?,
|
||||
plc: PlaybackLanguageChoice?,
|
||||
prefs: UserPreferences,
|
||||
): MediaStream? {
|
||||
val plc =
|
||||
plc ?: seriesId?.let {
|
||||
playbackLanguageChoiceDao.get(
|
||||
serverRepository.currentUser.value!!.rowId,
|
||||
it,
|
||||
)
|
||||
}
|
||||
return source.mediaStreams?.letNotEmpty { streams ->
|
||||
val candidates = streams.filter { it.type == MediaStreamType.SUBTITLE }
|
||||
chooseSubtitleStream(
|
||||
audioStream,
|
||||
candidates,
|
||||
itemPlayback,
|
||||
plc,
|
||||
prefs,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun chooseSubtitleStream(
|
||||
audioStream: MediaStream?,
|
||||
candidates: List<MediaStream>,
|
||||
itemPlayback: ItemPlayback?,
|
||||
playbackLanguageChoice: PlaybackLanguageChoice?,
|
||||
|
|
@ -202,7 +225,8 @@ class StreamChoiceService
|
|||
|
||||
SubtitlePlaybackMode.SMART -> {
|
||||
val audioLanguage = prefs.userConfig.audioLanguagePreference
|
||||
if (audioLanguage != null && subtitleLanguage != null && audioLanguage != subtitleLanguage) {
|
||||
val audioStreamLang = audioStream?.language
|
||||
if (audioLanguage.isNotNullOrBlank() && audioStreamLang.isNotNullOrBlank() && audioLanguage != audioStreamLang) {
|
||||
candidates.firstOrNull { it.language == subtitleLanguage }
|
||||
} else {
|
||||
null
|
||||
|
|
|
|||
|
|
@ -366,26 +366,26 @@ class PlaybackViewModel
|
|||
?.sortedWith(compareBy<AudioStream> { it.language }.thenByDescending { it.channels })
|
||||
.orEmpty()
|
||||
|
||||
val audioIndex =
|
||||
val audioStream =
|
||||
streamChoiceService
|
||||
.chooseStream(
|
||||
mediaSource,
|
||||
base.seriesId,
|
||||
playbackConfig,
|
||||
plc,
|
||||
MediaStreamType.AUDIO,
|
||||
preferences,
|
||||
)?.index
|
||||
.chooseAudioStream(
|
||||
source = mediaSource,
|
||||
seriesId = base.seriesId,
|
||||
itemPlayback = playbackConfig,
|
||||
plc = plc,
|
||||
prefs = preferences,
|
||||
)
|
||||
val audioIndex = audioStream?.index
|
||||
|
||||
val subtitleIndex =
|
||||
streamChoiceService
|
||||
.chooseStream(
|
||||
mediaSource,
|
||||
base.seriesId,
|
||||
playbackConfig,
|
||||
plc,
|
||||
MediaStreamType.SUBTITLE,
|
||||
preferences,
|
||||
.chooseSubtitleStream(
|
||||
source = mediaSource,
|
||||
audioStream = audioStream,
|
||||
seriesId = base.seriesId,
|
||||
itemPlayback = playbackConfig,
|
||||
plc = plc,
|
||||
prefs = preferences,
|
||||
)?.index
|
||||
|
||||
Timber.d("Selected mediaSource=${mediaSource.id}, audioIndex=$audioIndex, subtitleIndex=$subtitleIndex")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue