From 4bd847a509b0fb3329d920b6a2f17abd92c7fcbd Mon Sep 17 00:00:00 2001 From: jopejoe1 <34899572+jopejoe1@users.noreply.github.com> Date: Sat, 8 Jan 2022 03:23:23 +1300 Subject: [PATCH] Bato.to added more filters (#10382) * Added more filters * Update build.gradle * Update BatoTo.kt --- src/all/batoto/build.gradle | 2 +- .../tachiyomi/extension/all/batoto/BatoTo.kt | 61 ++++++++++++++++++- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/all/batoto/build.gradle b/src/all/batoto/build.gradle index 776c32e65..34572d59f 100644 --- a/src/all/batoto/build.gradle +++ b/src/all/batoto/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'Bato.to' pkgNameSuffix = 'all.batoto' extClass = '.BatoToFactory' - extVersionCode = 17 + extVersionCode = 18 isNsfw = true } diff --git a/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoTo.kt b/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoTo.kt index 1bb5b916b..440177ac3 100644 --- a/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoTo.kt +++ b/src/all/batoto/src/eu/kanade/tachiyomi/extension/all/batoto/BatoTo.kt @@ -116,6 +116,8 @@ open class BatoTo( override fun popularMangaNextPageSelector() = latestUpdatesNextPageSelector() override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable { + val utilsFilter = filters.findInstance()!! + val letterFilter = filters.findInstance()!! return when { query.startsWith("ID:") -> { val id = query.substringAfter("ID:") @@ -124,6 +126,13 @@ open class BatoTo( queryIDParse(response, id) } } + query.isNotBlank() && letterFilter.state != 0 -> { + val url = "$baseUrl/search?word=$query&page=$page&mode=letter" + client.newCall(GET(url, headers)).asObservableSuccess() + .map { response -> + queryParse(response) + } + } query.isNotBlank() -> { val url = "$baseUrl/search?word=$query&page=$page" client.newCall(GET(url, headers)).asObservableSuccess() @@ -131,6 +140,13 @@ open class BatoTo( queryParse(response) } } + utilsFilter.state != 0 -> { + val url = "$baseUrl/_utils/comic-list?type=${utilsFilter.selected}" + client.newCall(GET(url, headers)).asObservableSuccess() + .map { response -> + queryUtilsParse(response) + } + } else -> { val sortFilter = filters.findInstance()!! val reverseSortFilter = filters.findInstance()!! @@ -205,6 +221,21 @@ open class BatoTo( return MangasPage(mangas, nextPage) } + private fun queryUtilsParse(response: Response): MangasPage { + val document = response.asJsoup() + val mangas = document.select("tbody > tr") + .map { element -> searchUtilsFromElement(element) } + return MangasPage(mangas, false) + } + + private fun searchUtilsFromElement(element: Element): SManga { + val manga = SManga.create() + manga.setUrlWithoutDomain(element.select("td a").attr("href")) + manga.title = element.select("td a").text().removeEntities() + manga.thumbnail_url = element.select("img").attr("abs:src") + return manga + } + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request = throw UnsupportedOperationException("Not used") override fun searchMangaSelector() = throw UnsupportedOperationException("Not used") override fun searchMangaFromElement(element: Element) = throw UnsupportedOperationException("Not used") @@ -226,7 +257,7 @@ open class BatoTo( manga.artist = infoElement.select("div.attr-item:contains(author) a:last-child").text() manga.status = parseStatus(status) manga.genre = infoElement.select(".attr-item b:contains(genres) + span ").joinToString { it.text() } - manga.description = infoElement.select("div.limit-html").text() + manga.description = infoElement.select("div.limit-html").text() + "\n\n" + infoElement.select(".episode-list > .alert-warning").text() manga.thumbnail_url = document.select("div.attr-cover img") .attr("abs:src") return manga @@ -372,7 +403,7 @@ open class BatoTo( private fun String.removeEntities(): String = Parser.unescapeEntities(this, true) override fun getFilterList() = FilterList( - // LetterFilter(), + LetterFilter(getLetterFilter(), 0), Filter.Header("NOTE: Ignored if using text search!"), Filter.Separator(), SortFilter(getSortFilter(), 5), @@ -383,6 +414,9 @@ open class BatoTo( MinChapterTextFilter(), MaxChapterTextFilter(), ReverseSortFilter(), + Filter.Separator(), + Filter.Header("NOTE: Filters below are incompatible with any other filters!"), + UtilsFilter(getUtilsFilter(), 0), ) class SelectFilterOption(val name: String, val value: String) @@ -417,8 +451,13 @@ open class BatoTo( class MinChapterTextFilter : TextFilter("Min. Chapters") class MaxChapterTextFilter : TextFilter("Max. Chapters") class LangGroupFilter(options: List) : CheckboxGroupFilter("Languages", options) - class LetterFilter(default: Boolean = false) : Filter.CheckBox("Letter matching mode (Slow)", default) + class LetterFilter(options: List, default: Int) : SelectFilter("Letter matching mode (Slow)", options, default) + class UtilsFilter(options: List, default: Int) : SelectFilter("Utils comic list", options, default) + private fun getLetterFilter() = listOf( + SelectFilterOption("Disabled", "disabled"), + SelectFilterOption("Enabled", "enabled"), + ) private fun getSortFilter() = listOf( SelectFilterOption("Z-A", "title"), SelectFilterOption("Last Updated", "update"), @@ -431,6 +470,22 @@ open class BatoTo( SelectFilterOption("Most Views 60 minutes", "views_h"), ) + private fun getUtilsFilter() = listOf( + SelectFilterOption("None", ""), + SelectFilterOption("Comics: I Created", "i-created"), + SelectFilterOption("Comics: I Modified", "i-modified"), + SelectFilterOption("Comics: I Uploaded", "i-uploaded"), + SelectFilterOption("Comics: Authorized to me", "i-authorized"), + SelectFilterOption("Comics: Draft Status", "status-draft"), + SelectFilterOption("Comics: Hidden Status", "status-hidden"), + SelectFilterOption("Ongoing and Not updated in 30-60 days", "not-updated-30-60"), + SelectFilterOption("Ongoing and Not updated in 60-90 days", "not-updated-60-90"), + SelectFilterOption("Ongoing and Not updated in 90-180 days", "not-updated-90-180"), + SelectFilterOption("Ongoing and Not updated in 180-360 days", "not-updated-180-360"), + SelectFilterOption("Ongoing and Not updated in 360-1000 days", "not-updated-360-1000"), + SelectFilterOption("Ongoing and Not updated more than 1000 days", "not-updated-1000"), + ) + private fun getStatusFilter() = listOf( SelectFilterOption("All", ""), SelectFilterOption("Pending", "pending"),