diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs index 564cfa93a..7a14ace77 100644 --- a/MediaBrowser.Api/BaseApiService.cs +++ b/MediaBrowser.Api/BaseApiService.cs @@ -344,9 +344,7 @@ namespace MediaBrowser.Api return name; } - return libraryManager.GetAllPeople() - .Select(i => i.Name) - .DistinctNames() + return libraryManager.GetPeopleNames(new InternalPeopleQuery()) .FirstOrDefault(i => { i = _dashReplaceChars.Aggregate(i, (current, c) => current.Replace(c, SlugChar)); diff --git a/MediaBrowser.Api/Movies/MoviesService.cs b/MediaBrowser.Api/Movies/MoviesService.cs index 17eb448bc..97e9aa9c8 100644 --- a/MediaBrowser.Api/Movies/MoviesService.cs +++ b/MediaBrowser.Api/Movies/MoviesService.cs @@ -165,7 +165,7 @@ namespace MediaBrowser.Api.Movies return ToOptimizedResult(result); } - private async Task GetSimilarItemsResult(BaseGetSimilarItemsFromItem request, Func includeInSearch, Func getSimilarityScore) + private async Task GetSimilarItemsResult(BaseGetSimilarItemsFromItem request, Func includeInSearch, Func, List, BaseItem, int> getSimilarityScore) { var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null; @@ -358,12 +358,15 @@ namespace MediaBrowser.Api.Movies private IEnumerable GetWithActor(User user, List allMovies, IEnumerable names, int itemLimit, DtoOptions dtoOptions, RecommendationType type) { - var userId = user.Id; - foreach (var name in names) { + var itemsWithActor = _libraryManager.GetItemIds(new InternalItemsQuery + { + Person = name + }); + var items = allMovies - .Where(i => _libraryManager.GetPeople(i).Any(p => string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase))) + .Where(i => itemsWithActor.Contains(i.Id)) .Take(itemLimit) .ToList(); @@ -382,8 +385,6 @@ namespace MediaBrowser.Api.Movies private IEnumerable GetSimilarTo(User user, List allMovies, IEnumerable baselineItems, int itemLimit, DtoOptions dtoOptions, RecommendationType type) { - var userId = user.Id; - foreach (var item in baselineItems) { var similar = SimilarItemsHelper @@ -406,18 +407,37 @@ namespace MediaBrowser.Api.Movies private IEnumerable GetActors(IEnumerable items) { - // Get the two leading actors for all movies - return items - .SelectMany(i => _libraryManager.GetPeople(i).Where(p => !string.Equals(PersonType.Director, p.Type, StringComparison.OrdinalIgnoreCase)).Take(2)) + var people = _libraryManager.GetPeople(new InternalPeopleQuery + { + ExcludePersonTypes = new List + { + PersonType.Director + }, + MaxListOrder = 3 + }); + + var itemIds = items.Select(i => i.Id).ToList(); + + return people + .Where(i => itemIds.Contains(i.ItemId)) .Select(i => i.Name) .DistinctNames(); } private IEnumerable GetDirectors(IEnumerable items) { - return items - .Select(i => _libraryManager.GetPeople(i).FirstOrDefault(p => string.Equals(PersonType.Director, p.Type, StringComparison.OrdinalIgnoreCase))) - .Where(i => i != null) + var people = _libraryManager.GetPeople(new InternalPeopleQuery + { + PersonTypes = new List + { + PersonType.Director + } + }); + + var itemIds = items.Select(i => i.Id).ToList(); + + return people + .Where(i => itemIds.Contains(i.ItemId)) .Select(i => i.Name) .DistinctNames(); } diff --git a/MediaBrowser.Api/Music/AlbumsService.cs b/MediaBrowser.Api/Music/AlbumsService.cs index 3dc459bd2..ea87c3ad3 100644 --- a/MediaBrowser.Api/Music/AlbumsService.cs +++ b/MediaBrowser.Api/Music/AlbumsService.cs @@ -6,6 +6,7 @@ using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using ServiceStack; using System; +using System.Collections.Generic; using System.Linq; namespace MediaBrowser.Api.Music @@ -68,12 +69,13 @@ namespace MediaBrowser.Api.Music /// Gets the album similarity score. /// /// The item1. + /// The item1 people. + /// All people. /// The item2. - /// The library manager. /// System.Int32. - private int GetAlbumSimilarityScore(BaseItem item1, BaseItem item2, ILibraryManager libraryManager) + private int GetAlbumSimilarityScore(BaseItem item1, List item1People, List allPeople, BaseItem item2) { - var points = SimilarItemsHelper.GetSimiliarityScore(item1, item2, libraryManager); + var points = SimilarItemsHelper.GetSimiliarityScore(item1, item1People, allPeople, item2); var album1 = (MusicAlbum)item1; var album2 = (MusicAlbum)item2; diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 41d785a34..dc5858e86 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -632,7 +632,7 @@ namespace MediaBrowser.Api.Playback { var maxHeightParam = request.MaxHeight.Value.ToString(UsCulture); - filters.Add(string.Format("scale=trunc(oh*a*2)/2:min(ih\\,{0})", maxHeightParam)); + filters.Add(string.Format("scale=trunc(oh*a/2)*2:min(ih\\,{0})", maxHeightParam)); } if (string.Equals(outputVideoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase)) diff --git a/MediaBrowser.Api/SimilarItemsHelper.cs b/MediaBrowser.Api/SimilarItemsHelper.cs index 1e9b365db..d114446ee 100644 --- a/MediaBrowser.Api/SimilarItemsHelper.cs +++ b/MediaBrowser.Api/SimilarItemsHelper.cs @@ -68,7 +68,7 @@ namespace MediaBrowser.Api /// The include in search. /// The get similarity score. /// ItemsResult. - internal static ItemsResult GetSimilarItemsResult(DtoOptions dtoOptions, IUserManager userManager, IItemRepository itemRepository, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, ILogger logger, BaseGetSimilarItemsFromItem request, Func includeInSearch, Func getSimilarityScore) + internal static ItemsResult GetSimilarItemsResult(DtoOptions dtoOptions, IUserManager userManager, IItemRepository itemRepository, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, ILogger logger, BaseGetSimilarItemsFromItem request, Func includeInSearch, Func, List, BaseItem, int> getSimilarityScore) { var user = !string.IsNullOrWhiteSpace(request.UserId) ? userManager.GetUserById(request.UserId) : null; @@ -110,12 +110,17 @@ namespace MediaBrowser.Api /// The input items. /// The get similarity score. /// IEnumerable{BaseItem}. - internal static IEnumerable GetSimilaritems(BaseItem item, ILibraryManager libraryManager, IEnumerable inputItems, Func getSimilarityScore) + internal static IEnumerable GetSimilaritems(BaseItem item, ILibraryManager libraryManager, IEnumerable inputItems, Func, List, BaseItem, int> getSimilarityScore) { var itemId = item.Id; inputItems = inputItems.Where(i => i.Id != itemId); + var itemPeople = libraryManager.GetPeople(item); + var allPeople = libraryManager.GetPeople(new InternalPeopleQuery + { + AppearsInItemId = item.Id + }); - return inputItems.Select(i => new Tuple(i, getSimilarityScore(item, i, libraryManager))) + return inputItems.Select(i => new Tuple(i, getSimilarityScore(item, itemPeople, allPeople, i))) .Where(i => i.Item2 > 2) .OrderByDescending(i => i.Item2) .Select(i => i.Item1); @@ -147,9 +152,11 @@ namespace MediaBrowser.Api /// Gets the similiarity score. /// /// The item1. + /// The item1 people. + /// All people. /// The item2. /// System.Int32. - internal static int GetSimiliarityScore(BaseItem item1, BaseItem item2, ILibraryManager libraryManager) + internal static int GetSimiliarityScore(BaseItem item1, List item1People, List allPeople, BaseItem item2) { var points = 0; @@ -170,11 +177,13 @@ namespace MediaBrowser.Api // Find common studios points += item1.Studios.Where(i => item2.Studios.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 3); - var item2PeopleNames = libraryManager.GetPeople(item2).Select(i => i.Name) + var item2PeopleNames = allPeople.Where(i => i.ItemId == item2.Id) + .Select(i => i.Name) + .Where(i => !string.IsNullOrWhiteSpace(i)) .DistinctNames() .ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); - points += libraryManager.GetPeople(item1).Where(i => item2PeopleNames.ContainsKey(i.Name)).Sum(i => + points += item1People.Where(i => item2PeopleNames.ContainsKey(i.Name)).Sum(i => { if (string.Equals(i.Type, PersonType.Director, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase)) { diff --git a/MediaBrowser.Api/UserLibrary/PersonsService.cs b/MediaBrowser.Api/UserLibrary/PersonsService.cs index f95beb27e..bd9898dcd 100644 --- a/MediaBrowser.Api/UserLibrary/PersonsService.cs +++ b/MediaBrowser.Api/UserLibrary/PersonsService.cs @@ -5,7 +5,6 @@ using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using ServiceStack; -using System; using System.Collections.Generic; using System.Linq; @@ -151,18 +150,16 @@ namespace MediaBrowser.Api.UserLibrary /// The items list. /// The person types. /// IEnumerable{PersonInfo}. - private IEnumerable GetAllPeople(IEnumerable itemsList, string[] personTypes) + private IEnumerable GetAllPeople(IEnumerable itemsList, IEnumerable personTypes) { - var people = itemsList.SelectMany(i => LibraryManager.GetPeople(i).OrderBy(p => p.SortOrder ?? int.MaxValue).ThenBy(p => p.Type)); + var allIds = itemsList.Select(i => i.Id).ToList(); - if (personTypes.Length > 0) + var allPeople = LibraryManager.GetPeople(new InternalPeopleQuery { - people = people.Where(p => - personTypes.Contains(p.Type ?? string.Empty, StringComparer.OrdinalIgnoreCase) || - personTypes.Contains(p.Role ?? string.Empty, StringComparer.OrdinalIgnoreCase)); - } + PersonTypes = personTypes.ToList() + }); - return people; + return allPeople.Where(i => allIds.Contains(i.ItemId)).OrderBy(p => p.SortOrder ?? int.MaxValue).ThenBy(p => p.Type); } } } diff --git a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs index 77d9f80f9..698792802 100644 --- a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs +++ b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs @@ -85,6 +85,13 @@ namespace MediaBrowser.Common.Implementations.Logging { rule.EnableLoggingForLevel(level); } + foreach (var lev in rule.Levels.ToArray()) + { + if (lev < level) + { + rule.DisableLoggingForLevel(lev); + } + } } } diff --git a/MediaBrowser.Controller/Entities/IItemByName.cs b/MediaBrowser.Controller/Entities/IItemByName.cs index 14b69b8fd..e6667290c 100644 --- a/MediaBrowser.Controller/Entities/IItemByName.cs +++ b/MediaBrowser.Controller/Entities/IItemByName.cs @@ -6,7 +6,7 @@ namespace MediaBrowser.Controller.Entities /// /// Marker interface /// - public interface IItemByName + public interface IItemByName : IHasMetadata { /// /// Gets the tagged items. diff --git a/MediaBrowser.Controller/Entities/InternalPeopleQuery.cs b/MediaBrowser.Controller/Entities/InternalPeopleQuery.cs new file mode 100644 index 000000000..622dffe65 --- /dev/null +++ b/MediaBrowser.Controller/Entities/InternalPeopleQuery.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; + +namespace MediaBrowser.Controller.Entities +{ + public class InternalPeopleQuery + { + public Guid ItemId { get; set; } + public List PersonTypes { get; set; } + public List ExcludePersonTypes { get; set; } + public int? MaxListOrder { get; set; } + public Guid AppearsInItemId { get; set; } + + public InternalPeopleQuery() + { + PersonTypes = new List(); + ExcludePersonTypes = new List(); + } + } +} diff --git a/MediaBrowser.Controller/Entities/Person.cs b/MediaBrowser.Controller/Entities/Person.cs index 535574ad9..0a62655ee 100644 --- a/MediaBrowser.Controller/Entities/Person.cs +++ b/MediaBrowser.Controller/Entities/Person.cs @@ -99,6 +99,8 @@ namespace MediaBrowser.Controller.Entities /// public class PersonInfo { + public Guid ItemId { get; set; } + /// /// Gets or sets the name. /// diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 7bbe5c39c..62c71d169 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -1698,7 +1698,7 @@ namespace MediaBrowser.Controller.Entities .Select(libraryManager.GetItemById) .Select(i => i == null ? "-1" : i.Name) .ToList(); - + if (!(names.Any(v => libraryManager.GetPeople(item).Select(i => i.Name).Contains(v, StringComparer.OrdinalIgnoreCase)))) { return false; diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 58c696d55..f0bfaaf66 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -420,12 +420,19 @@ namespace MediaBrowser.Controller.Library /// List<PersonInfo>. List GetPeople(BaseItem item); + /// + /// Gets the people. + /// + /// The query. + /// List<PersonInfo>. + List GetPeople(InternalPeopleQuery query); + /// /// Gets the people items. /// - /// The item. + /// The query. /// List<Person>. - List GetPeopleItems(BaseItem item); + List GetPeopleItems(InternalPeopleQuery query); /// /// Gets all people names. @@ -447,5 +454,12 @@ namespace MediaBrowser.Controller.Library /// The query. /// List<Guid>. List GetItemIds(InternalItemsQuery query); + + /// + /// Gets the people names. + /// + /// The query. + /// List<System.String>. + List GetPeopleNames(InternalPeopleQuery query); } } \ No newline at end of file diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index fcb938acc..fcde6d8c0 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -166,6 +166,7 @@ + diff --git a/MediaBrowser.Controller/Persistence/IItemRepository.cs b/MediaBrowser.Controller/Persistence/IItemRepository.cs index a91a7d3ac..a4b9bf120 100644 --- a/MediaBrowser.Controller/Persistence/IItemRepository.cs +++ b/MediaBrowser.Controller/Persistence/IItemRepository.cs @@ -151,9 +151,9 @@ namespace MediaBrowser.Controller.Persistence /// /// Gets the people. /// - /// The item identifier. + /// The query. /// List<PersonInfo>. - List GetPeople(Guid itemId); + List GetPeople(InternalPeopleQuery query); /// /// Updates the people. @@ -166,9 +166,9 @@ namespace MediaBrowser.Controller.Persistence /// /// Gets the people names. /// - /// The item identifier. + /// The query. /// List<System.String>. - List GetPeopleNames(Guid itemId); + List GetPeopleNames(InternalPeopleQuery query); } } diff --git a/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs b/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs index 46c0f48e2..72040c8ae 100644 --- a/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs +++ b/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs @@ -410,7 +410,11 @@ namespace MediaBrowser.Dlna.ContentDirectory { if (stubType.Value == StubType.People) { - var items = _libraryManager.GetPeopleItems(item).ToArray(); + var items = _libraryManager.GetPeopleItems(new InternalPeopleQuery + { + ItemId = item.Id + + }).ToArray(); var result = new QueryResult { @@ -432,7 +436,7 @@ namespace MediaBrowser.Dlna.ContentDirectory var person = item as Person; if (person != null) { - return await GetItemsFromPerson(person, user, startIndex, limit).ConfigureAwait(false); + return GetItemsFromPerson(person, user, startIndex, limit); } return ApplyPaging(new QueryResult(), startIndex, limit); @@ -475,38 +479,19 @@ namespace MediaBrowser.Dlna.ContentDirectory }; } - private async Task> GetItemsFromPerson(Person person, User user, int? startIndex, int? limit) + private QueryResult GetItemsFromPerson(Person person, User user, int? startIndex, int? limit) { - var items = user.RootFolder.GetRecursiveChildren(user, i => i is Movie || i is Series && PeopleHelper.ContainsPerson(_libraryManager.GetPeople(i), person.Name)) - .ToList(); - - var trailerResult = await _channelManager.GetAllMediaInternal(new AllChannelMediaQuery + var itemsWithPerson = _libraryManager.GetItems(new InternalItemsQuery { - ContentTypes = new[] { ChannelMediaContentType.MovieExtra }, - ExtraTypes = new[] { ExtraType.Trailer }, - UserId = user.Id.ToString("N") + Person = person.Name - }, CancellationToken.None).ConfigureAwait(false); + }).Items; - var currentIds = items.Select(i => i.GetProviderId(MetadataProviders.Imdb)) + var items = itemsWithPerson + .Where(i => i is Movie || i is Series || i is IChannelItem) + .Where(i => i.IsVisibleStandalone(user)) .ToList(); - var trailersToAdd = trailerResult.Items - .Where(i => PeopleHelper.ContainsPerson(_libraryManager.GetPeople(i), person.Name)) - .Where(i => - { - // Try to filter out dupes using imdb id - var imdb = i.GetProviderId(MetadataProviders.Imdb); - if (!string.IsNullOrWhiteSpace(imdb) && - currentIds.Contains(imdb, StringComparer.OrdinalIgnoreCase)) - { - return false; - } - return true; - }); - - items.AddRange(trailersToAdd); - items = _libraryManager.Sort(items, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending) .Skip(startIndex ?? 0) .Take(limit ?? int.MaxValue) @@ -558,7 +543,11 @@ namespace MediaBrowser.Dlna.ContentDirectory private bool EnablePeopleDisplay(BaseItem item) { - if (_libraryManager.GetPeople(item).Count > 0) + if (_libraryManager.GetPeopleNames(new InternalPeopleQuery + { + ItemId = item.Id + + }).Count > 0) { return item is Movie; } diff --git a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs index 16b4e418e..97c5aecd0 100644 --- a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs @@ -834,7 +834,7 @@ namespace MediaBrowser.MediaEncoding.Encoder { var heightParam = request.Height.Value.ToString(UsCulture); - filters.Add(string.Format("scale=trunc(oh*a*2)/2:{0}", heightParam)); + filters.Add(string.Format("scale=trunc(oh*a/2)*2:{0}", heightParam)); } // If a max width was requested @@ -850,7 +850,7 @@ namespace MediaBrowser.MediaEncoding.Encoder { var maxHeightParam = request.MaxHeight.Value.ToString(UsCulture); - filters.Add(string.Format("scale=trunc(oh*a*2)/2:min(ih\\,{0})", maxHeightParam)); + filters.Add(string.Format("scale=trunc(oh*a/2)*2:min(ih\\,{0})", maxHeightParam)); } var output = string.Empty; diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index d147777bd..bdc758d8e 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -132,13 +132,7 @@ namespace MediaBrowser.Server.Implementations.Dto { if (options.Fields.Contains(ItemFields.ItemCounts)) { - var itemFilter = byName.GetItemFilter(); - - var libraryItems = user != null ? - user.RootFolder.GetRecursiveChildren(user, itemFilter) : - _libraryManager.RootFolder.GetRecursiveChildren(itemFilter); - - SetItemByNameInfo(item, dto, libraryItems.ToList(), user); + SetItemByNameInfo(item, dto, GetTaggedItems(byName, user), user); } FillSyncInfo(dto, item, options, user, syncProgress); @@ -150,6 +144,33 @@ namespace MediaBrowser.Server.Implementations.Dto return dto; } + private List GetTaggedItems(IItemByName byName, User user) + { + var person = byName as Person; + + if (person != null) + { + var items = _libraryManager.GetItems(new InternalItemsQuery + { + Person = byName.Name + + }).Items; + + if (user != null) + { + return items.Where(i => i.IsVisibleStandalone(user)).ToList(); + } + + return items.ToList(); + } + + var itemFilter = byName.GetItemFilter(); + + return user != null ? + user.RootFolder.GetRecursiveChildren(user, itemFilter).ToList() : + _libraryManager.RootFolder.GetRecursiveChildren(itemFilter).ToList(); + } + private SyncedItemProgress[] GetSyncedItemProgress(DtoOptions options) { if (!options.Fields.Contains(ItemFields.SyncInfo)) diff --git a/MediaBrowser.Server.Implementations/HttpServer/LoggerUtils.cs b/MediaBrowser.Server.Implementations/HttpServer/LoggerUtils.cs index 955c4ed2d..5558c24d7 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/LoggerUtils.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/LoggerUtils.cs @@ -1,6 +1,6 @@ using MediaBrowser.Model.Logging; using System; -using System.Net; +using System.Globalization; using System.Text; namespace MediaBrowser.Server.Implementations.HttpServer @@ -23,7 +23,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer //log.AppendLine("Headers: " + string.Join(",", response.Headers.AllKeys.Select(k => k + "=" + response.Headers[k]))); - var responseTime = string.Format(". Response time: {0} ms.", duration.TotalMilliseconds); + var responseTime = string.Format(". Response time: {0} ms.", duration.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); var msg = "HTTP Response " + statusCode + " to " + endPoint + responseTime; diff --git a/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs b/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs index f19668d5d..db9841f9d 100644 --- a/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs +++ b/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs @@ -71,6 +71,12 @@ namespace MediaBrowser.Server.Implementations.Intros var candidates = new List(); + var itemPeople = _libraryManager.GetPeople(item); + var allPeople = _libraryManager.GetPeople(new InternalPeopleQuery + { + AppearsInItemId = item.Id + }); + if (config.EnableIntrosFromMoviesInLibrary) { var itemsWithTrailers = user.RootFolder @@ -94,6 +100,8 @@ namespace MediaBrowser.Server.Implementations.Intros Type = ItemWithTrailerType.ItemWithTrailer, User = user, WatchingItem = item, + WatchingItemPeople = itemPeople, + AllPeople = allPeople, Random = random, LibraryManager = _libraryManager })); @@ -135,6 +143,8 @@ namespace MediaBrowser.Server.Implementations.Intros Type = ItemWithTrailerType.ChannelTrailer, User = user, WatchingItem = item, + WatchingItemPeople = itemPeople, + AllPeople = allPeople, Random = random, LibraryManager = _libraryManager })); @@ -241,7 +251,7 @@ namespace MediaBrowser.Server.Implementations.Intros return true; } - internal static int GetSimiliarityScore(BaseItem item1, BaseItem item2, Random random, ILibraryManager libraryManager) + internal static int GetSimiliarityScore(BaseItem item1, List item1People, List allPeople, BaseItem item2, Random random, ILibraryManager libraryManager) { var points = 0; @@ -262,11 +272,13 @@ namespace MediaBrowser.Server.Implementations.Intros // Find common studios points += item1.Studios.Where(i => item2.Studios.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 5); - var item2PeopleNames = libraryManager.GetPeople(item2).Select(i => i.Name) - .Distinct(StringComparer.OrdinalIgnoreCase) + var item2PeopleNames = allPeople.Where(i => i.ItemId == item2.Id) + .Select(i => i.Name) + .Where(i => !string.IsNullOrWhiteSpace(i)) + .DistinctNames() .ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); - points += libraryManager.GetPeople(item1).Where(i => item2PeopleNames.ContainsKey(i.Name)).Sum(i => + points += item1People.Where(i => item2PeopleNames.ContainsKey(i.Name)).Sum(i => { if (string.Equals(i.Type, PersonType.Director, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase)) { @@ -341,6 +353,8 @@ namespace MediaBrowser.Server.Implementations.Intros internal ItemWithTrailerType Type; internal User User; internal BaseItem WatchingItem; + internal List WatchingItemPeople; + internal List AllPeople; internal Random Random; internal ILibraryManager LibraryManager; @@ -364,7 +378,7 @@ namespace MediaBrowser.Server.Implementations.Intros { if (!_score.HasValue) { - _score = GetSimiliarityScore(WatchingItem, Item, Random, LibraryManager); + _score = GetSimiliarityScore(WatchingItem, WatchingItemPeople, AllPeople, Item, Random, LibraryManager); } return _score.Value; } diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index a4be54f27..995a7fabd 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -2062,14 +2062,22 @@ namespace MediaBrowser.Server.Implementations.Library } } - public List GetPeople(BaseItem item) + public List GetPeople(InternalPeopleQuery query) { - return item.People ?? ItemRepository.GetPeople(item.Id); + return ItemRepository.GetPeople(query); } - public List GetPeopleItems(BaseItem item) + public List GetPeople(BaseItem item) { - return ItemRepository.GetPeopleNames(item.Id).Select(i => + return item.People ?? GetPeople(new InternalPeopleQuery + { + ItemId = item.Id + }); + } + + public List GetPeopleItems(InternalPeopleQuery query) + { + return ItemRepository.GetPeopleNames(query).Select(i => { try { @@ -2084,11 +2092,14 @@ namespace MediaBrowser.Server.Implementations.Library }).Where(i => i != null).ToList(); } + public List GetPeopleNames(InternalPeopleQuery query) + { + return ItemRepository.GetPeopleNames(query); + } + public List GetAllPeople() { - return RootFolder.GetRecursiveChildren() - .SelectMany(GetPeople) - .Where(i => !string.IsNullOrWhiteSpace(i.Name)) + return GetPeople(new InternalPeopleQuery()) .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) .ToList(); } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index a247bbbe3..cc4b7f074 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -135,8 +135,8 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.RunQueries(queries, _logger); - _connection.AddColumn(_logger, "TypedBaseItems", "Path", "Text"); - _connection.AddColumn(_logger, "TypedBaseItems", "StartDate", "DATETIME"); + _connection.AddColumn(_logger, "TypedBaseItems", "Path", "Text"); + _connection.AddColumn(_logger, "TypedBaseItems", "StartDate", "DATETIME"); _connection.AddColumn(_logger, "TypedBaseItems", "EndDate", "DATETIME"); _connection.AddColumn(_logger, "TypedBaseItems", "ChannelId", "Text"); _connection.AddColumn(_logger, "TypedBaseItems", "IsMovie", "BIT"); @@ -286,9 +286,9 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = item.GetType().FullName; _saveItemCommand.GetParameter(index++).Value = _jsonSerializer.SerializeToBytes(item); - _saveItemCommand.GetParameter(index++).Value = item.Path; + _saveItemCommand.GetParameter(index++).Value = item.Path; - var hasStartDate = item as IHasStartDate; + var hasStartDate = item as IHasStartDate; if (hasStartDate != null) { _saveItemCommand.GetParameter(index++).Value = hasStartDate.StartDate; @@ -329,7 +329,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = item.ParentIndexNumber; _saveItemCommand.GetParameter(index++).Value = item.PremiereDate; _saveItemCommand.GetParameter(index++).Value = item.ProductionYear; - + _saveItemCommand.Transaction = transaction; _saveItemCommand.ExecuteNonQuery(); @@ -1009,7 +1009,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _deletePeopleCommand.GetParameter(0).Value = id; _deletePeopleCommand.Transaction = transaction; _deletePeopleCommand.ExecuteNonQuery(); - + // Delete the item _deleteItemCommand.GetParameter(0).Value = id; _deleteItemCommand.Transaction = transaction; @@ -1133,20 +1133,27 @@ namespace MediaBrowser.Server.Implementations.Persistence return _mediaStreamsRepository.SaveMediaStreams(id, streams, cancellationToken); } - public List GetPeopleNames(Guid itemId) + public List GetPeopleNames(InternalPeopleQuery query) { - if (itemId == Guid.Empty) + if (query == null) { - throw new ArgumentNullException("itemId"); + throw new ArgumentNullException("query"); } CheckDisposed(); using (var cmd = _connection.CreateCommand()) { - cmd.CommandText = "select Distinct Name from People where ItemId=@ItemId order by ListOrder"; + cmd.CommandText = "select Distinct Name from People"; - cmd.Parameters.Add(cmd, "@ItemId", DbType.Guid).Value = itemId; + var whereClauses = GetPeopleWhereClauses(query, cmd); + + if (whereClauses.Count > 0) + { + cmd.CommandText += " where " + string.Join(" AND ", whereClauses.ToArray()); + } + + cmd.CommandText += " order by ListOrder"; var list = new List(); @@ -1162,20 +1169,27 @@ namespace MediaBrowser.Server.Implementations.Persistence } } - public List GetPeople(Guid itemId) + public List GetPeople(InternalPeopleQuery query) { - if (itemId == Guid.Empty) + if (query == null) { - throw new ArgumentNullException("itemId"); + throw new ArgumentNullException("query"); } CheckDisposed(); using (var cmd = _connection.CreateCommand()) { - cmd.CommandText = "select ItemId, Name, Role, PersonType, SortOrder from People where ItemId=@ItemId order by ListOrder"; + cmd.CommandText = "select ItemId, Name, Role, PersonType, SortOrder from People"; - cmd.Parameters.Add(cmd, "@ItemId", DbType.Guid).Value = itemId; + var whereClauses = GetPeopleWhereClauses(query, cmd); + + if (whereClauses.Count > 0) + { + cmd.CommandText += " where " + string.Join(" AND ", whereClauses.ToArray()); + } + + cmd.CommandText += " order by ListOrder"; var list = new List(); @@ -1191,6 +1205,51 @@ namespace MediaBrowser.Server.Implementations.Persistence } } + private List GetPeopleWhereClauses(InternalPeopleQuery query, IDbCommand cmd) + { + var whereClauses = new List(); + + if (query.ItemId != Guid.Empty) + { + whereClauses.Add("ItemId=@ItemId"); + cmd.Parameters.Add(cmd, "@ItemId", DbType.Guid).Value = query.ItemId; + } + if (query.AppearsInItemId != Guid.Empty) + { + whereClauses.Add("Name in (Select Name from People where ItemId=@AppearsInItemId)"); + cmd.Parameters.Add(cmd, "@AppearsInItemId", DbType.Guid).Value = query.AppearsInItemId; + } + if (query.PersonTypes.Count == 1) + { + whereClauses.Add("PersonType=@PersonType"); + cmd.Parameters.Add(cmd, "@PersonType", DbType.String).Value = query.PersonTypes[0]; + } + if (query.PersonTypes.Count > 1) + { + var val = string.Join(",", query.PersonTypes.Select(i => "'" + i + "'").ToArray()); + + whereClauses.Add("PersonType in (" + val + ")"); + } + if (query.ExcludePersonTypes.Count == 1) + { + whereClauses.Add("PersonType<>@PersonType"); + cmd.Parameters.Add(cmd, "@PersonType", DbType.String).Value = query.ExcludePersonTypes[0]; + } + if (query.ExcludePersonTypes.Count > 1) + { + var val = string.Join(",", query.ExcludePersonTypes.Select(i => "'" + i + "'").ToArray()); + + whereClauses.Add("PersonType not in (" + val + ")"); + } + if (query.MaxListOrder.HasValue) + { + whereClauses.Add("ListOrder<=@MaxListOrder"); + cmd.Parameters.Add(cmd, "@MaxListOrder", DbType.Int32).Value = query.MaxListOrder.Value; + } + + return whereClauses; + } + public async Task UpdatePeople(Guid itemId, List people) { if (itemId == Guid.Empty) @@ -1277,6 +1336,7 @@ namespace MediaBrowser.Server.Implementations.Persistence { var item = new PersonInfo(); + item.ItemId = reader.GetGuid(0); item.Name = reader.GetString(1); if (!reader.IsDBNull(2)) diff --git a/MediaBrowser.WebDashboard/Api/PackageCreator.cs b/MediaBrowser.WebDashboard/Api/PackageCreator.cs index 0cd22baa9..c50f98c33 100644 --- a/MediaBrowser.WebDashboard/Api/PackageCreator.cs +++ b/MediaBrowser.WebDashboard/Api/PackageCreator.cs @@ -124,6 +124,15 @@ namespace MediaBrowser.WebDashboard.Api var fullPath = Path.Combine(rootPath, virtualPath.Replace('/', Path.DirectorySeparatorChar)); + try + { + fullPath = Path.GetFullPath(fullPath); + } + catch (Exception ex) + { + _logger.ErrorException("Error in Path.GetFullPath", ex); + } + // Don't allow file system access outside of the source folder if (!_fileSystem.ContainsSubPath(rootPath, fullPath)) { @@ -654,7 +663,7 @@ namespace MediaBrowser.WebDashboard.Api await AppendResource(memoryStream, "thirdparty/jquerymobile-1.4.5/jquery.mobile.custom.theme.min.css", newLineBytes).ConfigureAwait(false); await AppendResource(memoryStream, "thirdparty/jquerymobile-1.4.5/jquery.mobile.custom.structure.min.css", newLineBytes).ConfigureAwait(false); - + var files = new[] { "css/site.css", diff --git a/SharedVersion.cs b/SharedVersion.cs index 092708e9d..e35ca61dd 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,4 +1,4 @@ using System.Reflection; -[assembly: AssemblyVersion("3.0.*")] -//[assembly: AssemblyVersion("3.0.5666.0")] +//[assembly: AssemblyVersion("3.0.*")] +[assembly: AssemblyVersion("3.0.5666.2")]