You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.4 KiB
132 lines
4.4 KiB
6 years ago
|
using System;
|
||
6 years ago
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Threading;
|
||
|
using System.Threading.Tasks;
|
||
10 years ago
|
using MediaBrowser.Common.Net;
|
||
|
using MediaBrowser.Controller.Configuration;
|
||
|
using MediaBrowser.Controller.Entities;
|
||
|
using MediaBrowser.Controller.Providers;
|
||
|
using MediaBrowser.Model.Dto;
|
||
|
using MediaBrowser.Model.Entities;
|
||
6 years ago
|
using MediaBrowser.Model.Globalization;
|
||
|
using MediaBrowser.Model.IO;
|
||
10 years ago
|
using MediaBrowser.Model.Providers;
|
||
|
using MediaBrowser.Model.Serialization;
|
||
4 years ago
|
using MediaBrowser.Providers.Plugins.Tmdb.Models.General;
|
||
|
using MediaBrowser.Providers.Plugins.Tmdb.Movies;
|
||
6 years ago
|
using Microsoft.Extensions.Logging;
|
||
10 years ago
|
|
||
4 years ago
|
namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||
10 years ago
|
{
|
||
5 years ago
|
public class TmdbEpisodeImageProvider :
|
||
|
TmdbEpisodeProviderBase,
|
||
6 years ago
|
IRemoteImageProvider,
|
||
9 years ago
|
IHasOrder
|
||
10 years ago
|
{
|
||
5 years ago
|
public TmdbEpisodeImageProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ILocalizationManager localization, ILoggerFactory loggerFactory)
|
||
6 years ago
|
: base(httpClient, configurationManager, jsonSerializer, fileSystem, localization, loggerFactory)
|
||
6 years ago
|
{ }
|
||
10 years ago
|
|
||
6 years ago
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
||
10 years ago
|
{
|
||
|
return new List<ImageType>
|
||
|
{
|
||
|
ImageType.Primary
|
||
|
};
|
||
|
}
|
||
|
|
||
6 years ago
|
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
||
10 years ago
|
{
|
||
|
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;
|
||
|
}
|
||
|
|
||
8 years ago
|
var language = item.GetPreferredMetadataLanguage();
|
||
|
|
||
10 years ago
|
var response = await GetEpisodeInfo(seriesId, seasonNumber.Value, episodeNumber.Value,
|
||
8 years ago
|
language, cancellationToken).ConfigureAwait(false);
|
||
10 years ago
|
|
||
5 years ago
|
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
|
||
10 years ago
|
|
||
6 years ago
|
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
|
||
10 years ago
|
|
||
5 years ago
|
list.AddRange(GetPosters(response.Images).Select(i => new RemoteImageInfo
|
||
10 years ago
|
{
|
||
5 years ago
|
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),
|
||
10 years ago
|
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)
|
||
7 years ago
|
.ThenByDescending(i => i.VoteCount ?? 0);
|
||
10 years ago
|
|
||
|
}
|
||
|
|
||
5 years ago
|
private IEnumerable<Still> GetPosters(StillImages images)
|
||
10 years ago
|
{
|
||
5 years ago
|
return images.Stills ?? new List<Still>();
|
||
10 years ago
|
}
|
||
|
|
||
|
|
||
|
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
||
|
{
|
||
9 years ago
|
return GetResponse(url, cancellationToken);
|
||
10 years ago
|
}
|
||
|
|
||
5 years ago
|
public string Name => TmdbUtils.ProviderName;
|
||
10 years ago
|
|
||
6 years ago
|
public bool Supports(BaseItem item)
|
||
10 years ago
|
{
|
||
|
return item is Controller.Entities.TV.Episode;
|
||
|
}
|
||
5 years ago
|
|
||
6 years ago
|
// After TheTvDb
|
||
6 years ago
|
public int Order => 1;
|
||
10 years ago
|
}
|
||
|
}
|