Mangafreak: fix chapter number parser (#11244)

This commit is contained in:
Vetle Ledaal 2022-03-27 19:25:49 +00:00 committed by GitHub
parent 3ebc75464a
commit 9815de6a96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'Mangafreak'
pkgNameSuffix = 'en.mangafreak'
extClass = '.Mangafreak'
extVersionCode = 5
extVersionCode = 6
}

View File

@ -26,6 +26,8 @@ class Mangafreak : ParsedHttpSource() {
override val supportsLatest: Boolean = true
private val floatLetterPattern = Regex("""(\d+)(\.\d+|[a-i]+\b)?""")
override val client: OkHttpClient = network.cloudflareClient.newBuilder()
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES)
@ -122,7 +124,31 @@ class Mangafreak : ParsedHttpSource() {
override fun chapterListSelector(): String = "div.manga_series_list tr:has(a)"
override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply {
name = element.select("td:eq(0)").text()
chapter_number = name.substringAfter("Chapter ").substringBefore(" -").toFloat()
/*
* 123 -> 123
* 123.4 -> 123.4
* 123e -> 123.5 (a=1, b=2, ...)
* j-z is undefined, assume straight substitution
*/
val match = floatLetterPattern.find(name)
chapter_number = if (match == null) {
-1f
} else {
if (match.groupValues[2].isEmpty() || match.groupValues[2][0] == '.') {
match.value.toFloat()
} else {
val sb = StringBuilder("0.")
for (x in match.groupValues[2]) {
sb.append(x.toInt() - 'a'.toInt() + 1)
}
val p2 = sb.toString().toFloat()
val p1 = match.groupValues[1].toFloat()
p1 + p2
}
}
setUrlWithoutDomain(element.select("a").attr("href"))
date_upload = parseDate(element.select("td:eq(1)").text())
}