Walk through filesystem and print metadata
This commit is contained in:
25
src/metadata.rs
Normal file
25
src/metadata.rs
Normal 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()),
|
||||
}))
|
||||
}
|
||||
Reference in New Issue
Block a user