AnimeXNovel: Fix chapter list (#9806)

* Fix chapter list

* Close connection in chapterListParse

* throws an error when the chapter configuration cannot be performed
This commit is contained in:
Chopper 2025-07-27 03:36:38 -03:00 committed by Draff
parent dad8bbf372
commit 7a09f91cb7
Signed by: Draff
GPG Key ID: E8A89F3211677653
2 changed files with 30 additions and 14 deletions

View File

@ -3,7 +3,7 @@ ext {
extClass = '.AnimeXNovel'
themePkg = 'zeistmanga'
baseUrl = 'https://www.animexnovel.com'
overrideVersionCode = 2
overrideVersionCode = 3
isNsfw = false
}

View File

@ -62,26 +62,36 @@ class AnimeXNovel : ZeistManga(
.map(Element::data)
.firstOrNull(MANGA_TITLE_REGEX::containsMatchIn)?.let {
MANGA_TITLE_REGEX.find(it)?.groups?.get(1)?.value
} ?: return emptyList()
} ?: throw IOException("Manga title not found")
val script = document.select("script")
.map(Element::data)
.firstOrNull(API_KEY_REGEX::containsMatchIn)
?: return emptyList()
.firstOrNull(API_KEYS_REGEX::containsMatchIn)
?: throw IOException("The API keys could not be found.")
val blogId = BLOG_ID_REGEX.find(script)?.groups?.get(1)?.value ?: return emptyList()
val apiKey = API_KEY_REGEX.find(script)?.groups?.get(1)?.value ?: return emptyList()
val blogId = BLOG_ID_REGEX.find(script)?.groups?.get(1)?.value
?: throw IOException("Failed to retrieve blog ID")
val url = "https://www.googleapis.com/blogger/v3/blogs/$blogId/posts".toHttpUrl().newBuilder()
.addQueryParameter("key", apiKey)
.addQueryParameter("labels", label)
.addQueryParameter("maxResults", "500")
.build()
val apiKeys = getApiKeys(script)
?: throw IOException("Failed to retrieve API keys")
val response = client.newCall(GET(url, headers)).execute()
lateinit var response: Response
for (apiKey in apiKeys) {
val url = "https://www.googleapis.com/blogger/v3/blogs/$blogId/posts".toHttpUrl().newBuilder()
.addQueryParameter("key", apiKey)
.addQueryParameter("labels", label)
.addQueryParameter("maxResults", "500")
.build()
response = client.newCall(GET(url, headers)).execute()
if (response.isSuccessful) {
break
}
response.close()
}
if (response.isSuccessful.not()) {
throw IOException("Capítulos não encontrados")
throw IOException("Chapters not found")
}
return response.parseAs<ChapterWrapperDto>().items.map {
@ -93,6 +103,11 @@ class AnimeXNovel : ZeistManga(
}
}
private fun getApiKeys(script: String): List<String>? =
API_KEYS_REGEX.find(script)?.groupValues?.get(1)?.let { content ->
API_KEY_REGEX.findAll(content).map { it.groupValues[1] }.toList()
}
// ============================== Pages ===============================
override val pageListSelector = "#reader .separator"
@ -113,7 +128,8 @@ class AnimeXNovel : ZeistManga(
}
companion object {
private val API_KEY_REGEX = """(?:API_KEY(?:\s+)?=(?:\s+)?.)"([^(\\|")]+)""".toRegex()
private val API_KEY_REGEX = """"([^"]+)"""".toRegex()
private val API_KEYS_REGEX = """const\s+API_KEYS\s*=\s*\[\s*([\s\S]*?)\s*];""".toRegex()
private val BLOG_ID_REGEX = """(?:BLOG_ID(?:\s+)?=(?:\s+)?.)"([^(\\|")]+)""".toRegex()
private val MANGA_TITLE_REGEX = """iniciarCapituloLoader\("([^"]+)"\)""".toRegex()
private val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.ROOT)