Compare commits
16 Commits
v0.0.1-alp
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| ddf84b5cb6 | |||
| ca1d1fcab1 | |||
| 3b43d6807a | |||
| 2c91846d81 | |||
| c533eb4f90 | |||
| 2fdbae74e8 | |||
| 08e26943c9 | |||
| 65dd638b09 | |||
| 6b20bc0828 | |||
| db3a06cc67 | |||
| 1a4cefba40 | |||
| 2387fecfb6 | |||
| 1ddb840f4a | |||
| c001a4f2ca | |||
| 08747baf51 | |||
| 41c28f095f |
@@ -1,7 +1,5 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>0.0.0.1</Version>
|
<AssemblyVersion>0.0.0.7</AssemblyVersion>
|
||||||
<AssemblyVersion>0.0.0.1</AssemblyVersion>
|
</PropertyGroup>
|
||||||
<FileVersion>0.0.0.1</FileVersion>
|
|
||||||
</PropertyGroup>
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -31,4 +31,9 @@ public class PluginConfiguration : BasePluginConfiguration
|
|||||||
/// Gets or sets the cut off days before deleting unwatched files.
|
/// Gets or sets the cut off days before deleting unwatched files.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int StaleMediaCutoff { get; set; } = 90;
|
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%;"/>
|
<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 class="fieldDescription">How many days to wait before marking files as stale</div>
|
||||||
</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">
|
<!-- <div class="selectContainer">
|
||||||
<label class="selectLabel" for="Options">Several Options</label>
|
<label class="selectLabel" for="Options">Several Options</label>
|
||||||
<select is="emby-select" id="Options" name="Options" class="emby-select-withcolor emby-select">
|
<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('#RadarrAPIKey').value = config.RadarrAPIKey;
|
||||||
document.querySelector('#SonarrAPIKey').value = config.SonarrAPIKey;
|
document.querySelector('#SonarrAPIKey').value = config.SonarrAPIKey;
|
||||||
document.querySelector('#StaleMediaCutoff').value = config.StaleMediaCutoff;
|
document.querySelector('#StaleMediaCutoff').value = config.StaleMediaCutoff;
|
||||||
|
document.querySelector('#DebugMode').checked = config.DebugMode;
|
||||||
Dashboard.hideLoadingMsg();
|
Dashboard.hideLoadingMsg();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -86,6 +93,7 @@
|
|||||||
config.RadarrAPIKey = document.querySelector('#RadarrAPIKey').value;
|
config.RadarrAPIKey = document.querySelector('#RadarrAPIKey').value;
|
||||||
config.SonarrAPIKey = document.querySelector('#SonarrAPIKey').value;
|
config.SonarrAPIKey = document.querySelector('#SonarrAPIKey').value;
|
||||||
config.StaleMediaCutoff = document.querySelector('#StaleMediaCutoff').value;
|
config.StaleMediaCutoff = document.querySelector('#StaleMediaCutoff').value;
|
||||||
|
config.DebugMode = document.querySelector('#DebugMode').checked;
|
||||||
ApiClient.updatePluginConfiguration(MediaCleanerConfig.pluginUniqueId, config).then(function (result) {
|
ApiClient.updatePluginConfiguration(MediaCleanerConfig.pluginUniqueId, config).then(function (result) {
|
||||||
Dashboard.processPluginConfigurationUpdateResult(result);
|
Dashboard.processPluginConfigurationUpdateResult(result);
|
||||||
});
|
});
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
<RootNamespace>Jellyfin.Plugin.MediaCleaner</RootNamespace>
|
<RootNamespace>Jellyfin.Plugin.MediaCleaner</RootNamespace>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
|
||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
|
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Jellyfin.Controller" Version="10.11.3" >
|
<PackageReference Include="Jellyfin.Controller" Version="10.11.3">
|
||||||
<ExcludeAssets>runtime</ExcludeAssets>
|
<ExcludeAssets>runtime</ExcludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Jellyfin.Model" Version="10.11.3">
|
<PackageReference Include="Jellyfin.Model" Version="10.11.3">
|
||||||
@@ -20,14 +20,17 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
|
<None Remove="Configuration\settings.html" />
|
||||||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="All" />
|
<EmbeddedResource Include="Configuration\settings.html" />
|
||||||
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
|
<None Remove="Pages\home.html" />
|
||||||
|
<EmbeddedResource Include="Pages\home.html" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<PropertyGroup>
|
||||||
<None Remove="Configuration\configPage.html" />
|
<Timestamp>$([System.DateTime]::UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"))</Timestamp>
|
||||||
<EmbeddedResource Include="Configuration\configPage.html" />
|
</PropertyGroup>
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
|
<Target Name="GeneratePluginJson" BeforeTargets="Publish">
|
||||||
|
<WriteLinesToFile File="$(PublishDir)\meta.json" Lines="{
 "guid": "fef007a8-3e8f-4aa8-a22e-486a387f4192",
 "name": "Media Cleaner",
 "category": "Library",
 "overview": "A cleaner for your stale media.",
 "description": "Clean out the stale media from your library using scheduled tasks",
 "timestamp": "$(Timestamp)",
 "targetAbi": "10.11.0",
 "owner": "T-Gander",
 "version": "$(AssemblyVersion)"
 }" Overwrite="true" Encoding="utf-8" />
