Skip to content

Commit

Permalink
Add readcomments support.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonTeixidor committed Mar 14, 2021
1 parent 17a4394 commit 2235a4c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
15 changes: 14 additions & 1 deletion examples/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ extern crate mpd;
use mpd::{Client, Query};
use std::net::TcpStream;

fn main() {
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut c = Client::new(TcpStream::connect("127.0.0.1:6600").unwrap()).unwrap();
println!("version: {:?}", c.version);
println!("status: {:?}", c.status());
println!("stuff: {:?}", c.find(&Query::new(), (1, 2)));

let now_playing = c.currentsong()?;
if let Some(song) = now_playing {
println!("Metadata:");
for row in c.readcomments(song)? {
if let Ok((k, v)) = row {
println!("{}: {}", k, v);
}
}
} else {
println!("No song playing.");
}
Ok(())
}
8 changes: 7 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl<S: Read + Write> Client<S> {
// TODO: search type what [...] [window start:end], searchadd type what [...]
// TODO: listallinfo [uri], listfiles [uri]
// TODO: list type [filtertype] [filterwhat] [...] [group] [grouptype] [...]
// TODO: searchaddpl name type what [...], readcomments
// TODO: searchaddpl name type what [...]

/// Find songs matching Query conditions.
pub fn find<W>(&mut self, query: &Query, window: W) -> Result<Vec<Song>>
Expand Down Expand Up @@ -412,6 +412,12 @@ impl<S: Read + Write> Client<S> {
self.run_command("lsinfo", path).and_then(|_| self.read_struct())
}

/// Returns raw metadata for file
pub fn readcomments<'a, P: ToSongPath>(&'a mut self, path: P) -> Result<impl Iterator<Item = Result<(String, String)>> + 'a> {
self.run_command("readcomments", path)?;
Ok(self.read_pairs())
}

// }}}

// Output methods {{{
Expand Down

0 comments on commit 2235a4c

Please sign in to comment.