Compare commits
2 commits
8e7a087e41
...
26a3381a25
Author | SHA1 | Date | |
---|---|---|---|
26a3381a25 | |||
138446e040 |
2 changed files with 9 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::{path::Path, collections::HashMap};
|
||||
use std::{collections::HashMap, path::Path};
|
||||
|
||||
use askama::Template;
|
||||
use percent_encoding::percent_decode_str;
|
||||
|
@ -176,7 +176,8 @@ 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())
|
||||
}
|
||||
|
||||
|
|
15
src/mpd.rs
15
src/mpd.rs
|
@ -104,7 +104,6 @@ impl Mpd {
|
|||
stream.write_all(b"binarylimit 1048576\n").await?;
|
||||
buffer.clear();
|
||||
reader.read_line(&mut buffer).await?;
|
||||
dbg!(&buffer);
|
||||
|
||||
Ok(Self { stream, reader })
|
||||
}
|
||||
|
@ -126,7 +125,6 @@ impl Mpd {
|
|||
}
|
||||
|
||||
pub async fn command(&mut self, command: &str) -> anyhow::Result<CommandResult> {
|
||||
dbg!(command);
|
||||
let mut properties = Vec::new();
|
||||
|
||||
self.stream
|
||||
|
@ -151,7 +149,6 @@ impl Mpd {
|
|||
});
|
||||
}
|
||||
} else if buffer.starts_with("OK") {
|
||||
dbg!(&properties);
|
||||
break Ok(CommandResult {
|
||||
properties,
|
||||
binary: None,
|
||||
|
@ -159,7 +156,7 @@ impl Mpd {
|
|||
} else if buffer.starts_with("ACK") {
|
||||
break Err(anyhow!(buffer));
|
||||
} else {
|
||||
dbg!(&buffer);
|
||||
println!("Unexpected MPD response {buffer}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -246,7 +243,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)
|
||||
|
@ -256,7 +253,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"]);
|
||||
|
||||
|
@ -265,18 +262,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 {
|
||||
|
|
Loading…
Reference in a new issue