From e4e18beaa216a020c423388131c947552e132e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=9C=E5=8F=B6?= Date: Fri, 2 Oct 2020 00:02:19 +0800 Subject: [PATCH] Fix wnacg thumbnails loading (#4489) * Fix wnacg thumbnails loading * Fix wnacg thumbnails loading --- src/zh/wnacg/build.gradle | 2 +- .../tachiyomi/extension/zh/wnacg/wnacg.kt | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/zh/wnacg/build.gradle b/src/zh/wnacg/build.gradle index e647f37b5..20da713c6 100644 --- a/src/zh/wnacg/build.gradle +++ b/src/zh/wnacg/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'WNACG' pkgNameSuffix = 'zh.wnacg' extClass = '.wnacg' - extVersionCode = 2 + extVersionCode = 3 libVersion = '1.2' } diff --git a/src/zh/wnacg/src/eu/kanade/tachiyomi/extension/zh/wnacg/wnacg.kt b/src/zh/wnacg/src/eu/kanade/tachiyomi/extension/zh/wnacg/wnacg.kt index 24839fea5..9a23749c6 100644 --- a/src/zh/wnacg/src/eu/kanade/tachiyomi/extension/zh/wnacg/wnacg.kt +++ b/src/zh/wnacg/src/eu/kanade/tachiyomi/extension/zh/wnacg/wnacg.kt @@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup +import okhttp3.Headers import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document @@ -30,6 +31,7 @@ class wnacg : ParsedHttpSource() { override fun popularMangaRequest(page: Int): Request { return GET("$baseUrl/albums-index-page-$page.html", headers) } + override fun latestUpdatesRequest(page: Int) = throw Exception("Not used") override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { @@ -40,15 +42,24 @@ class wnacg : ParsedHttpSource() { override fun chapterListRequest(manga: SManga) = mangaDetailsRequest(manga) override fun pageListRequest(chapter: SChapter) = GET(baseUrl + chapter.url, headers) + override fun headersBuilder(): Headers.Builder = super.headersBuilder() + .set("referer", baseUrl) + .set("sec-fetch-mode", "no-cors") + .set("sec-fetch-site", "cross-site") + .set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36") override fun popularMangaFromElement(element: Element) = mangaFromElement(element) override fun latestUpdatesFromElement(element: Element) = throw Exception("Not used") override fun searchMangaFromElement(element: Element) = mangaFromElement(element) + private fun mangaFromElement(element: Element): SManga { val manga = SManga.create() manga.setUrlWithoutDomain(element.select("a").first().attr("href")) manga.title = element.select("a").attr("title").trim() - manga.thumbnail_url = "https:" + element.select("img").attr("src") + manga.thumbnail_url = "https://" + element.select("img").attr("data-original").replace("//", "") + // maybe the local cache cause the old source (url) can not be update. but the image can be update on detailpage. + // ps. new machine can be load img normal. + return manga } @@ -74,12 +85,12 @@ class wnacg : ParsedHttpSource() { manga.author = document.select("div.uwuinfo p")?.first()?.text()?.trim() ?: "Unknown" // val glist = document.select("a.tagshow").map { it?.text() } // manga.genre = glist.joinToString(", ") - manga.thumbnail_url = "$baseUrl/" + document.select("div.uwthumb img").first().attr("src") + manga.thumbnail_url = "https://" + document.select("div.uwthumb img").first().attr("data-original").replace("//", "") return manga } override fun pageListParse(document: Document): List { - val regex = "\\/\\/\\S*(jpg)".toRegex() + val regex = "\\/\\/\\S*(jpg|png)".toRegex() val slideaid = client.newCall(GET(baseUrl + document.select("a.btn:containsOwn(下拉閱讀)").attr("href"), headers)).execute().asJsoup() val galleryaid = client.newCall(GET(baseUrl + slideaid.select("script[src$=html]").attr("src"), headers)).execute().asJsoup().toString() val matchresult = regex.findAll(galleryaid).map { it.value }.toList() @@ -89,6 +100,7 @@ class wnacg : ParsedHttpSource() { } return pages } + override fun chapterFromElement(element: Element) = throw Exception("Not used") override fun imageUrlRequest(page: Page) = throw Exception("Not used") override fun imageUrlParse(document: Document) = throw Exception("Not used")