jellyfin/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs
2014-02-10 13:39:41 -05:00

52 lines
1.9 KiB
C#

using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Serialization;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.Omdb
{
public class OmdbItemProvider : ICustomMetadataProvider<Series>,
ICustomMetadataProvider<Movie>, ICustomMetadataProvider<Trailer>
{
private readonly IJsonSerializer _jsonSerializer;
private readonly IHttpClient _httpClient;
public OmdbItemProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient)
{
_jsonSerializer = jsonSerializer;
_httpClient = httpClient;
}
public string Name
{
get { return "IMDb via The Open Movie Database"; }
}
public Task<ItemUpdateType> FetchAsync(Series item, IDirectoryService directoryService, CancellationToken cancellationToken)
{
return new OmdbProvider(_jsonSerializer, _httpClient).Fetch(item, cancellationToken);
}
public Task<ItemUpdateType> FetchAsync(Movie item, IDirectoryService directoryService, CancellationToken cancellationToken)
{
return new OmdbProvider(_jsonSerializer, _httpClient).Fetch(item, cancellationToken);
}
private readonly Task<ItemUpdateType> _cachedTask = Task.FromResult(ItemUpdateType.None);
public Task<ItemUpdateType> FetchAsync(Trailer item, IDirectoryService directoryService, CancellationToken cancellationToken)
{
if (item.IsLocalTrailer)
{
return _cachedTask;
}
return new OmdbProvider(_jsonSerializer, _httpClient).Fetch(item, cancellationToken);
}
}
}