From bdf62a6107fa54a19f310276f8f04b78a241dce4 Mon Sep 17 00:00:00 2001 From: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Date: Tue, 13 Dec 2022 11:46:55 +0800 Subject: [PATCH] Fix Baozimh.org (#14525) --- .../madara/baozimhorg/src/BaozimhOrg.kt | 153 ------------- .../multisrc/madara/MadaraGenerator.kt | 1 - src/zh/baozimhorg/AndroidManifest.xml | 2 + src/zh/baozimhorg/build.gradle | 11 + .../res/mipmap-hdpi/ic_launcher.png | Bin .../res/mipmap-mdpi/ic_launcher.png | Bin .../res/mipmap-xhdpi/ic_launcher.png | Bin .../res/mipmap-xxhdpi/ic_launcher.png | Bin .../res/mipmap-xxxhdpi/ic_launcher.png | Bin .../zh}/baozimhorg/res/web_hi_res_512.png | Bin .../extension/zh/baozimhorg/BaozimhOrg.kt | 216 ++++++++++++++++++ .../extension/zh/baozimhorg/UrlInterceptor.kt | 32 +++ 12 files changed, 261 insertions(+), 154 deletions(-) delete mode 100644 multisrc/overrides/madara/baozimhorg/src/BaozimhOrg.kt create mode 100644 src/zh/baozimhorg/AndroidManifest.xml create mode 100644 src/zh/baozimhorg/build.gradle rename {multisrc/overrides/madara => src/zh}/baozimhorg/res/mipmap-hdpi/ic_launcher.png (100%) rename {multisrc/overrides/madara => src/zh}/baozimhorg/res/mipmap-mdpi/ic_launcher.png (100%) rename {multisrc/overrides/madara => src/zh}/baozimhorg/res/mipmap-xhdpi/ic_launcher.png (100%) rename {multisrc/overrides/madara => src/zh}/baozimhorg/res/mipmap-xxhdpi/ic_launcher.png (100%) rename {multisrc/overrides/madara => src/zh}/baozimhorg/res/mipmap-xxxhdpi/ic_launcher.png (100%) rename {multisrc/overrides/madara => src/zh}/baozimhorg/res/web_hi_res_512.png (100%) create mode 100644 src/zh/baozimhorg/src/eu/kanade/tachiyomi/extension/zh/baozimhorg/BaozimhOrg.kt create mode 100644 src/zh/baozimhorg/src/eu/kanade/tachiyomi/extension/zh/baozimhorg/UrlInterceptor.kt diff --git a/multisrc/overrides/madara/baozimhorg/src/BaozimhOrg.kt b/multisrc/overrides/madara/baozimhorg/src/BaozimhOrg.kt deleted file mode 100644 index 361129d96..000000000 --- a/multisrc/overrides/madara/baozimhorg/src/BaozimhOrg.kt +++ /dev/null @@ -1,153 +0,0 @@ -package eu.kanade.tachiyomi.extension.zh.baozimhorg - -import android.app.Application -import androidx.preference.ListPreference -import androidx.preference.PreferenceScreen -import eu.kanade.tachiyomi.multisrc.madara.Madara -import eu.kanade.tachiyomi.network.GET -import eu.kanade.tachiyomi.source.ConfigurableSource -import eu.kanade.tachiyomi.source.model.Filter -import eu.kanade.tachiyomi.source.model.FilterList -import eu.kanade.tachiyomi.source.model.MangasPage -import eu.kanade.tachiyomi.source.model.SChapter -import eu.kanade.tachiyomi.source.model.SManga -import eu.kanade.tachiyomi.util.asJsoup -import okhttp3.HttpUrl.Companion.toHttpUrl -import okhttp3.Request -import okhttp3.Response -import org.jsoup.nodes.Document -import org.jsoup.nodes.Element -import org.jsoup.select.Evaluator -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.api.get -import java.text.SimpleDateFormat -import java.util.Locale - -// Uses Elementor + Madara theme. -class BaozimhOrg : ConfigurableSource, Madara( - "包子漫画导航", - "", - "zh", - SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH) -) { - - override val baseUrl: String - - init { - val mirrors = MIRRORS - val mirrorIndex = Injekt.get().getSharedPreferences("source_$id", 0x0000) - .getString(MIRROR_PREF, "0")!!.toInt().coerceAtMost(mirrors.size - 1) - baseUrl = "https://" + mirrors[mirrorIndex] - } - - override val client = network.client - - override val useLoadMoreSearch = false - override val sendViewCount = false - - override fun popularMangaRequest(page: Int) = GET("$baseUrl/hots/$page/", headers) - override fun latestUpdatesRequest(page: Int) = GET("$baseUrl/dayup/$page/", headers) - override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - if (query.isNotEmpty()) { - val url = "$baseUrl/page/$page/".toHttpUrl().newBuilder() - .addQueryParameter("s", query) - return Request.Builder().url(url.build()).headers(headers).build() - } - for (filter in filters) { - if (filter is UriPartFilter) return GET(baseUrl + filter.toUriPart() + "page/$page/", headers) - } - return popularMangaRequest(page) - } - - override val popularMangaUrlSelector = "h3 > a" - - override fun latestUpdatesParse(response: Response) = popularMangaParse(response) - override fun searchMangaParse(response: Response) = popularMangaParse(response) - override fun popularMangaParse(response: Response): MangasPage { - val document = response.asJsoup().also(::parseGenresInternal) - val mangas = document.select(Evaluator.Tag("article")).map(::popularMangaFromElement) - val hasNextPage = document.selectFirst(Evaluator.Class("next"))?.tagName() == "a" - return MangasPage(mangas, hasNextPage) - } - - override val mangaDetailsSelectorStatus = "none" - override val mangaDetailsSelectorDescription = "div.summary_content > div.post-content_item:last-child" - override val seriesTypeSelector = "none" - override val altNameSelector = "none" - - override fun mangaDetailsParse(document: Document): SManga { - val manga = super.mangaDetailsParse(document) - val genre = manga.genre ?: return manga - val genreList = genre.split(", ") as ArrayList - for ((index, tag) in genreList.withIndex()) { - val status = when (tag) { - "连载中" -> SManga.ONGOING - "已完结" -> SManga.COMPLETED - else -> SManga.UNKNOWN - } - if (status != SManga.UNKNOWN) { - manga.status = status - genreList.removeAt(index) - manga.genre = genreList.joinToString() - return manga - } - } - return manga - } - - override fun chapterFromElement(element: Element) = SChapter.create().apply { - val link = element.selectFirst(Evaluator.Tag("a")) - url = link.attr("href").removePrefix(baseUrl) - name = link.ownText() - date_upload = parseChapterDate(link.child(0).text()) - } - - override fun parseRelativeDate(date: String) = - super.parseRelativeDate(date.replace("小时", "hour")) - - // Jsoup won't ignore duplicates inside