diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations')
6 files changed, 53 insertions, 47 deletions
diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 68d9a5e9b..56ab97dbb 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -636,7 +636,7 @@ namespace MediaBrowser.Server.Implementations.Dto // Ordering by person type to ensure actors and artists are at the front. // This is taking advantage of the fact that they both begin with A // This should be improved in the future - var people = item.People.OrderBy(i => i.SortOrder ?? int.MaxValue) + var people = _libraryManager.GetPeople(item).OrderBy(i => i.SortOrder ?? int.MaxValue) .ThenBy(i => { if (i.IsType(PersonType.Actor)) diff --git a/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs b/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs index 2af6e5588..f19668d5d 100644 --- a/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs +++ b/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs @@ -94,7 +94,8 @@ namespace MediaBrowser.Server.Implementations.Intros Type = ItemWithTrailerType.ItemWithTrailer, User = user, WatchingItem = item, - Random = random + Random = random, + LibraryManager = _libraryManager })); } @@ -134,7 +135,8 @@ namespace MediaBrowser.Server.Implementations.Intros Type = ItemWithTrailerType.ChannelTrailer, User = user, WatchingItem = item, - Random = random + Random = random, + LibraryManager = _libraryManager })); } @@ -239,7 +241,7 @@ namespace MediaBrowser.Server.Implementations.Intros return true; } - internal static int GetSimiliarityScore(BaseItem item1, BaseItem item2, Random random) + internal static int GetSimiliarityScore(BaseItem item1, BaseItem item2, Random random, ILibraryManager libraryManager) { var points = 0; @@ -260,11 +262,11 @@ namespace MediaBrowser.Server.Implementations.Intros // Find common studios points += item1.Studios.Where(i => item2.Studios.Contains(i, StringComparer.OrdinalIgnoreCase)).Sum(i => 5); - var item2PeopleNames = item2.People.Select(i => i.Name) + var item2PeopleNames = libraryManager.GetPeople(item2).Select(i => i.Name) .Distinct(StringComparer.OrdinalIgnoreCase) .ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); - points += item1.People.Where(i => item2PeopleNames.ContainsKey(i.Name)).Sum(i => + points += libraryManager.GetPeople(item1).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)) { @@ -340,6 +342,7 @@ namespace MediaBrowser.Server.Implementations.Intros internal User User; internal BaseItem WatchingItem; internal Random Random; + internal ILibraryManager LibraryManager; private bool? _isPlayed; public bool IsPlayed @@ -361,7 +364,7 @@ namespace MediaBrowser.Server.Implementations.Intros { if (!_score.HasValue) { - _score = GetSimiliarityScore(WatchingItem, Item, Random); + _score = GetSimiliarityScore(WatchingItem, Item, Random, LibraryManager); } return _score.Value; } diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index ed5dde4c5..351703e0c 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -32,6 +32,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MoreLinq; using SortOrder = MediaBrowser.Model.Entities.SortOrder; namespace MediaBrowser.Server.Implementations.Library @@ -2055,5 +2056,26 @@ namespace MediaBrowser.Server.Implementations.Library item.ExtraType = ExtraType.Clip; } } + + + public List<PersonInfo> GetPeople(BaseItem item) + { + return item.People ?? new List<PersonInfo>(); + } + + public List<PersonInfo> GetAllPeople() + { + return RootFolder.GetRecursiveChildren() + .SelectMany(GetPeople) + .Where(i => !string.IsNullOrWhiteSpace(i.Name)) + .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) + .ToList(); + } + + public Task UpdatePeople(BaseItem item, List<PersonInfo> people) + { + item.People = people; + return item.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None); + } } } diff --git a/MediaBrowser.Server.Implementations/Library/SearchEngine.cs b/MediaBrowser.Server.Implementations/Library/SearchEngine.cs index 72bbefae4..0cfa524eb 100644 --- a/MediaBrowser.Server.Implementations/Library/SearchEngine.cs +++ b/MediaBrowser.Server.Implementations/Library/SearchEngine.cs @@ -257,7 +257,7 @@ namespace MediaBrowser.Server.Implementations.Library if (query.IncludePeople) { // Find persons - var persons = items.SelectMany(i => i.People) + var persons = items.SelectMany(i => _libraryManager.GetPeople(i)) .Select(i => i.Name) .Where(i => !string.IsNullOrWhiteSpace(i)) .Distinct(StringComparer.OrdinalIgnoreCase) diff --git a/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs index 059ad2481..ef9dee8b5 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/PeopleValidator.cs @@ -72,39 +72,6 @@ namespace MediaBrowser.Server.Implementations.Library.Validators return options.DownloadOtherPeopleMetadata; } - private IEnumerable<PersonInfo> GetPeopleToValidate(BaseItem item, PeopleMetadataOptions options) - { - return item.People.Where(i => - { - if (i.IsType(PersonType.Actor)) - { - return options.DownloadActorMetadata; - } - if (i.IsType(PersonType.Director)) - { - return options.DownloadDirectorMetadata; - } - if (i.IsType(PersonType.Composer)) - { - return options.DownloadComposerMetadata; - } - if (i.IsType(PersonType.Writer)) - { - return options.DownloadWriterMetadata; - } - if (i.IsType(PersonType.Producer)) - { - return options.DownloadProducerMetadata; - } - if (i.IsType(PersonType.GuestStar)) - { - return options.DownloadGuestStarMetadata; - } - - return options.DownloadOtherPeopleMetadata; - }); - } - /// <summary> /// Validates the people. /// </summary> @@ -119,10 +86,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators var peopleOptions = _config.Configuration.PeopleMetadataOptions; - var people = _libraryManager.RootFolder.GetRecursiveChildren() - .SelectMany(i => i.People) - .Where(i => !string.IsNullOrWhiteSpace(i.Name)) - .ToList(); + var people = _libraryManager.GetAllPeople(); var dict = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase); diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 2f01af79b..c02540a90 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -143,6 +143,12 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(_logger, "TypedBaseItems", "Name", "Text"); _connection.AddColumn(_logger, "TypedBaseItems", "OfficialRating", "Text"); + _connection.AddColumn(_logger, "TypedBaseItems", "MediaType", "Text"); + _connection.AddColumn(_logger, "TypedBaseItems", "Overview", "Text"); + _connection.AddColumn(_logger, "TypedBaseItems", "ParentIndexNumber", "INT"); + _connection.AddColumn(_logger, "TypedBaseItems", "PremiereDate", "DATETIME"); + _connection.AddColumn(_logger, "TypedBaseItems", "ProductionYear", "INT"); + PrepareStatements(); _mediaStreamsRepository.Initialize(); @@ -176,10 +182,15 @@ namespace MediaBrowser.Server.Implementations.Persistence "IndexNumber", "IsLocked", "Name", - "OfficialRating" + "OfficialRating", + "MediaType", + "Overview", + "ParentIndexNumber", + "PremiereDate", + "ProductionYear" }; _saveItemCommand = _connection.CreateCommand(); - _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (@1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16)"; + _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (@1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20, @21)"; for (var i = 1; i <= saveColumns.Count; i++) { _saveItemCommand.Parameters.Add(_saveItemCommand, "@" + i.ToString(CultureInfo.InvariantCulture)); @@ -293,6 +304,12 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = item.Name; _saveItemCommand.GetParameter(index++).Value = item.OfficialRating; + + _saveItemCommand.GetParameter(index++).Value = item.MediaType; + _saveItemCommand.GetParameter(index++).Value = item.Overview; + _saveItemCommand.GetParameter(index++).Value = item.ParentIndexNumber; + _saveItemCommand.GetParameter(index++).Value = item.PremiereDate; + _saveItemCommand.GetParameter(index++).Value = item.ProductionYear; _saveItemCommand.Transaction = transaction; |
