Add date method

Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
Serial 2021-05-16 02:41:16 -04:00
parent ce1f873fee
commit 7f0501d95d
6 changed files with 86 additions and 6 deletions

View file

@ -7,6 +7,7 @@ use crate::{
pub use ape::Tag as ApeInnerTag;
use ape::Item;
use filepath::FilePath;
use std::fs::File;
use std::path::Path;
@ -85,6 +86,18 @@ impl AudioTagEdit for ApeTag {
self.remove_key("Artist")
}
fn date(&self) -> Option<String> {
self.get_value("Date").map(std::string::ToString::to_string)
}
fn set_date(&mut self, date: &str) {
self.set_value("Date", date)
}
fn remove_date(&mut self) {
self.remove_key("Date")
}
fn year(&self) -> Option<i32> {
if let Some(Ok(y)) = self
.get_value("Date")
@ -131,13 +144,16 @@ impl AudioTagEdit for ApeTag {
}
fn album_cover(&self) -> Option<Picture> {
// TODO
if let Some(val) = self.inner.item("Cover Art (Front)") {
return get_picture(val);
}
None
}
fn set_album_cover(&mut self, _cover: Picture) {
fn set_album_cover(&mut self, cover: Picture) {
// TODO
self.set_value("Cover Art (Front)", "TODO")
}
fn remove_album_cover(&mut self) {
self.remove_key("Cover Art (Front)")
}
@ -234,6 +250,14 @@ impl AudioTagEdit for ApeTag {
}
}
fn get_picture(item: &Item) -> Option<Picture> {
if let ape::ItemValue::Binary(bin) = &item.value {
// TODO
}
None
}
impl AudioTagWrite for ApeTag {
fn write_to(&self, file: &mut File) -> Result<()> {
// Write only uses paths, this is annoying

View file

@ -93,6 +93,33 @@ impl AudioTagEdit for Id3v2Tag {
self.inner.remove_artist()
}
fn date(&self) -> Option<String> {
if let Some(released) = self.inner.get("TDRL") {
if let id3::frame::Content::Text(date) = &released.content() {
return Some(date.clone());
}
}
if let Some(recorded) = self.inner.get("TRDC") {
if let id3::frame::Content::Text(date) = &recorded.content() {
return Some(date.clone());
}
}
None
}
fn set_date(&mut self, date: &str) {
if let Ok(t) = date.parse::<id3::Timestamp>() {
self.inner.set_date_released(t)
}
}
fn remove_date(&mut self) {
self.inner.remove_date_released();
self.inner.remove_date_recorded();
}
fn year(&self) -> Option<i32> {
self.inner.year()
}

View file

@ -295,6 +295,20 @@ impl AudioTagEdit for VorbisTag {
self.inner.remove_key("ARTIST");
}
fn date(&self) -> Option<String> {
self.inner
.get_value("DATE")
.map(std::string::ToString::to_string)
}
fn set_date(&mut self, date: &str) {
self.inner.set_value("DATE", date)
}
fn remove_date(&mut self) {
self.inner.remove_key("DATE")
}
fn year(&self) -> Option<i32> {
if let Some(Ok(y)) = self
.inner

View file

@ -79,8 +79,8 @@ macro_rules! impl_tag {
total_tracks: inp.total_tracks(),
disc_number: inp.disc_number(),
total_discs: inp.total_discs(),
comments: None,
date: None, // TODO
comments: None, // TODO
date: inp.date(),
}
}
}

View file

@ -30,6 +30,21 @@ pub trait AudioTagEdit {
/// Removes the artist string
fn remove_artist(&mut self);
/// Returns the track date
fn date(&self) -> Option<String> {
self.year().map(|y| y.to_string())
}
/// Sets the track date
fn set_date(&mut self, date: &str) {
if let Ok(d) = date.parse::<i32>() {
self.set_year(d)
}
}
/// Removes the track date
fn remove_date(&mut self) {
self.remove_year()
}
/// Returns the track year
fn year(&self) -> Option<i32>;
/// Sets the track year

View file

@ -14,7 +14,7 @@ pub struct AnyTag<'a> {
/// The track year
pub year: Option<i32>,
/// The track date
pub date: Option<&'a str>,
pub date: Option<String>,
/// The track number
pub track_number: Option<u32>,
/// The total tracks