Add genre methods

Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
Serial 2021-07-08 22:07:59 -04:00
parent 9878b5172f
commit b4d8c3657d
7 changed files with 70 additions and 0 deletions

View file

@ -130,6 +130,16 @@ impl AudioTagEdit for ApeTag {
self.remove_key("Copyright") 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> { fn album_title(&self) -> Option<&str> {
self.get_value("Album") self.get_value("Album")
} }

View file

@ -156,6 +156,16 @@ impl AudioTagEdit for Id3v2Tag {
self.inner.remove("TCOP") 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> { fn album_title(&self) -> Option<&str> {
self.inner.album() self.inner.album()
} }

View file

@ -95,6 +95,16 @@ impl AudioTagEdit for Mp4Tag {
self.inner.remove_copyright() 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> { fn album_title(&self) -> Option<&str> {
self.inner.album() self.inner.album()
} }

View file

@ -246,6 +246,16 @@ impl AudioTagEdit for OggTag {
self.inner.remove_key("COPYRIGHT") 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> { fn album_title(&self) -> Option<&str> {
self.inner.get_value("ALBUM") self.inner.get_value("ALBUM")
} }

View file

@ -97,6 +97,16 @@ impl AudioTagEdit for RiffTag {
self.remove_key("ICOP") 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> { fn album_title(&self) -> Option<&str> {
self.get_value("IPRD").or_else(|| self.get_value("ALBU")) self.get_value("IPRD").or_else(|| self.get_value("ALBU"))
} }

View file

@ -64,6 +64,15 @@ pub trait AudioTagEdit {
/// Removes the copyright /// Removes the copyright
fn remove_copyright(&mut self) {} 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`] /// Returns the track's [`Album`]
fn album(&self) -> Album<'_> { fn album(&self) -> Album<'_> {
Album { Album {

View file

@ -34,6 +34,9 @@ macro_rules! add_tags {
println!("Setting copyright"); println!("Setting copyright");
tag.set_copyright("1988"); tag.set_copyright("1988");
println!("Setting genre");
tag.set_genre("Country");
println!("Setting album title"); println!("Setting album title");
tag.set_album_title("foo album title"); tag.set_album_title("foo album title");
@ -109,6 +112,9 @@ macro_rules! verify_write {
println!("Verifying copyright"); println!("Verifying copyright");
assert_eq!(tag.copyright(), Some("1988")); assert_eq!(tag.copyright(), Some("1988"));
println!("Verifying genre");
assert_eq!(tag.genre(), Some("Country"));
println!("Verifying album title"); println!("Verifying album title");
assert_eq!(tag.album_title(), Some("foo album title")); assert_eq!(tag.album_title(), Some("foo album title"));
@ -185,6 +191,11 @@ macro_rules! remove_tags {
assert!(tag.copyright().is_none()); assert!(tag.copyright().is_none());
tag.remove_copyright(); tag.remove_copyright();
println!("Removing genre");
tag.remove_copyright();
assert!(tag.copyright().is_none());
tag.remove_copyright();
println!("Removing album title"); println!("Removing album title");
tag.remove_album_title(); tag.remove_album_title();
assert!(tag.album_title().is_none()); assert!(tag.album_title().is_none());