Formatting
This commit is contained in:
@@ -20,38 +20,33 @@ async fn process_file(
|
||||
let file_path_str = scanned.path.to_string_lossy().to_string();
|
||||
|
||||
// Check if file already exists with same mtime
|
||||
if let Some(existing) = queries::tracks::get_by_path(conn, &file_path_str).await? {
|
||||
if let Some(existing_mtime) = existing.file_mtime {
|
||||
// Compare at second granularity
|
||||
if existing_mtime.and_utc().timestamp() == scanned.mtime.and_utc().timestamp() {
|
||||
tracing::debug!(path = %file_path_str, "skipping (mtime unchanged)");
|
||||
return Ok(false);
|
||||
}
|
||||
}
|
||||
if let Some(existing) = queries::tracks::get_by_path(conn, &file_path_str).await?
|
||||
&& let Some(existing_mtime) = existing.file_mtime
|
||||
&& existing_mtime.and_utc().timestamp() == scanned.mtime.and_utc().timestamp()
|
||||
{
|
||||
tracing::debug!(path = %file_path_str, "skipping (mtime unchanged)");
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
// Extract metadata (CPU-bound, run in blocking thread)
|
||||
let path = scanned.path.clone();
|
||||
let mut meta: MusicMetadata = tokio::task::spawn_blocking(move || {
|
||||
metadata::extract_metadata(&path)
|
||||
})
|
||||
.await??;
|
||||
let mut meta: MusicMetadata =
|
||||
tokio::task::spawn_blocking(move || metadata::extract_metadata(&path)).await??;
|
||||
|
||||
// Fallback: if missing title or artist from tags, try parsing from filename ("Artist - Title.ext")
|
||||
if meta.title.is_none() || meta.artist.is_none() {
|
||||
if let Some(stem) = scanned.path.file_stem().and_then(|s| s.to_str()) {
|
||||
if let Some((artist, title)) = stem.split_once(" - ") {
|
||||
let artist = artist.trim();
|
||||
let title = title.trim();
|
||||
if !artist.is_empty() && !title.is_empty() {
|
||||
tracing::debug!(path = %file_path_str, artist = artist, title = title, "parsed metadata from filename");
|
||||
if meta.artist.is_none() {
|
||||
meta.artist = Some(artist.to_string());
|
||||
}
|
||||
if meta.title.is_none() {
|
||||
meta.title = Some(title.to_string());
|
||||
}
|
||||
}
|
||||
if (meta.title.is_none() || meta.artist.is_none())
|
||||
&& let Some(stem) = scanned.path.file_stem().and_then(|s| s.to_str())
|
||||
&& let Some((artist, title)) = stem.split_once(" - ")
|
||||
{
|
||||
let artist = artist.trim();
|
||||
let title = title.trim();
|
||||
if !artist.is_empty() && !title.is_empty() {
|
||||
tracing::debug!(path = %file_path_str, artist = artist, title = title, "parsed metadata from filename");
|
||||
if meta.artist.is_none() {
|
||||
meta.artist = Some(artist.to_string());
|
||||
}
|
||||
if meta.title.is_none() {
|
||||
meta.title = Some(title.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,10 +64,7 @@ async fn process_file(
|
||||
}
|
||||
|
||||
// Upsert artist (use album_artist if available, fall back to artist)
|
||||
let artist_name = meta
|
||||
.album_artist
|
||||
.as_deref()
|
||||
.or(meta.artist.as_deref());
|
||||
let artist_name = meta.album_artist.as_deref().or(meta.artist.as_deref());
|
||||
let artist_id = match artist_name {
|
||||
Some(name) if !name.is_empty() => {
|
||||
Some(queries::artists::upsert(conn, name, None).await?.id)
|
||||
|
||||
@@ -7,7 +7,10 @@ use shanty_db::Database;
|
||||
use shanty_index::{ScanConfig, run_scan};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "shanty-index", about = "Index music files into the Shanty database")]
|
||||
#[command(
|
||||
name = "shanty-index",
|
||||
about = "Index music files into the Shanty database"
|
||||
)]
|
||||
struct Cli {
|
||||
/// Directory to scan for music files.
|
||||
path: PathBuf,
|
||||
|
||||
@@ -45,9 +45,7 @@ fn file_type_to_codec(ft: FileType) -> &'static str {
|
||||
|
||||
/// Extract metadata from a music file. This is CPU-bound (sync).
|
||||
pub fn extract_metadata(path: &Path) -> IndexResult<MusicMetadata> {
|
||||
let tagged_file = Probe::open(path)?
|
||||
.options(ParseOptions::default())
|
||||
.read()?;
|
||||
let tagged_file = Probe::open(path)?.options(ParseOptions::default()).read()?;
|
||||
|
||||
let mut meta = MusicMetadata::default();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user