#551 - Add manual image selection for movies

pull/702/head
Luke Pulverenti 11 years ago
parent 6c8d919298
commit 882d0681e6

@ -1,4 +1,6 @@

using MediaBrowser.Model.Entities;
namespace MediaBrowser.Model.Providers
{
/// <summary>
@ -47,5 +49,11 @@ namespace MediaBrowser.Model.Providers
/// </summary>
/// <value>The language.</value>
public string Language { get; set; }
/// <summary>
/// Gets or sets the type.
/// </summary>
/// <value>The type.</value>
public ImageType Type { get; set; }
}
}

@ -6,6 +6,7 @@ using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -40,17 +41,27 @@ namespace MediaBrowser.Providers.Movies
public async Task<IEnumerable<RemoteImageInfo>> GetAvailableImages(BaseItem item, ImageType imageType, CancellationToken cancellationToken)
{
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var images = await GetAllImages(item, cancellationToken).ConfigureAwait(false);
var results = MovieDbImagesProvider.FetchImages(item, _jsonSerializer);
return images.Where(i => i.Type == imageType);
}
var tmdbImageUrl = tmdbSettings.images.base_url + "original";
public async Task<IEnumerable<RemoteImageInfo>> GetAllImages(BaseItem item, CancellationToken cancellationToken)
{
var list = new List<RemoteImageInfo>();
if (imageType == ImageType.Primary)
var results = FetchImages(item, _jsonSerializer);
if (results == null)
{
var sources = GetPosters(results, item);
return list;
}
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.base_url + "original";
return sources.Select(i => new RemoteImageInfo
list.AddRange(GetPosters(results, item).Select(i => new RemoteImageInfo
{
Url = tmdbImageUrl + i.file_path,
CommunityRating = i.vote_average,
@ -58,26 +69,22 @@ namespace MediaBrowser.Providers.Movies
Width = i.width,
Height = i.height,
Language = i.iso_639_1,
ProviderName = Name
});
}
ProviderName = Name,
Type = ImageType.Primary
}));
if (imageType == ImageType.Backdrop)
{
var sources = GetBackdrops(results, item);
return sources.Select(i => new RemoteImageInfo
list.AddRange(GetBackdrops(results, item).Select(i => new RemoteImageInfo
{
Url = tmdbImageUrl + i.file_path,
CommunityRating = i.vote_average,
VoteCount = i.vote_count,
Width = i.width,
Height = i.height,
ProviderName = Name
});
}
ProviderName = Name,
Type = ImageType.Backdrop
}));
throw new ArgumentException("Unrecognized ImageType: " + imageType);
return list;
}
/// <summary>
@ -86,7 +93,7 @@ namespace MediaBrowser.Providers.Movies
/// <param name="images">The images.</param>
/// <param name="item">The item.</param>
/// <returns>IEnumerable{MovieDbProvider.Poster}.</returns>
public IEnumerable<MovieDbProvider.Poster> GetPosters(MovieDbProvider.Images images, BaseItem item)
private IEnumerable<MovieDbProvider.Poster> GetPosters(MovieDbProvider.Images images, BaseItem item)
{
var language = _config.Configuration.PreferredMetadataLanguage;
@ -126,7 +133,7 @@ namespace MediaBrowser.Providers.Movies
/// <param name="images">The images.</param>
/// <param name="item">The item.</param>
/// <returns>IEnumerable{MovieDbProvider.Backdrop}.</returns>
public 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>() :
images.backdrops.Where(i => i.width >= _config.Configuration.MinMovieBackdropWidth)
@ -134,5 +141,28 @@ namespace MediaBrowser.Providers.Movies
return eligibleBackdrops.OrderByDescending(i => i.vote_average);
}
/// <summary>
/// Fetches the images.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <returns>Task{MovieImages}.</returns>
private MovieDbProvider.Images FetchImages(BaseItem item, IJsonSerializer jsonSerializer)
{
var path = MovieDbProvider.Current.GetDataFilePath(item, "default");
if (!string.IsNullOrEmpty(path))
{
var fileInfo = new FileInfo(path);
if (fileInfo.Exists)
{
return jsonSerializer.DeserializeFromFile<MovieDbProvider.CompleteMovieData>(path).images;
}
}
return null;
}
}
}

