mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-13 14:12:31 +00:00
Add genre methods
Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
parent
9878b5172f
commit
b4d8c3657d
7 changed files with 70 additions and 0 deletions
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
11
tests/io.rs
11
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());
|
||||
|
|
Loading…
Reference in a new issue