Significantly refactored code to help with readability of logging and episode processing
This commit is contained in:
@@ -8,26 +8,18 @@ using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.MediaCleaner.Helpers;
|
||||
|
||||
public class MovieHelper
|
||||
public class MovieHelper(ILogger logger)
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public MovieHelper(ILogger logger)
|
||||
{
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
private readonly LoggingHelper _loggingHelper = new(logger);
|
||||
|
||||
private static PluginConfiguration Configuration =>
|
||||
Plugin.Instance!.Configuration;
|
||||
|
||||
public bool IsMovieStale(BaseItem movie)
|
||||
{
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Start of scanning for movie: {Movie}", movie);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogDebugInformation("Start of scanning for movie: {Movie}", movie);
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
|
||||
bool movieIsStale = false;
|
||||
|
||||
@@ -38,40 +30,30 @@ public class MovieHelper
|
||||
{
|
||||
var mostRecentUserData = movie.UserData.OrderByDescending(data => data.LastPlayedDate).First(data => data.LastPlayedDate != null);
|
||||
|
||||
if (Configuration.DebugMode){
|
||||
_logger.LogInformation("Most recent user data: {Movie}", movie);
|
||||
_loggingHelper.LogDebugInformation("Most recent user data: {Movie}", movie);
|
||||
|
||||
foreach (var property in typeof(UserData).GetProperties())
|
||||
{
|
||||
_logger.LogInformation("{PropertyName}: {PropertyValue}", property.Name, property.GetValue(mostRecentUserData));
|
||||
}
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
foreach (var property in typeof(UserData).GetProperties())
|
||||
{
|
||||
_loggingHelper.LogDebugInformation("{PropertyName}: {PropertyValue}", property.Name, property.GetValue(mostRecentUserData));
|
||||
}
|
||||
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
|
||||
if (mostRecentUserData.LastPlayedDate < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff))
|
||||
{
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("Most recent user data last played date is outside of cutoff. Adding {Movie} to stale movies.", movie);
|
||||
}
|
||||
_loggingHelper.LogDebugInformation("Most recent user data last played date is outside of cutoff. Adding {Movie} to stale movies.", movie);
|
||||
movieIsStale = true;
|
||||
}
|
||||
}
|
||||
else if (createdOutsideCutoff)
|
||||
{
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("Movie has no user data and was created outside of cutoff: {DateCreated}. Adding {Movie} to stale movies.", [movie.DateCreated, movie]);
|
||||
}
|
||||
_loggingHelper.LogDebugInformation("Movie has no user data and was created outside of cutoff: {DateCreated}. Adding {Movie} to stale movies.", [movie.DateCreated, movie]);
|
||||
movieIsStale = true;
|
||||
}
|
||||
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("End of scanning for movie: {Movie}", movie);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
_loggingHelper.LogDebugInformation("End of scanning for movie: {Movie}", movie);
|
||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||
|
||||
return movieIsStale;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user