2020-06-19 11:24:13 -07:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 13:03:10 -07:00
|
|
|
using System;
|
2019-01-13 12:26:31 -07:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
2020-09-24 10:49:35 -07:00
|
|
|
using System.Linq;
|
2020-08-17 12:10:02 -07:00
|
|
|
using System.Net.Http;
|
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;
|
2020-09-24 10:49:35 -07:00
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2014-07-04 20:10:09 -07:00
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
|
2020-05-30 23:23:09 -07:00
|
|
|
namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
2014-07-04 20:10:09 -07:00
|
|
|
{
|
2019-08-18 04:20:52 -07:00
|
|
|
public class TmdbSeasonProvider : IRemoteMetadataProvider<Season, SeasonInfo>
|
2014-07-04 20:10:09 -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;
|
|
|
|
|
|
|
|
public TmdbSeasonProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager)
|
2014-07-04 20:10:09 -07:00
|
|
|
{
|
2020-08-17 12:10:02 -07:00
|
|
|
_httpClientFactory = httpClientFactory;
|
2020-09-24 10:49:35 -07:00
|
|
|
_tmdbClientManager = tmdbClientManager;
|
2014-07-04 20:10:09 -07:00
|
|
|
}
|
|
|
|
|
2020-09-08 07:12:47 -07:00
|
|
|
public string Name => TmdbUtils.ProviderName;
|
|
|
|
|
2014-07-04 20:10:09 -07:00
|
|
|
public async Task<MetadataResult<Season>> GetMetadata(SeasonInfo info, CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
var result = new MetadataResult<Season>();
|
|
|
|
|
2021-10-26 06:49:01 -07:00
|
|
|
info.SeriesProviderIds.TryGetValue(MetadataProvider.Tmdb.ToString(), out string? seriesTmdbId);
|
2014-07-04 20:10:09 -07:00
|
|
|
|
2014-07-08 19:53:04 -07:00
|
|
|
var seasonNumber = info.IndexNumber;
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (string.IsNullOrWhiteSpace(seriesTmdbId) || !seasonNumber.HasValue)
|
2014-07-04 20:10:09 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
return result;
|
2014-07-04 20:10:09 -07:00
|
|
|
}
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
var seasonResult = await _tmdbClientManager
|
|
|
|
.GetSeasonAsync(Convert.ToInt32(seriesTmdbId, CultureInfo.InvariantCulture), seasonNumber.Value, info.MetadataLanguage, TmdbUtils.GetImageLanguagesParam(info.MetadataLanguage), cancellationToken)
|
|
|
|
.ConfigureAwait(false);
|
2014-07-04 20:10:09 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (seasonResult == null)
|
2014-07-04 20:10:09 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
return result;
|
2014-07-04 20:10:09 -07:00
|
|
|
}
|
2020-05-30 23:28:01 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
result.HasMetadata = true;
|
|
|
|
result.Item = new Season
|
2014-07-04 20:10:09 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
IndexNumber = seasonNumber,
|
2021-06-26 17:00:17 -07:00
|
|
|
Overview = seasonResult.Overview
|
2020-09-24 10:49:35 -07:00
|
|
|
};
|
2014-07-04 20:10:09 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (!string.IsNullOrEmpty(seasonResult.ExternalIds?.TvdbId))
|
|
|
|
{
|
|
|
|
result.Item.SetProviderId(MetadataProvider.Tvdb, seasonResult.ExternalIds.TvdbId);
|
|
|
|
}
|
2014-07-04 20:10:09 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
// TODO why was this disabled?
|
|
|
|
var credits = seasonResult.Credits;
|
|
|
|
if (credits?.Cast != null)
|
2014-07-04 20:10:09 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
var cast = credits.Cast.OrderBy(c => c.Order).Take(TmdbUtils.MaxCastMembers).ToList();
|
|
|
|
for (var i = 0; i < cast.Count; i++)
|
2014-07-04 20:10:09 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
result.AddPerson(new PersonInfo
|
|
|
|
{
|
|
|
|
Name = cast[i].Name.Trim(),
|
|
|
|
Role = cast[i].Character,
|
|
|
|
Type = PersonType.Actor,
|
|
|
|
SortOrder = cast[i].Order
|
|
|
|
});
|
2014-07-04 20:10:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (credits?.Crew != null)
|
2014-07-04 20:10:09 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
foreach (var person in credits.Crew)
|
|
|
|
{
|
|
|
|
// Normalize this
|
|
|
|
var type = TmdbUtils.MapCrewToPersonType(person);
|
2020-05-30 23:28:01 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
if (!TmdbUtils.WantedCrewTypes.Contains(type, StringComparer.OrdinalIgnoreCase)
|
|
|
|
&& !TmdbUtils.WantedCrewTypes.Contains(person.Job ?? string.Empty, StringComparer.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2014-07-04 20:10:09 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
result.AddPerson(new PersonInfo
|
|
|
|
{
|
|
|
|
Name = person.Name.Trim(),
|
|
|
|
Role = person.Job,
|
|
|
|
Type = type
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-07-04 20:10:09 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
result.Item.PremiereDate = seasonResult.AirDate;
|
|
|
|
result.Item.ProductionYear = seasonResult.AirDate?.Year;
|
2014-07-04 20:10:09 -07:00
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
return result;
|
2014-07-04 20:10:09 -07:00
|
|
|
}
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeasonInfo searchInfo, CancellationToken cancellationToken)
|
2014-07-04 20:10:09 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
return Task.FromResult(Enumerable.Empty<RemoteSearchResult>());
|
2014-07-04 20:10:09 -07:00
|
|
|
}
|
|
|
|
|
2020-09-24 10:49:35 -07:00
|
|
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
2014-07-04 20:10:09 -07:00
|
|
|
{
|
2020-09-24 10:49:35 -07:00
|
|
|
return _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
|
2014-07-04 20:10:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|