Add better language support
This commit is contained in:
parent
e970d7a6aa
commit
8029cd3ebb
|
@ -17,6 +17,16 @@ namespace MediaBrowser.Controller.Library
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly string BannerUrl = TvdbBaseUrl + "banners/";
|
public static readonly string BannerUrl = TvdbBaseUrl + "banners/";
|
||||||
|
|
||||||
|
public static string NormalizeLanguage(string language)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(language))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// pt-br is just pt to tvdb
|
||||||
|
return language.Split('-')[0].ToLowerInvariant();
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the air days.
|
/// Gets the air days.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace MediaBrowser.Providers.People
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var actorsResult = await _tvDbClientManager.GetActorsAsync(tvdbId, cancellationToken);
|
var actorsResult = await _tvDbClientManager.GetActorsAsync(tvdbId, series.GetPreferredMetadataLanguage(), cancellationToken);
|
||||||
var actor = actorsResult.Data.FirstOrDefault(a =>
|
var actor = actorsResult.Data.FirstOrDefault(a =>
|
||||||
string.Equals(a.Name, personName, StringComparison.OrdinalIgnoreCase) &&
|
string.Equals(a.Name, personName, StringComparison.OrdinalIgnoreCase) &&
|
||||||
!string.IsNullOrEmpty(a.Image));
|
!string.IsNullOrEmpty(a.Image));
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace MediaBrowser.Providers.TV
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var episodes = await TvDbClientManager.Instance.GetAllEpisodesAsync(Convert.ToInt32(tvdbId), cancellationToken);
|
var episodes = await TvDbClientManager.Instance.GetAllEpisodesAsync(Convert.ToInt32(tvdbId), series.GetPreferredMetadataLanguage(), cancellationToken);
|
||||||
|
|
||||||
var episodeLookup = episodes
|
var episodeLookup = episodes
|
||||||
.Select(i =>
|
.Select(i =>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
|
@ -22,6 +23,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
private static readonly object syncRoot = new object();
|
private static readonly object syncRoot = new object();
|
||||||
private static TvDbClient tvDbClient;
|
private static TvDbClient tvDbClient;
|
||||||
private static DateTime tokenCreatedAt;
|
private static DateTime tokenCreatedAt;
|
||||||
|
private const string DefaultLanguage = "en";
|
||||||
|
|
||||||
private TvDbClientManager()
|
private TvDbClientManager()
|
||||||
{
|
{
|
||||||
|
@ -70,32 +72,35 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
|
|
||||||
tokenCreatedAt = DateTime.Now;
|
tokenCreatedAt = DateTime.Now;
|
||||||
}
|
}
|
||||||
// Default to English
|
|
||||||
tvDbClient.AcceptedLanguage = "en";
|
|
||||||
return tvDbClient;
|
return tvDbClient;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<TvDbResponse<SeriesSearchResult[]>> GetSeriesByNameAsync(string name, CancellationToken cancellationToken)
|
public Task<TvDbResponse<SeriesSearchResult[]>> GetSeriesByNameAsync(string name, string language,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return TryGetValue("series" + name,() => TvDbClient.Search.SearchSeriesByNameAsync(name, cancellationToken));
|
return TryGetValue("series" + name, language,() => TvDbClient.Search.SearchSeriesByNameAsync(name, cancellationToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<TvDbResponse<Series>> GetSeriesByIdAsync(int tvdbId, CancellationToken cancellationToken)
|
public Task<TvDbResponse<Series>> GetSeriesByIdAsync(int tvdbId, string language,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return TryGetValue("series" + tvdbId,() => TvDbClient.Series.GetAsync(tvdbId, cancellationToken));
|
return TryGetValue("series" + tvdbId, language,() => TvDbClient.Series.GetAsync(tvdbId, cancellationToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<TvDbResponse<EpisodeRecord>> GetEpisodesAsync(int episodeTvdbId, CancellationToken cancellationToken)
|
public Task<TvDbResponse<EpisodeRecord>> GetEpisodesAsync(int episodeTvdbId, string language,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return TryGetValue("episode" + episodeTvdbId,() => TvDbClient.Episodes.GetAsync(episodeTvdbId, cancellationToken));
|
return TryGetValue("episode" + episodeTvdbId, language,() => TvDbClient.Episodes.GetAsync(episodeTvdbId, cancellationToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<EpisodeRecord>> GetAllEpisodesAsync(int tvdbId, CancellationToken cancellationToken)
|
public async Task<List<EpisodeRecord>> GetAllEpisodesAsync(int tvdbId, string language,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// Traverse all episode pages and join them together
|
// Traverse all episode pages and join them together
|
||||||
var episodes = new List<EpisodeRecord>();
|
var episodes = new List<EpisodeRecord>();
|
||||||
var episodePage = await GetEpisodesPageAsync(tvdbId, new EpisodeQuery(), cancellationToken);
|
var episodePage = await GetEpisodesPageAsync(tvdbId, new EpisodeQuery(), language, cancellationToken);
|
||||||
episodes.AddRange(episodePage.Data);
|
episodes.AddRange(episodePage.Data);
|
||||||
if (!episodePage.Links.Next.HasValue || !episodePage.Links.Last.HasValue)
|
if (!episodePage.Links.Next.HasValue || !episodePage.Links.Last.HasValue)
|
||||||
{
|
{
|
||||||
|
@ -107,45 +112,51 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
|
|
||||||
for (var page = next; page <= last; ++page)
|
for (var page = next; page <= last; ++page)
|
||||||
{
|
{
|
||||||
episodePage = await GetEpisodesPageAsync(tvdbId, page, new EpisodeQuery(), cancellationToken);
|
episodePage = await GetEpisodesPageAsync(tvdbId, page, new EpisodeQuery(), language, cancellationToken);
|
||||||
episodes.AddRange(episodePage.Data);
|
episodes.AddRange(episodePage.Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return episodes;
|
return episodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<TvDbResponse<SeriesSearchResult[]>> GetSeriesByImdbIdAsync(string imdbId, CancellationToken cancellationToken)
|
public Task<TvDbResponse<SeriesSearchResult[]>> GetSeriesByImdbIdAsync(string imdbId, string language,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return TryGetValue("series" + imdbId,() => TvDbClient.Search.SearchSeriesByImdbIdAsync(imdbId, cancellationToken));
|
return TryGetValue("series" + imdbId, language,() => TvDbClient.Search.SearchSeriesByImdbIdAsync(imdbId, cancellationToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<TvDbResponse<SeriesSearchResult[]>> GetSeriesByZap2ItIdAsync(string zap2ItId, CancellationToken cancellationToken)
|
public Task<TvDbResponse<SeriesSearchResult[]>> GetSeriesByZap2ItIdAsync(string zap2ItId, string language,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return TryGetValue("series" + zap2ItId,() => TvDbClient.Search.SearchSeriesByZap2ItIdAsync(zap2ItId, cancellationToken));
|
return TryGetValue("series" + zap2ItId, language,() => TvDbClient.Search.SearchSeriesByZap2ItIdAsync(zap2ItId, cancellationToken));
|
||||||
}
|
}
|
||||||
public Task<TvDbResponse<Actor[]>> GetActorsAsync(int tvdbId, CancellationToken cancellationToken)
|
public Task<TvDbResponse<Actor[]>> GetActorsAsync(int tvdbId, string language,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return TryGetValue("actors" + tvdbId,() => TvDbClient.Series.GetActorsAsync(tvdbId, cancellationToken));
|
return TryGetValue("actors" + tvdbId, language,() => TvDbClient.Series.GetActorsAsync(tvdbId, cancellationToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<TvDbResponse<Image[]>> GetImagesAsync(int tvdbId, ImagesQuery imageQuery, CancellationToken cancellationToken)
|
public Task<TvDbResponse<Image[]>> GetImagesAsync(int tvdbId, ImagesQuery imageQuery, string language,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var cacheKey = "images" + tvdbId + "keytype" + imageQuery.KeyType + "subkey" + imageQuery.SubKey;
|
var cacheKey = "images" + tvdbId + "keytype" + imageQuery.KeyType + "subkey" + imageQuery.SubKey;
|
||||||
return TryGetValue(cacheKey,() => TvDbClient.Series.GetImagesAsync(tvdbId, imageQuery, cancellationToken));
|
return TryGetValue(cacheKey, language,() => TvDbClient.Series.GetImagesAsync(tvdbId, imageQuery, cancellationToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<TvDbResponse<Language[]>> GetLanguagesAsync(CancellationToken cancellationToken)
|
public Task<TvDbResponse<Language[]>> GetLanguagesAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return TryGetValue("languages",() => TvDbClient.Languages.GetAllAsync(cancellationToken));
|
return TryGetValue("languages", null,() => TvDbClient.Languages.GetAllAsync(cancellationToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<TvDbResponse<EpisodesSummary>> GetSeriesEpisodeSummaryAsync(int tvdbId, CancellationToken cancellationToken)
|
public Task<TvDbResponse<EpisodesSummary>> GetSeriesEpisodeSummaryAsync(int tvdbId, string language,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return TryGetValue("seriesepisodesummary" + tvdbId,
|
return TryGetValue("seriesepisodesummary" + tvdbId, language,
|
||||||
() => TvDbClient.Series.GetEpisodesSummaryAsync(tvdbId, cancellationToken));
|
() => TvDbClient.Series.GetEpisodesSummaryAsync(tvdbId, cancellationToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<TvDbResponse<EpisodeRecord[]>> GetEpisodesPageAsync(int tvdbId, int page, EpisodeQuery episodeQuery, CancellationToken cancellationToken)
|
public Task<TvDbResponse<EpisodeRecord[]>> GetEpisodesPageAsync(int tvdbId, int page, EpisodeQuery episodeQuery,
|
||||||
|
string language, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// Not quite as dynamic as it could be
|
// Not quite as dynamic as it could be
|
||||||
var cacheKey = "episodespage" + tvdbId + "page" + page;
|
var cacheKey = "episodespage" + tvdbId + "page" + page;
|
||||||
|
@ -157,11 +168,13 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
{
|
{
|
||||||
cacheKey += "airedepisode" + episodeQuery.AiredEpisode.Value;
|
cacheKey += "airedepisode" + episodeQuery.AiredEpisode.Value;
|
||||||
}
|
}
|
||||||
return TryGetValue(cacheKey,
|
|
||||||
|
return TryGetValue(cacheKey, language,
|
||||||
() => TvDbClient.Series.GetEpisodesAsync(tvdbId, page, episodeQuery, cancellationToken));
|
() => TvDbClient.Series.GetEpisodesAsync(tvdbId, page, episodeQuery, cancellationToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<string> GetEpisodeTvdbId(EpisodeInfo searchInfo, CancellationToken cancellationToken)
|
public Task<string> GetEpisodeTvdbId(EpisodeInfo searchInfo, string language,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
searchInfo.SeriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(),
|
searchInfo.SeriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(),
|
||||||
out var seriesTvdbId);
|
out var seriesTvdbId);
|
||||||
|
@ -180,21 +193,23 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
episodeQuery.FirstAired = searchInfo.PremiereDate.Value.ToString("yyyy-MM-dd");
|
episodeQuery.FirstAired = searchInfo.PremiereDate.Value.ToString("yyyy-MM-dd");
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetEpisodeTvdbId(Convert.ToInt32(seriesTvdbId), episodeQuery, cancellationToken);
|
return GetEpisodeTvdbId(Convert.ToInt32(seriesTvdbId), episodeQuery, cancellationToken, language);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> GetEpisodeTvdbId(int seriesTvdbId, EpisodeQuery episodeQuery, CancellationToken cancellationToken)
|
public async Task<string> GetEpisodeTvdbId(int seriesTvdbId, EpisodeQuery episodeQuery,
|
||||||
|
CancellationToken cancellationToken, string language)
|
||||||
{
|
{
|
||||||
var episodePage = await GetEpisodesPageAsync(Convert.ToInt32(seriesTvdbId), episodeQuery, cancellationToken);
|
var episodePage = await GetEpisodesPageAsync(Convert.ToInt32(seriesTvdbId), episodeQuery, language, cancellationToken);
|
||||||
return episodePage.Data.FirstOrDefault()?.Id.ToString();
|
return episodePage.Data.FirstOrDefault()?.Id.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<TvDbResponse<EpisodeRecord[]>> GetEpisodesPageAsync(int tvdbId, EpisodeQuery episodeQuery, CancellationToken cancellationToken)
|
public Task<TvDbResponse<EpisodeRecord[]>> GetEpisodesPageAsync(int tvdbId, EpisodeQuery episodeQuery,
|
||||||
|
string language, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return GetEpisodesPageAsync(tvdbId, 1, episodeQuery, cancellationToken);
|
return GetEpisodesPageAsync(tvdbId, 1, episodeQuery, language, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<T> TryGetValue<T>(object key, Func<Task<T>> resultFactory)
|
private async Task<T> TryGetValue<T>(string key, string language, Func<Task<T>> resultFactory)
|
||||||
{
|
{
|
||||||
if (_cache.TryGetValue(key, out T cachedValue))
|
if (_cache.TryGetValue(key, out T cachedValue))
|
||||||
{
|
{
|
||||||
|
@ -209,6 +224,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
return cachedValue;
|
return cachedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tvDbClient.AcceptedLanguage = TVUtils.NormalizeLanguage(language) ?? DefaultLanguage;
|
||||||
var result = await resultFactory.Invoke();
|
var result = await resultFactory.Invoke();
|
||||||
_cache.Set(key, result, TimeSpan.FromHours(1));
|
_cache.Set(key, result, TimeSpan.FromHours(1));
|
||||||
return result;
|
return result;
|
||||||
|
@ -218,5 +234,35 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
_cacheWriteLock.Release();
|
_cacheWriteLock.Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GenerateKey(object[] objects)
|
||||||
|
{
|
||||||
|
var key = string.Empty;
|
||||||
|
|
||||||
|
foreach (var obj in objects)
|
||||||
|
{
|
||||||
|
key += nameof(obj);
|
||||||
|
var objType = obj.GetType();
|
||||||
|
if (objType.IsPrimitive || objType == typeof(string))
|
||||||
|
{
|
||||||
|
key += obj.ToString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (PropertyInfo propertyInfo in objType.GetProperties())
|
||||||
|
{
|
||||||
|
var currentValue = propertyInfo.GetValue(obj, null);
|
||||||
|
if (currentValue == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
key += propertyInfo.Name + currentValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return key;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
var episode = (Episode)item;
|
var episode = (Episode)item;
|
||||||
var series = episode.Series;
|
var series = episode.Series;
|
||||||
var imageResult = new List<RemoteImageInfo>();
|
var imageResult = new List<RemoteImageInfo>();
|
||||||
|
var language = item.GetPreferredMetadataLanguage();
|
||||||
if (series != null && TvdbSeriesProvider.IsValidSeries(series.ProviderIds))
|
if (series != null && TvdbSeriesProvider.IsValidSeries(series.ProviderIds))
|
||||||
{
|
{
|
||||||
var episodeTvdbId = episode.GetProviderId(MetadataProviders.Tvdb);
|
var episodeTvdbId = episode.GetProviderId(MetadataProviders.Tvdb);
|
||||||
|
@ -66,7 +66,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
ParentIndexNumber = episode.ParentIndexNumber.Value,
|
ParentIndexNumber = episode.ParentIndexNumber.Value,
|
||||||
SeriesProviderIds = series.ProviderIds
|
SeriesProviderIds = series.ProviderIds
|
||||||
};
|
};
|
||||||
episodeTvdbId = await _tvDbClientManager.GetEpisodeTvdbId(episodeInfo, cancellationToken);
|
episodeTvdbId = await _tvDbClientManager.GetEpisodeTvdbId(episodeInfo, language, cancellationToken);
|
||||||
if (string.IsNullOrEmpty(episodeTvdbId))
|
if (string.IsNullOrEmpty(episodeTvdbId))
|
||||||
{
|
{
|
||||||
_logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
|
_logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
|
||||||
|
@ -76,7 +76,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
}
|
}
|
||||||
|
|
||||||
var episodeResult =
|
var episodeResult =
|
||||||
await _tvDbClientManager.GetEpisodesAsync(Convert.ToInt32(episodeTvdbId), cancellationToken);
|
await _tvDbClientManager.GetEpisodesAsync(Convert.ToInt32(episodeTvdbId), language, cancellationToken);
|
||||||
|
|
||||||
var image = GetImageInfo(episodeResult.Data);
|
var image = GetImageInfo(episodeResult.Data);
|
||||||
if (image != null)
|
if (image != null)
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
var episodeTvdbId = searchInfo.GetProviderId(MetadataProviders.Tvdb);
|
var episodeTvdbId = searchInfo.GetProviderId(MetadataProviders.Tvdb);
|
||||||
if (string.IsNullOrEmpty(episodeTvdbId))
|
if (string.IsNullOrEmpty(episodeTvdbId))
|
||||||
{
|
{
|
||||||
episodeTvdbId = await _tvDbClientManager.GetEpisodeTvdbId(searchInfo, cancellationToken);
|
episodeTvdbId = await _tvDbClientManager.GetEpisodeTvdbId(searchInfo, searchInfo.MetadataLanguage, cancellationToken);
|
||||||
if (string.IsNullOrEmpty(episodeTvdbId))
|
if (string.IsNullOrEmpty(episodeTvdbId))
|
||||||
{
|
{
|
||||||
_logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
|
_logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
|
||||||
|
@ -56,7 +56,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var episodeResult = await _tvDbClientManager.GetEpisodesAsync(Convert.ToInt32(episodeTvdbId), cancellationToken);
|
var episodeResult = await _tvDbClientManager.GetEpisodesAsync(Convert.ToInt32(episodeTvdbId), searchInfo.MetadataLanguage, cancellationToken);
|
||||||
var metadataResult = MapEpisodeToResult(searchInfo, episodeResult.Data);
|
var metadataResult = MapEpisodeToResult(searchInfo, episodeResult.Data);
|
||||||
|
|
||||||
if (metadataResult.HasMetadata)
|
if (metadataResult.HasMetadata)
|
||||||
|
@ -102,7 +102,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(tvdbId))
|
if (string.IsNullOrEmpty(tvdbId))
|
||||||
{
|
{
|
||||||
tvdbId = await _tvDbClientManager.GetEpisodeTvdbId(searchInfo, cancellationToken);
|
tvdbId = await _tvDbClientManager.GetEpisodeTvdbId(searchInfo, searchInfo.MetadataLanguage, cancellationToken);
|
||||||
if (string.IsNullOrEmpty(tvdbId))
|
if (string.IsNullOrEmpty(tvdbId))
|
||||||
{
|
{
|
||||||
_logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
|
_logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
|
||||||
|
@ -112,7 +112,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
}
|
}
|
||||||
|
|
||||||
var episodeResult = await _tvDbClientManager.GetEpisodesAsync(
|
var episodeResult = await _tvDbClientManager.GetEpisodesAsync(
|
||||||
Convert.ToInt32(tvdbId),
|
Convert.ToInt32(tvdbId), searchInfo.MetadataLanguage,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
|
|
||||||
result = MapEpisodeToResult(searchInfo, episodeResult.Data);
|
result = MapEpisodeToResult(searchInfo, episodeResult.Data);
|
||||||
|
|
|
@ -65,7 +65,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
var tvdbId = Convert.ToInt32(series.GetProviderId(MetadataProviders.Tvdb));
|
var tvdbId = Convert.ToInt32(series.GetProviderId(MetadataProviders.Tvdb));
|
||||||
var seasonNumber = season.IndexNumber.Value;
|
var seasonNumber = season.IndexNumber.Value;
|
||||||
var language = item.GetPreferredMetadataLanguage();
|
var language = item.GetPreferredMetadataLanguage();
|
||||||
_tvDbClientManager.TvDbClient.AcceptedLanguage = language;
|
|
||||||
var remoteImages = new List<RemoteImageInfo>();
|
var remoteImages = new List<RemoteImageInfo>();
|
||||||
|
|
||||||
var keyTypes = new[] {KeyType.Season, KeyType.Seasonwide, KeyType.Fanart};
|
var keyTypes = new[] {KeyType.Season, KeyType.Seasonwide, KeyType.Fanart};
|
||||||
|
@ -78,7 +77,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
};
|
};
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var imageResults = await _tvDbClientManager.GetImagesAsync(tvdbId, imageQuery, cancellationToken);
|
var imageResults = await _tvDbClientManager.GetImagesAsync(tvdbId, imageQuery, language, cancellationToken);
|
||||||
remoteImages.AddRange(GetImages(imageResults.Data, language));
|
remoteImages.AddRange(GetImages(imageResults.Data, language));
|
||||||
}
|
}
|
||||||
catch (TvDbServerException)
|
catch (TvDbServerException)
|
||||||
|
|
|
@ -58,7 +58,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
}
|
}
|
||||||
|
|
||||||
var language = item.GetPreferredMetadataLanguage();
|
var language = item.GetPreferredMetadataLanguage();
|
||||||
_tvDbClientManager.TvDbClient.AcceptedLanguage = language;
|
|
||||||
var remoteImages = new List<RemoteImageInfo>();
|
var remoteImages = new List<RemoteImageInfo>();
|
||||||
var keyTypes = new[] {KeyType.Poster, KeyType.Series, KeyType.Fanart};
|
var keyTypes = new[] {KeyType.Poster, KeyType.Series, KeyType.Fanart};
|
||||||
var tvdbId = Convert.ToInt32(item.GetProviderId(MetadataProviders.Tvdb));
|
var tvdbId = Convert.ToInt32(item.GetProviderId(MetadataProviders.Tvdb));
|
||||||
|
@ -71,7 +70,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var imageResults =
|
var imageResults =
|
||||||
await _tvDbClientManager.GetImagesAsync(tvdbId, imageQuery, cancellationToken);
|
await _tvDbClientManager.GetImagesAsync(tvdbId, imageQuery, language, cancellationToken);
|
||||||
|
|
||||||
remoteImages.AddRange(GetImages(imageResults.Data, language));
|
remoteImages.AddRange(GetImages(imageResults.Data, language));
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,17 +39,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
_tvDbClientManager = TvDbClientManager.Instance;
|
_tvDbClientManager = TvDbClientManager.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string NormalizeLanguage(string language)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(language))
|
|
||||||
{
|
|
||||||
return language;
|
|
||||||
}
|
|
||||||
|
|
||||||
// pt-br is just pt to tvdb
|
|
||||||
return language.Split('-')[0].ToLowerInvariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken)
|
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (IsValidSeries(searchInfo.ProviderIds))
|
if (IsValidSeries(searchInfo.ProviderIds))
|
||||||
|
@ -103,7 +92,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
|
|
||||||
private async Task FetchSeriesData(MetadataResult<Series> result, string metadataLanguage, Dictionary<string, string> seriesProviderIds, CancellationToken cancellationToken)
|
private async Task FetchSeriesData(MetadataResult<Series> result, string metadataLanguage, Dictionary<string, string> seriesProviderIds, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
_tvDbClientManager.TvDbClient.AcceptedLanguage = NormalizeLanguage(metadataLanguage);
|
|
||||||
var series = result.Item;
|
var series = result.Item;
|
||||||
|
|
||||||
if (seriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(), out var tvdbId) && !string.IsNullOrEmpty(tvdbId))
|
if (seriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(), out var tvdbId) && !string.IsNullOrEmpty(tvdbId))
|
||||||
|
@ -126,8 +114,8 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var seriesResult =
|
var seriesResult =
|
||||||
await _tvDbClientManager.GetSeriesByIdAsync(Convert.ToInt32(tvdbId), cancellationToken);
|
await _tvDbClientManager.GetSeriesByIdAsync(Convert.ToInt32(tvdbId), metadataLanguage, cancellationToken);
|
||||||
MapSeriesToResult(result, seriesResult.Data);
|
MapSeriesToResult(result, seriesResult.Data, metadataLanguage);
|
||||||
}
|
}
|
||||||
catch (TvDbServerException e)
|
catch (TvDbServerException e)
|
||||||
{
|
{
|
||||||
|
@ -141,7 +129,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var actorsResult = await _tvDbClientManager.GetActorsAsync(Convert.ToInt32(tvdbId), cancellationToken);
|
var actorsResult = await _tvDbClientManager.GetActorsAsync(Convert.ToInt32(tvdbId), metadataLanguage, cancellationToken);
|
||||||
MapActorsToResult(result, actorsResult.Data);
|
MapActorsToResult(result, actorsResult.Data);
|
||||||
}
|
}
|
||||||
catch (TvDbServerException e)
|
catch (TvDbServerException e)
|
||||||
|
@ -152,18 +140,17 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
|
|
||||||
private async Task<string> GetSeriesByRemoteId(string id, string idType, string language, CancellationToken cancellationToken)
|
private async Task<string> GetSeriesByRemoteId(string id, string idType, string language, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
_tvDbClientManager.TvDbClient.AcceptedLanguage = NormalizeLanguage(language);
|
|
||||||
TvDbResponse<SeriesSearchResult[]> result = null;
|
TvDbResponse<SeriesSearchResult[]> result = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (string.Equals(idType, MetadataProviders.Zap2It.ToString(), StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(idType, MetadataProviders.Zap2It.ToString(), StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
result = await _tvDbClientManager.GetSeriesByZap2ItIdAsync(id, cancellationToken);
|
result = await _tvDbClientManager.GetSeriesByZap2ItIdAsync(id, language, cancellationToken);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = await _tvDbClientManager.GetSeriesByImdbIdAsync(id, cancellationToken);
|
result = await _tvDbClientManager.GetSeriesByImdbIdAsync(id, language, cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (TvDbServerException e)
|
catch (TvDbServerException e)
|
||||||
|
@ -218,13 +205,12 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
|
|
||||||
private async Task<List<RemoteSearchResult>> FindSeriesInternal(string name, string language, CancellationToken cancellationToken)
|
private async Task<List<RemoteSearchResult>> FindSeriesInternal(string name, string language, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
_tvDbClientManager.TvDbClient.AcceptedLanguage = NormalizeLanguage(language);
|
|
||||||
var comparableName = GetComparableName(name);
|
var comparableName = GetComparableName(name);
|
||||||
var list = new List<Tuple<List<string>, RemoteSearchResult>>();
|
var list = new List<Tuple<List<string>, RemoteSearchResult>>();
|
||||||
TvDbResponse<SeriesSearchResult[]> result;
|
TvDbResponse<SeriesSearchResult[]> result;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result = await _tvDbClientManager.GetSeriesByNameAsync(comparableName, cancellationToken);
|
result = await _tvDbClientManager.GetSeriesByNameAsync(comparableName, language, cancellationToken);
|
||||||
}
|
}
|
||||||
catch (TvDbServerException e)
|
catch (TvDbServerException e)
|
||||||
{
|
{
|
||||||
|
@ -252,7 +238,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var seriesSesult =
|
var seriesSesult =
|
||||||
await _tvDbClientManager.GetSeriesByIdAsync(seriesSearchResult.Id, cancellationToken);
|
await _tvDbClientManager.GetSeriesByIdAsync(seriesSearchResult.Id, language, cancellationToken);
|
||||||
remoteSearchResult.SetProviderId(MetadataProviders.Imdb, seriesSesult.Data.ImdbId);
|
remoteSearchResult.SetProviderId(MetadataProviders.Imdb, seriesSesult.Data.ImdbId);
|
||||||
remoteSearchResult.SetProviderId(MetadataProviders.Zap2It, seriesSesult.Data.Zap2itId);
|
remoteSearchResult.SetProviderId(MetadataProviders.Zap2It, seriesSesult.Data.Zap2itId);
|
||||||
}
|
}
|
||||||
|
@ -329,7 +315,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
return name.Trim();
|
return name.Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MapSeriesToResult(MetadataResult<Series> result, TvDbSharper.Dto.Series tvdbSeries)
|
private void MapSeriesToResult(MetadataResult<Series> result, TvDbSharper.Dto.Series tvdbSeries, string metadataLanguage)
|
||||||
{
|
{
|
||||||
Series series = result.Item;
|
Series series = result.Item;
|
||||||
series.SetProviderId(MetadataProviders.Tvdb, tvdbSeries.Id.ToString());
|
series.SetProviderId(MetadataProviders.Tvdb, tvdbSeries.Id.ToString());
|
||||||
|
@ -367,14 +353,14 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var episodeSummary = _tvDbClientManager
|
var episodeSummary = _tvDbClientManager
|
||||||
.GetSeriesEpisodeSummaryAsync(tvdbSeries.Id, CancellationToken.None).Result.Data;
|
.GetSeriesEpisodeSummaryAsync(tvdbSeries.Id, metadataLanguage, CancellationToken.None).Result.Data;
|
||||||
var maxSeasonNumber = episodeSummary.AiredSeasons.Select(s => Convert.ToInt32(s)).Max();
|
var maxSeasonNumber = episodeSummary.AiredSeasons.Select(s => Convert.ToInt32(s)).Max();
|
||||||
var episodeQuery = new EpisodeQuery
|
var episodeQuery = new EpisodeQuery
|
||||||
{
|
{
|
||||||
AiredSeason = maxSeasonNumber
|
AiredSeason = maxSeasonNumber
|
||||||
};
|
};
|
||||||
var episodesPage =
|
var episodesPage =
|
||||||
_tvDbClientManager.GetEpisodesPageAsync(tvdbSeries.Id, episodeQuery, CancellationToken.None).Result.Data;
|
_tvDbClientManager.GetEpisodesPageAsync(tvdbSeries.Id, episodeQuery, metadataLanguage, CancellationToken.None).Result.Data;
|
||||||
result.Item.EndDate = episodesPage.Select(e =>
|
result.Item.EndDate = episodesPage.Select(e =>
|
||||||
{
|
{
|
||||||
DateTime.TryParse(e.FirstAired, out var firstAired);
|
DateTime.TryParse(e.FirstAired, out var firstAired);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user