mirror of
https://github.com/ZetaKebab/MpcNET.git
synced 2025-01-14 22:18:43 +00:00
Bug in find command fixed.
This commit is contained in:
parent
b12ded8121
commit
ba83fbd824
@ -16,7 +16,7 @@ namespace LibMpc
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds songs in the database that is exactly "searchText".
|
/// Finds songs in the database that is exactly "searchText".
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Find : IMpcCommand<IEnumerable<MpdFile>>
|
public class Find : IMpcCommand<IEnumerable<IMpdFile>>
|
||||||
{
|
{
|
||||||
private readonly ITag _tag;
|
private readonly ITag _tag;
|
||||||
private readonly string _searchText;
|
private readonly string _searchText;
|
||||||
@ -29,25 +29,19 @@ namespace LibMpc
|
|||||||
|
|
||||||
public string Value => string.Join(" ", "find", _tag.Value, _searchText);
|
public string Value => string.Join(" ", "find", _tag.Value, _searchText);
|
||||||
|
|
||||||
public IEnumerable<MpdFile> FormatResponse(IList<KeyValuePair<string, string>> response)
|
public IEnumerable<IMpdFile> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||||
{
|
{
|
||||||
var results = new List<MpdFile>();
|
var results = new List<MpdFile>();
|
||||||
|
|
||||||
var mpdFile = MpdFile.EmptyFile;
|
|
||||||
foreach (var line in response)
|
foreach (var line in response)
|
||||||
{
|
{
|
||||||
if (line.Key.Equals("file"))
|
if (line.Key.Equals("file"))
|
||||||
{
|
{
|
||||||
if (mpdFile.IsInitialized)
|
results.Add(new MpdFile(line.Value));
|
||||||
{
|
|
||||||
results.Add(mpdFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
mpdFile = new MpdFile(line.Value);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mpdFile.AddTag(line.Key, line.Value);
|
results.Last().AddTag(line.Key, line.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
LibMpc/Types/IMpdFile.cs
Normal file
28
LibMpc/Types/IMpdFile.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace LibMpc.Types
|
||||||
|
{
|
||||||
|
public interface IMpdFilePath
|
||||||
|
{
|
||||||
|
string File { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IMpdFile : IMpdFilePath
|
||||||
|
{
|
||||||
|
int Time { get; }
|
||||||
|
string Album { get; }
|
||||||
|
string Artist { get; }
|
||||||
|
string Title { get; }
|
||||||
|
string Track { get; }
|
||||||
|
string Name { get; }
|
||||||
|
string Genre { get; }
|
||||||
|
string Date { get; }
|
||||||
|
string Composer { get; }
|
||||||
|
string Performer { get; }
|
||||||
|
string Comment { get; }
|
||||||
|
int Disc { get; }
|
||||||
|
int Pos { get; }
|
||||||
|
int Id { get; }
|
||||||
|
IDictionary<string, string> UnknownTags { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -5,10 +5,8 @@ namespace LibMpc.Types
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The MpdFile class contains all meta data for a file of the MPD.
|
/// The MpdFile class contains all meta data for a file of the MPD.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MpdFile
|
public class MpdFile : IMpdFile
|
||||||
{
|
{
|
||||||
public static readonly MpdFile EmptyFile = new MpdFile(string.Empty);
|
|
||||||
|
|
||||||
private const string TagTime = "Time";
|
private const string TagTime = "Time";
|
||||||
private const string TagArtist = "Artist";
|
private const string TagArtist = "Artist";
|
||||||
private const string TagAlbum = "Album";
|
private const string TagAlbum = "Album";
|
||||||
@ -28,8 +26,9 @@ namespace LibMpc.Types
|
|||||||
|
|
||||||
public MpdFile(string file)
|
public MpdFile(string file)
|
||||||
{
|
{
|
||||||
|
file.CheckNotNull();
|
||||||
|
|
||||||
File = file;
|
File = file;
|
||||||
IsInitialized = !string.IsNullOrEmpty(File);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string File { get; }
|
public string File { get; }
|
||||||
@ -49,8 +48,6 @@ namespace LibMpc.Types
|
|||||||
public int Id { get; private set; } = -1;
|
public int Id { get; private set; } = -1;
|
||||||
public IDictionary<string, string> UnknownTags => _unknownTags;
|
public IDictionary<string, string> UnknownTags => _unknownTags;
|
||||||
|
|
||||||
internal bool IsInitialized { get; }
|
|
||||||
|
|
||||||
internal void AddTag(string tag, string value)
|
internal void AddTag(string tag, string value)
|
||||||
{
|
{
|
||||||
switch (tag)
|
switch (tag)
|
||||||
|
@ -27,7 +27,7 @@ namespace LibMpcTest
|
|||||||
TestOutput.WriteLine("FindGenreTest Result:");
|
TestOutput.WriteLine("FindGenreTest Result:");
|
||||||
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
|
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
|
||||||
|
|
||||||
Assert.True(response.Response.Body.Count().Equals(6));
|
Assert.True(response.Response.Body.Count().Equals(7));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user