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)
|
toAdd.add(toAddChapter)
|
||||||
} else {
|
} else {
|
||||||
if (shouldUpdateDbChapter.await(dbChapter, chapter)) {
|
if (shouldUpdateDbChapter.await(dbChapter, chapter)) {
|
||||||
if (dbChapter.name != chapter.name && downloadManager.isChapterDownloaded(dbChapter.name, dbChapter.scanlator, manga.title, manga.source)) {
|
downloadManager.run {
|
||||||
downloadManager.renameChapter(source, manga, dbChapter.toDbChapter(), chapter.toDbChapter())
|
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(
|
var toChangeChapter = dbChapter.copy(
|
||||||
name = chapter.name,
|
name = chapter.name,
|
||||||
|
|
|
@ -37,7 +37,7 @@ data class Chapter(
|
||||||
url = sChapter.url,
|
url = sChapter.url,
|
||||||
dateUpload = sChapter.date_upload,
|
dateUpload = sChapter.date_upload,
|
||||||
chapterNumber = sChapter.chapter_number,
|
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 kotlinx.coroutines.flow.onEach
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import uy.kohesive.injekt.injectLazy
|
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.
|
* 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.
|
* Returns valid downloaded chapter directory names.
|
||||||
*
|
*
|
||||||
|
@ -152,15 +157,21 @@ class DownloadProvider(private val context: Context) {
|
||||||
*/
|
*/
|
||||||
fun getValidChapterDirNames(chapterName: String, chapterScanlator: String?): List<String> {
|
fun getValidChapterDirNames(chapterName: String, chapterScanlator: String?): List<String> {
|
||||||
val chapterDirName = getChapterDirName(chapterName, chapterScanlator)
|
val chapterDirName = getChapterDirName(chapterName, chapterScanlator)
|
||||||
return listOf(
|
return buildList(5) {
|
||||||
// Folder of images
|
// Folder of images
|
||||||
chapterDirName,
|
add(chapterDirName)
|
||||||
|
|
||||||
// Archived chapters
|
// 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
|
// Legacy chapter directory name used in v0.9.2 and before
|
||||||
DiskUtil.buildValidFilename(chapterName),
|
add(DiskUtil.buildValidFilename(chapterName))
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue