mirror of
https://github.com/ZetaKebab/MpcNET.git
synced 2025-01-14 22:18:43 +00:00
TagConverter created from Mpc
This commit is contained in:
parent
ae983aa282
commit
cd04213791
@ -23,21 +23,6 @@ namespace LibMpc
|
||||
/// </summary>
|
||||
public class Mpc : IMpc
|
||||
{
|
||||
private const string TAG_ANY = "any";
|
||||
private const string TAG_FILENAME = "filename";
|
||||
|
||||
private const string TAG_ARTIST = "artist";
|
||||
private const string TAG_ALBUM = "album";
|
||||
private const string TAG_TITLE = "title";
|
||||
private const string TAG_TRACK = "track";
|
||||
private const string TAG_NAME = "name";
|
||||
private const string TAG_GENRE = "genre";
|
||||
private const string TAG_DATE = "date";
|
||||
private const string TAG_COMPOSER = "composer";
|
||||
private const string TAG_PERFORMER = "performer";
|
||||
private const string TAG_COMMENT = "comment";
|
||||
private const string TAG_DISC = "disc";
|
||||
|
||||
private static readonly Regex STATUS_AUDIO_REGEX = new Regex("^(?<sampleRate>[0-9]*):(?<bits>[0-9]*):(?<channels>[0-9]*)$");
|
||||
|
||||
private MpcConnection _connection;
|
||||
@ -223,7 +208,7 @@ namespace LibMpc
|
||||
if (token == null)
|
||||
throw new ArgumentNullException("token");
|
||||
|
||||
MpdResponse response = _connection.Exec("find", new string[] { toTag(scopeSpecifier), token });
|
||||
MpdResponse response = _connection.Exec("find", new string[] { TagConverter.ToTag(scopeSpecifier), token });
|
||||
|
||||
if (response.IsError)
|
||||
throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);
|
||||
@ -237,7 +222,7 @@ namespace LibMpc
|
||||
/// <returns>All values found in files of the MPD for the given attribute.</returns>
|
||||
public List<string> List(ScopeSpecifier scopeSpecifier)
|
||||
{
|
||||
MpdResponse response = _connection.Exec("list", new string[] { toTag(scopeSpecifier) });
|
||||
MpdResponse response = _connection.Exec("list", new string[] { TagConverter.ToTag(scopeSpecifier) });
|
||||
|
||||
if (response.IsError)
|
||||
throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);
|
||||
@ -256,7 +241,7 @@ namespace LibMpc
|
||||
if (searchValue == null)
|
||||
throw new ArgumentNullException("searchValue");
|
||||
|
||||
MpdResponse response = _connection.Exec("list", new string[] { toTag(resultTag), toTag(searchTag), searchValue });
|
||||
MpdResponse response = _connection.Exec("list", new string[] { TagConverter.ToTag(resultTag), TagConverter.ToTag(searchTag), searchValue });
|
||||
|
||||
if (response.IsError)
|
||||
throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);
|
||||
@ -337,7 +322,7 @@ namespace LibMpc
|
||||
if (token == null)
|
||||
throw new ArgumentNullException("token");
|
||||
|
||||
MpdResponse response = _connection.Exec("search", new string[] { toTag(scopeSpecifier), token });
|
||||
MpdResponse response = _connection.Exec("search", new string[] { TagConverter.ToTag(scopeSpecifier), token });
|
||||
|
||||
if (response.IsError)
|
||||
throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);
|
||||
@ -774,7 +759,7 @@ namespace LibMpc
|
||||
if (token == null)
|
||||
throw new ArgumentNullException("token");
|
||||
|
||||
MpdResponse response = _connection.Exec("playlistfind", new string[] { toTag(scopeSpecifier), token });
|
||||
MpdResponse response = _connection.Exec("playlistfind", new string[] { TagConverter.ToTag(scopeSpecifier), token });
|
||||
|
||||
if (response.IsError)
|
||||
throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);
|
||||
@ -792,7 +777,7 @@ namespace LibMpc
|
||||
if (token == null)
|
||||
throw new ArgumentNullException("token");
|
||||
|
||||
MpdResponse response = _connection.Exec("playlistsearch", new string[] { toTag(scopeSpecifier), token });
|
||||
MpdResponse response = _connection.Exec("playlistsearch", new string[] { TagConverter.ToTag(scopeSpecifier), token });
|
||||
|
||||
if (response.IsError)
|
||||
throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);
|
||||
@ -1268,40 +1253,5 @@ namespace LibMpc
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private string toTag(ScopeSpecifier scopeSpecifier)
|
||||
{
|
||||
switch (scopeSpecifier)
|
||||
{
|
||||
default:
|
||||
throw new ArgumentException("scopeSpecifier");
|
||||
case ScopeSpecifier.Any:
|
||||
return TAG_ANY;
|
||||
case ScopeSpecifier.Filename:
|
||||
return TAG_FILENAME;
|
||||
case ScopeSpecifier.Artist:
|
||||
return TAG_ARTIST;
|
||||
case ScopeSpecifier.Album:
|
||||
return TAG_ALBUM;
|
||||
case ScopeSpecifier.Title:
|
||||
return TAG_TITLE;
|
||||
case ScopeSpecifier.Track:
|
||||
return TAG_TRACK;
|
||||
case ScopeSpecifier.Name:
|
||||
return TAG_NAME;
|
||||
case ScopeSpecifier.Genre:
|
||||
return TAG_GENRE;
|
||||
case ScopeSpecifier.Date:
|
||||
return TAG_DATE;
|
||||
case ScopeSpecifier.Composer:
|
||||
return TAG_COMPOSER;
|
||||
case ScopeSpecifier.Performer:
|
||||
return TAG_PERFORMER;
|
||||
case ScopeSpecifier.Comment:
|
||||
return TAG_COMMENT;
|
||||
case ScopeSpecifier.Disc:
|
||||
return TAG_DISC;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
56
LibMpc/TagConverter.cs
Normal file
56
LibMpc/TagConverter.cs
Normal file
@ -0,0 +1,56 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user