Skip to content

Commit

Permalink
Merge pull request #19 from Serial-ATA/composer
Browse files Browse the repository at this point in the history
Add `AudioTagEdit::{set_,remove_}composer`
  • Loading branch information
pinkforest authored Aug 1, 2022
2 parents 039f2f4 + c8d0278 commit 5019202
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/anytag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct AnyTag<'a> {
pub disc_number: Option<u16>,
pub total_discs: Option<u16>,
pub genre: Option<&'a str>,
pub composer: Option<&'a str>,
}

impl AudioTagConfig for AnyTag<'_> {
Expand Down Expand Up @@ -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<'_> {
Expand Down
11 changes: 11 additions & 0 deletions src/components/flac_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};

Expand Down Expand Up @@ -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<u16> {
if let Some(Ok(n)) = self.get_first("TRACKNUMBER").map(|x| x.parse::<u16>()) {
Some(n)
Expand Down
17 changes: 16 additions & 1 deletion src/components/id3_tag.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::*;
use id3::{self, TagLike};
use id3::{self, Content, Frame, TagLike};

pub use id3::Tag as Id3v2InnerTag;

Expand All @@ -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(),
}
}
}
Expand Down Expand Up @@ -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<u16> {
self.inner.track().map(|x| x as u16)
}
Expand Down
12 changes: 12 additions & 0 deletions src/components/mp4_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -37,6 +38,7 @@ impl<'a> From<&'a Mp4Tag> for AnyTag<'a> {
disc_number,
total_discs,
genre,
composer,
}
}
}
Expand Down Expand Up @@ -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<u16> {
self.inner.track_number()
}
Expand Down
4 changes: 4 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u16>, Option<u16>) {
(self.track_number(), self.total_tracks())
}
Expand Down

0 comments on commit 5019202

Please sign in to comment.