Skip to content

Commit

Permalink
Feat: Remove thumbnails on media deleted (#690)
Browse files Browse the repository at this point in the history
* delete unused thumbnail files

* lint: run ktlintFormat

* refactor: use single map function
  • Loading branch information
anilbeesetti authored Oct 16, 2023
1 parent 843964b commit 4775260
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ class LocalMediaSynchronizer @Inject constructor(

mediumDao.delete(unwantedMediaPaths)

// Delete unwanted thumbnails
val unwantedThumbnailFiles = unwantedMedia.mapNotNull { medium -> medium.thumbnailPath?.let { File(it) } }
unwantedThumbnailFiles.forEach { file ->
try {
file.delete()
} catch (e: Exception) {
e.printStackTrace()
}
}

// Release external subtitle uri permission if not used by any other media
launch {
val currentMediaExternalSubs = mediumEntities.flatMap { UriListConverter.fromStringToList(it.externalSubs) }.toSet()
Expand Down

0 comments on commit 4775260

Please sign in to comment.