#606 - Add manual image selection for Seasons

This commit is contained in:
Luke Pulverenti 2013-11-01 16:14:21 -04:00
parent 0c93447380
commit d187b3b7dd
2 changed files with 41 additions and 55 deletions

View File

@ -6,11 +6,13 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Providers;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml;
namespace MediaBrowser.Providers.TV namespace MediaBrowser.Providers.TV
{ {
@ -99,26 +101,10 @@ namespace MediaBrowser.Providers.TV
var season = (Season)item; var season = (Season)item;
var seriesId = season.Series != null ? season.Series.GetProviderId(MetadataProviders.Tvdb) : null;
if (!string.IsNullOrEmpty(seriesId))
{
// Process images // Process images
var imagesXmlPath = FanArtTvProvider.Current.GetFanartXmlPath(seriesId); var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, ManualFanartSeasonImageProvider.ProviderName).ConfigureAwait(false);
var imagesFileInfo = new FileInfo(imagesXmlPath); await FetchImages(season, images.ToList(), cancellationToken).ConfigureAwait(false);
if (imagesFileInfo.Exists)
{
if (!season.HasImage(ImageType.Thumb))
{
var xmlDoc = new XmlDocument();
xmlDoc.Load(imagesXmlPath);
await FetchImages(season, xmlDoc, cancellationToken).ConfigureAwait(false);
}
}
}
SetLastRefreshed(item, DateTime.UtcNow); SetLastRefreshed(item, DateTime.UtcNow);
return true; return true;
@ -128,31 +114,18 @@ namespace MediaBrowser.Providers.TV
/// Fetches the images. /// Fetches the images.
/// </summary> /// </summary>
/// <param name="season">The season.</param> /// <param name="season">The season.</param>
/// <param name="doc">The doc.</param> /// <param name="images">The images.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns> /// <returns>Task.</returns>
private async Task FetchImages(Season season, XmlDocument doc, CancellationToken cancellationToken) private async Task FetchImages(Season season, List<RemoteImageInfo> 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)) if (ConfigurationManager.Configuration.DownloadSeasonImages.Thumb && !season.HasImage(ImageType.Thumb))
{ {
var node = doc.SelectSingleNode("//fanart/series/seasonthumbs/seasonthumb[@lang = \"" + language + "\"][@season = \"" + seasonNumber + "\"]/@url") ?? var image = images.FirstOrDefault(i => i.Type == ImageType.Thumb);
doc.SelectSingleNode("//fanart/series/seasonthumbs/seasonthumb[@season = \"" + seasonNumber + "\"]/@url");
var path = node != null ? node.Value : null; if (image != null)
if (!string.IsNullOrEmpty(path))
{ {
await _providerManager.SaveImage(season, path, FanArtResourcePool, ImageType.Thumb, null, cancellationToken) await _providerManager.SaveImage(season, image.Url, FanArtResourcePool, ImageType.Thumb, null, cancellationToken).ConfigureAwait(false);
.ConfigureAwait(false);
} }
} }
} }

View File

@ -55,11 +55,8 @@ namespace MediaBrowser.Providers.TV
var series = ((Season) item).Series; var series = ((Season) item).Series;
if (series == null) if (series != null)
{ {
return Task.FromResult<IEnumerable<RemoteImageInfo>>(list);
}
var id = series.GetProviderId(MetadataProviders.Tvdb); var id = series.GetProviderId(MetadataProviders.Tvdb);
if (!string.IsNullOrEmpty(id) && item.IndexNumber.HasValue) if (!string.IsNullOrEmpty(id) && item.IndexNumber.HasValue)
@ -75,6 +72,7 @@ namespace MediaBrowser.Providers.TV
// No biggie. Don't blow up // No biggie. Don't blow up
} }
} }
}
var language = _config.Configuration.PreferredMetadataLanguage; var language = _config.Configuration.PreferredMetadataLanguage;
@ -168,6 +166,14 @@ namespace MediaBrowser.Providers.TV
} }
break; break;
} }
case "showbackgrounds":
{
using (var subReader = reader.ReadSubtree())
{
PopulateImageCategory(list, subReader, cancellationToken, ImageType.Backdrop, 1920, 1080, seasonNumber);
}
break;
}
default: default:
reader.Skip(); reader.Skip();
break; break;
@ -189,11 +195,17 @@ namespace MediaBrowser.Providers.TV
switch (reader.Name) switch (reader.Name)
{ {
case "seasonthumb": case "seasonthumb":
case "showbackground":
{ {
var url = reader.GetAttribute("url"); var url = reader.GetAttribute("url");
var season = reader.GetAttribute("season"); 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"); var likesString = reader.GetAttribute("likes");
int likes; int likes;
@ -216,6 +228,7 @@ namespace MediaBrowser.Providers.TV
list.Add(info); list.Add(info);
} }
break; break;
} }
default: default: