cover art

This commit is contained in:
2026-08-24 16:46:42 -04:00
parent e6769164d6
commit 6b45477a9d
4 changed files with 49 additions and 6 deletions

View File

@@ -1,7 +1,20 @@
use lofty::{config::WriteOptions, prelude::*, probe::Probe, tag::Tag};
use lofty::{
config::WriteOptions,
picture::{MimeType, Picture, PictureType},
prelude::*,
probe::Probe,
tag::Tag,
};
use std::path::Path;
pub fn write_tags(path: &Path, title: &str, artist: &str, album: &str, track_num: u32) {
pub fn write_tags(
path: &Path,
title: &str,
artist: &str,
album: &str,
track_num: u32,
cover: Option<&[u8]>,
) {
let mut tagged_file = Probe::open(path)
.expect("couldn't open the flac :(\n")
.read()
@@ -24,6 +37,14 @@ pub fn write_tags(path: &Path, title: &str, artist: &str, album: &str, track_num
tag.set_album(album.to_string());
tag.set_track(track_num);
if let Some(image_bytes) = cover {
let picture = Picture::unchecked(image_bytes.to_vec())
.pic_type(PictureType::CoverFront)
.mime_type(MimeType::Jpeg)
.build();
tag.set_picture(0, picture);
}
tag.save_to_path(path, WriteOptions::default())
.expect("couldn't save the tags :(\n");
}