Tweak code
This commit is contained in:
@@ -1,24 +1,25 @@
|
||||
package it.vfsfitvnm.youtubemusic.utils
|
||||
|
||||
import io.ktor.utils.io.CancellationException
|
||||
import it.vfsfitvnm.youtubemusic.Innertube
|
||||
import it.vfsfitvnm.youtubemusic.models.SectionListRenderer
|
||||
|
||||
internal fun SectionListRenderer.findSectionByTitle(text: String): SectionListRenderer.Content? {
|
||||
return contents?.find { content ->
|
||||
val title = content
|
||||
.musicCarouselShelfRenderer
|
||||
?.header
|
||||
?.musicCarouselShelfBasicHeaderRenderer
|
||||
val title = content
|
||||
.musicCarouselShelfRenderer
|
||||
?.header
|
||||
?.musicCarouselShelfBasicHeaderRenderer
|
||||
?.title
|
||||
?: content
|
||||
.musicShelfRenderer
|
||||
?.title
|
||||
?: content
|
||||
.musicShelfRenderer
|
||||
?.title
|
||||
|
||||
title
|
||||
?.runs
|
||||
?.firstOrNull()
|
||||
?.text == text
|
||||
}
|
||||
title
|
||||
?.runs
|
||||
?.firstOrNull()
|
||||
?.text == text
|
||||
}
|
||||
}
|
||||
|
||||
internal fun SectionListRenderer.findSectionByStrapline(text: String): SectionListRenderer.Content? {
|
||||
@@ -31,14 +32,19 @@ internal fun SectionListRenderer.findSectionByStrapline(text: String): SectionLi
|
||||
?.runs
|
||||
?.firstOrNull()
|
||||
?.text == text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal inline fun <R> runCatchingNonCancellable(block: () -> R): Result<R>? {
|
||||
return Result.success(block())
|
||||
// val result = runCatching(block)
|
||||
// return when (val ex = result.exceptionOrNull()) {
|
||||
// is CancellationException -> null
|
||||
// else -> result
|
||||
// }
|
||||
val result = runCatching(block)
|
||||
return when (result.exceptionOrNull()) {
|
||||
is CancellationException -> null
|
||||
else -> result
|
||||
}
|
||||
}
|
||||
|
||||
infix operator fun <T : Innertube.Item> Innertube.ItemsPage<T>?.plus(other: Innertube.ItemsPage<T>) =
|
||||
other.copy(
|
||||
items = this?.items?.plus(other.items ?: emptyList())?.distinctBy(Innertube.Item::key)
|
||||
?: other.items
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user