AnimeSaturn (#36)

Added lasted episode

Added trailer & recommendations

Updated mainUrl
This commit is contained in:
Davide 2022-10-15 23:03:13 +02:00 committed by GitHub
parent 5aa10f47aa
commit f2933f5c6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 37 deletions

View file

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

View file

@ -6,13 +6,14 @@ import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId
import com.lagradost.cloudstream3.LoadResponse.Companion.addDuration import com.lagradost.cloudstream3.LoadResponse.Companion.addDuration
import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId
import com.lagradost.cloudstream3.LoadResponse.Companion.addRating import com.lagradost.cloudstream3.LoadResponse.Companion.addRating
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
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.Qualities import com.lagradost.cloudstream3.utils.Qualities
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
class AnimeSaturnProvider : MainAPI() { class AnimeSaturnProvider : MainAPI() {
override var mainUrl = "https://www.animesaturn.cc" override var mainUrl = "https://www.animesaturn.in"
override var name = "AnimeSaturn" override var name = "AnimeSaturn"
override var lang = "it" override var lang = "it"
override val hasMainPage = true override val hasMainPage = true
@ -40,8 +41,22 @@ class AnimeSaturnProvider : MainAPI() {
} }
} }
private fun Element.toSearchResult(): AnimeSearchResponse { private fun Element.toSearchResponse(): AnimeSearchResponse? {
val url = this.select("a").first()?.attr("href")
?: return null
val title = this.select("a[title]").first()?.attr("title")?.removeSuffix("(ITA)")
?: return null
val posterUrl = this.select("img.new-anime").first()!!.attr("src")
val isDubbed = this.select("a[title]").first()?.attr("title")?.contains("(ITA)")
?: false
return newAnimeSearchResponse(title, url, TvType.Anime){
addDubStatus(isDubbed)
addPoster(posterUrl)
}
}
private fun Element.toSearchResult(): AnimeSearchResponse {
var title = this.select("a.badge-archivio").first()!!.text() var title = this.select("a.badge-archivio").first()!!.text()
var isDubbed = false var isDubbed = false
@ -51,12 +66,11 @@ class AnimeSaturnProvider : MainAPI() {
} }
val url = this.select("a.badge-archivio").first()!!.attr("href") val url = this.select("a.badge-archivio").first()!!.attr("href")
val posterUrl = this.select("img.locandina-archivio[src]").first()!!.attr("src") val posterUrl = this.select("img.locandina-archivio[src]").first()!!.attr("src")
return newAnimeSearchResponse(title, url, TvType.Anime) { return newAnimeSearchResponse(title, url, TvType.Anime) {
addDubStatus(isDubbed) addDubStatus(isDubbed)
this.posterUrl = posterUrl addPoster(posterUrl)
} }
} }
@ -74,26 +88,36 @@ class AnimeSaturnProvider : MainAPI() {
} }
override suspend fun getMainPage(page: Int, request : MainPageRequest): HomePageResponse { override suspend fun getMainPage(page: Int, request : MainPageRequest): HomePageResponse {
val list = mutableListOf<HomePageList>()
val documentLastEpisode = app.get("$mainUrl/fetch_pages.php?request=episodes",
headers = mapOf("x-requested-with" to "XMLHttpRequest")
).document
val lastedEpisode = documentLastEpisode.select(".anime-card").mapNotNull {
val url = it.select("a").first()?.attr("href")?.let { href ->
href.split("-ep-")[0].replace("/ep/", "/anime/")
} ?: return@mapNotNull null
val title = it.select("a").first()?.attr("title")?.removeSuffix(" (ITA)")
?: return@mapNotNull null
val posterUrl = it.select("img").first()?.attr("src")
val dub = it.select("a").first()?.attr("title")?.contains("(ITA)") ?: false
val episode = it.select(".anime-episode").text().split(" ").last().toIntOrNull()
newAnimeSearchResponse(title, url, TvType.Anime) {
addPoster(posterUrl)
addDubStatus(dub, episode)
}
}
list.add(HomePageList("Ultimi episodi", lastedEpisode, isHorizontalImages = true))
val document = app.get(mainUrl).document val document = app.get(mainUrl).document
val list = ArrayList<HomePageList>()
document.select("div.container:has(span.badge-saturn)").forEach { document.select("div.container:has(span.badge-saturn)").forEach {
val tabName = it.select("span.badge-saturn").first()!!.text() val tabName = it.select("span.badge-saturn").first()!!.text()
if (tabName.equals("Ultimi episodi")) return@forEach if (tabName.equals("Ultimi episodi")) return@forEach
val results = ArrayList<AnimeSearchResponse>()
it.select(".main-anime-card").forEach { card ->
var title = card.select("a[title]").first()!!.attr("title")
var isDubbed = false
if(title.contains(" (ITA)")){
title = title.replace(" (ITA)", "")
isDubbed = true
}
val posterUrl = card.select("img.new-anime").first()!!.attr("src")
val url = card.select("a").first()!!.attr("href")
results.add(newAnimeSearchResponse(title, url, TvType.Anime){ val results = it.select(".main-anime-card").mapNotNull { card ->
addDubStatus(isDubbed) card.toSearchResponse()
this.posterUrl = posterUrl
})
} }
list.add(HomePageList(tabName, results)) list.add(HomePageList(tabName, results))
} }
@ -103,9 +127,9 @@ class AnimeSaturnProvider : MainAPI() {
override suspend fun quickSearch(query: String): List<SearchResponse>? { override suspend fun quickSearch(query: String): List<SearchResponse>? {
val quickSearchJ = app.get("$mainUrl/index.php?search=1&key=$query").text val quickSearchJ = app.get("$mainUrl/index.php?search=1&key=$query").text
return tryParseJson<List<QuickSearchParse>>(quickSearchJ)?.map { return tryParseJson<List<QuickSearchParse>>(quickSearchJ)?.map {
newAnimeSearchResponse(it.name.replace(" (ITA)", ""), it.link, TvType.Anime) { newAnimeSearchResponse(it.name.removeSuffix("(ITA)"), it.link, TvType.Anime) {
addDubStatus(it.name.contains(" (ITA)")) addDubStatus(it.name.contains(" (ITA)"))
this.posterUrl = it.image addPoster(it.image)
} }
} }
@ -119,11 +143,10 @@ class AnimeSaturnProvider : MainAPI() {
} }
override suspend fun load(url: String): LoadResponse { override suspend fun load(url: String): LoadResponse {
val document = app.get(url).document val document = app.get(url).document
val title = document.select("img.cover-anime").first()!!.attr("alt") val title = document.select("img.cover-anime").first()!!.attr("alt").removeSuffix("(ITA)")
val japTitle = document.select("div.box-trasparente-alternativo").first()!!.text() val japTitle = document.select("div.box-trasparente-alternativo").first()!!.text().removeSuffix("(ITA)")
val posterUrl = document.select("img.cover-anime[src]").first()!!.attr("src") val posterUrl = document.select("img.cover-anime[src]").first()!!.attr("src")
var malId : Int? = null var malId : Int? = null
var aniListId : Int? = null var aniListId : Int? = null
@ -136,8 +159,9 @@ class AnimeSaturnProvider : MainAPI() {
} }
val plot = document.select("div#shown-trama").first()?.text() val plot = document.select("div#shown-trama").first()?.text()
val tags = document.select("a.generi-as").map { it.text() } val tags = document.select("a.generi-as").map { it.text() }
val isDubbed = document.select("div.anime-title-as").first()!!.text().contains("(ITA)")
val trailerUrl = document.select("#trailer-iframe").first()?.attr("src")
val details : List<String>? = document.select("div.container:contains(Stato: )").first()?.text()?.split(" ") val details : List<String>? = document.select("div.container:contains(Stato: )").first()?.text()?.split(" ")
var status : String? = null var status : String? = null
@ -145,8 +169,6 @@ class AnimeSaturnProvider : MainAPI() {
var year : String? = null var year : String? = null
var score : String? = null var score : String? = null
val isDubbed = document.select("div.anime-title-as").first()!!.text().contains("(ITA)")
if (!details.isNullOrEmpty()) { if (!details.isNullOrEmpty()) {
details.forEach { details.forEach {
val index = details.indexOf(it) +1 val index = details.indexOf(it) +1
@ -162,6 +184,10 @@ class AnimeSaturnProvider : MainAPI() {
val episodes = document.select("a.bottone-ep").mapNotNull{ it.toEpisode() } val episodes = document.select("a.bottone-ep").mapNotNull{ it.toEpisode() }
val recommendations = document.select("#carousel > .main-anime-card").mapNotNull {
it.toSearchResponse()
}
return newAnimeLoadResponse(title, url, TvType.Anime) { return newAnimeLoadResponse(title, url, TvType.Anime) {
this.engName = title this.engName = title
this.japName = japTitle this.japName = japTitle
@ -175,6 +201,8 @@ class AnimeSaturnProvider : MainAPI() {
addMalId(malId) addMalId(malId)
addAniListId(aniListId) addAniListId(aniListId)
addDuration(duration) addDuration(duration)
addTrailer(trailerUrl)
this.recommendations = recommendations
} }
} }
@ -184,19 +212,17 @@ class AnimeSaturnProvider : MainAPI() {
subtitleCallback: (SubtitleFile) -> Unit, subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit callback: (ExtractorLink) -> Unit
): Boolean { ): Boolean {
val page = app.get(data).document val page = app.get(data).document
val episodeLink = page.select("div.card-body > a[href]").find {it1 -> val episodeLink = page.select("div.card-body > a[href]").find {it1 ->
it1.attr("href").contains("watch?") it1.attr("href").contains("watch?")
}?.attr("href") }?.attr("href") ?: return false
val episodePage = app.get(episodeLink!!).document val episodePage = app.get(episodeLink).document
val episodeUrl: String? val episodeUrl: String?
var isM3U8 = false var isM3U8 = false
if (episodePage.select("video.afterglow > source").isNotEmpty()) // Old player if (episodePage.select("video.afterglow > source").isNotEmpty()) // Old player
episodeUrl = episodePage.select("video.afterglow > source").first()!!.attr("src") episodeUrl = episodePage.select("video.afterglow > source").first()!!.attr("src")
else { // New player else { // New player
val script = episodePage.select("script").find { val script = episodePage.select("script").find {
it.toString().contains("jwplayer('player_hls').setup({") it.toString().contains("jwplayer('player_hls').setup({")
@ -205,7 +231,6 @@ class AnimeSaturnProvider : MainAPI() {
isM3U8 = true isM3U8 = true
} }
callback.invoke( callback.invoke(
ExtractorLink( ExtractorLink(
name, name,