2020-02-04 00:49:27 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
using System;
|
|
|
|
using System.Text.RegularExpressions;
|
2019-01-13 19:26:15 +00:00
|
|
|
using MediaBrowser.Model.Extensions;
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
|
2020-01-09 16:07:13 +00:00
|
|
|
if (string.Equals("upnp:class", subFactors[0], StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
(string.Equals("=", subFactors[1]) || string.Equals("derivedfrom", subFactors[1], StringComparison.OrdinalIgnoreCase)))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
2020-01-09 16:07:13 +00:00
|
|
|
if (string.Equals("\"object.item.imageItem\"", subFactors[2]) || string.Equals("\"object.item.imageItem.photo\"", subFactors[2], StringComparison.OrdinalIgnoreCase))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
SearchType = SearchType.Image;
|
|
|
|
}
|
2020-01-09 16:07:13 +00:00
|
|
|
else if (string.Equals("\"object.item.videoItem\"", subFactors[2], StringComparison.OrdinalIgnoreCase))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
SearchType = SearchType.Video;
|
|
|
|
}
|
2020-01-09 16:07:13 +00:00
|
|
|
else if (string.Equals("\"object.container.playlistContainer\"", subFactors[2], StringComparison.OrdinalIgnoreCase))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
SearchType = SearchType.Playlist;
|
|
|
|
}
|
2020-01-09 16:07:13 +00:00
|
|
|
else if (string.Equals("\"object.container.album.musicAlbum\"", subFactors[2], StringComparison.OrdinalIgnoreCase))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
SearchType = SearchType.MusicAlbum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|