Improved logging and correctly separated the debug logging. Logs should now make more sense and are easier to comprehend.
This commit is contained in:
@@ -55,17 +55,24 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
|
||||
Task IScheduledTask.ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("--DEBUG MODE ACTIVE--");
|
||||
}
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Starting stale media scan...");
|
||||
|
||||
var query = new InternalItemsQuery
|
||||
{
|
||||
IncludeItemTypes = [BaseItemKind.Movie, BaseItemKind.Series],
|
||||
Recursive = true
|
||||
};
|
||||
|
||||
List<BaseItem> allItems = [.. _libraryManager.GetItemsResult(query).Items];
|
||||
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("Total items found: {AllItems}", allItems);
|
||||
}
|
||||
_logger.LogInformation("Total stale items: {ItemCount}", allItems.Count);
|
||||
_logger.LogInformation("Stale items found: {AllItems}", allItems);
|
||||
|
||||
List<BaseItem> series = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Series)];
|
||||
List<BaseItem> movies = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Movie)];
|
||||
@@ -73,27 +80,33 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
List<BaseItem> staleEpisodes = [.. series.SelectMany(GetStaleEpisodes)];
|
||||
List<BaseItem> staleMovies = [.. GetStaleMovies(movies)];
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Stale Movies found: {StaleMovies}", staleMovies.Count);
|
||||
if (staleMovies.Count > 0)
|
||||
|
||||
if (staleMovies.Count > 0 && Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("Movies: {Names}", string.Join(", ", staleMovies.Select(movie => movie.Name)));
|
||||
foreach (var movieInfo in staleMovies)
|
||||
{
|
||||
_logger.LogInformation("Movie Info: ID: {Id} | Movie Name: {MovieName}", [movieInfo.Id, movieInfo.Name]);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Stale Episodes found: {StaleEpisodes}", staleEpisodes.Count);
|
||||
if (staleEpisodes.Count > 0)
|
||||
|
||||
if (staleEpisodes.Count > 0 && Configuration.DebugMode)
|
||||
{
|
||||
// Firstly figure out the seasons, and then the Series to find the name.
|
||||
List<SeriesInfo> seriesInfoList = FindSeriesInfoFromEpisodes(staleEpisodes);
|
||||
|
||||
foreach (var seriesInfo in seriesInfoList)
|
||||
{
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("Series Info: ID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.Id, seriesInfo.SeriesName, string.Join(", ", seriesInfo.Seasons)]);
|
||||
}
|
||||
_logger.LogInformation("Series Info: ID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.Id, seriesInfo.SeriesName, string.Join(", ", seriesInfo.Seasons)]);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -126,13 +139,19 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
|
||||
if (mostRecentUserData.LastPlayedDate < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff))
|
||||
{
|
||||
_logger.LogInformation("Most recent user data last played date is outside of cutoff. Adding to stale movies.");
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("Most recent user data last played date is outside of cutoff. Adding {Movie} to stale movies.", movie);
|
||||
}
|
||||
staleMovies.Add(movie);
|
||||
}
|
||||
}
|
||||
else if (movieIsStale)
|
||||
{
|
||||
_logger.LogInformation("Movie has no user data and was created outside of cutoff: {DateCreated}", movie.DateCreated);
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("Movie has no user data and was created outside of cutoff: {DateCreated}", movie.DateCreated);
|
||||
}
|
||||
staleMovies.Add(movie);
|
||||
}
|
||||
}
|
||||
@@ -184,6 +203,14 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
ParentId = item.Id,
|
||||
Recursive = false
|
||||
});
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Debug data for {SeriesName}", item.Name);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
int seasonNumber = 1;
|
||||
|
||||
foreach (var season in seasons)
|
||||
{
|
||||
@@ -193,17 +220,18 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
ParentId = season.Id,
|
||||
Recursive = false
|
||||
});
|
||||
|
||||
bool seasonHasUserData = episodes.Any(episode => episode.UserData.Count > 0);
|
||||
if (seasonHasUserData && Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("Season has user data for episodes: {Episodes}", episodes);
|
||||
_logger.LogInformation("Season {SeasonNumber} has user data.", [seasonNumber]);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
bool seasonIsStale = episodes.All(episode => episode.DateCreated < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff));
|
||||
if (seasonIsStale && Configuration.DebugMode)
|
||||
|
||||
bool seasonCanBeStale = episodes.All(episode => episode.DateCreated < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff));
|
||||
if (seasonCanBeStale && Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("All episodes are outside media cutoff.");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("All episodes were created outside of media cutoff, all episodes are eligible to be stale.");
|
||||
}
|
||||
|
||||
if (seasonHasUserData)
|
||||
@@ -228,7 +256,7 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
if (mostRecentUserData.LastPlayedDate < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff))
|
||||
{
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("Most Recent User Data Last Played Date is: {LastPlayedDate}. All Episodes are stale.", mostRecentUserData.LastPlayedDate);
|
||||
_logger.LogInformation("Most recent user data has a last played date of: {LastPlayedDate}. Therefore all episodes are stale. Adding season to stale list.", mostRecentUserData.LastPlayedDate);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
@@ -238,14 +266,15 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
}
|
||||
}
|
||||
// Check for episodes that have gone unwatched for stale media cutoff
|
||||
else if (seasonIsStale)
|
||||
else if (seasonCanBeStale)
|
||||
{
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("No user data, adding all episodes as it is outside of cutoff.");
|
||||
_logger.LogInformation("No user data, and creation date is outside of media cutoff, season is stale.");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
staleEpisodes.AddRange(episodes);
|
||||
}
|
||||
seasonNumber++;
|
||||
}
|
||||
|
||||
return staleEpisodes;
|
||||
|
||||
Reference in New Issue
Block a user