diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-11-03 02:37:52 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-11-03 02:37:52 -0400 |
| commit | 3eb4091808735858b01855d298226d239be464af (patch) | |
| tree | a17a94e2c677d60471a79617218c8ef9a7a7dee3 /MediaBrowser.Server.Implementations/FileOrganization/NameUtils.cs | |
| parent | 41bef184d1036b02baec00734f3edd8abbebf5fe (diff) | |
move additional classes to new server lib
Diffstat (limited to 'MediaBrowser.Server.Implementations/FileOrganization/NameUtils.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/FileOrganization/NameUtils.cs | 96 |
1 files changed, 0 insertions, 96 deletions
diff --git a/MediaBrowser.Server.Implementations/FileOrganization/NameUtils.cs b/MediaBrowser.Server.Implementations/FileOrganization/NameUtils.cs deleted file mode 100644 index 624133d4f..000000000 --- a/MediaBrowser.Server.Implementations/FileOrganization/NameUtils.cs +++ /dev/null @@ -1,96 +0,0 @@ -using MediaBrowser.Model.Extensions; -using MediaBrowser.Controller.Entities; -using System; -using System.Globalization; -using System.Linq; -using System.Text; - -namespace MediaBrowser.Server.Implementations.FileOrganization -{ - 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) - { - name = RemoveDiacritics(name); - - name = " " + name + " "; - - name = name.Replace(".", " ") - .Replace("_", " ") - .Replace(" and ", " ") - .Replace(".and.", " ") - .Replace("&", " ") - .Replace("!", " ") - .Replace("(", " ") - .Replace(")", " ") - .Replace(":", " ") - .Replace(",", " ") - .Replace("-", " ") - .Replace("'", " ") - .Replace("[", " ") - .Replace("]", " ") - .Replace(" a ", String.Empty, StringComparison.OrdinalIgnoreCase) - .Replace(" the ", String.Empty, StringComparison.OrdinalIgnoreCase) - .Replace(" ", String.Empty); - - return name.Trim(); - } - - /// <summary> - /// Removes the diacritics. - /// </summary> - /// <param name="text">The text.</param> - /// <returns>System.String.</returns> - private static string RemoveDiacritics(string text) - { - return String.Concat( - text.Normalize(NormalizationForm.FormD) - .Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) != - UnicodeCategory.NonSpacingMark) - ).Normalize(NormalizationForm.FormC); - } - } -} |
