From 159bee785ab9b3c3fe6f2502741d20d0681513e4 Mon Sep 17 00:00:00 2001 From: KenjieDec <65448230+KenjieDec@users.noreply.github.com> Date: Fri, 9 Aug 2024 12:28:27 +0700 Subject: [PATCH] ManyToon & ManhwaHentaiMe | Fix Next Page Selector (#4500) Fix Next Page Selector - ManyToon: Fix Next Page Selector and Filters - ManwhaHentaiMe: Fix Next Page Selector --- src/en/manhwahentaime/build.gradle | 2 +- .../en/manhwahentaime/ManhwahentaiMe.kt | 61 ++++---- src/en/manytoon/build.gradle | 2 +- .../extension/en/manytoon/ManyToon.kt | 135 +++++++++++++++++- 4 files changed, 168 insertions(+), 32 deletions(-) diff --git a/src/en/manhwahentaime/build.gradle b/src/en/manhwahentaime/build.gradle index 79178a2f3..7c2a385be 100644 --- a/src/en/manhwahentaime/build.gradle +++ b/src/en/manhwahentaime/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.ManhwahentaiMe' themePkg = 'madara' baseUrl = 'https://manhwahentai.me' - overrideVersionCode = 6 + overrideVersionCode = 7 isNsfw = true } diff --git a/src/en/manhwahentaime/src/eu/kanade/tachiyomi/extension/en/manhwahentaime/ManhwahentaiMe.kt b/src/en/manhwahentaime/src/eu/kanade/tachiyomi/extension/en/manhwahentaime/ManhwahentaiMe.kt index 750759c21..8d5408062 100644 --- a/src/en/manhwahentaime/src/eu/kanade/tachiyomi/extension/en/manhwahentaime/ManhwahentaiMe.kt +++ b/src/en/manhwahentaime/src/eu/kanade/tachiyomi/extension/en/manhwahentaime/ManhwahentaiMe.kt @@ -54,43 +54,45 @@ class ManhwahentaiMe : Madara("Manhwahentai.me", "https://manhwahentai.me", "en" } override fun searchRequest(page: Int, query: String, filters: FilterList): Request { - val url = "$baseUrl/${searchPage(page)}".toHttpUrl().newBuilder() - var alr = false - url.addQueryParameter("s", query) - url.addQueryParameter("post_type", "wp-manga") + val url = "$baseUrl/${searchPage(page)}".toHttpUrl().newBuilder().apply { + var alr = false + addQueryParameter("s", query) + addQueryParameter("post_type", "wp-manga") - filters.forEach { filter -> - when (filter) { - is AuthorFilter -> { - if (filter.state.isNotBlank() && !alr) { - url.addPathSegments("manga-author/${filter.state.replace(" ", "-")}") - alr = true + filters.forEach { filter -> + when (filter) { + is AuthorFilter -> { + if (filter.state.isNotBlank() && !alr) { + addPathSegments("manga-author/${filter.state.replace(" ", "-")}") + alr = true + } } - } - is ArtistFilter -> { - if (filter.state.isNotBlank() && !alr) { - url.addQueryParameter("artist", filter.state.replace(" ", "-")) - alr = true + is ArtistFilter -> { + if (filter.state.isNotBlank() && !alr) { + addQueryParameter("artist", filter.state.replace(" ", "-")) + alr = true + } } - } - is YearFilter -> { - if (filter.state.isNotBlank() && !alr) { - url.addPathSegments("webtoon-release/${filter.state}") - alr = true + is YearFilter -> { + if (filter.state.isNotBlank() && !alr) { + addPathSegments("webtoon-release/${filter.state}") + alr = true + } } - } - is OrderByFilter -> { - url.addQueryParameter("m_orderby", filter.toUriPart()) - } - is GenreConditionFilter -> { - val name = filter.toUriPart() - if (name != "all") { - url.addPathSegments("webtoon-genre/$name") + is OrderByFilter -> { + addQueryParameter("m_orderby", filter.toUriPart()) } + is GenreConditionFilter -> { + val name = filter.toUriPart() + if (name != "all" && !alr) { + addPathSegments("webtoon-genre/$name") + } + } + else -> {} } - else -> {} } } + return GET(url.build(), headers) } @@ -163,4 +165,5 @@ class ManhwahentaiMe : Madara("Manhwahentai.me", "https://manhwahentai.me", "en" } override fun searchMangaSelector() = "div.page-item-detail" + override fun popularMangaNextPageSelector() = "a.next" } diff --git a/src/en/manytoon/build.gradle b/src/en/manytoon/build.gradle index c21375c7a..c55904a5f 100644 --- a/src/en/manytoon/build.gradle +++ b/src/en/manytoon/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.ManyToon' themePkg = 'madara' baseUrl = 'https://manytoon.com' - overrideVersionCode = 7 + overrideVersionCode = 8 isNsfw = true } diff --git a/src/en/manytoon/src/eu/kanade/tachiyomi/extension/en/manytoon/ManyToon.kt b/src/en/manytoon/src/eu/kanade/tachiyomi/extension/en/manytoon/ManyToon.kt index 222216423..bc6876ed9 100644 --- a/src/en/manytoon/src/eu/kanade/tachiyomi/extension/en/manytoon/ManyToon.kt +++ b/src/en/manytoon/src/eu/kanade/tachiyomi/extension/en/manytoon/ManyToon.kt @@ -1,9 +1,15 @@ package eu.kanade.tachiyomi.extension.en.manytoon import eu.kanade.tachiyomi.multisrc.madara.Madara +import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST +import eu.kanade.tachiyomi.source.model.Filter +import eu.kanade.tachiyomi.source.model.FilterList +import eu.kanade.tachiyomi.util.asJsoup import okhttp3.FormBody +import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.Request +import org.jsoup.nodes.Document class ManyToon : Madara("ManyToon", "https://manytoon.com", "en") { @@ -11,7 +17,6 @@ class ManyToon : Madara("ManyToon", "https://manytoon.com", "en") { override val useNewChapterEndpoint = false override val sendViewCount = false - override val fetchGenres = false override fun oldXhrChaptersRequest(mangaId: String): Request { val form = FormBody.Builder() @@ -22,5 +27,133 @@ class ManyToon : Madara("ManyToon", "https://manytoon.com", "en") { return POST("$baseUrl/wp-admin/admin-ajax.php", xhrHeaders, form) } + override fun popularMangaRequest(page: Int): Request = + if (useLoadMoreRequest()) { + loadMoreRequest(page, popular = true) + } else { + GET("$baseUrl/$mangaSubString/${searchPage(page)}?m_orderby=trending", headers) + } + + override fun latestUpdatesRequest(page: Int): Request = + if (useLoadMoreRequest()) { + loadMoreRequest(page, popular = false) + } else { + GET("$baseUrl/home/${searchPage(page)}", headers) + } + + override fun searchRequest(page: Int, query: String, filters: FilterList): Request { + val url = baseUrl.toHttpUrl().newBuilder().apply { + var alr = false + addQueryParameter("s", query) + addQueryParameter("post_type", "wp-manga") + + filters.forEach { filter -> + when (filter) { + is AuthorFilter -> { + if (filter.state.isNotBlank() && !alr) { + addPathSegments("manga-author/${filter.state.replace(" ", "-")}") + alr = true + } + } + is ArtistFilter -> { + if (filter.state.isNotBlank() && !alr) { + addQueryParameter("artist", filter.state.replace(" ", "-")) + alr = true + } + } + is YearFilter -> { + if (filter.state.isNotBlank() && !alr) { + addPathSegments("comic-release/${filter.state}") + alr = true + } + } + is OrderByFilter -> { + addQueryParameter("m_orderby", filter.toUriPart()) + } + is GenreConditionFilter -> { + val name = filter.toUriPart() + if (name != "all" && !alr) { + addPathSegments("manga-genre/$name") + alr = true + } + } + else -> {} + } + } + + addPathSegments(searchPage(page)) + } + return GET(url.build(), headers) + } + + override val orderByFilterOptions: Map = mapOf( + intl["order_by_filter_az"] to "alphabet", + intl["order_by_filter_rating"] to "rating", + intl["order_by_filter_trending"] to "trending", + intl["order_by_filter_views"] to "views", + intl["order_by_filter_new"] to "new-manga", + ) + + private var genresList: List> = emptyList() + private var fetchGenresAttempts: Int = 0 + + private fun fetchGenresMe() { + if (fetchGenres && fetchGenresAttempts < 3 && genresList.isEmpty()) { + try { + genresList = client.newCall(genresRequest()).execute() + .use { parseGenresMe(it.asJsoup()) } + } catch (_: Exception) { + } finally { + fetchGenresAttempts++ + } + } + } + + private fun parseGenresMe(document: Document): List> { + return document.selectFirst("div.genres") + ?.select("a") + .orEmpty() + .map { a -> + a.ownText() to + a.attr("href").substringBeforeLast("/").substringAfterLast("/") + }.let { + listOf(("All" to "all")) + it + } + } + + override fun getFilterList(): FilterList { + launchIO { fetchGenresMe() } + + val filters = mutableListOf( + Filter.Header("All filters except the orderby filter are incompatible with each other"), + AuthorFilter(intl["author_filter_title"]), + ArtistFilter(intl["artist_filter_title"]), + YearFilter(intl["year_filter_title"]), + OrderByFilter( + title = intl["order_by_filter_title"], + options = orderByFilterOptions.toList(), + ), + ) + + if (genresList.isNotEmpty()) { + filters += listOf( + Filter.Separator(), + Filter.Header(intl["genre_filter_header"]), + GenreConditionFilter( + title = intl["genre_filter_title"], + options = genresList, + ), + ) + } else if (fetchGenres) { + filters += listOf( + Filter.Separator(), + Filter.Header(intl["genre_missing_warning"]), + ) + } + + return FilterList(filters) + } + override fun searchMangaSelector() = "div.page-item-detail" + override fun popularMangaNextPageSelector() = "a.next" }