Fixes to HentaiHaven

This commit is contained in:
KillerDogeEmpire 2024-02-12 17:30:50 -08:00
parent 8d30295490
commit 18df470197
2 changed files with 128 additions and 184 deletions

View File

@ -6,7 +6,7 @@ cloudstream {
// All of these properties are optional, you can safely remove them // All of these properties are optional, you can safely remove them
description = "" description = ""
authors = listOf("Jace") authors = listOf("Jace, KillerDogeEmpire")
/** /**
* Status int as the following: * Status int as the following:

View File

@ -1,101 +1,99 @@
package com.jacekun package com.jacekun
import android.util.Log
import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonProperty
import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.utils.getQualityFromName import okhttp3.FormBody
import org.jsoup.select.Elements import org.jsoup.nodes.Element
class HentaiHaven : MainAPI() { class HentaiHaven : MainAPI() {
private val globalTvType = TvType.NSFW
override var name = "Hentai Haven"
override var mainUrl = "https://hentaihaven.xxx" override var mainUrl = "https://hentaihaven.xxx"
override val supportedTypes = setOf(TvType.NSFW) override var name = "Hentai Haven"
override val hasDownloadSupport = false override val hasMainPage = true
override val hasMainPage= true override var lang = "en"
override val hasQuickSearch = false override val hasDownloadSupport = true
override val supportedTypes = setOf(
TvType.NSFW)
override val mainPage = mainPageOf(
"?m_orderby=new-manga" to "New",
"?m_orderby=views" to "Most Views",
"?m_orderby=rating" to "Rating",
"?m_orderby=alphabet" to "A-Z",
)
override suspend fun getMainPage( override suspend fun getMainPage(
page: Int, page: Int,
request: MainPageRequest request: MainPageRequest
): HomePageResponse { ): HomePageResponse {
val doc = app.get(mainUrl).document val document = app.get("$mainUrl/page/$page/${request.data}").document
val all = ArrayList<HomePageList>() val home =
document.select("div.page-listing-item div.col-6.col-md-zarat.badge-pos-1").mapNotNull {
doc.getElementsByTag("body").select("div.c-tabs-item") it.toSearchResult()
.select("div.vraven_home_slider").forEach { it2 ->
// Fetch row title
val title = it2?.select("div.home_slider_header")?.text() ?: "Unnamed Row"
// Fetch list of items and map
it2.select("div.page-content-listing div.item.vraven_item.badge-pos-1").let { inner ->
all.add(
HomePageList(
name = title,
list = inner.getResults(this.name),
isHorizontalImages = false
)
)
}
} }
return HomePageResponse(all) return newHomePageResponse(request.name, home)
}
private fun Element.toSearchResult(): AnimeSearchResponse? {
val href = fixUrl(this.selectFirst("a")!!.attr("href"))
val title =
this.selectFirst("h3 a, h5 a")?.text()?.trim() ?: this.selectFirst("a")?.attr("title")
?: return null
val posterUrl = fixUrlNull(this.selectFirst("img")?.attr("src"))
val episode = this.selectFirst("span.chapter.font-meta a")?.text()?.filter { it.isDigit() }
?.toIntOrNull()
return newAnimeSearchResponse(title, href, TvType.Anime) {
this.posterUrl = posterUrl
addSub(episode)
}
} }
override suspend fun search(query: String): List<SearchResponse> { override suspend fun search(query: String): List<SearchResponse> {
val searchUrl = "${mainUrl}/?s=${query}&post_type=wp-manga" val link = "$mainUrl/?s=$query&post_type=wp-manga"
return app.get(searchUrl).document val document = app.get(link).document
.select("div.c-tabs-item div.row.c-tabs-item__content")
.getResults(this.name) return document.select("div.c-tabs-item > div.c-tabs-item__content").mapNotNull {
it.toSearchResult()
}
} }
override suspend fun load(url: String): LoadResponse { override suspend fun load(url: String): LoadResponse? {
//TODO: Load polishing val document = app.get(url).document
val doc = app.get(url).document
//Log.i(this.name, "Result => (url) ${url}")
val poster = doc.select("meta[property=og:image]")
.firstOrNull()?.attr("content")
val title = doc.select("meta[name=title]")
.firstOrNull()?.attr("content")
?.toString() ?: ""
val descript = doc.select("div.description-summary").text()
val body = doc.getElementsByTag("body") val title = document.selectFirst("div.post-title h1")?.text()?.trim() ?: return null
val episodes = body.select("div.page-content-listing.single-page") val poster = document.select("div.summary_image img").attr("src")
.first()?.select("li") val tags = document.select("div.genres-content > a").map { it.text() }
val year = episodes?.last() val description = document.select("div.description-summary p").text().trim()
?.selectFirst("span.chapter-release-date") val trailer = document.selectFirst("a.trailerbutton")?.attr("href")
?.text()?.trim()?.takeLast(4)?.toIntOrNull()
val episodeList = episodes?.mapNotNull { val episodes = document.select("div.listing-chapters_wrap ul li").mapNotNull {
val innerA = it?.selectFirst("a") ?: return@mapNotNull null val name = it.selectFirst("a")?.text() ?: return@mapNotNull null
val eplink = innerA.attr("href") ?: return@mapNotNull null val image = fixUrlNull(it.selectFirst("a img")?.attr("src"))
val epCount = innerA.text().trim().filter { a -> a.isDigit() }.toIntOrNull() val link = fixUrlNull(it.selectFirst("a")?.attr("href")) ?: return@mapNotNull null
val imageEl = innerA.selectFirst("img") Episode(link, name, posterUrl = image)
val epPoster = imageEl?.attr("src") ?: imageEl?.attr("data-src") }.reversed()
Episode(
name = innerA.text(), val recommendations =
data = eplink, document.select("div.row div.col-6.col-md-zarat").mapNotNull {
posterUrl = epPoster, it.toSearchResult()
episode = epCount, }
)
} ?: listOf() return newAnimeLoadResponse(title, url, TvType.NSFW) {
engName = title
posterUrl = poster
addEpisodes(DubStatus.Subbed, episodes)
plot = description
this.tags = tags
this.recommendations = recommendations
addTrailer(trailer)
}
//Log.i(this.name, "Result => (id) ${id}")
return AnimeLoadResponse(
name = title,
url = url,
apiName = this.name,
type = globalTvType,
posterUrl = poster,
year = year,
plot = descript,
episodes = mutableMapOf(
Pair(DubStatus.Subbed, episodeList.reversed())
)
)
} }
override suspend fun loadLinks( override suspend fun loadLinks(
@ -105,120 +103,66 @@ class HentaiHaven : MainAPI() {
callback: (ExtractorLink) -> Unit callback: (ExtractorLink) -> Unit
): Boolean { ): Boolean {
try { val doc = app.get(data).document
Log.i(name, "Loading iframe") val meta = doc.selectFirst("meta[itemprop=thumbnailUrl]")?.attr("content")?.substringAfter("/hh/")?.substringBefore("/") ?: return false
val requestLink = "${mainUrl}/wp-content/plugins/player-logic/api.php" doc.select("div.player_logic_item iframe").attr("src").let { iframe ->
val action = "zarat_get_data_player_ajax" val document = app.get(iframe, referer = data).text
val reA = Regex("(?<=var en =)(.*?)(?=';)", setOf(RegexOption.DOT_MATCHES_ALL)) val en = Regex("var\\sen\\s=\\s'(\\S+)';").find(document)?.groupValues?.getOrNull(1)
val reB = Regex("(?<=var iv =)(.*?)(?=';)", setOf(RegexOption.DOT_MATCHES_ALL)) val iv = Regex("var\\siv\\s=\\s'(\\S+)';").find(document)?.groupValues?.getOrNull(1)
app.get(data).document.selectFirst("div.player_logic_item iframe") val body = FormBody.Builder()
?.attr("src")?.let { epLink -> .addEncoded("action", "zarat_get_data_player_ajax")
.addEncoded("a", "$en")
.addEncoded("b", "$iv")
.build()
Log.i(name, "Loading ep link => $epLink") app.post(
val scrAppGet = app.get(epLink, referer = data) "$mainUrl/wp-content/plugins/player-logic/api.php",
val scrDoc = scrAppGet.document.getElementsByTag("script").toString() // data = mapOf(
//Log.i(name, "Loading scrDoc => (${scrAppGet.code}) $scrDoc") // "action" to "zarat_get_data_player_ajax",
if (scrDoc.isNotBlank()) { // "a" to "$en",
//en // "b" to "$iv"
val a = reA.find(scrDoc)?.groupValues?.getOrNull(1) // ),
?.trim()?.removePrefix("'") ?: "" requestBody = body,
//iv // headers = mapOf("Sec-Fetch-Mode" to "cors")
val b = reB.find(scrDoc)?.groupValues?.getOrNull(1) ).parsedSafe<Response>()?.data?.sources?.map { res ->
?.trim()?.removePrefix("'") ?: "" // M3u8Helper.generateM3u8(
// this.name,
Log.i(name, "a => $a") // res.src ?: return@map null,
Log.i(name, "b => $b") // referer = "$mainUrl/",
// headers = mapOf(
val doc = app.post( // "Origin" to mainUrl,
url = requestLink, // )
headers = mapOf( // ).forEach(callback)
// Pair("mode", "cors"), callback.invoke(
// Pair("Content-Type", "multipart/form-data"), ExtractorLink(
// Pair("Origin", mainUrl), this.name,
// Pair("Host", mainUrl.split("//").last()), this.name,
Pair("User-Agent", USER_AGENT), res.src?.replace("/hh//", "/hh/$meta/") ?: return@map null,
Pair("Sec-Fetch-Mode", "cors") referer = "",
), quality = Qualities.Unknown.value,
data = mapOf( isM3u8 = true
Pair("action", action), )
Pair("a", a), )
Pair("b", b) }
)
)
Log.i(name, "Response (${doc.code}) => ${doc.text}")
//AppUtils.tryParseJson<ResponseJson?>(doc.text)
doc.parsedSafe<ResponseJson>()?.data?.sources?.map { m3src ->
val m3srcFile = m3src.src ?: return@map null
val label = m3src.label ?: ""
Log.i(name, "M3u8 link: $m3srcFile")
callback.invoke(
ExtractorLink(
name = "$name m3u8",
source = "$name m3u8",
url = m3srcFile,
referer = "$mainUrl/",
quality = getQualityFromName(label),
isM3u8 = true
)
)
}
}
}
} catch (e: Exception) {
Log.i(name, "Error => $e")
logError(e)
return false
} }
return true return true
} }
private fun Elements?.getResults(apiName: String): List<AnimeSearchResponse> { data class Response(
return this?.mapNotNull { @JsonProperty("data") val data: Data? = null,
val innerDiv = it.select("div").firstOrNull()
val firstA = innerDiv?.selectFirst("a")
val link = fixUrlNull(firstA?.attr("href")) ?: return@mapNotNull null
val name = firstA?.attr("title") ?: "<No Title>"
val year = innerDiv?.selectFirst("span.c-new-tag")?.selectFirst("a")
?.attr("title")?.takeLast(4)?.toIntOrNull()
val imageDiv = firstA?.selectFirst("img")
var image = imageDiv?.attr("src")
if (image.isNullOrBlank()) {
image = imageDiv?.attr("data-src")
}
val latestEp = innerDiv?.selectFirst("div.list-chapter")
?.selectFirst("div.chapter-item")
?.selectFirst("a")
?.text()
?.filter { a -> a.isDigit() }
?.toIntOrNull() ?: 0
val dubStatus = mutableMapOf(
Pair(DubStatus.Subbed, latestEp)
)
AnimeSearchResponse(
name = name,
url = link,
apiName = apiName,
type = globalTvType,
posterUrl = image,
year = year,
episodes = dubStatus
)
} ?: listOf()
}
private data class ResponseJson(
@JsonProperty("data") val data: ResponseData?
) )
private data class ResponseData(
@JsonProperty("sources") val sources: List<ResponseSources>? = listOf() data class Data(
@JsonProperty("sources") val sources: ArrayList<Sources>? = arrayListOf(),
) )
private data class ResponseSources(
@JsonProperty("src") val src: String?, data class Sources(
@JsonProperty("type") val type: String?, @JsonProperty("src") val src: String? = null,
@JsonProperty("label") val label: String? @JsonProperty("type") val type: String? = null,
@JsonProperty("label") val label: String? = null,
) )
} }