@ -7,6 +7,7 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using System;
using System.Collections.Generic;
@ -179,45 +180,18 @@ namespace MediaBrowser.Providers.Movies
{
var id = item.GetProviderId(MetadataProviders.Tmdb);
var status = ProviderRefreshStatus.Success;
if (!string.IsNullOrEmpty(id))
{
var images = FetchImages(item, _jsonSerializer);
var images = await new ManualMovieDbImageProvider(_jsonSerializer, ConfigurationManager).GetAllImages(item,
cancellationToken).ConfigureAwait(false);
if (images != null)
{
status = await ProcessImages(item, images, cancellationToken).ConfigureAwait(false);
}
await ProcessImages(item, images.ToList(), cancellationToken).ConfigureAwait(false);
}
SetLastRefreshed(item, DateTime.UtcNow, status);
SetLastRefreshed(item, DateTime.UtcNow);
return true;
}
/// <summary>
/// Fetches the images.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <returns>Task{MovieImages}.</returns>
internal static MovieDbProvider.Images FetchImages(BaseItem item, IJsonSerializer jsonSerializer)
{
var path = MovieDbProvider.Current.GetDataFilePath(item, "default");
if (!string.IsNullOrEmpty(path))
{
var fileInfo = new FileInfo(path);
if (fileInfo.Exists)
{
return jsonSerializer.DeserializeFromFile<MovieDbProvider.CompleteMovieData>(path).images;
}
}
return null;
}
/// <summary>
/// Processes the images.
/// </summary>
@ -225,26 +199,20 @@ namespace MediaBrowser.Providers.Movies
/// <param name="images">The images.</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns>Task.</returns>
private async Task<ProviderRefreshStatus> ProcessImages(BaseItem item, MovieDbProvider.Images images, CancellationToken cancellationToken)
private async Task ProcessImages(BaseItem item, List<RemoteImageInfo> images, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var status = ProviderRefreshStatus.Success;
var eligiblePosters = new ManualMovieDbImageProvider(_jsonSerializer, ConfigurationManager).GetPosters(images, item)
var eligiblePosters = images
.Where(i => i.Type == ImageType.Primary)
.ToList();
// poster
if (eligiblePosters.Count > 0 && !item.HasImage(ImageType.Primary))
{
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.base_url + "original";
// get highest rated poster for our language
var poster = eligiblePosters[0];
var url = tmdbImageUrl + poster.file_path;
var url = poster.Url;
var img = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{
@ -253,26 +221,24 @@ namespace MediaBrowser.Providers.Movies
}).ConfigureAwait(false);
await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(poster.file_path), ImageType.Primary, null, url, cancellationToken)
await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(url), ImageType.Primary, null, url, cancellationToken)
.ConfigureAwait(false);
}
cancellationToken.ThrowIfCancellationRequested();
var eligibleBackdrops = new ManualMovieDbImageProvider(_jsonSerializer, ConfigurationManager).GetBackdrops(images, item).ToList();
var eligibleBackdrops = images
.Where(i => i.Type == ImageType.Backdrop)
.ToList();
var backdropLimit = ConfigurationManager.Configuration.MaxBackdrops;
// backdrops - only download if earlier providers didn't find any (fanart)
if (eligibleBackdrops.Count > 0 && ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && item.BackdropImagePaths.Count < backdropLimit)
{
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
var tmdbImageUrl = tmdbSettings.images.base_url + "original";
for (var i = 0; i < eligibleBackdrops.Count; i++)
{
var url = tmdbImageUrl + eligibleBackdrops[i].file_path;
var url = eligibleBackdrops[i].Url;
if (!item.ContainsImageWithSourceUrl(url))
{
@ -283,7 +249,7 @@ namespace MediaBrowser.Providers.Movies
}).ConfigureAwait(false);
await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(eligibleBackdrops[i].file_path), ImageType.Backdrop, item.BackdropImagePaths.Count, url, cancellationToken)
await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(url), ImageType.Backdrop, item.BackdropImagePaths.Count, url, cancellationToken)
.ConfigureAwait(false);
}
@ -293,8 +259,6 @@ namespace MediaBrowser.Providers.Movies
}
}
}
return status;
}
}
}

