Fixes and Improvements CasaCinemaProvider (#66)

This commit is contained in:
contusionglory 2022-12-14 22:21:58 +00:00 committed by GitHub
parent 220d62d1dc
commit 86d2a704ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 137 additions and 86 deletions

View File

@ -1,5 +1,5 @@
// use an integer for version numbers
version = 2
version = 3
cloudstream {
@ -22,4 +22,5 @@ cloudstream {
"Movie",
)
iconUrl = "https://www.google.com/s2/favicons?domain=casacinema.lol&sz=%size%"
}

View File

@ -28,54 +28,31 @@ class CasaCinemaProvider : MainAPI() { // all providers must be an instance of M
"$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 {
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 hasNext = soup.select("div.navigation>ul>li>a").last()?.text() == "Pagina successiva »"
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> {
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() }
}
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 {
val document = app.get(url).document
val document = app.get(url, referer = mainUrl).document
val type =
if (document.selectFirst("h3")?.text() == "Altri Film:") TvType.Movie
else TvType.TvSeries
val title =
document.selectFirst("div.row > h1")
?.text()
?.replace("[HD]", "")
?.substringBefore("(")
?: "No Title found"
if (document.select("div.seasons-wraper").isNotEmpty()) TvType.TvSeries
else TvType.Movie
val title = fixTitle(document.selectFirst("div.row > h1"))
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 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) {
val episodeList =
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) {
this.year = year?.toIntOrNull()
this.plot = description
this.recommendations = recomm
addPoster(poster)
addRating(rating)
}
@ -125,7 +124,7 @@ class CasaCinemaProvider : MainAPI() { // all providers must be an instance of M
val actors: List<ActorData> =
document.select("div.cast_wraper>ul>li").map { actordata ->
val actorName = actordata.selectFirst("strong")?.text() ?: ""
val actorImage: String? =
val actorImage: String =
actordata.selectFirst("figure>img")?.attr("src") ?: ""
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.plot = description
this.actors = actors
this.recommendations = recomm
addPoster(poster)
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(
data: String,
isCasting: Boolean,