2013-10-31 07:03:23 -07:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-05-24 09:51:42 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-06-24 18:22:21 -07:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-06-09 09:47:28 -07:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-05-24 09:51:42 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-11-01 13:14:21 -07:00
|
|
|
|
using MediaBrowser.Model.Providers;
|
2013-05-24 09:51:42 -07:00
|
|
|
|
using System;
|
2013-11-01 13:14:21 -07:00
|
|
|
|
using System.Collections.Generic;
|
2013-05-24 09:51:42 -07:00
|
|
|
|
using System.IO;
|
2013-11-01 13:14:21 -07:00
|
|
|
|
using System.Linq;
|
2013-05-24 09:51:42 -07:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2013-11-29 23:08:14 -07:00
|
|
|
|
using MediaBrowser.Model.Net;
|
|
|
|
|
using System.Net;
|
2014-01-30 21:50:09 -07:00
|
|
|
|
using MediaBrowser.Providers.Music;
|
2013-05-24 09:51:42 -07:00
|
|
|
|
|
2013-06-09 09:47:28 -07:00
|
|
|
|
namespace MediaBrowser.Providers.TV
|
2013-05-24 09:51:42 -07:00
|
|
|
|
{
|
2013-05-24 09:53:59 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class FanArtSeasonProvider
|
|
|
|
|
/// </summary>
|
2014-01-30 21:50:09 -07:00
|
|
|
|
class FanArtSeasonProvider : BaseMetadataProvider
|
2013-05-24 09:51:42 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _provider manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IProviderManager _providerManager;
|
2013-10-31 07:03:23 -07:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2013-05-24 09:53:59 -07: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 07:03:23 -07:00
|
|
|
|
public FanArtSeasonProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager, IFileSystem fileSystem)
|
2013-05-24 09:51:42 -07:00
|
|
|
|
: base(logManager, configurationManager)
|
|
|
|
|
{
|
|
|
|
|
_providerManager = providerManager;
|
2013-10-31 07:03:23 -07:00
|
|
|
|
_fileSystem = fileSystem;
|
2013-05-24 09:51:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 18:22:21 -07:00
|
|
|
|
public override ItemUpdateType ItemUpdateType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return ItemUpdateType.ImageUpdate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 09:53:59 -07: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 09:51:42 -07:00
|
|
|
|
public override bool Supports(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
return item is Season;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-16 07:22:13 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return MetadataProviderPriority.Third; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-20 07:48:49 -07:00
|
|
|
|
protected override DateTime CompareDate(BaseItem item)
|
2013-05-24 09:51:42 -07: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 12:54:25 -07:00
|
|
|
|
var imagesXmlPath = FanArtTvProvider.Current.GetFanartXmlPath(seriesId);
|
2013-05-24 09:51:42 -07:00
|
|
|
|
|
|
|
|
|
var imagesFileInfo = new FileInfo(imagesXmlPath);
|
|
|
|
|
|
2013-06-20 07:48:49 -07:00
|
|
|
|
if (imagesFileInfo.Exists)
|
|
|
|
|
{
|
2013-10-31 07:03:23 -07:00
|
|
|
|
return _fileSystem.GetLastWriteTimeUtc(imagesFileInfo);
|
2013-06-20 07:48:49 -07:00
|
|
|
|
}
|
2013-05-24 09:51:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-20 07:48:49 -07:00
|
|
|
|
return base.CompareDate(item);
|
2013-05-24 09:51:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 09:53:59 -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>
|
2013-12-06 13:07:34 -07:00
|
|
|
|
public override async Task<bool> FetchAsync(BaseItem item, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken)
|
2013-05-24 09:51:42 -07:00
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
2013-12-15 11:33:07 -07:00
|
|
|
|
var season = (Season) item;
|
2013-05-24 09:51:42 -07:00
|
|
|
|
|
2013-12-15 11:33:07 -07:00
|
|
|
|
// Process images
|
|
|
|
|
var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, ManualFanartSeasonImageProvider.ProviderName).ConfigureAwait(false);
|
|
|
|
|
await FetchImages(season, images.ToList(), cancellationToken).ConfigureAwait(false);
|
2013-05-24 09:51:42 -07:00
|
|
|
|
|
2013-12-06 13:07:34 -07:00
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow, providerInfo);
|
2013-11-01 12:54:25 -07:00
|
|
|
|
return true;
|
2013-05-24 09:51:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches the images.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="season">The season.</param>
|
2013-11-01 13:14:21 -07:00
|
|
|
|
/// <param name="images">The images.</param>
|
2013-05-24 09:51:42 -07:00
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
2013-11-01 13:14:21 -07:00
|
|
|
|
private async Task FetchImages(Season season, List<RemoteImageInfo> images, CancellationToken cancellationToken)
|
2013-05-24 09:51:42 -07:00
|
|
|
|
{
|
2013-12-15 11:33:07 -07:00
|
|
|
|
if (ConfigurationManager.Configuration.DownloadSeasonImages.Thumb && !season.HasImage(ImageType.Thumb) && !season.LockedFields.Contains(MetadataFields.Images))
|
2013-05-24 09:51:42 -07:00
|
|
|
|
{
|
2013-11-29 23:08:14 -07:00
|
|
|
|
await SaveImage(season, images, ImageType.Thumb, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-01 13:14:21 -07:00
|
|
|
|
|
2013-11-29 23:08:14 -07: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
|
|
|
|
|
{
|
2014-01-30 21:50:09 -07:00
|
|
|
|
await _providerManager.SaveImage(item, image.Url, FanartArtistProvider.FanArtResourcePool, type, null, cancellationToken).ConfigureAwait(false);
|
2013-11-29 23:08:14 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
catch (HttpException ex)
|
2013-05-24 09:51:42 -07:00
|
|
|
|
{
|
2013-11-29 23:08:14 -07:00
|
|
|
|
// Sometimes fanart has bad url's in their xml
|
|
|
|
|
if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.NotFound)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2013-12-08 11:38:32 -07:00
|
|
|
|
break;
|
2013-05-24 09:51:42 -07: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";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|