consolidated duplicate code

This commit is contained in:
Luke Pulverenti 2013-04-28 19:39:17 -04:00
parent 46a546732c
commit 2a5ba9e707
9 changed files with 367 additions and 445 deletions

View File

@ -203,6 +203,8 @@ namespace MediaBrowser.Controller.Providers
throw new ArgumentNullException("providerInfo");
}
if (item.DontFetchMeta && RequiresInternet) return false;
if (CompareDate(item) > providerInfo.LastRefreshed)
{
return true;
@ -218,6 +220,16 @@ namespace MediaBrowser.Controller.Providers
return true;
}
if (RequiresInternet && DateTime.UtcNow > (providerInfo.LastRefreshed.AddDays(ConfigurationManager.Configuration.MetadataRefreshDays)))
{
return true;
}
if (providerInfo.LastRefreshStatus != ProviderRefreshStatus.Success)
{
return true;
}
return false;
}

View File

@ -67,20 +67,6 @@ namespace MediaBrowser.Controller.Providers
{
}
/// <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)
{
if (item.DontFetchMeta) return false;
return DateTime.UtcNow > (providerInfo.LastRefreshed.AddDays(ConfigurationManager.Configuration.MetadataRefreshDays))
&& ShouldFetch(item, providerInfo);
}
/// <summary>
/// Gets a value indicating whether [requires internet].
/// </summary>
@ -99,16 +85,6 @@ namespace MediaBrowser.Controller.Providers
get { return MetadataProviderPriority.Third; }
}
/// <summary>
/// Shoulds the fetch.
/// </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 virtual bool ShouldFetch(BaseItem item, BaseProviderInfo providerInfo)
{
return false;
}
#region Result Objects
protected class FanArtImageInfo

View File

