From 84b05567ded5cbee012ad0229f6f540b51090e92 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Fri, 31 Mar 2023 00:00:32 +0900 Subject: [PATCH] Some more clean up --- src/lib.rs | 3 ++- src/library/beets.rs | 22 ++++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bbe5a8d..1110f60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,8 @@ pub struct Track { pub artist: Vec, } -#[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, diff --git a/src/library/beets.rs b/src/library/beets.rs index 6d19e8c..c16b25a 100644 --- a/src/library/beets.rs +++ b/src/library/beets.rs @@ -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], }); }