mirror of
https://github.com/ZetaKebab/MpcNET.git
synced 2025-01-14 22:18:43 +00:00
Decoders command + test. Still to Assert response depending on build server.
This commit is contained in:
parent
ed2604f81b
commit
89990d5e81
@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LibMpc.Types;
|
||||
|
||||
namespace LibMpc
|
||||
{
|
||||
@ -53,7 +54,41 @@ namespace LibMpc
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: decoders
|
||||
public class Decoders : IMpcCommand<IEnumerable<MpdDecoderPlugin>>
|
||||
{
|
||||
public string Value => "decoders";
|
||||
|
||||
public IEnumerable<MpdDecoderPlugin> FormatResponse(IList<KeyValuePair<string, string>> response)
|
||||
{
|
||||
var result = new List<MpdDecoderPlugin>();
|
||||
|
||||
var mpdDecoderPlugin = MpdDecoderPlugin.Empty;
|
||||
foreach (var line in response)
|
||||
{
|
||||
if (line.Key.Equals("plugin"))
|
||||
{
|
||||
if (mpdDecoderPlugin.IsInitialized)
|
||||
{
|
||||
result.Add(mpdDecoderPlugin);
|
||||
}
|
||||
|
||||
mpdDecoderPlugin = new MpdDecoderPlugin(line.Value);
|
||||
}
|
||||
|
||||
if (line.Key.Equals("suffix") && mpdDecoderPlugin.IsInitialized)
|
||||
{
|
||||
mpdDecoderPlugin.AddSuffix(line.Value);
|
||||
}
|
||||
|
||||
if (line.Key.Equals("mime_type") && mpdDecoderPlugin.IsInitialized)
|
||||
{
|
||||
mpdDecoderPlugin.AddMediaType(line.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
36
LibMpc/Types/MpdDecoderPlugin.cs
Normal file
36
LibMpc/Types/MpdDecoderPlugin.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LibMpc.Types
|
||||
{
|
||||
public class MpdDecoderPlugin
|
||||
{
|
||||
public static readonly MpdDecoderPlugin Empty = new MpdDecoderPlugin(string.Empty);
|
||||
|
||||
private readonly IList<string> _suffixes = new List<string>();
|
||||
private readonly IList<string> _mediaTypes = new List<string>();
|
||||
|
||||
public MpdDecoderPlugin(string name)
|
||||
{
|
||||
name.CheckNotNull();
|
||||
|
||||
Name = name;
|
||||
IsInitialized = !string.IsNullOrEmpty(name);
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public IEnumerable<string> Suffixes => _suffixes;
|
||||
public IEnumerable<string> MediaTypes => _mediaTypes;
|
||||
|
||||
internal bool IsInitialized { get; }
|
||||
|
||||
internal void AddSuffix(string suffix)
|
||||
{
|
||||
_suffixes.Add(suffix);
|
||||
}
|
||||
|
||||
internal void AddMediaType(string type)
|
||||
{
|
||||
_mediaTypes.Add(type);
|
||||
}
|
||||
}
|
||||
}
|
@ -52,5 +52,16 @@ namespace LibMpcTest
|
||||
Assert.True(response.Response.Body.Any(handler => handler.Equals("gopher://")));
|
||||
Assert.True(response.Response.Body.Any(handler => handler.Equals("rtp://")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DecodersTest()
|
||||
{
|
||||
var response = await Mpc.SendAsync(new Commands.Reflection.Decoders());
|
||||
|
||||
TestOutput.WriteLine($"DecodersTest (decoders: {response.Response.Body.Count()}) Result:");
|
||||
TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
|
||||
|
||||
// TODO: Assert
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user