Removes MultiString
This commit is contained in:
parent
e8af339cde
commit
ae9f94ce4f
7 changed files with 42 additions and 59 deletions
|
@ -157,11 +157,8 @@ mod test {
|
||||||
assert_eq!(song.track_number, Some(5));
|
assert_eq!(song.track_number, Some(5));
|
||||||
assert_eq!(song.disc_number, None);
|
assert_eq!(song.disc_number, None);
|
||||||
assert_eq!(song.title, Some("シャーベット (Sherbet)".to_owned()));
|
assert_eq!(song.title, Some("シャーベット (Sherbet)".to_owned()));
|
||||||
assert_eq!(
|
assert_eq!(song.artists, vec!["Tobokegao".to_owned()]);
|
||||||
song.artists,
|
assert_eq!(song.album_artists, Vec::<String>::new());
|
||||||
collection::MultiString(vec!["Tobokegao".to_owned()])
|
|
||||||
);
|
|
||||||
assert_eq!(song.album_artists, collection::MultiString(vec![]));
|
|
||||||
assert_eq!(song.album, Some("Picnic".to_owned()));
|
assert_eq!(song.album, Some("Picnic".to_owned()));
|
||||||
assert_eq!(song.year, Some(2016));
|
assert_eq!(song.year, Some(2016));
|
||||||
assert_eq!(song.artwork, Some(artwork_virtual_path));
|
assert_eq!(song.artwork, Some(artwork_virtual_path));
|
||||||
|
|
|
@ -202,16 +202,16 @@ impl IndexBuilder {
|
||||||
fn add_album_to_artists(&mut self, song: &collection::Song) {
|
fn add_album_to_artists(&mut self, song: &collection::Song) {
|
||||||
let album_id: AlbumID = song.album_id();
|
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);
|
let artist = self.get_or_create_artist(artist_name);
|
||||||
artist.albums.insert(album_id);
|
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);
|
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);
|
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);
|
artist.album_appearances.insert(album_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,10 +252,10 @@ impl IndexBuilder {
|
||||||
|
|
||||||
album.date_added = album.date_added.min(song.date_added);
|
album.date_added = album.date_added.min(song.date_added);
|
||||||
|
|
||||||
if !song.album_artists.0.is_empty() {
|
if !song.album_artists.is_empty() {
|
||||||
album.artists = song.album_artists.0.clone();
|
album.artists = song.album_artists.clone();
|
||||||
} else if !song.artists.0.is_empty() {
|
} else if !song.artists.is_empty() {
|
||||||
album.artists = song.artists.0.clone();
|
album.artists = song.artists.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
album.songs.insert(song_id);
|
album.songs.insert(song_id);
|
||||||
|
@ -413,9 +413,9 @@ pub struct AlbumKey {
|
||||||
|
|
||||||
impl From<&collection::Song> for AlbumKey {
|
impl From<&collection::Song> for AlbumKey {
|
||||||
fn from(song: &collection::Song) -> Self {
|
fn from(song: &collection::Song) -> Self {
|
||||||
let album_artists = match song.album_artists.0.is_empty() {
|
let album_artists = match song.album_artists.is_empty() {
|
||||||
true => &song.artists.0,
|
true => &song.artists,
|
||||||
false => &song.album_artists.0,
|
false => &song.album_artists,
|
||||||
};
|
};
|
||||||
|
|
||||||
AlbumKey {
|
AlbumKey {
|
||||||
|
|
|
@ -9,7 +9,7 @@ use tokio::sync::mpsc::UnboundedSender;
|
||||||
|
|
||||||
use crate::app::vfs;
|
use crate::app::vfs;
|
||||||
use crate::app::{
|
use crate::app::{
|
||||||
collection::{self, MultiString},
|
collection::{self},
|
||||||
formats,
|
formats,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -135,16 +135,16 @@ fn process_directory<P: AsRef<Path>, Q: AsRef<Path>>(
|
||||||
track_number: metadata.track_number.map(|n| n as i64),
|
track_number: metadata.track_number.map(|n| n as i64),
|
||||||
disc_number: metadata.disc_number.map(|n| n as i64),
|
disc_number: metadata.disc_number.map(|n| n as i64),
|
||||||
title: metadata.title,
|
title: metadata.title,
|
||||||
artists: MultiString(metadata.artists),
|
artists: metadata.artists,
|
||||||
album_artists: MultiString(metadata.album_artists),
|
album_artists: metadata.album_artists,
|
||||||
year: metadata.year.map(|n| n as i64),
|
year: metadata.year.map(|n| n as i64),
|
||||||
album: metadata.album,
|
album: metadata.album,
|
||||||
artwork: metadata.has_artwork.then(|| entry_virtual_path.clone()),
|
artwork: metadata.has_artwork.then(|| entry_virtual_path.clone()),
|
||||||
duration: metadata.duration.map(|n| n as i64),
|
duration: metadata.duration.map(|n| n as i64),
|
||||||
lyricists: MultiString(metadata.lyricists),
|
lyricists: metadata.lyricists,
|
||||||
composers: MultiString(metadata.composers),
|
composers: metadata.composers,
|
||||||
genres: MultiString(metadata.genres),
|
genres: metadata.genres,
|
||||||
labels: MultiString(metadata.labels),
|
labels: metadata.labels,
|
||||||
date_added: get_date_created(&entry_real_path).unwrap_or_default(),
|
date_added: get_date_created(&entry_real_path).unwrap_or_default(),
|
||||||
});
|
});
|
||||||
} else if artwork_file.is_none()
|
} else if artwork_file.is_none()
|
||||||
|
|
|
@ -1,30 +1,12 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::prelude::FromRow;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app::vfs::{self},
|
app::vfs::{self},
|
||||||
db,
|
db,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO no longer needed!!
|
|
||||||
#[derive(Clone, Debug, FromRow, PartialEq, Eq, Serialize, Deserialize)]
|
|
||||||
pub struct MultiString(pub Vec<String>);
|
|
||||||
|
|
||||||
impl MultiString {
|
|
||||||
pub const SEPARATOR: &'static str = "\u{000C}";
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Option<String>> for MultiString {
|
|
||||||
fn from(value: Option<String>) -> Self {
|
|
||||||
match value {
|
|
||||||
None => Self(Vec::new()),
|
|
||||||
Some(s) => Self(s.split(Self::SEPARATOR).map(|s| s.to_string()).collect()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Directory not found: {0}")]
|
#[error("Directory not found: {0}")]
|
||||||
|
@ -63,16 +45,16 @@ pub struct Song {
|
||||||
pub track_number: Option<i64>,
|
pub track_number: Option<i64>,
|
||||||
pub disc_number: Option<i64>,
|
pub disc_number: Option<i64>,
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
pub artists: MultiString,
|
pub artists: Vec<String>,
|
||||||
pub album_artists: MultiString,
|
pub album_artists: Vec<String>,
|
||||||
pub year: Option<i64>,
|
pub year: Option<i64>,
|
||||||
pub album: Option<String>,
|
pub album: Option<String>,
|
||||||
pub artwork: Option<PathBuf>,
|
pub artwork: Option<PathBuf>,
|
||||||
pub duration: Option<i64>,
|
pub duration: Option<i64>,
|
||||||
pub lyricists: MultiString,
|
pub lyricists: Vec<String>,
|
||||||
pub composers: MultiString,
|
pub composers: Vec<String>,
|
||||||
pub genres: MultiString,
|
pub genres: Vec<String>,
|
||||||
pub labels: MultiString,
|
pub labels: Vec<String>,
|
||||||
pub date_added: i64,
|
pub date_added: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl Manager {
|
||||||
async fn scrobble_from_path(&self, track: &Path) -> Result<Scrobble, Error> {
|
async fn scrobble_from_path(&self, track: &Path) -> Result<Scrobble, Error> {
|
||||||
let song = self.browser.get_song(track).await?;
|
let song = self.browser.get_song(track).await?;
|
||||||
Ok(Scrobble::new(
|
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.title.as_deref().unwrap_or(""),
|
||||||
song.album.as_deref().unwrap_or(""),
|
song.album.as_deref().unwrap_or(""),
|
||||||
))
|
))
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::app::{
|
use crate::app::{
|
||||||
collection::{self, MultiString},
|
collection::{self},
|
||||||
config, ddns, settings, thumbnail, user, vfs,
|
config, ddns, settings, thumbnail, user, vfs,
|
||||||
};
|
};
|
||||||
use std::{convert::From, path::PathBuf};
|
use std::{convert::From, path::PathBuf};
|
||||||
|
@ -267,12 +267,16 @@ impl From<collection::File> for CollectionFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MultiString {
|
trait VecExt {
|
||||||
|
fn to_v7_string(&self) -> Option<String>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VecExt for Vec<String> {
|
||||||
fn to_v7_string(&self) -> Option<String> {
|
fn to_v7_string(&self) -> Option<String> {
|
||||||
if self.0.is_empty() {
|
if self.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(self.0.join(""))
|
Some(self.join(""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,7 +306,7 @@ impl From<collection::Song> for Song {
|
||||||
track_number: s.track_number,
|
track_number: s.track_number,
|
||||||
disc_number: s.disc_number,
|
disc_number: s.disc_number,
|
||||||
title: s.title,
|
title: s.title,
|
||||||
artist: s.artists.0.first().cloned(),
|
artist: s.artists.first().cloned(),
|
||||||
album_artist: s.album_artists.to_v7_string(),
|
album_artist: s.album_artists.to_v7_string(),
|
||||||
year: s.year,
|
year: s.year,
|
||||||
album: s.album,
|
album: s.album,
|
||||||
|
|
|
@ -266,16 +266,16 @@ impl From<collection::Song> for Song {
|
||||||
track_number: s.track_number,
|
track_number: s.track_number,
|
||||||
disc_number: s.disc_number,
|
disc_number: s.disc_number,
|
||||||
title: s.title,
|
title: s.title,
|
||||||
artists: s.artists.0,
|
artists: s.artists,
|
||||||
album_artists: s.album_artists.0,
|
album_artists: s.album_artists,
|
||||||
year: s.year,
|
year: s.year,
|
||||||
album: s.album,
|
album: s.album,
|
||||||
artwork: s.artwork,
|
artwork: s.artwork,
|
||||||
duration: s.duration,
|
duration: s.duration,
|
||||||
lyricists: s.lyricists.0,
|
lyricists: s.lyricists,
|
||||||
composers: s.composers.0,
|
composers: s.composers,
|
||||||
genres: s.genres.0,
|
genres: s.genres,
|
||||||
labels: s.labels.0,
|
labels: s.labels,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue