From b1b45199444e369b12844661f09d1cd0830d25f7 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Wed, 13 May 2026 00:58:03 +0200 Subject: Apply review suggestions --- .../Library/ILocalSimilarItemsProvider.cs | 38 +++++++++++++++++++++- .../Library/IRemoteSimilarItemsProvider.cs | 38 +++++++++++++++++++++- 2 files changed, 74 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Controller/Library') diff --git a/MediaBrowser.Controller/Library/ILocalSimilarItemsProvider.cs b/MediaBrowser.Controller/Library/ILocalSimilarItemsProvider.cs index 9bf0121f5f..b8e41ec810 100644 --- a/MediaBrowser.Controller/Library/ILocalSimilarItemsProvider.cs +++ b/MediaBrowser.Controller/Library/ILocalSimilarItemsProvider.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -5,12 +6,38 @@ using MediaBrowser.Controller.Entities; namespace MediaBrowser.Controller.Library; +/// +/// Provides similar items from the local library. +/// Returns fully resolved BaseItems directly - no additional resolution needed. +/// +public interface ILocalSimilarItemsProvider : ISimilarItemsProvider +{ + /// + /// Determines whether the provider can handle items of the specified type. + /// + /// The item type. + /// true if the provider handles this item type; otherwise false. + bool Supports(Type itemType); + + /// + /// Gets similar items from the local library. + /// + /// The source item to find similar items for. + /// The query options (user, limit, exclusions, etc.). + /// Cancellation token. + /// The list of similar items from the library. + Task> GetSimilarItemsAsync( + BaseItem item, + SimilarItemsQuery query, + CancellationToken cancellationToken); +} + /// /// Provides similar items from the local library for a specific item type. /// Returns fully resolved BaseItems directly - no additional resolution needed. /// /// The type of item this provider handles. -public interface ILocalSimilarItemsProvider : ISimilarItemsProvider +public interface ILocalSimilarItemsProvider : ILocalSimilarItemsProvider where TItemType : BaseItem { /// @@ -24,4 +51,13 @@ public interface ILocalSimilarItemsProvider : ISimilarItemsProvider TItemType item, SimilarItemsQuery query, CancellationToken cancellationToken); + + bool ILocalSimilarItemsProvider.Supports(Type itemType) + => typeof(TItemType).IsAssignableFrom(itemType); + + Task> ILocalSimilarItemsProvider.GetSimilarItemsAsync( + BaseItem item, + SimilarItemsQuery query, + CancellationToken cancellationToken) + => GetSimilarItemsAsync((TItemType)item, query, cancellationToken); } diff --git a/MediaBrowser.Controller/Library/IRemoteSimilarItemsProvider.cs b/MediaBrowser.Controller/Library/IRemoteSimilarItemsProvider.cs index a77b6628d9..3803e51769 100644 --- a/MediaBrowser.Controller/Library/IRemoteSimilarItemsProvider.cs +++ b/MediaBrowser.Controller/Library/IRemoteSimilarItemsProvider.cs @@ -1,15 +1,42 @@ +using System; using System.Collections.Generic; using System.Threading; using MediaBrowser.Controller.Entities; namespace MediaBrowser.Controller.Library; +/// +/// Provides similar item references from remote/external sources. +/// Returns lightweight references with ProviderIds that the manager resolves to library items. +/// +public interface IRemoteSimilarItemsProvider : ISimilarItemsProvider +{ + /// + /// Determines whether the provider can handle items of the specified type. + /// + /// The item type. + /// true if the provider handles this item type; otherwise false. + bool Supports(Type itemType); + + /// + /// Gets similar item references from an external source as an async stream. + /// + /// The source item to find similar items for. + /// The query options (user, limit, exclusions). + /// Cancellation token. + /// An async enumerable of similar item references. + IAsyncEnumerable GetSimilarItemsAsync( + BaseItem item, + SimilarItemsQuery query, + CancellationToken cancellationToken); +} + /// /// Provides similar item references from remote/external sources for a specific item type. /// Returns lightweight references with ProviderIds that the manager resolves to library items. /// /// The type of item this provider handles. -public interface IRemoteSimilarItemsProvider : ISimilarItemsProvider +public interface IRemoteSimilarItemsProvider : IRemoteSimilarItemsProvider where TItemType : BaseItem { /// @@ -23,4 +50,13 @@ public interface IRemoteSimilarItemsProvider : ISimilarItemsProvider TItemType item, SimilarItemsQuery query, CancellationToken cancellationToken); + + bool IRemoteSimilarItemsProvider.Supports(Type itemType) + => typeof(TItemType).IsAssignableFrom(itemType); + + IAsyncEnumerable IRemoteSimilarItemsProvider.GetSimilarItemsAsync( + BaseItem item, + SimilarItemsQuery query, + CancellationToken cancellationToken) + => GetSimilarItemsAsync((TItemType)item, query, cancellationToken); } -- cgit v1.2.3