From a4cd04699c2cea724c71c4e08c1a830648186169 Mon Sep 17 00:00:00 2001 From: Creepler13 Date: Sat, 15 Mar 2025 06:56:44 +0100 Subject: [PATCH] Fix Baozi (#8078) Fix baozi --- src/zh/baozimanhua/build.gradle | 2 +- .../extension/zh/baozimanhua/Baozi.kt | 39 ++++++++++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/zh/baozimanhua/build.gradle b/src/zh/baozimanhua/build.gradle index 014a9d616..012a55418 100644 --- a/src/zh/baozimanhua/build.gradle +++ b/src/zh/baozimanhua/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Baozi Manhua' extClass = '.Baozi' - extVersionCode = 24 + extVersionCode = 25 } 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 efe04da1a..232f2bc0e 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 @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.extension.zh.baozimanhua import android.content.SharedPreferences +import androidx.preference.CheckBoxPreference import androidx.preference.ListPreference import androidx.preference.PreferenceScreen import com.github.stevenyomi.baozibanner.BaoziBanner @@ -141,16 +142,18 @@ class Baozi : ParsedHttpSource(), ConfigurableSource { } override fun fetchPageList(chapter: SChapter): Observable> = Observable.fromCallable { - val pathToUrl = LinkedHashMap() - var request = GET(baseUrl + chapter.url, headers).newBuilder() - .tag(RedirectDomainInterceptor.Tag::class, RedirectDomainInterceptor.Tag()).build() + val urls = mutableListOf() + + var chapterUrl = baseUrl + chapter.url + if (preferences.getBoolean(QUICK_PAGES_PREF, true)) { + chapterUrl = quickPageUrl(chapterUrl) + } + + var request = GET(chapterUrl, headers).newBuilder().build() while (true) { val document = client.newCall(request).execute().asJsoup() - for (element in document.select(".comic-contain amp-img")) { - val imageUrl = element.attr("data-src") - val path = imageUrl.substring(imageUrl.indexOf('/', startIndex = 8)) // Skip "https://" - pathToUrl[path] = imageUrl - } + urls.addAll(document.select(".comic-contain amp-img").map { it.absUrl("src") }) + val url = document.selectFirst(Evaluator.Id("next-chapter")) ?.takeIf { val text = it.text() @@ -158,11 +161,20 @@ class Baozi : ParsedHttpSource(), ConfigurableSource { } ?.attr("href") ?: break + request = GET(url, headers) } - pathToUrl.values.mapIndexed { index, imageUrl -> Page(index, imageUrl = imageUrl) } + urls.mapIndexed { index, imageUrl -> Page(index, imageUrl = imageUrl) } } + private fun quickPageUrl(url: String): String = + baseUrl.toHttpUrl().newBuilder().apply { + val chapUrl = url.toHttpUrl() + addPathSegments("/comic/chapter") + chapUrl.queryParameter("comic_id")?.let { addPathSegment(it) } + addPathSegment("${chapUrl.queryParameter("section_slot")}_${chapUrl.queryParameter("chapter_slot")}.html") + }.build().toString() + override fun imageRequest(page: Page): Request { val url = page.imageUrl!!.replace(".baozicdn.com", ".baozimh.com") return GET(url, headers) @@ -268,6 +280,13 @@ class Baozi : ParsedHttpSource(), ConfigurableSource { entryValues = arrayOf(CHAPTER_ORDER_DISABLED, CHAPTER_ORDER_ENABLED, CHAPTER_ORDER_AGGRESSIVE) setDefaultValue(CHAPTER_ORDER_DISABLED) }.let { screen.addPreference(it) } + + CheckBoxPreference(screen.context).apply { + key = QUICK_PAGES_PREF + title = "Quick Pages/快速页面" + summary = "跳过页面上的重定向。五月休息。(对不起,必须使用翻译器)" + setDefaultValue(true) + }.let { screen.addPreference(it) } } companion object { @@ -300,5 +319,7 @@ class Baozi : ParsedHttpSource(), ConfigurableSource { private const val CHAPTER_ORDER_AGGRESSIVE = "2" private val DATE_FORMAT by lazy { SimpleDateFormat("yyyy年MM月dd日", Locale.ENGLISH) } + + private const val QUICK_PAGES_PREF = "QUICK_PAGES" } }