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

300 lines
12 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.mvvm.safeApiCall
import com.lagradost.cloudstream3.network.CloudflareKiller
2022-09-11 13:00:33 +00:00
import com.lagradost.cloudstream3.utils.*
import org.jsoup.nodes.Element
class Movierulzhd : MainAPI() {
2022-11-05 14:05:50 +00:00
override var mainUrl = "https://movierulzhd.guru"
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(
"$mainUrl/trending/page/" to "Trending",
"$mainUrl/movies/page/" to "Movies",
"$mainUrl/tvshows/page/" to "TV Shows",
2022-09-22 12:40:03 +00:00
"$mainUrl/genre/netflix/page/" to "Netflix",
"$mainUrl/genre/amazon-prime/page/" to "Amazon Prime",
"$mainUrl/genre/Zee5/page/" to "Zee5",
2022-09-11 13:00:33 +00:00
"$mainUrl/seasons/page/" to "Season",
"$mainUrl/episodes/page/" to "Episode",
)
2022-11-04 06:43:08 +00:00
private val interceptor = CloudflareKiller()
2022-09-11 13:00:33 +00:00
override suspend fun getMainPage(
page: Int,
request: MainPageRequest
): HomePageResponse {
2022-11-04 13:34:54 +00:00
var document = app.get(request.data + page,).document
if(document.select("title").text() == "Just a moment...") {
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
}
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
}
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")))
2022-09-11 13:00:33 +00:00
val posterUrl = fixUrlNull(this.select("div.poster > img").attr("src"))
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-04 13:34:54 +00:00
var document = app.get(link,).document
if(document.select("title").text() == "Just a moment...") {
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-04 13:34:54 +00:00
var document = app.get(url,).document
if(document.select("title").text() == "Just a moment...") {
document = app.get(url, interceptor = interceptor).document
}
2022-09-11 13:00:33 +00:00
val title =
document.selectFirst("div.data > h1")?.text()?.trim().toString()
val poster = document.select("div.poster > img").attr("src").toString()
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()
val tvType = if (document.select("ul#section > li:nth-child(1)").text().contains("Episodes")
) 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 {
Actor(it.select("meta[itemprop=name]").attr("content"), it.select("img").attr("src"))
}
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) {
val episodes = 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")
val episode = it.select("div.numerando").text().replace(" ", "").split("-").last()
.toIntOrNull()
val season = it.select("div.numerando").text().replace(" ", "").split("-").first()
.toIntOrNull()
Episode(
href,
name,
season,
episode,
image
)
}
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
}
}
}
2022-09-13 06:35:14 +00:00
private suspend fun invokeSbflix(
url: String,
callback: (ExtractorLink) -> Unit,
) {
val mainUrl = "https://sbflix.xyz"
val name = "Sbflix"
2022-09-13 18:42:47 +00:00
val regexID =
2022-09-14 04:05:26 +00:00
Regex("(embed-[a-zA-Z0-9]{0,8}[a-zA-Z0-9_-]+|/e/[a-zA-Z0-9]{0,8}[a-zA-Z0-9_-]+)")
2022-09-13 06:35:14 +00:00
val id = regexID.findAll(url).map {
2022-09-14 04:05:26 +00:00
it.value.replace(Regex("(embed-|/e/)"), "")
2022-09-13 06:35:14 +00:00
}.first()
val master = "$mainUrl/sources48/" + bytesToHex("||$id||||streamsb".toByteArray()) + "/"
val headers = mapOf(
"watchsb" to "sbstream",
)
2022-09-13 18:42:47 +00:00
val urltext = app.get(
master.lowercase(),
2022-09-13 06:35:14 +00:00
headers = headers,
referer = url,
).text
val mapped = urltext.let { AppUtils.parseJson<Main>(it) }
2022-09-13 18:42:47 +00:00
val testurl = app.get(mapped.streamData.file, headers = headers).text
if (urltext.contains("m3u8") && testurl.contains("EXTM3U"))
2022-09-13 17:19:36 +00:00
callback.invoke(
2022-09-13 18:42:47 +00:00
ExtractorLink(
name,
name,
mapped.streamData.file,
url,
Qualities.Unknown.value,
isM3u8 = true,
headers = headers
)
2022-09-13 17:19:36 +00:00
)
2022-09-13 06:35:14 +00:00
}
2022-09-11 13:00:33 +00:00
override suspend fun loadLinks(
data: String,
isCasting: Boolean,
subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit
): Boolean {
2022-11-04 13:34:54 +00:00
var document = app.get(data).document
if(document.select("title").text() == "Just a moment...") {
document = app.get(data, interceptor = interceptor).document
}
2022-09-11 13:00:33 +00:00
val id = document.select("meta#dooplay-ajax-counter").attr("data-postid")
val type = if (data.contains("/movies/")) "movie" else "tv"
document.select("ul#playeroptionsul > li").map {
it.attr("data-nume")
}.apmap { nume ->
safeApiCall {
val source = app.post(
url = "$mainUrl/wp-admin/admin-ajax.php",
data = mapOf(
"action" to "doo_player_ajax",
"post" to id,
"nume" to nume,
"type" to type
2022-09-13 06:35:14 +00:00
),
referer = data,
headers = mapOf("X-Requested-With" to "XMLHttpRequest")
2022-09-11 13:00:33 +00:00
).parsed<ResponseHash>().embed_url
2022-09-13 06:35:14 +00:00
when {
source.startsWith("https://sbflix.xyz") -> {
2022-09-13 07:01:23 +00:00
invokeSbflix(source, callback)
2022-09-13 06:35:14 +00:00
}
// source.startsWith("https://series.databasegdriveplayer.co") -> {
// invokeDatabase(source, callback, subtitleCallback)
// }
else -> loadExtractor(source, data, subtitleCallback, callback)
}
2022-09-11 13:00:33 +00:00
}
}
return true
}
data class ResponseHash(
@JsonProperty("embed_url") val embed_url: String,
@JsonProperty("type") val type: String?,
)
2022-09-13 06:35:14 +00:00
private val hexArray = "0123456789ABCDEF".toCharArray()
private fun bytesToHex(bytes: ByteArray): String {
val hexChars = CharArray(bytes.size * 2)
for (j in bytes.indices) {
val v = bytes[j].toInt() and 0xFF
hexChars[j * 2] = hexArray[v ushr 4]
hexChars[j * 2 + 1] = hexArray[v and 0x0F]
}
return String(hexChars)
}
2022-09-13 18:42:47 +00:00
data class Subs(
2022-09-13 06:35:14 +00:00
@JsonProperty("file") val file: String,
@JsonProperty("label") val label: String,
)
2022-09-13 18:42:47 +00:00
data class StreamData(
2022-09-13 06:35:14 +00:00
@JsonProperty("file") val file: String,
@JsonProperty("cdn_img") val cdnImg: String,
@JsonProperty("hash") val hash: String,
@JsonProperty("subs") val subs: List<Subs>?,
@JsonProperty("length") val length: String,
@JsonProperty("id") val id: String,
@JsonProperty("title") val title: String,
@JsonProperty("backup") val backup: String,
)
2022-09-13 18:42:47 +00:00
data class Main(
2022-09-13 06:35:14 +00:00
@JsonProperty("stream_data") val streamData: StreamData,
@JsonProperty("status_code") val statusCode: Int,
)
2022-10-20 20:52:32 +00:00
}