Further enhanced logging and refactored StaleMediaTask to aid in maintainability
This commit is contained in:
168
Jellyfin.Plugin.MediaCleaner/Helpers/LoggingHelper.cs
Normal file
168
Jellyfin.Plugin.MediaCleaner/Helpers/LoggingHelper.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Jellyfin.Plugin.MediaCleaner.Configuration;
|
||||
using Jellyfin.Plugin.MediaCleaner.Models;
|
||||
using Jellyfin.Plugin.MediaCleaner.ScheduledTasks;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.MediaCleaner.Helpers;
|
||||
|
||||
public class LoggingHelper
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public LoggingHelper(ILogger logger)
|
||||
{
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
private static PluginConfiguration Configuration =>
|
||||
Plugin.Instance!.Configuration;
|
||||
|
||||
public void StartLogging()
|
||||
{
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("--DEBUG MODE ACTIVE--");
|
||||
}
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Starting stale media scan...");
|
||||
}
|
||||
|
||||
public void EndLogging()
|
||||
{
|
||||
_logger.LogInformation("Ending stale media scan...");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
public void EndOfScanningForSeries(BaseItem item)
|
||||
{
|
||||
_logger.LogInformation("End of scanning for series: {Series}", item);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
|
||||
public void StartScanningSeriesItems()
|
||||
{
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Starting scan of series items.");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
public void StartScanningMoviesItems()
|
||||
{
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Starting scan of movies items.");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
public void PrintStaleItemsInformation(IReadOnlyCollection<BaseItem> staleItems)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(staleItems);
|
||||
|
||||
_logger.LogInformation("Total stale items: {ItemCount}", staleItems.Count);
|
||||
_logger.LogInformation("Stale items found: {AllItems}", staleItems);
|
||||
}
|
||||
|
||||
public void PrintStaleMoviesInformation(IReadOnlyCollection<BaseItem> staleMovies)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(staleMovies);
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Stale Movies found: {StaleMovies}", staleMovies.Count);
|
||||
|
||||
if (staleMovies.Count > 0 && Configuration.DebugMode)
|
||||
{
|
||||
foreach (var movieInfo in staleMovies)
|
||||
{
|
||||
_logger.LogInformation("Movie Info: ID: {Id} | Movie Name: {MovieName}", [movieInfo.Id, movieInfo.Name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintStaleEpisodesInformation(Func<IReadOnlyCollection<BaseItem>, List<SeriesInfo>> findSeriesInfoFromEpisodes, IReadOnlyCollection<BaseItem> staleEpisodes)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(staleEpisodes);
|
||||
ArgumentNullException.ThrowIfNull(findSeriesInfoFromEpisodes);
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Stale Episodes found: {StaleEpisodes}", staleEpisodes.Count);
|
||||
|
||||
if (staleEpisodes.Count > 0 && Configuration.DebugMode)
|
||||
{
|
||||
if (findSeriesInfoFromEpisodes == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(findSeriesInfoFromEpisodes), "The method to find series information cannot be null.");
|
||||
}
|
||||
|
||||
List<SeriesInfo> seriesInfoList = findSeriesInfoFromEpisodes(staleEpisodes);
|
||||
|
||||
foreach (var seriesInfo in seriesInfoList)
|
||||
{
|
||||
_logger.LogInformation("Series Info: ID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.Id, seriesInfo.SeriesName, string.Join(", ", seriesInfo.Seasons)]);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
public void PrintDebugDataForSeries(BaseItem item)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(item);
|
||||
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Debug data for series: {SeriesName}", item.Name);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintDebugSeasonNumber(int seasonNumber)
|
||||
{
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("Season {SeasonNumber} debug information:", [seasonNumber]);
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintDebugSeasonCreatedOutsideCutoff()
|
||||
{
|
||||
if(Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("All episodes were created outside of media cutoff, season is possibly stale.");
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintDebugEpisodesWithUserData(IReadOnlyCollection<BaseItem> episodesWithUserData)
|
||||
{
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("Episodes with user data: {EpisodesWithUserData}", episodesWithUserData);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintDebugNoUserDataAndOutsideCutoffEpisodeInfo(IReadOnlyCollection<BaseItem> episodes, int seasonNumber)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(episodes);
|
||||
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("No user data, and creation date is outside of media cutoff, Season {SeasonNumber} is stale.", seasonNumber);
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Episode creation dates:");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
foreach(BaseItem episode in episodes)
|
||||
{
|
||||
_logger.LogInformation("Episode: {EpisodeName} | Date Created: {EpisodeDateCreated}", [episode.Name, episode.DateCreated]);
|
||||
}
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user