commit bcd273eb27416845e980eb8ebd56d6f9e89eb734 from: mtmn date: Wed Jul 1 22:08:12 2026 UTC fix: allow edit with missing tags commit - a76c816b1a6b0f238f63bfd1076180a24704a09e commit + bcd273eb27416845e980eb8ebd56d6f9e89eb734 blob - d0037a387c771c596a5c4e5ac7d564379f650d4a blob + 9cbd1a5e956463d6e958443162ada44c0119aba9 --- src/tagging.rs +++ src/tagging.rs @@ -38,6 +38,12 @@ pub async fn process_files_batch( } match read_file_tags(&abs_path) { + Ok((_, artist, album)) if artist.is_empty() || album.is_empty() => { + eprintln!( + "Skipping {} - artist/album tags required to fetch metadata", + path.display() + ); + } Ok((_, artist, album)) => { files_by_release .entry((artist, album)) @@ -131,22 +137,7 @@ pub fn show_file_tags(path: &Path) -> Result<()> { } fn write_file_tags(path: &Path, metadata: &FetchedMetadata) -> Result<()> { - let file = - File::open(path).with_context(|| format!("Failed to open file: {}", path.display()))?; - let mut probe = Probe::new(file); - - if let Some(file_type) = path - .extension() - .and_then(|e| e.to_str()) - .and_then(lofty::file::FileType::from_ext) - { - probe = probe.set_file_type(file_type); - } - - let mut tagged_file = probe - .read() - .with_context(|| format!("Failed to read tags from {}", path.display()))?; - + let (mut tagged_file, _, _) = read_file_tags(path)?; let tag = tagged_file .primary_tag_mut() .context("No primary tag found")?; @@ -299,29 +290,35 @@ pub async fn edit_files(paths: &[std::path::PathBuf]) Ok(()) } +fn read_tagged_file(path: &Path) -> Result { + let file = + File::open(path).with_context(|| format!("Failed to open file: {}", path.display()))?; + let mut probe = Probe::new(file); + + if let Some(file_type) = path + .extension() + .and_then(|e| e.to_str()) + .and_then(lofty::file::FileType::from_ext) + { + probe = probe.set_file_type(file_type); + } + + probe + .read() + .with_context(|| format!("Failed to read tags from {}", path.display())) +} + fn read_file_tags(path: &Path) -> Result<(TaggedFile, String, String)> { - let file = - File::open(path).with_context(|| format!("Failed to open file: {}", path.display()))?; - let mut probe = Probe::new(file); + let mut tagged_file = read_tagged_file(path)?; - if let Some(file_type) = path - .extension() - .and_then(|e| e.to_str()) - .and_then(lofty::file::FileType::from_ext) - { - probe = probe.set_file_type(file_type); + if tagged_file.primary_tag().is_none() { + tagged_file.insert_tag(Tag::new(tagged_file.primary_tag_type())); } - let mut tagged_file = probe - .read() - .with_context(|| format!("Failed to read tags from {}", path.display()))?; + let tag = tagged_file.primary_tag().context("No primary tag found")?; + let artist = tag.artist().map(|a| a.to_string()).unwrap_or_default(); + let album = tag.album().map(|a| a.to_string()).unwrap_or_default(); - let tag = tagged_file - .primary_tag_mut() - .context("No primary tag found")?; - let artist = tag.artist().context("Artist not found")?.to_string(); - let album = tag.album().context("Album not found")?.to_string(); - Ok((tagged_file, artist, album)) }