From 47b60ed24db22330a9aa029071cfe7936ccce1a8 Mon Sep 17 00:00:00 2001 From: bapeey <90949336+bapeey@users.noreply.github.com> Date: Fri, 21 Jun 2024 03:46:28 -0500 Subject: [PATCH] ManhwaWeb: Fix chapters not found and webview (#3671) * Fix ManhwaWeb * more fix --- src/es/manhwaweb/build.gradle | 2 +- .../extension/es/manhwaweb/ManhwaWeb.kt | 57 +++---------------- .../extension/es/manhwaweb/ManhwaWebDto.kt | 14 +++-- 3 files changed, 18 insertions(+), 55 deletions(-) diff --git a/src/es/manhwaweb/build.gradle b/src/es/manhwaweb/build.gradle index 76cb0ad6f..af8e3f406 100644 --- a/src/es/manhwaweb/build.gradle +++ b/src/es/manhwaweb/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'ManhwaWeb' extClass = '.ManhwaWeb' - extVersionCode = 2 + extVersionCode = 3 isNsfw = true } diff --git a/src/es/manhwaweb/src/eu/kanade/tachiyomi/extension/es/manhwaweb/ManhwaWeb.kt b/src/es/manhwaweb/src/eu/kanade/tachiyomi/extension/es/manhwaweb/ManhwaWeb.kt index b1863f934..13329e48f 100644 --- a/src/es/manhwaweb/src/eu/kanade/tachiyomi/extension/es/manhwaweb/ManhwaWeb.kt +++ b/src/es/manhwaweb/src/eu/kanade/tachiyomi/extension/es/manhwaweb/ManhwaWeb.kt @@ -1,12 +1,7 @@ package eu.kanade.tachiyomi.extension.es.manhwaweb -import android.app.Application -import android.content.SharedPreferences -import androidx.preference.PreferenceScreen -import androidx.preference.SwitchPreferenceCompat import eu.kanade.tachiyomi.network.GET -import eu.kanade.tachiyomi.network.interceptor.rateLimitHost -import eu.kanade.tachiyomi.source.ConfigurableSource +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.MangasPage @@ -21,15 +16,9 @@ import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy -class ManhwaWeb : HttpSource(), ConfigurableSource { - - private val preferences by lazy { - Injekt.get().getSharedPreferences("source_$id", 0x0000) - } +class ManhwaWeb : HttpSource() { override val name = "ManhwaWeb" @@ -44,7 +33,7 @@ class ManhwaWeb : HttpSource(), ConfigurableSource { private val json: Json by injectLazy() override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .rateLimitHost(baseUrl.toHttpUrl(), 2) + .rateLimit(2) .build() override fun headersBuilder(): Headers.Builder = super.headersBuilder() @@ -67,7 +56,7 @@ class ManhwaWeb : HttpSource(), ConfigurableSource { override fun latestUpdatesParse(response: Response): MangasPage { val result = json.decodeFromString(response.body.string()) val mangas = (result.data.esp + result.data.raw18 + result.data.esp18) - .distinctBy { it.type + it.slug } + .distinctBy { it.slug } .sortedByDescending { it.latestChapterDate } .map { it.toSManga() } @@ -143,25 +132,17 @@ class ManhwaWeb : HttpSource(), ConfigurableSource { override fun chapterListParse(response: Response): List { val result = json.decodeFromString(response.body.string()) - val chaptersEsp = result.esp.map { it.toSChapter("Esp") } - val chaptersRaw = result.raw.map { it.toSChapter("Raw") } + val chapters = result.chapters.map { it.toSChapter() } - val filteredRaws = if (preferences.showAllRawsPref()) { - chaptersRaw - } else { - val chapterNumbers = chaptersEsp.map { it.chapter_number }.toSet() - chaptersRaw.filter { it.chapter_number !in chapterNumbers } - } - - return (chaptersEsp + filteredRaws).sortedByDescending { it.chapter_number } + return chapters.sortedByDescending { it.chapter_number } } - private fun ChapterDto.toSChapter(type: String) = SChapter.create().apply { + private fun ChapterDto.toSChapter() = SChapter.create().apply { name = "Capítulo ${number.toString().removeSuffix(".0")}" chapter_number = number date_upload = createdAt ?: 0 - setUrlWithoutDomain(this@toSChapter.url) - scanlator = type + url = espUrl ?: rawUrl!! + scanlator = if (espUrl != null) "Esp" else "Raw" } override fun pageListRequest(chapter: SChapter): Request { @@ -175,25 +156,5 @@ class ManhwaWeb : HttpSource(), ConfigurableSource { .mapIndexed { i, img -> Page(i, imageUrl = img) } } - override fun setupPreferenceScreen(screen: PreferenceScreen) { - val showAllRawsPref = SwitchPreferenceCompat(screen.context).apply { - key = SHOW_ALL_RAWS_PREF - title = SHOW_ALL_RAWS_TITLE - summary = SHOW_ALL_RAWS_SUMMARY - setDefaultValue(SHOW_ALL_RAWS_DEFAULT) - } - - screen.addPreference(showAllRawsPref) - } - - private fun SharedPreferences.showAllRawsPref() = getBoolean(SHOW_ALL_RAWS_PREF, SHOW_ALL_RAWS_DEFAULT) - override fun imageUrlParse(response: Response) = throw UnsupportedOperationException() - - companion object { - private const val SHOW_ALL_RAWS_PREF = "pref_show_all_raws_" - private const val SHOW_ALL_RAWS_TITLE = "Mostrar todos los capítulos \"Raw\"" - private const val SHOW_ALL_RAWS_SUMMARY = "Mostrar todos los capítulos \"Raw\" en la lista de capítulos, a pesar de que ya exista una versión en español." - private const val SHOW_ALL_RAWS_DEFAULT = false - } } diff --git a/src/es/manhwaweb/src/eu/kanade/tachiyomi/extension/es/manhwaweb/ManhwaWebDto.kt b/src/es/manhwaweb/src/eu/kanade/tachiyomi/extension/es/manhwaweb/ManhwaWebDto.kt index e078dfa1b..612ee3e41 100644 --- a/src/es/manhwaweb/src/eu/kanade/tachiyomi/extension/es/manhwaweb/ManhwaWebDto.kt +++ b/src/es/manhwaweb/src/eu/kanade/tachiyomi/extension/es/manhwaweb/ManhwaWebDto.kt @@ -25,7 +25,7 @@ class PopularComicDto( fun toSManga() = SManga.create().apply { title = name thumbnail_url = thumbnail - url = slug + url = slug.removePrefix("/") } } @@ -45,13 +45,14 @@ class LatestDto( class LatestComicDto( @SerialName("create") val latestChapterDate: Long, @SerialName("id_manhwa") val slug: String, - @SerialName("_tipo") val type: String, + @SerialName("_plataforma") val platform: String, @SerialName("name_manhwa") private val name: String, @SerialName("img") private val thumbnail: String, ) { fun toSManga() = SManga.create().apply { title = name thumbnail_url = thumbnail + val type = if (platform == "toptoon" || platform == "lezhin") "manhwa" else "manga" url = "$type/$slug" } } @@ -65,13 +66,14 @@ class PayloadSearchDto( @Serializable class SearchComicDto( @SerialName("_id") val slug: String, - @SerialName("_tipo") val type: String, + @SerialName("_plataforma") val platform: String, @SerialName("the_real_name") private val name: String, @SerialName("_imagen") private val thumbnail: String, ) { fun toSManga() = SManga.create().apply { title = name thumbnail_url = thumbnail + val type = if (platform == "toptoon" || platform == "lezhin") "manhwa" else "manga" url = "$type/$slug" } } @@ -113,14 +115,14 @@ class ComicDetailsExtrasDto( @Serializable class PayloadChapterDto( - @SerialName("chapters_esp") val esp: List, - @SerialName("chapters_raw") val raw: List, + val chapters: List, ) @Serializable class ChapterDto( @SerialName("chapter") val number: Float, - @SerialName("link") val url: String, + @SerialName("link") val espUrl: String? = null, + @SerialName("link_raw") val rawUrl: String? = null, @SerialName("create") val createdAt: Long?, )