Further enhanced logging and refactored StaleMediaTask to aid in maintainability
This commit is contained in:
61
Jellyfin.Plugin.MediaCleaner/Helpers/SeriesHelper.cs
Normal file
61
Jellyfin.Plugin.MediaCleaner/Helpers/SeriesHelper.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Jellyfin.Database.Implementations.Entities;
|
||||
using Jellyfin.Database.Implementations.Entities.Libraries;
|
||||
using Jellyfin.Plugin.MediaCleaner.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
namespace Jellyfin.Plugin.MediaCleaner.Helpers;
|
||||
|
||||
public class SeriesHelper
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly LoggingHelper _loggingHelper;
|
||||
|
||||
public SeriesHelper(ILogger logger)
|
||||
{
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
_loggingHelper = new LoggingHelper(logger);
|
||||
}
|
||||
|
||||
private static PluginConfiguration Configuration =>
|
||||
Plugin.Instance!.Configuration;
|
||||
|
||||
public bool IsSeasonUserDataStale(IReadOnlyList<BaseItem> episodes, int seasonNumber)
|
||||
{
|
||||
bool seasonIsStale = false;
|
||||
|
||||
var episodesWithUserData = episodes.Where(episode => episode.UserData.Where(data => data.LastPlayedDate != null).ToList().Count > 0).ToList();
|
||||
|
||||
_loggingHelper.PrintDebugEpisodesWithUserData(episodesWithUserData);
|
||||
|
||||
foreach (var episode in episodesWithUserData)
|
||||
{
|
||||
var mostRecentUserData = episode.UserData.OrderByDescending(data => data.LastPlayedDate).Where(data => data.LastPlayedDate != null).First();
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("User data for episode: {Episode}", episode);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
foreach (var property in typeof(UserData).GetProperties())
|
||||
{
|
||||
_logger.LogInformation("{PropertyName}: {PropertyValue}", property.Name, property.GetValue(mostRecentUserData));
|
||||
}
|
||||
_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;
|
||||
}
|
||||
}
|
||||
|
||||
return seasonIsStale;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user