Mangabz: Fix StringIndexOutOfBoundsException (#9710)
* Mangabz: Fix StringIndexOutOfBoundsException StringIndexOutOfBoundsException happens when description is the same as title * fix description * remove some lazys since JVM guarantees initialization only when calling this file --------- Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com>
This commit is contained in:
parent
b09647744c
commit
1f8bb317b6
@ -1,7 +1,7 @@
|
|||||||
ext {
|
ext {
|
||||||
extName = 'Mangabz'
|
extName = 'Mangabz'
|
||||||
extClass = '.Mangabz'
|
extClass = '.Mangabz'
|
||||||
extVersionCode = 11
|
extVersionCode = 12
|
||||||
isNsfw = false
|
isNsfw = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,10 +29,10 @@ fun parseDateInternal(source: String): Long {
|
|||||||
return fullDateFormat.parse(source)!!.time
|
return fullDateFormat.parse(source)!!.time
|
||||||
}
|
}
|
||||||
|
|
||||||
private val recentRegex by lazy { Regex("""[今昨前]天 \d{2}:\d{2}""") }
|
private val recentRegex = Regex("""[今昨前]天 \d{2}:\d{2}""")
|
||||||
private val timeFormat by lazy { cstFormat("yyyy-MM-dd hh:mm") }
|
private val timeFormat = cstFormat("yyyy-MM-dd hh:mm")
|
||||||
private val shortDateFormat by lazy { cstFormat("yyyy MM月dd") }
|
private val shortDateFormat = cstFormat("yyyy MM月dd")
|
||||||
private val fullDateFormat by lazy { cstFormat("yyyy-MM-dd") }
|
private val fullDateFormat = cstFormat("yyyy-MM-dd")
|
||||||
|
|
||||||
private fun cstFormat(pattern: String) =
|
private fun cstFormat(pattern: String) =
|
||||||
SimpleDateFormat(pattern, Locale.ENGLISH).apply { timeZone = TimeZone.getTimeZone("GMT+8") }
|
SimpleDateFormat(pattern, Locale.ENGLISH).apply { timeZone = TimeZone.getTimeZone("GMT+8") }
|
||||||
|
@ -26,7 +26,7 @@ import rx.Observable
|
|||||||
|
|
||||||
class Mangabz : MangabzTheme("Mangabz"), ConfigurableSource {
|
class Mangabz : MangabzTheme("Mangabz"), ConfigurableSource {
|
||||||
|
|
||||||
private val _baseUrl: String
|
override val baseUrl: String
|
||||||
override val client: OkHttpClient
|
override val client: OkHttpClient
|
||||||
|
|
||||||
private val urlSuffix: String
|
private val urlSuffix: String
|
||||||
@ -34,7 +34,10 @@ class Mangabz : MangabzTheme("Mangabz"), ConfigurableSource {
|
|||||||
init {
|
init {
|
||||||
val preferences = getPreferences()
|
val preferences = getPreferences()
|
||||||
val mirror = preferences.mirror
|
val mirror = preferences.mirror
|
||||||
_baseUrl = "https://" + mirror.domain
|
baseUrl = when (System.getenv("CI")) {
|
||||||
|
"true" -> MIRRORS.joinToString("#, ") { "https://" + it.domain }
|
||||||
|
else -> "https://" + mirror.domain
|
||||||
|
}
|
||||||
urlSuffix = mirror.urlSuffix
|
urlSuffix = mirror.urlSuffix
|
||||||
|
|
||||||
val cookieInterceptor = CookieInterceptor(mirror.domain, mirror.langCookie to preferences.lang)
|
val cookieInterceptor = CookieInterceptor(mirror.domain, mirror.langCookie to preferences.lang)
|
||||||
@ -44,14 +47,8 @@ class Mangabz : MangabzTheme("Mangabz"), ConfigurableSource {
|
|||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val isCi = System.getenv("CI") == "true"
|
|
||||||
override val baseUrl get() = when {
|
|
||||||
isCi -> MIRRORS.joinToString("#, ") { "https://" + it.domain }
|
|
||||||
else -> _baseUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun headersBuilder() = Headers.Builder()
|
override fun headersBuilder() = Headers.Builder()
|
||||||
.add("Referer", _baseUrl)
|
.add("Referer", baseUrl)
|
||||||
.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0")
|
.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0")
|
||||||
|
|
||||||
private fun SManga.stripMirror() = apply {
|
private fun SManga.stripMirror() = apply {
|
||||||
@ -95,10 +92,10 @@ class Mangabz : MangabzTheme("Mangabz"), ConfigurableSource {
|
|||||||
|
|
||||||
override fun parseDescription(element: Element, title: String, details: Elements): String {
|
override fun parseDescription(element: Element, title: String, details: Elements): String {
|
||||||
val text = element.ownText()
|
val text = element.ownText()
|
||||||
val start = if (text.startsWith(title)) title.length + 4 else 0
|
val start = text.removePrefix("${title}漫画 ,").removePrefix("${title}漫畫 ,")
|
||||||
val collapsed = element.selectFirst(Evaluator.Tag("span"))?.ownText()
|
val collapsed = element.selectFirst(Evaluator.Tag("span"))?.ownText()
|
||||||
?: return text.substring(start)
|
?: return start
|
||||||
return buildString { append(text, start, text.length - 1).append(collapsed) }
|
return start + collapsed
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun chapterListRequest(manga: SManga) = GET(baseUrl + manga.url.toMirror(), headers)
|
override fun chapterListRequest(manga: SManga) = GET(baseUrl + manga.url.toMirror(), headers)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user