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

230 lines
8.8 KiB
Kotlin
Raw Normal View History

2022-09-09 16:09:54 +00:00
package com.hexated
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.addActors
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
2023-03-11 20:39:22 +00:00
import com.lagradost.cloudstream3.utils.*
2022-09-09 16:09:54 +00:00
import org.jsoup.nodes.Element
2023-01-24 03:41:12 +00:00
import java.net.URLDecoder
2023-03-11 20:39:22 +00:00
import java.net.URI
2022-09-09 16:09:54 +00:00
class LayarKacaProvider : MainAPI() {
2023-05-07 20:19:52 +00:00
override var mainUrl = "https://nonton.lk21official.wiki"
private var seriesUrl = "https://tv.nontondrama.lol"
2022-09-09 16:09:54 +00:00
override var name = "LayarKaca"
override val hasMainPage = true
override var lang = "id"
override val hasDownloadSupport = true
override val supportedTypes = setOf(
TvType.Movie,
TvType.TvSeries,
TvType.AsianDrama
)
2023-03-11 20:39:22 +00:00
companion object {
const val filemoon = "https://filemoon.sx"
const val streamhide = "https://streamhide.to"
}
2022-09-09 16:09:54 +00:00
override val mainPage = mainPageOf(
"$mainUrl/populer/page/" to "Film Terplopuler",
"$mainUrl/rating/page/" to "Film Berdasarkan IMDb Rating",
"$mainUrl/most-commented/page/" to "Film Dengan Komentar Terbanyak",
"$seriesUrl/latest/page/" to "Series Terbaru",
"$seriesUrl/series/asian/page/" to "Film Asian Terbaru",
2022-09-09 16:09:54 +00:00
"$mainUrl/latest/page/" to "Film Upload Terbaru",
)
override suspend fun getMainPage(
page: Int,
request: MainPageRequest
): HomePageResponse {
2023-02-06 13:11:48 +00:00
val res = app.get(request.data + page)
val baseUrl = getBaseUrl(res.url)
when {
request.data.startsWith(mainUrl) -> {
mainUrl = baseUrl
}
request.data.startsWith(seriesUrl) -> {
seriesUrl = baseUrl
}
}
val document = res.document
2022-09-09 16:09:54 +00:00
val home = document.select("article.mega-item").mapNotNull {
it.toSearchResult()
}
return newHomePageResponse(request.name, home)
}
2022-09-24 09:11:36 +00:00
private fun getProperLink(str: String, check: String): String {
return if (check.contains("/series", true) || check.contains("Season", true)) {
str.replace(mainUrl, seriesUrl)
} else {
str
}
}
2022-09-09 16:09:54 +00:00
private fun Element.toSearchResult(): SearchResponse? {
val title = this.selectFirst("h1.grid-title > a")?.ownText()?.trim() ?: return null
2022-11-26 13:06:38 +00:00
val href = getProperLink(this.selectFirst("a")!!.attr("href"), title)
2022-09-09 16:09:54 +00:00
val posterUrl = fixUrlNull(this.selectFirst(".grid-poster > a > img")?.attr("src"))
val type =
if (this.selectFirst("div.last-episode") == null) TvType.Movie else TvType.TvSeries
return if (type == TvType.TvSeries) {
val episode = this.selectFirst("div.last-episode span")?.text()?.filter { it.isDigit() }
?.toIntOrNull()
newAnimeSearchResponse(title, href, TvType.TvSeries) {
this.posterUrl = posterUrl
addSub(episode)
}
} else {
val quality = this.select("div.quality").text().trim()
newMovieSearchResponse(title, href, TvType.Movie) {
this.posterUrl = posterUrl
addQuality(quality)
}
2022-09-09 16:09:54 +00:00
}
}
override suspend fun search(query: String): List<SearchResponse> {
2023-03-11 19:20:52 +00:00
val req = app.get("$mainUrl/?s=$query")
mainUrl = getBaseUrl(req.url)
val document = req.document
2022-09-09 16:09:54 +00:00
return document.select("div.search-item").map {
val title = it.selectFirst("h2 > a")!!.text().trim()
2022-09-24 09:11:36 +00:00
val type = it.selectFirst("p.cat-links a")?.attr("href").toString()
val href = getProperLink(it.selectFirst("a")!!.attr("href"), type)
2022-09-09 16:09:54 +00:00
val posterUrl = fixUrl(it.selectFirst("img.img-thumbnail")?.attr("src").toString())
newTvSeriesSearchResponse(title, href, TvType.TvSeries) {
this.posterUrl = posterUrl
}
}
}
override suspend fun load(url: String): LoadResponse {
val document = app.get(url).document
val title = document.selectFirst("li.last > span[itemprop=name]")?.text()?.trim().toString()
val poster = fixUrl(document.select("img.img-thumbnail").attr("src").toString())
val tags = document.select("div.content > div:nth-child(5) > h3 > a").map { it.text() }
val year = Regex("\\d, (\\d+)").find(
document.select("div.content > div:nth-child(7) > h3").text().trim()
)?.groupValues?.get(1).toString().toIntOrNull()
val tvType = if (document.select("div.serial-wrapper")
.isNotEmpty()
) TvType.TvSeries else TvType.Movie
val description = document.select("div.content > blockquote").text().trim()
val trailer = document.selectFirst("div.action-player li > a.fancybox")?.attr("href")
val rating =
document.selectFirst("div.content > div:nth-child(6) > h3")?.text()?.toRatingInt()
val actors =
document.select("div.col-xs-9.content > div:nth-child(3) > h3 > a").map { it.text() }
val recommendations = document.select("div.row.item-media").map {
val recName = it.selectFirst("h3")?.text()?.trim().toString()
val recHref = it.selectFirst(".content-media > a")!!.attr("href")
val recPosterUrl =
fixUrl(it.selectFirst(".poster-media > a > img")?.attr("src").toString())
newTvSeriesSearchResponse(recName, recHref, TvType.TvSeries) {
this.posterUrl = recPosterUrl
}
}
return if (tvType == TvType.TvSeries) {
val episodes = document.select("div.episode-list > a:matches(\\d+)").map {
2022-11-26 13:06:38 +00:00
val href = fixUrl(it.attr("href"))
2022-09-09 16:09:54 +00:00
val episode = it.text().toIntOrNull()
val season =
it.attr("href").substringAfter("season-").substringBefore("-").toIntOrNull()
Episode(
href,
"Episode $episode",
season,
episode,
)
}.reversed()
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 {
val document = app.get(data).document
document.select("ul#loadProviders > li").map {
fixUrl(it.select("a").attr("href"))
}.apmap {
2023-01-24 03:41:12 +00:00
val link = when {
it.startsWith("https://layarkacaxxi.icu") -> {
it.substringBeforeLast("/")
}
it.startsWith("https://bananalicious.xyz") -> decode(it.substringAfter("url="))
else -> {
it
}
2022-09-09 16:09:54 +00:00
}
2023-03-11 20:39:22 +00:00
if(link.startsWith(filemoon) || link.startsWith(streamhide)) {
invokeBackup(link, callback)
} else {
loadExtractor(link, data, subtitleCallback, callback)
}
2022-09-09 16:09:54 +00:00
}
return true
}
2023-03-11 20:39:22 +00:00
private suspend fun invokeBackup(
url: String,
callback: (ExtractorLink) -> Unit
) {
val response = app.get(url).document
response.select("script[type=text/javascript]").map { script ->
if (script.data().contains(Regex("eval\\(function\\(p,a,c,k,e,[rd]"))) {
val unpackedscript = getAndUnpack(script.data())
val m3u8Regex = Regex("file.\"(.*?m3u8.*?)\"")
val m3u8 = m3u8Regex.find(unpackedscript)?.destructured?.component1() ?: ""
if (m3u8.isNotEmpty()) {
M3u8Helper.generateM3u8(
fixTitle(URI(url).host).substringBefore("."),
m3u8,
mainUrl
).forEach(callback)
}
}
}
}
2023-02-06 13:11:48 +00:00
private fun getBaseUrl(url: String): String {
return URI(url).let {
"${it.scheme}://${it.host}"
}
}
2023-01-24 03:41:12 +00:00
private fun decode(input: String): String = URLDecoder.decode(input, "utf-8").replace(" ", "%20")
2022-09-09 16:09:54 +00:00
}