MangaReader: Add support for Portuguese and Spanish (#5972)

Add support for Portuguese and Spanish
This commit is contained in:
Chopper 2024-11-11 05:37:46 -03:00 committed by Draff
parent d07881f0b6
commit 49e35d5223
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
3 changed files with 24 additions and 7 deletions

View File

@ -3,7 +3,7 @@ ext {
extClass = '.MangaReaderFactory'
themePkg = 'mangareader'
baseUrl = 'https://mangareader.to'
overrideVersionCode = 3
overrideVersionCode = 4
isNsfw = true
}

View File

@ -22,8 +22,11 @@ import org.jsoup.select.Evaluator
import rx.Observable
open class MangaReader(
override val lang: String,
val language: Language,
) : MangaReader() {
override val lang = language.code
override val name = "MangaReader"
override val baseUrl = "https://mangareader.to"
@ -33,10 +36,10 @@ open class MangaReader(
.build()
override fun latestUpdatesRequest(page: Int) =
GET("$baseUrl/filter?sort=latest-updated&language=$lang&page=$page", headers)
GET("$baseUrl/filter?sort=latest-updated&language=${language.infix}&page=$page", headers)
override fun popularMangaRequest(page: Int) =
GET("$baseUrl/filter?sort=most-viewed&language=$lang&page=$page", headers)
GET("$baseUrl/filter?sort=most-viewed&language=${language.infix}&page=$page", headers)
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
val urlBuilder = baseUrl.toHttpUrl().newBuilder()
@ -47,7 +50,7 @@ open class MangaReader(
}
} else {
urlBuilder.addPathSegment("filter").apply {
addQueryParameter("language", lang)
addQueryParameter("language", language.infix)
addQueryParameter("page", page.toString())
filters.ifEmpty(::getFilterList).forEach { filter ->
when (filter) {
@ -142,7 +145,7 @@ open class MangaReader(
override fun parseChapterElements(response: Response, isVolume: Boolean): List<Element> {
val container = response.parseHtmlProperty().run {
val type = if (isVolume) "volumes" else "chapters"
selectFirst(Evaluator.Id("$lang-$type")) ?: return emptyList()
selectFirst(Evaluator.Id("${language.chapterInfix}-$type")) ?: return emptyList()
}
return container.children()
}

View File

@ -4,5 +4,19 @@ import eu.kanade.tachiyomi.source.SourceFactory
class MangaReaderFactory : SourceFactory {
override fun createSources() =
arrayOf("en", "fr", "ja", "ko", "zh").map(::MangaReader)
arrayOf(
Language("en"),
Language("es", chapterInfix = "es-mx"),
Language("fr"),
Language("ja"),
Language("ko"),
Language("pt-BR", infix = "pt"),
Language("zh"),
).map(::MangaReader)
}
data class Language(
val code: String,
val infix: String = code,
val chapterInfix: String = code.lowercase(),
)