From 49834e948bbb9f4abb8bf60ab4d385af685043fe Mon Sep 17 00:00:00 2001 From: Arraiment <76941874+Arraiment@users.noreply.github.com> Date: Sat, 14 Aug 2021 17:44:54 +0800 Subject: [PATCH] Fixes and adding filters for Mangaowl (#8556) * Add filtering by number of chapters * Fix search result pagination --- src/en/mangaowl/build.gradle | 2 +- .../extension/en/mangaowl/MangaOwl.kt | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/en/mangaowl/build.gradle b/src/en/mangaowl/build.gradle index 555ed31ef..0d817e49c 100644 --- a/src/en/mangaowl/build.gradle +++ b/src/en/mangaowl/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'MangaOwl' pkgNameSuffix = 'en.mangaowl' extClass = '.MangaOwl' - extVersionCode = 20 + extVersionCode = 21 libVersion = '1.2' } diff --git a/src/en/mangaowl/src/eu/kanade/tachiyomi/extension/en/mangaowl/MangaOwl.kt b/src/en/mangaowl/src/eu/kanade/tachiyomi/extension/en/mangaowl/MangaOwl.kt index 976c5dbb0..6cd94d235 100644 --- a/src/en/mangaowl/src/eu/kanade/tachiyomi/extension/en/mangaowl/MangaOwl.kt +++ b/src/en/mangaowl/src/eu/kanade/tachiyomi/extension/en/mangaowl/MangaOwl.kt @@ -3,13 +3,16 @@ package eu.kanade.tachiyomi.extension.en.mangaowl import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList +import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource +import eu.kanade.tachiyomi.util.asJsoup import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request +import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element import java.text.ParseException @@ -68,6 +71,19 @@ class MangaOwl : ParsedHttpSource() { // Search + // This is necessary because the HTML response does not contain pagination links + override fun searchMangaParse(response: Response): MangasPage { + val document = response.asJsoup() + + val mangas = document.select(searchMangaSelector()).map { element -> + searchMangaFromElement(element) + } + // Max manga in 1 page is 36 + val hasNextPage = document.select(searchMangaSelector()).size == 36 + + return MangasPage(mangas, hasNextPage) + } + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { val url = "$baseUrl/search/$page".toHttpUrlOrNull()!!.newBuilder() url.addQueryParameter("search", query) @@ -83,6 +99,8 @@ class MangaOwl : ParsedHttpSource() { .joinToString(".") { it.uriPart } url.addQueryParameter("genres", genres) } + is MinChapterFilter -> url.addQueryParameter("chapter_from", filter.state) + is MaxChapterFilter -> url.addQueryParameter("chapter_to", filter.state) } } return GET(url.toString(), headers) @@ -92,7 +110,7 @@ class MangaOwl : ParsedHttpSource() { override fun searchMangaFromElement(element: Element): SManga = popularMangaFromElement(element) - override fun searchMangaNextPageSelector() = "div.blog-pagenat-wthree li a:contains(>)" + override fun searchMangaNextPageSelector() = throw UnsupportedOperationException("Not used") // Manga summary page @@ -166,7 +184,11 @@ class MangaOwl : ParsedHttpSource() { SearchFilter(), SortFilter(), StatusFilter(), - GenreFilter(getGenreList()) + GenreFilter(getGenreList()), + Filter.Separator(), + Filter.Header("Only works with text search"), + MinChapterFilter(), + MaxChapterFilter() ) private open class UriPartFilter(displayName: String, val vals: Array>) : @@ -206,6 +228,7 @@ class MangaOwl : ParsedHttpSource() { private class Genre(name: String, val uriPart: String) : Filter.CheckBox(name) private class GenreFilter(genres: List) : Filter.Group("Genres", genres) + private fun getGenreList() = listOf( Genre("4-koma", "89"), Genre("Action", "1"), @@ -315,4 +338,7 @@ class MangaOwl : ParsedHttpSource() { Genre("Yuri", "54"), Genre("Zombies", "108") ) + + private class MinChapterFilter : Filter.Text("Minimum Chapters") + private class MaxChapterFilter : Filter.Text("Maximum Chapters") }