several fix

This commit is contained in:
hexated 2023-01-14 16:40:35 +07:00
parent 730556f5de
commit 7f83b0e73e
24 changed files with 479 additions and 372 deletions

View file

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

View file

@ -25,8 +25,6 @@ class NontonAnimeIDProvider : MainAPI() {
)
companion object {
private const val jikanAPI = "https://api.jikan.moe/v4"
fun getType(t: String): TvType {
return when {
t.contains("TV",true) -> TvType.Anime
@ -135,13 +133,7 @@ class NontonAnimeIDProvider : MainAPI() {
val description = document.select(".entry-content.seriesdesc > p").text().trim()
val trailer = document.selectFirst("a.trailerbutton")?.attr("href")
val malId = app.get("${jikanAPI}/anime?q=$title&start_date=${year}&type=$type&limit=1")
.parsedSafe<JikanResponse>()?.data?.firstOrNull()?.mal_id
val anilistId = app.post(
"https://graphql.anilist.co/", data = mapOf(
"query" to "{Media(idMal:$malId,type:ANIME){id}}",
)
).parsedSafe<DataAni>()?.data?.media?.id
val (malId, anilistId, image, cover) = getTracker(title, type, year)
val episodes = if (document.select("button.buttfilter").isNotEmpty()) {
val id = document.select("input[name=series_id]").attr("value")
@ -189,13 +181,14 @@ class NontonAnimeIDProvider : MainAPI() {
return newAnimeLoadResponse(title, url, getType(type)) {
engName = title
posterUrl = poster
posterUrl = image ?: poster
backgroundPosterUrl = cover ?: image ?: poster
this.year = year
addEpisodes(DubStatus.Subbed, episodes)
showStatus = status
this.rating = rating
plot = description
addMalId(malId?.toIntOrNull())
addMalId(malId)
addAniListId(anilistId?.toIntOrNull())
addTrailer(trailer)
this.tags = tags
@ -241,6 +234,43 @@ class NontonAnimeIDProvider : MainAPI() {
return true
}
private suspend fun getTracker(title: String?, type: String?, year: Int?): Tracker {
val res = app.get("https://api.consumet.org/meta/anilist/$title")
.parsedSafe<AniSearch>()?.results?.find { media ->
(media.title?.english.equals(title, true) || media.title?.romaji.equals(
title,
true
)) || (media.type.equals(type, true) && media.releaseDate == year)
}
return Tracker(res?.malId, res?.aniId, res?.image, res?.cover)
}
data class Tracker(
val malId: Int? = null,
val aniId: String? = null,
val image: String? = null,
val cover: String? = null,
)
data class Title(
@JsonProperty("romaji") val romaji: String? = null,
@JsonProperty("english") val english: String? = null,
)
data class Results(
@JsonProperty("id") val aniId: String? = null,
@JsonProperty("malId") val malId: Int? = null,
@JsonProperty("title") val title: Title? = null,
@JsonProperty("releaseDate") val releaseDate: Int? = null,
@JsonProperty("type") val type: String? = null,
@JsonProperty("image") val image: String? = null,
@JsonProperty("cover") val cover: String? = null,
)
data class AniSearch(
@JsonProperty("results") val results: java.util.ArrayList<Results>? = arrayListOf(),
)
private data class EpResponse(
@JsonProperty("posts") val posts: String?,
@JsonProperty("max_page") val max_page: Int?,
@ -248,23 +278,4 @@ class NontonAnimeIDProvider : MainAPI() {
@JsonProperty("content") val content: String
)
data class Data(
@JsonProperty("mal_id") val mal_id: String? = null,
)
data class JikanResponse(
@JsonProperty("data") val data: ArrayList<Data>? = arrayListOf(),
)
private data class IdAni(
@JsonProperty("id") val id: String? = null,
)
private data class MediaAni(
@JsonProperty("Media") val media: IdAni? = null,
)
private data class DataAni(
@JsonProperty("data") val data: MediaAni? = null,
)
}