2013-05-21 03:16:43 +00:00
|
|
|
|
using MediaBrowser.Common.Extensions;
|
2013-03-04 05:43:06 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-02-25 00:13:45 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-03-03 06:58:04 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-03-02 17:59:15 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Providers.TV
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class RemoteSeasonProvider
|
|
|
|
|
/// </summary>
|
|
|
|
|
class RemoteSeasonProvider : BaseMetadataProvider
|
|
|
|
|
{
|
2013-05-21 03:16:43 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _provider manager
|
|
|
|
|
/// </summary>
|
2013-03-08 05:08:27 +00:00
|
|
|
|
private readonly IProviderManager _providerManager;
|
2013-05-21 03:16:43 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="RemoteSeasonProvider"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <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>
|
2013-05-24 16:51:42 +00:00
|
|
|
|
public RemoteSeasonProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
|
2013-03-04 05:43:06 +00:00
|
|
|
|
: base(logManager, configurationManager)
|
2013-02-25 00:13:45 +00:00
|
|
|
|
{
|
2013-03-08 05:08:27 +00:00
|
|
|
|
_providerManager = providerManager;
|
2013-02-25 00:13:45 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +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>
|
|
|
|
|
public override bool Supports(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
return item is Season;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
2013-05-12 23:36:42 +00:00
|
|
|
|
// Run after fanart
|
|
|
|
|
get { return MetadataProviderPriority.Fourth; }
|
2013-02-21 01:33:05 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns true or false indicating if the provider should refresh when the contents of it's directory changes
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if [refresh on file system stamp change]; otherwise, <c>false</c>.</value>
|
2013-05-14 16:16:43 +00:00
|
|
|
|
protected override bool RefreshOnFileSystemStampChange
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return ConfigurationManager.Configuration.SaveLocalMeta;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 03:16:43 +00: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-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Needses the refresh internal.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="providerInfo">The provider info.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
|
|
|
|
{
|
2013-05-21 03:16:43 +00:00
|
|
|
|
if (GetComparisonData(item) != providerInfo.Data)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-21 03:16:43 +00:00
|
|
|
|
return true;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-28 23:39:17 +00:00
|
|
|
|
return base.NeedsRefreshInternal(item, providerInfo);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the comparison data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>Guid.</returns>
|
|
|
|
|
private Guid GetComparisonData(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
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(RemoteSeriesProvider.GetSeriesDataPath(ConfigurationManager.ApplicationPaths, seriesId), "banners.xml");
|
|
|
|
|
|
|
|
|
|
var imagesFileInfo = new FileInfo(imagesXmlPath);
|
|
|
|
|
|
|
|
|
|
return GetComparisonData(imagesFileInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Guid.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the comparison data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="imagesFileInfo">The images file info.</param>
|
|
|
|
|
/// <returns>Guid.</returns>
|
|
|
|
|
private Guid GetComparisonData(FileInfo imagesFileInfo)
|
|
|
|
|
{
|
|
|
|
|
var date = imagesFileInfo.Exists ? imagesFileInfo.LastWriteTimeUtc : DateTime.MinValue;
|
|
|
|
|
|
|
|
|
|
var key = date.Ticks + imagesFileInfo.FullName;
|
|
|
|
|
|
|
|
|
|
return key.GetMD5();
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +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-03-08 05:08:27 +00:00
|
|
|
|
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2013-02-25 00:13:45 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
var season = (Season)item;
|
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
var seriesId = season.Series != null ? season.Series.GetProviderId(MetadataProviders.Tvdb) : null;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(seriesId))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-21 03:16:43 +00:00
|
|
|
|
// Process images
|
|
|
|
|
var imagesXmlPath = Path.Combine(RemoteSeriesProvider.GetSeriesDataPath(ConfigurationManager.ApplicationPaths, seriesId), "banners.xml");
|
|
|
|
|
|
|
|
|
|
var imagesFileInfo = new FileInfo(imagesXmlPath);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
if (imagesFileInfo.Exists)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-21 03:16:43 +00:00
|
|
|
|
if (!season.HasImage(ImageType.Primary) || !season.HasImage(ImageType.Banner) || season.BackdropImagePaths.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
var xmlDoc = new XmlDocument();
|
|
|
|
|
xmlDoc.Load(imagesXmlPath);
|
2013-05-12 23:16:46 +00:00
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
await FetchImages(season, xmlDoc, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-12 23:16:46 +00:00
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
BaseProviderInfo data;
|
|
|
|
|
if (!item.ProviderData.TryGetValue(Id, out data))
|
|
|
|
|
{
|
|
|
|
|
data = new BaseProviderInfo();
|
|
|
|
|
item.ProviderData[Id] = data;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-05-21 03:16:43 +00:00
|
|
|
|
|
|
|
|
|
data.Data = GetComparisonData(imagesFileInfo);
|
2013-05-24 16:51:42 +00:00
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow);
|
|
|
|
|
return true;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-05-21 03:16:43 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2013-05-21 03:16:43 +00:00
|
|
|
|
/// Fetches the images.
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="season">The season.</param>
|
2013-05-21 03:16:43 +00:00
|
|
|
|
/// <param name="images">The images.</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
2013-05-21 03:16:43 +00:00
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
|
private async Task FetchImages(Season season, XmlDocument images, CancellationToken cancellationToken)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-21 03:16:43 +00:00
|
|
|
|
var seasonNumber = season.IndexNumber ?? -1;
|
2013-05-12 23:16:46 +00:00
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
if (seasonNumber == -1)
|
2013-05-12 23:16:46 +00:00
|
|
|
|
{
|
2013-05-21 03:16:43 +00:00
|
|
|
|
return;
|
2013-05-12 23:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
if (ConfigurationManager.Configuration.RefreshItemImages || !season.HasImage(ImageType.Primary))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-21 03:16:43 +00:00
|
|
|
|
var n = images.SelectSingleNode("//Banner[BannerType='season'][BannerType2='season'][Season='" + seasonNumber + "'][Language='" + ConfigurationManager.Configuration.PreferredMetadataLanguage + "']") ??
|
|
|
|
|
images.SelectSingleNode("//Banner[BannerType='season'][BannerType2='season'][Season='" + seasonNumber + "'][Language='en']");
|
|
|
|
|
if (n != null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-21 03:16:43 +00:00
|
|
|
|
n = n.SelectSingleNode("./BannerPath");
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
if (n != null)
|
|
|
|
|
season.PrimaryImagePath = await _providerManager.DownloadAndSaveImage(season, TVUtils.BannerUrl + n.InnerText, "folder" + Path.GetExtension(n.InnerText), ConfigurationManager.Configuration.SaveLocalMeta, RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken).ConfigureAwait(false);
|
2013-05-12 23:16:46 +00:00
|
|
|
|
}
|
2013-05-21 03:16:43 +00:00
|
|
|
|
}
|
2013-05-12 23:16:46 +00:00
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
if (ConfigurationManager.Configuration.DownloadSeasonImages.Banner && (ConfigurationManager.Configuration.RefreshItemImages || !season.HasImage(ImageType.Banner)))
|
|
|
|
|
{
|
|
|
|
|
var n = images.SelectSingleNode("//Banner[BannerType='season'][BannerType2='seasonwide'][Season='" + seasonNumber + "'][Language='" + ConfigurationManager.Configuration.PreferredMetadataLanguage + "']") ??
|
|
|
|
|
images.SelectSingleNode("//Banner[BannerType='season'][BannerType2='seasonwide'][Season='" + seasonNumber + "'][Language='en']");
|
|
|
|
|
if (n != null)
|
2013-05-12 23:16:46 +00:00
|
|
|
|
{
|
2013-05-21 03:16:43 +00:00
|
|
|
|
n = n.SelectSingleNode("./BannerPath");
|
|
|
|
|
if (n != null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-21 03:16:43 +00:00
|
|
|
|
var bannerImagePath =
|
|
|
|
|
await _providerManager.DownloadAndSaveImage(season,
|
|
|
|
|
TVUtils.BannerUrl + n.InnerText,
|
|
|
|
|
"banner" +
|
|
|
|
|
Path.GetExtension(n.InnerText),
|
|
|
|
|
ConfigurationManager.Configuration.SaveLocalMeta, RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken).
|
|
|
|
|
ConfigureAwait(false);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
season.SetImage(ImageType.Banner, bannerImagePath);
|
2013-05-12 23:16:46 +00:00
|
|
|
|
}
|
2013-05-21 03:16:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
if (ConfigurationManager.Configuration.DownloadSeasonImages.Backdrops && (ConfigurationManager.Configuration.RefreshItemImages || season.BackdropImagePaths.Count == 0))
|
|
|
|
|
{
|
|
|
|
|
var n = images.SelectSingleNode("//Banner[BannerType='fanart'][Season='" + seasonNumber + "']");
|
|
|
|
|
if (n != null)
|
|
|
|
|
{
|
|
|
|
|
n = n.SelectSingleNode("./BannerPath");
|
|
|
|
|
if (n != null)
|
2013-05-12 23:16:46 +00:00
|
|
|
|
{
|
2013-05-21 03:16:43 +00:00
|
|
|
|
season.BackdropImagePaths.Add(await _providerManager.DownloadAndSaveImage(season, TVUtils.BannerUrl + n.InnerText, "backdrop" + Path.GetExtension(n.InnerText), ConfigurationManager.Configuration.SaveLocalMeta, RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken).ConfigureAwait(false));
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|