From 348c373bc049fbddd58aaf7a113862f800794ef6 Mon Sep 17 00:00:00 2001 From: are-are-are <62763969+dejavui@users.noreply.github.com> Date: Fri, 29 Nov 2024 03:45:10 +0700 Subject: [PATCH] Hennojin: Fix chapter not found for Suwayomi user (#6296) * Fix chapter not found for Suwayomi user * Update changes by vetleledaal * Fix build * Revert old code URL, because code new URL doesn't work * Update url * make thumbnail optional * use .absUrl() where possible --------- Co-authored-by: Vetle Ledaal --- src/all/hennojin/build.gradle | 2 +- .../extension/all/hennojin/Hennojin.kt | 99 ++++++++++++------- .../extension/all/hennojin/HennojinFactory.kt | 4 +- 3 files changed, 67 insertions(+), 38 deletions(-) diff --git a/src/all/hennojin/build.gradle b/src/all/hennojin/build.gradle index e0897dd19..87eba06d5 100644 --- a/src/all/hennojin/build.gradle +++ b/src/all/hennojin/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Hennojin' extClass = '.HennojinFactory' - extVersionCode = 1 + extVersionCode = 2 isNsfw = true } diff --git a/src/all/hennojin/src/eu/kanade/tachiyomi/extension/all/hennojin/Hennojin.kt b/src/all/hennojin/src/eu/kanade/tachiyomi/extension/all/hennojin/Hennojin.kt index 208b0af7f..c5fd4a7d4 100644 --- a/src/all/hennojin/src/eu/kanade/tachiyomi/extension/all/hennojin/Hennojin.kt +++ b/src/all/hennojin/src/eu/kanade/tachiyomi/extension/all/hennojin/Hennojin.kt @@ -1,30 +1,32 @@ package eu.kanade.tachiyomi.extension.all.hennojin import eu.kanade.tachiyomi.network.GET -import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.Page 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.HttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element +import org.jsoup.select.Evaluator import java.text.SimpleDateFormat import java.util.Locale -class Hennojin(override val lang: String, suffix: String) : ParsedHttpSource() { - override val baseUrl = "https://hennojin.com/home/$suffix" +class Hennojin(override val lang: String) : ParsedHttpSource() { + override val baseUrl = "https://hennojin.com" override val name = "Hennojin" // Popular is latest override val supportsLatest = false - private val httpUrl by lazy { baseUrl.toHttpUrl() } + private val httpUrl by lazy { "$baseUrl/home".toHttpUrl() } override fun latestUpdatesSelector() = popularMangaSelector() @@ -41,15 +43,23 @@ class Hennojin(override val lang: String, suffix: String) : ParsedHttpSource() { override fun popularMangaNextPageSelector() = ".paginate .next" override fun popularMangaRequest(page: Int) = - httpUrl.request { addEncodedPathSegments("page/$page") } + httpUrl.request { + when (lang) { + "ja" -> { + addEncodedPathSegments("page/$page/") + addQueryParameter("archive", "raw") + } + else -> addEncodedPathSegments("page/$page") + } + } override fun popularMangaFromElement(element: Element) = SManga.create().apply { element.selectFirst(".title_link > a").let { title = it!!.text() - setUrlWithoutDomain(it.attr("href")) + setUrlWithoutDomain(it.absUrl("href")) } - thumbnail_url = element.selectFirst("img")!!.attr("src") + thumbnail_url = element.selectFirst("img")?.absUrl("src") } override fun searchMangaSelector() = popularMangaSelector() @@ -66,46 +76,68 @@ class Hennojin(override val lang: String, suffix: String) : ParsedHttpSource() { override fun searchMangaFromElement(element: Element) = popularMangaFromElement(element) - override fun mangaDetailsRequest(manga: SManga) = - GET("https://hennojin.com" + manga.url, headers) - override fun mangaDetailsParse(document: Document) = SManga.create().apply { - description = document.selectFirst( + description = document.select( ".manga-subtitle + p + p", - )?.html()?.replace("
", "\n") + ).joinToString("\n") { + it + .apply { select(Evaluator.Tag("br")).prepend("\\n") } + .text() + .replace("\\n", "\n") + .replace("\n ", "\n") + }.trim() genre = document.select( ".tags-list a[href*=/parody/]," + ".tags-list a[href*=/tags/]," + ".tags-list a[href*=/character/]", - )?.joinToString { it.text() } - artist = document.select( + ).joinToString { it.text() } + artist = document.selectFirst( ".tags-list a[href*=/artist/]", - )?.joinToString { it.text() } - author = document.select( + )?.text() + author = document.selectFirst( ".tags-list a[href*=/group/]", - )?.joinToString { it.text() } ?: artist + )?.text() ?: artist status = SManga.COMPLETED } - override fun fetchChapterList(manga: SManga) = - Request.Builder().url(manga.thumbnail_url!!) - .head().build().run(client::newCall) - .asObservableSuccess().map { res -> - SChapter.create().apply { - name = "Chapter" - url = manga.reader - date_upload = res.date - chapter_number = -1f - }.let(::listOf) - }!! - - override fun pageListRequest(chapter: SChapter) = - GET("https://hennojin.com" + chapter.url, headers) + override fun chapterListParse(response: Response): List { + val document = response.asJsoup(response.body.string()) + val date = document + .selectFirst(".manga-thumbnail > img") + ?.absUrl("src") + ?.let { url -> + Request.Builder() + .url(url) + .head() + .build() + .run(client::newCall) + .execute() + .date + } + return document.select("a:contains(Read Online)").map { + SChapter.create().apply { + setUrlWithoutDomain( + it + ?.absUrl("href") + ?.toHttpUrlOrNull() + ?.newBuilder() + ?.removeAllQueryParameters("view") + ?.addQueryParameter("view", "multi") + ?.build() + ?.toString() + ?: it.absUrl("href"), + ) + name = "Chapter" + date?.run { date_upload = this } + chapter_number = -1f + } + } + } override fun pageListParse(document: Document) = document.select(".slideshow-container > img") - .mapIndexed { idx, img -> Page(idx, "", img.absUrl("src")) } + .mapIndexed { idx, img -> Page(idx, imageUrl = img.absUrl("src")) } private inline fun HttpUrl.request( block: HttpUrl.Builder.() -> HttpUrl.Builder, @@ -114,9 +146,6 @@ class Hennojin(override val lang: String, suffix: String) : ParsedHttpSource() { private inline val Response.date: Long get() = headers["Last-Modified"]?.run(httpDate::parse)?.time ?: 0L - private inline val SManga.reader: String - get() = "/home/manga-reader/?manga=$title&view=multi" - override fun chapterListSelector() = throw UnsupportedOperationException() diff --git a/src/all/hennojin/src/eu/kanade/tachiyomi/extension/all/hennojin/HennojinFactory.kt b/src/all/hennojin/src/eu/kanade/tachiyomi/extension/all/hennojin/HennojinFactory.kt index 3ebf6fe62..3b7d8cb2a 100644 --- a/src/all/hennojin/src/eu/kanade/tachiyomi/extension/all/hennojin/HennojinFactory.kt +++ b/src/all/hennojin/src/eu/kanade/tachiyomi/extension/all/hennojin/HennojinFactory.kt @@ -4,7 +4,7 @@ import eu.kanade.tachiyomi.source.SourceFactory class HennojinFactory : SourceFactory { override fun createSources() = listOf( - Hennojin("en", ""), - Hennojin("ja", "?archive=raw"), + Hennojin("en"), + Hennojin("ja"), ) }