2019-01-06 20:50:43 +00:00
|
|
|
using MediaBrowser.Model.Extensions;
|
2018-12-27 23:27:57 +00:00
|
|
|
using System;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
namespace MediaBrowser.Model.Dlna
|
|
|
|
{
|
|
|
|
public class SearchCriteria
|
|
|
|
{
|
|
|
|
public SearchType SearchType { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Splits the specified string.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="str">The string.</param>
|
|
|
|
/// <param name="term">The term.</param>
|
|
|
|
/// <param name="limit">The limit.</param>
|
|
|
|
/// <returns>System.String[].</returns>
|
2019-01-06 20:50:43 +00:00
|
|
|
private static string[] RegexSplit(string str, string term, int limit)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
return new Regex(term).Split(str, limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Splits the specified string.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="str">The string.</param>
|
|
|
|
/// <param name="term">The term.</param>
|
|
|
|
/// <returns>System.String[].</returns>
|
2019-01-06 20:50:43 +00:00
|
|
|
private static string[] RegexSplit(string str, string term)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
return Regex.Split(str, term, RegexOptions.IgnoreCase);
|
|
|
|
}
|
|
|
|
|
|
|
|
public SearchCriteria(string search)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(search))
|
|
|
|
{
|
2019-01-06 20:50:43 +00:00
|
|
|
throw new ArgumentNullException(nameof(search));
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SearchType = SearchType.Unknown;
|
|
|
|
|
2019-01-06 20:50:43 +00:00
|
|
|
string[] factors = RegexSplit(search, "(and|or)");
|
|
|
|
foreach (string factor in factors)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
2019-01-06 20:50:43 +00:00
|
|
|
string[] subFactors = RegexSplit(factor.Trim().Trim('(').Trim(')').Trim(), "\\s", 3);
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
if (subFactors.Length == 3)
|
|
|
|
{
|
|
|
|
|
2019-01-07 23:27:46 +00:00
|
|
|
if (StringHelper.EqualsIgnoreCase("upnp:class", subFactors[0]) &&
|
2018-12-27 23:27:57 +00:00
|
|
|
(StringHelper.EqualsIgnoreCase("=", subFactors[1]) || StringHelper.EqualsIgnoreCase("derivedfrom", subFactors[1])))
|
|
|
|
{
|
|
|
|
if (StringHelper.EqualsIgnoreCase("\"object.item.imageItem\"", subFactors[2]) || StringHelper.EqualsIgnoreCase("\"object.item.imageItem.photo\"", subFactors[2]))
|
|
|
|
{
|
|
|
|
SearchType = SearchType.Image;
|
|
|
|
}
|
|
|
|
else if (StringHelper.EqualsIgnoreCase("\"object.item.videoItem\"", subFactors[2]))
|
|
|
|
{
|
|
|
|
SearchType = SearchType.Video;
|
|
|
|
}
|
|
|
|
else if (StringHelper.EqualsIgnoreCase("\"object.container.playlistContainer\"", subFactors[2]))
|
|
|
|
{
|
|
|
|
SearchType = SearchType.Playlist;
|
|
|
|
}
|
|
|
|
else if (StringHelper.EqualsIgnoreCase("\"object.container.album.musicAlbum\"", subFactors[2]))
|
|
|
|
{
|
|
|
|
SearchType = SearchType.MusicAlbum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|