mirror of
				https://github.com/ZetaKebab/MpcNET.git
				synced 2025-10-31 02:59:49 +00:00 
			
		
		
		
	listplaylists command created + test.
This commit is contained in:
		| @@ -1,4 +1,8 @@ | ||||
| namespace LibMpc | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using LibMpc.Types; | ||||
|  | ||||
| namespace LibMpc | ||||
| { | ||||
|     public partial class Commands | ||||
|     { | ||||
| @@ -17,7 +21,32 @@ | ||||
|             /// </summary> | ||||
|             public static class Stored | ||||
|             { | ||||
|                  | ||||
|                 /// <summary> | ||||
|                 /// Prints a list of the playlist directory. | ||||
|                 /// </summary> | ||||
|                 public class ListPlaylists : IMpcCommand<IEnumerable<MpdPlaylist>> | ||||
|                 { | ||||
|                     public string Value => "listplaylists"; | ||||
|  | ||||
|                     public IEnumerable<MpdPlaylist> FormatResponse(IList<KeyValuePair<string, string>> response) | ||||
|                     { | ||||
|                         var result = new List<MpdPlaylist>(); | ||||
|  | ||||
|                         foreach (var line in response) | ||||
|                         { | ||||
|                             if (line.Key.Equals("playlist")) | ||||
|                             { | ||||
|                                 result.Add(new MpdPlaylist(line.Value)); | ||||
|                             } | ||||
|                             else if (line.Key.Equals("Last-Modified")) | ||||
|                             { | ||||
|                                 result.Last().AddLastModified(line.Value); | ||||
|                             } | ||||
|                         } | ||||
|  | ||||
|                         return result; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -15,7 +15,7 @@ namespace LibMpc | ||||
|     [DebuggerDisplay("Request: {Request.Command.Value} | Response Status: {Response.State.Status}")] | ||||
|     public class MpdMessage<T> : IMpdMessage<T> | ||||
|     { | ||||
|         private readonly Regex _linePattern = new Regex("^(?<key>[A-Za-z_]*):[ ]{0,1}(?<value>.*)$"); | ||||
|         private readonly Regex _linePattern = new Regex("^(?<key>[A-Za-z_-]*):[ ]{0,1}(?<value>.*)$"); | ||||
|         private readonly IList<string> _rawResponse; | ||||
|  | ||||
|         public MpdMessage(IMpcCommand<T> command, bool connected, IReadOnlyCollection<string> response) | ||||
|   | ||||
							
								
								
									
										23
									
								
								LibMpc/Types/MpdPlaylist.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								LibMpc/Types/MpdPlaylist.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| using System; | ||||
| using System.Globalization; | ||||
|  | ||||
| namespace LibMpc.Types | ||||
| { | ||||
|     public class MpdPlaylist | ||||
|     { | ||||
|         public MpdPlaylist(string name) | ||||
|         { | ||||
|             name.CheckNotNull(); | ||||
|  | ||||
|             Name = name; | ||||
|         } | ||||
|  | ||||
|         public string Name { get; } | ||||
|         public DateTime LastModified { get; private set; } | ||||
|  | ||||
|         internal void AddLastModified(string lastModified) | ||||
|         { | ||||
|             LastModified = DateTime.Parse(lastModified, CultureInfo.InvariantCulture); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										22
									
								
								LibMpcTest/Tests/PlaylistsCommandsTest.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								LibMpcTest/Tests/PlaylistsCommandsTest.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| using System.Threading.Tasks; | ||||
| using Newtonsoft.Json; | ||||
| using Xunit; | ||||
| using LibMpc; | ||||
| using System.Linq; | ||||
|  | ||||
| namespace LibMpcTest | ||||
| { | ||||
|     public partial class LibMpcTest | ||||
|     { | ||||
|         [Fact] | ||||
|         public async Task ListPlaylistsTest() | ||||
|         { | ||||
|             var response = await Mpc.SendAsync(new Commands.Playlists.Stored.ListPlaylists()); | ||||
|  | ||||
|             TestOutput.WriteLine($"ListPlaylistsTest Result:"); | ||||
|             TestOutput.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); | ||||
|  | ||||
|             Assert.True(response.Response.Body.Count().Equals(3)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 glucaci
					glucaci