Handle in-season specials as part of the season (#314)

Co-authored-by: rlauu <46294892+rlauu@users.noreply.github.com>
Co-authored-by: Kilian von Pflugk <github@jumoog.io>
This commit is contained in:
rlauuzo 2024-09-29 21:46:46 +02:00 committed by GitHub
parent d2dc8daaed
commit f4fd66e26e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -50,20 +50,15 @@ public class QueueManager(ILogger<QueueManager> logger, ILibraryManager libraryM
_logger.LogInformation("Running enqueue of items in library {Name}", folder.Name);
try
// Some virtual folders don't have a proper item id.
if (!Guid.TryParse(folder.ItemId, out var folderId))
{
foreach (var location in folder.Locations)
{
var item = _libraryManager.FindByPath(location, true);
if (item is null)
{
_logger.LogWarning("Unable to find linked item at path {0}", location);
continue;
}
QueueLibraryContents(item.Id);
}
try
{
QueueLibraryContents(folderId);
}
catch (Exception ex)
{
@ -126,7 +121,7 @@ public class QueueManager(ILogger<QueueManager> logger, ILibraryManager libraryM
{
// Order by series name, season, and then episode number so that status updates are logged in order
ParentId = id,
OrderBy = [(ItemSortBy.SeriesSortName, SortOrder.Ascending), (ItemSortBy.ParentIndexNumber, SortOrder.Ascending), (ItemSortBy.IndexNumber, SortOrder.Ascending),],
OrderBy = [(ItemSortBy.SeriesSortName, SortOrder.Ascending), (ItemSortBy.ParentIndexNumber, SortOrder.Descending), (ItemSortBy.IndexNumber, SortOrder.Ascending),],
IncludeItemTypes = [BaseItemKind.Episode],
Recursive = true,
IsVirtualItem = false
@ -172,10 +167,11 @@ public class QueueManager(ILogger<QueueManager> logger, ILibraryManager libraryM
}
// Allocate a new list for each new season
if (!_queuedEpisodes.TryGetValue(episode.SeasonId, out var seasonEpisodes))
var seasonId = GetSeasonId(episode);
if (!_queuedEpisodes.TryGetValue(seasonId, out var seasonEpisodes))
{
seasonEpisodes = [];
_queuedEpisodes[episode.SeasonId] = seasonEpisodes;
_queuedEpisodes[seasonId] = seasonEpisodes;
}
if (seasonEpisodes.Any(e => e.EpisodeId == episode.Id))
@ -214,6 +210,24 @@ public class QueueManager(ILogger<QueueManager> logger, ILibraryManager libraryM
pluginInstance.TotalQueued++;
}
private Guid GetSeasonId(Episode episode)
{
if (episode.ParentIndexNumber == 0 && episode.AiredSeasonNumber != 0) // In-season special
{
foreach (var kvp in _queuedEpisodes)
{
var first = kvp.Value.FirstOrDefault();
if (first?.SeriesId == episode.SeriesId &&
first.SeasonNumber == episode.AiredSeasonNumber)
{
return kvp.Key;
}
}
}
return episode.SeasonId;
}
/// <summary>
/// Verify that a collection of queued media items still exist in Jellyfin and in storage.
/// This is done to ensure that we don't analyze items that were deleted between the call to GetMediaItems() and popping them from the queue.