|
@@ -13,7 +13,8 @@ use linear_map::LinearMap;
|
|
|
|
|
|
use core::mercury::MercuryError;
|
|
|
use core::session::Session;
|
|
|
-use core::util::{SpotifyId, FileId, StrChunksExt};
|
|
|
+use core::spotify_id::{FileId, SpotifyId};
|
|
|
+use core::util::StrChunksExt;
|
|
|
|
|
|
pub use protocol::metadata::AudioFile_Format as FileFormat;
|
|
|
|
|
@@ -22,7 +23,8 @@ fn countrylist_contains(list: &str, country: &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>,
|
|
|
{
|
|
|
let mut forbidden = "".to_string();
|
|
|
let mut has_forbidden = false;
|
|
@@ -30,9 +32,9 @@ fn parse_restrictions<'s, I>(restrictions: I, country: &str, catalogue: &str) ->
|
|
|
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())
|
|
|
- );
|
|
|
+ let rs = restrictions
|
|
|
+ .into_iter()
|
|
|
+ .filter(|r| r.get_catalogue_str().contains(&catalogue.to_owned()));
|
|
|
|
|
|
for r in rs {
|
|
|
if r.has_countries_forbidden() {
|
|
@@ -46,12 +48,12 @@ 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))
|
|
|
+ (has_forbidden || has_allowed)
|
|
|
+ && (!has_forbidden || !countrylist_contains(forbidden.as_str(), country))
|
|
|
+ && (!has_allowed || countrylist_contains(allowed.as_str(), country))
|
|
|
}
|
|
|
|
|
|
-pub trait Metadata : Send + Sized + 'static {
|
|
|
+pub trait Metadata: Send + Sized + 'static {
|
|
|
type Message: protobuf::MessageStatic;
|
|
|
|
|
|
fn base_url() -> &'static str;
|
|
@@ -110,20 +112,20 @@ impl Metadata for Track {
|
|
|
let country = session.country();
|
|
|
|
|
|
let artists = msg.get_artist()
|
|
|
- .iter()
|
|
|
- .filter(|artist| artist.has_gid())
|
|
|
- .map(|artist| SpotifyId::from_raw(artist.get_gid()))
|
|
|
- .collect::<Vec<_>>();
|
|
|
+ .iter()
|
|
|
+ .filter(|artist| artist.has_gid())
|
|
|
+ .map(|artist| SpotifyId::from_raw(artist.get_gid()))
|
|
|
+ .collect::<Vec<_>>();
|
|
|
|
|
|
let files = msg.get_file()
|
|
|
- .iter()
|
|
|
- .filter(|file| file.has_file_id())
|
|
|
- .map(|file| {
|
|
|
- let mut dst = [0u8; 20];
|
|
|
- dst.clone_from_slice(file.get_file_id());
|
|
|
- (file.get_format(), FileId(dst))
|
|
|
- })
|
|
|
- .collect();
|
|
|
+ .iter()
|
|
|
+ .filter(|file| file.has_file_id())
|
|
|
+ .map(|file| {
|
|
|
+ let mut dst = [0u8; 20];
|
|
|
+ dst.clone_from_slice(file.get_file_id());
|
|
|
+ (file.get_format(), FileId(dst))
|
|
|
+ })
|
|
|
+ .collect();
|
|
|
|
|
|
Track {
|
|
|
id: SpotifyId::from_raw(msg.get_gid()),
|
|
@@ -133,12 +135,10 @@ impl Metadata for Track {
|
|
|
artists: artists,
|
|
|
files: files,
|
|
|
alternatives: msg.get_alternative()
|
|
|
- .iter()
|
|
|
- .map(|alt| SpotifyId::from_raw(alt.get_gid()))
|
|
|
- .collect(),
|
|
|
- available: parse_restrictions(msg.get_restriction(),
|
|
|
- &country,
|
|
|
- "premium"),
|
|
|
+ .iter()
|
|
|
+ .map(|alt| SpotifyId::from_raw(alt.get_gid()))
|
|
|
+ .collect(),
|
|
|
+ available: parse_restrictions(msg.get_restriction(), &country, "premium"),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -152,28 +152,28 @@ impl Metadata for Album {
|
|
|
|
|
|
fn parse(msg: &Self::Message, _: &Session) -> Self {
|
|
|
let artists = msg.get_artist()
|
|
|
- .iter()
|
|
|
- .filter(|artist| artist.has_gid())
|
|
|
- .map(|artist| SpotifyId::from_raw(artist.get_gid()))
|
|
|
- .collect::<Vec<_>>();
|
|
|
+ .iter()
|
|
|
+ .filter(|artist| artist.has_gid())
|
|
|
+ .map(|artist| SpotifyId::from_raw(artist.get_gid()))
|
|
|
+ .collect::<Vec<_>>();
|
|
|
|
|
|
let tracks = msg.get_disc()
|
|
|
- .iter()
|
|
|
- .flat_map(|disc| disc.get_track())
|
|
|
- .filter(|track| track.has_gid())
|
|
|
- .map(|track| SpotifyId::from_raw(track.get_gid()))
|
|
|
- .collect::<Vec<_>>();
|
|
|
+ .iter()
|
|
|
+ .flat_map(|disc| disc.get_track())
|
|
|
+ .filter(|track| track.has_gid())
|
|
|
+ .map(|track| SpotifyId::from_raw(track.get_gid()))
|
|
|
+ .collect::<Vec<_>>();
|
|
|
|
|
|
let covers = msg.get_cover_group()
|
|
|
- .get_image()
|
|
|
- .iter()
|
|
|
- .filter(|image| image.has_file_id())
|
|
|
- .map(|image| {
|
|
|
- let mut dst = [0u8; 20];
|
|
|
- dst.clone_from_slice(image.get_file_id());
|
|
|
- FileId(dst)
|
|
|
- })
|
|
|
- .collect::<Vec<_>>();
|
|
|
+ .get_image()
|
|
|
+ .iter()
|
|
|
+ .filter(|image| image.has_file_id())
|
|
|
+ .map(|image| {
|
|
|
+ let mut dst = [0u8; 20];
|
|
|
+ dst.clone_from_slice(image.get_file_id());
|
|
|
+ FileId(dst)
|
|
|
+ })
|
|
|
+ .collect::<Vec<_>>();
|
|
|
|
|
|
Album {
|
|
|
id: SpotifyId::from_raw(msg.get_gid()),
|
|
@@ -185,7 +185,6 @@ impl Metadata for Album {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
impl Metadata for Artist {
|
|
|
type Message = protocol::metadata::Artist;
|
|
|
|
|
@@ -197,23 +196,22 @@ impl Metadata for Artist {
|
|
|
let country = session.country();
|
|
|
|
|
|
let top_tracks: Vec<SpotifyId> = match msg.get_top_track()
|
|
|
- .iter()
|
|
|
- .find(|tt| !tt.has_country() || countrylist_contains(tt.get_country(), &country)) {
|
|
|
- Some(tracks) => {
|
|
|
- tracks.get_track()
|
|
|
- .iter()
|
|
|
- .filter(|track| track.has_gid())
|
|
|
- .map(|track| SpotifyId::from_raw(track.get_gid()))
|
|
|
- .collect::<Vec<_>>()
|
|
|
- },
|
|
|
- None => Vec::new()
|
|
|
- };
|
|
|
-
|
|
|
+ .iter()
|
|
|
+ .find(|tt| !tt.has_country() || countrylist_contains(tt.get_country(), &country))
|
|
|
+ {
|
|
|
+ Some(tracks) => tracks
|
|
|
+ .get_track()
|
|
|
+ .iter()
|
|
|
+ .filter(|track| track.has_gid())
|
|
|
+ .map(|track| SpotifyId::from_raw(track.get_gid()))
|
|
|
+ .collect::<Vec<_>>(),
|
|
|
+ None => Vec::new(),
|
|
|
+ };
|
|
|
|
|
|
Artist {
|
|
|
id: SpotifyId::from_raw(msg.get_gid()),
|
|
|
name: msg.get_name().to_owned(),
|
|
|
- top_tracks: top_tracks
|
|
|
+ top_tracks: top_tracks,
|
|
|
}
|
|
|
}
|
|
|
}
|