From 4a17a15a827f72a046a5800bf546c5ae6974eec9 Mon Sep 17 00:00:00 2001 From: Evgeny S Date: Thu, 1 Jun 2017 13:04:22 +0300 Subject: [PATCH 1/3] 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 938631f0..c1d51737 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 { From 8bd91743708dbdf6d0996b0d631520ac97d39c28 Mon Sep 17 00:00:00 2001 From: Evgeny S Date: Sat, 3 Jun 2017 19:55:30 +0300 Subject: [PATCH 2/3] Update metadata.rs Properly check forbidden and allowed lists, skip tracks where allowed list is set but is empty. --- src/metadata.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/metadata.rs b/src/metadata.rs index c1d51737..03877af7 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -17,18 +17,29 @@ fn parse_restrictions<'s, I>(restrictions: I, country: &str, catalogue: &str) -> where I: IntoIterator { let mut forbidden = "".to_string(); + let mut has_forbidden = false; + let mut allowed = "".to_string(); + let mut has_allowed = false; + 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()); + if r.has_countries_forbidden() { + forbidden.push_str(r.get_countries_forbidden()); + has_forbidden = true; + } + + if r.has_countries_allowed() { + allowed.push_str(r.get_countries_allowed()); + has_allowed = true; + } } - (forbidden == "" || !countrylist_contains(forbidden.as_str(), country)) && - (allowed == "" || countrylist_contains(allowed.as_str(), country)) + (!has_forbidden || !countrylist_contains(forbidden.as_str(), country)) && + (!has_allowed || countrylist_contains(allowed.as_str(), country)) } pub trait MetadataTrait : Send + 'static { From 96c199e95a18e4c6bb97d89c709b51091bbdde1b Mon Sep 17 00:00:00 2001 From: Evgeny S Date: Sat, 3 Jun 2017 22:30:04 +0300 Subject: [PATCH 3/3] Update metadata.rs Turns out unreleased tracks can have no forbidden and allowed lists at all, take care of that. --- src/metadata.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/metadata.rs b/src/metadata.rs index 03877af7..c4eb3997 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -38,6 +38,7 @@ fn parse_restrictions<'s, I>(restrictions: I, country: &str, catalogue: &str) -> } } + (has_forbidden || has_allowed) && (!has_forbidden || !countrylist_contains(forbidden.as_str(), country)) && (!has_allowed || countrylist_contains(allowed.as_str(), country)) }