jellyfin-server/MediaBrowser.Providers/Tmdb/TV/TmdbSeriesProvider.cs

529 lines
20 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
2014-02-09 06:08:10 +00:00
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
2014-11-18 02:48:22 +00:00
using MediaBrowser.Controller.Library;
2014-02-09 06:08:10 +00:00
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
2014-02-09 06:08:10 +00:00
using MediaBrowser.Model.Serialization;
using MediaBrowser.Providers.Tmdb.Models.Search;
using MediaBrowser.Providers.Tmdb.Models.TV;
using MediaBrowser.Providers.Tmdb.Movies;
using Microsoft.Extensions.Logging;
2014-02-09 06:08:10 +00:00
namespace MediaBrowser.Providers.Tmdb.TV
2014-02-09 06:08:10 +00:00
{
public class TmdbSeriesProvider : IRemoteMetadataProvider<Series, SeriesInfo>, IHasOrder
2014-02-09 06:08:10 +00:00
{
2019-08-18 11:34:44 +00:00
private const string GetTvInfo3 = TmdbUtils.BaseTmdbApiUrl + @"3/tv/{0}?api_key={1}&append_to_response=credits,images,keywords,external_ids,videos,content_ratings";
2014-02-09 06:08:10 +00:00
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
internal static TmdbSeriesProvider Current { get; private set; }
2014-02-09 06:08:10 +00:00
private readonly IJsonSerializer _jsonSerializer;
private readonly IFileSystem _fileSystem;
private readonly IServerConfigurationManager _configurationManager;
private readonly ILogger _logger;
private readonly ILocalizationManager _localization;
2014-03-01 22:34:27 +00:00
private readonly IHttpClient _httpClient;
2014-11-18 02:48:22 +00:00
private readonly ILibraryManager _libraryManager;
2014-02-09 06:08:10 +00:00
public TmdbSeriesProvider(IJsonSerializer jsonSerializer, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILogger logger, ILocalizationManager localization, IHttpClient httpClient, ILibraryManager libraryManager)
2014-02-09 06:08:10 +00:00
{
_jsonSerializer = jsonSerializer;
_fileSystem = fileSystem;
_configurationManager = configurationManager;
_logger = logger;
_localization = localization;
2014-03-01 22:34:27 +00:00
_httpClient = httpClient;
2015-02-20 18:06:08 +00:00
_libraryManager = libraryManager;
2014-02-09 06:08:10 +00:00
Current = this;
}
public string Name => TmdbUtils.ProviderName;
2014-02-09 06:08:10 +00:00
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken)
{
2014-03-02 15:42:21 +00:00
var tmdbId = searchInfo.GetProviderId(MetadataProviders.Tmdb);
if (!string.IsNullOrEmpty(tmdbId))
{
cancellationToken.ThrowIfCancellationRequested();
await EnsureSeriesInfo(tmdbId, searchInfo.MetadataLanguage, cancellationToken).ConfigureAwait(false);
2014-03-02 15:42:21 +00:00
var dataFilePath = GetDataFilePath(tmdbId, searchInfo.MetadataLanguage);
var obj = _jsonSerializer.DeserializeFromFile<SeriesResult>(dataFilePath);
2014-03-02 15:42:21 +00:00
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
2018-09-12 17:26:21 +00:00
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
2014-03-02 18:01:46 +00:00
2014-03-02 15:42:21 +00:00
var remoteResult = new RemoteSearchResult
{
2019-08-18 12:44:13 +00:00
Name = obj.Name,
2014-03-02 15:42:21 +00:00
SearchProviderName = Name,
2019-08-18 12:44:13 +00:00
ImageUrl = string.IsNullOrWhiteSpace(obj.Poster_Path) ? null : tmdbImageUrl + obj.Poster_Path
2014-03-02 15:42:21 +00:00
};
2019-08-18 12:44:13 +00:00
remoteResult.SetProviderId(MetadataProviders.Tmdb, obj.Id.ToString(_usCulture));
remoteResult.SetProviderId(MetadataProviders.Imdb, obj.External_Ids.Imdb_Id);
2014-03-02 15:42:21 +00:00
2019-08-18 12:44:13 +00:00
if (obj.External_Ids.Tvdb_Id > 0)
2014-03-02 15:42:21 +00:00
{
2019-08-18 12:44:13 +00:00
remoteResult.SetProviderId(MetadataProviders.Tvdb, obj.External_Ids.Tvdb_Id.ToString(_usCulture));
2014-03-02 15:42:21 +00:00
}
2014-03-02 15:42:21 +00:00
return new[] { remoteResult };
}
var imdbId = searchInfo.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrEmpty(imdbId))
{
var searchResult = await FindByExternalId(imdbId, "imdb_id", cancellationToken).ConfigureAwait(false);
if (searchResult != null)
{
2014-03-02 18:01:46 +00:00
return new[] { searchResult };
2014-03-02 15:42:21 +00:00
}
}
var tvdbId = searchInfo.GetProviderId(MetadataProviders.Tvdb);
if (!string.IsNullOrEmpty(tvdbId))
{
var searchResult = await FindByExternalId(tvdbId, "tvdb_id", cancellationToken).ConfigureAwait(false);
if (searchResult != null)
{
2014-03-02 18:01:46 +00:00
return new[] { searchResult };
2014-03-02 15:42:21 +00:00
}
}
return await new TmdbSearch(_logger, _jsonSerializer, _libraryManager).GetSearchResults(searchInfo, cancellationToken).ConfigureAwait(false);
}
2014-02-09 06:08:10 +00:00
public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
{
var result = new MetadataResult<Series>();
result.QueriedById = true;
2014-02-09 06:08:10 +00:00
var tmdbId = info.GetProviderId(MetadataProviders.Tmdb);
2014-02-13 05:11:54 +00:00
if (string.IsNullOrEmpty(tmdbId))
{
var imdbId = info.GetProviderId(MetadataProviders.Imdb);
2014-02-09 06:08:10 +00:00
2014-02-13 05:11:54 +00:00
if (!string.IsNullOrEmpty(imdbId))
{
2014-03-02 15:42:21 +00:00
var searchResult = await FindByExternalId(imdbId, "imdb_id", cancellationToken).ConfigureAwait(false);
if (searchResult != null)
{
2014-03-02 18:01:46 +00:00
tmdbId = searchResult.GetProviderId(MetadataProviders.Tmdb);
2014-03-02 15:42:21 +00:00
}
2014-02-13 05:11:54 +00:00
}
}
if (string.IsNullOrEmpty(tmdbId))
{
var tvdbId = info.GetProviderId(MetadataProviders.Tvdb);
if (!string.IsNullOrEmpty(tvdbId))
{
2014-03-02 15:42:21 +00:00
var searchResult = await FindByExternalId(tvdbId, "tvdb_id", cancellationToken).ConfigureAwait(false);
if (searchResult != null)
{
2014-03-02 18:01:46 +00:00
tmdbId = searchResult.GetProviderId(MetadataProviders.Tmdb);
2014-03-02 15:42:21 +00:00
}
2014-02-13 05:11:54 +00:00
}
}
if (string.IsNullOrEmpty(tmdbId))
2014-02-09 06:08:10 +00:00
{
result.QueriedById = false;
var searchResults = await new TmdbSearch(_logger, _jsonSerializer, _libraryManager).GetSearchResults(info, cancellationToken).ConfigureAwait(false);
2014-03-01 22:34:27 +00:00
var searchResult = searchResults.FirstOrDefault();
2014-02-15 16:36:09 +00:00
if (searchResult != null)
{
2014-03-02 17:09:35 +00:00
tmdbId = searchResult.GetProviderId(MetadataProviders.Tmdb);
2014-02-15 16:36:09 +00:00
}
2014-02-09 06:08:10 +00:00
}
2014-02-13 05:11:54 +00:00
if (!string.IsNullOrEmpty(tmdbId))
2014-02-09 06:08:10 +00:00
{
cancellationToken.ThrowIfCancellationRequested();
result = await FetchMovieData(tmdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
2014-02-09 06:08:10 +00:00
result.HasMetadata = result.Item != null;
}
2014-03-02 15:42:21 +00:00
2014-02-09 06:08:10 +00:00
return result;
}
private async Task<MetadataResult<Series>> FetchMovieData(string tmdbId, string language, string preferredCountryCode, CancellationToken cancellationToken)
2014-02-09 06:08:10 +00:00
{
SeriesResult seriesInfo = await FetchMainResult(tmdbId, language, cancellationToken).ConfigureAwait(false);
2014-02-09 06:08:10 +00:00
2014-02-13 05:11:54 +00:00
if (seriesInfo == null)
{
return null;
}
2014-02-09 06:08:10 +00:00
2019-08-18 12:44:13 +00:00
tmdbId = seriesInfo.Id.ToString(_usCulture);
2014-02-09 06:08:10 +00:00
string dataFilePath = GetDataFilePath(tmdbId, language);
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
2014-02-13 05:11:54 +00:00
_jsonSerializer.SerializeToFile(seriesInfo, dataFilePath);
2014-02-09 06:08:10 +00:00
await EnsureSeriesInfo(tmdbId, language, cancellationToken).ConfigureAwait(false);
var result = new MetadataResult<Series>();
result.Item = new Series();
result.ResultLanguage = seriesInfo.ResultLanguage;
2014-02-09 06:08:10 +00:00
var settings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
2018-09-12 17:26:21 +00:00
ProcessMainInfo(result, seriesInfo, preferredCountryCode, settings);
2014-02-09 06:08:10 +00:00
return result;
2014-02-09 06:08:10 +00:00
}
private void ProcessMainInfo(MetadataResult<Series> seriesResult, SeriesResult seriesInfo, string preferredCountryCode, TmdbSettingsResult settings)
2014-02-09 06:08:10 +00:00
{
2018-09-12 17:26:21 +00:00
var series = seriesResult.Item;
2019-08-18 12:44:13 +00:00
series.Name = seriesInfo.Name;
series.SetProviderId(MetadataProviders.Tmdb, seriesInfo.Id.ToString(_usCulture));
2014-02-09 06:08:10 +00:00
2017-06-03 07:36:32 +00:00
//series.VoteCount = seriesInfo.vote_count;
2014-02-09 06:08:10 +00:00
2019-08-18 12:44:13 +00:00
string voteAvg = seriesInfo.Vote_Average.ToString(CultureInfo.InvariantCulture);
2014-02-09 06:08:10 +00:00
if (float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out float rating))
2014-02-09 06:08:10 +00:00
{
series.CommunityRating = rating;
}
2019-08-18 12:44:13 +00:00
series.Overview = seriesInfo.Overview;
2014-02-09 06:08:10 +00:00
2019-08-18 12:44:13 +00:00
if (seriesInfo.Networks != null)
2014-02-09 06:08:10 +00:00
{
2019-08-18 12:44:13 +00:00
series.Studios = seriesInfo.Networks.Select(i => i.Name).ToArray();
2014-02-09 06:08:10 +00:00
}
2019-08-18 12:44:13 +00:00
if (seriesInfo.Genres != null)
2014-02-09 06:08:10 +00:00
{
2019-08-18 12:44:13 +00:00
series.Genres = seriesInfo.Genres.Select(i => i.Name).ToArray();
2014-02-09 06:08:10 +00:00
}
2018-09-12 17:26:21 +00:00
//series.HomePageUrl = seriesInfo.homepage;
2019-08-18 12:44:13 +00:00
series.RunTimeTicks = seriesInfo.Episode_Run_Time.Select(i => TimeSpan.FromMinutes(i).Ticks).FirstOrDefault();
2014-02-09 06:08:10 +00:00
2019-08-18 12:44:13 +00:00
if (string.Equals(seriesInfo.Status, "Ended", StringComparison.OrdinalIgnoreCase))
2014-02-09 06:08:10 +00:00
{
series.Status = SeriesStatus.Ended;
2019-08-18 12:44:13 +00:00
series.EndDate = seriesInfo.Last_Air_Date;
2014-02-09 06:08:10 +00:00
}
else
{
series.Status = SeriesStatus.Continuing;
}
2019-08-18 12:44:13 +00:00
series.PremiereDate = seriesInfo.First_Air_Date;
2014-02-09 06:08:10 +00:00
2019-08-18 12:44:13 +00:00
var ids = seriesInfo.External_Ids;
2014-02-09 06:08:10 +00:00
if (ids != null)
{
2019-08-18 12:44:13 +00:00
if (!string.IsNullOrWhiteSpace(ids.Imdb_Id))
2014-02-09 06:08:10 +00:00
{
2019-08-18 12:44:13 +00:00
series.SetProviderId(MetadataProviders.Imdb, ids.Imdb_Id);
2014-02-09 06:08:10 +00:00
}
2019-08-18 12:44:13 +00:00
if (ids.Tvrage_Id > 0)
2014-02-09 06:08:10 +00:00
{
2019-08-18 12:44:13 +00:00
series.SetProviderId(MetadataProviders.TvRage, ids.Tvrage_Id.ToString(_usCulture));
2014-02-09 06:08:10 +00:00
}
2019-08-18 12:44:13 +00:00
if (ids.Tvdb_Id > 0)
2014-02-09 06:08:10 +00:00
{
2019-08-18 12:44:13 +00:00
series.SetProviderId(MetadataProviders.Tvdb, ids.Tvdb_Id.ToString(_usCulture));
2014-02-09 06:08:10 +00:00
}
}
2019-08-18 12:44:13 +00:00
var contentRatings = (seriesInfo.Content_Ratings ?? new ContentRatings()).Results ?? new List<ContentRating>();
2019-08-18 12:44:13 +00:00
var ourRelease = contentRatings.FirstOrDefault(c => string.Equals(c.Iso_3166_1, preferredCountryCode, StringComparison.OrdinalIgnoreCase));
var usRelease = contentRatings.FirstOrDefault(c => string.Equals(c.Iso_3166_1, "US", StringComparison.OrdinalIgnoreCase));
var minimumRelease = contentRatings.FirstOrDefault();
if (ourRelease != null)
{
2019-08-18 12:44:13 +00:00
series.OfficialRating = ourRelease.Rating;
}
else if (usRelease != null)
{
2019-08-18 12:44:13 +00:00
series.OfficialRating = usRelease.Rating;
}
else if (minimumRelease != null)
{
2019-08-18 12:44:13 +00:00
series.OfficialRating = minimumRelease.Rating;
}
2019-08-18 12:44:13 +00:00
if (seriesInfo.Videos != null && seriesInfo.Videos.Results != null)
{
2019-08-18 12:44:13 +00:00
foreach (var video in seriesInfo.Videos.Results)
{
2019-08-18 12:44:13 +00:00
if ((video.Type.Equals("trailer", StringComparison.OrdinalIgnoreCase)
|| video.Type.Equals("clip", StringComparison.OrdinalIgnoreCase))
&& video.Site.Equals("youtube", StringComparison.OrdinalIgnoreCase))
{
2019-08-18 12:44:13 +00:00
series.AddTrailerUrl($"http://www.youtube.com/watch?v={video.Key}");
}
}
}
2018-09-12 17:26:21 +00:00
seriesResult.ResetPeople();
var tmdbImageUrl = settings.images.GetImageUrl("original");
2019-08-18 12:44:13 +00:00
if (seriesInfo.Credits != null && seriesInfo.Credits.Cast != null)
2018-09-12 17:26:21 +00:00
{
2019-08-18 12:44:13 +00:00
foreach (var actor in seriesInfo.Credits.Cast.OrderBy(a => a.Order))
2018-09-12 17:26:21 +00:00
{
var personInfo = new PersonInfo
{
2019-08-18 12:44:13 +00:00
Name = actor.Name.Trim(),
Role = actor.Character,
2018-09-12 17:26:21 +00:00
Type = PersonType.Actor,
2019-08-18 12:44:13 +00:00
SortOrder = actor.Order
2018-09-12 17:26:21 +00:00
};
2019-08-18 12:44:13 +00:00
if (!string.IsNullOrWhiteSpace(actor.Profile_Path))
2018-09-12 17:26:21 +00:00
{
2019-08-18 12:44:13 +00:00
personInfo.ImageUrl = tmdbImageUrl + actor.Profile_Path;
2018-09-12 17:26:21 +00:00
}
2019-08-18 12:44:13 +00:00
if (actor.Id > 0)
2018-09-12 17:26:21 +00:00
{
2019-08-18 12:44:13 +00:00
personInfo.SetProviderId(MetadataProviders.Tmdb, actor.Id.ToString(CultureInfo.InvariantCulture));
2018-09-12 17:26:21 +00:00
}
seriesResult.AddPerson(personInfo);
}
}
2014-02-09 06:08:10 +00:00
}
internal static string GetSeriesDataPath(IApplicationPaths appPaths, string tmdbId)
{
var dataPath = GetSeriesDataPath(appPaths);
return Path.Combine(dataPath, tmdbId);
}
internal static string GetSeriesDataPath(IApplicationPaths appPaths)
{
2014-02-20 16:37:41 +00:00
var dataPath = Path.Combine(appPaths.CachePath, "tmdb-tv");
2014-02-09 06:08:10 +00:00
return dataPath;
}
2014-03-02 15:42:21 +00:00
2014-02-09 06:08:10 +00:00
internal async Task DownloadSeriesInfo(string id, string preferredMetadataLanguage, CancellationToken cancellationToken)
{
SeriesResult mainResult = await FetchMainResult(id, preferredMetadataLanguage, cancellationToken).ConfigureAwait(false);
2014-02-09 06:08:10 +00:00
if (mainResult == null)
{
return;
}
2014-02-09 06:08:10 +00:00
var dataFilePath = GetDataFilePath(id, preferredMetadataLanguage);
Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));
2014-02-09 06:08:10 +00:00
_jsonSerializer.SerializeToFile(mainResult, dataFilePath);
}
internal async Task<SeriesResult> FetchMainResult(string id, string language, CancellationToken cancellationToken)
2014-02-09 06:08:10 +00:00
{
var url = string.Format(GetTvInfo3, id, TmdbUtils.ApiKey);
2014-02-09 06:08:10 +00:00
if (!string.IsNullOrEmpty(language))
{
url += "&language=" + TmdbMovieProvider.NormalizeLanguage(language)
+ "&include_image_language=" + TmdbMovieProvider.GetImageLanguagesParam(language); // Get images in english and with no language
}
2014-02-09 06:08:10 +00:00
cancellationToken.ThrowIfCancellationRequested();
SeriesResult mainResult;
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
2014-02-09 06:08:10 +00:00
{
Url = url,
CancellationToken = cancellationToken,
AcceptHeader = TmdbUtils.AcceptHeader
2014-02-09 06:08:10 +00:00
}).ConfigureAwait(false))
{
2017-10-20 16:16:56 +00:00
using (var json = response.Content)
{
mainResult = await _jsonSerializer.DeserializeFromStreamAsync<SeriesResult>(json).ConfigureAwait(false);
2017-10-20 16:16:56 +00:00
if (!string.IsNullOrEmpty(language))
{
mainResult.ResultLanguage = language;
}
}
2014-02-09 06:08:10 +00:00
}
cancellationToken.ThrowIfCancellationRequested();
// If the language preference isn't english, then have the overview fallback to english if it's blank
if (mainResult != null &&
2019-08-18 12:44:13 +00:00
string.IsNullOrEmpty(mainResult.Overview) &&
!string.IsNullOrEmpty(language) &&
!string.Equals(language, "en", StringComparison.OrdinalIgnoreCase))
{
_logger.LogInformation("MovieDbSeriesProvider couldn't find meta for language {Language}. Trying English...", language);
url = string.Format(GetTvInfo3, id, TmdbUtils.ApiKey) + "&language=en";
if (!string.IsNullOrEmpty(language))
{
// Get images in english and with no language
url += "&include_image_language=" + TmdbMovieProvider.GetImageLanguagesParam(language);
}
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
{
Url = url,
CancellationToken = cancellationToken,
AcceptHeader = TmdbUtils.AcceptHeader
}).ConfigureAwait(false))
{
2017-10-20 16:16:56 +00:00
using (var json = response.Content)
{
var englishResult = await _jsonSerializer.DeserializeFromStreamAsync<SeriesResult>(json).ConfigureAwait(false);
2019-08-18 12:44:13 +00:00
mainResult.Overview = englishResult.Overview;
2017-10-20 16:16:56 +00:00
mainResult.ResultLanguage = "en";
}
}
}
return mainResult;
2014-02-09 06:08:10 +00:00
}
2014-03-02 15:42:21 +00:00
2014-02-09 06:08:10 +00:00
internal Task EnsureSeriesInfo(string tmdbId, string language, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(tmdbId))
{
throw new ArgumentNullException(nameof(tmdbId));
2014-02-09 06:08:10 +00:00
}
var path = GetDataFilePath(tmdbId, language);
var fileInfo = _fileSystem.GetFileSystemInfo(path);
if (fileInfo.Exists)
{
// If it's recent or automatic updates are enabled, don't re-download
2018-09-12 17:26:21 +00:00
if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 2)
2014-02-09 06:08:10 +00:00
{
2018-09-12 17:26:21 +00:00
return Task.CompletedTask;
2014-02-09 06:08:10 +00:00
}
}
return DownloadSeriesInfo(tmdbId, language, cancellationToken);
}
internal string GetDataFilePath(string tmdbId, string preferredLanguage)
{
if (string.IsNullOrEmpty(tmdbId))
{
throw new ArgumentNullException(nameof(tmdbId));
2014-02-09 06:08:10 +00:00
}
var path = GetSeriesDataPath(_configurationManager.ApplicationPaths, tmdbId);
var filename = string.Format("series-{0}.json", preferredLanguage ?? string.Empty);
2014-02-09 06:08:10 +00:00
return Path.Combine(path, filename);
}
2014-03-02 18:01:46 +00:00
private async Task<RemoteSearchResult> FindByExternalId(string id, string externalSource, CancellationToken cancellationToken)
2014-02-13 05:11:54 +00:00
{
2019-08-18 11:34:44 +00:00
var url = string.Format(TmdbUtils.BaseTmdbApiUrl + @"3/find/{0}?api_key={1}&external_source={2}",
2014-03-02 15:42:21 +00:00
id,
TmdbUtils.ApiKey,
2014-02-13 05:11:54 +00:00
externalSource);
using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions
2014-02-13 05:11:54 +00:00
{
Url = url,
CancellationToken = cancellationToken,
AcceptHeader = TmdbUtils.AcceptHeader
2014-02-13 05:11:54 +00:00
}).ConfigureAwait(false))
{
2017-10-20 16:16:56 +00:00
using (var json = response.Content)
2014-02-13 05:11:54 +00:00
{
var result = await _jsonSerializer.DeserializeFromStreamAsync<ExternalIdLookupResult>(json).ConfigureAwait(false);
2014-02-13 05:11:54 +00:00
2019-08-18 12:44:13 +00:00
if (result != null && result.Tv_Results != null)
2014-02-13 05:11:54 +00:00
{
2019-08-18 12:44:13 +00:00
var tv = result.Tv_Results.FirstOrDefault();
2014-03-02 18:01:46 +00:00
2017-10-20 16:16:56 +00:00
if (tv != null)
2014-03-02 18:01:46 +00:00
{
var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false);
2018-09-12 17:26:21 +00:00
var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original");
2014-03-02 18:01:46 +00:00
2017-10-20 16:16:56 +00:00
var remoteResult = new RemoteSearchResult
{
2019-08-18 12:44:13 +00:00
Name = tv.Name,
2017-10-20 16:16:56 +00:00
SearchProviderName = Name,
2019-08-18 12:44:13 +00:00
ImageUrl = string.IsNullOrWhiteSpace(tv.Poster_Path) ? null : tmdbImageUrl + tv.Poster_Path
2017-10-20 16:16:56 +00:00
};
2014-03-02 18:01:46 +00:00
2019-08-18 12:44:13 +00:00
remoteResult.SetProviderId(MetadataProviders.Tmdb, tv.Id.ToString(_usCulture));
2017-10-20 16:16:56 +00:00
return remoteResult;
}
2014-02-13 05:11:54 +00:00
}
}
}
return null;
}
// After TheTVDB
public int Order => 1;
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
2014-03-01 22:34:27 +00:00
return _httpClient.GetResponse(new HttpRequestOptions
{
CancellationToken = cancellationToken,
2016-10-31 18:39:41 +00:00
Url = url
2014-03-01 22:34:27 +00:00
});
}
2014-02-09 06:08:10 +00:00
}
}