support tv backdrops from fanart

This commit is contained in:
Luke Pulverenti 2013-05-24 12:05:53 -04:00
parent c702fb2179
commit 2f796d611b
9 changed files with 179 additions and 195 deletions

View File

@ -428,17 +428,13 @@ namespace MediaBrowser.Api
try try
{ {
await item.RefreshMetadata(CancellationToken.None, forceRefresh: request.Forced).ConfigureAwait(false);
if (folder != null) if (folder != null)
{ {
await await folder.ValidateChildren(new Progress<double>(), CancellationToken.None, request.Recursive,
folder.ValidateChildren(new Progress<double>(), CancellationToken.None, request.Recursive,
request.Forced).ConfigureAwait(false); request.Forced).ConfigureAwait(false);
} }
else
{
await
item.RefreshMetadata(CancellationToken.None, forceRefresh: request.Forced).ConfigureAwait(false);
}
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -1,25 +1,15 @@
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
namespace MediaBrowser.Controller.Providers namespace MediaBrowser.Controller.Providers
{ {
class FanArtProviderException : ApplicationException
{
public FanArtProviderException(string msg)
: base(msg)
{
}
}
/// <summary> /// <summary>
/// Class FanartBaseProvider /// Class FanartBaseProvider
/// </summary> /// </summary>
public abstract class FanartBaseProvider : BaseMetadataProvider public abstract class FanartBaseProvider : BaseMetadataProvider
{ {
protected static readonly SemaphoreSlim FanArtResourcePool = new SemaphoreSlim(3,3); protected static readonly SemaphoreSlim FanArtResourcePool = new SemaphoreSlim(3,3);
/// <summary> /// <summary>

View File

@ -192,16 +192,10 @@ namespace MediaBrowser.Controller.Providers.Movies
var saveLocal = ConfigurationManager.Configuration.SaveLocalMeta && var saveLocal = ConfigurationManager.Configuration.SaveLocalMeta &&
item.LocationType == LocationType.FileSystem; item.LocationType == LocationType.FileSystem;
if (doc.HasChildNodes)
{
string path; string path;
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : ""; var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
var hasLogo = item.LocationType == LocationType.FileSystem ? if (ConfigurationManager.Configuration.DownloadMovieImages.Logo && !item.HasImage(ImageType.Logo))
item.ResolveArgs.ContainsMetaFileByName(LogoFile)
: item.HasImage(ImageType.Logo);
if (ConfigurationManager.Configuration.DownloadMovieImages.Logo && !hasLogo)
{ {
var node = var node =
doc.SelectSingleNode("//fanart/movie/movielogos/" + hd + "movielogo[@lang = \"" + language + "\"]/@url") ?? doc.SelectSingleNode("//fanart/movie/movielogos/" + hd + "movielogo[@lang = \"" + language + "\"]/@url") ??
@ -219,11 +213,7 @@ namespace MediaBrowser.Controller.Providers.Movies
} }
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var hasArt = item.LocationType == LocationType.FileSystem ? if (ConfigurationManager.Configuration.DownloadMovieImages.Art && !item.HasImage(ImageType.Art))
item.ResolveArgs.ContainsMetaFileByName(ArtFile)
: item.HasImage(ImageType.Art);
if (ConfigurationManager.Configuration.DownloadMovieImages.Art && !hasArt)
{ {
var node = var node =
doc.SelectSingleNode("//fanart/movie/moviearts/" + hd + "movieart[@lang = \"" + language + "\"]/@url") ?? doc.SelectSingleNode("//fanart/movie/moviearts/" + hd + "movieart[@lang = \"" + language + "\"]/@url") ??
@ -238,11 +228,7 @@ namespace MediaBrowser.Controller.Providers.Movies
} }
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var hasDisc = item.LocationType == LocationType.FileSystem ? if (ConfigurationManager.Configuration.DownloadMovieImages.Disc && !item.HasImage(ImageType.Disc))
item.ResolveArgs.ContainsMetaFileByName(DiscFile)
: item.HasImage(ImageType.Disc);
if (ConfigurationManager.Configuration.DownloadMovieImages.Disc && !hasDisc)
{ {
var node = doc.SelectSingleNode("//fanart/movie/moviediscs/moviedisc[@lang = \"" + language + "\"]/@url") ?? var node = doc.SelectSingleNode("//fanart/movie/moviediscs/moviedisc[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/moviediscs/moviedisc/@url"); doc.SelectSingleNode("//fanart/movie/moviediscs/moviedisc/@url");
@ -255,11 +241,7 @@ namespace MediaBrowser.Controller.Providers.Movies
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var hasBanner = item.LocationType == LocationType.FileSystem ? if (ConfigurationManager.Configuration.DownloadMovieImages.Banner && !item.HasImage(ImageType.Banner))
item.ResolveArgs.ContainsMetaFileByName(BannerFile)
: item.HasImage(ImageType.Banner);
if (ConfigurationManager.Configuration.DownloadMovieImages.Banner && !hasBanner)
{ {
var node = doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner[@lang = \"" + language + "\"]/@url") ?? var node = doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner/@url"); doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner/@url");
@ -272,11 +254,7 @@ namespace MediaBrowser.Controller.Providers.Movies
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var hasThumb = item.LocationType == LocationType.FileSystem ? if (ConfigurationManager.Configuration.DownloadMovieImages.Thumb && !item.HasImage(ImageType.Thumb))
item.ResolveArgs.ContainsMetaFileByName(ThumbFile)
: item.HasImage(ImageType.Thumb);
if (ConfigurationManager.Configuration.DownloadMovieImages.Thumb && !hasThumb)
{ {
var node = doc.SelectSingleNode("//fanart/movie/moviethumbs/moviethumb[@lang = \"" + language + "\"]/@url") ?? var node = doc.SelectSingleNode("//fanart/movie/moviethumbs/moviethumb[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/movie/moviethumbs/moviethumb/@url"); doc.SelectSingleNode("//fanart/movie/moviethumbs/moviethumb/@url");
@ -287,33 +265,29 @@ namespace MediaBrowser.Controller.Providers.Movies
} }
} }
var hasBackdrop = item.LocationType == LocationType.FileSystem ? if (ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && item.BackdropImagePaths.Count < ConfigurationManager.Configuration.MaxBackdrops)
item.ResolveArgs.ContainsMetaFileByName(BackdropFile)
: item.BackdropImagePaths.Count > 0;
if (ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && !hasBackdrop)
{ {
var nodes = doc.SelectNodes("//fanart/movie/moviebackgrounds//@url"); var nodes = doc.SelectNodes("//fanart/movie/moviebackgrounds//@url");
if (nodes != null) if (nodes != null)
{ {
var numBackdrops = 0; var numBackdrops = item.BackdropImagePaths.Count;
item.BackdropImagePaths = new List<string>();
foreach (XmlNode node in nodes) foreach (XmlNode node in nodes)
{ {
path = node.Value; path = node.Value;
if (!string.IsNullOrEmpty(path)) if (!string.IsNullOrEmpty(path))
{ {
Logger.Debug("FanArtProvider getting Backdrop for " + item.Name);
item.BackdropImagePaths.Add(await _providerManager.DownloadAndSaveImage(item, path, ("backdrop" + (numBackdrops > 0 ? numBackdrops.ToString(UsCulture) : "") + ".jpg"), saveLocal, FanArtResourcePool, cancellationToken).ConfigureAwait(false)); item.BackdropImagePaths.Add(await _providerManager.DownloadAndSaveImage(item, path, ("backdrop" + (numBackdrops > 0 ? numBackdrops.ToString(UsCulture) : "") + ".jpg"), saveLocal, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
numBackdrops++; numBackdrops++;
if (numBackdrops >= ConfigurationManager.Configuration.MaxBackdrops) break;
if (item.BackdropImagePaths.Count >= ConfigurationManager.Configuration.MaxBackdrops) break;
} }
} }
} }
}
} }
data.Data = GetComparisonData(item.GetProviderId(MetadataProviders.Tmdb)); data.Data = GetComparisonData(item.GetProviderId(MetadataProviders.Tmdb));

View File

@ -265,7 +265,7 @@ namespace MediaBrowser.Controller.Providers.Movies
//still nothing - just get first one //still nothing - just get first one
profile = searchResult.profiles[0]; profile = searchResult.profiles[0];
} }
if (profile != null) if (profile != null && !person.HasImage(ImageType.Primary))
{ {
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false); var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
@ -299,8 +299,7 @@ namespace MediaBrowser.Controller.Providers.Movies
//download and save locally (if not already there) //download and save locally (if not already there)
var localPath = Path.Combine(item.MetaLocation, targetName); var localPath = Path.Combine(item.MetaLocation, targetName);
if (!item.ResolveArgs.ContainsMetaFileByName(targetName))
{
using (var sourceStream = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions using (var sourceStream = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{ {
Url = source, Url = source,
@ -312,7 +311,7 @@ namespace MediaBrowser.Controller.Providers.Movies
Logger.Debug("TmdbPersonProvider downloaded and saved image for {0}", item.Name); Logger.Debug("TmdbPersonProvider downloaded and saved image for {0}", item.Name);
} }
}
return localPath; return localPath;
} }

View File

@ -1,11 +1,11 @@
using MediaBrowser.Common.Extensions; using System.Globalization;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -80,6 +80,8 @@ namespace MediaBrowser.Controller.Providers.TV
return string.IsNullOrEmpty(id) ? Guid.Empty : id.GetMD5(); return string.IsNullOrEmpty(id) ? Guid.Empty : id.GetMD5();
} }
protected readonly CultureInfo UsCulture = new CultureInfo("en-US");
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken) public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@ -113,11 +115,9 @@ namespace MediaBrowser.Controller.Providers.TV
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
if (doc.HasChildNodes)
{
string path; string path;
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hdtv" : "clear"; var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hdtv" : "clear";
if (ConfigurationManager.Configuration.DownloadSeriesImages.Logo && !series.ResolveArgs.ContainsMetaFileByName(LogoFile)) if (ConfigurationManager.Configuration.DownloadSeriesImages.Logo && !series.HasImage(ImageType.Logo))
{ {
var node = doc.SelectSingleNode("//fanart/series/" + hd + "logos/" + hd + "logo[@lang = \"" + language + "\"]/@url") ?? var node = doc.SelectSingleNode("//fanart/series/" + hd + "logos/" + hd + "logo[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo[@lang = \"" + language + "\"]/@url") ?? doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo[@lang = \"" + language + "\"]/@url") ??
@ -134,7 +134,7 @@ namespace MediaBrowser.Controller.Providers.TV
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : ""; hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
if (ConfigurationManager.Configuration.DownloadSeriesImages.Art && !series.ResolveArgs.ContainsMetaFileByName(ArtFile)) if (ConfigurationManager.Configuration.DownloadSeriesImages.Art && !series.HasImage(ImageType.Art))
{ {
var node = doc.SelectSingleNode("//fanart/series/" + hd + "cleararts/" + hd + "clearart[@lang = \"" + language + "\"]/@url") ?? var node = doc.SelectSingleNode("//fanart/series/" + hd + "cleararts/" + hd + "clearart[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/cleararts/clearart[@lang = \"" + language + "\"]/@url") ?? doc.SelectSingleNode("//fanart/series/cleararts/clearart[@lang = \"" + language + "\"]/@url") ??
@ -150,7 +150,7 @@ namespace MediaBrowser.Controller.Providers.TV
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadSeriesImages.Thumb && !series.ResolveArgs.ContainsMetaFileByName(ThumbFile)) if (ConfigurationManager.Configuration.DownloadSeriesImages.Thumb && !series.HasImage(ImageType.Thumb))
{ {
var node = doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb[@lang = \"" + language + "\"]/@url") ?? var node = doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb/@url"); doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb/@url");
@ -162,7 +162,7 @@ namespace MediaBrowser.Controller.Providers.TV
} }
} }
if (ConfigurationManager.Configuration.DownloadSeriesImages.Banner && !series.ResolveArgs.ContainsMetaFileByName(BannerFile)) if (ConfigurationManager.Configuration.DownloadSeriesImages.Banner && !series.HasImage(ImageType.Banner))
{ {
var node = doc.SelectSingleNode("//fanart/series/tbbanners/tvbanner[@lang = \"" + language + "\"]/@url") ?? var node = doc.SelectSingleNode("//fanart/series/tbbanners/tvbanner[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/tbbanners/tvbanner/@url"); doc.SelectSingleNode("//fanart/series/tbbanners/tvbanner/@url");
@ -173,7 +173,32 @@ namespace MediaBrowser.Controller.Providers.TV
series.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(series, path, BannerFile, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false)); series.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(series, path, BannerFile, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
} }
} }
if (ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && item.BackdropImagePaths.Count < ConfigurationManager.Configuration.MaxBackdrops)
{
var nodes = doc.SelectNodes("//fanart/series/showbackgrounds//@url");
if (nodes != null)
{
var numBackdrops = item.BackdropImagePaths.Count;
foreach (XmlNode node in nodes)
{
path = node.Value;
if (!string.IsNullOrEmpty(path))
{
item.BackdropImagePaths.Add(await _providerManager.DownloadAndSaveImage(item, path, ("backdrop" + (numBackdrops > 0 ? numBackdrops.ToString(UsCulture) : "") + ".jpg"), ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
numBackdrops++;
if (item.BackdropImagePaths.Count >= ConfigurationManager.Configuration.MaxBackdrops) break;
} }
}
}
}
data.Data = GetComparisonData(item.GetProviderId(MetadataProviders.Tvdb)); data.Data = GetComparisonData(item.GetProviderId(MetadataProviders.Tvdb));
SetLastRefreshed(series, DateTime.UtcNow, status); SetLastRefreshed(series, DateTime.UtcNow, status);

View File

@ -7,7 +7,6 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -1,5 +1,4 @@
using System.Globalization; using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
@ -8,6 +7,7 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using System; using System;
using System.Globalization;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -257,6 +257,7 @@ namespace MediaBrowser.Controller.Providers.TV
if (series.BackdropImagePaths.Count < ConfigurationManager.Configuration.MaxBackdrops) if (series.BackdropImagePaths.Count < ConfigurationManager.Configuration.MaxBackdrops)
{ {
var bdNo = series.BackdropImagePaths.Count; var bdNo = series.BackdropImagePaths.Count;
var xmlNodeList = images.SelectNodes("//Banner[BannerType='fanart']"); var xmlNodeList = images.SelectNodes("//Banner[BannerType='fanart']");
if (xmlNodeList != null) if (xmlNodeList != null)
{ {

View File

@ -388,7 +388,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
var url = self.getUrl("Items/" + itemId + "/Refresh", { var url = self.getUrl("Items/" + itemId + "/Refresh", {
force: force || false, forced: force || false,
recursive: recursive || false recursive: recursive || false
}); });

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.117" targetFramework="net45" /> <package id="MediaBrowser.ApiClient.Javascript" version="3.0.118" targetFramework="net45" />
<package id="ServiceStack.Common" version="3.9.46" targetFramework="net45" /> <package id="ServiceStack.Common" version="3.9.46" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.45" targetFramework="net45" /> <package id="ServiceStack.Text" version="3.9.45" targetFramework="net45" />
</packages> </packages>