1 use std::io::{Result, Error, ErrorKind::Other};
3 #[cfg(target_os = "macos")]
5 #[cfg(target_os = "macos")]
8 #[cfg(target_os = "linux")]
11 #[cfg(target_os = "macos")]
12 use apple_music::AppleMusic;
13 #[cfg(target_os = "macos")]
16 #[cfg(target_os = "linux")]
21 pub trait LyricsSource {
22 fn name(&self) -> String;
24 fn current_track(&self) -> Option<Track>;
26 fn disable(&self) -> Result<()>;
27 fn enable(&self) -> Result<()>;
28 fn reset(&self) -> Result<()>;
31 pub fn list() -> Vec<String> {
32 available_sources().into_iter().map(|source| source.name()).collect()
35 pub fn enable(source_name: &String) -> Result<()> {
36 let sources = available_sources();
37 for source in sources {
38 if &source.name() == source_name {
39 return source.enable()
42 Err(Error::new(Other, "No such source was available."))
45 pub fn disable(source_name: &String) -> Result<()> {
46 let sources = available_sources();
47 for source in sources {
48 if &source.name() == source_name {
49 return source.disable()
52 Err(Error::new(Other, "No such source was available."))
55 pub fn reset(source_name: &String) -> Result<()> {
56 let sources = available_sources();
57 for source in sources {
58 if &source.name() == source_name {
62 Err(Error::new(Other, "No such source was available."))
65 pub fn get_track() -> Option<Track> {
66 let sources = available_sources();
67 for source in sources {
68 if let Some(track) = source.current_track() {
75 pub fn available_sources() -> Vec<Box<dyn LyricsSource>> {
76 let mut sources: Vec<Box<dyn LyricsSource>> = Vec::new();
77 #[cfg(target_os = "macos")]
79 sources.push(Box::new(AppleMusic::new()));
80 sources.push(Box::new(Spotify::new()));
83 #[cfg(not(target_os = "macos"))]
85 sources.push(Box::new(Dbus::new()));