mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Fix up collection searching in MovieDbProvider.cs
This commit is contained in:
parent
055515d221
commit
58afe5dd41
@ -180,7 +180,7 @@ namespace MediaBrowser.Providers.Movies
|
|||||||
}
|
}
|
||||||
|
|
||||||
private const string TmdbConfigUrl = "http://api.themoviedb.org/3/configuration?api_key={0}";
|
private const string TmdbConfigUrl = "http://api.themoviedb.org/3/configuration?api_key={0}";
|
||||||
private const string Search3 = @"http://api.themoviedb.org/3/search/movie?api_key={1}&query={0}&language={2}";
|
private const string Search3 = @"http://api.themoviedb.org/3/search/{3}?api_key={1}&query={0}&language={2}";
|
||||||
private const string GetMovieInfo3 = @"http://api.themoviedb.org/3/movie/{0}?api_key={1}&language={2}&append_to_response=casts,releases,images,keywords,trailers";
|
private const string GetMovieInfo3 = @"http://api.themoviedb.org/3/movie/{0}?api_key={1}&language={2}&append_to_response=casts,releases,images,keywords,trailers";
|
||||||
private const string GetBoxSetInfo3 = @"http://api.themoviedb.org/3/collection/{0}?api_key={1}&language={2}&append_to_response=images";
|
private const string GetBoxSetInfo3 = @"http://api.themoviedb.org/3/collection/{0}?api_key={1}&language={2}&append_to_response=images";
|
||||||
|
|
||||||
@ -311,7 +311,7 @@ namespace MediaBrowser.Providers.Movies
|
|||||||
|
|
||||||
var year = item.ProductionYear ?? yearInName;
|
var year = item.ProductionYear ?? yearInName;
|
||||||
|
|
||||||
Logger.Info("MovieDbProvider: Finding id for movie: " + name);
|
Logger.Info("MovieDbProvider: Finding id for item: " + name);
|
||||||
string language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
|
string language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
|
||||||
|
|
||||||
//if we are a boxset - look at our first child
|
//if we are a boxset - look at our first child
|
||||||
@ -319,19 +319,23 @@ namespace MediaBrowser.Providers.Movies
|
|||||||
if (boxset != null)
|
if (boxset != null)
|
||||||
{
|
{
|
||||||
// See if any movies have a collection id already
|
// See if any movies have a collection id already
|
||||||
return boxset.Children.Concat(boxset.GetLinkedChildren()).OfType<Video>()
|
var collId = boxset.Children.Concat(boxset.GetLinkedChildren()).OfType<Video>()
|
||||||
.Select(i => i.GetProviderId(MetadataProviders.TmdbCollection))
|
.Select(i => i.GetProviderId(MetadataProviders.TmdbCollection))
|
||||||
.FirstOrDefault(i => i != null);
|
.FirstOrDefault(i => i != null);
|
||||||
|
|
||||||
|
if (collId != null) return collId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//nope - search for it
|
//nope - search for it
|
||||||
var id = await AttemptFindId(name, year, language, cancellationToken).ConfigureAwait(false);
|
var searchType = item is BoxSet ? "collection" : "movie";
|
||||||
|
var id = await AttemptFindId(name, searchType, year, language, cancellationToken).ConfigureAwait(false);
|
||||||
if (id == null)
|
if (id == null)
|
||||||
{
|
{
|
||||||
//try in english if wasn't before
|
//try in english if wasn't before
|
||||||
if (language != "en")
|
if (language != "en")
|
||||||
{
|
{
|
||||||
id = await AttemptFindId(name, year, "en", cancellationToken).ConfigureAwait(false);
|
id = await AttemptFindId(name, searchType, year, "en", cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -346,12 +350,12 @@ namespace MediaBrowser.Providers.Movies
|
|||||||
// Search again if the new name is different
|
// Search again if the new name is different
|
||||||
if (!string.Equals(name, originalName))
|
if (!string.Equals(name, originalName))
|
||||||
{
|
{
|
||||||
id = await AttemptFindId(name, year, language, cancellationToken).ConfigureAwait(false);
|
id = await AttemptFindId(name, searchType, year, language, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
if (id == null && language != "en")
|
if (id == null && language != "en")
|
||||||
{
|
{
|
||||||
//one more time, in english
|
//one more time, in english
|
||||||
id = await AttemptFindId(name, year, "en", cancellationToken).ConfigureAwait(false);
|
id = await AttemptFindId(name, searchType, year, "en", cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -365,7 +369,7 @@ namespace MediaBrowser.Providers.Movies
|
|||||||
if (!string.Equals(pathName, name, StringComparison.OrdinalIgnoreCase)
|
if (!string.Equals(pathName, name, StringComparison.OrdinalIgnoreCase)
|
||||||
&& !string.Equals(pathName, originalName, StringComparison.OrdinalIgnoreCase))
|
&& !string.Equals(pathName, originalName, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
id = await AttemptFindId(pathName, year, "en", cancellationToken).ConfigureAwait(false);
|
id = await AttemptFindId(pathName, searchType, year, "en", cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -378,13 +382,14 @@ namespace MediaBrowser.Providers.Movies
|
|||||||
/// Attempts the find id.
|
/// Attempts the find id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
|
/// <param name="type">movie or collection</param>
|
||||||
/// <param name="year">The year.</param>
|
/// <param name="year">The year.</param>
|
||||||
/// <param name="language">The language.</param>
|
/// <param name="language">The language.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token</param>
|
/// <param name="cancellationToken">The cancellation token</param>
|
||||||
/// <returns>Task{System.String}.</returns>
|
/// <returns>Task{System.String}.</returns>
|
||||||
private async Task<string> AttemptFindId(string name, int? year, string language, CancellationToken cancellationToken)
|
private async Task<string> AttemptFindId(string name, string type, int? year, string language, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
string url3 = string.Format(Search3, UrlEncode(name), ApiKey, language);
|
string url3 = string.Format(Search3, UrlEncode(name), ApiKey, language, type);
|
||||||
TmdbMovieSearchResults searchResult = null;
|
TmdbMovieSearchResults searchResult = null;
|
||||||
|
|
||||||
using (Stream json = await GetMovieDbResponse(new HttpRequestOptions
|
using (Stream json = await GetMovieDbResponse(new HttpRequestOptions
|
||||||
@ -402,7 +407,7 @@ namespace MediaBrowser.Providers.Movies
|
|||||||
{
|
{
|
||||||
foreach (var possible in searchResult.results)
|
foreach (var possible in searchResult.results)
|
||||||
{
|
{
|
||||||
string matchedName = possible.title;
|
string matchedName = possible.title ?? possible.name;
|
||||||
string id = possible.id.ToString(CultureInfo.InvariantCulture);
|
string id = possible.id.ToString(CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
if (matchedName != null)
|
if (matchedName != null)
|
||||||
@ -442,45 +447,6 @@ namespace MediaBrowser.Providers.Movies
|
|||||||
return WebUtility.UrlEncode(name);
|
return WebUtility.UrlEncode(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the boxset id from movie.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The name.</param>
|
|
||||||
/// <param name="year">The year.</param>
|
|
||||||
/// <param name="language">The language.</param>
|
|
||||||
/// <param name="cancellationToken">The cancellation token</param>
|
|
||||||
/// <returns>Task{System.String}.</returns>
|
|
||||||
protected async Task<string> GetBoxsetIdFromMovie(string name, int? year, string language, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
string id = null;
|
|
||||||
string childId = await AttemptFindId(name, year, language, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (childId != null)
|
|
||||||
{
|
|
||||||
string url = string.Format(GetMovieInfo3, childId, ApiKey, language);
|
|
||||||
|
|
||||||
using (Stream json = await GetMovieDbResponse(new HttpRequestOptions
|
|
||||||
{
|
|
||||||
Url = url,
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
AcceptHeader = AcceptHeader
|
|
||||||
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
var movieResult = JsonSerializer.DeserializeFromStream<CompleteMovieData>(json);
|
|
||||||
|
|
||||||
if (movieResult != null && movieResult.belongs_to_collection != null)
|
|
||||||
{
|
|
||||||
id = movieResult.belongs_to_collection.id.ToString(CultureInfo.InvariantCulture);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Logger.Error("Unable to obtain boxset id.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fetches the movie data.
|
/// Fetches the movie data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -861,6 +827,10 @@ namespace MediaBrowser.Providers.Movies
|
|||||||
/// <value>The vote_average.</value>
|
/// <value>The vote_average.</value>
|
||||||
public double vote_average { get; set; }
|
public double vote_average { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// For collection search results
|
||||||
|
/// </summary>
|
||||||
|
public string name { get; set; }
|
||||||
|
/// <summary>
|
||||||
/// Gets or sets the vote_count.
|
/// Gets or sets the vote_count.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The vote_count.</value>
|
/// <value>The vote_count.</value>
|
||||||
|
@ -237,7 +237,4 @@ Global
|
|||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(Performance) = preSolution
|
|
||||||
HasPerformanceSessions = true
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
Loading…
x
Reference in New Issue
Block a user