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 System.Linq;
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
2016-12-20 11:35:41 +00:00
/// <summary>
/// Finds songs in the database that is exactly "searchText".
/// </summary>
2016-12-20 14:42:48 +00:00
public class Find : IMpcCommand<IEnumerable<IMpdFile>>
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-20 14:42:48 +00:00
public IEnumerable<IMpdFile> 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
foreach (var line in response)
{
if (line.Key.Equals("file"))
{
2016-12-20 14:42:48 +00:00
results.Add(new MpdFile(line.Value));
2016-12-07 15:30:47 +00:00
}
else
{
2016-12-20 14:42:48 +00:00
results.Last().AddTag(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<IEnumerable<MpdDirectory>>
2016-12-02 12:24:03 +00:00
{
public string Value => "listall";
2016-12-02 12:24:03 +00:00
public IEnumerable<MpdDirectory> FormatResponse(IList<KeyValuePair<string, string>> response)
2016-12-02 12:24:03 +00:00
{
var rootDirectory = new List<MpdDirectory>
{
new MpdDirectory("/") // Add by default the root directory
};
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.Last().AddFile(line.Value);
2016-12-16 13:00:16 +00:00
}
if (line.Key.Equals("directory"))
{
rootDirectory.Add(new MpdDirectory(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
}
}
}