mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Fix download chapter dir when scanlator is empty or changed (#7780)
This commit is contained in:
parent
97656935a2
commit
1f9f9662bc
3 changed files with 24 additions and 8 deletions
|
@ -103,8 +103,13 @@ class SyncChaptersWithSource(
|
|||
toAdd.add(toAddChapter)
|
||||
} else {
|
||||
if (shouldUpdateDbChapter.await(dbChapter, chapter)) {
|
||||
if (dbChapter.name != chapter.name && downloadManager.isChapterDownloaded(dbChapter.name, dbChapter.scanlator, manga.title, manga.source)) {
|
||||
downloadManager.renameChapter(source, manga, dbChapter.toDbChapter(), chapter.toDbChapter())
|
||||
downloadManager.run {
|
||||
val shouldRenameChapter = provider.isChapterDirNameChanged(dbChapter, chapter) &&
|
||||
isChapterDownloaded(dbChapter.name, dbChapter.scanlator, manga.title, manga.source)
|
||||
|
||||
if (shouldRenameChapter) {
|
||||
renameChapter(source, manga, dbChapter.toDbChapter(), chapter.toDbChapter())
|
||||
}
|
||||
}
|
||||
var toChangeChapter = dbChapter.copy(
|
||||
name = chapter.name,
|
||||
|
|
|
@ -37,7 +37,7 @@ data class Chapter(
|
|||
url = sChapter.url,
|
||||
dateUpload = sChapter.date_upload,
|
||||
chapterNumber = sChapter.chapter_number,
|
||||
scanlator = sChapter.scanlator,
|
||||
scanlator = sChapter.scanlator?.ifBlank { null },
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.launchIn
|
|||
import kotlinx.coroutines.flow.onEach
|
||||
import logcat.LogPriority
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import eu.kanade.domain.chapter.model.Chapter as DomainChapter
|
||||
|
||||
/**
|
||||
* This class is used to provide the directories where the downloads should be saved.
|
||||
|
@ -144,6 +145,10 @@ class DownloadProvider(private val context: Context) {
|
|||
)
|
||||
}
|
||||
|
||||
fun isChapterDirNameChanged(oldChapter: DomainChapter, newChapter: DomainChapter): Boolean {
|
||||
return oldChapter.name != newChapter.name || oldChapter.scanlator != newChapter.scanlator
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns valid downloaded chapter directory names.
|
||||
*
|
||||
|
@ -152,15 +157,21 @@ class DownloadProvider(private val context: Context) {
|
|||
*/
|
||||
fun getValidChapterDirNames(chapterName: String, chapterScanlator: String?): List<String> {
|
||||
val chapterDirName = getChapterDirName(chapterName, chapterScanlator)
|
||||
return listOf(
|
||||
return buildList(5) {
|
||||
// Folder of images
|
||||
chapterDirName,
|
||||
add(chapterDirName)
|
||||
|
||||
// Archived chapters
|
||||
"$chapterDirName.cbz",
|
||||
add("$chapterDirName.cbz")
|
||||
|
||||
if (chapterScanlator == null) {
|
||||
// Previously null scanlator fields were converted to "" due to a bug
|
||||
add("_$chapterDirName")
|
||||
add("_$chapterDirName.cbz")
|
||||
}
|
||||
|
||||
// Legacy chapter directory name used in v0.9.2 and before
|
||||
DiskUtil.buildValidFilename(chapterName),
|
||||
)
|
||||
add(DiskUtil.buildValidFilename(chapterName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue