From 2bcc7733b6ce7ea649020e1b34caa02cdd116419 Mon Sep 17 00:00:00 2001 From: Duncan Tourolle Date: Sun, 14 Dec 2025 00:07:18 +0100 Subject: [PATCH] filter by date and descneding order --- .../Channels/JellypodChannel.cs | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/Jellyfin.Plugin.Jellypod/Channels/JellypodChannel.cs b/Jellyfin.Plugin.Jellypod/Channels/JellypodChannel.cs index 68c9b3e..2e10153 100644 --- a/Jellyfin.Plugin.Jellypod/Channels/JellypodChannel.cs +++ b/Jellyfin.Plugin.Jellypod/Channels/JellypodChannel.cs @@ -137,11 +137,11 @@ public class JellypodChannel : IChannel, IHasCacheKey, IRequiresMediaInfoCallbac /// public async Task GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken) { - _logger.LogDebug("GetChannelItems called for folder {FolderId}", query.FolderId); + _logger.LogDebug("GetChannelItems called for folder {FolderId}, SortBy: {SortBy}, SortDescending: {SortDescending}", query.FolderId, query.SortBy, query.SortDescending); try { - var items = await GetFolderItemsAsync(query.FolderId, cancellationToken).ConfigureAwait(false); + var items = await GetFolderItemsAsync(query.FolderId, query.SortBy, query.SortDescending, cancellationToken).ConfigureAwait(false); _logger.LogDebug("Returning {Count} channel items for folder {FolderId}", items.Count, query.FolderId); return new ChannelItemResult @@ -157,7 +157,7 @@ public class JellypodChannel : IChannel, IHasCacheKey, IRequiresMediaInfoCallbac } } - private async Task> GetFolderItemsAsync(string? folderId, CancellationToken cancellationToken) + private async Task> GetFolderItemsAsync(string? folderId, ChannelItemSortField? sortBy, bool? sortDescending, CancellationToken cancellationToken) { // Root level - show all subscribed podcasts as folders if (string.IsNullOrEmpty(folderId)) @@ -168,7 +168,7 @@ public class JellypodChannel : IChannel, IHasCacheKey, IRequiresMediaInfoCallbac // Podcast folder - show episodes if (Guid.TryParse(folderId, out var podcastId)) { - return await GetPodcastEpisodesAsync(podcastId, cancellationToken).ConfigureAwait(false); + return await GetPodcastEpisodesAsync(podcastId, sortBy, sortDescending, cancellationToken).ConfigureAwait(false); } return new List(); @@ -203,7 +203,7 @@ public class JellypodChannel : IChannel, IHasCacheKey, IRequiresMediaInfoCallbac return items; } - private async Task> GetPodcastEpisodesAsync(Guid podcastId, CancellationToken cancellationToken) + private async Task> GetPodcastEpisodesAsync(Guid podcastId, ChannelItemSortField? sortBy, bool? sortDescending, CancellationToken cancellationToken) { var items = new List(); var podcast = await _storageService.GetPodcastAsync(podcastId).ConfigureAwait(false); @@ -214,10 +214,25 @@ public class JellypodChannel : IChannel, IHasCacheKey, IRequiresMediaInfoCallbac return items; } - // Sort episodes by published date, newest first - var episodes = podcast.Episodes - .OrderByDescending(e => e.PublishedDate) - .ToList(); + // Default to sorting by premiere date descending (newest first) + var sortField = sortBy ?? ChannelItemSortField.PremiereDate; + var descending = sortDescending ?? true; + + _logger.LogDebug("Sorting episodes by {SortField}, descending: {Descending}", sortField, descending); + + // Sort episodes based on query parameters + IEnumerable sortedEpisodes = sortField switch + { + ChannelItemSortField.Name => descending + ? podcast.Episodes.OrderByDescending(e => e.Title) + : podcast.Episodes.OrderBy(e => e.Title), + ChannelItemSortField.DateCreated or ChannelItemSortField.PremiereDate => descending + ? podcast.Episodes.OrderByDescending(e => e.PublishedDate) + : podcast.Episodes.OrderBy(e => e.PublishedDate), + _ => podcast.Episodes.OrderByDescending(e => e.PublishedDate) + }; + + var episodes = sortedEpisodes.ToList(); foreach (var episode in episodes) {