From d89120eb494548f81fe9c7bf92d977d32808fb26 Mon Sep 17 00:00:00 2001 From: bapeey <90949336+bapeey@users.noreply.github.com> Date: Sun, 22 Dec 2024 00:28:11 -0500 Subject: [PATCH] EternalMangas: Fix search and filter tab (#6743) fix search --- .../tachiyomi/multisrc/mangaesp/MangaEsp.kt | 37 ++++++++++++++----- src/all/eternalmangas/build.gradle | 2 +- .../all/eternalmangas/EternalMangas.kt | 31 ++-------------- 3 files changed, 32 insertions(+), 38 deletions(-) diff --git a/lib-multisrc/mangaesp/src/eu/kanade/tachiyomi/multisrc/mangaesp/MangaEsp.kt b/lib-multisrc/mangaesp/src/eu/kanade/tachiyomi/multisrc/mangaesp/MangaEsp.kt index a4907e944..13b6e7793 100644 --- a/lib-multisrc/mangaesp/src/eu/kanade/tachiyomi/multisrc/mangaesp/MangaEsp.kt +++ b/lib-multisrc/mangaesp/src/eu/kanade/tachiyomi/multisrc/mangaesp/MangaEsp.kt @@ -46,6 +46,8 @@ abstract class MangaEsp( protected open val seriesPath = "/ver" + protected open val useApiSearch = false + override val client: OkHttpClient = network.client.newBuilder() .rateLimitHost(baseUrl.toHttpUrl(), 2) .build() @@ -62,7 +64,9 @@ abstract class MangaEsp( val topWeekly = responseData.response.topWeekly.flatten().map { it.data } val topMonthly = responseData.response.topMonthly.flatten().map { it.data } - val mangas = (topDaily + topWeekly + topMonthly).distinctBy { it.slug }.map { it.toSManga(seriesPath) } + val mangas = (topDaily + topWeekly + topMonthly).distinctBy { it.slug } + .additionalParse() + .map { it.toSManga(seriesPath) } return MangasPage(mangas, false) } @@ -72,7 +76,9 @@ abstract class MangaEsp( override fun latestUpdatesParse(response: Response): MangasPage { val responseData = json.decodeFromString(response.body.string()) - val mangas = responseData.response.map { it.toSManga(seriesPath) } + val mangas = responseData.response + .additionalParse() + .map { it.toSManga(seriesPath) } return MangasPage(mangas, false) } @@ -93,20 +99,33 @@ abstract class MangaEsp( } } - override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request = GET("$baseUrl/comics", headers) + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { + return if (useApiSearch) { + GET("$apiBaseUrl$apiPath/comics", headers) + } else { + GET("$baseUrl/comics", headers) + } + } override fun searchMangaParse(response: Response): MangasPage = throw UnsupportedOperationException() protected open fun searchMangaParse(response: Response, page: Int, query: String, filters: FilterList): MangasPage { - val document = response.asJsoup() - val script = document.select("script:containsData(self.__next_f.push)").joinToString { it.data() } - val jsonString = MANGA_LIST_REGEX.find(script)?.groupValues?.get(1) - ?: throw Exception(intl["comics_list_error"]) - val unescapedJson = jsonString.unescape() - comicsList = json.decodeFromString>(unescapedJson).toMutableList() + comicsList = if (useApiSearch) { + json.decodeFromString>(response.body.string()).toMutableList() + } else { + val script = response.asJsoup().select("script:containsData(self.__next_f.push)").joinToString { it.data() } + val jsonString = MANGA_LIST_REGEX.find(script)?.groupValues?.get(1) + ?: throw Exception(intl["comics_list_error"]) + val unescapedJson = jsonString.unescape() + json.decodeFromString>(unescapedJson).toMutableList() + }.additionalParse().toMutableList() return parseComicsList(page, query, filters) } + protected open fun List.additionalParse(): List { + return this + } + private var filteredList = mutableListOf() protected open fun parseComicsList(page: Int, query: String, filterList: FilterList): MangasPage { diff --git a/src/all/eternalmangas/build.gradle b/src/all/eternalmangas/build.gradle index 09deb9071..d826be84f 100644 --- a/src/all/eternalmangas/build.gradle +++ b/src/all/eternalmangas/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.EternalMangasFactory' themePkg = 'mangaesp' baseUrl = 'https://eternalmangas.com' - overrideVersionCode = 1 + overrideVersionCode = 2 isNsfw = true } diff --git a/src/all/eternalmangas/src/eu/kanade/tachiyomi/extension/all/eternalmangas/EternalMangas.kt b/src/all/eternalmangas/src/eu/kanade/tachiyomi/extension/all/eternalmangas/EternalMangas.kt index cd97fba84..f79761e00 100644 --- a/src/all/eternalmangas/src/eu/kanade/tachiyomi/extension/all/eternalmangas/EternalMangas.kt +++ b/src/all/eternalmangas/src/eu/kanade/tachiyomi/extension/all/eternalmangas/EternalMangas.kt @@ -2,14 +2,11 @@ package eu.kanade.tachiyomi.extension.all.eternalmangas import eu.kanade.tachiyomi.multisrc.mangaesp.MangaEsp import eu.kanade.tachiyomi.multisrc.mangaesp.SeriesDto -import eu.kanade.tachiyomi.multisrc.mangaesp.TopSeriesDto import eu.kanade.tachiyomi.network.POST -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.util.asJsoup import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromString import okhttp3.FormBody @@ -27,21 +24,7 @@ open class EternalMangas( "https://eternalmangas.com", lang, ) { - - override fun popularMangaParse(response: Response): MangasPage { - val body = response.body.string() - val responseData = json.decodeFromString(body) - - val topDaily = responseData.response.topDaily.flatten().map { it.data } - val topWeekly = responseData.response.topWeekly.flatten().map { it.data } - val topMonthly = responseData.response.topMonthly.flatten().map { it.data } - - val mangas = (topDaily + topWeekly + topMonthly).distinctBy { it.slug } - .filter { it.language == internalLang } - .map { it.toSManga(seriesPath) } - - return MangasPage(mangas, false) - } + override val useApiSearch = true override fun latestUpdatesParse(response: Response): MangasPage { val responseData = json.decodeFromString(response.body.string()) @@ -49,16 +32,8 @@ open class EternalMangas( return MangasPage(mangas, false) } - override fun searchMangaParse(response: Response, page: Int, query: String, filters: FilterList): MangasPage { - val document = response.asJsoup() - val script = document.select("script:containsData(self.__next_f.push)").joinToString { it.data() } - val jsonString = MANGA_LIST_REGEX.find(script)?.groupValues?.get(1) - ?: throw Exception(intl["comics_list_error"]) - val unescapedJson = jsonString.unescape() - comicsList = json.decodeFromString>(unescapedJson) - .filter { it.language == internalLang } - .toMutableList() - return parseComicsList(page, query, filters) + override fun List.additionalParse(): List { + return this.filter { it.language == internalLang }.toMutableList() } override fun mangaDetailsParse(response: Response) = SManga.create().apply {