#680 - improve name comparisons

pull/702/head
Luke Pulverenti 11 years ago
parent d2ed436a6f
commit 92c76de2ba

@ -1,5 +1,6 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.Serialization;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using System;
@ -91,6 +92,16 @@ namespace MediaBrowser.Model.LiveTv
/// <value>The original primary image aspect ratio.</value>
public double? OriginalPrimaryImageAspectRatio { get; set; }
/// <summary>
/// Gets a value indicating whether this instance has primary image.
/// </summary>
/// <value><c>true</c> if this instance has primary image; otherwise, <c>false</c>.</value>
[IgnoreDataMember]
public bool HasPrimaryImage
{
get { return ImageTags != null && ImageTags.ContainsKey(ImageType.Primary); }
}
public ChannelInfoDto()
{
ImageTags = new Dictionary<ImageType, Guid>();

@ -1,5 +1,6 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.Serialization;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using System;
@ -190,6 +191,16 @@ namespace MediaBrowser.Model.LiveTv
/// <value><c>true</c> if this instance is premiere; otherwise, <c>false</c>.</value>
public bool IsPremiere { get; set; }
/// <summary>
/// Gets a value indicating whether this instance has primary image.
/// </summary>
/// <value><c>true</c> if this instance has primary image; otherwise, <c>false</c>.</value>
[IgnoreDataMember]
public bool HasPrimaryImage
{
get { return ImageTags != null && ImageTags.ContainsKey(ImageType.Primary); }
}
public ProgramInfoDto()
{
Genres = new List<string>();

@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Runtime.Serialization;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using System;
@ -224,6 +225,16 @@ namespace MediaBrowser.Model.LiveTv
/// <value>The user data.</value>
public UserItemDataDto UserData { get; set; }
/// <summary>
/// Gets a value indicating whether this instance has primary image.
/// </summary>
/// <value><c>true</c> if this instance has primary image; otherwise, <c>false</c>.</value>
[IgnoreDataMember]
public bool HasPrimaryImage
{
get { return ImageTags != null && ImageTags.ContainsKey(ImageType.Primary); }
}
/// <summary>
/// Gets or sets the type.
/// </summary>

@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.Serialization;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Model.LiveTv
{
@ -133,8 +135,25 @@ namespace MediaBrowser.Model.LiveTv
/// <value><c>true</c> if this instance is post padding required; otherwise, <c>false</c>.</value>
public bool IsPostPaddingRequired { get; set; }
/// <summary>
/// Gets or sets the image tags.
/// </summary>
/// <value>The image tags.</value>
public Dictionary<ImageType, Guid> ImageTags { get; set; }
/// <summary>
/// Gets a value indicating whether this instance has primary image.
/// </summary>
/// <value><c>true</c> if this instance has primary image; otherwise, <c>false</c>.</value>
[IgnoreDataMember]
public bool HasPrimaryImage
{
get { return ImageTags != null && ImageTags.ContainsKey(ImageType.Primary); }
}
public SeriesTimerInfoDto()
{
ImageTags = new Dictionary<ImageType, Guid>();
Days = new List<DayOfWeek>();
}

@ -130,6 +130,9 @@ namespace MediaBrowser.Model.LiveTv
/// <value>The program information.</value>
public ProgramInfoDto ProgramInfo { get; set; }
/// <summary>
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
}
}

@ -1,4 +1,5 @@
using MediaBrowser.Common.IO;
using System.Text;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.FileOrganization;
using MediaBrowser.Controller.IO;
@ -429,9 +430,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
{
var score = 0;
// TODO: Improve this - should ignore spaces, periods, underscores, most likely all symbols and
// possibly remove sorting words like "the", "and", etc.
if (string.Equals(sortedName, series.Name, StringComparison.OrdinalIgnoreCase))
if (IsNameMatch(sortedName, series.Name))
{
score++;
@ -452,6 +451,49 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
return new Tuple<Series, int>(series, score);
}
private bool IsNameMatch(string name1, string name2)
{
name1 = GetComparableName(name1);
name2 = GetComparableName(name2);
return string.Equals(name1, name2, StringComparison.OrdinalIgnoreCase);
}
private string GetComparableName(string name)
{
// TODO: Improve this - should ignore spaces, periods, underscores, most likely all symbols and
// possibly remove sorting words like "the", "and", etc.
name = RemoveDiacritics(name);
name = " " + name.ToLower() + " ";
name = name.Replace(".", " ")
.Replace("_", " ")
.Replace("&", " ")
.Replace("!", " ")
.Replace(",", " ")
.Replace(" a ", string.Empty)
.Replace(" the ", string.Empty)
.Replace(" ", string.Empty);
return name.Trim();
}
/// <summary>
/// Removes the diacritics.
/// </summary>
/// <param name="text">The text.</param>
/// <returns>System.String.</returns>
private string RemoveDiacritics(string text)
{
return string.Concat(
text.Normalize(NormalizationForm.FormD)
.Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) !=
UnicodeCategory.NonSpacingMark)
).Normalize(NormalizationForm.FormC);
}
/// <summary>
/// Deletes the left over files.
/// </summary>

Loading…
Cancel
Save