fix Samehadaku

This commit is contained in:
alex 2024-01-06 09:28:31 +07:00
parent 0740da3b1a
commit fd5d4afc22
2 changed files with 67 additions and 63 deletions

View file

@ -1,5 +1,5 @@
// use an integer for version numbers // use an integer for version numbers
version = 19 version = 20
cloudstream { cloudstream {

View file

@ -4,6 +4,7 @@ import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId
import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
import com.lagradost.cloudstream3.network.CloudflareKiller
import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.Qualities import com.lagradost.cloudstream3.utils.Qualities
import com.lagradost.cloudstream3.utils.loadExtractor import com.lagradost.cloudstream3.utils.loadExtractor
@ -16,11 +17,11 @@ class Samehadaku : MainAPI() {
override var lang = "id" override var lang = "id"
override val hasDownloadSupport = true override val hasDownloadSupport = true
override val supportedTypes = setOf( override val supportedTypes = setOf(
TvType.Anime, TvType.Anime,
TvType.AnimeMovie, TvType.AnimeMovie,
TvType.OVA TvType.OVA
) )
private val interceptor = CloudflareKiller()
companion object { companion object {
const val acefile = "https://acefile.co" const val acefile = "https://acefile.co"
@ -40,18 +41,18 @@ class Samehadaku : MainAPI() {
} }
override val mainPage = mainPageOf( override val mainPage = mainPageOf(
"$mainUrl/page/" to "Episode Terbaru", "$mainUrl/page/" to "Episode Terbaru",
"$mainUrl/" to "HomePage", "$mainUrl/" to "HomePage",
) )
override suspend fun getMainPage( override suspend fun getMainPage(
page: Int, page: Int,
request: MainPageRequest request: MainPageRequest
): HomePageResponse { ): HomePageResponse {
val items = mutableListOf<HomePageList>() val items = mutableListOf<HomePageList>()
if (request.name != "Episode Terbaru" && page <= 1) { if (request.name != "Episode Terbaru" && page <= 1) {
val doc = app.get(request.data).document val doc = app.get(request.data, interceptor = interceptor).document
doc.select("div.widget_senction:not(:contains(Baca Komik))").forEach { block -> doc.select("div.widget_senction:not(:contains(Baca Komik))").forEach { block ->
val header = block.selectFirst("div.widget-title h3")?.ownText() ?: return@forEach val header = block.selectFirst("div.widget-title h3")?.ownText() ?: return@forEach
val home = block.select("div.animepost").mapNotNull { val home = block.select("div.animepost").mapNotNull {
@ -62,7 +63,7 @@ class Samehadaku : MainAPI() {
} }
if (request.name == "Episode Terbaru") { if (request.name == "Episode Terbaru") {
val home = app.get(request.data + page).document.selectFirst("div.post-show")?.select("ul li") val home = app.get(request.data + page, interceptor = interceptor).document.selectFirst("div.post-show")?.select("ul li")
?.mapNotNull { ?.mapNotNull {
it.toSearchResult() it.toSearchResult()
} ?: throw ErrorLoadingException("No Media Found") } ?: throw ErrorLoadingException("No Media Found")
@ -75,19 +76,20 @@ class Samehadaku : MainAPI() {
private fun Element.toSearchResult(): AnimeSearchResponse? { private fun Element.toSearchResult(): AnimeSearchResponse? {
val title = this.selectFirst("div.title, h2.entry-title a, div.lftinfo h2")?.text()?.trim() val title = this.selectFirst("div.title, h2.entry-title a, div.lftinfo h2")?.text()?.trim()
?: return null ?: return null
val href = fixUrlNull(this.selectFirst("a")?.attr("href") ?: return null) val href = fixUrlNull(this.selectFirst("a")?.attr("href") ?: return null)
val posterUrl = fixUrlNull(this.select("img").attr("src")) val posterUrl = fixUrlNull(this.select("img").attr("src"))
val epNum = this.selectFirst("div.dtla author")?.text()?.toIntOrNull() val epNum = this.selectFirst("div.dtla author")?.text()?.toIntOrNull()
return newAnimeSearchResponse(title, href ?: return null, TvType.Anime) { return newAnimeSearchResponse(title, href ?: return null, TvType.Anime) {
this.posterUrl = posterUrl this.posterUrl = posterUrl
addSub(epNum) addSub(epNum)
posterHeaders = interceptor.getCookieHeaders(mainUrl).toMap()
} }
} }
override suspend fun search(query: String): List<SearchResponse> { override suspend fun search(query: String): List<SearchResponse> {
val document = app.get("$mainUrl/?s=$query").document val document = app.get("$mainUrl/?s=$query", interceptor = interceptor).document
return document.select("main#main div.animepost").mapNotNull { return document.select("main#main div.animepost").mapNotNull {
it.toSearchResult() it.toSearchResult()
} }
@ -97,10 +99,10 @@ class Samehadaku : MainAPI() {
val fixUrl = if (url.contains("/anime/")) { val fixUrl = if (url.contains("/anime/")) {
url url
} else { } else {
app.get(url).document.selectFirst("div.nvs.nvsc a")?.attr("href") app.get(url, interceptor = interceptor).document.selectFirst("div.nvs.nvsc a")?.attr("href")
} }
val document = app.get(fixUrl ?: return null).document val document = app.get(fixUrl ?: return null, interceptor = interceptor).document
val title = document.selectFirst("h1.entry-title")?.text()?.removeBloat() ?: return null val title = document.selectFirst("h1.entry-title")?.text()?.removeBloat() ?: return null
val poster = document.selectFirst("div.thumb > img")?.attr("src") val poster = document.selectFirst("div.thumb > img")?.attr("src")
val tags = document.select("div.genre-info > a").map { it.text() } val tags = document.select("div.genre-info > a").map { it.text() }
@ -108,11 +110,11 @@ class Samehadaku : MainAPI() {
Regex("\\d,\\s(\\d*)").find(it)?.groupValues?.getOrNull(1)?.toIntOrNull() Regex("\\d,\\s(\\d*)").find(it)?.groupValues?.getOrNull(1)?.toIntOrNull()
} }
val status = getStatus( val status = getStatus(
document.selectFirst("div.spe > span:contains(Status)")?.ownText() ?: return null document.selectFirst("div.spe > span:contains(Status)")?.ownText() ?: return null
) )
val type = val type =
getType(document.selectFirst("div.spe > span:contains(Type)")?.ownText()?.trim()?.lowercase() getType(document.selectFirst("div.spe > span:contains(Type)")?.ownText()?.trim()?.lowercase()
?: "tv") ?: "tv")
val rating = document.selectFirst("span.ratingValue")?.text()?.trim()?.toRatingInt() val rating = document.selectFirst("span.ratingValue")?.text()?.trim()?.toRatingInt()
val description = document.select("div.desc p").text().trim() val description = document.select("div.desc p").text().trim()
val trailer = document.selectFirst("div.trailer-anime iframe")?.attr("src") val trailer = document.selectFirst("div.trailer-anime iframe")?.attr("src")
@ -120,7 +122,7 @@ class Samehadaku : MainAPI() {
val episodes = document.select("div.lstepsiode.listeps ul li").mapNotNull { val episodes = document.select("div.lstepsiode.listeps ul li").mapNotNull {
val header = it.selectFirst("span.lchx > a") ?: return@mapNotNull null val header = it.selectFirst("span.lchx > a") ?: return@mapNotNull null
val episode = Regex("Episode\\s?(\\d+)").find(header.text())?.groupValues?.getOrNull(1) val episode = Regex("Episode\\s?(\\d+)").find(header.text())?.groupValues?.getOrNull(1)
?.toIntOrNull() ?.toIntOrNull()
val link = fixUrl(header.attr("href")) val link = fixUrl(header.attr("href"))
Episode(link, episode = episode) Episode(link, episode = episode)
}.reversed() }.reversed()
@ -145,73 +147,75 @@ class Samehadaku : MainAPI() {
this.recommendations = recommendations this.recommendations = recommendations
addMalId(tracker?.malId) addMalId(tracker?.malId)
addAniListId(tracker?.aniId?.toIntOrNull()) addAniListId(tracker?.aniId?.toIntOrNull())
posterHeaders = interceptor.getCookieHeaders(mainUrl).toMap()
} }
} }
override suspend fun loadLinks( override suspend fun loadLinks(
data: String, data: String,
isCasting: Boolean, isCasting: Boolean,
subtitleCallback: (SubtitleFile) -> Unit, subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit callback: (ExtractorLink) -> Unit
): Boolean { ): Boolean {
val document = app.get(data).document val document = app.get(data, interceptor = interceptor).document
argamap( argamap(
{ {
document.select("div#server ul li div").apmap { document.select("div#server ul li div").apmap {
val dataPost = it.attr("data-post") val dataPost = it.attr("data-post")
val dataNume = it.attr("data-nume") val dataNume = it.attr("data-nume")
val dataType = it.attr("data-type") val dataType = it.attr("data-type")
val iframe = app.post( val iframe = app.post(
url = "$mainUrl/wp-admin/admin-ajax.php", url = "$mainUrl/wp-admin/admin-ajax.php",
data = mapOf( data = mapOf(
"action" to "player_ajax", "action" to "player_ajax",
"post" to dataPost, "post" to dataPost,
"nume" to dataNume, "nume" to dataNume,
"type" to dataType "type" to dataType
), ),
referer = data, referer = data,
headers = mapOf("X-Requested-With" to "XMLHttpRequest"), headers = mapOf("X-Requested-With" to "XMLHttpRequest"),
).document.select("iframe").attr("src") interceptor = interceptor
).document.select("iframe").attr("src")
loadFixedExtractor(fixedIframe(iframe), it.text(), "$mainUrl/", subtitleCallback, callback) loadFixedExtractor(fixedIframe(iframe), it.text(), "$mainUrl/", subtitleCallback, callback)
} }
}, },
{ {
document.select("div#downloadb li").map { el -> document.select("div#downloadb li").map { el ->
el.select("a").apmap { el.select("a").apmap {
loadFixedExtractor(fixedIframe(it.attr("href")), el.select("strong").text(), "$mainUrl/", subtitleCallback, callback) loadFixedExtractor(fixedIframe(it.attr("href")), el.select("strong").text(), "$mainUrl/", subtitleCallback, callback)
}
} }
} }
}
) )
return true return true
} }
private suspend fun loadFixedExtractor( private suspend fun loadFixedExtractor(
url: String, url: String,
name: String, name: String,
referer: String? = null, referer: String? = null,
subtitleCallback: (SubtitleFile) -> Unit, subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit callback: (ExtractorLink) -> Unit
) { ) {
loadExtractor(url, referer, subtitleCallback) { link -> loadExtractor(url, referer, subtitleCallback) { link ->
callback.invoke( callback.invoke(
ExtractorLink( ExtractorLink(
link.name, link.name,
link.name, link.name,
link.url, link.url,
link.referer, link.referer,
name.fixQuality(), name.fixQuality(),
link.type, link.type,
link.headers, link.headers,
link.extractorData link.extractorData
) )
) )
} }
} }