HBrowse - some tweaks (#3961)

This commit is contained in:
Mike 2020-07-31 23:37:56 -04:00 committed by GitHub
parent 2d02b19748
commit 555469d389
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 27 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'HBrowse'
pkgNameSuffix = 'en.hbrowse'
extClass = '.HBrowse'
extVersionCode = 1
extVersionCode = 2
libVersion = '1.2'
}

View File

@ -26,6 +26,10 @@ class HBrowse : ParsedHttpSource() {
override val supportsLatest = true
// Clients
private lateinit var phpSessId: String
private val searchClient = OkHttpClient().newBuilder()
.followRedirects(false)
.cookieJar(CookieJar.NO_COOKIES)
@ -35,8 +39,9 @@ class HBrowse : ParsedHttpSource() {
.followRedirects(false)
.addInterceptor { chain ->
val originalRequest = chain.request()
if (originalRequest.url().toString() == searchUrl) {
val sessionCookie = searchClient.newCall(originalRequest).execute()
when {
originalRequest.url().toString() == searchUrl -> {
phpSessId = searchClient.newCall(originalRequest).execute()
.headers("Set-Cookie")
.firstOrNull { it.contains("PHPSESSID") }
?.toString()
@ -44,13 +49,16 @@ class HBrowse : ParsedHttpSource() {
?: throw IOException("PHPSESSID missing")
val newHeaders = headersBuilder()
.add("Cookie", sessionCookie)
.add("Cookie", phpSessId)
val contentLength = originalRequest.body()!!.contentLength()
searchClient.newCall(GET("$baseUrl/${if (contentLength > 8000) "result" else "search"}/1", newHeaders.build())).execute()
} else {
chain.proceed(originalRequest)
}
originalRequest.url().toString().contains(nextSearchPageUrlRegex) -> {
searchClient.newCall(originalRequest).execute()
}
else -> chain.proceed(originalRequest)
}
}
.build()
@ -67,7 +75,7 @@ class HBrowse : ParsedHttpSource() {
return SManga.create().apply {
element.select("div.thumbDiv a").let {
setUrlWithoutDomain(it.attr("href"))
title = it.attr("title").substringAfter("\'").substringBefore("\'")
title = it.attr("title").substringAfter("\'").substringBeforeLast("\'")
}
thumbnail_url = element.select("img.thumbImg").attr("abs:src")
}
@ -90,10 +98,12 @@ class HBrowse : ParsedHttpSource() {
// Search
private val searchUrl = "$baseUrl/content/process.php"
private val nextSearchPageUrlRegex = Regex("""(/search/|/result/)""")
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
val filterList = if (filters.isEmpty()) getFilterList() else filters
return if (page == 1) {
val rBody = FormBody.Builder().apply {
if (query.isNotBlank()) {
add("type", "search")
@ -105,8 +115,12 @@ class HBrowse : ParsedHttpSource() {
.forEach { filter -> add(filter.formName, filter.formValue()) }
}
}
return POST(searchUrl, headers, rBody.build())
POST(searchUrl, headers, rBody.build())
} else {
val url = "$baseUrl/${if (query.isNotBlank()) "search" else "result"}/$page"
val nextPageHeaders = headersBuilder().add("Cookie", phpSessId).build()
GET(url, nextPageHeaders)
}
}
override fun searchMangaSelector() = "tbody > tr td.browseTitle a"
@ -167,7 +181,10 @@ class HBrowse : ParsedHttpSource() {
// Filters
override fun getFilterList(): FilterList {
return FilterList(advFilterMap.map { AdvancedFilter(getAdvTriStateList(it.key, it.value.split(", "))) })
return FilterList(
listOf(Filter.Header("Can't combine with text search!"), Filter.Separator()) +
advFilterMap.map { AdvancedFilter(getAdvTriStateList(it.key, it.value.split(", "))) }
)
}
private class AdvTriStateFilter(val groupName: String, name: String) : Filter.TriState(name) {