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"); throw new ArgumentNullException("providerInfo");
} }
if (item.DontFetchMeta && RequiresInternet) return false;
if (CompareDate(item) > providerInfo.LastRefreshed) if (CompareDate(item) > providerInfo.LastRefreshed)
{ {
return true; return true;
@ -218,6 +220,16 @@ namespace MediaBrowser.Controller.Providers
return true; return true;
} }
if (RequiresInternet && DateTime.UtcNow > (providerInfo.LastRefreshed.AddDays(ConfigurationManager.Configuration.MetadataRefreshDays)))
{
return true;
}
if (providerInfo.LastRefreshStatus != ProviderRefreshStatus.Success)
{
return true;
}
return false; 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> /// <summary>
/// Gets a value indicating whether [requires internet]. /// Gets a value indicating whether [requires internet].
/// </summary> /// </summary>
@ -99,16 +85,6 @@ namespace MediaBrowser.Controller.Providers
get { return MetadataProviderPriority.Third; } 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 #region Result Objects
protected class FanArtImageInfo 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.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.Movies;
@ -57,7 +56,7 @@ namespace MediaBrowser.Controller.Providers.Movies
FanArtResourcePool.Dispose(); FanArtResourcePool.Dispose();
} }
} }
/// <summary> /// <summary>
/// The fan art base URL /// The fan art base URL
/// </summary> /// </summary>
@ -74,22 +73,26 @@ namespace MediaBrowser.Controller.Providers.Movies
} }
/// <summary> /// <summary>
/// Shoulds the fetch. /// Needses the refresh internal.
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
/// <param name="providerInfo">The provider info.</param> /// <param name="providerInfo">The provider info.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> /// <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 (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tmdb)))
if (item.Path == null || item.DontFetchMeta || string.IsNullOrEmpty(baseItem.GetProviderId(MetadataProviders.Tmdb))) return false; //nothing to do {
var artExists = item.ResolveArgs.ContainsMetaFileByName(ART_FILE); return false;
var logoExists = item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE); }
var discExists = item.ResolveArgs.ContainsMetaFileByName(DISC_FILE);
return (!artExists && ConfigurationManager.Configuration.DownloadMovieImages.Art) if (!ConfigurationManager.Configuration.DownloadMovieImages.Art &&
|| (!logoExists && ConfigurationManager.Configuration.DownloadMovieImages.Logo) !ConfigurationManager.Configuration.DownloadMovieImages.Logo &&
|| (!discExists && ConfigurationManager.Configuration.DownloadMovieImages.Disc); !ConfigurationManager.Configuration.DownloadMovieImages.Disc)
{
return false;
}
return base.NeedsRefreshInternal(item, providerInfo);
} }
/// <summary> /// <summary>
@ -105,157 +108,148 @@ namespace MediaBrowser.Controller.Providers.Movies
var movie = item; 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(); using (var xml = await HttpClient.Get(url, FanArtResourcePool, cancellationToken).ConfigureAwait(false))
}
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)) 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(); cancellationToken.ThrowIfCancellationRequested();
if (doc.HasChildNodes) if (ConfigurationManager.Configuration.DownloadMovieImages.Banner && !item.ResolveArgs.ContainsMetaFileByName(BANNER_FILE))
{ {
string path; var node = doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner[@lang = \"" + language + "\"]/@url") ??
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : ""; doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner/@url");
if (ConfigurationManager.Configuration.DownloadMovieImages.Logo && !item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE)) path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{ {
var node = Logger.Debug("FanArtProvider getting Banner for " + movie.Name);
doc.SelectSingleNode("//fanart/movie/movielogos/" + hd + "movielogo[@lang = \"" + language + "\"]/@url") ?? try
doc.SelectSingleNode("//fanart/movie/movielogos/movielogo[@lang = \"" + language + "\"]/@url");
if (node == null && language != "en")
{ {
//maybe just couldn't find language - try just first one movie.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(movie, path, BANNER_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
node = doc.SelectSingleNode("//fanart/movie/movielogos/" + hd + "movielogo/@url");
} }
path = node != null ? node.Value : null; catch (HttpException)
if (!string.IsNullOrEmpty(path)) {
}
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 = Logger.Debug("FanArtProvider getting Banner for " + movie.Name);
doc.SelectSingleNode("//fanart/movie/moviearts/" + hd + "movieart[@lang = \"" + language + "\"]/@url") ?? try
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); movie.SetImage(ImageType.Thumb, await _providerManager.DownloadAndSaveImage(movie, path, THUMB_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
try
{
movie.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(movie, path, ART_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
} }
} catch (HttpException)
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)
{
}
} }
} 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))
{ {
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; 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) public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{ {
var mbid = item.GetProviderId(MetadataProviders.Musicbrainz); 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.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net; using MediaBrowser.Model.Net;
@ -60,18 +58,28 @@ namespace MediaBrowser.Controller.Providers.Music
} }
/// <summary> /// <summary>
/// Shoulds the fetch. /// Needses the refresh internal.
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
/// <param name="providerInfo">The provider info.</param> /// <param name="providerInfo">The provider info.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> /// <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) if (!ConfigurationManager.Configuration.DownloadMusicArtistImages.Art &&
|| (!item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE) && ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo) !ConfigurationManager.Configuration.DownloadMusicArtistImages.Backdrops &&
|| (!item.ResolveArgs.ContainsMetaFileByName(DISC_FILE) && ConfigurationManager.Configuration.DownloadMusicArtistImages.Disc); !ConfigurationManager.Configuration.DownloadMusicArtistImages.Banner &&
!ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo &&
!ConfigurationManager.Configuration.DownloadMusicArtistImages.Primary)
{
return false;
}
return base.NeedsRefreshInternal(item, providerInfo);
} }
/// <summary> /// <summary>
@ -87,165 +95,156 @@ namespace MediaBrowser.Controller.Providers.Music
//var artist = item; //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)) cancellationToken.ThrowIfCancellationRequested();
{
var url = string.Format(FanArtBaseUrl, APIKey, item.GetProviderId(MetadataProviders.Musicbrainz));
var doc = new XmlDocument();
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(); cancellationToken.ThrowIfCancellationRequested();
if (doc.HasChildNodes) if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Art && !item.ResolveArgs.ContainsMetaFileByName(ART_FILE))
{ {
string path; var node =
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : ""; doc.SelectSingleNode("//fanart/music/musicarts/" + hd + "musicart/@url") ??
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo && !item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE)) doc.SelectSingleNode("//fanart/music/musicarts/musicart/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{ {
var node = Logger.Debug("FanArtProvider getting ClearArt for " + item.Name);
doc.SelectSingleNode("//fanart/music/musiclogos/" + hd + "musiclogo/@url") ?? try
doc.SelectSingleNode("//fanart/music/musiclogos/musiclogo/@url"); {
path = node != null ? node.Value : null; item.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(item, path, ART_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
if (!string.IsNullOrEmpty(path)) }
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"); Logger.Debug("FanArtProvider getting Banner for " + item.Name);
if (nodes != null) try
{ {
var numBackdrops = 0; item.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(item, path, BANNER_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
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)
{
}
}
}
} }
catch (HttpException)
} {
}
cancellationToken.ThrowIfCancellationRequested(); catch (IOException)
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))
{ {
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") ?? Logger.Debug("FanArtProvider getting Primary image for " + item.Name);
doc.SelectSingleNode("//fanart/music/musicbanners/musicbanner/@url"); try
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{ {
Logger.Debug("FanArtProvider getting Banner for " + item.Name); item.SetImage(ImageType.Primary, await _providerManager.DownloadAndSaveImage(item, path, PRIMARY_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
try
{
item.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(item, path, BANNER_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
} }
} catch (HttpException)
{
cancellationToken.ThrowIfCancellationRequested(); }
catch (IOException)
// 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))
{ {
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); SetLastRefreshed(item, DateTime.UtcNow);
return true; return true;
} }

View File

@ -168,36 +168,6 @@ namespace MediaBrowser.Controller.Providers.Music
return WebUtility.UrlEncode(name); 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> /// <summary>
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done /// Fetches metadata and returns true or false indicating if any work that requires persistence was done
/// </summary> /// </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.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Entities.TV;
@ -25,7 +24,7 @@ namespace MediaBrowser.Controller.Providers.TV
protected IHttpClient HttpClient { get; private set; } protected IHttpClient HttpClient { get; private set; }
private readonly IProviderManager _providerManager; private readonly IProviderManager _providerManager;
public FanArtTvProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager) public FanArtTvProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(logManager, configurationManager) : base(logManager, configurationManager)
{ {
@ -42,17 +41,27 @@ namespace MediaBrowser.Controller.Providers.TV
return item is Series; 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 if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tvdb)))
var artExists = item.ResolveArgs.ContainsMetaFileByName(ART_FILE); {
var logoExists = item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE); return false;
var thumbExists = item.ResolveArgs.ContainsMetaFileByName(THUMB_FILE); }
if (!ConfigurationManager.Configuration.DownloadSeriesImages.Art &&
!ConfigurationManager.Configuration.DownloadSeriesImages.Logo &&
!ConfigurationManager.Configuration.DownloadSeriesImages.Thumb)
{
return false;
}
return (!artExists && ConfigurationManager.Configuration.DownloadSeriesImages.Art) return base.NeedsRefreshInternal(item, providerInfo);
|| (!logoExists && ConfigurationManager.Configuration.DownloadSeriesImages.Logo)
|| (!thumbExists && ConfigurationManager.Configuration.DownloadSeriesImages.Thumb);
} }
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken) 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; 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)) cancellationToken.ThrowIfCancellationRequested();
{
string language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
string url = string.Format(FanArtBaseUrl, APIKey, series.GetProviderId(MetadataProviders.Tvdb));
var doc = new XmlDocument();
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(); cancellationToken.ThrowIfCancellationRequested();
if (doc.HasChildNodes) hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
if (ConfigurationManager.Configuration.DownloadSeriesImages.Art && !series.ResolveArgs.ContainsMetaFileByName(ART_FILE))
{ {
string path; var node = doc.SelectSingleNode("//fanart/series/" + hd + "cleararts/" + hd + "clearart[@lang = \"" + language + "\"]/@url") ??
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hdtv" : "clear"; doc.SelectSingleNode("//fanart/series/cleararts/clearart[@lang = \"" + language + "\"]/@url") ??
if (ConfigurationManager.Configuration.DownloadSeriesImages.Logo && !series.ResolveArgs.ContainsMetaFileByName(LOGO_FILE)) 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") ?? Logger.Debug("FanArtProvider getting ClearArt for " + series.Name);
doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo[@lang = \"" + language + "\"]/@url") ?? try
doc.SelectSingleNode("//fanart/series/"+hd+"logos/"+hd+"logo/@url") ?? {
doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo/@url"); series.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(series, path, ART_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 " + 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.Thumb && !series.ResolveArgs.ContainsMetaFileByName(THUMB_FILE))
if (ConfigurationManager.Configuration.DownloadSeriesImages.Art && !series.ResolveArgs.ContainsMetaFileByName(ART_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") ?? Logger.Debug("FanArtProvider getting ThumbArt for " + series.Name);
doc.SelectSingleNode("//fanart/series/cleararts/clearart[@lang = \"" + language + "\"]/@url") ?? try
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 ClearArt for " + series.Name); series.SetImage(ImageType.Disc, await _providerManager.DownloadAndSaveImage(series, path, THUMB_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
try
{
series.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(series, path, ART_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
} }
} catch (HttpException)
{
cancellationToken.ThrowIfCancellationRequested(); }
catch (IOException)
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))
{ {
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); SetLastRefreshed(series, DateTime.UtcNow);
return true; return true;
} }
} }

View File

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