From 97546e697176e6ad3d373157537d073d277d1729 Mon Sep 17 00:00:00 2001 From: Braden Steffaniak Date: Tue, 19 Sep 2023 07:30:00 -0400 Subject: [PATCH 1/6] Remove unused import --- src/components/id3_tag.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/id3_tag.rs b/src/components/id3_tag.rs index 9cd86db..5b0d3ae 100644 --- a/src/components/id3_tag.rs +++ b/src/components/id3_tag.rs @@ -1,5 +1,5 @@ use crate::*; -use id3::{self, Content, Frame, TagLike, Timestamp, Version}; +use id3::{self, Content, Frame, TagLike, Timestamp}; pub use id3::Tag as Id3v2InnerTag; From 082777f7e724b79a9be1ef30631735fd1bcb963f Mon Sep 17 00:00:00 2001 From: Braden Steffaniak Date: Tue, 19 Sep 2023 07:30:00 -0400 Subject: [PATCH 2/6] Add date_released, original_date_released, and date_recorded --- src/anytag.rs | 22 ++++++++++++ src/components/flac_tag.rs | 64 ++++++++++++++++++++++++++++++++--- src/components/id3_tag.rs | 69 ++++++++++++++++++++++++-------------- src/components/mp4_tag.rs | 50 +++++++++++++++++++++++++++ src/traits.rs | 13 +++++++ tests/io.rs | 29 ++++++++++++++++ 6 files changed, 216 insertions(+), 31 deletions(-) diff --git a/src/anytag.rs b/src/anytag.rs index 26059ee..b985477 100644 --- a/src/anytag.rs +++ b/src/anytag.rs @@ -1,10 +1,14 @@ use crate::*; +use id3::Timestamp; #[derive(Default)] pub struct AnyTag<'a> { pub config: Config, pub title: Option<&'a str>, pub artists: Option>, + pub date_released: Option, + pub original_date_released: Option, + pub date_recorded: Option, pub year: Option, pub duration: Option, pub album_title: Option<&'a str>, @@ -39,6 +43,24 @@ impl<'a> AnyTag<'a> { self.artists.as_deref() } // set_artists; add_artist + pub fn date_released(&self) -> Option { + self.date_released + } + pub fn set_date_released(&mut self, date_released: Timestamp) { + self.date_released = Some(date_released); + } + pub fn original_date_released(&self) -> Option { + self.original_date_released + } + pub fn set_original_date_released(&mut self, original_date_released: Timestamp) { + self.original_date_released = Some(original_date_released); + } + pub fn date_recorded(&self) -> Option { + self.date_recorded + } + pub fn set_date_recorded(&mut self, date_recorded: Timestamp) { + self.date_recorded = Some(date_recorded); + } pub fn year(&self) -> Option { self.year } diff --git a/src/components/flac_tag.rs b/src/components/flac_tag.rs index b1dcca1..8ae43b1 100644 --- a/src/components/flac_tag.rs +++ b/src/components/flac_tag.rs @@ -1,5 +1,7 @@ use crate::*; +use id3::Timestamp; use metaflac; +use std::str::FromStr; pub use metaflac::Tag as FlacInnerTag; @@ -14,6 +16,15 @@ impl<'a> From> for FlacTag { if let Some(v) = inp.artists_as_string() { t.set_artist(&v) } + if let Some(v) = inp.date_released { + t.set_date_released(v) + } + if let Some(v) = inp.original_date_released { + t.set_original_date_released(v) + } + if let Some(v) = inp.date_recorded { + t.set_date_recorded(v) + } if let Some(v) = inp.year { t.set_year(v) } @@ -44,6 +55,9 @@ impl<'a> From<&'a FlacTag> for AnyTag<'a> { let tag = Self { title: inp.title(), artists: inp.artists(), + date_released: inp.date_released(), + original_date_released: inp.original_date_released(), + date_recorded: inp.date_recorded(), year: inp.year(), duration: inp.duration(), album_title: inp.album_title(), @@ -104,25 +118,65 @@ impl AudioTagEdit for FlacTag { self.remove("ARTIST"); } + fn date_released(&self) -> Option { + if let Some(Ok(timestamp)) = self.get_first("DATE").map(Timestamp::from_str) { + Some(timestamp) + } else { + None + } + } + fn set_date_released(&mut self, date_released: Timestamp) { + self.set_first("DATE", &date_released.to_string()); + } + fn remove_date_released(&mut self) { + self.remove("DATE"); + } + + fn original_date_released(&self) -> Option { + if let Some(Ok(timestamp)) = self.get_first("DATE").map(Timestamp::from_str) { + Some(timestamp) + } else { + None + } + } + fn set_original_date_released(&mut self, original_date_released: Timestamp) { + self.set_first("DATE", &original_date_released.to_string()); + } + fn remove_original_date_released(&mut self) { + self.remove("DATE"); + } + + fn date_recorded(&self) -> Option { + if let Some(Ok(timestamp)) = self.get_first("DATE").map(Timestamp::from_str) { + Some(timestamp) + } else { + None + } + } + fn set_date_recorded(&mut self, date_recorded: Timestamp) { + self.set_first("DATE", &date_recorded.to_string()); + } + fn remove_date_recorded(&mut self) { + self.remove("DATE"); + } + fn year(&self) -> Option { - if let Some(Ok(y)) = self + if let Some(Ok(y)) = self.get_first("YEAR").map(|s| s.parse::()) { + Some(y) + } else if let Some(Ok(y)) = self .get_first("DATE") .map(|s| s.chars().take(4).collect::().parse::()) { Some(y) - } else if let Some(Ok(y)) = self.get_first("YEAR").map(|s| s.parse::()) { - Some(y) } else { None } } fn set_year(&mut self, year: i32) { - self.set_first("DATE", &year.to_string()); self.set_first("YEAR", &year.to_string()); } fn remove_year(&mut self) { self.remove("YEAR"); - self.remove("DATE"); } fn duration(&self) -> Option { diff --git a/src/components/id3_tag.rs b/src/components/id3_tag.rs index 5b0d3ae..0a596ff 100644 --- a/src/components/id3_tag.rs +++ b/src/components/id3_tag.rs @@ -12,6 +12,9 @@ impl<'a> From<&'a Id3v2Tag> for AnyTag<'a> { title: inp.title(), artists: inp.artists(), + date_released: inp.date_released(), + original_date_released: inp.original_date_released(), + date_recorded: inp.date_recorded(), year: inp.year(), duration: Some(inp.inner.duration().unwrap() as f64), album_title: inp.album_title(), @@ -40,6 +43,15 @@ impl<'a> From> for Id3v2Tag { if let Some(v) = inp.artists_as_string() { t.set_artist(&v) } + if let Some(v) = inp.date_released() { + t.set_date_released(v) + } + if let Some(v) = inp.original_date_released() { + t.set_original_date_released(v) + } + if let Some(v) = inp.date_recorded() { + t.set_date_recorded(v) + } if let Some(v) = inp.year { t.set_year(v) } @@ -102,38 +114,43 @@ impl AudioTagEdit for Id3v2Tag { self.inner.remove_artist(); } - fn year(&self) -> Option { - if self.inner.version() == Version::Id3v23 { - if let ret @ Some(_) = self.inner.year() { - return ret; - } - } + fn original_date_released(&self) -> Option { + self.inner.original_date_released() + } + fn set_original_date_released(&mut self, timestamp: Timestamp) { + self.inner.set_original_date_released(timestamp) + } + fn remove_original_date_released(&mut self) { + self.inner.remove_original_date_released() + } - self.inner.date_recorded().map(|timestamp| timestamp.year) + fn date_released(&self) -> Option { + self.inner.date_released() + } + fn set_date_released(&mut self, timestamp: Timestamp) { + self.inner.set_date_released(timestamp) + } + fn remove_date_released(&mut self) { + self.inner.remove_date_released() } - fn set_year(&mut self, year: i32) { - if self.inner.version() == Version::Id3v23 { - self.inner.set_year(year); - return; - } - if let Some(mut timestamp) = self.inner.date_recorded() { - timestamp.year = year; - self.inner.set_date_recorded(timestamp); - return; - } + fn date_recorded(&self) -> Option { + self.inner.date_recorded() + } + fn set_date_recorded(&mut self, timestamp: Timestamp) { + self.inner.set_date_recorded(timestamp) + } + fn remove_date_recorded(&mut self) { + self.inner.remove_date_recorded() + } - self.inner.set_date_recorded(Timestamp { - year, - month: None, - day: None, - hour: None, - minute: None, - second: None, - }); + fn year(&self) -> Option { + self.inner.year() + } + fn set_year(&mut self, year: i32) { + self.inner.set_year(year); } fn remove_year(&mut self) { - self.inner.remove_date_recorded(); self.inner.remove_year(); } fn duration(&self) -> Option { diff --git a/src/components/mp4_tag.rs b/src/components/mp4_tag.rs index 44f76cf..837bd97 100644 --- a/src/components/mp4_tag.rs +++ b/src/components/mp4_tag.rs @@ -1,5 +1,7 @@ use crate::*; +use id3::Timestamp; use mp4ameta::{self, ImgFmt}; +use std::str::FromStr; pub use mp4ameta::Tag as Mp4InnerTag; @@ -9,6 +11,9 @@ impl<'a> From<&'a Mp4Tag> for AnyTag<'a> { fn from(inp: &'a Mp4Tag) -> Self { let title = inp.title(); let artists = inp.artists().map(|i| i.into_iter().collect::>()); + let date_released = inp.date_released(); + let original_date_released = inp.original_date_released(); + let date_recorded = inp.date_recorded(); let year = inp.year(); let duration = inp.duration(); let album_title = inp.album_title(); @@ -29,6 +34,9 @@ impl<'a> From<&'a Mp4Tag> for AnyTag<'a> { config: inp.config, title, artists, + date_released, + original_date_released, + date_recorded, year, duration, album_title, @@ -137,6 +145,48 @@ impl AudioTagEdit for Mp4Tag { self.inner.add_artist(v); } + fn date_released(&self) -> Option { + if let Some(Ok(date)) = self.inner.year().map(Timestamp::from_str) { + Some(date) + } else { + None + } + } + fn set_date_released(&mut self, date_released: Timestamp) { + self.inner.set_year(date_released.to_string()) + } + fn remove_date_released(&mut self) { + self.inner.remove_year() + } + + fn original_date_released(&self) -> Option { + if let Some(Ok(date)) = self.inner.year().map(Timestamp::from_str) { + Some(date) + } else { + None + } + } + fn set_original_date_released(&mut self, original_date_released: Timestamp) { + self.inner.set_year(original_date_released.to_string()) + } + fn remove_original_date_released(&mut self) { + self.inner.remove_year() + } + + fn date_recorded(&self) -> Option { + if let Some(Ok(date)) = self.inner.year().map(Timestamp::from_str) { + Some(date) + } else { + None + } + } + fn set_date_recorded(&mut self, date_recorded: Timestamp) { + self.inner.set_year(date_recorded.to_string()) + } + fn remove_date_recorded(&mut self) { + self.inner.remove_year() + } + fn year(&self) -> Option { self.inner.year().and_then(|x| str::parse(x).ok()) } diff --git a/src/traits.rs b/src/traits.rs index 874c4f3..e60cf34 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -1,4 +1,5 @@ use super::*; +use id3::Timestamp; pub trait AudioTag: AudioTagEdit + AudioTagWrite + ToAnyTag {} @@ -31,6 +32,18 @@ pub trait AudioTagEdit: AudioTagConfig { self.set_artist(artist); } + fn original_date_released(&self) -> Option; + fn set_original_date_released(&mut self, date: Timestamp); + fn remove_original_date_released(&mut self); + + fn date_released(&self) -> Option; + fn set_date_released(&mut self, date: Timestamp); + fn remove_date_released(&mut self); + + fn date_recorded(&self) -> Option; + fn set_date_recorded(&mut self, date: Timestamp); + fn remove_date_recorded(&mut self); + fn year(&self) -> Option; fn set_year(&mut self, year: i32); fn remove_year(&mut self); diff --git a/tests/io.rs b/tests/io.rs index 4451e2e..67fe65a 100644 --- a/tests/io.rs +++ b/tests/io.rs @@ -1,7 +1,9 @@ use audiotags::{MimeType, Picture, Tag}; +use id3::Timestamp; use std::ffi::OsString; use std::fs; use std::path::Path; +use std::str::FromStr; use tempfile::Builder; macro_rules! test_file { @@ -28,6 +30,33 @@ macro_rules! test_file { assert!(tags.artist().is_none()); tags.remove_artist(); + tags.set_date_released(Timestamp::from_str("2020-05-22").unwrap()); + assert_eq!( + tags.date_released(), + Some(Timestamp::from_str("2020-05-22").unwrap()) + ); + tags.remove_date_released(); + assert!(tags.date_released().is_none()); + tags.remove_date_released(); + + tags.set_original_date_released(Timestamp::from_str("2020-05-22").unwrap()); + assert_eq!( + tags.original_date_released(), + Some(Timestamp::from_str("2020-05-22").unwrap()) + ); + tags.remove_original_date_released(); + assert!(tags.original_date_released().is_none()); + tags.remove_original_date_released(); + + tags.set_date_recorded(Timestamp::from_str("2020-05-22").unwrap()); + assert_eq!( + tags.date_recorded(), + Some(Timestamp::from_str("2020-05-22").unwrap()) + ); + tags.remove_date_recorded(); + assert!(tags.date_recorded().is_none()); + tags.remove_date_recorded(); + tags.set_year(2020); assert_eq!(tags.year(), Some(2020)); tags.remove_year(); From da4b5f0d225a9d3690a0b43853ee2590693ab76f Mon Sep 17 00:00:00 2001 From: Braden Steffaniak Date: Fri, 22 Sep 2023 07:30:00 -0400 Subject: [PATCH 3/6] Remove DATE as well as YEAR --- src/components/flac_tag.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/flac_tag.rs b/src/components/flac_tag.rs index 8ae43b1..5c577fb 100644 --- a/src/components/flac_tag.rs +++ b/src/components/flac_tag.rs @@ -177,6 +177,7 @@ impl AudioTagEdit for FlacTag { } fn remove_year(&mut self) { self.remove("YEAR"); + self.remove("DATE"); } fn duration(&self) -> Option { From 6f5c5d03cb48c7bff884a4bb14382f57140a13f6 Mon Sep 17 00:00:00 2001 From: Braden Steffaniak Date: Fri, 22 Sep 2023 07:30:00 -0400 Subject: [PATCH 4/6] Generify 'date' concept to singular generic `date` property --- src/anytag.rs | 24 +++++------------------- src/components/flac_tag.rs | 12 ++---------- src/components/id3_tag.rs | 12 ++---------- src/components/mp4_tag.rs | 8 ++------ 4 files changed, 11 insertions(+), 45 deletions(-) diff --git a/src/anytag.rs b/src/anytag.rs index b985477..3397fe5 100644 --- a/src/anytag.rs +++ b/src/anytag.rs @@ -6,9 +6,7 @@ pub struct AnyTag<'a> { pub config: Config, pub title: Option<&'a str>, pub artists: Option>, - pub date_released: Option, - pub original_date_released: Option, - pub date_recorded: Option, + pub date: Option, pub year: Option, pub duration: Option, pub album_title: Option<&'a str>, @@ -43,23 +41,11 @@ impl<'a> AnyTag<'a> { self.artists.as_deref() } // set_artists; add_artist - pub fn date_released(&self) -> Option { - self.date_released + pub fn date(&self) -> Option { + self.date } - pub fn set_date_released(&mut self, date_released: Timestamp) { - self.date_released = Some(date_released); - } - pub fn original_date_released(&self) -> Option { - self.original_date_released - } - pub fn set_original_date_released(&mut self, original_date_released: Timestamp) { - self.original_date_released = Some(original_date_released); - } - pub fn date_recorded(&self) -> Option { - self.date_recorded - } - pub fn set_date_recorded(&mut self, date_recorded: Timestamp) { - self.date_recorded = Some(date_recorded); + pub fn set_date(&mut self, date: Timestamp) { + self.date = Some(date); } pub fn year(&self) -> Option { self.year diff --git a/src/components/flac_tag.rs b/src/components/flac_tag.rs index 5c577fb..dc538ff 100644 --- a/src/components/flac_tag.rs +++ b/src/components/flac_tag.rs @@ -16,13 +16,7 @@ impl<'a> From> for FlacTag { if let Some(v) = inp.artists_as_string() { t.set_artist(&v) } - if let Some(v) = inp.date_released { - t.set_date_released(v) - } - if let Some(v) = inp.original_date_released { - t.set_original_date_released(v) - } - if let Some(v) = inp.date_recorded { + if let Some(v) = inp.date { t.set_date_recorded(v) } if let Some(v) = inp.year { @@ -55,9 +49,7 @@ impl<'a> From<&'a FlacTag> for AnyTag<'a> { let tag = Self { title: inp.title(), artists: inp.artists(), - date_released: inp.date_released(), - original_date_released: inp.original_date_released(), - date_recorded: inp.date_recorded(), + date: inp.date_released(), year: inp.year(), duration: inp.duration(), album_title: inp.album_title(), diff --git a/src/components/id3_tag.rs b/src/components/id3_tag.rs index 0a596ff..ee64988 100644 --- a/src/components/id3_tag.rs +++ b/src/components/id3_tag.rs @@ -12,9 +12,7 @@ impl<'a> From<&'a Id3v2Tag> for AnyTag<'a> { title: inp.title(), artists: inp.artists(), - date_released: inp.date_released(), - original_date_released: inp.original_date_released(), - date_recorded: inp.date_recorded(), + date: inp.date_recorded(), year: inp.year(), duration: Some(inp.inner.duration().unwrap() as f64), album_title: inp.album_title(), @@ -43,13 +41,7 @@ impl<'a> From> for Id3v2Tag { if let Some(v) = inp.artists_as_string() { t.set_artist(&v) } - if let Some(v) = inp.date_released() { - t.set_date_released(v) - } - if let Some(v) = inp.original_date_released() { - t.set_original_date_released(v) - } - if let Some(v) = inp.date_recorded() { + if let Some(v) = inp.date() { t.set_date_recorded(v) } if let Some(v) = inp.year { diff --git a/src/components/mp4_tag.rs b/src/components/mp4_tag.rs index 837bd97..6111e9c 100644 --- a/src/components/mp4_tag.rs +++ b/src/components/mp4_tag.rs @@ -11,9 +11,7 @@ impl<'a> From<&'a Mp4Tag> for AnyTag<'a> { fn from(inp: &'a Mp4Tag) -> Self { let title = inp.title(); let artists = inp.artists().map(|i| i.into_iter().collect::>()); - let date_released = inp.date_released(); - let original_date_released = inp.original_date_released(); - let date_recorded = inp.date_recorded(); + let date = inp.date_recorded(); let year = inp.year(); let duration = inp.duration(); let album_title = inp.album_title(); @@ -34,9 +32,7 @@ impl<'a> From<&'a Mp4Tag> for AnyTag<'a> { config: inp.config, title, artists, - date_released, - original_date_released, - date_recorded, + date, year, duration, album_title, From 0042cde57d26c4f9a559471abcffc5791edf3077 Mon Sep 17 00:00:00 2001 From: Braden Steffaniak Date: Fri, 22 Sep 2023 07:30:00 -0400 Subject: [PATCH 5/6] Generify to `date` on AudioTagEdit --- src/components/flac_tag.rs | 40 ++++++-------------------------------- src/components/id3_tag.rs | 28 ++++---------------------- src/components/mp4_tag.rs | 38 +++++------------------------------- src/traits.rs | 14 +++---------- tests/io.rs | 28 +++++--------------------- 5 files changed, 23 insertions(+), 125 deletions(-) diff --git a/src/components/flac_tag.rs b/src/components/flac_tag.rs index dc538ff..857a22f 100644 --- a/src/components/flac_tag.rs +++ b/src/components/flac_tag.rs @@ -17,7 +17,7 @@ impl<'a> From> for FlacTag { t.set_artist(&v) } if let Some(v) = inp.date { - t.set_date_recorded(v) + t.set_date(v) } if let Some(v) = inp.year { t.set_year(v) @@ -49,7 +49,7 @@ impl<'a> From<&'a FlacTag> for AnyTag<'a> { let tag = Self { title: inp.title(), artists: inp.artists(), - date: inp.date_released(), + date: inp.date(), year: inp.year(), duration: inp.duration(), album_title: inp.album_title(), @@ -110,45 +110,17 @@ impl AudioTagEdit for FlacTag { self.remove("ARTIST"); } - fn date_released(&self) -> Option { + fn date(&self) -> Option { if let Some(Ok(timestamp)) = self.get_first("DATE").map(Timestamp::from_str) { Some(timestamp) } else { None } } - fn set_date_released(&mut self, date_released: Timestamp) { - self.set_first("DATE", &date_released.to_string()); + fn set_date(&mut self, date: Timestamp) { + self.set_first("DATE", &date.to_string()); } - fn remove_date_released(&mut self) { - self.remove("DATE"); - } - - fn original_date_released(&self) -> Option { - if let Some(Ok(timestamp)) = self.get_first("DATE").map(Timestamp::from_str) { - Some(timestamp) - } else { - None - } - } - fn set_original_date_released(&mut self, original_date_released: Timestamp) { - self.set_first("DATE", &original_date_released.to_string()); - } - fn remove_original_date_released(&mut self) { - self.remove("DATE"); - } - - fn date_recorded(&self) -> Option { - if let Some(Ok(timestamp)) = self.get_first("DATE").map(Timestamp::from_str) { - Some(timestamp) - } else { - None - } - } - fn set_date_recorded(&mut self, date_recorded: Timestamp) { - self.set_first("DATE", &date_recorded.to_string()); - } - fn remove_date_recorded(&mut self) { + fn remove_date(&mut self) { self.remove("DATE"); } diff --git a/src/components/id3_tag.rs b/src/components/id3_tag.rs index ee64988..ccc4b8e 100644 --- a/src/components/id3_tag.rs +++ b/src/components/id3_tag.rs @@ -12,7 +12,7 @@ impl<'a> From<&'a Id3v2Tag> for AnyTag<'a> { title: inp.title(), artists: inp.artists(), - date: inp.date_recorded(), + date: inp.date(), year: inp.year(), duration: Some(inp.inner.duration().unwrap() as f64), album_title: inp.album_title(), @@ -106,33 +106,13 @@ impl AudioTagEdit for Id3v2Tag { self.inner.remove_artist(); } - fn original_date_released(&self) -> Option { - self.inner.original_date_released() - } - fn set_original_date_released(&mut self, timestamp: Timestamp) { - self.inner.set_original_date_released(timestamp) - } - fn remove_original_date_released(&mut self) { - self.inner.remove_original_date_released() - } - - fn date_released(&self) -> Option { - self.inner.date_released() - } - fn set_date_released(&mut self, timestamp: Timestamp) { - self.inner.set_date_released(timestamp) - } - fn remove_date_released(&mut self) { - self.inner.remove_date_released() - } - - fn date_recorded(&self) -> Option { + fn date(&self) -> Option { self.inner.date_recorded() } - fn set_date_recorded(&mut self, timestamp: Timestamp) { + fn set_date(&mut self, timestamp: Timestamp) { self.inner.set_date_recorded(timestamp) } - fn remove_date_recorded(&mut self) { + fn remove_date(&mut self) { self.inner.remove_date_recorded() } diff --git a/src/components/mp4_tag.rs b/src/components/mp4_tag.rs index 6111e9c..0e4281a 100644 --- a/src/components/mp4_tag.rs +++ b/src/components/mp4_tag.rs @@ -11,7 +11,7 @@ impl<'a> From<&'a Mp4Tag> for AnyTag<'a> { fn from(inp: &'a Mp4Tag) -> Self { let title = inp.title(); let artists = inp.artists().map(|i| i.into_iter().collect::>()); - let date = inp.date_recorded(); + let date = inp.date(); let year = inp.year(); let duration = inp.duration(); let album_title = inp.album_title(); @@ -141,45 +141,17 @@ impl AudioTagEdit for Mp4Tag { self.inner.add_artist(v); } - fn date_released(&self) -> Option { + fn date(&self) -> Option { if let Some(Ok(date)) = self.inner.year().map(Timestamp::from_str) { Some(date) } else { None } } - fn set_date_released(&mut self, date_released: Timestamp) { - self.inner.set_year(date_released.to_string()) + fn set_date(&mut self, date: Timestamp) { + self.inner.set_year(date.to_string()) } - fn remove_date_released(&mut self) { - self.inner.remove_year() - } - - fn original_date_released(&self) -> Option { - if let Some(Ok(date)) = self.inner.year().map(Timestamp::from_str) { - Some(date) - } else { - None - } - } - fn set_original_date_released(&mut self, original_date_released: Timestamp) { - self.inner.set_year(original_date_released.to_string()) - } - fn remove_original_date_released(&mut self) { - self.inner.remove_year() - } - - fn date_recorded(&self) -> Option { - if let Some(Ok(date)) = self.inner.year().map(Timestamp::from_str) { - Some(date) - } else { - None - } - } - fn set_date_recorded(&mut self, date_recorded: Timestamp) { - self.inner.set_year(date_recorded.to_string()) - } - fn remove_date_recorded(&mut self) { + fn remove_date(&mut self) { self.inner.remove_year() } diff --git a/src/traits.rs b/src/traits.rs index e60cf34..7cd43fa 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -32,17 +32,9 @@ pub trait AudioTagEdit: AudioTagConfig { self.set_artist(artist); } - fn original_date_released(&self) -> Option; - fn set_original_date_released(&mut self, date: Timestamp); - fn remove_original_date_released(&mut self); - - fn date_released(&self) -> Option; - fn set_date_released(&mut self, date: Timestamp); - fn remove_date_released(&mut self); - - fn date_recorded(&self) -> Option; - fn set_date_recorded(&mut self, date: Timestamp); - fn remove_date_recorded(&mut self); + fn date(&self) -> Option; + fn set_date(&mut self, date: Timestamp); + fn remove_date(&mut self); fn year(&self) -> Option; fn set_year(&mut self, year: i32); diff --git a/tests/io.rs b/tests/io.rs index 67fe65a..c4ed80c 100644 --- a/tests/io.rs +++ b/tests/io.rs @@ -30,32 +30,14 @@ macro_rules! test_file { assert!(tags.artist().is_none()); tags.remove_artist(); - tags.set_date_released(Timestamp::from_str("2020-05-22").unwrap()); + tags.set_date(Timestamp::from_str("2020-05-22").unwrap()); assert_eq!( - tags.date_released(), + tags.date(), Some(Timestamp::from_str("2020-05-22").unwrap()) ); - tags.remove_date_released(); - assert!(tags.date_released().is_none()); - tags.remove_date_released(); - - tags.set_original_date_released(Timestamp::from_str("2020-05-22").unwrap()); - assert_eq!( - tags.original_date_released(), - Some(Timestamp::from_str("2020-05-22").unwrap()) - ); - tags.remove_original_date_released(); - assert!(tags.original_date_released().is_none()); - tags.remove_original_date_released(); - - tags.set_date_recorded(Timestamp::from_str("2020-05-22").unwrap()); - assert_eq!( - tags.date_recorded(), - Some(Timestamp::from_str("2020-05-22").unwrap()) - ); - tags.remove_date_recorded(); - assert!(tags.date_recorded().is_none()); - tags.remove_date_recorded(); + tags.remove_date(); + assert!(tags.date().is_none()); + tags.remove_date(); tags.set_year(2020); assert_eq!(tags.year(), Some(2020)); From 4dc25001fd2fe16fa8da9b1d7054ff6c10b0f554 Mon Sep 17 00:00:00 2001 From: Braden Steffaniak Date: Fri, 22 Sep 2023 07:30:00 -0400 Subject: [PATCH 6/6] Remove `date_recorded` as well as `year` --- src/components/id3_tag.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/id3_tag.rs b/src/components/id3_tag.rs index ccc4b8e..f7859fb 100644 --- a/src/components/id3_tag.rs +++ b/src/components/id3_tag.rs @@ -123,6 +123,7 @@ impl AudioTagEdit for Id3v2Tag { self.inner.set_year(year); } fn remove_year(&mut self) { + self.inner.remove_date_recorded(); self.inner.remove_year(); } fn duration(&self) -> Option {