fixup vc=48: pickAutoplayCandidate uses try/catch (runCatching not suspend-aware)

This commit is contained in:
Sulkta 2026-05-26 07:08:39 -07:00
parent a6db9ccc19
commit 487296617f

View file

@ -206,50 +206,44 @@ class PlaybackService : MediaSessionService() {
} }
} }
private fun pickAutoplayCandidate( private suspend fun pickAutoplayCandidate(
mode: AutoplayMode, mode: AutoplayMode,
currentStreamUrl: String, currentStreamUrl: String,
uploaderUrl: String?, uploaderUrl: String?,
): String? = when (mode) { ): String? {
AutoplayMode.Off -> null
AutoplayMode.SameChannel -> {
if (uploaderUrl.isNullOrBlank()) null
else runCatching {
val ch = uniffi.strawcore.channelInfo(uploaderUrl)
val watched = if (Settings.get().autoplaySkipWatched.value) { val watched = if (Settings.get().autoplaySkipWatched.value) {
History.get().watches.value.map { it.videoId }.toSet() History.get().watches.value.map { it.videoId }.toSet()
} else emptySet() } else emptySet()
fun unwatched(url: String): Boolean {
if (watched.isEmpty()) return true
val id = com.sulkta.straw.feature.detail.extractYtVideoId(url)
return id == null || id !in watched
}
return try {
when (mode) {
AutoplayMode.Off -> null
AutoplayMode.SameChannel -> {
if (uploaderUrl.isNullOrBlank()) return null
val ch = uniffi.strawcore.channelInfo(uploaderUrl)
ch.videos ch.videos
.asSequence() .asSequence()
.filter { it.url != currentStreamUrl } .filter { it.url != currentStreamUrl }
.filter { .filter { unwatched(it.url) }
if (watched.isEmpty()) true
else {
val id = com.sulkta.straw.feature.detail.extractYtVideoId(it.url)
id == null || id !in watched
}
}
.firstOrNull()?.url .firstOrNull()?.url
}.getOrNull()
} }
AutoplayMode.YtRelated -> { AutoplayMode.YtRelated -> {
runCatching {
val info = uniffi.strawcore.streamInfo(currentStreamUrl) val info = uniffi.strawcore.streamInfo(currentStreamUrl)
val watched = if (Settings.get().autoplaySkipWatched.value) {
History.get().watches.value.map { it.videoId }.toSet()
} else emptySet()
info.related info.related
.asSequence() .asSequence()
.filter { it.url != currentStreamUrl } .filter { it.url != currentStreamUrl }
.filter { .filter { unwatched(it.url) }
if (watched.isEmpty()) true
else {
val id = com.sulkta.straw.feature.detail.extractYtVideoId(it.url)
id == null || id !in watched
}
}
.firstOrNull()?.url .firstOrNull()?.url
}.getOrNull() }
}
} catch (c: kotlinx.coroutines.CancellationException) {
throw c
} catch (_: Throwable) {
null
} }
} }