Updated logging to now show stale seasons for a show
This commit is contained in:
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
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
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 +11,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;
|
||||||
@@ -77,8 +79,12 @@ 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)
|
||||||
|
{
|
||||||
|
_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;
|
||||||
@@ -99,7 +105,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 +119,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)
|
||||||
|
|||||||
Reference in New Issue
Block a user