1
0
mirror of https://github.com/ZetaKebab/MpcNET.git synced 2025-01-14 22:18:43 +00:00
MpcNET/LibMpc/Commands/Commands.Database.cs

131 lines
4.5 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
2016-12-16 13:00:16 +00:00
public class ListAll : IMpcCommand<IList<IDictionary<string, IList<string>>>>
2016-12-02 12:24:03 +00:00
{
public string Value => "listall";
2016-12-02 12:24:03 +00:00
2016-12-16 13:00:16 +00:00
public IDictionary<string, IList<IDictionary<string, IList<string>>>> FormatResponse(IList<KeyValuePair<string, string>> response)
2016-12-02 12:24:03 +00:00
{
2016-12-16 13:00:16 +00:00
var results = new Dictionary<string, IList<IDictionary<string, IList<string>>>>
{
2016-12-16 13:00:16 +00:00
{ "directories", new List<IDictionary<string, IList<string>>>() }
};
2016-12-16 13:00:16 +00:00
// Add by default the root directory
results["directories"].Add(new Dictionary<string, IList<string>>
{
{ "path", new List<string>() },
{ "files", new List<string>() }
});
2016-12-02 12:24:03 +00:00
2016-12-16 13:00:16 +00:00
foreach (var line in response)
{
2016-12-16 13:00:16 +00:00
if (line.Key.Equals("file"))
{
results["directories"].Last()["files"].Add(line.Value);
}
if (line.Key.Equals("directory"))
{
results["directories"].Add(new Dictionary<string, IList<string>>
{
{ "path", new []{ line.Value } },
{ "files", new List<string>() }
});
}
}
2016-12-02 12:24:03 +00:00
return results;
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
}
}
}