diff --git a/src/app/collection/browser.rs b/src/app/collection/browser.rs index d8d61c3..e932a18 100644 --- a/src/app/collection/browser.rs +++ b/src/app/collection/browser.rs @@ -157,11 +157,8 @@ mod test { assert_eq!(song.track_number, Some(5)); assert_eq!(song.disc_number, None); assert_eq!(song.title, Some("シャーベット (Sherbet)".to_owned())); - assert_eq!( - song.artists, - collection::MultiString(vec!["Tobokegao".to_owned()]) - ); - assert_eq!(song.album_artists, collection::MultiString(vec![])); + assert_eq!(song.artists, vec!["Tobokegao".to_owned()]); + assert_eq!(song.album_artists, Vec::::new()); assert_eq!(song.album, Some("Picnic".to_owned())); assert_eq!(song.year, Some(2016)); assert_eq!(song.artwork, Some(artwork_virtual_path)); diff --git a/src/app/collection/index.rs b/src/app/collection/index.rs index 6b61223..aa64c5a 100644 --- a/src/app/collection/index.rs +++ b/src/app/collection/index.rs @@ -202,16 +202,16 @@ impl IndexBuilder { fn add_album_to_artists(&mut self, song: &collection::Song) { let album_id: AlbumID = song.album_id(); - for artist_name in &song.album_artists.0 { + for artist_name in &song.album_artists { let artist = self.get_or_create_artist(artist_name); artist.albums.insert(album_id); } - for artist_name in &song.artists.0 { + for artist_name in &song.artists { let artist = self.get_or_create_artist(artist_name); - if song.album_artists.0.is_empty() { + if song.album_artists.is_empty() { artist.albums.insert(album_id); - } else if !song.album_artists.0.contains(artist_name) { + } else if !song.album_artists.contains(artist_name) { artist.album_appearances.insert(album_id); } } @@ -252,10 +252,10 @@ impl IndexBuilder { album.date_added = album.date_added.min(song.date_added); - if !song.album_artists.0.is_empty() { - album.artists = song.album_artists.0.clone(); - } else if !song.artists.0.is_empty() { - album.artists = song.artists.0.clone(); + if !song.album_artists.is_empty() { + album.artists = song.album_artists.clone(); + } else if !song.artists.is_empty() { + album.artists = song.artists.clone(); } album.songs.insert(song_id); @@ -413,9 +413,9 @@ pub struct AlbumKey { impl From<&collection::Song> for AlbumKey { fn from(song: &collection::Song) -> Self { - let album_artists = match song.album_artists.0.is_empty() { - true => &song.artists.0, - false => &song.album_artists.0, + let album_artists = match song.album_artists.is_empty() { + true => &song.artists, + false => &song.album_artists, }; AlbumKey { diff --git a/src/app/collection/scanner.rs b/src/app/collection/scanner.rs index 60d19f3..7fe7ad4 100644 --- a/src/app/collection/scanner.rs +++ b/src/app/collection/scanner.rs @@ -9,7 +9,7 @@ use tokio::sync::mpsc::UnboundedSender; use crate::app::vfs; use crate::app::{ - collection::{self, MultiString}, + collection::{self}, formats, }; @@ -135,16 +135,16 @@ fn process_directory, Q: AsRef>( track_number: metadata.track_number.map(|n| n as i64), disc_number: metadata.disc_number.map(|n| n as i64), title: metadata.title, - artists: MultiString(metadata.artists), - album_artists: MultiString(metadata.album_artists), + artists: metadata.artists, + album_artists: metadata.album_artists, year: metadata.year.map(|n| n as i64), album: metadata.album, artwork: metadata.has_artwork.then(|| entry_virtual_path.clone()), duration: metadata.duration.map(|n| n as i64), - lyricists: MultiString(metadata.lyricists), - composers: MultiString(metadata.composers), - genres: MultiString(metadata.genres), - labels: MultiString(metadata.labels), + lyricists: metadata.lyricists, + composers: metadata.composers, + genres: metadata.genres, + labels: metadata.labels, date_added: get_date_created(&entry_real_path).unwrap_or_default(), }); } else if artwork_file.is_none() diff --git a/src/app/collection/types.rs b/src/app/collection/types.rs index dc8402c..4601900 100644 --- a/src/app/collection/types.rs +++ b/src/app/collection/types.rs @@ -1,30 +1,12 @@ use std::path::PathBuf; use serde::{Deserialize, Serialize}; -use sqlx::prelude::FromRow; use crate::{ app::vfs::{self}, db, }; -// TODO no longer needed!! -#[derive(Clone, Debug, FromRow, PartialEq, Eq, Serialize, Deserialize)] -pub struct MultiString(pub Vec); - -impl MultiString { - pub const SEPARATOR: &'static str = "\u{000C}"; -} - -impl From> for MultiString { - fn from(value: Option) -> Self { - match value { - None => Self(Vec::new()), - Some(s) => Self(s.split(Self::SEPARATOR).map(|s| s.to_string()).collect()), - } - } -} - #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Directory not found: {0}")] @@ -63,16 +45,16 @@ pub struct Song { pub track_number: Option, pub disc_number: Option, pub title: Option, - pub artists: MultiString, - pub album_artists: MultiString, + pub artists: Vec, + pub album_artists: Vec, pub year: Option, pub album: Option, pub artwork: Option, pub duration: Option, - pub lyricists: MultiString, - pub composers: MultiString, - pub genres: MultiString, - pub labels: MultiString, + pub lyricists: Vec, + pub composers: Vec, + pub genres: Vec, + pub labels: Vec, pub date_added: i64, } diff --git a/src/app/lastfm.rs b/src/app/lastfm.rs index 451e710..eec1bb2 100644 --- a/src/app/lastfm.rs +++ b/src/app/lastfm.rs @@ -83,7 +83,7 @@ impl Manager { async fn scrobble_from_path(&self, track: &Path) -> Result { let song = self.browser.get_song(track).await?; Ok(Scrobble::new( - song.artists.0.first().map(|s| s.as_str()).unwrap_or(""), + song.artists.first().map(|s| s.as_str()).unwrap_or(""), song.title.as_deref().unwrap_or(""), song.album.as_deref().unwrap_or(""), )) diff --git a/src/server/dto/v7.rs b/src/server/dto/v7.rs index 301f3ba..40310bf 100644 --- a/src/server/dto/v7.rs +++ b/src/server/dto/v7.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use crate::app::{ - collection::{self, MultiString}, + collection::{self}, config, ddns, settings, thumbnail, user, vfs, }; use std::{convert::From, path::PathBuf}; @@ -267,12 +267,16 @@ impl From for CollectionFile { } } -impl MultiString { +trait VecExt { + fn to_v7_string(&self) -> Option; +} + +impl VecExt for Vec { fn to_v7_string(&self) -> Option { - if self.0.is_empty() { + if self.is_empty() { None } else { - Some(self.0.join("")) + Some(self.join("")) } } } @@ -302,7 +306,7 @@ impl From for Song { track_number: s.track_number, disc_number: s.disc_number, title: s.title, - artist: s.artists.0.first().cloned(), + artist: s.artists.first().cloned(), album_artist: s.album_artists.to_v7_string(), year: s.year, album: s.album, diff --git a/src/server/dto/v8.rs b/src/server/dto/v8.rs index 8f54549..5ca51eb 100644 --- a/src/server/dto/v8.rs +++ b/src/server/dto/v8.rs @@ -266,16 +266,16 @@ impl From for Song { track_number: s.track_number, disc_number: s.disc_number, title: s.title, - artists: s.artists.0, - album_artists: s.album_artists.0, + artists: s.artists, + album_artists: s.album_artists, year: s.year, album: s.album, artwork: s.artwork, duration: s.duration, - lyricists: s.lyricists.0, - composers: s.composers.0, - genres: s.genres.0, - labels: s.labels.0, + lyricists: s.lyricists, + composers: s.composers, + genres: s.genres, + labels: s.labels, } } }