Fix mangakatana Image array not found (#13194)

Mangakatana updated their javascript again and
is using the ytaw variable again as the array of images.
To make sure mangakatana keeps working even if the website changes back
and forth we check both variables and choose the array that is most
likely the one with all of the pages.

Closes #13188
This commit is contained in:
dec05eba 2022-08-26 04:20:56 +02:00 committed by GitHub
parent 0e13a3f0be
commit 3fc3a8261d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 8 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'MangaKatana'
pkgNameSuffix = 'en.mangakatana'
extClass = '.MangaKatana'
extVersionCode = 7
extVersionCode = 8
}
apply from: "$rootDir/common.gradle"

View File

@ -179,7 +179,8 @@ class MangaKatana : ConfigurableSource, ParsedHttpSource() {
date_upload = dateFormat.parse(element.select(".update_time").text())?.time ?: 0
}
private val imageArrayRegex = Regex("""var htnc=\[([^\[]*)]""")
private val imageArrayYtawRegex = Regex("""var ytaw=\[([^\[]*)]""")
private val imageArrayHtncRegex = Regex("""var htnc=\[([^\[]*)]""")
private val imageUrlRegex = Regex("""'([^']*)'""")
// Page List
@ -190,12 +191,28 @@ class MangaKatana : ConfigurableSource, ParsedHttpSource() {
}
override fun pageListParse(document: Document): List<Page> {
val imageArray = document.select("script:containsData(var htnc)").firstOrNull()?.data()
?.let { imageArrayRegex.find(it)?.groupValues?.get(1) }
?: throw Exception("Image array not found")
return imageUrlRegex.findAll(imageArray).asIterable().mapIndexed { i, mr ->
Page(i, "", mr.groupValues[1])
}
val imageArrayYtaw = document.select("script:containsData(var ytaw)").firstOrNull()?.data()
?.let { imageArrayYtawRegex.find(it)?.groupValues?.get(1) }
val imageArrayHtnc = document.select("script:containsData(var htnc)").firstOrNull()?.data()
?.let { imageArrayHtncRegex.find(it)?.groupValues?.get(1) }
val pagesYtaw =
imageArrayYtaw?.let {
imageUrlRegex.findAll(it).asIterable().mapIndexed { i, mr ->
Page(i, "", mr.groupValues[1])
}
} ?: emptyList()
val pagesHtnc =
imageArrayHtnc?.let {
imageUrlRegex.findAll(it).asIterable().mapIndexed { i, mr ->
Page(i, "", mr.groupValues[1])
}
} ?: emptyList()
return if (pagesYtaw.size >= pagesHtnc.size)
pagesYtaw
else
pagesHtnc
}
override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not Used")