using System.Collections.Generic; using System.Linq; using LibMpc.Types; namespace LibMpc { public partial class Commands { /// /// https://www.musicpd.org/doc/protocol/database.html /// public class Database { // TODO: count public class Find : IMpcCommand> { private readonly ITag _tag; private readonly string _searchText; public Find(ITag tag, string searchText) { _tag = tag; _searchText = searchText; } public string Value => string.Join(" ", "find", _tag.Value, _searchText); public IEnumerable FormatResponse(IList> response) { var results = new List(); var mpdFile = MpdFile.EmptyFile; foreach (var line in response) { if (line.Key.Equals("file")) { if (mpdFile.IsInitialized) { results.Add(mpdFile); } mpdFile = new MpdFile(line.Value); } else { mpdFile.AddTag(line.Key, line.Value); } } return results; } } public class List : IMpcCommand { private readonly ITag _tag; public List(ITag tag) { _tag = tag; } public string Value => string.Join(" ", "list", _tag); public string FormatResponse(IList> response) { // TODO: return response.ToString(); } } // TODO: findadd public class ListAll : IMpcCommand> { public string Value => "listall"; public IEnumerable FormatResponse(IList> response) { var rootDirectory = new List { new MpdDirectory("/") // Add by default the root directory }; foreach (var line in response) { if (line.Key.Equals("file")) { rootDirectory.Last().AddFile(line.Value); } if (line.Key.Equals("directory")) { rootDirectory.Add(new MpdDirectory(line.Value)); } } return rootDirectory; } } // TODO: listallinfo // TODO: listfiles // TODO: lsinfo // TODO: readcomments // TODO: search // TODO: searchadd // TODO: searchaddpl public class Update : IMpcCommand { // TODO: Extend command: < update [URI] > public string Value => "update"; public string FormatResponse(IList> response) { // TODO: return response.ToString(); } } // TODO: rescan } } }