1 use std::io::{Result, Error, ErrorKind::Other};
3 #[cfg(target_os = "macos")]
5 #[cfg(target_os = "macos")]
8 // #[cfg(not(target_os = "macos"))]
10 // #[cfg(not(target_os = "macos"))]
12 // #[cfg(not(target_os = "macos"))]
14 // #[cfg(not(target_os = "macos"))]
17 #[cfg(target_os = "macos")]
18 use apple_music::AppleMusic;
19 #[cfg(target_os = "macos")]
22 // #[cfg(not(target_os = "macos"))]
23 // use rhythmbox::Rhythmbox;
24 // #[cfg(not(target_os = "macos"))]
25 // use quod_libet::QuodLibet;
26 // #[cfg(not(target_os = "macos"))]
27 // use strawberry::Strawberry;
28 // #[cfg(not(target_os = "macos"))]
33 pub trait LyricsSource {
34 fn name(&self) -> String;
36 fn current_track(&self) -> Option<Track>;
38 fn disable(&self) -> Result<()>;
39 fn enable(&self) -> Result<()>;
40 fn reset(&self) -> Result<()>;
43 pub fn list() -> Vec<String> {
44 available_sources().into_iter().map(|source| source.name()).collect()
47 pub fn enable(source_name: &String) -> Result<()> {
48 let sources = available_sources();
49 for source in sources {
50 if &source.name() == source_name {
51 return source.enable()
54 Err(Error::new(Other, "No such source was available."))
57 pub fn disable(source_name: &String) -> Result<()> {
58 let sources = available_sources();
59 for source in sources {
60 if &source.name() == source_name {
61 return source.disable()
64 Err(Error::new(Other, "No such source was available."))
67 pub fn reset(source_name: &String) -> Result<()> {
68 let sources = available_sources();
69 for source in sources {
70 if &source.name() == source_name {
74 Err(Error::new(Other, "No such source was available."))
77 pub fn get_track() -> Option<Track> {
78 let sources = available_sources();
79 for source in sources {
80 if let Some(track) = source.current_track() {
87 pub fn available_sources() -> Vec<Box<dyn LyricsSource>> {
88 let mut sources: Vec<Box<dyn LyricsSource>> = Vec::new();
89 #[cfg(target_os = "macos")]
91 sources.push(Box::new(AppleMusic::new()));
92 sources.push(Box::new(Spotify::new()));
95 #[cfg(not(target_os = "macos"))]
97 // sources.push(Box::new(Rhythmbox::new()));
98 // sources.push(Box::new(QuodLibet::new()));
99 // sources.push(Box::new(Strawberry::new()));
100 // sources.push(Box::new(Tauon::new()));