diff --git a/CHANGELOG.md b/CHANGELOG.md index dd8a6137..99c8308e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **MP4**: `mp4::AudioObjectType` - This new type is used in `mp4::Mp4Properties`, accessible with `Mp4Properties::audio_object_type`. This provides additional information for the type of audio being dealt with. +- `TagExt::clear` + - This allows tags to be cleared of any items or pictures, while retaining any flags (if applicable) ### Changed - **MP4**: Sample rates are now retrieved from the [audio specific config](https://wiki.multimedia.cx/index.php?title=MPEG-4_Audio#Audio_Specific_Config) (if possible). diff --git a/src/ape/tag/mod.rs b/src/ape/tag/mod.rs index 417a0350..536bca94 100644 --- a/src/ape/tag/mod.rs +++ b/src/ape/tag/mod.rs @@ -171,6 +171,10 @@ impl TagExt for ApeTag { fn remove_from(&self, file: &mut File) -> std::result::Result<(), Self::Err> { TagType::Ape.remove_from(file) } + + fn clear(&mut self) { + self.items.clear(); + } } impl From for Tag { diff --git a/src/id3/v1/tag.rs b/src/id3/v1/tag.rs index 09290f5d..860dd29b 100644 --- a/src/id3/v1/tag.rs +++ b/src/id3/v1/tag.rs @@ -148,6 +148,10 @@ impl TagExt for Id3v1Tag { fn remove_from(&self, file: &mut File) -> std::result::Result<(), Self::Err> { TagType::Id3v1.remove_from(file) } + + fn clear(&mut self) { + *self = Self::default(); + } } impl From for Tag { diff --git a/src/id3/v2/tag.rs b/src/id3/v2/tag.rs index 2df2a54e..0752b0a8 100644 --- a/src/id3/v2/tag.rs +++ b/src/id3/v2/tag.rs @@ -318,6 +318,10 @@ impl TagExt for Id3v2Tag { fn remove_from(&self, file: &mut File) -> std::result::Result<(), Self::Err> { TagType::Id3v2.remove_from(file) } + + fn clear(&mut self) { + self.frames.clear(); + } } impl From for Tag { diff --git a/src/iff/aiff/tag.rs b/src/iff/aiff/tag.rs index c457592f..47bd0641 100644 --- a/src/iff/aiff/tag.rs +++ b/src/iff/aiff/tag.rs @@ -169,6 +169,10 @@ impl TagExt for AiffTextChunks { fn remove_from(&self, file: &mut File) -> std::result::Result<(), Self::Err> { TagType::AiffText.remove_from(file) } + + fn clear(&mut self) { + *self = Self::default(); + } } impl From for Tag { diff --git a/src/iff/wav/tag/mod.rs b/src/iff/wav/tag/mod.rs index 666828d4..158769d3 100644 --- a/src/iff/wav/tag/mod.rs +++ b/src/iff/wav/tag/mod.rs @@ -127,6 +127,10 @@ impl TagExt for RiffInfoList { fn remove_from(&self, file: &mut File) -> std::result::Result<(), Self::Err> { TagType::RiffInfo.remove_from(file) } + + fn clear(&mut self) { + self.items.clear(); + } } impl From for Tag { diff --git a/src/mp4/ilst/mod.rs b/src/mp4/ilst/mod.rs index e1b9e82c..5884aa21 100644 --- a/src/mp4/ilst/mod.rs +++ b/src/mp4/ilst/mod.rs @@ -250,6 +250,10 @@ impl TagExt for Ilst { fn remove_from(&self, file: &mut File) -> std::result::Result<(), Self::Err> { TagType::Mp4Ilst.remove_from(file) } + + fn clear(&mut self) { + self.atoms.clear(); + } } impl From for Tag { diff --git a/src/ogg/tag.rs b/src/ogg/tag.rs index f1fbdd43..d26ffb34 100644 --- a/src/ogg/tag.rs +++ b/src/ogg/tag.rs @@ -194,6 +194,11 @@ impl TagExt for VorbisComments { fn remove_from(&self, file: &mut File) -> std::result::Result<(), Self::Err> { TagType::VorbisComments.remove_from(file) } + + fn clear(&mut self) { + self.items.clear(); + self.pictures.clear(); + } } impl From for Tag { diff --git a/src/tag/mod.rs b/src/tag/mod.rs index 82c8606b..ab7b45c8 100644 --- a/src/tag/mod.rs +++ b/src/tag/mod.rs @@ -395,6 +395,11 @@ impl TagExt for Tag { fn remove_from(&self, file: &mut File) -> std::result::Result<(), Self::Err> { self.tag_type.remove_from(file) } + + fn clear(&mut self) { + self.items.clear(); + self.pictures.clear(); + } } /// The tag's format diff --git a/src/traits.rs b/src/traits.rs index f8419cd2..a52e917c 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -129,5 +129,8 @@ pub trait TagExt: Accessor + Into + Sized { /// * It is unable to write to the file fn remove_from(&self, file: &mut File) -> std::result::Result<(), Self::Err>; - // TODO: clear method + /// Clear the tag, removing all items + /// + /// NOTE: This will **not** remove any format-specific extras, such as flags + fn clear(&mut self); }