|
|
@ -7,6 +7,8 @@ using System.Linq;
|
|
|
|
using System.Net.Http;
|
|
|
|
using System.Net.Http;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using TMDbLib.Objects.Find;
|
|
|
|
|
|
|
|
using TMDbLib.Objects.Search;
|
|
|
|
using MediaBrowser.Common.Net;
|
|
|
|
using MediaBrowser.Common.Net;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
@ -43,64 +45,89 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken)
|
|
|
|
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var tmdbId = Convert.ToInt32(searchInfo.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);
|
|
|
|
if (searchInfo.TryGetProviderId(MetadataProvider.Tmdb, out var id))
|
|
|
|
|
|
|
|
|
|
|
|
if (tmdbId == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var movieResults = await _tmdbClientManager
|
|
|
|
var movie = await _tmdbClientManager
|
|
|
|
.SearchMovieAsync(searchInfo.Name, searchInfo.Year ?? 0, searchInfo.MetadataLanguage, cancellationToken)
|
|
|
|
.GetMovieAsync(
|
|
|
|
|
|
|
|
int.Parse(id, CultureInfo.InvariantCulture),
|
|
|
|
|
|
|
|
searchInfo.MetadataLanguage,
|
|
|
|
|
|
|
|
TmdbUtils.GetImageLanguagesParam(searchInfo.MetadataLanguage),
|
|
|
|
|
|
|
|
cancellationToken)
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
var remoteSearchResults = new List<RemoteSearchResult>();
|
|
|
|
var remoteResult = new RemoteSearchResult
|
|
|
|
for (var i = 0; i < movieResults.Count; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var movieResult = movieResults[i];
|
|
|
|
Name = movie.Title ?? movie.OriginalTitle,
|
|
|
|
var remoteSearchResult = new RemoteSearchResult
|
|
|
|
SearchProviderName = Name,
|
|
|
|
{
|
|
|
|
ImageUrl = _tmdbClientManager.GetPosterUrl(movie.PosterPath),
|
|
|
|
Name = movieResult.Title ?? movieResult.OriginalTitle,
|
|
|
|
Overview = movie.Overview
|
|
|
|
ImageUrl = _tmdbClientManager.GetPosterUrl(movieResult.PosterPath),
|
|
|
|
};
|
|
|
|
Overview = movieResult.Overview,
|
|
|
|
|
|
|
|
SearchProviderName = Name
|
|
|
|
if (movie.ReleaseDate != null)
|
|
|
|
};
|
|
|
|
{
|
|
|
|
|
|
|
|
var releaseDate = movie.ReleaseDate.Value.ToUniversalTime();
|
|
|
|
|
|
|
|
remoteResult.PremiereDate = releaseDate;
|
|
|
|
|
|
|
|
remoteResult.ProductionYear = releaseDate.Year;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var releaseDate = movieResult.ReleaseDate?.ToUniversalTime();
|
|
|
|
remoteResult.SetProviderId(MetadataProvider.Tmdb, movie.Id.ToString(CultureInfo.InvariantCulture));
|
|
|
|
remoteSearchResult.PremiereDate = releaseDate;
|
|
|
|
|
|
|
|
remoteSearchResult.ProductionYear = releaseDate?.Year;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
remoteSearchResult.SetProviderId(MetadataProvider.Tmdb, movieResult.Id.ToString(CultureInfo.InvariantCulture));
|
|
|
|
if (!string.IsNullOrWhiteSpace(movie.ImdbId))
|
|
|
|
remoteSearchResults.Add(remoteSearchResult);
|
|
|
|
{
|
|
|
|
|
|
|
|
remoteResult.SetProviderId(MetadataProvider.Imdb, movie.ImdbId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return remoteSearchResults;
|
|
|
|
return new[] { remoteResult };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var movie = await _tmdbClientManager
|
|
|
|
IReadOnlyList<SearchMovie> movieResults;
|
|
|
|
.GetMovieAsync(tmdbId, searchInfo.MetadataLanguage, TmdbUtils.GetImageLanguagesParam(searchInfo.MetadataLanguage), cancellationToken)
|
|
|
|
if (searchInfo.TryGetProviderId(MetadataProvider.Imdb, out id))
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var remoteResult = new RemoteSearchResult
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name = movie.Title ?? movie.OriginalTitle,
|
|
|
|
var result = await _tmdbClientManager.FindByExternalIdAsync(
|
|
|
|
SearchProviderName = Name,
|
|
|
|
id,
|
|
|
|
ImageUrl = _tmdbClientManager.GetPosterUrl(movie.PosterPath),
|
|
|
|
FindExternalSource.Imdb,
|
|
|
|
Overview = movie.Overview
|
|
|
|
TmdbUtils.GetImageLanguagesParam(searchInfo.MetadataLanguage),
|
|
|
|
};
|
|
|
|
cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
movieResults = result.MovieResults;
|
|
|
|
if (movie.ReleaseDate != null)
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (searchInfo.TryGetProviderId(MetadataProvider.Tvdb, out id))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var releaseDate = movie.ReleaseDate.Value.ToUniversalTime();
|
|
|
|
var result = await _tmdbClientManager.FindByExternalIdAsync(
|
|
|
|
remoteResult.PremiereDate = releaseDate;
|
|
|
|
id,
|
|
|
|
remoteResult.ProductionYear = releaseDate.Year;
|
|
|
|
FindExternalSource.TvDb,
|
|
|
|
|
|
|
|
TmdbUtils.GetImageLanguagesParam(searchInfo.MetadataLanguage),
|
|
|
|
|
|
|
|
cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
movieResults = result.MovieResults;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
movieResults = await _tmdbClientManager
|
|
|
|
|
|
|
|
.SearchMovieAsync(searchInfo.Name, searchInfo.Year ?? 0, searchInfo.MetadataLanguage, cancellationToken)
|
|
|
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
remoteResult.SetProviderId(MetadataProvider.Tmdb, movie.Id.ToString(CultureInfo.InvariantCulture));
|
|
|
|
var len = movieResults.Count;
|
|
|
|
|
|
|
|
var remoteSearchResults = new RemoteSearchResult[len];
|
|
|
|
if (!string.IsNullOrWhiteSpace(movie.ImdbId))
|
|
|
|
for (var i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
remoteResult.SetProviderId(MetadataProvider.Imdb, movie.ImdbId);
|
|
|
|
var movieResult = movieResults[i];
|
|
|
|
|
|
|
|
var remoteSearchResult = new RemoteSearchResult
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Name = movieResult.Title ?? movieResult.OriginalTitle,
|
|
|
|
|
|
|
|
ImageUrl = _tmdbClientManager.GetPosterUrl(movieResult.PosterPath),
|
|
|
|
|
|
|
|
Overview = movieResult.Overview,
|
|
|
|
|
|
|
|
SearchProviderName = Name
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var releaseDate = movieResult.ReleaseDate?.ToUniversalTime();
|
|
|
|
|
|
|
|
remoteSearchResult.PremiereDate = releaseDate;
|
|
|
|
|
|
|
|
remoteSearchResult.ProductionYear = releaseDate?.Year;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
remoteSearchResult.SetProviderId(MetadataProvider.Tmdb, movieResult.Id.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
|
|
|
remoteSearchResults[i] = remoteSearchResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new[] { remoteResult };
|
|
|
|
return remoteSearchResults;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<MetadataResult<Movie>> GetMetadata(MovieInfo info, CancellationToken cancellationToken)
|
|
|
|
public async Task<MetadataResult<Movie>> GetMetadata(MovieInfo info, CancellationToken cancellationToken)
|
|
|
|