possibly added mal sync

This commit is contained in:
KillerDogeEmpire 2023-02-04 19:48:42 -08:00
parent 1f255e555f
commit 0271fb3d1b
1 changed files with 52 additions and 40 deletions

View File

@ -2,8 +2,11 @@ package com.lagradost
import com.fasterxml.jackson.annotation.JsonProperty
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId
import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId
import com.lagradost.cloudstream3.LoadResponse.Companion.addActors
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
import com.lagradost.cloudstream3.R.string.year
import com.lagradost.cloudstream3.mvvm.safeApiCall
import com.lagradost.cloudstream3.ui.settings.SettingsProviders
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
@ -211,6 +214,7 @@ class AllAnimeProvider : MainAPI() {
override suspend fun load(url: String): LoadResponse? {
val document = app.get(url).document
val rhino = Context.enter()
rhino.initSafeStandardObjects()
rhino.optimizationLevel = -1
@ -218,11 +222,11 @@ class AllAnimeProvider : MainAPI() {
val html = app.get(url).text
val soup = Jsoup.parse(html)
val (malId, anilistId, image, cover) = getTracker(title, typeCheck, year)
val script = soup.select("script").firstOrNull {
it.html().contains("window.__NUXT__")
} ?: return null
val js = """
const window = {}
${script.html()}
@ -234,10 +238,20 @@ class AllAnimeProvider : MainAPI() {
val showData = parseJson<Edges>(jsEval as String)
val typeCheck =
when (document.select(".info-content > .spe > span:nth-child(5), .info-content > .spe > span")
.text().trim()) {
"OVA" -> "OVA"
"Movie" -> "Movie"
else -> "TV"
}
val title = showData.name
val description = showData.description
val poster = showData.thumbnail
val (malId, anilistId, image, cover) = getTracker(title, typeCheck, year)
val episodes = showData.availableEpisodes.let {
if (it == null) return@let Pair(null, null)
Pair(if (it.sub != 0) ((1..it.sub).map { epNum ->
@ -417,8 +431,16 @@ class AllAnimeProvider : MainAPI() {
).path),
Qualities.P1080.value,
false
)
)
}
}
}
}
}
}
return true
}
private suspend fun getTracker(title: String?, type: String?, year: Int?): Tracker {
val res = app.get("https://api.consumet.org/meta/anilist/$title")
@ -455,16 +477,6 @@ class AllAnimeProvider : MainAPI() {
data class AniSearch(
@JsonProperty("results") val results: ArrayList<Results>? = arrayListOf(),
)
)
)
}
}
}
}
}
}
return true
}
)
}