@@ -30,15 +30,15 @@ use std::ops::Deref;
30
30
use lofty_attr:: tag;
31
31
32
32
macro_rules! impl_accessor {
33
- ( $( $method: ident => ( $target: ident, $name: literal ) ) ,+ $( , ) ?) => {
33
+ ( $( $method: ident => ( $target: ident, $name: expr ) ) ,+ $( , ) ?) => {
34
34
paste:: paste! {
35
35
$(
36
36
fn $method( & self ) -> Option <Cow <' _, str >> {
37
- self . get_str( MatroskaTagKey ( TargetType :: $target, Cow :: Borrowed ( $name) ) )
37
+ self . get_str( MatroskaTagKey ( TargetType :: $target, $name. into ( ) ) )
38
38
}
39
39
40
40
fn [ <set_ $method>] ( & mut self , value: String ) {
41
- todo! ( )
41
+ self . push ( TargetType :: $target , SimpleTag :: new ( Into :: < Cow < ' _ , str >> :: into ( $name ) , value ) )
42
42
}
43
43
44
44
fn [ <remove_ $method>] ( & mut self ) {
@@ -116,6 +116,43 @@ impl MatroskaTag {
116
116
simple_tag. get_str ( ) . map ( Cow :: from)
117
117
}
118
118
119
+ /// Append a new [`SimpleTag`] for the given [`TargetType`]
120
+ ///
121
+ /// NOTE: This will **not** remove other items with the same key.
122
+ ///
123
+ /// # Examples
124
+ ///
125
+ /// ```rust
126
+ /// use lofty::ebml::{SimpleTag, TagName, TargetType, MatroskaTag, Language};
127
+ /// use lofty::picture::Picture;
128
+ /// use lofty::tag::TagExt;
129
+ /// use lofty::tag::Accessor;
130
+ ///
131
+ /// # fn main() -> lofty::error::Result<()> {
132
+ /// let mut tag = MatroskaTag::default();
133
+ ///
134
+ /// // Set the track title the manual way
135
+ /// let title = SimpleTag::new(TagName::Title, "Foo title");
136
+ /// tag.push(TargetType::Track, title);
137
+ ///
138
+ /// // Push a Spanish variant of the title
139
+ /// let mut title2 = SimpleTag::new(TagName::Title, "Título foo");
140
+ /// title2.language = Language::Iso639_2(String::from("spa"));
141
+ ///
142
+ /// tag.push(TargetType::Track, title2);
143
+ ///
144
+ /// // The variant with an undefined language was first in the list
145
+ /// assert_eq!(tag.title().as_deref(), Some("Foo title"));
146
+ ///
147
+ /// // And the Spanish variant exists in the tag for players that support it
148
+ /// assert_eq!(tag.len(), 2);
149
+ /// # Ok(()) }
150
+ pub fn push ( & mut self , target : TargetType , value : SimpleTag < ' _ > ) {
151
+ let value = value. into_owned ( ) ;
152
+ let tag = self . get_or_insert_tag_for_type ( target) ;
153
+ tag. simple_tags . push ( value) ;
154
+ }
155
+
119
156
/// Returns all [`Tag`]s, if there are any
120
157
pub fn tags ( & self ) -> impl Iterator < Item = & Tag < ' _ > > {
121
158
self . tags . iter ( )
@@ -234,10 +271,10 @@ impl MatroskaTag {
234
271
235
272
impl Accessor for MatroskaTag {
236
273
impl_accessor ! (
237
- artist => ( Track , "ARTIST" ) ,
238
- title => ( Track , "TITLE" ) ,
239
- album => ( Album , "TITLE" ) ,
240
- comment => ( Track , "COMMENT" ) ,
274
+ artist => ( Track , TagName :: Artist ) ,
275
+ title => ( Track , TagName :: Title ) ,
276
+ album => ( Album , TagName :: Title ) ,
277
+ comment => ( Track , TagName :: Comment ) ,
241
278
) ;
242
279
243
280
fn track ( & self ) -> Option < u32 > {
0 commit comments