From adc8fdafb8fec6a57577bd705f7c8d954246310d Mon Sep 17 00:00:00 2001 From: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Date: Thu, 21 Jul 2022 10:35:30 +0800 Subject: [PATCH] Baozi Manhua: chapter image pagination (#12646) --- src/zh/baozimanhua/CHANGELOG.md | 4 +++ src/zh/baozimanhua/build.gradle | 2 +- .../extension/zh/baozimanhua/Baozi.kt | 28 +++++++++++++++---- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/zh/baozimanhua/CHANGELOG.md b/src/zh/baozimanhua/CHANGELOG.md index 50fcc1648..09520d441 100644 --- a/src/zh/baozimanhua/CHANGELOG.md +++ b/src/zh/baozimanhua/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.3.10 (2022-07-20) + +- 适配章节分页 + ## 1.3.9 (2022-07-12) - 修复章节图片解析 diff --git a/src/zh/baozimanhua/build.gradle b/src/zh/baozimanhua/build.gradle index 30da50d53..939d0845e 100644 --- a/src/zh/baozimanhua/build.gradle +++ b/src/zh/baozimanhua/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Baozi Manhua' pkgNameSuffix = 'zh.baozimanhua' extClass = '.Baozi' - extVersionCode = 9 + extVersionCode = 10 } apply from: "$rootDir/common.gradle" diff --git a/src/zh/baozimanhua/src/eu/kanade/tachiyomi/extension/zh/baozimanhua/Baozi.kt b/src/zh/baozimanhua/src/eu/kanade/tachiyomi/extension/zh/baozimanhua/Baozi.kt index 9ee21e165..a32ae1db1 100644 --- a/src/zh/baozimanhua/src/eu/kanade/tachiyomi/extension/zh/baozimanhua/Baozi.kt +++ b/src/zh/baozimanhua/src/eu/kanade/tachiyomi/extension/zh/baozimanhua/Baozi.kt @@ -21,7 +21,9 @@ import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element +import org.jsoup.select.Evaluator import rx.Observable +import rx.Single import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.text.SimpleDateFormat @@ -122,11 +124,27 @@ class Baozi : ParsedHttpSource(), ConfigurableSource { } } - override fun pageListParse(document: Document): List { - return document.select(".comic-contain amp-img").mapIndexed { index, element -> - Page(index, imageUrl = element.attr("src")) - } - } + override fun fetchPageList(chapter: SChapter): Observable> = Single.create> { + val pageList = ArrayList(0) + var url = baseUrl + chapter.url + var pageCount = 0 + var i = 0 + do { + val document = client.newCall(GET(url, headers)).execute().asJsoup() + if (i == 0) { + pageCount = document.selectFirst(Evaluator.Class("comic-text__amp")) + ?.run { text().substringAfter('/').toInt() } ?: break + pageList.ensureCapacity(pageCount) + } + document.select(".comic-contain amp-img").mapTo(pageList) { element -> + Page(i++, imageUrl = element.attr("src")) + } + url = document.selectFirst(Evaluator.Id("next-chapter"))?.attr("href") ?: "" + } while (i < pageCount) + it.onSuccess(pageList) + }.toObservable() + + override fun pageListParse(document: Document) = throw UnsupportedOperationException("Not used.") override fun imageUrlParse(document: Document) = throw UnsupportedOperationException("Not used.")