diff --git a/app/src/main/kotlin/xyz/mpv/rex/database/repository/HybridMediaIndexRepository.kt b/app/src/main/kotlin/xyz/mpv/rex/database/repository/HybridMediaIndexRepository.kt index 82564bd36..76b5567ae 100644 --- a/app/src/main/kotlin/xyz/mpv/rex/database/repository/HybridMediaIndexRepository.kt +++ b/app/src/main/kotlin/xyz/mpv/rex/database/repository/HybridMediaIndexRepository.kt @@ -20,6 +20,7 @@ import xyz.mpv.rex.domain.media.model.Video import xyz.mpv.rex.preferences.BrowserPreferences import xyz.mpv.rex.preferences.FoldersPreferences import xyz.mpv.rex.utils.media.MediaFormatter +import xyz.mpv.rex.utils.storage.isPathExcluded import xyz.mpv.rex.utils.storage.FileFilterUtils import xyz.mpv.rex.utils.storage.FileTypeUtils import xyz.mpv.rex.utils.storage.StorageVolumeUtils @@ -84,11 +85,10 @@ class HybridMediaIndexRepository( suspend fun purgeExcludedFolders(excludedPaths: Set = foldersPreferences.blacklistedFolders.get()) = withContext(Dispatchers.IO) { if (excludedPaths.isEmpty()) return@withContext Log.d(TAG, "Purging excluded folders from Room index: $excludedPaths") - excludedPaths.forEach { rawPath -> - val normalized = normalizePath(File(rawPath)) - val escaped = normalized.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_") - dao.deleteByPathPrefix(normalized, "$escaped/%") - } + val locations = dao.getAvailableMedia(includeNoMedia = true) + .filter { isPathExcluded(it.location, excludedPaths) || isPathExcluded(it.parentIdentity, excludedPaths) } + .map { it.location } + locations.chunked(400).forEach { dao.deleteByLocations(it) } } suspend fun removeEntries(paths: List) = withContext(Dispatchers.IO) { @@ -318,13 +318,20 @@ class HybridMediaIndexRepository( } + private suspend fun visibleMedia(includeNoMedia: Boolean): List { + val blacklist = foldersPreferences.blacklistedFolders.get() + return dao.getAvailableMedia(includeNoMedia).filter { item -> + !isPathExcluded(item.location, blacklist) && !isPathExcluded(item.parentIdentity, blacklist) + } + } + suspend fun getFlatFolders( playbackStates: List, thresholdDays: Int, watchedThreshold: Int, includeNoMedia: Boolean = browserPreferences.includeNoMediaContent.get(), ): List = withContext(Dispatchers.IO) { - val items = dao.getAvailableMedia(includeNoMedia) + val items = visibleMedia(includeNoMedia) val stateByIdentity = playbackStates.associateBy { it.mediaTitle } val thresholdMillis = thresholdDays * 24L * 60L * 60L * 1000L val now = System.currentTimeMillis() @@ -381,7 +388,7 @@ class HybridMediaIndexRepository( includeNoMedia: Boolean = browserPreferences.includeNoMediaContent.get(), ): List = withContext(Dispatchers.IO) { val tree = buildFileTree( - dao.getAvailableMedia(includeNoMedia), + visibleMedia(includeNoMedia), playbackStates, thresholdDays, watchedThreshold, @@ -399,7 +406,7 @@ class HybridMediaIndexRepository( includeNoMedia: Boolean = browserPreferences.includeNoMediaContent.get(), ): MediaFolder? = withContext(Dispatchers.IO) { buildFileTree( - dao.getAvailableMedia(includeNoMedia), + visibleMedia(includeNoMedia), playbackStates, thresholdDays, watchedThreshold, @@ -410,7 +417,7 @@ class HybridMediaIndexRepository( parentIdentity: String, includeNoMedia: Boolean = browserPreferences.includeNoMediaContent.get(), ): List