From dea10e5040e165444b7ab3990a92b62604025d3b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 18 Apr 2013 09:54:38 -0400 Subject: [PATCH] Capture revenue and add it as a sort order --- .../UserLibrary/BaseItemsRequest.cs | 2 +- MediaBrowser.Api/UserLibrary/ItemsService.cs | 2 +- MediaBrowser.Controller/Dto/DtoBuilder.cs | 5 ++++ MediaBrowser.Controller/Entities/BaseItem.cs | 6 ++++ .../Providers/Movies/MovieDbProvider.cs | 1 + MediaBrowser.Model/DTO/BaseItemDto.cs | 9 +++++- MediaBrowser.Model/Querying/ItemFields.cs | 5 ++++ MediaBrowser.Model/Querying/ItemSortBy.cs | 4 +++ ...MediaBrowser.Server.Implementations.csproj | 1 + .../Sorting/BudgetComparer.cs | 2 +- .../Sorting/RevenueComparer.cs | 29 +++++++++++++++++++ 11 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 MediaBrowser.Server.Implementations/Sorting/RevenueComparer.cs diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs index 46084ffeb..afe93a086 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs @@ -55,7 +55,7 @@ namespace MediaBrowser.Api.UserLibrary /// Fields to return within the items, in addition to basic information /// /// The fields. - [ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: AudioInfo, Budget, Chapters, DateCreated, DisplayMediaType, DisplayPreferences, EndDate, Genres, HomePageUrl, ItemCounts, IndexOptions, Locations, MediaStreams, Overview, OverviewHtml, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, SeriesInfo, SortName, Studios, Taglines, TrailerUrls, UserData", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] + [ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: AudioInfo, Budget, Chapters, DateCreated, DisplayMediaType, DisplayPreferences, EndDate, Genres, HomePageUrl, ItemCounts, IndexOptions, Locations, MediaStreams, Overview, OverviewHtml, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SeriesInfo, SortName, Studios, Taglines, TrailerUrls, UserData", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string Fields { get; set; } /// diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 3b8702e7d..79e00998f 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -32,7 +32,7 @@ namespace MediaBrowser.Api.UserLibrary /// What to sort the results by /// /// The sort by. - [ApiMember(Name = "SortBy", Description = "Optional. Specify one or more sort orders, comma delimeted. Options: Album, AlbumArtist, Artist, Budget, CommunityRating, DateCreated, DatePlayed, PlayCount, PremiereDate, ProductionYear, SortName, Random, Runtime", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] + [ApiMember(Name = "SortBy", Description = "Optional. Specify one or more sort orders, comma delimeted. Options: Album, AlbumArtist, Artist, Budget, CommunityRating, DateCreated, DatePlayed, PlayCount, PremiereDate, ProductionYear, SortName, Random, Revenue, Runtime", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string SortBy { get; set; } /// diff --git a/MediaBrowser.Controller/Dto/DtoBuilder.cs b/MediaBrowser.Controller/Dto/DtoBuilder.cs index 504b3d92a..9256acd6e 100644 --- a/MediaBrowser.Controller/Dto/DtoBuilder.cs +++ b/MediaBrowser.Controller/Dto/DtoBuilder.cs @@ -264,6 +264,11 @@ namespace MediaBrowser.Controller.Dto dto.Budget = item.Budget; } + if (fields.Contains(ItemFields.Revenue)) + { + dto.Revenue = item.Revenue; + } + if (fields.Contains(ItemFields.EndDate)) { dto.EndDate = item.EndDate; diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 295b9b27d..a2d045a5f 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -564,6 +564,12 @@ namespace MediaBrowser.Controller.Entities /// The budget. public double? Budget { get; set; } + /// + /// Gets or sets the revenue. + /// + /// The revenue. + public double? Revenue { get; set; } + /// /// Gets or sets the production locations. /// diff --git a/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs b/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs index 8e20f0fad..a013a85e0 100644 --- a/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs +++ b/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs @@ -907,6 +907,7 @@ namespace MediaBrowser.Controller.Providers.Movies movie.Overview = movie.Overview != null ? movie.Overview.Replace("\n\n", "\n") : null; movie.HomePageUrl = movieData.homepage; movie.Budget = movieData.budget; + movie.Revenue = movieData.revenue; if (!string.IsNullOrEmpty(movieData.tagline)) movie.AddTagline(movieData.tagline); movie.SetProviderId(MetadataProviders.Imdb, movieData.imdb_id); diff --git a/MediaBrowser.Model/DTO/BaseItemDto.cs b/MediaBrowser.Model/DTO/BaseItemDto.cs index 7d4823cdd..ac36d8b1a 100644 --- a/MediaBrowser.Model/DTO/BaseItemDto.cs +++ b/MediaBrowser.Model/DTO/BaseItemDto.cs @@ -458,8 +458,15 @@ namespace MediaBrowser.Model.Dto /// Gets or sets the budget. /// /// The budget. - [ProtoMember(73)] + [ProtoMember(74)] public double? Budget { get; set; } + + /// + /// Gets or sets the revenue. + /// + /// The revenue. + [ProtoMember(75)] + public double? Revenue { get; set; } /// /// Gets a value indicating whether this instance can resume. diff --git a/MediaBrowser.Model/Querying/ItemFields.cs b/MediaBrowser.Model/Querying/ItemFields.cs index 727de42f4..81ccf54a1 100644 --- a/MediaBrowser.Model/Querying/ItemFields.cs +++ b/MediaBrowser.Model/Querying/ItemFields.cs @@ -100,6 +100,11 @@ namespace MediaBrowser.Model.Querying /// The aspect ratio of the primary image /// PrimaryImageAspectRatio, + + /// + /// The revenue + /// + Revenue, /// /// AirDays, status, SeriesName, etc diff --git a/MediaBrowser.Model/Querying/ItemSortBy.cs b/MediaBrowser.Model/Querying/ItemSortBy.cs index b1ad7c550..fdd920ad3 100644 --- a/MediaBrowser.Model/Querying/ItemSortBy.cs +++ b/MediaBrowser.Model/Querying/ItemSortBy.cs @@ -23,6 +23,10 @@ namespace MediaBrowser.Model.Querying /// public const string Budget = "Budget"; /// + /// The revenue + /// + public const string Revenue = "Revenue"; + /// /// The date created /// public const string DateCreated = "DateCreated"; diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index 156ade135..3df640943 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -164,6 +164,7 @@ + diff --git a/MediaBrowser.Server.Implementations/Sorting/BudgetComparer.cs b/MediaBrowser.Server.Implementations/Sorting/BudgetComparer.cs index 3637f2939..39bdc6363 100644 --- a/MediaBrowser.Server.Implementations/Sorting/BudgetComparer.cs +++ b/MediaBrowser.Server.Implementations/Sorting/BudgetComparer.cs @@ -4,7 +4,7 @@ using MediaBrowser.Model.Querying; namespace MediaBrowser.Server.Implementations.Sorting { - public class BudgetDateComparer : IBaseItemComparer + public class BudgetComparer : IBaseItemComparer { /// /// Compares the specified x. diff --git a/MediaBrowser.Server.Implementations/Sorting/RevenueComparer.cs b/MediaBrowser.Server.Implementations/Sorting/RevenueComparer.cs new file mode 100644 index 000000000..8764c97d0 --- /dev/null +++ b/MediaBrowser.Server.Implementations/Sorting/RevenueComparer.cs @@ -0,0 +1,29 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Sorting; +using MediaBrowser.Model.Querying; + +namespace MediaBrowser.Server.Implementations.Sorting +{ + public class RevenueComparer : IBaseItemComparer + { + /// + /// Compares the specified x. + /// + /// The x. + /// The y. + /// System.Int32. + public int Compare(BaseItem x, BaseItem y) + { + return (x.Revenue ?? 0).CompareTo(y.Revenue ?? 0); + } + + /// + /// Gets the name. + /// + /// The name. + public string Name + { + get { return ItemSortBy.Revenue; } + } + } +}