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