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.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::<String>::new());
|
||||
assert_eq!(song.album, Some("Picnic".to_owned()));
|
||||
assert_eq!(song.year, Some(2016));
|
||||
assert_eq!(song.artwork, Some(artwork_virtual_path));
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<P: AsRef<Path>, Q: AsRef<Path>>(
|
|||
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()
|
||||
|
|
|
@ -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<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)]
|
||||
pub enum Error {
|
||||
#[error("Directory not found: {0}")]
|
||||
|
@ -63,16 +45,16 @@ pub struct Song {
|
|||
pub track_number: Option<i64>,
|
||||
pub disc_number: Option<i64>,
|
||||
pub title: Option<String>,
|
||||
pub artists: MultiString,
|
||||
pub album_artists: MultiString,
|
||||
pub artists: Vec<String>,
|
||||
pub album_artists: Vec<String>,
|
||||
pub year: Option<i64>,
|
||||
pub album: Option<String>,
|
||||
pub artwork: Option<PathBuf>,
|
||||
pub duration: Option<i64>,
|
||||
pub lyricists: MultiString,
|
||||
pub composers: MultiString,
|
||||
pub genres: MultiString,
|
||||
pub labels: MultiString,
|
||||
pub lyricists: Vec<String>,
|
||||
pub composers: Vec<String>,
|
||||
pub genres: Vec<String>,
|
||||
pub labels: Vec<String>,
|
||||
pub date_added: i64,
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ impl Manager {
|
|||
async fn scrobble_from_path(&self, track: &Path) -> Result<Scrobble, Error> {
|
||||
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(""),
|
||||
))
|
||||
|
|
|
@ -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<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> {
|
||||
if self.0.is_empty() {
|
||||
if self.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(self.0.join(""))
|
||||
Some(self.join(""))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -302,7 +306,7 @@ impl From<collection::Song> 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,
|
||||
|
|
|
@ -266,16 +266,16 @@ impl From<collection::Song> 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue