ManhwaWeb: Fix chapters not found and webview (#3671)

* Fix ManhwaWeb

* more fix
This commit is contained in:
bapeey 2024-06-21 03:46:28 -05:00 committed by Draff
parent 731bcf021d
commit 47b60ed24d
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
3 changed files with 18 additions and 55 deletions

View File

@ -1,7 +1,7 @@
ext { ext {
extName = 'ManhwaWeb' extName = 'ManhwaWeb'
extClass = '.ManhwaWeb' extClass = '.ManhwaWeb'
extVersionCode = 2 extVersionCode = 3
isNsfw = true isNsfw = true
} }

View File

@ -1,12 +1,7 @@
package eu.kanade.tachiyomi.extension.es.manhwaweb 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.GET
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost import eu.kanade.tachiyomi.network.interceptor.rateLimit
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.MangasPage
@ -21,15 +16,9 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
class ManhwaWeb : HttpSource(), ConfigurableSource { class ManhwaWeb : HttpSource() {
private val preferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
override val name = "ManhwaWeb" override val name = "ManhwaWeb"
@ -44,7 +33,7 @@ class ManhwaWeb : HttpSource(), ConfigurableSource {
private val json: Json by injectLazy() private val json: Json by injectLazy()
override val client: OkHttpClient = network.cloudflareClient.newBuilder() override val client: OkHttpClient = network.cloudflareClient.newBuilder()
.rateLimitHost(baseUrl.toHttpUrl(), 2) .rateLimit(2)
.build() .build()
override fun headersBuilder(): Headers.Builder = super.headersBuilder() override fun headersBuilder(): Headers.Builder = super.headersBuilder()
@ -67,7 +56,7 @@ class ManhwaWeb : HttpSource(), ConfigurableSource {
override fun latestUpdatesParse(response: Response): MangasPage { override fun latestUpdatesParse(response: Response): MangasPage {
val result = json.decodeFromString<PayloadLatestDto>(response.body.string()) val result = json.decodeFromString<PayloadLatestDto>(response.body.string())
val mangas = (result.data.esp + result.data.raw18 + result.data.esp18) val mangas = (result.data.esp + result.data.raw18 + result.data.esp18)
.distinctBy { it.type + it.slug } .distinctBy { it.slug }
.sortedByDescending { it.latestChapterDate } .sortedByDescending { it.latestChapterDate }
.map { it.toSManga() } .map { it.toSManga() }
@ -143,25 +132,17 @@ class ManhwaWeb : HttpSource(), ConfigurableSource {
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {
val result = json.decodeFromString<PayloadChapterDto>(response.body.string()) val result = json.decodeFromString<PayloadChapterDto>(response.body.string())
val chaptersEsp = result.esp.map { it.toSChapter("Esp") } val chapters = result.chapters.map { it.toSChapter() }
val chaptersRaw = result.raw.map { it.toSChapter("Raw") }
val filteredRaws = if (preferences.showAllRawsPref()) { return chapters.sortedByDescending { it.chapter_number }
chaptersRaw
} else {
val chapterNumbers = chaptersEsp.map { it.chapter_number }.toSet()
chaptersRaw.filter { it.chapter_number !in chapterNumbers }
}
return (chaptersEsp + filteredRaws).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")}" name = "Capítulo ${number.toString().removeSuffix(".0")}"
chapter_number = number chapter_number = number
date_upload = createdAt ?: 0 date_upload = createdAt ?: 0
setUrlWithoutDomain(this@toSChapter.url) url = espUrl ?: rawUrl!!
scanlator = type scanlator = if (espUrl != null) "Esp" else "Raw"
} }
override fun pageListRequest(chapter: SChapter): Request { override fun pageListRequest(chapter: SChapter): Request {
@ -175,25 +156,5 @@ class ManhwaWeb : HttpSource(), ConfigurableSource {
.mapIndexed { i, img -> Page(i, imageUrl = img) } .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() 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
}
} }

View File

@ -25,7 +25,7 @@ class PopularComicDto(
fun toSManga() = SManga.create().apply { fun toSManga() = SManga.create().apply {
title = name title = name
thumbnail_url = thumbnail thumbnail_url = thumbnail
url = slug url = slug.removePrefix("/")
} }
} }
@ -45,13 +45,14 @@ class LatestDto(
class LatestComicDto( class LatestComicDto(
@SerialName("create") val latestChapterDate: Long, @SerialName("create") val latestChapterDate: Long,
@SerialName("id_manhwa") val slug: String, @SerialName("id_manhwa") val slug: String,
@SerialName("_tipo") val type: String, @SerialName("_plataforma") val platform: String,
@SerialName("name_manhwa") private val name: String, @SerialName("name_manhwa") private val name: String,
@SerialName("img") private val thumbnail: String, @SerialName("img") private val thumbnail: String,
) { ) {
fun toSManga() = SManga.create().apply { fun toSManga() = SManga.create().apply {
title = name title = name
thumbnail_url = thumbnail thumbnail_url = thumbnail
val type = if (platform == "toptoon" || platform == "lezhin") "manhwa" else "manga"
url = "$type/$slug" url = "$type/$slug"
} }
} }
@ -65,13 +66,14 @@ class PayloadSearchDto(
@Serializable @Serializable
class SearchComicDto( class SearchComicDto(
@SerialName("_id") val slug: String, @SerialName("_id") val slug: String,
@SerialName("_tipo") val type: String, @SerialName("_plataforma") val platform: String,
@SerialName("the_real_name") private val name: String, @SerialName("the_real_name") private val name: String,
@SerialName("_imagen") private val thumbnail: String, @SerialName("_imagen") private val thumbnail: String,
) { ) {
fun toSManga() = SManga.create().apply { fun toSManga() = SManga.create().apply {
title = name title = name
thumbnail_url = thumbnail thumbnail_url = thumbnail
val type = if (platform == "toptoon" || platform == "lezhin") "manhwa" else "manga"
url = "$type/$slug" url = "$type/$slug"
} }
} }
@ -113,14 +115,14 @@ class ComicDetailsExtrasDto(
@Serializable @Serializable
class PayloadChapterDto( class PayloadChapterDto(
@SerialName("chapters_esp") val esp: List<ChapterDto>, val chapters: List<ChapterDto>,
@SerialName("chapters_raw") val raw: List<ChapterDto>,
) )
@Serializable @Serializable
class ChapterDto( class ChapterDto(
@SerialName("chapter") val number: Float, @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?, @SerialName("create") val createdAt: Long?,
) )