aboutsummaryrefslogtreecommitdiff
path: root/src/sources/mpris.rs
blob: 69eb86208f9c10cd1b2a2463ba778b3829932bf0 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use mpris::PlayerFinder;
use std::io::Result;

use crate::Track;

use super::LyricsSource;

pub struct Mpris;

impl Mpris {
    pub fn new() -> Self {
        Mpris
    }
}

impl LyricsSource for Mpris {
    fn name(&self) -> String {
        "mpris".to_string()
    }

    fn current_track(&self) -> Option<Track> {
        let player = PlayerFinder::new().ok()?.find_active().ok()?;

        let metadata = player.get_metadata().ok()?;
        let name = metadata.title()?.to_string();
        let artists = metadata.artists()?;
        let artist = artists.get(0)?.to_string();

        Some(Track { name, artist })
    }

    fn disable(&self) -> Result<()> {
        Ok(())
    }

    fn enable(&self) -> Result<()> {
        Ok(())
    }

    fn reset(&self) -> Result<()> {
        Ok(())
    }
}