jellyfin-server/MediaBrowser.Model/Dlna/SearchCriteria.cs

56 lines
2.3 KiB
C#
Raw Normal View History

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)
{
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);
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)
{
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
{
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;
}
}
}
}
}
public SearchType SearchType { get; set; }
2023-05-22 20:48:09 +00:00
[GeneratedRegex("\\s")]
private static partial Regex WhiteSpaceRegex();
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
}
}