Skip to content

Commit

Permalink
Properly sort files, if more upgraded downloads are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Schaka committed Jan 15, 2024
1 parent 661c38d commit 5857fe4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package com.github.schaka.janitorr.servarr

import java.time.LocalDateTime

interface ServarrService {

fun getEntries(): List<LibraryItem>

fun removeEntries(items: List<LibraryItem>)

/**
* Sort by oldest file. If upgrades are allowed, sort by most recently grabbed files.
*/
fun byDate(upgradesAllowed: Boolean): Comparator<LibraryItem> {
val comp = compareBy<LibraryItem>{ it.date }
return if (upgradesAllowed) comp.reversed() else comp
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class RadarrService(
return radarrClient.getAllMovies().mapNotNull { movie ->
radarrClient.getHistory(movie.id)
.filter { it.eventType == "downloadFolderImported" && it.data.droppedPath != null }
.sortedBy { LocalDateTime.parse(it.date.substring(0, it.date.length - 1)) }
.map {
LibraryItem(
movie.id,
Expand All @@ -50,6 +49,7 @@ class RadarrService(
imdbId = movie.imdbId
)
}
.sortedWith ( byDate(upgradesAllowed) )
.firstOrNull()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class SonarrService(
sonarrClient.getHistory(series.id, season.seasonNumber)
.filter { it.eventType == "downloadFolderImported" && it.data.droppedPath != null }
// TODO: If automatic upgrades are enabled, grab the most recent date, not the oldest
.sortedBy { LocalDateTime.parse(it.date.substring(0, it.date.length - 1)) }
.map {

var seriesPath = series.path;
Expand All @@ -63,6 +62,7 @@ class SonarrService(
imdbId = series.imdbId
)
}
.sortedWith ( byDate(upgradesAllowed) )
.firstOrNull()
}
}.filterNotNull()
Expand All @@ -85,6 +85,9 @@ class SonarrService(
unmonitorSeason(item.id, item.season)
}
}

// TODO: Clean up entire show, if all seasons are unmonitored
// Also requires support for deletion in Jellyfin
}

private fun unmonitorSeason(seriesId: Int, seasonNumber: Int) {
Expand Down

0 comments on commit 5857fe4

Please sign in to comment.