From e49848b8bfcbae5870b6f2d5639cfbecbb83c084 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 5 May 2013 22:23:19 -0400 Subject: [PATCH] Added critic rating as a sort order --- .../UserLibrary/BaseItemsRequest.cs | 2 +- MediaBrowser.Api/UserLibrary/ItemsService.cs | 2 +- MediaBrowser.Controller/Dto/DtoBuilder.cs | 6 ++++ .../Movies/RottenTomatoesMovieProvider.cs | 12 +++---- MediaBrowser.Model/DTO/BaseItemDto.cs | 12 +++++++ MediaBrowser.Model/Entities/ItemReview.cs | 8 ++++- MediaBrowser.Model/Querying/ItemFields.cs | 5 +++ MediaBrowser.Model/Querying/ItemSortBy.cs | 5 +++ ...MediaBrowser.Server.Implementations.csproj | 1 + .../Sorting/CriticRatingComparer.cs | 32 +++++++++++++++++++ 10 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 MediaBrowser.Server.Implementations/Sorting/CriticRatingComparer.cs diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs index a69fedf25..2e3b84e8d 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs @@ -48,7 +48,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, Revenue, 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, CriticRatingSummary, DateCreated, DisplayMediaType, 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 45bf17397..af4f94f50 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -41,7 +41,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, Revenue, 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, CriticRating, 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 803e198bf..3a2412aeb 100644 --- a/MediaBrowser.Controller/Dto/DtoBuilder.cs +++ b/MediaBrowser.Controller/Dto/DtoBuilder.cs @@ -312,6 +312,12 @@ namespace MediaBrowser.Controller.Dto dto.Language = item.Language; dto.MediaType = item.MediaType; dto.LocationType = item.LocationType; + dto.CriticRating = item.CriticRating; + + if (fields.Contains(ItemFields.CriticRatingSummary)) + { + dto.CriticRatingSummary = item.CriticRatingSummary; + } var localTrailerCount = item.LocalTrailers == null ? 0 : item.LocalTrailers.Count; diff --git a/MediaBrowser.Controller/Providers/Movies/RottenTomatoesMovieProvider.cs b/MediaBrowser.Controller/Providers/Movies/RottenTomatoesMovieProvider.cs index d6f66fa4f..c8b3e988a 100644 --- a/MediaBrowser.Controller/Providers/Movies/RottenTomatoesMovieProvider.cs +++ b/MediaBrowser.Controller/Providers/Movies/RottenTomatoesMovieProvider.cs @@ -7,11 +7,10 @@ using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; using System; -using System.Threading; -using System.Threading.Tasks; -using System.IO; using System.Collections.Generic; using System.Linq; +using System.Threading; +using System.Threading.Tasks; namespace MediaBrowser.Controller.Providers.Movies { @@ -35,7 +34,7 @@ namespace MediaBrowser.Controller.Providers.Movies /// /// The _rotten tomatoes resource pool /// - private readonly SemaphoreSlim _rottenTomatoesResourcePool = new SemaphoreSlim(3, 3); + private readonly SemaphoreSlim _rottenTomatoesResourcePool = new SemaphoreSlim(1, 1); /// /// Gets the json serializer. @@ -71,7 +70,7 @@ namespace MediaBrowser.Controller.Providers.Movies { get { - return "2"; + return "4"; } } @@ -251,7 +250,8 @@ namespace MediaBrowser.Controller.Providers.Movies Publisher = rtReview.publication, Date = DateTime.Parse(rtReview.date).ToUniversalTime(), Caption = rtReview.quote, - Url = rtReview.links.review + Url = rtReview.links.review, + Likes = string.Equals(rtReview.freshness, "fresh", StringComparison.OrdinalIgnoreCase) }).ToList(); diff --git a/MediaBrowser.Model/DTO/BaseItemDto.cs b/MediaBrowser.Model/DTO/BaseItemDto.cs index 2e54f3311..e8f389940 100644 --- a/MediaBrowser.Model/DTO/BaseItemDto.cs +++ b/MediaBrowser.Model/DTO/BaseItemDto.cs @@ -42,6 +42,18 @@ namespace MediaBrowser.Model.Dto /// The premiere date. public DateTime? PremiereDate { get; set; } + /// + /// Gets or sets the critic rating. + /// + /// The critic rating. + public float? CriticRating { get; set; } + + /// + /// Gets or sets the critic rating summary. + /// + /// The critic rating summary. + public string CriticRatingSummary { get; set; } + /// /// Gets or sets the path. /// diff --git a/MediaBrowser.Model/Entities/ItemReview.cs b/MediaBrowser.Model/Entities/ItemReview.cs index fcd4c1c2b..3b496cce8 100644 --- a/MediaBrowser.Model/Entities/ItemReview.cs +++ b/MediaBrowser.Model/Entities/ItemReview.cs @@ -29,7 +29,13 @@ namespace MediaBrowser.Model.Entities /// Gets or sets the score. /// /// The score. - public float Score { get; set; } + public float? Score { get; set; } + + /// + /// Gets or sets a value indicating whether this is likes. + /// + /// null if [likes] contains no value, true if [likes]; otherwise, false. + public bool? Likes { get; set; } /// /// Gets or sets the URL. diff --git a/MediaBrowser.Model/Querying/ItemFields.cs b/MediaBrowser.Model/Querying/ItemFields.cs index 81ccf54a1..2e6e6b7dc 100644 --- a/MediaBrowser.Model/Querying/ItemFields.cs +++ b/MediaBrowser.Model/Querying/ItemFields.cs @@ -21,6 +21,11 @@ namespace MediaBrowser.Model.Querying /// Chapters, + /// + /// The critic rating summary + /// + CriticRatingSummary, + /// /// The date created of the item /// diff --git a/MediaBrowser.Model/Querying/ItemSortBy.cs b/MediaBrowser.Model/Querying/ItemSortBy.cs index fdd920ad3..c47993d38 100644 --- a/MediaBrowser.Model/Querying/ItemSortBy.cs +++ b/MediaBrowser.Model/Querying/ItemSortBy.cs @@ -62,5 +62,10 @@ namespace MediaBrowser.Model.Querying /// The play count /// public const string PlayCount = "PlayCount"; + /// + /// The critic rating + /// + public const string CriticRating = "CriticRating"; + } } diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index 4b614454b..97f033731 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -161,6 +161,7 @@ + diff --git a/MediaBrowser.Server.Implementations/Sorting/CriticRatingComparer.cs b/MediaBrowser.Server.Implementations/Sorting/CriticRatingComparer.cs new file mode 100644 index 000000000..358e06f3b --- /dev/null +++ b/MediaBrowser.Server.Implementations/Sorting/CriticRatingComparer.cs @@ -0,0 +1,32 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Sorting; +using MediaBrowser.Model.Querying; + +namespace MediaBrowser.Server.Implementations.Sorting +{ + /// + /// Class CriticRatingComparer + /// + public class CriticRatingComparer : IBaseItemComparer + { + /// + /// Compares the specified x. + /// + /// The x. + /// The y. + /// System.Int32. + public int Compare(BaseItem x, BaseItem y) + { + return (x.CriticRating ?? 0).CompareTo(y.CriticRating ?? 0); + } + + /// + /// Gets the name. + /// + /// The name. + public string Name + { + get { return ItemSortBy.CriticRating; } + } + } +}