Backport E-Hentai fixes from ilwaz/TachiyomiEH (closes #1003) (#1004)

Backport E-Hentai fixes from ilwaz/TachiyomiEH (closes #1003)
This commit is contained in:
Eugene 2019-04-06 10:42:27 -04:00 committed by Carlos
parent d2f0f443bb
commit bf68665bc4
2 changed files with 13 additions and 23 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: E-Hentai' appName = 'Tachiyomi: E-Hentai'
pkgNameSuffix = 'all.ehentai' pkgNameSuffix = 'all.ehentai'
extClass = '.EHJapanese; .EHEnglish; .EHChinese; .EHDutch; .EHFrench; .EHGerman; .EHHungarian; .EHItalian; .EHKorean; .EHPolish; .EHPolish; .EHPortuguese; .EHRussian; .EHSpanish; .EHThai; .EHVietnamese; .EHSpeechless; .EHOther' extClass = '.EHJapanese; .EHEnglish; .EHChinese; .EHDutch; .EHFrench; .EHGerman; .EHHungarian; .EHItalian; .EHKorean; .EHPolish; .EHPolish; .EHPortuguese; .EHRussian; .EHSpanish; .EHThai; .EHVietnamese; .EHSpeechless; .EHOther'
extVersionCode = 3 extVersionCode = 4
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -28,29 +28,19 @@ open class EHentai(override val lang: String, val ehLang: String) : HttpSource()
override val supportsLatest = true override val supportsLatest = true
val initMetaRegex = """inits?~(?:ul\.)?(.*?)~(.*?)~""".toRegex()
fun parseInitsMeta(meta: String): String{
val match = initMetaRegex.find(meta)
return "https://" + match?.groupValues?.get(1) +"/"+ match?.groupValues?.get(2)
}
private fun genericMangaParse(response: Response): MangasPage { private fun genericMangaParse(response: Response): MangasPage {
val doc = response.asJsoup() val doc = response.asJsoup()
val parsedMangas = doc.select("table.itg td.glname").map { val parsedMangas = doc.select("table.itg td.glname").map {
SManga.create().apply { SManga.create().apply {
//Get title //Get title
it.select("a")?.first()?.apply { it.select("a")?.first()?.apply {
title = text() title = this.select(".glink").text()
url = ExGalleryMetadata.normalizeUrl(attr("href")) url = ExGalleryMetadata.normalizeUrl(attr("href"))
} }
//Get image //Get image
it.parent().select(".glthumb")?.first().apply { it.parent().select(".glthumb img")?.first().apply {
thumbnail_url = this!!.select("img").first()?.attr("src")?.nullIfBlank() thumbnail_url = this?.attr("data-src")?.nullIfBlank()
?: parseInitsMeta(it.parent() ?: this?.attr("src")
.select(".glthumb").first()
.childNode(0).toString())
} }
} }
} }
@ -125,7 +115,7 @@ open class EHentai(override val lang: String, val ehLang: String) : HttpSource()
override fun searchMangaParse(response: Response) = genericMangaParse(response) override fun searchMangaParse(response: Response) = genericMangaParse(response)
override fun latestUpdatesParse(response: Response) = genericMangaParse(response) override fun latestUpdatesParse(response: Response) = genericMangaParse(response)
fun exGet(url: String, page: Int? = null, additionalHeaders: Headers? = null, cache: Boolean = true) private fun exGet(url: String, page: Int? = null, additionalHeaders: Headers? = null, cache: Boolean = true)
= GET(page?.let { = GET(page?.let {
addParam(url, "page", (it - 1).toString()) addParam(url, "page", (it - 1).toString())
} ?: url, additionalHeaders?.let { } ?: url, additionalHeaders?.let {
@ -235,7 +225,7 @@ open class EHentai(override val lang: String, val ehLang: String) : HttpSource()
.asObservableSuccess() .asObservableSuccess()
.map { realImageUrlParse(it, page) }!! .map { realImageUrlParse(it, page) }!!
fun realImageUrlParse(response: Response, page: Page) private fun realImageUrlParse(response: Response, page: Page)
= with(response.asJsoup()) { = with(response.asJsoup()) {
val currentImage = getElementById("img").attr("src") val currentImage = getElementById("img").attr("src")
//TODO We cannot currently do this as page.url is immutable //TODO We cannot currently do this as page.url is immutable
@ -249,7 +239,7 @@ open class EHentai(override val lang: String, val ehLang: String) : HttpSource()
override fun imageUrlParse(response: Response) override fun imageUrlParse(response: Response)
= throw UnsupportedOperationException("Unused method was called somehow!") = throw UnsupportedOperationException("Unused method was called somehow!")
val cookiesHeader by lazy { private val cookiesHeader by lazy {
val cookies = mutableMapOf<String, String>() val cookies = mutableMapOf<String, String>()
//Setup settings //Setup settings
@ -272,15 +262,15 @@ open class EHentai(override val lang: String, val ehLang: String) : HttpSource()
override fun headersBuilder() override fun headersBuilder()
= super.headersBuilder().add("Cookie", cookiesHeader)!! = super.headersBuilder().add("Cookie", cookiesHeader)!!
fun buildSettings(settings: List<String?>) private fun buildSettings(settings: List<String?>)
= settings.filterNotNull().joinToString(separator = "-") = settings.filterNotNull().joinToString(separator = "-")
fun buildCookies(cookies: Map<String, String>) private fun buildCookies(cookies: Map<String, String>)
= cookies.entries.map { = cookies.entries.map {
"${URLEncoder.encode(it.key, "UTF-8")}=${URLEncoder.encode(it.value, "UTF-8")}" "${URLEncoder.encode(it.key, "UTF-8")}=${URLEncoder.encode(it.value, "UTF-8")}"
}.joinToString(separator = "; ", postfix = ";") }.joinToString(separator = "; ", postfix = ";")
fun addParam(url: String, param: String, value: String) private fun addParam(url: String, param: String, value: String)
= Uri.parse(url) = Uri.parse(url)
.buildUpon() .buildUpon()
.appendQueryParameter(param, value) .appendQueryParameter(param, value)
@ -357,7 +347,7 @@ open class EHentai(override val lang: String, val ehLang: String) : HttpSource()
)) ))
//map languages to their internal ids //map languages to their internal ids
val languageMappings = listOf( private val languageMappings = listOf(
Pair("japanese", listOf("0", "1024", "2048")), Pair("japanese", listOf("0", "1024", "2048")),
Pair("english", listOf("1", "1025", "2049")), Pair("english", listOf("1", "1025", "2049")),
Pair("chinese", listOf("10", "1034", "2058")), Pair("chinese", listOf("10", "1034", "2058")),
@ -381,4 +371,4 @@ open class EHentai(override val lang: String, val ehLang: String) : HttpSource()
const val QUERY_PREFIX = "?f_apply=Apply+Filter" const val QUERY_PREFIX = "?f_apply=Apply+Filter"
const val TR_SUFFIX = "TR" const val TR_SUFFIX = "TR"
} }
} }