aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Providers/TV
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-04-28 19:39:17 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-04-28 19:39:17 -0400
commit2a5ba9e707fd68f9982cbab70fa2ca323bf72242 (patch)
tree92fd42eb33b58f6ae449e3939e69e2ff30a99fef /MediaBrowser.Controller/Providers/TV
parent46a546732c70a4a7ddfff8cdd17777e071853aa2 (diff)
consolidated duplicate code
Diffstat (limited to 'MediaBrowser.Controller/Providers/TV')
-rw-r--r--MediaBrowser.Controller/Providers/TV/FanArtTVProvider.cs181
-rw-r--r--MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs16
-rw-r--r--MediaBrowser.Controller/Providers/TV/RemoteSeasonProvider.cs13
3 files changed, 97 insertions, 113 deletions
diff --git a/MediaBrowser.Controller/Providers/TV/FanArtTVProvider.cs b/MediaBrowser.Controller/Providers/TV/FanArtTVProvider.cs
index c974d58575..26053a39d6 100644
--- a/MediaBrowser.Controller/Providers/TV/FanArtTVProvider.cs
+++ b/MediaBrowser.Controller/Providers/TV/FanArtTVProvider.cs
@@ -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
{
- providerData = new BaseProviderInfo();
+ using (var xml = await HttpClient.Get(url, FanArtResourcePool, cancellationToken).ConfigureAwait(false))
+ {
+ doc.Load(xml);
+ }
}
-
- if (ShouldFetch(series, providerData))
+ catch (HttpException)
{
- 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
{
- 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)
- {
-
- }
+ series.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(series, path, ART_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
- }
-
- cancellationToken.ThrowIfCancellationRequested();
-
- hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
- if (ConfigurationManager.Configuration.DownloadSeriesImages.Art && !series.ResolveArgs.ContainsMetaFileByName(ART_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))
+ catch (HttpException)
{
- 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)
- {
-
- }
+ }
+ catch (IOException)
+ {
+
}
}
+ }
- cancellationToken.ThrowIfCancellationRequested();
+ cancellationToken.ThrowIfCancellationRequested();
- if (ConfigurationManager.Configuration.DownloadSeriesImages.Thumb && !series.ResolveArgs.ContainsMetaFileByName(THUMB_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/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)
{
- 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)
- {
-
- }
+ }
+ catch (IOException)
+ {
+
}
}
}
}
+
SetLastRefreshed(series, DateTime.UtcNow);
+
return true;
}
}
diff --git a/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs b/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs
index ba3df07b40..34c4752f9e 100644
--- a/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs
+++ b/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs
@@ -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"));
}
diff --git a/MediaBrowser.Controller/Providers/TV/RemoteSeasonProvider.cs b/MediaBrowser.Controller/Providers/TV/RemoteSeasonProvider.cs
index 9d1a7c2566..a30b8f83f0 100644
--- a/MediaBrowser.Controller/Providers/TV/RemoteSeasonProvider.cs
+++ b/MediaBrowser.Controller/Providers/TV/RemoteSeasonProvider.cs
@@ -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>