|
|
@ -11,6 +11,8 @@ use std::time::Duration; |
|
|
|
use mpris::Event; |
|
|
|
use mpris::Event; |
|
|
|
use std::collections::HashSet; |
|
|
|
use std::collections::HashSet; |
|
|
|
use failure::Error; |
|
|
|
use failure::Error; |
|
|
|
|
|
|
|
use dbus::arg::Variant; |
|
|
|
|
|
|
|
use dbus::arg::RefArg; |
|
|
|
|
|
|
|
|
|
|
|
mod brainz; |
|
|
|
mod brainz; |
|
|
|
mod config_file; |
|
|
|
mod config_file; |
|
|
@ -167,6 +169,9 @@ fn main() -> Result<(), Error> { |
|
|
|
break 'event_loop; |
|
|
|
break 'event_loop; |
|
|
|
} |
|
|
|
} |
|
|
|
Event::TrackChanged(mut metadata) => { |
|
|
|
Event::TrackChanged(mut metadata) => { |
|
|
|
|
|
|
|
::std::thread::sleep(Duration::from_millis(250)); |
|
|
|
|
|
|
|
metadata = player.get_metadata().unwrap_or(metadata); |
|
|
|
|
|
|
|
|
|
|
|
let mut title = metadata.title().unwrap_or(""); |
|
|
|
let mut title = metadata.title().unwrap_or(""); |
|
|
|
info!("--- new track : {} ---", title); |
|
|
|
info!("--- new track : {} ---", title); |
|
|
|
|
|
|
|
|
|
|
@ -185,6 +190,39 @@ fn main() -> Result<(), Error> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut skip = !config.allow_by_default; |
|
|
|
|
|
|
|
let mut confidence = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug!("MPRIS meta: {:#?}", metadata); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// try to get genre from the 'rest' map in the metadata struct
|
|
|
|
|
|
|
|
#[allow(deprecated)] // 2.0.0 will provide some nicer API, hopefully
|
|
|
|
|
|
|
|
let rest = metadata.rest(); |
|
|
|
|
|
|
|
let meta_genre : Option<&Variant<Box<RefArg>>> = rest.get("xesam:genre"); |
|
|
|
|
|
|
|
match meta_genre { |
|
|
|
|
|
|
|
Some(variant) => { |
|
|
|
|
|
|
|
let b : &RefArg = variant.0.as_ref(); |
|
|
|
|
|
|
|
if let Some(s) = b.as_str() { |
|
|
|
|
|
|
|
info!("Using genre from MPRIS metadata: {}", s); |
|
|
|
|
|
|
|
skip = !brainz::check_genre(&config, &s.to_string().to_lowercase()); |
|
|
|
|
|
|
|
confidence = true; |
|
|
|
|
|
|
|
} else if let Some(list) = b.as_iter() { |
|
|
|
|
|
|
|
debug!("MPRIS contains array of genres"); |
|
|
|
|
|
|
|
for item in list { |
|
|
|
|
|
|
|
if let Some(s) = item.as_str() { |
|
|
|
|
|
|
|
info!("Using genre from MPRIS metadata: {}", s); |
|
|
|
|
|
|
|
skip = !brainz::check_genre(&config, &s.to_string().to_lowercase()); |
|
|
|
|
|
|
|
confidence = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
None => { |
|
|
|
|
|
|
|
debug!("No MPRIS genre"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !confidence { |
|
|
|
let mut artists = HashSet::new(); |
|
|
|
let mut artists = HashSet::new(); |
|
|
|
|
|
|
|
|
|
|
|
if let Some(aa) = metadata.artists() { |
|
|
|
if let Some(aa) = metadata.artists() { |
|
|
@ -198,15 +236,14 @@ fn main() -> Result<(), Error> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let mut skip = false; |
|
|
|
let artists_e = artists |
|
|
|
let mut confidence = false; |
|
|
|
|
|
|
|
'artists_loop: for (an, a) in artists |
|
|
|
|
|
|
|
.iter() |
|
|
|
.iter() |
|
|
|
.take(config.max_artists_per_track as usize) |
|
|
|
.take(config.max_artists_per_track as usize) |
|
|
|
.enumerate() |
|
|
|
.enumerate(); |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
'artists_loop: for (an, a) in artists_e { |
|
|
|
info!("Checking artist #{}: {}", an + 1, a); |
|
|
|
info!("Checking artist #{}: {}", an + 1, a); |
|
|
|
if let Some(resolution) = artist_cache.get(a.as_str()) { |
|
|
|
if let Some(resolution) = artist_cache.get(*a) { |
|
|
|
confidence = true; |
|
|
|
confidence = true; |
|
|
|
if !resolution { |
|
|
|
if !resolution { |
|
|
|
info!("~ result cached: BAD"); |
|
|
|
info!("~ result cached: BAD"); |
|
|
@ -253,6 +290,7 @@ fn main() -> Result<(), Error> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if skip || (!confidence && !config.allow_by_default) { |
|
|
|
if skip || (!confidence && !config.allow_by_default) { |
|
|
|
info!(">>>>>> SKIP : {} >>>>>>\n", title); |
|
|
|
info!(">>>>>> SKIP : {} >>>>>>\n", title); |
|
|
|