From 9a48fc85ca724a917ddc2f885db6f5c37b815c33 Mon Sep 17 00:00:00 2001 From: SkyNalix <56894341+SkyNalix@users.noreply.github.com> Date: Mon, 2 Oct 2023 00:19:36 +0200 Subject: [PATCH] Mangafire: fix manga chapters load (#18298) * Mangafire: fix manga and chapters load * Mangafire: increase version code --- .../mangareader/mangafire/src/MangaFire.kt | 90 +++++++++++-------- .../mangareader/MangaReaderGenerator.kt | 2 +- 2 files changed, 54 insertions(+), 38 deletions(-) diff --git a/multisrc/overrides/mangareader/mangafire/src/MangaFire.kt b/multisrc/overrides/mangareader/mangafire/src/MangaFire.kt index 262ded34c..06d32517d 100644 --- a/multisrc/overrides/mangareader/mangafire/src/MangaFire.kt +++ b/multisrc/overrides/mangareader/mangafire/src/MangaFire.kt @@ -85,15 +85,15 @@ open class MangaFire( return GET(urlBuilder.build(), headers) } - override fun searchMangaSelector() = ".mangas.items .inner" - override fun searchMangaNextPageSelector() = ".page-item.active + .page-item .page-link" + override fun searchMangaSelector() = ".original.card-lg .unit .inner" + override fun searchMangaFromElement(element: Element) = SManga.create().apply { - element.selectFirst("a.color-light")!!.let { - url = it.attr("href") - title = it.attr("title") + element.selectFirst(".info > a")!!.let { + setUrlWithoutDomain(it.attr("href")) + title = it.ownText() } element.selectFirst(Evaluator.Tag("img"))!!.let { thumbnail_url = it.attr("src") @@ -101,25 +101,26 @@ open class MangaFire( } override fun mangaDetailsParse(document: Document) = SManga.create().apply { - val root = document.selectFirst(".detail .top .wrapper")!! - val mangaTitle = root.selectFirst(Evaluator.Class("name"))!!.ownText() + val root = document.selectFirst(".info")!! + val mangaTitle = root.child(1).ownText() title = mangaTitle description = document.run { - val description = selectFirst(Evaluator.Class("summary"))!!.ownText() - when (val altTitle = root.selectFirst(Evaluator.Class("al-name"))!!.ownText()) { + val description = selectFirst(Evaluator.Class("description"))!!.ownText() + when (val altTitle = root.child(2).ownText()) { "", mangaTitle -> description else -> "$description\n\nAlternative Title: $altTitle" } } - thumbnail_url = root.selectFirst(Evaluator.Tag("img"))!!.attr("src") - status = when (root.selectFirst(Evaluator.Class("status"))!!.ownText()) { + thumbnail_url = document.selectFirst(".poster")!! + .selectFirst("img")!!.attr("src") + status = when (root.child(0).ownText()) { "Completed" -> SManga.COMPLETED "Releasing" -> SManga.ONGOING "On_hiatus" -> SManga.ON_HIATUS "Discontinued" -> SManga.CANCELLED else -> SManga.UNKNOWN } - with(root.selectFirst(Evaluator.Class("more-info"))!!) { + with(document.selectFirst(Evaluator.Class("meta"))!!) { author = selectFirst("span:contains(Author:) + span")?.text() val type = selectFirst("span:contains(Type:) + span")?.text() val genres = selectFirst("span:contains(Genres:) + span")?.text() @@ -132,20 +133,39 @@ open class MangaFire( override fun chapterListRequest(mangaUrl: String, type: String): Request { val id = mangaUrl.substringAfterLast('.') - return GET("$baseUrl/ajax/read/$id/list?viewby=$type", headers) + return GET("$baseUrl/ajax/manga/$id/$type/$langCode", headers) } override fun parseChapterElements(response: Response, isVolume: Boolean): List { - val result = json.decodeFromString>(response.body.string()).result - val container = result.parseHtml(if (isVolume) volumeType else chapterType) - ?.selectFirst(".numberlist[data-lang=$langCode]") - ?: return emptyList() - return container.children().map { it.child(0) } + val result = json.decodeFromString>(response.body.string()).result + val document = Jsoup.parse(result) + + val elements = document.select("ul li") + if (elements.size > 0) { + val linkToFirstChapter = elements[0].selectFirst(Evaluator.Tag("a"))!!.attr("href") + val mangaId = linkToFirstChapter.toString().substringAfter('.').substringBefore('/') + + val request = GET("$baseUrl/ajax/read/$mangaId/chapter/$langCode", headers) + val response = client.newCall(request).execute() + val res = json.decodeFromString>(response.body.string()).result.html + val chapterInfoDocument = Jsoup.parse(res) + val chapters = chapterInfoDocument.select("ul li") + for ((i, it) in elements.withIndex()) { + it.attr("data-id", chapters[i].select("a").attr("data-id")) + } + } + return elements.toList() } + @Serializable + class ChapterIdsDto( + val html: String, + val title_format: String, + ) + override fun updateChapterList(manga: SManga, chapters: List) { val document = client.newCall(mangaDetailsRequest(manga)).execute().asJsoup() - val elements = document.selectFirst(".chapter-list[data-name=$langCode]")!!.children() + val elements = document.selectFirst(".scroll-sm")!!.children() val chapterCount = chapters.size if (elements.size != chapterCount) throw Exception("Chapter count doesn't match. Try updating again.") val dateFormat = SimpleDateFormat("MMM dd, yyyy", Locale.US) @@ -180,6 +200,20 @@ open class MangaFire( } } + @Serializable + class PageListDto(private val images: List>) { + val pages get() = images.map { + Image(it[0].content, it[2].int) + } + } + class Image(val url: String, val offset: Int) + + @Serializable + class ResponseDto( + val result: T, + val status: Int, + ) + override fun getFilterList() = FilterList( Filter.Header("NOTE: Ignored if using text search!"), @@ -191,22 +225,4 @@ open class MangaFire( ChapterCountFilter(), SortFilter(), ) - - @Serializable - class ChapterListDto(private val html: String, private val link_format: String) { - fun parseHtml(type: String): Document? { - if ("LANG/$type-NUMBER" !in link_format) return null - return Jsoup.parseBodyFragment(html) - } - } - - @Serializable - class PageListDto(private val images: List>) { - val pages get() = images.map { Image(it[0].content, it[2].int) } - } - - class Image(val url: String, val offset: Int) - - @Serializable - class ResponseDto(val result: T) } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangareader/MangaReaderGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangareader/MangaReaderGenerator.kt index 63bcb401f..867c81e97 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangareader/MangaReaderGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangareader/MangaReaderGenerator.kt @@ -21,7 +21,7 @@ class MangaReaderGenerator : ThemeSourceGenerator { baseUrl = "https://mangafire.to", langs = listOf("en", "es", "es-419", "fr", "ja", "pt", "pt-BR"), isNsfw = true, - overrideVersionCode = 1, + overrideVersionCode = 2, ), )