#174 - Fanart - missing images

This commit is contained in:
Luke Pulverenti 2013-05-12 18:57:51 -04:00
parent 2bfcf89abf
commit 1f898cef2d
12 changed files with 568 additions and 255 deletions

View File

@ -72,6 +72,7 @@
<Compile Include="Configuration\IServerConfigurationManager.cs" /> <Compile Include="Configuration\IServerConfigurationManager.cs" />
<Compile Include="Dto\SessionInfoDtoBuilder.cs" /> <Compile Include="Dto\SessionInfoDtoBuilder.cs" />
<Compile Include="Entities\Audio\MusicAlbumDisc.cs" /> <Compile Include="Entities\Audio\MusicAlbumDisc.cs" />
<Compile Include="Providers\Movies\MovieDbImagesProvider.cs" />
<Compile Include="Session\ISessionManager.cs" /> <Compile Include="Session\ISessionManager.cs" />
<Compile Include="Drawing\ImageExtensions.cs" /> <Compile Include="Drawing\ImageExtensions.cs" />
<Compile Include="Drawing\ImageHeader.cs" /> <Compile Include="Drawing\ImageHeader.cs" />

View File

@ -24,10 +24,15 @@ namespace MediaBrowser.Controller.Providers
/// </summary> /// </summary>
Third = 3, Third = 3,
/// <summary>
/// The fourth
/// </summary>
Fourth = 4,
// Run this provider last // Run this provider last
/// <summary> /// <summary>
/// The last /// The last
/// </summary> /// </summary>
Last = 4 Last = 5
} }
} }

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common.Net; using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.Movies;
@ -6,7 +7,8 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net; using MediaBrowser.Model.Net;
using System; using System;
using System.IO; using System.Collections.Generic;
using System.Globalization;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml; using System.Xml;
@ -26,6 +28,8 @@ namespace MediaBrowser.Controller.Providers.Movies
private readonly IProviderManager _providerManager; private readonly IProviderManager _providerManager;
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="FanArtMovieProvider" /> class. /// Initializes a new instance of the <see cref="FanArtMovieProvider" /> class.
/// </summary> /// </summary>
@ -57,6 +61,30 @@ namespace MediaBrowser.Controller.Providers.Movies
} }
} }
/// <summary>
/// Gets a value indicating whether [refresh on version change].
/// </summary>
/// <value><c>true</c> if [refresh on version change]; otherwise, <c>false</c>.</value>
protected override bool RefreshOnVersionChange
{
get
{
return true;
}
}
/// <summary>
/// Gets the provider version.
/// </summary>
/// <value>The provider version.</value>
protected override string ProviderVersion
{
get
{
return "12";
}
}
/// <summary> /// <summary>
/// The fan art base URL /// The fan art base URL
/// </summary> /// </summary>
@ -92,9 +120,18 @@ namespace MediaBrowser.Controller.Providers.Movies
return false; return false;
} }
// Refresh if tmdb id has changed
if (providerInfo.Data != GetComparisonData(item.GetProviderId(MetadataProviders.Tmdb)))
{
return true;
}
if (!ConfigurationManager.Configuration.DownloadMovieImages.Art && if (!ConfigurationManager.Configuration.DownloadMovieImages.Art &&
!ConfigurationManager.Configuration.DownloadMovieImages.Logo && !ConfigurationManager.Configuration.DownloadMovieImages.Logo &&
!ConfigurationManager.Configuration.DownloadMovieImages.Disc) !ConfigurationManager.Configuration.DownloadMovieImages.Disc &&
!ConfigurationManager.Configuration.DownloadMovieImages.Backdrops &&
!ConfigurationManager.Configuration.DownloadMovieImages.Banner &&
!ConfigurationManager.Configuration.DownloadMovieImages.Thumb)
{ {
return false; return false;
} }
@ -102,6 +139,15 @@ namespace MediaBrowser.Controller.Providers.Movies
return base.NeedsRefreshInternal(item, providerInfo); return base.NeedsRefreshInternal(item, providerInfo);
} }
/// <summary>
/// Gets the comparison data.
/// </summary>
/// <returns>Guid.</returns>
private Guid GetComparisonData(string id)
{
return string.IsNullOrEmpty(id) ? Guid.Empty : id.GetMD5();
}
/// <summary> /// <summary>
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done /// Fetches metadata and returns true or false indicating if any work that requires persistence was done
/// </summary> /// </summary>
@ -113,28 +159,32 @@ namespace MediaBrowser.Controller.Providers.Movies
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
BaseProviderInfo data;
if (!item.ProviderData.TryGetValue(Id, out data))
{
data = new BaseProviderInfo();
item.ProviderData[Id] = data;
}
var status = ProviderRefreshStatus.Success;
var movie = item; var movie = item;
var language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower(); var language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
var url = string.Format(FanArtBaseUrl, APIKey, movie.GetProviderId(MetadataProviders.Tmdb)); var url = string.Format(FanArtBaseUrl, APIKey, movie.GetProviderId(MetadataProviders.Tmdb));
var doc = new XmlDocument(); var doc = new XmlDocument();
try using (var xml = await HttpClient.Get(new HttpRequestOptions
{ {
using (var xml = await HttpClient.Get(new HttpRequestOptions Url = url,
{ ResourcePool = FanArtResourcePool,
Url = url, CancellationToken = cancellationToken,
ResourcePool = FanArtResourcePool, EnableResponseCache = true
CancellationToken = cancellationToken,
EnableResponseCache = true
}).ConfigureAwait(false)) }).ConfigureAwait(false))
{
doc.Load(xml);
}
}
catch (HttpException)
{ {
doc.Load(xml);
} }
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@ -170,10 +220,7 @@ namespace MediaBrowser.Controller.Providers.Movies
} }
catch (HttpException) catch (HttpException)
{ {
} status = ProviderRefreshStatus.CompletedWithErrors;
catch (IOException)
{
} }
} }
} }
@ -199,10 +246,7 @@ namespace MediaBrowser.Controller.Providers.Movies
} }
catch (HttpException) catch (HttpException)
{ {
} status = ProviderRefreshStatus.CompletedWithErrors;
catch (IOException)
{
} }
} }
} }
@ -225,10 +269,7 @@ namespace MediaBrowser.Controller.Providers.Movies
} }
catch (HttpException) catch (HttpException)
{ {
} status = ProviderRefreshStatus.CompletedWithErrors;
catch (IOException)
{
} }
} }
} }
@ -252,10 +293,7 @@ namespace MediaBrowser.Controller.Providers.Movies
} }
catch (HttpException) catch (HttpException)
{ {
} status = ProviderRefreshStatus.CompletedWithErrors;
catch (IOException)
{
} }
} }
} }
@ -279,15 +317,49 @@ namespace MediaBrowser.Controller.Providers.Movies
} }
catch (HttpException) catch (HttpException)
{ {
} status = ProviderRefreshStatus.CompletedWithErrors;
catch (IOException)
{
} }
} }
} }
var hasBackdrop = item.LocationType == LocationType.FileSystem ?
item.ResolveArgs.ContainsMetaFileByName(BACKDROP_FILE)
: item.BackdropImagePaths.Count > 0;
if (ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && !hasBackdrop)
{
var nodes = doc.SelectNodes("//fanart/movie/moviebackgrounds//@url");
if (nodes != null)
{
var numBackdrops = 0;
item.BackdropImagePaths = new List<string>();
foreach (XmlNode node in nodes)
{
path = node.Value;
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting Backdrop for " + item.Name);
try
{
item.BackdropImagePaths.Add(await _providerManager.DownloadAndSaveImage(item, path, ("backdrop" + (numBackdrops > 0 ? numBackdrops.ToString(UsCulture) : "") + ".jpg"), saveLocal, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
numBackdrops++;
if (numBackdrops >= ConfigurationManager.Configuration.MaxBackdrops) break;
}
catch (HttpException)
{
status = ProviderRefreshStatus.CompletedWithErrors;
}
}
}
}
}
} }
SetLastRefreshed(movie, DateTime.UtcNow);
data.Data = GetComparisonData(item.GetProviderId(MetadataProviders.Tmdb));
SetLastRefreshed(movie, DateTime.UtcNow, status);
return true; return true;
} }

