mirror of
https://github.com/mihonapp/mihon.git
synced 2025-08-26 16:11:31 +02:00
Compare commits
2 Commits
87fe64468c
...
6a80305d6c
Author | SHA1 | Date | |
---|---|---|---|
|
6a80305d6c | ||
|
119bcbf8ed |
@@ -17,14 +17,20 @@ class CategoriesRestorer(
|
||||
if (backupCategories.isNotEmpty()) {
|
||||
val dbCategories = getCategories.await()
|
||||
val dbCategoriesByName = dbCategories.associateBy { it.name }
|
||||
var nextOrder = dbCategories.maxOfOrNull { it.order }?.plus(1) ?: 0
|
||||
|
||||
val categories = backupCategories.map {
|
||||
dbCategoriesByName[it.name]
|
||||
?: handler.awaitOneExecutable {
|
||||
categoriesQueries.insert(it.name, it.order, it.flags)
|
||||
val categories = backupCategories
|
||||
.sortedBy { it.order }
|
||||
.map {
|
||||
val dbCategory = dbCategoriesByName[it.name]
|
||||
if (dbCategory != null) return@map dbCategory
|
||||
val order = nextOrder++
|
||||
handler.awaitOneExecutable {
|
||||
categoriesQueries.insert(it.name, order, it.flags)
|
||||
categoriesQueries.selectLastInsertedRowId()
|
||||
}.let { id -> it.toCategory(id) }
|
||||
}
|
||||
}
|
||||
.let { id -> it.toCategory(id).copy(order = order) }
|
||||
}
|
||||
|
||||
libraryPreferences.categorizedDisplaySettings().set(
|
||||
(dbCategories + categories)
|
||||
|
@@ -41,27 +41,35 @@ object ChapterRecognition {
|
||||
}
|
||||
|
||||
// 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.
|
||||
name = name.replace(mangaTitle.lowercase(), "").trim()
|
||||
val numberMatch = number.findAll(cleanChapterName)
|
||||
|
||||
// Remove comma's or hyphens.
|
||||
name = name.replace(',', '.').replace('-', '.')
|
||||
when {
|
||||
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.
|
||||
name = unwantedWhiteSpace.replace(name, "")
|
||||
// need to find again first number might already removed
|
||||
number.find(name)?.let { return getChapterNumberFromMatch(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove unwanted tags.
|
||||
name = unwanted.replace(name, "")
|
||||
|
||||
// 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
|
||||
// return the first number encountered
|
||||
return getChapterNumberFromMatch(numberMatch.first())
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -171,6 +171,17 @@ class ChapterRecognitionTest {
|
||||
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
|
||||
fun `Unparseable chapter`() {
|
||||
val mangaTitle = "random"
|
||||
|
Reference in New Issue
Block a user