From 234c317465720045652b189aacfe67b7279458ed Mon Sep 17 00:00:00 2001 From: Mike <51273546+SnakeDoc83@users.noreply.github.com> Date: Sat, 25 Jul 2020 23:55:08 -0400 Subject: [PATCH] Manhuagui - small tweaks (#3901) --- src/zh/manhuagui/build.gradle | 2 +- .../tachiyomi/extension/zh/manhuagui/Manhuagui.kt | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/zh/manhuagui/build.gradle b/src/zh/manhuagui/build.gradle index c498b96d5..78fb2d709 100644 --- a/src/zh/manhuagui/build.gradle +++ b/src/zh/manhuagui/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'ManHuaGui' pkgNameSuffix = 'zh.manhuagui' extClass = '.Manhuagui' - extVersionCode = 2 + extVersionCode = 3 libVersion = '1.2' } diff --git a/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Manhuagui.kt b/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Manhuagui.kt index 64bbb0758..6a6ee3229 100644 --- a/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Manhuagui.kt +++ b/src/zh/manhuagui/src/eu/kanade/tachiyomi/extension/zh/manhuagui/Manhuagui.kt @@ -199,11 +199,13 @@ class Manhuagui : ConfigurableSource, ParsedHttpSource() { } } val chapterList = document.select("ul > li > a.status0") - val latestChapterHref = document.select("div.book-detail > ul.detail-list > li.status > span > a.blue").first().attr("href") + val latestChapterHref = document.select("div.book-detail > ul.detail-list > li.status > span > a.blue").first()?.attr("href") + val chNumRegex = Regex("""\d+""") chapterList.forEach { val currentChapter = SChapter.create() currentChapter.url = it.attr("href") - currentChapter.name = it.attr("title").trim() + currentChapter.name = it?.attr("title")?.trim() ?: it.select("span").first().ownText() + currentChapter.chapter_number = chNumRegex.find(currentChapter.name)?.value?.toFloatOrNull() ?: 0F // Manhuagui only provide upload date for latest chapter if (currentChapter.url == latestChapterHref) { @@ -212,10 +214,10 @@ class Manhuagui : ConfigurableSource, ParsedHttpSource() { chapters.add(currentChapter) } - return chapters + return chapters.sortedByDescending { it.chapter_number } } - private fun parseDate(element: Element): Long = SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).parse(element.text()).time + private fun parseDate(element: Element): Long = SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).parse(element.text())?.time ?: 0 override fun mangaDetailsParse(document: Document): SManga { val manga = SManga.create() @@ -250,13 +252,13 @@ class Manhuagui : ConfigurableSource, ParsedHttpSource() { error("R18作品显示开关未开启或未生效") // "R18 setting didn't enabled or became effective" val html = document.html() - val re = Regex("""window\[".*?"\](\(.*\)\s*\{[\s\S]+\}\s*\(.*\))""") + val re = Regex("""window\[".*?"](\(.*\)\s*\{[\s\S]+}\s*\(.*\))""") val imgCode = re.find(html)?.groups?.get(1)?.value val imgDecode = Duktape.create().use { it.evaluate(jsDecodeFunc + imgCode) as String } - val re2 = Regex("""\{.*\}""") + val re2 = Regex("""\{.*}""") val imgJsonStr = re2.find(imgDecode)?.groups?.get(0)?.value val imageJson: Comic = gson.fromJson(imgJsonStr, Comic::class.java)