blob: 78f749994ca5ce76725639e27ee15560e6b330b6 (
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
use std::io::{Result, Error, ErrorKind::Other};
#[cfg(target_os = "macos")]
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 = "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;
use crate::Track;
pub trait LyricsSource {
fn name(&self) -> String;
fn current_track(&self) -> Option<Track>;
fn disable(&self) -> Result<()>;
fn enable(&self) -> Result<()>;
fn reset(&self) -> Result<()>;
}
pub fn list() -> Vec<String> {
available_sources().into_iter().map(|source| source.name()).collect()
}
pub fn enable(source_name: &String) -> Result<()> {
let sources = available_sources();
for source in sources {
if &source.name() == source_name {
return source.enable()
}
}
Err(Error::new(Other, "No such source was available."))
}
pub fn disable(source_name: &String) -> Result<()> {
let sources = available_sources();
for source in sources {
if &source.name() == source_name {
return source.disable()
}
}
Err(Error::new(Other, "No such source was available."))
}
pub fn reset(source_name: &String) -> Result<()> {
let sources = available_sources();
for source in sources {
if &source.name() == source_name {
return source.reset()
}
}
Err(Error::new(Other, "No such source was available."))
}
pub fn get_track() -> Option<Track> {
let sources = available_sources();
for source in sources {
if let Some(track) = source.current_track() {
return Some(track);
}
}
return None
}
pub fn available_sources() -> Vec<Box<dyn LyricsSource>> {
let mut sources: Vec<Box<dyn LyricsSource>> = Vec::new();
#[cfg(target_os = "macos")]
{
sources.push(Box::new(AppleMusic::new()));
sources.push(Box::new(Spotify::new()));
}
#[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
}
|