1use crate::types::AudioMeta;
2use lofty::file::TaggedFileExt;
3use lofty::probe::Probe;
4use lofty::tag::Accessor;
5use std::path::Path;
6
7pub fn read_audio_tags(path: &Path) -> Option<AudioMeta> {
8 let tagged = Probe::open(path).ok()?.read().ok()?;
10 let tag = tagged.primary_tag().or_else(|| tagged.first_tag())?;
11
12 let m = AudioMeta {
13 artist: tag.artist().map(|s| s.to_string()),
14 title: tag.title().map(|s| s.to_string()),
15 album: tag.album().map(|s| s.to_string()),
16 };
17
18 if m.artist.is_none() && m.title.is_none() && m.album.is_none() {
19 None
20 } else {
21 Some(m)
22 }
23}