mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2025-03-04 23:07:20 +00:00
Add ItemKey
mappings for new AIFF chunks
This commit is contained in:
parent
a86738d1d4
commit
f42dfb50bf
4 changed files with 49 additions and 39 deletions
|
@ -499,20 +499,14 @@ mod tests {
|
||||||
tag.insert_text(ItemKey::TrackTitle, String::from("Foo title"));
|
tag.insert_text(ItemKey::TrackTitle, String::from("Foo title"));
|
||||||
tag.insert_text(ItemKey::TrackArtist, String::from("Bar artist"));
|
tag.insert_text(ItemKey::TrackArtist, String::from("Bar artist"));
|
||||||
tag.insert_text(ItemKey::CopyrightMessage, String::from("Baz copyright"));
|
tag.insert_text(ItemKey::CopyrightMessage, String::from("Baz copyright"));
|
||||||
tag.insert_item_unchecked(
|
tag.push_item_unchecked(TagItem::new(
|
||||||
TagItem::new(
|
ItemKey::Comment,
|
||||||
ItemKey::Comment,
|
ItemValue::Text(String::from("Qux annotation")),
|
||||||
ItemValue::Text(String::from("Qux annotation")),
|
));
|
||||||
),
|
tag.push_item_unchecked(TagItem::new(
|
||||||
false,
|
ItemKey::Comment,
|
||||||
);
|
ItemValue::Text(String::from("Quux annotation")),
|
||||||
tag.insert_item_unchecked(
|
));
|
||||||
TagItem::new(
|
|
||||||
ItemKey::Comment,
|
|
||||||
ItemValue::Text(String::from("Quux annotation")),
|
|
||||||
),
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
let aiff_text: AiffTextChunks = tag.into();
|
let aiff_text: AiffTextChunks = tag.into();
|
||||||
|
|
||||||
|
|
|
@ -65,9 +65,10 @@ gen_map!(
|
||||||
#[cfg(feature = "aiff_text_chunks")]
|
#[cfg(feature = "aiff_text_chunks")]
|
||||||
AIFF_TEXT_MAP;
|
AIFF_TEXT_MAP;
|
||||||
|
|
||||||
"NAME" => TrackTitle,
|
"NAME" => TrackTitle,
|
||||||
"AUTH" => TrackArtist,
|
"AUTH" => TrackArtist,
|
||||||
"(c) " => CopyrightMessage
|
"(c) " => CopyrightMessage,
|
||||||
|
"COMM" | "AUTH" => Comment
|
||||||
);
|
);
|
||||||
|
|
||||||
gen_map!(
|
gen_map!(
|
||||||
|
|
|
@ -44,7 +44,7 @@ macro_rules! impl_accessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn [<set_ $name>](&mut self, value: String) {
|
fn [<set_ $name>](&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 [<remove_ $name>](&mut self) {
|
fn [<remove_ $name>](&mut self) {
|
||||||
|
@ -199,46 +199,64 @@ impl Tag {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a [`TagItem`]
|
/// Insert a [`TagItem`], replacing any existing one of the same [`ItemKey`]
|
||||||
///
|
|
||||||
/// 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.
|
|
||||||
///
|
///
|
||||||
/// NOTE: This **will** verify an [`ItemKey`] mapping exists for the target [`TagType`]
|
/// NOTE: This **will** verify an [`ItemKey`] mapping exists for the target [`TagType`]
|
||||||
///
|
///
|
||||||
/// This will return `true` if the item was inserted.
|
/// 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) {
|
if item.re_map(self.tag_type) {
|
||||||
self.insert_item_unchecked(item, replace);
|
self.insert_item_unchecked(item);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a [`TagItem`], replacing any existing one of the same type
|
/// Insert a [`TagItem`], replacing any existing one of the same [`ItemKey`]
|
||||||
///
|
///
|
||||||
/// Notes:
|
/// Notes:
|
||||||
///
|
///
|
||||||
/// * `replace`: See [`Tag::insert_item`]
|
|
||||||
/// * This **will not** verify an [`ItemKey`] mapping exists
|
/// * 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 **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`].
|
/// This is only necessary if dealing with [`ItemKey::Unknown`].
|
||||||
pub fn insert_item_unchecked(&mut self, item: TagItem, replace: bool) {
|
pub fn insert_item_unchecked(&mut self, item: TagItem) {
|
||||||
if replace {
|
self.retain_items(|i| i.item_key != item.item_key);
|
||||||
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);
|
self.items.push(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An alias for [`Tag::insert_item`] that doesn't require the user to create a [`TagItem`]
|
/// 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 {
|
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
|
/// Removes all items with the specified [`ItemKey`], and returns them
|
||||||
|
|
|
@ -62,13 +62,10 @@ macro_rules! set_artist {
|
||||||
set_artist!($file_write, $new_value, tag)
|
set_artist!($file_write, $new_value, tag)
|
||||||
};
|
};
|
||||||
($file_write:ident, $new_value:literal, $tag:ident) => {
|
($file_write:ident, $new_value:literal, $tag:ident) => {
|
||||||
$tag.insert_item_unchecked(
|
$tag.insert_item_unchecked(TagItem::new(
|
||||||
TagItem::new(
|
ItemKey::TrackArtist,
|
||||||
ItemKey::TrackArtist,
|
ItemValue::Text(String::from($new_value)),
|
||||||
ItemValue::Text(String::from($new_value)),
|
));
|
||||||
),
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
|
|
||||||
$file_write.seek(std::io::SeekFrom::Start(0)).unwrap();
|
$file_write.seek(std::io::SeekFrom::Start(0)).unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue