Fixed stale episode logic.
This commit is contained in:
@@ -125,11 +125,11 @@ public class LoggingHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PrintDebugSeasonNumber(int seasonNumber)
|
public void PrintDebugSeasonInfo()
|
||||||
{
|
{
|
||||||
if (Configuration.DebugMode)
|
if (Configuration.DebugMode)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Season {SeasonNumber} debug information:", [seasonNumber]);
|
_logger.LogInformation("Season debug information:");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,12 +149,12 @@ public class LoggingHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PrintDebugNoUserDataAndOutsideCutoffEpisodeInfo(IReadOnlyCollection<BaseItem> episodes, int seasonNumber)
|
public void PrintDebugNoUserDataAndOutsideCutoffEpisodeInfo(IReadOnlyCollection<BaseItem> episodes)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(episodes);
|
ArgumentNullException.ThrowIfNull(episodes);
|
||||||
|
|
||||||
if(Configuration.DebugMode){
|
if(Configuration.DebugMode){
|
||||||
_logger.LogInformation("No user data, and creation date is outside of media cutoff, Season {SeasonNumber} is stale.", seasonNumber);
|
_logger.LogInformation("No user data, and creation date is outside of media cutoff, Season is stale.");
|
||||||
|
|
||||||
_logger.LogInformation("-------------------------------------------------");
|
_logger.LogInformation("-------------------------------------------------");
|
||||||
_logger.LogInformation("Episode creation dates:");
|
_logger.LogInformation("Episode creation dates:");
|
||||||
|
|||||||
@@ -25,17 +25,24 @@ public class SeriesHelper
|
|||||||
private static PluginConfiguration Configuration =>
|
private static PluginConfiguration Configuration =>
|
||||||
Plugin.Instance!.Configuration;
|
Plugin.Instance!.Configuration;
|
||||||
|
|
||||||
public bool IsSeasonUserDataStale(IReadOnlyList<BaseItem> episodes, int seasonNumber)
|
public bool IsSeasonUserDataStale(IReadOnlyList<BaseItem> episodes)
|
||||||
{
|
{
|
||||||
bool seasonIsStale = false;
|
bool seasonIsStale = false;
|
||||||
|
|
||||||
|
List<BaseItem> staleEpisodes = [];
|
||||||
|
|
||||||
var episodesWithUserData = episodes.Where(episode => episode.UserData.Where(data => data.LastPlayedDate != null).ToList().Count > 0).ToList();
|
var episodesWithUserData = episodes.Where(episode => episode.UserData.Where(data => data.LastPlayedDate != null).ToList().Count > 0).ToList();
|
||||||
|
|
||||||
_loggingHelper.PrintDebugEpisodesWithUserData(episodesWithUserData);
|
_loggingHelper.PrintDebugEpisodesWithUserData(episodesWithUserData);
|
||||||
|
|
||||||
foreach (var episode in episodesWithUserData)
|
foreach (var episode in episodesWithUserData)
|
||||||
{
|
{
|
||||||
|
bool episodeIsStale = false;
|
||||||
|
|
||||||
var mostRecentUserData = episode.UserData.OrderByDescending(data => data.LastPlayedDate).First(data => data.LastPlayedDate != null);
|
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){
|
if(Configuration.DebugMode){
|
||||||
_logger.LogInformation("User data for episode: {Episode}", episode);
|
_logger.LogInformation("User data for episode: {Episode}", episode);
|
||||||
_logger.LogInformation("-------------------------------------------------");
|
_logger.LogInformation("-------------------------------------------------");
|
||||||
@@ -45,15 +52,30 @@ public class SeriesHelper
|
|||||||
}
|
}
|
||||||
_logger.LogInformation("-------------------------------------------------");
|
_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;
|
return seasonIsStale;
|
||||||
|
|||||||
@@ -112,8 +112,6 @@ public sealed class StaleMediaTask : IScheduledTask
|
|||||||
|
|
||||||
_loggingHelper.PrintDebugDataForSeries(item);
|
_loggingHelper.PrintDebugDataForSeries(item);
|
||||||
|
|
||||||
int seasonNumber = 1;
|
|
||||||
|
|
||||||
foreach (var season in seasons)
|
foreach (var season in seasons)
|
||||||
{
|
{
|
||||||
// Gets each episode, to access user data.
|
// Gets each episode, to access user data.
|
||||||
@@ -125,7 +123,7 @@ public sealed class StaleMediaTask : IScheduledTask
|
|||||||
|
|
||||||
bool seasonCreatedOutsideCutoff = episodes.All(episode => episode.DateCreated < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff));
|
bool seasonCreatedOutsideCutoff = episodes.All(episode => episode.DateCreated < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff));
|
||||||
|
|
||||||
_loggingHelper.PrintDebugSeasonNumber(seasonNumber);
|
_loggingHelper.PrintDebugSeasonInfo();
|
||||||
|
|
||||||
if (seasonCreatedOutsideCutoff)
|
if (seasonCreatedOutsideCutoff)
|
||||||
{
|
{
|
||||||
@@ -133,19 +131,18 @@ public sealed class StaleMediaTask : IScheduledTask
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool seasonHasUserData = episodes.Any(episode => episode.UserData.Count > 0);
|
bool seasonHasUserData = episodes.Any(episode => episode.UserData.Count > 0);
|
||||||
bool seasonIsStale = (seasonHasUserData && _seriesHelper.IsSeasonUserDataStale(episodes, seasonNumber)) || seasonCreatedOutsideCutoff;
|
bool seasonIsStale = (seasonHasUserData && _seriesHelper.IsSeasonUserDataStale(episodes)) || seasonCreatedOutsideCutoff;
|
||||||
bool noUserDataAndOutsideCutoff = !seasonHasUserData && seasonCreatedOutsideCutoff;
|
bool noUserDataAndOutsideCutoff = !seasonHasUserData && seasonCreatedOutsideCutoff;
|
||||||
|
|
||||||
if (seasonIsStale)
|
if (seasonIsStale)
|
||||||
{
|
{
|
||||||
if (noUserDataAndOutsideCutoff)
|
if (noUserDataAndOutsideCutoff)
|
||||||
{
|
{
|
||||||
_loggingHelper.PrintDebugNoUserDataAndOutsideCutoffEpisodeInfo(episodes, seasonNumber);
|
_loggingHelper.PrintDebugNoUserDataAndOutsideCutoffEpisodeInfo(episodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
staleEpisodes.AddRange(episodes);
|
staleEpisodes.AddRange(episodes);
|
||||||
}
|
}
|
||||||
seasonNumber++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_loggingHelper.PrintDebugEndOfScanningForSeries(item);
|
_loggingHelper.PrintDebugEndOfScanningForSeries(item);
|
||||||
|
|||||||
Reference in New Issue
Block a user