diff --git a/src/components/tags/ape_tag.rs b/src/components/tags/ape_tag.rs index fde14669..003c6e8f 100644 --- a/src/components/tags/ape_tag.rs +++ b/src/components/tags/ape_tag.rs @@ -130,6 +130,16 @@ impl AudioTagEdit for ApeTag { self.remove_key("Copyright") } + fn genre(&self) -> Option<&str> { + self.get_value("Genre") + } + fn set_genre(&mut self, genre: &str) { + self.set_value("Genre", genre) + } + fn remove_genre(&mut self) { + self.remove_key("Genre") + } + fn album_title(&self) -> Option<&str> { self.get_value("Album") } diff --git a/src/components/tags/id3_tag.rs b/src/components/tags/id3_tag.rs index fd8f4162..58f2bcbe 100644 --- a/src/components/tags/id3_tag.rs +++ b/src/components/tags/id3_tag.rs @@ -156,6 +156,16 @@ impl AudioTagEdit for Id3v2Tag { self.inner.remove("TCOP") } + fn genre(&self) -> Option<&str> { + self.inner.genre() + } + fn set_genre(&mut self, genre: &str) { + self.inner.set_genre(genre) + } + fn remove_genre(&mut self) { + self.inner.remove_genre() + } + fn album_title(&self) -> Option<&str> { self.inner.album() } diff --git a/src/components/tags/mp4_tag.rs b/src/components/tags/mp4_tag.rs index f0911a7b..ddad9215 100644 --- a/src/components/tags/mp4_tag.rs +++ b/src/components/tags/mp4_tag.rs @@ -95,6 +95,16 @@ impl AudioTagEdit for Mp4Tag { self.inner.remove_copyright() } + fn genre(&self) -> Option<&str> { + self.inner.genre() + } + fn set_genre(&mut self, genre: &str) { + self.inner.set_genre(genre) + } + fn remove_genre(&mut self) { + self.inner.remove_genres() + } + fn album_title(&self) -> Option<&str> { self.inner.album() } diff --git a/src/components/tags/ogg_tag.rs b/src/components/tags/ogg_tag.rs index 074b52ae..6e44a410 100644 --- a/src/components/tags/ogg_tag.rs +++ b/src/components/tags/ogg_tag.rs @@ -246,6 +246,16 @@ impl AudioTagEdit for OggTag { self.inner.remove_key("COPYRIGHT") } + fn genre(&self) -> Option<&str> { + self.inner.get_value("GENRE") + } + fn set_genre(&mut self, genre: &str) { + self.inner.set_value("GENRE", genre) + } + fn remove_genre(&mut self) { + self.inner.remove_key("GENRE") + } + fn album_title(&self) -> Option<&str> { self.inner.get_value("ALBUM") } diff --git a/src/components/tags/riff_tag.rs b/src/components/tags/riff_tag.rs index bcc919e1..48a88ea7 100644 --- a/src/components/tags/riff_tag.rs +++ b/src/components/tags/riff_tag.rs @@ -97,6 +97,16 @@ impl AudioTagEdit for RiffTag { self.remove_key("ICOP") } + fn genre(&self) -> Option<&str> { + self.get_value("IGNR") + } + fn set_genre(&mut self, genre: &str) { + self.set_value("IGNR", genre) + } + fn remove_genre(&mut self) { + self.remove_key("IGNR") + } + fn album_title(&self) -> Option<&str> { self.get_value("IPRD").or_else(|| self.get_value("ALBU")) } diff --git a/src/traits.rs b/src/traits.rs index 3afdbfdf..d7cb8364 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -64,6 +64,15 @@ pub trait AudioTagEdit { /// Removes the copyright fn remove_copyright(&mut self) {} + /// Returns the genre + fn genre(&self) -> Option<&str> { + None + } + /// Sets the genre + fn set_genre(&mut self, _genre: &str) {} + /// Removes the genre + fn remove_genre(&mut self) {} + /// Returns the track's [`Album`] fn album(&self) -> Album<'_> { Album { diff --git a/tests/io.rs b/tests/io.rs index 7b5bf78c..d48efd12 100644 --- a/tests/io.rs +++ b/tests/io.rs @@ -34,6 +34,9 @@ macro_rules! add_tags { println!("Setting copyright"); tag.set_copyright("1988"); + println!("Setting genre"); + tag.set_genre("Country"); + println!("Setting album title"); tag.set_album_title("foo album title"); @@ -109,6 +112,9 @@ macro_rules! verify_write { println!("Verifying copyright"); assert_eq!(tag.copyright(), Some("1988")); + println!("Verifying genre"); + assert_eq!(tag.genre(), Some("Country")); + println!("Verifying album title"); assert_eq!(tag.album_title(), Some("foo album title")); @@ -185,6 +191,11 @@ macro_rules! remove_tags { assert!(tag.copyright().is_none()); tag.remove_copyright(); + println!("Removing genre"); + tag.remove_copyright(); + assert!(tag.copyright().is_none()); + tag.remove_copyright(); + println!("Removing album title"); tag.remove_album_title(); assert!(tag.album_title().is_none());