Compare commits

..

No commits in common. "26a3381a25d17dd51b4e617c0444e2cd36dd2da6" and "8e7a087e41255a7d2223d6bd1e02c231a166384d" have entirely different histories.

2 changed files with 11 additions and 9 deletions

View file

@ -1,4 +1,4 @@
use std::{collections::HashMap, path::Path};
use std::{path::Path, collections::HashMap};
use askama::Template;
use percent_encoding::percent_decode_str;
@ -176,8 +176,7 @@ struct UpdateQueueBody {
async fn post_queue_move(mut req: tide::Request<()>) -> tide::Result {
let body: UpdateQueueBody = req.body_json().await?;
let mut mpd = mpd::Mpd::connect().await?;
mpd.command(&format!("move {} {}", body.from, body.to))
.await?;
mpd.command(&format!("move {} {}", body.from, body.to)).await?;
Ok("".into())
}

View file

@ -104,6 +104,7 @@ impl Mpd {
stream.write_all(b"binarylimit 1048576\n").await?;
buffer.clear();
reader.read_line(&mut buffer).await?;
dbg!(&buffer);
Ok(Self { stream, reader })
}
@ -125,6 +126,7 @@ impl Mpd {
}
pub async fn command(&mut self, command: &str) -> anyhow::Result<CommandResult> {
dbg!(command);
let mut properties = Vec::new();
self.stream
@ -149,6 +151,7 @@ impl Mpd {
});
}
} else if buffer.starts_with("OK") {
dbg!(&properties);
break Ok(CommandResult {
properties,
binary: None,
@ -156,7 +159,7 @@ impl Mpd {
} else if buffer.starts_with("ACK") {
break Err(anyhow!(buffer));
} else {
println!("Unexpected MPD response {buffer}");
dbg!(&buffer);
}
}
}
@ -243,7 +246,7 @@ impl Mpd {
}
}
#[allow(clippy::manual_map)]
pub async fn ls(&mut self, path: &str) -> anyhow::Result<Vec<Entry>> {
fn get_filename(path: &str) -> String {
std::path::Path::new(path)
@ -253,7 +256,7 @@ impl Mpd {
}
let result = self
.command(&format!("lsinfo \"{}\"", Self::escape_str(path)))
.command(&format!("lsinfo \"{}\"", Self::escape_str(&path)))
.await?
.into_hashmaps(&["file", "directory", "playlist"]);
@ -262,18 +265,18 @@ impl Mpd {
.flat_map(|prop| {
if let Some(file) = prop.get("file") {
Some(Entry::Song {
name: prop.get("Title").unwrap_or(&get_filename(file)).clone(),
name: prop.get("Title").unwrap_or(&get_filename(&file)).clone(),
artist: prop.get("Artist").unwrap_or(&String::new()).clone(),
path: file.to_string(),
})
} else if let Some(file) = prop.get("directory") {
Some(Entry::Directory {
name: get_filename(file),
name: get_filename(&file),
path: file.to_string(),
})
} else if let Some(file) = prop.get("playlist") {
Some(Entry::Playlist {
name: get_filename(file),
name: get_filename(&file),
path: file.to_string(),
})
} else {