From 3123795f2d878f5c586e241eda507f667fcb2179 Mon Sep 17 00:00:00 2001 From: Secozzi <49240133+Secozzi@users.noreply.github.com> Date: Thu, 21 Dec 2023 12:53:56 +0000 Subject: [PATCH] Manga1s: fix images & add paging, genre filter (#19356) * cleanup: fix thumbnails & pages, and add ratelimit + paging * add genre filter * bump version --- src/en/manga1s/build.gradle | 2 +- .../tachiyomi/extension/en/manga1s/manga1s.kt | 112 ++++++++++++++++-- 2 files changed, 104 insertions(+), 10 deletions(-) diff --git a/src/en/manga1s/build.gradle b/src/en/manga1s/build.gradle index a1fb8c71c..1c3965b8e 100644 --- a/src/en/manga1s/build.gradle +++ b/src/en/manga1s/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Manga1s' pkgNameSuffix = 'en.manga1s' extClass = '.manga1s' - extVersionCode = 3 + extVersionCode = 4 isNsfw = true } diff --git a/src/en/manga1s/src/eu/kanade/tachiyomi/extension/en/manga1s/manga1s.kt b/src/en/manga1s/src/eu/kanade/tachiyomi/extension/en/manga1s/manga1s.kt index 17158e907..48e2fdff1 100644 --- a/src/en/manga1s/src/eu/kanade/tachiyomi/extension/en/manga1s/manga1s.kt +++ b/src/en/manga1s/src/eu/kanade/tachiyomi/extension/en/manga1s/manga1s.kt @@ -1,11 +1,14 @@ package eu.kanade.tachiyomi.extension.en.manga1s import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.network.interceptor.rateLimit +import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList 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 okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.OkHttpClient import okhttp3.Request import org.jsoup.nodes.Document @@ -21,11 +24,13 @@ class manga1s : ParsedHttpSource() { override val supportsLatest = true - override val client: OkHttpClient = network.cloudflareClient + override val client: OkHttpClient = network.cloudflareClient.newBuilder() + .rateLimit(2) + .build() // Popular override fun popularMangaRequest(page: Int): Request = - GET("$baseUrl/top-search", headers) + GET("$baseUrl/top-search/$page", headers) override fun popularMangaSelector() = ".novel-wrap" @@ -34,7 +39,7 @@ class manga1s : ParsedHttpSource() { SManga.create().apply { setUrlWithoutDomain(element.select("h2 > a").attr("href")) title = element.select("h2 > a").text() - thumbnail_url = element.select("img").attr("data-src") + thumbnail_url = element.select("img").attr("abs:data-src") } override fun popularMangaNextPageSelector() = @@ -42,7 +47,7 @@ class manga1s : ParsedHttpSource() { // Latest override fun latestUpdatesRequest(page: Int): Request = - GET("$baseUrl/last-update", headers) + GET("$baseUrl/last-update/$page", headers) override fun latestUpdatesSelector() = popularMangaSelector() @@ -54,8 +59,22 @@ class manga1s : ParsedHttpSource() { popularMangaNextPageSelector() // Search - override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request = - GET("$baseUrl/search?q=$query", headers) + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { + val genre = filters.filterIsInstance().first().selected + + val url = baseUrl.toHttpUrl().newBuilder().apply { + if (genre.isNotEmpty()) { + addPathSegment("genre") + addPathSegment(genre) + } else { + addPathSegment("search") + addQueryParameter("q", query) + } + addQueryParameter("p", page.toString()) + }.build() + + return GET(url, headers) + } override fun searchMangaSelector() = popularMangaSelector() @@ -66,6 +85,81 @@ class manga1s : ParsedHttpSource() { override fun searchMangaNextPageSelector() = popularMangaNextPageSelector() + // Genres + abstract class SelectFilter( + name: String, + private val options: List>, + ) : Filter.Select( + name, + options.map { it.first }.toTypedArray(), + ) { + val selected get() = options[state].second + } + + class GenreFilter : SelectFilter("Genre", genres) { + companion object { + private val genres = listOf( + Pair("