Walk through filesystem and print metadata

This commit is contained in:
Connor Johnstone
2026-03-02 21:09:47 -05:00
commit 8a07a3edc2
6 changed files with 281 additions and 0 deletions

25
src/metadata.rs Normal file
View File

@@ -0,0 +1,25 @@
use std::path::Path;
use lofty::file::TaggedFileExt;
use lofty::tag::Accessor;
pub struct TrackMetadata {
pub title: Option<String>,
pub artist: Option<String>,
pub album: Option<String>,
}
/// Read metadata from a music file, returning `None` if no tags are present.
pub fn read_track_metadata(path: &Path) -> Result<Option<TrackMetadata>, lofty::error::LoftyError> {
let tagged_file = lofty::read_from_path(path)?;
let Some(tag) = tagged_file.primary_tag().or_else(|| tagged_file.first_tag()) else {
return Ok(None);
};
Ok(Some(TrackMetadata {
title: tag.title().map(|s| s.into_owned()),
artist: tag.artist().map(|s| s.into_owned()),
album: tag.album().map(|s| s.into_owned()),
}))
}