#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.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Providers;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
namespace MediaBrowser.Providers.TV
{
@ -173,10 +175,9 @@ namespace MediaBrowser.Providers.TV
await DownloadSeriesXml(seriesId, cancellationToken).ConfigureAwait(false);
}
if (File.Exists(xmlPath))
{
await FetchFromXml(item, xmlPath, cancellationToken).ConfigureAwait(false);
}
var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, ManualFanartSeriesImageProvider.ProviderName).ConfigureAwait(false);
await FetchFromXml(item, images.ToList(), cancellationToken).ConfigureAwait(false);
}
SetLastRefreshed(item, DateTime.UtcNow);
@ -188,27 +189,20 @@ namespace MediaBrowser.Providers.TV
/// Fetches from XML.
/// </summary>
/// <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>
/// <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();
var language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
if (ConfigurationManager.Configuration.DownloadSeriesImages.Primary && !item.HasImage(ImageType.Primary))
{
var node = doc.SelectSingleNode("//fanart/series/tvposters/tvposter[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/tvposters/tvposter/@url");
var path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
var image = images.FirstOrDefault(i => i.Type == ImageType.Primary);
if (image != null)
{
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Primary, null, cancellationToken)
.ConfigureAwait(false);
await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Primary, null, cancellationToken).ConfigureAwait(false);
}
}
@ -216,15 +210,11 @@ namespace MediaBrowser.Providers.TV
if (ConfigurationManager.Configuration.DownloadSeriesImages.Logo && !item.HasImage(ImageType.Logo))
{
var node = doc.SelectSingleNode("//fanart/series/hdtvlogos/hdtvlogo[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/hdtvlogos/hdtvlogo/@url") ??
doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo/@url");
var path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
var image = images.FirstOrDefault(i => i.Type == ImageType.Logo);
if (image != null)
{
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Logo, null, cancellationToken)
.ConfigureAwait(false);
await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Logo, null, cancellationToken).ConfigureAwait(false);
}
}
@ -232,15 +222,11 @@ namespace MediaBrowser.Providers.TV
if (ConfigurationManager.Configuration.DownloadSeriesImages.Art && !item.HasImage(ImageType.Art))
{
var node = doc.SelectSingleNode("//fanart/series/hdcleararts/hdclearart[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/cleararts/clearart[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/hdcleararts/hdclearart/@url") ??
doc.SelectSingleNode("//fanart/series/cleararts/clearart/@url");
var path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
var image = images.FirstOrDefault(i => i.Type == ImageType.Art);
if (image != null)
{
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Art, null, cancellationToken)
.ConfigureAwait(false);
await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Art, null, cancellationToken).ConfigureAwait(false);
}
}
@ -248,53 +234,42 @@ namespace MediaBrowser.Providers.TV
if (ConfigurationManager.Configuration.DownloadSeriesImages.Thumb && !item.HasImage(ImageType.Thumb))
{
var node = doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb/@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(item, path, FanArtResourcePool, ImageType.Thumb, null, cancellationToken)
.ConfigureAwait(false);
await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Thumb, null, cancellationToken).ConfigureAwait(false);
}
}
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadSeriesImages.Banner && !item.HasImage(ImageType.Banner))
{
var node = doc.SelectSingleNode("//fanart/series/tbbanners/tvbanner[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/tbbanners/tvbanner/@url");
var path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
var image = images.FirstOrDefault(i => i.Type == ImageType.Banner);
if (image != null)
{
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Banner, null, cancellationToken)
.ConfigureAwait(false);
await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Banner, null, cancellationToken).ConfigureAwait(false);
}
}
cancellationToken.ThrowIfCancellationRequested();
var backdropLimit = ConfigurationManager.Configuration.MaxBackdrops;
if (ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && item.BackdropImagePaths.Count < backdropLimit)
if (ConfigurationManager.Configuration.DownloadSeriesImages.Backdrops &&
item.BackdropImagePaths.Count < backdropLimit)
{
var nodes = doc.SelectNodes("//fanart/series/showbackgrounds//@url");
var numBackdrops = item.BackdropImagePaths.Count;
if (nodes != null)
foreach (var image in images.Where(i => i.Type == ImageType.Backdrop))
{
var numBackdrops = item.BackdropImagePaths.Count;
await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Backdrop, numBackdrops, cancellationToken)
.ConfigureAwait(false);
foreach (XmlNode node in nodes)
{
var path = node.Value;
if (!string.IsNullOrEmpty(path) && !item.ContainsImageWithSourceUrl(path))
{
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Backdrop, numBackdrops, cancellationToken)
.ConfigureAwait(false);
numBackdrops++;
if (item.BackdropImagePaths.Count >= backdropLimit) break;
}
}
numBackdrops++;
if (item.BackdropImagePaths.Count >= backdropLimit) break;
}
}