[ALlHentai] New parser

source/neox^2
Koitharu 3 years ago
parent 96b9ac36f3
commit 20ad9d0472
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -0,0 +1,53 @@
package org.koitharu.kotatsu.parsers.site.grouple
import org.koitharu.kotatsu.parsers.MangaLoaderContext
import org.koitharu.kotatsu.parsers.MangaSourceParser
import org.koitharu.kotatsu.parsers.config.ConfigKey
import org.koitharu.kotatsu.parsers.exception.AuthRequiredException
import org.koitharu.kotatsu.parsers.exception.ParseException
import org.koitharu.kotatsu.parsers.model.MangaChapter
import org.koitharu.kotatsu.parsers.model.MangaPage
import org.koitharu.kotatsu.parsers.model.MangaSource
import org.koitharu.kotatsu.parsers.util.domain
import org.koitharu.kotatsu.parsers.util.parseFailed
import org.koitharu.kotatsu.parsers.util.parseHtml
import org.koitharu.kotatsu.parsers.util.urlEncoded
@MangaSourceParser("ALLHENTAI", "ALlHentai", "ru")
internal class AllHentaiParser(
context: MangaLoaderContext,
) : GroupleParser(context, MangaSource.ALLHENTAI, 1) {
override val configKeyDomain = ConfigKey.Domain(
"2023.allhen.online",
null,
)
override val defaultIsNsfw = true
override val authUrl: String
get() {
val targetUri = "https://${domain}/".urlEncoded()
return "https://qawa.org/internal/auth/login?targetUri=$targetUri&siteId=1"
}
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
try {
return super.getPages(chapter)
} catch (e: ParseException) {
if (isAuthorized) {
throw e
} else {
throw AuthRequiredException(source)
}
}
}
override suspend fun getUsername(): String {
val root = webClient.httpGet("https://qawa.org/").parseHtml().body()
val element = root.selectFirst("img.user-avatar") ?: throw AuthRequiredException(source)
val res = element.parent()?.text()
return if (res.isNullOrEmpty()) {
root.parseFailed("Cannot find username")
} else res
}
}

@ -37,6 +37,7 @@ internal abstract class GroupleParser(
@Volatile @Volatile
private var cachedPagesServer: String? = null private var cachedPagesServer: String? = null
protected open val defaultIsNsfw = false
private val userAgentKey = ConfigKey.UserAgent( private val userAgentKey = ConfigKey.UserAgent(
"Mozilla/5.0 (X11; U; UNICOS lcLinux; en-US) Gecko/20140730 (KHTML, like Gecko, Safari/419.3) Arora/0.8.0", "Mozilla/5.0 (X11; U; UNICOS lcLinux; en-US) Gecko/20140730 (KHTML, like Gecko, Safari/419.3) Arora/0.8.0",
@ -131,7 +132,7 @@ internal abstract class GroupleParser(
?.div(5f) ?.div(5f)
}.getOrNull() ?: RATING_UNKNOWN, }.getOrNull() ?: RATING_UNKNOWN,
author = tileInfo?.selectFirst("a.person-link")?.text(), author = tileInfo?.selectFirst("a.person-link")?.text(),
isNsfw = false, isNsfw = defaultIsNsfw,
tags = runCatching { tags = runCatching {
tileInfo?.select("a.element-link") tileInfo?.select("a.element-link")
?.mapToSet { ?.mapToSet {
@ -173,7 +174,7 @@ internal abstract class GroupleParser(
) )
}, },
author = root.selectFirst("a.person-link")?.text() ?: manga.author, author = root.selectFirst("a.person-link")?.text() ?: manga.author,
isNsfw = root.select(".alert-warning").any { it.ownText().contains(NSFW_ALERT) }, isNsfw = manga.isNsfw || root.select(".alert-warning").any { it.ownText().contains(NSFW_ALERT) },
chapters = root.selectFirst("div.chapters-link")?.selectFirst("table") chapters = root.selectFirst("div.chapters-link")?.selectFirst("table")
?.select("tr:has(td > a)")?.mapChapters(reversed = true) { i, tr -> ?.select("tr:has(td > a)")?.mapChapters(reversed = true) { i, tr ->
val a = tr.selectFirst("a.chapter-link") ?: return@mapChapters null val a = tr.selectFirst("a.chapter-link") ?: return@mapChapters null

Loading…
Cancel
Save