Make Mpd::connect use Mpd::command
This commit is contained in:
parent
1cf1429753
commit
62651ea80b
1 changed files with 7 additions and 11 deletions
18
src/mpd.rs
18
src/mpd.rs
|
@ -98,28 +98,24 @@ impl Mpd {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect() -> anyhow::Result<Self> {
|
pub async fn connect() -> anyhow::Result<Self> {
|
||||||
let mut stream = TcpStream::connect(host()).await?;
|
let stream = TcpStream::connect(host()).await?;
|
||||||
let mut reader = BufReader::new(stream.clone());
|
let reader = BufReader::new(stream.clone());
|
||||||
|
let mut this = Self { stream, reader };
|
||||||
|
|
||||||
// skip OK MPD line
|
// skip OK MPD line
|
||||||
// TODO check if it is indeed OK
|
// TODO check if it is indeed OK
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
reader.read_line(&mut buffer).await?;
|
this.reader.read_line(&mut buffer).await?;
|
||||||
|
|
||||||
let password = std::env::var("MPD_PASSWORD").unwrap_or(String::new());
|
let password = std::env::var("MPD_PASSWORD").unwrap_or(String::new());
|
||||||
if !password.is_empty() {
|
if !password.is_empty() {
|
||||||
let password = Self::escape_str(&password);
|
let password = Self::escape_str(&password);
|
||||||
let command = format!("password \"{password}\"\n");
|
this.command(&format!(r#"password "{password}""#)).await?;
|
||||||
stream.write_all(command.as_bytes()).await?;
|
|
||||||
|
|
||||||
reader.read_line(&mut buffer).await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.write_all(b"binarylimit 1048576\n").await?;
|
this.command("binarylimit 1048576").await?;
|
||||||
buffer.clear();
|
|
||||||
reader.read_line(&mut buffer).await?;
|
|
||||||
|
|
||||||
Ok(Self { stream, reader })
|
Ok(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_binary_data(&mut self, size: usize) -> anyhow::Result<Vec<u8>> {
|
async fn read_binary_data(&mut self, size: usize) -> anyhow::Result<Vec<u8>> {
|
||||||
|
|
Loading…
Reference in a new issue