From bce86c502206b016cc448afc1934101b852a1994 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 19 Nov 2013 22:15:48 -0500 Subject: [PATCH] pull person sort order from tvdb/tmdb data --- MediaBrowser.Api/ItemUpdateService.cs | 7 +++++- MediaBrowser.Api/LibraryService.cs | 23 ++++++++++++------- .../UserLibrary/PersonsService.cs | 2 +- MediaBrowser.Controller/Entities/BaseItem.cs | 21 +++++++++++++---- .../Entities/IHasAspectRatio.cs | 14 +++++++++++ MediaBrowser.Controller/Entities/Person.cs | 6 +++++ MediaBrowser.Controller/Entities/Video.cs | 8 ++++++- .../LiveTv/ILiveTvService.cs | 11 ++++++++- .../MediaBrowser.Controller.csproj | 1 + .../Providers/BaseItemXmlParser.cs | 5 ++-- .../Movies/MovieDbProvider.cs | 2 +- .../Savers/XmlSaverHelpers.cs | 8 +++++-- .../TV/TvdbSeriesProvider.cs | 17 ++++++++++++++ .../Dto/DtoService.cs | 8 +++++-- 14 files changed, 109 insertions(+), 24 deletions(-) create mode 100644 MediaBrowser.Controller/Entities/IHasAspectRatio.cs diff --git a/MediaBrowser.Api/ItemUpdateService.cs b/MediaBrowser.Api/ItemUpdateService.cs index 6e1dbc08b9..cfbaf70c90 100644 --- a/MediaBrowser.Api/ItemUpdateService.cs +++ b/MediaBrowser.Api/ItemUpdateService.cs @@ -247,11 +247,16 @@ namespace MediaBrowser.Api item.PremiereDate = request.PremiereDate.HasValue ? request.PremiereDate.Value.ToUniversalTime() : (DateTime?)null; item.ProductionYear = request.ProductionYear; item.ProductionLocations = request.ProductionLocations; - item.AspectRatio = request.AspectRatio; item.Language = request.Language; item.OfficialRating = request.OfficialRating; item.CustomRating = request.CustomRating; + var hasAspectRatio = item as IHasAspectRatio; + if (hasAspectRatio != null) + { + hasAspectRatio.AspectRatio = request.AspectRatio; + } + item.DontFetchMeta = !(request.EnableInternetProviders ?? true); if (request.EnableInternetProviders ?? true) { diff --git a/MediaBrowser.Api/LibraryService.cs b/MediaBrowser.Api/LibraryService.cs index 582eb6f497..06b90b32cb 100644 --- a/MediaBrowser.Api/LibraryService.cs +++ b/MediaBrowser.Api/LibraryService.cs @@ -681,6 +681,11 @@ namespace MediaBrowser.Api { var album = originalItem as MusicAlbum; + if (album == null) + { + album = originalItem.Parents.OfType().FirstOrDefault(); + } + if (album != null) { var linkedItemWithThemes = album.SoundtrackIds @@ -744,17 +749,12 @@ namespace MediaBrowser.Api : (Folder)_libraryManager.RootFolder) : _dtoService.GetItemByDtoId(id, userId); - while (GetSoundtrackSongIds(item).Count == 0 && inheritFromParent && item.Parent != null) - { - item = item.Parent; - } - // Get everything var fields = Enum.GetNames(typeof(ItemFields)) .Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)) .ToList(); - var dtos = GetSoundtrackSongIds(item) + var dtos = GetSoundtrackSongIds(item, inheritFromParent) .Select(_libraryManager.GetItemById) .OfType() .SelectMany(i => i.RecursiveChildren) @@ -772,7 +772,7 @@ namespace MediaBrowser.Api }; } - private List GetSoundtrackSongIds(BaseItem item) + private IEnumerable GetSoundtrackSongIds(BaseItem item, bool inherit) { var hasSoundtracks = item as IHasSoundtracks; @@ -781,7 +781,14 @@ namespace MediaBrowser.Api return hasSoundtracks.SoundtrackIds; } - return new List(); + if (!inherit) + { + return null; + } + + hasSoundtracks = item.Parents.OfType().FirstOrDefault(); + + return hasSoundtracks != null ? hasSoundtracks.SoundtrackIds : new List(); } } } diff --git a/MediaBrowser.Api/UserLibrary/PersonsService.cs b/MediaBrowser.Api/UserLibrary/PersonsService.cs index 885a4a3e67..09b5ef09fe 100644 --- a/MediaBrowser.Api/UserLibrary/PersonsService.cs +++ b/MediaBrowser.Api/UserLibrary/PersonsService.cs @@ -155,7 +155,7 @@ namespace MediaBrowser.Api.UserLibrary /// IEnumerable{PersonInfo}. private IEnumerable GetAllPeople(IEnumerable itemsList, string[] personTypes) { - var people = itemsList.SelectMany(i => i.People.OrderBy(p => p.Type)); + var people = itemsList.SelectMany(i => i.People.OrderBy(p => p.SortOrder ?? int.MaxValue).ThenBy(p => p.Type)); return personTypes.Length == 0 ? diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index a6178536c6..6b6719f013 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -483,6 +483,22 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public Folder Parent { get; set; } + [IgnoreDataMember] + public IEnumerable Parents + { + get + { + var parent = Parent; + + while (parent != null) + { + yield return parent; + + parent = parent.Parent; + } + } + } + /// /// When the item first debuted. For movies this could be premiere date, episodes would be first aired /// @@ -630,11 +646,6 @@ namespace MediaBrowser.Controller.Entities /// The original run time ticks. public long? OriginalRunTimeTicks { get; set; } /// - /// Gets or sets the aspect ratio. - /// - /// The aspect ratio. - public string AspectRatio { get; set; } - /// /// Gets or sets the production year. /// /// The production year. diff --git a/MediaBrowser.Controller/Entities/IHasAspectRatio.cs b/MediaBrowser.Controller/Entities/IHasAspectRatio.cs new file mode 100644 index 0000000000..5aecf4eac1 --- /dev/null +++ b/MediaBrowser.Controller/Entities/IHasAspectRatio.cs @@ -0,0 +1,14 @@ +namespace MediaBrowser.Controller.Entities +{ + /// + /// Interface IHasAspectRatio + /// + public interface IHasAspectRatio + { + /// + /// Gets or sets the aspect ratio. + /// + /// The aspect ratio. + string AspectRatio { get; set; } + } +} diff --git a/MediaBrowser.Controller/Entities/Person.cs b/MediaBrowser.Controller/Entities/Person.cs index e5cf48ad08..17b9d77413 100644 --- a/MediaBrowser.Controller/Entities/Person.cs +++ b/MediaBrowser.Controller/Entities/Person.cs @@ -49,6 +49,12 @@ namespace MediaBrowser.Controller.Entities /// The type. public string Type { get; set; } + /// + /// Gets or sets the sort order - ascending + /// + /// The sort order. + public int? SortOrder { get; set; } + /// /// Returns a that represents this instance. /// diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index e900dd77e9..6a27ed6906 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -14,7 +14,7 @@ namespace MediaBrowser.Controller.Entities /// /// Class Video /// - public class Video : BaseItem, IHasMediaStreams + public class Video : BaseItem, IHasMediaStreams, IHasAspectRatio { public bool IsMultiPart { get; set; } @@ -65,6 +65,12 @@ namespace MediaBrowser.Controller.Entities return GetPlayableStreamFiles(Path); } + /// + /// Gets or sets the aspect ratio. + /// + /// The aspect ratio. + public string AspectRatio { get; set; } + /// /// Should be overridden to return the proper folder where metadata lives /// diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs index 5c019ae8c4..d39d98fa3c 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Model.LiveTv; +using System.IO; +using MediaBrowser.Model.LiveTv; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -23,6 +24,14 @@ namespace MediaBrowser.Controller.LiveTv /// Task{IEnumerable{ChannelInfo}}. Task> GetChannelsAsync(CancellationToken cancellationToken); + /// + /// Gets the channel image asynchronous. + /// + /// The channel identifier. + /// The cancellation token. + /// Task{Stream}. + Task GetChannelImageAsync(string channelId, CancellationToken cancellationToken); + /// /// Gets the recordings asynchronous. /// diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index f2837a1f1d..8837d04f5e 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -89,6 +89,7 @@ + diff --git a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs index 9fdbbf3b7e..d3fa7b09b1 100644 --- a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs +++ b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs @@ -375,9 +375,10 @@ namespace MediaBrowser.Controller.Providers { var val = reader.ReadElementContentAsString(); - if (!string.IsNullOrWhiteSpace(val)) + var hasAspectRatio = item as IHasAspectRatio; + if (!string.IsNullOrWhiteSpace(val) && hasAspectRatio != null) { - item.AspectRatio = val; + hasAspectRatio.AspectRatio = val; } break; } diff --git a/MediaBrowser.Providers/Movies/MovieDbProvider.cs b/MediaBrowser.Providers/Movies/MovieDbProvider.cs index cc6e07d622..f493353399 100644 --- a/MediaBrowser.Providers/Movies/MovieDbProvider.cs +++ b/MediaBrowser.Providers/Movies/MovieDbProvider.cs @@ -845,7 +845,7 @@ namespace MediaBrowser.Providers.Movies //actors come from cast if (movieData.casts != null && movieData.casts.cast != null) { - foreach (var actor in movieData.casts.cast.OrderBy(a => a.order)) movie.AddPerson(new PersonInfo { Name = actor.name.Trim(), Role = actor.character, Type = PersonType.Actor }); + foreach (var actor in movieData.casts.cast.OrderBy(a => a.order)) movie.AddPerson(new PersonInfo { Name = actor.name.Trim(), Role = actor.character, Type = PersonType.Actor, SortOrder = actor.order }); } //and the rest from crew diff --git a/MediaBrowser.Providers/Savers/XmlSaverHelpers.cs b/MediaBrowser.Providers/Savers/XmlSaverHelpers.cs index 69276e0b8e..7c8d0431b2 100644 --- a/MediaBrowser.Providers/Savers/XmlSaverHelpers.cs +++ b/MediaBrowser.Providers/Savers/XmlSaverHelpers.cs @@ -301,9 +301,13 @@ namespace MediaBrowser.Providers.Savers builder.Append("" + SecurityElement.Escape(item.HomePageUrl) + ""); } - if (!string.IsNullOrEmpty(item.AspectRatio)) + var hasAspectRatio = item as IHasAspectRatio; + if (hasAspectRatio != null) { - builder.Append("" + SecurityElement.Escape(item.AspectRatio) + ""); + if (!string.IsNullOrEmpty(hasAspectRatio.AspectRatio)) + { + builder.Append("" + SecurityElement.Escape(hasAspectRatio.AspectRatio) + ""); + } } if (!string.IsNullOrEmpty(item.Language)) diff --git a/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs b/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs index a22f4f1c32..29e191a594 100644 --- a/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs +++ b/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs @@ -1056,6 +1056,23 @@ namespace MediaBrowser.Providers.TV break; } + case "SortOrder": + { + var val = reader.ReadElementContentAsString(); + + if (!string.IsNullOrWhiteSpace(val)) + { + int rval; + + // int.TryParse is local aware, so it can be probamatic, force us culture + if (int.TryParse(val, NumberStyles.Integer, UsCulture, out rval)) + { + personInfo.SortOrder = rval; + } + } + break; + } + default: reader.Skip(); break; diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 1f0e7d1e1e..4efafcd772 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -433,7 +433,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.Type).ToList(); + var people = item.People.OrderBy(i => i.SortOrder ?? int.MaxValue).ThenBy(i => i.Type).ToList(); // Attach People by transforming them into BaseItemPerson (DTO) dto.People = new BaseItemPerson[people.Count]; @@ -760,7 +760,11 @@ namespace MediaBrowser.Server.Implementations.Dto dto.ProductionLocations = item.ProductionLocations; } - dto.AspectRatio = item.AspectRatio; + var hasAspectRatio = item as IHasAspectRatio; + if (hasAspectRatio != null) + { + dto.AspectRatio = hasAspectRatio.AspectRatio; + } dto.BackdropImageTags = GetBackdropImageTags(item);