diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-03-16 11:01:41 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-03-16 11:01:41 +0100 |
| commit | 040b91a7a5b085f8aa0bec3580bf7d68450e6fc9 (patch) | |
| tree | f27088c562fea977c9cbb97ffde3e81590db91fa /src | |
| parent | 616cee0382cb0b9e287d1037ec82813aa859c1a0 (diff) | |
Add linux config
Diffstat (limited to 'src')
| -rw-r--r-- | src/configuration.rs | 5 | ||||
| -rw-r--r-- | src/sources/dbus.rs | 48 | ||||
| -rw-r--r-- | src/sources/mod.rs | 25 |
3 files changed, 56 insertions, 22 deletions
diff --git a/src/configuration.rs b/src/configuration.rs index f678461..55443eb 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -8,7 +8,7 @@ use serde_json; const CONFIG_ENV_VARIABLE: &str = "LYRICLI_CONFIG_DIRECTORY"; const CONFIG_DEFAULT_LOCATION: &str = "XDG_CONFIG_HOME"; const CONFIG_FALLBACK_LOCATION: &str = ".config"; -const CONFIG_SUBDIRECTORY: &str = ".config"; +const CONFIG_SUBDIRECTORY: &str = "lyricli"; const CONFIG_FILENAME: &str = "lyricli.conf"; #[derive(Serialize, Deserialize, Debug)] @@ -55,7 +55,8 @@ impl Configuration { Configuration { enabled_sources: vec![ "apple_music".to_string(), - "spotify".to_string() + "spotify".to_string(), + "strawberry".to_string() ] } } diff --git a/src/sources/dbus.rs b/src/sources/dbus.rs new file mode 100644 index 0000000..57c5853 --- /dev/null +++ b/src/sources/dbus.rs @@ -0,0 +1,48 @@ +use std::io::Result; +use mpris::PlayerFinder; + +use crate::Track; + +use super::LyricsSource; + +pub struct Dbus; + +impl Dbus { + pub fn new() -> Self { + Dbus + } +} + +impl LyricsSource for Dbus { + + fn name(&self) -> String { + "dbus".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(()) + } +} diff --git a/src/sources/mod.rs b/src/sources/mod.rs index 78f7499..087a87f 100644 --- a/src/sources/mod.rs +++ b/src/sources/mod.rs @@ -5,28 +5,16 @@ mod apple_music; #[cfg(target_os = "macos")] mod spotify; -// #[cfg(not(target_os = "macos"))] -// mod rhythmbox; -// #[cfg(not(target_os = "macos"))] -// mod quod_libe; -// #[cfg(not(target_os = "macos"))] -// mod strawberry; -// #[cfg(not(target_os = "macos"))] -// mod tauon; +#[cfg(target_os = "linux")] +mod dbus; #[cfg(target_os = "macos")] use apple_music::AppleMusic; #[cfg(target_os = "macos")] use spotify::Spotify; -// #[cfg(not(target_os = "macos"))] -// use rhythmbox::Rhythmbox; -// #[cfg(not(target_os = "macos"))] -// use quod_libet::QuodLibet; -// #[cfg(not(target_os = "macos"))] -// use strawberry::Strawberry; -// #[cfg(not(target_os = "macos"))] -// use tauon::Tauon; +#[cfg(target_os = "linux")] +use dbus::Dbus; use crate::Track; @@ -94,10 +82,7 @@ pub fn available_sources() -> Vec<Box<dyn LyricsSource>> { #[cfg(not(target_os = "macos"))] { - // sources.push(Box::new(Rhythmbox::new())); - // sources.push(Box::new(QuodLibet::new())); - // sources.push(Box::new(Strawberry::new())); - // sources.push(Box::new(Tauon::new())); + sources.push(Box::new(Dbus::new())); } sources |