E-Hentai - backport changes from AZ, cleanup (#3582)

This commit is contained in:
Mike 2020-06-21 03:17:33 -04:00 committed by GitHub
parent 17e3831deb
commit 2b7d5095c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 39 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: E-Hentai' appName = 'Tachiyomi: E-Hentai'
pkgNameSuffix = 'all.ehentai' pkgNameSuffix = 'all.ehentai'
extClass = '.EHFactory' extClass = '.EHFactory'
extVersionCode = 10 extVersionCode = 11
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.extension.all.ehentai package eu.kanade.tachiyomi.extension.all.ehentai
import android.annotation.SuppressLint
import android.net.Uri import android.net.Uri
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.network.asObservableSuccess
@ -114,26 +115,33 @@ open class EHentai(override val lang: String, private val ehLang: String) : Http
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)
private fun exGet(url: String, page: Int? = null, additionalHeaders: Headers? = null, cache: Boolean = true) = GET(page?.let { private fun exGet(url: String, page: Int? = null, additionalHeaders: Headers? = null, cache: Boolean = true): Request {
addParam(url, "page", (it - 1).toString()) return GET(
} ?: url, additionalHeaders?.let { page?.let {
val headers = headers.newBuilder() addParam(url, "page", (page - 1).toString())
it.toMultimap().forEach { (t, u) -> } ?: url,
u.forEach { string -> additionalHeaders?.let { header ->
headers.add(t, string) val headers = headers.newBuilder()
header.toMultimap().forEach { (t, u) ->
u.forEach {
headers.add(t, it)
}
}
headers.build()
} ?: headers
).let {
if (!cache) {
it.newBuilder().cacheControl(CacheControl.FORCE_NETWORK).build()
} else {
it
} }
} }
headers.build() }
} ?: headers).let {
if (!cache)
it.newBuilder().cacheControl(CacheControl.FORCE_NETWORK).build()
else
it
}!!
/** /**
* Parse gallery page to metadata model * Parse gallery page to metadata model
*/ */
@SuppressLint("DefaultLocale")
override fun mangaDetailsParse(response: Response) = with(response.asJsoup()) { override fun mangaDetailsParse(response: Response) = with(response.asJsoup()) {
with(ExGalleryMetadata()) { with(ExGalleryMetadata()) {
url = response.request().url().encodedPath() url = response.request().url().encodedPath()
@ -235,21 +243,7 @@ open class EHentai(override val lang: String, private val ehLang: String) : Http
override fun pageListParse(response: Response) = throw UnsupportedOperationException("Unused method was called somehow!") override fun pageListParse(response: Response) = throw UnsupportedOperationException("Unused method was called somehow!")
override fun fetchImageUrl(page: Page) = client.newCall(imageUrlRequest(page)) override fun imageUrlParse(response: Response): String = response.asJsoup().select("#img").attr("abs:src")
.asObservableSuccess()
.map { realImageUrlParse(it, page) }!!
private fun realImageUrlParse(response: Response, page: Page) = with(response.asJsoup()) {
val currentImage = getElementById("img").attr("src")
// TODO We cannot currently do this as page.url is immutable
// Each press of the retry button will choose another server
/*select("#loadfail").attr("onclick").nullIfBlank()?.let {
page.url = addParam(page.url, "nl", it.substring(it.indexOf('\'') + 1 until it.lastIndexOf('\'')))
}*/
currentImage
}!!
override fun imageUrlParse(response: Response) = throw UnsupportedOperationException("Unused method was called somehow!")
private val cookiesHeader by lazy { private val cookiesHeader by lazy {
val cookies = mutableMapOf<String, String>() val cookies = mutableMapOf<String, String>()
@ -282,6 +276,7 @@ open class EHentai(override val lang: String, private val ehLang: String) : Http
"${URLEncoder.encode(it.key, "UTF-8")}=${URLEncoder.encode(it.value, "UTF-8")}" "${URLEncoder.encode(it.key, "UTF-8")}=${URLEncoder.encode(it.value, "UTF-8")}"
} }
@Suppress("SameParameterValue")
private fun addParam(url: String, param: String, value: String) = Uri.parse(url) private fun addParam(url: String, param: String, value: String) = Uri.parse(url)
.buildUpon() .buildUpon()
.appendQueryParameter(param, value) .appendQueryParameter(param, value)
@ -340,15 +335,38 @@ open class EHentai(override val lang: String, private val ehLang: String) : Http
} }
} }
class RatingOption : Filter.Select<String>("Minimum Rating", arrayOf( open class PageOption(name: String, private val queryKey: String) : Filter.Text(name), UriFilter {
"Any",
"2 stars",
"3 stars",
"4 stars",
"5 stars"
)), UriFilter {
override fun addToUri(builder: Uri.Builder) { override fun addToUri(builder: Uri.Builder) {
if (state > 0) builder.appendQueryParameter("f_srdd", (state + 1).toString()) if (state.isNotBlank()) {
if (builder.build().getQueryParameters("f_sp").isEmpty()) {
builder.appendQueryParameter("f_sp", "on")
}
builder.appendQueryParameter(queryKey, state.trim())
}
}
}
class MinPagesOption : PageOption("Minimum Pages", "f_spf")
class MaxPagesOption : PageOption("Maximum Pages", "f_spt")
class RatingOption :
Filter.Select<String>(
"Minimum Rating",
arrayOf(
"Any",
"2 stars",
"3 stars",
"4 stars",
"5 stars"
)
),
UriFilter {
override fun addToUri(builder: Uri.Builder) {
if (state > 0) {
builder.appendQueryParameter("f_srdd", (state + 1).toString())
builder.appendQueryParameter("f_sr", "on")
}
} }
} }
@ -362,7 +380,9 @@ open class EHentai(override val lang: String, private val ehLang: String) : Http
AdvancedOption("Search Low-Power Tags", "f_sdt1"), AdvancedOption("Search Low-Power Tags", "f_sdt1"),
AdvancedOption("Search Downvoted Tags", "f_sdt2"), AdvancedOption("Search Downvoted Tags", "f_sdt2"),
AdvancedOption("Show Expunged Galleries", "f_sh"), AdvancedOption("Show Expunged Galleries", "f_sh"),
RatingOption() RatingOption(),
MinPagesOption(),
MaxPagesOption()
)) ))
// map languages to their internal ids // map languages to their internal ids