1
0
mirror of https://github.com/ZetaKebab/MpcNET.git synced 2024-09-16 05:30:09 +00:00
MpcNET/LibMpc/Commands/Commands.Database.cs

109 lines
3.4 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2016-12-07 15:30:47 +00:00
using System.Linq;
2016-12-02 12:24:03 +00:00
namespace LibMpc
{
public partial class Commands
{
/// <summary>
/// https://www.musicpd.org/doc/protocol/database.html
/// </summary>
public class Database
{
// TODO: count
2016-12-07 15:30:47 +00:00
public class Find : IMpcCommand<IList<IDictionary<string, string>>>
2016-12-02 12:24:03 +00:00
{
2016-12-02 12:41:53 +00:00
private readonly ITag _tag;
2016-12-02 12:24:03 +00:00
private readonly string _searchText;
2016-12-02 12:41:53 +00:00
public Find(ITag tag, string searchText)
2016-12-02 12:24:03 +00:00
{
2016-12-02 12:41:53 +00:00
_tag = tag;
2016-12-02 12:24:03 +00:00
_searchText = searchText;
}
2016-12-02 12:41:53 +00:00
public string Value => string.Join(" ", "find", _tag.Value, _searchText);
2016-12-02 12:24:03 +00:00
2016-12-07 15:30:47 +00:00
public IDictionary<string, IList<IDictionary<string, string>>> FormatResponse(IList<KeyValuePair<string, string>> response)
2016-12-02 12:24:03 +00:00
{
2016-12-07 15:30:47 +00:00
var results = new Dictionary<string, IList<IDictionary<string, string>>>
{
{ "files", new List<IDictionary<string, string>>() }
};
foreach (var line in response)
{
if (line.Key.Equals("file"))
{
results["files"].Add(new Dictionary<string, string> { { "file", line.Value } });
}
else
{
results["files"].Last().Add(line.Key, line.Value);
}
}
return results;
2016-12-02 12:24:03 +00:00
}
}
public class List : IMpcCommand<string>
2016-12-02 12:24:03 +00:00
{
2016-12-02 12:41:53 +00:00
private readonly ITag _tag;
2016-12-02 12:24:03 +00:00
2016-12-02 12:41:53 +00:00
public List(ITag tag)
2016-12-02 12:24:03 +00:00
{
2016-12-02 12:41:53 +00:00
_tag = tag;
2016-12-02 12:24:03 +00:00
}
2016-12-02 12:41:53 +00:00
public string Value => string.Join(" ", "list", _tag);
2016-12-02 12:24:03 +00:00
public IDictionary<string, string> FormatResponse(IList<KeyValuePair<string, string>> response)
2016-12-02 12:24:03 +00:00
{
return response.ToDefaultDictionary();
2016-12-02 12:24:03 +00:00
}
}
// TODO: findadd
public class ListAll : IMpcCommand<string>
2016-12-02 12:24:03 +00:00
{
private readonly string _path;
public ListAll(string path)
{
_path = path;
}
public string Value => string.Join(" ", "listall", _path);
public IDictionary<string, string> FormatResponse(IList<KeyValuePair<string, string>> response)
2016-12-02 12:24:03 +00:00
{
return response.ToDefaultDictionary();
2016-12-02 12:24:03 +00:00
}
}
// TODO: listallinfo
// TODO: listfiles
// TODO: lsinfo
// TODO: readcomments
// TODO: search
// TODO: searchadd
// TODO: searchaddpl
public class Update : IMpcCommand<string>
2016-12-02 12:24:03 +00:00
{
// TODO: Extend command: < update [URI] >
2016-12-02 12:24:03 +00:00
public string Value => "update";
public IDictionary<string, string> FormatResponse(IList<KeyValuePair<string, string>> response)
2016-12-02 12:24:03 +00:00
{
return response.ToDefaultDictionary();
2016-12-02 12:24:03 +00:00
}
}
2016-12-02 12:24:03 +00:00
// TODO: rescan
}
}
}