fixed Aniworld

This commit is contained in:
hexated 2023-06-30 10:27:10 +07:00
parent 8e1758872c
commit fa3a705a4b
2 changed files with 46 additions and 14 deletions

View file

@ -1,5 +1,5 @@
// use an integer for version numbers
version = 3
version = 4
cloudstream {

View file

@ -7,9 +7,11 @@ import com.lagradost.cloudstream3.extractors.DoodLaExtractor
import com.lagradost.cloudstream3.extractors.Voe
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.M3u8Helper
import com.lagradost.cloudstream3.utils.loadExtractor
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import java.net.URI
class Aniworld : MainAPI() {
override var mainUrl = "https://aniworld.to"
@ -144,6 +146,9 @@ class Aniworld : MainAPI() {
it.third != "Vidoza"
}.apmap {
val redirectUrl = app.get(fixUrl(it.second)).url
if (it.third == "VOE") {
invokeVoe(redirectUrl, data, callback)
} else {
loadExtractor(redirectUrl, data, subtitleCallback) { link ->
val name = "${link.name} [${it.first.getLanguage(document)}]"
callback.invoke(
@ -160,10 +165,31 @@ class Aniworld : MainAPI() {
)
}
}
}
return true
}
private suspend fun invokeVoe(
url: String,
referer: String,
callback: (ExtractorLink) -> Unit,
) {
val request = app.get(url, referer = referer)
val baseUrl = getBaseUrl(request.url)
val res = request.document
val script = res.select("script").find { it.data().contains("sources =") }?.data()
val link =
Regex("[\"']hls[\"']:\\s*[\"'](.*)[\"']").find(script ?: return)?.groupValues?.get(1)
M3u8Helper.generateM3u8(
name,
link ?: return,
"$baseUrl/",
headers = mapOf("Origin" to "$baseUrl/")
).forEach(callback)
}
private fun Element.toSearchResult(): AnimeSearchResponse? {
val href = fixUrlNull(this.selectFirst("a")?.attr("href")) ?: return null
val title = this.selectFirst("h3")?.text() ?: return null
@ -178,6 +204,12 @@ class Aniworld : MainAPI() {
?.removePrefix("mit")?.trim()
}
private fun getBaseUrl(url: String): String {
return URI(url).let {
"${it.scheme}://${it.host}"
}
}
private data class AnimeSearch(
@JsonProperty("link") val link: String,
@JsonProperty("title") val title: String? = null,