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;
|
|
|
|
|
|
|
|
namespace MediaBrowser.Model.Dlna
|
|
|
|
{
|
2023-05-22 20:48:09 +00:00
|
|
|
public partial class SearchCriteria
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
public SearchCriteria(string search)
|
|
|
|
{
|
2022-10-13 17:08:00 +00:00
|
|
|
ArgumentException.ThrowIfNullOrEmpty(search);
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
SearchType = SearchType.Unknown;
|
|
|
|
|
2023-05-22 20:48:09 +00:00
|
|
|
string[] factors = AndOrRegex().Split(search);
|
2019-01-06 20:50:43 +00:00
|
|
|
foreach (string factor in factors)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
2023-05-22 20:48:09 +00:00
|
|
|
string[] subFactors = WhiteSpaceRegex().Split(factor.Trim().Trim('(').Trim(')').Trim(), 3);
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
if (subFactors.Length == 3)
|
|
|
|
{
|
2021-02-20 22:13:04 +00:00
|
|
|
if (string.Equals("upnp:class", subFactors[0], StringComparison.OrdinalIgnoreCase)
|
|
|
|
&& (string.Equals("=", subFactors[1], StringComparison.Ordinal) || string.Equals("derivedfrom", subFactors[1], StringComparison.OrdinalIgnoreCase)))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
2020-04-05 16:10:56 +00:00
|
|
|
if (string.Equals("\"object.item.imageItem\"", subFactors[2], StringComparison.Ordinal) || 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-20 22:13:04 +00:00
|
|
|
|
|
|
|
public SearchType SearchType { get; set; }
|
|
|
|
|
2023-05-22 20:48:09 +00:00
|
|
|
[GeneratedRegex("\\s")]
|
|
|
|
private static partial Regex WhiteSpaceRegex();
|
2021-02-20 22:13:04 +00:00
|
|
|
|
2023-05-22 20:48:09 +00:00
|
|
|
[GeneratedRegex("(and|or)", RegexOptions.IgnoreCase)]
|
|
|
|
private static partial Regex AndOrRegex();
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
}
|