SY maybe supports J2k downloads now

This commit is contained in:
Jobobby04 2020-07-24 21:46:59 -04:00
parent a311a3b497
commit 75e9911317
3 changed files with 36 additions and 13 deletions

View File

@ -81,7 +81,7 @@ class DownloadCache(
if (sourceDir != null) {
val mangaDir = sourceDir.files[provider.getMangaDirName(manga)]
if (mangaDir != null) {
return provider.getChapterDirName(chapter) in mangaDir.files
return provider.getValidChapterDirNames(chapter).any { it in mangaDir.files }
}
}
return false
@ -191,9 +191,11 @@ class DownloadCache(
fun removeChapter(chapter: Chapter, manga: Manga) {
val sourceDir = rootDir.files[manga.source] ?: return
val mangaDir = sourceDir.files[provider.getMangaDirName(manga)] ?: return
val chapterDirName = provider.getChapterDirName(chapter)
if (chapterDirName in mangaDir.files) {
mangaDir.files -= chapterDirName
val chapterDirName = provider.getValidChapterDirNames(chapter)
chapterDirName.forEach {
if (it in mangaDir.files) {
mangaDir.files -= chapterDirName
}
}
}
@ -208,9 +210,11 @@ class DownloadCache(
val sourceDir = rootDir.files[manga.source] ?: return
val mangaDir = sourceDir.files[provider.getMangaDirName(manga)] ?: return
chapters.forEach { chapter ->
val chapterDirName = provider.getChapterDirName(chapter)
if (chapterDirName in mangaDir.files) {
mangaDir.files -= chapterDirName
val chapterDirName = provider.getValidChapterDirNames(chapter)
chapterDirName.forEach {
if (it in mangaDir.files) {
mangaDir.files -= chapterDirName
}
}
}
}

View File

@ -251,16 +251,16 @@ class DownloadManager(/* SY private */ val context: Context) {
* @param newChapter the target chapter with the new name.
*/
fun renameChapter(source: Source, manga: Manga, oldChapter: Chapter, newChapter: Chapter) {
val oldName = provider.getChapterDirName(oldChapter)
val oldName = provider.getValidChapterDirNames(oldChapter)
val newName = provider.getChapterDirName(newChapter)
val mangaDir = provider.getMangaDir(manga, source)
val oldFolder = mangaDir.findFile(oldName)
val oldFolder = mangaDir.findFile(oldName.find { mangaDir.findFile(it) != null })
if (oldFolder?.renameTo(newName) == true) {
cache.removeChapter(oldChapter, manga)
cache.addChapter(newName, mangaDir, manga)
} else {
Timber.e("Could not rename downloaded chapter: %s.", oldName)
Timber.e("Could not rename downloaded chapter: %s.", oldName.last())
}
}
}

View File

@ -88,7 +88,7 @@ class DownloadProvider(private val context: Context) {
*/
fun findChapterDir(chapter: Chapter, manga: Manga, source: Source): UniFile? {
val mangaDir = findMangaDir(manga, source)
return mangaDir?.findFile(getChapterDirName(chapter))
return getValidChapterDirNames(chapter).mapNotNull { mangaDir?.findFile(it) }.firstOrNull()
}
/**
@ -100,7 +100,9 @@ class DownloadProvider(private val context: Context) {
*/
fun findChapterDirs(chapters: List<Chapter>, manga: Manga, source: Source): List<UniFile> {
val mangaDir = findMangaDir(manga, source) ?: return emptyList()
return chapters.mapNotNull { mangaDir.findFile(getChapterDirName(it)) }
return chapters.mapNotNull { chp ->
getValidChapterDirNames(chp).mapNotNull { mangaDir.findFile(it) }.firstOrNull()
}
}
/**
@ -129,6 +131,23 @@ class DownloadProvider(private val context: Context) {
* @param chapter the chapter to query.
*/
fun getChapterDirName(chapter: Chapter): String {
return DiskUtil.buildValidFilename(chapter.name)
return DiskUtil.buildValidFilename(
if (chapter.scanlator != null) "${chapter.scanlator}_${chapter.name}"
else chapter.name
)
}
/**
* Returns valid downloaded chapter directory names.
*
* @param chapter the chapter to query.
*/
fun getValidChapterDirNames(chapter: Chapter): List<String> {
return listOf(
// Legacy chapter directory name used in v0.9.2 and before
DiskUtil.buildValidFilename(chapter.name),
// New chapter chapter directory name
getChapterDirName(chapter)
)
}
}