cover art
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user