@@ -14,6 +14,8 @@ import org.springframework.aot.hint.annotation.RegisterReflectionForBinding
14
14
import org.springframework.cache.annotation.CacheEvict
15
15
import org.springframework.scheduling.annotation.Scheduled
16
16
import org.springframework.stereotype.Service
17
+ import sun.jvm.hotspot.HelloWorld.e
18
+ import java.time.LocalDate
17
19
import java.time.LocalDateTime
18
20
19
21
/* *
@@ -57,7 +59,11 @@ class WeeklyEpisodeCleanupSchedule(
57
59
58
60
for (show in series) {
59
61
val latestSeason = show.seasons.maxBy { season -> season.seasonNumber }
60
- val episodes = sonarrClient.getAllEpisodes(show.id, latestSeason.seasonNumber).toMutableList()
62
+ val episodes = sonarrClient.getAllEpisodes(show.id, latestSeason.seasonNumber)
63
+ .filter { it.airDate != null }
64
+ .filter { LocalDate .parse(it.airDate!! ) <= today.toLocalDate() }
65
+ .toMutableList()
66
+
61
67
val episodesHistory = sonarrClient.getHistory(show.id, latestSeason.seasonNumber)
62
68
.sortedBy { parseDate(it.date)}
63
69
.distinctBy { it.episodeId }
@@ -85,13 +91,12 @@ class WeeklyEpisodeCleanupSchedule(
85
91
val leftoverEpisodes = episodes.sortedByDescending { it.episodeNumber }.take(applicationProperties.episodeDeletion.maxEpisodes)
86
92
episodes.removeAll(leftoverEpisodes) // remove the most recent episodes from the list, as we want to keep those
87
93
88
- for (episode in leftoverEpisodes ) {
94
+ for (episode in episodes ) {
89
95
log.trace(" Deleting episode ${episode.episodeNumber} of ${show.title} S${latestSeason.seasonNumber} because there are too many episodes" )
90
96
91
97
if (episode.episodeFileId != null && episode.episodeFileId != 0 ) {
92
98
if (! applicationProperties.dryRun) {
93
99
sonarrClient.deleteEpisodeFile(episode.episodeFileId)
94
- episodes.remove(episode)
95
100
}
96
101
}
97
102
}
0 commit comments