diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-04-28 19:39:17 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-04-28 19:39:17 -0400 |
| commit | 2a5ba9e707fd68f9982cbab70fa2ca323bf72242 (patch) | |
| tree | 92fd42eb33b58f6ae449e3939e69e2ff30a99fef /MediaBrowser.Controller/Providers/Music | |
| parent | 46a546732c70a4a7ddfff8cdd17777e071853aa2 (diff) | |
consolidated duplicate code
Diffstat (limited to 'MediaBrowser.Controller/Providers/Music')
3 files changed, 123 insertions, 167 deletions
diff --git a/MediaBrowser.Controller/Providers/Music/FanArtAlbumProvider.cs b/MediaBrowser.Controller/Providers/Music/FanArtAlbumProvider.cs index 4d7f78413d..ac9d0ae540 100644 --- a/MediaBrowser.Controller/Providers/Music/FanArtAlbumProvider.cs +++ b/MediaBrowser.Controller/Providers/Music/FanArtAlbumProvider.cs @@ -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); diff --git a/MediaBrowser.Controller/Providers/Music/FanArtArtistProvider.cs b/MediaBrowser.Controller/Providers/Music/FanArtArtistProvider.cs index 1d4d811b65..ba07da2c12 100644 --- a/MediaBrowser.Controller/Providers/Music/FanArtArtistProvider.cs +++ b/MediaBrowser.Controller/Providers/Music/FanArtArtistProvider.cs @@ -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; + } + + if (!ConfigurationManager.Configuration.DownloadMusicArtistImages.Art && + !ConfigurationManager.Configuration.DownloadMusicArtistImages.Backdrops && + !ConfigurationManager.Configuration.DownloadMusicArtistImages.Banner && + !ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo && + !ConfigurationManager.Configuration.DownloadMusicArtistImages.Primary) + { + 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); + 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 { - providerData = new BaseProviderInfo(); - } - - if (ShouldFetch(item, providerData)) - { - var url = string.Format(FanArtBaseUrl, APIKey, item.GetProviderId(MetadataProviders.Musicbrainz)); - var doc = new XmlDocument(); - - try - { - using (var xml = await HttpClient.Get(url, FanArtResourcePool, cancellationToken).ConfigureAwait(false)) - { - doc.Load(xml); - } - } - catch (HttpException) + using (var xml = await HttpClient.Get(url, FanArtResourcePool, cancellationToken).ConfigureAwait(false)) { + doc.Load(xml); } + } + catch (HttpException) + { + } - cancellationToken.ThrowIfCancellationRequested(); + cancellationToken.ThrowIfCancellationRequested(); - if (doc.HasChildNodes) + if (doc.HasChildNodes) + { + string path; + var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : ""; + if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo && !item.ResolveArgs.ContainsMetaFileByName(LOGO_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/musiclogos/" + hd + "musiclogo/@url") ?? + doc.SelectSingleNode("//fanart/music/musiclogos/musiclogo/@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 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) { - 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.Backdrops && !item.ResolveArgs.ContainsMetaFileByName(BACKDROP_FILE)) + { + var nodes = doc.SelectNodes("//fanart/music/artistbackgrounds//@url"); + if (nodes != null) { - var nodes = doc.SelectNodes("//fanart/music/artistbackgrounds//@url"); - if (nodes != null) + var numBackdrops = 0; + item.BackdropImagePaths = new List<string>(); + foreach (XmlNode node in nodes) { - var numBackdrops = 0; - item.BackdropImagePaths = new List<string>(); - foreach (XmlNode node in nodes) + path = node.Value; + if (!string.IsNullOrEmpty(path)) { - path = node.Value; - if (!string.IsNullOrEmpty(path)) + Logger.Debug("FanArtProvider getting Backdrop for " + item.Name); + try { - 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.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 (ConfigurationManager.Configuration.DownloadMusicArtistImages.Art && !item.ResolveArgs.ContainsMetaFileByName(ART_FILE)) + 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)) { - 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) { - 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(); + } + cancellationToken.ThrowIfCancellationRequested(); - if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Banner && !item.ResolveArgs.ContainsMetaFileByName(BANNER_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 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 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) { - 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) - { - } } } + } - cancellationToken.ThrowIfCancellationRequested(); + cancellationToken.ThrowIfCancellationRequested(); - // Artist thumbs are actually primary images (they are square/portrait) - if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Primary && !item.ResolveArgs.ContainsMetaFileByName(PRIMARY_FILE)) + // 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/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) { - 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; } diff --git a/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs index fefd6eed6f..f8c9685f77 100644 --- a/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs +++ b/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs @@ -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> |
