aboutsummaryrefslogtreecommitdiff
path: root/src/utils/mpd.rs
diff options
context:
space:
mode:
authormustafa salih <mustafasalih1991@gmail.com>2021-01-14 05:41:01 +0300
committermustafa salih <mustafasalih1991@gmail.com>2021-01-14 05:41:01 +0300
commit6a349a0e0282e56b03adbe02b41bfaf0cc3213f1 (patch)
treeacdd23279a8fc837fa076739933b1269d74110fd /src/utils/mpd.rs
parente829871f2d757c7414763992839a584038c7b443 (diff)
orginized the code to seprated mods and deleted the lib file
Diffstat (limited to 'src/utils/mpd.rs')
-rw-r--r--src/utils/mpd.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/utils/mpd.rs b/src/utils/mpd.rs
new file mode 100644
index 0000000..e521c4f
--- /dev/null
+++ b/src/utils/mpd.rs
@@ -0,0 +1,27 @@
+use crate::types::Config;
+use mpd::{Client, Song};
+
+// yes, error handling looks fucking sucks!
+// getting mpd song file
+pub fn get_mpd_current(config: &Config) -> String {
+ let stream_path = format!("{}:{}", config.mpd.host, config.mpd.port);
+ let empty_string = String::from("");
+ let mut conn = match Client::connect(&stream_path) {
+ Ok(connection) => connection,
+ _ => return empty_string,
+ };
+ let current: Song = match conn.currentsong() {
+ Ok(opt) => match opt {
+ Some(song) => song,
+ _ => return empty_string,
+ },
+ _ => return empty_string,
+ };
+
+ let result = format!(
+ " {} {} {}",
+ config.mpd.icon, current.file, config.seperator
+ );
+
+ result
+}