Skip to content

Commit

Permalink
[Jellyfin] Add option to build Leaving Soon from scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
Schaka committed Feb 15, 2024
1 parent 9ae52d9 commit 3597c6f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import org.springframework.stereotype.Component
data class FileSystemProperties(
var leavingSoonDir: String?,
var access: Boolean = false,
var fromScratch: Boolean = true
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.github.schaka.janitorr.servarr.LibraryItem
import org.slf4j.LoggerFactory
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.stereotype.Service
import org.springframework.util.FileSystemUtils
import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.*
Expand Down Expand Up @@ -53,6 +54,8 @@ class JellyfinRestService(
}
}
}

// TODO: Remove TV shows if all seasons gone
}

override fun cleanupMovies(items: List<LibraryItem>) {
Expand Down Expand Up @@ -97,7 +100,7 @@ class JellyfinRestService(
override fun updateGoneSoon(type: LibraryType, items: List<LibraryItem>) {

// Only do this, if we can get access to the file system to create a link structure
if (!fileSystemProperties.access) {
if (!fileSystemProperties.access || fileSystemProperties.leavingSoonDir == null) {
return
}

Expand All @@ -114,6 +117,12 @@ class JellyfinRestService(
goneSoonCollection = jellyfinClient.listLibraries().firstOrNull { it.CollectionType == collectionFilter && it.Name == "${type.collectionName} (Deleted Soon)" }
}

// Clean up entire directory and rebuild from scratch - this can help with clearing orphaned data
// TODO: Might make sense to run this BEFORE deleting any data
if (fileSystemProperties.fromScratch) {
FileSystemUtils.deleteRecursively(Path.of(fileSystemProperties.leavingSoonDir))
}

items.forEach {
try {

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ server:
file-system:
access: true
leaving-soon-dir: "/data/media/leaving-soon" # A directory this container can write to and Jellyfin can find under the same path - this will contain new folders with SymLinks to files for Jellyfin's "Leaving Soon" collections
from-scratch: true # Clean up entire directory and rebuild from scratch - this can help with clearing orphaned data - turning this off can save resources (less writes to drive)

application:
dry-run: true
Expand Down

0 comments on commit 3597c6f

Please sign in to comment.