added critic rating interface

This commit is contained in:
Luke Pulverenti 2013-11-06 11:06:16 -05:00
parent 885287e631
commit a4cea5a5d3
12 changed files with 118 additions and 46 deletions

View File

@ -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;

View File

@ -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

View File

@ -111,18 +111,6 @@ namespace MediaBrowser.Controller.Entities
/// <value>The revenue.</value>
public double? Revenue { get; set; }
/// <summary>
/// Gets or sets the critic rating.
/// </summary>
/// <value>The critic rating.</value>
public float? CriticRating { get; set; }
/// <summary>
/// Gets or sets the critic rating summary.
/// </summary>
/// <value>The critic rating summary.</value>
public string CriticRatingSummary { get; set; }
/// <summary>
/// Gets or sets the trailer URL.
/// </summary>

View File

@ -0,0 +1,20 @@
namespace MediaBrowser.Controller.Entities
{
/// <summary>
/// Interface IHasCriticRating
/// </summary>
public interface IHasCriticRating
{
/// <summary>
/// Gets or sets the critic rating.
/// </summary>
/// <value>The critic rating.</value>
float? CriticRating { get; set; }
/// <summary>
/// Gets or sets the critic rating summary.
/// </summary>
/// <value>The critic rating summary.</value>
string CriticRatingSummary { get; set; }
}
}

View File

@ -11,7 +11,7 @@ namespace MediaBrowser.Controller.Entities.Movies
/// <summary>
/// Class Movie
/// </summary>
public class Movie : Video
public class Movie : Video, IHasCriticRating
{
public List<Guid> SpecialFeatureIds { get; set; }
@ -20,6 +20,18 @@ namespace MediaBrowser.Controller.Entities.Movies
SpecialFeatureIds = new List<Guid>();
}
/// <summary>
/// Gets or sets the critic rating.
/// </summary>
/// <value>The critic rating.</value>
public float? CriticRating { get; set; }
/// <summary>
/// Gets or sets the critic rating summary.
/// </summary>
/// <value>The critic rating summary.</value>
public string CriticRatingSummary { get; set; }
/// <summary>
/// Gets or sets the name of the TMDB collection.
/// </summary>

View File

@ -7,7 +7,7 @@ namespace MediaBrowser.Controller.Entities
/// <summary>
/// Class Trailer
/// </summary>
public class Trailer : Video
public class Trailer : Video, IHasCriticRating
{
public Trailer()
{
@ -15,6 +15,18 @@ namespace MediaBrowser.Controller.Entities
Taglines = new List<string>();
}
/// <summary>
/// Gets or sets the critic rating.
/// </summary>
/// <value>The critic rating.</value>
public float? CriticRating { get; set; }
/// <summary>
/// Gets or sets the critic rating summary.
/// </summary>
/// <value>The critic rating summary.</value>
public string CriticRatingSummary { get; set; }
/// <summary>
/// Gets a value indicating whether this instance is local trailer.
/// </summary>

View File

@ -89,6 +89,7 @@
<Compile Include="Entities\GameGenre.cs" />
<Compile Include="Entities\GameSystem.cs" />
<Compile Include="Entities\IByReferenceItem.cs" />
<Compile Include="Entities\IHasCriticRating.cs" />
<Compile Include="Entities\IItemByName.cs" />
<Compile Include="Entities\ILibraryItem.cs" />
<Compile Include="Entities\ImageSourceInfo.cs" />

View File

@ -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;

View File

@ -139,22 +139,26 @@ namespace MediaBrowser.Providers.Movies
{
var result = JsonSerializer.DeserializeFromStream<RootObject>(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;

View File

@ -209,14 +209,18 @@ namespace MediaBrowser.Providers.Savers
builder.Append("<Type>" + SecurityElement.Escape(item.DisplayMediaType) + "</Type>");
}
if (item.CriticRating.HasValue)
var hasCriticRating = item as IHasCriticRating;
if (hasCriticRating != null)
{
builder.Append("<CriticRating>" + SecurityElement.Escape(item.CriticRating.Value.ToString(UsCulture)) + "</CriticRating>");
}
if (hasCriticRating.CriticRating.HasValue)
{
builder.Append("<CriticRating>" + SecurityElement.Escape(hasCriticRating.CriticRating.Value.ToString(UsCulture)) + "</CriticRating>");
}
if (!string.IsNullOrEmpty(item.CriticRatingSummary))
{
builder.Append("<CriticRatingSummary><![CDATA[" + item.CriticRatingSummary + "]]></CriticRatingSummary>");
if (!string.IsNullOrEmpty(hasCriticRating.CriticRatingSummary))
{
builder.Append("<CriticRatingSummary><![CDATA[" + hasCriticRating.CriticRatingSummary + "]]></CriticRatingSummary>");
}
}
if (!string.IsNullOrEmpty(item.Overview))

View File

@ -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;

View File

@ -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;
}
/// <summary>