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

MPD Tags added.

This commit is contained in:
glucaci 2016-12-02 13:41:53 +01:00
parent e1430d193f
commit 74061bdab4
5 changed files with 59 additions and 143 deletions

View File

@ -13,16 +13,16 @@ namespace LibMpc
public class Find : IMpcCommand
{
private readonly SearchTag _searchTag;
private readonly ITag _tag;
private readonly string _searchText;
public Find(SearchTag searchTag, string searchText)
public Find(ITag tag, string searchText)
{
_searchTag = searchTag;
_tag = tag;
_searchText = searchText;
}
public string Value => string.Join(" ", "find", _searchTag.Value, _searchText);
public string Value => string.Join(" ", "find", _tag.Value, _searchText);
public object ParseResponse(object response)
{
@ -32,14 +32,14 @@ namespace LibMpc
public class List : IMpcCommand
{
private readonly SearchTag _searchTag;
private readonly ITag _tag;
public List(SearchTag searchTag)
public List(ITag tag)
{
_searchTag = searchTag;
_tag = tag;
}
public string Value => string.Join(" ", "list", _searchTag);
public string Value => string.Join(" ", "list", _tag);
public object ParseResponse(object response)
{

View File

@ -1,62 +0,0 @@
namespace LibMpc
{
/// <summary>
/// The scope specifier for search commands.
/// </summary>
public enum ScopeSpecifier
{
/// <summary>
/// Any attribute of a file.
/// </summary>
Any,
/// <summary>
/// The path and name of the file.
/// </summary>
Filename,
/// <summary>
/// The artist of the track.
/// </summary>
Artist,
/// <summary>
/// The album the track appears on.
/// </summary>
Album,
/// <summary>
/// The title of the track.
/// </summary>
Title,
/// <summary>
/// The index of the track on its album.
/// </summary>
Track,
/// <summary>
/// The name of the track.
/// </summary>
Name,
/// <summary>
/// The genre of the song.
/// </summary>
Genre,
/// <summary>
/// The date the track was released.
/// </summary>
Date,
/// <summary>
/// The composer of the song.
/// </summary>
Composer,
/// <summary>
/// The performer of the song.
/// </summary>
Performer,
/// <summary>
/// A comment for the track.
/// </summary>
Comment,
/// <summary>
/// The disc of a multidisc album the track is on.
/// </summary>
Disc
}
}

View File

@ -156,15 +156,15 @@ namespace LibMpc
/// <summary>
/// Returns all files in the database who's attribute matches the given token. Works like the Search command but is case sensitive.
/// </summary>
/// <param name="scopeSpecifier">Specifies the attribute to search for.</param>
/// <param name="tag">Specifies the attribute to search for.</param>
/// <param name="token">The value the files attribute must have to be included in the result.</param>
/// <returns>All files in the database who's attribute matches the given token.</returns>
public async Task<List<MpdFile>> FindAsync(ScopeSpecifier scopeSpecifier, string token)
public async Task<List<MpdFile>> FindAsync(ITag tag, string token)
{
if (token == null)
throw new ArgumentNullException("token");
MpdResponse response = await _connection.Exec("find", new string[] { TagConverter.ToTag(scopeSpecifier), token });
MpdResponse response = await _connection.Exec("find", new string[] { tag.Value, token });
if (response.IsError)
throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);
@ -174,11 +174,11 @@ namespace LibMpc
/// <summary>
/// Returns all values found in files of the MPD for the given attribute.
/// </summary>
/// <param name="scopeSpecifier">The attribute who's values are requested.</param>
/// <param name="tag">The attribute who's values are requested.</param>
/// <returns>All values found in files of the MPD for the given attribute.</returns>
public async Task<List<string>> ListAsync(ScopeSpecifier scopeSpecifier)
public async Task<List<string>> ListAsync(ITag tag)
{
MpdResponse response = await _connection.Exec("list", new string[] { TagConverter.ToTag(scopeSpecifier) });
MpdResponse response = await _connection.Exec("list", new string[] { tag.Value });
if (response.IsError)
throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);
@ -192,12 +192,12 @@ namespace LibMpc
/// <param name="searchTag">The attribute whos value should match a given value for the file to be included in the result.</param>
/// <param name="searchValue">The value the searchTag attribute must match for the file to be included in the result.</param>
/// <returns>All values found in files of the MPD for the given attribute.</returns>
public async Task<List<string>> ListAsync(ScopeSpecifier resultTag, ScopeSpecifier searchTag, string searchValue)
public async Task<List<string>> ListAsync(ITag resultTag, ITag searchTag, string searchValue)
{
if (searchValue == null)
throw new ArgumentNullException("searchValue");
MpdResponse response = await _connection.Exec("list", new string[] { TagConverter.ToTag(resultTag), TagConverter.ToTag(searchTag), searchValue });
MpdResponse response = await _connection.Exec("list", new string[] { resultTag.Value, searchTag.Value, searchValue });
if (response.IsError)
throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);
@ -270,15 +270,15 @@ namespace LibMpc
/// <summary>
/// Returns all files in the database who's attribute matches the given token. Works like the Find command but is case insensitive.
/// </summary>
/// <param name="scopeSpecifier">Specifies the attribute to search for.</param>
/// <param name="tag">Specifies the attribute to search for.</param>
/// <param name="token">The value the files attribute must have to be included in the result.</param>
/// <returns>All files in the database who's attribute matches the given token.</returns>
public async Task<List<MpdFile>> SearchAsync(ScopeSpecifier scopeSpecifier, string token)
public async Task<List<MpdFile>> SearchAsync(ITag tag, string token)
{
if (token == null)
throw new ArgumentNullException("token");
MpdResponse response = await _connection.Exec("search", new string[] { TagConverter.ToTag(scopeSpecifier), token });
MpdResponse response = await _connection.Exec("search", new string[] { tag.Value, token });
if (response.IsError)
throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);
@ -707,15 +707,15 @@ namespace LibMpc
/// <summary>
/// Returns the meta data for all tracks in the current playlist whos attribute equals the given value.
/// </summary>
/// <param name="scopeSpecifier">The attribute to search for the given value.</param>
/// <param name="tag">The attribute to search for the given value.</param>
/// <param name="token">The value to search for in the given attribute.</param>
/// <returns>The meta data for all tracks in the current playlist whos attribute equals the given value.</returns>
public async Task<List<MpdFile>> PlaylistFindAsync(ScopeSpecifier scopeSpecifier, string token)
public async Task<List<MpdFile>> PlaylistFindAsync(ITag tag, string token)
{
if (token == null)
throw new ArgumentNullException("token");
MpdResponse response = await _connection.Exec("playlistfind", new string[] { TagConverter.ToTag(scopeSpecifier), token });
MpdResponse response = await _connection.Exec("playlistfind", new string[] { tag.Value, token });
if (response.IsError)
throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);
@ -725,15 +725,15 @@ namespace LibMpc
/// <summary>
/// Returns the meta data for all tracks in the current playlist whos attribute contains the given value.
/// </summary>
/// <param name="scopeSpecifier">The attribute to search for the given value.</param>
/// <param name="tag">The attribute to search for the given value.</param>
/// <param name="token">The value to search for in the given attribute.</param>
/// <returns>The meta data for all tracks in the current playlist whos attribute contains the given value.</returns>
public async Task<List<MpdFile>> PlaylistSearchAsync(ScopeSpecifier scopeSpecifier, string token)
public async Task<List<MpdFile>> PlaylistSearchAsync(ITag tag, string token)
{
if (token == null)
throw new ArgumentNullException("token");
MpdResponse response = await _connection.Exec("playlistsearch", new string[] { TagConverter.ToTag(scopeSpecifier), token });
MpdResponse response = await _connection.Exec("playlistsearch", new string[] { tag.Value, token });
if (response.IsError)
throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);

View File

@ -1,56 +0,0 @@
using System;
namespace LibMpc
{
public static class TagConverter
{
private const string TagAny = "any";
private const string TagFilename = "filename";
private const string TagArtist = "artist";
private const string TagAlbum = "album";
private const string TagTitle = "title";
private const string TagTrack = "track";
private const string TagName = "name";
private const string TagGenre = "genre";
private const string TagDate = "date";
private const string TagComposer = "composer";
private const string TagPerformer = "performer";
private const string TagComment = "comment";
private const string TagDisc = "disc";
public static string ToTag(ScopeSpecifier scopeSpecifier)
{
switch (scopeSpecifier)
{
default:
throw new ArgumentException("scopeSpecifier");
case ScopeSpecifier.Any:
return TagAny;
case ScopeSpecifier.Filename:
return TagFilename;
case ScopeSpecifier.Artist:
return TagArtist;
case ScopeSpecifier.Album:
return TagAlbum;
case ScopeSpecifier.Title:
return TagTitle;
case ScopeSpecifier.Track:
return TagTrack;
case ScopeSpecifier.Name:
return TagName;
case ScopeSpecifier.Genre:
return TagGenre;
case ScopeSpecifier.Date:
return TagDate;
case ScopeSpecifier.Composer:
return TagComposer;
case ScopeSpecifier.Performer:
return TagPerformer;
case ScopeSpecifier.Comment:
return TagComment;
case ScopeSpecifier.Disc:
return TagDisc;
}
}
}
}

34
LibMpc/Tags.cs Normal file
View File

@ -0,0 +1,34 @@
namespace LibMpc
{
public class Tags
{
internal class Tag : ITag
{
internal Tag(string value)
{
Value = value;
}
public string Value { get; }
}
public ITag Any { get; } = new Tag("any");
public ITag Filename { get; } = new Tag("filename");
public ITag Artist { get; }= new Tag("artist");
public ITag Album { get; }= new Tag("album");
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; }
}
}