Minor improvements to tmdb code

pull/4286/head
Bond-009 4 years ago
parent 3a238de35e
commit 6def4b06a8

@ -67,17 +67,17 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
.GetEpisodeAsync(seriesTmdbId, seasonNumber.Value, episodeNumber.Value, language, TmdbUtils.GetImageLanguagesParam(language), cancellationToken) .GetEpisodeAsync(seriesTmdbId, seasonNumber.Value, episodeNumber.Value, language, TmdbUtils.GetImageLanguagesParam(language), cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
if (episodeResult?.Images?.Stills == null) var stills = episodeResult?.Images?.Stills;
if (stills == null)
{ {
return Enumerable.Empty<RemoteImageInfo>(); return Enumerable.Empty<RemoteImageInfo>();
} }
var remoteImages = new List<RemoteImageInfo>(); var remoteImages = new RemoteImageInfo[stills.Count];
for (var i = 0; i < stills.Count; i++)
for (var i = 0; i < episodeResult.Images.Stills.Count; i++)
{ {
var image = episodeResult.Images.Stills[i]; var image = stills[i];
remoteImages.Add(new RemoteImageInfo remoteImages[i] = new RemoteImageInfo
{ {
Url = _tmdbClientManager.GetStillUrl(image.FilePath), Url = _tmdbClientManager.GetStillUrl(image.FilePath),
CommunityRating = image.VoteAverage, CommunityRating = image.VoteAverage,
@ -88,7 +88,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
ProviderName = Name, ProviderName = Name,
Type = ImageType.Primary, Type = ImageType.Primary,
RatingType = RatingType.Score RatingType = RatingType.Score
}); };
} }
return remoteImages.OrderByLanguageDescending(language); return remoteImages.OrderByLanguageDescending(language);

@ -40,18 +40,18 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
return Enumerable.Empty<RemoteSearchResult>(); return Enumerable.Empty<RemoteSearchResult>();
} }
var metadataResult = await GetMetadata(searchInfo, cancellationToken); var metadataResult = await GetMetadata(searchInfo, cancellationToken).ConfigureAwait(false);
if (!metadataResult.HasMetadata) if (!metadataResult.HasMetadata)
{ {
return Enumerable.Empty<RemoteSearchResult>(); return Enumerable.Empty<RemoteSearchResult>();
} }
var list = new List<RemoteSearchResult>();
var item = metadataResult.Item; var item = metadataResult.Item;
list.Add(new RemoteSearchResult return new[]
{
new RemoteSearchResult
{ {
IndexNumber = item.IndexNumber, IndexNumber = item.IndexNumber,
Name = item.Name, Name = item.Name,
@ -61,9 +61,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
ProviderIds = item.ProviderIds, ProviderIds = item.ProviderIds,
SearchProviderName = Name, SearchProviderName = Name,
IndexNumberEnd = item.IndexNumberEnd IndexNumberEnd = item.IndexNumberEnd
}); }
};
return list;
} }
public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo info, CancellationToken cancellationToken) public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo info, CancellationToken cancellationToken)
@ -137,8 +136,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
{ {
if (TmdbUtils.IsTrailerType(video)) if (TmdbUtils.IsTrailerType(video))
{ {
var videoUrl = string.Format(CultureInfo.InvariantCulture, "http://www.youtube.com/watch?v={0}", video.Key); item.AddTrailerUrl("https://www.youtube.com/watch?v=" + video.Key);
item.AddTrailerUrl(videoUrl);
} }
} }
} }

@ -56,16 +56,17 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
.GetSeasonAsync(seriesTmdbId, season.IndexNumber.Value, language, TmdbUtils.GetImageLanguagesParam(language), cancellationToken) .GetSeasonAsync(seriesTmdbId, season.IndexNumber.Value, language, TmdbUtils.GetImageLanguagesParam(language), cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
if (seasonResult?.Images?.Posters == null) var posters = seasonResult?.Images?.Posters;
if (posters == null)
{ {
return Enumerable.Empty<RemoteImageInfo>(); return Enumerable.Empty<RemoteImageInfo>();
} }
var remoteImages = new List<RemoteImageInfo>(); var remoteImages = new RemoteImageInfo[posters.Count];
for (var i = 0; i < seasonResult.Images.Posters.Count; i++) for (var i = 0; i < posters.Count; i++)
{ {
var image = seasonResult.Images.Posters[i]; var image = posters[i];
remoteImages.Add(new RemoteImageInfo remoteImages[i] = new RemoteImageInfo
{ {
Url = _tmdbClientManager.GetPosterUrl(image.FilePath), Url = _tmdbClientManager.GetPosterUrl(image.FilePath),
CommunityRating = image.VoteAverage, CommunityRating = image.VoteAverage,
@ -76,7 +77,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
ProviderName = Name, ProviderName = Name,
Type = ImageType.Primary, Type = ImageType.Primary,
RatingType = RatingType.Score RatingType = RatingType.Score
}); };
} }
return remoteImages.OrderByLanguageDescending(language); return remoteImages.OrderByLanguageDescending(language);

@ -68,12 +68,15 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
return Enumerable.Empty<RemoteImageInfo>(); return Enumerable.Empty<RemoteImageInfo>();
} }
var remoteImages = new List<RemoteImageInfo>(); var posters = series.Images.Posters;
var backdrops = series.Images.Backdrops;
for (var i = 0; i < series.Images.Posters.Count; i++) var remoteImages = new RemoteImageInfo[posters.Count + backdrops.Count];
for (var i = 0; i < posters.Count; i++)
{ {
var poster = series.Images.Posters[i]; var poster = posters[i];
remoteImages.Add(new RemoteImageInfo remoteImages[i] = new RemoteImageInfo
{ {
Url = _tmdbClientManager.GetPosterUrl(poster.FilePath), Url = _tmdbClientManager.GetPosterUrl(poster.FilePath),
CommunityRating = poster.VoteAverage, CommunityRating = poster.VoteAverage,
@ -84,13 +87,13 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
ProviderName = Name, ProviderName = Name,
Type = ImageType.Primary, Type = ImageType.Primary,
RatingType = RatingType.Score RatingType = RatingType.Score
}); };
} }
for (var i = 0; i < series.Images.Backdrops.Count; i++) for (var i = 0; i < backdrops.Count; i++)
{ {
var backdrop = series.Images.Backdrops[i]; var backdrop = series.Images.Backdrops[i];
remoteImages.Add(new RemoteImageInfo remoteImages[posters.Count + i] = new RemoteImageInfo
{ {
Url = _tmdbClientManager.GetBackdropUrl(backdrop.FilePath), Url = _tmdbClientManager.GetBackdropUrl(backdrop.FilePath),
CommunityRating = backdrop.VoteAverage, CommunityRating = backdrop.VoteAverage,
@ -100,7 +103,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
ProviderName = Name, ProviderName = Name,
Type = ImageType.Backdrop, Type = ImageType.Backdrop,
RatingType = RatingType.Score RatingType = RatingType.Score
}); };
} }
return remoteImages.OrderByLanguageDescending(language); return remoteImages.OrderByLanguageDescending(language);

