|
|
|
@ -18,8 +18,11 @@ use std::collections::HashMap; |
|
|
|
|
#[derive(Serialize, Deserialize, Debug)] |
|
|
|
|
#[serde(default)] |
|
|
|
|
pub struct BlacklistConf { |
|
|
|
|
/// Literal tags to reject
|
|
|
|
|
pub tag: Vec<String>, |
|
|
|
|
/// Tag sub-strings to reject (must be a whole word)
|
|
|
|
|
pub tag_partial: Vec<String>, |
|
|
|
|
/// Artists to reject
|
|
|
|
|
pub artist: Vec<String>, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -41,7 +44,9 @@ impl Default for BlacklistConf { |
|
|
|
|
#[derive(Serialize, Deserialize, Debug)] |
|
|
|
|
#[serde(default)] |
|
|
|
|
pub struct WhiteList { |
|
|
|
|
/// Tags to allow despite e.g. a substring match
|
|
|
|
|
pub tag: Vec<String>, |
|
|
|
|
/// Artists to allow
|
|
|
|
|
pub artist: Vec<String>, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -59,6 +64,8 @@ impl Default for WhiteList { |
|
|
|
|
pub struct Config { |
|
|
|
|
/// Logging - trace, debug, (info), warning, error
|
|
|
|
|
pub logging: String, |
|
|
|
|
/// Players to handle (empty = all)
|
|
|
|
|
pub allowed_players: Vec<String>, |
|
|
|
|
/// Blacklists
|
|
|
|
|
pub blacklist: BlacklistConf, |
|
|
|
|
/// Whitelist (overrides blacklist)
|
|
|
|
@ -81,6 +88,7 @@ impl Default for Config { |
|
|
|
|
fn default() -> Self { |
|
|
|
|
Self { |
|
|
|
|
logging: "info".to_owned(), |
|
|
|
|
allowed_players: vec![], |
|
|
|
|
blacklist: BlacklistConf::default(), |
|
|
|
|
whitelist: WhiteList::default(), |
|
|
|
|
artist_min_score: 95, |
|
|
|
@ -137,12 +145,20 @@ fn main() -> Result<(), Error> { |
|
|
|
|
|
|
|
|
|
'main_loop: |
|
|
|
|
loop { |
|
|
|
|
// XXX this picks the first player, which isn't always ideal - see mpris/src/find.rs
|
|
|
|
|
let player = PlayerFinder::new() |
|
|
|
|
.expect("Could not connect to D-Bus") |
|
|
|
|
.find_active(); |
|
|
|
|
|
|
|
|
|
if let Ok(player) = player { |
|
|
|
|
info!("Connected to player: {}{}", player.bus_name().to_string(), player.unique_name()); |
|
|
|
|
let player_name = player.bus_name().to_string(); |
|
|
|
|
if !config.allowed_players.is_empty() && !config.allowed_players.contains(&player_name) { |
|
|
|
|
debug!("Ignoring player {}", player_name); |
|
|
|
|
::std::thread::sleep(Duration::from_millis(config.player_find_interval_ms)); |
|
|
|
|
continue 'main_loop; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
info!("Connected to player: {}{}", player_name, player.unique_name()); |
|
|
|
|
|
|
|
|
|
let events = player.events(); |
|
|
|
|
if events.is_err() { |
|
|
|
|