2013-05-24 09:05:53 -07:00
|
|
|
|
using MediaBrowser.Common.Extensions;
|
2013-05-24 08:29:10 -07:00
|
|
|
|
using MediaBrowser.Common.Net;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-06-09 09:47:28 -07:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-05-24 08:29:10 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
2013-05-24 09:05:53 -07:00
|
|
|
|
using System.Globalization;
|
2013-05-24 08:29:10 -07:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
2013-06-09 09:47:28 -07:00
|
|
|
|
namespace MediaBrowser.Providers.TV
|
2013-05-24 08:29:10 -07:00
|
|
|
|
{
|
|
|
|
|
public class TvdbSeriesImageProvider : BaseMetadataProvider
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the HTTP client.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The HTTP client.</value>
|
|
|
|
|
protected IHttpClient HttpClient { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _provider manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IProviderManager _providerManager;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="TvdbSeriesImageProvider"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="httpClient">The HTTP client.</param>
|
|
|
|
|
/// <param name="logManager">The log manager.</param>
|
|
|
|
|
/// <param name="configurationManager">The configuration manager.</param>
|
|
|
|
|
/// <param name="providerManager">The provider manager.</param>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException">httpClient</exception>
|
|
|
|
|
public TvdbSeriesImageProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
|
|
|
|
|
: base(logManager, configurationManager)
|
|
|
|
|
{
|
|
|
|
|
if (httpClient == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("httpClient");
|
|
|
|
|
}
|
|
|
|
|
HttpClient = httpClient;
|
|
|
|
|
_providerManager = providerManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Supportses 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)
|
|
|
|
|
{
|
|
|
|
|
return item is Series;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
// Run after fanart
|
|
|
|
|
get { return MetadataProviderPriority.Fourth; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 18:22:21 -07:00
|
|
|
|
public override ItemUpdateType ItemUpdateType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return ItemUpdateType.ImageUpdate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 08:29:10 -07:00
|
|
|
|
/// <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>
|
|
|
|
|
/// Gets the provider version.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The provider version.</value>
|
|
|
|
|
protected override string ProviderVersion
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return "1";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-20 07:48:49 -07:00
|
|
|
|
protected override DateTime CompareDate(BaseItem item)
|
2013-05-24 08:29:10 -07:00
|
|
|
|
{
|
|
|
|
|
var seriesId = item.GetProviderId(MetadataProviders.Tvdb);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(seriesId))
|
|
|
|
|
{
|
|
|
|
|
// Process images
|
|
|
|
|
var imagesXmlPath = Path.Combine(RemoteSeriesProvider.GetSeriesDataPath(ConfigurationManager.ApplicationPaths, seriesId), "banners.xml");
|
|
|
|
|
|
|
|
|
|
var imagesFileInfo = new FileInfo(imagesXmlPath);
|
|
|
|
|
|
2013-06-20 07:48:49 -07:00
|
|
|
|
if (imagesFileInfo.Exists)
|
|
|
|
|
{
|
|
|
|
|
return imagesFileInfo.LastWriteTimeUtc;
|
|
|
|
|
}
|
2013-05-24 08:29:10 -07:00
|
|
|
|
}
|
2013-06-20 07:48:49 -07:00
|
|
|
|
|
|
|
|
|
return base.CompareDate(item);
|
2013-05-24 08:29:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
var series = (Series)item;
|
|
|
|
|
var seriesId = series.GetProviderId(MetadataProviders.Tvdb);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(seriesId))
|
|
|
|
|
{
|
|
|
|
|
// Process images
|
|
|
|
|
var imagesXmlPath = Path.Combine(RemoteSeriesProvider.GetSeriesDataPath(ConfigurationManager.ApplicationPaths, seriesId), "banners.xml");
|
|
|
|
|
|
|
|
|
|
var imagesFileInfo = new FileInfo(imagesXmlPath);
|
|
|
|
|
|
|
|
|
|
if (imagesFileInfo.Exists)
|
|
|
|
|
{
|
|
|
|
|
if (!series.HasImage(ImageType.Primary) || !series.HasImage(ImageType.Banner) || series.BackdropImagePaths.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
var xmlDoc = new XmlDocument();
|
|
|
|
|
xmlDoc.Load(imagesXmlPath);
|
|
|
|
|
|
|
|
|
|
await FetchImages(series, xmlDoc, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BaseProviderInfo data;
|
|
|
|
|
if (!item.ProviderData.TryGetValue(Id, out data))
|
|
|
|
|
{
|
|
|
|
|
data = new BaseProviderInfo();
|
|
|
|
|
item.ProviderData[Id] = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
2013-06-01 15:35:35 -07:00
|
|
|
|
|
2013-05-24 08:29:10 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches the images.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="series">The series.</param>
|
|
|
|
|
/// <param name="images">The images.</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
|
private async Task FetchImages(Series series, XmlDocument images, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2013-06-19 06:54:45 -07:00
|
|
|
|
if (!series.HasImage(ImageType.Primary))
|
2013-05-24 08:29:10 -07:00
|
|
|
|
{
|
|
|
|
|
var n = images.SelectSingleNode("//Banner[BannerType='poster']");
|
|
|
|
|
if (n != null)
|
|
|
|
|
{
|
|
|
|
|
n = n.SelectSingleNode("./BannerPath");
|
|
|
|
|
if (n != null)
|
|
|
|
|
{
|
2013-06-28 13:25:58 -07:00
|
|
|
|
var url = TVUtils.BannerUrl + n.InnerText;
|
2013-06-01 15:35:35 -07:00
|
|
|
|
|
2013-06-28 13:25:58 -07:00
|
|
|
|
await _providerManager.SaveImage(series, url, RemoteSeriesProvider.Current.TvDbResourcePool, ImageType.Primary, null, cancellationToken)
|
|
|
|
|
.ConfigureAwait(false);
|
2013-05-24 08:29:10 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-19 06:54:45 -07:00
|
|
|
|
if (ConfigurationManager.Configuration.DownloadSeriesImages.Banner && !series.HasImage(ImageType.Banner))
|
2013-05-24 08:29:10 -07:00
|
|
|
|
{
|
|
|
|
|
var n = images.SelectSingleNode("//Banner[BannerType='series']");
|
|
|
|
|
if (n != null)
|
|
|
|
|
{
|
|
|
|
|
n = n.SelectSingleNode("./BannerPath");
|
|
|
|
|
if (n != null)
|
|
|
|
|
{
|
2013-06-28 13:25:58 -07:00
|
|
|
|
var url = TVUtils.BannerUrl + n.InnerText;
|
2013-05-24 08:29:10 -07:00
|
|
|
|
|
2013-06-28 13:25:58 -07:00
|
|
|
|
await _providerManager.SaveImage(series, url, RemoteSeriesProvider.Current.TvDbResourcePool, ImageType.Banner, null, cancellationToken)
|
|
|
|
|
.ConfigureAwait(false);
|
2013-05-24 08:29:10 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-19 06:54:45 -07:00
|
|
|
|
if (series.BackdropImagePaths.Count == 0)
|
2013-05-24 08:29:10 -07:00
|
|
|
|
{
|
|
|
|
|
var bdNo = series.BackdropImagePaths.Count;
|
2013-05-24 09:05:53 -07:00
|
|
|
|
|
2013-05-24 08:29:10 -07:00
|
|
|
|
var xmlNodeList = images.SelectNodes("//Banner[BannerType='fanart']");
|
|
|
|
|
if (xmlNodeList != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (XmlNode b in xmlNodeList)
|
|
|
|
|
{
|
|
|
|
|
var p = b.SelectSingleNode("./BannerPath");
|
|
|
|
|
|
|
|
|
|
if (p != null)
|
|
|
|
|
{
|
2013-06-28 13:25:58 -07:00
|
|
|
|
var url = TVUtils.BannerUrl + p.InnerText;
|
|
|
|
|
|
|
|
|
|
await _providerManager.SaveImage(series, url, RemoteSeriesProvider.Current.TvDbResourcePool, ImageType.Backdrop, bdNo, cancellationToken)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
2013-05-24 08:29:10 -07:00
|
|
|
|
bdNo++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (series.BackdropImagePaths.Count >= ConfigurationManager.Configuration.MaxBackdrops) break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|