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

This commit is contained in:
Kayos 2026-05-26 07:08:39 -07:00
parent 964bcddb3a
commit 62cc18c940

View file

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