@ -66,14 +66,15 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
.FindByExternalIdAsync(imdbId, FindExternalSource.Imdb, searchInfo.MetadataLanguage, cancellationToken) .FindByExternalIdAsync(imdbId, FindExternalSource.Imdb, searchInfo.MetadataLanguage, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
if (findResult?.TvResults != null) var tvResults = findResult?.TvResults;
if (tvResults != null)
{ {
var imdbIdResults = new List<RemoteSearchResult>(); var imdbIdResults = new RemoteSearchResult[tvResults.Count];
for (var i = 0; i < findResult.TvResults.Count; i++) for (var i = 0; i < tvResults.Count; i++)
{ {
var remoteResult = MapSearchTvToRemoteSearchResult(findResult.TvResults[i]); var remoteResult = MapSearchTvToRemoteSearchResult(tvResults[i]);
remoteResult.SetProviderId(MetadataProvider.Imdb, imdbId); remoteResult.SetProviderId(MetadataProvider.Imdb, imdbId);
imdbIdResults.Add(remoteResult); imdbIdResults[i] = remoteResult;
} }
return imdbIdResults; return imdbIdResults;
@ -88,14 +89,15 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
.FindByExternalIdAsync(tvdbId, FindExternalSource.TvDb, searchInfo.MetadataLanguage, cancellationToken) .FindByExternalIdAsync(tvdbId, FindExternalSource.TvDb, searchInfo.MetadataLanguage, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
if (findResult?.TvResults != null) var tvResults = findResult?.TvResults;
if (tvResults != null)
{ {
var tvIdResults = new List<RemoteSearchResult>(); var tvIdResults = new RemoteSearchResult[tvResults.Count];
for (var i = 0; i < findResult.TvResults.Count; i++) for (var i = 0; i < tvResults.Count; i++)
{ {
var remoteResult = MapSearchTvToRemoteSearchResult(findResult.TvResults[i]); var remoteResult = MapSearchTvToRemoteSearchResult(tvResults[i]);
remoteResult.SetProviderId(MetadataProvider.Tvdb, tvdbId); remoteResult.SetProviderId(MetadataProvider.Tvdb, tvdbId);
tvIdResults.Add(remoteResult); tvIdResults[i] = remoteResult;
} }
return tvIdResults; return tvIdResults;
@ -105,10 +107,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
var tvSearchResults = await _tmdbClientManager.SearchSeriesAsync(searchInfo.Name, searchInfo.MetadataLanguage, cancellationToken) var tvSearchResults = await _tmdbClientManager.SearchSeriesAsync(searchInfo.Name, searchInfo.MetadataLanguage, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
var remoteResults = new List<RemoteSearchResult>(); var remoteResults = new RemoteSearchResult[tvSearchResults.Count];
for (var i = 0; i < tvSearchResults.Count; i++) for (var i = 0; i < tvSearchResults.Count; i++)
{ {
remoteResults.Add(MapSearchTvToRemoteSearchResult(tvSearchResults[i])); remoteResults[i] = MapSearchTvToRemoteSearchResult(tvSearchResults[i]);
} }
return remoteResults; return remoteResults;
@ -236,7 +238,11 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
private Series MapTvShowToSeries(TvShow seriesResult, string preferredCountryCode) private Series MapTvShowToSeries(TvShow seriesResult, string preferredCountryCode)
{ {
var series = new Series {Name = seriesResult.Name, OriginalTitle = seriesResult.OriginalName}; var series = new Series
{
Name = seriesResult.Name,
OriginalTitle = seriesResult.OriginalName
};
series.SetProviderId(MetadataProvider.Tmdb, seriesResult.Id.ToString(CultureInfo.InvariantCulture)); series.SetProviderId(MetadataProvider.Tmdb, seriesResult.Id.ToString(CultureInfo.InvariantCulture));
@ -322,7 +328,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
{ {
if (TmdbUtils.IsTrailerType(video)) if (TmdbUtils.IsTrailerType(video))
{ {
series.AddTrailerUrl($"http://www.youtube.com/watch?v={video.Key}"); series.AddTrailerUrl("https://www.youtube.com/watch?v=" + video.Key);
} }
} }
} }

Loading…
Cancel
Save