aboutsummaryrefslogtreecommitdiff
path: root/src/utils/mpd.rs
blob: 375238718f863456c07f93d5ac17872379e3b40a (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
25
26
27
28
use crate::config::CONFIG;
use crate::types::ThreadsData;
use mpd::{Client, Song};

// yes, error handling looks fucking sucks!
// getting mpd song file
pub 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(opt) => match opt {
            Some(song) => song,
            _ => return empty_data,
        },
        _ => return empty_data,
    };

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

    ThreadsData::Mpd(result)
}