2019-01-13 20:03:10 +00:00
|
|
|
using System;
|
2019-01-13 19:26:31 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2014-07-07 14:23:08 +00:00
|
|
|
using MediaBrowser.Common.Net;
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Dto;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2019-01-13 19:26:31 +00:00
|
|
|
using MediaBrowser.Model.Globalization;
|
|
|
|
using MediaBrowser.Model.IO;
|
2014-07-07 14:23:08 +00:00
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
using MediaBrowser.Providers.Movies;
|
2019-01-13 19:26:31 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2014-07-07 14:23:08 +00:00
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.TV
|
|
|
|
{
|
2016-03-03 01:56:51 +00:00
|
|
|
public class MovieDbEpisodeImageProvider :
|
|
|
|
MovieDbProviderBase,
|
2019-01-07 23:27:46 +00:00
|
|
|
IRemoteImageProvider,
|
2016-03-03 01:56:51 +00:00
|
|
|
IHasOrder
|
2014-07-07 14:23:08 +00:00
|
|
|
{
|
2018-12-13 13:18:25 +00:00
|
|
|
public MovieDbEpisodeImageProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
|
|
|
|
: base(httpClient, configurationManager, jsonSerializer, fileSystem, localization, loggerFactory)
|
2019-01-13 19:26:31 +00:00
|
|
|
{ }
|
2014-07-07 14:23:08 +00:00
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
2014-07-07 14:23:08 +00:00
|
|
|
{
|
|
|
|
return new List<ImageType>
|
|
|
|
{
|
|
|
|
ImageType.Primary
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
2014-07-07 14:23:08 +00:00
|
|
|
{
|
|
|
|
var episode = (Controller.Entities.TV.Episode)item;
|
|
|
|
var series = episode.Series;
|
|
|
|
|
|
|
|
var seriesId = series != null ? series.GetProviderId(MetadataProviders.Tmdb) : null;
|
|
|
|
|
|
|
|
var list = new List<RemoteImageInfo>();
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(seriesId))
|
|
|
|
{
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
var seasonNumber = episode.ParentIndexNumber;
|
|
|
|
var episodeNumber = episode.IndexNumber;
|
|
|
|
|
|
|
|
if (!seasonNumber.HasValue || !episodeNumber.HasValue)
|
|
|
|
{
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2016-06-24 23:53:38 +00:00
|
|
|
var language = item.GetPreferredMetadataLanguage();
|
|
|
|
|
2014-07-07 14:23:08 +00:00
|
|
|
var response = await GetEpisodeInfo(seriesId, seasonNumber.Value, episodeNumber.Value,
|
2016-06-24 23:53:38 +00:00
|
|
|
language, cancellationToken).ConfigureAwait(false);
|
2014-07-07 14:23:08 +00:00
|
|
|
|
|
|
|
var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
|
2014-07-07 14:23:08 +00:00
|
|
|
|
|
|
|
list.AddRange(GetPosters(response.images).Select(i => new RemoteImageInfo
|
|
|
|
{
|
|
|
|
Url = tmdbImageUrl + i.file_path,
|
|
|
|
CommunityRating = i.vote_average,
|
|
|
|
VoteCount = i.vote_count,
|
|
|
|
Width = i.width,
|
|
|
|
Height = i.height,
|
2016-06-24 23:53:38 +00:00
|
|
|
Language = MovieDbProvider.AdjustImageLanguage(i.iso_639_1, language),
|
2014-07-07 14:23:08 +00:00
|
|
|
ProviderName = Name,
|
|
|
|
Type = ImageType.Primary,
|
|
|
|
RatingType = RatingType.Score
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
2017-08-09 19:56:38 +00:00
|
|
|
.ThenByDescending(i => i.VoteCount ?? 0);
|
2014-07-07 14:23:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerable<Still> GetPosters(Images images)
|
|
|
|
{
|
|
|
|
return images.stills ?? new List<Still>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
|
|
|
{
|
2016-03-03 01:56:51 +00:00
|
|
|
return GetResponse(url, cancellationToken);
|
2014-07-07 14:23:08 +00:00
|
|
|
}
|
|
|
|
|
2019-01-13 20:31:14 +00:00
|
|
|
public string Name => "TheMovieDb";
|
2014-07-07 14:23:08 +00:00
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
public bool Supports(BaseItem item)
|
2014-07-07 14:23:08 +00:00
|
|
|
{
|
|
|
|
return item is Controller.Entities.TV.Episode;
|
|
|
|
}
|
|
|
|
|
2019-01-13 20:31:14 +00:00
|
|
|
public int Order => 1;
|
2014-07-07 14:23:08 +00:00
|
|
|
}
|
|
|
|
}
|