EternalMangas: Fix search and filter tab (#6743)

fix search
This commit is contained in:
bapeey 2024-12-22 00:28:11 -05:00 committed by Draff
parent a383626ae6
commit d89120eb49
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
3 changed files with 32 additions and 38 deletions

View File

@ -46,6 +46,8 @@ abstract class MangaEsp(
protected open val seriesPath = "/ver" protected open val seriesPath = "/ver"
protected open val useApiSearch = false
override val client: OkHttpClient = network.client.newBuilder() override val client: OkHttpClient = network.client.newBuilder()
.rateLimitHost(baseUrl.toHttpUrl(), 2) .rateLimitHost(baseUrl.toHttpUrl(), 2)
.build() .build()
@ -62,7 +64,9 @@ abstract class MangaEsp(
val topWeekly = responseData.response.topWeekly.flatten().map { it.data } val topWeekly = responseData.response.topWeekly.flatten().map { it.data }
val topMonthly = responseData.response.topMonthly.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) return MangasPage(mangas, false)
} }
@ -72,7 +76,9 @@ abstract class MangaEsp(
override fun latestUpdatesParse(response: Response): MangasPage { override fun latestUpdatesParse(response: Response): MangasPage {
val responseData = json.decodeFromString<LastUpdatesDto>(response.body.string()) val responseData = json.decodeFromString<LastUpdatesDto>(response.body.string())
val mangas = responseData.response.map { it.toSManga(seriesPath) } val mangas = responseData.response
.additionalParse()
.map { it.toSManga(seriesPath) }
return MangasPage(mangas, false) 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() override fun searchMangaParse(response: Response): MangasPage = throw UnsupportedOperationException()
protected open fun searchMangaParse(response: Response, page: Int, query: String, filters: FilterList): MangasPage { protected open fun searchMangaParse(response: Response, page: Int, query: String, filters: FilterList): MangasPage {
val document = response.asJsoup() comicsList = if (useApiSearch) {
val script = document.select("script:containsData(self.__next_f.push)").joinToString { it.data() } json.decodeFromString<List<SeriesDto>>(response.body.string()).toMutableList()
val jsonString = MANGA_LIST_REGEX.find(script)?.groupValues?.get(1) } else {
?: throw Exception(intl["comics_list_error"]) val script = response.asJsoup().select("script:containsData(self.__next_f.push)").joinToString { it.data() }
val unescapedJson = jsonString.unescape() val jsonString = MANGA_LIST_REGEX.find(script)?.groupValues?.get(1)
comicsList = json.decodeFromString<List<SeriesDto>>(unescapedJson).toMutableList() ?: throw Exception(intl["comics_list_error"])
val unescapedJson = jsonString.unescape()
json.decodeFromString<List<SeriesDto>>(unescapedJson).toMutableList()
}.additionalParse().toMutableList()
return parseComicsList(page, query, filters) return parseComicsList(page, query, filters)
} }
protected open fun List<SeriesDto>.additionalParse(): List<SeriesDto> {
return this
}
private var filteredList = mutableListOf<SeriesDto>() private var filteredList = mutableListOf<SeriesDto>()
protected open fun parseComicsList(page: Int, query: String, filterList: FilterList): MangasPage { protected open fun parseComicsList(page: Int, query: String, filterList: FilterList): MangasPage {

View File

@ -3,7 +3,7 @@ ext {
extClass = '.EternalMangasFactory' extClass = '.EternalMangasFactory'
themePkg = 'mangaesp' themePkg = 'mangaesp'
baseUrl = 'https://eternalmangas.com' baseUrl = 'https://eternalmangas.com'
overrideVersionCode = 1 overrideVersionCode = 2
isNsfw = true isNsfw = true
} }

View File

@ -2,14 +2,11 @@ package eu.kanade.tachiyomi.extension.all.eternalmangas
import eu.kanade.tachiyomi.multisrc.mangaesp.MangaEsp import eu.kanade.tachiyomi.multisrc.mangaesp.MangaEsp
import eu.kanade.tachiyomi.multisrc.mangaesp.SeriesDto import eu.kanade.tachiyomi.multisrc.mangaesp.SeriesDto
import eu.kanade.tachiyomi.multisrc.mangaesp.TopSeriesDto
import eu.kanade.tachiyomi.network.POST 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.MangasPage
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.util.asJsoup
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString import kotlinx.serialization.decodeFromString
import okhttp3.FormBody import okhttp3.FormBody
@ -27,21 +24,7 @@ open class EternalMangas(
"https://eternalmangas.com", "https://eternalmangas.com",
lang, lang,
) { ) {
override val useApiSearch = true
override fun popularMangaParse(response: Response): MangasPage {
val body = response.body.string()
val responseData = json.decodeFromString<TopSeriesDto>(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 fun latestUpdatesParse(response: Response): MangasPage { override fun latestUpdatesParse(response: Response): MangasPage {
val responseData = json.decodeFromString<LatestUpdatesDto>(response.body.string()) val responseData = json.decodeFromString<LatestUpdatesDto>(response.body.string())
@ -49,16 +32,8 @@ open class EternalMangas(
return MangasPage(mangas, false) return MangasPage(mangas, false)
} }
override fun searchMangaParse(response: Response, page: Int, query: String, filters: FilterList): MangasPage { override fun List<SeriesDto>.additionalParse(): List<SeriesDto> {
val document = response.asJsoup() return this.filter { it.language == internalLang }.toMutableList()
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<List<SeriesDto>>(unescapedJson)
.filter { it.language == internalLang }
.toMutableList()
return parseComicsList(page, query, filters)
} }
override fun mangaDetailsParse(response: Response) = SManga.create().apply { override fun mangaDetailsParse(response: Response) = SManga.create().apply {