mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 02:34:39 +00:00
refactor(chapter): Make chapter recognition return its value
Also move it to domain module
This commit is contained in:
parent
1cd40907ef
commit
497d387c4b
3 changed files with 26 additions and 30 deletions
|
@ -9,7 +9,6 @@ import eu.kanade.tachiyomi.source.model.FilterList
|
|||
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.util.chapter.ChapterRecognition
|
||||
import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder
|
||||
import eu.kanade.tachiyomi.util.storage.EpubFile
|
||||
import eu.kanade.tachiyomi.util.storage.fillMetadata
|
||||
|
@ -19,6 +18,10 @@ import eu.kanade.tachiyomi.util.system.extension
|
|||
import eu.kanade.tachiyomi.util.system.nameWithoutExtension
|
||||
import eu.kanade.tachiyomi.util.system.withIOContext
|
||||
import eu.kanade.tachiyomi.util.system.writeText
|
||||
import java.io.FileInputStream
|
||||
import java.io.InputStream
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.concurrent.*
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.serialization.Serializable
|
||||
|
@ -34,13 +37,10 @@ import yokai.core.metadata.COMIC_INFO_FILE
|
|||
import yokai.core.metadata.ComicInfo
|
||||
import yokai.core.metadata.copyFromComicInfo
|
||||
import yokai.core.metadata.toComicInfo
|
||||
import yokai.domain.chapter.services.ChapterRecognition
|
||||
import yokai.domain.storage.StorageManager
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
import java.io.FileInputStream
|
||||
import java.io.InputStream
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.concurrent.*
|
||||
|
||||
class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSource {
|
||||
companion object {
|
||||
|
@ -101,9 +101,9 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
|
|||
val comicInfo = decodeComicInfo(stream)
|
||||
|
||||
comicInfo.title?.let { chapter.name = it.value }
|
||||
comicInfo.number?.value?.toFloatOrNull()?.let {
|
||||
chapter.chapter_number = it
|
||||
} ?: ChapterRecognition.parseChapterNumber(chapter, manga)
|
||||
chapter.chapter_number =
|
||||
comicInfo.number?.value?.toFloatOrNull()
|
||||
?: ChapterRecognition.parseChapterNumber(chapter.name, manga.title, chapter.chapter_number)
|
||||
comicInfo.translator?.let { chapter.scanlator = it.value }
|
||||
}
|
||||
|
||||
|
@ -297,7 +297,10 @@ class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSour
|
|||
date_upload = chapterFile.lastModified()
|
||||
|
||||
val success = updateMetadata(this, manga, chapterFile)
|
||||
if (!success) ChapterRecognition.parseChapterNumber(this, manga)
|
||||
if (!success) {
|
||||
chapter_number =
|
||||
ChapterRecognition.parseChapterNumber(this.name, manga.title, this.chapter_number)
|
||||
}
|
||||
}
|
||||
}
|
||||
.sortedWith { c1, c2 ->
|
||||
|
|
|
@ -6,6 +6,7 @@ import eu.kanade.tachiyomi.domain.manga.models.Manga
|
|||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import java.util.*
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
@ -15,9 +16,9 @@ import yokai.domain.chapter.interactor.GetChapter
|
|||
import yokai.domain.chapter.interactor.InsertChapter
|
||||
import yokai.domain.chapter.interactor.UpdateChapter
|
||||
import yokai.domain.chapter.models.ChapterUpdate
|
||||
import yokai.domain.chapter.services.ChapterRecognition
|
||||
import yokai.domain.manga.interactor.UpdateManga
|
||||
import yokai.domain.manga.models.MangaUpdate
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Helper method for syncing the list of chapters from the source with the ones from the database.
|
||||
|
@ -76,7 +77,8 @@ suspend fun syncChaptersWithSource(
|
|||
source.prepareNewChapter(sourceChapter, manga)
|
||||
}
|
||||
|
||||
ChapterRecognition.parseChapterNumber(sourceChapter, manga)
|
||||
sourceChapter.chapter_number =
|
||||
ChapterRecognition.parseChapterNumber(sourceChapter.name, manga.title, sourceChapter.chapter_number)
|
||||
|
||||
if (shouldUpdateDbChapter(dbChapter, sourceChapter)) {
|
||||
if ((dbChapter.name != sourceChapter.name || dbChapter.scanlator != sourceChapter.scanlator) &&
|
||||
|
@ -102,7 +104,7 @@ suspend fun syncChaptersWithSource(
|
|||
if (source is HttpSource) {
|
||||
source.prepareNewChapter(it, manga)
|
||||
}
|
||||
ChapterRecognition.parseChapterNumber(it, manga)
|
||||
it.chapter_number = ChapterRecognition.parseChapterNumber(it.name, manga.title, it.chapter_number)
|
||||
}
|
||||
|
||||
// Chapters from the db not in the source.
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
package eu.kanade.tachiyomi.util.chapter
|
||||
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
package yokai.domain.chapter.services
|
||||
|
||||
/**
|
||||
* -R> = regex conversion.
|
||||
|
@ -33,17 +30,17 @@ object ChapterRecognition {
|
|||
*/
|
||||
private val unwantedWhiteSpace = Regex("""\s(?=extra|special|omake)""")
|
||||
|
||||
fun parseChapterNumber(chapter: SChapter, manga: SManga) {
|
||||
fun parseChapterNumber(chapterName: String, mangaTitle: String, chapterNumber: Float? = null): Float {
|
||||
// If chapter number is known return.
|
||||
if (chapter.chapter_number == -2f || chapter.chapter_number > -1f) {
|
||||
return
|
||||
if (chapterNumber != null && (chapterNumber == -2f || chapterNumber > -1f)) {
|
||||
return chapterNumber
|
||||
}
|
||||
|
||||
// Get chapter title with lower case
|
||||
var name = chapter.name.lowercase()
|
||||
var name = chapterName.lowercase()
|
||||
|
||||
// Remove manga title from chapter title.
|
||||
name = name.replace(manga.title.lowercase(), "").trim()
|
||||
name = name.replace(mangaTitle.lowercase(), "").trim()
|
||||
|
||||
// Remove comma's or hyphens.
|
||||
name = name.replace(',', '.').replace('-', '.')
|
||||
|
@ -54,17 +51,11 @@ object ChapterRecognition {
|
|||
// Remove unwanted tags.
|
||||
name = unwanted.replace(name, "")
|
||||
|
||||
basic.find(name)?.let {
|
||||
chapter.chapter_number = getChapterNumberFromMatch(it)
|
||||
return
|
||||
}
|
||||
basic.find(name)?.let { return getChapterNumberFromMatch(it) }
|
||||
|
||||
number.find(name)?.let {
|
||||
chapter.chapter_number = getChapterNumberFromMatch(it)
|
||||
return
|
||||
}
|
||||
number.find(name)?.let { return getChapterNumberFromMatch(it) }
|
||||
|
||||
// if (chapter.chapter_number == null) chapter.chapter_number = -1f
|
||||
return chapterNumber ?: -1f
|
||||
}
|
||||
|
||||
/**
|
Loading…
Add table
Add a link
Reference in a new issue