mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-14 14:42:33 +00:00
Remove metaflac::Tag -> OggTag conversion
This commit is contained in:
parent
3d6f1f846e
commit
091daefd85
2 changed files with 13 additions and 59 deletions
|
@ -89,49 +89,6 @@ impl TryFrom<OGGTags> for OggTag {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "format-flac")]
|
||||
impl TryFrom<metaflac::Tag> for OggTag {
|
||||
type Error = LoftyError;
|
||||
|
||||
fn try_from(inp: metaflac::Tag) -> Result<Self> {
|
||||
if let Some(comments) = inp.vorbis_comments() {
|
||||
let mut user_comments = comments.comments.clone();
|
||||
|
||||
let mut pictures = Vec::new();
|
||||
|
||||
if let Some(pics) = user_comments.remove("METADATA_BLOCK_PICTURE") {
|
||||
pics.iter().for_each(|item| {
|
||||
if let Ok(pic) = Picture::from_apic_bytes(item.as_bytes()) {
|
||||
pictures.push(pic)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let mut comment_collection: HashMap<UniCase<String>, String> = HashMap::new();
|
||||
|
||||
for (k, v) in user_comments.clone() {
|
||||
for e in v {
|
||||
comment_collection.insert(UniCase::from(k.clone()), e.clone());
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(Self {
|
||||
inner: OggInnerTag {
|
||||
vendor: comments.vendor_string.clone(),
|
||||
comments: comment_collection,
|
||||
pictures: Some(Cow::from(pictures)),
|
||||
},
|
||||
properties: FileProperties::default(), // TODO
|
||||
_format: TagType::Ogg(OggFormat::Flac),
|
||||
});
|
||||
}
|
||||
|
||||
Err(LoftyError::InvalidData(
|
||||
"Flac file contains no vorbis comment blocks",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl OggTag {
|
||||
#[allow(missing_docs)]
|
||||
#[allow(clippy::missing_errors_doc)]
|
||||
|
|
|
@ -1,38 +1,35 @@
|
|||
#![cfg(feature = "default")]
|
||||
|
||||
use lofty::{Id3Format, OggTag, Tag, TagType, ToAnyTag};
|
||||
use std::convert::TryInto;
|
||||
use lofty::{Id3Format, OggTag, Tag, TagType, ToAnyTag, OggFormat, AudioTagEdit};
|
||||
|
||||
use std::io::Cursor;
|
||||
|
||||
#[test]
|
||||
fn test_inner() {
|
||||
// New flac tag
|
||||
let mut innertag = metaflac::Tag::new();
|
||||
// Create a new flac OggTag
|
||||
let mut flac_data = Cursor::new(std::fs::read("tests/assets/a.flac").unwrap());
|
||||
let mut flac_tag = OggTag::read_from(&mut flac_data, &OggFormat::Flac).unwrap();
|
||||
|
||||
// Set the title of the flac tag
|
||||
innertag
|
||||
.vorbis_comments_mut()
|
||||
.set_title(vec!["title from metaflac::Tag"]);
|
||||
flac_tag.set_title("Foo title");
|
||||
|
||||
// Turn the flac tag into a VorbisTag
|
||||
let tag: OggTag = innertag.try_into().unwrap();
|
||||
// Turn the VorbisTag into an Id3v2Tag
|
||||
let id3tag = flac_tag.to_dyn_tag(TagType::Id3v2(Id3Format::Mp3));
|
||||
|
||||
// Turn the VorbisTag into a Box<dyn AudioTag>
|
||||
let id3tag = tag.to_dyn_tag(TagType::Id3v2(Id3Format::Mp3));
|
||||
|
||||
// Write Box<dyn AudioTag> to `a.mp3`
|
||||
// Write the Id3v2Tag to `a.mp3`
|
||||
id3tag
|
||||
.write_to_path("tests/assets/a.mp3")
|
||||
.expect("Fail to write!");
|
||||
|
||||
// Read from `a.mp3`
|
||||
let id3tag_reload = Tag::default()
|
||||
let id3tag_reload = Tag::new()
|
||||
.read_from_path("tests/assets/a.mp3")
|
||||
.expect("Fail to read!");
|
||||
|
||||
// Confirm title still matches
|
||||
assert_eq!(id3tag_reload.title(), Some("title from metaflac::Tag"));
|
||||
assert_eq!(id3tag_reload.title(), Some("Foo title"));
|
||||
|
||||
// Convert Box<dyn AudioTag> to id3::Tag
|
||||
// Convert Id3v2Tag to id3::Tag
|
||||
let mut id3tag_inner: id3::Tag = id3tag_reload.into();
|
||||
|
||||
// Create timestamp and change date_recorded
|
||||
|
|
Loading…
Reference in a new issue