fixes #538 - Support additional artist splitting

pull/702/head
Luke Pulverenti 11 years ago
parent 3b41f9cd23
commit 37f0e23bf4

@ -20,9 +20,40 @@ namespace MediaBrowser.Common.Extensions
{ {
// http://stackoverflow.com/questions/1349023/how-can-i-strip-html-from-text-in-net // http://stackoverflow.com/questions/1349023/how-can-i-strip-html-from-text-in-net
const string pattern = @"<(.|\n)*?>"; const string pattern = @"<(.|\n)*?>";
return Regex.Replace(htmlString, pattern, string.Empty).Trim(); return Regex.Replace(htmlString, pattern, string.Empty).Trim();
} }
/// <summary>
/// Replaces the specified STR.
/// </summary>
/// <param name="str">The STR.</param>
/// <param name="oldValue">The old value.</param>
/// <param name="newValue">The new value.</param>
/// <param name="comparison">The comparison.</param>
/// <returns>System.String.</returns>
public static string Replace(this string str, string oldValue, string newValue, StringComparison comparison)
{
var sb = new StringBuilder();
var previousIndex = 0;
var index = str.IndexOf(oldValue, comparison);
while (index != -1)
{
sb.Append(str.Substring(previousIndex, index - previousIndex));
sb.Append(newValue);
index += oldValue.Length;
previousIndex = index;
index = str.IndexOf(oldValue, index, comparison);
}
sb.Append(str.Substring(previousIndex));
return sb.ToString();
}
/// <summary> /// <summary>
/// Gets the M d5. /// Gets the M d5.
/// </summary> /// </summary>

@ -1,4 +1,5 @@
using MediaBrowser.Common.MediaInfo; using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.MediaInfo;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Audio;
@ -114,7 +115,7 @@ namespace MediaBrowser.Providers.MediaInfo
if (!string.IsNullOrWhiteSpace(composer)) if (!string.IsNullOrWhiteSpace(composer))
{ {
foreach (var person in Split(composer, true)) foreach (var person in Split(composer))
{ {
audio.AddPerson(new PersonInfo { Name = person, Type = PersonType.Composer }); audio.AddPerson(new PersonInfo { Name = person, Type = PersonType.Composer });
} }
@ -131,7 +132,7 @@ namespace MediaBrowser.Providers.MediaInfo
} }
else else
{ {
audio.Artists = Split(artist, false) audio.Artists = SplitArtists(artist)
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase)
.ToList(); .ToList();
@ -181,13 +182,28 @@ namespace MediaBrowser.Providers.MediaInfo
/// Splits the specified val. /// Splits the specified val.
/// </summary> /// </summary>
/// <param name="val">The val.</param> /// <param name="val">The val.</param>
/// <param name="allowSplitByComma">if set to <c>true</c> [allow split by comma].</param>
/// <returns>System.String[][].</returns> /// <returns>System.String[][].</returns>
private IEnumerable<string> Split(string val, bool allowSplitByComma) private IEnumerable<string> Split(string val)
{ {
// Only use the comma as a delimeter if there are no slashes or pipes. // Only use the comma as a delimeter if there are no slashes or pipes.
// We want to be careful not to split names that have commas in them // We want to be careful not to split names that have commas in them
var delimeter = allowSplitByComma ? (_nameDelimiters.Any(i => val.IndexOf(i) != -1) ? _nameDelimiters : new[] { ',' }) : _nameDelimiters; var delimeter = _nameDelimiters.Any(i => val.IndexOf(i) != -1) ? _nameDelimiters : new[] { ',' };
return val.Split(delimeter, StringSplitOptions.RemoveEmptyEntries)
.Where(i => !string.IsNullOrWhiteSpace(i))
.Select(i => i.Trim());
}
private const string ArtistReplaceValue = " | ";
private IEnumerable<string> SplitArtists(string val)
{
val = val.Replace(" featuring ", ArtistReplaceValue, StringComparison.OrdinalIgnoreCase)
.Replace(" feat. ", ArtistReplaceValue, StringComparison.OrdinalIgnoreCase);
// Only use the comma as a delimeter if there are no slashes or pipes.
// We want to be careful not to split names that have commas in them
var delimeter = _nameDelimiters;
return val.Split(delimeter, StringSplitOptions.RemoveEmptyEntries) return val.Split(delimeter, StringSplitOptions.RemoveEmptyEntries)
.Where(i => !string.IsNullOrWhiteSpace(i)) .Where(i => !string.IsNullOrWhiteSpace(i))
@ -207,7 +223,7 @@ namespace MediaBrowser.Providers.MediaInfo
if (!string.IsNullOrEmpty(val)) if (!string.IsNullOrEmpty(val))
{ {
// Sometimes the artist name is listed here, account for that // Sometimes the artist name is listed here, account for that
var studios = Split(val, true).Where(i => !audio.HasArtist(i)); var studios = Split(val).Where(i => !audio.HasArtist(i));
foreach (var studio in studios) foreach (var studio in studios)
{ {
@ -229,7 +245,7 @@ namespace MediaBrowser.Providers.MediaInfo
{ {
audio.Genres.Clear(); audio.Genres.Clear();
foreach (var genre in Split(val, true)) foreach (var genre in Split(val))
{ {
audio.AddGenre(genre); audio.AddGenre(genre);
} }

Loading…
Cancel
Save