2020-06-19 11:24:13 -07:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 13:03:10 -07:00
|
|
|
using System;
|
2020-09-24 10:49:35 -07:00
|
|
|
using System.Collections;
|
2019-01-13 12:26:31 -07:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2020-08-17 12:10:02 -07:00
|
|
|
using System.Net.Http;
|
|
|
|
using System.Net.Http.Headers;
|
2019-01-13 12:26:31 -07:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2020-08-31 10:05:21 -07:00
|
|
|
using MediaBrowser.Common.Net;
|
2014-02-08 23:08:10 -07:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2014-11-17 19:48:22 -07:00
|
|
|
using MediaBrowser.Controller.Library;
|
2014-02-08 23:08:10 -07:00
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2020-09-24 10:49:35 -07:00
|
|
|
using MediaBrowser.Model.Globalization;
|
|
|
|
using MediaBrowser.Model.IO;
|
2014-02-19 21:53:15 -07:00
|
|
|
using MediaBrowser.Model.Providers;
|
2014-02-08 23:08:10 -07:00
|
|
|
using MediaBrowser.Model.Serialization;
|
2020-05-30 23:23:09 -07:00
|
|
|
using MediaBrowser.Providers.Plugins.Tmdb.Movies;
|
2019-01-13 12:26:31 -07:00
|
|
|
using Microsoft.Extensions.Logging;
|
2020-09-24 10:49:35 -07:00
|
|
|
using TMDbLib.Objects.Find;
|
|
|
|
using TMDbLib.Objects.Search;
|
|
|
|
using TMDbLib.Objects.TvShows;
|
2014-02-08 23:08:10 -07:00
|
|
|
|
2020-05-30 23:23:09 -07:00
|
|
|
namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
2014-02-08 23:08:10 -07:00
|
|
|
{
|
2019-08-18 04:20:52 -07:00
|
|
|
public class TmdbSeriesProvider : IRemoteMetadataProvider<Series, SeriesInfo>, IHasOrder
|
2014-02-08 23:08:10 -07:00
|
|
|
{
|
2020-08-17 12:10:02 -07:00
|
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
2020-09-24 10:49:35 -07:00
|
|
|
private readonly TmdbClientManager _tmdbClientManager;
|
2014-02-08 23:08:10 -07:00
|
|
|
|
2020-05-10 04:53:04 -07:00
|
|
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
|
|
|
|
2020-03-03 15:07:10 -07:00
|
|
|
public TmdbSeriesProvider(
|
2020-08-17 12:10:02 -07:00
|
|
|
IHttpClientFactory httpClientFactory,
|
2020-09-24 10:49:35 -07:00
|
|
|
TmdbClientManager tmdbClientManager)
|
2014-02-08 23:08:10 -07:00
|
|
|
{
|
2020-08-17 12:10:02 -07:00
|
|
|
_httpClientFactory = httpClientFactory;
|
2020-09-24 10:49:35 -07:00
|
|
|
_tmdbClientManager = tmdbClientManager;
|
2014-02-08 23:08:10 -07:00
|
|
|
Current = this;
|
|
|
|
}
|
|
|
|
|
2019-08-18 04:20:52 -07:00
|
|
|
public string Name => TmdbUtils.ProviderName;
|
2014-02-08 23:08:10 -07:00
|
|
|
|
2020-09-08 07:12:47 -07:00
|
|
|
// After TheTVDB
|
|
|
|
public int Order => 1;
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
internal static TmdbSeriesProvider Current { get; private set; }
|
|
|
|
|
2014-02-19 21:53:15 -07:00
|
|
|
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken)
|
|
|
|
{
|
2020-06-06 12:17:49 -07:00
|
|
|
var tmdbId = searchInfo.GetProviderId(MetadataProvider.Tmdb);
|
2014-03-02 08:42:21 -07:00
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(tmdbId))
|
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
var series = await _tmdbClientManager
|
|
|
|
.GetSeriesAsync(Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture), searchInfo.MetadataLanguage, searchInfo.MetadataLanguage, cancellationToken)
|
|
|
|
.ConfigureAwait(false);
|
2014-03-02 11:01:46 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (series != null)
|
2014-03-02 08:42:21 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
var remoteResult = MapTvShowToRemoteSearchResult(series);
|
2014-03-02 08:42:21 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
return new[] { remoteResult };
|
2014-03-02 08:42:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 12:17:49 -07:00
|
|
|
var imdbId = searchInfo.GetProviderId(MetadataProvider.Imdb);
|
2014-03-02 08:42:21 -07:00
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(imdbId))
|
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
var findResult = await _tmdbClientManager
|
|
|
|
.FindByExternalIdAsync(imdbId, FindExternalSource.Imdb, searchInfo.MetadataLanguage, cancellationToken)
|
|
|
|
.ConfigureAwait(false);
|
2014-03-02 08:42:21 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (findResult?.TvResults != null)
|
2014-03-02 08:42:21 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
var imdbIdResults = new List<RemoteSearchResult>();
|
|
|
|
for (var i = 0; i < findResult.TvResults.Count; i++)
|
|
|
|
{
|
|
|
|
var remoteResult = MapSearchTvToRemoteSearchResult(findResult.TvResults[i]);
|
|
|
|
remoteResult.SetProviderId(MetadataProvider.Imdb, imdbId);
|
|
|
|
imdbIdResults.Add(remoteResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return imdbIdResults;
|
2014-03-02 08:42:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 12:17:49 -07:00
|
|
|
var tvdbId = searchInfo.GetProviderId(MetadataProvider.Tvdb);
|
2014-03-02 08:42:21 -07:00
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(tvdbId))
|
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
var findResult = await _tmdbClientManager
|
|
|
|
.FindByExternalIdAsync(tvdbId, FindExternalSource.TvDb, searchInfo.MetadataLanguage, cancellationToken)
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
if (findResult?.TvResults != null)
|
|
|
|
{
|
|
|
|
var tvIdResults = new List<RemoteSearchResult>();
|
|
|
|
for (var i = 0; i < findResult.TvResults.Count; i++)
|
|
|
|
{
|
|
|
|
var remoteResult = MapSearchTvToRemoteSearchResult(findResult.TvResults[i]);
|
|
|
|
remoteResult.SetProviderId(MetadataProvider.Tvdb, tvdbId);
|
|
|
|
tvIdResults.Add(remoteResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tvIdResults;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var tvSearchResults = await _tmdbClientManager.SearchSeriesAsync(searchInfo.Name, searchInfo.MetadataLanguage, cancellationToken)
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
var remoteResults = new List<RemoteSearchResult>();
|
|
|
|
for (var i = 0; i < tvSearchResults.Count; i++)
|
|
|
|
{
|
|
|
|
remoteResults.Add(MapSearchTvToRemoteSearchResult(tvSearchResults[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return remoteResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
private RemoteSearchResult MapTvShowToRemoteSearchResult(TvShow series)
|
|
|
|
{
|
|
|
|
var remoteResult = new RemoteSearchResult
|
|
|
|
{
|
|
|
|
Name = series.Name ?? series.OriginalName,
|
|
|
|
SearchProviderName = Name,
|
|
|
|
ImageUrl = _tmdbClientManager.GetPosterUrl(series.PosterPath),
|
|
|
|
Overview = series.Overview
|
|
|
|
};
|
|
|
|
|
|
|
|
remoteResult.SetProviderId(MetadataProvider.Tmdb, series.Id.ToString(_usCulture));
|
|
|
|
if (series.ExternalIds != null)
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(series.ExternalIds.ImdbId))
|
|
|
|
{
|
|
|
|
remoteResult.SetProviderId(MetadataProvider.Imdb, series.ExternalIds.ImdbId);
|
|
|
|
}
|
2014-03-02 08:42:21 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (!string.IsNullOrEmpty(series.ExternalIds.TvdbId))
|
2014-03-02 08:42:21 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
remoteResult.SetProviderId(MetadataProvider.Tvdb, series.ExternalIds.TvdbId);
|
2014-03-02 08:42:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
remoteResult.PremiereDate = series.FirstAirDate?.ToUniversalTime();
|
|
|
|
|
|
|
|
return remoteResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
private RemoteSearchResult MapSearchTvToRemoteSearchResult(SearchTv series)
|
|
|
|
{
|
|
|
|
var remoteResult = new RemoteSearchResult
|
|
|
|
{
|
|
|
|
Name = series.Name ?? series.OriginalName,
|
|
|
|
SearchProviderName = Name,
|
|
|
|
ImageUrl = _tmdbClientManager.GetPosterUrl(series.PosterPath),
|
|
|
|
Overview = series.Overview
|
|
|
|
};
|
|
|
|
|
|
|
|
remoteResult.SetProviderId(MetadataProvider.Tmdb, series.Id.ToString(_usCulture));
|
|
|
|
remoteResult.PremiereDate = series.FirstAirDate?.ToUniversalTime();
|
|
|
|
|
|
|
|
return remoteResult;
|
2014-02-19 21:53:15 -07:00
|
|
|
}
|
|
|
|
|
2014-02-08 23:08:10 -07:00
|
|
|
public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
|
|
|
|
{
|
2020-09-08 07:12:47 -07:00
|
|
|
var result = new MetadataResult<Series>
|
|
|
|
{
|
|
|
|
QueriedById = true
|
|
|
|
};
|
2014-02-08 23:08:10 -07:00
|
|
|
|
2020-06-06 12:17:49 -07:00
|
|
|
var tmdbId = info.GetProviderId(MetadataProvider.Tmdb);
|
2014-02-08 23:08:10 -07:00
|
|
|
|
2014-02-12 22:11:54 -07:00
|
|
|
if (string.IsNullOrEmpty(tmdbId))
|
|
|
|
{
|
2020-06-06 12:17:49 -07:00
|
|
|
var imdbId = info.GetProviderId(MetadataProvider.Imdb);
|
2014-02-08 23:08:10 -07:00
|
|
|
|
2014-02-12 22:11:54 -07:00
|
|
|
if (!string.IsNullOrEmpty(imdbId))
|
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
var searchResult = await _tmdbClientManager.FindByExternalIdAsync(imdbId, FindExternalSource.Imdb, info.MetadataLanguage, cancellationToken).ConfigureAwait(false);
|
2014-03-02 08:42:21 -07:00
|
|
|
|
|
|
|
if (searchResult != null)
|
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
tmdbId = searchResult.TvResults.FirstOrDefault()?.Id.ToString(CultureInfo.InvariantCulture);
|
2014-03-02 08:42:21 -07:00
|
|
|
}
|
2014-02-12 22:11:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(tmdbId))
|
|
|
|
{
|
2020-06-06 12:17:49 -07:00
|
|
|
var tvdbId = info.GetProviderId(MetadataProvider.Tvdb);
|
2014-02-12 22:11:54 -07:00
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(tvdbId))
|
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
var searchResult = await _tmdbClientManager.FindByExternalIdAsync(tvdbId, FindExternalSource.TvDb, info.MetadataLanguage, cancellationToken).ConfigureAwait(false);
|
2014-03-02 08:42:21 -07:00
|
|
|
|
|
|
|
if (searchResult != null)
|
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
tmdbId = searchResult.TvResults.FirstOrDefault()?.Id.ToString(CultureInfo.InvariantCulture);
|
2014-03-02 08:42:21 -07:00
|
|
|
}
|
2014-02-12 22:11:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(tmdbId))
|
2014-02-08 23:08:10 -07:00
|
|
|
{
|
2016-09-17 21:27:17 -07:00
|
|
|
result.QueriedById = false;
|
2020-09-24 10:49:35 -07:00
|
|
|
var searchResults = await _tmdbClientManager.SearchSeriesAsync(info.Name, info.MetadataLanguage, cancellationToken).ConfigureAwait(false);
|
2014-02-15 09:36:09 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (searchResults.Count > 0)
|
2014-02-15 09:36:09 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
tmdbId = searchResults[0].Id.ToString(CultureInfo.InvariantCulture);
|
2014-02-15 09:36:09 -07:00
|
|
|
}
|
2014-02-08 23:08:10 -07:00
|
|
|
}
|
|
|
|
|
2014-02-12 22:11:54 -07:00
|
|
|
if (!string.IsNullOrEmpty(tmdbId))
|
2014-02-08 23:08:10 -07:00
|
|
|
{
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
var tvShow = await _tmdbClientManager
|
|
|
|
.GetSeriesAsync(Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture), info.MetadataLanguage, TmdbUtils.GetImageLanguagesParam(info.MetadataLanguage), cancellationToken)
|
|
|
|
.ConfigureAwait(false);
|
2014-03-02 08:42:21 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
result = new MetadataResult<Series>
|
|
|
|
{
|
|
|
|
Item = MapTvShowToSeries(tvShow, info.MetadataCountryCode),
|
|
|
|
ResultLanguage = info.MetadataLanguage ?? tvShow.OriginalLanguage
|
|
|
|
};
|
2014-02-08 23:08:10 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
foreach (var person in GetPersons(tvShow))
|
|
|
|
{
|
|
|
|
result.AddPerson(person);
|
|
|
|
}
|
2014-02-08 23:08:10 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
result.HasMetadata = result.Item != null;
|
2014-02-12 22:11:54 -07:00
|
|
|
}
|
2014-02-08 23:08:10 -07:00
|
|
|
|
2016-05-13 18:55:46 -07:00
|
|
|
return result;
|
2014-02-08 23:08:10 -07:00
|
|
|
}
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
private Series MapTvShowToSeries(TvShow seriesResult, string preferredCountryCode)
|
2014-02-08 23:08:10 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
var series = new Series {Name = seriesResult.Name, OriginalTitle = seriesResult.OriginalName};
|
2018-09-12 10:26:21 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
series.SetProviderId(MetadataProvider.Tmdb, seriesResult.Id.ToString(_usCulture));
|
2014-02-08 23:08:10 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
series.CommunityRating = Convert.ToSingle(seriesResult.VoteAverage);
|
2014-02-08 23:08:10 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
series.Overview = seriesResult.Overview;
|
2014-02-08 23:08:10 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (seriesResult.Networks != null)
|
2014-02-08 23:08:10 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
series.Studios = seriesResult.Networks.Select(i => i.Name).ToArray();
|
2014-02-08 23:08:10 -07:00
|
|
|
}
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (seriesResult.Genres != null)
|
2014-02-08 23:08:10 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
series.Genres = seriesResult.Genres.Select(i => i.Name).ToArray();
|
2014-02-08 23:08:10 -07:00
|
|
|
}
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
series.HomePageUrl = seriesResult.Homepage;
|
2015-01-30 20:19:41 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
series.RunTimeTicks = seriesResult.EpisodeRunTime.Select(i => TimeSpan.FromMinutes(i).Ticks).FirstOrDefault();
|
2014-02-08 23:08:10 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (string.Equals(seriesResult.Status, "Ended", StringComparison.OrdinalIgnoreCase))
|
2014-02-08 23:08:10 -07:00
|
|
|
{
|
|
|
|
series.Status = SeriesStatus.Ended;
|
2020-09-24 10:49:35 -07:00
|
|
|
series.EndDate = seriesResult.LastAirDate;
|
2014-02-08 23:08:10 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
series.Status = SeriesStatus.Continuing;
|
|
|
|
}
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
series.PremiereDate = seriesResult.FirstAirDate;
|
2014-02-08 23:08:10 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
var ids = seriesResult.ExternalIds;
|
2014-02-08 23:08:10 -07:00
|
|
|
if (ids != null)
|
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
if (!string.IsNullOrWhiteSpace(ids.ImdbId))
|
2014-02-08 23:08:10 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
series.SetProviderId(MetadataProvider.Imdb, ids.ImdbId);
|
2014-02-08 23:08:10 -07:00
|
|
|
}
|
2020-05-30 23:28:01 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (!string.IsNullOrEmpty(ids.TvrageId))
|
2014-02-08 23:08:10 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
series.SetProviderId(MetadataProvider.TvRage, ids.TvrageId);
|
2014-02-08 23:08:10 -07:00
|
|
|
}
|
2020-05-30 23:28:01 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (!string.IsNullOrEmpty(ids.TvdbId))
|
2014-02-08 23:08:10 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
series.SetProviderId(MetadataProvider.Tvdb, ids.TvdbId);
|
2014-02-08 23:08:10 -07:00
|
|
|
}
|
|
|
|
}
|
2016-04-18 20:14:45 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
var contentRatings = seriesResult.ContentRatings.Results ?? new List<ContentRating>();
|
2016-04-18 20:14:45 -07:00
|
|
|
|
2019-08-18 05:44:13 -07: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));
|
2016-04-18 20:14:45 -07:00
|
|
|
var minimumRelease = contentRatings.FirstOrDefault();
|
|
|
|
|
|
|
|
if (ourRelease != null)
|
|
|
|
{
|
2019-08-18 05:44:13 -07:00
|
|
|
series.OfficialRating = ourRelease.Rating;
|
2016-04-18 20:14:45 -07:00
|
|
|
}
|
|
|
|
else if (usRelease != null)
|
|
|
|
{
|
2019-08-18 05:44:13 -07:00
|
|
|
series.OfficialRating = usRelease.Rating;
|
2016-04-18 20:14:45 -07:00
|
|
|
}
|
|
|
|
else if (minimumRelease != null)
|
|
|
|
{
|
2019-08-18 05:44:13 -07:00
|
|
|
series.OfficialRating = minimumRelease.Rating;
|
2016-04-18 20:14:45 -07:00
|
|
|
}
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (seriesResult.Videos?.Results != null)
|
2016-06-03 21:30:06 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
foreach (var video in seriesResult.Videos.Results)
|
2016-06-03 21:30:06 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
if (TmdbUtils.IsTrailerType(video))
|
2016-06-03 21:30:06 -07:00
|
|
|
{
|
2019-08-18 05:44:13 -07:00
|
|
|
series.AddTrailerUrl($"http://www.youtube.com/watch?v={video.Key}");
|
2016-06-03 21:30:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-12 10:26:21 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
return series;
|
|
|
|
}
|
2018-09-12 10:26:21 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
private IEnumerable<PersonInfo> GetPersons(TvShow seriesResult)
|
|
|
|
{
|
|
|
|
if (seriesResult.Credits?.Cast != null)
|
2018-09-12 10:26:21 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
foreach (var actor in seriesResult.Credits.Cast.OrderBy(a => a.Order).Take(TmdbUtils.MaxCastMembers))
|
2018-09-12 10:26:21 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
var personInfo = new PersonInfo
|
2018-09-12 10:26:21 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
Name = actor.Name.Trim(),
|
|
|
|
Role = actor.Character,
|
|
|
|
Type = PersonType.Actor,
|
|
|
|
SortOrder = actor.Order,
|
|
|
|
ImageUrl = _tmdbClientManager.GetPosterUrl(actor.ProfilePath)
|
2020-05-10 04:53:04 -07:00
|
|
|
};
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (actor.Id > 0)
|
2020-05-10 04:53:04 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
personInfo.SetProviderId(MetadataProvider.Tmdb, actor.Id.ToString(CultureInfo.InvariantCulture));
|
2020-05-10 04:53:04 -07:00
|
|
|
}
|
2015-01-30 20:19:41 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
yield return personInfo;
|
2020-08-17 12:59:29 -07:00
|
|
|
}
|
2014-02-08 23:08:10 -07:00
|
|
|
}
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (seriesResult.Credits?.Crew != null)
|
2014-02-08 23:08:10 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
var keepTypes = new[]
|
2014-02-08 23:08:10 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
PersonType.Director,
|
|
|
|
PersonType.Writer,
|
|
|
|
PersonType.Producer
|
|
|
|
};
|
2020-08-17 12:10:02 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
foreach (var person in seriesResult.Credits.Crew)
|
2014-02-12 22:11:54 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
// Normalize this
|
|
|
|
var type = TmdbUtils.MapCrewToPersonType(person);
|
2014-02-12 22:11:54 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (!keepTypes.Contains(type, StringComparer.OrdinalIgnoreCase)
|
|
|
|
&& !keepTypes.Contains(person.Job ?? string.Empty, StringComparer.OrdinalIgnoreCase))
|
2014-02-12 22:11:54 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
continue;
|
|
|
|
}
|
2017-10-20 09:16:56 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
yield return new PersonInfo
|
|
|
|
{
|
|
|
|
Name = person.Name.Trim(),
|
|
|
|
Role = person.Job,
|
|
|
|
Type = type
|
|
|
|
};
|
2014-02-12 22:11:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 12:10:02 -07:00
|
|
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
2014-02-19 21:53:15 -07:00
|
|
|
{
|
2020-08-31 10:05:21 -07:00
|
|
|
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
|
2014-02-19 21:53:15 -07:00
|
|
|
}
|
2014-02-08 23:08:10 -07:00
|
|
|
}
|
|
|
|
}
|