#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.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 images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, ManualFanartSeasonImageProvider.ProviderName).ConfigureAwait(false);
var imagesFileInfo = new FileInfo(imagesXmlPath);
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.
/// </summary>
/// <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>
/// <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))
{
var node = doc.SelectSingleNode("//fanart/series/seasonthumbs/seasonthumb[@lang = \"" + language + "\"][@season = \"" + seasonNumber + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/seasonthumbs/seasonthumb[@season = \"" + seasonNumber + "\"]/@url");
var image = images.FirstOrDefault(i => i.Type == ImageType.Thumb);
var path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
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);
}
}
}

View File

@ -55,11 +55,8 @@ namespace MediaBrowser.Providers.TV
var series = ((Season) item).Series;
if (series == null)
if (series != null)
{
return Task.FromResult<IEnumerable<RemoteImageInfo>>(list);
}
var id = series.GetProviderId(MetadataProviders.Tvdb);
if (!string.IsNullOrEmpty(id) && item.IndexNumber.HasValue)
@ -75,6 +72,7 @@ namespace MediaBrowser.Providers.TV
// No biggie. Don't blow up
}
}
}
var language = _config.Configuration.PreferredMetadataLanguage;
@ -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: