Some more clean up
This commit is contained in:
parent
6dacdd3742
commit
84b05567de
@ -17,7 +17,8 @@ pub struct Track {
|
||||
pub artist: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
|
||||
/// The album identifier.
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone, Hash)]
|
||||
pub struct AlbumId {
|
||||
pub artist: String,
|
||||
pub year: u32,
|
||||
|
@ -123,32 +123,26 @@ impl Beets {
|
||||
let track_title = split[4].to_string();
|
||||
let track_artist = split[5].to_string();
|
||||
|
||||
let track = Track {
|
||||
number: track_number,
|
||||
title: track_title,
|
||||
artist: track_artist.split("; ").map(|s| s.to_owned()).collect(),
|
||||
};
|
||||
|
||||
let aid = AlbumId {
|
||||
artist: album_artist,
|
||||
year: album_year,
|
||||
title: album_title,
|
||||
};
|
||||
|
||||
let track = Track {
|
||||
number: track_number,
|
||||
title: track_title,
|
||||
artist: track_artist.split("; ").map(|s| s.to_owned()).collect(),
|
||||
};
|
||||
|
||||
if album_ids.contains(&aid) {
|
||||
// Beets returns results in order so we look from the back.
|
||||
let album = albums.iter_mut().rev().find(|a| a.id == aid).unwrap();
|
||||
album.tracks.push(track);
|
||||
} else {
|
||||
let album_artist = aid.artist.to_string();
|
||||
let album_title = aid.title.to_string();
|
||||
album_ids.insert(aid);
|
||||
album_ids.insert(aid.clone());
|
||||
albums.push(Album {
|
||||
id: AlbumId {
|
||||
artist: album_artist,
|
||||
year: album_year,
|
||||
title: album_title,
|
||||
},
|
||||
id: aid,
|
||||
tracks: vec![track],
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user