MangaDex - tweak group search (#3135)

This commit is contained in:
Mike 2020-05-12 18:00:12 -04:00 committed by GitHub
parent 27252e718f
commit ff800f6fea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 18 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: MangaDex' appName = 'Tachiyomi: MangaDex'
pkgNameSuffix = 'all.mangadex' pkgNameSuffix = 'all.mangadex'
extClass = '.MangadexFactory' extClass = '.MangadexFactory'
extVersionCode = 89 extVersionCode = 90
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -206,9 +206,10 @@ abstract class Mangadex(
return clientBuilder() return clientBuilder()
} }
private var groupSearch = "" private var groupSearch: String? = null
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
if (page == 1) groupSearch = null
val genresToInclude = mutableListOf<String>() val genresToInclude = mutableListOf<String>()
val genresToExclude = mutableListOf<String>() val genresToExclude = mutableListOf<String>()
@ -302,8 +303,8 @@ abstract class Mangadex(
is ScanGroup -> { is ScanGroup -> {
groupSearch = when { groupSearch = when {
filter.state.isNotEmpty() && page == 1 -> "$baseUrl/groups/0/1/${filter.state}" filter.state.isNotEmpty() && page == 1 -> "$baseUrl/groups/0/1/${filter.state}"
filter.state.isNotEmpty() && page > 1 -> groupSearch.dropLast(1) + page filter.state.isNotEmpty() && page > 1 -> "${groupSearch!!}/$page"
else -> "" else -> null
} }
} }
} }
@ -318,23 +319,17 @@ abstract class Mangadex(
urlToUse += "&tags_exc=" + genresToExclude.joinToString(",") urlToUse += "&tags_exc=" + genresToExclude.joinToString(",")
} }
return if (groupSearch.isNotEmpty()) { return GET(groupSearch ?: urlToUse, headersBuilder().build(), CacheControl.FORCE_NETWORK)
GET(groupSearch, headersBuilder().build(), CacheControl.FORCE_NETWORK)
} else {
GET(urlToUse, headersBuilder().build(), CacheControl.FORCE_NETWORK)
}
} }
override fun searchMangaParse(response: Response): MangasPage { override fun searchMangaParse(response: Response): MangasPage {
if (response.request().url().toString().contains("/groups/")) { return if (response.request().url().toString().contains("/groups/")) {
response.asJsoup().select(".table > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2) > a:nth-child(1)").attr("abs:href").let { response.asJsoup().select(".table > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2) > a").firstOrNull()?.attr("abs:href")
return if (it.isNotEmpty()) { ?.let {
groupSearch = "$it/manga/0/1" groupSearch = "$it/manga/0"
super.searchMangaParse(client.newCall(GET(groupSearch, headersBuilder().build())).execute()) super.searchMangaParse(client.newCall(GET(groupSearch!!, headersBuilder().build())).execute())
} else {
MangasPage(emptyList(), false)
}
} }
?: MangasPage(emptyList(), false)
} else { } else {
val document = response.asJsoup() val document = response.asJsoup()
if (document.select("#login_button").isNotEmpty()) throw Exception("Log in via WebView to enable search") if (document.select("#login_button").isNotEmpty()) throw Exception("Log in via WebView to enable search")
@ -347,7 +342,7 @@ abstract class Mangadex(
document.select(selector).first() document.select(selector).first()
} != null } != null
return MangasPage(mangas, hasNextPage) MangasPage(mangas, hasNextPage)
} }
} }