musichoard/src/lib.rs

150 lines
4.9 KiB
Rust

//! MusicHoard - a music collection manager.
use serde::{Deserialize, Serialize};
use uuid::Uuid;
pub mod database;
pub mod library;
/// [MusicBrainz Identifier](https://musicbrainz.org/doc/MusicBrainz_Identifier) (MBID).
pub type Mbid = Uuid;
/// The track file format.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub enum TrackFormat {
Flac,
Mp3,
}
/// A single track on an album.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct Track {
pub number: u32,
pub title: String,
pub artist: Vec<String>,
pub format: TrackFormat,
}
/// The album identifier.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
pub struct AlbumId {
pub year: u32,
pub title: String,
}
/// An album is a collection of tracks that were released together.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct Album {
pub id: AlbumId,
pub tracks: Vec<Track>,
}
/// The artist identifier.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
pub struct ArtistId {
pub name: String,
}
/// An artist.
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct Artist {
pub id: ArtistId,
pub albums: Vec<Album>,
}
#[cfg(test)]
mod tests {
use super::*;
use once_cell::sync::Lazy;
pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| {
vec![
Artist {
id: ArtistId {
name: "album_artist a".to_string(),
},
albums: vec![
Album {
id: AlbumId {
year: 1998,
title: "album_title a.a".to_string(),
},
tracks: vec![
Track {
number: 1,
title: "track a.a.1".to_string(),
artist: vec!["artist a.a.1".to_string()],
format: TrackFormat::Flac,
},
Track {
number: 2,
title: "track a.a.2".to_string(),
artist: vec![
"artist a.a.2.1".to_string(),
"artist a.a.2.2".to_string(),
],
format: TrackFormat::Flac,
},
Track {
number: 3,
title: "track a.a.3".to_string(),
artist: vec!["artist a.a.3".to_string()],
format: TrackFormat::Flac,
},
],
},
Album {
id: AlbumId {
year: 2015,
title: "album_title a.b".to_string(),
},
tracks: vec![
Track {
number: 1,
title: "track a.b.1".to_string(),
artist: vec!["artist a.b.1".to_string()],
format: TrackFormat::Mp3,
},
Track {
number: 2,
title: "track a.b.2".to_string(),
artist: vec!["artist a.b.2".to_string()],
format: TrackFormat::Flac,
},
],
},
],
},
Artist {
id: ArtistId {
name: "album_artist b.a".to_string(),
},
albums: vec![Album {
id: AlbumId {
year: 2003,
title: "album_title b.a".to_string(),
},
tracks: vec![
Track {
number: 1,
title: "track b.a.1".to_string(),
artist: vec!["artist b.a.1".to_string()],
format: TrackFormat::Mp3,
},
Track {
number: 2,
title: "track b.a.2".to_string(),
artist: vec![
"artist b.a.2.1".to_string(),
"artist b.a.2.2".to_string(),
],
format: TrackFormat::Mp3,
},
],
}],
},
]
});
}