2023-03-29 01:29:11 +02:00
|
|
|
//! MusicHoard - a music collection manager.
|
|
|
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
2023-03-29 08:37:01 +02:00
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
pub mod database;
|
2023-03-31 14:24:54 +02:00
|
|
|
pub mod library;
|
2023-03-29 01:29:11 +02:00
|
|
|
|
|
|
|
/// [MusicBrainz Identifier](https://musicbrainz.org/doc/MusicBrainz_Identifier) (MBID).
|
2023-03-29 08:37:01 +02:00
|
|
|
pub type Mbid = Uuid;
|
2023-03-29 01:29:11 +02:00
|
|
|
|
2023-04-10 11:27:07 +02:00
|
|
|
/// The track file format.
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
|
|
|
pub enum TrackFormat {
|
|
|
|
Flac,
|
|
|
|
Mp3,
|
|
|
|
}
|
|
|
|
|
2023-03-31 14:24:54 +02:00
|
|
|
/// A single track on an album.
|
2023-04-10 00:13:18 +02:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
2023-03-29 01:29:11 +02:00
|
|
|
pub struct Track {
|
|
|
|
pub number: u32,
|
|
|
|
pub title: String,
|
2023-03-31 14:24:54 +02:00
|
|
|
pub artist: Vec<String>,
|
2023-04-10 11:27:07 +02:00
|
|
|
pub format: TrackFormat,
|
2023-03-28 22:49:59 +02:00
|
|
|
}
|
|
|
|
|
2023-03-31 14:24:54 +02:00
|
|
|
/// The album identifier.
|
2023-04-10 00:13:18 +02:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
|
2023-03-31 14:24:54 +02:00
|
|
|
pub struct AlbumId {
|
|
|
|
pub year: u32,
|
|
|
|
pub title: String,
|
2023-03-29 01:29:11 +02:00
|
|
|
}
|
2023-03-28 22:49:59 +02:00
|
|
|
|
2023-03-31 14:24:54 +02:00
|
|
|
/// An album is a collection of tracks that were released together.
|
2023-04-10 00:13:18 +02:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
2023-03-31 14:24:54 +02:00
|
|
|
pub struct Album {
|
|
|
|
pub id: AlbumId,
|
|
|
|
pub tracks: Vec<Track>,
|
2023-03-28 22:49:59 +02:00
|
|
|
}
|
2023-04-01 01:59:59 +02:00
|
|
|
|
|
|
|
/// The artist identifier.
|
2023-04-10 00:13:18 +02:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
|
2023-04-01 01:59:59 +02:00
|
|
|
pub struct ArtistId {
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// An artist.
|
2023-04-10 00:13:18 +02:00
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
2023-04-01 01:59:59 +02:00
|
|
|
pub struct Artist {
|
|
|
|
pub id: ArtistId,
|
|
|
|
pub albums: Vec<Album>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
2023-04-10 00:13:18 +02:00
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
|
|
|
|
pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| {
|
2023-04-01 01:59:59 +02:00
|
|
|
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()],
|
2023-04-10 11:27:07 +02:00
|
|
|
format: TrackFormat::Flac,
|
2023-04-01 01:59:59 +02:00
|
|
|
},
|
|
|
|
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(),
|
|
|
|
],
|
2023-04-10 11:27:07 +02:00
|
|
|
format: TrackFormat::Flac,
|
2023-04-01 01:59:59 +02:00
|
|
|
},
|
|
|
|
Track {
|
|
|
|
number: 3,
|
|
|
|
title: "track a.a.3".to_string(),
|
|
|
|
artist: vec!["artist a.a.3".to_string()],
|
2023-04-10 11:27:07 +02:00
|
|
|
format: TrackFormat::Flac,
|
2023-04-01 01:59:59 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
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()],
|
2023-04-10 11:27:07 +02:00
|
|
|
format: TrackFormat::Mp3,
|
2023-04-01 01:59:59 +02:00
|
|
|
},
|
|
|
|
Track {
|
|
|
|
number: 2,
|
|
|
|
title: "track a.b.2".to_string(),
|
|
|
|
artist: vec!["artist a.b.2".to_string()],
|
2023-04-10 11:27:07 +02:00
|
|
|
format: TrackFormat::Flac,
|
2023-04-01 01:59:59 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
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()],
|
2023-04-10 11:27:07 +02:00
|
|
|
format: TrackFormat::Mp3,
|
2023-04-01 01:59:59 +02:00
|
|
|
},
|
|
|
|
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(),
|
|
|
|
],
|
2023-04-10 11:27:07 +02:00
|
|
|
format: TrackFormat::Mp3,
|
2023-04-01 01:59:59 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
]
|
2023-04-10 00:13:18 +02:00
|
|
|
});
|
2023-04-01 01:59:59 +02:00
|
|
|
}
|