Moflix: update detail page

This commit is contained in:
alex 2024-01-16 17:04:44 +07:00
parent aaf7413dfe
commit 7253111d3e
2 changed files with 20 additions and 4 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 {

View File

@ -8,6 +8,7 @@ import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
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.toJson import com.lagradost.cloudstream3.utils.AppUtils.toJson
import org.jsoup.Jsoup
import kotlin.math.roundToInt import kotlin.math.roundToInt
class Moflix : MainAPI() { class Moflix : MainAPI() {
@ -72,10 +73,11 @@ class Moflix : MainAPI() {
override suspend fun load(url: String): LoadResponse { override suspend fun load(url: String): LoadResponse {
val res = app.get( val res = app.get(
"$mainUrl/api/v1/titles/${url.removePrefix("$mainUrl/")}?loader=titlePage", "$mainUrl/api/v1/titles/${url.fixId()}?loader=titlePage",
referer = "$mainUrl/" referer = "$mainUrl/"
).parsedSafe<Responses>() ).parsedSafe<Responses>()
val uri = Jsoup.parse(res?.seo.toString()).selectFirst("link[rel=canonical]")?.attr("href")
val id = res?.title?.id val id = res?.title?.id
val title = res?.title?.name ?: "" val title = res?.title?.name ?: ""
val poster = res?.title?.poster val poster = res?.title?.poster
@ -83,6 +85,8 @@ class Moflix : MainAPI() {
val tags = res?.title?.keywords?.mapNotNull { it.displayName } val tags = res?.title?.keywords?.mapNotNull { it.displayName }
val year = res?.title?.year val year = res?.title?.year
val isSeries = res?.title?.isSeries val isSeries = res?.title?.isSeries
val certification = res?.title?.certification
val duration = res?.title?.runtime
val type = getType(isSeries) val type = getType(isSeries)
val description = res?.title?.description val description = res?.title?.description
val trailers = res?.title?.videos?.filter { it.category.equals("trailer", true) } val trailers = res?.title?.videos?.filter { it.category.equals("trailer", true) }
@ -123,7 +127,7 @@ class Moflix : MainAPI() {
} }
} }
}?.flatten() ?: emptyList() }?.flatten() ?: emptyList()
newTvSeriesLoadResponse(title, url, TvType.TvSeries, episodes) { newTvSeriesLoadResponse(title, uri ?: url, TvType.TvSeries, episodes) {
this.posterUrl = poster this.posterUrl = poster
this.backgroundPosterUrl = backdrop this.backgroundPosterUrl = backdrop
this.year = year this.year = year
@ -132,7 +136,9 @@ class Moflix : MainAPI() {
this.tags = tags this.tags = tags
this.rating = rating this.rating = rating
this.actors = actors this.actors = actors
this.duration = duration
this.recommendations = recommendations this.recommendations = recommendations
this.contentRating = certification
addTrailer(trailers) addTrailer(trailers)
addImdbId(res?.title?.imdbId) addImdbId(res?.title?.imdbId)
addTMDbId(res?.title?.tmdbId) addTMDbId(res?.title?.tmdbId)
@ -142,7 +148,7 @@ class Moflix : MainAPI() {
newMovieLoadResponse( newMovieLoadResponse(
title, title,
url, uri ?: url,
TvType.Movie, TvType.Movie,
LoadData(isSeries = isSeries, urls = urls) LoadData(isSeries = isSeries, urls = urls)
) { ) {
@ -154,7 +160,9 @@ class Moflix : MainAPI() {
this.tags = tags this.tags = tags
this.rating = rating this.rating = rating
this.actors = actors this.actors = actors
this.duration = duration
this.recommendations = recommendations this.recommendations = recommendations
this.contentRating = certification
addTrailer(trailers) addTrailer(trailers)
addImdbId(res?.title?.imdbId) addImdbId(res?.title?.imdbId)
addTMDbId(res?.title?.tmdbId) addTMDbId(res?.title?.tmdbId)
@ -193,6 +201,12 @@ class Moflix : MainAPI() {
return true return true
} }
private fun String.fixId(): String {
val chunk = "/titles/"
return if (this.contains(chunk)) this.substringAfter(chunk)
.substringBefore("/") else this.substringAfterLast("/")
}
private suspend fun loadCustomExtractor( private suspend fun loadCustomExtractor(
url: String, url: String,
referer: String? = null, referer: String? = null,
@ -233,6 +247,7 @@ class Moflix : MainAPI() {
data class Responses( data class Responses(
@JsonProperty("pagination") val pagination: Pagination? = null, @JsonProperty("pagination") val pagination: Pagination? = null,
@JsonProperty("title") val title: Title? = null, @JsonProperty("title") val title: Title? = null,
@JsonProperty("seo") val seo: String? = null,
@JsonProperty("credits") val credits: Credits? = null, @JsonProperty("credits") val credits: Credits? = null,
@JsonProperty("seasons") val seasons: Seasons? = null, @JsonProperty("seasons") val seasons: Seasons? = null,
@JsonProperty("episodes") val episodes: Episodes? = null, @JsonProperty("episodes") val episodes: Episodes? = null,
@ -305,6 +320,7 @@ class Moflix : MainAPI() {
@JsonProperty("name") val name: String? = null, @JsonProperty("name") val name: String? = null,
@JsonProperty("release_date") val releaseDate: String? = null, @JsonProperty("release_date") val releaseDate: String? = null,
@JsonProperty("year") val year: Int? = null, @JsonProperty("year") val year: Int? = null,
@JsonProperty("runtime") val runtime: Int? = null,
@JsonProperty("poster") val poster: String? = null, @JsonProperty("poster") val poster: String? = null,
@JsonProperty("backdrop") val backdrop: String? = null, @JsonProperty("backdrop") val backdrop: String? = null,
@JsonProperty("description") val description: String? = null, @JsonProperty("description") val description: String? = null,