2013-11-05 16:52:43 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.Movies
|
|
|
|
|
{
|
|
|
|
|
public class ManualMovieDbPersonImageProvider : IImageProvider
|
|
|
|
|
{
|
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
|
private readonly IJsonSerializer _jsonSerializer;
|
|
|
|
|
|
|
|
|
|
public ManualMovieDbPersonImageProvider(IServerConfigurationManager config, IJsonSerializer jsonSerializer)
|
|
|
|
|
{
|
|
|
|
|
_config = config;
|
|
|
|
|
_jsonSerializer = jsonSerializer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return ProviderName; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ProviderName
|
|
|
|
|
{
|
|
|
|
|
get { return "TheMovieDb"; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-21 18:37:34 +00:00
|
|
|
|
public bool Supports(IHasImages item)
|
2013-11-05 16:52:43 +00:00
|
|
|
|
{
|
|
|
|
|
return item is Person;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-21 18:37:34 +00:00
|
|
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, ImageType imageType, CancellationToken cancellationToken)
|
2013-11-05 16:52:43 +00:00
|
|
|
|
{
|
|
|
|
|
var images = await GetAllImages(item, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return images.Where(i => i.Type == imageType);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-23 04:22:40 +00:00
|
|
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetAllImages(IHasImages item, CancellationToken cancellationToken)
|
2013-11-05 16:52:43 +00:00
|
|
|
|
{
|
2013-12-21 18:37:34 +00:00
|
|
|
|
var person = (Person)item;
|
|
|
|
|
var id = person.GetProviderId(MetadataProviders.Tmdb);
|
2013-11-05 16:52:43 +00:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(id))
|
|
|
|
|
{
|
2013-12-23 04:22:40 +00:00
|
|
|
|
await MovieDbPersonProvider.Current.DownloadPersonInfoIfNeeded(id, cancellationToken).ConfigureAwait(false);
|
2013-11-05 16:52:43 +00:00
|
|
|
|
|
2013-12-23 04:22:40 +00:00
|
|
|
|
var dataFilePath = MovieDbPersonProvider.GetPersonDataFilePath(_config.ApplicationPaths, id);
|
2013-11-05 16:52:43 +00:00
|
|
|
|
|
2013-12-23 04:22:40 +00:00
|
|
|
|
var result = _jsonSerializer.DeserializeFromFile<MovieDbPersonProvider.PersonResult>(dataFilePath);
|
2013-11-05 16:52:43 +00:00
|
|
|
|
|
2013-12-23 04:22:40 +00:00
|
|
|
|
var images = result.images ?? new MovieDbPersonProvider.Images();
|
2013-11-05 16:52:43 +00:00
|
|
|
|
|
2013-12-23 04:22:40 +00:00
|
|
|
|
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
|
2013-11-05 16:52:43 +00:00
|
|
|
|
|
2013-12-23 04:22:40 +00:00
|
|
|
|
var tmdbImageUrl = tmdbSettings.images.base_url + "original";
|
2013-12-02 15:47:24 +00:00
|
|
|
|
|
2013-12-27 00:23:58 +00:00
|
|
|
|
return GetImages(images, item.GetPreferredMetadataLanguage(), tmdbImageUrl);
|
2013-11-05 16:52:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new List<RemoteImageInfo>();
|
|
|
|
|
}
|
2013-12-21 18:37:34 +00:00
|
|
|
|
|
2013-12-27 00:23:58 +00:00
|
|
|
|
private IEnumerable<RemoteImageInfo> GetImages(MovieDbPersonProvider.Images images, string preferredLanguage, string baseImageUrl)
|
2013-11-05 16:52:43 +00:00
|
|
|
|
{
|
|
|
|
|
var list = new List<RemoteImageInfo>();
|
|
|
|
|
|
|
|
|
|
if (images.profiles != null)
|
|
|
|
|
{
|
|
|
|
|
list.AddRange(images.profiles.Select(i => new RemoteImageInfo
|
|
|
|
|
{
|
|
|
|
|
ProviderName = Name,
|
|
|
|
|
Type = ImageType.Primary,
|
|
|
|
|
Width = i.width,
|
|
|
|
|
Height = i.height,
|
|
|
|
|
Language = GetLanguage(i),
|
|
|
|
|
Url = baseImageUrl + i.file_path
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-27 00:23:58 +00:00
|
|
|
|
var language = preferredLanguage;
|
2013-11-05 16:52:43 +00:00
|
|
|
|
|
|
|
|
|
var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
return list.OrderByDescending(i =>
|
|
|
|
|
{
|
|
|
|
|
if (string.Equals(language, i.Language, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
if (!isLanguageEn)
|
|
|
|
|
{
|
|
|
|
|
if (string.Equals("en", i.Language, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(i.Language))
|
|
|
|
|
{
|
|
|
|
|
return isLanguageEn ? 3 : 2;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
})
|
|
|
|
|
.ThenByDescending(i => i.CommunityRating ?? 0)
|
|
|
|
|
.ThenByDescending(i => i.VoteCount ?? 0)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetLanguage(MovieDbPersonProvider.Profile profile)
|
|
|
|
|
{
|
|
|
|
|
return profile.iso_639_1 == null ? null : profile.iso_639_1.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Priority
|
|
|
|
|
{
|
|
|
|
|
get { return 0; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|