Merge pull request #5559 from cvium/fix-tmdb-search-clean
Clean the entity name for non-words before searching
This commit is contained in:
commit
9360fecb31
|
@ -9,6 +9,7 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Controller.Entities.Movies;
|
using MediaBrowser.Controller.Entities.Movies;
|
||||||
|
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;
|
||||||
|
@ -19,11 +20,13 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
|
||||||
{
|
{
|
||||||
private readonly IHttpClientFactory _httpClientFactory;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly TmdbClientManager _tmdbClientManager;
|
private readonly TmdbClientManager _tmdbClientManager;
|
||||||
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
|
||||||
public TmdbBoxSetProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager)
|
public TmdbBoxSetProvider(IHttpClientFactory httpClientFactory, TmdbClientManager tmdbClientManager, ILibraryManager libraryManager)
|
||||||
{
|
{
|
||||||
_httpClientFactory = httpClientFactory;
|
_httpClientFactory = httpClientFactory;
|
||||||
_tmdbClientManager = tmdbClientManager;
|
_tmdbClientManager = tmdbClientManager;
|
||||||
|
_libraryManager = libraryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => TmdbUtils.ProviderName;
|
public string Name => TmdbUtils.ProviderName;
|
||||||
|
@ -83,7 +86,11 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
|
||||||
// We don't already have an Id, need to fetch it
|
// We don't already have an Id, need to fetch it
|
||||||
if (tmdbId <= 0)
|
if (tmdbId <= 0)
|
||||||
{
|
{
|
||||||
var searchResults = await _tmdbClientManager.SearchCollectionAsync(id.Name, language, cancellationToken).ConfigureAwait(false);
|
// ParseName is required here.
|
||||||
|
// Caller provides the filename with extension stripped and NOT the parsed filename
|
||||||
|
var parsedName = _libraryManager.ParseName(id.Name);
|
||||||
|
var cleanedName = TmdbUtils.CleanName(parsedName.Name);
|
||||||
|
var searchResults = await _tmdbClientManager.SearchCollectionAsync(cleanedName, language, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
if (searchResults != null && searchResults.Count > 0)
|
if (searchResults != null && searchResults.Count > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -140,7 +140,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
||||||
// ParseName is required here.
|
// ParseName is required here.
|
||||||
// Caller provides the filename with extension stripped and NOT the parsed filename
|
// Caller provides the filename with extension stripped and NOT the parsed filename
|
||||||
var parsedName = _libraryManager.ParseName(info.Name);
|
var parsedName = _libraryManager.ParseName(info.Name);
|
||||||
var searchResults = await _tmdbClientManager.SearchMovieAsync(parsedName.Name, info.Year ?? parsedName.Year ?? 0, info.MetadataLanguage, cancellationToken).ConfigureAwait(false);
|
var cleanedName = TmdbUtils.CleanName(parsedName.Name);
|
||||||
|
var searchResults = await _tmdbClientManager.SearchMovieAsync(cleanedName, info.Year ?? parsedName.Year ?? 0, info.MetadataLanguage, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
if (searchResults.Count > 0)
|
if (searchResults.Count > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -189,7 +189,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
||||||
// ParseName is required here.
|
// ParseName is required here.
|
||||||
// Caller provides the filename with extension stripped and NOT the parsed filename
|
// Caller provides the filename with extension stripped and NOT the parsed filename
|
||||||
var parsedName = _libraryManager.ParseName(info.Name);
|
var parsedName = _libraryManager.ParseName(info.Name);
|
||||||
var searchResults = await _tmdbClientManager.SearchSeriesAsync(parsedName.Name, info.MetadataLanguage, info.Year ?? parsedName.Year ?? 0, cancellationToken).ConfigureAwait(false);
|
var cleanedName = TmdbUtils.CleanName(parsedName.Name);
|
||||||
|
var searchResults = await _tmdbClientManager.SearchSeriesAsync(cleanedName, info.MetadataLanguage, info.Year ?? parsedName.Year ?? 0, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
if (searchResults.Count > 0)
|
if (searchResults.Count > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using TMDbLib.Objects.General;
|
using TMDbLib.Objects.General;
|
||||||
|
|
||||||
|
@ -12,6 +13,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class TmdbUtils
|
public static class TmdbUtils
|
||||||
{
|
{
|
||||||
|
private static readonly Regex _nonWords = new (@"[\W_]+", RegexOptions.Compiled);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// URL of the TMDB instance to use.
|
/// URL of the TMDB instance to use.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -42,6 +45,17 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
||||||
PersonType.Producer
|
PersonType.Producer
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cleans the name according to TMDb requirements.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name of the entity.</param>
|
||||||
|
/// <returns>The cleaned name.</returns>
|
||||||
|
public static string CleanName(string name)
|
||||||
|
{
|
||||||
|
// TMDb expects a space separated list of words make sure that is the case
|
||||||
|
return _nonWords.Replace(name, " ");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Maps the TMDB provided roles for crew members to Jellyfin roles.
|
/// Maps the TMDB provided roles for crew members to Jellyfin roles.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user