ripping+tagging

This commit is contained in:
2026-08-24 16:07:14 -04:00
parent 99379a1faa
commit 7c82b582ce
7 changed files with 300 additions and 105 deletions

29
src/tagging.rs Normal file
View File

@@ -0,0 +1,29 @@
use lofty::{config::WriteOptions, prelude::*, probe::Probe, tag::Tag};
use std::path::Path;
pub fn write_tags(path: &Path, title: &str, artist: &str, album: &str, track_num: u32) {
let mut tagged_file = Probe::open(path)
.expect("couldn't open the flac :(\n")
.read()
.expect("couldn't read the flac :(\n");
let tag = match tagged_file.primary_tag_mut() {
Some(t) => t,
None => {
if let Some(first_tag) = tagged_file.first_tag_mut() {
first_tag
} else {
let tag_type = tagged_file.primary_tag_type();
tagged_file.insert_tag(Tag::new(tag_type));
tagged_file.primary_tag_mut().unwrap()
}
}
};
tag.set_title(title.to_string());
tag.set_artist(artist.to_string());
tag.set_album(album.to_string());
tag.set_track(track_num);
tag.save_to_path(path, WriteOptions::default())
.expect("couldn't save the tags :(\n");
}