@ -4,7 +4,6 @@ using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;

@ -39,6 +39,13 @@ namespace MediaBrowser.Providers.TV
private async Task RunInternal(IProgress<double> progress, CancellationToken cancellationToken)
{
if (!_config.Configuration.EnableInternetProviders ||
_config.Configuration.InternetProviderExcludeTypes.Contains(typeof(Series).Name, StringComparer.OrdinalIgnoreCase))
{
progress.Report(100);
return;
}
var seriesList = _libraryManager.RootFolder
.RecursiveChildren
.OfType<Series>()
@ -136,21 +143,27 @@ namespace MediaBrowser.Providers.TV
.Where(i => i.Item1 != -1 && i.Item2 != -1)
.ToList();
var anySeasonsRemoved = await RemoveObsoleteOrMissingSeasons(series, episodeLookup, cancellationToken).ConfigureAwait(false);
var anySeasonsRemoved = await RemoveObsoleteOrMissingSeasons(series, episodeLookup, cancellationToken)
.ConfigureAwait(false);
var anyEpisodesRemoved = await RemoveObsoleteOrMissingEpisodes(series, episodeLookup, cancellationToken).ConfigureAwait(false);
var anyEpisodesRemoved = await RemoveObsoleteOrMissingEpisodes(series, episodeLookup, cancellationToken)
.ConfigureAwait(false);
var hasNewEpisodes = false;
if (_config.Configuration.EnableInternetProviders)
{
hasNewEpisodes = await AddMissingEpisodes(series, seriesDataPath, episodeLookup, cancellationToken).ConfigureAwait(false);
hasNewEpisodes = await AddMissingEpisodes(series, seriesDataPath, episodeLookup, cancellationToken)
.ConfigureAwait(false);
}
if (hasNewEpisodes || anySeasonsRemoved || anyEpisodesRemoved)
{
await series.RefreshMetadata(cancellationToken, true).ConfigureAwait(false);
await series.ValidateChildren(new Progress<double>(), cancellationToken, true).ConfigureAwait(false);
await series.RefreshMetadata(cancellationToken, true)
.ConfigureAwait(false);
await series.ValidateChildren(new Progress<double>(), cancellationToken, true)
.ConfigureAwait(false);
}
}

@ -1,12 +1,13 @@
using System.Globalization;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
@ -69,7 +70,8 @@ namespace MediaBrowser.Providers.TV
/// <returns>Task.</returns>
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
if (!_config.Configuration.EnableInternetProviders)
if (!_config.Configuration.EnableInternetProviders ||
_config.Configuration.InternetProviderExcludeTypes.Contains(typeof(Series).Name, StringComparer.OrdinalIgnoreCase))
{
progress.Report(100);
return;

@ -306,6 +306,24 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
});
};
self.getAvailableRemoteImages = function (itemId, imageType) {
if (!itemId) {
throw new Error("null itemId");
}
if (!imageType) {
throw new Error("null imageType");
}
var url = self.getUrl("Items/" + itemId + "/RemoteImages/" + imageType);
return self.ajax({
type: "GET",
url: url,
dataType: "json"
});
};
/**
* Gets the current server status
*/

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.182" targetFramework="net45" />
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.183" targetFramework="net45" />
<package id="ServiceStack.Common" version="3.9.62" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.62" targetFramework="net45" />
</packages>
Loading…
Cancel
Save