Yokan / rebuild
Course 1 8624561

VidBomExtractor.kt

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

implementation47 lines
1package eu.friedcutlet.yokan.services.media.extractors23import eu.friedcutlet.yokan.database.DbVideo4import eu.friedcutlet.yokan.services.http.HttpRequest5import eu.friedcutlet.yokan.services.http.HttpService6import eu.friedcutlet.yokan.services.media.AnimeExtractorService7import eu.friedcutlet.yokan.services.media.ExtractorResult8import eu.friedcutlet.yokan.services.media.extractVideos910/**11 * VidBom (and VidShare) embed extractor.12 *13 * The player exposes its `sources: [ { file: "…", label: "…" }, … ]` block14 * inside a `<script>` tag. We slice the block out and split on `file:"` to15 * iterate the entries.16 *17 * The Flutter source keys VidShare off "the label longer than 15 characters"18 * — we preserve that quirk because it's what shipped sources rely on.19 */20class VidBomExtractor(21    private val http: HttpService,22) : AnimeExtractorService {2324    override val hostName: String get() = "vidbom"2526    override suspend fun extract(url: String, headers: Map<String, String>): ExtractorResult =27        extractVideos(headers) { videosFromUrl(url) }2829    private suspend fun videosFromUrl(url: String): List<DbVideo> {30        val response = http.request(HttpRequest(url))31        if (response.statusCode !in 200..299) return emptyList()32        val script = ScriptTagRegex.findAll(response.body)33            .map { it.groupValues[1] }34            .firstOrNull { it.contains("sources") } ?: return emptyList()35        val block = script36            .substringAfter("sources: [", "")37            .substringBefore("],", "")38        if (block.isBlank()) return emptyList()39        return block.split("file:\"").drop(1).mapNotNull { entry ->40            val src = entry.substringBefore("\"", "")41            if (src.isBlank()) return@mapNotNull null42            val rawLabel = entry.substringAfter("label:\"", "").substringBefore("\"", "")43            val quality = if (rawLabel.length > 15) "Vidshare - 480p" else "Vidbom - $rawLabel"44            DbVideo(url = src, quality = quality, originalUrl = src)45        }46    }47}48

Search chapters, reference and source filenames.