From 79bdda34b2093120e239e12335fccdc4ac105648 Mon Sep 17 00:00:00 2001 From: Alan Tan Date: Mon, 1 Sep 2025 17:05:33 +0800 Subject: [PATCH] Goda (baozimhorg): Update api url (#10299) * baozimhorg: Update api url * baozimhorg: fix unparseable date * baozimhorg: version bump * baozimhorg: fix some chapter is missing api v3 return different result depending if there is origin or not * baozimhorg: cleanup * baozimhorg: update parseDate function Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com> * baozimhorg: update parseDate function * Update headers Co-authored-by: Vetle Ledaal --------- Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Co-authored-by: Vetle Ledaal --- src/zh/baozimhorg/build.gradle | 2 +- .../tachiyomi/extension/zh/baozimhorg/Dto.kt | 21 +++++++++++++++---- .../extension/zh/baozimhorg/GoDaManhua.kt | 6 ++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/zh/baozimhorg/build.gradle b/src/zh/baozimhorg/build.gradle index 24cb1b094..67256995e 100644 --- a/src/zh/baozimhorg/build.gradle +++ b/src/zh/baozimhorg/build.gradle @@ -2,7 +2,7 @@ ext { extName = 'GoDa' extClass = '.GoDaManhua' themePkg = 'goda' - overrideVersionCode = 31 + overrideVersionCode = 32 } apply from: "$rootDir/common.gradle" diff --git a/src/zh/baozimhorg/src/eu/kanade/tachiyomi/extension/zh/baozimhorg/Dto.kt b/src/zh/baozimhorg/src/eu/kanade/tachiyomi/extension/zh/baozimhorg/Dto.kt index a581abbb1..277bd00c9 100644 --- a/src/zh/baozimhorg/src/eu/kanade/tachiyomi/extension/zh/baozimhorg/Dto.kt +++ b/src/zh/baozimhorg/src/eu/kanade/tachiyomi/extension/zh/baozimhorg/Dto.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.extension.zh.baozimhorg import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import kotlinx.serialization.Serializable +import java.text.ParsePosition import java.text.SimpleDateFormat import java.util.Locale import java.util.TimeZone @@ -40,13 +41,25 @@ class AttributesDto( fun toSChapter(mangaSlug: String, mangaId: String, chapterId: String) = SChapter.create().apply { url = "$mangaSlug/$slug#$mangaId/$chapterId" name = title - date_upload = dateFormat.parse(updatedAt)!!.time + date_upload = parseDate(updatedAt) } } -// Static field, no need for lazy -private val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US).apply { - timeZone = TimeZone.getTimeZone("UTC") +private val formats = listOf( + SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US).apply { + timeZone = TimeZone.getTimeZone("UTC") + }, + SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US).apply { + timeZone = TimeZone.getTimeZone("UTC") + }, +) + +fun parseDate(dateString: String): Long { + for (format in formats) { + val date = format.parse(dateString, ParsePosition(0)) ?: continue + return date.time + } + throw IllegalArgumentException("Unable to parse date: $dateString") } @Serializable diff --git a/src/zh/baozimhorg/src/eu/kanade/tachiyomi/extension/zh/baozimhorg/GoDaManhua.kt b/src/zh/baozimhorg/src/eu/kanade/tachiyomi/extension/zh/baozimhorg/GoDaManhua.kt index 7938298a2..9f576b43a 100644 --- a/src/zh/baozimhorg/src/eu/kanade/tachiyomi/extension/zh/baozimhorg/GoDaManhua.kt +++ b/src/zh/baozimhorg/src/eu/kanade/tachiyomi/extension/zh/baozimhorg/GoDaManhua.kt @@ -23,6 +23,8 @@ class GoDaManhua : GoDa("GoDa漫画", "", "zh"), ConfigurableSource { override val baseUrl: String + override fun headersBuilder() = super.headersBuilder().add("Referer", "$baseUrl/").add("Origin", baseUrl) + init { val mirrors = MIRRORS if (System.getenv("CI") == "true") { @@ -39,13 +41,13 @@ class GoDaManhua : GoDa("GoDa漫画", "", "zh"), ConfigurableSource { private val json: Json = Injekt.get() override fun fetchChapterList(mangaId: String): List { - val response = client.newCall(GET("https://api-get-v2.mgsearcher.com/api/manga/get?mid=$mangaId&mode=all", headers)).execute() + val response = client.newCall(GET("https://api-get-v3.mgsearcher.com/api/manga/get?mid=$mangaId&mode=all", headers)).execute() return json.decodeFromString>(response.body.string()).data.toChapterList() } override fun pageListRequest(mangaId: String, chapterId: String): Request { if (mangaId.isEmpty() || chapterId.isEmpty()) throw Exception("请刷新漫画") - return GET("https://api-get-v2.mgsearcher.com/api/chapter/getinfo?m=$mangaId&c=$chapterId", headers) + return GET("https://api-get-v3.mgsearcher.com/api/chapter/getinfo?m=$mangaId&c=$chapterId", headers) } override fun pageListParse(response: Response): List {