mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Merge pull request #189 from jsopenrb/patch-1
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.
This commit is contained in:
commit
d09f469aad
1 changed files with 25 additions and 7 deletions
|
@ -16,13 +16,31 @@ fn countrylist_contains(list: &str, country: &str) -> bool {
|
||||||
fn parse_restrictions<'s, I>(restrictions: I, country: &str, catalogue: &str) -> bool
|
fn parse_restrictions<'s, I>(restrictions: I, country: &str, catalogue: &str) -> bool
|
||||||
where I: IntoIterator<Item = &'s protocol::metadata::Restriction>
|
where I: IntoIterator<Item = &'s protocol::metadata::Restriction>
|
||||||
{
|
{
|
||||||
restrictions.into_iter()
|
let mut forbidden = "".to_string();
|
||||||
.filter(|r| r.get_catalogue_str().contains(&catalogue.to_owned()))
|
let mut has_forbidden = false;
|
||||||
.all(|r| {
|
|
||||||
!countrylist_contains(r.get_countries_forbidden(), country) &&
|
let mut allowed = "".to_string();
|
||||||
(!r.has_countries_allowed() ||
|
let mut has_allowed = false;
|
||||||
countrylist_contains(r.get_countries_allowed(), country))
|
|
||||||
})
|
let rs = restrictions.into_iter().filter(|r|
|
||||||
|
r.get_catalogue_str().contains(&catalogue.to_owned())
|
||||||
|
);
|
||||||
|
|
||||||
|
for r in rs {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(has_forbidden || has_allowed) &&
|
||||||
|
(!has_forbidden || !countrylist_contains(forbidden.as_str(), country)) &&
|
||||||
|
(!has_allowed || countrylist_contains(allowed.as_str(), country))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MetadataTrait : Send + 'static {
|
pub trait MetadataTrait : Send + 'static {
|
||||||
|
|
Loading…
Reference in a new issue