View File

@ -0,0 +1,408 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Providers.Movies
{
/// <summary>
/// Class MovieDbImagesProvider
/// </summary>
public class MovieDbImagesProvider : BaseMetadataProvider
{
/// <summary>
/// The get images
/// </summary>
private const string GetImages = @"http://api.themoviedb.org/3/{2}/{0}/images?api_key={1}";
/// <summary>
/// The _provider manager
/// </summary>
private readonly IProviderManager _providerManager;
/// <summary>
/// The _json serializer
/// </summary>
private readonly IJsonSerializer _jsonSerializer;
/// <summary>
/// The _HTTP client
/// </summary>
private readonly IHttpClient _httpClient;
/// <summary>
/// Initializes a new instance of the <see cref="MovieDbImagesProvider"/> class.
/// </summary>
/// <param name="logManager">The log manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <param name="providerManager">The provider manager.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <param name="httpClient">The HTTP client.</param>
public MovieDbImagesProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager, IJsonSerializer jsonSerializer, IHttpClient httpClient)
: base(logManager, configurationManager)
{
_providerManager = providerManager;
_jsonSerializer = jsonSerializer;
_httpClient = httpClient;
}
/// <summary>
/// Gets the priority.
/// </summary>
/// <value>The priority.</value>
public override MetadataProviderPriority Priority
{
get { return MetadataProviderPriority.Fourth; }
}
/// <summary>
/// Supports the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
public override bool Supports(BaseItem item)
{
var trailer = item as Trailer;
if (trailer != null)
{
return !trailer.IsLocalTrailer;
}
// Don't support local trailers
return item is Movie || item is BoxSet;
}
/// <summary>
/// Gets a value indicating whether [requires internet].
/// </summary>
/// <value><c>true</c> if [requires internet]; otherwise, <c>false</c>.</value>
public override bool RequiresInternet
{
get
{
return true;
}
}
/// <summary>
/// If we save locally, refresh if they delete something
/// </summary>
/// <value><c>true</c> if [refresh on file system stamp change]; otherwise, <c>false</c>.</value>
protected override bool RefreshOnFileSystemStampChange
{
get
{
return ConfigurationManager.Configuration.SaveLocalMeta;
}
}
/// <summary>
/// Gets a value indicating whether [refresh on version change].
/// </summary>
/// <value><c>true</c> if [refresh on version change]; otherwise, <c>false</c>.</value>
protected override bool RefreshOnVersionChange
{
get
{
return true;
}
}
/// <summary>
/// Gets the provider version.
/// </summary>
/// <value>The provider version.</value>
protected override string ProviderVersion
{
get
{
return "3";
}
}
/// <summary>
/// Needses the refresh internal.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="providerInfo">The provider info.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
{
if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tmdb)))
{
return false;
}
// Refresh if tmdb id has changed
if (providerInfo.Data != GetComparisonData(item.GetProviderId(MetadataProviders.Tmdb)))
{
return true;
}
return base.NeedsRefreshInternal(item, providerInfo);
}
/// <summary>
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
/// </summary>
/// <param name="item">The item.</param>
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns>Task{System.Boolean}.</returns>
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
BaseProviderInfo data;
if (!item.ProviderData.TryGetValue(Id, out data))
{
data = new BaseProviderInfo();
item.ProviderData[Id] = data;
}
var images = await FetchImages(item, item.GetProviderId(MetadataProviders.Tmdb), cancellationToken).ConfigureAwait(false);
var status = await ProcessImages(item, images, cancellationToken).ConfigureAwait(false);
data.Data = GetComparisonData(item.GetProviderId(MetadataProviders.Tmdb));
SetLastRefreshed(item, DateTime.UtcNow, status);
return true;
}
/// <summary>
/// Gets the comparison data.
/// </summary>
/// <returns>Guid.</returns>
private Guid GetComparisonData(string id)
{
return string.IsNullOrEmpty(id) ? Guid.Empty : id.GetMD5();
}
/// <summary>
/// Fetches the images.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="id">The id.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{MovieImages}.</returns>
private async Task<MovieImages> FetchImages(BaseItem item, string id, CancellationToken cancellationToken)
{
using (var json = await _httpClient.Get(new HttpRequestOptions
{
Url = string.Format(GetImages, id, MovieDbProvider.ApiKey, item is BoxSet ? "collection" : "movie"),
CancellationToken = cancellationToken,
ResourcePool = MovieDbProvider.Current.MovieDbResourcePool,
AcceptHeader = MovieDbProvider.AcceptHeader,
EnableResponseCache = true
}).ConfigureAwait(false))
{
return _jsonSerializer.DeserializeFromStream<MovieImages>(json);
}
}
/// <summary>
/// Processes the images.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="images">The images.</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns>Task.</returns>
protected virtual async Task<ProviderRefreshStatus> ProcessImages(BaseItem item, MovieImages images, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var status = ProviderRefreshStatus.Success;
var hasLocalPoster = item.LocationType == LocationType.FileSystem ? item.HasLocalImage("folder") : item.HasImage(ImageType.Primary);
// poster
if (images.posters != null && images.posters.Count > 0 && (ConfigurationManager.Configuration.RefreshItemImages || !hasLocalPoster))
{
var tmdbSettings = await MovieDbProvider.Current.TmdbSettings.ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedPosterSize;
// get highest rated poster for our language
var postersSortedByVote = images.posters.OrderByDescending(i => i.vote_average);
var poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 != null && p.iso_639_1.Equals(ConfigurationManager.Configuration.PreferredMetadataLanguage, StringComparison.OrdinalIgnoreCase));
if (poster == null && !ConfigurationManager.Configuration.PreferredMetadataLanguage.Equals("en"))
{
// couldn't find our specific language, find english (if that wasn't our language)
poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 != null && p.iso_639_1.Equals("en", StringComparison.OrdinalIgnoreCase));
}
if (poster == null)
{
//still couldn't find it - try highest rated null one
poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 == null);
}
if (poster == null)
{
//finally - just get the highest rated one
poster = postersSortedByVote.FirstOrDefault();
}
if (poster != null)
{
try
{
item.PrimaryImagePath = await _providerManager.DownloadAndSaveImage(item, tmdbImageUrl + poster.file_path, "folder" + Path.GetExtension(poster.file_path), ConfigurationManager.Configuration.SaveLocalMeta && item.LocationType == LocationType.FileSystem, MovieDbProvider.Current.MovieDbResourcePool, cancellationToken).ConfigureAwait(false);
}
catch (HttpException)
{
status = ProviderRefreshStatus.CompletedWithErrors;
}
}
}
cancellationToken.ThrowIfCancellationRequested();
// backdrops
if (images.backdrops != null && images.backdrops.Count > 0 && ConfigurationManager.Configuration.DownloadMovieImages.Backdrops)
{
item.BackdropImagePaths = new List<string>();
var tmdbSettings = await MovieDbProvider.Current.TmdbSettings.ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedBackdropSize;
//backdrops should be in order of rating. get first n ones
var numToFetch = Math.Min(ConfigurationManager.Configuration.MaxBackdrops, images.backdrops.Count);
for (var i = 0; i < numToFetch; i++)
{
var bdName = "backdrop" + (i == 0 ? "" : i.ToString(CultureInfo.InvariantCulture));
var hasLocalBackdrop = item.LocationType == LocationType.FileSystem ? item.HasLocalImage(bdName) : item.BackdropImagePaths.Count > i;
if (ConfigurationManager.Configuration.RefreshItemImages || !hasLocalBackdrop)
{
try
{
item.BackdropImagePaths.Add(await _providerManager.DownloadAndSaveImage(item, tmdbImageUrl + images.backdrops[i].file_path, bdName + Path.GetExtension(images.backdrops[i].file_path), ConfigurationManager.Configuration.SaveLocalMeta && item.LocationType == LocationType.FileSystem, MovieDbProvider.Current.MovieDbResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
status = ProviderRefreshStatus.CompletedWithErrors;
}
}
}
}
return status;
}
/// <summary>
/// Class Backdrop
/// </summary>
protected class Backdrop
{
/// <summary>
/// Gets or sets the file_path.
/// </summary>
/// <value>The file_path.</value>
public string file_path { get; set; }
/// <summary>
/// Gets or sets the width.
/// </summary>
/// <value>The width.</value>
public int width { get; set; }
/// <summary>
/// Gets or sets the height.
/// </summary>
/// <value>The height.</value>
public int height { get; set; }
/// <summary>
/// Gets or sets the iso_639_1.
/// </summary>
/// <value>The iso_639_1.</value>
public string iso_639_1 { get; set; }
/// <summary>
/// Gets or sets the aspect_ratio.
/// </summary>
/// <value>The aspect_ratio.</value>
public double aspect_ratio { get; set; }
/// <summary>
/// Gets or sets the vote_average.
/// </summary>
/// <value>The vote_average.</value>
public double vote_average { get; set; }
/// <summary>
/// Gets or sets the vote_count.
/// </summary>
/// <value>The vote_count.</value>
public int vote_count { get; set; }
}
/// <summary>
/// Class Poster
/// </summary>
protected class Poster
{
/// <summary>
/// Gets or sets the file_path.
/// </summary>
/// <value>The file_path.</value>
public string file_path { get; set; }
/// <summary>
/// Gets or sets the width.
/// </summary>
/// <value>The width.</value>
public int width { get; set; }
/// <summary>
/// Gets or sets the height.
/// </summary>
/// <value>The height.</value>
public int height { get; set; }
/// <summary>
/// Gets or sets the iso_639_1.
/// </summary>
/// <value>The iso_639_1.</value>
public string iso_639_1 { get; set; }
/// <summary>
/// Gets or sets the aspect_ratio.
/// </summary>
/// <value>The aspect_ratio.</value>
public double aspect_ratio { get; set; }
/// <summary>
/// Gets or sets the vote_average.
/// </summary>
/// <value>The vote_average.</value>
public double vote_average { get; set; }
/// <summary>
/// Gets or sets the vote_count.
/// </summary>
/// <value>The vote_count.</value>
public int vote_count { get; set; }
}
/// <summary>
/// Class MovieImages
/// </summary>
protected class MovieImages
{
/// <summary>
/// Gets or sets the backdrops.
/// </summary>
/// <value>The backdrops.</value>
public List<Backdrop> backdrops { get; set; }
/// <summary>
/// Gets or sets the posters.
/// </summary>
/// <value>The posters.</value>
public List<Poster> posters { get; set; }
}
}
}

