Compare commits
No commits in common. "ef46017ed85eca037a9ad73d80a879e42edaf547" and "66d263bc5fae1e7648e167cc17f0f3da2aca5370" have entirely different histories.
ef46017ed8
...
66d263bc5f
4 changed files with 29 additions and 66 deletions
|
@ -12,10 +12,9 @@
|
|||
Empede is configured using environment variables:
|
||||
|
||||
| Name | Default | Description |
|
||||
| ---------------- | ------------ | --------------------------------- |
|
||||
| --------------- | ------------ | --------------------------------- |
|
||||
| **MPD_HOST** | localhost | MPD server host |
|
||||
| **MPD_PORT** | 6600 | MPD server port |
|
||||
| **MPD_PASSWORD** | | MPD server password |
|
||||
| **EMPEDE_BIND** | 0.0.0.0:8080 | Address for Empede to bind to |
|
||||
|
||||
## Running
|
||||
|
|
|
@ -165,10 +165,8 @@ async fn sse(_req: tide::Request<()>, sender: tide::sse::Sender) -> tide::Result
|
|||
sender.send("playlist", "", None).await?;
|
||||
sender.send("player", "", None).await?;
|
||||
|
||||
let mut mpd = mpd::Mpd::connect().await?;
|
||||
|
||||
loop {
|
||||
let systems = mpd.idle(&["playlist", "player", "database"]).await?;
|
||||
let systems = mpd::idle(&["playlist", "player", "database"]).await?;
|
||||
for system in systems {
|
||||
sender.send(&system, "", None).await?;
|
||||
}
|
||||
|
|
42
src/mpd.rs
42
src/mpd.rs
|
@ -14,14 +14,7 @@ pub(crate) fn host() -> String {
|
|||
}
|
||||
|
||||
pub(crate) fn connect() -> Result<mpdrs::Client, mpdrs::error::Error> {
|
||||
let mut client = mpdrs::Client::connect(host())?;
|
||||
|
||||
let password = std::env::var("MPD_PASSWORD").unwrap_or(String::new());
|
||||
if !password.is_empty() {
|
||||
client.login(&password)?;
|
||||
}
|
||||
|
||||
Ok(client)
|
||||
mpdrs::Client::connect(host())
|
||||
}
|
||||
|
||||
pub(crate) fn ls(path: &str) -> anyhow::Result<Vec<Entry>> {
|
||||
|
@ -98,17 +91,7 @@ pub(crate) enum Entry {
|
|||
},
|
||||
}
|
||||
|
||||
pub(crate) struct Mpd {
|
||||
stream: TcpStream,
|
||||
reader: BufReader<TcpStream>,
|
||||
}
|
||||
|
||||
impl Mpd {
|
||||
fn escape_str(s: &str) -> String {
|
||||
s.replace("\"", "\\\"").replace("'", "\\'")
|
||||
}
|
||||
|
||||
pub async fn connect() -> anyhow::Result<Self> {
|
||||
pub(crate) async fn idle(systems: &[&str]) -> anyhow::Result<Vec<String>> {
|
||||
let mut stream = TcpStream::connect(host()).await?;
|
||||
let mut reader = BufReader::new(stream.clone());
|
||||
|
||||
|
@ -117,30 +100,14 @@ impl Mpd {
|
|||
let mut buffer = String::new();
|
||||
reader.read_line(&mut buffer).await?;
|
||||
|
||||
let password = std::env::var("MPD_PASSWORD").unwrap_or(String::new());
|
||||
if !password.is_empty() {
|
||||
let password = Self::escape_str(&password);
|
||||
let command = format!("password \"{password}\"\n");
|
||||
stream.write_all(command.as_bytes()).await?;
|
||||
|
||||
buffer.clear();
|
||||
reader.read_line(&mut buffer).await?;
|
||||
}
|
||||
|
||||
Ok(Self { stream, reader })
|
||||
}
|
||||
|
||||
pub(crate) async fn idle(&mut self, systems: &[&str]) -> anyhow::Result<Vec<String>> {
|
||||
let mut buffer = String::new();
|
||||
|
||||
let systems = systems.join(" ");
|
||||
let command = format!("idle {systems}\n");
|
||||
self.stream.write_all(command.as_bytes()).await?;
|
||||
stream.write_all(command.as_bytes()).await?;
|
||||
|
||||
let mut updated = vec![];
|
||||
loop {
|
||||
buffer.clear();
|
||||
self.reader.read_line(&mut buffer).await?;
|
||||
reader.read_line(&mut buffer).await?;
|
||||
if buffer == "OK\n" {
|
||||
break Ok(updated);
|
||||
}
|
||||
|
@ -152,4 +119,3 @@ impl Mpd {
|
|||
updated.push(changed.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
<div class="queue-header">
|
||||
<div class="queue-next">Next in queue</div>
|
||||
<button class="queue-clear" role="button" hx-delete="/queue" hx-swap="none">
|
||||
<button class="queue-clear" role="button" hx-delete="/queue">
|
||||
<span class="material-symbols-outlined">playlist_remove</span>
|
||||
Clear
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue