jellyfin/MediaBrowser.Providers/TV/TvdbPersonImageProvider.cs

98 lines
3.1 KiB
C#
Raw Normal View History

2013-07-30 19:21:16 +00:00
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Providers;
2013-07-30 19:21:16 +00:00
using System;
using System.Collections.Generic;
2013-07-30 19:21:16 +00:00
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.TV
{
public class TvdbPersonImageProvider : BaseMetadataProvider
{
private readonly IProviderManager _providerManager;
public TvdbPersonImageProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
2013-07-30 19:21:16 +00:00
: base(logManager, configurationManager)
{
_providerManager = providerManager;
}
2013-09-16 17:52:14 +00:00
protected override bool RefreshOnVersionChange
{
get
{
return true;
}
}
protected override string ProviderVersion
{
get
{
return "2";
}
}
public override bool RequiresInternet
{
get
{
return true;
}
}
2013-07-30 19:21:16 +00:00
public override bool Supports(BaseItem item)
{
return item is Person;
}
/// <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)
{
if (string.IsNullOrEmpty(item.PrimaryImagePath))
{
cancellationToken.ThrowIfCancellationRequested();
2013-07-30 19:21:16 +00:00
var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, ManualTvdbPersonImageProvider.ProviderName).ConfigureAwait(false);
2013-07-30 19:21:16 +00:00
await DownloadImages(item, images.ToList(), cancellationToken).ConfigureAwait(false);
2013-07-30 19:21:16 +00:00
SetLastRefreshed(item, DateTime.UtcNow);
return true;
2013-07-30 19:21:16 +00:00
}
SetLastRefreshed(item, DateTime.UtcNow);
return true;
}
private async Task DownloadImages(BaseItem item, List<RemoteImageInfo> images, CancellationToken cancellationToken)
2013-09-15 17:34:48 +00:00
{
if (!item.HasImage(ImageType.Primary))
2013-09-15 17:34:48 +00:00
{
var image = images.FirstOrDefault(i => i.Type == ImageType.Primary);
2013-09-15 17:34:48 +00:00
if (image != null)
2013-09-15 17:34:48 +00:00
{
await _providerManager.SaveImage(item, image.Url, TvdbSeriesProvider.Current.TvDbResourcePool, ImageType.Primary, null, cancellationToken)
.ConfigureAwait(false);
2013-07-30 19:21:16 +00:00
}
}
}
public override MetadataProviderPriority Priority
{
get { return MetadataProviderPriority.Fourth; }
2013-07-30 19:21:16 +00:00
}
}
}