mirror of
https://github.com/jellyfin/jellyfin-plugin-bookshelf.git
synced 2024-11-30 09:00:49 +00:00
update to latest server
This commit is contained in:
parent
10b3f55aa1
commit
6d2acc5f2c
@ -36,17 +36,17 @@
|
||||
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MediaBrowser.Common, Version=3.0.4878.13107, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="MediaBrowser.Common, Version=3.0.4878.40366, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.98\lib\net45\MediaBrowser.Common.dll</HintPath>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.100\lib\net45\MediaBrowser.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MediaBrowser.Controller, Version=3.0.4878.13107, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="MediaBrowser.Controller, Version=3.0.4878.40367, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MediaBrowser.Server.Core.3.0.98\lib\net45\MediaBrowser.Controller.dll</HintPath>
|
||||
<HintPath>..\packages\MediaBrowser.Server.Core.3.0.100\lib\net45\MediaBrowser.Controller.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MediaBrowser.Model, Version=3.0.4878.13106, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="MediaBrowser.Model, Version=3.0.4878.40366, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.98\lib\net45\MediaBrowser.Model.dll</HintPath>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.100\lib\net45\MediaBrowser.Model.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MoreLinq">
|
||||
<HintPath>..\packages\morelinq.1.0.15631-beta\lib\net35\MoreLinq.dll</HintPath>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MediaBrowser.Common" version="3.0.98" targetFramework="net45" />
|
||||
<package id="MediaBrowser.Server.Core" version="3.0.98" targetFramework="net45" />
|
||||
<package id="MediaBrowser.Common" version="3.0.100" targetFramework="net45" />
|
||||
<package id="MediaBrowser.Server.Core" version="3.0.100" targetFramework="net45" />
|
||||
<package id="morelinq" version="1.0.15631-beta" targetFramework="net45" />
|
||||
</packages>
|
@ -37,13 +37,13 @@
|
||||
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MediaBrowser.Common, Version=3.0.4878.13107, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="MediaBrowser.Common, Version=3.0.4878.40366, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.98\lib\net45\MediaBrowser.Common.dll</HintPath>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.100\lib\net45\MediaBrowser.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MediaBrowser.Model, Version=3.0.4878.13106, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="MediaBrowser.Model, Version=3.0.4878.40366, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.98\lib\net45\MediaBrowser.Model.dll</HintPath>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.100\lib\net45\MediaBrowser.Model.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MediaBrowser.UI, Version=3.0.4815.21813, Culture=neutral, processorArchitecture=x86">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MediaBrowser.Common" version="3.0.98" targetFramework="net45" />
|
||||
<package id="MediaBrowser.Common" version="3.0.100" targetFramework="net45" />
|
||||
<package id="MediaBrowser.Theater.Core" version="3.0.37" targetFramework="net45" />
|
||||
</packages>
|
@ -0,0 +1,11 @@
|
||||
using MediaBrowser.Model.Plugins;
|
||||
|
||||
namespace MediaBrowser.Plugins.RottenTomatoes.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Class PluginConfiguration
|
||||
/// </summary>
|
||||
public class PluginConfiguration : BasePluginConfiguration
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{71BF266C-BFB0-4821-8909-FF21F95A4B49}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>MediaBrowser.Plugins.RottenTomatoes</RootNamespace>
|
||||
<AssemblyName>MediaBrowser.Plugins.RottenTomatoes</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MediaBrowser.Common, Version=3.0.4878.40366, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.100\lib\net45\MediaBrowser.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MediaBrowser.Controller, Version=3.0.4878.40367, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MediaBrowser.Server.Core.3.0.100\lib\net45\MediaBrowser.Controller.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MediaBrowser.Model, Version=3.0.4878.40366, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.100\lib\net45\MediaBrowser.Model.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Configuration\PluginConfiguration.cs" />
|
||||
<Compile Include="Plugin.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Providers\RottenTomatoesMovieProvider.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\..\MediaBrowser\ProgramData-Server\Plugins\" /y</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
52
MediaBrowser.Plugins.RottenTomatoes/Plugin.cs
Normal file
52
MediaBrowser.Plugins.RottenTomatoes/Plugin.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Plugins;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MediaBrowser.Plugins.RottenTomatoes.Configuration;
|
||||
using System.Threading;
|
||||
|
||||
namespace MediaBrowser.Plugins.RottenTomatoes
|
||||
{
|
||||
/// <summary>
|
||||
/// Class Plugin
|
||||
/// </summary>
|
||||
public class Plugin : BasePlugin<PluginConfiguration>
|
||||
{
|
||||
/// <summary>
|
||||
/// Apple doesn't seem to like too many simulataneous requests.
|
||||
/// </summary>
|
||||
public readonly SemaphoreSlim AppleTrailers = new SemaphoreSlim(1, 1);
|
||||
|
||||
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
|
||||
: base(applicationPaths, xmlSerializer)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the plugin
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public override string Name
|
||||
{
|
||||
get { return "Rotten Tomatoes Reviews"; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the description.
|
||||
/// </summary>
|
||||
/// <value>The description.</value>
|
||||
public override string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Displays critic reviews from Rotten Tomatoes.";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance.
|
||||
/// </summary>
|
||||
/// <value>The instance.</value>
|
||||
public static Plugin Instance { get; private set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("MediaBrowser.Plugins.RottenTomatoes")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("MediaBrowser.Plugins.RottenTomatoes")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2013")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("99b9deee-2f49-418f-b3c3-b4390a7b3761")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
@ -0,0 +1,504 @@
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Plugins.RottenTomatoes.Providers
|
||||
{
|
||||
/// <summary>
|
||||
/// Class RottenTomatoesMovieProvider
|
||||
/// </summary>
|
||||
public class RottenTomatoesProvider : BaseMetadataProvider
|
||||
{
|
||||
// http://developer.rottentomatoes.com/iodocs
|
||||
|
||||
private const int DailyRefreshLimit = 200;
|
||||
|
||||
private const string MoviesReviews = @"movies/{1}/reviews.json?review_type=top_critic&page_limit=10&page=1&country=us&apikey={0}";
|
||||
|
||||
private readonly string[] _apiKeys =
|
||||
{
|
||||
// MB Server key
|
||||
"x9wjnvv39ntjmt9zs95nm7bg",
|
||||
|
||||
// Donated by Redshirt
|
||||
"gecbjvjka5may65qmqrczk97",
|
||||
|
||||
// MB Theater
|
||||
"4wku9pfehuvwrrt5fyjgbert"
|
||||
};
|
||||
|
||||
private const string BasicUrl = @"http://api.rottentomatoes.com/api/public/v1.0/";
|
||||
private const string MovieImdb = @"movie_alias.json?id={1}&type=imdb&apikey={0}";
|
||||
|
||||
private readonly SemaphoreSlim _rottenTomatoesResourcePool = new SemaphoreSlim(1, 1);
|
||||
|
||||
private readonly SemaphoreSlim _refreshResourcePool = new SemaphoreSlim(1, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the json serializer.
|
||||
/// </summary>
|
||||
/// <value>The json serializer.</value>
|
||||
protected IJsonSerializer JsonSerializer { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTTP client.
|
||||
/// </summary>
|
||||
/// <value>The HTTP client.</value>
|
||||
protected IHttpClient HttpClient { get; private set; }
|
||||
|
||||
private readonly IItemRepository _itemRepo;
|
||||
|
||||
private readonly string _requestHistoryPath;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RottenTomatoesMovieProvider" /> class.
|
||||
/// </summary>
|
||||
/// <param name="logManager">The log manager.</param>
|
||||
/// <param name="configurationManager">The configuration manager.</param>
|
||||
/// <param name="jsonSerializer">The json serializer.</param>
|
||||
/// <param name="httpClient">The HTTP client.</param>
|
||||
/// <param name="appPaths">The app paths.</param>
|
||||
public RottenTomatoesProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient, IApplicationPaths appPaths, IItemRepository itemRepo)
|
||||
: base(logManager, configurationManager)
|
||||
{
|
||||
JsonSerializer = jsonSerializer;
|
||||
HttpClient = httpClient;
|
||||
_itemRepo = itemRepo;
|
||||
|
||||
_requestHistoryPath = Path.Combine(appPaths.CachePath, "rotten-tomatoes");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the provider version.
|
||||
/// </summary>
|
||||
/// <value>The provider version.</value>
|
||||
protected override string ProviderVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return "7";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether [requires internet].
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if [requires internet]; otherwise, <c>false</c>.</value>
|
||||
public override bool RequiresInternet
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether [refresh on version change].
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if [refresh on version change]; otherwise, <c>false</c>.</value>
|
||||
protected override bool RefreshOnVersionChange
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The _configuration
|
||||
/// </summary>
|
||||
private List<DateTime> _requestHistory;
|
||||
/// <summary>
|
||||
/// The _configuration initialized
|
||||
/// </summary>
|
||||
private bool _requestHistoryInitialized;
|
||||
/// <summary>
|
||||
/// The _configuration sync lock
|
||||
/// </summary>
|
||||
private object _requestHistorySyncLock = new object();
|
||||
/// <summary>
|
||||
/// Gets the user's configuration
|
||||
/// </summary>
|
||||
/// <value>The configuration.</value>
|
||||
public List<DateTime> RequestHistory
|
||||
{
|
||||
get
|
||||
{
|
||||
// Lazy load
|
||||
LazyInitializer.EnsureInitialized(ref _requestHistory, ref _requestHistoryInitialized, ref _requestHistorySyncLock, LoadRequestHistory);
|
||||
return _requestHistory;
|
||||
}
|
||||
private set
|
||||
{
|
||||
_requestHistory = value;
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
_requestHistoryInitialized = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the request history file path.
|
||||
/// </summary>
|
||||
/// <value>The request history file path.</value>
|
||||
private string RequestHistoryFilePath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Directory.Exists(_requestHistoryPath))
|
||||
{
|
||||
Directory.CreateDirectory(_requestHistoryPath);
|
||||
}
|
||||
|
||||
return Path.Combine(_requestHistoryPath, "data.dat");
|
||||
}
|
||||
}
|
||||
|
||||
protected readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
||||
|
||||
/// <summary>
|
||||
/// Loads the request history.
|
||||
/// </summary>
|
||||
/// <returns>List{DateTime}.</returns>
|
||||
private List<DateTime> LoadRequestHistory()
|
||||
{
|
||||
try
|
||||
{
|
||||
return
|
||||
File.ReadAllText(RequestHistoryFilePath)
|
||||
.Split('|')
|
||||
.Select(i =>
|
||||
{
|
||||
long ticks;
|
||||
|
||||
if (long.TryParse(i, NumberStyles.Any, UsCulture, out ticks))
|
||||
{
|
||||
return new DateTime(ticks, DateTimeKind.Utc);
|
||||
}
|
||||
|
||||
return DateTime.MinValue;
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new List<DateTime>();
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveRequestHistory(IEnumerable<DateTime> history)
|
||||
{
|
||||
using (var fs = new FileStream(RequestHistoryFilePath, FileMode.Create, FileAccess.Write, FileShare.Read))
|
||||
{
|
||||
using (var streamWriter = new StreamWriter(fs))
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
var text = string.Join("|", history.Where(i => (now - i).TotalDays <= 2)
|
||||
.Select(i => i.Ticks.ToString(UsCulture))
|
||||
.ToArray());
|
||||
|
||||
streamWriter.Write(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Supports the specified item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
public override bool Supports(BaseItem item)
|
||||
{
|
||||
var trailer = item as Trailer;
|
||||
|
||||
if (trailer != null)
|
||||
{
|
||||
return !trailer.IsLocalTrailer;
|
||||
}
|
||||
|
||||
// Don't support local trailers
|
||||
return item is Movie;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the comparison data.
|
||||
/// </summary>
|
||||
/// <param name="imdbId">The imdb id.</param>
|
||||
/// <returns>Guid.</returns>
|
||||
private Guid GetComparisonData(string imdbId)
|
||||
{
|
||||
return string.IsNullOrEmpty(imdbId) ? Guid.Empty : imdbId.GetMD5();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
/// <value>The priority.</value>
|
||||
public override MetadataProviderPriority Priority
|
||||
{
|
||||
get
|
||||
{
|
||||
// Run after moviedb and xml providers
|
||||
return MetadataProviderPriority.Last;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Needses the refresh internal.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="providerInfo">The provider info.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
// Refresh if rt id has changed
|
||||
if (providerInfo.Data != GetComparisonData(item.GetProviderId(MetadataProviders.Imdb)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.NeedsRefreshInternal(item, providerInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="force">if set to <c>true</c> [force].</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task{System.Boolean}.</returns>
|
||||
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
||||
{
|
||||
await _refreshResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var history = RequestHistory;
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
if (history.Count(i => (now - i).TotalDays <= 1) >= DailyRefreshLimit)
|
||||
{
|
||||
_refreshResourcePool.Release();
|
||||
|
||||
Logger.Debug("Skipping {0} because daily request limit has been reached. Tomorrow's refresh will retrieve it.", item.Name);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await FetchAsyncInternal(item, force, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
SaveRequestHistory(history);
|
||||
|
||||
_refreshResourcePool.Release();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches the async internal.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="force">if set to <c>true</c> [force].</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task{System.Boolean}.</returns>
|
||||
private async Task FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
|
||||
{
|
||||
BaseProviderInfo data;
|
||||
|
||||
if (!item.ProviderData.TryGetValue(Id, out data))
|
||||
{
|
||||
data = new BaseProviderInfo();
|
||||
item.ProviderData[Id] = data;
|
||||
}
|
||||
|
||||
var imdbId = item.GetProviderId(MetadataProviders.Imdb);
|
||||
|
||||
if (string.IsNullOrEmpty(imdbId))
|
||||
{
|
||||
data.Data = GetComparisonData(imdbId);
|
||||
data.LastRefreshStatus = ProviderRefreshStatus.Success;
|
||||
return;
|
||||
}
|
||||
|
||||
var apiKey = GetApiKey();
|
||||
|
||||
if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.RottenTomatoes)))
|
||||
{
|
||||
await FetchRottenTomatoesId(item, apiKey, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
RequestHistory.Add(DateTime.UtcNow);
|
||||
|
||||
using (var stream = await HttpClient.Get(new HttpRequestOptions
|
||||
{
|
||||
Url = GetMovieReviewsUrl(item.GetProviderId(MetadataProviders.RottenTomatoes), apiKey),
|
||||
ResourcePool = _rottenTomatoesResourcePool,
|
||||
CancellationToken = cancellationToken,
|
||||
EnableResponseCache = true
|
||||
|
||||
}).ConfigureAwait(false))
|
||||
{
|
||||
|
||||
var result = JsonSerializer.DeserializeFromStream<RTReviewList>(stream);
|
||||
|
||||
var criticReviews = result.reviews.Select(rtReview => new ItemReview
|
||||
{
|
||||
ReviewerName = rtReview.critic,
|
||||
Publisher = rtReview.publication,
|
||||
Date = DateTime.Parse(rtReview.date).ToUniversalTime(),
|
||||
Caption = rtReview.quote,
|
||||
Url = rtReview.links.review,
|
||||
Likes = string.Equals(rtReview.freshness, "fresh", StringComparison.OrdinalIgnoreCase)
|
||||
|
||||
}).ToList();
|
||||
|
||||
await _itemRepo.SaveCriticReviews(item.Id, criticReviews).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
data.Data = GetComparisonData(item.GetProviderId(MetadataProviders.Imdb));
|
||||
data.LastRefreshStatus = ProviderRefreshStatus.Success;
|
||||
SetLastRefreshed(item, DateTime.UtcNow);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches the rotten tomatoes id.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="apiKey">The API key.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
private async Task FetchRottenTomatoesId(BaseItem item, string apiKey, CancellationToken cancellationToken)
|
||||
{
|
||||
var imdbId = item.GetProviderId(MetadataProviders.Imdb);
|
||||
|
||||
RequestHistory.Add(DateTime.UtcNow);
|
||||
|
||||
// Have IMDB Id
|
||||
using (var stream = await HttpClient.Get(new HttpRequestOptions
|
||||
{
|
||||
Url = GetMovieImdbUrl(imdbId, apiKey),
|
||||
ResourcePool = _rottenTomatoesResourcePool,
|
||||
CancellationToken = cancellationToken,
|
||||
EnableResponseCache = true
|
||||
|
||||
}).ConfigureAwait(false))
|
||||
{
|
||||
var hit = JsonSerializer.DeserializeFromStream<RTMovieSearchResult>(stream);
|
||||
|
||||
if (!string.IsNullOrEmpty(hit.id))
|
||||
{
|
||||
// Got a result
|
||||
item.CriticRatingSummary = hit.critics_consensus;
|
||||
item.CriticRating = float.Parse(hit.ratings.critics_score);
|
||||
|
||||
item.SetProviderId(MetadataProviders.RottenTomatoes, hit.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Utility functions to get the URL of the API calls
|
||||
|
||||
private string GetMovieReviewsUrl(string rtId, string apiKey)
|
||||
{
|
||||
return BasicUrl + string.Format(MoviesReviews, apiKey, rtId);
|
||||
}
|
||||
private string GetMovieImdbUrl(string imdbId, string apiKey)
|
||||
{
|
||||
return BasicUrl + string.Format(MovieImdb, apiKey, imdbId.TrimStart('t'));
|
||||
}
|
||||
|
||||
private string GetApiKey()
|
||||
{
|
||||
var index = Environment.MachineName.GetHashCode()%_apiKeys.Length;
|
||||
|
||||
return _apiKeys[index];
|
||||
}
|
||||
|
||||
// Data contract classes for use with the Rotten Tomatoes API
|
||||
|
||||
protected class RTReviewList
|
||||
{
|
||||
public int total { get; set; }
|
||||
public List<RTReview> reviews { get; set; }
|
||||
}
|
||||
|
||||
protected class RTReview
|
||||
{
|
||||
public string critic { get; set; }
|
||||
public string date { get; set; }
|
||||
public string freshness { get; set; }
|
||||
public string publication { get; set; }
|
||||
public string quote { get; set; }
|
||||
public RTReviewLink links { get; set; }
|
||||
public string original_score { get; set; }
|
||||
}
|
||||
|
||||
protected class RTReviewLink
|
||||
{
|
||||
public string review { get; set; }
|
||||
}
|
||||
|
||||
protected class RTSearchResults
|
||||
{
|
||||
public int total { get; set; }
|
||||
public List<RTMovieSearchResult> movies { get; set; }
|
||||
public RTSearchLinks links { get; set; }
|
||||
public string link_template { get; set; }
|
||||
}
|
||||
|
||||
protected class RTSearchLinks
|
||||
{
|
||||
public string self { get; set; }
|
||||
public string next { get; set; }
|
||||
public string previous { get; set; }
|
||||
}
|
||||
|
||||
protected class RTMovieSearchResult
|
||||
{
|
||||
public string title { get; set; }
|
||||
public int year { get; set; }
|
||||
public string runtime { get; set; }
|
||||
public string synopsis { get; set; }
|
||||
public string critics_consensus { get; set; }
|
||||
public string mpaa_rating { get; set; }
|
||||
public string id { get; set; }
|
||||
public RTRatings ratings { get; set; }
|
||||
public RTAlternateIds alternate_ids { get; set; }
|
||||
}
|
||||
|
||||
protected class RTRatings
|
||||
{
|
||||
public string critics_rating { get; set; }
|
||||
public string critics_score { get; set; }
|
||||
}
|
||||
|
||||
protected class RTAlternateIds
|
||||
{
|
||||
public string imdb { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
5
MediaBrowser.Plugins.RottenTomatoes/packages.config
Normal file
5
MediaBrowser.Plugins.RottenTomatoes/packages.config
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MediaBrowser.Common" version="3.0.100" targetFramework="net45" />
|
||||
<package id="MediaBrowser.Server.Core" version="3.0.100" targetFramework="net45" />
|
||||
</packages>
|
@ -37,13 +37,13 @@
|
||||
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MediaBrowser.Common, Version=3.0.4878.13107, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="MediaBrowser.Common, Version=3.0.4878.40366, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.98\lib\net45\MediaBrowser.Common.dll</HintPath>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.100\lib\net45\MediaBrowser.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MediaBrowser.Model, Version=3.0.4878.13106, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="MediaBrowser.Model, Version=3.0.4878.40366, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.98\lib\net45\MediaBrowser.Model.dll</HintPath>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.100\lib\net45\MediaBrowser.Model.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MediaBrowser.UI, Version=3.0.4815.21813, Culture=neutral, processorArchitecture=x86">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MediaBrowser.Common" version="3.0.98" targetFramework="net45" />
|
||||
<package id="MediaBrowser.Common" version="3.0.100" targetFramework="net45" />
|
||||
<package id="MediaBrowser.Theater.Core" version="3.0.37" targetFramework="net45" />
|
||||
</packages>
|
@ -35,17 +35,17 @@
|
||||
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MediaBrowser.Common, Version=3.0.4878.13107, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="MediaBrowser.Common, Version=3.0.4878.40366, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.98\lib\net45\MediaBrowser.Common.dll</HintPath>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.100\lib\net45\MediaBrowser.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MediaBrowser.Controller, Version=3.0.4878.13107, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="MediaBrowser.Controller, Version=3.0.4878.40367, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MediaBrowser.Server.Core.3.0.98\lib\net45\MediaBrowser.Controller.dll</HintPath>
|
||||
<HintPath>..\packages\MediaBrowser.Server.Core.3.0.100\lib\net45\MediaBrowser.Controller.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MediaBrowser.Model, Version=3.0.4878.13106, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="MediaBrowser.Model, Version=3.0.4878.40366, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.98\lib\net45\MediaBrowser.Model.dll</HintPath>
|
||||
<HintPath>..\packages\MediaBrowser.Common.3.0.100\lib\net45\MediaBrowser.Model.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MediaBrowser.Common" version="3.0.98" targetFramework="net45" />
|
||||
<package id="MediaBrowser.Server.Core" version="3.0.98" targetFramework="net45" />
|
||||
<package id="MediaBrowser.Common" version="3.0.100" targetFramework="net45" />
|
||||
<package id="MediaBrowser.Server.Core" version="3.0.100" targetFramework="net45" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user