Fix TMDb search name containing year (#5349)

pull/5359/head
David Ullmer 4 years ago committed by GitHub
parent e858e5f0b8
commit 8f99bdd07c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -111,10 +111,14 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
var item = new Episode var item = new Episode
{ {
Name = info.Name,
IndexNumber = info.IndexNumber, IndexNumber = info.IndexNumber,
ParentIndexNumber = info.ParentIndexNumber, ParentIndexNumber = info.ParentIndexNumber,
IndexNumberEnd = info.IndexNumberEnd IndexNumberEnd = info.IndexNumberEnd,
Name = episodeResult.Name,
PremiereDate = episodeResult.AirDate,
ProductionYear = episodeResult.AirDate?.Year,
Overview = episodeResult.Overview,
CommunityRating = Convert.ToSingle(episodeResult.VoteAverage)
}; };
if (!string.IsNullOrEmpty(episodeResult.ExternalIds?.TvdbId)) if (!string.IsNullOrEmpty(episodeResult.ExternalIds?.TvdbId))
@ -122,14 +126,6 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
item.SetProviderId(MetadataProvider.Tvdb, episodeResult.ExternalIds.TvdbId); item.SetProviderId(MetadataProvider.Tvdb, episodeResult.ExternalIds.TvdbId);
} }
item.PremiereDate = episodeResult.AirDate;
item.ProductionYear = episodeResult.AirDate?.Year;
item.Name = episodeResult.Name;
item.Overview = episodeResult.Overview;
item.CommunityRating = Convert.ToSingle(episodeResult.VoteAverage);
if (episodeResult.Videos?.Results != null) if (episodeResult.Videos?.Results != null)
{ {
foreach (var video in episodeResult.Videos.Results) foreach (var video in episodeResult.Videos.Results)

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers; using MediaBrowser.Model.Providers;
@ -22,15 +23,17 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
public class TmdbSeriesProvider : IRemoteMetadataProvider<Series, SeriesInfo>, IHasOrder public class TmdbSeriesProvider : IRemoteMetadataProvider<Series, SeriesInfo>, IHasOrder
{ {
private readonly IHttpClientFactory _httpClientFactory; private readonly IHttpClientFactory _httpClientFactory;
private readonly ILibraryManager _libraryManager;
private readonly TmdbClientManager _tmdbClientManager; private readonly TmdbClientManager _tmdbClientManager;
public TmdbSeriesProvider( public TmdbSeriesProvider(
ILibraryManager libraryManager,
IHttpClientFactory httpClientFactory, IHttpClientFactory httpClientFactory,
TmdbClientManager tmdbClientManager) TmdbClientManager tmdbClientManager)
{ {
_libraryManager = libraryManager;
_httpClientFactory = httpClientFactory; _httpClientFactory = httpClientFactory;
_tmdbClientManager = tmdbClientManager; _tmdbClientManager = tmdbClientManager;
Current = this;
} }
public string Name => TmdbUtils.ProviderName; public string Name => TmdbUtils.ProviderName;
@ -38,8 +41,6 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
// After TheTVDB // After TheTVDB
public int Order => 1; public int Order => 1;
internal static TmdbSeriesProvider Current { get; private set; }
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken) public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken)
{ {
var tmdbId = searchInfo.GetProviderId(MetadataProvider.Tmdb); var tmdbId = searchInfo.GetProviderId(MetadataProvider.Tmdb);
@ -104,7 +105,7 @@ 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: cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
var remoteResults = new RemoteSearchResult[tvSearchResults.Count]; var remoteResults = new RemoteSearchResult[tvSearchResults.Count];
@ -203,7 +204,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
if (string.IsNullOrEmpty(tmdbId)) if (string.IsNullOrEmpty(tmdbId))
{ {
result.QueriedById = false; result.QueriedById = false;
var searchResults = await _tmdbClientManager.SearchSeriesAsync(info.Name, info.MetadataLanguage, cancellationToken).ConfigureAwait(false); // ParseName is required here.
// Caller provides the filename with extension stripped and NOT the parsed filename
var parsedName = _libraryManager.ParseName(info.Name);
var searchResults = await _tmdbClientManager.SearchSeriesAsync(parsedName.Name, info.MetadataLanguage, info.Year ?? 0, cancellationToken).ConfigureAwait(false);
if (searchResults.Count > 0) if (searchResults.Count > 0)
{ {

@ -278,9 +278,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// </summary> /// </summary>
/// <param name="name">The name of the tv show.</param> /// <param name="name">The name of the tv show.</param>
/// <param name="language">The tv show's language.</param> /// <param name="language">The tv show's language.</param>
/// <param name="year">The year the tv show first aired.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The TMDb tv show information.</returns> /// <returns>The TMDb tv show information.</returns>
public async Task<IReadOnlyList<SearchTv>> SearchSeriesAsync(string name, string language, CancellationToken cancellationToken) public async Task<IReadOnlyList<SearchTv>> SearchSeriesAsync(string name, string language, int year = 0, CancellationToken cancellationToken = default)
{ {
var key = $"searchseries-{name}-{language}"; var key = $"searchseries-{name}-{language}";
if (_memoryCache.TryGetValue(key, out SearchContainer<SearchTv> series)) if (_memoryCache.TryGetValue(key, out SearchContainer<SearchTv> series))
@ -291,7 +292,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
await EnsureClientConfigAsync().ConfigureAwait(false); await EnsureClientConfigAsync().ConfigureAwait(false);
var searchResults = await _tmDbClient var searchResults = await _tmDbClient
.SearchTvShowAsync(name, TmdbUtils.NormalizeLanguage(language), cancellationToken: cancellationToken) .SearchTvShowAsync(name, TmdbUtils.NormalizeLanguage(language), firstAirDateYear: year, cancellationToken: cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
if (searchResults.Results.Count > 0) if (searchResults.Results.Count > 0)

Loading…
Cancel
Save