From 76a7c8c54acadeefc7320127863b2d3cc0176879 Mon Sep 17 00:00:00 2001 From: Vetle Ledaal Date: Sat, 13 Jan 2024 12:37:24 +0000 Subject: [PATCH] Nicomanga: fix cover and image fetching (#214) * Nicomanga: fix cover and image fetching * not extlib 1.5 yet --- src/ja/nicomanga/build.gradle | 2 +- .../extension/ja/nicomanga/Nicomanga.kt | 20 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/ja/nicomanga/build.gradle b/src/ja/nicomanga/build.gradle index 5a62955b4..286fec54c 100644 --- a/src/ja/nicomanga/build.gradle +++ b/src/ja/nicomanga/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Nicomanga' pkgNameSuffix = 'ja.nicomanga' extClass = '.Nicomanga' - extVersionCode = 1 + extVersionCode = 2 } apply from: "$rootDir/common.gradle" diff --git a/src/ja/nicomanga/src/eu/kanade/tachiyomi/extension/ja/nicomanga/Nicomanga.kt b/src/ja/nicomanga/src/eu/kanade/tachiyomi/extension/ja/nicomanga/Nicomanga.kt index 7407700c3..c1273fdd6 100644 --- a/src/ja/nicomanga/src/eu/kanade/tachiyomi/extension/ja/nicomanga/Nicomanga.kt +++ b/src/ja/nicomanga/src/eu/kanade/tachiyomi/extension/ja/nicomanga/Nicomanga.kt @@ -34,6 +34,9 @@ class Nicomanga : HttpSource() { override val client: OkHttpClient = network.cloudflareClient + override fun headersBuilder() = super.headersBuilder() + .add("Referer", "$baseUrl/") + private fun mangaListParse(response: Response): MangasPage { val doc = response.asJsoup() val hasNextPage = ( @@ -113,10 +116,17 @@ class Nicomanga : HttpSource() { override fun chapterListParse(response: Response): List { val doc = response.asJsoup() val chapterList = doc.select("ul > a") + val chapterPrefix = "$baseUrl/app/manga/controllers" + val chapters = chapterList.map { chapter -> SChapter.create().apply { name = chapter.attr("title").trim() - setUrlWithoutDomain(chapter.absUrl("href")) + val url = chapter.absUrl("href").run { + takeIf { startsWith(chapterPrefix) } + ?.replaceFirst(chapterPrefix, baseUrl) + ?: this + } + setUrlWithoutDomain(url) } } return chapters @@ -124,19 +134,13 @@ class Nicomanga : HttpSource() { override fun pageListParse(response: Response): List { val id = chapterIdRegex.find(response.body.string())?.groupValues?.get(1) ?: throw Exception("chapter-id not found") - val headers = headersBuilder().set("referer", response.request.url.toString()).build() val r = client.newCall(GET("$baseUrl/app/manga/controllers/cont.imgsList.php?cid=$id", headers)).execute() val doc = r.asJsoup() return doc.select("img.chapter-img").mapIndexed { i, page -> - Page(i + 1, page.attr("data-src")) + Page(i + 1, imageUrl = page.attr("data-src")) } } - override fun imageRequest(page: Page): Request { - val headers = headersBuilder().set("referer", baseUrl).build() - return GET(page.imageUrl!!, headers) - } - override fun imageUrlParse(response: Response): String = throw UnsupportedOperationException("Not used") }