From acd2defbf7161077c430518cb41782f5771f3282 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 22 May 2016 18:37:50 -0400 Subject: handle flat tv folders --- .../Library/Resolvers/TV/EpisodeResolver.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers') diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs index e62049821..14e5e446b 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs @@ -1,6 +1,9 @@ -using MediaBrowser.Controller.Entities.TV; +using System; +using System.IO; +using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using System.Linq; +using MediaBrowser.Model.Entities; namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV { @@ -37,7 +40,8 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV } // If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something - if (season != null || args.HasParent()) + // Also handle flat tv folders + if (season != null || args.HasParent() || string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) { var episode = ResolveVideo(args, false); -- cgit v1.2.3 From f9847be17c5037671b622b61df9aaa113723f318 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 17 Jun 2016 09:06:13 -0400 Subject: update item by name queries --- MediaBrowser.Api/StartupWizardService.cs | 2 +- MediaBrowser.Api/UserLibrary/ArtistsService.cs | 40 ++- .../UserLibrary/BaseItemsByNameService.cs | 134 +++++++- MediaBrowser.Api/UserLibrary/GameGenresService.cs | 25 +- MediaBrowser.Api/UserLibrary/GenresService.cs | 61 +--- MediaBrowser.Api/UserLibrary/MusicGenresService.cs | 17 +- MediaBrowser.Api/UserLibrary/StudiosService.cs | 11 +- MediaBrowser.Controller/Entities/Audio/Audio.cs | 2 - .../Entities/Audio/MusicArtist.cs | 10 +- .../Entities/Audio/MusicGenre.cs | 11 +- MediaBrowser.Controller/Entities/BaseItem.cs | 4 + MediaBrowser.Controller/Entities/Folder.cs | 8 +- MediaBrowser.Controller/Entities/GameGenre.cs | 11 +- MediaBrowser.Controller/Entities/Genre.cs | 11 +- MediaBrowser.Controller/Entities/Person.cs | 11 +- MediaBrowser.Controller/Entities/Studio.cs | 11 +- MediaBrowser.Controller/Entities/Video.cs | 3 - MediaBrowser.Controller/Library/ILibraryManager.cs | 8 + .../Persistence/IItemRepository.cs | 8 + .../MediaBrowser.Model.Portable.csproj | 3 - .../MediaBrowser.Model.net35.csproj | 3 - MediaBrowser.Model/Dto/ItemCounts.cs | 1 + MediaBrowser.Model/Entities/MediaUrl.cs | 1 - MediaBrowser.Model/Entities/VideoSize.cs | 8 - MediaBrowser.Model/MediaBrowser.Model.csproj | 1 - .../Movies/GenericMovieDbInfo.cs | 3 +- .../Dto/DtoService.cs | 2 +- .../Library/LibraryManager.cs | 96 +++++- .../Library/Resolvers/BaseVideoResolver.cs | 2 +- .../MediaBrowser.Server.Implementations.csproj | 4 +- .../Persistence/CleanDatabaseScheduledTask.cs | 24 +- .../Persistence/SqliteItemRepository.cs | 348 +++++++++++++++++++-- .../packages.config | 2 +- 33 files changed, 733 insertions(+), 153 deletions(-) delete mode 100644 MediaBrowser.Model/Entities/VideoSize.cs (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers') diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index f4aee080a..e4949b4d8 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -114,7 +114,7 @@ namespace MediaBrowser.Api config.EnableStandaloneMusicKeys = true; config.EnableCaseSensitiveItemIds = true; config.EnableFolderView = true; - config.SchemaVersion = 92; + config.SchemaVersion = 95; } public void Post(UpdateStartupConfiguration request) diff --git a/MediaBrowser.Api/UserLibrary/ArtistsService.cs b/MediaBrowser.Api/UserLibrary/ArtistsService.cs index cde5eade5..df73ef720 100644 --- a/MediaBrowser.Api/UserLibrary/ArtistsService.cs +++ b/MediaBrowser.Api/UserLibrary/ArtistsService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Dto; +using System; +using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; @@ -8,6 +9,8 @@ using MediaBrowser.Model.Dto; using ServiceStack; using System.Collections.Generic; using System.Linq; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Querying; namespace MediaBrowser.Api.UserLibrary { @@ -100,7 +103,12 @@ namespace MediaBrowser.Api.UserLibrary /// System.Object. public object Get(GetArtists request) { - var result = GetResult(request); + if (string.IsNullOrWhiteSpace(request.IncludeItemTypes)) + { + //request.IncludeItemTypes = "Audio,MusicVideo"; + } + + var result = GetResultSlim(request); return ToOptimizedResult(result); } @@ -112,11 +120,26 @@ namespace MediaBrowser.Api.UserLibrary /// System.Object. public object Get(GetAlbumArtists request) { - var result = GetResult(request); + if (string.IsNullOrWhiteSpace(request.IncludeItemTypes)) + { + //request.IncludeItemTypes = "Audio,MusicVideo"; + } + + var result = GetResultSlim(request); return ToOptimizedResult(result); } + protected override QueryResult> GetItems(GetItemsByName request, InternalItemsQuery query) + { + if (request is GetAlbumArtists) + { + return LibraryManager.GetAlbumArtists(query); + } + + return LibraryManager.GetArtists(query); + } + /// /// Gets all items. /// @@ -125,16 +148,7 @@ namespace MediaBrowser.Api.UserLibrary /// IEnumerable{Tuple{System.StringFunc{System.Int32}}}. protected override IEnumerable GetAllItems(GetItemsByName request, IEnumerable items) { - if (request is GetAlbumArtists) - { - return LibraryManager.GetAlbumArtists(items - .Where(i => !i.IsFolder) - .OfType()); - } - - return LibraryManager.GetArtists(items - .Where(i => !i.IsFolder) - .OfType()); + throw new NotImplementedException(); } } } diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs index 18dec3253..9465d1fdc 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs @@ -8,6 +8,7 @@ using ServiceStack; using System; using System.Collections.Generic; using System.Linq; +using MediaBrowser.Model.Dto; namespace MediaBrowser.Api.UserLibrary { @@ -83,6 +84,137 @@ namespace MediaBrowser.Api.UserLibrary return null; } + protected ItemsResult GetResultSlim(GetItemsByName request) + { + var dtoOptions = GetDtoOptions(request); + + User user = null; + BaseItem parentItem; + + if (!string.IsNullOrWhiteSpace(request.UserId)) + { + user = UserManager.GetUserById(request.UserId); + parentItem = string.IsNullOrEmpty(request.ParentId) ? user.RootFolder : LibraryManager.GetItemById(request.ParentId); + } + else + { + parentItem = string.IsNullOrEmpty(request.ParentId) ? LibraryManager.RootFolder : LibraryManager.GetItemById(request.ParentId); + } + + var excludeItemTypes = request.GetExcludeItemTypes(); + var includeItemTypes = request.GetIncludeItemTypes(); + var mediaTypes = request.GetMediaTypes(); + + var query = new InternalItemsQuery(user) + { + ExcludeItemTypes = excludeItemTypes, + IncludeItemTypes = includeItemTypes, + MediaTypes = mediaTypes, + StartIndex = request.StartIndex, + Limit = request.Limit, + IsFavorite = request.IsFavorite, + NameLessThan = request.NameLessThan, + NameStartsWith = request.NameStartsWith, + NameStartsWithOrGreater = request.NameStartsWithOrGreater, + AlbumArtistStartsWithOrGreater = request.AlbumArtistStartsWithOrGreater, + Tags = request.GetTags(), + OfficialRatings = request.GetOfficialRatings(), + Genres = request.GetGenres(), + GenreIds = request.GetGenreIds(), + Studios = request.GetStudios(), + StudioIds = request.GetStudioIds(), + Person = request.Person, + PersonIds = request.GetPersonIds(), + PersonTypes = request.GetPersonTypes(), + Years = request.GetYears(), + MinCommunityRating = request.MinCommunityRating + }; + + if (!string.IsNullOrWhiteSpace(request.ParentId)) + { + if (parentItem is Folder) + { + query.AncestorIds = new[] { request.ParentId }; + } + else + { + query.ItemIds = new[] { request.ParentId }; + } + } + + foreach (var filter in request.GetFilters()) + { + switch (filter) + { + case ItemFilter.Dislikes: + query.IsLiked = false; + break; + case ItemFilter.IsFavorite: + query.IsFavorite = true; + break; + case ItemFilter.IsFavoriteOrLikes: + query.IsFavoriteOrLiked = true; + break; + case ItemFilter.IsFolder: + query.IsFolder = true; + break; + case ItemFilter.IsNotFolder: + query.IsFolder = false; + break; + case ItemFilter.IsPlayed: + query.IsPlayed = true; + break; + case ItemFilter.IsRecentlyAdded: + break; + case ItemFilter.IsResumable: + query.IsResumable = true; + break; + case ItemFilter.IsUnplayed: + query.IsPlayed = false; + break; + case ItemFilter.Likes: + query.IsLiked = true; + break; + } + } + + var result = GetItems(request, query); + + var dtos = result.Items.Select(i => + { + var dto = DtoService.GetItemByNameDto(i.Item1, dtoOptions, null, user); + + if (!string.IsNullOrWhiteSpace(request.IncludeItemTypes)) + { + SetItemCounts(dto, i.Item2); + } + return dto; + }); + + return new ItemsResult + { + Items = dtos.ToArray(), + TotalRecordCount = result.TotalRecordCount + }; + } + + protected virtual QueryResult> GetItems(GetItemsByName request, InternalItemsQuery query) + { + return new QueryResult>(); + } + + private void SetItemCounts(BaseItemDto dto, ItemCounts counts) + { + dto.ChildCount = counts.ItemCount; + dto.SeriesCount = counts.SeriesCount; + dto.EpisodeCount = counts.EpisodeCount; + dto.MovieCount = counts.MovieCount; + dto.TrailerCount = counts.TrailerCount; + dto.AlbumCount = counts.AlbumCount; + dto.SongCount = counts.SongCount; + dto.GameCount = counts.GameCount; + } + /// /// Gets the specified request. /// @@ -374,7 +506,7 @@ namespace MediaBrowser.Api.UserLibrary /// The include item types. /// The media types. /// IEnumerable{BaseItem}. - protected bool FilterItem(GetItemsByName request, BaseItem f, string[] excludeItemTypes, string[] includeItemTypes, string[] mediaTypes) + private bool FilterItem(GetItemsByName request, BaseItem f, string[] excludeItemTypes, string[] includeItemTypes, string[] mediaTypes) { // Exclude item types if (excludeItemTypes.Length > 0) diff --git a/MediaBrowser.Api/UserLibrary/GameGenresService.cs b/MediaBrowser.Api/UserLibrary/GameGenresService.cs index 58237f80f..ebc9a970d 100644 --- a/MediaBrowser.Api/UserLibrary/GameGenresService.cs +++ b/MediaBrowser.Api/UserLibrary/GameGenresService.cs @@ -9,6 +9,7 @@ using ServiceStack; using System; using System.Collections.Generic; using System.Linq; +using MediaBrowser.Model.Querying; namespace MediaBrowser.Api.UserLibrary { @@ -87,11 +88,16 @@ namespace MediaBrowser.Api.UserLibrary /// System.Object. public object Get(GetGameGenres request) { - var result = GetResult(request); + var result = GetResultSlim(request); return ToOptimizedSerializedResultUsingCache(result); } + protected override QueryResult> GetItems(GetItemsByName request, InternalItemsQuery query) + { + return LibraryManager.GetGameGenres(query); + } + /// /// Gets all items. /// @@ -100,22 +106,7 @@ namespace MediaBrowser.Api.UserLibrary /// IEnumerable{Tuple{System.StringFunc{System.Int32}}}. protected override IEnumerable GetAllItems(GetItemsByName request, IEnumerable items) { - return items - .SelectMany(i => i.Genres) - .DistinctNames() - .Select(name => - { - try - { - return LibraryManager.GetGameGenre(name); - } - catch (Exception ex) - { - Logger.ErrorException("Error getting genre {0}", ex, name); - return null; - } - }) - .Where(i => i != null); + throw new NotImplementedException(); } } } diff --git a/MediaBrowser.Api/UserLibrary/GenresService.cs b/MediaBrowser.Api/UserLibrary/GenresService.cs index d383bd0ad..57c11a1fa 100644 --- a/MediaBrowser.Api/UserLibrary/GenresService.cs +++ b/MediaBrowser.Api/UserLibrary/GenresService.cs @@ -9,6 +9,7 @@ using ServiceStack; using System; using System.Collections.Generic; using System.Linq; +using MediaBrowser.Model.Querying; namespace MediaBrowser.Api.UserLibrary { @@ -92,65 +93,37 @@ namespace MediaBrowser.Api.UserLibrary /// System.Object. public object Get(GetGenres request) { - var result = GetResult(request); + var result = GetResultSlim(request); return ToOptimizedSerializedResultUsingCache(result); } - /// - /// Gets all items. - /// - /// The request. - /// The items. - /// IEnumerable{Tuple{System.StringFunc{System.Int32}}}. - protected override IEnumerable GetAllItems(GetItemsByName request, IEnumerable items) + protected override QueryResult> GetItems(GetItemsByName request, InternalItemsQuery query) { var viewType = GetParentItemViewType(request); if (string.Equals(viewType, CollectionType.Music) || string.Equals(viewType, CollectionType.MusicVideos)) { - return items - .SelectMany(i => i.Genres) - .DistinctNames() - .Select(name => LibraryManager.GetMusicGenre(name)); + return LibraryManager.GetMusicGenres(query); } if (string.Equals(viewType, CollectionType.Games)) { - return items - .SelectMany(i => i.Genres) - .DistinctNames() - .Select(name => - { - try - { - return LibraryManager.GetGameGenre(name); - } - catch (Exception ex) - { - Logger.ErrorException("Error getting genre {0}", ex, name); - return null; - } - }) - .Where(i => i != null); + return LibraryManager.GetGameGenres(query); } - return items - .SelectMany(i => i.Genres) - .DistinctNames() - .Select(name => - { - try - { - return LibraryManager.GetGenre(name); - } - catch (Exception ex) - { - Logger.ErrorException("Error getting genre {0}", ex, name); - return null; - } - }) - .Where(i => i != null); + return LibraryManager.GetGenres(query); + } + + /// + /// Gets all items. + /// + /// The request. + /// The items. + /// IEnumerable{Tuple{System.StringFunc{System.Int32}}}. + protected override IEnumerable GetAllItems(GetItemsByName request, IEnumerable items) + { + throw new NotImplementedException(); } } } diff --git a/MediaBrowser.Api/UserLibrary/MusicGenresService.cs b/MediaBrowser.Api/UserLibrary/MusicGenresService.cs index 12cb62fac..f02136e05 100644 --- a/MediaBrowser.Api/UserLibrary/MusicGenresService.cs +++ b/MediaBrowser.Api/UserLibrary/MusicGenresService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Dto; +using System; +using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; @@ -8,6 +9,8 @@ using MediaBrowser.Model.Dto; using ServiceStack; using System.Collections.Generic; using System.Linq; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Querying; namespace MediaBrowser.Api.UserLibrary { @@ -86,11 +89,16 @@ namespace MediaBrowser.Api.UserLibrary /// System.Object. public object Get(GetMusicGenres request) { - var result = GetResult(request); + var result = GetResultSlim(request); return ToOptimizedSerializedResultUsingCache(result); } + protected override QueryResult> GetItems(GetItemsByName request, InternalItemsQuery query) + { + return LibraryManager.GetMusicGenres(query); + } + /// /// Gets all items. /// @@ -99,10 +107,7 @@ namespace MediaBrowser.Api.UserLibrary /// IEnumerable{Tuple{System.StringFunc{System.Int32}}}. protected override IEnumerable GetAllItems(GetItemsByName request, IEnumerable items) { - return items - .SelectMany(i => i.Genres) - .DistinctNames() - .Select(name => LibraryManager.GetMusicGenre(name)); + throw new NotImplementedException(); } } } diff --git a/MediaBrowser.Api/UserLibrary/StudiosService.cs b/MediaBrowser.Api/UserLibrary/StudiosService.cs index 2cdabf721..9e9c25d78 100644 --- a/MediaBrowser.Api/UserLibrary/StudiosService.cs +++ b/MediaBrowser.Api/UserLibrary/StudiosService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Dto; +using System; +using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Net; @@ -7,6 +8,7 @@ using MediaBrowser.Model.Dto; using ServiceStack; using System.Collections.Generic; using System.Linq; +using MediaBrowser.Model.Querying; namespace MediaBrowser.Api.UserLibrary { @@ -90,11 +92,16 @@ namespace MediaBrowser.Api.UserLibrary /// System.Object. public object Get(GetStudios request) { - var result = GetResult(request); + var result = GetResultSlim(request); return ToOptimizedSerializedResultUsingCache(result); } + protected override QueryResult> GetItems(GetItemsByName request, InternalItemsQuery query) + { + return LibraryManager.GetStudios(query); + } + /// /// Gets all items. /// diff --git a/MediaBrowser.Controller/Entities/Audio/Audio.cs b/MediaBrowser.Controller/Entities/Audio/Audio.cs index 06710b030..b3df34c4d 100644 --- a/MediaBrowser.Controller/Entities/Audio/Audio.cs +++ b/MediaBrowser.Controller/Entities/Audio/Audio.cs @@ -26,8 +26,6 @@ namespace MediaBrowser.Controller.Entities.Audio { public List ChannelMediaSources { get; set; } - public long? Size { get; set; } - public string Container { get; set; } public int? TotalBitrate { get; set; } public ExtraType? ExtraType { get; set; } diff --git a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs index 950701687..6790a1bcf 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Runtime.Serialization; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.Extensions; namespace MediaBrowser.Controller.Entities.Audio { @@ -165,10 +166,17 @@ namespace MediaBrowser.Controller.Entities.Audio list.Add("Artist-Musicbrainz-" + id); } - list.Add("Artist-" + item.Name); + list.Add("Artist-" + (item.Name ?? string.Empty).RemoveDiacritics()); return list; } + public override string PresentationUniqueKey + { + get + { + return "Artist-" + (Name ?? string.Empty).RemoveDiacritics(); + } + } protected override bool GetBlockUnratedValue(UserPolicy config) { return config.BlockUnratedItems.Contains(UnratedItem.Music); diff --git a/MediaBrowser.Controller/Entities/Audio/MusicGenre.cs b/MediaBrowser.Controller/Entities/Audio/MusicGenre.cs index 77cf0cc49..798bc79fb 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicGenre.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicGenre.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; +using MediaBrowser.Common.Extensions; namespace MediaBrowser.Controller.Entities.Audio { @@ -14,10 +15,18 @@ namespace MediaBrowser.Controller.Entities.Audio { var list = base.GetUserDataKeys(); - list.Insert(0, "MusicGenre-" + Name); + list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics()); return list; } + public override string PresentationUniqueKey + { + get + { + return GetUserDataKeys()[0]; + } + } + [IgnoreDataMember] public override bool SupportsAddingToPlaylist { diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 33fd03e15..ed838ab31 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -69,6 +69,10 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public string PreferredMetadataLanguage { get; set; } + public long? Size { get; set; } + public string Container { get; set; } + public string ShortOverview { get; set; } + public List ImageInfos { get; set; } [IgnoreDataMember] diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index e3841099e..91ca1f009 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -216,7 +216,7 @@ namespace MediaBrowser.Controller.Entities { get { - return LoadChildren().Select(LibraryManager.GetItemById).Where(i => i != null); + return LoadChildren(); } } @@ -270,7 +270,7 @@ namespace MediaBrowser.Controller.Entities /// Loads our children. Validation will occur externally. /// We want this sychronous. /// - protected virtual IEnumerable LoadChildren() + protected virtual IEnumerable LoadChildren() { //just load our children from the repo - the library will be validated and maintained in other processes return GetCachedChildren(); @@ -657,9 +657,9 @@ namespace MediaBrowser.Controller.Entities /// Get our children from the repo - stubbed for now /// /// IEnumerable{BaseItem}. - protected IEnumerable GetCachedChildren() + protected IEnumerable GetCachedChildren() { - return ItemRepository.GetItemIdsList(new InternalItemsQuery + return ItemRepository.GetItemList(new InternalItemsQuery { ParentId = Id, GroupByPresentationUniqueKey = false diff --git a/MediaBrowser.Controller/Entities/GameGenre.cs b/MediaBrowser.Controller/Entities/GameGenre.cs index 7c1e88cb1..45e766c0f 100644 --- a/MediaBrowser.Controller/Entities/GameGenre.cs +++ b/MediaBrowser.Controller/Entities/GameGenre.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; +using MediaBrowser.Common.Extensions; namespace MediaBrowser.Controller.Entities { @@ -11,10 +12,18 @@ namespace MediaBrowser.Controller.Entities { var list = base.GetUserDataKeys(); - list.Insert(0, "GameGenre-" + Name); + list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics()); return list; } + public override string PresentationUniqueKey + { + get + { + return GetUserDataKeys()[0]; + } + } + /// /// Returns the folder containing the item. /// If the item is a folder, it returns the folder itself diff --git a/MediaBrowser.Controller/Entities/Genre.cs b/MediaBrowser.Controller/Entities/Genre.cs index c87d4daaf..cc5aebb2a 100644 --- a/MediaBrowser.Controller/Entities/Genre.cs +++ b/MediaBrowser.Controller/Entities/Genre.cs @@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities.Audio; using System; using System.Collections.Generic; using System.Linq; +using MediaBrowser.Common.Extensions; namespace MediaBrowser.Controller.Entities { @@ -15,10 +16,18 @@ namespace MediaBrowser.Controller.Entities { var list = base.GetUserDataKeys(); - list.Insert(0, "Genre-" + Name); + list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics()); return list; } + public override string PresentationUniqueKey + { + get + { + return GetUserDataKeys()[0]; + } + } + /// /// Returns the folder containing the item. /// If the item is a folder, it returns the folder itself diff --git a/MediaBrowser.Controller/Entities/Person.cs b/MediaBrowser.Controller/Entities/Person.cs index 2b099e3d5..8ef0d70bf 100644 --- a/MediaBrowser.Controller/Entities/Person.cs +++ b/MediaBrowser.Controller/Entities/Person.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; +using MediaBrowser.Common.Extensions; using MediaBrowser.Model.Entities; namespace MediaBrowser.Controller.Entities @@ -22,10 +23,18 @@ namespace MediaBrowser.Controller.Entities { var list = base.GetUserDataKeys(); - list.Insert(0, "Person-" + Name); + list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics()); return list; } + public override string PresentationUniqueKey + { + get + { + return GetUserDataKeys()[0]; + } + } + public PersonLookupInfo GetLookupInfo() { return GetItemLookupInfo(); diff --git a/MediaBrowser.Controller/Entities/Studio.cs b/MediaBrowser.Controller/Entities/Studio.cs index e46978af3..762798b55 100644 --- a/MediaBrowser.Controller/Entities/Studio.cs +++ b/MediaBrowser.Controller/Entities/Studio.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; +using MediaBrowser.Common.Extensions; namespace MediaBrowser.Controller.Entities { @@ -14,10 +15,18 @@ namespace MediaBrowser.Controller.Entities { var list = base.GetUserDataKeys(); - list.Insert(0, "Studio-" + Name); + list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics()); return list; } + public override string PresentationUniqueKey + { + get + { + return GetUserDataKeys()[0]; + } + } + /// /// Returns the folder containing the item. /// If the item is a folder, it returns the folder itself diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index 2502033c8..73c893dd6 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -58,10 +58,7 @@ namespace MediaBrowser.Controller.Entities } } - public long? Size { get; set; } - public string Container { get; set; } public int? TotalBitrate { get; set; } - public string ShortOverview { get; set; } public ExtraType? ExtraType { get; set; } /// diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 1d0e06482..4e641b005 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using CommonIO; +using MediaBrowser.Model.Dto; namespace MediaBrowser.Controller.Library { @@ -567,5 +568,12 @@ namespace MediaBrowser.Controller.Library void RemoveVirtualFolder(string name, bool refreshLibrary); void AddMediaPath(string virtualFolderName, string path); void RemoveMediaPath(string virtualFolderName, string path); + + QueryResult> GetGenres(InternalItemsQuery query); + QueryResult> GetMusicGenres(InternalItemsQuery query); + QueryResult> GetGameGenres(InternalItemsQuery query); + QueryResult> GetStudios(InternalItemsQuery query); + QueryResult> GetArtists(InternalItemsQuery query); + QueryResult> GetAlbumArtists(InternalItemsQuery query); } } \ No newline at end of file diff --git a/MediaBrowser.Controller/Persistence/IItemRepository.cs b/MediaBrowser.Controller/Persistence/IItemRepository.cs index 80a6e4042..2ef8b70f0 100644 --- a/MediaBrowser.Controller/Persistence/IItemRepository.cs +++ b/MediaBrowser.Controller/Persistence/IItemRepository.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.Querying; namespace MediaBrowser.Controller.Persistence @@ -161,6 +162,13 @@ namespace MediaBrowser.Controller.Persistence /// The cancellation token. /// Task. Task UpdateInheritedValues(CancellationToken cancellationToken); + + QueryResult> GetGenres(InternalItemsQuery query); + QueryResult> GetMusicGenres(InternalItemsQuery query); + QueryResult> GetGameGenres(InternalItemsQuery query); + QueryResult> GetStudios(InternalItemsQuery query); + QueryResult> GetArtists(InternalItemsQuery query); + QueryResult> GetAlbumArtists(InternalItemsQuery query); } } diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index f759ffeae..f9d28605e 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -599,9 +599,6 @@ Entities\Video3DFormat.cs - - Entities\VideoSize.cs - Entities\VideoType.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index 05bbeb50e..edaa0e027 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -573,9 +573,6 @@ Entities\Video3DFormat.cs - - Entities\VideoSize.cs - Entities\VideoType.cs diff --git a/MediaBrowser.Model/Dto/ItemCounts.cs b/MediaBrowser.Model/Dto/ItemCounts.cs index a3a00c341..07ddfa1ac 100644 --- a/MediaBrowser.Model/Dto/ItemCounts.cs +++ b/MediaBrowser.Model/Dto/ItemCounts.cs @@ -60,5 +60,6 @@ /// /// The book count. public int BookCount { get; set; } + public int ItemCount { get; set; } } } diff --git a/MediaBrowser.Model/Entities/MediaUrl.cs b/MediaBrowser.Model/Entities/MediaUrl.cs index 24e3b1492..2e17bba8a 100644 --- a/MediaBrowser.Model/Entities/MediaUrl.cs +++ b/MediaBrowser.Model/Entities/MediaUrl.cs @@ -5,6 +5,5 @@ namespace MediaBrowser.Model.Entities { public string Url { get; set; } public string Name { get; set; } - public VideoSize? VideoSize { get; set; } } } diff --git a/MediaBrowser.Model/Entities/VideoSize.cs b/MediaBrowser.Model/Entities/VideoSize.cs deleted file mode 100644 index 0100f3b90..000000000 --- a/MediaBrowser.Model/Entities/VideoSize.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace MediaBrowser.Model.Entities -{ - public enum VideoSize - { - StandardDefinition, - HighDefinition - } -} \ No newline at end of file diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index 522b7d38d..7c9f132db 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -227,7 +227,6 @@ - diff --git a/MediaBrowser.Providers/Movies/GenericMovieDbInfo.cs b/MediaBrowser.Providers/Movies/GenericMovieDbInfo.cs index 3b3065893..a6b6de7e5 100644 --- a/MediaBrowser.Providers/Movies/GenericMovieDbInfo.cs +++ b/MediaBrowser.Providers/Movies/GenericMovieDbInfo.cs @@ -326,8 +326,7 @@ namespace MediaBrowser.Providers.Movies hasTrailers.RemoteTrailers = movieData.trailers.youtube.Select(i => new MediaUrl { Url = string.Format("https://www.youtube.com/watch?v={0}", i.source), - Name = i.name, - VideoSize = string.Equals("hd", i.size, StringComparison.OrdinalIgnoreCase) ? VideoSize.HighDefinition : VideoSize.StandardDefinition + Name = i.name }).ToList(); } diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 95a235109..bb9fcc924 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -418,7 +418,7 @@ namespace MediaBrowser.Server.Implementations.Dto var dto = GetBaseItemDtoInternal(item, options, GetSyncedItemProgressDictionary(syncProgress), user); - if (options.Fields.Contains(ItemFields.ItemCounts)) + if (taggedItems != null && options.Fields.Contains(ItemFields.ItemCounts)) { SetItemByNameInfo(item, dto, taggedItems, user); } diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index c0c40aa5b..09dc0400c 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -33,6 +33,7 @@ using System.Net; using System.Threading; using System.Threading.Tasks; using CommonIO; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Library; using MediaBrowser.Model.Net; @@ -1278,7 +1279,7 @@ namespace MediaBrowser.Server.Implementations.Library private bool EnableCaching { - get { return true; } + get { return false; } } public IEnumerable GetItemList(InternalItemsQuery query) @@ -1326,6 +1327,99 @@ namespace MediaBrowser.Server.Implementations.Library return ItemRepository.GetItemIdsList(query); } + public QueryResult> GetStudios(InternalItemsQuery query) + { + if (query.User != null) + { + AddUserToQuery(query, query.User); + } + + SetTopParentOrAncestorIds(query); + return ItemRepository.GetStudios(query); + } + + public QueryResult> GetGenres(InternalItemsQuery query) + { + if (query.User != null) + { + AddUserToQuery(query, query.User); + } + + SetTopParentOrAncestorIds(query); + return ItemRepository.GetGenres(query); + } + + public QueryResult> GetGameGenres(InternalItemsQuery query) + { + if (query.User != null) + { + AddUserToQuery(query, query.User); + } + + SetTopParentOrAncestorIds(query); + return ItemRepository.GetGameGenres(query); + } + + public QueryResult> GetMusicGenres(InternalItemsQuery query) + { + if (query.User != null) + { + AddUserToQuery(query, query.User); + } + + SetTopParentOrAncestorIds(query); + return ItemRepository.GetMusicGenres(query); + } + + public QueryResult> GetArtists(InternalItemsQuery query) + { + if (query.User != null) + { + AddUserToQuery(query, query.User); + } + + SetTopParentOrAncestorIds(query); + return ItemRepository.GetArtists(query); + } + + private void SetTopParentOrAncestorIds(InternalItemsQuery query) + { + if (query.AncestorIds.Length == 0) + { + return; + } + + var parents = query.AncestorIds.Select(i => GetItemById(new Guid(i))).ToList(); + + if (parents.All(i => + { + if (i is ICollectionFolder || i is UserView) + { + return true; + } + + _logger.Debug("Query requires ancestor query due to type: " + i.GetType().Name); + return false; + + })) + { + // Optimize by querying against top level views + query.TopParentIds = parents.SelectMany(i => GetTopParentsForQuery(i, query.User)).Select(i => i.Id.ToString("N")).ToArray(); + query.AncestorIds = new string[] { }; + } + } + + public QueryResult> GetAlbumArtists(InternalItemsQuery query) + { + if (query.User != null) + { + AddUserToQuery(query, query.User); + } + + SetTopParentOrAncestorIds(query); + return ItemRepository.GetAlbumArtists(query); + } + public IEnumerable GetItemList(InternalItemsQuery query, IEnumerable parentIds) { var parents = parentIds.Select(i => GetItemById(new Guid(i))).Where(i => i != null).ToList(); diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs index 9edd3f83f..703a33856 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs @@ -126,7 +126,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers } else { - var videoInfo = parser.ResolveFile(args.Path); + var videoInfo = parser.Resolve(args.Path, false, false); if (videoInfo == null) { diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index 066a8c3ca..c69c788c8 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -56,8 +56,8 @@ ..\packages\Interfaces.IO.1.0.0.5\lib\portable-net45+sl4+wp71+win8+wpa81\Interfaces.IO.dll - - ..\packages\MediaBrowser.Naming.1.0.0.51\lib\portable-net45+sl4+wp71+win8+wpa81\MediaBrowser.Naming.dll + + ..\packages\MediaBrowser.Naming.1.0.0.52\lib\portable-net45+sl4+wp71+win8+wpa81\MediaBrowser.Naming.dll True diff --git a/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs b/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs index 2a2f9a09d..b11a3e496 100644 --- a/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs +++ b/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs @@ -15,6 +15,7 @@ using System.Threading.Tasks; using CommonIO; using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.Net; using MediaBrowser.Server.Implementations.ScheduledTasks; @@ -145,7 +146,8 @@ namespace MediaBrowser.Server.Implementations.Persistence { var itemIds = _libraryManager.GetItemIds(new InternalItemsQuery { - IsCurrentSchema = false + IsCurrentSchema = false, + ExcludeItemTypes = new[] { typeof(LiveTvProgram).Name } }); var numComplete = 0; @@ -236,14 +238,14 @@ namespace MediaBrowser.Server.Implementations.Persistence // These have their own cleanup routines ExcludeItemTypes = new[] { - typeof(Person).Name, - typeof(Genre).Name, - typeof(MusicGenre).Name, - typeof(GameGenre).Name, - typeof(Studio).Name, - typeof(Year).Name, - typeof(Channel).Name, - typeof(AggregateFolder).Name, + typeof(Person).Name, + typeof(Genre).Name, + typeof(MusicGenre).Name, + typeof(GameGenre).Name, + typeof(Studio).Name, + typeof(Year).Name, + typeof(Channel).Name, + typeof(AggregateFolder).Name, typeof(CollectionFolder).Name } }); @@ -313,8 +315,8 @@ namespace MediaBrowser.Server.Implementations.Persistence public IEnumerable GetDefaultTriggers() { - return new ITaskTrigger[] - { + return new ITaskTrigger[] + { new IntervalTrigger{ Interval = TimeSpan.FromHours(24)} }; } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 437d16974..121074a6e 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -22,6 +22,7 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Playlists; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.LiveTv; namespace MediaBrowser.Server.Implementations.Persistence @@ -94,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Persistence private IDbCommand _updateInheritedRatingCommand; private IDbCommand _updateInheritedTagsCommand; - public const int LatestSchemaVersion = 92; + public const int LatestSchemaVersion = 95; /// /// Initializes a new instance of the class. @@ -157,7 +158,7 @@ namespace MediaBrowser.Server.Implementations.Persistence "create table if not exists UserDataKeys (ItemId GUID, UserDataKey TEXT, PRIMARY KEY (ItemId, UserDataKey))", "create index if not exists idx_UserDataKeys1 on UserDataKeys(ItemId)", - "create table if not exists ItemValues (ItemId GUID, Type INT, Value TEXT)", + "create table if not exists ItemValues (ItemId GUID, Type INT, Value TEXT, CleanValue TEXT)", "create index if not exists idx_ItemValues on ItemValues(ItemId)", "create index if not exists idx_ItemValues2 on ItemValues(ItemId,Type)", @@ -263,6 +264,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(Logger, "TypedBaseItems", "SeriesName", "Text"); _connection.AddColumn(Logger, "UserDataKeys", "Priority", "INT"); + _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text"); string[] postQueries = { @@ -568,10 +570,11 @@ namespace MediaBrowser.Server.Implementations.Persistence _deleteItemValuesCommand.Parameters.Add(_deleteItemValuesCommand, "@Id"); _saveItemValuesCommand = _connection.CreateCommand(); - _saveItemValuesCommand.CommandText = "insert into ItemValues (ItemId, Type, Value) values (@ItemId, @Type, @Value)"; + _saveItemValuesCommand.CommandText = "insert into ItemValues (ItemId, Type, Value, CleanValue) values (@ItemId, @Type, @Value, @CleanValue)"; _saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@ItemId"); _saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@Type"); _saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@Value"); + _saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@CleanValue"); // provider ids _deleteProviderIdsCommand = _connection.CreateCommand(); @@ -905,7 +908,7 @@ namespace MediaBrowser.Server.Implementations.Persistence UpdateUserDataKeys(item.Id, item.GetUserDataKeys().Distinct(StringComparer.OrdinalIgnoreCase).ToList(), transaction); UpdateImages(item.Id, item.ImageInfos, transaction); UpdateProviderIds(item.Id, item.ProviderIds, transaction); - UpdateItemValues(item.Id, GetItemValues(item), transaction); + UpdateItemValues(item.Id, GetItemValuesToSave(item), transaction); } transaction.Commit(); @@ -2019,7 +2022,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } if (string.Equals(name, ItemSortBy.SeriesDatePlayed, StringComparison.OrdinalIgnoreCase)) { - return new Tuple("(Select MAX(LastPlayedDate) from TypedBaseItems B"+ GetJoinUserDataText(query) + " where B.Guid in (Select ItemId from AncestorIds where AncestorId in (select guid from typedbaseitems c where C.Type = 'MediaBrowser.Controller.Entities.TV.Series' And C.Guid in (Select AncestorId from AncestorIds where ItemId=A.Guid))))", false); + return new Tuple("(Select MAX(LastPlayedDate) from TypedBaseItems B" + GetJoinUserDataText(query) + " where B.Guid in (Select ItemId from AncestorIds where AncestorId in (select guid from typedbaseitems c where C.Type = 'MediaBrowser.Controller.Entities.TV.Series' And C.Guid in (Select AncestorId from AncestorIds where ItemId=A.Guid))))", false); } return new Tuple(name, false); @@ -2245,7 +2248,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } } - private List GetWhereClauses(InternalItemsQuery query, IDbCommand cmd) + private List GetWhereClauses(InternalItemsQuery query, IDbCommand cmd, string paramSuffix = "") { var whereClauses = new List(); @@ -2321,8 +2324,8 @@ namespace MediaBrowser.Server.Implementations.Persistence var includeTypes = query.IncludeItemTypes.SelectMany(MapIncludeItemTypes).ToArray(); if (includeTypes.Length == 1) { - whereClauses.Add("type=@type"); - cmd.Parameters.Add(cmd, "@type", DbType.String).Value = includeTypes[0]; + whereClauses.Add("type=@type" + paramSuffix); + cmd.Parameters.Add(cmd, "@type" + paramSuffix, DbType.String).Value = includeTypes[0]; } else if (includeTypes.Length > 1) { @@ -2626,8 +2629,8 @@ namespace MediaBrowser.Server.Implementations.Persistence var index = 0; foreach (var artist in query.ArtistNames) { - clauses.Add("@ArtistName" + index + " in (select value from itemvalues where ItemId=Guid and Type <= 1)"); - cmd.Parameters.Add(cmd, "@ArtistName" + index, DbType.String).Value = artist; + clauses.Add("@ArtistName" + index + " in (select CleanValue from itemvalues where ItemId=Guid and Type <= 1)"); + cmd.Parameters.Add(cmd, "@ArtistName" + index, DbType.String).Value = artist.RemoveDiacritics(); index++; } var clause = "(" + string.Join(" OR ", clauses.ToArray()) + ")"; @@ -2640,8 +2643,8 @@ namespace MediaBrowser.Server.Implementations.Persistence var index = 0; foreach (var item in query.Genres) { - clauses.Add("@Genre" + index + " in (select value from itemvalues where ItemId=Guid and Type=2)"); - cmd.Parameters.Add(cmd, "@Genre" + index, DbType.String).Value = item; + clauses.Add("@Genre" + index + " in (select CleanValue from itemvalues where ItemId=Guid and Type=2)"); + cmd.Parameters.Add(cmd, "@Genre" + index, DbType.String).Value = item.RemoveDiacritics(); index++; } var clause = "(" + string.Join(" OR ", clauses.ToArray()) + ")"; @@ -2654,8 +2657,8 @@ namespace MediaBrowser.Server.Implementations.Persistence var index = 0; foreach (var item in query.Tags) { - clauses.Add("@Tag" + index + " in (select value from itemvalues where ItemId=Guid and Type=4)"); - cmd.Parameters.Add(cmd, "@Tag" + index, DbType.String).Value = item; + clauses.Add("@Tag" + index + " in (select CleanValue from itemvalues where ItemId=Guid and Type=4)"); + cmd.Parameters.Add(cmd, "@Tag" + index, DbType.String).Value = item.RemoveDiacritics(); index++; } var clause = "(" + string.Join(" OR ", clauses.ToArray()) + ")"; @@ -2668,8 +2671,8 @@ namespace MediaBrowser.Server.Implementations.Persistence var index = 0; foreach (var item in query.Studios) { - clauses.Add("@Studio" + index + " in (select value from itemvalues where ItemId=Guid and Type=3)"); - cmd.Parameters.Add(cmd, "@Studio" + index, DbType.String).Value = item; + clauses.Add("@Studio" + index + " in (select CleanValue from itemvalues where ItemId=Guid and Type=3)"); + cmd.Parameters.Add(cmd, "@Studio" + index, DbType.String).Value = item.RemoveDiacritics(); index++; } var clause = "(" + string.Join(" OR ", clauses.ToArray()) + ")"; @@ -2682,8 +2685,8 @@ namespace MediaBrowser.Server.Implementations.Persistence var index = 0; foreach (var item in query.Keywords) { - clauses.Add("@Keyword" + index + " in (select value from itemvalues where ItemId=Guid and Type=5)"); - cmd.Parameters.Add(cmd, "@Keyword" + index, DbType.String).Value = item; + clauses.Add("@Keyword" + index + " in (select CleanValue from itemvalues where ItemId=Guid and Type=5)"); + cmd.Parameters.Add(cmd, "@Keyword" + index, DbType.String).Value = item.RemoveDiacritics(); index++; } var clause = "(" + string.Join(" OR ", clauses.ToArray()) + ")"; @@ -2812,6 +2815,20 @@ namespace MediaBrowser.Server.Implementations.Persistence whereClauses.Add("MediaType in (" + val + ")"); } + if (query.ItemIds.Length > 0) + { + var excludeIds = new List(); + + var index = 0; + foreach (var id in query.ItemIds) + { + excludeIds.Add("Guid = @IncludeId" + index); + cmd.Parameters.Add(cmd, "@IncludeId" + index, DbType.Guid).Value = new Guid(id); + index++; + } + + whereClauses.Add(string.Join(" OR ", excludeIds.ToArray())); + } if (query.ExcludeItemIds.Length > 0) { var excludeIds = new List(); @@ -3478,7 +3495,292 @@ namespace MediaBrowser.Server.Implementations.Persistence } } - private List> GetItemValues(BaseItem item) + public QueryResult> GetArtists(InternalItemsQuery query) + { + return GetItemValues(query, 0, typeof(MusicArtist).FullName); + } + + public QueryResult> GetAlbumArtists(InternalItemsQuery query) + { + return GetItemValues(query, 1, typeof(MusicArtist).FullName); + } + + public QueryResult> GetStudios(InternalItemsQuery query) + { + return GetItemValues(query, 3, typeof(Studio).FullName); + } + + public QueryResult> GetGenres(InternalItemsQuery query) + { + return GetItemValues(query, 2, typeof(Genre).FullName); + } + + public QueryResult> GetGameGenres(InternalItemsQuery query) + { + return GetItemValues(query, 2, typeof(GameGenre).FullName); + } + + public QueryResult> GetMusicGenres(InternalItemsQuery query) + { + return GetItemValues(query, 2, typeof(MusicGenre).FullName); + } + + private QueryResult> GetItemValues(InternalItemsQuery query, int itemValueType, string returnType) + { + if (query == null) + { + throw new ArgumentNullException("query"); + } + + if (!query.Limit.HasValue) + { + query.EnableTotalRecordCount = false; + } + + CheckDisposed(); + + var now = DateTime.UtcNow; + + using (var cmd = _connection.CreateCommand()) + { + var itemCountColumns = new List>(); + + var typesToCount = query.IncludeItemTypes.ToList(); + + if (typesToCount.Count == 0) + { + //typesToCount.Add("Item"); + } + + foreach (var type in typesToCount) + { + var itemCountColumnQuery = "Select Count(Value) from ItemValues where ItemValues.CleanValue=CleanName AND Type=@ItemValueType AND ItemId in ("; + itemCountColumnQuery += "select guid" + GetFromText(); + + var typeSubQuery = new InternalItemsQuery(query.User) + { + ExcludeItemTypes = query.ExcludeItemTypes, + MediaTypes = query.MediaTypes, + AncestorIds = query.AncestorIds, + ExcludeItemIds = query.ExcludeItemIds, + ItemIds = query.ItemIds, + TopParentIds = query.TopParentIds, + ParentId = query.ParentId, + IsPlayed = query.IsPlayed + }; + if (string.Equals(type, "Item", StringComparison.OrdinalIgnoreCase)) + { + typeSubQuery.IncludeItemTypes = query.IncludeItemTypes; + } + else + { + typeSubQuery.IncludeItemTypes = new[] { type }; + } + var whereClauses = GetWhereClauses(typeSubQuery, cmd, type); + + var typeWhereText = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + itemCountColumnQuery += typeWhereText; + + itemCountColumnQuery += ")"; + + var columnName = type + "Count"; + + itemCountColumns.Add(new Tuple(columnName, "(" + itemCountColumnQuery + ") as " + columnName)); + } + + var columns = _retriveItemColumns.ToList(); + columns.AddRange(itemCountColumns.Select(i => i.Item2).ToArray()); + + cmd.CommandText = "select " + string.Join(",", GetFinalColumnsToSelect(query, columns.ToArray(), cmd)) + GetFromText(); + cmd.CommandText += GetJoinUserDataText(query); + + var innerQuery = new InternalItemsQuery(query.User) + { + ExcludeItemTypes = query.ExcludeItemTypes, + IncludeItemTypes = query.IncludeItemTypes, + MediaTypes = query.MediaTypes, + AncestorIds = query.AncestorIds, + ExcludeItemIds = query.ExcludeItemIds, + ItemIds = query.ItemIds, + TopParentIds = query.TopParentIds, + ParentId = query.ParentId, + IsPlayed = query.IsPlayed + }; + + var innerWhereClauses = GetWhereClauses(innerQuery, cmd); + + var innerWhereText = innerWhereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", innerWhereClauses.ToArray()); + + var whereText = " where Type=@SelectType"; + whereText += " And CleanName In (Select CleanValue from ItemValues where Type=@ItemValueType AND ItemId in (select guid from TypedBaseItems" + innerWhereText + "))"; + cmd.CommandText += whereText; + + var outerQuery = new InternalItemsQuery(query.User) + { + IsFavorite = query.IsFavorite, + IsFavoriteOrLiked = query.IsFavoriteOrLiked, + IsLiked = query.IsLiked, + IsLocked = query.IsLocked, + NameLessThan = query.NameLessThan, + NameStartsWith = query.NameStartsWith, + NameStartsWithOrGreater = query.NameStartsWithOrGreater, + AlbumArtistStartsWithOrGreater = query.AlbumArtistStartsWithOrGreater, + Tags = query.Tags, + OfficialRatings = query.OfficialRatings, + Genres = query.GenreIds, + Years = query.Years + }; + + var outerWhereClauses = GetWhereClauses(outerQuery, cmd); + + var outerWhereText = outerWhereClauses.Count == 0 ? + string.Empty : + " AND " + string.Join(" AND ", outerWhereClauses.ToArray()); + cmd.CommandText += outerWhereText; + + cmd.Parameters.Add(cmd, "@SelectType", DbType.String).Value = returnType; + cmd.Parameters.Add(cmd, "@ItemValueType", DbType.Int32).Value = itemValueType; + + if (EnableJoinUserData(query)) + { + cmd.Parameters.Add(cmd, "@UserId", DbType.Guid).Value = query.User.Id; + } + + //cmd.CommandText += GetGroupBy(query); + cmd.CommandText += " group by PresentationUniqueKey"; + + cmd.CommandText += " order by SortName"; + + if (query.Limit.HasValue || query.StartIndex.HasValue) + { + var limit = query.Limit ?? int.MaxValue; + + cmd.CommandText += " LIMIT " + limit.ToString(CultureInfo.InvariantCulture); + + if (query.StartIndex.HasValue) + { + cmd.CommandText += " OFFSET " + query.StartIndex.Value.ToString(CultureInfo.InvariantCulture); + } + } + + cmd.CommandText += ";"; + + var isReturningZeroItems = query.Limit.HasValue && query.Limit <= 0; + + if (isReturningZeroItems) + { + cmd.CommandText = ""; + } + + if (query.EnableTotalRecordCount) + { + cmd.CommandText += "select count (guid)" + GetFromText(); + + cmd.CommandText += GetJoinUserDataText(query); + cmd.CommandText += whereText; + } + else + { + cmd.CommandText = cmd.CommandText.TrimEnd(';'); + } + + var list = new List>(); + var count = 0; + + var commandBehavior = isReturningZeroItems || !query.EnableTotalRecordCount + ? (CommandBehavior.SequentialAccess | CommandBehavior.SingleResult) + : CommandBehavior.SequentialAccess; + + using (var reader = cmd.ExecuteReader(commandBehavior)) + { + LogQueryTime("GetItemValues", cmd, now); + + if (isReturningZeroItems) + { + if (reader.Read()) + { + count = reader.GetInt32(0); + } + } + else + { + while (reader.Read()) + { + var item = GetItem(reader); + if (item != null) + { + var countStartColumn = columns.Count - typesToCount.Count; + + list.Add(new Tuple(item, GetItemCounts(reader, countStartColumn, typesToCount))); + } + } + + if (reader.NextResult() && reader.Read()) + { + count = reader.GetInt32(0); + } + } + } + + if (count == 0) + { + count = list.Count; + } + + return new QueryResult> + { + Items = list.ToArray(), + TotalRecordCount = count + }; + + } + } + + private ItemCounts GetItemCounts(IDataReader reader, int countStartColumn, List typesToCount) + { + var counts = new ItemCounts(); + + for (var i = 0; i < typesToCount.Count; i++) + { + var value = reader.GetInt32(countStartColumn + i); + + var type = typesToCount[i]; + if (string.Equals(type, "Series", StringComparison.OrdinalIgnoreCase)) + { + counts.SeriesCount = value; + } + else if (string.Equals(type, "Episode", StringComparison.OrdinalIgnoreCase)) + { + counts.EpisodeCount = value; + } + else if (string.Equals(type, "Movie", StringComparison.OrdinalIgnoreCase)) + { + counts.MovieCount = value; + } + else if (string.Equals(type, "MusicAlbum", StringComparison.OrdinalIgnoreCase)) + { + counts.AlbumCount = value; + } + else if (string.Equals(type, "Audio", StringComparison.OrdinalIgnoreCase)) + { + counts.SongCount = value; + } + else if (string.Equals(type, "Game", StringComparison.OrdinalIgnoreCase)) + { + counts.GameCount = value; + } + counts.ItemCount += value; + } + + return counts; + } + + private List> GetItemValuesToSave(BaseItem item) { var list = new List>(); @@ -3604,6 +3906,14 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemValuesCommand.GetParameter(0).Value = itemId; _saveItemValuesCommand.GetParameter(1).Value = pair.Item1; _saveItemValuesCommand.GetParameter(2).Value = pair.Item2; + if (pair.Item2 == null) + { + _saveItemValuesCommand.GetParameter(3).Value = null; + } + else + { + _saveItemValuesCommand.GetParameter(3).Value = pair.Item2.RemoveDiacritics(); + } _saveItemValuesCommand.Transaction = transaction; _saveItemValuesCommand.ExecuteNonQuery(); diff --git a/MediaBrowser.Server.Implementations/packages.config b/MediaBrowser.Server.Implementations/packages.config index 42fc51a63..326721ff3 100644 --- a/MediaBrowser.Server.Implementations/packages.config +++ b/MediaBrowser.Server.Implementations/packages.config @@ -4,7 +4,7 @@ - + -- cgit v1.2.3 From 2772d595596b3e682dbce890e53bdc3ef027df46 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 5 Jul 2016 01:40:18 -0400 Subject: denormalize seasonid --- MediaBrowser.Api/StartupWizardService.cs | 2 +- MediaBrowser.Controller/Entities/TV/Episode.cs | 23 +-- MediaBrowser.Model/Dto/BaseItemDto.cs | 10 + .../TV/MissingEpisodeProvider.cs | 3 +- .../Dto/DtoService.cs | 220 +++++++++------------ .../Library/LibraryManager.cs | 8 +- .../Library/Resolvers/TV/EpisodeResolver.cs | 8 + .../LiveTv/LiveTvManager.cs | 2 - .../Persistence/SqliteItemRepository.cs | 15 +- .../UserViews/CollectionFolderImageProvider.cs | 5 - .../UserViews/DynamicImageProvider.cs | 5 - 11 files changed, 135 insertions(+), 166 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers') diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 7cdc3b6a2..8f4a62ced 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -117,7 +117,7 @@ namespace MediaBrowser.Api config.EnableStandaloneMusicKeys = true; config.EnableCaseSensitiveItemIds = true; //config.EnableFolderView = true; - config.SchemaVersion = 99; + config.SchemaVersion = 100; } public void Post(UpdateStartupConfiguration request) diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.cs index d7526a535..4ff1813ff 100644 --- a/MediaBrowser.Controller/Entities/TV/Episode.cs +++ b/MediaBrowser.Controller/Entities/TV/Episode.cs @@ -13,7 +13,6 @@ namespace MediaBrowser.Controller.Entities.TV /// public class Episode : Video, IHasTrailers, IHasLookupInfo, IHasSeries { - public Episode() { RemoteTrailers = new List(); @@ -181,6 +180,12 @@ namespace MediaBrowser.Controller.Entities.TV { var series = Series; return series == null ? SeriesName : series.Name; + } + + public Guid? FindSeasonId() + { + var season = Season; + return season == null ? (Guid?)null : season.Id; } /// @@ -243,21 +248,7 @@ namespace MediaBrowser.Controller.Entities.TV } [IgnoreDataMember] - public Guid? SeasonId - { - get - { - // First see if the parent is a Season - var season = Season; - - if (season != null) - { - return season.Id; - } - - return null; - } - } + public Guid? SeasonId { get; set; } public override IEnumerable GetAncestorIds() { diff --git a/MediaBrowser.Model/Dto/BaseItemDto.cs b/MediaBrowser.Model/Dto/BaseItemDto.cs index 146fcc74e..ac7d97288 100644 --- a/MediaBrowser.Model/Dto/BaseItemDto.cs +++ b/MediaBrowser.Model/Dto/BaseItemDto.cs @@ -954,6 +954,16 @@ namespace MediaBrowser.Model.Dto get { return ImageTags != null && ImageTags.ContainsKey(ImageType.Thumb); } } + /// + /// Gets a value indicating whether this instance has thumb. + /// + /// true if this instance has thumb; otherwise, false. + [IgnoreDataMember] + public bool HasBackdrop + { + get { return (BackdropImageTags != null && BackdropImageTags.Count > 0) || (ParentBackdropImageTags != null && ParentBackdropImageTags.Count > 0); } + } + /// /// Gets a value indicating whether this instance has primary image. /// diff --git a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs index 4e2d9a8d2..e8a0057fe 100644 --- a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs @@ -429,7 +429,8 @@ namespace MediaBrowser.Providers.TV IndexNumber = episodeNumber, ParentIndexNumber = seasonNumber, Id = _libraryManager.GetNewItemId((series.Id + seasonNumber.ToString(_usCulture) + name), typeof(Episode)), - IsVirtualItem = true + IsVirtualItem = true, + SeasonId = season == null ? (Guid?)null : season.Id }; episode.SetParent(season); diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 67ae24f3e..257448941 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -663,19 +663,12 @@ namespace MediaBrowser.Server.Implementations.Dto dto.GameSystem = item.GameSystemName; } - private List GetBackdropImageTags(BaseItem item, int limit) + private List GetImageTags(BaseItem item, List images) { - return GetCacheTags(item, ImageType.Backdrop, limit).ToList(); - } - - private List GetScreenshotImageTags(BaseItem item, int limit) - { - var hasScreenshots = item as IHasScreenshots; - if (hasScreenshots == null) - { - return new List(); - } - return GetCacheTags(item, ImageType.Screenshot, limit).ToList(); + return images + .Select(p => GetImageCacheTag(item, p)) + .Where(i => i != null) + .ToList(); } private IEnumerable GetCacheTags(BaseItem item, ImageType type, int limit) @@ -850,53 +843,6 @@ namespace MediaBrowser.Server.Implementations.Dto } } - /// - /// If an item does not any backdrops, this can be used to find the first parent that does have one - /// - /// The item. - /// The owner. - /// BaseItem. - private BaseItem GetParentBackdropItem(BaseItem item, BaseItem owner) - { - var parent = item.GetParent() ?? owner; - - while (parent != null) - { - if (parent.GetImages(ImageType.Backdrop).Any()) - { - return parent; - } - - parent = parent.GetParent(); - } - - return null; - } - - /// - /// If an item does not have a logo, this can be used to find the first parent that does have one - /// - /// The item. - /// The type. - /// The owner. - /// BaseItem. - private BaseItem GetParentImageItem(BaseItem item, ImageType type, BaseItem owner) - { - var parent = item.GetParent() ?? owner; - - while (parent != null) - { - if (parent.HasImage(type)) - { - return parent; - } - - parent = parent.GetParent(); - } - - return null; - } - /// /// Gets the chapter info dto. /// @@ -1027,7 +973,7 @@ namespace MediaBrowser.Server.Implementations.Dto var backdropLimit = options.GetImageLimit(ImageType.Backdrop); if (backdropLimit > 0) { - dto.BackdropImageTags = GetBackdropImageTags(item, backdropLimit); + dto.BackdropImageTags = GetImageTags(item, item.GetImages(ImageType.Backdrop).Take(backdropLimit).ToList()); } if (fields.Contains(ItemFields.ScreenshotImageTags)) @@ -1035,7 +981,7 @@ namespace MediaBrowser.Server.Implementations.Dto var screenshotLimit = options.GetImageLimit(ImageType.Screenshot); if (screenshotLimit > 0) { - dto.ScreenshotImageTags = GetScreenshotImageTags(item, screenshotLimit); + dto.BackdropImageTags = GetImageTags(item, item.GetImages(ImageType.Screenshot).Take(screenshotLimit).ToList()); } } @@ -1064,6 +1010,7 @@ namespace MediaBrowser.Server.Implementations.Dto dto.Id = GetDtoId(item); dto.IndexNumber = item.IndexNumber; + dto.ParentIndexNumber = item.ParentIndexNumber; dto.IsFolder = item.IsFolder; dto.MediaType = item.MediaType; dto.LocationType = item.LocationType; @@ -1126,18 +1073,6 @@ namespace MediaBrowser.Server.Implementations.Dto dto.ShortOverview = item.ShortOverview; } - // If there are no backdrops, indicate what parent has them in case the Ui wants to allow inheritance - if (backdropLimit > 0 && dto.BackdropImageTags.Count == 0) - { - var parentWithBackdrop = GetParentBackdropItem(item, owner); - - if (parentWithBackdrop != null) - { - dto.ParentBackdropItemId = GetDtoId(parentWithBackdrop); - dto.ParentBackdropImageTags = GetBackdropImageTags(parentWithBackdrop, backdropLimit); - } - } - if (fields.Contains(ItemFields.ParentId)) { var displayParentId = item.DisplayParentId; @@ -1147,46 +1082,7 @@ namespace MediaBrowser.Server.Implementations.Dto } } - dto.ParentIndexNumber = item.ParentIndexNumber; - - // If there is no logo, indicate what parent has one in case the Ui wants to allow inheritance - if (!dto.HasLogo && options.GetImageLimit(ImageType.Logo) > 0) - { - var parentWithLogo = GetParentImageItem(item, ImageType.Logo, owner); - - if (parentWithLogo != null) - { - dto.ParentLogoItemId = GetDtoId(parentWithLogo); - - dto.ParentLogoImageTag = GetImageCacheTag(parentWithLogo, ImageType.Logo); - } - } - - // If there is no art, indicate what parent has one in case the Ui wants to allow inheritance - if (!dto.HasArtImage && options.GetImageLimit(ImageType.Art) > 0) - { - var parentWithImage = GetParentImageItem(item, ImageType.Art, owner); - - if (parentWithImage != null) - { - dto.ParentArtItemId = GetDtoId(parentWithImage); - - dto.ParentArtImageTag = GetImageCacheTag(parentWithImage, ImageType.Art); - } - } - - // If there is no thumb, indicate what parent has one in case the Ui wants to allow inheritance - if (!dto.HasThumb && options.GetImageLimit(ImageType.Thumb) > 0) - { - var parentWithImage = GetParentImageItem(item, ImageType.Thumb, owner); - - if (parentWithImage != null) - { - dto.ParentThumbItemId = GetDtoId(parentWithImage); - - dto.ParentThumbImageTag = GetImageCacheTag(parentWithImage, ImageType.Thumb); - } - } + AddInheritedImages(dto, item, options, owner); if (fields.Contains(ItemFields.Path)) { @@ -1420,33 +1316,36 @@ namespace MediaBrowser.Server.Implementations.Dto dto.SeasonName = episode.SeasonName; - var episodeSeries = episode.Series; + Series episodeSeries = null; - if (episodeSeries != null) + if (fields.Contains(ItemFields.SeriesGenres)) { - if (fields.Contains(ItemFields.SeriesGenres)) + episodeSeries = episodeSeries ?? episode.Series; + if (episodeSeries != null) { dto.SeriesGenres = episodeSeries.Genres.ToList(); } + } + episodeSeries = episodeSeries ?? episode.Series; + if (episodeSeries != null) + { dto.SeriesId = GetDtoId(episodeSeries); + } - if (fields.Contains(ItemFields.AirTime)) - { - dto.AirTime = episodeSeries.AirTime; - } - - if (options.GetImageLimit(ImageType.Thumb) > 0) - { - dto.SeriesThumbImageTag = GetImageCacheTag(episodeSeries, ImageType.Thumb); - } - - if (options.GetImageLimit(ImageType.Primary) > 0) + if (options.GetImageLimit(ImageType.Primary) > 0) + { + episodeSeries = episodeSeries ?? episode.Series; + if (episodeSeries != null) { dto.SeriesPrimaryImageTag = GetImageCacheTag(episodeSeries, ImageType.Primary); } + } - if (fields.Contains(ItemFields.SeriesStudio)) + if (fields.Contains(ItemFields.SeriesStudio)) + { + episodeSeries = episodeSeries ?? episode.Series; + if (episodeSeries != null) { dto.SeriesStudio = episodeSeries.Studios.FirstOrDefault(); } @@ -1475,7 +1374,6 @@ namespace MediaBrowser.Server.Implementations.Dto if (series != null) { dto.SeriesId = GetDtoId(series); - dto.AirTime = series.AirTime; if (fields.Contains(ItemFields.SeriesStudio)) { @@ -1533,6 +1431,70 @@ namespace MediaBrowser.Server.Implementations.Dto } } + private void AddInheritedImages(BaseItemDto dto, BaseItem item, DtoOptions options, BaseItem owner) + { + var logoLimit = options.GetImageLimit(ImageType.Logo); + var artLimit = options.GetImageLimit(ImageType.Art); + var thumbLimit = options.GetImageLimit(ImageType.Thumb); + var backdropLimit = options.GetImageLimit(ImageType.Backdrop); + + if (logoLimit == 0 && artLimit == 0 && thumbLimit == 0 && backdropLimit == 0) + { + return; + } + + BaseItem parent = null; + var isFirst = true; + + while (((!dto.HasLogo && logoLimit > 0) || (!dto.HasArtImage && artLimit > 0) || (!dto.HasThumb && thumbLimit > 0) || parent is Series) && + (parent = parent ?? (isFirst ? item.GetParent() ?? owner : parent)) != null) + { + if (logoLimit > 0 && !dto.HasLogo && dto.ParentLogoItemId == null) + { + var image = parent.GetImageInfo(ImageType.Logo, 0); + + if (image != null) + { + dto.ParentLogoItemId = GetDtoId(parent); + dto.ParentLogoImageTag = GetImageCacheTag(parent, image); + } + } + if (artLimit > 0 && !dto.HasArtImage && dto.ParentArtItemId == null) + { + var image = parent.GetImageInfo(ImageType.Art, 0); + + if (image != null) + { + dto.ParentArtItemId = GetDtoId(parent); + dto.ParentArtImageTag = GetImageCacheTag(parent, image); + } + } + if (thumbLimit > 0 && !dto.HasThumb && (dto.ParentThumbItemId == null || parent is Series)) + { + var image = parent.GetImageInfo(ImageType.Thumb, 0); + + if (image != null) + { + dto.ParentThumbItemId = GetDtoId(parent); + dto.ParentThumbImageTag = GetImageCacheTag(parent, image); + } + } + if (backdropLimit > 0 && !dto.HasBackdrop) + { + var images = parent.GetImages(ImageType.Backdrop).Take(backdropLimit).ToList(); + + if (images.Count > 0) + { + dto.ParentBackdropItemId = GetDtoId(parent); + dto.ParentBackdropImageTags = GetImageTags(parent, images); + } + } + + isFirst = false; + parent = parent.GetParent(); + } + } + private string GetMappedPath(IHasMetadata item) { var path = item.Path; diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 9d66455e7..7458e7541 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -368,10 +368,10 @@ namespace MediaBrowser.Server.Implementations.Library { return; } - //if (!(item is Folder)) - //{ - // return; - //} + if (!(item is Folder)) + { + return; + } LibraryItemsCache.AddOrUpdate(id, item, delegate { return item; }); } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs index 14e5e446b..e279a978e 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs @@ -45,6 +45,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV { var episode = ResolveVideo(args, false); + if (episode != null) + { + if (season != null) + { + episode.SeasonId = season.Id; + } + } + return episode; } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index f32a4b59e..64af35a9a 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -1214,8 +1214,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv var item = await GetChannel(channelInfo.Item2, channelInfo.Item1, parentFolderId, cancellationToken).ConfigureAwait(false); list.Add(item); - - _libraryManager.RegisterItem(item); } catch (OperationCanceledException) { diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 041647439..e239c3b83 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -95,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Persistence private IDbCommand _updateInheritedRatingCommand; private IDbCommand _updateInheritedTagsCommand; - public const int LatestSchemaVersion = 99; + public const int LatestSchemaVersion = 100; /// /// Initializes a new instance of the class. @@ -272,6 +272,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(Logger, "TypedBaseItems", "SeriesName", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "UserDataKey", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "SeasonName", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "SeasonId", "GUID"); _connection.AddColumn(Logger, "UserDataKeys", "Priority", "INT"); _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text"); @@ -405,7 +406,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "CriticRatingSummary", "IsVirtualItem", "SeriesName", - "SeasonName" + "SeasonName", + "SeasonId" }; private readonly string[] _mediaStreamSaveColumns = @@ -526,7 +528,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "IsVirtualItem", "SeriesName", "UserDataKey", - "SeasonName" + "SeasonName", + "SeasonId" }; _saveItemCommand = _connection.CreateCommand(); _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values ("; @@ -961,10 +964,12 @@ namespace MediaBrowser.Server.Implementations.Persistence if (episode != null) { _saveItemCommand.GetParameter(index++).Value = episode.FindSeasonName(); + _saveItemCommand.GetParameter(index++).Value = episode.FindSeasonId(); } else { _saveItemCommand.GetParameter(index++).Value = null; + _saveItemCommand.GetParameter(index++).Value = null; } _saveItemCommand.Transaction = transaction; @@ -1405,6 +1410,10 @@ namespace MediaBrowser.Server.Implementations.Persistence { episode.SeasonName = reader.GetString(60); } + if (!reader.IsDBNull(61)) + { + episode.SeasonId = reader.GetGuid(61); + } } return item; diff --git a/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs b/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs index a66884f89..29716d33e 100644 --- a/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs +++ b/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs @@ -54,11 +54,6 @@ namespace MediaBrowser.Server.Implementations.UserViews { return series; } - var episodeSeason = episode.Season; - if (episodeSeason != null) - { - return episodeSeason; - } return episode; } diff --git a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs index 161f771a9..ea4da19b2 100644 --- a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs +++ b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs @@ -86,11 +86,6 @@ namespace MediaBrowser.Server.Implementations.UserViews { return series; } - var episodeSeason = episode.Season; - if (episodeSeason != null) - { - return episodeSeason; - } return episode; } -- cgit v1.2.3 From 1fcbd3c6da5bd061473a3f34a6410c9bbce0fc13 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 5 Jul 2016 02:01:31 -0400 Subject: denormalize seriesid --- MediaBrowser.Api/StartupWizardService.cs | 2 +- MediaBrowser.Controller/Entities/Book.cs | 9 +++++- MediaBrowser.Controller/Entities/IHasSeries.cs | 5 +++- MediaBrowser.Controller/Entities/TV/Episode.cs | 9 +++++- MediaBrowser.Controller/Entities/TV/Season.cs | 8 +++++ MediaBrowser.Model/Querying/ItemFields.cs | 2 ++ .../TV/MissingEpisodeProvider.cs | 3 +- .../Dto/DtoService.cs | 35 ++++++++++++++-------- .../Library/Resolvers/TV/EpisodeResolver.cs | 29 +++++++++++------- .../Persistence/SqliteItemRepository.cs | 26 ++++++++++++++-- 10 files changed, 97 insertions(+), 31 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers') diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 8f4a62ced..a59cc6909 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -117,7 +117,7 @@ namespace MediaBrowser.Api config.EnableStandaloneMusicKeys = true; config.EnableCaseSensitiveItemIds = true; //config.EnableFolderView = true; - config.SchemaVersion = 100; + config.SchemaVersion = 101; } public void Post(UpdateStartupConfiguration request) diff --git a/MediaBrowser.Controller/Entities/Book.cs b/MediaBrowser.Controller/Entities/Book.cs index 76f54edea..34368d61f 100644 --- a/MediaBrowser.Controller/Entities/Book.cs +++ b/MediaBrowser.Controller/Entities/Book.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Providers; +using System; +using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Configuration; using System.Linq; using System.Runtime.Serialization; @@ -19,12 +20,18 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public string SeriesName { get; set; } + public Guid? SeriesId { get; set; } public string FindSeriesName() { return SeriesName; } + public Guid? FindSeriesId() + { + return SeriesId; + } + public override bool CanDownload() { var locationType = LocationType; diff --git a/MediaBrowser.Controller/Entities/IHasSeries.cs b/MediaBrowser.Controller/Entities/IHasSeries.cs index 1a262ed28..d4dbb8ef6 100644 --- a/MediaBrowser.Controller/Entities/IHasSeries.cs +++ b/MediaBrowser.Controller/Entities/IHasSeries.cs @@ -1,4 +1,6 @@  +using System; + namespace MediaBrowser.Controller.Entities { public interface IHasSeries @@ -8,7 +10,8 @@ namespace MediaBrowser.Controller.Entities /// /// The name of the series. string SeriesName { get; set; } - string FindSeriesName(); + Guid? SeriesId { get; set; } + Guid? FindSeriesId(); } } diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.cs index 4ff1813ff..b13c291d1 100644 --- a/MediaBrowser.Controller/Entities/TV/Episode.cs +++ b/MediaBrowser.Controller/Entities/TV/Episode.cs @@ -248,7 +248,14 @@ namespace MediaBrowser.Controller.Entities.TV } [IgnoreDataMember] - public Guid? SeasonId { get; set; } + public Guid? SeasonId { get; set; } + public Guid? SeriesId { get; set; } + + public Guid? FindSeriesId() + { + var series = Series; + return series == null ? (Guid?)null : series.Id; + } public override IEnumerable GetAncestorIds() { diff --git a/MediaBrowser.Controller/Entities/TV/Season.cs b/MediaBrowser.Controller/Entities/TV/Season.cs index a689ca550..218d0fef8 100644 --- a/MediaBrowser.Controller/Entities/TV/Season.cs +++ b/MediaBrowser.Controller/Entities/TV/Season.cs @@ -237,12 +237,20 @@ namespace MediaBrowser.Controller.Entities.TV [IgnoreDataMember] public string SeriesName { get; set; } + public Guid? SeriesId { get; set; } + public string FindSeriesName() { var series = Series; return series == null ? SeriesName : series.Name; } + public Guid? FindSeriesId() + { + var series = Series; + return series == null ? (Guid?)null : series.Id; + } + /// /// Gets the lookup information. /// diff --git a/MediaBrowser.Model/Querying/ItemFields.cs b/MediaBrowser.Model/Querying/ItemFields.cs index cea638a39..21f87247a 100644 --- a/MediaBrowser.Model/Querying/ItemFields.cs +++ b/MediaBrowser.Model/Querying/ItemFields.cs @@ -197,6 +197,8 @@ /// SeriesGenres, + SeriesPrimaryImage, + /// /// The series studio /// diff --git a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs index e8a0057fe..22e126795 100644 --- a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs @@ -430,7 +430,8 @@ namespace MediaBrowser.Providers.TV ParentIndexNumber = seasonNumber, Id = _libraryManager.GetNewItemId((series.Id + seasonNumber.ToString(_usCulture) + name), typeof(Episode)), IsVirtualItem = true, - SeasonId = season == null ? (Guid?)null : season.Id + SeasonId = season == null ? (Guid?)null : season.Id, + SeriesId = series.Id }; episode.SetParent(season); diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 257448941..925afa428 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -1316,6 +1316,12 @@ namespace MediaBrowser.Server.Implementations.Dto dto.SeasonName = episode.SeasonName; + var seriesId = episode.SeriesId; + if (seriesId.HasValue) + { + dto.SeriesId = seriesId.Value.ToString("N"); + } + Series episodeSeries = null; if (fields.Contains(ItemFields.SeriesGenres)) @@ -1327,13 +1333,7 @@ namespace MediaBrowser.Server.Implementations.Dto } } - episodeSeries = episodeSeries ?? episode.Series; - if (episodeSeries != null) - { - dto.SeriesId = GetDtoId(episodeSeries); - } - - if (options.GetImageLimit(ImageType.Primary) > 0) + if (fields.Contains(ItemFields.SeriesPrimaryImage)) { episodeSeries = episodeSeries ?? episode.Series; if (episodeSeries != null) @@ -1369,18 +1369,27 @@ namespace MediaBrowser.Server.Implementations.Dto { dto.SeriesName = season.SeriesName; - series = season.Series; - - if (series != null) + var seriesId = season.SeriesId; + if (seriesId.HasValue) { - dto.SeriesId = GetDtoId(series); + dto.SeriesId = seriesId.Value.ToString("N"); + } + + series = null; - if (fields.Contains(ItemFields.SeriesStudio)) + if (fields.Contains(ItemFields.SeriesStudio)) + { + series = series ?? season.Series; + if (series != null) { dto.SeriesStudio = series.Studios.FirstOrDefault(); } + } - if (options.GetImageLimit(ImageType.Primary) > 0) + if (fields.Contains(ItemFields.SeriesPrimaryImage)) + { + series = series ?? season.Series; + if (series != null) { dto.SeriesPrimaryImageTag = GetImageCacheTag(series, ImageType.Primary); } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs index e279a978e..6d0f4ffe2 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs @@ -30,23 +30,32 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV return null; } - var season = parent as Season; - - // Just in case the user decided to nest episodes. - // Not officially supported but in some cases we can handle it. - if (season == null) - { - season = parent.GetParents().OfType().FirstOrDefault(); - } - // If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something // Also handle flat tv folders - if (season != null || args.HasParent() || string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) { var episode = ResolveVideo(args, false); if (episode != null) { + var season = parent as Season; + // Just in case the user decided to nest episodes. + // Not officially supported but in some cases we can handle it. + if (season == null) + { + season = parent.GetParents().OfType().FirstOrDefault(); + } + + var series = parent as Series; + if (series == null) + { + series = parent.GetParents().OfType().FirstOrDefault(); + } + + if (series != null) + { + episode.SeriesId = series.Id; + } if (season != null) { episode.SeasonId = season.Id; diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index e239c3b83..4a70ddc2e 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -95,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Persistence private IDbCommand _updateInheritedRatingCommand; private IDbCommand _updateInheritedTagsCommand; - public const int LatestSchemaVersion = 100; + public const int LatestSchemaVersion = 101; /// /// Initializes a new instance of the class. @@ -273,6 +273,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(Logger, "TypedBaseItems", "UserDataKey", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "SeasonName", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "SeasonId", "GUID"); + _connection.AddColumn(Logger, "TypedBaseItems", "SeriesId", "GUID"); _connection.AddColumn(Logger, "UserDataKeys", "Priority", "INT"); _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text"); @@ -407,7 +408,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "IsVirtualItem", "SeriesName", "SeasonName", - "SeasonId" + "SeasonId", + "SeriesId" }; private readonly string[] _mediaStreamSaveColumns = @@ -529,7 +531,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "SeriesName", "UserDataKey", "SeasonName", - "SeasonId" + "SeasonId", + "SeriesId" }; _saveItemCommand = _connection.CreateCommand(); _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values ("; @@ -972,6 +975,15 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = null; } + if (hasSeries != null) + { + _saveItemCommand.GetParameter(index++).Value = hasSeries.FindSeriesId(); + } + else + { + _saveItemCommand.GetParameter(index++).Value = null; + } + _saveItemCommand.Transaction = transaction; _saveItemCommand.ExecuteNonQuery(); @@ -1416,6 +1428,14 @@ namespace MediaBrowser.Server.Implementations.Persistence } } + if (hasSeries != null) + { + if (!reader.IsDBNull(62)) + { + hasSeries.SeriesId = reader.GetGuid(62); + } + } + return item; } -- cgit v1.2.3 From 959c6a397cf9bb7c5494e8bb04d9b8f7dff40383 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 9 Jul 2016 13:39:04 -0400 Subject: add new streambuilder options --- MediaBrowser.Model/Dlna/AudioOptions.cs | 6 + MediaBrowser.Model/Dlna/CodecProfile.cs | 3 + MediaBrowser.Model/Dlna/StreamBuilder.cs | 158 +++++++++++++++++---- MediaBrowser.Providers/TV/DummySeasonProvider.cs | 3 +- .../Library/LibraryManager.cs | 43 +++--- .../Library/Resolvers/TV/EpisodeResolver.cs | 20 +-- .../Library/Resolvers/TV/SeasonResolver.cs | 6 +- 7 files changed, 186 insertions(+), 53 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers') diff --git a/MediaBrowser.Model/Dlna/AudioOptions.cs b/MediaBrowser.Model/Dlna/AudioOptions.cs index 6ad4fa265..162b88c98 100644 --- a/MediaBrowser.Model/Dlna/AudioOptions.cs +++ b/MediaBrowser.Model/Dlna/AudioOptions.cs @@ -11,8 +11,14 @@ namespace MediaBrowser.Model.Dlna public AudioOptions() { Context = EncodingContext.Streaming; + + EnableDirectPlay = true; + EnableDirectStream = true; } + public bool EnableDirectPlay { get; set; } + public bool EnableDirectStream { get; set; } + public string ItemId { get; set; } public List MediaSources { get; set; } public DeviceProfile Profile { get; set; } diff --git a/MediaBrowser.Model/Dlna/CodecProfile.cs b/MediaBrowser.Model/Dlna/CodecProfile.cs index 7200f648c..385e98f61 100644 --- a/MediaBrowser.Model/Dlna/CodecProfile.cs +++ b/MediaBrowser.Model/Dlna/CodecProfile.cs @@ -11,6 +11,8 @@ namespace MediaBrowser.Model.Dlna public ProfileCondition[] Conditions { get; set; } + public ProfileCondition[] ApplyConditions { get; set; } + [XmlAttribute("codec")] public string Codec { get; set; } @@ -20,6 +22,7 @@ namespace MediaBrowser.Model.Dlna public CodecProfile() { Conditions = new ProfileCondition[] {}; + ApplyConditions = new ProfileCondition[] { }; } public List GetCodecs() diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index 41efa51b9..e07e56d39 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -131,6 +131,11 @@ namespace MediaBrowser.Model.Dlna List directPlayMethods = GetAudioDirectPlayMethods(item, audioStream, options); + ConditionProcessor conditionProcessor = new ConditionProcessor(); + + int? inputAudioChannels = audioStream == null ? null : audioStream.Channels; + int? inputAudioBitrate = audioStream == null ? null : audioStream.BitDepth; + if (directPlayMethods.Count > 0) { string audioCodec = audioStream == null ? null : audioStream.Codec; @@ -138,27 +143,36 @@ namespace MediaBrowser.Model.Dlna // Make sure audio codec profiles are satisfied if (!string.IsNullOrEmpty(audioCodec)) { - ConditionProcessor conditionProcessor = new ConditionProcessor(); - List conditions = new List(); foreach (CodecProfile i in options.Profile.CodecProfiles) { if (i.Type == CodecType.Audio && i.ContainsCodec(audioCodec, item.Container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - conditions.Add(c); + if (!conditionProcessor.IsAudioConditionSatisfied(applyCondition, inputAudioChannels, inputAudioBitrate)) + { + LogConditionFailure(options.Profile, "AudioCodecProfile", applyCondition, item); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + conditions.Add(c); + } } } } - int? audioChannels = audioStream.Channels; - int? audioBitrate = audioStream.BitRate; - bool all = true; foreach (ProfileCondition c in conditions) { - if (!conditionProcessor.IsAudioConditionSatisfied(c, audioChannels, audioBitrate)) + if (!conditionProcessor.IsAudioConditionSatisfied(c, inputAudioChannels, inputAudioBitrate)) { LogConditionFailure(options.Profile, "AudioCodecProfile", c, item); all = false; @@ -241,9 +255,23 @@ namespace MediaBrowser.Model.Dlna List audioTranscodingConditions = new List(); foreach (CodecProfile i in audioCodecProfiles) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - audioTranscodingConditions.Add(c); + if (!conditionProcessor.IsAudioConditionSatisfied(applyCondition, inputAudioChannels, inputAudioBitrate)) + { + LogConditionFailure(options.Profile, "AudioCodecProfile", applyCondition, item); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + audioTranscodingConditions.Add(c); + } } } @@ -294,7 +322,7 @@ namespace MediaBrowser.Model.Dlna if (directPlayProfile != null) { // While options takes the network and other factors into account. Only applies to direct stream - if (item.SupportsDirectStream && IsAudioEligibleForDirectPlay(item, options.GetMaxBitrate())) + if (item.SupportsDirectStream && IsAudioEligibleForDirectPlay(item, options.GetMaxBitrate()) && options.EnableDirectStream) { playMethods.Add(PlayMethod.DirectStream); } @@ -302,7 +330,7 @@ namespace MediaBrowser.Model.Dlna // The profile describes what the device supports // If device requirements are satisfied then allow both direct stream and direct play if (item.SupportsDirectPlay && - IsAudioEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options))) + IsAudioEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options)) && options.EnableDirectPlay) { playMethods.Add(PlayMethod.DirectPlay); } @@ -385,8 +413,8 @@ namespace MediaBrowser.Model.Dlna MediaStream videoStream = item.VideoStream; // TODO: This doesn't accout for situation of device being able to handle media bitrate, but wifi connection not fast enough - bool isEligibleForDirectPlay = IsEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options), subtitleStream, options, PlayMethod.DirectPlay); - bool isEligibleForDirectStream = IsEligibleForDirectPlay(item, options.GetMaxBitrate(), subtitleStream, options, PlayMethod.DirectStream); + bool isEligibleForDirectPlay = options.EnableDirectPlay && IsEligibleForDirectPlay(item, GetBitrateForDirectPlayCheck(item, options), subtitleStream, options, PlayMethod.DirectPlay); + bool isEligibleForDirectStream = options.EnableDirectStream && IsEligibleForDirectPlay(item, options.GetMaxBitrate(), subtitleStream, options, PlayMethod.DirectStream); _logger.Info("Profile: {0}, Path: {1}, isEligibleForDirectPlay: {2}, isEligibleForDirectStream: {3}", options.Profile.Name ?? "Unknown Profile", @@ -463,17 +491,37 @@ namespace MediaBrowser.Model.Dlna } playlistItem.SubProtocol = transcodingProfile.Protocol; playlistItem.AudioStreamIndex = audioStreamIndex; + ConditionProcessor conditionProcessor = new ConditionProcessor(); List videoTranscodingConditions = new List(); foreach (CodecProfile i in options.Profile.CodecProfiles) { if (i.Type == CodecType.Video && i.ContainsCodec(transcodingProfile.VideoCodec, transcodingProfile.Container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - videoTranscodingConditions.Add(c); + bool? isSecondaryAudio = audioStream == null ? null : item.IsSecondaryAudio(audioStream); + int? inputAudioBitrate = audioStream == null ? null : audioStream.BitRate; + int? audioChannels = audioStream == null ? null : audioStream.Channels; + string audioProfile = audioStream == null ? null : audioStream.Profile; + + if (!conditionProcessor.IsVideoAudioConditionSatisfied(applyCondition, audioChannels, inputAudioBitrate, audioProfile, isSecondaryAudio)) + { + LogConditionFailure(options.Profile, "AudioCodecProfile", applyCondition, item); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + videoTranscodingConditions.Add(c); + } + break; } - break; } } ApplyTranscodingConditions(playlistItem, videoTranscodingConditions); @@ -483,11 +531,42 @@ namespace MediaBrowser.Model.Dlna { if (i.Type == CodecType.VideoAudio && i.ContainsCodec(playlistItem.TargetAudioCodec, transcodingProfile.Container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - audioTranscodingConditions.Add(c); + int? width = videoStream == null ? null : videoStream.Width; + int? height = videoStream == null ? null : videoStream.Height; + int? bitDepth = videoStream == null ? null : videoStream.BitDepth; + int? videoBitrate = videoStream == null ? null : videoStream.BitRate; + double? videoLevel = videoStream == null ? null : videoStream.Level; + string videoProfile = videoStream == null ? null : videoStream.Profile; + float? videoFramerate = videoStream == null ? null : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate; + bool? isAnamorphic = videoStream == null ? null : videoStream.IsAnamorphic; + string videoCodecTag = videoStream == null ? null : videoStream.CodecTag; + + TransportStreamTimestamp? timestamp = videoStream == null ? TransportStreamTimestamp.None : item.Timestamp; + int? packetLength = videoStream == null ? null : videoStream.PacketLength; + int? refFrames = videoStream == null ? null : videoStream.RefFrames; + + int? numAudioStreams = item.GetStreamCount(MediaStreamType.Audio); + int? numVideoStreams = item.GetStreamCount(MediaStreamType.Video); + + if (!conditionProcessor.IsVideoConditionSatisfied(applyCondition, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) + { + LogConditionFailure(options.Profile, "VideoCodecProfile", applyCondition, item); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + audioTranscodingConditions.Add(c); + } + break; } - break; } } ApplyTranscodingConditions(playlistItem, audioTranscodingConditions); @@ -666,9 +745,23 @@ namespace MediaBrowser.Model.Dlna { if (i.Type == CodecType.Video && i.ContainsCodec(videoCodec, container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - conditions.Add(c); + if (!conditionProcessor.IsVideoConditionSatisfied(applyCondition, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) + { + LogConditionFailure(profile, "VideoCodecProfile", applyCondition, mediaSource); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + conditions.Add(c); + } } } } @@ -697,20 +790,35 @@ namespace MediaBrowser.Model.Dlna } conditions = new List(); + bool? isSecondaryAudio = audioStream == null ? null : mediaSource.IsSecondaryAudio(audioStream); + foreach (CodecProfile i in profile.CodecProfiles) { if (i.Type == CodecType.VideoAudio && i.ContainsCodec(audioCodec, container)) { - foreach (ProfileCondition c in i.Conditions) + bool applyConditions = true; + foreach (ProfileCondition applyCondition in i.ApplyConditions) { - conditions.Add(c); + if (!conditionProcessor.IsVideoAudioConditionSatisfied(applyCondition, audioChannels, audioBitrate, audioProfile, isSecondaryAudio)) + { + LogConditionFailure(profile, "VideoAudioCodecProfile", applyCondition, mediaSource); + applyConditions = false; + break; + } + } + + if (applyConditions) + { + foreach (ProfileCondition c in i.Conditions) + { + conditions.Add(c); + } } } } foreach (ProfileCondition i in conditions) { - bool? isSecondaryAudio = audioStream == null ? null : mediaSource.IsSecondaryAudio(audioStream); if (!conditionProcessor.IsVideoAudioConditionSatisfied(i, audioChannels, audioBitrate, audioProfile, isSecondaryAudio)) { LogConditionFailure(profile, "VideoAudioCodecProfile", i, mediaSource); diff --git a/MediaBrowser.Providers/TV/DummySeasonProvider.cs b/MediaBrowser.Providers/TV/DummySeasonProvider.cs index 909760fee..baea0a06d 100644 --- a/MediaBrowser.Providers/TV/DummySeasonProvider.cs +++ b/MediaBrowser.Providers/TV/DummySeasonProvider.cs @@ -111,7 +111,8 @@ namespace MediaBrowser.Providers.TV Name = seasonName, IndexNumber = seasonNumber, Id = _libraryManager.GetNewItemId((series.Id + (seasonNumber ?? -1).ToString(_usCulture) + seasonName), typeof(Season)), - IsVirtualItem = isVirtualItem + IsVirtualItem = isVirtualItem, + SeriesId = series.Id }; season.SetParent(series); diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 7458e7541..a6c5d5429 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -33,6 +33,7 @@ using System.Net; using System.Threading; using System.Threading.Tasks; using CommonIO; +using MediaBrowser.Controller.Channels; using MediaBrowser.Model.Channels; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Extensions; @@ -353,10 +354,6 @@ namespace MediaBrowser.Server.Implementations.Library private void RegisterItem(Guid id, BaseItem item) { - if (item.SourceType != SourceType.Library) - { - return; - } if (item is IItemByName) { if (!(item is MusicArtist)) @@ -364,14 +361,26 @@ namespace MediaBrowser.Server.Implementations.Library return; } } - if (item is Photo) + + if (item.IsFolder) { - return; + if (!(item is ICollectionFolder) && !(item is UserView) && !(item is Channel)) + { + if (item.SourceType != SourceType.Library) + { + return; + } + } } - if (!(item is Folder)) + else { return; + if (item is Photo) + { + return; + } } + LibraryItemsCache.AddOrUpdate(id, item, delegate { return item; }); } @@ -782,19 +791,19 @@ namespace MediaBrowser.Server.Implementations.Library public BaseItem FindByPath(string path, bool? isFolder) { + // If this returns multiple items it could be tricky figuring out which one is correct. + // In most cases, the newest one will be and the others obsolete but not yet cleaned up + var query = new InternalItemsQuery { Path = path, - IsFolder = isFolder + IsFolder = isFolder, + SortBy = new[] { ItemSortBy.DateCreated }, + SortOrder = SortOrder.Descending, + Limit = 1 }; - // If this returns multiple items it could be tricky figuring out which one is correct. - // In most cases, the newest one will be and the others obsolete but not yet cleaned up - - return GetItemIds(query) - .Select(GetItemById) - .Where(i => i != null) - .OrderByDescending(i => i.DateCreated) + return GetItemList(query) .FirstOrDefault(); } @@ -1258,6 +1267,8 @@ namespace MediaBrowser.Server.Implementations.Library item = RetrieveItem(id); + //_logger.Debug("GetitemById {0}", id); + if (item != null) { RegisterItem(item); @@ -1508,7 +1519,7 @@ namespace MediaBrowser.Server.Implementations.Library UserId = user.Id.ToString("N") }, CancellationToken.None).Result; - + return channelResult.Items; } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs index 6d0f4ffe2..7b8832c59 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs @@ -30,22 +30,24 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV return null; } + var season = parent as Season; + // Just in case the user decided to nest episodes. + // Not officially supported but in some cases we can handle it. + if (season == null) + { + season = parent.GetParents().OfType().FirstOrDefault(); + } + // If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something // Also handle flat tv folders - if (string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) + if (season != null || + string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) || + args.HasParent()) { var episode = ResolveVideo(args, false); if (episode != null) { - var season = parent as Season; - // Just in case the user decided to nest episodes. - // Not officially supported but in some cases we can handle it. - if (season == null) - { - season = parent.GetParents().OfType().FirstOrDefault(); - } - var series = parent as Series; if (series == null) { diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs index 7d13b11ad..eeac1345e 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs @@ -38,10 +38,12 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV if (args.Parent is Series && args.IsDirectory) { var namingOptions = ((LibraryManager)_libraryManager).GetNamingOptions(); - + var series = ((Series)args.Parent); + var season = new Season { - IndexNumber = new SeasonPathParser(namingOptions, new RegexProvider()).Parse(args.Path, true, true).SeasonNumber + IndexNumber = new SeasonPathParser(namingOptions, new RegexProvider()).Parse(args.Path, true, true).SeasonNumber, + SeriesId = series.Id }; if (season.IndexNumber.HasValue && season.IndexNumber.Value == 0) -- cgit v1.2.3 From 96efd27e2030703e7ab8b767c27c16f868c5ac22 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 11 Jul 2016 00:57:22 -0400 Subject: allow photos in home video libraries --- .../Library/Resolvers/PhotoResolver.cs | 48 ++++++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers') diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs index 8beb03b71..9dd30edde 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs @@ -5,15 +5,19 @@ using MediaBrowser.Model.Entities; using System; using System.IO; using System.Linq; +using CommonIO; namespace MediaBrowser.Server.Implementations.Library.Resolvers { public class PhotoResolver : ItemResolver { private readonly IImageProcessor _imageProcessor; - public PhotoResolver(IImageProcessor imageProcessor) + private readonly ILibraryManager _libraryManager; + + public PhotoResolver(IImageProcessor imageProcessor, ILibraryManager libraryManager) { _imageProcessor = imageProcessor; + _libraryManager = libraryManager; } /// @@ -23,20 +27,45 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers /// Trailer. protected override Photo Resolve(ItemResolveArgs args) { - // Must be an image file within a photo collection - if (string.Equals(args.GetCollectionType(), CollectionType.Photos, StringComparison.OrdinalIgnoreCase) && - !args.IsDirectory && - IsImageFile(args.Path, _imageProcessor)) + if (!args.IsDirectory) { - return new Photo + // Must be an image file within a photo collection + var collectionType = args.GetCollectionType(); + + if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase) || + string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) { - Path = args.Path - }; + if (IsImageFile(args.Path, _imageProcessor)) + { + var filename = Path.GetFileNameWithoutExtension(args.Path); + + // Make sure the image doesn't belong to a video file + if (args.DirectoryService.GetFiles(Path.GetDirectoryName(args.Path)).Any(i => IsOwnedByMedia(i, filename))) + { + return null; + } + + return new Photo + { + Path = args.Path + }; + } + } } return null; } + private bool IsOwnedByMedia(FileSystemMetadata file, string imageFilename) + { + if (_libraryManager.IsVideoFile(file.FullName) && imageFilename.StartsWith(Path.GetFileNameWithoutExtension(file.Name), StringComparison.OrdinalIgnoreCase)) + { + return true; + } + + return false; + } + private static readonly string[] IgnoreFiles = { "folder", @@ -44,7 +73,8 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers "landscape", "fanart", "backdrop", - "poster" + "poster", + "cover" }; internal static bool IsImageFile(string path, IImageProcessor imageProcessor) -- cgit v1.2.3