#606 - Add manual image selection for Seasons
This commit is contained in:
parent
0c93447380
commit
d187b3b7dd
|
@ -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;
|
||||
// Process images
|
||||
var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, ManualFanartSeasonImageProvider.ProviderName).ConfigureAwait(false);
|
||||
|
||||
if (!string.IsNullOrEmpty(seriesId))
|
||||
{
|
||||
// Process images
|
||||
var imagesXmlPath = FanArtTvProvider.Current.GetFanartXmlPath(seriesId);
|
||||
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,24 +55,22 @@ 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);
|
||||
|
||||
var id = series.GetProviderId(MetadataProviders.Tvdb);
|
||||
|
||||
if (!string.IsNullOrEmpty(id) && item.IndexNumber.HasValue)
|
||||
{
|
||||
var xmlPath = FanArtTvProvider.Current.GetFanartXmlPath(id);
|
||||
|
||||
try
|
||||
if (!string.IsNullOrEmpty(id) && item.IndexNumber.HasValue)
|
||||
{
|
||||
AddImages(list, item.IndexNumber.Value, xmlPath, cancellationToken);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
// 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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user