Merge pull request #1214 from softworkz/ProvidersFixSeriesSearch
Remote-Search: Fixed providers to return year information when searching for series
This commit is contained in:
commit
44a5559542
|
@ -125,6 +125,18 @@ namespace MediaBrowser.Providers.Movies
|
||||||
|
|
||||||
private async Task<List<RemoteSearchResult>> GetSearchResults(string name, string type, int? year, string language, string baseImageUrl, CancellationToken cancellationToken)
|
private async Task<List<RemoteSearchResult>> GetSearchResults(string name, string type, int? year, string language, string baseImageUrl, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case "tv":
|
||||||
|
return await GetSearchResultsTv(name, year, language, baseImageUrl, cancellationToken);
|
||||||
|
default:
|
||||||
|
return await GetSearchResultsGeneric(name, type, year, language, baseImageUrl, cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<List<RemoteSearchResult>> GetSearchResultsGeneric(string name, string type, int? year, string language, string baseImageUrl, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
|
||||||
var url3 = string.Format(Search3, WebUtility.UrlEncode(name), ApiKey, language, type);
|
var url3 = string.Format(Search3, WebUtility.UrlEncode(name), ApiKey, language, type);
|
||||||
|
|
||||||
using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
||||||
|
@ -153,7 +165,7 @@ namespace MediaBrowser.Providers.Movies
|
||||||
Name = i.title ?? i.name ?? i.original_title,
|
Name = i.title ?? i.name ?? i.original_title,
|
||||||
ImageUrl = string.IsNullOrWhiteSpace(i.poster_path) ? null : baseImageUrl + i.poster_path
|
ImageUrl = string.IsNullOrWhiteSpace(i.poster_path) ? null : baseImageUrl + i.poster_path
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(i.release_date))
|
if (!string.IsNullOrWhiteSpace(i.release_date))
|
||||||
{
|
{
|
||||||
DateTime r;
|
DateTime r;
|
||||||
|
@ -175,6 +187,58 @@ namespace MediaBrowser.Providers.Movies
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<List<RemoteSearchResult>> GetSearchResultsTv(string name, int? year, string language, string baseImageUrl, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var url3 = string.Format(Search3, WebUtility.UrlEncode(name), ApiKey, language, "tv");
|
||||||
|
|
||||||
|
using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
|
||||||
|
{
|
||||||
|
Url = url3,
|
||||||
|
CancellationToken = cancellationToken,
|
||||||
|
AcceptHeader = AcceptHeader
|
||||||
|
|
||||||
|
}).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
var searchResults = _json.DeserializeFromStream<TmdbTvSearchResults>(json);
|
||||||
|
|
||||||
|
var results = searchResults.results ?? new List<TvResult>();
|
||||||
|
|
||||||
|
var index = 0;
|
||||||
|
var resultTuples = results.Select(result => new Tuple<TvResult, int>(result, index++)).ToList();
|
||||||
|
|
||||||
|
return resultTuples.OrderBy(i => GetSearchResultOrder(i.Item1, year))
|
||||||
|
.ThenBy(i => i.Item2)
|
||||||
|
.Select(i => i.Item1)
|
||||||
|
.Select(i =>
|
||||||
|
{
|
||||||
|
var remoteResult = new RemoteSearchResult
|
||||||
|
{
|
||||||
|
SearchProviderName = MovieDbProvider.Current.Name,
|
||||||
|
Name = i.name ?? i.original_name,
|
||||||
|
ImageUrl = string.IsNullOrWhiteSpace(i.poster_path) ? null : baseImageUrl + i.poster_path
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(i.first_air_date))
|
||||||
|
{
|
||||||
|
DateTime r;
|
||||||
|
|
||||||
|
// These dates are always in this exact format
|
||||||
|
if (DateTime.TryParseExact(i.first_air_date, "yyyy-MM-dd", EnUs, DateTimeStyles.None, out r))
|
||||||
|
{
|
||||||
|
remoteResult.PremiereDate = r.ToUniversalTime();
|
||||||
|
remoteResult.ProductionYear = remoteResult.PremiereDate.Value.Year;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteResult.SetProviderId(MetadataProviders.Tmdb, i.id.ToString(EnUs));
|
||||||
|
|
||||||
|
return remoteResult;
|
||||||
|
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int GetSearchResultOrder(TmdbMovieSearchResult result, int? year)
|
private int GetSearchResultOrder(TmdbMovieSearchResult result, int? year)
|
||||||
{
|
{
|
||||||
if (year.HasValue)
|
if (year.HasValue)
|
||||||
|
@ -192,6 +256,23 @@ namespace MediaBrowser.Providers.Movies
|
||||||
return int.MaxValue;
|
return int.MaxValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int GetSearchResultOrder(TvResult result, int? year)
|
||||||
|
{
|
||||||
|
if (year.HasValue)
|
||||||
|
{
|
||||||
|
DateTime r;
|
||||||
|
|
||||||
|
// These dates are always in this exact format
|
||||||
|
if (DateTime.TryParseExact(result.first_air_date, "yyyy-MM-dd", EnUs, DateTimeStyles.None, out r))
|
||||||
|
{
|
||||||
|
// Allow one year tolernace, preserve order from Tmdb
|
||||||
|
return Math.Abs(r.Year - year.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return int.MaxValue;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Class TmdbMovieSearchResult
|
/// Class TmdbMovieSearchResult
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -288,9 +369,9 @@ namespace MediaBrowser.Providers.Movies
|
||||||
public class TvResult
|
public class TvResult
|
||||||
{
|
{
|
||||||
public string backdrop_path { get; set; }
|
public string backdrop_path { get; set; }
|
||||||
|
public string first_air_date { get; set; }
|
||||||
public int id { get; set; }
|
public int id { get; set; }
|
||||||
public string original_name { get; set; }
|
public string original_name { get; set; }
|
||||||
public string first_air_date { get; set; }
|
|
||||||
public string poster_path { get; set; }
|
public string poster_path { get; set; }
|
||||||
public double popularity { get; set; }
|
public double popularity { get; set; }
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
||||||
|
@ -298,6 +379,33 @@ namespace MediaBrowser.Providers.Movies
|
||||||
public int vote_count { get; set; }
|
public int vote_count { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Class TmdbTvSearchResults
|
||||||
|
/// </summary>
|
||||||
|
private class TmdbTvSearchResults
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the page.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The page.</value>
|
||||||
|
public int page { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the results.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The results.</value>
|
||||||
|
public List<TvResult> results { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the total_pages.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The total_pages.</value>
|
||||||
|
public int total_pages { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the total_results.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The total_results.</value>
|
||||||
|
public int total_results { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class ExternalIdLookupResult
|
public class ExternalIdLookupResult
|
||||||
{
|
{
|
||||||
public List<object> movie_results { get; set; }
|
public List<object> movie_results { get; set; }
|
||||||
|
|
|
@ -133,7 +133,8 @@ namespace MediaBrowser.Providers.Omdb
|
||||||
item.SetProviderId(MetadataProviders.Imdb, result.imdbID);
|
item.SetProviderId(MetadataProviders.Imdb, result.imdbID);
|
||||||
|
|
||||||
int parsedYear;
|
int parsedYear;
|
||||||
if (int.TryParse(result.Year, NumberStyles.Any, CultureInfo.InvariantCulture, out parsedYear))
|
if (result.Year.Length > 0
|
||||||
|
&& int.TryParse(result.Year.Substring(0, Math.Min(result.Year.Length, 4)), NumberStyles.Any, CultureInfo.InvariantCulture, out parsedYear))
|
||||||
{
|
{
|
||||||
item.ProductionYear = parsedYear;
|
item.ProductionYear = parsedYear;
|
||||||
}
|
}
|
||||||
|
|
|
@ -389,6 +389,20 @@ namespace MediaBrowser.Providers.TV
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var airDateNode = node.SelectSingleNode("./FirstAired");
|
||||||
|
if (airDateNode != null)
|
||||||
|
{
|
||||||
|
var val = airDateNode.InnerText;
|
||||||
|
if (!string.IsNullOrWhiteSpace(val))
|
||||||
|
{
|
||||||
|
DateTime date;
|
||||||
|
if (DateTime.TryParse(val, out date))
|
||||||
|
{
|
||||||
|
searchResult.ProductionYear = date.Year;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var title in titles)
|
foreach (var title in titles)
|
||||||
{
|
{
|
||||||
if (string.Equals(title, comparableName, StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(title, comparableName, StringComparison.OrdinalIgnoreCase))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user