Yokan / rebuild
Course 1 8624561

AnimeExtractorService.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/services/media/AnimeExtractorService.kt

implementation29 lines
1package eu.friedcutlet.yokan.services.media23import eu.friedcutlet.yokan.database.DbVideo4import eu.friedcutlet.yokan.services.catchingNonCancellation5import eu.friedcutlet.yokan.services.extensions.ExtensionLogger67interface AnimeExtractorService {8    val hostName: String9    suspend fun extract(url: String, headers: Map<String, String> = emptyMap()): ExtractorResult10}1112data class ExtractorResult(13    val videos: List<DbVideo>,14    val headers: Map<String, String> = emptyMap(),15)1617/**18 * Runs [block] for [AnimeExtractorService.extract]: failures are logged and19 * yield no videos, cancellation propagates. [headers] are returned either way.20 */21internal inline fun AnimeExtractorService.extractVideos(22    headers: Map<String, String>,23    block: () -> List<DbVideo>,24): ExtractorResult {25    val videos = catchingNonCancellation(block)26        .onFailure { ExtensionLogger.error(hostName, "extract", it) }27        .getOrDefault(emptyList())28    return ExtractorResult(videos = videos, headers = headers)29}30

Search chapters, reference and source filenames.