jellyfin/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs

100 lines
3.0 KiB
C#
Raw Normal View History

2019-01-30 20:23:23 +00:00
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
2019-01-30 20:23:23 +00:00
using TvDbSharper;
using TvDbSharper.Dto;
namespace MediaBrowser.Providers.TV.TheTVDB
{
2016-05-25 00:42:12 +00:00
public class TvdbEpisodeImageProvider : IRemoteImageProvider
{
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly IHttpClient _httpClient;
2019-01-30 22:28:43 +00:00
private readonly TvDbClientManager _tvDbClientManager;
2019-01-30 20:23:23 +00:00
public TvdbEpisodeImageProvider(IHttpClient httpClient)
{
_httpClient = httpClient;
2019-01-30 22:28:43 +00:00
_tvDbClientManager = TvDbClientManager.Instance;
}
public string Name => "TheTVDB";
2018-09-12 17:26:21 +00:00
public bool Supports(BaseItem item)
{
return item is Episode;
}
2018-09-12 17:26:21 +00:00
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{
return new List<ImageType>
{
ImageType.Primary
};
}
2019-01-30 20:23:23 +00:00
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var episode = (Episode)item;
2014-02-06 15:58:49 +00:00
var series = episode.Series;
2015-11-24 18:45:52 +00:00
if (series != null && TvdbSeriesProvider.IsValidSeries(series.ProviderIds))
{
2019-01-30 20:23:23 +00:00
var tvdbId = episode.GetProviderId(MetadataProviders.Tvdb);
// Process images
2019-01-30 22:28:43 +00:00
var episodeResult = await _tvDbClientManager.TvDbClient.Episodes.GetAsync(Convert.ToInt32(tvdbId), cancellationToken);
2019-01-30 20:23:23 +00:00
var image = GetImageInfo(episodeResult.Data);
return new List<RemoteImageInfo>
{
image
};
}
2019-01-30 20:23:23 +00:00
return new RemoteImageInfo[] { };
}
2019-01-30 20:23:23 +00:00
private RemoteImageInfo GetImageInfo(EpisodeRecord episode)
{
var height = 225;
var width = 400;
var url = string.Empty;
2019-01-30 20:23:23 +00:00
if (string.IsNullOrEmpty(episode.Filename))
{
return null;
}
return new RemoteImageInfo
{
2019-01-30 20:23:23 +00:00
Width = Convert.ToInt32(episode.ThumbWidth),
Height = Convert.ToInt32(episode.ThumbHeight),
ProviderName = Name,
2019-01-30 20:23:23 +00:00
Url = TVUtils.BannerUrl + episode.Filename,
Type = ImageType.Primary
};
}
public int Order => 0;
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClient.GetResponse(new HttpRequestOptions
{
CancellationToken = cancellationToken,
2017-04-30 02:37:51 +00:00
Url = url
});
}
}
}