cloudstream-extensions-hexated/Movierulzhd/src/main/kotlin/com/hexated/Movierulzhd.kt

284 lines
11 KiB
Kotlin
Raw Normal View History

2022-09-11 13:00:33 +00:00
package com.hexated
import com.fasterxml.jackson.annotation.JsonProperty
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.addActors
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
import com.lagradost.cloudstream3.network.CloudflareKiller
2022-09-11 13:00:33 +00:00
import com.lagradost.cloudstream3.utils.*
2022-11-29 13:08:14 +00:00
import com.lagradost.cloudstream3.utils.AppUtils.toJson
2022-09-11 13:00:33 +00:00
import org.jsoup.nodes.Element
import java.net.URI
2022-09-11 13:00:33 +00:00
2023-07-27 16:09:25 +00:00
open class Movierulzhd : MainAPI() {
override var mainUrl = "https://movierulzvid.gold"
2023-07-27 16:09:25 +00:00
var directUrl = ""
2022-09-11 13:00:33 +00:00
override var name = "Movierulzhd"
override val hasMainPage = true
override var lang = "hi"
override val hasDownloadSupport = true
override val supportedTypes = setOf(
TvType.Movie,
TvType.TvSeries,
)
override val mainPage = mainPageOf(
2023-07-27 16:09:25 +00:00
"trending" to "Trending",
"movies" to "Movies",
"tvshows" to "TV Shows",
"genre/netflix" to "Netflix",
"genre/amazon-prime" to "Amazon Prime",
"genre/Zee5" to "Zee5",
"seasons" to "Season",
"episodes" to "Episode",
2022-09-11 13:00:33 +00:00
)
2023-07-27 16:09:25 +00:00
val interceptor = CloudflareKiller()
2022-09-11 13:00:33 +00:00
override suspend fun getMainPage(
page: Int,
request: MainPageRequest
): HomePageResponse {
2023-07-27 16:09:25 +00:00
var document = app.get("$mainUrl/${request.data}/page/$page").document
if (document.select("title").text() == "Just a moment...") {
2022-11-04 13:34:54 +00:00
document = app.get(request.data + page, interceptor = interceptor).document
}
2022-09-13 18:42:47 +00:00
val home =
document.select("div.items.normal article, div#archive-content article").mapNotNull {
it.toSearchResult()
}
2022-09-11 13:00:33 +00:00
return newHomePageResponse(request.name, home)
}
private fun getProperLink(uri: String): String {
return when {
2022-09-13 07:01:23 +00:00
uri.contains("/episodes/") -> {
var title = uri.substringAfter("$mainUrl/episodes/")
2022-09-11 13:00:33 +00:00
title = Regex("(.+?)-season").find(title)?.groupValues?.get(1).toString()
2022-09-13 07:01:23 +00:00
"$mainUrl/tvshows/$title"
2022-09-11 13:00:33 +00:00
}
2023-07-27 16:09:25 +00:00
2022-09-13 07:01:23 +00:00
uri.contains("/seasons/") -> {
var title = uri.substringAfter("$mainUrl/seasons/")
2022-09-11 13:00:33 +00:00
title = Regex("(.+?)-season").find(title)?.groupValues?.get(1).toString()
2022-09-13 07:01:23 +00:00
"$mainUrl/tvshows/$title"
2022-09-11 13:00:33 +00:00
}
2023-07-27 16:09:25 +00:00
2022-09-11 13:00:33 +00:00
else -> {
uri
}
}
}
private fun Element.toSearchResult(): SearchResponse? {
val title = this.selectFirst("h3 > a")?.text() ?: return null
2022-09-13 07:01:23 +00:00
val href = getProperLink(fixUrl(this.selectFirst("h3 > a")!!.attr("href")))
2023-07-27 16:09:25 +00:00
val posterUrl = fixUrlNull(this.select("div.poster img").last()?.attr("src"))
2022-09-11 13:00:33 +00:00
val quality = getQualityFromString(this.select("span.quality").text())
return newMovieSearchResponse(title, href, TvType.Movie) {
this.posterUrl = posterUrl
this.quality = quality
2022-11-04 06:43:08 +00:00
posterHeaders = interceptor.getCookieHeaders(mainUrl).toMap()
2022-09-11 13:00:33 +00:00
}
}
override suspend fun search(query: String): List<SearchResponse> {
val link = "$mainUrl/search/$query"
2022-11-29 13:08:14 +00:00
var document = app.get(link).document
2023-07-27 16:09:25 +00:00
if (document.select("title").text() == "Just a moment...") {
2022-11-04 13:34:54 +00:00
document = app.get(link, interceptor = interceptor).document
}
2022-09-11 13:00:33 +00:00
return document.select("div.result-item").map {
val title =
it.selectFirst("div.title > a")!!.text().replace(Regex("\\(\\d{4}\\)"), "").trim()
val href = getProperLink(it.selectFirst("div.title > a")!!.attr("href"))
val posterUrl = it.selectFirst("img")!!.attr("src").toString()
newMovieSearchResponse(title, href, TvType.TvSeries) {
this.posterUrl = posterUrl
2022-11-04 13:34:54 +00:00
posterHeaders = interceptor.getCookieHeaders(mainUrl).toMap()
2022-09-11 13:00:33 +00:00
}
}
}
override suspend fun load(url: String): LoadResponse {
2022-11-29 13:08:14 +00:00
val request = app.get(url)
var document = request.document
2023-07-27 16:09:25 +00:00
if (document.select("title").text() == "Just a moment...") {
2022-11-04 13:34:54 +00:00
document = app.get(url, interceptor = interceptor).document
}
2022-11-29 13:08:14 +00:00
directUrl = getBaseUrl(request.url)
2022-09-11 13:00:33 +00:00
val title =
document.selectFirst("div.data > h1")?.text()?.trim().toString()
2023-07-27 16:09:25 +00:00
val poster = fixUrlNull(document.select("div.poster img:last-child").attr("src"))
2022-09-11 13:00:33 +00:00
val tags = document.select("div.sgeneros > a").map { it.text() }
val year = Regex(",\\s?(\\d+)").find(
document.select("span.date").text().trim()
)?.groupValues?.get(1).toString().toIntOrNull()
2022-11-29 13:08:14 +00:00
val tvType = if (document.select("ul#section > li:nth-child(1)").text()
.contains("Episodes") || document.select("ul#playeroptionsul li span.title")
.text().contains(
2023-07-27 16:09:25 +00:00
Regex("Episode\\s+\\d+|EP\\d+|PE\\d+")
)
2022-09-11 13:00:33 +00:00
) TvType.TvSeries else TvType.Movie
val description = document.select("div.wp-content > p").text().trim()
val trailer = document.selectFirst("div.embed iframe")?.attr("src")
val rating =
document.selectFirst("span.dt_rating_vgs")?.text()?.toRatingInt()
val actors = document.select("div.persons > div[itemprop=actor]").map {
2023-07-27 16:09:25 +00:00
Actor(
it.select("meta[itemprop=name]").attr("content"),
it.select("img:last-child").attr("src")
)
2022-09-11 13:00:33 +00:00
}
val recommendations = document.select("div.owl-item").map {
val recName =
it.selectFirst("a")!!.attr("href").toString().removeSuffix("/").split("/").last()
val recHref = it.selectFirst("a")!!.attr("href")
val recPosterUrl = it.selectFirst("img")?.attr("src").toString()
newTvSeriesSearchResponse(recName, recHref, TvType.TvSeries) {
this.posterUrl = recPosterUrl
2022-11-04 06:43:08 +00:00
posterHeaders = interceptor.getCookieHeaders(url).toMap()
2022-09-11 13:00:33 +00:00
}
}
return if (tvType == TvType.TvSeries) {
2023-07-27 16:09:25 +00:00
val episodes = if (document.select("ul.episodios > li").isNotEmpty()) {
2022-11-29 13:08:14 +00:00
document.select("ul.episodios > li").map {
val href = it.select("a").attr("href")
val name = fixTitle(it.select("div.episodiotitle > a").text().trim())
val image = it.select("div.imagen > img").attr("src")
2023-07-27 16:09:25 +00:00
val episode =
it.select("div.numerando").text().replace(" ", "").split("-").last()
.toIntOrNull()
val season =
it.select("div.numerando").text().replace(" ", "").split("-").first()
.toIntOrNull()
2022-11-29 13:08:14 +00:00
Episode(
href,
name,
season,
episode,
image
)
}
} else {
document.select("ul#playeroptionsul > li").map {
val name = it.selectFirst("span.title")?.text()
val type = it.attr("data-type")
val post = it.attr("data-post")
val nume = it.attr("data-nume")
Episode(
LinkData(type, post, nume).toJson(),
name,
)
}
2022-09-11 13:00:33 +00:00
}
newTvSeriesLoadResponse(title, url, TvType.TvSeries, episodes) {
this.posterUrl = poster
this.year = year
this.plot = description
this.tags = tags
this.rating = rating
addActors(actors)
this.recommendations = recommendations
addTrailer(trailer)
2022-11-04 06:43:08 +00:00
posterHeaders = interceptor.getCookieHeaders(url).toMap()
2022-09-11 13:00:33 +00:00
}
} else {
newMovieLoadResponse(title, url, TvType.Movie, url) {
this.posterUrl = poster
this.year = year
this.plot = description
this.tags = tags
this.rating = rating
addActors(actors)
this.recommendations = recommendations
addTrailer(trailer)
2022-11-04 06:43:08 +00:00
posterHeaders = interceptor.getCookieHeaders(url).toMap()
2022-09-11 13:00:33 +00:00
}
}
}
private fun getBaseUrl(url: String): String {
return URI(url).let {
"${it.scheme}://${it.host}"
}
}
2022-09-11 13:00:33 +00:00
override suspend fun loadLinks(
data: String,
isCasting: Boolean,
subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit
): Boolean {
2023-07-27 16:09:25 +00:00
if (data.startsWith("{")) {
2022-11-29 13:08:14 +00:00
val loadData = AppUtils.tryParseJson<LinkData>(data)
val source = app.post(
url = "$directUrl/wp-admin/admin-ajax.php",
data = mapOf(
"action" to "doo_player_ajax",
"post" to "${loadData?.post}",
"nume" to "${loadData?.nume}",
"type" to "${loadData?.type}"
),
referer = data,
headers = mapOf("X-Requested-With" to "XMLHttpRequest")
).parsed<ResponseHash>().embed_url
2023-07-27 16:09:25 +00:00
if (!source.contains("youtube")) loadExtractor(source, data, subtitleCallback, callback)
2022-11-29 13:08:14 +00:00
} else {
var document = app.get(data).document
if (document.select("title").text() == "Just a moment...") {
document = app.get(data, interceptor = interceptor).document
}
val id = document.select("meta#dooplay-ajax-counter").attr("data-postid")
val type = if (data.contains("/movies/")) "movie" else "tv"
2022-09-11 13:00:33 +00:00
2022-11-29 13:08:14 +00:00
document.select("ul#playeroptionsul > li").map {
it.attr("data-nume")
}.apmap { nume ->
2023-07-27 16:09:25 +00:00
val source = app.post(
url = "$directUrl/wp-admin/admin-ajax.php",
data = mapOf(
"action" to "doo_player_ajax",
"post" to id,
"nume" to nume,
"type" to type
),
referer = data,
headers = mapOf("X-Requested-With" to "XMLHttpRequest")
).parsed<ResponseHash>().embed_url
2022-09-11 13:00:33 +00:00
2023-07-27 16:09:25 +00:00
when {
!source.contains("youtube") -> loadExtractor(
source,
data,
subtitleCallback,
callback
)
else -> return@apmap
2022-09-13 06:35:14 +00:00
}
2022-09-11 13:00:33 +00:00
}
}
return true
}
2022-11-29 13:08:14 +00:00
data class LinkData(
val type: String? = null,
val post: String? = null,
val nume: String? = null,
)
2022-09-11 13:00:33 +00:00
data class ResponseHash(
@JsonProperty("embed_url") val embed_url: String,
@JsonProperty("type") val type: String?,
)
2022-10-20 20:52:32 +00:00
}