Skip to content

Commit

Permalink
fix crash for artists without tracks (closes librespot-org#103) (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
XDjackieXD authored and plietar committed Oct 1, 2017
1 parent 696aec3 commit 030b318
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,19 @@ impl Metadata for Artist {
fn parse(msg: &Self::Message, session: &Session) -> Self {
let country = session.country();

let top_tracks = msg.get_top_track()
let top_tracks: Vec<SpotifyId> = match msg.get_top_track()
.iter()
.find(|tt| !tt.has_country() || countrylist_contains(tt.get_country(), &country))
.unwrap()
.get_track()
.iter()
.filter(|track| track.has_gid())
.map(|track| SpotifyId::from_raw(track.get_gid()))
.collect::<Vec<_>>();
.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()),
Expand Down

0 comments on commit 030b318

Please sign in to comment.