From d187b3b7dd5e683fc0c96ce212010bf4df6f5f4e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 1 Nov 2013 16:14:21 -0400 Subject: [PATCH] #606 - Add manual image selection for Seasons --- .../TV/FanArtSeasonProvider.cs | 51 +++++-------------- .../TV/ManualFanartSeasonProvider.cs | 45 ++++++++++------ 2 files changed, 41 insertions(+), 55 deletions(-) diff --git a/MediaBrowser.Providers/TV/FanArtSeasonProvider.cs b/MediaBrowser.Providers/TV/FanArtSeasonProvider.cs index 3d1d3f8b92..2a5b16bef4 100644 --- a/MediaBrowser.Providers/TV/FanArtSeasonProvider.cs +++ b/MediaBrowser.Providers/TV/FanArtSeasonProvider.cs @@ -6,11 +6,13 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Providers; using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; -using System.Xml; namespace MediaBrowser.Providers.TV { @@ -99,26 +101,10 @@ namespace MediaBrowser.Providers.TV var season = (Season)item; - var seriesId = season.Series != null ? season.Series.GetProviderId(MetadataProviders.Tvdb) : null; - - if (!string.IsNullOrEmpty(seriesId)) - { - // Process images - var imagesXmlPath = FanArtTvProvider.Current.GetFanartXmlPath(seriesId); - - var imagesFileInfo = new FileInfo(imagesXmlPath); + // Process images + var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, ManualFanartSeasonImageProvider.ProviderName).ConfigureAwait(false); - if (imagesFileInfo.Exists) - { - if (!season.HasImage(ImageType.Thumb)) - { - var xmlDoc = new XmlDocument(); - xmlDoc.Load(imagesXmlPath); - - await FetchImages(season, xmlDoc, cancellationToken).ConfigureAwait(false); - } - } - } + await FetchImages(season, images.ToList(), cancellationToken).ConfigureAwait(false); SetLastRefreshed(item, DateTime.UtcNow); return true; @@ -128,31 +114,18 @@ namespace MediaBrowser.Providers.TV /// Fetches the images. /// /// The season. - /// The doc. + /// The images. /// The cancellation token. /// Task. - private async Task FetchImages(Season season, XmlDocument doc, CancellationToken cancellationToken) + private async Task FetchImages(Season season, List images, CancellationToken cancellationToken) { - var seasonNumber = season.IndexNumber ?? -1; - - if (seasonNumber == -1) - { - return; - } - - var language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower(); - if (ConfigurationManager.Configuration.DownloadSeasonImages.Thumb && !season.HasImage(ImageType.Thumb)) { - var node = doc.SelectSingleNode("//fanart/series/seasonthumbs/seasonthumb[@lang = \"" + language + "\"][@season = \"" + seasonNumber + "\"]/@url") ?? - doc.SelectSingleNode("//fanart/series/seasonthumbs/seasonthumb[@season = \"" + seasonNumber + "\"]/@url"); - - var path = node != null ? node.Value : null; - - if (!string.IsNullOrEmpty(path)) + var image = images.FirstOrDefault(i => i.Type == ImageType.Thumb); + + if (image != null) { - await _providerManager.SaveImage(season, path, FanArtResourcePool, ImageType.Thumb, null, cancellationToken) - .ConfigureAwait(false); + await _providerManager.SaveImage(season, image.Url, FanArtResourcePool, ImageType.Thumb, null, cancellationToken).ConfigureAwait(false); } } } diff --git a/MediaBrowser.Providers/TV/ManualFanartSeasonProvider.cs b/MediaBrowser.Providers/TV/ManualFanartSeasonProvider.cs index 71b96f0372..d1d172699d 100644 --- a/MediaBrowser.Providers/TV/ManualFanartSeasonProvider.cs +++ b/MediaBrowser.Providers/TV/ManualFanartSeasonProvider.cs @@ -55,24 +55,22 @@ namespace MediaBrowser.Providers.TV var series = ((Season) item).Series; - if (series == null) + if (series != null) { - return Task.FromResult>(list); - } - - var id = series.GetProviderId(MetadataProviders.Tvdb); + var id = series.GetProviderId(MetadataProviders.Tvdb); - if (!string.IsNullOrEmpty(id) && item.IndexNumber.HasValue) - { - var xmlPath = FanArtTvProvider.Current.GetFanartXmlPath(id); - - try - { - AddImages(list, item.IndexNumber.Value, xmlPath, cancellationToken); - } - catch (FileNotFoundException) + if (!string.IsNullOrEmpty(id) && item.IndexNumber.HasValue) { - // No biggie. Don't blow up + var xmlPath = FanArtTvProvider.Current.GetFanartXmlPath(id); + + try + { + AddImages(list, item.IndexNumber.Value, xmlPath, cancellationToken); + } + catch (FileNotFoundException) + { + // No biggie. Don't blow up + } } } @@ -168,6 +166,14 @@ namespace MediaBrowser.Providers.TV } break; } + case "showbackgrounds": + { + using (var subReader = reader.ReadSubtree()) + { + PopulateImageCategory(list, subReader, cancellationToken, ImageType.Backdrop, 1920, 1080, seasonNumber); + } + break; + } default: reader.Skip(); break; @@ -189,11 +195,17 @@ namespace MediaBrowser.Providers.TV switch (reader.Name) { case "seasonthumb": + case "showbackground": { var url = reader.GetAttribute("url"); var season = reader.GetAttribute("season"); - if (!string.IsNullOrEmpty(url) && string.Equals(season, seasonNumber.ToString(_usCulture))) + int imageSeasonNumber; + + if (!string.IsNullOrEmpty(url) && + !string.IsNullOrEmpty(season) && + int.TryParse(season, NumberStyles.Any, _usCulture, out imageSeasonNumber) && + seasonNumber == imageSeasonNumber) { var likesString = reader.GetAttribute("likes"); int likes; @@ -216,6 +228,7 @@ namespace MediaBrowser.Providers.TV list.Add(info); } + break; } default: