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

299 lines
11 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.addAniListId
import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId
2022-09-09 16:09:54 +00:00
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
2023-03-03 22:37:14 +00:00
import com.lagradost.cloudstream3.extractors.Filesim
2022-09-09 16:09:54 +00:00
import com.lagradost.cloudstream3.utils.*
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import java.util.ArrayList
class OploverzProvider : MainAPI() {
2023-03-03 22:37:14 +00:00
override var mainUrl = "https://oploverz.tv"
2022-09-09 16:09:54 +00:00
override var name = "Oploverz"
override val hasMainPage = true
override var lang = "id"
override val hasDownloadSupport = true
override val supportedTypes = setOf(
TvType.Anime,
TvType.AnimeMovie,
TvType.OVA
)
companion object {
const val acefile = "https://acefile.co"
2023-03-03 22:37:14 +00:00
const val lbx = "https://lbx.to"
const val linkbox = "https://www.linkbox.to"
2022-09-09 16:09:54 +00:00
fun getType(t: String): TvType {
return when {
t.contains("TV") -> TvType.Anime
t.contains("Movie") -> TvType.AnimeMovie
else -> TvType.OVA
}
}
fun getStatus(t: String): ShowStatus {
return when (t) {
"Completed" -> ShowStatus.Completed
"Ongoing" -> ShowStatus.Ongoing
else -> ShowStatus.Completed
}
}
}
override val mainPage = mainPageOf(
"&status=&type=&order=update" to "Episode Terbaru",
"&status=&type=&order=latest" to "Anime Terbaru",
"&sub=&order=popular" to "Popular Anime",
)
override suspend fun getMainPage(
page: Int,
request: MainPageRequest
): HomePageResponse {
val document = app.get("$mainUrl/anime/?page=$page${request.data}").document
val home = document.select("article[itemscope=itemscope]").mapNotNull {
it.toSearchResult()
}
return newHomePageResponse(request.name, home)
}
private fun getProperAnimeLink(uri: String): String {
return if (uri.contains("/anime/")) {
uri
} else {
var title = uri.substringAfter("$mainUrl/")
title = when {
(title.contains("-episode")) && !(title.contains("-ova")) -> Regex("(.+)-episode").find(
title
)?.groupValues?.get(1).toString()
(title.contains("-ova")) -> Regex("(.+)-ova").find(title)?.groupValues?.get(1)
.toString()
(title.contains("-movie")) -> Regex("(.+)-subtitle").find(title)?.groupValues?.get(1)
.toString()
else -> Regex("(.+)-subtitle").find(title)?.groupValues?.get(1).toString()
.replace(Regex("-\\d+"), "")
}
when {
title.contains("overlord") -> {
title = title.replace("s", "season-")
}
title.contains("kaguya-sama") -> {
title = title.replace("s3", "ultra-romantic")
}
}
"$mainUrl/anime/$title"
}
}
private fun Element.toSearchResult(): AnimeSearchResponse? {
val href = getProperAnimeLink(this.selectFirst("a.tip")!!.attr("href"))
val title = this.selectFirst("h2[itemprop=headline]")?.text()?.trim() ?: return null
val posterUrl = fixUrlNull(this.selectFirst("img")?.attr("src"))
val type = getType(this.selectFirst(".eggtype, .typez")?.text()?.trim().toString())
return newAnimeSearchResponse(title, href, type) {
this.posterUrl = posterUrl
}
}
override suspend fun search(query: String): List<SearchResponse> {
val link = "$mainUrl/?s=$query"
val document = app.get(link).document
return document.select("article[itemscope=itemscope]").map {
val title = it.selectFirst(".tt")?.ownText()?.trim().toString()
val poster = fixUrlNull(it.selectFirst("img")?.attr("src"))
val tvType = getType(it.selectFirst(".typez")?.text().toString())
val href = fixUrl(it.selectFirst("a.tip")!!.attr("href"))
newAnimeSearchResponse(title, href, tvType) {
this.posterUrl = poster
addDubStatus(dubExist = false, subExist = true)
}
}
}
override suspend fun load(url: String): LoadResponse {
val document = app.get(url).document
val title = document.selectFirst("h1.entry-title")!!.text().trim()
val poster = document.select(".thumb > img").attr("src")
val tags = document.select(".genxed > a").map { it.text() }
2023-01-31 09:29:53 +00:00
val year = Regex("\\d, (\\d*)").find(
2022-09-09 16:09:54 +00:00
document.selectFirst(".info-content > .spe > span > time")!!.text().trim()
)?.groupValues?.get(1).toString().toIntOrNull()
val status = getStatus(
document.select(".info-content > .spe > span:nth-child(1)")
.text().trim().replace("Status: ", "")
)
val typeCheck =
when (document.select(".info-content > .spe > span:nth-child(5), .info-content > .spe > span")
.text().trim()) {
"OVA" -> "OVA"
"Movie" -> "Movie"
else -> "TV"
}
val type = getType(typeCheck)
val description = document.select(".entry-content > p").text().trim()
val trailer = document.selectFirst("a.trailerbutton")?.attr("href")
2023-01-14 09:40:35 +00:00
val (malId, anilistId, image, cover) = getTracker(title, typeCheck, year)
2022-09-09 16:09:54 +00:00
val episodes = document.select(".eplister > ul > li").map {
val link = fixUrl(it.select("a").attr("href"))
val name = it.select(".epl-title").text()
2023-01-31 09:29:53 +00:00
val episode = Regex("Episode\\s?(\\d+[.,]?\\d*)").find(name)?.groupValues?.getOrNull(1)?.toIntOrNull()
Episode(link, name, episode = episode)
2022-09-09 16:09:54 +00:00
}.reversed()
val recommendations =
document.select(".listupd > article[itemscope=itemscope]").mapNotNull { rec ->
val epTitle = rec.selectFirst(".tt")!!.ownText().trim()
val epPoster = rec.selectFirst("img")!!.attr("src")
val epType = getType(rec.selectFirst(".typez")?.text().toString())
val epHref = fixUrl(rec.selectFirst("a.tip")!!.attr("href"))
newAnimeSearchResponse(epTitle, epHref, epType) {
this.posterUrl = epPoster
addDubStatus(dubExist = false, subExist = true)
}
}
return newAnimeLoadResponse(title, url, type) {
engName = title
2023-01-14 09:40:35 +00:00
posterUrl = image ?: poster
backgroundPosterUrl = cover ?: image ?: poster
2022-09-09 16:09:54 +00:00
this.year = year
addEpisodes(DubStatus.Subbed, episodes)
showStatus = status
plot = description
this.tags = tags
2023-01-14 09:40:35 +00:00
addMalId(malId)
addAniListId(anilistId?.toIntOrNull())
2022-09-09 16:09:54 +00:00
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
val sources = mutableListOf<Pair<String?, String>>()
2022-09-09 16:09:54 +00:00
val streamingSources = document.select(".mobius > .mirror > option").mapNotNull {
"" to fixUrl(Jsoup.parse(base64Decode(it.attr("value"))).select("iframe").attr("src"))
}
if (streamingSources.isNotEmpty()) sources.addAll(streamingSources)
val downloadSources =
2023-03-06 18:14:17 +00:00
document.select("div.mctnx div.soraurlx").mapNotNull { item ->
2023-03-03 22:37:14 +00:00
item.select("a").map { item.select("strong").text() to it.attr("href") }
}.flatten()
if (downloadSources.isNotEmpty()) sources.addAll(downloadSources)
2023-03-03 22:37:14 +00:00
sources.filter { it.second.startsWith("https") }.
apmap { (quality, source) ->
2023-02-24 12:18:52 +00:00
loadExtractor(fixedIframe(source), data, subtitleCallback) { link ->
callback.invoke(
ExtractorLink(
link.name,
link.name,
link.url,
link.referer,
if (source.startsWith(acefile)) getQualityFromName(quality) else link.quality,
link.isM3u8,
link.headers,
link.extractorData
)
2023-02-24 12:18:52 +00:00
)
}
2022-09-09 16:09:54 +00:00
}
return true
}
2023-03-03 22:37:14 +00:00
private suspend fun fixedIframe(url: String): String {
val id = Regex("""(?:/f/|/file/)(\w+)""").find(url)?.groupValues?.getOrNull(1)
2023-02-24 12:18:52 +00:00
return when {
url.startsWith(acefile) -> "$acefile/player/$id"
2023-03-03 22:37:14 +00:00
url.startsWith(lbx) -> {
val itemId = app.get("$linkbox/api/file/share_out_list/?sortField=utime&sortAsc=0&pageNo=1&pageSize=50&shareToken=$id&scene=singleItem&needTpInfo=1&lan=en").parsedSafe<Responses>()?.data?.itemId
"$linkbox/a/f/$itemId"
}
2023-02-24 12:18:52 +00:00
else -> url
}
}
2023-01-14 09:40:35 +00:00
private suspend fun getTracker(title: String?, type: String?, year: Int?): Tracker {
val res = app.get("https://api.consumet.org/meta/anilist/$title")
.parsedSafe<AniSearch>()?.results?.find { media ->
(media.title?.english.equals(title, true) || media.title?.romaji.equals(
title,
true
)) || (media.type.equals(type, true) && media.releaseDate == year)
}
return Tracker(res?.malId, res?.aniId, res?.image, res?.cover)
}
2023-01-14 09:40:35 +00:00
data class Tracker(
val malId: Int? = null,
val aniId: String? = null,
val image: String? = null,
val cover: String? = null,
)
2023-01-14 09:40:35 +00:00
data class Title(
@JsonProperty("romaji") val romaji: String? = null,
@JsonProperty("english") val english: String? = null,
)
2023-01-14 09:40:35 +00:00
data class Results(
@JsonProperty("id") val aniId: String? = null,
@JsonProperty("malId") val malId: Int? = null,
@JsonProperty("title") val title: Title? = null,
@JsonProperty("releaseDate") val releaseDate: Int? = null,
@JsonProperty("type") val type: String? = null,
@JsonProperty("image") val image: String? = null,
@JsonProperty("cover") val cover: String? = null,
)
2023-01-14 09:40:35 +00:00
data class AniSearch(
@JsonProperty("results") val results: ArrayList<Results>? = arrayListOf(),
)
data class RList(
@JsonProperty("url") val url: String,
@JsonProperty("resolution") val resolution: String?,
)
data class Data(
2023-03-03 22:37:14 +00:00
@JsonProperty("rList") val rList: List<RList>? = arrayListOf(),
@JsonProperty("itemId") val itemId: String? = null,
)
data class Responses(
@JsonProperty("data") val data: Data?,
)
2023-03-03 22:37:14 +00:00
}
class Streamhide : Filesim() {
override val mainUrl = "https://streamhide.to"
override val name = "Streamhide"
2022-09-09 16:09:54 +00:00
}