aboutsummaryrefslogtreecommitdiff
path: root/src/utils/mpd.rs
blob: 95af7680b1b81a0e6062fe9d243de8cc53c01694 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use crate::config::CONFIG;
use crate::types::ThreadsData;
use mpd::{Client, Song};

// getting mpd song file
pub async fn get_mpd_current() -> ThreadsData {
    let stream_path = format!("{}:{}", CONFIG.mpd.host, CONFIG.mpd.port);
    let empty_data = ThreadsData::Mpd(String::from(""));
    let mut conn = match Client::connect(&stream_path) {
        Ok(connection) => connection,
        _ => return empty_data,
    };
    let current: Song = match conn.currentsong() {
        Ok(Some(song)) => song,
        _ => return empty_data,
    };

    let result = format!(
        "  {}  {}  {}",
        CONFIG.mpd.icon, current.file, CONFIG.seperator
    );

    ThreadsData::Mpd(result)
}