mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-14 20:39:59 -05:00
Fix chapter number parsing when number is after unwanted tag
Fixes #554 Co-authored-by: Naputt1 <94742489+Naputt1@users.noreply.github.com>
This commit is contained in:
parent
119bcbf8ed
commit
6a80305d6c
2 changed files with 36 additions and 17 deletions
|
@ -41,27 +41,35 @@ object ChapterRecognition {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get chapter title with lower case
|
// Get chapter title with lower case
|
||||||
var name = chapterName.lowercase()
|
val cleanChapterName = chapterName.lowercase()
|
||||||
|
// Remove manga title from chapter title.
|
||||||
|
.replace(mangaTitle.lowercase(), "").trim()
|
||||||
|
// Remove comma's or hyphens.
|
||||||
|
.replace(',', '.')
|
||||||
|
.replace('-', '.')
|
||||||
|
// Remove unwanted white spaces.
|
||||||
|
.replace(unwantedWhiteSpace, "")
|
||||||
|
|
||||||
// Remove manga title from chapter title.
|
val numberMatch = number.findAll(cleanChapterName)
|
||||||
name = name.replace(mangaTitle.lowercase(), "").trim()
|
|
||||||
|
|
||||||
// Remove comma's or hyphens.
|
when {
|
||||||
name = name.replace(',', '.').replace('-', '.')
|
numberMatch.none() -> {
|
||||||
|
return chapterNumber ?: -1.0
|
||||||
|
}
|
||||||
|
numberMatch.count() > 1 -> {
|
||||||
|
// Remove unwanted tags.
|
||||||
|
unwanted.replace(cleanChapterName, "").let { name ->
|
||||||
|
// Check base case ch.xx
|
||||||
|
basic.find(name)?.let { return getChapterNumberFromMatch(it) }
|
||||||
|
|
||||||
// Remove unwanted white spaces.
|
// need to find again first number might already removed
|
||||||
name = unwantedWhiteSpace.replace(name, "")
|
number.find(name)?.let { return getChapterNumberFromMatch(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove unwanted tags.
|
// return the first number encountered
|
||||||
name = unwanted.replace(name, "")
|
return getChapterNumberFromMatch(numberMatch.first())
|
||||||
|
|
||||||
// Check base case ch.xx
|
|
||||||
basic.find(name)?.let { return getChapterNumberFromMatch(it) }
|
|
||||||
|
|
||||||
// Take the first number encountered.
|
|
||||||
number.find(name)?.let { return getChapterNumberFromMatch(it) }
|
|
||||||
|
|
||||||
return chapterNumber ?: -1.0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -171,6 +171,17 @@ class ChapterRecognitionTest {
|
||||||
assertChapter(mangaTitle, "Tokyo ESP 027: Part 002: Chapter 001", 027.0)
|
assertChapter(mangaTitle, "Tokyo ESP 027: Part 002: Chapter 001", 027.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Case where the chapter title contains the unwanted tag
|
||||||
|
* But follow by chapter number.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun `Number after unwanted tag`() {
|
||||||
|
val mangaTitle = "One-punch Man"
|
||||||
|
|
||||||
|
assertChapter(mangaTitle, "Mag Version 195.5", 195.5)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `Unparseable chapter`() {
|
fun `Unparseable chapter`() {
|
||||||
val mangaTitle = "random"
|
val mangaTitle = "random"
|
||||||
|
|
Loading…
Reference in a new issue