Track num songs by artist

This commit is contained in:
Antoine Gersant 2024-09-06 19:20:21 -07:00
parent 07324ccca6
commit e0bf259be3
3 changed files with 12 additions and 6 deletions
src
app/index
server/dto

View file

@ -23,11 +23,12 @@ pub struct ArtistHeader {
pub num_albums_as_composer: u32,
pub num_albums_as_lyricist: u32,
pub num_songs_by_genre: HashMap<String, u32>,
pub num_songs: u32,
}
#[derive(Debug, Default, PartialEq, Eq)]
pub struct Artist {
pub header: ArtistHeader,
pub name: String,
pub albums_as_performer: Vec<Album>,
pub albums_as_additional_performer: Vec<Album>, // Albums where this artist shows up as `artist` without being `album_artist`
pub albums_as_composer: Vec<Album>,
@ -104,7 +105,7 @@ impl Collection {
let albums_as_lyricist = list_albums(&a.albums_as_lyricist);
Artist {
header: make_artist_header(a, strings),
name: strings.resolve(&a.name).to_owned(),
albums_as_performer,
albums_as_additional_performer,
albums_as_composer,
@ -183,6 +184,7 @@ fn make_artist_header(artist: &storage::Artist, strings: &RodeoReader) -> Artist
.iter()
.map(|(genre, num)| (strings.resolve(genre).to_string(), *num))
.collect(),
num_songs: artist.num_songs,
}
}
@ -269,6 +271,7 @@ impl Builder {
for name in all_artists {
let artist = self.get_or_create_artist(name);
artist.num_songs += 1;
for genre in &song.genres {
*artist
.num_songs_by_genre
@ -290,6 +293,7 @@ impl Builder {
albums_as_composer: HashSet::new(),
albums_as_lyricist: HashSet::new(),
num_songs_by_genre: HashMap::new(),
num_songs: 0,
})
.borrow_mut()
}

View file

@ -24,6 +24,7 @@ pub struct Artist {
pub albums_as_composer: HashSet<AlbumKey>,
pub albums_as_lyricist: HashSet<AlbumKey>,
pub num_songs_by_genre: HashMap<Spur, u32>,
pub num_songs: u32,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
@ -114,7 +115,7 @@ pub fn store_song(
let mut canonicalize = |s: &String| {
minuscules
.entry(s.to_lowercase())
.entry(s.trim().to_lowercase())
.or_insert_with(|| strings.get_or_intern(s))
.to_owned()
};

View file

@ -325,6 +325,7 @@ pub struct ArtistHeader {
pub num_albums_as_composer: u32,
pub num_albums_as_lyricist: u32,
pub num_songs_by_genre: HashMap<String, u32>,
pub num_songs: u32,
}
impl From<index::ArtistHeader> for ArtistHeader {
@ -336,14 +337,14 @@ impl From<index::ArtistHeader> for ArtistHeader {
num_albums_as_composer: a.num_albums_as_composer,
num_albums_as_lyricist: a.num_albums_as_lyricist,
num_songs_by_genre: a.num_songs_by_genre,
num_songs: a.num_songs,
}
}
}
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Artist {
#[serde(flatten)]
pub header: ArtistHeader,
pub name: String,
pub albums_as_performer: Vec<AlbumHeader>,
pub albums_as_additional_performer: Vec<AlbumHeader>,
pub albums_as_composer: Vec<AlbumHeader>,
@ -354,7 +355,7 @@ impl From<index::Artist> for Artist {
fn from(a: index::Artist) -> Self {
let convert_albums = |a: Vec<index::Album>| a.into_iter().map(|a| a.into()).collect();
Self {
header: a.header.into(),
name: a.name,
albums_as_performer: convert_albums(a.albums_as_performer),
albums_as_additional_performer: convert_albums(a.albums_as_additional_performer),
albums_as_composer: convert_albums(a.albums_as_composer),