Tojimangas: fix extension (#6926)

* fix extension

* requested changes
This commit is contained in:
dngonz 2025-01-03 08:44:03 +01:00 committed by Draff
parent 2821b0dce8
commit 280ae02b9b
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 113 additions and 45 deletions

View File

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

View File

@ -11,8 +11,8 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Request import okhttp3.Request
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import java.text.SimpleDateFormat import java.text.ParseException
import java.util.Locale import java.util.Calendar
class Tojimangas : ParsedHttpSource() { class Tojimangas : ParsedHttpSource() {
@ -21,15 +21,15 @@ class Tojimangas : ParsedHttpSource() {
override val name = "Tojimangas" override val name = "Tojimangas"
override val supportsLatest = true override val supportsLatest = true
override fun searchMangaSelector(): String = ".animposx a" override fun searchMangaSelector(): String = "a.poster"
override fun popularMangaSelector(): String = searchMangaSelector() override fun popularMangaSelector(): String = searchMangaSelector()
override fun latestUpdatesSelector(): String = searchMangaSelector() override fun latestUpdatesSelector(): String = ".recently-updated a.poster"
override fun searchMangaNextPageSelector(): String = ".arrow_pag" override fun searchMangaNextPageSelector(): String = "a.next"
override fun popularMangaNextPageSelector(): String = searchMangaNextPageSelector() override fun popularMangaNextPageSelector(): String = searchMangaNextPageSelector()
override fun latestUpdatesNextPageSelector(): String = searchMangaNextPageSelector() override fun latestUpdatesNextPageSelector(): String = searchMangaNextPageSelector()
override fun chapterListSelector(): String = "li .epsleft" override fun chapterListSelector(): String = ".item"
private fun makeMangaRequest( private fun makeMangaRequest(
page: Int, page: Int,
@ -37,9 +37,11 @@ class Tojimangas : ParsedHttpSource() {
): Request = GET( ): Request = GET(
addToBuilder( addToBuilder(
baseUrl.toHttpUrl().newBuilder().apply { baseUrl.toHttpUrl().newBuilder().apply {
addPathSegment("biblioteca")
addPathSegment("page") addPathSegment("page")
addPathSegment(page.toString()) addPathSegment(page.toString())
addPathSegment("")
addQueryParameter("post_type", "manga")
addQueryParameter("s", "")
}, },
).build(), ).build(),
headers, headers,
@ -47,66 +49,132 @@ class Tojimangas : ParsedHttpSource() {
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request = override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request =
makeMangaRequest(page) { makeMangaRequest(page) {
it.addQueryParameter("title", query) it.setQueryParameter("s", query)
} }
override fun popularMangaRequest(page: Int): Request = makeMangaRequest(page) { override fun popularMangaRequest(page: Int): Request = makeMangaRequest(page) {
it.addQueryParameter("order", "popular") it.addQueryParameter("orderby", "popular")
} }
override fun latestUpdatesRequest(page: Int): Request = makeMangaRequest(page) { override fun latestUpdatesRequest(page: Int): Request {
it.addQueryParameter("order", "update") val url = baseUrl.toHttpUrl().newBuilder()
if (page > 1) {
url.addPathSegment("page")
url.addPathSegment(page.toString())
url.addPathSegment("")
}
return GET(url.build(), headers)
} }
override fun searchMangaFromElement(element: Element): SManga = SManga.create().apply { override fun searchMangaFromElement(element: Element): SManga = SManga.create().apply {
setUrlWithoutDomain(element.absUrl("href")) setUrlWithoutDomain(element.absUrl("href"))
title = element.attr("title") title = element.selectFirst("img")!!.attr("alt")
thumbnail_url = element.selectFirst("img")?.absUrl("src") thumbnail_url = element.selectFirst("img")?.attr("abs:src")
} }
override fun popularMangaFromElement(element: Element): SManga = searchMangaFromElement(element) override fun popularMangaFromElement(element: Element): SManga = searchMangaFromElement(element)
override fun latestUpdatesFromElement(element: Element): SManga = override fun latestUpdatesFromElement(element: Element): SManga = SManga.create().apply {
searchMangaFromElement(element) setUrlWithoutDomain(element.absUrl("href"))
title = element.selectFirst("img")!!.attr("alt")
override fun mangaDetailsParse(document: Document): SManga = SManga.create().apply { thumbnail_url = element.selectFirst("img")?.attr("abs:src")
thumbnail_url = document.selectFirst("thumb img")?.absUrl("src")
description =
document.select(".desc > div > :not(h2, [style='display: none;'], .manga-update-info)")
.filter { p -> p.text() != "" }
.joinToString { p -> p.text() }
genre = document.select(".genre-info a").joinToString { a -> a.text() }
val infoGrid = document.selectFirst(".infox .spe")
author = infoGrid?.selectFirst("span:contains(Autor)")?.text()?.substringAfter("Autor")
status =
when (
infoGrid?.selectFirst("span:contains(Estado)")?.text()?.substringAfter("Estado")
?.trim()?.lowercase()
) {
"activo" -> SManga.ONGOING
"finalizado" -> SManga.COMPLETED
else -> SManga.UNKNOWN
}
} }
private val dateFormat = SimpleDateFormat("dd MMMM, yyyy", Locale("es")) override fun mangaDetailsParse(document: Document): SManga = SManga.create().apply {
val content = document.selectFirst(".content")
thumbnail_url = content?.selectFirst("img")?.absUrl("src")
genre = document.select(".meta a").joinToString { it.text() }
}
override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply { override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply {
val a = element.selectFirst("a") val a = element.selectFirst("a")
a?.absUrl("href")?.let { setUrlWithoutDomain(it) } a?.absUrl("href")?.let { setUrlWithoutDomain(it) }
name = a?.text() ?: "" name = a?.text() ?: ""
date_upload = element.selectFirst(".date")?.text()?.let { dateFormat.parse(it)?.time } ?: 0 date_upload = element.selectFirst(".time")?.text()?.trim()?.parseDate() ?: 0
} }
override fun pageListParse(document: Document): List<Page> = override fun pageListParse(document: Document): List<Page> {
document.select(".reader-area img").mapIndexed { idx, img -> return document.select("#ch-images img").mapIndexed { idx, img ->
Page(idx, imageUrl = img.absUrl("src")) Page(idx, imageUrl = img.absUrl("data-src"))
} }
}
private fun String.parseDate(): Long {
return try {
parseRelativeDate(this)
} catch (_: ParseException) {
0L
}
}
protected open fun parseRelativeDate(date: String): Long {
val number = DATE_REGEX.find(date)?.value?.toIntOrNull() ?: return 0
val cal = Calendar.getInstance()
return when {
WordSet("segundo", "segundos").anyWordIn(date) -> cal.apply {
add(
Calendar.SECOND,
-number,
)
}.timeInMillis
WordSet("minuto", "minutos").anyWordIn(date) -> cal.apply {
add(
Calendar.MINUTE,
-number,
)
}.timeInMillis
WordSet("día", "días").anyWordIn(date) -> cal.apply {
add(
Calendar.DAY_OF_MONTH,
-number,
)
}.timeInMillis
WordSet("hora", "horas").anyWordIn(date) -> cal.apply {
add(
Calendar.HOUR,
-number,
)
}.timeInMillis
WordSet("semana", "semanas").anyWordIn(date) -> cal.apply {
add(
Calendar.DAY_OF_MONTH,
-number * 7,
)
}.timeInMillis
WordSet("mes", "meses").anyWordIn(date) -> cal.apply {
add(
Calendar.MONTH,
-number,
)
}.timeInMillis
WordSet("año", "años").anyWordIn(date) -> cal.apply {
add(
Calendar.YEAR,
-number,
)
}.timeInMillis
else -> 0
}
}
class WordSet(private vararg val words: String) {
fun anyWordIn(dateString: String): Boolean =
words.any { dateString.contains(it, ignoreCase = true) }
}
override fun imageUrlParse(document: Document): String = "" override fun imageUrlParse(document: Document): String = ""
companion object {
private val DATE_REGEX = """(\d+)""".toRegex()
}
} }