From 2f4f7001ea22952cbf37a6207d5ea09dcbcf3499 Mon Sep 17 00:00:00 2001 From: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> Date: Sat, 9 Mar 2024 16:07:26 +0500 Subject: [PATCH] Fix NPEs in some sources (#1773) * Siren Komik: fix NPE * West Manga: fix NPE --- src/id/mangkomik/build.gradle | 4 +- .../extension/id/mangkomik/MangKomik.kt | 29 ----------- .../extension/id/mangkomik/SirenKomik.kt | 51 +++++++++++++++++++ src/id/westmanga/build.gradle | 2 +- .../extension/id/westmanga/WestManga.kt | 34 +++++++++++++ 5 files changed, 88 insertions(+), 32 deletions(-) delete mode 100644 src/id/mangkomik/src/eu/kanade/tachiyomi/extension/id/mangkomik/MangKomik.kt create mode 100644 src/id/mangkomik/src/eu/kanade/tachiyomi/extension/id/mangkomik/SirenKomik.kt diff --git a/src/id/mangkomik/build.gradle b/src/id/mangkomik/build.gradle index e11eb88f2..53ef37c25 100644 --- a/src/id/mangkomik/build.gradle +++ b/src/id/mangkomik/build.gradle @@ -1,9 +1,9 @@ ext { extName = 'Siren Komik' - extClass = '.MangKomik' + extClass = '.SirenKomik' themePkg = 'mangathemesia' baseUrl = 'https://sirenkomik.my.id' - overrideVersionCode = 2 + overrideVersionCode = 3 } apply from: "$rootDir/common.gradle" diff --git a/src/id/mangkomik/src/eu/kanade/tachiyomi/extension/id/mangkomik/MangKomik.kt b/src/id/mangkomik/src/eu/kanade/tachiyomi/extension/id/mangkomik/MangKomik.kt deleted file mode 100644 index 69f450d71..000000000 --- a/src/id/mangkomik/src/eu/kanade/tachiyomi/extension/id/mangkomik/MangKomik.kt +++ /dev/null @@ -1,29 +0,0 @@ -package eu.kanade.tachiyomi.extension.id.mangkomik - -import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia -import eu.kanade.tachiyomi.network.GET -import eu.kanade.tachiyomi.source.model.Page -import org.jsoup.nodes.Document - -class MangKomik : MangaThemesia("Siren Komik", "https://sirenkomik.my.id", "id") { - override val id = 8457447675410081142 - - override val hasProjectPage = true - - override fun pageListParse(document: Document): List { - // Get external JS for image urls - val scriptEl = document.selectFirst("script[data-minify]") - val scriptUrl = scriptEl?.attr("src") - if (scriptUrl.isNullOrEmpty()) { - return super.pageListParse(document) - } - - val scriptResponse = client.newCall( - GET(scriptUrl, headers), - ).execute() - - // Inject external JS - scriptEl.text(scriptResponse.body.string()) - return super.pageListParse(document) - } -} diff --git a/src/id/mangkomik/src/eu/kanade/tachiyomi/extension/id/mangkomik/SirenKomik.kt b/src/id/mangkomik/src/eu/kanade/tachiyomi/extension/id/mangkomik/SirenKomik.kt new file mode 100644 index 000000000..a102ea9d8 --- /dev/null +++ b/src/id/mangkomik/src/eu/kanade/tachiyomi/extension/id/mangkomik/SirenKomik.kt @@ -0,0 +1,51 @@ +package eu.kanade.tachiyomi.extension.id.mangkomik + +import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia +import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.source.model.Page +import eu.kanade.tachiyomi.source.model.SChapter +import org.jsoup.nodes.Document +import org.jsoup.nodes.Element +import java.text.SimpleDateFormat +import java.util.Locale + +class SirenKomik : MangaThemesia( + "Siren Komik", + "https://sirenkomik.my.id", + "id", + dateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale("id")), +) { + override val id = 8457447675410081142 + + override val hasProjectPage = true + + override val seriesTitleSelector = "h1.judul-komik" + override val seriesThumbnailSelector = ".gambar-kecil img" + override val seriesGenreSelector = ".genre-komik a" + override val seriesAuthorSelector = ".keterangan-komik:contains(author) span" + override val seriesArtistSelector = ".keterangan-komik:contains(artist) span" + + override fun chapterFromElement(element: Element) = SChapter.create().apply { + val urlElements = element.select("a") + setUrlWithoutDomain(urlElements.attr("href")) + name = element.select(".nomer-chapter").text().ifBlank { urlElements.first()!!.text() } + date_upload = element.selectFirst(".tgl-chapter")?.text().parseChapterDate() + } + + override fun pageListParse(document: Document): List { + // Get external JS for image urls + val scriptEl = document.selectFirst("script[data-minify]") + val scriptUrl = scriptEl?.attr("src") + if (scriptUrl.isNullOrEmpty()) { + return super.pageListParse(document) + } + + val scriptResponse = client.newCall( + GET(scriptUrl, headers), + ).execute() + + // Inject external JS + scriptEl.text(scriptResponse.body.string()) + return super.pageListParse(document) + } +} diff --git a/src/id/westmanga/build.gradle b/src/id/westmanga/build.gradle index d0c399a9b..f70d13166 100644 --- a/src/id/westmanga/build.gradle +++ b/src/id/westmanga/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.WestManga' themePkg = 'mangathemesia' baseUrl = 'https://westmanga.fun' - overrideVersionCode = 3 + overrideVersionCode = 4 } apply from: "$rootDir/common.gradle" diff --git a/src/id/westmanga/src/eu/kanade/tachiyomi/extension/id/westmanga/WestManga.kt b/src/id/westmanga/src/eu/kanade/tachiyomi/extension/id/westmanga/WestManga.kt index c57502b0d..eb9dc6222 100644 --- a/src/id/westmanga/src/eu/kanade/tachiyomi/extension/id/westmanga/WestManga.kt +++ b/src/id/westmanga/src/eu/kanade/tachiyomi/extension/id/westmanga/WestManga.kt @@ -2,7 +2,10 @@ package eu.kanade.tachiyomi.extension.id.westmanga import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit +import eu.kanade.tachiyomi.source.model.SManga import okhttp3.OkHttpClient +import org.jsoup.nodes.Document +import java.util.Locale class WestManga : MangaThemesia("West Manga", "https://westmanga.fun", "id") { // Formerly "West Manga (WP Manga Stream)" @@ -12,8 +15,39 @@ class WestManga : MangaThemesia("West Manga", "https://westmanga.fun", "id") { .rateLimit(4) .build() + override val seriesTitleSelector = "h1" override val seriesDetailsSelector = ".seriestucontent" override val seriesTypeSelector = ".infotable tr:contains(Type) td:last-child" + override fun mangaDetailsParse(document: Document) = SManga.create().apply { + document.selectFirst(seriesDetailsSelector)!!.let { seriesDetails -> + title = document.selectFirst("div.postbody h1")!!.text() + artist = seriesDetails.selectFirst(seriesArtistSelector)?.ownText().removeEmptyPlaceholder() + author = seriesDetails.selectFirst(seriesAuthorSelector)?.ownText().removeEmptyPlaceholder() + description = seriesDetails.select(seriesDescriptionSelector).joinToString("\n") { it.text() }.trim() + // Add alternative name to manga description + val altName = document.selectFirst(".seriestualt")?.ownText().takeIf { it.isNullOrBlank().not() } + altName?.let { + description = "$description\n\n$altNamePrefix$altName".trim() + } + val genres = seriesDetails.select(seriesGenreSelector).map { it.text() }.toMutableList() + // Add series type (manga/manhwa/manhua/other) to genre + seriesDetails.selectFirst(seriesTypeSelector)?.ownText().takeIf { it.isNullOrBlank().not() }?.let { genres.add(it) } + genre = genres.map { genre -> + genre.lowercase(Locale.forLanguageTag(lang)).replaceFirstChar { char -> + if (char.isLowerCase()) { + char.titlecase(Locale.forLanguageTag(lang)) + } else { + char.toString() + } + } + } + .joinToString { it.trim() } + + status = seriesDetails.selectFirst(seriesStatusSelector)?.text().parseStatus() + thumbnail_url = seriesDetails.select(seriesThumbnailSelector).imgAttr() + } + } + override val hasProjectPage = true }