You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Model/Dlna/SearchCriteria.cs

76 lines
2.8 KiB

6 years ago
using System;
using System.Text.RegularExpressions;
using MediaBrowser.Model.Extensions;
6 years ago
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>
private static string[] RegexSplit(string str, string term, int limit)
6 years ago
{
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>
private static string[] RegexSplit(string str, string term)
6 years ago
{
return Regex.Split(str, term, RegexOptions.IgnoreCase);
}
public SearchCriteria(string search)
{
if (string.IsNullOrEmpty(search))
{
throw new ArgumentNullException(nameof(search));
6 years ago
}
SearchType = SearchType.Unknown;
string[] factors = RegexSplit(search, "(and|or)");
foreach (string factor in factors)
6 years ago
{
string[] subFactors = RegexSplit(factor.Trim().Trim('(').Trim(')').Trim(), "\\s", 3);
6 years ago
if (subFactors.Length == 3)
{
if (StringHelper.EqualsIgnoreCase("upnp:class", subFactors[0]) &&
6 years ago
(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;
}
}
}
}
}
}
}