diff --git a/src/anytag.rs b/src/anytag.rs index 018b87b..cc8231f 100644 --- a/src/anytag.rs +++ b/src/anytag.rs @@ -15,6 +15,7 @@ pub struct AnyTag<'a> { pub disc_number: Option, pub total_discs: Option, pub genre: Option<&'a str>, + pub composer: Option<&'a str>, } impl AudioTagConfig for AnyTag<'_> { @@ -67,6 +68,9 @@ impl<'a> AnyTag<'a> { pub fn genre(&self) -> Option<&str> { self.genre } + pub fn composer(&self) -> Option<&str> { + self.composer + } } impl AnyTag<'_> { diff --git a/src/components/flac_tag.rs b/src/components/flac_tag.rs index d3e1220..e017350 100644 --- a/src/components/flac_tag.rs +++ b/src/components/flac_tag.rs @@ -54,6 +54,7 @@ impl<'a> From<&'a FlacTag> for AnyTag<'a> { disc_number: inp.disc_number(), total_discs: inp.total_discs(), genre: inp.genre(), + composer: inp.composer(), ..Self::default() }; @@ -152,6 +153,16 @@ impl AudioTagEdit for FlacTag { .add_picture(mime, picture_type, (cover.data).to_owned()); } + fn composer(&self) -> Option<&str> { + self.get_first("COMPOSER") + } + fn set_composer(&mut self, composer: String) { + self.set_first("COMPOSER", &composer); + } + fn remove_composer(&mut self) { + self.remove("COMPOSER") + } + fn track_number(&self) -> Option { if let Some(Ok(n)) = self.get_first("TRACKNUMBER").map(|x| x.parse::()) { Some(n) diff --git a/src/components/id3_tag.rs b/src/components/id3_tag.rs index 71d82e0..d907096 100644 --- a/src/components/id3_tag.rs +++ b/src/components/id3_tag.rs @@ -1,5 +1,5 @@ use crate::*; -use id3::{self, TagLike}; +use id3::{self, Content, Frame, TagLike}; pub use id3::Tag as Id3v2InnerTag; @@ -22,6 +22,7 @@ impl<'a> From<&'a Id3v2Tag> for AnyTag<'a> { disc_number: inp.disc_number(), total_discs: inp.total_discs(), genre: inp.genre(), + composer: inp.composer(), } } } @@ -160,6 +161,20 @@ impl AudioTagEdit for Id3v2Tag { .remove_picture_by_type(id3::frame::PictureType::CoverFront); } + fn composer(&self) -> Option<&str> { + if let Some(Content::Text(text)) = self.inner.get("TCOM").map(Frame::content) { + return Some(text); + } + + None + } + fn set_composer(&mut self, composer: String) { + self.inner.add_frame(Frame::text("TCOM", composer)); + } + fn remove_composer(&mut self) { + self.inner.remove("TCOM"); + } + fn track_number(&self) -> Option { self.inner.track().map(|x| x as u16) } diff --git a/src/components/mp4_tag.rs b/src/components/mp4_tag.rs index f88811a..acc8f96 100644 --- a/src/components/mp4_tag.rs +++ b/src/components/mp4_tag.rs @@ -23,6 +23,7 @@ impl<'a> From<&'a Mp4Tag> for AnyTag<'a> { let disc_number = a; let total_discs = b; let genre = inp.genre(); + let composer = inp.composer(); Self { config: inp.config, title, @@ -37,6 +38,7 @@ impl<'a> From<&'a Mp4Tag> for AnyTag<'a> { disc_number, total_discs, genre, + composer, } } } @@ -195,6 +197,16 @@ impl AudioTagEdit for Mp4Tag { }); } + fn composer(&self) -> Option<&str> { + self.inner.composer() + } + fn set_composer(&mut self, composer: String) { + self.inner.set_composer(composer); + } + fn remove_composer(&mut self) { + self.inner.remove_composers(); + } + fn track_number(&self) -> Option { self.inner.track_number() } diff --git a/src/traits.rs b/src/traits.rs index 5f40972..56e6727 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -87,6 +87,10 @@ pub trait AudioTagEdit: AudioTagConfig { fn set_album_cover(&mut self, cover: Picture); fn remove_album_cover(&mut self); + fn composer(&self) -> Option<&str>; + fn set_composer(&mut self, composer: String); + fn remove_composer(&mut self); + fn track(&self) -> (Option, Option) { (self.track_number(), self.total_tracks()) }