Significantly refactored code to help with readability of logging and episode processing
This commit is contained in:
@@ -60,7 +60,10 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
|
||||
Task IScheduledTask.ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
_loggingHelper.StartLogging();
|
||||
_loggingHelper.LogDebugInformation("--DEBUG MODE ACTIVE--");
|
||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogInformation("Starting stale media scan...");
|
||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||
|
||||
var query = new InternalItemsQuery
|
||||
{
|
||||
@@ -70,21 +73,51 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
|
||||
List<BaseItem> allItems = [.. _libraryManager.GetItemsResult(query).Items];
|
||||
|
||||
_loggingHelper.PrintItemsInformation(allItems);
|
||||
_loggingHelper.LogInformation("Total items: {ItemCount}", allItems.Count);
|
||||
_loggingHelper.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)];
|
||||
|
||||
_loggingHelper.StartScanningSeriesItems();
|
||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogInformation("Starting scan of series items.");
|
||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||
|
||||
List<BaseItem> staleEpisodes = [.. series.SelectMany(GetStaleEpisodes)];
|
||||
|
||||
_loggingHelper.StartScanningMoviesItems();
|
||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogInformation("Starting scan of movies items.");
|
||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||
|
||||
List<BaseItem> staleMovies = [.. GetStaleMovies(movies)];
|
||||
|
||||
_loggingHelper.PrintStaleMoviesInformation(staleMovies);
|
||||
_loggingHelper.PrintStaleEpisodesInformation(FindSeriesInfoFromEpisodes, staleEpisodes);
|
||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogInformation("Stale Movies found: {StaleMovies}", staleMovies.Count);
|
||||
|
||||
_loggingHelper.EndLogging();
|
||||
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.LogInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogInformation("Stale Episodes found: {StaleEpisodes}", staleEpisodes.Count);
|
||||
|
||||
if (staleEpisodes.Count > 0 && Configuration.DebugMode)
|
||||
{
|
||||
List<SeriesInfo> seriesInfoList = FindSeriesInfoFromEpisodes(staleEpisodes);
|
||||
|
||||
foreach (var seriesInfo in seriesInfoList)
|
||||
{
|
||||
_loggingHelper.LogDebugInformation("Series Info: ID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.Id, seriesInfo.SeriesName, string.Join(", ", seriesInfo.Seasons)]);
|
||||
}
|
||||
}
|
||||
|
||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogInformation("Ending stale media scan...");
|
||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@@ -101,7 +134,9 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
|
||||
private List<BaseItem> GetStaleEpisodes(BaseItem item)
|
||||
{
|
||||
List<BaseItem> staleEpisodes = [];
|
||||
_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
|
||||
@@ -110,34 +145,21 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
Recursive = false
|
||||
});
|
||||
|
||||
_loggingHelper.PrintDebugDataForSeries(item);
|
||||
|
||||
foreach (var season in seasons)
|
||||
{
|
||||
// Gets each episode, to access user data.
|
||||
List<BaseItem> staleEpisodes = [ ..seasons
|
||||
.Where(season => {
|
||||
var episodes = _libraryManager.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
ParentId = season.Id,
|
||||
Recursive = false
|
||||
});
|
||||
|
||||
_loggingHelper.PrintDebugSeasonInfo();
|
||||
_loggingHelper.LogDebugInformation("Season debug information for {SeasonNumber}:", season);
|
||||
|
||||
bool seasonHasUserData = episodes.Any(episode => episode.UserData.Count > 0);
|
||||
bool seasonIsStale = seasonHasUserData && _seriesHelper.IsSeasonUserDataStale(episodes);
|
||||
return _seriesHelper.IsSeasonDataStale(episodes);
|
||||
})];
|
||||
|
||||
if (seasonIsStale)
|
||||
{
|
||||
if (!seasonHasUserData)
|
||||
{
|
||||
_loggingHelper.PrintDebugEpisodeCreationInfo(episodes);
|
||||
}
|
||||
|
||||
staleEpisodes.AddRange(episodes);
|
||||
}
|
||||
}
|
||||
|
||||
_loggingHelper.PrintDebugEndOfScanningForSeries(item);
|
||||
_loggingHelper.LogDebugInformation("End of scanning for series: {Series}", item);
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
|
||||
return staleEpisodes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user