From 091daefd85ebe9550b22add5300045a7e7c8d1e3 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Sat, 24 Jul 2021 15:54:51 -0400 Subject: [PATCH] Remove metaflac::Tag -> OggTag conversion --- src/components/tags/ogg_tag.rs | 43 ---------------------------------- tests/inner.rs | 29 ++++++++++------------- 2 files changed, 13 insertions(+), 59 deletions(-) diff --git a/src/components/tags/ogg_tag.rs b/src/components/tags/ogg_tag.rs index 9eb15df0..22a8fa32 100644 --- a/src/components/tags/ogg_tag.rs +++ b/src/components/tags/ogg_tag.rs @@ -89,49 +89,6 @@ impl TryFrom for OggTag { } } -#[cfg(feature = "format-flac")] -impl TryFrom for OggTag { - type Error = LoftyError; - - fn try_from(inp: metaflac::Tag) -> Result { - 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, 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)] diff --git a/tests/inner.rs b/tests/inner.rs index e0d154e1..0b12ed93 100644 --- a/tests/inner.rs +++ b/tests/inner.rs @@ -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 - let id3tag = tag.to_dyn_tag(TagType::Id3v2(Id3Format::Mp3)); - - // Write Box 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 to id3::Tag + // Convert Id3v2Tag to id3::Tag let mut id3tag_inner: id3::Tag = id3tag_reload.into(); // Create timestamp and change date_recorded