mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-12 13:42:34 +00:00
Partial cover support for MP4
Since MP4 doesn't let you differentiate one image from another, all images are PictureType::Other, and all back_cover functions are aliases for front_cover.
This commit is contained in:
parent
16f4ecce0d
commit
36d9d5195a
2 changed files with 46 additions and 10 deletions
|
@ -112,17 +112,17 @@ impl AudioTagEdit for Mp4Tag {
|
|||
fn front_cover(&self) -> Option<Picture> {
|
||||
self.inner.artwork().and_then(|data| match data {
|
||||
mp4ameta::Data::Jpeg(d) => Some(Picture {
|
||||
pic_type: PictureType::CoverFront, // TODO
|
||||
pic_type: PictureType::Other,
|
||||
data: d.clone(),
|
||||
mime_type: MimeType::Jpeg,
|
||||
}),
|
||||
mp4ameta::Data::Png(d) => Some(Picture {
|
||||
pic_type: PictureType::CoverFront, // TODO
|
||||
pic_type: PictureType::Other,
|
||||
data: d.clone(),
|
||||
mime_type: MimeType::Png,
|
||||
}),
|
||||
mp4ameta::Data::Bmp(d) => Some(Picture {
|
||||
pic_type: PictureType::CoverFront, // TODO
|
||||
pic_type: PictureType::Other,
|
||||
data: d.clone(),
|
||||
mime_type: MimeType::Bmp,
|
||||
}),
|
||||
|
@ -131,7 +131,7 @@ impl AudioTagEdit for Mp4Tag {
|
|||
}
|
||||
|
||||
fn set_front_cover(&mut self, cover: Picture) {
|
||||
self.remove_front_cover();
|
||||
self.inner.remove_artwork();
|
||||
|
||||
self.inner.add_artwork(match cover.mime_type {
|
||||
MimeType::Png => mp4ameta::Data::Png(cover.data),
|
||||
|
@ -146,19 +146,42 @@ impl AudioTagEdit for Mp4Tag {
|
|||
}
|
||||
|
||||
fn back_cover(&self) -> Option<Picture> {
|
||||
todo!()
|
||||
self.front_cover()
|
||||
}
|
||||
|
||||
fn set_back_cover(&mut self, cover: Picture) {
|
||||
todo!()
|
||||
self.set_front_cover(cover)
|
||||
}
|
||||
|
||||
fn remove_back_cover(&mut self) {
|
||||
todo!()
|
||||
self.inner.remove_artwork();
|
||||
}
|
||||
|
||||
fn pictures(&self) -> Option<Vec<Picture>> {
|
||||
todo!()
|
||||
let mut pictures = Vec::new();
|
||||
|
||||
for art in self.inner.artworks() {
|
||||
let info = match art {
|
||||
mp4ameta::Data::Png(d) => Some((MimeType::Png, d.clone())),
|
||||
mp4ameta::Data::Jpeg(d) => Some((MimeType::Jpeg, d.clone())),
|
||||
mp4ameta::Data::Bmp(d) => Some((MimeType::Bmp, d.clone())),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some((mime_type, data)) = info {
|
||||
pictures.push(Picture {
|
||||
pic_type: PictureType::Other,
|
||||
mime_type,
|
||||
data,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if pictures.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(pictures)
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_track(&mut self) {
|
||||
|
|
17
tests/io.rs
17
tests/io.rs
|
@ -50,8 +50,8 @@ macro_rules! add_tags {
|
|||
|
||||
let file = stringify!($file);
|
||||
|
||||
// Skip this since RIFF INFO doesn't store images
|
||||
if file != stringify!("tests/assets/a.wav") {
|
||||
// Skip this since RIFF INFO doesn't store images, and MP4 doesn't specify what pictures are
|
||||
if file != stringify!("tests/assets/a.wav") && file != stringify!("tests/assets/a.m4a") {
|
||||
println!("Setting front cover");
|
||||
tag.set_front_cover(covers.0.clone());
|
||||
assert_eq!(tag.front_cover(), Some(covers.0));
|
||||
|
@ -61,6 +61,19 @@ macro_rules! add_tags {
|
|||
assert_eq!(tag.back_cover(), Some(covers.1));
|
||||
}
|
||||
|
||||
// All MP4 Pictures are PictureType::Other
|
||||
if file == stringify!("tests/assets/a.m4a") {
|
||||
let cover = Picture {
|
||||
pic_type: PictureType::Other,
|
||||
mime_type: MimeType::Jpeg,
|
||||
data: vec![0, 74, 80, 69, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
};
|
||||
|
||||
println!("Setting cover");
|
||||
tag.set_front_cover(cover.clone());
|
||||
assert_eq!(tag.front_cover(), Some(cover));
|
||||
}
|
||||
|
||||
println!("Writing");
|
||||
tag.write_to_path($file).unwrap();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue