198 lines
7.8 KiB
Kotlin
198 lines
7.8 KiB
Kotlin
package com.hexated
|
|
|
|
import com.lagradost.cloudstream3.*
|
|
import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId
|
|
import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId
|
|
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
|
|
import com.lagradost.cloudstream3.network.CloudflareKiller
|
|
import com.lagradost.cloudstream3.utils.ExtractorLink
|
|
import com.lagradost.cloudstream3.utils.httpsify
|
|
import com.lagradost.cloudstream3.utils.loadExtractor
|
|
import okhttp3.Interceptor
|
|
import okhttp3.Response
|
|
import org.jsoup.Jsoup
|
|
import org.jsoup.nodes.Element
|
|
|
|
class AnimeIndoProvider : MainAPI() {
|
|
override var mainUrl = "https://animeindo.quest"
|
|
override var name = "AnimeIndo"
|
|
override val hasMainPage = true
|
|
override var lang = "id"
|
|
private val cloudflareKiller by lazy { CloudflareKiller() }
|
|
private val interceptor by lazy { CloudflareInterceptor(cloudflareKiller) }
|
|
override val supportedTypes = setOf(
|
|
TvType.Anime,
|
|
TvType.AnimeMovie,
|
|
TvType.OVA
|
|
)
|
|
|
|
class CloudflareInterceptor(private val cloudflareKiller: CloudflareKiller): Interceptor {
|
|
override fun intercept(chain: Interceptor.Chain): Response {
|
|
val request = chain.request()
|
|
val response = chain.proceed(request)
|
|
val doc = Jsoup.parse(response.peekBody(1024 * 1024).string())
|
|
if (doc.select("title").text() == "Just a moment...") {
|
|
return cloudflareKiller.intercept(chain)
|
|
}
|
|
return response
|
|
}
|
|
}
|
|
|
|
companion object {
|
|
fun getType(t: String): TvType {
|
|
return if (t.contains("OVA", true) || t.contains("Special")) TvType.OVA
|
|
else if (t.contains("Movie", true)) TvType.AnimeMovie
|
|
else TvType.Anime
|
|
}
|
|
|
|
fun getStatus(t: String): ShowStatus {
|
|
return when (t) {
|
|
"Finished Airing" -> ShowStatus.Completed
|
|
"Currently Airing" -> ShowStatus.Ongoing
|
|
else -> ShowStatus.Completed
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
override val mainPage = mainPageOf(
|
|
"episode-terbaru" to "Episode Terbaru",
|
|
"ongoing" to "Anime Ongoing",
|
|
"populer" to "Anime Populer",
|
|
"donghua-terbaru" to "Donghua Terbaru",
|
|
)
|
|
|
|
override suspend fun getMainPage(
|
|
page: Int,
|
|
request: MainPageRequest
|
|
): HomePageResponse {
|
|
val url = "$mainUrl/${request.data}/page/$page"
|
|
val document = app.get(url, interceptor = interceptor).document
|
|
val home = document.select("main#main div.animposx").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("-movie")) -> title.substringBefore(
|
|
"-episode"
|
|
)
|
|
|
|
(title.contains("-movie")) -> title.substringBefore("-movie")
|
|
else -> title
|
|
}
|
|
|
|
"$mainUrl/anime/$title"
|
|
}
|
|
}
|
|
|
|
private fun Element.toSearchResult(): AnimeSearchResponse {
|
|
val title = this.selectFirst("div.title, h2.entry-title, h4")?.text()?.trim() ?: ""
|
|
val href = getProperAnimeLink(this.selectFirst("a")!!.attr("href"))
|
|
val posterUrl = fixUrlNull(this.selectFirst("img")?.attr("src"))
|
|
val epNum = this.selectFirst("span.episode")?.ownText()?.replace(Regex("\\D"), "")?.trim()
|
|
?.toIntOrNull()
|
|
return newAnimeSearchResponse(title, href, TvType.Anime) {
|
|
this.posterUrl = posterUrl
|
|
addSub(epNum)
|
|
posterHeaders = cloudflareKiller.getCookieHeaders(mainUrl).toMap()
|
|
}
|
|
|
|
}
|
|
|
|
override suspend fun search(query: String): List<SearchResponse> {
|
|
val anime = mutableListOf<SearchResponse>()
|
|
(1..2).forEach { page ->
|
|
val link = "$mainUrl/page/$page/?s=$query"
|
|
val document = app.get(link, interceptor = interceptor).document
|
|
val media = document.select(".site-main.relat > article").mapNotNull {
|
|
val title = it.selectFirst("div.title > h2")!!.ownText().trim()
|
|
val href = it.selectFirst("a")!!.attr("href")
|
|
val posterUrl = it.selectFirst("img")!!.attr("src").toString()
|
|
val type = getType(it.select("div.type").text().trim())
|
|
newAnimeSearchResponse(title, href, type) {
|
|
this.posterUrl = posterUrl
|
|
posterHeaders = cloudflareKiller.getCookieHeaders(mainUrl).toMap()
|
|
}
|
|
}
|
|
if(media.isNotEmpty()) anime.addAll(media)
|
|
}
|
|
return anime
|
|
}
|
|
|
|
override suspend fun load(url: String): LoadResponse? {
|
|
val document = app.get(url, interceptor = interceptor).document
|
|
|
|
val title = document.selectFirst("h1.entry-title")?.text()?.replace("Subtitle Indonesia", "")
|
|
?.trim() ?: return null
|
|
val poster = document.selectFirst("div.thumb > img[itemprop=image]")?.attr("src")
|
|
val tags = document.select("div.genxed > a").map { it.text() }
|
|
val type = getType(document.selectFirst("div.info-content > div.spe > span:contains(Type:)")?.ownText()
|
|
?.trim()?.lowercase() ?: "tv")
|
|
val year = document.selectFirst("div.info-content > div.spe > span:contains(Released:)")?.ownText()?.let {
|
|
Regex("\\d,\\s(\\d*)").find(it)?.groupValues?.get(1)?.toIntOrNull()
|
|
}
|
|
val status = getStatus(document.selectFirst("div.info-content > div.spe > span:nth-child(1)")!!.ownText().trim())
|
|
val description = document.select("div[itemprop=description] > p").text()
|
|
|
|
val trailer = document.selectFirst("div.player-embed iframe")?.attr("src")
|
|
val episodes = document.select("div.lstepsiode.listeps ul li").mapNotNull {
|
|
val header = it.selectFirst("span.lchx > a") ?: return@mapNotNull null
|
|
val episode = header.text().trim().replace("Episode", "").trim().toIntOrNull()
|
|
val link = fixUrl(header.attr("href"))
|
|
Episode(link, episode = episode)
|
|
}.reversed()
|
|
|
|
val recommendations = document.select("div.relat div.animposx").mapNotNull {
|
|
it.toSearchResult()
|
|
}
|
|
|
|
val tracker = APIHolder.getTracker(listOf(title),TrackerType.getTypes(type),year,true)
|
|
|
|
return newAnimeLoadResponse(title, url, type) {
|
|
engName = title
|
|
posterUrl = tracker?.image ?: poster
|
|
backgroundPosterUrl = tracker?.cover
|
|
this.year = year
|
|
addEpisodes(DubStatus.Subbed, episodes)
|
|
showStatus = status
|
|
plot = description
|
|
this.tags = tags
|
|
this.recommendations = recommendations
|
|
addTrailer(trailer)
|
|
addMalId(tracker?.malId)
|
|
addAniListId(tracker?.aniId?.toIntOrNull())
|
|
posterHeaders = cloudflareKiller.getCookieHeaders(mainUrl).toMap()
|
|
}
|
|
}
|
|
|
|
override suspend fun loadLinks(
|
|
data: String,
|
|
isCasting: Boolean,
|
|
subtitleCallback: (SubtitleFile) -> Unit,
|
|
callback: (ExtractorLink) -> Unit
|
|
): Boolean {
|
|
|
|
val document = app.get(data, interceptor = interceptor).document
|
|
document.select("div.itemleft > .mirror > option").mapNotNull {
|
|
fixUrl(Jsoup.parse(base64Decode(it.attr("value"))).select("iframe").attr("src"))
|
|
}.apmap {
|
|
if (it.startsWith(mainUrl)) {
|
|
app.get(it, referer = "$mainUrl/", interceptor = interceptor).document.select("iframe").attr("src")
|
|
} else {
|
|
it
|
|
}
|
|
}.apmap {
|
|
loadExtractor(httpsify(it), data, subtitleCallback, callback)
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
} |