Skip to content

Commit

Permalink
Add log
Browse files Browse the repository at this point in the history
  • Loading branch information
shemanaev committed Aug 26, 2024
1 parent 99a60c5 commit 61addf4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion MediaCleaner/Filtering/SeriesFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,32 @@ public List<ExpiredItem> Apply(List<ExpiredItem> items)
{
var result = new List<ExpiredItem>();

_logger.LogInformation("SeriesFilter start: {Items}", items.Select(x => x.Item.Id));

switch (_kind)
{
case SeriesDeleteKind.Season:
var seasons = items.GroupBy(x => x.Item is Episode episode ? episode.Season?.Id ?? episode.Series?.Id : null);
var seasons = items.GroupBy(x => x.Item is Episode episode ? episode.Season?.Id ?? episode.Series?.Id : null);
_logger.LogInformation("SeriesFilter seasons: {Count}, {Items}", seasons.Count(), seasons.Select(x => x.Key));
foreach (var season in seasons)
{
_logger.LogInformation("SeriesFilter season: {Id}", season.Key);
var first = season.MaxBy(x => x.Data?.First()?.LastPlayedDate ?? x.Item.DateCreated);
if (first?.Item is not Episode episode) continue;
if (episode.Season == null) continue;
_logger.LogInformation("SeriesFilter first episode: {episode}", episode.Id);
var episodes = episode.Season.GetEpisodes().Where(x => !x.IsVirtualItem).ToList();
var allWatched = season.Count() == episodes.Count && season.All(value => episodes.Contains(value.Item));

_logger.LogInformation("SeriesFilter allWatched: {allWatched}", allWatched);

_logger.LogDebug("\"{Username}\" has watched episodes {Count} of {Total} in season \"{SeriesName}\": \"{SeasonName}\"",
season.First().Data?.First()?.User.Username ?? "[None]", season.Count(), episodes.Count, episode.Series.Name, episode.Season.Name);

if (allWatched)
{
_logger.LogInformation("SeriesFilter allWatched true: {OriginalTitle}", episode.Season);

result.Add(new ExpiredItem
{
Item = episode.Season,
Expand Down

0 comments on commit 61addf4

Please sign in to comment.