diff --git a/src/iff/aiff/tag.rs b/src/iff/aiff/tag.rs index ee7a77aa..0f7d45d1 100644 --- a/src/iff/aiff/tag.rs +++ b/src/iff/aiff/tag.rs @@ -499,20 +499,14 @@ mod tests { tag.insert_text(ItemKey::TrackTitle, String::from("Foo title")); tag.insert_text(ItemKey::TrackArtist, String::from("Bar artist")); tag.insert_text(ItemKey::CopyrightMessage, String::from("Baz copyright")); - tag.insert_item_unchecked( - TagItem::new( - ItemKey::Comment, - ItemValue::Text(String::from("Qux annotation")), - ), - false, - ); - tag.insert_item_unchecked( - TagItem::new( - ItemKey::Comment, - ItemValue::Text(String::from("Quux annotation")), - ), - false, - ); + tag.push_item_unchecked(TagItem::new( + ItemKey::Comment, + ItemValue::Text(String::from("Qux annotation")), + )); + tag.push_item_unchecked(TagItem::new( + ItemKey::Comment, + ItemValue::Text(String::from("Quux annotation")), + )); let aiff_text: AiffTextChunks = tag.into(); diff --git a/src/types/item.rs b/src/types/item.rs index cb92c21f..c2e86c7f 100644 --- a/src/types/item.rs +++ b/src/types/item.rs @@ -65,9 +65,10 @@ gen_map!( #[cfg(feature = "aiff_text_chunks")] AIFF_TEXT_MAP; - "NAME" => TrackTitle, - "AUTH" => TrackArtist, - "(c) " => CopyrightMessage + "NAME" => TrackTitle, + "AUTH" => TrackArtist, + "(c) " => CopyrightMessage, + "COMM" | "AUTH" => Comment ); gen_map!( diff --git a/src/types/tag.rs b/src/types/tag.rs index 8ad6f9a0..10068877 100644 --- a/src/types/tag.rs +++ b/src/types/tag.rs @@ -44,7 +44,7 @@ macro_rules! impl_accessor { } fn [](&mut self, value: String) { - self.insert_item(TagItem::new(ItemKey::$item_key, ItemValue::Text(value)), false); + self.insert_item(TagItem::new(ItemKey::$item_key, ItemValue::Text(value))); } fn [](&mut self) { @@ -199,46 +199,64 @@ impl Tag { None } - /// Insert a [`TagItem`] - /// - /// Use `replace` to replace any existing items of the same [`ItemKey`]. - /// Multiple items of the same [`ItemKey`] are not valid in all formats, in which case - /// the first available item will be used. + /// Insert a [`TagItem`], replacing any existing one of the same [`ItemKey`] /// /// NOTE: This **will** verify an [`ItemKey`] mapping exists for the target [`TagType`] /// /// This will return `true` if the item was inserted. - pub fn insert_item(&mut self, item: TagItem, replace: bool) -> bool { + pub fn insert_item(&mut self, item: TagItem) -> bool { if item.re_map(self.tag_type) { - self.insert_item_unchecked(item, replace); + self.insert_item_unchecked(item); return true; } false } - /// Insert a [`TagItem`], replacing any existing one of the same type + /// Insert a [`TagItem`], replacing any existing one of the same [`ItemKey`] /// /// Notes: /// - /// * `replace`: See [`Tag::insert_item`] /// * This **will not** verify an [`ItemKey`] mapping exists /// * This **will not** allow writing item keys that are out of spec (keys are verified before writing) /// /// This is only necessary if dealing with [`ItemKey::Unknown`]. - pub fn insert_item_unchecked(&mut self, item: TagItem, replace: bool) { - if replace { - self.retain_items(|i| i.item_key != item.item_key); + pub fn insert_item_unchecked(&mut self, item: TagItem) { + self.retain_items(|i| i.item_key != item.item_key); + self.items.push(item); + } + + /// Append a [`TagItem`] to the tag + /// + /// This will not remove any items of the same [`ItemKey`], unlike [`Tag::insert_item`] + /// + /// NOTE: This **will** verify an [`ItemKey`] mapping exists for the target [`TagType`] + /// + /// Multiple items of the same [`ItemKey`] are not valid in all formats, in which case + /// the first available item will be used. + /// + /// This will return `true` if the item was pushed. + pub fn push_item(&mut self, item: TagItem) -> bool { + if item.re_map(self.tag_type) { + self.items.push(item); + return true; } + false + } + + /// Append a [`TagItem`] to the tag + /// + /// Notes: See [`Tag::insert_item_unchecked`] + pub fn push_item_unchecked(&mut self, item: TagItem) { self.items.push(item); } /// An alias for [`Tag::insert_item`] that doesn't require the user to create a [`TagItem`] /// - /// NOTE: This will call [`Tag::insert_text`] with `replace` = `false` + /// NOTE: This will replace any existing item with `item_key`. See [`Tag::insert_item`] pub fn insert_text(&mut self, item_key: ItemKey, text: String) -> bool { - self.insert_item(TagItem::new(item_key, ItemValue::Text(text)), false) + self.insert_item(TagItem::new(item_key, ItemValue::Text(text))) } /// Removes all items with the specified [`ItemKey`], and returns them diff --git a/tests/files/util/mod.rs b/tests/files/util/mod.rs index 858ec48a..627562dc 100644 --- a/tests/files/util/mod.rs +++ b/tests/files/util/mod.rs @@ -62,13 +62,10 @@ macro_rules! set_artist { set_artist!($file_write, $new_value, tag) }; ($file_write:ident, $new_value:literal, $tag:ident) => { - $tag.insert_item_unchecked( - TagItem::new( - ItemKey::TrackArtist, - ItemValue::Text(String::from($new_value)), - ), - true, - ); + $tag.insert_item_unchecked(TagItem::new( + ItemKey::TrackArtist, + ItemValue::Text(String::from($new_value)), + )); $file_write.seek(std::io::SeekFrom::Start(0)).unwrap();