|
@@ -4,18 +4,17 @@ using MediaBrowser.Common.Net;
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
-using MediaBrowser.Controller.IO;
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
+using MediaBrowser.Model.Providers;
|
|
|
using System;
|
|
|
-using System.Globalization;
|
|
|
+using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
-using System.Xml;
|
|
|
|
|
|
namespace MediaBrowser.Providers.Movies
|
|
|
{
|
|
@@ -35,11 +34,6 @@ namespace MediaBrowser.Providers.Movies
|
|
|
/// </summary>
|
|
|
private readonly IProviderManager _providerManager;
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// The us culture
|
|
|
- /// </summary>
|
|
|
- private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
|
|
-
|
|
|
internal static FanArtMovieProvider Current { get; private set; }
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
@@ -139,28 +133,6 @@ namespace MediaBrowser.Providers.Movies
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if (!ConfigurationManager.Configuration.DownloadMovieImages.Art &&
|
|
|
- !ConfigurationManager.Configuration.DownloadMovieImages.Logo &&
|
|
|
- !ConfigurationManager.Configuration.DownloadMovieImages.Disc &&
|
|
|
- !ConfigurationManager.Configuration.DownloadMovieImages.Backdrops &&
|
|
|
- !ConfigurationManager.Configuration.DownloadMovieImages.Banner &&
|
|
|
- !ConfigurationManager.Configuration.DownloadMovieImages.Thumb &&
|
|
|
- !ConfigurationManager.Configuration.DownloadMovieImages.Primary)
|
|
|
- {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- if (item.HasImage(ImageType.Primary) &&
|
|
|
- item.HasImage(ImageType.Art) &&
|
|
|
- item.HasImage(ImageType.Logo) &&
|
|
|
- item.HasImage(ImageType.Disc) &&
|
|
|
- item.HasImage(ImageType.Banner) &&
|
|
|
- item.HasImage(ImageType.Thumb) &&
|
|
|
- item.BackdropImagePaths.Count >= ConfigurationManager.Configuration.MaxBackdrops)
|
|
|
- {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
return base.NeedsRefreshInternal(item, providerInfo);
|
|
|
}
|
|
|
|
|
@@ -171,24 +143,11 @@ namespace MediaBrowser.Providers.Movies
|
|
|
if (!string.IsNullOrEmpty(id))
|
|
|
{
|
|
|
// Process images
|
|
|
- var path = GetMovieDataPath(ConfigurationManager.ApplicationPaths, id);
|
|
|
+ var xmlPath = GetFanartXmlPath(id);
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- var files = new DirectoryInfo(path)
|
|
|
- .EnumerateFiles("*.xml", SearchOption.TopDirectoryOnly)
|
|
|
- .Select(i => _fileSystem.GetLastWriteTimeUtc(i))
|
|
|
- .ToList();
|
|
|
-
|
|
|
- if (files.Count > 0)
|
|
|
- {
|
|
|
- return files.Max() > providerInfo.LastRefreshed;
|
|
|
- }
|
|
|
- }
|
|
|
- catch (DirectoryNotFoundException)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
+ var fileInfo = new FileInfo(xmlPath);
|
|
|
+
|
|
|
+ return !fileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(fileInfo) > providerInfo.LastRefreshed;
|
|
|
}
|
|
|
|
|
|
return base.NeedsRefreshBasedOnCompareDate(item, providerInfo);
|
|
@@ -234,41 +193,44 @@ namespace MediaBrowser.Providers.Movies
|
|
|
|
|
|
if (!string.IsNullOrEmpty(movieId))
|
|
|
{
|
|
|
- var movieDataPath = GetMovieDataPath(ConfigurationManager.ApplicationPaths, movieId);
|
|
|
- var xmlPath = Path.Combine(movieDataPath, "fanart.xml");
|
|
|
+ var xmlPath = GetFanartXmlPath(movieId);
|
|
|
|
|
|
// Only download the xml if it doesn't already exist. The prescan task will take care of getting updates
|
|
|
if (!File.Exists(xmlPath))
|
|
|
{
|
|
|
- await DownloadMovieXml(movieDataPath, movieId, cancellationToken).ConfigureAwait(false);
|
|
|
+ await DownloadMovieXml(movieId, cancellationToken).ConfigureAwait(false);
|
|
|
}
|
|
|
|
|
|
- if (File.Exists(xmlPath))
|
|
|
- {
|
|
|
- await FetchFromXml(item, xmlPath, cancellationToken).ConfigureAwait(false);
|
|
|
- }
|
|
|
+ var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, ManualFanartMovieImageProvider.ProviderName).ConfigureAwait(false);
|
|
|
+
|
|
|
+ await FetchImages(item, images.ToList(), cancellationToken).ConfigureAwait(false);
|
|
|
}
|
|
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ public string GetFanartXmlPath(string tmdbId)
|
|
|
+ {
|
|
|
+ var movieDataPath = GetMovieDataPath(ConfigurationManager.ApplicationPaths, tmdbId);
|
|
|
+ return Path.Combine(movieDataPath, "fanart.xml");
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Downloads the movie XML.
|
|
|
/// </summary>
|
|
|
- /// <param name="movieDataPath">The movie data path.</param>
|
|
|
/// <param name="tmdbId">The TMDB id.</param>
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
/// <returns>Task.</returns>
|
|
|
- internal async Task DownloadMovieXml(string movieDataPath, string tmdbId, CancellationToken cancellationToken)
|
|
|
+ internal async Task DownloadMovieXml(string tmdbId, CancellationToken cancellationToken)
|
|
|
{
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
- string url = string.Format(FanArtBaseUrl, ApiKey, tmdbId);
|
|
|
+ var url = string.Format(FanArtBaseUrl, ApiKey, tmdbId);
|
|
|
|
|
|
- var xmlPath = Path.Combine(movieDataPath, "fanart.xml");
|
|
|
+ var xmlPath = GetFanartXmlPath(tmdbId);
|
|
|
|
|
|
- Directory.CreateDirectory(movieDataPath);
|
|
|
+ Directory.CreateDirectory(Path.GetDirectoryName(xmlPath));
|
|
|
|
|
|
using (var response = await HttpClient.Get(new HttpRequestOptions
|
|
|
{
|
|
@@ -285,82 +247,53 @@ namespace MediaBrowser.Providers.Movies
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Fetches from XML.
|
|
|
- /// </summary>
|
|
|
- /// <param name="item">The item.</param>
|
|
|
- /// <param name="xmlFilePath">The XML file path.</param>
|
|
|
- /// <param name="cancellationToken">The cancellation token.</param>
|
|
|
- /// <returns>Task.</returns>
|
|
|
- private async Task FetchFromXml(BaseItem item, string xmlFilePath, CancellationToken cancellationToken)
|
|
|
+ private async Task FetchImages(BaseItem item, List<RemoteImageInfo> images, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- var doc = new XmlDocument();
|
|
|
- doc.Load(xmlFilePath);
|
|
|
-
|
|
|
- var language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
|
|
|
-
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
- string path;
|
|
|
-
|
|
|
if (ConfigurationManager.Configuration.DownloadMovieImages.Primary && !item.HasImage(ImageType.Primary))
|
|
|
{
|
|
|
- var node = doc.SelectSingleNode("//fanart/movie/movieposters/movieposter[@lang = \"" + language + "\"]/@url") ??
|
|
|
- doc.SelectSingleNode("//fanart/movie/movieposters/movieposter/@url");
|
|
|
- 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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
-
|
|
|
+
|
|
|
if (ConfigurationManager.Configuration.DownloadMovieImages.Logo && !item.HasImage(ImageType.Logo))
|
|
|
{
|
|
|
- var node =
|
|
|
- doc.SelectSingleNode("//fanart/movie/hdmovielogos/hdmovielogo[@lang = \"" + language + "\"]/@url") ??
|
|
|
- doc.SelectSingleNode("//fanart/movie/movielogos/movielogo[@lang = \"" + language + "\"]/@url");
|
|
|
- if (node == null && language != "en")
|
|
|
- {
|
|
|
- //maybe just couldn't find language - try just first one
|
|
|
- node = doc.SelectSingleNode("//fanart/movie/hdmovielogos/hdmovielogo/@url") ??
|
|
|
- doc.SelectSingleNode("//fanart/movie/movielogos/movielogo/@url");
|
|
|
- }
|
|
|
- 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);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
if (ConfigurationManager.Configuration.DownloadMovieImages.Art && !item.HasImage(ImageType.Art))
|
|
|
{
|
|
|
- var node =
|
|
|
- doc.SelectSingleNode("//fanart/movie/hdmoviecleararts/hdmovieclearart[@lang = \"" + language + "\"]/@url") ??
|
|
|
- doc.SelectSingleNode("//fanart/movie/hdmoviecleararts/hdmovieclearart/@url") ??
|
|
|
- doc.SelectSingleNode("//fanart/movie/moviearts/movieart[@lang = \"" + language + "\"]/@url") ??
|
|
|
- doc.SelectSingleNode("//fanart/movie/moviearts/movieart/@url");
|
|
|
- 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);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
if (ConfigurationManager.Configuration.DownloadMovieImages.Disc && !item.HasImage(ImageType.Disc))
|
|
|
{
|
|
|
- var node = doc.SelectSingleNode("//fanart/movie/moviediscs/moviedisc[@lang = \"" + language + "\"]/@url") ??
|
|
|
- doc.SelectSingleNode("//fanart/movie/moviediscs/moviedisc/@url");
|
|
|
- path = node != null ? node.Value : null;
|
|
|
- if (!string.IsNullOrEmpty(path))
|
|
|
+ var image = images.FirstOrDefault(i => i.Type == ImageType.Disc);
|
|
|
+
|
|
|
+ if (image != null)
|
|
|
{
|
|
|
- await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Disc, null, cancellationToken)
|
|
|
- .ConfigureAwait(false);
|
|
|
+ await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Disc, null, cancellationToken).ConfigureAwait(false);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -368,13 +301,11 @@ namespace MediaBrowser.Providers.Movies
|
|
|
|
|
|
if (ConfigurationManager.Configuration.DownloadMovieImages.Banner && !item.HasImage(ImageType.Banner))
|
|
|
{
|
|
|
- var node = doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner[@lang = \"" + language + "\"]/@url") ??
|
|
|
- doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner/@url");
|
|
|
- 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);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -382,40 +313,30 @@ namespace MediaBrowser.Providers.Movies
|
|
|
|
|
|
if (ConfigurationManager.Configuration.DownloadMovieImages.Thumb && !item.HasImage(ImageType.Thumb))
|
|
|
{
|
|
|
- var node = doc.SelectSingleNode("//fanart/movie/moviethumbs/moviethumb[@lang = \"" + language + "\"]/@url") ??
|
|
|
- doc.SelectSingleNode("//fanart/movie/moviethumbs/moviethumb/@url");
|
|
|
- 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();
|
|
|
+
|
|
|
var backdropLimit = ConfigurationManager.Configuration.MaxBackdrops;
|
|
|
- if (ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && item.BackdropImagePaths.Count < backdropLimit)
|
|
|
+ if (ConfigurationManager.Configuration.DownloadMovieImages.Backdrops &&
|
|
|
+ item.BackdropImagePaths.Count < backdropLimit)
|
|
|
{
|
|
|
- var nodes = doc.SelectNodes("//fanart/movie/moviebackgrounds//@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;
|
|
|
-
|
|
|
- foreach (XmlNode node in nodes)
|
|
|
- {
|
|
|
- path = node.Value;
|
|
|
-
|
|
|
- if (!string.IsNullOrEmpty(path) && !item.ContainsImageWithSourceUrl(path))
|
|
|
- {
|
|
|
- await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Backdrop, numBackdrops, cancellationToken)
|
|
|
- .ConfigureAwait(false);
|
|
|
-
|
|
|
- numBackdrops++;
|
|
|
+ await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Backdrop, numBackdrops, cancellationToken)
|
|
|
+ .ConfigureAwait(false);
|
|
|
|
|
|
- if (item.BackdropImagePaths.Count >= backdropLimit) break;
|
|
|
- }
|
|
|
- }
|
|
|
+ numBackdrops++;
|
|
|
|
|
|
+ if (item.BackdropImagePaths.Count >= backdropLimit) break;
|
|
|
}
|
|
|
}
|
|
|
}
|