mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 15:21:51 +01:00
Changing the downloads folder naming AGAIN
This time folders are named just the chapter, or scanlator_chapterName if there's a scanlator Migrations now needs a rename to set the chapters from the new to the new new format
This commit is contained in:
parent
a5120edd0e
commit
f475a0882b
@ -1,5 +1,6 @@
|
|||||||
package eu.kanade.tachiyomi
|
package eu.kanade.tachiyomi
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.data.download.DownloadProvider
|
||||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
@ -60,6 +61,8 @@ object Migrations {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (oldVersion < 54)
|
||||||
|
DownloadProvider(context).renameChaapters()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -121,7 +121,7 @@ class DownloadCache(
|
|||||||
/**
|
/**
|
||||||
* Renews the downloads cache.
|
* Renews the downloads cache.
|
||||||
*/
|
*/
|
||||||
private fun renew() {
|
fun renew() {
|
||||||
val onlineSources = sourceManager.getOnlineSources()
|
val onlineSources = sourceManager.getOnlineSources()
|
||||||
|
|
||||||
val sourceDirs = rootDir.dir.listFiles()
|
val sourceDirs = rootDir.dir.listFiles()
|
||||||
|
@ -4,11 +4,13 @@ import android.content.Context
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import com.hippo.unifile.UniFile
|
import com.hippo.unifile.UniFile
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import eu.kanade.tachiyomi.util.DiskUtil
|
import eu.kanade.tachiyomi.util.DiskUtil
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
@ -97,7 +99,37 @@ class DownloadProvider(private val context: Context) {
|
|||||||
*/
|
*/
|
||||||
fun findChapterDirs(chapters: List<Chapter>, manga: Manga, source: Source): List<UniFile> {
|
fun findChapterDirs(chapters: List<Chapter>, manga: Manga, source: Source): List<UniFile> {
|
||||||
val mangaDir = findMangaDir(manga, source) ?: return emptyList()
|
val mangaDir = findMangaDir(manga, source) ?: return emptyList()
|
||||||
return chapters.flatMap { getValidChapterDirNames(it) }.mapNotNull { mangaDir.findFile(it) }
|
return chapters.mapNotNull { chp ->
|
||||||
|
getValidChapterDirNames(chp).mapNotNull { mangaDir.findFile(it) }.firstOrNull()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renames the chapter folders with id's and removes it + null scanlators
|
||||||
|
*
|
||||||
|
* @param chapters the chapters to query.
|
||||||
|
* @param manga the manga of the chapter.
|
||||||
|
* @param source the source of the chapter.
|
||||||
|
*/
|
||||||
|
fun renameChaapters() {
|
||||||
|
val db by injectLazy<DatabaseHelper>()
|
||||||
|
val sourceManager by injectLazy<SourceManager>()
|
||||||
|
val mangas = db.getLibraryMangas().executeAsBlocking()
|
||||||
|
mangas.forEach sfor@{ manga ->
|
||||||
|
val sourceId = manga.source
|
||||||
|
val source = sourceManager.get(sourceId) ?: return@sfor
|
||||||
|
val mangaDir = findMangaDir(manga, source) ?: return@sfor
|
||||||
|
mangaDir.listFiles()?.forEach {
|
||||||
|
val nameSplit = it.name?.split("_")?.toMutableList() ?: return@sfor
|
||||||
|
if (nameSplit.size > 2 && nameSplit.first().first().isDigit()) {
|
||||||
|
nameSplit.removeAt(0)
|
||||||
|
val newName = nameSplit.joinToString("_").removePrefix("null_")
|
||||||
|
it.renameTo(newName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val cache = DownloadCache(context, this, sourceManager)
|
||||||
|
cache.renew()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,7 +189,10 @@ class DownloadProvider(private val context: Context) {
|
|||||||
* @param chapter the chapter to query.
|
* @param chapter the chapter to query.
|
||||||
*/
|
*/
|
||||||
fun getChapterDirName(chapter: Chapter): String {
|
fun getChapterDirName(chapter: Chapter): String {
|
||||||
return DiskUtil.buildValidFilename("${chapter.id}_${chapter.scanlator}_${chapter.name}")
|
return DiskUtil.buildValidFilename(
|
||||||
|
if (chapter.scanlator != null) "${chapter.scanlator}_${chapter.name}"
|
||||||
|
else chapter.name
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,7 +9,6 @@ import android.graphics.Color
|
|||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@ -63,7 +62,6 @@ import kotlinx.android.synthetic.main.main_activity.*
|
|||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.lang.Exception
|
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
class MainActivity : BaseActivity() {
|
class MainActivity : BaseActivity() {
|
||||||
|
Loading…
Reference in New Issue
Block a user