animeua: Add MAL/AniList

This commit is contained in:
CakesTwix 2023-03-03 15:38:26 +02:00
parent 70e197c958
commit e21570f834
Signed by: CakesTwix
GPG key ID: 7B11051D5CE19825
3 changed files with 75 additions and 6 deletions

View file

@ -1,5 +1,5 @@
// use an integer for version numbers // use an integer for version numbers
version = 1 version = 2
cloudstream { cloudstream {
@ -16,7 +16,7 @@ cloudstream {
* 2: Slow * 2: Slow
* 3: Beta only * 3: Beta only
* */ * */
status = 3 // will be 3 if unspecified status = 1 // will be 3 if unspecified
tvTypes = listOf( tvTypes = listOf(
"Anime", "Anime",
"AnimeMovie", "AnimeMovie",

View file

@ -1,7 +1,10 @@
package com.lagradost package com.lagradost
import android.util.Log
import com.lagradost.models.PlayerJson import com.lagradost.models.PlayerJson
import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId
import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.M3u8Helper import com.lagradost.cloudstream3.utils.M3u8Helper
@ -55,13 +58,14 @@ class AnimeUAProvider : MainAPI() {
return newHomePageResponse(request.name, home) return newHomePageResponse(request.name, home)
} }
private fun Element.toSearchResponse(): SearchResponse { private fun Element.toSearchResponse(): AnimeSearchResponse {
val title = this.selectFirst(titleSelector)?.text()?.trim().toString() val title = this.selectFirst(titleSelector)?.text()?.trim().toString()
val href = this.selectFirst(hrefSelector)?.attr("href").toString() val href = this.selectFirst(hrefSelector)?.attr("href").toString()
val posterUrl = mainUrl + this.selectFirst(posterSelector)?.attr("data-src") val posterUrl = mainUrl + this.selectFirst(posterSelector)?.attr("data-src")
val status = this.select(".poster__label").text()
return newMovieSearchResponse(title, href, TvType.Anime) { return newAnimeSearchResponse(title, href, TvType.Anime) {
this.posterUrl = posterUrl this.posterUrl = posterUrl
addDubStatus(isDub = true)
} }
} }
@ -87,6 +91,7 @@ class AnimeUAProvider : MainAPI() {
// Parse info // Parse info
val title = document.selectFirst(titleLoadSelector)?.text()?.trim().toString() val title = document.selectFirst(titleLoadSelector)?.text()?.trim().toString()
val engTitle = document.select(".pmovie__original-title").text()
val poster = mainUrl + document.selectFirst("div.page__subcol-side $posterSelector")?.attr("data-src") val poster = mainUrl + document.selectFirst("div.page__subcol-side $posterSelector")?.attr("data-src")
val tags = document.select(genresSelector).map { it.text() } val tags = document.select(genresSelector).map { it.text() }
val year = document.select(yearSelector).text().substringAfter(": ").substringBefore("-").toIntOrNull() val year = document.select(yearSelector).text().substringAfter(": ").substringBefore("-").toIntOrNull()
@ -107,6 +112,9 @@ class AnimeUAProvider : MainAPI() {
it.toSearchResponse() it.toSearchResponse()
} }
val (malId, anilistId, image, cover) = Tracker().getTracker(engTitle, "TV", year)
Log.d("load-debug", engTitle)
//Log.d("load-debug", anilistId!!)
// Return to app // Return to app
// Parse Episodes as Series // Parse Episodes as Series
return if (tvType == TvType.Anime || tvType == TvType.OVA) { return if (tvType == TvType.Anime || tvType == TvType.OVA) {
@ -130,13 +138,16 @@ class AnimeUAProvider : MainAPI() {
} }
} }
} }
newTvSeriesLoadResponse(title, url, tvType, episodes) { newAnimeLoadResponse(title, url, tvType) {
this.posterUrl = poster this.posterUrl = poster
this.year = year this.year = year
this.plot = description this.plot = description
this.tags = tags this.tags = tags
this.rating = rating this.rating = rating
this.recommendations = recommendations this.recommendations = recommendations
addEpisodes(DubStatus.Dubbed, episodes)
addMalId(malId)
addAniListId(anilistId?.toIntOrNull())
} }
} else { // Parse as Movie. } else { // Parse as Movie.
newMovieLoadResponse(title, url, tvType, "$title, $playerUrl") { newMovieLoadResponse(title, url, tvType, "$title, $playerUrl") {

View file

@ -0,0 +1,58 @@
package com.lagradost
import android.util.Log
import com.lagradost.cloudstream3.app
class Tracker {
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 ->
Log.d("load-debug", media.toString())
(media.title?.english.equals(title, true) || media.title?.romaji.equals(
title,
true
))
}
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(
val romaji: String? = null,
val english: String? = null,
)
data class Results(
val aniId: String? = null,
val malId: Int? = null,
val title: Title? = null,
val releaseDate: Int? = null,
val type: String? = null,
val image: String? = null,
val cover: String? = null,
)
data class AniSearch(
val results: ArrayList<Results>? = arrayListOf(),
)
private data class Episodes(
val file: String? = null,
val title: String? = null,
val poster: String? = null,
)
private data class Home(
val table: String? = null,
)
private data class Search(
val mes: String? = null,
)
}