diff --git a/src/anytag.rs b/src/anytag.rs index d0ba6ea..26059ee 100644 --- a/src/anytag.rs +++ b/src/anytag.rs @@ -16,6 +16,7 @@ pub struct AnyTag<'a> { pub total_discs: Option, pub genre: Option<&'a str>, pub composer: Option<&'a str>, + pub comment: Option<&'a str>, } impl AudioTagConfig for AnyTag<'_> { @@ -71,6 +72,9 @@ impl<'a> AnyTag<'a> { pub fn composer(&self) -> Option<&str> { self.composer } + pub fn comment(&self) -> Option<&str> { + self.comment + } } impl AnyTag<'_> { diff --git a/src/components/flac_tag.rs b/src/components/flac_tag.rs index 61e3903..e7b0629 100644 --- a/src/components/flac_tag.rs +++ b/src/components/flac_tag.rs @@ -55,6 +55,7 @@ impl<'a> From<&'a FlacTag> for AnyTag<'a> { total_discs: inp.total_discs(), genre: inp.genre(), composer: inp.composer(), + comment: inp.comment(), ..Self::default() }; @@ -250,6 +251,16 @@ impl AudioTagEdit for FlacTag { fn remove_genre(&mut self) { self.remove("GENRE"); } + + fn comment(&self) -> Option<&str> { + self.get_first("COMMENT") + } + fn set_comment(&mut self, v: String) { + self.set_first("COMMENT", &v); + } + fn remove_comment(&mut self) { + self.remove("COMMENT"); + } } impl AudioTagWrite for FlacTag { diff --git a/src/components/id3_tag.rs b/src/components/id3_tag.rs index a906b7e..b452e6f 100644 --- a/src/components/id3_tag.rs +++ b/src/components/id3_tag.rs @@ -23,6 +23,7 @@ impl<'a> From<&'a Id3v2Tag> for AnyTag<'a> { total_discs: inp.total_discs(), genre: inp.genre(), composer: inp.composer(), + comment: inp.comment(), } } } @@ -247,6 +248,25 @@ impl AudioTagEdit for Id3v2Tag { fn remove_genre(&mut self) { self.inner.remove_genre(); } + + fn comment(&self) -> Option<&str> { + for comment in self.inner.comments() { + if comment.description.is_empty() { + return Some(comment.text.as_str()); + } + } + None + } + fn set_comment(&mut self, comment: String) { + self.inner.add_frame(id3::frame::Comment { + lang: "XXX".to_string(), + description: "".to_string(), + text: comment, + }); + } + fn remove_comment(&mut self) { + self.inner.remove("COMM"); + } } impl AudioTagWrite for Id3v2Tag { diff --git a/src/components/mp4_tag.rs b/src/components/mp4_tag.rs index f037d25..44f76cf 100644 --- a/src/components/mp4_tag.rs +++ b/src/components/mp4_tag.rs @@ -24,6 +24,7 @@ impl<'a> From<&'a Mp4Tag> for AnyTag<'a> { let total_discs = b; let genre = inp.genre(); let composer = inp.composer(); + let comment = inp.comment(); Self { config: inp.config, title, @@ -39,6 +40,7 @@ impl<'a> From<&'a Mp4Tag> for AnyTag<'a> { total_discs, genre, composer, + comment, } } } @@ -283,6 +285,16 @@ impl AudioTagEdit for Mp4Tag { fn remove_genre(&mut self) { self.inner.remove_genres(); } + + fn comment(&self) -> Option<&str> { + self.inner.comment() + } + fn set_comment(&mut self, comment: String) { + self.inner.set_comment(comment); + } + fn remove_comment(&mut self) { + self.inner.remove_comments(); + } } impl AudioTagWrite for Mp4Tag { diff --git a/src/traits.rs b/src/traits.rs index 56e6727..874c4f3 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -134,6 +134,10 @@ pub trait AudioTagEdit: AudioTagConfig { fn genre(&self) -> Option<&str>; fn set_genre(&mut self, genre: &str); fn remove_genre(&mut self); + + fn comment(&self) -> Option<&str>; + fn set_comment(&mut self, genre: String); + fn remove_comment(&mut self); } pub trait AudioTagWrite { diff --git a/tests/io.rs b/tests/io.rs index 73a7513..4451e2e 100644 --- a/tests/io.rs +++ b/tests/io.rs @@ -62,6 +62,12 @@ macro_rules! test_file { tags.remove_genre(); assert!(tags.genre().is_none()); tags.remove_genre(); + + tags.set_comment("foo song comment".to_string()); + assert_eq!(tags.comment(), Some("foo song comment")); + tags.remove_comment(); + assert!(tags.comment().is_none()); + tags.remove_comment(); } }; }