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;
|
2020-05-31 06:23:09 +00:00
|
|
|
using MediaBrowser.Providers.Plugins.Tmdb.Models.General;
|
|
|
|
using MediaBrowser.Providers.Plugins.Tmdb.Movies;
|
2019-01-13 19:26:31 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2014-07-07 14:23:08 +00:00
|
|
|
|
2020-05-31 06:23:09 +00:00
|
|
|
namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
2014-07-07 14:23:08 +00:00
|
|
|
{
|
2019-08-18 11:20:52 +00:00
|
|
|
public class TmdbEpisodeImageProvider :
|
|
|
|
TmdbEpisodeProviderBase,
|
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
|
|
|
{
|
2019-08-18 11:20:52 +00:00
|
|
|
public TmdbEpisodeImageProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
|
2018-12-13 13:18:25 +00:00
|
|
|
: 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;
|
|
|
|
|
2020-06-06 19:17:49 +00:00
|
|
|
var seriesId = series != null ? series.GetProviderId(MetadataProvider.Tmdb) : null;
|
2014-07-07 14:23:08 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2019-08-18 11:20:52 +00:00
|
|
|
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
|
2014-07-07 14:23:08 +00:00
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
|
2014-07-07 14:23:08 +00:00
|
|
|
|
2019-08-18 12:44:13 +00:00
|
|
|
list.AddRange(GetPosters(response.Images).Select(i => new RemoteImageInfo
|
2014-07-07 14:23:08 +00:00
|
|
|
{
|
2019-08-18 12:44:13 +00:00
|
|
|
Url = tmdbImageUrl + i.File_Path,
|
|
|
|
CommunityRating = i.Vote_Average,
|
|
|
|
VoteCount = i.Vote_Count,
|
|
|
|
Width = i.Width,
|
|
|
|
Height = i.Height,
|
|
|
|
Language = TmdbMovieProvider.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;
|
|
|
|
}
|
2020-05-31 06:28:01 +00:00
|
|
|
|
2014-07-07 14:23:08 +00:00
|
|
|
if (!isLanguageEn)
|
|
|
|
{
|
|
|
|
if (string.Equals("en", i.Language, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
2020-05-31 06:28:01 +00:00
|
|
|
|
2014-07-07 14:23:08 +00:00
|
|
|
if (string.IsNullOrEmpty(i.Language))
|
|
|
|
{
|
|
|
|
return isLanguageEn ? 3 : 2;
|
|
|
|
}
|
2020-05-31 06:28:01 +00:00
|
|
|
|
2014-07-07 14:23:08 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-08-18 11:20:52 +00:00
|
|
|
private IEnumerable<Still> GetPosters(StillImages images)
|
2014-07-07 14:23:08 +00:00
|
|
|
{
|
2019-08-18 12:44:13 +00:00
|
|
|
return images.Stills ?? new List<Still>();
|
2014-07-07 14:23:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-08-18 11:20:52 +00:00
|
|
|
public string Name => TmdbUtils.ProviderName;
|
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-08-18 11:20:52 +00:00
|
|
|
|
2019-01-17 19:24:39 +00:00
|
|
|
// After TheTvDb
|
2019-01-13 20:31:14 +00:00
|
|
|
public int Order => 1;
|
2014-07-07 14:23:08 +00:00
|
|
|
}
|
|
|
|
}
|