#605 - Add manual image selection for Series

This commit is contained in:
Luke Pulverenti 2013-11-02 10:19:24 -04:00
parent 5fa577a9ee
commit ab490d7467

View File

@ -8,12 +8,14 @@ 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.Globalization; using System.Globalization;
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
{ {
@ -173,10 +175,9 @@ namespace MediaBrowser.Providers.TV
await DownloadSeriesXml(seriesId, cancellationToken).ConfigureAwait(false); await DownloadSeriesXml(seriesId, cancellationToken).ConfigureAwait(false);
} }
if (File.Exists(xmlPath)) var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, ManualFanartSeriesImageProvider.ProviderName).ConfigureAwait(false);
{
await FetchFromXml(item, xmlPath, cancellationToken).ConfigureAwait(false); await FetchFromXml(item, images.ToList(), cancellationToken).ConfigureAwait(false);
}
} }
SetLastRefreshed(item, DateTime.UtcNow); SetLastRefreshed(item, DateTime.UtcNow);
@ -188,27 +189,20 @@ namespace MediaBrowser.Providers.TV
/// Fetches from XML. /// Fetches from XML.
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
/// <param name="xmlFilePath">The XML file path.</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 FetchFromXml(BaseItem item, string xmlFilePath, CancellationToken cancellationToken) private async Task FetchFromXml(BaseItem item, List<RemoteImageInfo> images, CancellationToken cancellationToken)
{ {
var doc = new XmlDocument();
doc.Load(xmlFilePath);
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
if (ConfigurationManager.Configuration.DownloadSeriesImages.Primary && !item.HasImage(ImageType.Primary)) if (ConfigurationManager.Configuration.DownloadSeriesImages.Primary && !item.HasImage(ImageType.Primary))
{ {
var node = doc.SelectSingleNode("//fanart/series/tvposters/tvposter[@lang = \"" + language + "\"]/@url") ?? var image = images.FirstOrDefault(i => i.Type == ImageType.Primary);
doc.SelectSingleNode("//fanart/series/tvposters/tvposter/@url");
var path = node != null ? node.Value : null; if (image != null)
if (!string.IsNullOrEmpty(path))
{ {
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Primary, null, cancellationToken) await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Primary, null, cancellationToken).ConfigureAwait(false);
.ConfigureAwait(false);
} }
} }
@ -216,15 +210,11 @@ namespace MediaBrowser.Providers.TV
if (ConfigurationManager.Configuration.DownloadSeriesImages.Logo && !item.HasImage(ImageType.Logo)) if (ConfigurationManager.Configuration.DownloadSeriesImages.Logo && !item.HasImage(ImageType.Logo))
{ {
var node = doc.SelectSingleNode("//fanart/series/hdtvlogos/hdtvlogo[@lang = \"" + language + "\"]/@url") ?? var image = images.FirstOrDefault(i => i.Type == ImageType.Logo);
doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/hdtvlogos/hdtvlogo/@url") ?? if (image != null)
doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo/@url");
var path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{ {
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Logo, null, cancellationToken) await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Logo, null, cancellationToken).ConfigureAwait(false);
.ConfigureAwait(false);
} }
} }
@ -232,15 +222,11 @@ namespace MediaBrowser.Providers.TV
if (ConfigurationManager.Configuration.DownloadSeriesImages.Art && !item.HasImage(ImageType.Art)) if (ConfigurationManager.Configuration.DownloadSeriesImages.Art && !item.HasImage(ImageType.Art))
{ {
var node = doc.SelectSingleNode("//fanart/series/hdcleararts/hdclearart[@lang = \"" + language + "\"]/@url") ?? var image = images.FirstOrDefault(i => i.Type == ImageType.Art);
doc.SelectSingleNode("//fanart/series/cleararts/clearart[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/hdcleararts/hdclearart/@url") ?? if (image != null)
doc.SelectSingleNode("//fanart/series/cleararts/clearart/@url");
var path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{ {
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Art, null, cancellationToken) await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Art, null, cancellationToken).ConfigureAwait(false);
.ConfigureAwait(false);
} }
} }
@ -248,45 +234,37 @@ namespace MediaBrowser.Providers.TV
if (ConfigurationManager.Configuration.DownloadSeriesImages.Thumb && !item.HasImage(ImageType.Thumb)) if (ConfigurationManager.Configuration.DownloadSeriesImages.Thumb && !item.HasImage(ImageType.Thumb))
{ {
var node = doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb[@lang = \"" + language + "\"]/@url") ?? var image = images.FirstOrDefault(i => i.Type == ImageType.Thumb);
doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb/@url");
var path = node != null ? node.Value : null; if (image != null)
if (!string.IsNullOrEmpty(path))
{ {
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Thumb, null, cancellationToken) await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Thumb, null, cancellationToken).ConfigureAwait(false);
.ConfigureAwait(false);
} }
} }
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadSeriesImages.Banner && !item.HasImage(ImageType.Banner)) if (ConfigurationManager.Configuration.DownloadSeriesImages.Banner && !item.HasImage(ImageType.Banner))
{ {
var node = doc.SelectSingleNode("//fanart/series/tbbanners/tvbanner[@lang = \"" + language + "\"]/@url") ?? var image = images.FirstOrDefault(i => i.Type == ImageType.Banner);
doc.SelectSingleNode("//fanart/series/tbbanners/tvbanner/@url");
var path = node != null ? node.Value : null; if (image != null)
if (!string.IsNullOrEmpty(path))
{ {
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Banner, null, cancellationToken) await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Banner, null, cancellationToken).ConfigureAwait(false);
.ConfigureAwait(false);
} }
} }
cancellationToken.ThrowIfCancellationRequested();
var backdropLimit = ConfigurationManager.Configuration.MaxBackdrops; var backdropLimit = ConfigurationManager.Configuration.MaxBackdrops;
if (ConfigurationManager.Configuration.DownloadSeriesImages.Backdrops &&
if (ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && item.BackdropImagePaths.Count < backdropLimit) item.BackdropImagePaths.Count < backdropLimit)
{
var nodes = doc.SelectNodes("//fanart/series/showbackgrounds//@url");
if (nodes != null)
{ {
var numBackdrops = item.BackdropImagePaths.Count; var numBackdrops = item.BackdropImagePaths.Count;
foreach (XmlNode node in nodes) foreach (var image in images.Where(i => i.Type == ImageType.Backdrop))
{ {
var path = node.Value; await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Backdrop, numBackdrops, cancellationToken)
if (!string.IsNullOrEmpty(path) && !item.ContainsImageWithSourceUrl(path))
{
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Backdrop, numBackdrops, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
numBackdrops++; numBackdrops++;
@ -296,9 +274,6 @@ namespace MediaBrowser.Providers.TV
} }
} }
}
}
/// <summary> /// <summary>
/// Downloads the series XML. /// Downloads the series XML.