From c4a5dfe065e0bb07671381a16b29ca2c4a11a3a9 Mon Sep 17 00:00:00 2001 From: hexated Date: Fri, 3 Feb 2023 10:16:37 +0700 Subject: [PATCH] [test] added lib support in YugenAnime --- YugenAnime/build.gradle.kts | 2 +- .../src/main/kotlin/com/hexated/YugenAnime.kt | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/YugenAnime/build.gradle.kts b/YugenAnime/build.gradle.kts index 8f6bfe58..62cdb34d 100644 --- a/YugenAnime/build.gradle.kts +++ b/YugenAnime/build.gradle.kts @@ -1,5 +1,5 @@ // use an integer for version numbers -version = 3 +version = 4 cloudstream { diff --git a/YugenAnime/src/main/kotlin/com/hexated/YugenAnime.kt b/YugenAnime/src/main/kotlin/com/hexated/YugenAnime.kt index 11705147..ddaeab16 100644 --- a/YugenAnime/src/main/kotlin/com/hexated/YugenAnime.kt +++ b/YugenAnime/src/main/kotlin/com/hexated/YugenAnime.kt @@ -5,6 +5,7 @@ import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer +import com.lagradost.cloudstream3.syncproviders.SyncIdName import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.M3u8Helper import org.jsoup.nodes.Document @@ -18,6 +19,11 @@ class YugenAnime : MainAPI() { override var lang = "en" override val hasDownloadSupport = true + override val supportedSyncNames = setOf( + SyncIdName.Anilist, + SyncIdName.MyAnimeList + ) + override val supportedTypes = setOf( TvType.Anime, TvType.AnimeMovie, @@ -25,6 +31,9 @@ class YugenAnime : MainAPI() { ) companion object { + private const val consumetAnilist = "https://api.consumet.org/meta/anilist" + private const val consumetMal = "https://api.consumet.org/meta/mal" + fun getType(t: String): TvType { return if (t.contains("OVA", true) || t.contains("Special", true)) TvType.OVA else if (t.contains("Movie", true)) TvType.AnimeMovie @@ -81,6 +90,28 @@ class YugenAnime : MainAPI() { } } + override suspend fun getLoadUrl(name: SyncIdName, id: String): String? { + val syncId = id.split("/").last() + val url = if (name == SyncIdName.Anilist) { + "${consumetAnilist}/info/$syncId" + } else { + "${consumetMal}/info/$syncId" + } + val res = app.get(url).parsedSafe() + + val title = res?.title?.romaji ?: res?.title?.english + val year = res?.startDate?.year + val season = res?.season + + val document = app.get("$mainUrl/discover/?q=$title").document + val syncUrl = document.select("div.cards-grid a.anime-meta").find { + it.attr("title").equals(title, true) || it.select("div.anime-details span").text().equals("$season $year", true) + }?.attr("href") + + return fixUrl(syncUrl ?: return null) + + } + override suspend fun load(url: String): LoadResponse? { val document = app.get(url).document @@ -185,4 +216,19 @@ class YugenAnime : MainAPI() { @JsonProperty("hls") val hls: List? = null, ) + data class SyncTitle( + @JsonProperty("romaji") val romaji: String? = null, + @JsonProperty("english") val english: String? = null, + ) + + data class StartDate( + @JsonProperty("year") val year: Int? = null, + ) + + data class SyncInfo( + @JsonProperty("title") val title: SyncTitle? = null, + @JsonProperty("startDate") val startDate: StartDate? = null, + @JsonProperty("season") val season: String? = null, + ) + } \ No newline at end of file