Added debugging
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<AssemblyVersion>0.0.0.3</AssemblyVersion>
|
||||
<AssemblyVersion>0.0.0.4</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
@@ -31,4 +31,9 @@ public class PluginConfiguration : BasePluginConfiguration
|
||||
/// Gets or sets the cut off days before deleting unwatched files.
|
||||
/// </summary>
|
||||
public int StaleMediaCutoff { get; set; } = 90;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets debug mode.
|
||||
/// </summary>
|
||||
public bool DebugMode { get; set; }
|
||||
}
|
||||
|
||||
@@ -24,6 +24,12 @@
|
||||
<input id="StaleMediaCutoff" name="StaleMediaCutoff" type="number" is="emby-input" style="width: 20%;"/>
|
||||
<div class="fieldDescription">How many days to wait before marking files as stale</div>
|
||||
</div>
|
||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||
<label class="emby-checkbox-label">
|
||||
<input id="DebugMode" name="DebugMode" type="checkbox" is="emby-checkbox" />
|
||||
<span>Debug Mode</span>
|
||||
</label>
|
||||
</div>
|
||||
<!-- <div class="selectContainer">
|
||||
<label class="selectLabel" for="Options">Several Options</label>
|
||||
<select is="emby-select" id="Options" name="Options" class="emby-select-withcolor emby-select">
|
||||
@@ -71,6 +77,7 @@
|
||||
document.querySelector('#RadarrAPIKey').value = config.RadarrAPIKey;
|
||||
document.querySelector('#SonarrAPIKey').value = config.SonarrAPIKey;
|
||||
document.querySelector('#StaleMediaCutoff').value = config.StaleMediaCutoff;
|
||||
document.querySelector('#DebugMode').checked = config.DebugMode;
|
||||
Dashboard.hideLoadingMsg();
|
||||
});
|
||||
});
|
||||
@@ -86,6 +93,7 @@
|
||||
config.RadarrAPIKey = document.querySelector('#RadarrAPIKey').value;
|
||||
config.SonarrAPIKey = document.querySelector('#SonarrAPIKey').value;
|
||||
config.StaleMediaCutoff = document.querySelector('#StaleMediaCutoff').value;
|
||||
config.DebugMode = document.querySelector('#DebugMode').checked;
|
||||
ApiClient.updatePluginConfiguration(MediaCleanerConfig.pluginUniqueId, config).then(function (result) {
|
||||
Dashboard.processPluginConfigurationUpdateResult(result);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Data.Common;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
@@ -61,7 +62,10 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
};
|
||||
List<BaseItem> allItems = [.. _libraryManager.GetItemsResult(query).Items];
|
||||
|
||||
_logger.LogInformation("Total items found: {AllItems}", allItems);
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("Total items found: {AllItems}", allItems);
|
||||
}
|
||||
|
||||
List<BaseItem> series = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Series)];
|
||||
List<BaseItem> movies = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Movie)];
|
||||
@@ -83,7 +87,10 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
|
||||
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)]);
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("Series Info: ID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.Id, seriesInfo.SeriesName, string.Join(", ", seriesInfo.Seasons)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,17 +105,34 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
{
|
||||
bool movieIsStale = movie.DateCreated < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff);
|
||||
bool movieHasUserData = movie.UserData.Count > 0;
|
||||
|
||||
if (movieHasUserData)
|
||||
{
|
||||
if (Configuration.DebugMode){
|
||||
_logger.LogInformation("Movie has user data: {Movie}", movie);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
var mostRecentUserData = movie.UserData.OrderByDescending(data => data.LastPlayedDate).First();
|
||||
|
||||
if (Configuration.DebugMode){
|
||||
_logger.LogInformation("Most recent user data: {Movie}", movie);
|
||||
|
||||
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))
|
||||
{
|
||||
_logger.LogInformation("Most recent user data last played date is outside of cutoff. Adding to stale movies.");
|
||||
staleMovies.Add(movie);
|
||||
}
|
||||
}
|
||||
else if (movieIsStale)
|
||||
{
|
||||
_logger.LogInformation("Movie has no user data and was created outside of cutoff: {DateCreated}", movie.DateCreated);
|
||||
staleMovies.Add(movie);
|
||||
}
|
||||
}
|
||||
@@ -170,13 +194,13 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
Recursive = false
|
||||
});
|
||||
bool seasonHasUserData = episodes.Any(episode => episode.UserData.Count > 0);
|
||||
if (seasonHasUserData)
|
||||
if (seasonHasUserData && Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("Season has user data for episodes: {Episodes}", episodes);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
bool seasonIsStale = episodes.All(episode => episode.DateCreated < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff));
|
||||
if (seasonIsStale)
|
||||
if (seasonIsStale && Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("All episodes are outside media cutoff.");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
@@ -185,17 +209,29 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
if (seasonHasUserData)
|
||||
{
|
||||
var episodesWithUserData = episodes.Where(episode => episode.UserData.Count > 0).ToList();
|
||||
_logger.LogInformation("Episodes with user data: {EpisodesWithUserData}", episodesWithUserData);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("Episodes with user data: {EpisodesWithUserData}", episodesWithUserData);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
foreach (var episode in episodesWithUserData)
|
||||
{
|
||||
var mostRecentUserData = episode.UserData.OrderByDescending(data => data.LastPlayedDate).First();
|
||||
_logger.LogInformation("Most recent user data: {MostRecentUserData}", mostRecentUserData);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
if(Configuration.DebugMode){
|
||||
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))
|
||||
{
|
||||
_logger.LogInformation("Episodes outside of cutoff: {Episodes}", episodes);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("Most Recent User Data Last Played Date is: {LastPlayedDate}. All Episodes are stale.", mostRecentUserData.LastPlayedDate);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
staleEpisodes.AddRange(episodes);
|
||||
break;
|
||||
}
|
||||
@@ -204,8 +240,10 @@ public sealed class StaleMediaTask : IScheduledTask
|
||||
// Check for episodes that have gone unwatched for stale media cutoff
|
||||
else if (seasonIsStale)
|
||||
{
|
||||
_logger.LogInformation("No user data, adding all episodes as it is outside of cutoff.");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("No user data, adding all episodes as it is outside of cutoff.");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
staleEpisodes.AddRange(episodes);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user