mirror of
https://github.com/ZetaKebab/MpcNET.git
synced 2025-01-14 22:18:43 +00:00
Implement find filter list
This commit is contained in:
parent
405e85f30f
commit
e565528b33
@ -7,6 +7,7 @@
|
|||||||
namespace MpcNET.Commands.Database
|
namespace MpcNET.Commands.Database
|
||||||
{
|
{
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using MpcNET.Tags;
|
using MpcNET.Tags;
|
||||||
using MpcNET.Types;
|
using MpcNET.Types;
|
||||||
|
|
||||||
@ -16,8 +17,7 @@ namespace MpcNET.Commands.Database
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class FindCommand : IMpcCommand<IEnumerable<IMpdFile>>
|
public class FindCommand : IMpcCommand<IEnumerable<IMpdFile>>
|
||||||
{
|
{
|
||||||
private readonly ITag tag;
|
private readonly List<KeyValuePair<ITag, string>> filters;
|
||||||
private readonly string searchText;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="FindCommand"/> class.
|
/// Initializes a new instance of the <see cref="FindCommand"/> class.
|
||||||
@ -26,8 +26,17 @@ namespace MpcNET.Commands.Database
|
|||||||
/// <param name="searchText">The search text.</param>
|
/// <param name="searchText">The search text.</param>
|
||||||
public FindCommand(ITag tag, string searchText)
|
public FindCommand(ITag tag, string searchText)
|
||||||
{
|
{
|
||||||
this.tag = tag;
|
this.filters = new List<KeyValuePair<ITag, string>>();
|
||||||
this.searchText = searchText;
|
this.filters.Add(new KeyValuePair<ITag, string>(tag, searchText));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="FindCommand"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filters">List of key/value filters</param>
|
||||||
|
public FindCommand(List<KeyValuePair<ITag, string>> filters)
|
||||||
|
{
|
||||||
|
this.filters = filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -36,7 +45,14 @@ namespace MpcNET.Commands.Database
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The serialize command.
|
/// The serialize command.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public string Serialize() => string.Join(" ", "find", this.tag.Value, this.searchText);
|
public string Serialize() =>
|
||||||
|
string.Join(" ",
|
||||||
|
"find",
|
||||||
|
string.Join(" ",
|
||||||
|
this.filters
|
||||||
|
.Select(x => string.Join(" ",
|
||||||
|
x.Key.Value, escape(x.Value)))
|
||||||
|
.ToArray()));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserializes the specified response text pairs.
|
/// Deserializes the specified response text pairs.
|
||||||
@ -49,7 +65,8 @@ namespace MpcNET.Commands.Database
|
|||||||
{
|
{
|
||||||
return MpdFile.CreateList(response);
|
return MpdFile.CreateList(response);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
private string escape(string value) => string.Format("\"{0}\"", value.Replace("\\", "\\\\").Replace("\"", "\\\""));
|
||||||
|
}
|
||||||
// TODO: rescan
|
// TODO: rescan
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user