|
| 1 | +package com.moviebox |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonProperty |
| 4 | +import com.lagradost.cloudstream3.* |
| 5 | +import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer |
| 6 | +import com.lagradost.cloudstream3.utils.* |
| 7 | +import com.lagradost.cloudstream3.utils.AppUtils.parseJson |
| 8 | +import com.lagradost.cloudstream3.utils.AppUtils.toJson |
| 9 | +import com.lagradost.nicehttp.RequestBodyTypes |
| 10 | +import okhttp3.MediaType.Companion.toMediaTypeOrNull |
| 11 | +import okhttp3.RequestBody.Companion.toRequestBody |
| 12 | + |
| 13 | +class MovieboxProvider : MainAPI() { |
| 14 | + |
| 15 | + override var mainUrl = "https://moviebox.ph" |
| 16 | + private val apiUrl = "https://fmoviesunblocked.net" |
| 17 | + override val instantLinkLoading = true |
| 18 | + override var name = "Moviebox" |
| 19 | + override val hasMainPage = true |
| 20 | + override val hasQuickSearch = true |
| 21 | + override var lang = "id" |
| 22 | + override val supportedTypes = setOf(TvType.Movie, TvType.TvSeries, TvType.Anime, TvType.AsianDrama) |
| 23 | + |
| 24 | + override val mainPage = mainPageOf( |
| 25 | + "872031290915189720" to "Trending Now", |
| 26 | + "997144265920760504" to "Popular Movie", |
| 27 | + "5283462032510044280" to "Drama Indonesia Terkini", |
| 28 | + "6528093688173053896" to "Trending Indonesian Movies", |
| 29 | + "4380734070238626200" to "K-Drama", |
| 30 | + "7736026911486755336" to "Western TV", |
| 31 | + "8624142774394406504" to "Most Popular C-Drama", |
| 32 | + "5404290953194750296" to "Trending Anime", |
| 33 | + "5848753831881965888" to "Indonesian Horror Stories", |
| 34 | + "1164329479448281992" to "Thai-Drama", |
| 35 | + "7132534597631837112" to "Animated Film", |
| 36 | + ) |
| 37 | + |
| 38 | + override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse { |
| 39 | + val url = "$mainUrl/wefeed-h5-bff/web/ranking-list/content?id=${request.data}&page=$page&perPage=12" |
| 40 | + val home = app.get(url).parsedSafe<Media>()?.data?.subjectList?.map { it.toSearchResponse(this) } |
| 41 | + ?: throw ErrorLoadingException("No Data Found") |
| 42 | + return newHomePageResponse(request.name, home) |
| 43 | + } |
| 44 | + |
| 45 | + override suspend fun quickSearch(query: String): List<SearchResponse> = search(query) |
| 46 | + |
| 47 | + override suspend fun search(query: String): List<SearchResponse> { |
| 48 | + val body = mapOf("keyword" to query, "page" to "1", "perPage" to "0", "subjectType" to "0") |
| 49 | + .toJson().toRequestBody(RequestBodyTypes.JSON.toMediaTypeOrNull()) |
| 50 | + return app.post("$mainUrl/wefeed-h5-bff/web/subject/search", requestBody = body) |
| 51 | + .parsedSafe<Media>()?.data?.items?.map { it.toSearchResponse(this) } ?: throw ErrorLoadingException() |
| 52 | + } |
| 53 | + |
| 54 | + override suspend fun load(url: String): LoadResponse { |
| 55 | + val id = url.substringAfterLast("/") |
| 56 | + val doc = app.get("$mainUrl/wefeed-h5-bff/web/subject/detail?subjectId=$id").parsedSafe<MediaDetail>()?.data |
| 57 | + val subject = doc?.subject |
| 58 | + val title = subject?.title ?: "" |
| 59 | + val poster = subject?.cover?.url |
| 60 | + val tags = subject?.genre?.split(",")?.map { it.trim() } |
| 61 | + val year = subject?.releaseDate?.substringBefore("-")?.toIntOrNull() |
| 62 | + val tvType = if (subject?.subjectType == 2) TvType.TvSeries else TvType.Movie |
| 63 | + val description = subject?.description |
| 64 | + val trailer = subject?.trailer?.videoAddress?.url |
| 65 | + val rating = subject?.imdbRatingValue.toRatingInt() |
| 66 | + val actors = doc?.stars?.mapNotNull { cast -> |
| 67 | + ActorData(Actor(cast.name ?: return@mapNotNull null, cast.avatarUrl), roleString = cast.character) |
| 68 | + }?.distinctBy { it.actor } |
| 69 | + val recommendations = app.get("$mainUrl/wefeed-h5-bff/web/subject/detail-rec?subjectId=$id&page=1&perPage=12") |
| 70 | + .parsedSafe<Media>()?.data?.items?.map { it.toSearchResponse(this) } |
| 71 | + |
| 72 | + return if (tvType == TvType.TvSeries) { |
| 73 | + val episodes = doc?.resource?.seasons?.map { seasons -> |
| 74 | + (if (seasons.allEp.isNullOrEmpty()) (1..seasons.maxEp!!) else seasons.allEp.split(",").map { it.toInt() }) |
| 75 | + .map { episode -> newEpisode(LoadData(id, seasons.se, episode, subject?.detailPath).toJson()) { |
| 76 | + this.season = seasons.se |
| 77 | + this.episode = episode |
| 78 | + }} |
| 79 | + }?.flatten() ?: emptyList() |
| 80 | + newTvSeriesLoadResponse(title, url, TvType.TvSeries, episodes) { |
| 81 | + this.posterUrl = poster |
| 82 | + this.year = year |
| 83 | + this.plot = description |
| 84 | + this.tags = tags |
| 85 | + this.rating = rating |
| 86 | + this.actors = actors |
| 87 | + this.recommendations = recommendations |
| 88 | + addTrailer(trailer, addRaw = true) |
| 89 | + } |
| 90 | + } else { |
| 91 | + newMovieLoadResponse(title, url, TvType.Movie, LoadData(id, detailPath = subject?.detailPath).toJson()) { |
| 92 | + this.posterUrl = poster |
| 93 | + this.year = year |
| 94 | + this.plot = description |
| 95 | + this.tags = tags |
| 96 | + this.rating = rating |
| 97 | + this.actors = actors |
| 98 | + this.recommendations = recommendations |
| 99 | + addTrailer(trailer, addRaw = true) |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + override suspend fun loadLinks(data: String, isCasting: Boolean, subtitleCallback: (SubtitleFile) -> Unit, callback: (ExtractorLink) -> Unit): Boolean { |
| 105 | + val media = parseJson<LoadData>(data) |
| 106 | + val referer = "$apiUrl/spa/videoPlayPage/movies/${media.detailPath}?id=${media.id}&type=/movie/detail&lang=en" |
| 107 | + val streams = app.get("$apiUrl/wefeed-h5-bff/web/subject/play?subjectId=${media.id}&se=${media.season ?: 0}&ep=${media.episode ?: 0}", referer = referer) |
| 108 | + .parsedSafe<Media>()?.data?.streams |
| 109 | + |
| 110 | + streams?.reversed()?.distinctBy { it.url }?.forEach { source -> |
| 111 | + callback(newExtractorLink(this.name, this.name, source.url ?: return@forEach, INFER_TYPE) { |
| 112 | + this.referer = "$apiUrl/" |
| 113 | + this.quality = getQualityFromName(source.resolutions) |
| 114 | + }) |
| 115 | + } |
| 116 | + |
| 117 | + val id = streams?.first()?.id |
| 118 | + val format = streams?.first()?.format |
| 119 | + app.get("$apiUrl/wefeed-h5-bff/web/subject/caption?format=$format&id=$id&subjectId=${media.id}", referer = referer) |
| 120 | + .parsedSafe<Media>()?.data?.captions?.forEach { subtitle -> |
| 121 | + subtitleCallback(SubtitleFile(subtitle.lanName ?: "", subtitle.url ?: return@forEach)) |
| 122 | + } |
| 123 | + |
| 124 | + return true |
| 125 | + } |
| 126 | + |
| 127 | + data class LoadData(val id: String? = null, val season: Int? = null, val episode: Int? = null, val detailPath: String? = null) |
| 128 | + |
| 129 | + data class Media(@JsonProperty("data") val data: Data? = null) { |
| 130 | + data class Data( |
| 131 | + @JsonProperty("subjectList") val subjectList: ArrayList<Items>? = arrayListOf(), |
| 132 | + @JsonProperty("items") val items: ArrayList<Items>? = arrayListOf(), |
| 133 | + @JsonProperty("streams") val streams: ArrayList<Streams>? = arrayListOf(), |
| 134 | + @JsonProperty("captions") val captions: ArrayList<Captions>? = arrayListOf() |
| 135 | + ) { |
| 136 | + data class Streams(@JsonProperty("id") val id: String? = null, @JsonProperty("format") val format: String? = null, @JsonProperty("url") val url: String? = null, @JsonProperty("resolutions") val resolutions: String? = null) |
| 137 | + data class Captions(@JsonProperty("lan") val lan: String? = null, @JsonProperty("lanName") val lanName: String? = null, @JsonProperty("url") val url: String? = null) |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + data class MediaDetail(@JsonProperty("data") val data: Data? = null) { |
| 142 | + data class Data( |
| 143 | + @JsonProperty("subject") val subject: Items? = null, |
| 144 | + @JsonProperty("stars") val stars: ArrayList<Stars>? = arrayListOf(), |
| 145 | + @JsonProperty("resource") val resource: Resource? = null |
| 146 | + ) { |
| 147 | + data class Stars(@JsonProperty("name") val name: String? = null, @JsonProperty("character") val character: String? = null, @JsonProperty("avatarUrl") val avatarUrl: String? = null) |
| 148 | + data class Resource(@JsonProperty("seasons") val seasons: ArrayList<Seasons>? = arrayListOf()) { |
| 149 | + data class Seasons(@JsonProperty("se") val se: Int? = null, @JsonProperty("maxEp") val maxEp: Int? = null, @JsonProperty("allEp") val allEp: String? = null) |
| 150 | + } |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + data class Items( |
| 155 | + @JsonProperty("subjectId") val subjectId: String? = null, |
| 156 | + @JsonProperty("subjectType") val subjectType: Int? = null, |
| 157 | + @JsonProperty("title") val title: String? = null, |
| 158 | + @JsonProperty("description") val description: String? = null, |
| 159 | + @JsonProperty("releaseDate") val releaseDate: String? = null, |
| 160 | + @JsonProperty("duration") val duration: Long? = null, |
| 161 | + @JsonProperty("genre") val genre: String? = null, |
| 162 | + @JsonProperty("cover") val cover: Cover? = null, |
| 163 | + @JsonProperty("imdbRatingValue") val imdbRatingValue: String? = null, |
| 164 | + @JsonProperty("countryName") val countryName: String? = null, |
| 165 | + @JsonProperty("trailer") val trailer: Trailer? = null, |
| 166 | + @JsonProperty("detailPath") val detailPath: String? = null |
| 167 | + ) { |
| 168 | + fun toSearchResponse(provider: Moviebox): SearchResponse { |
| 169 | + return provider.newMovieSearchResponse(title ?: "", subjectId!!, if (subjectType == 1) TvType.Movie else TvType.TvSeries, false) { |
| 170 | + this.posterUrl = cover?.url |
| 171 | + } |
| 172 | + } |
| 173 | + data class Cover(@JsonProperty("url") val url: String? = null) |
| 174 | + data class Trailer(@JsonProperty("videoAddress") val videoAddress: VideoAddress? = null) { |
| 175 | + data class VideoAddress(@JsonProperty("url") val url: String? = null) |
| 176 | + } |
| 177 | + } |
| 178 | +} |
0 commit comments