Yokan / rebuild
Course 1 8624561

YourUploadExtractor.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/services/media/extractors/YourUploadExtractor.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 * YourUpload embed extractor.12 *13 * Finds the `jwplayerOptions` script and reads its `file: '…'` literal.14 * YourUpload 403s without `Referer: https://www.yourupload.com/`, which we15 * always set on both the embed fetch and the emitted video headers.16 */17class YourUploadExtractor(18    private val http: HttpService,19) : AnimeExtractorService {2021    override val hostName: String get() = "yourupload"2223    override suspend fun extract(url: String, headers: Map<String, String>): ExtractorResult =24        extractVideos(headers) { videosFromUrl(url, headers) }2526    private suspend fun videosFromUrl(27        url: String,28        headers: Map<String, String>,29        name: String = "YourUpload",30        prefix: String = "",31    ): List<DbVideo> {32        val merged = headers.toMutableMap().apply { put("referer", REFERER) }33        val response = http.request(HttpRequest(url, headers = merged))34        if (response.statusCode !in 200..299) return emptyList()35        val script = ScriptTagRegex.findAll(response.body)36            .map { it.groupValues[1] }37            .firstOrNull { it.contains("jwplayerOptions") } ?: return emptyList()38        val file = script.substringAfter("file: '", "").substringBefore("',", "")39        if (file.isBlank()) return emptyList()40        val quality = prefix + name41        return listOf(DbVideo(url = file, quality = quality, originalUrl = file, headers = merged))42    }4344    private companion object {45        const val REFERER = "https://www.yourupload.com/"46    }47}48

Search chapters, reference and source filenames.