mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-16 02:18:54 -07:00
improve movie matching by looking for titles with same year first
This commit is contained in:
parent
415a2d4e31
commit
b827f4058d
@ -441,36 +441,71 @@ namespace MediaBrowser.Providers.Movies
|
||||
|
||||
if (searchResult != null)
|
||||
{
|
||||
foreach (var possible in searchResult.results)
|
||||
{
|
||||
string matchedName = possible.title ?? possible.name;
|
||||
string id = possible.id.ToString(CultureInfo.InvariantCulture);
|
||||
return FindIdOfBestResult(searchResult.results, name, year);
|
||||
}
|
||||
|
||||
if (matchedName != null)
|
||||
return null;
|
||||
}
|
||||
|
||||
private string FindIdOfBestResult(List<TmdbMovieSearchResult> results, string name, int? year)
|
||||
{
|
||||
Logger.Debug("Match " + matchedName + " for " + name);
|
||||
if (year != null)
|
||||
if (year.HasValue)
|
||||
{
|
||||
// Take the first result from the same year
|
||||
var id = results.Where(i =>
|
||||
{
|
||||
// Make sure it has a name
|
||||
if (!string.IsNullOrEmpty(i.title ?? i.name))
|
||||
{
|
||||
DateTime r;
|
||||
|
||||
// These dates are always in this exact format
|
||||
if (DateTime.TryParseExact(possible.release_date, "yyyy-MM-dd", EnUs, DateTimeStyles.None, out r))
|
||||
if (DateTime.TryParseExact(i.release_date, "yyyy-MM-dd", EnUs, DateTimeStyles.None, out r))
|
||||
{
|
||||
if (Math.Abs(r.Year - year.Value) > 1) // allow a 1 year tolerance on release date
|
||||
return r.Year == year.Value;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
})
|
||||
.Select(i => i.id.ToString(CultureInfo.InvariantCulture))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
{
|
||||
Logger.Debug("Result " + matchedName + " released on " + r + " did not match year " + year);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
//matched name and year
|
||||
return id;
|
||||
}
|
||||
|
||||
// Take the first result within one year
|
||||
id = results.Where(i =>
|
||||
{
|
||||
// Make sure it has a name
|
||||
if (!string.IsNullOrEmpty(i.title ?? i.name))
|
||||
{
|
||||
DateTime r;
|
||||
|
||||
// These dates are always in this exact format
|
||||
if (DateTime.TryParseExact(i.release_date, "yyyy-MM-dd", EnUs, DateTimeStyles.None, out r))
|
||||
{
|
||||
return Math.Abs(r.Year - year.Value) <= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return false;
|
||||
})
|
||||
.Select(i => i.id.ToString(CultureInfo.InvariantCulture))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
// Just take the first one
|
||||
return results.Where(i => !string.IsNullOrEmpty(i.title ?? i.name))
|
||||
.Select(i => i.id.ToString(CultureInfo.InvariantCulture))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user