From 07e9161137e677d250c72a35b2daba45bc6f793e Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 8 Dec 2025 00:29:00 +0900 Subject: [PATCH] commands/currentsong: implement response parser --- .../querying_mpd_status/currentsong.rs | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/commands/querying_mpd_status/currentsong.rs b/src/commands/querying_mpd_status/currentsong.rs index 5d8329a7..357cf21e 100644 --- a/src/commands/querying_mpd_status/currentsong.rs +++ b/src/commands/querying_mpd_status/currentsong.rs @@ -1,8 +1,13 @@ +use std::collections::HashMap; + use serde::{Deserialize, Serialize}; use crate::{ + DbSongInfo, Priority, SongId, SongPosition, commands::{Command, CommandResponse, ResponseParserError, empty_command_request}, - response_tokenizer::ResponseAttributes, + response_tokenizer::{ + ResponseAttributes, get_and_parse_optional_property, get_and_parse_property, + }, }; /// Displays the song info of the current song (same song that is identified in status) @@ -10,8 +15,13 @@ pub struct CurrentSong; empty_command_request!(CurrentSong, "currentsong"); -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct CurrentSongResponse {} +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct CurrentSongResponse { + position: SongPosition, + id: SongId, + priority: Option, + song_info: DbSongInfo, +} impl CommandResponse<'_> for CurrentSongResponse { fn into_response_enum(self) -> crate::Response { @@ -23,7 +33,24 @@ impl CommandResponse<'_> for CurrentSongResponse { } fn parse(parts: ResponseAttributes<'_>) -> Result> { - unimplemented!() + let mut parts: HashMap<_, _> = parts.into_map()?; + + let position: SongPosition = get_and_parse_property!(parts, "Pos", Text); + let id: SongId = get_and_parse_property!(parts, "Id", Text); + let priority: Option = get_and_parse_optional_property!(parts, "Prio", Text); + + parts.remove("Pos"); + parts.remove("Id"); + parts.remove("Prio"); + + let song_info = DbSongInfo::parse_map(parts)?; + + Ok(CurrentSongResponse { + position, + id, + priority, + song_info, + }) } }