diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index c478151b49..83690c243f 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -29,6 +29,7 @@ namespace MediaBrowser.Controller.Entities TrailerUrls = new List(); Studios = new List(); People = new List(); + CriticReviews = new List(); } /// @@ -587,6 +588,18 @@ namespace MediaBrowser.Controller.Entities /// The production locations. public List ProductionLocations { 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 community rating. /// @@ -622,6 +635,12 @@ namespace MediaBrowser.Controller.Entities /// The parent index number. public int? ParentIndexNumber { get; set; } + /// + /// Gets or sets the critic reviews. + /// + /// The critic reviews. + public List CriticReviews { get; set; } + /// /// The _local trailers /// diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 09a59286ee..4c6d81dcf3 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -115,6 +115,7 @@ + diff --git a/MediaBrowser.Controller/Providers/Movies/RottenTomatoesMovieProvider.cs b/MediaBrowser.Controller/Providers/Movies/RottenTomatoesMovieProvider.cs new file mode 100644 index 0000000000..edb6db14d0 --- /dev/null +++ b/MediaBrowser.Controller/Providers/Movies/RottenTomatoesMovieProvider.cs @@ -0,0 +1,168 @@ +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Movies; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Serialization; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Controller.Providers.Movies +{ + /// + /// Class RottenTomatoesMovieProvider + /// + public class RottenTomatoesMovieProvider : BaseMetadataProvider + { + // http://developer.rottentomatoes.com/iodocs + /// + /// The API key + /// + private const string ApiKey = "x9wjnvv39ntjmt9zs95nm7bg"; + + /// + /// The _rotten tomatoes resource pool + /// + private SemaphoreSlim _rottenTomatoesResourcePool = new SemaphoreSlim(3, 3); + + /// + /// Gets the json serializer. + /// + /// The json serializer. + protected IJsonSerializer JsonSerializer { get; private set; } + + /// + /// Gets the HTTP client. + /// + /// The HTTP client. + protected IHttpClient HttpClient { get; private set; } + + /// + /// Initializes a new instance of the class. + /// + /// The log manager. + /// The configuration manager. + /// The json serializer. + /// The HTTP client. + public RottenTomatoesMovieProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient) + : base(logManager, configurationManager) + { + JsonSerializer = jsonSerializer; + HttpClient = httpClient; + } + + /// + /// Gets the provider version. + /// + /// The provider version. + protected override string ProviderVersion + { + get + { + return "1"; + } + } + + /// + /// Gets a value indicating whether [requires internet]. + /// + /// true if [requires internet]; otherwise, false. + public override bool RequiresInternet + { + get + { + return true; + } + } + + /// + /// Gets a value indicating whether [refresh on version change]. + /// + /// true if [refresh on version change]; otherwise, false. + protected override bool RefreshOnVersionChange + { + get + { + return true; + } + } + + /// + /// Supportses the specified item. + /// + /// The item. + /// true if XXXX, false otherwise + public override bool Supports(BaseItem item) + { + return item is Movie; + } + + /// + /// Needses the refresh internal. + /// + /// The item. + /// The provider info. + /// true if XXXX, false otherwise + protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo) + { + if (providerInfo.LastRefreshStatus != ProviderRefreshStatus.Success) + { + Logger.Debug("RottenTomatoesMovieProvider for {0} - last attempt had errors. Will try again.", item.Path); + return true; + } + + // Refresh if imdb id has changed + if (!string.Equals(item.GetProviderId(MetadataProviders.Imdb), providerInfo.CustomData)) + { + return true; + } + + if (DateTime.Today.Subtract(providerInfo.LastRefreshed).TotalDays < ConfigurationManager.Configuration.MetadataRefreshDays) + { + return false; + } + + return base.NeedsRefreshInternal(item, providerInfo); + } + + /// + /// Fetches metadata and returns true or false indicating if any work that requires persistence was done + /// + /// The item. + /// if set to true [force]. + /// The cancellation token. + /// Task{System.Boolean}. + public override Task FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken) + { + // Do work here + + + // Lastly, record the Imdb id here + BaseProviderInfo data; + + if (item.ProviderData.TryGetValue(Id, out data)) + { + data.CustomData = item.GetProviderId(MetadataProviders.Imdb); + } + + SetLastRefreshed(item, DateTime.UtcNow); + + return Task.FromResult(true); + } + + /// + /// Gets the priority. + /// + /// The priority. + public override MetadataProviderPriority Priority + { + get + { + // Run after moviedb and xml providers + return MetadataProviderPriority.Last; + } + } + } +} diff --git a/MediaBrowser.Model/Entities/ItemReview.cs b/MediaBrowser.Model/Entities/ItemReview.cs new file mode 100644 index 0000000000..fcd4c1c2bf --- /dev/null +++ b/MediaBrowser.Model/Entities/ItemReview.cs @@ -0,0 +1,52 @@ +using System; + +namespace MediaBrowser.Model.Entities +{ + /// + /// Class ItemReview + /// + public class ItemReview + { + /// + /// Gets or sets the name of the reviewer. + /// + /// The name of the reviewer. + public string ReviewerName { get; set; } + + /// + /// Gets or sets the publisher. + /// + /// The publisher. + public string Publisher { get; set; } + + /// + /// Gets or sets the date. + /// + /// The date. + public DateTime Date { get; set; } + + /// + /// Gets or sets the score. + /// + /// The score. + public float Score { get; set; } + + /// + /// Gets or sets the URL. + /// + /// The URL. + public string Url { get; set; } + + /// + /// Gets or sets the caption. + /// + /// The caption. + public string Caption { get; set; } + + /// + /// Gets or sets the text. + /// + /// The text. + public string Text { get; set; } + } +} diff --git a/MediaBrowser.Model/Entities/MetadataProviders.cs b/MediaBrowser.Model/Entities/MetadataProviders.cs index 28e4b1646a..15648604fd 100644 --- a/MediaBrowser.Model/Entities/MetadataProviders.cs +++ b/MediaBrowser.Model/Entities/MetadataProviders.cs @@ -25,6 +25,10 @@ namespace MediaBrowser.Model.Entities /// /// MusicBrainz /// - Musicbrainz + Musicbrainz, + /// + /// The rotten tomatoes + /// + RottenTomatoes } } diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index 8e29d302c8..99e34aaf65 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -47,6 +47,7 @@ +