2013-10-31 14:03:23 +00:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
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;
|
2013-11-01 20:14:21 +00:00
|
|
|
|
using MediaBrowser.Model.Providers;
|
2013-05-24 16:51:42 +00:00
|
|
|
|
using System;
|
2013-11-01 20:14:21 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-05-24 16:51:42 +00:00
|
|
|
|
using System.IO;
|
2013-11-01 20:14:21 +00:00
|
|
|
|
using System.Linq;
|
2013-05-24 16:51:42 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2013-11-30 06:08:14 +00:00
|
|
|
|
using MediaBrowser.Model.Net;
|
|
|
|
|
using System.Net;
|
2013-05-24 16:51:42 +00:00
|
|
|
|
|
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-10-31 14:03:23 +00:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
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-10-31 14:03:23 +00:00
|
|
|
|
public FanArtSeasonProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager, IFileSystem fileSystem)
|
2013-05-24 16:51:42 +00:00
|
|
|
|
: base(logManager, configurationManager)
|
|
|
|
|
{
|
|
|
|
|
_providerManager = providerManager;
|
2013-10-31 14:03:23 +00:00
|
|
|
|
_fileSystem = fileSystem;
|
2013-05-24 16:51:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
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-10-16 14:22:13 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return MetadataProviderPriority.Third; }
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2013-11-01 19:54:25 +00:00
|
|
|
|
var imagesXmlPath = FanArtTvProvider.Current.GetFanartXmlPath(seriesId);
|
2013-05-24 16:51:42 +00:00
|
|
|
|
|
|
|
|
|
var imagesFileInfo = new FileInfo(imagesXmlPath);
|
|
|
|
|
|
2013-06-20 14:48:49 +00:00
|
|
|
|
if (imagesFileInfo.Exists)
|
|
|
|
|
{
|
2013-10-31 14:03:23 +00:00
|
|
|
|
return _fileSystem.GetLastWriteTimeUtc(imagesFileInfo);
|
2013-06-20 14:48:49 +00:00
|
|
|
|
}
|
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-12-06 20:07:34 +00:00
|
|
|
|
public override async Task<bool> FetchAsync(BaseItem item, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken)
|
2013-05-24 16:51:42 +00:00
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
var season = (Season)item;
|
|
|
|
|
|
2013-11-01 20:14:21 +00:00
|
|
|
|
// Process images
|
|
|
|
|
var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, ManualFanartSeasonImageProvider.ProviderName).ConfigureAwait(false);
|
2013-05-24 16:51:42 +00:00
|
|
|
|
|
2013-11-01 20:14:21 +00:00
|
|
|
|
await FetchImages(season, images.ToList(), cancellationToken).ConfigureAwait(false);
|
2013-05-24 16:51:42 +00:00
|
|
|
|
|
2013-12-06 20:07:34 +00:00
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow, providerInfo);
|
2013-11-01 19:54:25 +00:00
|
|
|
|
return true;
|
2013-05-24 16:51:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches the images.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="season">The season.</param>
|
2013-11-01 20:14:21 +00:00
|
|
|
|
/// <param name="images">The images.</param>
|
2013-05-24 16:51:42 +00:00
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
2013-11-01 20:14:21 +00:00
|
|
|
|
private async Task FetchImages(Season season, List<RemoteImageInfo> images, CancellationToken cancellationToken)
|
2013-05-24 16:51:42 +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
|
|
|
|
{
|
2013-11-30 06:08:14 +00:00
|
|
|
|
await SaveImage(season, images, ImageType.Thumb, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-01 20:14:21 +00:00
|
|
|
|
|
2013-11-30 06:08:14 +00:00
|
|
|
|
private async Task SaveImage(BaseItem item, List<RemoteImageInfo> images, ImageType type, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
foreach (var image in images.Where(i => i.Type == type))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, type, null, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
catch (HttpException ex)
|
2013-05-24 16:51:42 +00:00
|
|
|
|
{
|
2013-11-30 06:08:14 +00:00
|
|
|
|
// Sometimes fanart has bad url's in their xml
|
|
|
|
|
if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.NotFound)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2013-12-08 18:38:32 +00:00
|
|
|
|
break;
|
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";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|