Add album artist field

This commit is contained in:
Agatha Lovelace 2022-09-23 20:45:01 +02:00
parent f471bd77a6
commit 0490795f02
Signed by: sorceress
GPG Key ID: 11BBCFC65FC9F401
5 changed files with 16 additions and 18 deletions

View File

@ -17,7 +17,7 @@ pub struct Config {
impl Config {
pub fn read_config() -> Result<Self> {
let file = std::env::current_dir()
.and_then(|v| Ok(v.join("settings.toml")))
.map(|v| v.join("settings.toml"))
.into_diagnostic()?;
let contents = std::fs::read_to_string(file).into_diagnostic()?;
@ -28,7 +28,7 @@ impl Config {
let contents = toml::to_string(config).into_diagnostic()?;
let path = std::env::current_dir()
.and_then(|v| Ok(v.join("settings.toml")))
.map(|v| v.join("settings.toml"))
.into_diagnostic()?;
File::create(path)

View File

@ -61,7 +61,7 @@ pub async fn index_source(source: Source, mode: IndexMode, db: &DatabaseConnecti
.filter(|e| {
mime_guess::from_path(e.path())
.first()
.and_then(|v| Some(v.type_() == mime::AUDIO))
.map(|v| v.type_() == mime::AUDIO)
.unwrap_or(false)
})
{
@ -92,20 +92,15 @@ pub async fn index_source(source: Source, mode: IndexMode, db: &DatabaseConnecti
.to_string()),
source_id: Set(source.id.into()),
hash: Set(hash.try_into().into_diagnostic()?),
artist: Set(tags
.and_then(|t| t.artist())
.and_then(|t| Some(t.to_string()))),
name: Set(tags
.and_then(|t| t.title())
.and_then(|t| Some(t.to_string()))),
album: Set(tags
.and_then(|t| t.album())
.and_then(|t| Some(t.to_string()))),
genres: Set(tags
.and_then(|t| t.genre())
.and_then(|t| Some(t.to_string()))),
track: Set(tags.and_then(|t| t.track()).and_then(|t| Some(t as i32))),
year: Set(tags.and_then(|t| t.year()).and_then(|t| Some(t as i32))),
artist: Set(tags.and_then(|t| t.artist()).map(|t| t.to_string())),
album_artist: Set(tags
.and_then(|t| t.get_string(&lofty::ItemKey::AlbumArtist))
.map(|t| t.to_string())),
name: Set(tags.and_then(|t| t.title()).map(|t| t.to_string())),
album: Set(tags.and_then(|t| t.album()).map(|t| t.to_string())),
genres: Set(tags.and_then(|t| t.genre()).map(|t| t.to_string())),
track: Set(tags.and_then(|t| t.track()).map(|t| t as i32)),
year: Set(tags.and_then(|t| t.year()).map(|t| t as i32)),
duration: Set(properties
.duration()
.as_millis()

View File

@ -28,6 +28,7 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(Song::SourceId).integer().not_null())
.col(ColumnDef::new(Song::Hash).integer().not_null().unique_key())
.col(ColumnDef::new(Song::Artist).string())
.col(ColumnDef::new(Song::AlbumArtist).string())
.col(ColumnDef::new(Song::Name).string())
.col(ColumnDef::new(Song::Album).string())
.col(ColumnDef::new(Song::Duration).integer().not_null())
@ -60,6 +61,7 @@ pub enum Song {
/// A hash of the song's samples as Vec<f32>
Hash,
Artist,
AlbumArtist,
Name,
Album,
Duration,

View File

@ -13,6 +13,7 @@ pub struct Model {
pub source_id: i32,
pub hash: u32,
pub artist: Option<String>,
pub album_artist: Option<String>,
pub name: Option<String>,
pub album: Option<String>,
pub duration: u32,

View File

@ -10,7 +10,7 @@ use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
/// If no files have been created in the current directory, the app is running for the first time
pub fn is_first_run() -> Result<bool> {
let path = std::env::current_dir()
.and_then(|v| Ok(v.join("settings.toml")))
.map(|v| v.join("settings.toml"))
.into_diagnostic()?;
Ok(!path.exists())