mirror of
https://github.com/recloudstream/cloudstream-extensions-multilingual.git
synced 2024-08-15 03:15:14 +00:00
Fixes and Improvements CasaCinemaProvider (#66)
This commit is contained in:
parent
220d62d1dc
commit
86d2a704ef
2 changed files with 137 additions and 86 deletions
|
@ -1,5 +1,5 @@
|
||||||
// use an integer for version numbers
|
// use an integer for version numbers
|
||||||
version = 2
|
version = 3
|
||||||
|
|
||||||
|
|
||||||
cloudstream {
|
cloudstream {
|
||||||
|
@ -22,4 +22,5 @@ cloudstream {
|
||||||
"Movie",
|
"Movie",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
iconUrl = "https://www.google.com/s2/favicons?domain=casacinema.lol&sz=%size%"
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,54 +28,31 @@ class CasaCinemaProvider : MainAPI() { // all providers must be an instance of M
|
||||||
"$mainUrl/category/film/page/" to "Ultimi Film",
|
"$mainUrl/category/film/page/" to "Ultimi Film",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private fun fixTitle(element: Element?): String {
|
||||||
|
return element?.text()
|
||||||
|
?.trim()
|
||||||
|
?.substringBefore("Streaming")
|
||||||
|
?.replace("[HD]", "")
|
||||||
|
?.replace("\\(\\d{4}\\)".toRegex(), "")
|
||||||
|
?: "No Title found"
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Element?.isMovie(): Boolean {
|
||||||
|
return (this
|
||||||
|
?.text() ?: "")
|
||||||
|
.contains("\\(\\d{4}\\)".toRegex())
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
|
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
|
||||||
|
|
||||||
val url = request.data + page
|
val url = request.data + page
|
||||||
|
|
||||||
val soup = app.get(url).document
|
val soup = app.get(url, referer = mainUrl).document
|
||||||
val home = soup.select("ul.posts>li").mapNotNull { it.toSearchResult() }
|
val home = soup.select("ul.posts>li").mapNotNull { it.toSearchResult() }
|
||||||
val hasNext = soup.select("div.navigation>ul>li>a").last()?.text() == "Pagina successiva »"
|
val hasNext = soup.select("div.navigation>ul>li>a").last()?.text() == "Pagina successiva »"
|
||||||
return newHomePageResponse(arrayListOf(HomePageList(request.name, home)), hasNext = hasNext)
|
return newHomePageResponse(arrayListOf(HomePageList(request.name, home)), hasNext = hasNext)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Element.toSearchResult(): SearchResponse {
|
|
||||||
val title =
|
|
||||||
this.selectFirst(".title")?.text()?.replace("[HD]", "")?.substringBefore("(")
|
|
||||||
?: "No title"
|
|
||||||
val isMovie = (this.selectFirst(".title")?.text() ?: "").contains("\\(\\d{4}\\)".toRegex())
|
|
||||||
val link =
|
|
||||||
this.selectFirst("a")?.attr("href") ?: throw ErrorLoadingException("No Link found")
|
|
||||||
|
|
||||||
val quality = this.selectFirst("div.hd")?.text()
|
|
||||||
|
|
||||||
val posterUrl = this.selectFirst("a")?.attr("data-thumbnail")
|
|
||||||
|
|
||||||
if (isMovie) {
|
|
||||||
return newMovieSearchResponse(title, link, TvType.Movie) {
|
|
||||||
addPoster(posterUrl)
|
|
||||||
if (quality != null) {
|
|
||||||
addQuality(quality)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return newTvSeriesSearchResponse(title, link, TvType.TvSeries) {
|
|
||||||
addPoster(posterUrl)
|
|
||||||
if (quality != null) {
|
|
||||||
addQuality(quality)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Element.toEpisode(season: Int): Episode {
|
|
||||||
val data =
|
|
||||||
this.select("div.fix-table>table>tbody>tr>td>a[target=_blank]")
|
|
||||||
.map { it.attr("href") }
|
|
||||||
.toJson() // isecure.link
|
|
||||||
val epTitle = this.selectFirst("li.other_link>a")?.text() ?: "No Ep. Title 0"
|
|
||||||
val epNum = epTitle.substringAfter("Episodio ").toInt()
|
|
||||||
return Episode(data, epTitle, season, epNum)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun search(query: String): List<SearchResponse> {
|
override suspend fun search(query: String): List<SearchResponse> {
|
||||||
val queryFormatted = query.replace(" ", "+")
|
val queryFormatted = query.replace(" ", "+")
|
||||||
|
@ -84,22 +61,43 @@ class CasaCinemaProvider : MainAPI() { // all providers must be an instance of M
|
||||||
return doc.select("ul.posts>li").map { it.toSearchResult() }
|
return doc.select("ul.posts>li").map { it.toSearchResult() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Element.toSearchResult(): SearchResponse {
|
||||||
|
val title = fixTitle(this.selectFirst(".title"))
|
||||||
|
val isMovie = this.selectFirst(".title").isMovie()
|
||||||
|
val link =
|
||||||
|
this.selectFirst("a")?.attr("href") ?: throw ErrorLoadingException("No Link found")
|
||||||
|
|
||||||
|
val quality = this.selectFirst("div.hd")?.text()
|
||||||
|
val posterUrl = this.selectFirst("a")?.attr("data-thumbnail")
|
||||||
|
|
||||||
|
return if (isMovie) {
|
||||||
|
newMovieSearchResponse(title, link, TvType.Movie) {
|
||||||
|
addPoster(posterUrl)
|
||||||
|
quality?.let { addQuality(it) }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newTvSeriesSearchResponse(title, link, TvType.TvSeries) {
|
||||||
|
addPoster(posterUrl)
|
||||||
|
quality?.let { addQuality(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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, referer = mainUrl).document
|
||||||
val type =
|
val type =
|
||||||
if (document.selectFirst("h3")?.text() == "Altri Film:") TvType.Movie
|
if (document.select("div.seasons-wraper").isNotEmpty()) TvType.TvSeries
|
||||||
else TvType.TvSeries
|
else TvType.Movie
|
||||||
val title =
|
val title = fixTitle(document.selectFirst("div.row > h1"))
|
||||||
document.selectFirst("div.row > h1")
|
|
||||||
?.text()
|
|
||||||
?.replace("[HD]", "")
|
|
||||||
?.substringBefore("(")
|
|
||||||
?: "No Title found"
|
|
||||||
val description = document.select("div.element").last()?.text()
|
val description = document.select("div.element").last()?.text()
|
||||||
val year = document.selectFirst("div.element>a.tag")?.text()?.substringBefore("-")
|
val year = document.selectFirst("div.element>a.tag")
|
||||||
|
?.text()
|
||||||
|
?.substringBefore("-")
|
||||||
|
?.substringAfter(",")
|
||||||
|
?.filter { it.isDigit() }
|
||||||
val poster = document.selectFirst("img.thumbnail")?.attr("src")
|
val poster = document.selectFirst("img.thumbnail")?.attr("src")
|
||||||
val rating = document.selectFirst("div.rating>div.value")?.text()?.trim()?.toRatingInt()
|
val rating = document.selectFirst("div.rating>div.value")?.text()?.trim()?.toRatingInt()
|
||||||
|
val recomm = document.select("div.crp_related>ul>li").map { it.toRecommendResult() }
|
||||||
if (type == TvType.TvSeries) {
|
if (type == TvType.TvSeries) {
|
||||||
val episodeList =
|
val episodeList =
|
||||||
document.select("div.accordion>div.accordion-item")
|
document.select("div.accordion>div.accordion-item")
|
||||||
|
@ -118,6 +116,7 @@ class CasaCinemaProvider : MainAPI() { // all providers must be an instance of M
|
||||||
return newTvSeriesLoadResponse(title, url, TvType.TvSeries, episodeList) {
|
return newTvSeriesLoadResponse(title, url, TvType.TvSeries, episodeList) {
|
||||||
this.year = year?.toIntOrNull()
|
this.year = year?.toIntOrNull()
|
||||||
this.plot = description
|
this.plot = description
|
||||||
|
this.recommendations = recomm
|
||||||
addPoster(poster)
|
addPoster(poster)
|
||||||
addRating(rating)
|
addRating(rating)
|
||||||
}
|
}
|
||||||
|
@ -125,7 +124,7 @@ class CasaCinemaProvider : MainAPI() { // all providers must be an instance of M
|
||||||
val actors: List<ActorData> =
|
val actors: List<ActorData> =
|
||||||
document.select("div.cast_wraper>ul>li").map { actordata ->
|
document.select("div.cast_wraper>ul>li").map { actordata ->
|
||||||
val actorName = actordata.selectFirst("strong")?.text() ?: ""
|
val actorName = actordata.selectFirst("strong")?.text() ?: ""
|
||||||
val actorImage: String? =
|
val actorImage: String =
|
||||||
actordata.selectFirst("figure>img")?.attr("src") ?: ""
|
actordata.selectFirst("figure>img")?.attr("src") ?: ""
|
||||||
ActorData(actor = Actor(actorName, image = actorImage))
|
ActorData(actor = Actor(actorName, image = actorImage))
|
||||||
}
|
}
|
||||||
|
@ -134,12 +133,63 @@ class CasaCinemaProvider : MainAPI() { // all providers must be an instance of M
|
||||||
this.year = year?.toIntOrNull()
|
this.year = year?.toIntOrNull()
|
||||||
this.plot = description
|
this.plot = description
|
||||||
this.actors = actors
|
this.actors = actors
|
||||||
|
this.recommendations = recomm
|
||||||
addPoster(poster)
|
addPoster(poster)
|
||||||
addRating(rating)
|
addRating(rating)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Element.toRecommendResult(): SearchResponse {
|
||||||
|
val title =
|
||||||
|
fixTitle(this.selectFirst("span.crp_title"))
|
||||||
|
val isMovie = this.selectFirst("span.crp_title").isMovie()
|
||||||
|
val link =
|
||||||
|
this.selectFirst("a")?.attr("href") ?: throw ErrorLoadingException("No Link found")
|
||||||
|
|
||||||
|
val quality =
|
||||||
|
this.selectFirst("span.crp_title")?.text()?.substringAfter("[")?.substringBefore("]")
|
||||||
|
val posterUrl = this.selectFirst("img")?.attr("src")
|
||||||
|
|
||||||
|
return if (isMovie) {
|
||||||
|
newMovieSearchResponse(title, link, TvType.Movie) {
|
||||||
|
addPoster(posterUrl)
|
||||||
|
if (quality != null) {
|
||||||
|
addQuality(quality)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newTvSeriesSearchResponse(title, link, TvType.TvSeries) {
|
||||||
|
addPoster(posterUrl)
|
||||||
|
if (quality != null) {
|
||||||
|
addQuality(quality)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Element.toEpisode(season: Int): Episode {
|
||||||
|
val data =
|
||||||
|
this.select("div.fix-table>table>tbody>tr>td>a[target=_blank]")
|
||||||
|
.map { it.attr("href") }
|
||||||
|
.toJson() // isecure.link
|
||||||
|
val epNum =
|
||||||
|
this.selectFirst("li.season-no")
|
||||||
|
?.text()
|
||||||
|
?.substringAfter("x")
|
||||||
|
?.substringBefore(" ")
|
||||||
|
?.filter { it.isDigit() }
|
||||||
|
.orEmpty().ifBlank { "0" }
|
||||||
|
|
||||||
|
val epTitle =
|
||||||
|
this.selectFirst("li.other_link>a")?.text().orEmpty().ifBlank {
|
||||||
|
"Episodio $epNum"
|
||||||
|
}
|
||||||
|
val posterUrl = this.selectFirst("figure>img")?.attr("src")
|
||||||
|
return Episode(data, epTitle, season, epNum.toInt(), posterUrl = posterUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override suspend fun loadLinks(
|
override suspend fun loadLinks(
|
||||||
data: String,
|
data: String,
|
||||||
isCasting: Boolean,
|
isCasting: Boolean,
|
||||||
|
|
Loading…
Reference in a new issue