From ff800f6fea5a09e5d4813e3079c129f52c65ada9 Mon Sep 17 00:00:00 2001 From: Mike <51273546+SnakeDoc83@users.noreply.github.com> Date: Tue, 12 May 2020 18:00:12 -0400 Subject: [PATCH] MangaDex - tweak group search (#3135) --- src/all/mangadex/build.gradle | 2 +- .../extension/all/mangadex/Mangadex.kt | 29 ++++++++----------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/all/mangadex/build.gradle b/src/all/mangadex/build.gradle index d5517aea2..7f33ebf7b 100644 --- a/src/all/mangadex/build.gradle +++ b/src/all/mangadex/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: MangaDex' pkgNameSuffix = 'all.mangadex' extClass = '.MangadexFactory' - extVersionCode = 89 + extVersionCode = 90 libVersion = '1.2' } diff --git a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt index b6f1a4572..7bed5725c 100644 --- a/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt +++ b/src/all/mangadex/src/eu/kanade/tachiyomi/extension/all/mangadex/Mangadex.kt @@ -206,9 +206,10 @@ abstract class Mangadex( return clientBuilder() } - private var groupSearch = "" + private var groupSearch: String? = null override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { + if (page == 1) groupSearch = null val genresToInclude = mutableListOf() val genresToExclude = mutableListOf() @@ -302,8 +303,8 @@ abstract class Mangadex( is ScanGroup -> { groupSearch = when { filter.state.isNotEmpty() && page == 1 -> "$baseUrl/groups/0/1/${filter.state}" - filter.state.isNotEmpty() && page > 1 -> groupSearch.dropLast(1) + page - else -> "" + filter.state.isNotEmpty() && page > 1 -> "${groupSearch!!}/$page" + else -> null } } } @@ -318,23 +319,17 @@ abstract class Mangadex( urlToUse += "&tags_exc=" + genresToExclude.joinToString(",") } - return if (groupSearch.isNotEmpty()) { - GET(groupSearch, headersBuilder().build(), CacheControl.FORCE_NETWORK) - } else { - GET(urlToUse, headersBuilder().build(), CacheControl.FORCE_NETWORK) - } + return GET(groupSearch ?: urlToUse, headersBuilder().build(), CacheControl.FORCE_NETWORK) } override fun searchMangaParse(response: Response): MangasPage { - 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 { - return if (it.isNotEmpty()) { - groupSearch = "$it/manga/0/1" - super.searchMangaParse(client.newCall(GET(groupSearch, headersBuilder().build())).execute()) - } else { - MangasPage(emptyList(), false) + 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").firstOrNull()?.attr("abs:href") + ?.let { + groupSearch = "$it/manga/0" + super.searchMangaParse(client.newCall(GET(groupSearch!!, headersBuilder().build())).execute()) } - } + ?: MangasPage(emptyList(), false) } else { val document = response.asJsoup() 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() } != null - return MangasPage(mangas, hasNextPage) + MangasPage(mangas, hasNextPage) } }