mirror of
https://github.com/ZetaKebab/MpcNET.git
synced 2025-01-14 22:18:43 +00:00
Response from MPD will be specific type. MpdDirectory and MpdFile created. Metadata for MpdFile still to be done.
This commit is contained in:
parent
15c81b96e9
commit
f6653e0075
@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LibMpc.Types;
|
||||
|
||||
namespace LibMpc
|
||||
{
|
||||
@ -12,7 +12,7 @@ namespace LibMpc
|
||||
{
|
||||
// TODO: count
|
||||
|
||||
public class Find : IMpcCommand<IList<IDictionary<string, string>>>
|
||||
public class Find : IMpcCommand<IEnumerable<MpdFile>>
|
||||
{
|
||||
private readonly ITag _tag;
|
||||
private readonly string _searchText;
|
||||
@ -25,22 +25,25 @@ namespace LibMpc
|
||||
|
||||
public string Value => string.Join(" ", "find", _tag.Value, _searchText);
|
||||
|
||||
public IDictionary<string, IList<IDictionary<string, string>>> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
public IEnumerable<MpdFile> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
var results = new Dictionary<string, IList<IDictionary<string, string>>>
|
||||
{
|
||||
{ "files", new List<IDictionary<string, string>>() }
|
||||
};
|
||||
var results = new List<MpdFile>();
|
||||
|
||||
var fileBuilder = new MpdFileBuidler();
|
||||
foreach (var line in response)
|
||||
{
|
||||
if (line.Key.Equals("file"))
|
||||
{
|
||||
results["files"].Add(new Dictionary<string, string> { { "file", line.Value } });
|
||||
if (fileBuilder.IsInitialized)
|
||||
{
|
||||
results.Add(fileBuilder.Build());
|
||||
}
|
||||
|
||||
fileBuilder.Init(line.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
results["files"].Last().Add(line.Key, line.Value);
|
||||
fileBuilder.WithProperty(line.Key, line.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,50 +62,38 @@ namespace LibMpc
|
||||
|
||||
public string Value => string.Join(" ", "list", _tag);
|
||||
|
||||
public IDictionary<string, string> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
public string FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
return response.ToDefaultDictionary();
|
||||
// TODO:
|
||||
return response.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: findadd
|
||||
|
||||
public class ListAll : IMpcCommand<IList<IDictionary<string, IList<string>>>>
|
||||
public class ListAll : IMpcCommand<MpdDirectory>
|
||||
{
|
||||
public string Value => "listall";
|
||||
|
||||
public IDictionary<string, IList<IDictionary<string, IList<string>>>> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
public MpdDirectory FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
var results = new Dictionary<string, IList<IDictionary<string, IList<string>>>>
|
||||
{
|
||||
{ "directories", new List<IDictionary<string, IList<string>>>() }
|
||||
};
|
||||
|
||||
// Add by default the root directory
|
||||
results["directories"].Add(new Dictionary<string, IList<string>>
|
||||
{
|
||||
{ "path", new List<string>() },
|
||||
{ "files", new List<string>() }
|
||||
});
|
||||
var rootDirectory = new MpdDirectory("/");
|
||||
|
||||
foreach (var line in response)
|
||||
{
|
||||
if (line.Key.Equals("file"))
|
||||
{
|
||||
results["directories"].Last()["files"].Add(line.Value);
|
||||
rootDirectory.AddFile(line.Value);
|
||||
}
|
||||
|
||||
if (line.Key.Equals("directory"))
|
||||
{
|
||||
results["directories"].Add(new Dictionary<string, IList<string>>
|
||||
{
|
||||
{ "path", new []{ line.Value } },
|
||||
{ "files", new List<string>() }
|
||||
});
|
||||
rootDirectory.AddDirectory(line.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
return rootDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,9 +110,10 @@ namespace LibMpc
|
||||
// TODO: Extend command: < update [URI] >
|
||||
public string Value => "update";
|
||||
|
||||
public IDictionary<string, string> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
public string FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
return response.ToDefaultDictionary();
|
||||
// TODO:
|
||||
return response.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using LibMpc.Types;
|
||||
|
||||
namespace LibMpc
|
||||
{
|
||||
@ -23,9 +24,10 @@ namespace LibMpc
|
||||
|
||||
public string Value => string.Join(" ", "disableoutput", _outputId);
|
||||
|
||||
public IDictionary<string, string> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
public string FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
return response.ToDefaultDictionary();
|
||||
// TODO:
|
||||
return response.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,9 +45,10 @@ namespace LibMpc
|
||||
|
||||
public string Value => string.Join(" ", "enableoutput", _outputId);
|
||||
|
||||
public IDictionary<string, string> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
public string FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
return response.ToDefaultDictionary();
|
||||
// TODO:
|
||||
return response.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,29 +57,21 @@ namespace LibMpc
|
||||
/// <summary>
|
||||
/// Shows information about all outputs.
|
||||
/// </summary>
|
||||
public class Outputs : IMpcCommand<IList<IDictionary<string, string>>>
|
||||
public class Outputs : IMpcCommand<IEnumerable<MpdOutput>>
|
||||
{
|
||||
public string Value => "outputs";
|
||||
|
||||
public IDictionary<string, IList<IDictionary<string, string>>> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
public IEnumerable<MpdOutput> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
var result = new Dictionary<string, IList<IDictionary<string, string>>>
|
||||
{
|
||||
{ "outputs", new List<IDictionary<string, string>>() }
|
||||
};
|
||||
var result = new List<MpdOutput>();
|
||||
|
||||
for (var i = 0; i < response.Count; i += 3)
|
||||
{
|
||||
var outputId = response[i].Value;
|
||||
var outputId = int.Parse(response[i].Value);
|
||||
var outputName = response[i + 1].Value;
|
||||
var outputEnabled = response[i + 2].Value;
|
||||
var outputEnabled = bool.Parse(response[i + 2].Value);
|
||||
|
||||
result["outputs"].Add(new Dictionary<string, string>
|
||||
{
|
||||
{"id", outputId},
|
||||
{"name", outputName},
|
||||
{"enabled", outputEnabled}
|
||||
});
|
||||
result.Add(new MpdOutput(outputId, outputName, outputEnabled));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -14,16 +14,13 @@ namespace LibMpc
|
||||
// TODO: commands
|
||||
// TODO: notcommands
|
||||
|
||||
public class TagTypes : IMpcCommand<IList<string>>
|
||||
public class TagTypes : IMpcCommand<IEnumerable<string>>
|
||||
{
|
||||
public string Value => "tagtypes";
|
||||
|
||||
IDictionary<string, IList<string>> IMpcCommand<IList<string>>.FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
public IEnumerable<string> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
var result = new Dictionary<string, IList<string>>
|
||||
{
|
||||
{ "tagtypes", response.Where(item => item.Key.Equals("tagtype")).Select(item => item.Value).ToList() }
|
||||
};
|
||||
var result = response.Where(item => item.Key.Equals("tagtype")).Select(item => item.Value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -3,18 +3,10 @@ using System.Linq;
|
||||
|
||||
namespace LibMpc
|
||||
{
|
||||
public interface IMpcCommand<T>
|
||||
public interface IMpcCommand<out T>
|
||||
{
|
||||
string Value { get; }
|
||||
|
||||
IDictionary<string, T> FormatResponse(IList<KeyValuePair<string, string>> response);
|
||||
}
|
||||
|
||||
internal static class MpdCommandExtensions
|
||||
{
|
||||
public static IDictionary<string, string> ToDefaultDictionary(this IList<KeyValuePair<string, string>> items)
|
||||
{
|
||||
return items.ToDictionary(item => item.Key, item => item.Value);
|
||||
}
|
||||
T FormatResponse(IList<KeyValuePair<string, string>> response);
|
||||
}
|
||||
}
|
@ -6,19 +6,19 @@ namespace LibMpc
|
||||
public interface IMpdResponse<T>
|
||||
{
|
||||
IMpdResponseState State { get; }
|
||||
IDictionary<string, T> Body { get; }
|
||||
T Body { get; }
|
||||
}
|
||||
|
||||
public class MpdResponse<T> : IMpdResponse<T>
|
||||
{
|
||||
public MpdResponse(string endLine, IDictionary<string, T> body, bool connected)
|
||||
public MpdResponse(string endLine, T body, bool connected)
|
||||
{
|
||||
State = new MpdResponseState(endLine, connected);
|
||||
Body = body;
|
||||
}
|
||||
|
||||
public IMpdResponseState State { get; }
|
||||
public IDictionary<string, T> Body { get; }
|
||||
public T Body { get; }
|
||||
}
|
||||
|
||||
public static class CheckNotNullExtension
|
||||
|
@ -1,544 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace LibMpc
|
||||
{
|
||||
/// <summary>
|
||||
/// The MpdFile class contains all meta data for a file of the MPD.
|
||||
/// </summary>
|
||||
public class MpdFile
|
||||
{
|
||||
private const string TAG_FILE = "file";
|
||||
private const string TAG_TIME = "Time";
|
||||
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 const string TAG_POS = "Pos";
|
||||
private const string TAG_ID = "Id";
|
||||
|
||||
private const int NO_TIME = -1;
|
||||
private const string NO_ALBUM = null;
|
||||
private const string NO_ARTIST = null;
|
||||
private const string NO_TITLE = null;
|
||||
private const string NO_TRACK = null;
|
||||
private const string NO_NAME = null;
|
||||
private const string NO_GENRE = null;
|
||||
private const string NO_DATE = null;
|
||||
private const string NO_COMPOSER = null;
|
||||
private const string NO_PERFORMER = null;
|
||||
private const string NO_COMMENT = null;
|
||||
private const int NO_DISC = -1;
|
||||
private const int NO_POS = -1;
|
||||
private const int NO_ID = -1;
|
||||
|
||||
private readonly string file;
|
||||
private readonly int time;
|
||||
private readonly string album;
|
||||
private readonly string artist;
|
||||
private readonly string title;
|
||||
private readonly string track;
|
||||
private readonly string name;
|
||||
private readonly string genre;
|
||||
private readonly string date;
|
||||
private readonly string composer;
|
||||
private readonly string performer;
|
||||
private readonly string comment;
|
||||
private readonly int disc;
|
||||
private readonly int pos;
|
||||
private readonly int id;
|
||||
/// <summary>
|
||||
/// The name and path of the file.
|
||||
/// </summary>
|
||||
public string File { get { return this.file; } }
|
||||
/// <summary>
|
||||
/// The length of the file in seconds.
|
||||
/// </summary>
|
||||
public int Time { get { return this.time; } }
|
||||
/// <summary>
|
||||
/// The album of the file.
|
||||
/// </summary>
|
||||
public string Album { get { return this.album; } }
|
||||
/// <summary>
|
||||
/// The artist of the file.
|
||||
/// </summary>
|
||||
public string Artist { get { return this.artist; } }
|
||||
/// <summary>
|
||||
/// The title of the file.
|
||||
/// </summary>
|
||||
public string Title { get { return this.title; } }
|
||||
/// <summary>
|
||||
/// The value of the track property of the file.
|
||||
/// </summary>
|
||||
public string Track { get { return this.track; } }
|
||||
/// <summary>
|
||||
/// The name of the song.
|
||||
/// </summary>
|
||||
public string Name { get { return this.name; } }
|
||||
/// <summary>
|
||||
/// The genre of the song.
|
||||
/// </summary>
|
||||
public string Genre { get { return this.genre; } }
|
||||
/// <summary>
|
||||
/// The date the song was released.
|
||||
/// </summary>
|
||||
public string Date { get { return this.date; } }
|
||||
/// <summary>
|
||||
/// The composer of the song.
|
||||
/// </summary>
|
||||
public string Composer { get { return this.composer; } }
|
||||
/// <summary>
|
||||
/// The performer of the song.
|
||||
/// </summary>
|
||||
public string Performer { get { return this.performer; } }
|
||||
/// <summary>
|
||||
/// A comment to the file.
|
||||
/// </summary>
|
||||
public string Comment { get { return this.comment; } }
|
||||
/// <summary>
|
||||
/// The number of the disc on a multidisc album.
|
||||
/// </summary>
|
||||
public int Disc { get { return this.disc; } }
|
||||
/// <summary>
|
||||
/// The index of the file in a playlist.
|
||||
/// </summary>
|
||||
public int Pos { get { return this.pos; } }
|
||||
/// <summary>
|
||||
/// The id of the file in a playlist.
|
||||
/// </summary>
|
||||
public int Id { get { return this.id; } }
|
||||
/// <summary>
|
||||
/// If the MpdFile has the <see cref="Time"/> property set.
|
||||
/// </summary>
|
||||
public bool HasTime { get { return this.time != NO_TIME; } }
|
||||
/// <summary>
|
||||
/// If the MpdFile has the <see cref="Album"/> property set.
|
||||
/// </summary>
|
||||
public bool HasAlbum { get { return this.album != NO_ALBUM; } }
|
||||
/// <summary>
|
||||
/// If the MpdFile has the <see cref="Artist"/> property set.
|
||||
/// </summary>
|
||||
public bool HasArtist { get { return this.artist != NO_ARTIST; } }
|
||||
/// <summary>
|
||||
/// If the MpdFile has the <see cref="Title"/> property set.
|
||||
/// </summary>
|
||||
public bool HasTitle { get { return this.title != NO_TITLE; } }
|
||||
/// <summary>
|
||||
/// If the MpdFile has the <see cref="Track"/> property set.
|
||||
/// </summary>
|
||||
public bool HasTrack { get { return this.track != NO_TRACK; } }
|
||||
/// <summary>
|
||||
/// If the MpdFile has the <see cref="Name"/> property set.
|
||||
/// </summary>
|
||||
public bool HasName { get { return this.name != NO_NAME; } }
|
||||
/// <summary>
|
||||
/// If the MpdFile has the <see cref="Genre"/> property set.
|
||||
/// </summary>
|
||||
public bool HasGenre { get { return this.genre != NO_GENRE; } }
|
||||
/// <summary>
|
||||
/// If the MpdFile has the <see cref="Date"/> property set.
|
||||
/// </summary>
|
||||
public bool HasDate { get { return this.date != NO_DATE; } }
|
||||
/// <summary>
|
||||
/// If the MpdFile has the <see cref="Composer"/> property set.
|
||||
/// </summary>
|
||||
public bool HasComposer { get { return this.composer != NO_COMPOSER; } }
|
||||
/// <summary>
|
||||
/// If the MpdFile has the <see cref="Performer"/> property set.
|
||||
/// </summary>
|
||||
public bool HasPerformer { get { return this.performer != NO_PERFORMER; } }
|
||||
/// <summary>
|
||||
/// If the MpdFile has the <see cref="Comment"/> property set.
|
||||
/// </summary>
|
||||
public bool HasComment { get { return this.comment != NO_COMMENT; } }
|
||||
/// <summary>
|
||||
/// If the MpdFile has the <see cref="Disc"/> property set.
|
||||
/// </summary>
|
||||
public bool HasDisc { get { return this.disc != NO_DISC; } }
|
||||
/// <summary>
|
||||
/// If the MpdFile has the <see cref="Pos"/> property set.
|
||||
/// </summary>
|
||||
public bool HasPos { get { return this.pos != NO_POS; } }
|
||||
/// <summary>
|
||||
/// If the MpdFile has the <see cref="Id"/> property set.
|
||||
/// </summary>
|
||||
public bool HasId { get { return this.id != NO_ID; } }
|
||||
/// <summary>
|
||||
/// Creates a new MpdFile.
|
||||
/// </summary>
|
||||
/// <param name="file">The name and path of the file.</param>
|
||||
/// <param name="time">The length of the file in seconds.</param>
|
||||
/// <param name="album">The album of the file.</param>
|
||||
/// <param name="artist">The artist of the file.</param>
|
||||
/// <param name="title">The title of the file.</param>
|
||||
/// <param name="track">The value of the track property of the file.</param>
|
||||
/// <param name="name">The name of the song.</param>
|
||||
/// <param name="genre">The genre of the song.</param>
|
||||
/// <param name="date">The date the song was released.</param>
|
||||
/// <param name="composer">The composer of the song.</param>
|
||||
/// <param name="performer">The performer of the song.</param>
|
||||
/// <param name="comment">A comment to the file.</param>
|
||||
/// <param name="disc">The number of the disc on a multidisc album.</param>
|
||||
/// <param name="pos">The index of the file in a playlist.</param>
|
||||
/// <param name="id">The id of the file in a playlist.</param>
|
||||
public MpdFile(string file,
|
||||
int time,
|
||||
string album,
|
||||
string artist,
|
||||
string title,
|
||||
string track,
|
||||
string name,
|
||||
string genre,
|
||||
string date,
|
||||
string composer,
|
||||
string performer,
|
||||
string comment,
|
||||
int disc,
|
||||
int pos,
|
||||
int id)
|
||||
{
|
||||
if (file == null)
|
||||
throw new ArgumentNullException("file");
|
||||
|
||||
this.file = file;
|
||||
this.time = time;
|
||||
this.album = album;
|
||||
this.artist = artist;
|
||||
this.title = title;
|
||||
this.track = track;
|
||||
this.name = name;
|
||||
this.genre = genre;
|
||||
this.date = date;
|
||||
this.composer = composer;
|
||||
this.performer = performer;
|
||||
this.comment = comment;
|
||||
this.disc = disc;
|
||||
this.pos = pos;
|
||||
this.id = id;
|
||||
}
|
||||
/// <summary>
|
||||
/// A string containing all the properties of the file.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
appendString(builder, TAG_FILE, this.file);
|
||||
if (this.HasTime)
|
||||
appendInt(builder, TAG_TIME, this.time);
|
||||
if (this.HasAlbum)
|
||||
appendString(builder, TAG_ALBUM, this.album);
|
||||
if (this.HasArtist)
|
||||
appendString(builder, TAG_ARTIST, this.artist);
|
||||
if (this.HasTitle)
|
||||
appendString(builder, TAG_TITLE, this.title);
|
||||
if (this.HasTrack)
|
||||
appendString(builder, TAG_TRACK, this.track);
|
||||
if (this.HasName)
|
||||
appendString(builder, TAG_NAME, this.name);
|
||||
if (this.HasGenre)
|
||||
appendString(builder, TAG_GENRE, this.genre);
|
||||
if (this.HasDate)
|
||||
appendString(builder, TAG_DATE, this.date);
|
||||
if (this.HasComposer)
|
||||
appendString(builder, TAG_COMPOSER, this.composer);
|
||||
if (this.HasPerformer)
|
||||
appendString(builder, TAG_PERFORMER, this.performer);
|
||||
if (this.HasComment)
|
||||
appendString(builder, TAG_COMMENT, this.comment);
|
||||
if (this.HasDisc)
|
||||
appendInt(builder, TAG_DISC, this.disc);
|
||||
if (this.HasPos)
|
||||
appendInt(builder, TAG_POS, this.pos);
|
||||
if (this.HasId)
|
||||
appendInt(builder, TAG_ID, this.id);
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
private static void appendString(StringBuilder builder, string name, string value)
|
||||
{
|
||||
builder.Append(name);
|
||||
builder.Append(": ");
|
||||
builder.Append(value);
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
private static void appendInt(StringBuilder builder, string name, int value)
|
||||
{
|
||||
builder.Append(name);
|
||||
builder.Append(": ");
|
||||
builder.Append(value);
|
||||
builder.AppendLine();
|
||||
}
|
||||
/*
|
||||
/// <summary>
|
||||
/// Returns a MpdFile object from a MpdResponse object.
|
||||
/// </summary>
|
||||
/// <param name="response">The response of the MPD server.</param>
|
||||
/// <returns>A new MpdFile object build from the MpdResponse object.</returns>
|
||||
public static MpdFile build(MpdResponse response)
|
||||
{
|
||||
if (response == null)
|
||||
throw new ArgumentNullException("response");
|
||||
|
||||
string file = null;
|
||||
int time = NO_TIME;
|
||||
string album = NO_ALBUM;
|
||||
string artist = NO_ARTIST;
|
||||
string title = NO_TITLE;
|
||||
string track = NO_TRACK;
|
||||
string name = NO_NAME;
|
||||
string genre = NO_GENRE;
|
||||
string date = NO_DATE;
|
||||
string composer = NO_COMPOSER;
|
||||
string performer = NO_PERFORMER;
|
||||
string comment = NO_COMMENT;
|
||||
int disc = NO_DISC;
|
||||
int pos = NO_POS;
|
||||
int id = NO_ID;
|
||||
|
||||
|
||||
foreach (KeyValuePair<string, string> line in response)
|
||||
{
|
||||
if( line.Key != null )
|
||||
switch (line.Key)
|
||||
{
|
||||
case TAG_FILE:
|
||||
file = line.Value;
|
||||
break;
|
||||
case TAG_TIME:
|
||||
int tryTime;
|
||||
if( int.TryParse( line.Value, out tryTime ) )
|
||||
time = tryTime;
|
||||
break;
|
||||
case TAG_ALBUM:
|
||||
album = line.Value;
|
||||
break;
|
||||
case TAG_ARTIST:
|
||||
artist = line.Value;
|
||||
break;
|
||||
case TAG_TITLE:
|
||||
title = line.Value;
|
||||
break;
|
||||
case TAG_TRACK:
|
||||
track = line.Value;
|
||||
break;
|
||||
case TAG_NAME:
|
||||
name = line.Value;
|
||||
break;
|
||||
case TAG_GENRE:
|
||||
genre = line.Value;
|
||||
break;
|
||||
case TAG_DATE:
|
||||
date = line.Value;
|
||||
break;
|
||||
case TAG_COMPOSER:
|
||||
composer = line.Value;
|
||||
break;
|
||||
case TAG_PERFORMER:
|
||||
performer = line.Value;
|
||||
break;
|
||||
case TAG_COMMENT:
|
||||
comment = line.Value;
|
||||
break;
|
||||
case TAG_DISC:
|
||||
int tryDisc;
|
||||
if (int.TryParse(line.Value, out tryDisc))
|
||||
disc = tryDisc;
|
||||
break;
|
||||
case TAG_POS:
|
||||
int tryPos;
|
||||
if (int.TryParse(line.Value, out tryPos))
|
||||
pos = tryPos;
|
||||
break;
|
||||
case TAG_ID:
|
||||
int tryId;
|
||||
if (int.TryParse(line.Value, out tryId))
|
||||
id = tryId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (file == null)
|
||||
return null;
|
||||
else
|
||||
return new MpdFile(
|
||||
file,
|
||||
time,
|
||||
album,
|
||||
artist,
|
||||
title,
|
||||
track,
|
||||
name,
|
||||
genre,
|
||||
date,
|
||||
composer,
|
||||
performer,
|
||||
comment,
|
||||
disc,
|
||||
pos,
|
||||
id);
|
||||
}
|
||||
/// <summary>
|
||||
/// Builds a list of MpdFile objects from a MpdResponse object.
|
||||
/// </summary>
|
||||
/// <param name="response">The MpdResponse object to build the list of MpdFiles from.</param>
|
||||
/// <returns>A list ob MpdFiles built from the MpdResponse object.</returns>
|
||||
public static List<MpdFile> buildList(MpdResponse response)
|
||||
{
|
||||
if (response == null)
|
||||
throw new ArgumentNullException("response");
|
||||
|
||||
List<MpdFile> ret = new List<MpdFile>();
|
||||
|
||||
string file = null;
|
||||
int time = NO_TIME;
|
||||
string album = NO_ALBUM;
|
||||
string artist = NO_ARTIST;
|
||||
string title = NO_TITLE;
|
||||
string track = NO_TRACK;
|
||||
string name = NO_NAME;
|
||||
string genre = NO_GENRE;
|
||||
string date = NO_DATE;
|
||||
string composer = NO_COMPOSER;
|
||||
string performer = NO_PERFORMER;
|
||||
string comment = NO_COMMENT;
|
||||
int disc = NO_DISC;
|
||||
int pos = NO_POS;
|
||||
int id = NO_ID;
|
||||
|
||||
|
||||
foreach (KeyValuePair<string, string> line in response)
|
||||
{
|
||||
if( line.Key != null )
|
||||
switch (line.Key)
|
||||
{
|
||||
case TAG_FILE:
|
||||
if( file != null )
|
||||
ret.Add( new MpdFile(
|
||||
file,
|
||||
time,
|
||||
album,
|
||||
artist,
|
||||
title,
|
||||
track,
|
||||
name,
|
||||
genre,
|
||||
date,
|
||||
composer,
|
||||
performer,
|
||||
comment,
|
||||
disc,
|
||||
pos,
|
||||
id ) );
|
||||
|
||||
file = line.Value;
|
||||
|
||||
time = NO_TIME;
|
||||
album = NO_ALBUM;
|
||||
artist = NO_ARTIST;
|
||||
title = NO_TITLE;
|
||||
track = NO_TRACK;
|
||||
name = NO_NAME;
|
||||
genre = NO_GENRE;
|
||||
date = NO_DATE;
|
||||
composer = NO_COMPOSER;
|
||||
performer = NO_PERFORMER;
|
||||
comment = NO_COMMENT;
|
||||
disc = NO_DISC;
|
||||
pos = NO_POS;
|
||||
id = NO_ID;
|
||||
|
||||
break;
|
||||
case TAG_TIME:
|
||||
int tryTime;
|
||||
if( int.TryParse( line.Value, out tryTime ) )
|
||||
time = tryTime;
|
||||
break;
|
||||
case TAG_ALBUM:
|
||||
album = line.Value;
|
||||
break;
|
||||
case TAG_ARTIST:
|
||||
artist = line.Value;
|
||||
break;
|
||||
case TAG_TITLE:
|
||||
title = line.Value;
|
||||
break;
|
||||
case TAG_TRACK:
|
||||
track = line.Value;
|
||||
|
||||
// TODO:
|
||||
int tryTrack;
|
||||
if (int.TryParse(line.Value, out tryTrack))
|
||||
track = tryTrack;
|
||||
|
||||
break;
|
||||
case TAG_NAME:
|
||||
name = line.Value;
|
||||
break;
|
||||
case TAG_GENRE:
|
||||
genre = line.Value;
|
||||
break;
|
||||
case TAG_DATE:
|
||||
date = line.Value;
|
||||
break;
|
||||
case TAG_COMPOSER:
|
||||
composer = line.Value;
|
||||
break;
|
||||
case TAG_PERFORMER:
|
||||
performer = line.Value;
|
||||
break;
|
||||
case TAG_COMMENT:
|
||||
comment = line.Value;
|
||||
break;
|
||||
case TAG_DISC:
|
||||
int tryDisc;
|
||||
if (int.TryParse(line.Value, out tryDisc))
|
||||
disc = tryDisc;
|
||||
break;
|
||||
case TAG_POS:
|
||||
int tryPos;
|
||||
if (int.TryParse(line.Value, out tryPos))
|
||||
pos = tryPos;
|
||||
break;
|
||||
case TAG_ID:
|
||||
int tryId;
|
||||
if (int.TryParse(line.Value, out tryId))
|
||||
id = tryId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (file != null)
|
||||
ret.Add(new MpdFile(
|
||||
file,
|
||||
time,
|
||||
album,
|
||||
artist,
|
||||
title,
|
||||
track,
|
||||
name,
|
||||
genre,
|
||||
date,
|
||||
composer,
|
||||
performer,
|
||||
comment,
|
||||
disc,
|
||||
pos,
|
||||
id ));
|
||||
|
||||
return ret;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace LibMpc
|
||||
{
|
||||
/// <summary>
|
||||
/// The MpdOutput class contains all attributes of an output device of the MPD.
|
||||
/// </summary>
|
||||
public class MpdOutput
|
||||
{
|
||||
private readonly int id;
|
||||
private readonly string name;
|
||||
private readonly bool enabled;
|
||||
/// <summary>
|
||||
/// The id of the output.
|
||||
/// </summary>
|
||||
public int Id { get { return this.id; } }
|
||||
/// <summary>
|
||||
/// The name of the output.
|
||||
/// </summary>
|
||||
public string Name { get { return this.name; } }
|
||||
/// <summary>
|
||||
/// If the output is enabled.
|
||||
/// </summary>
|
||||
public bool IsEnabled { get { return this.enabled; } }
|
||||
/// <summary>
|
||||
/// Creates a new MpdOutput object.
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the output.</param>
|
||||
/// <param name="name">The name of the output.</param>
|
||||
/// <param name="enabled">If the output is enabled.</param>
|
||||
public MpdOutput(int id, string name, bool enabled)
|
||||
{
|
||||
if (name == null)
|
||||
throw new ArgumentNullException("name");
|
||||
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a string representation of the object mainly for debuging purpose.
|
||||
/// </summary>
|
||||
/// <returns>A string representation of the object.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return this.id + "::" + this.name + "::" + this.enabled;
|
||||
}
|
||||
}
|
||||
}
|
70
LibMpc/Types/MpdDirectory.cs
Normal file
70
LibMpc/Types/MpdDirectory.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace LibMpc.Types
|
||||
{
|
||||
public class MpdDirectory
|
||||
{
|
||||
private readonly IList<MpdFile> _files = new List<MpdFile>();
|
||||
private readonly IList<MpdDirectory> _subDirectories = new List<MpdDirectory>();
|
||||
|
||||
public MpdDirectory(string path)
|
||||
{
|
||||
path.CheckNotNull();
|
||||
|
||||
Path = path;
|
||||
|
||||
var name = path.Split('/').Last();
|
||||
Name = string.IsNullOrEmpty(name) ? "root" : name;
|
||||
}
|
||||
|
||||
public string Path { get; }
|
||||
public string Name { get; }
|
||||
public IEnumerable<MpdFile> Files => _files;
|
||||
public IEnumerable<MpdDirectory> SubDirectories => _subDirectories;
|
||||
|
||||
internal void AddFile(string file)
|
||||
{
|
||||
var filePath = file.Split('/');
|
||||
var name = filePath[filePath.Length - 1];
|
||||
|
||||
if (filePath.Length == 1)
|
||||
{
|
||||
_files.Add(new MpdFile(name));
|
||||
}
|
||||
else
|
||||
{
|
||||
var filePathWithoutCurrentDirectory = string.Join("/", filePath.Skip(1));
|
||||
foreach (var subDirectory in _subDirectories)
|
||||
{
|
||||
if (subDirectory.Path.Equals(filePath[0]))
|
||||
{
|
||||
subDirectory.AddFile(filePathWithoutCurrentDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddDirectory(string directory)
|
||||
{
|
||||
var directoryPath = directory.Split('/');
|
||||
var name = directoryPath[directoryPath.Length - 1];
|
||||
|
||||
if (directoryPath.Length == 1)
|
||||
{
|
||||
_subDirectories.Add(new MpdDirectory(name));
|
||||
}
|
||||
else
|
||||
{
|
||||
var directoryPathWithoutCurrentDirectory = string.Join("/", directoryPath.Skip(1));
|
||||
foreach (var subDirectory in _subDirectories)
|
||||
{
|
||||
if (subDirectory.Path.Equals(directoryPath[0]))
|
||||
{
|
||||
subDirectory.AddDirectory(directoryPathWithoutCurrentDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
73
LibMpc/Types/MpdFile.cs
Normal file
73
LibMpc/Types/MpdFile.cs
Normal file
@ -0,0 +1,73 @@
|
||||
namespace LibMpc.Types
|
||||
{
|
||||
public class MpdFileBuidler
|
||||
{
|
||||
private const string TagFile = "file";
|
||||
private const string TagTime = "Time";
|
||||
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";
|
||||
private const string TagPos = "Pos";
|
||||
private const string TagId = "Id";
|
||||
|
||||
private MpdFile _mpdFile;
|
||||
|
||||
public bool IsInitialized => _mpdFile != null;
|
||||
|
||||
public MpdFileBuidler Init(string file)
|
||||
{
|
||||
_mpdFile = new MpdFile(file);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MpdFileBuidler WithProperty(string tag, string value)
|
||||
{
|
||||
_mpdFile.CheckNotNull();
|
||||
|
||||
// TODO: Parse tag
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MpdFile Build()
|
||||
{
|
||||
return _mpdFile;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The MpdFile class contains all meta data for a file of the MPD.
|
||||
/// </summary>
|
||||
public class MpdFile
|
||||
{
|
||||
public MpdFile(string file)
|
||||
{
|
||||
File = file;
|
||||
}
|
||||
|
||||
public string File { get; }
|
||||
public int Time { get; internal set; } = -1;
|
||||
public string Album { get; internal set; } = string.Empty;
|
||||
public string Artist { get; internal set; } = string.Empty;
|
||||
public string Title { get; internal set; } = string.Empty;
|
||||
public string Track { get; internal set; } = string.Empty;
|
||||
public string Name { get; internal set; } = string.Empty;
|
||||
public string Genre { get; internal set; } = string.Empty;
|
||||
public string Date { get; internal set; } = string.Empty;
|
||||
public string Composer { get; internal set; } = string.Empty;
|
||||
public string Performer { get; internal set; } = string.Empty;
|
||||
public string Comment { get; internal set; } = string.Empty;
|
||||
public int Disc { get; internal set; } = -1;
|
||||
public int Pos { get; internal set; } = -1;
|
||||
public int Id { get; internal set; } = -1;
|
||||
}
|
||||
}
|
21
LibMpc/Types/MpdOutput.cs
Normal file
21
LibMpc/Types/MpdOutput.cs
Normal file
@ -0,0 +1,21 @@
|
||||
namespace LibMpc.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// The MpdOutput class contains all attributes of an output device of the MPD.
|
||||
/// </summary>
|
||||
public class MpdOutput
|
||||
{
|
||||
public MpdOutput(int id, string name, bool enabled)
|
||||
{
|
||||
name.CheckNotNull();
|
||||
|
||||
Id = id;
|
||||
Name = name;
|
||||
IsEnabled = enabled;
|
||||
}
|
||||
|
||||
public int Id { get; }
|
||||
public string Name { get; }
|
||||
public bool IsEnabled { get; }
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using LibMpc;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
@ -25,11 +26,11 @@ namespace LibMpcTest
|
||||
var connected = Task.Run(async () => await _mpc.ConnectAsync()).Result;
|
||||
if (connected)
|
||||
{
|
||||
Console.Out.WriteLine("Connected to MPD.");
|
||||
WriteLine("Connected to MPD.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Out.WriteLine("Could not connect to MPD.");
|
||||
WriteLine("Could not connect to MPD.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,11 +39,10 @@ namespace LibMpcTest
|
||||
{
|
||||
var response = await _mpc.SendAsync(new Commands.Reflection.TagTypes());
|
||||
|
||||
Console.Out.WriteLine("TagTypesTest Result:");
|
||||
Console.Out.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
|
||||
WriteLine("TagTypesTest Result:");
|
||||
WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
|
||||
|
||||
Assert.True(response.Response.Body.Keys.Contains("tagtypes"));
|
||||
Assert.True(response.Response.Body.Values.Any());
|
||||
Assert.True(response.Response.Body.Count().Equals(17));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -50,16 +50,25 @@ namespace LibMpcTest
|
||||
{
|
||||
var response = await _mpc.SendAsync(new Commands.Database.ListAll());
|
||||
|
||||
Console.Out.WriteLine("ListAllTest Result:");
|
||||
Console.Out.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
|
||||
WriteLine("ListAllTest Result:");
|
||||
WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
|
||||
|
||||
Assert.True(response.Response.Body.Keys.Contains("directories"));
|
||||
Assert.True(response.Response.Body["directories"].Count.Equals(5));
|
||||
Assert.True(response.Response.Body.SubDirectories.Count().Equals(4));
|
||||
Assert.True(response.Response.Body.Files.Count().Equals(3));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_mpc?.DisconnectAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
private void WriteLine(string value)
|
||||
{
|
||||
#if DEBUG
|
||||
Debug.WriteLine(value);
|
||||
#else
|
||||
Console.Out.WriteLine(value);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,23 +21,36 @@ tag: MUSICBRAINZ_ALBUMARTISTID
|
||||
tag: MUSICBRAINZ_TRACKID
|
||||
info_end
|
||||
directory: A long name directory with some spaces
|
||||
mtime: 1481622608
|
||||
mtime: 1482142041
|
||||
begin: A long name directory with some spaces
|
||||
song_begin: pouring-water-into-mug-of-coffee.mp3
|
||||
Time: 4
|
||||
Artist: Geek & Dummy
|
||||
Title: Sound effect: pouring water into mug of coffee
|
||||
Date: 2013
|
||||
Date: 2013
|
||||
mtime: 1481622059
|
||||
song_end
|
||||
directory: Sub Directory Two
|
||||
mtime: 1482142041
|
||||
begin: A long name directory with some spaces/Sub Directory Two
|
||||
song_begin: short-trouser-pants-zip-closing.mp3
|
||||
Time: 1
|
||||
Artist: Geek & Dummy
|
||||
Title: Sound effect: short trouser pants zip closing
|
||||
Date: 2013
|
||||
Date: 2013
|
||||
mtime: 1481622066
|
||||
mtime: 1481623577
|
||||
song_end
|
||||
song_begin: starting-engine-Ford-Mondeo-Mk-3-diesel.mp3
|
||||
Time: 6
|
||||
Artist: Geek & Dummy
|
||||
Title: Sound effect: starting engine - Ford Mondeo Mk 3 diesel
|
||||
Album: Geek & Dummy Sound Library
|
||||
Date: 2014
|
||||
Genre: soundfx
|
||||
mtime: 1481623577
|
||||
song_end
|
||||
end: A long name directory with some spaces/Sub Directory Two
|
||||
song_begin: pouring-water-into-mug-of-coffee.mp3
|
||||
Time: 4
|
||||
Artist: Geek & Dummy
|
||||
Title: Sound effect: pouring water into mug of coffee
|
||||
Date: 2013
|
||||
Date: 2013
|
||||
mtime: 1481623577
|
||||
song_end
|
||||
song_begin: Ghost-Sounds.mp3
|
||||
Time: 95
|
||||
@ -47,20 +60,11 @@ Album: Geek & Dummy Sound Library
|
||||
Date: 2014
|
||||
Date: 2014
|
||||
Genre: soundfx
|
||||
mtime: 1481622054
|
||||
song_end
|
||||
song_begin: starting-engine-Ford-Mondeo-Mk-3-diesel.mp3
|
||||
Time: 6
|
||||
Artist: Geek & Dummy
|
||||
Title: Sound effect: starting engine - Ford Mondeo Mk 3 diesel
|
||||
Album: Geek & Dummy Sound Library
|
||||
Date: 2014
|
||||
Genre: soundfx
|
||||
mtime: 1481622063
|
||||
mtime: 1481623577
|
||||
song_end
|
||||
end: A long name directory with some spaces
|
||||
directory: Directory
|
||||
mtime: 1481622608
|
||||
mtime: 1482142041
|
||||
begin: Directory
|
||||
song_begin: 2-Kids-Laughing.mp3
|
||||
Time: 30
|
||||
@ -70,7 +74,7 @@ Album: Geek & Dummy Sound Library
|
||||
Date: 2014
|
||||
Date: 2014
|
||||
Genre: soundfx
|
||||
mtime: 1481622083
|
||||
mtime: 1481623577
|
||||
song_end
|
||||
song_begin: ambient-noise-server-room.mp3
|
||||
Time: 71
|
||||
@ -80,20 +84,15 @@ Album: Geek & Dummy Sound Library
|
||||
Date: 2014
|
||||
Date: 2014
|
||||
Genre: soundfx
|
||||
mtime: 1481622020
|
||||
mtime: 1481623577
|
||||
song_end
|
||||
end: Directory
|
||||
directory: Directory With Spaces
|
||||
mtime: 1481622608
|
||||
mtime: 1482142041
|
||||
begin: Directory With Spaces
|
||||
song_begin: coin-spin-light.mp3
|
||||
Time: 5
|
||||
Artist: Geek & Dummy
|
||||
Title: Sound effect: coin spin (light coin)
|
||||
Date: 2013
|
||||
Date: 2013
|
||||
mtime: 1481622036
|
||||
song_end
|
||||
directory: SubDirectory One
|
||||
mtime: 1482142041
|
||||
begin: Directory With Spaces/SubDirectory One
|
||||
song_begin: central-locking-Ford-Mondeo-Mk-3.mp3
|
||||
Time: 5
|
||||
Artist: Geek & Dummy
|
||||
@ -102,7 +101,16 @@ Album: Geek & Dummy Sound Library
|
||||
Date: 2014
|
||||
Date: 2014
|
||||
Genre: soundfx
|
||||
mtime: 1481622024
|
||||
mtime: 1481623577
|
||||
song_end
|
||||
end: Directory With Spaces/SubDirectory One
|
||||
song_begin: coin-spin-light.mp3
|
||||
Time: 5
|
||||
Artist: Geek & Dummy
|
||||
Title: Sound effect: coin spin (light coin)
|
||||
Date: 2013
|
||||
Date: 2013
|
||||
mtime: 1481623577
|
||||
song_end
|
||||
song_begin: finger-snap-click.mp3
|
||||
Time: 0
|
||||
@ -112,11 +120,11 @@ Album: Geek & Dummy Sound Library
|
||||
Date: 2014
|
||||
Date: 2014
|
||||
Genre: soundfx
|
||||
mtime: 1481622047
|
||||
mtime: 1481623577
|
||||
song_end
|
||||
end: Directory With Spaces
|
||||
directory: _My Directory
|
||||
mtime: 1481622608
|
||||
mtime: 1482142041
|
||||
begin: _My Directory
|
||||
song_begin: gas-fire-lighting.mp3
|
||||
Time: 58
|
||||
@ -126,7 +134,7 @@ Album: Geek & Dummy Sound Library
|
||||
Date: 2014
|
||||
Date: 2014
|
||||
Genre: soundfx
|
||||
mtime: 1481622051
|
||||
mtime: 1481623577
|
||||
song_end
|
||||
end: _My Directory
|
||||
song_begin: teaspoon-stirring-mug-of-coffee.mp3
|
||||
@ -135,7 +143,7 @@ Artist: Geek & Dummy
|
||||
Title: Sound effect: teaspoon stirring mug of coffee
|
||||
Date: 2013
|
||||
Date: 2013
|
||||
mtime: 1481622029
|
||||
mtime: 1481623577
|
||||
song_end
|
||||
song_begin: whistle-kettle-boiling.mp3
|
||||
Time: 36
|
||||
@ -143,7 +151,7 @@ Artist: Geek & Dummy
|
||||
Title: Sound effect: whistle kettle boiling
|
||||
Date: 2013
|
||||
Date: 2013
|
||||
mtime: 1481622087
|
||||
mtime: 1481623577
|
||||
song_end
|
||||
song_begin: wine-glass-double-chink-clink-cheers.mp3
|
||||
Time: 1
|
||||
@ -151,5 +159,5 @@ Artist: Geek & Dummy
|
||||
Title: Sound effect: wine glass double chink/clink/cheers
|
||||
Date: 2013
|
||||
Date: 2013
|
||||
mtime: 1481622090
|
||||
mtime: 1481623577
|
||||
song_end
|
||||
|
Loading…
Reference in New Issue
Block a user