3 Commits

4 changed files with 68 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<AssemblyVersion>0.0.0.9</AssemblyVersion>
<AssemblyVersion>0.0.0.10</AssemblyVersion>
</PropertyGroup>
</Project>

View File

@@ -17,7 +17,10 @@ public class MovieHelper(ILogger logger)
public bool IsMovieStale(BaseItem movie)
{
_loggingHelper.LogDebugInformation("Start of scanning for movie: {Movie}", movie);
ArgumentNullException.ThrowIfNull(movie, "IsMovieStale process recieved a null movie. Logic failure. Exception thrown.");
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("Scanning movie: {Movie}", movie);
_loggingHelper.LogDebugInformation("-------------------------------------------------");
bool movieIsStale = false;
@@ -47,13 +50,20 @@ public class MovieHelper(ILogger logger)
movieIsStale = true;
}
}
else if (createdOutsideCutoff)
if (createdOutsideCutoff && !hasUserData)
{
_loggingHelper.LogDebugInformation("Movie has no user data and was created outside of cutoff: {DateCreated}.", movie.DateCreated);
_loggingHelper.LogDebugInformation("Adding {Movie} to stale movies.", movie);
movieIsStale = true;
}
if (!createdOutsideCutoff && !hasUserData)
{
_loggingHelper.LogDebugInformation("Movie has no user data and was not created outside of cutoff: {DateCreated}.", movie.DateCreated);
_loggingHelper.LogDebugInformation("Movie is not stale.");
}
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("End of scanning for movie: {Movie}", movie);

View File

@@ -69,10 +69,7 @@ public class SeriesHelper(ILogger logger)
public bool IsSeasonDataStale(IReadOnlyList<BaseItem> episodes)
{
if(episodes == null)
{
ArgumentNullException.ThrowIfNull(episodes);
}
ArgumentNullException.ThrowIfNull(episodes, "IsSeasonDataStale process recieved null episodes. Logic failure. Exception thrown.");
bool seasonIsStale = false;

View File

@@ -73,46 +73,59 @@ public sealed class StaleMediaTask : IScheduledTask
List<BaseItem> allItems = [.. _libraryManager.GetItemsResult(query).Items];
_loggingHelper.LogInformation("Total items: {ItemCount}", allItems.Count);
_loggingHelper.LogInformation("Stale items found: {AllItems}", allItems);
_loggingHelper.LogInformation("Total items to scan: {ItemCount}", allItems.Count);
_loggingHelper.LogDebugInformation("Items found: {AllItems}", allItems);
List<BaseItem> series = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Series)];
List<BaseItem> movies = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Movie)];
_loggingHelper.LogInformation("-------------------------------------------------");
_loggingHelper.LogInformation("Starting scan of series items.");
_loggingHelper.LogInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("Starting scan of series items.");
List<BaseItem> staleSeasons = [.. series.SelectMany(GetStaleSeasons)];
_loggingHelper.LogInformation("Starting scan of movies items.");
_loggingHelper.LogInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("End of scan for series items.");
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("Starting scan of movie items.");
List<BaseItem> staleMovies = [.. GetStaleMovies(movies)];
_loggingHelper.LogInformation("-------------------------------------------------");
_loggingHelper.LogInformation("Stale Movies found: {StaleMovies}", staleMovies.Count);
if (staleMovies.Count > 0 && Configuration.DebugMode)
{
foreach (var movieInfo in staleMovies)
{
_loggingHelper.LogDebugInformation("Movie Info: ID: {Id} | Movie Name: {MovieName}", [movieInfo.Id, movieInfo.Name]);
}
}
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("End of scan for movie items.");
_loggingHelper.LogInformation("-------------------------------------------------");
_loggingHelper.LogInformation("Stale seasons found: {StaleSeasons}", staleSeasons.Count);
if (staleSeasons.Count > 0 && Configuration.DebugMode)
if (staleSeasons.Count > 0)
{
IEnumerable<SeriesInfo> staleSeriesInfo = FindSeriesInfo(staleSeasons);
foreach (var seriesInfo in staleSeriesInfo)
{
_loggingHelper.LogDebugInformation("Series Info: ID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.Id, seriesInfo.SeriesName, string.Join(", ", seriesInfo.Seasons)]);
_loggingHelper.LogInformation("Series Info: ID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.Id, seriesInfo.SeriesName, string.Join(", ", seriesInfo.Seasons)]);
}
}
else
{
_loggingHelper.LogInformation("No stale seasons found!");
}
_loggingHelper.LogInformation("-------------------------------------------------");
_loggingHelper.LogInformation("Stale Movies found: {StaleMovies}", staleMovies.Count);
if (staleMovies.Count > 0)
{
foreach (var movieInfo in staleMovies)
{
_loggingHelper.LogInformation("Movie Info: ID: {Id} | Movie Name: {MovieName}", [movieInfo.Id, movieInfo.Name]);
}
}
else
{
_loggingHelper.LogInformation("No stale movies found!");
}
_loggingHelper.LogInformation("-------------------------------------------------");
_loggingHelper.LogInformation("Ending stale media scan...");
@@ -125,7 +138,15 @@ public sealed class StaleMediaTask : IScheduledTask
{
List<BaseItem> staleMovies = [];
staleMovies.AddRange(movies.Where(_movieHelper.IsMovieStale));
try
{
staleMovies.AddRange(movies.Where(_movieHelper.IsMovieStale));
}
catch (ArgumentNullException ex)
{
_loggingHelper.LogInformation("Arguement Null Exception in GetStaleMovies!");
_loggingHelper.LogInformation(ex.Message);
}
return staleMovies;
}
@@ -133,10 +154,10 @@ public sealed class StaleMediaTask : IScheduledTask
private List<BaseItem> GetStaleSeasons(BaseItem item)
{
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("Debug data for series: {SeriesName}", item.Name);
_loggingHelper.LogDebugInformation("-------------------------------------------------");
// Gets each season in a show
var seasons = _libraryManager.GetItemList(new InternalItemsQuery
{
ParentId = item.Id,
@@ -153,7 +174,17 @@ public sealed class StaleMediaTask : IScheduledTask
_loggingHelper.LogDebugInformation("Season debug information for {SeasonNumber}:", season);
bool isSeasonDataStale = _seriesHelper.IsSeasonDataStale(episodes);
bool isSeasonDataStale = false;
try
{
isSeasonDataStale = _seriesHelper.IsSeasonDataStale(episodes);
}
catch (ArgumentNullException ex)
{
_loggingHelper.LogInformation("Arguement Null Exception in GetStaleSeasons!");
_loggingHelper.LogInformation(ex.Message);
}
_loggingHelper.LogDebugInformation("End of season debug information for {SeasonNumber}.", season);
@@ -163,7 +194,6 @@ public sealed class StaleMediaTask : IScheduledTask
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("End of scanning for series: {Series}", item);
_loggingHelper.LogDebugInformation("-------------------------------------------------");
return staleSeasons;
}
@@ -193,6 +223,7 @@ public sealed class StaleMediaTask : IScheduledTask
IEnumerable<TaskTriggerInfo> IScheduledTask.GetDefaultTriggers()
{
// Run this task every 24 hours
// Unnecessary, and will be removed once front end page is ready.
yield return new TaskTriggerInfo
{
Type = TaskTriggerInfoType.IntervalTrigger,