fixes #607 - Add manual image selection for episodes
This commit is contained in:
parent
926a610075
commit
142d0e5f48
|
@ -110,6 +110,7 @@
|
||||||
<Compile Include="TV\FanArtSeasonProvider.cs" />
|
<Compile Include="TV\FanArtSeasonProvider.cs" />
|
||||||
<Compile Include="TV\FanArtTVProvider.cs" />
|
<Compile Include="TV\FanArtTVProvider.cs" />
|
||||||
<Compile Include="TV\FanArtTvUpdatesPrescanTask.cs" />
|
<Compile Include="TV\FanArtTvUpdatesPrescanTask.cs" />
|
||||||
|
<Compile Include="TV\ManualTvdbEpisodeImageProvider.cs" />
|
||||||
<Compile Include="TV\RemoteEpisodeProvider.cs" />
|
<Compile Include="TV\RemoteEpisodeProvider.cs" />
|
||||||
<Compile Include="TV\RemoteSeasonProvider.cs" />
|
<Compile Include="TV\RemoteSeasonProvider.cs" />
|
||||||
<Compile Include="TV\RemoteSeriesProvider.cs" />
|
<Compile Include="TV\RemoteSeriesProvider.cs" />
|
||||||
|
|
|
@ -8,13 +8,13 @@ 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.Globalization;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Providers.Movies
|
namespace MediaBrowser.Providers.Movies
|
||||||
{
|
{
|
||||||
|
@ -193,18 +193,19 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(movieId))
|
if (!string.IsNullOrEmpty(movieId))
|
||||||
{
|
{
|
||||||
var movieDataPath = GetMovieDataPath(ConfigurationManager.ApplicationPaths, movieId);
|
var xmlPath = GetFanartXmlPath(movieId);
|
||||||
var xmlPath = Path.Combine(movieDataPath, "fanart.xml");
|
|
||||||
|
|
||||||
// Only download the xml if it doesn't already exist. The prescan task will take care of getting updates
|
// Only download the xml if it doesn't already exist. The prescan task will take care of getting updates
|
||||||
if (!File.Exists(xmlPath))
|
if (!File.Exists(xmlPath))
|
||||||
{
|
{
|
||||||
await DownloadMovieXml(movieDataPath, movieId, cancellationToken).ConfigureAwait(false);
|
await DownloadMovieXml(movieId, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (File.Exists(xmlPath))
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,19 +222,18 @@ namespace MediaBrowser.Providers.Movies
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Downloads the movie XML.
|
/// Downloads the movie XML.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="movieDataPath">The movie data path.</param>
|
|
||||||
/// <param name="tmdbId">The TMDB id.</param>
|
/// <param name="tmdbId">The TMDB id.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
internal async Task DownloadMovieXml(string movieDataPath, string tmdbId, CancellationToken cancellationToken)
|
internal async Task DownloadMovieXml(string tmdbId, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
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
|
using (var response = await HttpClient.Get(new HttpRequestOptions
|
||||||
{
|
{
|
||||||
|
@ -250,33 +250,17 @@ namespace MediaBrowser.Providers.Movies
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
private async Task FetchImages(BaseItem item, List<RemoteImageInfo> images, CancellationToken cancellationToken)
|
||||||
/// 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)
|
|
||||||
{
|
{
|
||||||
var doc = new XmlDocument();
|
|
||||||
doc.Load(xmlFilePath);
|
|
||||||
|
|
||||||
var language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
string path;
|
|
||||||
|
|
||||||
if (ConfigurationManager.Configuration.DownloadMovieImages.Primary && !item.HasImage(ImageType.Primary))
|
if (ConfigurationManager.Configuration.DownloadMovieImages.Primary && !item.HasImage(ImageType.Primary))
|
||||||
{
|
{
|
||||||
var node = doc.SelectSingleNode("//fanart/movie/movieposters/movieposter[@lang = \"" + language + "\"]/@url") ??
|
var image = images.FirstOrDefault(i => i.Type == ImageType.Primary);
|
||||||
doc.SelectSingleNode("//fanart/movie/movieposters/movieposter/@url");
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,48 +268,35 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
if (ConfigurationManager.Configuration.DownloadMovieImages.Logo && !item.HasImage(ImageType.Logo))
|
if (ConfigurationManager.Configuration.DownloadMovieImages.Logo && !item.HasImage(ImageType.Logo))
|
||||||
{
|
{
|
||||||
var node =
|
var image = images.FirstOrDefault(i => i.Type == ImageType.Logo);
|
||||||
doc.SelectSingleNode("//fanart/movie/hdmovielogos/hdmovielogo[@lang = \"" + language + "\"]/@url") ??
|
|
||||||
doc.SelectSingleNode("//fanart/movie/movielogos/movielogo[@lang = \"" + language + "\"]/@url");
|
if (image != null)
|
||||||
if (node == null && language != "en")
|
|
||||||
{
|
{
|
||||||
//maybe just couldn't find language - try just first one
|
await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Logo, null, cancellationToken).ConfigureAwait(false);
|
||||||
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))
|
|
||||||
{
|
|
||||||
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Logo, null, cancellationToken).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
if (ConfigurationManager.Configuration.DownloadMovieImages.Art && !item.HasImage(ImageType.Art))
|
if (ConfigurationManager.Configuration.DownloadMovieImages.Art && !item.HasImage(ImageType.Art))
|
||||||
{
|
{
|
||||||
var node =
|
var image = images.FirstOrDefault(i => i.Type == ImageType.Art);
|
||||||
doc.SelectSingleNode("//fanart/movie/hdmoviecleararts/hdmovieclearart[@lang = \"" + language + "\"]/@url") ??
|
|
||||||
doc.SelectSingleNode("//fanart/movie/hdmoviecleararts/hdmovieclearart/@url") ??
|
if (image != null)
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
if (ConfigurationManager.Configuration.DownloadMovieImages.Disc && !item.HasImage(ImageType.Disc))
|
if (ConfigurationManager.Configuration.DownloadMovieImages.Disc && !item.HasImage(ImageType.Disc))
|
||||||
{
|
{
|
||||||
var node = doc.SelectSingleNode("//fanart/movie/moviediscs/moviedisc[@lang = \"" + language + "\"]/@url") ??
|
var image = images.FirstOrDefault(i => i.Type == ImageType.Disc);
|
||||||
doc.SelectSingleNode("//fanart/movie/moviediscs/moviedisc/@url");
|
|
||||||
path = node != null ? node.Value : null;
|
if (image != null)
|
||||||
if (!string.IsNullOrEmpty(path))
|
|
||||||
{
|
{
|
||||||
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Disc, null, cancellationToken)
|
await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Disc, null, cancellationToken).ConfigureAwait(false);
|
||||||
.ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,13 +304,11 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
if (ConfigurationManager.Configuration.DownloadMovieImages.Banner && !item.HasImage(ImageType.Banner))
|
if (ConfigurationManager.Configuration.DownloadMovieImages.Banner && !item.HasImage(ImageType.Banner))
|
||||||
{
|
{
|
||||||
var node = doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner[@lang = \"" + language + "\"]/@url") ??
|
var image = images.FirstOrDefault(i => i.Type == ImageType.Banner);
|
||||||
doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner/@url");
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,32 +316,25 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
if (ConfigurationManager.Configuration.DownloadMovieImages.Thumb && !item.HasImage(ImageType.Thumb))
|
if (ConfigurationManager.Configuration.DownloadMovieImages.Thumb && !item.HasImage(ImageType.Thumb))
|
||||||
{
|
{
|
||||||
var node = doc.SelectSingleNode("//fanart/movie/moviethumbs/moviethumb[@lang = \"" + language + "\"]/@url") ??
|
var image = images.FirstOrDefault(i => i.Type == ImageType.Thumb);
|
||||||
doc.SelectSingleNode("//fanart/movie/moviethumbs/moviethumb/@url");
|
|
||||||
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();
|
||||||
|
|
||||||
var backdropLimit = ConfigurationManager.Configuration.MaxBackdrops;
|
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");
|
|
||||||
|
|
||||||
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))
|
||||||
{
|
{
|
||||||
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++;
|
||||||
|
@ -380,9 +342,6 @@ namespace MediaBrowser.Providers.Movies
|
||||||
if (item.BackdropImagePaths.Count >= backdropLimit) break;
|
if (item.BackdropImagePaths.Count >= backdropLimit) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
progress.Report(5);
|
progress.Report(5);
|
||||||
|
|
||||||
await UpdateMovies(moviesToUpdate, path, progress, cancellationToken).ConfigureAwait(false);
|
await UpdateMovies(moviesToUpdate, progress, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var newUpdateTime = Convert.ToInt64(DateTimeToUnixTimestamp(DateTime.UtcNow)).ToString(UsCulture);
|
var newUpdateTime = Convert.ToInt64(DateTimeToUnixTimestamp(DateTime.UtcNow)).ToString(UsCulture);
|
||||||
|
@ -127,14 +127,16 @@ namespace MediaBrowser.Providers.Movies
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateMovies(IEnumerable<string> idList, string moviesDataPath, IProgress<double> progress, CancellationToken cancellationToken)
|
private async Task UpdateMovies(IEnumerable<string> idList, IProgress<double> progress, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var list = idList.ToList();
|
var list = idList.ToList();
|
||||||
var numComplete = 0;
|
var numComplete = 0;
|
||||||
|
|
||||||
foreach (var id in list)
|
foreach (var id in list)
|
||||||
{
|
{
|
||||||
await UpdateMovie(id, moviesDataPath, cancellationToken).ConfigureAwait(false);
|
_logger.Info("Updating movie " + id);
|
||||||
|
|
||||||
|
await FanArtMovieProvider.Current.DownloadMovieXml(id, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
numComplete++;
|
numComplete++;
|
||||||
double percent = numComplete;
|
double percent = numComplete;
|
||||||
|
@ -145,17 +147,6 @@ namespace MediaBrowser.Providers.Movies
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task UpdateMovie(string tmdbId, string movieDataPath, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
_logger.Info("Updating movie " + tmdbId);
|
|
||||||
|
|
||||||
movieDataPath = Path.Combine(movieDataPath, tmdbId);
|
|
||||||
|
|
||||||
Directory.CreateDirectory(movieDataPath);
|
|
||||||
|
|
||||||
return FanArtMovieProvider.Current.DownloadMovieXml(movieDataPath, tmdbId, cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dates the time to unix timestamp.
|
/// Dates the time to unix timestamp.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -27,6 +27,11 @@ namespace MediaBrowser.Providers.Movies
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
|
{
|
||||||
|
get { return ProviderName; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ProviderName
|
||||||
{
|
{
|
||||||
get { return "FanArt"; }
|
get { return "FanArt"; }
|
||||||
}
|
}
|
||||||
|
@ -67,6 +72,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase);
|
var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
// Sort first by width to prioritize HD versions
|
||||||
list = list.OrderByDescending(i => i.Width ?? 0)
|
list = list.OrderByDescending(i => i.Width ?? 0)
|
||||||
.ThenByDescending(i =>
|
.ThenByDescending(i =>
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,11 @@ namespace MediaBrowser.Providers.Movies
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
|
{
|
||||||
|
get { return ProviderName; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ProviderName
|
||||||
{
|
{
|
||||||
get { return "TheMovieDb"; }
|
get { return "TheMovieDb"; }
|
||||||
}
|
}
|
||||||
|
@ -99,7 +104,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
var eligiblePosters = images.posters == null ?
|
var eligiblePosters = images.posters == null ?
|
||||||
new List<MovieDbProvider.Poster>() :
|
new List<MovieDbProvider.Poster>() :
|
||||||
images.posters.Where(i => i.width >= _config.Configuration.MinMoviePosterWidth)
|
images.posters
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
return eligiblePosters.OrderByDescending(i =>
|
return eligiblePosters.OrderByDescending(i =>
|
||||||
|
@ -135,7 +140,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
private IEnumerable<MovieDbProvider.Backdrop> GetBackdrops(MovieDbProvider.Images images, BaseItem item)
|
private IEnumerable<MovieDbProvider.Backdrop> GetBackdrops(MovieDbProvider.Images images, BaseItem item)
|
||||||
{
|
{
|
||||||
var eligibleBackdrops = images.backdrops == null ? new List<MovieDbProvider.Backdrop>() :
|
var eligibleBackdrops = images.backdrops == null ? new List<MovieDbProvider.Backdrop>() :
|
||||||
images.backdrops.Where(i => i.width >= _config.Configuration.MinMovieBackdropWidth)
|
images.backdrops
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
return eligibleBackdrops.OrderByDescending(i => i.vote_average).ThenByDescending(i => i.vote_count);
|
return eligibleBackdrops.OrderByDescending(i => i.vote_average).ThenByDescending(i => i.vote_count);
|
||||||
|
@ -149,7 +154,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
/// <returns>Task{MovieImages}.</returns>
|
/// <returns>Task{MovieImages}.</returns>
|
||||||
private MovieDbProvider.Images FetchImages(BaseItem item, IJsonSerializer jsonSerializer)
|
private MovieDbProvider.Images FetchImages(BaseItem item, IJsonSerializer jsonSerializer)
|
||||||
{
|
{
|
||||||
var path = MovieDbProvider.Current.GetDataFilePath(item, "default");
|
var path = MovieDbProvider.Current.GetImagesDataFilePath(item);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(path))
|
if (!string.IsNullOrEmpty(path))
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,7 +8,6 @@ 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 MediaBrowser.Model.Providers;
|
||||||
using MediaBrowser.Model.Serialization;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -28,10 +27,6 @@ namespace MediaBrowser.Providers.Movies
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IProviderManager _providerManager;
|
private readonly IProviderManager _providerManager;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The _json serializer
|
|
||||||
/// </summary>
|
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -40,12 +35,10 @@ namespace MediaBrowser.Providers.Movies
|
||||||
/// <param name="logManager">The log manager.</param>
|
/// <param name="logManager">The log manager.</param>
|
||||||
/// <param name="configurationManager">The configuration manager.</param>
|
/// <param name="configurationManager">The configuration manager.</param>
|
||||||
/// <param name="providerManager">The provider manager.</param>
|
/// <param name="providerManager">The provider manager.</param>
|
||||||
/// <param name="jsonSerializer">The json serializer.</param>
|
public MovieDbImagesProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager, IFileSystem fileSystem)
|
||||||
public MovieDbImagesProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem)
|
|
||||||
: base(logManager, configurationManager)
|
: base(logManager, configurationManager)
|
||||||
{
|
{
|
||||||
_providerManager = providerManager;
|
_providerManager = providerManager;
|
||||||
_jsonSerializer = jsonSerializer;
|
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,12 +142,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
|
protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tmdb)))
|
var path = MovieDbProvider.Current.GetImagesDataFilePath(item);
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var path = MovieDbProvider.Current.GetDataFilePath(item, "default");
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(path))
|
if (!string.IsNullOrEmpty(path))
|
||||||
{
|
{
|
||||||
|
@ -182,8 +170,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(id))
|
if (!string.IsNullOrEmpty(id))
|
||||||
{
|
{
|
||||||
var images = await new ManualMovieDbImageProvider(_jsonSerializer, ConfigurationManager).GetAllImages(item,
|
var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, ManualMovieDbImageProvider.ProviderName).ConfigureAwait(false);
|
||||||
cancellationToken).ConfigureAwait(false);
|
|
||||||
|
|
||||||
await ProcessImages(item, images.ToList(), cancellationToken).ConfigureAwait(false);
|
await ProcessImages(item, images.ToList(), cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
@ -204,7 +191,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
var eligiblePosters = images
|
var eligiblePosters = images
|
||||||
.Where(i => i.Type == ImageType.Primary)
|
.Where(i => i.Type == ImageType.Primary && i.Width.HasValue && i.Width.Value >= ConfigurationManager.Configuration.MinMoviePosterWidth)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// poster
|
// poster
|
||||||
|
@ -228,7 +215,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
var eligibleBackdrops = images
|
var eligibleBackdrops = images
|
||||||
.Where(i => i.Type == ImageType.Backdrop)
|
.Where(i => i.Type == ImageType.Backdrop && i.Width.HasValue && i.Width.Value >= ConfigurationManager.Configuration.MinMovieBackdropWidth)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var backdropLimit = ConfigurationManager.Configuration.MaxBackdrops;
|
var backdropLimit = ConfigurationManager.Configuration.MaxBackdrops;
|
||||||
|
|
|
@ -209,17 +209,17 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
|
protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
|
||||||
{
|
{
|
||||||
var language = ConfigurationManager.Configuration.PreferredMetadataLanguage;
|
var path = GetDataFilePath(item);
|
||||||
|
|
||||||
var path = GetDataFilePath(item, language);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(path))
|
if (!string.IsNullOrEmpty(path))
|
||||||
{
|
{
|
||||||
|
var imagesFilePath = GetImagesDataFilePath(item);
|
||||||
|
|
||||||
var fileInfo = new FileInfo(path);
|
var fileInfo = new FileInfo(path);
|
||||||
var defaultFileInfo = new FileInfo(Path.Combine(Path.GetDirectoryName(path), "default.json"));
|
var imagesFileInfo = new FileInfo(imagesFilePath);
|
||||||
|
|
||||||
return !fileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(fileInfo) > providerInfo.LastRefreshed ||
|
return !fileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(fileInfo) > providerInfo.LastRefreshed ||
|
||||||
!defaultFileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(defaultFileInfo) > providerInfo.LastRefreshed;
|
!imagesFileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(imagesFileInfo) > providerInfo.LastRefreshed;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -505,9 +505,9 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
var language = ConfigurationManager.Configuration.PreferredMetadataLanguage;
|
var language = ConfigurationManager.Configuration.PreferredMetadataLanguage;
|
||||||
|
|
||||||
var dataFilePath = GetDataFilePath(item, language);
|
var dataFilePath = GetDataFilePath(item);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(dataFilePath) || !File.Exists(dataFilePath) || !File.Exists(Path.Combine(Path.GetDirectoryName(dataFilePath), "default.json")))
|
if (string.IsNullOrEmpty(dataFilePath) || !File.Exists(dataFilePath) || !File.Exists(GetImagesDataFilePath(item)))
|
||||||
{
|
{
|
||||||
var isBoxSet = item is BoxSet;
|
var isBoxSet = item is BoxSet;
|
||||||
|
|
||||||
|
@ -535,7 +535,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
if (isForcedRefresh || ConfigurationManager.Configuration.EnableTmdbUpdates || !HasAltMeta(item))
|
if (isForcedRefresh || ConfigurationManager.Configuration.EnableTmdbUpdates || !HasAltMeta(item))
|
||||||
{
|
{
|
||||||
dataFilePath = GetDataFilePath(item, language);
|
dataFilePath = GetDataFilePath(item);
|
||||||
|
|
||||||
var mainResult = JsonSerializer.DeserializeFromFile<CompleteMovieData>(dataFilePath);
|
var mainResult = JsonSerializer.DeserializeFromFile<CompleteMovieData>(dataFilePath);
|
||||||
|
|
||||||
|
@ -577,10 +577,11 @@ namespace MediaBrowser.Providers.Movies
|
||||||
/// Gets the data file path.
|
/// Gets the data file path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item">The item.</param>
|
/// <param name="item">The item.</param>
|
||||||
/// <param name="language">The language.</param>
|
|
||||||
/// <returns>System.String.</returns>
|
/// <returns>System.String.</returns>
|
||||||
internal string GetDataFilePath(BaseItem item, string language)
|
internal string GetDataFilePath(BaseItem item)
|
||||||
{
|
{
|
||||||
|
var language = ConfigurationManager.Configuration.PreferredMetadataLanguage;
|
||||||
|
|
||||||
var id = item.GetProviderId(MetadataProviders.Tmdb);
|
var id = item.GetProviderId(MetadataProviders.Tmdb);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(id))
|
if (string.IsNullOrEmpty(id))
|
||||||
|
@ -595,6 +596,18 @@ namespace MediaBrowser.Providers.Movies
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal string GetImagesDataFilePath(BaseItem item)
|
||||||
|
{
|
||||||
|
var path = GetDataFilePath(item);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(path))
|
||||||
|
{
|
||||||
|
path = Path.Combine(Path.GetDirectoryName(path), "default.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fetches the main result.
|
/// Fetches the main result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
166
MediaBrowser.Providers/TV/ManualTvdbEpisodeImageProvider.cs
Normal file
166
MediaBrowser.Providers/TV/ManualTvdbEpisodeImageProvider.cs
Normal file
|
@ -0,0 +1,166 @@
|
||||||
|
using System.Globalization;
|
||||||
|
using MediaBrowser.Controller.Configuration;
|
||||||
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using MediaBrowser.Controller.Providers;
|
||||||
|
using MediaBrowser.Model.Entities;
|
||||||
|
using MediaBrowser.Model.Providers;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Providers.TV
|
||||||
|
{
|
||||||
|
public class ManualTvdbEpisodeImageProvider : IImageProvider
|
||||||
|
{
|
||||||
|
private readonly IServerConfigurationManager _config;
|
||||||
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||||
|
|
||||||
|
public ManualTvdbEpisodeImageProvider(IServerConfigurationManager config)
|
||||||
|
{
|
||||||
|
_config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return "TvDb"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Supports(BaseItem item)
|
||||||
|
{
|
||||||
|
return item is Episode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, ImageType imageType, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return GetAllImages(item, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<RemoteImageInfo>> GetAllImages(BaseItem item, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var episode = (Episode)item;
|
||||||
|
|
||||||
|
var seriesId = episode.Series != null ? episode.Series.GetProviderId(MetadataProviders.Tvdb) : null;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(seriesId))
|
||||||
|
{
|
||||||
|
// Process images
|
||||||
|
var seriesDataPath = RemoteSeriesProvider.GetSeriesDataPath(_config.ApplicationPaths, seriesId);
|
||||||
|
|
||||||
|
var files = RemoteEpisodeProvider.Current.GetEpisodeXmlFiles(episode, seriesDataPath);
|
||||||
|
|
||||||
|
var result = files.Select(i => GetImageInfo(i, cancellationToken)).Where(i => i != null);
|
||||||
|
|
||||||
|
return Task.FromResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.FromResult<IEnumerable<RemoteImageInfo>>(new RemoteImageInfo[] { });
|
||||||
|
}
|
||||||
|
|
||||||
|
private RemoteImageInfo GetImageInfo(FileInfo xmlFile, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var height = 225;
|
||||||
|
var width = 400;
|
||||||
|
var url = string.Empty;
|
||||||
|
|
||||||
|
using (var streamReader = new StreamReader(xmlFile.FullName, Encoding.UTF8))
|
||||||
|
{
|
||||||
|
// Use XmlReader for best performance
|
||||||
|
using (var reader = XmlReader.Create(streamReader, new XmlReaderSettings
|
||||||
|
{
|
||||||
|
CheckCharacters = false,
|
||||||
|
IgnoreProcessingInstructions = true,
|
||||||
|
IgnoreComments = true,
|
||||||
|
ValidationType = ValidationType.None
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
reader.MoveToContent();
|
||||||
|
|
||||||
|
// Loop through each element
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
if (reader.NodeType == XmlNodeType.Element)
|
||||||
|
{
|
||||||
|
switch (reader.Name)
|
||||||
|
{
|
||||||
|
case "thumb_width":
|
||||||
|
{
|
||||||
|
var val = reader.ReadElementContentAsString();
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(val))
|
||||||
|
{
|
||||||
|
int rval;
|
||||||
|
|
||||||
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
||||||
|
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
|
||||||
|
{
|
||||||
|
width = rval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "thumb_height":
|
||||||
|
{
|
||||||
|
var val = reader.ReadElementContentAsString();
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(val))
|
||||||
|
{
|
||||||
|
int rval;
|
||||||
|
|
||||||
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
||||||
|
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
|
||||||
|
{
|
||||||
|
height = rval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "filename":
|
||||||
|
{
|
||||||
|
var val = reader.ReadElementContentAsString();
|
||||||
|
if (!string.IsNullOrWhiteSpace(val))
|
||||||
|
{
|
||||||
|
url = TVUtils.BannerUrl + val;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
reader.Skip();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(url))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RemoteImageInfo
|
||||||
|
{
|
||||||
|
Width = width,
|
||||||
|
Height = height,
|
||||||
|
ProviderName = Name,
|
||||||
|
Url = url,
|
||||||
|
Type = ImageType.Primary
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Priority
|
||||||
|
{
|
||||||
|
get { return 0; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,6 +39,8 @@ namespace MediaBrowser.Providers.TV
|
||||||
protected IHttpClient HttpClient { get; private set; }
|
protected IHttpClient HttpClient { get; private set; }
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
|
internal static RemoteEpisodeProvider Current;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RemoteEpisodeProvider" /> class.
|
/// Initializes a new instance of the <see cref="RemoteEpisodeProvider" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -52,6 +54,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
HttpClient = httpClient;
|
HttpClient = httpClient;
|
||||||
_providerManager = providerManager;
|
_providerManager = providerManager;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
|
Current = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -165,7 +168,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
/// <param name="episode">The episode.</param>
|
/// <param name="episode">The episode.</param>
|
||||||
/// <param name="seriesDataPath">The series data path.</param>
|
/// <param name="seriesDataPath">The series data path.</param>
|
||||||
/// <returns>List{FileInfo}.</returns>
|
/// <returns>List{FileInfo}.</returns>
|
||||||
private List<FileInfo> GetEpisodeXmlFiles(Episode episode, string seriesDataPath)
|
internal List<FileInfo> GetEpisodeXmlFiles(Episode episode, string seriesDataPath)
|
||||||
{
|
{
|
||||||
var files = new List<FileInfo>();
|
var files = new List<FileInfo>();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user