support tv banner from fanart

This commit is contained in:
Luke Pulverenti 2013-05-12 19:16:46 -04:00
parent 1f898cef2d
commit 9d24362695
3 changed files with 154 additions and 140 deletions

View File

@ -270,8 +270,8 @@ namespace MediaBrowser.Controller.Providers.Movies
cancellationToken.ThrowIfCancellationRequested();
// backdrops
if (images.backdrops != null && images.backdrops.Count > 0 && ConfigurationManager.Configuration.DownloadMovieImages.Backdrops)
// backdrops - only download if earlier providers didn't find any (fanart)
if (images.backdrops != null && images.backdrops.Count > 0 && ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && item.BackdropImagePaths.Count == 0)
{
item.BackdropImagePaths = new List<string>();

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
@ -6,7 +7,6 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
@ -53,43 +53,62 @@ namespace MediaBrowser.Controller.Providers.TV
{
return false;
}
if (!ConfigurationManager.Configuration.DownloadSeriesImages.Art &&
!ConfigurationManager.Configuration.DownloadSeriesImages.Logo &&
!ConfigurationManager.Configuration.DownloadSeriesImages.Thumb)
!ConfigurationManager.Configuration.DownloadSeriesImages.Thumb &&
!ConfigurationManager.Configuration.DownloadSeriesImages.Backdrops &&
!ConfigurationManager.Configuration.DownloadSeriesImages.Banner)
{
return false;
}
if (providerInfo.Data != GetComparisonData(item.GetProviderId(MetadataProviders.Tvdb)))
{
return true;
}
return base.NeedsRefreshInternal(item, providerInfo);
}
/// <summary>
/// Gets the comparison data.
/// </summary>
/// <returns>Guid.</returns>
private Guid GetComparisonData(string id)
{
return string.IsNullOrEmpty(id) ? Guid.Empty : id.GetMD5();
}
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var status = ProviderRefreshStatus.Success;
BaseProviderInfo data;
if (!item.ProviderData.TryGetValue(Id, out data))
{
data = new BaseProviderInfo();
item.ProviderData[Id] = data;
}
var series = (Series)item;
string language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
string url = string.Format(FanArtBaseUrl, APIKey, series.GetProviderId(MetadataProviders.Tvdb));
var doc = new XmlDocument();
try
using (var xml = await HttpClient.Get(new HttpRequestOptions
{
using (var xml = await HttpClient.Get(new HttpRequestOptions
{
Url = url,
ResourcePool = FanArtResourcePool,
CancellationToken = cancellationToken,
EnableResponseCache = true
Url = url,
ResourcePool = FanArtResourcePool,
CancellationToken = cancellationToken,
EnableResponseCache = true
}).ConfigureAwait(false))
{
doc.Load(xml);
}
}
catch (HttpException)
}).ConfigureAwait(false))
{
doc.Load(xml);
}
cancellationToken.ThrowIfCancellationRequested();
@ -114,10 +133,7 @@ namespace MediaBrowser.Controller.Providers.TV
}
catch (HttpException)
{
}
catch (IOException)
{
status = ProviderRefreshStatus.CompletedWithErrors;
}
}
}
@ -141,10 +157,7 @@ namespace MediaBrowser.Controller.Providers.TV
}
catch (HttpException)
{
}
catch (IOException)
{
status = ProviderRefreshStatus.CompletedWithErrors;
}
}
}
@ -161,20 +174,37 @@ namespace MediaBrowser.Controller.Providers.TV
Logger.Debug("FanArtProvider getting ThumbArt for " + series.Name);
try
{
series.SetImage(ImageType.Disc, await _providerManager.DownloadAndSaveImage(series, path, THUMB_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
series.SetImage(ImageType.Thumb, await _providerManager.DownloadAndSaveImage(series, path, THUMB_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
status = ProviderRefreshStatus.CompletedWithErrors;
}
catch (IOException)
{
}
}
if (ConfigurationManager.Configuration.DownloadSeriesImages.Banner && !series.ResolveArgs.ContainsMetaFileByName(BANNER_FILE))
{
var node = doc.SelectSingleNode("//fanart/series/tbbanners/tvbanner[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/tbbanners/tvbanner/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting banner for " + series.Name);
try
{
series.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(series, path, BANNER_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
status = ProviderRefreshStatus.CompletedWithErrors;
}
}
}
}
SetLastRefreshed(series, DateTime.UtcNow);
data.Data = GetComparisonData(item.GetProviderId(MetadataProviders.Tvcom));
SetLastRefreshed(series, DateTime.UtcNow, status);
return true;
}

View File

@ -105,8 +105,10 @@ namespace MediaBrowser.Controller.Providers.TV
if (seriesId != null)
{
await FetchSeasonData(season, seriesId, cancellationToken).ConfigureAwait(false);
SetLastRefreshed(item, DateTime.UtcNow);
var status = await FetchSeasonData(season, seriesId, cancellationToken).ConfigureAwait(false);
SetLastRefreshed(item, DateTime.UtcNow, status);
return true;
}
Logger.Info("Season provider unable to obtain series id for {0}", item.Path);
@ -126,10 +128,8 @@ namespace MediaBrowser.Controller.Providers.TV
/// <param name="seriesId">The series id.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
private async Task<bool> FetchSeasonData(Season season, string seriesId, CancellationToken cancellationToken)
private async Task<ProviderRefreshStatus> FetchSeasonData(Season season, string seriesId, CancellationToken cancellationToken)
{
string name = season.Name;
var seasonNumber = TVUtils.GetSeasonNumberFromPath(season.Path) ?? -1;
season.IndexNumber = seasonNumber;
@ -139,151 +139,135 @@ namespace MediaBrowser.Controller.Providers.TV
season.Name = "Specials";
}
if (!string.IsNullOrEmpty(seriesId))
var status = ProviderRefreshStatus.Success;
if (string.IsNullOrEmpty(seriesId))
{
if ((season.PrimaryImagePath == null) || (!season.HasImage(ImageType.Banner)) || (season.BackdropImagePaths == null))
return status;
}
if ((season.PrimaryImagePath == null) || (!season.HasImage(ImageType.Banner)) || (season.BackdropImagePaths == null))
{
var images = new XmlDocument();
var url = string.Format("http://www.thetvdb.com/api/" + TVUtils.TVDBApiKey + "/series/{0}/banners.xml", seriesId);
using (var imgs = await HttpClient.Get(new HttpRequestOptions
{
var images = new XmlDocument();
var url = string.Format("http://www.thetvdb.com/api/" + TVUtils.TVDBApiKey + "/series/{0}/banners.xml", seriesId);
Url = url,
ResourcePool = RemoteSeriesProvider.Current.TvDbResourcePool,
CancellationToken = cancellationToken,
EnableResponseCache = true
try
}).ConfigureAwait(false))
{
images.Load(imgs);
}
if (images.HasChildNodes)
{
if (ConfigurationManager.Configuration.RefreshItemImages || !season.HasLocalImage("folder"))
{
using (var imgs = await HttpClient.Get(new HttpRequestOptions
var n = images.SelectSingleNode("//Banner[BannerType='season'][BannerType2='season'][Season='" + seasonNumber + "']");
if (n != null)
{
Url = url,
ResourcePool = RemoteSeriesProvider.Current.TvDbResourcePool,
CancellationToken = cancellationToken,
EnableResponseCache = true
n = n.SelectSingleNode("./BannerPath");
}).ConfigureAwait(false))
{
images.Load(imgs);
try
{
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);
}
catch (HttpException)
{
status = ProviderRefreshStatus.CompletedWithErrors;
}
}
}
catch (HttpException)
{
}
if (images.HasChildNodes)
if (ConfigurationManager.Configuration.DownloadSeasonImages.Banner && (ConfigurationManager.Configuration.RefreshItemImages || !season.HasLocalImage("banner")))
{
if (ConfigurationManager.Configuration.RefreshItemImages || !season.HasLocalImage("folder"))
var n = images.SelectSingleNode("//Banner[BannerType='season'][BannerType2='seasonwide'][Season='" + seasonNumber + "']");
if (n != null)
{
var n = images.SelectSingleNode("//Banner[BannerType='season'][BannerType2='season'][Season='" + seasonNumber + "']");
n = n.SelectSingleNode("./BannerPath");
if (n != null)
{
n = n.SelectSingleNode("./BannerPath");
try
{
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);
var bannerImagePath =
await _providerManager.DownloadAndSaveImage(season,
TVUtils.BannerUrl + n.InnerText,
"banner" +
Path.GetExtension(n.InnerText),
ConfigurationManager.Configuration.SaveLocalMeta, RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken).
ConfigureAwait(false);
season.SetImage(ImageType.Banner, bannerImagePath);
}
catch (HttpException)
{
}
catch (IOException)
{
status = ProviderRefreshStatus.CompletedWithErrors;
}
}
}
}
if (ConfigurationManager.Configuration.DownloadSeasonImages.Banner && (ConfigurationManager.Configuration.RefreshItemImages || !season.HasLocalImage("banner")))
if (ConfigurationManager.Configuration.DownloadSeasonImages.Backdrops && (ConfigurationManager.Configuration.RefreshItemImages || !season.HasLocalImage("backdrop")))
{
var n = images.SelectSingleNode("//Banner[BannerType='fanart'][Season='" + seasonNumber + "']");
if (n != null)
{
var n = images.SelectSingleNode("//Banner[BannerType='season'][BannerType2='seasonwide'][Season='" + seasonNumber + "']");
n = n.SelectSingleNode("./BannerPath");
if (n != null)
{
try
{
if (season.BackdropImagePaths == null) season.BackdropImagePaths = new List<string>();
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));
}
catch (HttpException)
{
status = ProviderRefreshStatus.CompletedWithErrors;
}
}
}
else if (!ConfigurationManager.Configuration.SaveLocalMeta) //if saving local - season will inherit from series
{
// not necessarily accurate but will give a different bit of art to each season
var lst = images.SelectNodes("//Banner[BannerType='fanart']");
if (lst != null && lst.Count > 0)
{
var num = seasonNumber % lst.Count;
n = lst[num];
n = n.SelectSingleNode("./BannerPath");
if (n != null)
{
if (season.BackdropImagePaths == null)
season.BackdropImagePaths = new List<string>();
try
{
var bannerImagePath =
season.BackdropImagePaths.Add(
await _providerManager.DownloadAndSaveImage(season,
TVUtils.BannerUrl + n.InnerText,
"banner" +
Path.GetExtension(n.InnerText),
ConfigurationManager.Configuration.SaveLocalMeta, RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken).
ConfigureAwait(false);
season.SetImage(ImageType.Banner, bannerImagePath);
TVUtils.BannerUrl +
n.InnerText,
"backdrop" +
Path.GetExtension(
n.InnerText),
ConfigurationManager.Configuration.SaveLocalMeta, RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken)
.ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
}
if (ConfigurationManager.Configuration.DownloadSeasonImages.Backdrops && (ConfigurationManager.Configuration.RefreshItemImages || !season.HasLocalImage("backdrop")))
{
var n = images.SelectSingleNode("//Banner[BannerType='fanart'][Season='" + seasonNumber + "']");
if (n != null)
{
n = n.SelectSingleNode("./BannerPath");
if (n != null)
{
try
{
if (season.BackdropImagePaths == null) season.BackdropImagePaths = new List<string>();
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));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
else if (!ConfigurationManager.Configuration.SaveLocalMeta) //if saving local - season will inherit from series
{
// not necessarily accurate but will give a different bit of art to each season
var lst = images.SelectNodes("//Banner[BannerType='fanart']");
if (lst != null && lst.Count > 0)
{
var num = seasonNumber % lst.Count;
n = lst[num];
n = n.SelectSingleNode("./BannerPath");
if (n != null)
{
if (season.BackdropImagePaths == null)
season.BackdropImagePaths = new List<string>();
try
{
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));
}
catch (HttpException)
{
}
catch (IOException)
{
}
status = ProviderRefreshStatus.CompletedWithErrors;
}
}
}
}
}
}
return true;
}
return false;
return status;
}
/// <summary>