Skip to content

Commit

Permalink
Fix series virtual episodes messing with detection
Browse files Browse the repository at this point in the history
  • Loading branch information
shemanaev committed Aug 2, 2022
1 parent cb34b54 commit 6895ac6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
22 changes: 17 additions & 5 deletions MediaCleaner/JunkCollectors/BaseJunkCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,24 @@ protected List<T> GetUserItems<T>(User user) where T : BaseItem =>
})
.Cast<T>().ToList();

protected List<ExpiredItem> FilterExcludedLocations(List<ExpiredItem> items, List<string> locations, LocationsListMode mode) => mode switch
protected List<ExpiredItem> FilterExcludedLocations(List<ExpiredItem> items, List<string> locations, LocationsListMode mode) => items.Where(x =>
{
LocationsListMode.Exclude => items.Where(x => !locations.Any(s => _fileSystem.ContainsSubPath(s, x.Item.Path))).ToList(),
LocationsListMode.Include => items.Where(x => locations.Any(s => _fileSystem.ContainsSubPath(s, x.Item.Path))).ToList(),
_ => throw new NotSupportedException()
};
var path = x.Item switch
{
Episode episode => episode.Path,
Season season => season.GetEpisodes().Where(x => !x.IsVirtualItem).First().Path,
Series series => series.GetEpisodes().Where(x => !x.IsVirtualItem).First().Path,
Movie movie => movie.Path,
_ => x.Item.Path
};
var contains = locations.Any(s => _fileSystem.ContainsSubPath(s, path));
return mode switch
{
LocationsListMode.Exclude => !contains,
LocationsListMode.Include => contains,
_ => throw new NotSupportedException()
};
}).ToList();

protected List<ExpiredItem> FilterFavorites(FavoriteKeepKind kind, List<ExpiredItem> items, List<User> users) => kind switch
{
Expand Down
10 changes: 5 additions & 5 deletions MediaCleaner/JunkCollectors/SeriesJunkCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private List<ExpiredItem> FilterGroup(SeriesDeleteKind kind, List<ExpiredItem> i
{
var first = season.OrderByDescending(x => x.LastPlayedDate).FirstOrDefault();
if (first?.Item is not Episode episode) continue;
var episodes = episode.Season.GetEpisodes();
var episodes = episode.Season.GetEpisodes().Where(x => !x.IsVirtualItem).ToList();
var allWatched = season.Count() == episodes.Count && season.All(value => episodes.Contains(value.Item));
if (allWatched)
{
Expand All @@ -55,8 +55,8 @@ private List<ExpiredItem> FilterGroup(SeriesDeleteKind kind, List<ExpiredItem> i
});
}

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

break;
Expand All @@ -67,7 +67,7 @@ private List<ExpiredItem> FilterGroup(SeriesDeleteKind kind, List<ExpiredItem> i
{
var first = show.OrderByDescending(x => x.LastPlayedDate).FirstOrDefault();
if (first?.Item is not Episode episode) continue;
var episodes = episode.Series.GetEpisodes().ToList();
var episodes = episode.Series.GetEpisodes().Where(x => !x.IsVirtualItem).ToList();
var allWatched = show.Count() == episodes.Count && show.All(value => episodes.Contains(value.Item));
if (allWatched)
{
Expand All @@ -79,7 +79,7 @@ private List<ExpiredItem> FilterGroup(SeriesDeleteKind kind, List<ExpiredItem> i
});
}
_logger.LogDebug("'{User}' has watched episodes {Count} of {Total} in series {SeriesName}",
show.First().User.Username, episodes.Count, show.Count(), episode.Series.Name);
show.First().User.Username, show.Count(), episodes.Count, episode.Series.Name);
}

break;
Expand Down

0 comments on commit 6895ac6

Please sign in to comment.