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;
|
2013-11-05 16:08:44 +00:00
|
|
|
|
using MediaBrowser.Model.Providers;
|
2013-07-30 19:21:16 +00:00
|
|
|
|
using System;
|
2013-11-05 16:08:44 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2013-11-05 16:08:44 +00:00
|
|
|
|
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>
|
2013-12-06 20:07:34 +00:00
|
|
|
|
public override async Task<bool> FetchAsync(BaseItem item, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken)
|
2013-07-30 19:21:16 +00:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(item.PrimaryImagePath))
|
|
|
|
|
{
|
2013-11-05 16:08:44 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2013-07-30 19:21:16 +00:00
|
|
|
|
|
2013-11-05 16:08:44 +00:00
|
|
|
|
var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, ManualTvdbPersonImageProvider.ProviderName).ConfigureAwait(false);
|
2013-07-30 19:21:16 +00:00
|
|
|
|
|
2013-11-05 16:08:44 +00:00
|
|
|
|
await DownloadImages(item, images.ToList(), cancellationToken).ConfigureAwait(false);
|
2013-07-30 19:21:16 +00:00
|
|
|
|
|
2013-12-06 20:07:34 +00:00
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow, providerInfo);
|
2013-11-05 16:08:44 +00:00
|
|
|
|
return true;
|
2013-07-30 19:21:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 20:07:34 +00:00
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow, providerInfo);
|
2013-07-30 19:21:16 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-12-15 00:26:01 +00:00
|
|
|
|
|
2013-11-05 16:08:44 +00:00
|
|
|
|
private async Task DownloadImages(BaseItem item, List<RemoteImageInfo> images, CancellationToken cancellationToken)
|
2013-09-15 17:34:48 +00:00
|
|
|
|
{
|
2013-12-15 00:26:01 +00:00
|
|
|
|
if (!item.HasImage(ImageType.Primary) && !item.LockedFields.Contains(MetadataFields.Images))
|
2013-09-15 17:34:48 +00:00
|
|
|
|
{
|
2013-11-05 16:08:44 +00:00
|
|
|
|
var image = images.FirstOrDefault(i => i.Type == ImageType.Primary);
|
2013-09-15 17:34:48 +00:00
|
|
|
|
|
2013-11-05 16:08:44 +00:00
|
|
|
|
if (image != null)
|
2013-09-15 17:34:48 +00:00
|
|
|
|
{
|
2013-11-05 16:08:44 +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
|
|
|
|
|
{
|
2013-11-05 16:52:43 +00:00
|
|
|
|
get { return MetadataProviderPriority.Fourth; }
|
2013-07-30 19:21:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|