| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using System.Threading; |
| | | 3 | | using System.Threading.Tasks; |
| | | 4 | | using Jellyfin.Data.Enums; |
| | | 5 | | using Jellyfin.Database.Implementations.Enums; |
| | | 6 | | using MediaBrowser.Controller.Configuration; |
| | | 7 | | using MediaBrowser.Controller.Dto; |
| | | 8 | | using MediaBrowser.Controller.Entities; |
| | | 9 | | using MediaBrowser.Controller.Library; |
| | | 10 | | using MediaBrowser.Controller.LiveTv; |
| | | 11 | | using MediaBrowser.Model.Configuration; |
| | | 12 | | |
| | | 13 | | namespace Emby.Server.Implementations.Library.SimilarItems; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Provides similar items for Live TV programs. |
| | | 17 | | /// </summary> |
| | | 18 | | public class LiveTvProgramSimilarItemsProvider : ILocalSimilarItemsProvider<LiveTvProgram> |
| | | 19 | | { |
| | | 20 | | private readonly ILibraryManager _libraryManager; |
| | | 21 | | private readonly IServerConfigurationManager _serverConfigurationManager; |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Initializes a new instance of the <see cref="LiveTvProgramSimilarItemsProvider"/> class. |
| | | 25 | | /// </summary> |
| | | 26 | | /// <param name="libraryManager">The library manager.</param> |
| | | 27 | | /// <param name="serverConfigurationManager">The server configuration manager.</param> |
| | | 28 | | public LiveTvProgramSimilarItemsProvider( |
| | | 29 | | ILibraryManager libraryManager, |
| | | 30 | | IServerConfigurationManager serverConfigurationManager) |
| | | 31 | | { |
| | 21 | 32 | | _libraryManager = libraryManager; |
| | 21 | 33 | | _serverConfigurationManager = serverConfigurationManager; |
| | 21 | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <inheritdoc/> |
| | 0 | 37 | | public string Name => "Local Genre/Tag"; |
| | | 38 | | |
| | | 39 | | /// <inheritdoc/> |
| | 0 | 40 | | public MetadataPluginType Type => MetadataPluginType.LocalSimilarityProvider; |
| | | 41 | | |
| | | 42 | | /// <inheritdoc/> |
| | | 43 | | public Task<IReadOnlyList<BaseItem>> GetSimilarItemsAsync(LiveTvProgram item, SimilarItemsQuery query, CancellationT |
| | | 44 | | { |
| | | 45 | | BaseItemKind[] includeItemTypes; |
| | | 46 | | bool enableGroupByMetadataKey; |
| | | 47 | | bool enableTotalRecordCount; |
| | | 48 | | |
| | 0 | 49 | | if (item.IsMovie) |
| | | 50 | | { |
| | | 51 | | // Movie-like program |
| | 0 | 52 | | var itemTypes = new List<BaseItemKind> { BaseItemKind.Movie }; |
| | | 53 | | |
| | 0 | 54 | | if (_serverConfigurationManager.Configuration.EnableExternalContentInSuggestions) |
| | | 55 | | { |
| | 0 | 56 | | itemTypes.Add(BaseItemKind.Trailer); |
| | 0 | 57 | | itemTypes.Add(BaseItemKind.LiveTvProgram); |
| | | 58 | | } |
| | | 59 | | |
| | 0 | 60 | | includeItemTypes = [.. itemTypes]; |
| | 0 | 61 | | enableGroupByMetadataKey = true; |
| | 0 | 62 | | enableTotalRecordCount = false; |
| | | 63 | | } |
| | 0 | 64 | | else if (item.IsSeries) |
| | | 65 | | { |
| | | 66 | | // Series-like program |
| | 0 | 67 | | includeItemTypes = [BaseItemKind.Series]; |
| | 0 | 68 | | enableGroupByMetadataKey = false; |
| | 0 | 69 | | enableTotalRecordCount = true; |
| | | 70 | | } |
| | | 71 | | else |
| | | 72 | | { |
| | | 73 | | // Default - match same type |
| | 0 | 74 | | includeItemTypes = [item.GetBaseItemKind()]; |
| | 0 | 75 | | enableGroupByMetadataKey = false; |
| | 0 | 76 | | enableTotalRecordCount = true; |
| | | 77 | | } |
| | | 78 | | |
| | 0 | 79 | | var internalQuery = new InternalItemsQuery(query.User) |
| | 0 | 80 | | { |
| | 0 | 81 | | Genres = item.Genres, |
| | 0 | 82 | | Tags = item.Tags, |
| | 0 | 83 | | Limit = query.Limit, |
| | 0 | 84 | | DtoOptions = query.DtoOptions ?? new DtoOptions(), |
| | 0 | 85 | | ExcludeItemIds = [.. query.ExcludeItemIds], |
| | 0 | 86 | | IncludeItemTypes = includeItemTypes, |
| | 0 | 87 | | EnableGroupByMetadataKey = enableGroupByMetadataKey, |
| | 0 | 88 | | EnableTotalRecordCount = enableTotalRecordCount, |
| | 0 | 89 | | OrderBy = [(ItemSortBy.Random, SortOrder.Ascending)] |
| | 0 | 90 | | }; |
| | | 91 | | |
| | 0 | 92 | | return Task.FromResult(_libraryManager.GetItemList(internalQuery)); |
| | | 93 | | } |
| | | 94 | | } |