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

123 lines
3.8 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using LibMpc.Types;
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
public class Find : IMpcCommand<IEnumerable<MpdFile>>
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
public IEnumerable<MpdFile> FormatResponse(IList<KeyValuePair<string, string>> response)
2016-12-02 12:24:03 +00:00
{
var results = new List<MpdFile>();
2016-12-07 15:30:47 +00:00
var fileBuilder = new MpdFileBuidler();
2016-12-07 15:30:47 +00:00
foreach (var line in response)
{
if (line.Key.Equals("file"))
{
if (fileBuilder.IsInitialized)
{
results.Add(fileBuilder.Build());
}
fileBuilder.Init(line.Value);
2016-12-07 15:30:47 +00:00
}
else
{
fileBuilder.WithProperty(line.Key, line.Value);
2016-12-07 15:30:47 +00:00
}
}
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 string FormatResponse(IList<KeyValuePair<string, string>> response)
2016-12-02 12:24:03 +00:00
{
// TODO:
return response.ToString();
2016-12-02 12:24:03 +00:00
}
}
// TODO: findadd
public class ListAll : IMpcCommand<MpdDirectory>
2016-12-02 12:24:03 +00:00
{
public string Value => "listall";
2016-12-02 12:24:03 +00:00
public MpdDirectory FormatResponse(IList<KeyValuePair<string, string>> response)
2016-12-02 12:24:03 +00:00
{
2016-12-16 13:00:16 +00:00
// Add by default the root directory
var rootDirectory = new MpdDirectory("/");
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"))
{
rootDirectory.AddFile(line.Value);
2016-12-16 13:00:16 +00:00
}
if (line.Key.Equals("directory"))
{
rootDirectory.AddDirectory(line.Value);
2016-12-16 13:00:16 +00:00
}
}
2016-12-02 12:24:03 +00:00
return rootDirectory;
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 string FormatResponse(IList<KeyValuePair<string, string>> response)
2016-12-02 12:24:03 +00:00
{
// TODO:
return response.ToString();
2016-12-02 12:24:03 +00:00
}
}
2016-12-02 12:24:03 +00:00
// TODO: rescan
}
}
}