Refactoring and fixing SoraItalianStream (#70)

* Refactoring and fixing SoraItalianStream

* Fixes

* Fixes

* Remove not null operator

* Remove run

* Change to apmap and replace some map with foreach

* Change map to foreach and set the right referer
This commit is contained in:
contusionglory 2022-12-23 20:21:33 +00:00 committed by GitHub
parent 86d2a704ef
commit 93ee6d5c6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 229 additions and 264 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 {
@ -7,7 +7,7 @@ cloudstream {
// All of these properties are optional, you can safely remove them // All of these properties are optional, you can safely remove them
description = "Provider che utilizza tmdb. Non tutti i links sono funzionanti" description = "Provider che utilizza tmdb. Non tutti i links sono funzionanti"
authors = listOf("Adippe") authors = listOf("Adippe", "Forthe")
/** /**
* Status int as the following: * Status int as the following:

View file

@ -4,6 +4,7 @@ import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.utils.* import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.utils.AppUtils.parseJson import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
import com.lagradost.cloudstream3.utils.ShortLink.unshorten
import com.lagradost.nicehttp.Requests import com.lagradost.nicehttp.Requests
object SoraItalianExtractor : SoraItalianStream() { object SoraItalianExtractor : SoraItalianStream() {
@ -17,14 +18,13 @@ object SoraItalianExtractor : SoraItalianStream() {
"https://guardahd.stream/movie/$id", "https://guardahd.stream/movie/$id",
referer = "/" referer = "/"
).document ).document
res.select("ul._player-mirrors > li").map { source -> res.select("ul._player-mirrors > li").forEach { source ->
loadExtractor( loadExtractor(
fixUrl(source.attr("data-link")), fixUrl(source.attr("data-link")),
"$/", "https://guardahd.stream",
subtitleCallback, subtitleCallback,
callback callback
) )
println("LINK DI Guardare " + fixUrl(source.attr("data-link")))
} }
} }
@ -42,18 +42,18 @@ object SoraItalianExtractor : SoraItalianStream() {
"story" to id!! "story" to id!!
) )
).document.selectFirst("h2>a")?.attr("href") ?: return ).document.selectFirst("h2>a")?.attr("href") ?: return
val document = app.get(url).document val document = app.get(url).document
document.select("div.tab-content > div").mapIndexed { seasonData, data -> document.select("div.tab-content > div").forEachIndexed { seasonData, data ->
data.select("li").mapIndexed { epNum, epData -> data.select("li").forEachIndexed { epNum, epData ->
if (season == seasonData + 1 && episode == epNum + 1) { if (season == seasonData + 1 && episode == epNum + 1) {
epData.select("div.mirrors > a").map { epData.select("div.mirrors > a.mr").forEach {
loadExtractor( loadExtractor(
fixUrl(it.attr("data-link")), fixUrl(it.attr("data-link")),
"$/", guardaserieUrl,
subtitleCallback, subtitleCallback,
callback callback
) )
println("LINK DI guardaserie " + it.attr("data-link"))
} }
} }
} }
@ -79,84 +79,53 @@ object SoraItalianExtractor : SoraItalianStream() {
.filter { it != filmpertuttiUrl } .filter { it != filmpertuttiUrl }
links.apmap { links.apmap {
val doc = app.get(it).document val doc = app.get(it).document
if (id == doc.selectFirst(" div.rating > p > a")?.attr("href") if (id == doc.selectFirst("div.rating > p > a") //check if corresponds to the imdb id
?.attr("href")
?.substringAfterLast("/") ?.substringAfterLast("/")
) { ) {
if (type == "tv") { if (type == "tv") {
val seasonData = doc.select("div.accordion-item").filter { a -> val seasonData = doc.select("div.accordion-item").filter { a ->
a.selectFirst("#season > ul > li.s_title > span")!!.text().isNotEmpty() a.selectFirst("#season > ul > li.s_title > span")!!
.text()
.isNotEmpty()
}.find { }.find {
season == it.selectFirst("#season > ul > li.s_title > span")!!.text() season == it.selectFirst("#season > ul > li.s_title > span")!!
.text()
.toInt() .toInt()
} }
val episodeData = seasonData?.select("div.episode-wrap")?.find { val episodeData = seasonData?.select("div.episode-wrap")?.find {
episode == it.selectFirst("li.season-no")!!.text().substringAfter("x") episode == it.selectFirst("li.season-no")!!.text()
.substringAfter("x")
.substringBefore(" ")
.filter { it.isDigit() }.toIntOrNull() .filter { it.isDigit() }.toIntOrNull()
} }
episodeData?.select("#links > div > div > table > tbody:nth-child(2) > tr") episodeData?.select("#links > div > div > table > tbody:nth-child(2) > tr")
?.map { ?.forEach {
val unshortenLink = unshorten(it.selectFirst("a")?.attr("href") ?: "")
loadExtractor( loadExtractor(
it.selectFirst("a")!!.attr("href") ?: "", unshortenLink,
filmpertuttiUrl, filmpertuttiUrl,
subtitleCallback, subtitleCallback,
callback callback
) )
println("FIlmpetutti " + it.selectFirst("a")!!.attr("href") ?: "")
} }
} else { } else { //movie
val urls0 = doc.select("div.embed-player") doc.select("#info > ul > li").forEach {
if (urls0.isNotEmpty()) { val unshortenLink = unshorten(it.selectFirst("a")?.attr("href") ?: "")
urls0.map {
loadExtractor( loadExtractor(
it.attr("data-id"), unshortenLink,
filmpertuttiUrl, filmpertuttiUrl,
subtitleCallback, subtitleCallback,
callback callback
) )
println("LINK DI FIlmpetutti " + it.attr("data-id"))
}
} else {
doc.select("#info > ul > li ").mapNotNull {
val link = it.selectFirst("a")?.attr("href") ?: ""
loadExtractor(
ShortLink.unshorten(link).trim().replace("/v/", "/e/")
.replace("/f/", "/e/"),
"$/",
subtitleCallback,
callback
)
println("LINK DI FIlmpetutti " + it.selectFirst("a")?.attr("href"))
} }
} }
} }
} }
} }
}
suspend fun invoAltadefinizione(
id: String? = null,
subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit
) {
val url = app.get(
"$altadefinizioneUrl/index.php?story=$id&do=search&subaction=search"
).document.selectFirst("div.cover_kapsul > a")?.attr("href") ?: return
val document = app.get(url).document
document.select("ul.host>a").map {
loadExtractor(
fixUrl(it.attr("data-link")),
altadefinizioneUrl,
subtitleCallback,
callback
)
println("LINK DI altadefinizione " + fixUrl(it.attr("data-link")))
}
}
suspend fun invoCb01( suspend fun invoCb01(
title: String?, title: String?,
@ -164,36 +133,48 @@ object SoraItalianExtractor : SoraItalianStream() {
subtitleCallback: (SubtitleFile) -> Unit, subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit callback: (ExtractorLink) -> Unit
) { ) {
val res = app.get("$cb01Url/search/$title $year/feed").text
val res = app.get("$cb01Url/search/$title%20$year/feed").text
val links = Regex("<link>(.*)</link>").findAll(res).map { it.groupValues.last() }.toList() val links = Regex("<link>(.*)</link>").findAll(res).map { it.groupValues.last() }.toList()
.filter { it != cb01Url && it != "$cb01Url/" } .filter { it != cb01Url && it != "$cb01Url/" }
if (links.size != 1) return if (links.size != 1) return
links.apmap { links.apmap {
val doc = app.get(it).document val doc = app.get(it).document
doc.select("tr > td > a").mapNotNull { doc.select("tr > td > a[href*='stayonline.pro']").forEach {
val link = it.selectFirst("a")?.attr("href") ?: "" val link = it.selectFirst("a")?.attr("href") ?: ""
val url = ShortLink.unshorten(link).trim().replace("/v/", "/e/") val apiPostId = link.substringAfter("/l/")
.substringBefore("/") //https://stayonline.pro/l/abcdef/ -> abcdef
val apiBodyBypass = app.post(
"https://stayonline.pro/ajax/linkView.php",
data = mapOf("id" to apiPostId)
).text
var bypassedUrl =
apiBodyBypass.substringAfter("\"value\": \"").substringBefore("\"")
.replace("\\", "") //bypass stayonline link
if (bypassedUrl.contains("mixdrop.club")) //https://mixdrop.club/f/lllllllll/2/abcdefghilmn.mp4 (fake mp4 url) -> https://mixdrop.ch/e/lllllllll
bypassedUrl = bypassedUrl.replace("mixdrop.club", "mixdrop.ch")
.substringBeforeLast("/")
.substringBeforeLast("/")
.replace("/f/", "/e/") .replace("/f/", "/e/")
val processedUrl = if (url.contains("mixdrop.club")){ else
fixUrl(app.get(url).document.selectFirst("iframe")?.attr("src")?:"") bypassedUrl = unshorten(bypassedUrl)
}
else{url}
loadExtractor( loadExtractor(
processedUrl, bypassedUrl,
"$/", cb01Url,
subtitleCallback, subtitleCallback,
callback callback
) )
println("LINK DI CB01 " + url)
} }
} }
} }
suspend fun invoAnimeWorld( suspend fun invoAnimeWorld(
malId: String?, malId: String?,
title: String?, title: String?,
episode: Int?, episode: Int?,
subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit callback: (ExtractorLink) -> Unit
) { ) {
val pagedata = app.get("$animeworldUrl/search?keyword=$title").document val pagedata = app.get("$animeworldUrl/search?keyword=$title").document
@ -202,13 +183,13 @@ object SoraItalianExtractor : SoraItalianStream() {
fixUrl(it.select("a.name").firstOrNull()?.attr("href") ?: "", animeworldUrl) fixUrl(it.select("a.name").firstOrNull()?.attr("href") ?: "", animeworldUrl)
}.apmap { }.apmap {
val document = app.get(it).document val document = app.get(it).document
val malID = document.select("#mal-button").attr("href") val pageMalId = document.select("#mal-button").attr("href")
.split('/').last().toString() .split('/').last().toString()
if (malId == malID) { if (malId == pageMalId) {
val servers = document.select(".widget.servers") val servers = document.select(".widget.servers")
servers.select(".server[data-name=\"9\"] .episode > a").toList() servers.select(".server[data-name=\"9\"] .episode > a").toList()
.filter { it.attr("data-episode-num").toIntOrNull()?.equals(episode) ?: false } .filter { it.attr("data-episode-num").toIntOrNull()?.equals(episode) ?: false }
.map { id -> .forEach { id ->
val url = tryParseJson<AnimeWorldJson>( val url = tryParseJson<AnimeWorldJson>(
app.get("$animeworldUrl/api/episode/info?id=${id.attr("data-id")}").text app.get("$animeworldUrl/api/episode/info?id=${id.attr("data-id")}").text
)?.grabber )?.grabber
@ -234,7 +215,6 @@ object SoraItalianExtractor : SoraItalianStream() {
quality = Qualities.Unknown.value quality = Qualities.Unknown.value
) )
) )
println("LINK DI Animeworld " + url)
} }
} }
} }
@ -245,7 +225,6 @@ object SoraItalianExtractor : SoraItalianStream() {
title: String?, title: String?,
episode: Int?, episode: Int?,
year: Int?, year: Int?,
subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit callback: (ExtractorLink) -> Unit
) { ) {
val response = val response =
@ -266,7 +245,6 @@ object SoraItalianExtractor : SoraItalianStream() {
val streamUrl = val streamUrl =
parseJson<AniPlayApiEpisodeUrl>(app.get(episodeUrl).text).url parseJson<AniPlayApiEpisodeUrl>(app.get(episodeUrl).text).url
callback.invoke( callback.invoke(
ExtractorLink( ExtractorLink(
name, name,
AnimeName, AnimeName,
@ -276,9 +254,9 @@ object SoraItalianExtractor : SoraItalianStream() {
isM3u8 = streamUrl.contains(".m3u8"), isM3u8 = streamUrl.contains(".m3u8"),
) )
) )
} } else {
else { val seasonid = response.seasons.sortedBy { it.episodeStart }
val seasonid = response.seasons.sortedBy { it.episodeStart }.last { it.episodeStart < episode!!} .last { it.episodeStart < episode!! }
val episodesData = val episodesData =
tryParseJson<List<AniplayApiEpisode>>( tryParseJson<List<AniplayApiEpisode>>(
app.get( app.get(
@ -299,7 +277,6 @@ object SoraItalianExtractor : SoraItalianStream() {
isM3u8 = streamUrl.contains(".m3u8"), isM3u8 = streamUrl.contains(".m3u8"),
) )
) )
println("LINK DI aniplay " + streamUrl)
} }
} }
} }
@ -310,10 +287,10 @@ object SoraItalianExtractor : SoraItalianStream() {
malId: String?, malId: String?,
title: String?, title: String?,
episode: Int?, episode: Int?,
subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit callback: (ExtractorLink) -> Unit
) { ) {
val document = app.get("$animesaturnUrl/animelist?search=${title?.replace("-"," ")}").document val document =
app.get("$animesaturnUrl/animelist?search=${title?.replace("-", " ")}").document
val links = document.select("div.item-archivio").map { val links = document.select("div.item-archivio").map {
it.select("a.badge-archivio").first()!!.attr("href") it.select("a.badge-archivio").first()!!.attr("href")
} }
@ -324,47 +301,42 @@ object SoraItalianExtractor : SoraItalianStream() {
} else { } else {
"AnimeSaturn SUB" "AnimeSaturn SUB"
} }
var malID : String? = null var malID: String?
response.select("[rel=\"noopener noreferrer\"]").forEach { response.select("a[href*=myanimelist]").forEach {
if(it.attr("href").contains("myanimelist")) malID = it.attr("href").substringBeforeLast("/")
malID = it.attr("href").removeSuffix("/").split('/').last() .substringAfterLast("/") //https://myanimelist.net/anime/19/ -> 19
if (malId == malID) { if (malId == malID) {
val link = response.select("a.bottone-ep").find { it.text().split(" ")[1] == episode.toString() }?.attr("href") val link = response.select("a.bottone-ep")
if (link != null) { .find { it.text().substringAfter("Episodio ") == episode.toString() }
?.attr("href")
if (link?.isBlank() == false) { //links exists
val page = app.get(link).document val page = app.get(link).document
val episodeLink = page.select("div.card-body > a[href]").find { it1 -> val episodeLink = page.select("div.card-body > a[href*=watch]").attr("href")
it1.attr("href").contains("watch?") ?: throw ErrorLoadingException("No link Found")
}?.attr("href") ?: throw ErrorLoadingException("No link Found")
val episodePage = app.get(episodeLink).document val episodePage = app.get(episodeLink).document
val episodeUrl: String? val episodeUrl: String? = episodePage.select("video.afterglow > source")
var isM3U8 = false .let { // Old player
it.first()?.attr("src")
if (episodePage.select("video.afterglow > source").isNotEmpty()) // Old player
episodeUrl =
episodePage.select("video.afterglow > source").first()!!.attr("src")
else { // New player
val script = episodePage.select("script").find {
it.toString().contains("jwplayer('player_hls').setup({")
}!!.toString()
episodeUrl = script.split(" ")
.find { it.contains(".m3u8") and !it.contains(".replace") }!!
.replace("\"", "").replace(",", "")
isM3U8 = true
} }
?: //new player
Regex("\"(https[A-z0-9\\/\\:\\.]*\\.m3u8)\",").find(
episodePage.select("script").find {
it.toString().contains("jwplayer('player_hls').setup({")
}.toString()
)?.value
callback.invoke( callback.invoke(
ExtractorLink( ExtractorLink(
name, name,
AnimeName, AnimeName,
episodeUrl!!, episodeUrl!!,
isM3u8 = isM3U8, isM3u8 = episodeUrl.contains(".m3u8"),
referer = "https://www.animesaturn.io/", //Some servers need the old host as referer, and the new ones accept it too referer = "https://www.animesaturn.io/", //Some servers need the old host as referer, and the new ones accept it too
quality = Qualities.Unknown.value quality = Qualities.Unknown.value
) )
) )
println("LINK DI animesaturn " + episodeUrl)
} }
} }
@ -397,6 +369,4 @@ fun fixUrl(url: String, domain: String): String {
return "$domain/$url" return "$domain/$url"
} }
} }

View file

@ -5,7 +5,6 @@ import com.lagradost.SoraItalianExtractor.invoGuardare
import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
import com.lagradost.cloudstream3.metaproviders.TmdbProvider import com.lagradost.cloudstream3.metaproviders.TmdbProvider
import com.lagradost.SoraItalianExtractor.invoAltadefinizione
import com.lagradost.SoraItalianExtractor.invoAniPlay import com.lagradost.SoraItalianExtractor.invoAniPlay
import com.lagradost.SoraItalianExtractor.invoAnimeSaturn import com.lagradost.SoraItalianExtractor.invoAnimeSaturn
import com.lagradost.SoraItalianExtractor.invoAnimeWorld import com.lagradost.SoraItalianExtractor.invoAnimeWorld
@ -37,8 +36,7 @@ open class SoraItalianStream : TmdbProvider() {
private const val apiKey = "71f37e6dff3b879fa4656f19547c418c" // PLEASE DON'T STEAL private const val apiKey = "71f37e6dff3b879fa4656f19547c418c" // PLEASE DON'T STEAL
const val guardaserieUrl = "https://guardaserie.app" const val guardaserieUrl = "https://guardaserie.app"
const val filmpertuttiUrl = "https://www.filmpertutti.skin" const val filmpertuttiUrl = "https://www.filmpertutti.skin"
const val altadefinizioneUrl = "https://altadefinizione01.autos" const val cb01Url = "https://cb01.tours/"
const val cb01Url = "https://cb01.delivery"
const val animeworldUrl = "https://www.animeworld.tv" const val animeworldUrl = "https://www.animeworld.tv"
const val aniplayUrl = "https://aniplay.it" const val aniplayUrl = "https://aniplay.it"
const val animesaturnUrl = "https://www.animesaturn.in" const val animesaturnUrl = "https://www.animesaturn.in"
@ -69,6 +67,12 @@ open class SoraItalianStream : TmdbProvider() {
return api.chunked(4).map { base64Decode(it) }.reversed().joinToString("") return api.chunked(4).map { base64Decode(it) }.reversed().joinToString("")
} }
fun containsJapaneseCharacters(str: String?): Boolean { //sometimes the it-It translation of names gives the japanese name of the anime
val japaneseCharactersRegex =
Regex("[\\u3000-\\u303f\\u3040-\\u309f\\u30a0-\\u30ff\\uff00-\\uff9f\\u4e00-\\u9faf\\u3400-\\u4dbf]")
return str?.let { japaneseCharactersRegex.containsMatchIn(it) } == true
}
} }
@ -119,22 +123,13 @@ open class SoraItalianStream : TmdbProvider() {
} }
override suspend fun search(query: String): List<SearchResponse> { override suspend fun search(query: String): List<SearchResponse>? {
val searchResponse = mutableListOf<SearchResponse>() return app.get(
val mainResponse = app.get(
"$tmdbAPI/search/multi?api_key=$apiKey&language=it-IT&query=$query&page=1&include_adult=false" "$tmdbAPI/search/multi?api_key=$apiKey&language=it-IT&query=$query&page=1&include_adult=false"
).parsedSafe<Results>()?.results?.mapNotNull { media -> )
.parsedSafe<Results>()?.results?.mapNotNull { media ->
media.toSearchResponse() media.toSearchResponse()
} }
if (mainResponse?.isNotEmpty() == true) searchResponse.addAll(mainResponse)
// val animeResponse =
// app.get("$mainServerAPI/search/anime/$query?_data=routes/search/anime/\$animeKeyword")
// .parsedSafe<SearchAnime>()?.searchResults?.results?.mapNotNull { anime -> anime.toSearchResponse() }
// if (animeResponse?.isNotEmpty() == true) searchResponse.addAll(animeResponse)
return searchResponse
} }
@ -143,16 +138,16 @@ open class SoraItalianStream : TmdbProvider() {
val type = getType(data.type) val type = getType(data.type)
val typename = when(type){ val typename = data.type
TvType.TvSeries-> "tv"
TvType.Movie -> "movie"
else -> ""
}
val res = var res =
app.get("$tmdbAPI/$typename/${data.id}?api_key=$apiKey&language=it-IT&append_to_response=external_ids,credits,recommendations,videos") app.get("$tmdbAPI/$typename/${data.id}?api_key=$apiKey&language=it-IT&append_to_response=external_ids,credits,recommendations,videos")
.parsedSafe<MovieDetails>() ?: throw ErrorLoadingException("Invalid Json Response") .parsedSafe<MovieDetails>() ?: throw ErrorLoadingException("Invalid Json Response")
if (containsJapaneseCharacters(res.name)) {
res =
app.get("$tmdbAPI/$typename/${data.id}?api_key=$apiKey&language=en-US&append_to_response=external_ids,credits,recommendations,videos")
.parsedSafe() ?: throw ErrorLoadingException("Invalid Json Response")
}
val title = res.name ?: res.title ?: return null val title = res.name ?: res.title ?: return null
val orgTitle = res.originalName ?: res.originalTitle ?: return null val orgTitle = res.originalName ?: res.originalTitle ?: return null
@ -175,73 +170,59 @@ open class SoraItalianStream : TmdbProvider() {
res.videos?.results?.map { "https://www.youtube.com/watch?v=${it.key}" } res.videos?.results?.map { "https://www.youtube.com/watch?v=${it.key}" }
?.randomOrNull() ?.randomOrNull()
if (res.genres?.map { it.id }?.contains(16) == true && type == TvType.TvSeries) { val isAnime = res.genres?.any { it.id == 16L } == true
val episodes = mutableListOf<Episode>() return if (type == TvType.Movie) { //can be a movie or a anime movie
res.seasons?.filter { it.seasonNumber != 0L }?.apmap { season -> newMovieLoadResponse(
val seasonData = app.get("$tmdbAPI/${data.type}/${data.id}/season/${season.seasonNumber}?api_key=$apiKey&language=it-IT") title,
.parsedSafe<MediaDetailEpisodes>()?.episodes url,
val seasonID = if (season.seasonNumber!! > 1 && seasonData?.isNotEmpty() == true && seasonData?.first()?.episodeNumber != 1){ 1 } else { season.seasonNumber }.toInt() TvType.Movie,
seasonData?.map { eps ->
episodes.add(Episode(
LinkData( LinkData(
data.id, data.id,
res.externalIds?.imdbId, res.externalIds?.imdbId,
data.type, data.type,
seasonID,
eps.episodeNumber,
title = title, title = title,
year = year, year = year,
orgTitle = orgTitle, orgTitle = orgTitle,
isAnime = true isAnime = isAnime
).toJson(), ).toJson(),
name = eps.name,
season = eps.seasonNumber,
episode = eps.episodeNumber,
posterUrl = getImageUrl(eps.stillPath),
rating = eps.voteAverage?.times(10)?.roundToInt(),
description = eps.overview
).apply {
this.addDate(eps.airDate)
})
}
}
return newTvSeriesLoadResponse(
title,
url,
TvType.TvSeries,
episodes
) { ) {
this.posterUrl = getOriImageUrl(res.backdropPath) this.posterUrl = getOriImageUrl(res.backdropPath)
this.year = year this.year = year
this.plot = res.overview this.plot = res.overview
this.tags = res.genres?.mapNotNull { it.name } this.tags = res.genres?.mapNotNull { it.name }
this.showStatus = getStatus(res.status)
this.recommendations = recommendations this.recommendations = recommendations
this.actors = actors this.actors = actors
addTrailer(trailer) addTrailer(trailer)
} }
} else { //can be anime series or tv series
}
return if (type == TvType.TvSeries) {
val episodes = mutableListOf<Episode>() val episodes = mutableListOf<Episode>()
res.seasons?.filter { it.seasonNumber != 0L }?.apmap { season -> var seasonNum = 0
val seasonDataList = res.seasons?.filter { it.seasonNumber != 0 }?.apmap { season ->
app.get("$tmdbAPI/${data.type}/${data.id}/season/${season.seasonNumber}?api_key=$apiKey&language=it-IT") app.get("$tmdbAPI/${data.type}/${data.id}/season/${season.seasonNumber}?api_key=$apiKey&language=it-IT")
.parsedSafe<MediaDetailEpisodes>()?.episodes?.map { eps -> .parsedSafe<MediaDetailEpisodes>()?.episodes
}
res.seasons?.filter { it.seasonNumber != 0 }?.forEachIndexed { index, season ->
val seasonData = seasonDataList?.get(index)
if (seasonData?.first()?.episodeNumber == 1)
seasonNum += 1
seasonData?.forEach { eps ->
episodes.add(Episode( episodes.add(Episode(
LinkData( LinkData(
data.id, data.id,
res.externalIds?.imdbId, res.externalIds?.imdbId,
data.type, data.type,
eps.seasonNumber, seasonNum,
eps.episodeNumber, eps.episodeNumber,
title = title, title = title,
year = season.airDate?.split("-")?.first()?.toIntOrNull(), year = year ?: season.airDate?.split("-")?.first()?.toIntOrNull(),
orgTitle = orgTitle, orgTitle = orgTitle,
isAnime = false isAnime = isAnime
).toJson(), ).toJson(),
name = eps.name, name = eps.name,
season = eps.seasonNumber, season = seasonNum,
episode = eps.episodeNumber, episode = eps.episodeNumber,
posterUrl = getImageUrl(eps.stillPath), posterUrl = getImageUrl(eps.stillPath),
rating = eps.voteAverage?.times(10)?.roundToInt(), rating = eps.voteAverage?.times(10)?.roundToInt(),
@ -267,30 +248,6 @@ open class SoraItalianStream : TmdbProvider() {
addTrailer(trailer) addTrailer(trailer)
} }
} }
else {
newMovieLoadResponse(
title,
url,
TvType.Movie,
LinkData(
data.id,
res.externalIds?.imdbId,
data.type,
title = title,
year = year,
orgTitle = orgTitle,
isAnime = res.genres?.map { it.id }?.contains(16)?:false
).toJson(),
) {
this.posterUrl = getOriImageUrl(res.backdropPath)
this.year = year
this.plot = res.overview
this.tags = res.genres?.mapNotNull { it.name }
this.recommendations = recommendations
this.actors = actors
addTrailer(trailer)
}
}
} }
override suspend fun loadLinks( override suspend fun loadLinks(
@ -304,28 +261,60 @@ open class SoraItalianStream : TmdbProvider() {
val malID = app.get("$tmdb2mal/?id=${res.id}&s=${res.season}").text.trim() val malID = app.get("$tmdb2mal/?id=${res.id}&s=${res.season}").text.trim()
argamap( argamap(
{ {
if (res.isAnime ) invoAnimeWorld(malID, res.title, res.episode, subtitleCallback, callback) if (res.isAnime) invoAnimeWorld(
malID,
res.title,
res.episode,
callback
)
}, },
{ {
if (res.isAnime) invoAniPlay(malID, res.title, res.episode, res.year, subtitleCallback, callback) if (res.isAnime) invoAniPlay(
malID,
res.title,
res.episode,
res.year,
callback
)
}, },
{ {
if (res.isAnime) invoAnimeSaturn(malID, res.title, res.episode, subtitleCallback, callback) if (res.isAnime) invoAnimeSaturn(
malID,
res.title,
res.episode,
callback
)
}, },
{ {
invoGuardare(res.imdbId, subtitleCallback, callback) if (res.type == "movie") invoGuardare(
res.imdbId,
subtitleCallback,
callback
) //just movies/anime movie
}, },
{ {
if (malID == "") invoGuardaserie(res.imdbId, res.season, res.episode, subtitleCallback, callback) if (res.type == "tv") invoGuardaserie( //has tv series and anime
res.imdbId,
res.season,
res.episode,
subtitleCallback,
callback
)
}, },
{ {
if (!res.isAnime) invoFilmpertutti(res.imdbId,res.title, res.type, res.season, res.episode, res.year, subtitleCallback, callback) invoFilmpertutti( //has tv series, film and some anime
res.imdbId,
res.title,
res.type,
res.season,
res.episode,
res.year,
subtitleCallback,
callback
)
}, },
{ {
if (!res.isAnime) invoAltadefinizione(res.imdbId, subtitleCallback, callback) if (res.type == "movie") invoCb01(res.title, res.year, subtitleCallback, callback)
},
{
if (!res.isAnime) invoCb01(res.title, res.year, subtitleCallback, callback)
} }
) )
@ -335,7 +324,7 @@ open class SoraItalianStream : TmdbProvider() {
private data class LinkData( private data class LinkData(
val id: Int? = null, val id: Int? = null,
val imdbId: String? = null, val imdbId: String? = null,
val type: String? = null, val type: String? = null, //movie or tv
val season: Int? = null, val season: Int? = null,
val episode: Int? = null, val episode: Int? = null,
val aniId: String? = null, val aniId: String? = null,
@ -469,12 +458,12 @@ open class SoraItalianStream : TmdbProvider() {
data class Season( data class Season(
@JsonProperty("air_date") val airDate: String? = null, @JsonProperty("air_date") val airDate: String? = null,
@JsonProperty("episode_count") val episodeCount: Long? = null, @JsonProperty("episode_count") val episodeCount: Int? = null,
val id: Long? = null, val id: Long? = null,
val name: String? = null, val name: String? = null,
val overview: String? = null, val overview: String? = null,
@JsonProperty("poster_path") val posterPath: String? = null, @JsonProperty("poster_path") val posterPath: String? = null,
@JsonProperty("season_number") val seasonNumber: Long? = null @JsonProperty("season_number") val seasonNumber: Int? = null
) )
data class AnimeWorldJson( data class AnimeWorldJson(
@ -482,29 +471,35 @@ open class SoraItalianStream : TmdbProvider() {
@JsonProperty("name") val name: String, @JsonProperty("name") val name: String,
@JsonProperty("target") val target: String, @JsonProperty("target") val target: String,
) )
data class AniPlayApiSearchResult( data class AniPlayApiSearchResult(
@JsonProperty("id") val id: Int, @JsonProperty("id") val id: Int,
@JsonProperty("listWebsites") val websites: List<AniPlayWebsites> @JsonProperty("listWebsites") val websites: List<AniPlayWebsites>
) )
data class AniPlayWebsites( data class AniPlayWebsites(
@JsonProperty("url") val url: String? = null, @JsonProperty("url") val url: String? = null,
@JsonProperty("listWebsiteId") val websitesId: Int? = null @JsonProperty("listWebsiteId") val websitesId: Int? = null
) )
data class AniplayApiAnime( data class AniplayApiAnime(
@JsonProperty("episodes") val episodes: List<AniplayApiEpisode>, @JsonProperty("episodes") val episodes: List<AniplayApiEpisode>,
@JsonProperty("seasons") val seasons: List<AniplayApiSeason>?, @JsonProperty("seasons") val seasons: List<AniplayApiSeason>?,
@JsonProperty("title") val title: String? @JsonProperty("title") val title: String?
) )
data class AniplayApiEpisode( data class AniplayApiEpisode(
@JsonProperty("id") val id: Int, @JsonProperty("id") val id: Int,
@JsonProperty("title") val title: String?, @JsonProperty("title") val title: String?,
@JsonProperty("episodeNumber") val number: String, @JsonProperty("episodeNumber") val number: String,
) )
data class AniplayApiSeason( data class AniplayApiSeason(
@JsonProperty("id") val id: Int, @JsonProperty("id") val id: Int,
@JsonProperty("name") val name: String, @JsonProperty("name") val name: String,
@JsonProperty("episodeStart") val episodeStart: Int @JsonProperty("episodeStart") val episodeStart: Int
) )
data class AniPlayApiEpisodeUrl( data class AniPlayApiEpisodeUrl(
@JsonProperty("videoUrl") val url: String @JsonProperty("videoUrl") val url: String
) )