mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-13 14:12:31 +00:00
Add date method
Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
parent
ce1f873fee
commit
7f0501d95d
6 changed files with 86 additions and 6 deletions
|
@ -7,6 +7,7 @@ use crate::{
|
||||||
|
|
||||||
pub use ape::Tag as ApeInnerTag;
|
pub use ape::Tag as ApeInnerTag;
|
||||||
|
|
||||||
|
use ape::Item;
|
||||||
use filepath::FilePath;
|
use filepath::FilePath;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -85,6 +86,18 @@ impl AudioTagEdit for ApeTag {
|
||||||
self.remove_key("Artist")
|
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> {
|
fn year(&self) -> Option<i32> {
|
||||||
if let Some(Ok(y)) = self
|
if let Some(Ok(y)) = self
|
||||||
.get_value("Date")
|
.get_value("Date")
|
||||||
|
@ -131,13 +144,16 @@ impl AudioTagEdit for ApeTag {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn album_cover(&self) -> Option<Picture> {
|
fn album_cover(&self) -> Option<Picture> {
|
||||||
// TODO
|
if let Some(val) = self.inner.item("Cover Art (Front)") {
|
||||||
|
return get_picture(val);
|
||||||
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn set_album_cover(&mut self, _cover: Picture) {
|
fn set_album_cover(&mut self, cover: Picture) {
|
||||||
// TODO
|
// TODO
|
||||||
|
self.set_value("Cover Art (Front)", "TODO")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_album_cover(&mut self) {
|
fn remove_album_cover(&mut self) {
|
||||||
self.remove_key("Cover Art (Front)")
|
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 {
|
impl AudioTagWrite for ApeTag {
|
||||||
fn write_to(&self, file: &mut File) -> Result<()> {
|
fn write_to(&self, file: &mut File) -> Result<()> {
|
||||||
// Write only uses paths, this is annoying
|
// Write only uses paths, this is annoying
|
||||||
|
|
|
@ -93,6 +93,33 @@ impl AudioTagEdit for Id3v2Tag {
|
||||||
self.inner.remove_artist()
|
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> {
|
fn year(&self) -> Option<i32> {
|
||||||
self.inner.year()
|
self.inner.year()
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,6 +295,20 @@ impl AudioTagEdit for VorbisTag {
|
||||||
self.inner.remove_key("ARTIST");
|
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> {
|
fn year(&self) -> Option<i32> {
|
||||||
if let Some(Ok(y)) = self
|
if let Some(Ok(y)) = self
|
||||||
.inner
|
.inner
|
||||||
|
|
|
@ -79,8 +79,8 @@ macro_rules! impl_tag {
|
||||||
total_tracks: inp.total_tracks(),
|
total_tracks: inp.total_tracks(),
|
||||||
disc_number: inp.disc_number(),
|
disc_number: inp.disc_number(),
|
||||||
total_discs: inp.total_discs(),
|
total_discs: inp.total_discs(),
|
||||||
comments: None,
|
comments: None, // TODO
|
||||||
date: None, // TODO
|
date: inp.date(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,21 @@ pub trait AudioTagEdit {
|
||||||
/// Removes the artist string
|
/// Removes the artist string
|
||||||
fn remove_artist(&mut self);
|
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
|
/// Returns the track year
|
||||||
fn year(&self) -> Option<i32>;
|
fn year(&self) -> Option<i32>;
|
||||||
/// Sets the track year
|
/// Sets the track year
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub struct AnyTag<'a> {
|
||||||
/// The track year
|
/// The track year
|
||||||
pub year: Option<i32>,
|
pub year: Option<i32>,
|
||||||
/// The track date
|
/// The track date
|
||||||
pub date: Option<&'a str>,
|
pub date: Option<String>,
|
||||||
/// The track number
|
/// The track number
|
||||||
pub track_number: Option<u32>,
|
pub track_number: Option<u32>,
|
||||||
/// The total tracks
|
/// The total tracks
|
||||||
|
|
Loading…
Reference in a new issue