fix(lib/dood): Make extractor accept all dood hosts (#1921)

This commit is contained in:
adly98
2023-07-18 17:11:15 +03:00
committed by GitHub
parent 96eac08a7b
commit 0d5425616c

View File

@ -12,13 +12,13 @@ class DoodExtractor(private val client: OkHttpClient) {
quality: String? = null,
redirect: Boolean = true,
): Video? {
val newQuality = quality ?: "Doodstream" + if (redirect) " mirror" else ""
val newQuality = quality ?: ("Doodstream" + if (redirect) " mirror" else "")
return runCatching {
val response = client.newCall(GET(url)).execute()
val newUrl = if (redirect) response.request.url.toString() else url
val doodTld = newUrl.substringAfter("https://dood.").substringBefore("/")
val doodHost = Regex("https://(.*?)/").find(newUrl)!!.groupValues[1]
val content = response.body.string()
if (!content.contains("'/pass_md5/")) return null
val md5 = content.substringAfter("'/pass_md5/").substringBefore("',")
@ -27,12 +27,12 @@ class DoodExtractor(private val client: OkHttpClient) {
val expiry = System.currentTimeMillis()
val videoUrlStart = client.newCall(
GET(
"https://dood.$doodTld/pass_md5/$md5",
"https://$doodHost/pass_md5/$md5",
Headers.headersOf("referer", newUrl),
),
).execute().body.string()
val videoUrl = "$videoUrlStart$randomString?token=$token&expiry=$expiry"
Video(newUrl, newQuality, videoUrl, headers = doodHeaders(doodTld))
Video(newUrl, newQuality, videoUrl, headers = doodHeaders(doodHost))
}.getOrNull()
}
@ -52,8 +52,8 @@ class DoodExtractor(private val client: OkHttpClient) {
.joinToString("")
}
private fun doodHeaders(tld: String) = Headers.Builder().apply {
private fun doodHeaders(host: String) = Headers.Builder().apply {
add("User-Agent", "Aniyomi")
add("Referer", "https://dood.$tld/")
add("Referer", "https://$host/")
}.build()
}