View File

@ -274,7 +274,6 @@ namespace MediaBrowser.Controller.Providers.Movies
private const string TmdbConfigUrl = "http://api.themoviedb.org/3/configuration?api_key={0}"; private const string TmdbConfigUrl = "http://api.themoviedb.org/3/configuration?api_key={0}";
private const string Search3 = @"http://api.themoviedb.org/3/search/movie?api_key={1}&query={0}&language={2}"; private const string Search3 = @"http://api.themoviedb.org/3/search/movie?api_key={1}&query={0}&language={2}";
private const string AltTitleSearch = @"http://api.themoviedb.org/3/movie/{0}/alternative_titles?api_key={1}&country={2}"; private const string AltTitleSearch = @"http://api.themoviedb.org/3/movie/{0}/alternative_titles?api_key={1}&country={2}";
private const string GetImages = @"http://api.themoviedb.org/3/{2}/{0}/images?api_key={1}";
private const string GetMovieInfo3 = @"http://api.themoviedb.org/3/movie/{0}?api_key={1}&language={2}&append_to_response=casts,releases,images,keywords"; private const string GetMovieInfo3 = @"http://api.themoviedb.org/3/movie/{0}?api_key={1}&language={2}&append_to_response=casts,releases,images,keywords";
private const string GetBoxSetInfo3 = @"http://api.themoviedb.org/3/collection/{0}?api_key={1}&language={2}&append_to_response=images"; private const string GetBoxSetInfo3 = @"http://api.themoviedb.org/3/collection/{0}?api_key={1}&language={2}&append_to_response=images";
@ -793,10 +792,6 @@ namespace MediaBrowser.Controller.Providers.Movies
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
mainResult.images = await FetchImages(item, id, cancellationToken).ConfigureAwait(false);
await ProcessImages(item, mainResult.images, cancellationToken).ConfigureAwait(false);
//and save locally //and save locally
if (ConfigurationManager.Configuration.SaveLocalMeta && item.LocationType == LocationType.FileSystem) if (ConfigurationManager.Configuration.SaveLocalMeta && item.LocationType == LocationType.FileSystem)
{ {
@ -809,22 +804,6 @@ namespace MediaBrowser.Controller.Providers.Movies
} }
} }
private async Task<MovieImages> FetchImages(BaseItem item, string id, CancellationToken cancellationToken)
{
using (var json = await HttpClient.Get(new HttpRequestOptions
{
Url = string.Format(GetImages, id, ApiKey, item is BoxSet ? "collection" : "movie"),
CancellationToken = cancellationToken,
ResourcePool = Current.MovieDbResourcePool,
AcceptHeader = AcceptHeader,
EnableResponseCache = true
}).ConfigureAwait(false))
{
return JsonSerializer.DeserializeFromStream<MovieImages>(json);
}
}
/// <summary> /// <summary>
/// Fetches the main result. /// Fetches the main result.
/// </summary> /// </summary>
@ -1043,97 +1022,6 @@ namespace MediaBrowser.Controller.Providers.Movies
} }
/// <summary>
/// Processes the images.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="images">The images.</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns>Task.</returns>
protected virtual async Task ProcessImages(BaseItem item, MovieImages images, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var hasLocalPoster = item.LocationType == LocationType.FileSystem ? item.HasLocalImage("folder") : item.HasImage(ImageType.Primary);
// poster
if (images.posters != null && images.posters.Count > 0 && (ConfigurationManager.Configuration.RefreshItemImages || !hasLocalPoster))
{
var tmdbSettings = await TmdbSettings.ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedPosterSize;
// get highest rated poster for our language
var postersSortedByVote = images.posters.OrderByDescending(i => i.vote_average);
var poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 != null && p.iso_639_1.Equals(ConfigurationManager.Configuration.PreferredMetadataLanguage, StringComparison.OrdinalIgnoreCase));
if (poster == null && !ConfigurationManager.Configuration.PreferredMetadataLanguage.Equals("en"))
{
// couldn't find our specific language, find english (if that wasn't our language)
poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 != null && p.iso_639_1.Equals("en", StringComparison.OrdinalIgnoreCase));
}
if (poster == null)
{
//still couldn't find it - try highest rated null one
poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 == null);
}
if (poster == null)
{
//finally - just get the highest rated one
poster = postersSortedByVote.FirstOrDefault();
}
if (poster != null)
{
try
{
item.PrimaryImagePath = await ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + poster.file_path, "folder" + Path.GetExtension(poster.file_path), ConfigurationManager.Configuration.SaveLocalMeta && item.LocationType == LocationType.FileSystem, MovieDbResourcePool, cancellationToken).ConfigureAwait(false);
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
cancellationToken.ThrowIfCancellationRequested();
// backdrops
if (images.backdrops != null && images.backdrops.Count > 0)
{
item.BackdropImagePaths = new List<string>();
var tmdbSettings = await TmdbSettings.ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedBackdropSize;
//backdrops should be in order of rating. get first n ones
var numToFetch = Math.Min(ConfigurationManager.Configuration.MaxBackdrops, images.backdrops.Count);
for (var i = 0; i < numToFetch; i++)
{
var bdName = "backdrop" + (i == 0 ? "" : i.ToString(CultureInfo.InvariantCulture));
var hasLocalBackdrop = item.LocationType == LocationType.FileSystem ? item.HasLocalImage(bdName) : item.BackdropImagePaths.Count > i;
if (ConfigurationManager.Configuration.RefreshItemImages || !hasLocalBackdrop)
{
try
{
item.BackdropImagePaths.Add(await ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + images.backdrops[i].file_path, bdName + Path.GetExtension(images.backdrops[i].file_path), ConfigurationManager.Configuration.SaveLocalMeta && item.LocationType == LocationType.FileSystem, MovieDbResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
}
catch (IOException)
{
}
}
}
}
}
/// <summary> /// <summary>
/// The remove /// The remove
@ -1445,34 +1333,6 @@ namespace MediaBrowser.Controller.Providers.Movies
public List<Country> countries { get; set; } public List<Country> countries { get; set; }
} }
protected class Backdrop
{
public string file_path { get; set; }
public int width { get; set; }
public int height { get; set; }
public string iso_639_1 { get; set; }
public double aspect_ratio { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
}
protected class Poster
{
public string file_path { get; set; }
public int width { get; set; }
public int height { get; set; }
public string iso_639_1 { get; set; }
public double aspect_ratio { get; set; }
public double vote_average { get; set; }
public int vote_count { get; set; }
}
protected class MovieImages
{
public List<Backdrop> backdrops { get; set; }
public List<Poster> posters { get; set; }
}
protected class Keyword protected class Keyword
{ {
public int id { get; set; } public int id { get; set; }
@ -1511,7 +1371,6 @@ namespace MediaBrowser.Controller.Providers.Movies
public int vote_count { get; set; } public int vote_count { get; set; }
public Casts casts { get; set; } public Casts casts { get; set; }
public Releases releases { get; set; } public Releases releases { get; set; }
public MovieImages images { get; set; }
public Keywords keywords { get; set; } public Keywords keywords { get; set; }
} }

View File

@ -121,7 +121,7 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo) protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
{ {
// Refresh if rt id has changed // Refresh if imdb id has changed
if (providerInfo.Data != GetComparisonData(item.GetProviderId(MetadataProviders.Imdb))) if (providerInfo.Data != GetComparisonData(item.GetProviderId(MetadataProviders.Imdb)))
{ {
return true; return true;

View File

@ -204,23 +204,17 @@ namespace MediaBrowser.Controller.Providers.Movies
string url = string.Format(@"http://api.themoviedb.org/3/person/{1}?api_key={0}&append_to_response=credits,images", MovieDbProvider.ApiKey, id); string url = string.Format(@"http://api.themoviedb.org/3/person/{1}?api_key={0}&append_to_response=credits,images", MovieDbProvider.ApiKey, id);
PersonResult searchResult = null; PersonResult searchResult = null;
try using (var json = await HttpClient.Get(new HttpRequestOptions
{ {
using (var json = await HttpClient.Get(new HttpRequestOptions Url = url,
{ CancellationToken = cancellationToken,
Url = url, ResourcePool = MovieDbProvider.Current.MovieDbResourcePool,
CancellationToken = cancellationToken, AcceptHeader = MovieDbProvider.AcceptHeader,
ResourcePool = MovieDbProvider.Current.MovieDbResourcePool, EnableResponseCache = true
AcceptHeader = MovieDbProvider.AcceptHeader,
EnableResponseCache = true
}).ConfigureAwait(false)) }).ConfigureAwait(false))
{
searchResult = JsonSerializer.DeserializeFromStream<PersonResult>(json);
}
}
catch (HttpException)
{ {
searchResult = JsonSerializer.DeserializeFromStream<PersonResult>(json);
} }
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();

View File

@ -139,22 +139,18 @@ namespace MediaBrowser.Controller.Providers.Music
var doc = new XmlDocument(); var doc = new XmlDocument();
try var status = ProviderRefreshStatus.Success;
{
using (var xml = await HttpClient.Get(new HttpRequestOptions
{
Url = url,
ResourcePool = FanArtResourcePool,
CancellationToken = cancellationToken,
EnableResponseCache = true
}).ConfigureAwait(false)) using (var xml = await HttpClient.Get(new HttpRequestOptions
{
doc.Load(xml);
}
}
catch (HttpException)
{ {
Url = url,
ResourcePool = FanArtResourcePool,
CancellationToken = cancellationToken,
EnableResponseCache = true
}).ConfigureAwait(false))
{
doc.Load(xml);
} }
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@ -176,10 +172,7 @@ namespace MediaBrowser.Controller.Providers.Music
} }
catch (HttpException) catch (HttpException)
{ {
} status = ProviderRefreshStatus.CompletedWithErrors;
catch (IOException)
{
} }
} }
} }
@ -199,16 +192,13 @@ namespace MediaBrowser.Controller.Providers.Music
} }
catch (HttpException) catch (HttpException)
{ {
} status = ProviderRefreshStatus.CompletedWithErrors;
catch (IOException)
{
} }
} }
} }
} }
SetLastRefreshed(item, DateTime.UtcNow); SetLastRefreshed(item, DateTime.UtcNow, status);
return true; return true;
} }

