Add ability to reverse search result order

Actually activate hath perks
This commit is contained in:
NerdNumber9 2018-07-08 19:44:22 -04:00
parent 43dc12a0f3
commit 6ae90e0a7d
5 changed files with 61 additions and 8 deletions

View File

@ -151,6 +151,8 @@ object PreferenceKeys {
const val eh_sessionCookie = "eh_sessionCookie"
const val eh_hathPerksCookie = "eh_hathPerksCookie"
const val eh_enableExHentai = "enable_exhentai"
const val eh_ts_aspNetCookie = "eh_ts_aspNetCookie"

View File

@ -203,6 +203,7 @@ class PreferencesHelper(val context: Context) {
fun eh_exhSettingsProfile() = rxPrefs.getInteger(Keys.eh_exhSettingsProfile, -1)
fun eh_settingsKey() = rxPrefs.getString(Keys.eh_settingsKey, "")
fun eh_sessionCookie() = rxPrefs.getString(Keys.eh_sessionCookie, "")
fun eh_hathPerksCookies() = rxPrefs.getString(Keys.eh_hathPerksCookie, "")
//Lock
fun eh_lockHash() = rxPrefs.getString(Keys.eh_lock_hash, null)

View File

@ -82,10 +82,18 @@ class EHentai(override val id: Long,
}
})
}
val parsedLocation = HttpUrl.parse(doc.location())
//Add to page if required
val hasNextPage = select("a[onclick=return false]").last()?.let {
it.text() == ">"
} ?: false
val hasNextPage = if(parsedLocation == null
|| !parsedLocation.queryParameterNames().contains(REVERSE_PARAM)) {
select("a[onclick=return false]").last()?.let {
it.text() == ">"
} ?: false
} else {
parsedLocation.queryParameter(REVERSE_PARAM)!!.toBoolean()
}
Pair(parsedMangas, hasNextPage)
}
@ -155,18 +163,47 @@ class EHentai(override val id: Long,
//Support direct URL importing
override fun fetchSearchManga(page: Int, query: String, filters: FilterList) =
urlImportFetchSearchManga(query, {
super.fetchSearchManga(page, query, filters)
searchMangaRequestObservable(page, query, filters).flatMap {
client.newCall(it).asObservableSuccess()
} .map { response ->
searchMangaParse(response)
}
})
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
private fun searchMangaRequestObservable(page: Int, query: String, filters: FilterList): Observable<Request> {
val uri = Uri.parse("$baseUrl$QUERY_PREFIX").buildUpon()
uri.appendQueryParameter("f_search", query)
filters.forEach {
if(it is UriFilter) it.addToUri(uri)
}
return exGet(uri.toString(), page)
val request = exGet(uri.toString(), page)
// Reverse search results on filter
if(filters.any { it is ReverseFilter && it.state }) {
return client.newCall(request)
.asObservableSuccess()
.map {
val doc = it.asJsoup()
val elements = doc.select(".ptt > tbody > tr > td")
val totalElement = elements[elements.size - 2]
val thisPage = totalElement.text().toInt() - (page - 1)
uri.appendQueryParameter(REVERSE_PARAM, (thisPage > 1).toString())
exGet(uri.toString(), thisPage)
}
} else {
return Observable.just(request)
}
}
override fun searchMangaRequest(page: Int, query: String, filters: FilterList)
= throw UnsupportedOperationException()
override fun latestUpdatesRequest(page: Int) = exGet(baseUrl, page)
override fun popularMangaParse(response: Response) = genericMangaParse(response)
@ -349,6 +386,10 @@ class EHentai(override val id: Long,
val sessionCookie = prefs.eh_sessionCookie().getOrDefault()
if(sessionCookie != null)
cookies["s"] = sessionCookie
val hathPerksCookie = prefs.eh_hathPerksCookies().getOrDefault()
if(hathPerksCookie != null)
cookies["hath_perks"] = hathPerksCookie
}
//Session-less list display mode (for users without ExHentai)
@ -386,7 +427,8 @@ class EHentai(override val id: Long,
//Filters
override fun getFilterList() = FilterList(
GenreGroup(),
AdvancedGroup()
AdvancedGroup(),
ReverseFilter()
)
class GenreOption(name: String, val genreId: String): Filter.CheckBox(name, false), UriFilter {
@ -437,6 +479,8 @@ class EHentai(override val id: Long,
RatingOption()
))
class ReverseFilter : Filter.CheckBox("Reverse search results")
override val name = if(exh)
"ExHentai"
else
@ -448,6 +492,7 @@ class EHentai(override val id: Long,
companion object {
val QUERY_PREFIX = "?f_apply=Apply+Filter"
val TR_SUFFIX = "TR"
val REVERSE_PARAM = "TEH_REVERSE"
fun buildCookies(cookies: Map<String, String>)
= cookies.entries.joinToString(separator = "; ") {

View File

@ -224,7 +224,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
retried++
}
toast("Retried $retried failed pages...")
toast("Retrying $retried failed pages...")
}
subscriptions += eh_retry_all_help.clicks().subscribe {

View File

@ -120,11 +120,16 @@ class EHConfigurator {
val sessionCookie = response.headers().toMultimap()["Set-Cookie"]?.find {
it.startsWith("s=")
}?.removePrefix("s=")?.substringBefore(';')
val hathPerksCookie = response.headers().toMultimap()["Set-Cookie"]?.find {
it.startsWith("hath_perks=")
}?.removePrefix("hath_perks=")?.substringBefore(';')
if(keyCookie != null)
prefs.eh_settingsKey().set(keyCookie)
if(sessionCookie != null)
prefs.eh_sessionCookie().set(sessionCookie)
if(hathPerksCookie != null)
prefs.eh_hathPerksCookies().set(hathPerksCookie)
}
companion object {