2020-06-19 11:24:13 -07:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 13:03:10 -07:00
|
|
|
using System;
|
2019-01-13 12:26:31 -07:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2014-07-07 07:23:08 -07: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 12:26:31 -07:00
|
|
|
using MediaBrowser.Model.Globalization;
|
|
|
|
using MediaBrowser.Model.IO;
|
2014-07-07 07:23:08 -07:00
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2020-05-30 23:23:09 -07:00
|
|
|
using MediaBrowser.Providers.Plugins.Tmdb.Models.General;
|
|
|
|
using MediaBrowser.Providers.Plugins.Tmdb.Movies;
|
2019-01-13 12:26:31 -07:00
|
|
|
using Microsoft.Extensions.Logging;
|
2014-07-07 07:23:08 -07:00
|
|
|
|
2020-05-30 23:23:09 -07:00
|
|
|
namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
2019-08-18 04:20:52 -07:00
|
|
|
public class TmdbEpisodeImageProvider :
|
|
|
|
TmdbEpisodeProviderBase,
|
2019-01-07 16:27:46 -07:00
|
|
|
IRemoteImageProvider,
|
2016-03-02 18:56:51 -07:00
|
|
|
IHasOrder
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
2019-08-18 04:20:52 -07:00
|
|
|
public TmdbEpisodeImageProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
|
2018-12-13 06:18:25 -07:00
|
|
|
: base(httpClient, configurationManager, jsonSerializer, fileSystem, localization, loggerFactory)
|
2019-01-13 12:26:31 -07:00
|
|
|
{ }
|
2014-07-07 07:23:08 -07:00
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
|
|
|
return new List<ImageType>
|
|
|
|
{
|
|
|
|
ImageType.Primary
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
|
|
|
var episode = (Controller.Entities.TV.Episode)item;
|
|
|
|
var series = episode.Series;
|
|
|
|
|
2020-06-06 12:17:49 -07:00
|
|
|
var seriesId = series != null ? series.GetProviderId(MetadataProvider.Tmdb) : null;
|
2014-07-07 07:23:08 -07: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 16:53:38 -07:00
|
|
|
var language = item.GetPreferredMetadataLanguage();
|
|
|
|
|
2014-07-07 07:23:08 -07:00
|
|
|
var response = await GetEpisodeInfo(seriesId, seasonNumber.Value, episodeNumber.Value,
|
2016-06-24 16:53:38 -07:00
|
|
|
language, cancellationToken).ConfigureAwait(false);
|
2014-07-07 07:23:08 -07:00
|
|
|
|
2019-08-18 04:20:52 -07:00
|
|
|
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
|
2014-07-07 07:23:08 -07:00
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
|
2014-07-07 07:23:08 -07:00
|
|
|
|
2019-08-18 05:44:13 -07:00
|
|
|
list.AddRange(GetPosters(response.Images).Select(i => new RemoteImageInfo
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
2019-08-18 05:44:13 -07: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 07:23:08 -07: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-30 23:28:01 -07:00
|
|
|
|
2014-07-07 07:23:08 -07:00
|
|
|
if (!isLanguageEn)
|
|
|
|
{
|
|
|
|
if (string.Equals("en", i.Language, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
2020-05-30 23:28:01 -07:00
|
|
|
|
2014-07-07 07:23:08 -07:00
|
|
|
if (string.IsNullOrEmpty(i.Language))
|
|
|
|
{
|
|
|
|
return isLanguageEn ? 3 : 2;
|
|
|
|
}
|
2020-05-30 23:28:01 -07:00
|
|
|
|
2014-07-07 07:23:08 -07:00
|
|
|
return 0;
|
|
|
|
})
|
|
|
|
.ThenByDescending(i => i.CommunityRating ?? 0)
|
2017-08-09 12:56:38 -07:00
|
|
|
.ThenByDescending(i => i.VoteCount ?? 0);
|
2014-07-07 07:23:08 -07:00
|
|
|
}
|
|
|
|
|
2019-08-18 04:20:52 -07:00
|
|
|
private IEnumerable<Still> GetPosters(StillImages images)
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
2019-08-18 05:44:13 -07:00
|
|
|
return images.Stills ?? new List<Still>();
|
2014-07-07 07:23:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
|
|
|
{
|
2016-03-02 18:56:51 -07:00
|
|
|
return GetResponse(url, cancellationToken);
|
2014-07-07 07:23:08 -07:00
|
|
|
}
|
|
|
|
|
2019-08-18 04:20:52 -07:00
|
|
|
public string Name => TmdbUtils.ProviderName;
|
2014-07-07 07:23:08 -07:00
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
public bool Supports(BaseItem item)
|
2014-07-07 07:23:08 -07:00
|
|
|
{
|
|
|
|
return item is Controller.Entities.TV.Episode;
|
|
|
|
}
|
2019-08-18 04:20:52 -07:00
|
|
|
|
2019-01-17 12:24:39 -07:00
|
|
|
// After TheTvDb
|
2019-01-13 13:31:14 -07:00
|
|
|
public int Order => 1;
|
2014-07-07 07:23:08 -07:00
|
|
|
}
|
|
|
|
}
|