View File

@ -1,5 +1,4 @@
using System.Globalization; 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.Audio; using MediaBrowser.Controller.Entities.Audio;
@ -8,7 +7,7 @@ using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net; using MediaBrowser.Model.Net;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.Globalization;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml; using System.Xml;
@ -118,22 +117,18 @@ namespace MediaBrowser.Controller.Providers.Music
var url = string.Format(FanArtBaseUrl, APIKey, item.GetProviderId(MetadataProviders.Musicbrainz)); var url = string.Format(FanArtBaseUrl, APIKey, item.GetProviderId(MetadataProviders.Musicbrainz));
var doc = new XmlDocument(); var doc = new XmlDocument();
try var status = ProviderRefreshStatus.Success;
{
using (var xml = await HttpClient.Get(new HttpRequestOptions
{
Url = url,
ResourcePool = FanArtResourcePool,
CancellationToken = cancellationToken,
EnableResponseCache = true
}).ConfigureAwait(false)) using (var xml = await HttpClient.Get(new HttpRequestOptions
{
doc.Load(xml);
}
}
catch (HttpException)
{ {
Url = url,
ResourcePool = FanArtResourcePool,
CancellationToken = cancellationToken,
EnableResponseCache = true
}).ConfigureAwait(false))
{
doc.Load(xml);
} }
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@ -157,10 +152,7 @@ namespace MediaBrowser.Controller.Providers.Music
} }
catch (HttpException) catch (HttpException)
{ {
} status = ProviderRefreshStatus.CompletedWithErrors;
catch (IOException)
{
} }
} }
} }
@ -187,10 +179,7 @@ namespace MediaBrowser.Controller.Providers.Music
} }
catch (HttpException) catch (HttpException)
{ {
} status = ProviderRefreshStatus.CompletedWithErrors;
catch (IOException)
{
} }
} }
} }
@ -216,10 +205,7 @@ namespace MediaBrowser.Controller.Providers.Music
} }
catch (HttpException) catch (HttpException)
{ {
} status = ProviderRefreshStatus.CompletedWithErrors;
catch (IOException)
{
} }
} }
} }
@ -239,10 +225,7 @@ namespace MediaBrowser.Controller.Providers.Music
} }
catch (HttpException) catch (HttpException)
{ {
} status = ProviderRefreshStatus.CompletedWithErrors;
catch (IOException)
{
} }
} }
} }
@ -263,16 +246,13 @@ namespace MediaBrowser.Controller.Providers.Music
} }
catch (HttpException) catch (HttpException)
{ {
} status = ProviderRefreshStatus.CompletedWithErrors;
catch (IOException)
{
} }
} }
} }
} }
SetLastRefreshed(item, DateTime.UtcNow); SetLastRefreshed(item, DateTime.UtcNow, status);
return true; return true;
} }
} }

