about summary refs log tree commit diff stats
path: root/pkgs/by-name/mp/mpdpopm/src/dj/mod.rs
blob: a211a571f7326d662200fd9fabf77b8205a196df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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(())
    }
}