@ -1,5 +1,4 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
@ -57,7 +56,7 @@ namespace MediaBrowser.Controller.Providers.Movies
FanArtResourcePool.Dispose();
}
}
/// <summary>
/// The fan art base URL
/// </summary>
@ -74,22 +73,26 @@ namespace MediaBrowser.Controller.Providers.Movies
}
/// <summary>
/// Shoulds the fetch.
/// 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 ShouldFetch(BaseItem item, BaseProviderInfo providerInfo)
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
{
var baseItem = item;
if (item.Path == null || item.DontFetchMeta || string.IsNullOrEmpty(baseItem.GetProviderId(MetadataProviders.Tmdb))) return false; //nothing to do
var artExists = item.ResolveArgs.ContainsMetaFileByName(ART_FILE);
var logoExists = item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE);
var discExists = item.ResolveArgs.ContainsMetaFileByName(DISC_FILE);
if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tmdb)))
{
return false;
}
return (!artExists && ConfigurationManager.Configuration.DownloadMovieImages.Art)
|| (!logoExists && ConfigurationManager.Configuration.DownloadMovieImages.Logo)
|| (!discExists && ConfigurationManager.Configuration.DownloadMovieImages.Disc);
if (!ConfigurationManager.Configuration.DownloadMovieImages.Art &&
!ConfigurationManager.Configuration.DownloadMovieImages.Logo &&
!ConfigurationManager.Configuration.DownloadMovieImages.Disc)
{
return false;
}
return base.NeedsRefreshInternal(item, providerInfo);
}
/// <summary>
@ -105,157 +108,148 @@ namespace MediaBrowser.Controller.Providers.Movies
var movie = item;
BaseProviderInfo providerData;
var language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
var url = string.Format(FanArtBaseUrl, APIKey, movie.GetProviderId(MetadataProviders.Tmdb));
var doc = new XmlDocument();
if (!item.ProviderData.TryGetValue(Id, out providerData))
try
{
providerData = new BaseProviderInfo();
}
if (ShouldFetch(movie, providerData))
{
var language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
var url = string.Format(FanArtBaseUrl, APIKey, movie.GetProviderId(MetadataProviders.Tmdb));
var doc = new XmlDocument();
try
using (var xml = await HttpClient.Get(url, FanArtResourcePool, cancellationToken).ConfigureAwait(false))
{
using (var xml = await HttpClient.Get(url, FanArtResourcePool, cancellationToken).ConfigureAwait(false))
doc.Load(xml);
}
}
catch (HttpException)
{
}
cancellationToken.ThrowIfCancellationRequested();
if (doc.HasChildNodes)
{
string path;
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
if (ConfigurationManager.Configuration.DownloadMovieImages.Logo && !item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE))
{
var node =
doc.SelectSingleNode("//fanart/movie/movielogos/" + hd + "movielogo[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/movielogos/movielogo[@lang = \"" + language + "\"]/@url");
if (node == null && language != "en")
{
doc.Load(xml);
//maybe just couldn't find language - try just first one
node = doc.SelectSingleNode("//fanart/movie/movielogos/" + hd + "movielogo/@url");
}
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting ClearLogo for " + movie.Name);
try
{
movie.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(movie, path, LOGO_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
catch (HttpException)
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadMovieImages.Art && !item.ResolveArgs.ContainsMetaFileByName(ART_FILE))
{
var node =
doc.SelectSingleNode("//fanart/movie/moviearts/" + hd + "movieart[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/moviearts/" + hd + "movieart/@url") ??
doc.SelectSingleNode("//fanart/movie/moviearts/movieart[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/moviearts/movieart/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting ClearArt for " + movie.Name);
try
{
movie.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(movie, path, ART_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadMovieImages.Disc && !item.ResolveArgs.ContainsMetaFileByName(DISC_FILE))
{
var node = doc.SelectSingleNode("//fanart/movie/moviediscs/moviedisc[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/moviediscs/moviedisc/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting DiscArt for " + movie.Name);
try
{
movie.SetImage(ImageType.Disc, await _providerManager.DownloadAndSaveImage(movie, path, DISC_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
cancellationToken.ThrowIfCancellationRequested();
if (doc.HasChildNodes)
if (ConfigurationManager.Configuration.DownloadMovieImages.Banner && !item.ResolveArgs.ContainsMetaFileByName(BANNER_FILE))
{
string path;
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
if (ConfigurationManager.Configuration.DownloadMovieImages.Logo && !item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE))
var node = doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
var node =
doc.SelectSingleNode("//fanart/movie/movielogos/" + hd + "movielogo[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/movielogos/movielogo[@lang = \"" + language + "\"]/@url");
if (node == null && language != "en")
Logger.Debug("FanArtProvider getting Banner for " + movie.Name);
try
{
//maybe just couldn't find language - try just first one
node = doc.SelectSingleNode("//fanart/movie/movielogos/" + hd + "movielogo/@url");
movie.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(movie, path, BANNER_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
catch (HttpException)
{
}
catch (IOException)
{
Logger.Debug("FanArtProvider getting ClearLogo for " + movie.Name);
try
{
movie.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(movie, path, LOGO_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
cancellationToken.ThrowIfCancellationRequested();
}
if (ConfigurationManager.Configuration.DownloadMovieImages.Art && !item.ResolveArgs.ContainsMetaFileByName(ART_FILE))
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadMovieImages.Thumb && !item.ResolveArgs.ContainsMetaFileByName(THUMB_FILE))
{
var node = doc.SelectSingleNode("//fanart/movie/moviethumbs/moviethumb[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/moviethumbs/moviethumb/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
var node =
doc.SelectSingleNode("//fanart/movie/moviearts/" + hd + "movieart[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/moviearts/" + hd + "movieart/@url") ??
doc.SelectSingleNode("//fanart/movie/moviearts/movieart[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/moviearts/movieart/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
Logger.Debug("FanArtProvider getting Banner for " + movie.Name);
try
{
Logger.Debug("FanArtProvider getting ClearArt for " + movie.Name);
try
{
movie.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(movie, path, ART_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
movie.SetImage(ImageType.Thumb, await _providerManager.DownloadAndSaveImage(movie, path, THUMB_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadMovieImages.Disc && !item.ResolveArgs.ContainsMetaFileByName(DISC_FILE))
{
var node = doc.SelectSingleNode("//fanart/movie/moviediscs/moviedisc[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/moviediscs/moviedisc/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
catch (HttpException)
{
Logger.Debug("FanArtProvider getting DiscArt for " + movie.Name);
try
{
movie.SetImage(ImageType.Disc, await _providerManager.DownloadAndSaveImage(movie, path, DISC_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadMovieImages.Banner && !item.ResolveArgs.ContainsMetaFileByName(BANNER_FILE))
{
var node = doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
catch (IOException)
{
Logger.Debug("FanArtProvider getting Banner for " + movie.Name);
try
{
movie.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(movie, path, BANNER_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadMovieImages.Thumb && !item.ResolveArgs.ContainsMetaFileByName(THUMB_FILE))
{
var node = doc.SelectSingleNode("//fanart/movie/moviethumbs/moviethumb[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/moviethumbs/moviethumb/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting Banner for " + movie.Name);
try
{
movie.SetImage(ImageType.Thumb, await _providerManager.DownloadAndSaveImage(movie, path, THUMB_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
}

View File

@ -31,19 +31,6 @@ namespace MediaBrowser.Controller.Providers.Music
return item is MusicAlbum;
}
/// <summary>
/// Needses the refresh internal.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="providerInfo">The provider info.</param>
/// <returns><c>true</c> if we need refreshing, <c>false</c> otherwise</returns>
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
{
//we fetch if image needed and haven't already tried recently
return (string.IsNullOrEmpty(item.PrimaryImagePath) || !item.HasImage(ImageType.Disc)) &&
DateTime.Today.Subtract(providerInfo.LastRefreshed).TotalDays > ConfigurationManager.Configuration.MetadataRefreshDays;
}
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
var mbid = item.GetProviderId(MetadataProviders.Musicbrainz);

View File

@ -1,8 +1,6 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
@ -60,18 +58,28 @@ namespace MediaBrowser.Controller.Providers.Music
}
/// <summary>
/// Shoulds the fetch.
/// 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 ShouldFetch(BaseItem item, BaseProviderInfo providerInfo)
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
{
if (item.Path == null || item.DontFetchMeta || string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Musicbrainz))) return false; //nothing to do
if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Musicbrainz)))
{
return false;
}
return (!item.ResolveArgs.ContainsMetaFileByName(ART_FILE) && ConfigurationManager.Configuration.DownloadMusicArtistImages.Art)
|| (!item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE) && ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo)
|| (!item.ResolveArgs.ContainsMetaFileByName(DISC_FILE) && ConfigurationManager.Configuration.DownloadMusicArtistImages.Disc);
if (!ConfigurationManager.Configuration.DownloadMusicArtistImages.Art &&
!ConfigurationManager.Configuration.DownloadMusicArtistImages.Backdrops &&
!ConfigurationManager.Configuration.DownloadMusicArtistImages.Banner &&
!ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo &&
!ConfigurationManager.Configuration.DownloadMusicArtistImages.Primary)
{
return false;
}
return base.NeedsRefreshInternal(item, providerInfo);
}
/// <summary>
@ -87,165 +95,156 @@ namespace MediaBrowser.Controller.Providers.Music
//var artist = item;
BaseProviderInfo providerData;
var url = string.Format(FanArtBaseUrl, APIKey, item.GetProviderId(MetadataProviders.Musicbrainz));
var doc = new XmlDocument();
if (!item.ProviderData.TryGetValue(Id, out providerData))
try
{
using (var xml = await HttpClient.Get(url, FanArtResourcePool, cancellationToken).ConfigureAwait(false))
{
doc.Load(xml);
}
}
catch (HttpException)
{
providerData = new BaseProviderInfo();
}
if (ShouldFetch(item, providerData))
{
var url = string.Format(FanArtBaseUrl, APIKey, item.GetProviderId(MetadataProviders.Musicbrainz));
var doc = new XmlDocument();
cancellationToken.ThrowIfCancellationRequested();
try
if (doc.HasChildNodes)
{
string path;
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo && !item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE))
{
using (var xml = await HttpClient.Get(url, FanArtResourcePool, cancellationToken).ConfigureAwait(false))
var node =
doc.SelectSingleNode("//fanart/music/musiclogos/" + hd + "musiclogo/@url") ??
doc.SelectSingleNode("//fanart/music/musiclogos/musiclogo/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
doc.Load(xml);
Logger.Debug("FanArtProvider getting ClearLogo for " + item.Name);
try
{
item.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(item, path, LOGO_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
catch (HttpException)
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Backdrops && !item.ResolveArgs.ContainsMetaFileByName(BACKDROP_FILE))
{
var nodes = doc.SelectNodes("//fanart/music/artistbackgrounds//@url");
if (nodes != null)
{
var numBackdrops = 0;
item.BackdropImagePaths = new List<string>();
foreach (XmlNode node in nodes)
{
path = node.Value;
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting Backdrop for " + item.Name);
try
{
item.BackdropImagePaths.Add(await _providerManager.DownloadAndSaveImage(item, path, ("Backdrop" + (numBackdrops > 0 ? numBackdrops.ToString() : "") + ".jpg"), SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
numBackdrops++;
if (numBackdrops >= ConfigurationManager.Configuration.MaxBackdrops) break;
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
}
}
cancellationToken.ThrowIfCancellationRequested();
if (doc.HasChildNodes)
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Art && !item.ResolveArgs.ContainsMetaFileByName(ART_FILE))
{
string path;
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo && !item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE))
var node =
doc.SelectSingleNode("//fanart/music/musicarts/" + hd + "musicart/@url") ??
doc.SelectSingleNode("//fanart/music/musicarts/musicart/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
var node =
doc.SelectSingleNode("//fanart/music/musiclogos/" + hd + "musiclogo/@url") ??
doc.SelectSingleNode("//fanart/music/musiclogos/musiclogo/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
Logger.Debug("FanArtProvider getting ClearArt for " + item.Name);
try
{
item.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(item, path, ART_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
Logger.Debug("FanArtProvider getting ClearLogo for " + item.Name);
try
{
item.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(item, path, LOGO_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
cancellationToken.ThrowIfCancellationRequested();
}
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Backdrops && !item.ResolveArgs.ContainsMetaFileByName(BACKDROP_FILE))
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Banner && !item.ResolveArgs.ContainsMetaFileByName(BANNER_FILE))
{
var node = doc.SelectSingleNode("//fanart/music/musicbanners/" + hd + "musicbanner/@url") ??
doc.SelectSingleNode("//fanart/music/musicbanners/musicbanner/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
var nodes = doc.SelectNodes("//fanart/music/artistbackgrounds//@url");
if (nodes != null)
Logger.Debug("FanArtProvider getting Banner for " + item.Name);
try
{
var numBackdrops = 0;
item.BackdropImagePaths = new List<string>();
foreach (XmlNode node in nodes)
{
path = node.Value;
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting Backdrop for " + item.Name);
try
{
item.BackdropImagePaths.Add(await _providerManager.DownloadAndSaveImage(item, path, ("Backdrop" + (numBackdrops > 0 ? numBackdrops.ToString() : "") + ".jpg"), SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
numBackdrops++;
if (numBackdrops >= ConfigurationManager.Configuration.MaxBackdrops) break;
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
item.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(item, path, BANNER_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Art && !item.ResolveArgs.ContainsMetaFileByName(ART_FILE))
{
var node =
doc.SelectSingleNode("//fanart/music/musicarts/" + hd + "musicart/@url") ??
doc.SelectSingleNode("//fanart/music/musicarts/musicart/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
catch (HttpException)
{
}
catch (IOException)
{
Logger.Debug("FanArtProvider getting ClearArt for " + item.Name);
try
{
item.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(item, path, ART_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
cancellationToken.ThrowIfCancellationRequested();
}
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Banner && !item.ResolveArgs.ContainsMetaFileByName(BANNER_FILE))
cancellationToken.ThrowIfCancellationRequested();
// Artist thumbs are actually primary images (they are square/portrait)
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Primary && !item.ResolveArgs.ContainsMetaFileByName(PRIMARY_FILE))
{
var node = doc.SelectSingleNode("//fanart/music/artistthumbs/artistthumb/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
var node = doc.SelectSingleNode("//fanart/music/musicbanners/"+hd+"musicbanner/@url") ??
doc.SelectSingleNode("//fanart/music/musicbanners/musicbanner/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
Logger.Debug("FanArtProvider getting Primary image for " + item.Name);
try
{
Logger.Debug("FanArtProvider getting Banner for " + item.Name);
try
{
item.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(item, path, BANNER_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
item.SetImage(ImageType.Primary, await _providerManager.DownloadAndSaveImage(item, path, PRIMARY_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
cancellationToken.ThrowIfCancellationRequested();
// Artist thumbs are actually primary images (they are square/portrait)
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Primary && !item.ResolveArgs.ContainsMetaFileByName(PRIMARY_FILE))
{
var node = doc.SelectSingleNode("//fanart/music/artistthumbs/artistthumb/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
catch (HttpException)
{
}
catch (IOException)
{
Logger.Debug("FanArtProvider getting Primary image for " + item.Name);
try
{
item.SetImage(ImageType.Primary, await _providerManager.DownloadAndSaveImage(item, path, PRIMARY_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
}
}
SetLastRefreshed(item, DateTime.UtcNow);
return true;
}

View File

@ -168,36 +168,6 @@ namespace MediaBrowser.Controller.Providers.Music
return WebUtility.UrlEncode(name);
}
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
{
if (item.DontFetchMeta) return false;
if (RefreshOnFileSystemStampChange && HasFileSystemStampChanged(item, providerInfo))
{
//If they deleted something from file system, chances are, this item was mis-identified the first time
item.SetProviderId(MetadataProviders.Musicbrainz, null);
Logger.Debug("LastfmProvider reports file system stamp change...");
return true;
}
if (providerInfo.LastRefreshStatus != ProviderRefreshStatus.Success)
{
Logger.Debug("LastfmProvider for {0} - last attempt had errors. Will try again.", item.Path);
return true;
}
if (RefreshOnVersionChange && ProviderVersion != providerInfo.ProviderVersion)
{
Logger.Debug("LastfmProvider version change re-running for {0}", item.Path);
return true;
}
if (DateTime.UtcNow.Subtract(providerInfo.LastRefreshed).TotalDays > ConfigurationManager.Configuration.MetadataRefreshDays) // only refresh every n days
return true;
return false;
}
/// <summary>
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
/// </summary>

View File

@ -1,5 +1,4 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
@ -25,7 +24,7 @@ namespace MediaBrowser.Controller.Providers.TV
protected IHttpClient HttpClient { get; private set; }
private readonly IProviderManager _providerManager;
public FanArtTvProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(logManager, configurationManager)
{
@ -42,17 +41,27 @@ namespace MediaBrowser.Controller.Providers.TV
return item is Series;
}
protected override bool ShouldFetch(BaseItem item, BaseProviderInfo providerInfo)
/// <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)
{
if (item.DontFetchMeta || string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tvdb))) return false; //nothing to do
var artExists = item.ResolveArgs.ContainsMetaFileByName(ART_FILE);
var logoExists = item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE);
var thumbExists = item.ResolveArgs.ContainsMetaFileByName(THUMB_FILE);
if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tvdb)))
{
return false;
}
if (!ConfigurationManager.Configuration.DownloadSeriesImages.Art &&
!ConfigurationManager.Configuration.DownloadSeriesImages.Logo &&
!ConfigurationManager.Configuration.DownloadSeriesImages.Thumb)
{
return false;
}
return (!artExists && ConfigurationManager.Configuration.DownloadSeriesImages.Art)
|| (!logoExists && ConfigurationManager.Configuration.DownloadSeriesImages.Logo)
|| (!thumbExists && ConfigurationManager.Configuration.DownloadSeriesImages.Thumb);
return base.NeedsRefreshInternal(item, providerInfo);
}
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
@ -61,113 +70,105 @@ namespace MediaBrowser.Controller.Providers.TV
var series = (Series)item;
BaseProviderInfo providerData;
string language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
string url = string.Format(FanArtBaseUrl, APIKey, series.GetProviderId(MetadataProviders.Tvdb));
var doc = new XmlDocument();
if (!item.ProviderData.TryGetValue(Id, out providerData))
try
{
using (var xml = await HttpClient.Get(url, FanArtResourcePool, cancellationToken).ConfigureAwait(false))
{
doc.Load(xml);
}
}
catch (HttpException)
{
providerData = new BaseProviderInfo();
}
if (ShouldFetch(series, providerData))
{
string language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
string url = string.Format(FanArtBaseUrl, APIKey, series.GetProviderId(MetadataProviders.Tvdb));
var doc = new XmlDocument();
cancellationToken.ThrowIfCancellationRequested();
try
if (doc.HasChildNodes)
{
string path;
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hdtv" : "clear";
if (ConfigurationManager.Configuration.DownloadSeriesImages.Logo && !series.ResolveArgs.ContainsMetaFileByName(LOGO_FILE))
{
using (var xml = await HttpClient.Get(url, FanArtResourcePool, cancellationToken).ConfigureAwait(false))
var node = doc.SelectSingleNode("//fanart/series/" + hd + "logos/" + hd + "logo[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/" + hd + "logos/" + hd + "logo/@url") ??
doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
doc.Load(xml);
Logger.Debug("FanArtProvider getting ClearLogo for " + series.Name);
try
{
series.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(series, path, LOGO_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
catch (HttpException)
{
}
cancellationToken.ThrowIfCancellationRequested();
if (doc.HasChildNodes)
hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
if (ConfigurationManager.Configuration.DownloadSeriesImages.Art && !series.ResolveArgs.ContainsMetaFileByName(ART_FILE))
{
string path;
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hdtv" : "clear";
if (ConfigurationManager.Configuration.DownloadSeriesImages.Logo && !series.ResolveArgs.ContainsMetaFileByName(LOGO_FILE))
var node = doc.SelectSingleNode("//fanart/series/" + hd + "cleararts/" + hd + "clearart[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/cleararts/clearart[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/" + hd + "cleararts/" + hd + "clearart/@url") ??
doc.SelectSingleNode("//fanart/series/cleararts/clearart/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
var node = doc.SelectSingleNode("//fanart/series/"+hd+"logos/"+hd+"logo[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/"+hd+"logos/"+hd+"logo/@url") ??
doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
Logger.Debug("FanArtProvider getting ClearArt for " + series.Name);
try
{
series.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(series, path, ART_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
Logger.Debug("FanArtProvider getting ClearLogo for " + series.Name);
try
{
series.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(series, path, LOGO_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
}
cancellationToken.ThrowIfCancellationRequested();
cancellationToken.ThrowIfCancellationRequested();
hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
if (ConfigurationManager.Configuration.DownloadSeriesImages.Art && !series.ResolveArgs.ContainsMetaFileByName(ART_FILE))
if (ConfigurationManager.Configuration.DownloadSeriesImages.Thumb && !series.ResolveArgs.ContainsMetaFileByName(THUMB_FILE))
{
var node = doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
var node = doc.SelectSingleNode("//fanart/series/"+hd+"cleararts/"+hd+"clearart[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/cleararts/clearart[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/"+hd+"cleararts/"+hd+"clearart/@url") ??
doc.SelectSingleNode("//fanart/series/cleararts/clearart/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
Logger.Debug("FanArtProvider getting ThumbArt for " + series.Name);
try
{
Logger.Debug("FanArtProvider getting ClearArt for " + series.Name);
try
{
series.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(series, path, ART_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
series.SetImage(ImageType.Disc, await _providerManager.DownloadAndSaveImage(series, path, THUMB_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadSeriesImages.Thumb && !series.ResolveArgs.ContainsMetaFileByName(THUMB_FILE))
{
var node = doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
catch (HttpException)
{
}
catch (IOException)
{
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));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
}
}
SetLastRefreshed(series, DateTime.UtcNow);
return true;
}
}

View File

@ -96,22 +96,12 @@ namespace MediaBrowser.Controller.Providers.TV
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
{
bool fetch = false;
var episode = (Episode)item;
var downloadDate = providerInfo.LastRefreshed;
if (ConfigurationManager.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue)
if (HasLocalMeta(item))
{
return false;
}
if (!item.DontFetchMeta && !HasLocalMeta(episode))
{
fetch = ConfigurationManager.Configuration.MetadataRefreshDays != -1 &&
DateTime.Today.Subtract(downloadDate).TotalDays > ConfigurationManager.Configuration.MetadataRefreshDays;
}
return fetch;
return base.NeedsRefreshInternal(item, providerInfo);
}
/// <summary>
@ -313,7 +303,7 @@ namespace MediaBrowser.Controller.Providers.TV
/// </summary>
/// <param name="episode">The episode.</param>
/// <returns><c>true</c> if [has local meta] [the specified episode]; otherwise, <c>false</c>.</returns>
private bool HasLocalMeta(Episode episode)
private bool HasLocalMeta(BaseItem episode)
{
return (episode.Parent.ResolveArgs.ContainsMetaFileByName(Path.GetFileNameWithoutExtension(episode.Path) + ".xml"));
}

View File

@ -78,19 +78,12 @@ namespace MediaBrowser.Controller.Providers.TV
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
{
bool fetch = false;
var downloadDate = providerInfo.LastRefreshed;
if (ConfigurationManager.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue)
return false;
if (!HasLocalMeta(item))
if (HasLocalMeta(item))
{
fetch = ConfigurationManager.Configuration.MetadataRefreshDays != -1 &&
DateTime.UtcNow.Subtract(downloadDate).TotalDays > ConfigurationManager.Configuration.MetadataRefreshDays;
return false;
}
return fetch;
return base.NeedsRefreshInternal(item, providerInfo);
}
/// <summary>