Skip to content

Commit

Permalink
Fix Id3v2Tag::{*year} methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed Aug 1, 2022
1 parent bb031f4 commit 6bc125a
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/components/id3_tag.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::*;
use id3::{self, Content, Frame, TagLike};
use id3::{self, Content, Frame, TagLike, Timestamp, Version};

pub use id3::Tag as Id3v2InnerTag;

Expand Down Expand Up @@ -104,12 +104,37 @@ impl AudioTagEdit for Id3v2Tag {
}

fn year(&self) -> Option<i32> {
self.inner.year()
if self.inner.version() == Version::Id3v23 {
if let ret @ Some(_) = self.inner.year() {
return ret;
}
}

self.inner.date_recorded().map(|timestamp| timestamp.year)
}
fn set_year(&mut self, year: i32) {
self.inner.set_year(year)
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;
}

self.inner.set_date_recorded(Timestamp {
year,
month: None,
day: None,
hour: None,
minute: None,
second: None
});
}
fn remove_year(&mut self) {
self.inner.remove_date_recorded();
self.inner.remove_year();
}
fn duration(&self) -> Option<f64> {
Expand Down

0 comments on commit 6bc125a

Please sign in to comment.