[Hentai18VN] Fix attempt 1

master
Draken 1 year ago
parent c1990dde75
commit 2760dc8a76

@ -24,6 +24,10 @@ internal class Hentai18VN(context: MangaLoaderContext) : PagedMangaParser(contex
keys.add(userAgentKey) keys.add(userAgentKey)
} }
override fun getRequestHeaders(): Headers = Headers.Builder()
.add("X-Requested-With", "XMLHttpRequest")
.build()
override val filterCapabilities: MangaListFilterCapabilities override val filterCapabilities: MangaListFilterCapabilities
get() = MangaListFilterCapabilities( get() = MangaListFilterCapabilities(
isSearchSupported = true, isSearchSupported = true,
@ -43,15 +47,16 @@ internal class Hentai18VN(context: MangaLoaderContext) : PagedMangaParser(contex
if (page > 1) { if (page > 1) {
return emptyList() return emptyList()
} }
val url = "https://$domain/search/html/1".toHttpUrl() val url = buildString {
append("http://")
append(domain)
append("/search/html/1")
}.toHttpUrl()
val body = JSONObject().apply { val body = JSONObject().apply {
put("keyword", filter.query.urlEncoded()) put("keyword", filter.query)
} }
val headers = Headers.Builder() val headers = Headers.Builder().add("X-Requested-With", "XMLHttpRequest").build()
.add("X-Requested-With", "XMLHttpRequest")
.build()
val response = webClient.httpPost(url, body, headers).parseHtml() val response = webClient.httpPost(url, body, headers).parseHtml()
parseMangaSearch(response) parseMangaSearch(response)
} }
@ -186,16 +191,6 @@ internal class Hentai18VN(context: MangaLoaderContext) : PagedMangaParser(contex
) )
} }
private fun parseChapterDate(date: String?): Long {
if (date == null) return 0
return try {
val now = SimpleDateFormat("dd/MM/yyyy", Locale.US)
now.parse(date)?.time ?: 0L
} catch (e: Exception) {
0L
}
}
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> { override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
val doc = webClient.httpGet(chapter.url.toAbsoluteUrl(domain)).parseHtml() val doc = webClient.httpGet(chapter.url.toAbsoluteUrl(domain)).parseHtml()
return doc.select("div.chapter-content div.item-photo img").mapNotNull { img -> return doc.select("div.chapter-content div.item-photo img").mapNotNull { img ->
@ -210,34 +205,39 @@ internal class Hentai18VN(context: MangaLoaderContext) : PagedMangaParser(contex
} }
private suspend fun fetchAvailableTags(): Set<MangaTag> { private suspend fun fetchAvailableTags(): Set<MangaTag> {
val tags = arraySetOf<MangaTag>()
val firstPage = webClient.httpGet("https://$domain/tim-the-loai").parseHtml() val firstPage = webClient.httpGet("https://$domain/tim-the-loai").parseHtml()
val lastPage = firstPage.selectFirst("a[aria-label=Last]") val lastPage = firstPage.selectFirst("a[aria-label=Last]")
?.attr("href") ?.attr("href")
?.substringAfter("page=") ?.substringAfter("page=")
?.toIntOrNull() ?: 1 ?.toIntOrNull() ?: 1
for (page in 1..lastPage) { return (1..lastPage).flatMap { page ->
val doc = if (page == 1) { val doc = if (page == 1) {
firstPage firstPage
} else { } else {
webClient.httpGet("https://$domain/tim-the-loai?page=$page").parseHtml() webClient.httpGet("https://$domain/tim-the-loai?page=$page").parseHtml()
} }
doc.select("ul.list-tags li").forEach { li -> doc.select("ul.list-tags li").mapNotNull { li ->
val a = li.selectFirst("a") ?: return@forEach val a = li.selectFirst("a") ?: return@mapNotNull null
val title = a.selectFirst("h3.tag-name")?.text()?.trim() ?: return@forEach val title = a.selectFirst("h3.tag-name")?.text()?.trim() ?: return@mapNotNull null
val url = a.attr("href") val url = a.attr("href")
tags.add( MangaTag(
MangaTag( title = title,
title = title, key = url.substringAfterLast("/"),
key = url.substringAfterLast("/"), source = source
source = source
)
) )
} }
} }.toSet()
}
return tags private fun parseChapterDate(date: String?): Long {
if (date == null) return 0
return try {
val now = SimpleDateFormat("dd/MM/yyyy", Locale.US)
now.parse(date)?.time ?: 0L
} catch (e: Exception) {
0L
}
} }
} }
Loading…
Cancel
Save