Continued to improve logging and fixed a few bugs introduced by refactor
This commit is contained in:
@@ -17,7 +17,6 @@ public class MovieHelper(ILogger logger)
|
||||
|
||||
public bool IsMovieStale(BaseItem movie)
|
||||
{
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogDebugInformation("Start of scanning for movie: {Movie}", movie);
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
|
||||
@@ -41,19 +40,22 @@ public class MovieHelper(ILogger logger)
|
||||
|
||||
if (mostRecentUserData.LastPlayedDate < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff))
|
||||
{
|
||||
_loggingHelper.LogDebugInformation("Most recent user data last played date is outside of cutoff. Adding {Movie} to stale movies.", movie);
|
||||
_loggingHelper.LogDebugInformation("Most recent user data has last played date that is outside of cutoff.");
|
||||
_loggingHelper.LogDebugInformation("Adding {Movie} to stale movies.", movie);
|
||||
_loggingHelper.LogDebugInformation("With Last Played Date: {LastPlayedDate}", mostRecentUserData.LastPlayedDate);
|
||||
|
||||
movieIsStale = true;
|
||||
}
|
||||
}
|
||||
else if (createdOutsideCutoff)
|
||||
{
|
||||
_loggingHelper.LogDebugInformation("Movie has no user data and was created outside of cutoff: {DateCreated}. Adding {Movie} to stale movies.", [movie.DateCreated, movie]);
|
||||
_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;
|
||||
}
|
||||
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogDebugInformation("End of scanning for movie: {Movie}", movie);
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
|
||||
return movieIsStale;
|
||||
}
|
||||
|
||||
@@ -28,8 +28,13 @@ public class SeriesHelper(ILogger logger)
|
||||
var staleCreationDate = episode.DateCreated < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff);
|
||||
var hasUserDataWithLastPlayedDate = episode.UserData.Any(data => data.LastPlayedDate != null);
|
||||
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogDebugInformation("Debug data for episode: {Episode}", episode);
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
|
||||
if (staleCreationDate && !hasUserDataWithLastPlayedDate){
|
||||
_loggingHelper.LogInformation("Creation date is stale, and no user data for episode {Episode}.", episode);
|
||||
_loggingHelper.LogDebugInformation("Creation date is stale, and no user data for episode {Episode}.", episode);
|
||||
_loggingHelper.LogDebugInformation("Date created: {DateCreated}", episode.DateCreated);
|
||||
episodeIsStale = true;
|
||||
}
|
||||
|
||||
@@ -38,9 +43,6 @@ public class SeriesHelper(ILogger logger)
|
||||
.OrderByDescending(data => data.LastPlayedDate)
|
||||
.First();
|
||||
|
||||
_loggingHelper.LogDebugInformation("User data for episode: {Episode}", episode);
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
|
||||
foreach (var property in typeof(UserData).GetProperties())
|
||||
{
|
||||
_loggingHelper.LogDebugInformation("{PropertyName}: {PropertyValue}", property.Name, property.GetValue(mostRecentUserData));
|
||||
@@ -54,7 +56,7 @@ public class SeriesHelper(ILogger logger)
|
||||
{
|
||||
episodeIsStale = true;
|
||||
_loggingHelper.LogDebugInformation("Most recent user data has a last played date of: {LastPlayedDate}.", [mostRecentUserData.LastPlayedDate]);
|
||||
_loggingHelper.LogDebugInformation("And episode created {DateCreated}.", episode.DateCreated);
|
||||
_loggingHelper.LogDebugInformation("Episode created {DateCreated}.", episode.DateCreated);
|
||||
_loggingHelper.LogDebugInformation("Episode is marked as stale.");
|
||||
}
|
||||
}
|
||||
@@ -79,6 +81,8 @@ public class SeriesHelper(ILogger logger)
|
||||
if(staleEpisodes.Count == episodes.Count)
|
||||
{
|
||||
seasonIsStale = true;
|
||||
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogDebugInformation("Stale episodes count matches season episode count. Season is stale.");
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
@@ -22,9 +22,5 @@ public class SeriesInfo
|
||||
/// <summary>
|
||||
/// Gets or sets seasons.
|
||||
/// </summary>
|
||||
#pragma warning disable CA2227 // Collection properties should be read only
|
||||
#pragma warning disable CA1002 // Do not expose generic lists
|
||||
public List<string> Seasons { get; set; } = [];
|
||||
#pragma warning restore CA1002 // Do not expose generic lists
|
||||
#pragma warning restore CA2227 // Collection properties should be read only
|
||||
public IEnumerable<string> Seasons { get; set; } = [];
|
||||
}
|
||||
|
||||
@@ -83,9 +83,8 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
_loggingHelper.LogInformation("Starting scan of series items.");
|
||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||
|
||||
List<BaseItem> staleEpisodes = [.. series.SelectMany(GetStaleEpisodes)];
|
||||
List<BaseItem> staleSeasons = [.. series.SelectMany(GetStaleSeasons)];
|
||||
|
||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogInformation("Starting scan of movies items.");
|
||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||
|
||||
@@ -103,13 +102,13 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
}
|
||||
|
||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogInformation("Stale Episodes found: {StaleEpisodes}", staleEpisodes.Count);
|
||||
_loggingHelper.LogInformation("Stale seasons found: {StaleSeasons}", staleSeasons.Count);
|
||||
|
||||
if (staleEpisodes.Count > 0 && Configuration.DebugMode)
|
||||
if (staleSeasons.Count > 0 && Configuration.DebugMode)
|
||||
{
|
||||
List<SeriesInfo> seriesInfoList = FindSeriesInfoFromEpisodes(staleEpisodes);
|
||||
IEnumerable<SeriesInfo> staleSeriesInfo = FindSeriesInfo(staleSeasons);
|
||||
|
||||
foreach (var seriesInfo in seriesInfoList)
|
||||
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)]);
|
||||
}
|
||||
@@ -132,9 +131,8 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
}
|
||||
|
||||
|
||||
private List<BaseItem> GetStaleEpisodes(BaseItem item)
|
||||
private List<BaseItem> GetStaleSeasons(BaseItem item)
|
||||
{
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogDebugInformation("Debug data for series: {SeriesName}", item.Name);
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
|
||||
@@ -145,7 +143,7 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
Recursive = false
|
||||
});
|
||||
|
||||
List<BaseItem> staleEpisodes = [ ..seasons
|
||||
List<BaseItem> staleSeasons = [ ..seasons
|
||||
.Where(season => {
|
||||
var episodes = _libraryManager.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
@@ -155,43 +153,38 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
|
||||
_loggingHelper.LogDebugInformation("Season debug information for {SeasonNumber}:", season);
|
||||
|
||||
return _seriesHelper.IsSeasonDataStale(episodes);
|
||||
bool isSeasonDataStale = _seriesHelper.IsSeasonDataStale(episodes);
|
||||
|
||||
_loggingHelper.LogDebugInformation("End of season debug information for {SeasonNumber}.", season);
|
||||
|
||||
return isSeasonDataStale;
|
||||
})];
|
||||
|
||||
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogDebugInformation("End of scanning for series: {Series}", item);
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
|
||||
return staleEpisodes;
|
||||
return staleSeasons;
|
||||
}
|
||||
|
||||
private List<SeriesInfo> FindSeriesInfoFromEpisodes(IReadOnlyCollection<BaseItem> episodes)
|
||||
private IEnumerable<SeriesInfo> FindSeriesInfo(IReadOnlyCollection<BaseItem> seasons)
|
||||
{
|
||||
Guid[] seasonIds = [.. episodes.Select(episode => episode.ParentId).Distinct()];
|
||||
|
||||
var seasons = _libraryManager.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
ItemIds = seasonIds
|
||||
});
|
||||
|
||||
Guid[] seriesIds = [.. seasons.Select(season => season.ParentId).Distinct()];
|
||||
|
||||
var series = _libraryManager.GetItemList(new InternalItemsQuery
|
||||
IReadOnlyCollection<BaseItem> series = _libraryManager.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
ItemIds = seriesIds
|
||||
}).ToList();
|
||||
});
|
||||
|
||||
List<string> seriesNames = [.. series.Select(series => series.Name).Distinct()];
|
||||
|
||||
List<SeriesInfo> seriesInfoList = [];
|
||||
|
||||
series.ForEach(series =>
|
||||
IEnumerable<SeriesInfo> seriesInfoList = series.Select(series =>
|
||||
{
|
||||
seriesInfoList.Add(new SeriesInfo
|
||||
return new SeriesInfo
|
||||
{
|
||||
Id = series.Id,
|
||||
SeriesName = series.Name,
|
||||
Seasons = [.. seasons.Where(season => season.ParentId == series.Id).Select(season => season.Name)]
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
return seriesInfoList;
|
||||
|
||||
Reference in New Issue
Block a user