2015-01-17 13:12:02 -07:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2014-02-22 22:52:30 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-01-22 10:05:06 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
2016-11-02 23:37:52 -07:00
|
|
|
|
using MediaBrowser.Controller.Extensions;
|
2014-01-22 10:05:06 -07:00
|
|
|
|
|
2016-11-02 23:37:52 -07:00
|
|
|
|
namespace Emby.Server.Implementations.FileOrganization
|
2014-01-22 10:05:06 -07:00
|
|
|
|
{
|
|
|
|
|
public static class NameUtils
|
|
|
|
|
{
|
|
|
|
|
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
|
|
|
|
|
|
|
|
|
internal static Tuple<T, int> GetMatchScore<T>(string sortedName, int? year, T series)
|
|
|
|
|
where T : BaseItem
|
|
|
|
|
{
|
|
|
|
|
var score = 0;
|
|
|
|
|
|
|
|
|
|
var seriesNameWithoutYear = series.Name;
|
|
|
|
|
if (series.ProductionYear.HasValue)
|
|
|
|
|
{
|
|
|
|
|
seriesNameWithoutYear = seriesNameWithoutYear.Replace(series.ProductionYear.Value.ToString(UsCulture), String.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsNameMatch(sortedName, seriesNameWithoutYear))
|
|
|
|
|
{
|
|
|
|
|
score++;
|
|
|
|
|
|
|
|
|
|
if (year.HasValue && series.ProductionYear.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if (year.Value == series.ProductionYear.Value)
|
|
|
|
|
{
|
|
|
|
|
score++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Regardless of name, return a 0 score if the years don't match
|
|
|
|
|
return new Tuple<T, int>(series, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Tuple<T, int>(series, score);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static bool IsNameMatch(string name1, string name2)
|
|
|
|
|
{
|
|
|
|
|
name1 = GetComparableName(name1);
|
|
|
|
|
name2 = GetComparableName(name2);
|
|
|
|
|
|
|
|
|
|
return String.Equals(name1, name2, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetComparableName(string name)
|
|
|
|
|
{
|
2016-11-02 23:37:52 -07:00
|
|
|
|
name = name.RemoveDiacritics();
|
2014-01-22 10:05:06 -07:00
|
|
|
|
|
2014-02-22 22:52:30 -07:00
|
|
|
|
name = " " + name + " ";
|
2014-01-22 10:05:06 -07:00
|
|
|
|
|
|
|
|
|
name = name.Replace(".", " ")
|
|
|
|
|
.Replace("_", " ")
|
2014-10-03 18:42:38 -07:00
|
|
|
|
.Replace(" and ", " ")
|
|
|
|
|
.Replace(".and.", " ")
|
2014-01-22 10:05:06 -07:00
|
|
|
|
.Replace("&", " ")
|
|
|
|
|
.Replace("!", " ")
|
|
|
|
|
.Replace("(", " ")
|
|
|
|
|
.Replace(")", " ")
|
2014-03-22 11:25:03 -07:00
|
|
|
|
.Replace(":", " ")
|
2014-01-22 10:05:06 -07:00
|
|
|
|
.Replace(",", " ")
|
|
|
|
|
.Replace("-", " ")
|
2014-09-20 08:48:23 -07:00
|
|
|
|
.Replace("'", " ")
|
|
|
|
|
.Replace("[", " ")
|
|
|
|
|
.Replace("]", " ")
|
2014-02-22 22:52:30 -07:00
|
|
|
|
.Replace(" a ", String.Empty, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
.Replace(" the ", String.Empty, StringComparison.OrdinalIgnoreCase)
|
2014-01-22 10:05:06 -07:00
|
|
|
|
.Replace(" ", String.Empty);
|
|
|
|
|
|
|
|
|
|
return name.Trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|