From 4a17a15a827f72a046a5800bf546c5ae6974eec9 Mon Sep 17 00:00:00 2001 From: Evgeny S Date: Thu, 1 Jun 2017 13:04:22 +0300 Subject: [PATCH] Fix #173 (a track cannot be played with librespot) Some tracks might have several `allowed` fields, librespot assumes that all fields must match, otherwise track cannot be played. This change collects all `allowed` and `forbidden` lists, then does the final check on whole lists at once. --- src/metadata.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/metadata.rs b/src/metadata.rs index 938631f..c1d5173 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -16,13 +16,19 @@ fn countrylist_contains(list: &str, country: &str) -> bool { fn parse_restrictions<'s, I>(restrictions: I, country: &str, catalogue: &str) -> bool where I: IntoIterator { - restrictions.into_iter() - .filter(|r| r.get_catalogue_str().contains(&catalogue.to_owned())) - .all(|r| { - !countrylist_contains(r.get_countries_forbidden(), country) && - (!r.has_countries_allowed() || - countrylist_contains(r.get_countries_allowed(), country)) - }) + let mut forbidden = "".to_string(); + let mut allowed = "".to_string(); + let rs = restrictions.into_iter().filter(|r| + r.get_catalogue_str().contains(&catalogue.to_owned()) + ); + + for r in rs { + forbidden.push_str(r.get_countries_forbidden()); + allowed.push_str(r.get_countries_allowed()); + } + + (forbidden == "" || !countrylist_contains(forbidden.as_str(), country)) && + (allowed == "" || countrylist_contains(allowed.as_str(), country)) } pub trait MetadataTrait : Send + 'static {