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

246 lines
9.3 KiB
Kotlin
Raw Normal View History

2022-09-09 16:09:54 +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
2023-09-13 15:16:03 +00:00
import com.lagradost.cloudstream3.extractors.helper.AesHelper
2023-09-01 22:48:35 +00:00
import com.lagradost.cloudstream3.network.CloudflareKiller
2022-09-09 16:09:54 +00:00
import com.lagradost.cloudstream3.utils.*
import org.jsoup.nodes.Element
2022-12-05 22:22:04 +00:00
import java.net.URI
2022-09-09 16:09:54 +00:00
class IdlixProvider : MainAPI() {
2023-08-29 13:28:15 +00:00
override var mainUrl = "https://tv.idlixplus.net"
2022-12-05 22:22:04 +00:00
private var directUrl = mainUrl
2022-09-09 16:09:54 +00:00
override var name = "Idlix"
override val hasMainPage = true
override var lang = "id"
override val hasDownloadSupport = true
2023-09-01 22:48:35 +00:00
private val cloudflareKiller by lazy { CloudflareKiller() }
2022-09-09 16:09:54 +00:00
override val supportedTypes = setOf(
TvType.Movie,
TvType.TvSeries,
2022-09-30 09:02:16 +00:00
TvType.Anime,
TvType.AsianDrama
2022-09-09 16:09:54 +00:00
)
override val mainPage = mainPageOf(
2022-09-30 09:02:16 +00:00
"$mainUrl/" to "Featured",
2022-09-09 16:09:54 +00:00
"$mainUrl/trending/page/?get=movies" to "Trending Movies",
"$mainUrl/trending/page/?get=tv" to "Trending TV Series",
"$mainUrl/movie/page/" to "Movie Terbaru",
"$mainUrl/tvseries/page/" to "TV Series Terbaru",
2023-09-13 15:16:03 +00:00
// "$mainUrl/network/netflix/page/" to "Netflix",
// "$mainUrl/genre/anime/page/" to "Anime",
// "$mainUrl/genre/drama-korea/page/" to "Drama Korea",
2022-09-09 16:09:54 +00:00
)
2022-12-05 22:22:04 +00:00
private fun getBaseUrl(url: String): String {
return URI(url).let {
"${it.scheme}://${it.host}"
}
}
2022-09-09 16:09:54 +00:00
override suspend fun getMainPage(
page: Int,
request: MainPageRequest
): HomePageResponse {
val url = request.data.split("?")
2022-09-30 18:02:50 +00:00
val nonPaged = request.name == "Featured" && page <= 1
2023-03-28 04:50:08 +00:00
val req = if (nonPaged) {
2023-09-13 15:16:03 +00:00
app.get(request.data)
2022-09-30 09:02:16 +00:00
} else {
2023-09-13 15:16:03 +00:00
app.get("${url.first()}$page/?${url.lastOrNull()}")
2022-09-30 09:02:16 +00:00
}
2023-03-28 04:50:08 +00:00
mainUrl = getBaseUrl(req.url)
val document = req.document
2022-09-30 18:02:50 +00:00
val home = (if (nonPaged) {
2022-09-30 09:02:16 +00:00
document.select("div.items.featured article")
} else {
document.select("div.items.full article, div#archive-content article")
}).mapNotNull {
2022-09-09 16:09:54 +00:00
it.toSearchResult()
}
return newHomePageResponse(request.name, home)
}
private fun getProperLink(uri: String): String {
return when {
uri.contains("/episode/") -> {
var title = uri.substringAfter("$mainUrl/episode/")
title = Regex("(.+?)-season").find(title)?.groupValues?.get(1).toString()
"$mainUrl/tvseries/$title"
}
2023-09-13 15:16:03 +00:00
2022-09-09 16:09:54 +00:00
uri.contains("/season/") -> {
var title = uri.substringAfter("$mainUrl/season/")
title = Regex("(.+?)-season").find(title)?.groupValues?.get(1).toString()
"$mainUrl/tvseries/$title"
}
2023-09-13 15:16:03 +00:00
2022-09-09 16:09:54 +00:00
else -> {
uri
}
}
}
private fun Element.toSearchResult(): SearchResponse {
val title = this.selectFirst("h3 > a")!!.text().replace(Regex("\\(\\d{4}\\)"), "").trim()
val href = getProperLink(this.selectFirst("h3 > a")!!.attr("href"))
val posterUrl = this.select("div.poster > img").attr("src").toString()
val quality = getQualityFromString(this.select("span.quality").text())
return newMovieSearchResponse(title, href, TvType.Movie) {
this.posterUrl = posterUrl
this.quality = quality
}
}
override suspend fun search(query: String): List<SearchResponse> {
2023-09-13 15:16:03 +00:00
val req = app.get("$mainUrl/search/$query")
2023-03-28 04:50:08 +00:00
mainUrl = getBaseUrl(req.url)
val document = req.document
2022-09-09 16:09:54 +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
}
}
}
override suspend fun load(url: String): LoadResponse {
2023-09-13 15:16:03 +00:00
val request = app.get(url)
2022-12-05 22:22:04 +00:00
directUrl = getBaseUrl(request.url)
val document = request.document
2022-09-09 16:09:54 +00:00
val title =
document.selectFirst("div.data > h1")?.text()?.replace(Regex("\\(\\d{4}\\)"), "")
?.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
}
}
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)
}
} 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)
}
}
}
override suspend fun loadLinks(
data: String,
isCasting: Boolean,
subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit
): Boolean {
2023-09-13 15:16:03 +00:00
val document = app.get(data).document
2022-09-09 16:09:54 +00:00
document.select("ul#playeroptionsul > li").map {
2023-09-13 15:16:03 +00:00
Triple(
it.attr("data-post"),
it.attr("data-nume"),
it.attr("data-type")
)
}.apmap { (id, nume, type) ->
val json = 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("Accept" to "*/*", "X-Requested-With" to "XMLHttpRequest")
).parsedSafe<ResponseHash>() ?: return@apmap
val metrix = AppUtils.parseJson<AesData>(json.embed_url).m
val password = createKey(json.key, metrix)
val decrypted = AesHelper.cryptoAESHandler(json.embed_url, password.toByteArray(), false)?.fixBloat() ?: return@apmap
when {
!decrypted.contains("youtube") -> loadExtractor(decrypted, "$directUrl/", subtitleCallback, callback)
else -> return@apmap
2022-09-09 16:09:54 +00:00
}
}
return true
}
2023-09-13 15:16:03 +00:00
private fun createKey(r: String, m: String): String {
val rList = r.split("\\x").toTypedArray()
var n = ""
val decodedM = String(base64Decode(m.split("").reversed().joinToString("")).toCharArray())
for (s in decodedM.split("|")) {
n += "\\x" + rList[Integer.parseInt(s) + 1]
2023-09-01 22:48:35 +00:00
}
2023-09-13 15:16:03 +00:00
return n
2023-09-01 22:48:35 +00:00
}
2023-09-13 15:16:03 +00:00
private fun String.fixBloat(): String {
2023-08-29 13:28:15 +00:00
return this.replace("\"", "").replace("\\", "")
}
2022-10-21 15:53:47 +00:00
data class ResponseHash(
@JsonProperty("embed_url") val embed_url: String,
2023-09-13 15:16:03 +00:00
@JsonProperty("key") val key: String,
)
data class AesData(
@JsonProperty("m") val m: String,
2022-10-21 15:53:47 +00:00
)
2023-08-29 13:28:15 +00:00
2022-09-09 16:09:54 +00:00
}