View File

@ -255,7 +255,7 @@ namespace MediaBrowser.Model.Configuration
DownloadMusicArtistImages = new ImageDownloadOptions(); DownloadMusicArtistImages = new ImageDownloadOptions();
DownloadMusicAlbumImages = new ImageDownloadOptions(); DownloadMusicAlbumImages = new ImageDownloadOptions();
DownloadHDFanArt = true; DownloadHDFanArt = true;
MaxBackdrops = 4; MaxBackdrops = 3;
SortReplaceCharacters = new[] { ".", "+", "%" }; SortReplaceCharacters = new[] { ".", "+", "%" };
SortRemoveCharacters = new[] { ",", "&", "-", "{", "}", "'" }; SortRemoveCharacters = new[] { ",", "&", "-", "{", "}", "'" };

View File

@ -95,6 +95,10 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return name; return name;
}()); }());
self.deviceId = function () {
return deviceId;
};
self.encodeName = function (name) { self.encodeName = function (name) {
name = name.split('/').join('-'); name = name.split('/').join('-');

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.108" targetFramework="net45" /> <package id="MediaBrowser.ApiClient.Javascript" version="3.0.109" targetFramework="net45" />
<package id="ServiceStack.Common" version="3.9.44" targetFramework="net45" /> <package id="ServiceStack.Common" version="3.9.44" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.44" targetFramework="net45" /> <package id="ServiceStack.Text" version="3.9.44" targetFramework="net45" />
</packages> </packages>