fixup vc=48: pickAutoplayCandidate uses try/catch (runCatching not suspend-aware)
This commit is contained in:
parent
a6db9ccc19
commit
487296617f
1 changed files with 34 additions and 40 deletions
|
|
@ -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
|
val watched = if (Settings.get().autoplaySkipWatched.value) {
|
||||||
AutoplayMode.SameChannel -> {
|
History.get().watches.value.map { it.videoId }.toSet()
|
||||||
if (uploaderUrl.isNullOrBlank()) null
|
} else emptySet()
|
||||||
else runCatching {
|
fun unwatched(url: String): Boolean {
|
||||||
val ch = uniffi.strawcore.channelInfo(uploaderUrl)
|
if (watched.isEmpty()) return true
|
||||||
val watched = if (Settings.get().autoplaySkipWatched.value) {
|
val id = com.sulkta.straw.feature.detail.extractYtVideoId(url)
|
||||||
History.get().watches.value.map { it.videoId }.toSet()
|
return id == null || id !in watched
|
||||||
} 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()
|
|
||||||
}
|
}
|
||||||
AutoplayMode.YtRelated -> {
|
return try {
|
||||||
runCatching {
|
when (mode) {
|
||||||
val info = uniffi.strawcore.streamInfo(currentStreamUrl)
|
AutoplayMode.Off -> null
|
||||||
val watched = if (Settings.get().autoplaySkipWatched.value) {
|
AutoplayMode.SameChannel -> {
|
||||||
History.get().watches.value.map { it.videoId }.toSet()
|
if (uploaderUrl.isNullOrBlank()) return null
|
||||||
} else emptySet()
|
val ch = uniffi.strawcore.channelInfo(uploaderUrl)
|
||||||
info.related
|
ch.videos
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.filter { it.url != currentStreamUrl }
|
.filter { it.url != currentStreamUrl }
|
||||||
.filter {
|
.filter { unwatched(it.url) }
|
||||||
if (watched.isEmpty()) true
|
.firstOrNull()?.url
|
||||||
else {
|
}
|
||||||
val id = com.sulkta.straw.feature.detail.extractYtVideoId(it.url)
|
AutoplayMode.YtRelated -> {
|
||||||
id == null || id !in watched
|
val info = uniffi.strawcore.streamInfo(currentStreamUrl)
|
||||||
}
|
info.related
|
||||||
}
|
.asSequence()
|
||||||
.firstOrNull()?.url
|
.filter { it.url != currentStreamUrl }
|
||||||
}.getOrNull()
|
.filter { unwatched(it.url) }
|
||||||
|
.firstOrNull()?.url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (c: kotlinx.coroutines.CancellationException) {
|
||||||
|
throw c
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue