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

234 lines
8.3 KiB
Kotlin
Raw Normal View History

2022-11-26 09:32:51 +00:00
package com.hexated
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
import com.lagradost.cloudstream3.utils.ExtractorLink
2023-05-27 04:30:27 +00:00
import com.lagradost.cloudstream3.utils.Qualities
2022-11-26 09:32:51 +00:00
import com.lagradost.cloudstream3.utils.loadExtractor
import org.jsoup.nodes.Element
class Samehadaku : MainAPI() {
2023-08-21 17:23:43 +00:00
override var mainUrl = "https://samehadaku.world"
2022-11-26 09:32:51 +00:00
override var name = "Samehadaku"
override val hasMainPage = true
override var lang = "id"
override val hasDownloadSupport = true
override val supportedTypes = setOf(
TvType.Anime,
TvType.AnimeMovie,
TvType.OVA
)
companion object {
2023-05-27 04:30:27 +00:00
const val acefile = "https://acefile.co"
2022-11-26 09:32:51 +00:00
fun getType(t: String): TvType {
return if (t.contains("OVA", true) || t.contains("Special", true)) TvType.OVA
else if (t.contains("Movie", true)) TvType.AnimeMovie
else TvType.Anime
}
fun getStatus(t: String): ShowStatus {
return when (t) {
"Completed" -> ShowStatus.Completed
"Ongoing" -> ShowStatus.Ongoing
else -> ShowStatus.Completed
}
}
}
override val mainPage = mainPageOf(
"$mainUrl/page/" to "Episode Terbaru",
"$mainUrl/" to "HomePage",
)
override suspend fun getMainPage(
page: Int,
request: MainPageRequest
): HomePageResponse {
val items = mutableListOf<HomePageList>()
if (request.name != "Episode Terbaru" && page <= 1) {
2022-12-06 10:32:26 +00:00
val doc = app.get(request.data).document
2023-08-07 14:17:34 +00:00
doc.select("div.widget_senction:not(:contains(Baca Komik))").forEach { block ->
2022-11-26 09:32:51 +00:00
val header = block.selectFirst("div.widget-title h3")?.ownText() ?: return@forEach
val home = block.select("div.animepost").mapNotNull {
it.toSearchResult()
}
if (home.isNotEmpty()) items.add(HomePageList(header, home))
}
}
if (request.name == "Episode Terbaru") {
2022-12-06 10:32:26 +00:00
val home =
app.get(request.data + page).document.selectFirst("div.post-show")?.select("ul li")
2022-11-26 09:32:51 +00:00
?.mapNotNull {
it.toSearchResult()
} ?: throw ErrorLoadingException("No Media Found")
items.add(HomePageList(request.name, home, true))
}
return newHomePageResponse(items)
}
private fun Element.toSearchResult(): AnimeSearchResponse? {
2023-05-27 04:30:27 +00:00
val title = this.selectFirst("div.title, h2.entry-title a, div.lftinfo h2")?.text()?.trim()
?: return null
2022-11-26 09:32:51 +00:00
val href = fixUrlNull(this.selectFirst("a")?.attr("href") ?: return null)
val posterUrl = fixUrlNull(this.select("img").attr("src"))
val epNum = this.selectFirst("div.dtla author")?.text()?.toIntOrNull()
return newAnimeSearchResponse(title, href ?: return null, TvType.Anime) {
this.posterUrl = posterUrl
addSub(epNum)
}
}
override suspend fun search(query: String): List<SearchResponse> {
2022-12-06 10:32:26 +00:00
val document = app.get("$mainUrl/?s=$query").document
2022-11-26 09:32:51 +00:00
return document.select("main#main div.animepost").mapNotNull {
it.toSearchResult()
}
}
override suspend fun load(url: String): LoadResponse? {
val fixUrl = if (url.contains("/anime/")) {
url
} else {
2022-12-06 10:32:26 +00:00
app.get(url).document.selectFirst("div.nvs.nvsc a")?.attr("href")
2022-11-26 09:32:51 +00:00
}
2022-12-06 10:32:26 +00:00
val document = app.get(fixUrl ?: return null).document
2023-01-17 21:27:26 +00:00
val title = document.selectFirst("h1.entry-title")?.text()?.removeBloat() ?: return null
2022-11-26 09:32:51 +00:00
val poster = document.selectFirst("div.thumb > img")?.attr("src")
val tags = document.select("div.genre-info > a").map { it.text() }
2022-12-06 10:32:26 +00:00
val year = document.selectFirst("div.spe > span:contains(Rilis)")?.ownText()?.let {
Regex("\\d,\\s(\\d*)").find(it)?.groupValues?.getOrNull(1)?.toIntOrNull()
2022-12-06 10:32:26 +00:00
}
2023-05-27 04:30:27 +00:00
val status = getStatus(
document.selectFirst("div.spe > span:contains(Status)")?.ownText() ?: return null
)
val type =
document.selectFirst("div.spe > span:contains(Type)")?.ownText()?.trim()?.lowercase()
?: "tv"
2022-11-26 09:32:51 +00:00
val rating = document.selectFirst("span.ratingValue")?.text()?.trim()?.toRatingInt()
val description = document.select("div.desc p").text().trim()
val trailer = document.selectFirst("div.trailer-anime iframe")?.attr("src")
val episodes = document.select("div.lstepsiode.listeps ul li").mapNotNull {
val header = it.selectFirst("span.lchx > a") ?: return@mapNotNull null
2023-05-27 04:30:27 +00:00
val episode = Regex("Episode\\s?(\\d+)").find(header.text())?.groupValues?.getOrNull(1)
?.toIntOrNull()
2022-11-26 09:32:51 +00:00
val link = fixUrl(header.attr("href"))
Episode(link, episode = episode)
}.reversed()
val recommendations = document.select("aside#sidebar ul li").mapNotNull {
it.toSearchResult()
}
return newAnimeLoadResponse(title, url, getType(type)) {
engName = title
posterUrl = poster
2022-11-26 09:32:51 +00:00
this.year = year
addEpisodes(DubStatus.Subbed, episodes)
showStatus = status
this.rating = rating
plot = description
addTrailer(trailer)
this.tags = tags
this.recommendations = recommendations
}
}
override suspend fun loadLinks(
data: String,
isCasting: Boolean,
subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit
): Boolean {
2022-12-06 10:32:26 +00:00
val document = app.get(data).document
2023-05-27 04:30:27 +00:00
argamap(
{
document.select("div#server ul li div").apmap {
val dataPost = it.attr("data-post")
val dataNume = it.attr("data-nume")
val dataType = it.attr("data-type")
val iframe = app.post(
url = "$mainUrl/wp-admin/admin-ajax.php",
data = mapOf(
"action" to "player_ajax",
"post" to dataPost,
"nume" to dataNume,
"type" to dataType
),
referer = data,
headers = mapOf("X-Requested-With" to "XMLHttpRequest")
).document.select("iframe").attr("src")
loadFixedExtractor(fixedIframe(iframe), it.text(), "$mainUrl/", subtitleCallback, callback)
}
},
{
document.select("div#downloadb li").map { el ->
el.select("a").apmap {
loadFixedExtractor(fixedIframe(it.attr("href")), el.select("strong").text(), "$mainUrl/", subtitleCallback, callback)
}
}
}
)
return true
}
private suspend fun loadFixedExtractor(
url: String,
name: String,
referer: String? = null,
subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit
) {
loadExtractor(url, referer, subtitleCallback) { link ->
callback.invoke(
ExtractorLink(
link.name,
link.name,
link.url,
link.referer,
name.fixQuality(),
2023-09-09 12:16:04 +00:00
link.type,
2023-05-27 04:30:27 +00:00
link.headers,
link.extractorData
)
)
2022-11-26 09:32:51 +00:00
}
2023-05-27 04:30:27 +00:00
}
2022-11-26 09:32:51 +00:00
2023-05-27 04:30:27 +00:00
private fun String.fixQuality() : Int {
return when(this) {
"MP4HD" -> Qualities.P720.value
"FULLHD" -> Qualities.P1080.value
else -> this.filter { it.isDigit() }.toIntOrNull() ?: Qualities.Unknown.value
2022-11-26 09:32:51 +00:00
}
}
2023-05-27 04:30:27 +00:00
private fun fixedIframe(url: String): String {
val id = Regex("""(?:/f/|/file/)(\w+)""").find(url)?.groupValues?.getOrNull(1)
return when {
url.startsWith(acefile) -> "${acefile}/player/$id"
else -> fixUrl(url)
}
2023-01-17 21:27:26 +00:00
}
2023-05-27 04:30:27 +00:00
private fun String.removeBloat(): String {
return this.replace(Regex("(Nonton)|(Anime)|(Subtitle\\sIndonesia)"), "").trim()
}
2022-11-26 09:32:51 +00:00
2023-05-27 04:30:27 +00:00
}