MANGA REGEX FIX

This commit is contained in:
rebelonion 2024-01-18 21:32:49 -06:00
parent 0d32342765
commit b1eedce229

View file

@ -6,6 +6,7 @@ import java.util.regex.Pattern
class MangaNameAdapter { class MangaNameAdapter {
companion object { companion object {
const val chapterRegex = "(chapter|chap|ch|c)[\\s:.\\-]*([\\d]+\\.?[\\d]*)[\\s:.\\-]*" const val chapterRegex = "(chapter|chap|ch|c)[\\s:.\\-]*([\\d]+\\.?[\\d]*)[\\s:.\\-]*"
const val filedChapterNumberRegex = "(?<!part\\s)\\b(\\d+)\\b"
fun findChapterNumber(text: String): Float? { fun findChapterNumber(text: String): Float? {
val pattern: Pattern = Pattern.compile(chapterRegex, Pattern.CASE_INSENSITIVE) val pattern: Pattern = Pattern.compile(chapterRegex, Pattern.CASE_INSENSITIVE)
val matcher: Matcher = pattern.matcher(text) val matcher: Matcher = pattern.matcher(text)
@ -13,7 +14,15 @@ class MangaNameAdapter {
return if (matcher.find()) { return if (matcher.find()) {
matcher.group(2)?.toFloat() matcher.group(2)?.toFloat()
} else { } else {
null val failedChapterNumberPattern: Pattern =
Pattern.compile(filedChapterNumberRegex, Pattern.CASE_INSENSITIVE)
val failedChapterNumberMatcher: Matcher =
failedChapterNumberPattern.matcher(text)
if (failedChapterNumberMatcher.find()) {
failedChapterNumberMatcher.group(1)?.toFloat()
} else {
null
}
} }
} }
} }