|
||||||
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
30
Jellyfin.Plugin.MediaCleaner/Models/SeriesInfo.cs
Normal file
30
Jellyfin.Plugin.MediaCleaner/Models/SeriesInfo.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains series information.
|
||||||
|
/// </summary>
|
||||||
|
public class SeriesInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets series identifier.
|
||||||
|
/// </summary>
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets series name.
|
||||||
|
/// </summary>
|
||||||
|
public string SeriesName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets seasons.
|
||||||
|
/// </summary>
|
||||||
|
#pragma warning disable CA2227 // Collection properties should be read only
|
||||||
|
#pragma warning disable CA1002 // Do not expose generic lists
|
||||||
|
public List<string> Seasons { get; set; } = [];
|
||||||
|
#pragma warning restore CA1002 // Do not expose generic lists
|
||||||
|
#pragma warning restore CA2227 // Collection properties should be read only
|
||||||
|
}
|
||||||
11
Jellyfin.Plugin.MediaCleaner/Pages/home.html
Normal file
11
Jellyfin.Plugin.MediaCleaner/Pages/home.html
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<div data-role="page" class="page type-interior pluginConfigurationPage withTabs">
|
||||||
|
<div data-role="content">
|
||||||
|
<div class="content-primary">
|
||||||
|
<div>
|
||||||
|
<a href="#configurationpage?name=Home">Home</a>
|
||||||
|
<a href="#configurationpage?name=Settings">Settings</a>
|
||||||
|
</div>
|
||||||
|
<h2>Media Cleaner</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -44,9 +44,15 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
|||||||
[
|
[
|
||||||
new PluginPageInfo
|
new PluginPageInfo
|
||||||
{
|
{
|
||||||
Name = Name,
|
Name = "Settings",
|
||||||
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Configuration.configPage.html", GetType().Namespace)
|
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Configuration.settings.html", GetType().Namespace),
|
||||||
}
|
},
|
||||||
|
new PluginPageInfo
|
||||||
|
{
|
||||||
|
Name = "Home",
|
||||||
|
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Pages.home.html", GetType().Namespace),
|
||||||
|
EnableInMainMenu = true,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
#pragma warning disable RS0030 // Do not use banned APIs
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Database.Implementations;
|
||||||
|
using MediaBrowser.Model.Globalization;
|
||||||
|
using MediaBrowser.Model.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.MediaCleaner.ScheduledTasks;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Task to clean up any detached userdata from the database.
|
||||||
|
/// </summary>
|
||||||
|
public class CleanupUserDataTask : IScheduledTask
|
||||||
|
{
|
||||||
|
private readonly ILocalizationManager _localization;
|
||||||
|
private readonly IDbContextFactory<JellyfinDbContext> _dbProvider;
|
||||||
|
private readonly ILogger<CleanupUserDataTask> _logger;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="CleanupUserDataTask"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="localization">The localisation Provider.</param>
|
||||||
|
/// <param name="dbProvider">The DB context factory.</param>
|
||||||
|
/// <param name="logger">A logger.</param>
|
||||||
|
public CleanupUserDataTask(ILocalizationManager localization, IDbContextFactory<JellyfinDbContext> dbProvider, ILogger<CleanupUserDataTask> logger)
|
||||||
|
{
|
||||||
|
_localization = localization;
|
||||||
|
_dbProvider = dbProvider;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string Name => _localization.GetLocalizedString("CleanupUserDataTask");
|
||||||
|
|
||||||
|
public Guid PlaceholderId => new("00000000-0000-0000-0000-000000000001");
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string Description => _localization.GetLocalizedString("CleanupUserDataTaskDescription");
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string Category => _localization.GetLocalizedString("Media");
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string Key => nameof(CleanupUserDataTask);
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var dbContext = await _dbProvider.CreateDbContextAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
await using (dbContext.ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
var detachedUserData = dbContext.UserData.Where(e => e.ItemId == PlaceholderId);
|
||||||
|
_logger.LogInformation("Deleting {DetachedUserDataCount} detached UserData entries.", detachedUserData.Count());
|
||||||
|
|
||||||
|
await detachedUserData.ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection.Metadata.Ecma335;
|
using System.Reflection.Metadata.Ecma335;
|
||||||
@@ -10,6 +12,7 @@ using Jellyfin.Data.Enums;
|
|||||||
using Jellyfin.Database.Implementations.Entities;
|
using Jellyfin.Database.Implementations.Entities;
|
||||||
using Jellyfin.Database.Implementations.Entities.Libraries;
|
using Jellyfin.Database.Implementations.Entities.Libraries;
|
||||||
using Jellyfin.Plugin.MediaCleaner.Configuration;
|
using Jellyfin.Plugin.MediaCleaner.Configuration;
|
||||||
|
using Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Model.Tasks;
|
using MediaBrowser.Model.Tasks;
|
||||||
@@ -59,10 +62,13 @@ public sealed class StaleMediaTask : IScheduledTask
|
|||||||
};
|
};
|
||||||
List<BaseItem> allItems = [.. _libraryManager.GetItemsResult(query).Items];
|
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> series = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Series)];
|
||||||
List<BaseItem> movies = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Movie && item.UserData.Count > 0)];
|
List<BaseItem> movies = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Movie)];
|
||||||
|
|
||||||
List<BaseItem> staleEpisodes = [.. series.SelectMany(GetStaleEpisodes)];
|
List<BaseItem> staleEpisodes = [.. series.SelectMany(GetStaleEpisodes)];
|
||||||
List<BaseItem> staleMovies = [.. GetStaleMovies(movies)];
|
List<BaseItem> staleMovies = [.. GetStaleMovies(movies)];
|
||||||
@@ -77,8 +83,15 @@ public sealed class StaleMediaTask : IScheduledTask
|
|||||||
if (staleEpisodes.Count > 0)
|
if (staleEpisodes.Count > 0)
|
||||||
{
|
{
|
||||||
// Firstly figure out the seasons, and then the Series to find the name.
|
// Firstly figure out the seasons, and then the Series to find the name.
|
||||||
List<string> seriesNames = FindDistinctSeriesNamesFromEpisodes(staleEpisodes);
|
List<SeriesInfo> seriesInfoList = FindSeriesInfoFromEpisodes(staleEpisodes);
|
||||||
_logger.LogInformation("Series: {Names}", string.Join(", ", seriesNames));
|
|
||||||
|
foreach (var seriesInfo in seriesInfoList)
|
||||||
|
{
|
||||||
|
if (Configuration.DebugMode)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Series Info: ID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.Id, seriesInfo.SeriesName, string.Join(", ", seriesInfo.Seasons)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
@@ -87,11 +100,39 @@ public sealed class StaleMediaTask : IScheduledTask
|
|||||||
private List<BaseItem> GetStaleMovies(List<BaseItem> movies)
|
private List<BaseItem> GetStaleMovies(List<BaseItem> movies)
|
||||||
{
|
{
|
||||||
List<BaseItem> staleMovies = [];
|
List<BaseItem> staleMovies = [];
|
||||||
|
|
||||||
foreach (var movie in movies)
|
foreach (var movie in movies)
|
||||||
{
|
{
|
||||||
var mostRecentUserData = movie.UserData.OrderByDescending(data => data.LastPlayedDate).First();
|
bool movieIsStale = movie.DateCreated < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff);
|
||||||
if (mostRecentUserData.LastPlayedDate < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff))
|
bool movieHasUserData = movie.UserData.Where(data => data.LastPlayedDate != null).ToList().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).Where(data => data.LastPlayedDate != null).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);
|
staleMovies.Add(movie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,7 +140,7 @@ public sealed class StaleMediaTask : IScheduledTask
|
|||||||
return staleMovies;
|
return staleMovies;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<string> FindDistinctSeriesNamesFromEpisodes(List<BaseItem> episodes)
|
private List<SeriesInfo> FindSeriesInfoFromEpisodes(List<BaseItem> episodes)
|
||||||
{
|
{
|
||||||
Guid[] seasonIds = [.. episodes.Select(episode => episode.ParentId).Distinct()];
|
Guid[] seasonIds = [.. episodes.Select(episode => episode.ParentId).Distinct()];
|
||||||
|
|
||||||
@@ -113,11 +154,24 @@ public sealed class StaleMediaTask : IScheduledTask
|
|||||||
var series = _libraryManager.GetItemList(new InternalItemsQuery
|
var series = _libraryManager.GetItemList(new InternalItemsQuery
|
||||||
{
|
{
|
||||||
ItemIds = seriesIds
|
ItemIds = seriesIds
|
||||||
});
|
}).ToList();
|
||||||
|
|
||||||
|
// Series Id, Series Name and Stale Seasons
|
||||||
List<string> seriesNames = [.. series.Select(series => series.Name).Distinct()];
|
List<string> seriesNames = [.. series.Select(series => series.Name).Distinct()];
|
||||||
|
|
||||||
return seriesNames;
|
List<SeriesInfo> seriesInfoList = [];
|
||||||
|
|
||||||
|
series.ForEach(series =>
|
||||||
|
{
|
||||||
|
seriesInfoList.Add(new SeriesInfo
|
||||||
|
{
|
||||||
|
Id = series.Id,
|
||||||
|
SeriesName = series.Name,
|
||||||
|
Seasons = [.. seasons.Where(season => season.ParentId == series.Id).Select(season => season.Name)]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return seriesInfoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BaseItem> GetStaleEpisodes(BaseItem item)
|
private List<BaseItem> GetStaleEpisodes(BaseItem item)
|
||||||
@@ -139,22 +193,59 @@ public sealed class StaleMediaTask : IScheduledTask
|
|||||||
ParentId = season.Id,
|
ParentId = season.Id,
|
||||||
Recursive = false
|
Recursive = false
|
||||||
});
|
});
|
||||||
|
|
||||||
bool seasonHasUserData = episodes.Any(episode => episode.UserData.Count > 0);
|
bool seasonHasUserData = episodes.Any(episode => episode.UserData.Count > 0);
|
||||||
|
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 && Configuration.DebugMode)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("All episodes are outside media cutoff.");
|
||||||
|
_logger.LogInformation("-------------------------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
if (seasonHasUserData)
|
if (seasonHasUserData)
|
||||||
{
|
{
|
||||||
var episodesWithUserData = episodes.Where(episode => episode.UserData.Count > 0).ToList();
|
var episodesWithUserData = episodes.Where(episode => episode.UserData.Where(data => data.LastPlayedDate != null).ToList().Count > 0).ToList();
|
||||||
|
|
||||||
|
if(Configuration.DebugMode){
|
||||||
|
_logger.LogInformation("Episodes with user data: {EpisodesWithUserData}", episodesWithUserData);
|
||||||
|
_logger.LogInformation("-------------------------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var episode in episodesWithUserData)
|
foreach (var episode in episodesWithUserData)
|
||||||
{
|
{
|
||||||
var mostRecentUserData = episode.UserData.OrderByDescending(data => data.LastPlayedDate).First();
|
var mostRecentUserData = episode.UserData.OrderByDescending(data => data.LastPlayedDate).Where(data => data.LastPlayedDate != null).First();
|
||||||
|
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))
|
if (mostRecentUserData.LastPlayedDate < DateTime.Now.AddDays(-Configuration.StaleMediaCutoff))
|
||||||
{
|
{
|
||||||
|
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);
|
staleEpisodes.AddRange(episodes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check for episodes that have gone unwatched for stale media cutoff
|
||||||
|
else if (seasonIsStale)
|
||||||
|
{
|
||||||
|
if(Configuration.DebugMode){
|
||||||
|
_logger.LogInformation("No user data, adding all episodes as it is outside of cutoff.");
|
||||||
|
_logger.LogInformation("-------------------------------------------------");
|
||||||
|
}
|
||||||
|
staleEpisodes.AddRange(episodes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return staleEpisodes;
|
return staleEpisodes;
|
||||||
|
|||||||
Reference in New Issue
Block a user