about summary refs log tree commit diff stats
path: root/pkgs/by-name/mp/mpdpopm/src/dj/mod.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-01-31 16:29:24 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-01-31 16:29:24 +0100
commit9741228b51856902f3791b43012b2ae792cf3f5d (patch)
tree4fa1b571cf9c5a9bed725249a5557563ef53d035 /pkgs/by-name/mp/mpdpopm/src/dj/mod.rs
parentpkgs/mpdpopm: Change the default config to be the new json format (diff)
downloadnixos-config-9741228b51856902f3791b43012b2ae792cf3f5d.zip
pkgs/mpdpopm: Add a (basic) dj mode
Diffstat (limited to '')
-rw-r--r--pkgs/by-name/mp/mpdpopm/src/dj/mod.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/pkgs/by-name/mp/mpdpopm/src/dj/mod.rs b/pkgs/by-name/mp/mpdpopm/src/dj/mod.rs
new file mode 100644
index 00000000..a211a571
--- /dev/null
+++ b/pkgs/by-name/mp/mpdpopm/src/dj/mod.rs
@@ -0,0 +1,28 @@
+use anyhow::Result;
+use tracing::info;
+
+use crate::{clients::Client, dj::algorithms::Algorithm};
+
+pub(crate) mod algorithms;
+
+pub(crate) struct Dj<A: Algorithm> {
+    algo: A,
+}
+
+impl<A: Algorithm> Dj<A> {
+    pub(crate) fn new(algo: A) -> Self {
+        Self { algo }
+    }
+
+    /// Add the next track to the playlist.
+    ///
+    /// This should be called after the previous track is finished, to avoid unbounded growth.
+    pub(crate) async fn add_track(&mut self, client: &mut Client) -> Result<()> {
+        let next = self.algo.next_track(client).await?;
+
+        info!("Adding `{next}`, due to active dj mode");
+        client.add(&next).await?;
+
+        Ok(())
+    }
+}