Fixed stale episode logic.
This commit is contained in:
@@ -25,17 +25,24 @@ public class SeriesHelper
|
||||
private static PluginConfiguration Configuration =>
|
||||
Plugin.Instance!.Configuration;
|
||||
|
||||
public bool IsSeasonUserDataStale(IReadOnlyList<BaseItem> episodes, int seasonNumber)
|
||||
public bool IsSeasonUserDataStale(IReadOnlyList<BaseItem> episodes)
|
||||
{
|
||||
bool seasonIsStale = false;
|
||||
|
||||
List<BaseItem> staleEpisodes = [];
|
||||
|
||||
var episodesWithUserData = episodes.Where(episode => episode.UserData.Where(data => data.LastPlayedDate != null).ToList().Count > 0).ToList();
|
||||
|
||||
_loggingHelper.PrintDebugEpisodesWithUserData(episodesWithUserData);
|
||||
|
||||
foreach (var episode in episodesWithUserData)
|
||||
{
|
||||
bool episodeIsStale = false;
|
||||
|
||||
var mostRecentUserData = episode.UserData.OrderByDescending(data => data.LastPlayedDate).First(data => data.LastPlayedDate != null);
|
||||
var staleLastPlayedDate = mostRecentUserData.LastPlayedDate < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff);
|
||||
var staleCreationDate = episode.DateCreated < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff);
|
||||
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("User data for episode: {Episode}", episode);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
@@ -45,15 +52,30 @@ public class SeriesHelper
|
||||
}
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
if (mostRecentUserData.LastPlayedDate < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff))
|
||||
{
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("Most recent user data has a last played date of: {LastPlayedDate}. Therefore all episodes are stale. Adding Season {SeasonNumber} to stale list.", [mostRecentUserData.LastPlayedDate, seasonNumber]);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
seasonIsStale = true;
|
||||
if (staleLastPlayedDate && staleCreationDate)
|
||||
{
|
||||
episodeIsStale = true;
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("Most recent user data has a last played date of: {LastPlayedDate}.", [mostRecentUserData.LastPlayedDate]);
|
||||
_logger.LogInformation("And episode created {DateCreated}.", episode.DateCreated);
|
||||
}
|
||||
}
|
||||
|
||||
if (episodeIsStale)
|
||||
{
|
||||
staleEpisodes.Add(episode);
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("Episode is stale.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(staleEpisodes.Count == episodes.Count)
|
||||
{
|
||||
seasonIsStale = true;
|
||||
_logger.LogInformation("Stale episodes count matches all episode count. Season is stale.");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
return seasonIsStale;
|
||||
|
||||
Reference in New Issue
Block a user