From d49494476770b3c0a091841bd3bbd44862fb8137 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 9 Mar 2014 18:14:44 -0400 Subject: calculate item by name counts on the fly --- .../Channels/ChannelItemInfo.cs | 67 ++++++++++++++++++++++ MediaBrowser.Controller/Channels/IChannel.cs | 57 ++++++++++++++++++ .../Channels/IChannelManager.cs | 12 ++++ MediaBrowser.Controller/Dto/IDtoService.cs | 21 +++++++ MediaBrowser.Controller/Entities/Audio/Audio.cs | 18 ++++++ .../Entities/Audio/MusicArtist.cs | 11 ++-- .../Entities/Audio/MusicGenre.cs | 18 +++--- MediaBrowser.Controller/Entities/GameGenre.cs | 17 +++--- MediaBrowser.Controller/Entities/Genre.cs | 18 +++--- MediaBrowser.Controller/Entities/IItemByName.cs | 38 +++--------- MediaBrowser.Controller/Entities/Person.cs | 17 +++--- MediaBrowser.Controller/Entities/Studio.cs | 18 +++--- MediaBrowser.Controller/Entities/Year.cs | 29 ++++++---- MediaBrowser.Controller/Library/ILibraryManager.cs | 13 ----- MediaBrowser.Controller/LiveTv/ILiveTvManager.cs | 7 --- MediaBrowser.Controller/LiveTv/LiveTvChannel.cs | 15 ++--- .../MediaBrowser.Controller.csproj | 3 + 17 files changed, 248 insertions(+), 131 deletions(-) create mode 100644 MediaBrowser.Controller/Channels/ChannelItemInfo.cs create mode 100644 MediaBrowser.Controller/Channels/IChannel.cs create mode 100644 MediaBrowser.Controller/Channels/IChannelManager.cs (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Channels/ChannelItemInfo.cs b/MediaBrowser.Controller/Channels/ChannelItemInfo.cs new file mode 100644 index 0000000000..496fbfbf45 --- /dev/null +++ b/MediaBrowser.Controller/Channels/ChannelItemInfo.cs @@ -0,0 +1,67 @@ +using MediaBrowser.Controller.Entities; +using System.Collections.Generic; + +namespace MediaBrowser.Controller.Channels +{ + public class ChannelItemInfo + { + public string Name { get; set; } + + public string Id { get; set; } + + public ChannelItemType Type { get; set; } + + public string OfficialRating { get; set; } + + public string Overview { get; set; } + + public List Genres { get; set; } + + public List People { get; set; } + + public float? CommunityRating { get; set; } + + public long? RunTimeTicks { get; set; } + + public bool IsInfinite { get; set; } + + public string ImageUrl { get; set; } + + public ChannelMediaType MediaType { get; set; } + + public ChannelMediaContentType ContentType { get; set; } + + public ChannelItemInfo() + { + Genres = new List(); + People = new List(); + } + } + + public enum ChannelItemType + { + Media = 0, + + Category = 1 + } + + public enum ChannelMediaType + { + Audio = 0, + + Video = 1 + } + + public enum ChannelMediaContentType + { + Clip = 0, + + Podcast = 1, + + Trailer = 2, + + Movie = 3, + + Episode = 4 + } +} diff --git a/MediaBrowser.Controller/Channels/IChannel.cs b/MediaBrowser.Controller/Channels/IChannel.cs new file mode 100644 index 0000000000..edb2347c05 --- /dev/null +++ b/MediaBrowser.Controller/Channels/IChannel.cs @@ -0,0 +1,57 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Controller.Channels +{ + public interface IChannel + { + /// + /// Gets the name. + /// + /// The name. + string Name { get; } + + /// + /// Gets the home page URL. + /// + /// The home page URL. + string HomePageUrl { get; } + + /// + /// Gets the capabilities. + /// + /// ChannelCapabilities. + ChannelCapabilities GetCapabilities(); + + /// + /// Searches the specified search term. + /// + /// The search term. + /// The cancellation token. + /// Task{IEnumerable{ChannelItemInfo}}. + Task> Search(string searchTerm, CancellationToken cancellationToken); + + /// + /// Gets the channel items. + /// + /// The cancellation token. + /// Task{IEnumerable{ChannelItem}}. + Task> GetChannelItems(CancellationToken cancellationToken); + + /// + /// Gets the channel items. + /// + /// The category identifier. + /// The cancellation token. + /// Task{IEnumerable{ChannelItem}}. + Task> GetChannelItems(string categoryId, CancellationToken cancellationToken); + } + + public class ChannelCapabilities + { + public bool CanSearch { get; set; } + + public bool CanBeIndexed { get; set; } + } +} diff --git a/MediaBrowser.Controller/Channels/IChannelManager.cs b/MediaBrowser.Controller/Channels/IChannelManager.cs new file mode 100644 index 0000000000..561ab555bd --- /dev/null +++ b/MediaBrowser.Controller/Channels/IChannelManager.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MediaBrowser.Controller.Channels +{ + public interface IChannelManager + { + } +} diff --git a/MediaBrowser.Controller/Dto/IDtoService.cs b/MediaBrowser.Controller/Dto/IDtoService.cs index fd5ccac5b2..606b51628b 100644 --- a/MediaBrowser.Controller/Dto/IDtoService.cs +++ b/MediaBrowser.Controller/Dto/IDtoService.cs @@ -73,5 +73,26 @@ namespace MediaBrowser.Controller.Dto /// The owner. /// Task{BaseItemDto}. BaseItemDto GetBaseItemDto(BaseItem item, List fields, User user = null, BaseItem owner = null); + + /// + /// Gets the item by name dto. + /// + /// The item. + /// The fields. + /// The user. + /// BaseItemDto. + BaseItemDto GetItemByNameDto(T item, List fields, User user = null) + where T : BaseItem, IItemByName; + + /// + /// Gets the item by name dto. + /// + /// The item. + /// The fields. + /// The tagged items. + /// The user. + /// BaseItemDto. + BaseItemDto GetItemByNameDto(T item, List fields, List taggedItems, User user = null) + where T : BaseItem, IItemByName; } } diff --git a/MediaBrowser.Controller/Entities/Audio/Audio.cs b/MediaBrowser.Controller/Entities/Audio/Audio.cs index 73e276f3ba..8eb6236d1a 100644 --- a/MediaBrowser.Controller/Entities/Audio/Audio.cs +++ b/MediaBrowser.Controller/Entities/Audio/Audio.cs @@ -66,6 +66,24 @@ namespace MediaBrowser.Controller.Entities.Audio /// The artist. public List Artists { get; set; } + [IgnoreDataMember] + public List AllArtists + { + get + { + var list = new List(); + + if (!string.IsNullOrEmpty(AlbumArtist)) + { + list.Add(AlbumArtist); + } + list.AddRange(Artists); + + return list; + + } + } + /// /// Gets or sets the album. /// diff --git a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs index 11cf441f7b..0a5d8eec03 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs @@ -1,12 +1,10 @@ using MediaBrowser.Common.Progress; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Configuration; -using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.Serialization; using System.Threading; using System.Threading.Tasks; @@ -17,9 +15,6 @@ namespace MediaBrowser.Controller.Entities.Audio /// public class MusicArtist : Folder, IMetadataContainer, IItemByName, IHasMusicGenres, IHasDualAccess, IHasTags, IHasProductionLocations, IHasLookupInfo { - [IgnoreDataMember] - public List UserItemCountList { get; set; } - public bool IsAccessedByName { get; set; } /// @@ -65,7 +60,6 @@ namespace MediaBrowser.Controller.Entities.Audio public MusicArtist() { - UserItemCountList = new List(); Tags = new List(); ProductionLocations = new List(); } @@ -230,5 +224,10 @@ namespace MediaBrowser.Controller.Entities.Audio return info; } + + public IEnumerable GetTaggedItems(IEnumerable inputItems) + { + return inputItems.OfType().Where(i => i.HasArtist(Name)).Cast(); + } } } diff --git a/MediaBrowser.Controller/Entities/Audio/MusicGenre.cs b/MediaBrowser.Controller/Entities/Audio/MusicGenre.cs index 5e1d4c3c9c..bce9da4d15 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicGenre.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicGenre.cs @@ -1,7 +1,6 @@ -using System.Runtime.Serialization; -using MediaBrowser.Model.Dto; -using System; +using System; using System.Collections.Generic; +using System.Linq; namespace MediaBrowser.Controller.Entities.Audio { @@ -10,11 +9,6 @@ namespace MediaBrowser.Controller.Entities.Audio /// public class MusicGenre : BaseItem, IItemByName { - public MusicGenre() - { - UserItemCountList = new List(); - } - /// /// Gets the user data key. /// @@ -24,9 +18,6 @@ namespace MediaBrowser.Controller.Entities.Audio return "MusicGenre-" + Name; } - [IgnoreDataMember] - public List UserItemCountList { get; set; } - /// /// Returns the folder containing the item. /// If the item is a folder, it returns the folder itself @@ -51,5 +42,10 @@ namespace MediaBrowser.Controller.Entities.Audio return false; } } + + public IEnumerable GetTaggedItems(IEnumerable inputItems) + { + return inputItems.Where(i => (i is IHasMusicGenres) && i.Genres.Contains(Name, StringComparer.OrdinalIgnoreCase)); + } } } diff --git a/MediaBrowser.Controller/Entities/GameGenre.cs b/MediaBrowser.Controller/Entities/GameGenre.cs index 3a3c575cd1..8254689540 100644 --- a/MediaBrowser.Controller/Entities/GameGenre.cs +++ b/MediaBrowser.Controller/Entities/GameGenre.cs @@ -1,16 +1,11 @@ -using MediaBrowser.Model.Dto; +using System; using System.Collections.Generic; -using System.Runtime.Serialization; +using System.Linq; namespace MediaBrowser.Controller.Entities { public class GameGenre : BaseItem, IItemByName { - public GameGenre() - { - UserItemCountList = new List(); - } - /// /// Gets the user data key. /// @@ -20,9 +15,6 @@ namespace MediaBrowser.Controller.Entities return "GameGenre-" + Name; } - [IgnoreDataMember] - public List UserItemCountList { get; set; } - /// /// Returns the folder containing the item. /// If the item is a folder, it returns the folder itself @@ -47,5 +39,10 @@ namespace MediaBrowser.Controller.Entities return false; } } + + public IEnumerable GetTaggedItems(IEnumerable inputItems) + { + return inputItems.Where(i => (i is Game) && i.Genres.Contains(Name, StringComparer.OrdinalIgnoreCase)); + } } } diff --git a/MediaBrowser.Controller/Entities/Genre.cs b/MediaBrowser.Controller/Entities/Genre.cs index c15ca0aa2a..05442f2b7f 100644 --- a/MediaBrowser.Controller/Entities/Genre.cs +++ b/MediaBrowser.Controller/Entities/Genre.cs @@ -1,6 +1,7 @@ -using MediaBrowser.Model.Dto; +using MediaBrowser.Controller.Entities.Audio; +using System; using System.Collections.Generic; -using System.Runtime.Serialization; +using System.Linq; namespace MediaBrowser.Controller.Entities { @@ -9,11 +10,6 @@ namespace MediaBrowser.Controller.Entities /// public class Genre : BaseItem, IItemByName { - public Genre() - { - UserItemCountList = new List(); - } - /// /// Gets the user data key. /// @@ -23,9 +19,6 @@ namespace MediaBrowser.Controller.Entities return "Genre-" + Name; } - [IgnoreDataMember] - public List UserItemCountList { get; set; } - /// /// Returns the folder containing the item. /// If the item is a folder, it returns the folder itself @@ -50,5 +43,10 @@ namespace MediaBrowser.Controller.Entities return false; } } + + public IEnumerable GetTaggedItems(IEnumerable inputItems) + { + return inputItems.Where(i => !(i is Game) && !(i is IHasMusicGenres) && i.Genres.Contains(Name, StringComparer.OrdinalIgnoreCase)); + } } } diff --git a/MediaBrowser.Controller/Entities/IItemByName.cs b/MediaBrowser.Controller/Entities/IItemByName.cs index 1e83c7466e..70d5b840fd 100644 --- a/MediaBrowser.Controller/Entities/IItemByName.cs +++ b/MediaBrowser.Controller/Entities/IItemByName.cs @@ -1,7 +1,4 @@ -using MediaBrowser.Model.Dto; -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; namespace MediaBrowser.Controller.Entities { @@ -10,37 +7,16 @@ namespace MediaBrowser.Controller.Entities /// public interface IItemByName { - List UserItemCountList { get; set; } + /// + /// Gets the tagged items. + /// + /// The input items. + /// IEnumerable{BaseItem}. + IEnumerable GetTaggedItems(IEnumerable inputItems); } public interface IHasDualAccess : IItemByName { bool IsAccessedByName { get; } } - - public static class ItemByNameExtensions - { - public static ItemByNameCounts GetItemByNameCounts(this IItemByName item, Guid userId) - { - if (userId == Guid.Empty) - { - throw new ArgumentNullException("userId"); - } - - return item.UserItemCountList.FirstOrDefault(i => i.UserId == userId); - } - - public static void SetItemByNameCounts(this IItemByName item, Guid userId, ItemByNameCounts counts) - { - var current = item.UserItemCountList.FirstOrDefault(i => i.UserId == userId); - - if (current != null) - { - item.UserItemCountList.Remove(current); - } - - counts.UserId = userId; - item.UserItemCountList.Add(counts); - } - } } diff --git a/MediaBrowser.Controller/Entities/Person.cs b/MediaBrowser.Controller/Entities/Person.cs index c1dc811369..1def47391a 100644 --- a/MediaBrowser.Controller/Entities/Person.cs +++ b/MediaBrowser.Controller/Entities/Person.cs @@ -1,7 +1,7 @@ using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Dto; +using System; using System.Collections.Generic; -using System.Runtime.Serialization; +using System.Linq; namespace MediaBrowser.Controller.Entities { @@ -10,19 +10,11 @@ namespace MediaBrowser.Controller.Entities /// public class Person : BaseItem, IItemByName, IHasLookupInfo { - public Person() - { - UserItemCountList = new List(); - } - /// /// Gets or sets the place of birth. /// /// The place of birth. public string PlaceOfBirth { get; set; } - - [IgnoreDataMember] - public List UserItemCountList { get; set; } /// /// Gets the user data key. @@ -62,6 +54,11 @@ namespace MediaBrowser.Controller.Entities return false; } } + + public IEnumerable GetTaggedItems(IEnumerable inputItems) + { + return inputItems.Where(i => i.People.Any(p => string.Equals(p.Name, Name, StringComparison.OrdinalIgnoreCase))); + } } /// diff --git a/MediaBrowser.Controller/Entities/Studio.cs b/MediaBrowser.Controller/Entities/Studio.cs index 5c3946f9ba..8271a3df20 100644 --- a/MediaBrowser.Controller/Entities/Studio.cs +++ b/MediaBrowser.Controller/Entities/Studio.cs @@ -1,7 +1,6 @@ -using System.Runtime.Serialization; -using MediaBrowser.Model.Dto; -using System; +using System; using System.Collections.Generic; +using System.Linq; namespace MediaBrowser.Controller.Entities { @@ -10,11 +9,6 @@ namespace MediaBrowser.Controller.Entities /// public class Studio : BaseItem, IItemByName { - public Studio() - { - UserItemCountList = new List(); - } - /// /// Gets the user data key. /// @@ -24,9 +18,6 @@ namespace MediaBrowser.Controller.Entities return "Studio-" + Name; } - [IgnoreDataMember] - public List UserItemCountList { get; set; } - /// /// Returns the folder containing the item. /// If the item is a folder, it returns the folder itself @@ -51,5 +42,10 @@ namespace MediaBrowser.Controller.Entities return false; } } + + public IEnumerable GetTaggedItems(IEnumerable inputItems) + { + return inputItems.Where(i => i.Studios.Contains(Name, StringComparer.OrdinalIgnoreCase)); + } } } diff --git a/MediaBrowser.Controller/Entities/Year.cs b/MediaBrowser.Controller/Entities/Year.cs index c6ca028aef..8deb930e8b 100644 --- a/MediaBrowser.Controller/Entities/Year.cs +++ b/MediaBrowser.Controller/Entities/Year.cs @@ -1,7 +1,6 @@ -using System.Runtime.Serialization; -using MediaBrowser.Model.Dto; -using System; -using System.Collections.Generic; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; namespace MediaBrowser.Controller.Entities { @@ -10,14 +9,6 @@ namespace MediaBrowser.Controller.Entities /// public class Year : BaseItem, IItemByName { - public Year() - { - UserItemCountList = new List(); - } - - [IgnoreDataMember] - public List UserItemCountList { get; set; } - /// /// Gets the user data key. /// @@ -51,5 +42,19 @@ namespace MediaBrowser.Controller.Entities return false; } } + + public IEnumerable GetTaggedItems(IEnumerable inputItems) + { + int year; + + var usCulture = new CultureInfo("en-US"); + + if (!int.TryParse(Name, NumberStyles.Integer, usCulture, out year)) + { + return inputItems; + } + + return inputItems.Where(i => i.ProductionYear.HasValue && i.ProductionYear.Value == year); + } } } diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 747ae48ad4..9bde9aa299 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -304,19 +304,6 @@ namespace MediaBrowser.Controller.Library /// System.String. string FindCollectionType(BaseItem item); - /// - /// Gets all artists. - /// - /// IEnumerable{System.String}. - IEnumerable GetAllArtists(); - - /// - /// Gets all artists. - /// - /// The items. - /// IEnumerable{System.String}. - IEnumerable GetAllArtists(IEnumerable items); - /// /// Normalizes the root path list. /// diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index ad42c50910..dddd263582 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -138,13 +138,6 @@ namespace MediaBrowser.Controller.LiveTv /// The identifier. /// Channel. LiveTvChannel GetInternalChannel(string id); - - /// - /// Gets the internal program. - /// - /// The identifier. - /// LiveTvProgram. - LiveTvProgram GetInternalProgram(string id); /// /// Gets the recording. diff --git a/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs b/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs index ff5d6a4d2a..3e6832123e 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs @@ -1,20 +1,13 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Configuration; -using MediaBrowser.Model.Dto; using MediaBrowser.Model.LiveTv; using System.Collections.Generic; -using System.Runtime.Serialization; using System.Linq; namespace MediaBrowser.Controller.LiveTv { public class LiveTvChannel : BaseItem, IItemByName { - public LiveTvChannel() - { - UserItemCountList = new List(); - } - /// /// Gets the user data key. /// @@ -24,9 +17,6 @@ namespace MediaBrowser.Controller.LiveTv return GetClientTypeName() + "-" + Name; } - [IgnoreDataMember] - public List UserItemCountList { get; set; } - /// /// Returns the folder containing the item. /// If the item is a folder, it returns the folder itself @@ -119,5 +109,10 @@ namespace MediaBrowser.Controller.LiveTv { return "Channel"; } + + public IEnumerable GetTaggedItems(IEnumerable inputItems) + { + return new List(); + } } } diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 100ac9f4c4..16c54861ee 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -68,6 +68,9 @@ Properties\SharedVersion.cs + + + -- cgit v1.2.3