about summary refs log tree commit diff stats
path: root/pkgs/by-name/mp/mpdpopm/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--pkgs/by-name/mp/mpdpopm/src/config.rs127
1 files changed, 15 insertions, 112 deletions
diff --git a/pkgs/by-name/mp/mpdpopm/src/config.rs b/pkgs/by-name/mp/mpdpopm/src/config.rs
index b4fe3c53..8bb5abfb 100644
--- a/pkgs/by-name/mp/mpdpopm/src/config.rs
+++ b/pkgs/by-name/mp/mpdpopm/src/config.rs
@@ -116,6 +116,17 @@ mod test_connection {
     }
 }
 
+/// THe possible start-up mode.
+#[derive(Default, Deserialize, Debug, Serialize)]
+pub enum Mode {
+    #[default]
+    /// Don't do anything special
+    Normal,
+
+    /// Already start the DJ mode on start-up
+    Dj,
+}
+
 /// This is the most recent `mppopmd` configuration struct.
 #[derive(Deserialize, Debug, Serialize)]
 #[serde(default)]
@@ -133,6 +144,9 @@ pub struct Config {
     /// How to connect to mpd
     pub conn: Connection,
 
+    /// The mode to start in
+    pub mode: Mode,
+
     /// The `mpd' root music directory, relative to the host on which *this* daemon is running
     pub local_music_dir: PathBuf,
 
@@ -142,9 +156,6 @@ pub struct Config {
 
     /// The interval, in milliseconds, at which to poll `mpd' for the current state
     pub poll_interval_ms: u64,
-
-    /// Channel to setup for assorted commands-- channel names must satisfy "[-a-zA-Z-9_.:]+"
-    pub commands_chan: String,
 }
 
 impl Default for Config {
@@ -162,7 +173,7 @@ impl Config {
             local_music_dir: [PREFIX, "Music"].iter().collect(),
             played_thresh: 0.6,
             poll_interval_ms: 5000,
-            commands_chan: String::from("unwoundstack.com:commands"),
+            mode: Mode::default(),
         })
     }
 }
@@ -176,111 +187,3 @@ pub fn from_str(text: &str) -> Result<Config> {
     };
     Ok(cfg)
 }
-
-#[cfg(test)]
-mod test {
-    use super::*;
-
-    #[test]
-    #[ignore = "We changed the config format to json"]
-    fn test_from_str() {
-        let cfg = Config::default();
-        assert_eq!(cfg.commands_chan, String::from("unwoundstack.com:commands"));
-
-        assert_eq!(
-            serde_json::to_string(&cfg).unwrap(),
-            format!(
-                r#"((version . "1") (log . "{}/log/mppopmd.log") (conn TCP (host . "localhost") (port . 6600)) (local_music_dir . "{}/Music") (playcount_sticker . "unwoundstack.com:playcount") (lastplayed_sticker . "unwoundstack.com:lastplayed") (played_thresh . 0.6) (poll_interval_ms . 5000) (commands_chan . "unwoundstack.com:commands") (playcount_command . "") (playcount_command_args) (rating_sticker . "unwoundstack.com:rating") (ratings_command . "") (ratings_command_args) (gen_cmds))"#,
-                LOCALSTATEDIR, PREFIX
-            )
-        );
-
-        let cfg: Config = serde_json::from_str(
-            r#"
-((version . "1")
- (log . "/usr/local/var/log/mppopmd.log")
- (conn TCP (host . "localhost") (port . 6600))
- (local_music_dir . "/usr/local/Music")
- (playcount_sticker . "unwoundstack.com:playcount")
- (lastplayed_sticker . "unwoundstack.com:lastplayed")
- (played_thresh . 0.6)
- (poll_interval_ms . 5000)
- (commands_chan . "unwoundstack.com:commands")
- (playcount_command . "")
- (playcount_command_args)
- (rating_sticker . "unwoundstack.com:rating")
- (ratings_command . "")
- (ratings_command_args)
- (gen_cmds))
-"#,
-        )
-        .unwrap();
-        assert_eq!(cfg._version, String::from("1"));
-
-        let cfg: Config = serde_json::from_str(
-            r#"
-((version . "1")
- (log . "/usr/local/var/log/mppopmd.log")
- (conn Local (path . "/home/mgh/var/run/mpd/mpd.sock"))
- (local_music_dir . "/usr/local/Music")
- (playcount_sticker . "unwoundstack.com:playcount")
- (lastplayed_sticker . "unwoundstack.com:lastplayed")
- (played_thresh . 0.6)
- (poll_interval_ms . 5000)
- (commands_chan . "unwoundstack.com:commands")
- (playcount_command . "")
- (playcount_command_args)
- (rating_sticker . "unwoundstack.com:rating")
- (ratings_command . "")
- (ratings_command_args)
- (gen_cmds))
-"#,
-        )
-        .unwrap();
-        assert_eq!(cfg._version, String::from("1"));
-        assert_eq!(
-            cfg.conn,
-            Connection::Local {
-                path: PathBuf::from("/home/mgh/var/run/mpd/mpd.sock")
-            }
-        );
-
-        // Test fallback to "v0" of the config struct
-        let cfg = from_str(r#"
-((log . "/home/mgh/var/log/mppopmd.log")
- (host . "192.168.1.14")
- (port . 6600)
- (local_music_dir . "/space/mp3")
- (playcount_sticker . "unwoundstack.com:playcount")
- (lastplayed_sticker . "unwoundstack.com:lastplayed")
- (played_thresh . 0.6)
- (poll_interval_ms . 5000)
- (playcount_command . "/usr/local/bin/scribbu")
- (playcount_command_args . ("popm" "-v" "-a" "-f" "-o" "sp1ff@pobox.com" "-C" "%playcount" "%full-file"))
- (commands_chan . "unwoundstack.com:commands")
- (rating_sticker . "unwoundstack.com:rating")
- (ratings_command . "/usr/local/bin/scribbu")
- (ratings_command_args . ("popm" "-v" "-a" "-f" "-o" "sp1ff@pobox.com" "-r" "%rating" "%full-file"))
- (gen_cmds .
-	   (((name . "set-genre")
-	     (formal_parameters . (Literal Track))
-	     (default_after . 1)
-	     (cmd . "/usr/local/bin/scribbu")
-	     (args . ("genre" "-a" "-C" "-g" "%1" "%full-file"))
-	     (update . TrackOnly))
-	    ((name . "set-xtag")
-	     (formal_parameters . (Literal Track))
-	     (default_after . 1)
-	     (cmd . "/usr/local/bin/scribbu")
-	     (args . ("xtag" "-A" "-o" "sp1ff@pobox.com" "-T" "%1" "%full-file"))
-	     (update . TrackOnly))
-	    ((name . "merge-xtag")
-	     (formal_parameters . (Literal Track))
-	     (default_after . 1)
-	     (cmd . "/usr/local/bin/scribbu")
-	     (args . ("xtag" "-m" "-o" "sp1ff@pobox.com" "-T" "%1" "%full-file"))
-	     (update . TrackOnly)))))
-"#).unwrap();
-        assert_eq!(cfg.log, PathBuf::from("/home/mgh/var/log/mppopmd.log"));
-    }
-}