From 30d3dc1ac8783933ed3ee86994925faeb9331240 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Thu, 11 May 2023 21:35:39 +0200 Subject: [PATCH] Replace Quality enum with struct --- src/database/json/mod.rs | 15 +- src/lib.rs | 13 +- src/library/beets/mod.rs | 20 +- src/testlib.rs | 65 ++++- src/tui/ui.rs | 8 +- tests/files/database/database.json | 2 +- tests/lib.rs | 397 +++++++++++++++++++++++------ 7 files changed, 402 insertions(+), 118 deletions(-) diff --git a/src/database/json/mod.rs b/src/database/json/mod.rs index ee4c66e..38b6aec 100644 --- a/src/database/json/mod.rs +++ b/src/database/json/mod.rs @@ -61,7 +61,7 @@ mod tests { use super::*; - use crate::{tests::COLLECTION, Artist, ArtistId, Quality}; + use crate::{tests::COLLECTION, Artist, ArtistId, Format}; fn artist_to_json(artist: &Artist) -> String { let album_artist = &artist.id.name; @@ -81,21 +81,18 @@ mod tests { track_artist.push(format!("\"{artist}\"")) } let track_artist = track_artist.join(","); - - let quality_field = match track.quality { - Quality::Flac => format!("\"quality\":\"{format}\"", format = stringify!(Flac)), - Quality::Mp3(bitrate) => format!( - "\"quality\":{{\"{format}\":{bitrate}}}", - format = stringify!(Mp3) - ), + let track_format = match track.quality.format { + Format::Flac => stringify!(Flac), + Format::Mp3 => stringify!(Mp3), }; + let track_bitrate = track.quality.bitrate; tracks.push(format!( "{{\ \"number\":{track_number},\ \"title\":\"{track_title}\",\ \"artist\":[{track_artist}],\ - {quality_field}\ + \"quality\":{{\"format\":\"{track_format}\",\"bitrate\":{track_bitrate}}}\ }}" )); } diff --git a/src/lib.rs b/src/lib.rs index fad5c4e..d372e05 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,10 +14,17 @@ use uuid::Uuid; pub type Mbid = Uuid; /// The track file format. -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] -pub enum Quality { +#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)] +pub enum Format { Flac, - Mp3(u32), + Mp3, +} + +/// The track quality. Combines format and bitrate information. +#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)] +pub struct Quality { + pub format: Format, + pub bitrate: u32, } /// A single track on an album. diff --git a/src/library/beets/mod.rs b/src/library/beets/mod.rs index 41934e6..761e974 100644 --- a/src/library/beets/mod.rs +++ b/src/library/beets/mod.rs @@ -9,7 +9,7 @@ use std::{ #[cfg(test)] use mockall::automock; -use crate::{Album, AlbumId, Artist, ArtistId, Quality, Track}; +use crate::{Album, AlbumId, Artist, ArtistId, Format, Quality, Track}; use super::{Error, Field, ILibrary, Query}; @@ -153,10 +153,13 @@ impl ILibraryPrivate for BeetsLibrary { number: track_number, title: track_title, artist: track_artist.split("; ").map(|s| s.to_owned()).collect(), - quality: match track_format.as_ref() { - TRACK_FORMAT_FLAC => Quality::Flac, - TRACK_FORMAT_MP3 => Quality::Mp3(track_bitrate), - _ => return Err(Error::Invalid(line.to_string())), + quality: Quality { + format: match track_format.as_ref() { + TRACK_FORMAT_FLAC => Format::Flac, + TRACK_FORMAT_MP3 => Format::Mp3, + _ => return Err(Error::Invalid(line.to_string())), + }, + bitrate: track_bitrate, }, }; @@ -222,10 +225,11 @@ mod tests { let track_number = &track.number; let track_title = &track.title; let track_artist = &track.artist.join("; "); - let (track_format, track_bitrate) = match track.quality { - Quality::Flac => (TRACK_FORMAT_FLAC, 1411), - Quality::Mp3(bitrate) => (TRACK_FORMAT_MP3, bitrate), + let track_format = match track.quality.format { + Format::Flac => TRACK_FORMAT_FLAC, + Format::Mp3 => TRACK_FORMAT_MP3, }; + let track_bitrate = track.quality.bitrate; strings.push(format!( "{album_artist}{0}{album_year}{0}{album_title}{0}\ diff --git a/src/testlib.rs b/src/testlib.rs index 9f628b0..95703ca 100644 --- a/src/testlib.rs +++ b/src/testlib.rs @@ -16,7 +16,10 @@ macro_rules! collection { number: 1, title: "track a.a.1".to_string(), artist: vec!["artist a.a.1".to_string()], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 992, + }, }, Track { number: 2, @@ -25,13 +28,19 @@ macro_rules! collection { "artist a.a.2.1".to_string(), "artist a.a.2.2".to_string(), ], - quality: Quality::Mp3(320), + quality: Quality { + format: Format::Mp3, + bitrate: 320, + }, }, Track { number: 3, title: "track a.a.3".to_string(), artist: vec!["artist a.a.3".to_string()], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1061, + }, }, ], }, @@ -45,13 +54,19 @@ macro_rules! collection { number: 1, title: "track a.b.1".to_string(), artist: vec!["artist a.b.1".to_string()], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1004, + }, }, Track { number: 2, title: "track a.b.2".to_string(), artist: vec!["artist a.b.2".to_string()], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1077, + }, }, ], }, @@ -72,7 +87,10 @@ macro_rules! collection { number: 1, title: "track b.a.1".to_string(), artist: vec!["artist b.a.1".to_string()], - quality: Quality::Mp3(190), + quality: Quality { + format: Format::Mp3, + bitrate: 190, + }, }, Track { number: 2, @@ -81,7 +99,10 @@ macro_rules! collection { "artist b.a.2.1".to_string(), "artist b.a.2.2".to_string(), ], - quality: Quality::Mp3(120), + quality: Quality { + format: Format::Mp3, + bitrate: 120, + }, }, ], }, @@ -95,7 +116,10 @@ macro_rules! collection { number: 1, title: "track b.b.1".to_string(), artist: vec!["artist b.b.1".to_string()], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1077, + }, }, Track { number: 2, @@ -104,7 +128,10 @@ macro_rules! collection { "artist b.b.2.1".to_string(), "artist b.b.2.2".to_string(), ], - quality: Quality::Mp3(320), + quality: Quality { + format: Format::Mp3, + bitrate: 320, + }, }, ], }, @@ -125,7 +152,10 @@ macro_rules! collection { number: 1, title: "track c.a.1".to_string(), artist: vec!["artist c.a.1".to_string()], - quality: Quality::Mp3(320), + quality: Quality { + format: Format::Mp3, + bitrate: 320, + }, }, Track { number: 2, @@ -134,7 +164,10 @@ macro_rules! collection { "artist c.a.2.1".to_string(), "artist c.a.2.2".to_string(), ], - quality: Quality::Mp3(120), + quality: Quality { + format: Format::Mp3, + bitrate: 120, + }, }, ], }, @@ -148,7 +181,10 @@ macro_rules! collection { number: 1, title: "track c.b.1".to_string(), artist: vec!["artist c.b.1".to_string()], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1041, + }, }, Track { number: 2, @@ -157,7 +193,10 @@ macro_rules! collection { "artist c.b.2.1".to_string(), "artist c.b.2.2".to_string(), ], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 756, + }, }, ], }, diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 07211dd..7c8eee5 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -1,4 +1,4 @@ -use musichoard::{Album, Artist, Collection, Quality, Track}; +use musichoard::{Album, Artist, Collection, Format, Track}; use ratatui::{ backend::Backend, layout::{Alignment, Rect}, @@ -422,9 +422,9 @@ impl<'a, 'b> TrackState<'a, 'b> { .map(|t| t.artist.join("; ")) .unwrap_or_else(|| "".to_string()), track - .map(|t| match t.quality { - Quality::Flac => "FLAC".to_string(), - Quality::Mp3(bitrate) => format!("MP3 {bitrate}"), + .map(|t| match t.quality.format { + Format::Flac => "FLAC".to_string(), + Format::Mp3 => format!("MP3 {}", t.quality.bitrate), }) .unwrap_or_else(|| "".to_string()), )); diff --git a/tests/files/database/database.json b/tests/files/database/database.json index 25f2810..42cb67a 100644 --- a/tests/files/database/database.json +++ b/tests/files/database/database.json @@ -1 +1 @@ -[{"id":{"name":"Аркона"},"albums":[{"id":{"year":2011,"title":"Slovo"},"tracks":[{"number":1,"title":"Az’","artist":["Аркона"],"quality":"Flac"},{"number":2,"title":"Arkaim","artist":["Аркона"],"quality":"Flac"},{"number":3,"title":"Bol’no mne","artist":["Аркона"],"quality":"Flac"},{"number":4,"title":"Leshiy","artist":["Аркона"],"quality":"Flac"},{"number":5,"title":"Zakliatie","artist":["Аркона"],"quality":"Flac"},{"number":6,"title":"Predok","artist":["Аркона"],"quality":"Flac"},{"number":7,"title":"Nikogda","artist":["Аркона"],"quality":"Flac"},{"number":8,"title":"Tam za tumanami","artist":["Аркона"],"quality":"Flac"},{"number":9,"title":"Potomok","artist":["Аркона"],"quality":"Flac"},{"number":10,"title":"Slovo","artist":["Аркона"],"quality":"Flac"},{"number":11,"title":"Odna","artist":["Аркона"],"quality":"Flac"},{"number":12,"title":"Vo moiom sadochke…","artist":["Аркона"],"quality":"Flac"},{"number":13,"title":"Stenka na stenku","artist":["Аркона"],"quality":"Flac"},{"number":14,"title":"Zimushka","artist":["Аркона"],"quality":"Flac"}]}]},{"id":{"name":"Eluveitie"},"albums":[{"id":{"year":2008,"title":"Slania"},"tracks":[{"number":1,"title":"Samon","artist":["Eluveitie"],"quality":"Flac"},{"number":2,"title":"Primordial Breath","artist":["Eluveitie"],"quality":"Flac"},{"number":3,"title":"Inis Mona","artist":["Eluveitie"],"quality":"Flac"},{"number":4,"title":"Gray Sublime Archon","artist":["Eluveitie"],"quality":"Flac"},{"number":5,"title":"Anagantios","artist":["Eluveitie"],"quality":"Flac"},{"number":6,"title":"Bloodstained Ground","artist":["Eluveitie"],"quality":"Flac"},{"number":7,"title":"The Somber Lay","artist":["Eluveitie"],"quality":"Flac"},{"number":8,"title":"Slanias Song","artist":["Eluveitie"],"quality":"Flac"},{"number":9,"title":"Giamonios","artist":["Eluveitie"],"quality":"Flac"},{"number":10,"title":"Tarvos","artist":["Eluveitie"],"quality":"Flac"},{"number":11,"title":"Calling the Rain","artist":["Eluveitie"],"quality":"Flac"},{"number":12,"title":"Elembivos","artist":["Eluveitie"],"quality":"Flac"}]},{"id":{"year":2004,"title":"Vên [re‐recorded]"},"tracks":[{"number":1,"title":"Verja Urit an Bitus","artist":["Eluveitie"],"quality":"Flac"},{"number":2,"title":"Uis Elveti","artist":["Eluveitie"],"quality":"Flac"},{"number":3,"title":"Ôrô","artist":["Eluveitie"],"quality":"Flac"},{"number":4,"title":"Lament","artist":["Eluveitie"],"quality":"Flac"},{"number":5,"title":"Druid","artist":["Eluveitie"],"quality":"Flac"},{"number":6,"title":"Jêzaïg","artist":["Eluveitie"],"quality":"Flac"}]}]},{"id":{"name":"Frontside"},"albums":[{"id":{"year":2001,"title":"…nasze jest królestwo, potęga i chwała na wieki…"},"tracks":[{"number":1,"title":"Intro = Chaos","artist":["Frontside"],"quality":"Flac"},{"number":2,"title":"Modlitwa","artist":["Frontside"],"quality":"Flac"},{"number":3,"title":"Długa droga z piekła","artist":["Frontside"],"quality":"Flac"},{"number":4,"title":"Synowie ognia","artist":["Frontside"],"quality":"Flac"},{"number":5,"title":"1902","artist":["Frontside"],"quality":"Flac"},{"number":6,"title":"Krew za krew","artist":["Frontside"],"quality":"Flac"},{"number":7,"title":"Kulminacja","artist":["Frontside"],"quality":"Flac"},{"number":8,"title":"Judasz","artist":["Frontside"],"quality":"Flac"},{"number":9,"title":"Więzy","artist":["Frontside"],"quality":"Flac"},{"number":10,"title":"Zagubione dusze","artist":["Frontside"],"quality":"Flac"},{"number":11,"title":"Linia życia","artist":["Frontside"],"quality":"Flac"}]}]},{"id":{"name":"Heaven’s Basement"},"albums":[{"id":{"year":2011,"title":"Unbreakable"},"tracks":[{"number":1,"title":"Unbreakable","artist":["Heaven’s Basement"],"quality":{"Mp3":208}},{"number":2,"title":"Guilt Trips and Sins","artist":["Heaven’s Basement"],"quality":{"Mp3":205}},{"number":3,"title":"The Long Goodbye","artist":["Heaven’s Basement"],"quality":{"Mp3":227}},{"number":4,"title":"Close Encounters","artist":["Heaven’s Basement"],"quality":{"Mp3":213}},{"number":5,"title":"Paranoia","artist":["Heaven’s Basement"],"quality":{"Mp3":218}},{"number":6,"title":"Let Me Out of Here","artist":["Heaven’s Basement"],"quality":{"Mp3":207}},{"number":7,"title":"Leeches","artist":["Heaven’s Basement"],"quality":{"Mp3":225}}]}]},{"id":{"name":"Metallica"},"albums":[{"id":{"year":1984,"title":"Ride the Lightning"},"tracks":[{"number":1,"title":"Fight Fire with Fire","artist":["Metallica"],"quality":"Flac"},{"number":2,"title":"Ride the Lightning","artist":["Metallica"],"quality":"Flac"},{"number":3,"title":"For Whom the Bell Tolls","artist":["Metallica"],"quality":"Flac"},{"number":4,"title":"Fade to Black","artist":["Metallica"],"quality":"Flac"},{"number":5,"title":"Trapped under Ice","artist":["Metallica"],"quality":"Flac"},{"number":6,"title":"Escape","artist":["Metallica"],"quality":"Flac"},{"number":7,"title":"Creeping Death","artist":["Metallica"],"quality":"Flac"},{"number":8,"title":"The Call of Ktulu","artist":["Metallica"],"quality":"Flac"}]},{"id":{"year":1999,"title":"S&M"},"tracks":[{"number":1,"title":"The Ecstasy of Gold","artist":["Metallica"],"quality":"Flac"},{"number":2,"title":"The Call of Ktulu","artist":["Metallica"],"quality":"Flac"},{"number":3,"title":"Master of Puppets","artist":["Metallica"],"quality":"Flac"},{"number":4,"title":"Of Wolf and Man","artist":["Metallica"],"quality":"Flac"},{"number":5,"title":"The Thing That Should Not Be","artist":["Metallica"],"quality":"Flac"},{"number":6,"title":"Fuel","artist":["Metallica"],"quality":"Flac"},{"number":7,"title":"The Memory Remains","artist":["Metallica"],"quality":"Flac"},{"number":8,"title":"No Leaf Clover","artist":["Metallica"],"quality":"Flac"},{"number":9,"title":"Hero of the Day","artist":["Metallica"],"quality":"Flac"},{"number":10,"title":"Devil’s Dance","artist":["Metallica"],"quality":"Flac"},{"number":11,"title":"Bleeding Me","artist":["Metallica"],"quality":"Flac"},{"number":12,"title":"Nothing Else Matters","artist":["Metallica"],"quality":"Flac"},{"number":13,"title":"Until It Sleeps","artist":["Metallica"],"quality":"Flac"},{"number":14,"title":"For Whom the Bell Tolls","artist":["Metallica"],"quality":"Flac"},{"number":15,"title":"−Human","artist":["Metallica"],"quality":"Flac"},{"number":16,"title":"Wherever I May Roam","artist":["Metallica"],"quality":"Flac"},{"number":17,"title":"Outlaw Torn","artist":["Metallica"],"quality":"Flac"},{"number":18,"title":"Sad but True","artist":["Metallica"],"quality":"Flac"},{"number":19,"title":"One","artist":["Metallica"],"quality":"Flac"},{"number":20,"title":"Enter Sandman","artist":["Metallica"],"quality":"Flac"},{"number":21,"title":"Battery","artist":["Metallica"],"quality":"Flac"}]}]}] \ No newline at end of file +[{"id":{"name":"Аркона"},"albums":[{"id":{"year":2011,"title":"Slovo"},"tracks":[{"number":1,"title":"Az’","artist":["Аркона"],"quality":{"format":"Flac","bitrate":992}},{"number":2,"title":"Arkaim","artist":["Аркона"],"quality":{"format":"Flac","bitrate":1061}},{"number":3,"title":"Bol’no mne","artist":["Аркона"],"quality":{"format":"Flac","bitrate":1004}},{"number":4,"title":"Leshiy","artist":["Аркона"],"quality":{"format":"Flac","bitrate":1077}},{"number":5,"title":"Zakliatie","artist":["Аркона"],"quality":{"format":"Flac","bitrate":1041}},{"number":6,"title":"Predok","artist":["Аркона"],"quality":{"format":"Flac","bitrate":756}},{"number":7,"title":"Nikogda","artist":["Аркона"],"quality":{"format":"Flac","bitrate":1059}},{"number":8,"title":"Tam za tumanami","artist":["Аркона"],"quality":{"format":"Flac","bitrate":1023}},{"number":9,"title":"Potomok","artist":["Аркона"],"quality":{"format":"Flac","bitrate":838}},{"number":10,"title":"Slovo","artist":["Аркона"],"quality":{"format":"Flac","bitrate":1028}},{"number":11,"title":"Odna","artist":["Аркона"],"quality":{"format":"Flac","bitrate":991}},{"number":12,"title":"Vo moiom sadochke…","artist":["Аркона"],"quality":{"format":"Flac","bitrate":919}},{"number":13,"title":"Stenka na stenku","artist":["Аркона"],"quality":{"format":"Flac","bitrate":1039}},{"number":14,"title":"Zimushka","artist":["Аркона"],"quality":{"format":"Flac","bitrate":974}}]}]},{"id":{"name":"Eluveitie"},"albums":[{"id":{"year":2008,"title":"Slania"},"tracks":[{"number":1,"title":"Samon","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":953}},{"number":2,"title":"Primordial Breath","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1103}},{"number":3,"title":"Inis Mona","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1117}},{"number":4,"title":"Gray Sublime Archon","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1092}},{"number":5,"title":"Anagantios","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":923}},{"number":6,"title":"Bloodstained Ground","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1098}},{"number":7,"title":"The Somber Lay","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1068}},{"number":8,"title":"Slanias Song","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1098}},{"number":9,"title":"Giamonios","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":825}},{"number":10,"title":"Tarvos","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1115}},{"number":11,"title":"Calling the Rain","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1096}},{"number":12,"title":"Elembivos","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1059}}]},{"id":{"year":2004,"title":"Vên [re‐recorded]"},"tracks":[{"number":1,"title":"Verja Urit an Bitus","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":961}},{"number":2,"title":"Uis Elveti","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1067}},{"number":3,"title":"Ôrô","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":933}},{"number":4,"title":"Lament","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1083}},{"number":5,"title":"Druid","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1073}},{"number":6,"title":"Jêzaïg","artist":["Eluveitie"],"quality":{"format":"Flac","bitrate":1002}}]}]},{"id":{"name":"Frontside"},"albums":[{"id":{"year":2001,"title":"…nasze jest królestwo, potęga i chwała na wieki…"},"tracks":[{"number":1,"title":"Intro = Chaos","artist":["Frontside"],"quality":{"format":"Flac","bitrate":1024}},{"number":2,"title":"Modlitwa","artist":["Frontside"],"quality":{"format":"Flac","bitrate":1073}},{"number":3,"title":"Długa droga z piekła","artist":["Frontside"],"quality":{"format":"Flac","bitrate":1058}},{"number":4,"title":"Synowie ognia","artist":["Frontside"],"quality":{"format":"Flac","bitrate":1066}},{"number":5,"title":"1902","artist":["Frontside"],"quality":{"format":"Flac","bitrate":1074}},{"number":6,"title":"Krew za krew","artist":["Frontside"],"quality":{"format":"Flac","bitrate":1080}},{"number":7,"title":"Kulminacja","artist":["Frontside"],"quality":{"format":"Flac","bitrate":992}},{"number":8,"title":"Judasz","artist":["Frontside"],"quality":{"format":"Flac","bitrate":1018}},{"number":9,"title":"Więzy","artist":["Frontside"],"quality":{"format":"Flac","bitrate":1077}},{"number":10,"title":"Zagubione dusze","artist":["Frontside"],"quality":{"format":"Flac","bitrate":1033}},{"number":11,"title":"Linia życia","artist":["Frontside"],"quality":{"format":"Flac","bitrate":987}}]}]},{"id":{"name":"Heaven’s Basement"},"albums":[{"id":{"year":2011,"title":"Unbreakable"},"tracks":[{"number":1,"title":"Unbreakable","artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":208}},{"number":2,"title":"Guilt Trips and Sins","artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":205}},{"number":3,"title":"The Long Goodbye","artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":227}},{"number":4,"title":"Close Encounters","artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":213}},{"number":5,"title":"Paranoia","artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":218}},{"number":6,"title":"Let Me Out of Here","artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":207}},{"number":7,"title":"Leeches","artist":["Heaven’s Basement"],"quality":{"format":"Mp3","bitrate":225}}]}]},{"id":{"name":"Metallica"},"albums":[{"id":{"year":1984,"title":"Ride the Lightning"},"tracks":[{"number":1,"title":"Fight Fire with Fire","artist":["Metallica"],"quality":{"format":"Flac","bitrate":954}},{"number":2,"title":"Ride the Lightning","artist":["Metallica"],"quality":{"format":"Flac","bitrate":951}},{"number":3,"title":"For Whom the Bell Tolls","artist":["Metallica"],"quality":{"format":"Flac","bitrate":889}},{"number":4,"title":"Fade to Black","artist":["Metallica"],"quality":{"format":"Flac","bitrate":939}},{"number":5,"title":"Trapped under Ice","artist":["Metallica"],"quality":{"format":"Flac","bitrate":955}},{"number":6,"title":"Escape","artist":["Metallica"],"quality":{"format":"Flac","bitrate":941}},{"number":7,"title":"Creeping Death","artist":["Metallica"],"quality":{"format":"Flac","bitrate":958}},{"number":8,"title":"The Call of Ktulu","artist":["Metallica"],"quality":{"format":"Flac","bitrate":888}}]},{"id":{"year":1999,"title":"S&M"},"tracks":[{"number":1,"title":"The Ecstasy of Gold","artist":["Metallica"],"quality":{"format":"Flac","bitrate":875}},{"number":2,"title":"The Call of Ktulu","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1030}},{"number":3,"title":"Master of Puppets","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1082}},{"number":4,"title":"Of Wolf and Man","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1115}},{"number":5,"title":"The Thing That Should Not Be","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1029}},{"number":6,"title":"Fuel","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1057}},{"number":7,"title":"The Memory Remains","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1080}},{"number":8,"title":"No Leaf Clover","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1004}},{"number":9,"title":"Hero of the Day","artist":["Metallica"],"quality":{"format":"Flac","bitrate":962}},{"number":10,"title":"Devil’s Dance","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1076}},{"number":11,"title":"Bleeding Me","artist":["Metallica"],"quality":{"format":"Flac","bitrate":993}},{"number":12,"title":"Nothing Else Matters","artist":["Metallica"],"quality":{"format":"Flac","bitrate":875}},{"number":13,"title":"Until It Sleeps","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1038}},{"number":14,"title":"For Whom the Bell Tolls","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1072}},{"number":15,"title":"−Human","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1029}},{"number":16,"title":"Wherever I May Roam","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1035}},{"number":17,"title":"Outlaw Torn","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1042}},{"number":18,"title":"Sad but True","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1082}},{"number":19,"title":"One","artist":["Metallica"],"quality":{"format":"Flac","bitrate":1017}},{"number":20,"title":"Enter Sandman","artist":["Metallica"],"quality":{"format":"Flac","bitrate":993}},{"number":21,"title":"Battery","artist":["Metallica"],"quality":{"format":"Flac","bitrate":967}}]}]}] \ No newline at end of file diff --git a/tests/lib.rs b/tests/lib.rs index a180036..b92eb2b 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -1,7 +1,7 @@ mod database; mod library; -use musichoard::{Album, AlbumId, Artist, ArtistId, Quality, Track}; +use musichoard::{Album, AlbumId, Artist, ArtistId, Format, Quality, Track}; use once_cell::sync::Lazy; static COLLECTION: Lazy> = Lazy::new(|| { @@ -20,85 +20,127 @@ static COLLECTION: Lazy> = Lazy::new(|| { number: 01, title: String::from("Az’"), artist: vec![String::from("Аркона")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 992, + }, }, Track { number: 02, title: String::from("Arkaim"), artist: vec![String::from("Аркона")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1061, + }, }, Track { number: 03, title: String::from("Bol’no mne"), artist: vec![String::from("Аркона")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1004, + }, }, Track { number: 04, title: String::from("Leshiy"), artist: vec![String::from("Аркона")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1077, + }, }, Track { number: 05, title: String::from("Zakliatie"), artist: vec![String::from("Аркона")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1041, + }, }, Track { number: 06, title: String::from("Predok"), artist: vec![String::from("Аркона")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 756, + }, }, Track { number: 07, title: String::from("Nikogda"), artist: vec![String::from("Аркона")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1059, + }, }, Track { number: 08, title: String::from("Tam za tumanami"), artist: vec![String::from("Аркона")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1023, + }, }, Track { number: 09, title: String::from("Potomok"), artist: vec![String::from("Аркона")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 838, + }, }, Track { number: 10, title: String::from("Slovo"), artist: vec![String::from("Аркона")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1028, + }, }, Track { number: 11, title: String::from("Odna"), artist: vec![String::from("Аркона")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 991, + }, }, Track { number: 12, title: String::from("Vo moiom sadochke…"), artist: vec![String::from("Аркона")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 919, + }, }, Track { number: 13, title: String::from("Stenka na stenku"), artist: vec![String::from("Аркона")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1039, + }, }, Track { number: 14, title: String::from("Zimushka"), artist: vec![String::from("Аркона")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 974, + }, }, ], }], @@ -118,73 +160,109 @@ static COLLECTION: Lazy> = Lazy::new(|| { number: 01, title: String::from("Samon"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 953, + }, }, Track { number: 02, title: String::from("Primordial Breath"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1103, + }, }, Track { number: 03, title: String::from("Inis Mona"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1117, + }, }, Track { number: 04, title: String::from("Gray Sublime Archon"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1092, + }, }, Track { number: 05, title: String::from("Anagantios"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 923, + }, }, Track { number: 06, title: String::from("Bloodstained Ground"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1098, + }, }, Track { number: 07, title: String::from("The Somber Lay"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1068, + }, }, Track { number: 08, title: String::from("Slanias Song"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1098, + }, }, Track { number: 09, title: String::from("Giamonios"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 825, + }, }, Track { number: 10, title: String::from("Tarvos"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1115, + }, }, Track { number: 11, title: String::from("Calling the Rain"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1096, + }, }, Track { number: 12, title: String::from("Elembivos"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1059, + }, }, ], }, @@ -198,37 +276,55 @@ static COLLECTION: Lazy> = Lazy::new(|| { number: 01, title: String::from("Verja Urit an Bitus"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 961, + }, }, Track { number: 02, title: String::from("Uis Elveti"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1067, + }, }, Track { number: 03, title: String::from("Ôrô"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 933, + }, }, Track { number: 04, title: String::from("Lament"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1083, + }, }, Track { number: 05, title: String::from("Druid"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1073, + }, }, Track { number: 06, title: String::from("Jêzaïg"), artist: vec![String::from("Eluveitie")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1002, + }, }, ], }, @@ -248,67 +344,100 @@ static COLLECTION: Lazy> = Lazy::new(|| { number: 01, title: String::from("Intro = Chaos"), artist: vec![String::from("Frontside")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1024, + }, }, Track { number: 02, title: String::from("Modlitwa"), artist: vec![String::from("Frontside")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1073, + }, }, Track { number: 03, title: String::from("Długa droga z piekła"), artist: vec![String::from("Frontside")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1058, + }, }, Track { number: 04, title: String::from("Synowie ognia"), artist: vec![String::from("Frontside")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1066, + }, }, Track { number: 05, title: String::from("1902"), artist: vec![String::from("Frontside")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1074, + }, }, Track { number: 06, title: String::from("Krew za krew"), artist: vec![String::from("Frontside")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1080, + }, }, Track { number: 07, title: String::from("Kulminacja"), artist: vec![String::from("Frontside")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 992, + }, }, Track { number: 08, title: String::from("Judasz"), artist: vec![String::from("Frontside")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1018, + }, }, Track { number: 09, title: String::from("Więzy"), artist: vec![String::from("Frontside")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1077, + }, }, Track { number: 10, title: String::from("Zagubione dusze"), artist: vec![String::from("Frontside")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1033, + }, }, Track { number: 11, title: String::from("Linia życia"), artist: vec![String::from("Frontside")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 987, + }, }, ], }], @@ -327,43 +456,64 @@ static COLLECTION: Lazy> = Lazy::new(|| { number: 01, title: String::from("Unbreakable"), artist: vec![String::from("Heaven’s Basement")], - quality: Quality::Mp3(208), + quality: Quality { + format: Format::Mp3, + bitrate: 208, + }, }, Track { number: 02, title: String::from("Guilt Trips and Sins"), artist: vec![String::from("Heaven’s Basement")], - quality: Quality::Mp3(205), + quality: Quality { + format: Format::Mp3, + bitrate: 205, + }, }, Track { number: 03, title: String::from("The Long Goodbye"), artist: vec![String::from("Heaven’s Basement")], - quality: Quality::Mp3(227), + quality: Quality { + format: Format::Mp3, + bitrate: 227, + }, }, Track { number: 04, title: String::from("Close Encounters"), artist: vec![String::from("Heaven’s Basement")], - quality: Quality::Mp3(213), + quality: Quality { + format: Format::Mp3, + bitrate: 213, + }, }, Track { number: 05, title: String::from("Paranoia"), artist: vec![String::from("Heaven’s Basement")], - quality: Quality::Mp3(218), + quality: Quality { + format: Format::Mp3, + bitrate: 218, + }, }, Track { number: 06, title: String::from("Let Me Out of Here"), artist: vec![String::from("Heaven’s Basement")], - quality: Quality::Mp3(207), + quality: Quality { + format: Format::Mp3, + bitrate: 207, + }, }, Track { number: 07, title: String::from("Leeches"), artist: vec![String::from("Heaven’s Basement")], - quality: Quality::Mp3(225), + quality: Quality { + format: Format::Mp3, + bitrate: 225, + }, }, ], }], @@ -383,49 +533,73 @@ static COLLECTION: Lazy> = Lazy::new(|| { number: 01, title: String::from("Fight Fire with Fire"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 954, + }, }, Track { number: 02, title: String::from("Ride the Lightning"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 951, + }, }, Track { number: 03, title: String::from("For Whom the Bell Tolls"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 889, + }, }, Track { number: 04, title: String::from("Fade to Black"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 939, + }, }, Track { number: 05, title: String::from("Trapped under Ice"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 955, + }, }, Track { number: 06, title: String::from("Escape"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 941, + }, }, Track { number: 07, title: String::from("Creeping Death"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 958, + }, }, Track { number: 08, title: String::from("The Call of Ktulu"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 888, + }, }, ], }, @@ -439,127 +613,190 @@ static COLLECTION: Lazy> = Lazy::new(|| { number: 01, title: String::from("The Ecstasy of Gold"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 875, + }, }, Track { number: 02, title: String::from("The Call of Ktulu"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1030, + }, }, Track { number: 03, title: String::from("Master of Puppets"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1082, + }, }, Track { number: 04, title: String::from("Of Wolf and Man"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1115, + }, }, Track { number: 05, title: String::from("The Thing That Should Not Be"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1029, + }, }, Track { number: 06, title: String::from("Fuel"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1057, + }, }, Track { number: 07, title: String::from("The Memory Remains"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1080, + }, }, Track { number: 08, title: String::from("No Leaf Clover"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1004, + }, }, Track { number: 09, title: String::from("Hero of the Day"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 962, + }, }, Track { number: 10, title: String::from("Devil’s Dance"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1076, + }, }, Track { number: 11, title: String::from("Bleeding Me"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 993, + }, }, Track { number: 12, title: String::from("Nothing Else Matters"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 875, + }, }, Track { number: 13, title: String::from("Until It Sleeps"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1038, + }, }, Track { number: 14, title: String::from("For Whom the Bell Tolls"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1072, + }, }, Track { number: 15, title: String::from("−Human"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1029, + }, }, Track { number: 16, title: String::from("Wherever I May Roam"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1035, + }, }, Track { number: 17, title: String::from("Outlaw Torn"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1042, + }, }, Track { number: 18, title: String::from("Sad but True"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1082, + }, }, Track { number: 19, title: String::from("One"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 1017, + }, }, Track { number: 20, title: String::from("Enter Sandman"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 993, + }, }, Track { number: 21, title: String::from("Battery"), artist: vec![String::from("Metallica")], - quality: Quality::Flac, + quality: Quality { + format: Format::Flac, + bitrate: 967, + }, }, ], },