mirror of
https://github.com/ZetaKebab/MpcNET.git
synced 2025-01-14 22:18:43 +00:00
Find command and MpdTags implemented.
This commit is contained in:
parent
adc532c6e2
commit
c8a7621b38
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace LibMpc
|
||||
{
|
||||
@ -11,7 +12,7 @@ namespace LibMpc
|
||||
{
|
||||
// TODO: count
|
||||
|
||||
public class Find : IMpcCommand<string>
|
||||
public class Find : IMpcCommand<IList<IDictionary<string, string>>>
|
||||
{
|
||||
private readonly ITag _tag;
|
||||
private readonly string _searchText;
|
||||
@ -24,9 +25,26 @@ namespace LibMpc
|
||||
|
||||
public string Value => string.Join(" ", "find", _tag.Value, _searchText);
|
||||
|
||||
public IDictionary<string, string> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
public IDictionary<string, IList<IDictionary<string, string>>> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
return response.ToDefaultDictionary();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,32 +60,6 @@ namespace LibMpc
|
||||
}
|
||||
|
||||
/*
|
||||
#region Admin Commands
|
||||
|
||||
/// <summary>
|
||||
/// Starts an update of the MPD database.
|
||||
/// </summary>
|
||||
/// <returns>An sequential number of the update process.</returns>
|
||||
public async Task<int> UpdateAsync()
|
||||
{
|
||||
MpdResponse response = await _connection.SendAsync("update");
|
||||
|
||||
if (response.Message.Count != 1)
|
||||
throw new InvalidMpdResponseException("Respose message has more than one line.");
|
||||
|
||||
int ret;
|
||||
|
||||
KeyValuePair<string, string> line = response[0];
|
||||
if (!line.Key.Equals("updating_db"))
|
||||
throw new InvalidMpdResponseException("Key of line 0 is not 'updating_db'");
|
||||
if (!int.TryParse(line.Value, out ret))
|
||||
throw new InvalidMpdResponseException("Value of line 0 is not a number");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Database Commands
|
||||
/// <summary>
|
||||
/// Returns all files in the database who's attribute matches the given token. Works like the Search command but is case sensitive.
|
||||
|
@ -1,39 +0,0 @@
|
||||
namespace LibMpc
|
||||
{
|
||||
/// <summary>
|
||||
/// https://www.musicpd.org/doc/protocol/tags.html
|
||||
/// </summary>
|
||||
public class Tags
|
||||
{
|
||||
internal class Tag : ITag
|
||||
{
|
||||
internal Tag(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string Value { get; }
|
||||
}
|
||||
|
||||
public ITag Artist { get; } = new Tag("artist");
|
||||
public ITag ArtistSort { get; } = new Tag("artistsort");
|
||||
public ITag Album { get; } = new Tag("album");
|
||||
public ITag AlbumSort { get; } = new Tag("albumsort");
|
||||
public ITag AlbumArtist { get; } = new Tag("albumartist");
|
||||
public ITag AlbumArtistSort { get; } = new Tag("albumartistsort");
|
||||
public ITag Title { get; } = new Tag("title");
|
||||
public ITag Track { get; } = new Tag("track");
|
||||
public ITag Name { get; } = new Tag("name");
|
||||
public ITag Genre { get; } = new Tag("genre");
|
||||
public ITag Date { get; } = new Tag("date");
|
||||
public ITag Composer { get; } = new Tag("composer");
|
||||
public ITag Performer { get; } = new Tag("performer");
|
||||
public ITag Comment { get; } = new Tag("comment");
|
||||
public ITag Disc { get; } = new Tag("disc");
|
||||
}
|
||||
|
||||
public interface ITag
|
||||
{
|
||||
string Value { get; }
|
||||
}
|
||||
}
|
13
LibMpc/Tags/FindTags.cs
Normal file
13
LibMpc/Tags/FindTags.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace LibMpc
|
||||
{
|
||||
/// <summary>
|
||||
/// https://www.musicpd.org/doc/protocol/database.html : find {TYPE} {WHAT} [...] [window START:END]
|
||||
/// </summary>
|
||||
public class FindTags
|
||||
{
|
||||
public static ITag Any { get; } = new Tag("any");
|
||||
public static ITag File { get; } = new Tag("file");
|
||||
public static ITag Base { get; } = new Tag("base");
|
||||
public static ITag ModifiedSince { get; } = new Tag("modified-since");
|
||||
}
|
||||
}
|
24
LibMpc/Tags/MpdTags.cs
Normal file
24
LibMpc/Tags/MpdTags.cs
Normal file
@ -0,0 +1,24 @@
|
||||
namespace LibMpc
|
||||
{
|
||||
/// <summary>
|
||||
/// https://www.musicpd.org/doc/protocol/tags.html
|
||||
/// </summary>
|
||||
public class MpdTags
|
||||
{
|
||||
public static ITag Artist { get; } = new Tag("artist");
|
||||
public static ITag ArtistSort { get; } = new Tag("artistsort");
|
||||
public static ITag Album { get; } = new Tag("album");
|
||||
public static ITag AlbumSort { get; } = new Tag("albumsort");
|
||||
public static ITag AlbumArtist { get; } = new Tag("albumartist");
|
||||
public static ITag AlbumArtistSort { get; } = new Tag("albumartistsort");
|
||||
public static ITag Title { get; } = new Tag("title");
|
||||
public static ITag Track { get; } = new Tag("track");
|
||||
public static ITag Name { get; } = new Tag("name");
|
||||
public static ITag Genre { get; } = new Tag("genre");
|
||||
public static ITag Date { get; } = new Tag("date");
|
||||
public static ITag Composer { get; } = new Tag("composer");
|
||||
public static ITag Performer { get; } = new Tag("performer");
|
||||
public static ITag Comment { get; } = new Tag("comment");
|
||||
public static ITag Disc { get; } = new Tag("disc");
|
||||
}
|
||||
}
|
18
LibMpc/Tags/Tag.cs
Normal file
18
LibMpc/Tags/Tag.cs
Normal file
@ -0,0 +1,18 @@
|
||||
namespace LibMpc
|
||||
{
|
||||
public interface ITag
|
||||
{
|
||||
string Value { get; }
|
||||
}
|
||||
|
||||
|
||||
internal class Tag : ITag
|
||||
{
|
||||
internal Tag(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string Value { get; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user