From a4cea5a5d326677bf74da6bf7df2203c12088d38 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 6 Nov 2013 11:06:16 -0500 Subject: [PATCH] added critic rating interface --- MediaBrowser.Api/ItemUpdateService.cs | 8 +++-- MediaBrowser.Api/UserLibrary/ItemsService.cs | 12 ++++++- MediaBrowser.Controller/Entities/BaseItem.cs | 12 ------- .../Entities/IHasCriticRating.cs | 20 ++++++++++++ .../Entities/Movies/Movie.cs | 14 +++++++- MediaBrowser.Controller/Entities/Trailer.cs | 14 +++++++- .../MediaBrowser.Controller.csproj | 1 + .../Providers/BaseItemXmlParser.cs | 19 ++++++++--- .../Movies/OpenMovieDatabaseProvider.cs | 32 +++++++++++-------- .../Savers/XmlSaverHelpers.cs | 16 ++++++---- .../Dto/DtoService.cs | 12 ++++--- .../Sorting/CriticRatingComparer.cs | 4 ++- 12 files changed, 118 insertions(+), 46 deletions(-) create mode 100644 MediaBrowser.Controller/Entities/IHasCriticRating.cs diff --git a/MediaBrowser.Api/ItemUpdateService.cs b/MediaBrowser.Api/ItemUpdateService.cs index ace8c4a6e..6e1dbc08b 100644 --- a/MediaBrowser.Api/ItemUpdateService.cs +++ b/MediaBrowser.Api/ItemUpdateService.cs @@ -219,8 +219,12 @@ namespace MediaBrowser.Api item.Budget = request.Budget; item.Revenue = request.Revenue; - item.CriticRating = request.CriticRating; - item.CriticRatingSummary = request.CriticRatingSummary; + var hasCriticRating = item as IHasCriticRating; + if (hasCriticRating != null) + { + hasCriticRating.CriticRating = request.CriticRating; + hasCriticRating.CriticRatingSummary = request.CriticRatingSummary; + } item.DisplayMediaType = request.DisplayMediaType; item.CommunityRating = request.CommunityRating; diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 29a894b1c..9547cc0a4 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -581,7 +581,17 @@ namespace MediaBrowser.Api.UserLibrary { var val = request.MinCriticRating.Value; - items = items.Where(i => i.CriticRating.HasValue && i.CriticRating >= val); + items = items.Where(i => + { + var hasCriticRating = i as IHasCriticRating; + + if (hasCriticRating != null) + { + return hasCriticRating.CriticRating.HasValue && hasCriticRating.CriticRating >= val; + } + + return false; + }); } // Artists diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 839fe34ff..f8b2fad23 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -111,18 +111,6 @@ namespace MediaBrowser.Controller.Entities /// The revenue. public double? Revenue { 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 trailer URL. /// diff --git a/MediaBrowser.Controller/Entities/IHasCriticRating.cs b/MediaBrowser.Controller/Entities/IHasCriticRating.cs new file mode 100644 index 000000000..d2b93759d --- /dev/null +++ b/MediaBrowser.Controller/Entities/IHasCriticRating.cs @@ -0,0 +1,20 @@ +namespace MediaBrowser.Controller.Entities +{ + /// + /// Interface IHasCriticRating + /// + public interface IHasCriticRating + { + /// + /// Gets or sets the critic rating. + /// + /// The critic rating. + float? CriticRating { get; set; } + + /// + /// Gets or sets the critic rating summary. + /// + /// The critic rating summary. + string CriticRatingSummary { get; set; } + } +} diff --git a/MediaBrowser.Controller/Entities/Movies/Movie.cs b/MediaBrowser.Controller/Entities/Movies/Movie.cs index 516ee9a8a..54ad9c1c9 100644 --- a/MediaBrowser.Controller/Entities/Movies/Movie.cs +++ b/MediaBrowser.Controller/Entities/Movies/Movie.cs @@ -11,7 +11,7 @@ namespace MediaBrowser.Controller.Entities.Movies /// /// Class Movie /// - public class Movie : Video + public class Movie : Video, IHasCriticRating { public List SpecialFeatureIds { get; set; } @@ -20,6 +20,18 @@ namespace MediaBrowser.Controller.Entities.Movies SpecialFeatureIds = new List(); } + /// + /// 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 name of the TMDB collection. /// diff --git a/MediaBrowser.Controller/Entities/Trailer.cs b/MediaBrowser.Controller/Entities/Trailer.cs index e7d47f7ec..c9fe471b3 100644 --- a/MediaBrowser.Controller/Entities/Trailer.cs +++ b/MediaBrowser.Controller/Entities/Trailer.cs @@ -7,7 +7,7 @@ namespace MediaBrowser.Controller.Entities /// /// Class Trailer /// - public class Trailer : Video + public class Trailer : Video, IHasCriticRating { public Trailer() { @@ -15,6 +15,18 @@ namespace MediaBrowser.Controller.Entities Taglines = new List(); } + /// + /// 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 a value indicating whether this instance is local trailer. /// diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 978d56bd4..94ff5d305 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 e9bb7f66d..9fdbbf3b7 100644 --- a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs +++ b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs @@ -143,10 +143,16 @@ namespace MediaBrowser.Controller.Providers case "CriticRating": { var text = reader.ReadElementContentAsString(); - float value; - if (float.TryParse(text, NumberStyles.Any, _usCulture, out value)) + + var hasCriticRating = item as IHasCriticRating; + + if (hasCriticRating != null && !string.IsNullOrEmpty(text)) { - item.CriticRating = value; + float value; + if (float.TryParse(text, NumberStyles.Any, _usCulture, out value)) + { + hasCriticRating.CriticRating = value; + } } break; @@ -207,7 +213,12 @@ namespace MediaBrowser.Controller.Providers if (!string.IsNullOrWhiteSpace(val)) { - item.CriticRatingSummary = val; + var hasCriticRating = item as IHasCriticRating; + + if (hasCriticRating != null) + { + hasCriticRating.CriticRatingSummary = val; + } } break; diff --git a/MediaBrowser.Providers/Movies/OpenMovieDatabaseProvider.cs b/MediaBrowser.Providers/Movies/OpenMovieDatabaseProvider.cs index a6fdbdcef..6550396e5 100644 --- a/MediaBrowser.Providers/Movies/OpenMovieDatabaseProvider.cs +++ b/MediaBrowser.Providers/Movies/OpenMovieDatabaseProvider.cs @@ -139,22 +139,26 @@ namespace MediaBrowser.Providers.Movies { var result = JsonSerializer.DeserializeFromStream(stream); - // Seeing some bogus RT data on omdb for series, so filter it out here - // RT doesn't even have tv series - int tomatoMeter; - - if (!string.IsNullOrEmpty(result.tomatoMeter) - && int.TryParse(result.tomatoMeter, NumberStyles.Integer, UsCulture, out tomatoMeter) - && tomatoMeter >= 0) + var hasCriticRating = item as IHasCriticRating; + if (hasCriticRating != null) { - item.CriticRating = tomatoMeter; - } + // Seeing some bogus RT data on omdb for series, so filter it out here + // RT doesn't even have tv series + int tomatoMeter; - if (!string.IsNullOrEmpty(result.tomatoConsensus) - && !string.Equals(result.tomatoConsensus, "n/a", StringComparison.OrdinalIgnoreCase) - && !string.Equals(result.tomatoConsensus, "No consensus yet.", StringComparison.OrdinalIgnoreCase)) - { - item.CriticRatingSummary = result.tomatoConsensus; + if (!string.IsNullOrEmpty(result.tomatoMeter) + && int.TryParse(result.tomatoMeter, NumberStyles.Integer, UsCulture, out tomatoMeter) + && tomatoMeter >= 0) + { + hasCriticRating.CriticRating = tomatoMeter; + } + + if (!string.IsNullOrEmpty(result.tomatoConsensus) + && !string.Equals(result.tomatoConsensus, "n/a", StringComparison.OrdinalIgnoreCase) + && !string.Equals(result.tomatoConsensus, "No consensus yet.", StringComparison.OrdinalIgnoreCase)) + { + hasCriticRating.CriticRatingSummary = result.tomatoConsensus; + } } int voteCount; diff --git a/MediaBrowser.Providers/Savers/XmlSaverHelpers.cs b/MediaBrowser.Providers/Savers/XmlSaverHelpers.cs index d9e0fb6e2..69276e0b8 100644 --- a/MediaBrowser.Providers/Savers/XmlSaverHelpers.cs +++ b/MediaBrowser.Providers/Savers/XmlSaverHelpers.cs @@ -209,14 +209,18 @@ namespace MediaBrowser.Providers.Savers builder.Append("" + SecurityElement.Escape(item.DisplayMediaType) + ""); } - if (item.CriticRating.HasValue) + var hasCriticRating = item as IHasCriticRating; + if (hasCriticRating != null) { - builder.Append("" + SecurityElement.Escape(item.CriticRating.Value.ToString(UsCulture)) + ""); - } + if (hasCriticRating.CriticRating.HasValue) + { + builder.Append("" + SecurityElement.Escape(hasCriticRating.CriticRating.Value.ToString(UsCulture)) + ""); + } - if (!string.IsNullOrEmpty(item.CriticRatingSummary)) - { - builder.Append(""); + if (!string.IsNullOrEmpty(hasCriticRating.CriticRatingSummary)) + { + builder.Append(""); + } } if (!string.IsNullOrEmpty(item.Overview)) diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 19e19f8ea..0104196e0 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -792,11 +792,15 @@ namespace MediaBrowser.Server.Implementations.Dto dto.MediaType = item.MediaType; dto.LocationType = item.LocationType; - dto.CriticRating = item.CriticRating; - - if (fields.Contains(ItemFields.CriticRatingSummary)) + var hasCriticRating = item as IHasCriticRating; + if (hasCriticRating != null) { - dto.CriticRatingSummary = item.CriticRatingSummary; + dto.CriticRating = hasCriticRating.CriticRating; + + if (fields.Contains(ItemFields.CriticRatingSummary)) + { + dto.CriticRatingSummary = hasCriticRating.CriticRatingSummary; + } } var localTrailerCount = item.LocalTrailerIds.Count; diff --git a/MediaBrowser.Server.Implementations/Sorting/CriticRatingComparer.cs b/MediaBrowser.Server.Implementations/Sorting/CriticRatingComparer.cs index 9484130cb..d01f7ed1b 100644 --- a/MediaBrowser.Server.Implementations/Sorting/CriticRatingComparer.cs +++ b/MediaBrowser.Server.Implementations/Sorting/CriticRatingComparer.cs @@ -22,7 +22,9 @@ namespace MediaBrowser.Server.Implementations.Sorting private float GetValue(BaseItem x) { - return x.CriticRating ?? 0; + var hasCriticRating = x as IHasCriticRating; + + return hasCriticRating == null ? 0 : hasCriticRating.CriticRating ?? 0; } ///