From 0490795f0224012d8a0695ba5f6b37f2c2d4cfa4 Mon Sep 17 00:00:00 2001 From: Agatha Lovelace Date: Fri, 23 Sep 2022 20:45:01 +0200 Subject: [PATCH] Add album artist field --- src/config.rs | 4 +-- src/fetching.rs | 25 ++++++++----------- .../m20220815_000001_create_library.rs | 2 ++ src/model/library.rs | 1 + src/utils.rs | 2 +- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/config.rs b/src/config.rs index e72801c..feae31e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,7 +17,7 @@ pub struct Config { impl Config { pub fn read_config() -> Result { 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) diff --git a/src/fetching.rs b/src/fetching.rs index 77f918f..0289458 100644 --- a/src/fetching.rs +++ b/src/fetching.rs @@ -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() diff --git a/src/migrator/m20220815_000001_create_library.rs b/src/migrator/m20220815_000001_create_library.rs index 1ba8f5f..28f202f 100644 --- a/src/migrator/m20220815_000001_create_library.rs +++ b/src/migrator/m20220815_000001_create_library.rs @@ -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 Hash, Artist, + AlbumArtist, Name, Album, Duration, diff --git a/src/model/library.rs b/src/model/library.rs index 94acc81..b0689dd 100644 --- a/src/model/library.rs +++ b/src/model/library.rs @@ -13,6 +13,7 @@ pub struct Model { pub source_id: i32, pub hash: u32, pub artist: Option, + pub album_artist: Option, pub name: Option, pub album: Option, pub duration: u32, diff --git a/src/utils.rs b/src/utils.rs index fa570b1..d2b41b6 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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 { 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())