Compare commits
7 Commits
v0.0.8-alp
...
d78d1069b1
| Author | SHA1 | Date | |
|---|---|---|---|
| d78d1069b1 | |||
| f7c463aba4 | |||
| 77f2873180 | |||
| b2da7beb00 | |||
| 9696826406 | |||
| 873b29985c | |||
| 30107010b1 |
@@ -1,5 +1,5 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<AssemblyVersion>0.0.0.8</AssemblyVersion>
|
||||
<AssemblyVersion>0.0.0.9</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
@@ -39,10 +39,13 @@ public class LoggingHelper
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
public void EndOfScanningForSeries(BaseItem item)
|
||||
public void PrintDebugEndOfScanningForSeries(BaseItem item)
|
||||
{
|
||||
_logger.LogInformation("End of scanning for series: {Series}", item);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("End of scanning for series: {Series}", item);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,12 +63,12 @@ public class LoggingHelper
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
public void PrintStaleItemsInformation(IReadOnlyCollection<BaseItem> staleItems)
|
||||
public void PrintItemsInformation(IReadOnlyCollection<BaseItem> items)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(staleItems);
|
||||
ArgumentNullException.ThrowIfNull(items);
|
||||
|
||||
_logger.LogInformation("Total stale items: {ItemCount}", staleItems.Count);
|
||||
_logger.LogInformation("Stale items found: {AllItems}", staleItems);
|
||||
_logger.LogInformation("Total items: {ItemCount}", items.Count);
|
||||
_logger.LogInformation("Stale items found: {AllItems}", items);
|
||||
}
|
||||
|
||||
public void PrintStaleMoviesInformation(IReadOnlyCollection<BaseItem> staleMovies)
|
||||
@@ -122,11 +125,11 @@ public class LoggingHelper
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintDebugSeasonNumber(int seasonNumber)
|
||||
public void PrintDebugSeasonInfo()
|
||||
{
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("Season {SeasonNumber} debug information:", [seasonNumber]);
|
||||
_logger.LogInformation("Season debug information:");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,13 +149,11 @@ public class LoggingHelper
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintDebugNoUserDataAndOutsideCutoffEpisodeInfo(IReadOnlyCollection<BaseItem> episodes, int seasonNumber)
|
||||
public void PrintDebugEpisodeCreationInfo(IReadOnlyCollection<BaseItem> episodes)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(episodes);
|
||||
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("No user data, and creation date is outside of media cutoff, Season {SeasonNumber} is stale.", seasonNumber);
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Episode creation dates:");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
|
||||
@@ -22,9 +22,12 @@ public class MovieHelper
|
||||
|
||||
public bool IsMovieStale(BaseItem movie)
|
||||
{
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Start of scanning for movie: {Movie}", movie);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Start of scanning for movie: {Movie}", movie);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
bool movieIsStale = false;
|
||||
|
||||
@@ -33,7 +36,7 @@ public class MovieHelper
|
||||
|
||||
if (hasUserData)
|
||||
{
|
||||
var mostRecentUserData = movie.UserData.OrderByDescending(data => data.LastPlayedDate).Where(data => data.LastPlayedDate != null).First();
|
||||
var mostRecentUserData = movie.UserData.OrderByDescending(data => data.LastPlayedDate).First(data => data.LastPlayedDate != null);
|
||||
|
||||
if (Configuration.DebugMode){
|
||||
_logger.LogInformation("Most recent user data: {Movie}", movie);
|
||||
@@ -63,10 +66,12 @@ public class MovieHelper
|
||||
movieIsStale = true;
|
||||
}
|
||||
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("End of scanning for movie: {Movie}", movie);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("End of scanning for movie: {Movie}", movie);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
return movieIsStale;
|
||||
}
|
||||
|
||||
@@ -25,17 +25,24 @@ public class SeriesHelper
|
||||
private static PluginConfiguration Configuration =>
|
||||
Plugin.Instance!.Configuration;
|
||||
|
||||
public bool IsSeasonUserDataStale(IReadOnlyList<BaseItem> episodes, int seasonNumber)
|
||||
public bool IsSeasonUserDataStale(IReadOnlyList<BaseItem> episodes)
|
||||
{
|
||||
bool seasonIsStale = false;
|
||||
|
||||
List<BaseItem> staleEpisodes = [];
|
||||
|
||||
var episodesWithUserData = episodes.Where(episode => episode.UserData.Where(data => data.LastPlayedDate != null).ToList().Count > 0).ToList();
|
||||
|
||||
_loggingHelper.PrintDebugEpisodesWithUserData(episodesWithUserData);
|
||||
|
||||
foreach (var episode in episodesWithUserData)
|
||||
{
|
||||
var mostRecentUserData = episode.UserData.OrderByDescending(data => data.LastPlayedDate).Where(data => data.LastPlayedDate != null).First();
|
||||
bool episodeIsStale = false;
|
||||
|
||||
var mostRecentUserData = episode.UserData.OrderByDescending(data => data.LastPlayedDate).First(data => data.LastPlayedDate != null);
|
||||
var staleLastPlayedDate = mostRecentUserData.LastPlayedDate < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff);
|
||||
var staleCreationDate = episode.DateCreated < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff);
|
||||
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("User data for episode: {Episode}", episode);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
@@ -45,15 +52,30 @@ public class SeriesHelper
|
||||
}
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
if (mostRecentUserData.LastPlayedDate < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff))
|
||||
{
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("Most recent user data has a last played date of: {LastPlayedDate}. Therefore all episodes are stale. Adding Season {SeasonNumber} to stale list.", [mostRecentUserData.LastPlayedDate, seasonNumber]);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
seasonIsStale = true;
|
||||
if (staleLastPlayedDate && staleCreationDate)
|
||||
{
|
||||
episodeIsStale = true;
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("Most recent user data has a last played date of: {LastPlayedDate}.", [mostRecentUserData.LastPlayedDate]);
|
||||
_logger.LogInformation("And episode created {DateCreated}.", episode.DateCreated);
|
||||
}
|
||||
}
|
||||
|
||||
if (episodeIsStale)
|
||||
{
|
||||
staleEpisodes.Add(episode);
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("Episode is stale.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(staleEpisodes.Count == episodes.Count)
|
||||
{
|
||||
seasonIsStale = true;
|
||||
_logger.LogInformation("Stale episodes count matches all episode count. Season is stale.");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
return seasonIsStale;
|
||||
|
||||
@@ -70,7 +70,7 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
|
||||
List<BaseItem> allItems = [.. _libraryManager.GetItemsResult(query).Items];
|
||||
|
||||
_loggingHelper.PrintStaleItemsInformation(allItems);
|
||||
_loggingHelper.PrintItemsInformation(allItems);
|
||||
|
||||
List<BaseItem> series = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Series)];
|
||||
List<BaseItem> movies = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Movie)];
|
||||
@@ -112,8 +112,6 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
|
||||
_loggingHelper.PrintDebugDataForSeries(item);
|
||||
|
||||
int seasonNumber = 1;
|
||||
|
||||
foreach (var season in seasons)
|
||||
{
|
||||
// Gets each episode, to access user data.
|
||||
@@ -123,32 +121,23 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
Recursive = false
|
||||
});
|
||||
|
||||
bool seasonCreatedOutsideCutoff = episodes.All(episode => episode.DateCreated < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff));
|
||||
|
||||
_loggingHelper.PrintDebugSeasonNumber(seasonNumber);
|
||||
|
||||
if (seasonCreatedOutsideCutoff)
|
||||
{
|
||||
_loggingHelper.PrintDebugSeasonCreatedOutsideCutoff();
|
||||
}
|
||||
_loggingHelper.PrintDebugSeasonInfo();
|
||||
|
||||
bool seasonHasUserData = episodes.Any(episode => episode.UserData.Count > 0);
|
||||
bool seasonIsStale = (seasonHasUserData && _seriesHelper.IsSeasonUserDataStale(episodes, seasonNumber)) || seasonCreatedOutsideCutoff;
|
||||
bool noUserDataAndOutsideCutoff = !seasonHasUserData && seasonCreatedOutsideCutoff;
|
||||
bool seasonIsStale = seasonHasUserData && _seriesHelper.IsSeasonUserDataStale(episodes);
|
||||
|
||||
if (seasonIsStale)
|
||||
{
|
||||
if (noUserDataAndOutsideCutoff)
|
||||
if (!seasonHasUserData)
|
||||
{
|
||||
_loggingHelper.PrintDebugNoUserDataAndOutsideCutoffEpisodeInfo(episodes, seasonNumber);
|
||||
_loggingHelper.PrintDebugEpisodeCreationInfo(episodes);
|
||||
}
|
||||
|
||||
staleEpisodes.AddRange(episodes);
|
||||
}
|
||||
seasonNumber++;
|
||||
}
|
||||
|
||||
_loggingHelper.EndOfScanningForSeries(item);
|
||||
_loggingHelper.PrintDebugEndOfScanningForSeries(item);
|
||||
|
||||
return staleEpisodes;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
The idea behind this plugin is to have an easy way to run a task to find all movies and shows in your media collection that users haven't viewed in a number of cutoff days.
|
||||
|
||||
At the time of writing, the plugin is only capable of logging movies and shows that are stale (Unwatched for 90 days) by running a scheduled task. You will need to view your logs to know the number of stale files.
|
||||
At the time of writing, the plugin is only capable of logging movies and shows that are stale (Unwatched for a user set number of days) by running a scheduled task. You will need to view your logs to know the number of stale files and the names of said files.
|
||||
|
||||
Planned features:
|
||||
- Better logging to show more than just the count.
|
||||
- Better logging to show more than just the count. ✅
|
||||
- A page that shows what media is currently flagged for removal. And a button to confirm removal.
|
||||
- Integration with sonarr and radarr apis to delete your media.
|
||||
- Whitelist for shows to ignore. (Seasonal shows)
|
||||
|
||||
Reference in New Issue
Block a user