2013-09-04 17:02:19 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-05-24 16:51:42 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-06-25 01:22:21 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-06-09 16:47:28 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-05-24 16:51:42 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
2013-06-09 16:47:28 +00:00
|
|
|
|
namespace MediaBrowser.Providers.TV
|
2013-05-24 16:51:42 +00:00
|
|
|
|
{
|
2013-05-24 16:53:59 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class FanArtSeasonProvider
|
|
|
|
|
/// </summary>
|
2013-05-24 16:51:42 +00:00
|
|
|
|
class FanArtSeasonProvider : FanartBaseProvider
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _provider manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IProviderManager _providerManager;
|
2013-05-24 16:53:59 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="FanArtSeasonProvider"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logManager">The log manager.</param>
|
|
|
|
|
/// <param name="configurationManager">The configuration manager.</param>
|
|
|
|
|
/// <param name="providerManager">The provider manager.</param>
|
2013-05-24 16:51:42 +00:00
|
|
|
|
public FanArtSeasonProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
|
|
|
|
|
: base(logManager, configurationManager)
|
|
|
|
|
{
|
|
|
|
|
_providerManager = providerManager;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-25 01:22:21 +00:00
|
|
|
|
public override ItemUpdateType ItemUpdateType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return ItemUpdateType.ImageUpdate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 16:53:59 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Supportses the specified item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
2013-05-24 16:51:42 +00:00
|
|
|
|
public override bool Supports(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
return item is Season;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-20 14:48:49 +00:00
|
|
|
|
protected override DateTime CompareDate(BaseItem item)
|
2013-05-24 16:51:42 +00:00
|
|
|
|
{
|
|
|
|
|
var season = (Season)item;
|
|
|
|
|
var seriesId = season.Series != null ? season.Series.GetProviderId(MetadataProviders.Tvdb) : null;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(seriesId))
|
|
|
|
|
{
|
|
|
|
|
// Process images
|
|
|
|
|
var imagesXmlPath = Path.Combine(FanArtTvProvider.GetSeriesDataPath(ConfigurationManager.ApplicationPaths, seriesId), "fanart.xml");
|
|
|
|
|
|
|
|
|
|
var imagesFileInfo = new FileInfo(imagesXmlPath);
|
|
|
|
|
|
2013-06-20 14:48:49 +00:00
|
|
|
|
if (imagesFileInfo.Exists)
|
|
|
|
|
{
|
|
|
|
|
return imagesFileInfo.LastWriteTimeUtc;
|
|
|
|
|
}
|
2013-05-24 16:51:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-20 14:48:49 +00:00
|
|
|
|
return base.CompareDate(item);
|
2013-05-24 16:51:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 16:53:59 +00: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>
|
2013-05-24 16:51:42 +00:00
|
|
|
|
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
var season = (Season)item;
|
|
|
|
|
|
|
|
|
|
var seriesId = season.Series != null ? season.Series.GetProviderId(MetadataProviders.Tvdb) : null;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(seriesId))
|
|
|
|
|
{
|
|
|
|
|
// Process images
|
|
|
|
|
var imagesXmlPath = Path.Combine(FanArtTvProvider.GetSeriesDataPath(ConfigurationManager.ApplicationPaths, seriesId), "fanart.xml");
|
|
|
|
|
|
|
|
|
|
var imagesFileInfo = new FileInfo(imagesXmlPath);
|
|
|
|
|
|
|
|
|
|
if (imagesFileInfo.Exists)
|
|
|
|
|
{
|
2013-05-24 16:53:59 +00:00
|
|
|
|
if (!season.HasImage(ImageType.Thumb))
|
2013-05-24 16:51:42 +00:00
|
|
|
|
{
|
|
|
|
|
var xmlDoc = new XmlDocument();
|
|
|
|
|
xmlDoc.Load(imagesXmlPath);
|
|
|
|
|
|
|
|
|
|
await FetchImages(season, 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches the images.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="season">The season.</param>
|
|
|
|
|
/// <param name="doc">The doc.</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
|
private async Task FetchImages(Season season, XmlDocument doc, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var seasonNumber = season.IndexNumber ?? -1;
|
|
|
|
|
|
|
|
|
|
if (seasonNumber == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
|
2013-06-15 22:19:47 +00:00
|
|
|
|
|
2013-06-19 13:54:45 +00:00
|
|
|
|
if (ConfigurationManager.Configuration.DownloadSeasonImages.Thumb && !season.HasImage(ImageType.Thumb))
|
2013-05-24 16:51:42 +00:00
|
|
|
|
{
|
|
|
|
|
var node = doc.SelectSingleNode("//fanart/series/seasonthumbs/seasonthumb[@lang = \"" + language + "\"][@season = \"" + seasonNumber + "\"]/@url") ??
|
|
|
|
|
doc.SelectSingleNode("//fanart/series/seasonthumbs/seasonthumb[@season = \"" + seasonNumber + "\"]/@url");
|
|
|
|
|
|
|
|
|
|
var path = node != null ? node.Value : null;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(path))
|
|
|
|
|
{
|
2013-06-28 20:25:58 +00:00
|
|
|
|
await _providerManager.SaveImage(season, path, FanArtResourcePool, ImageType.Thumb, null, cancellationToken)
|
|
|
|
|
.ConfigureAwait(false);
|
2013-05-24 16:51:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
/// Gets the provider version.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The provider version.</value>
|
|
|
|
|
protected override string ProviderVersion
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return "3";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|