mirror of
https://github.com/Jacekun/cs3xxx-repo.git
synced 2024-08-14 23:57:09 +00:00
Cleanups on Hanime
This commit is contained in:
parent
019a3bcb2c
commit
0dd66ffdea
1 changed files with 49 additions and 20 deletions
|
@ -3,11 +3,13 @@ package com.jacekun
|
||||||
import com.lagradost.cloudstream3.MainAPI
|
import com.lagradost.cloudstream3.MainAPI
|
||||||
import com.lagradost.cloudstream3.TvType
|
import com.lagradost.cloudstream3.TvType
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
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.utils.ExtractorLink
|
import com.lagradost.cloudstream3.utils.ExtractorLink
|
||||||
import com.lagradost.cloudstream3.utils.getQualityFromName
|
import com.lagradost.cloudstream3.utils.getQualityFromName
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
|
import com.lagradost.cloudstream3.network.CloudflareKiller
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
|
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -17,6 +19,16 @@ import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class Hanime : MainAPI() {
|
class Hanime : MainAPI() {
|
||||||
private val globalTvType = TvType.NSFW
|
private val globalTvType = TvType.NSFW
|
||||||
|
private val interceptor = CloudflareKiller()
|
||||||
|
private var globalHeaders = mapOf<String, String>()
|
||||||
|
private val DEV = "DevDebug"
|
||||||
|
|
||||||
|
override var mainUrl = "https://hanime.tv"
|
||||||
|
override var name = "Hanime"
|
||||||
|
override val hasQuickSearch = false
|
||||||
|
override val hasMainPage = true
|
||||||
|
override val hasDownloadSupport = true
|
||||||
|
override val supportedTypes = setOf(TvType.NSFW)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@SuppressLint("SimpleDateFormat")
|
@SuppressLint("SimpleDateFormat")
|
||||||
|
@ -43,13 +55,6 @@ class Hanime : MainAPI() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override var mainUrl = "https://hanime.tv"
|
|
||||||
override var name = "Hanime"
|
|
||||||
override val hasQuickSearch = false
|
|
||||||
override val hasMainPage = true
|
|
||||||
override val hasDownloadSupport = true
|
|
||||||
override val supportedTypes = setOf(TvType.NSFW)
|
|
||||||
|
|
||||||
private data class HpHentaiVideos (
|
private data class HpHentaiVideos (
|
||||||
@JsonProperty("id") val id : Int,
|
@JsonProperty("id") val id : Int,
|
||||||
@JsonProperty("name") val name : String,
|
@JsonProperty("name") val name : String,
|
||||||
|
@ -90,15 +95,18 @@ class Hanime : MainAPI() {
|
||||||
request: MainPageRequest
|
request: MainPageRequest
|
||||||
): HomePageResponse {
|
): HomePageResponse {
|
||||||
|
|
||||||
val data = app.get("https://hanime.tv/").text
|
val requestGet = app.get("https://hanime.tv/")
|
||||||
val jsonText = Regex("""window\.__NUXT__=(.*?);</script>""").find(data)!!.destructured.component1()
|
globalHeaders = requestGet.headers.toMap()
|
||||||
val json = mapper.readValue<HpHanimeHomePage>(jsonText)
|
val data = requestGet.text
|
||||||
|
val jsonText = Regex("""window\.__NUXT__=(.*?);</script>""").find(data)?.destructured?.component1()
|
||||||
val titles = ArrayList<String>()
|
val titles = ArrayList<String>()
|
||||||
val items = ArrayList<HomePageList>()
|
val items = ArrayList<HomePageList>()
|
||||||
|
|
||||||
try {
|
tryParseJson<HpHanimeHomePage?>(jsonText)?.let { json ->
|
||||||
json.state.data.landing.sections.forEach { section ->
|
json.state.data.landing.sections.forEach { section ->
|
||||||
items.add(HomePageList(section.title, (section.hentaiVideoIds.map {
|
items.add(HomePageList(
|
||||||
|
section.title,
|
||||||
|
(section.hentaiVideoIds.map {
|
||||||
val hentai = getHentaiByIdFromList(it, json.state.data.landing.hentaiVideos)!!
|
val hentai = getHentaiByIdFromList(it, json.state.data.landing.hentaiVideos)!!
|
||||||
val title = getTitle(hentai.name)
|
val title = getTitle(hentai.name)
|
||||||
if (!titles.contains(title)) {
|
if (!titles.contains(title)) {
|
||||||
|
@ -117,8 +125,6 @@ class Hanime : MainAPI() {
|
||||||
}
|
}
|
||||||
}).filterNotNull()))
|
}).filterNotNull()))
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (items.size <= 0) throw ErrorLoadingException()
|
if (items.size <= 0) throw ErrorLoadingException()
|
||||||
|
@ -130,20 +136,43 @@ class Hanime : MainAPI() {
|
||||||
@JsonProperty("name") val name : String,
|
@JsonProperty("name") val name : String,
|
||||||
@JsonProperty("slug") val slug : String,
|
@JsonProperty("slug") val slug : String,
|
||||||
@JsonProperty("titles") val titles : List<String>?,
|
@JsonProperty("titles") val titles : List<String>?,
|
||||||
@JsonProperty("cover_url") val coverUrl : String,
|
@JsonProperty("cover_url") val coverUrl : String?,
|
||||||
@JsonProperty("tags") val tags : List<String>,
|
@JsonProperty("tags") val tags : List<String>?,
|
||||||
@JsonProperty("released_at") val releasedAt : Int
|
@JsonProperty("released_at") val releasedAt : Int
|
||||||
)
|
)
|
||||||
|
|
||||||
override suspend fun search(query: String): ArrayList<SearchResponse> {
|
override suspend fun search(query: String): ArrayList<SearchResponse> {
|
||||||
val link = "https://search.htv-services.com/"
|
val link = "https://search.htv-services.com/"
|
||||||
val data = mapOf("search_text" to query, "tags" to listOf<String>(), "tags_mode" to "AND", "brands" to listOf<String>(), "blacklist" to listOf<String>(), "order_by" to "created_at_unix", "ordering" to "desc", "page" to 0)
|
val data = mapOf(
|
||||||
val response = khttp.post(link, json=data).jsonObject.getString("hits").let { mapper.readValue<List<HanimeSearchResult>>(it) }
|
"search_text" to query,
|
||||||
|
"tags" to emptyList<String>(),
|
||||||
|
"tags_mode" to "AND",
|
||||||
|
"brands" to emptyList<String>(),
|
||||||
|
"blacklist" to emptyList<String>(),
|
||||||
|
"order_by" to "created_at_unix",
|
||||||
|
"ordering" to "desc",
|
||||||
|
"page" to 0
|
||||||
|
)
|
||||||
|
val headers = mapOf(
|
||||||
|
Pair("Origin", mainUrl),
|
||||||
|
Pair("Sec-Fetch-Mode", "cors"),
|
||||||
|
Pair("Sec-Fetch-Site", "cross-site"),
|
||||||
|
Pair("TE", "trailers"),
|
||||||
|
Pair("User-Agent", USER_AGENT),
|
||||||
|
)
|
||||||
|
val response = app.post(
|
||||||
|
url = link,
|
||||||
|
json = data,
|
||||||
|
headers = globalHeaders
|
||||||
|
)
|
||||||
|
val responseText = response.text
|
||||||
val titles = ArrayList<String>()
|
val titles = ArrayList<String>()
|
||||||
val searchResults = ArrayList<SearchResponse>()
|
val searchResults = ArrayList<SearchResponse>()
|
||||||
|
|
||||||
response.reversed().forEach {
|
Log.i(DEV, "Response => (${response.code}) ${responseText}")
|
||||||
val title = getTitle(it.name)
|
tryParseJson<List<HanimeSearchResult?>?>(responseText)?.reversed()?.forEach {
|
||||||
|
val rawName = it?.name ?: return@forEach
|
||||||
|
val title = getTitle(rawName)
|
||||||
if (!titles.contains(title)) {
|
if (!titles.contains(title)) {
|
||||||
titles.add(title)
|
titles.add(title)
|
||||||
searchResults.add(
|
searchResults.add(
|
||||||
|
|
Loading…
Reference in a new issue