wip: original_tag/modified_tag

This commit is contained in:
🪞👃🪞 2025-04-05 07:29:08 +03:00
parent c55f50162d
commit af8f08c765

View file

@ -12,28 +12,28 @@ use lofty::{
pub enum Metadata {
Directory {
hash_file: Option<()>,
hash_file: Option<()>,
catalog_file: Option<()>,
artist_file: Option<()>,
artist_file: Option<()>,
release_file: Option<()>,
},
Music {
invalid: bool,
hash: Arc<str>,
size: Arc<str>,
tag: Option<Arc<Tag>>,
new_tag: Option<Arc<Tag>>,
invalid: bool,
hash: Arc<str>,
size: Arc<str>,
original_tag: Option<Arc<Tag>>,
modified_tag: Option<Arc<Tag>>,
},
Image {
invalid: bool,
hash: Arc<str>,
size: Arc<str>,
title: Option<String>,
author: Option<String>,
invalid: bool,
hash: Arc<str>,
size: Arc<str>,
title: Option<String>,
author: Option<String>,
},
Unknown {
hash: Arc<str>,
size: Arc<str>,
hash: Arc<str>,
size: Arc<str>,
}
}
@ -55,9 +55,9 @@ impl Metadata {
Ok(Self::Music {
hash,
size: format!("{:#>8.2}", size).into(),
tag: tag.map(|t|t.clone().into()),
new_tag: tag.map(|t|t.clone().into()),
invalid: false,
original_tag: tag.map(|t|t.clone().into()),
modified_tag: tag.map(|t|t.clone().into()),
})
} else {
Self::new_fallback(path)
@ -123,31 +123,55 @@ impl Metadata {
}
}
macro_rules! metadata_field {
macro_rules! music_tag_field {
(string: $get:ident $set:ident $key:expr) => {
impl Metadata {
pub fn $get (&self) -> Option<Arc<str>> {
if let Metadata::Music { tag: Some(tag), .. } = self {
return tag.$get().map(|t|t.into())
if let Metadata::Music { original_tag, modified_tag, .. } = self {
return modified_tag
.as_ref()
.map(|tag|tag.$get().map(|t|t.into()))
.flatten()
.or_else(||original_tag
.as_ref()
.map(|tag|tag.$get().map(|t|t.into()))
.flatten())
}
None
}
pub fn $set (&mut self, value: &impl AsRef<str>) -> Option<TagItem> {
if let Metadata::Music { tag: Some(old_tag), new_tag, .. } = self {
if old_tag.$get().is_none() {
if let Metadata::Music { original_tag, modified_tag, .. } = self {
let value = value.as_ref().trim();
match (value.len(), original_tag, modified_tag) {
(0, Some(old_tag), Some(new_tag)) => {
},
(_, Some(old_tag), Some(new_tag)) => {
},
(0, Some(old_tag), None) => {
},
(_, Some(old_tag), None) => {
},
(0, None, Some(new_tag)) => {
},
(_, None, Some(new_tag)) => {
},
(0, None, None) => {
unimplemented!("specifying new tag type")
},
(_, None, None) => {
unimplemented!("specifying new tag type")
},
}
if let Some(old_value) = old_tag.$get() {
if old_value != value.as_ref() {
}
}
}
//match self {
//Metadata::Music { tag: Some(tag), new_tag, .. } => {
//let value = value.as_ref().trim();
//if value.len() > 0 {
//if old_tag.$get().is_none() {
//old_tag.$set(value)
//}
//if let Some(old_value) = old_tag.$get() {
//}
//} else {
//}
//_ => None
//}
//let old_tag = &mut self.tag;
//let new_tag = &mut self.new_tag;
}
//if let Metadata::Music { tag: Some(tag), .. } = self
//&& Some(value.as_ref()) != tag.$get().as_deref()
//{
@ -161,24 +185,57 @@ macro_rules! metadata_field {
(number: $get:ident $set:ident $key:expr) => {
impl Metadata {
pub fn $get (&self) -> Option<Arc<str>> {
if let Metadata::Music { tag: Some(tag), .. } = self {
return tag.$get().map(|t|format!("{t}").into())
if let Metadata::Music { original_tag, modified_tag, .. } = self {
return modified_tag
.as_ref()
.map(|tag|tag.$get().map(|t|format!("{t}").into()))
.flatten()
.or_else(||original_tag
.as_ref()
.map(|tag|tag.$get().map(|t|format!("{t}").into()))
.flatten())
}
None
}
pub fn $set (&mut self, value: &impl AsRef<str>) -> Option<TagItem> {
if let Ok(value) = value.as_ref().trim().parse::<u32>() {
if let Metadata::Music { tag: Some(old_tag), new_tag, .. } = self {
if old_tag.$get().is_none() {
}
if let Some(old_value) = old_tag.$get() {
if old_value != value {
}
}
if let Metadata::Music { original_tag, modified_tag, .. } = self {
let value = value.as_ref().trim();
match (value.len(), original_tag, modified_tag) {
(0, Some(old_tag), Some(new_tag)) => {
},
(_, Some(old_tag), Some(new_tag)) => {
},
(0, Some(old_tag), None) => {
},
(_, Some(old_tag), None) => {
},
(0, None, Some(new_tag)) => {
},
(_, None, Some(new_tag)) => {
},
(0, None, None) => {
unimplemented!("specifying new tag type")
},
(_, None, None) => {
unimplemented!("specifying new tag type")
},
}
}
//let old_tag = &mut self.tag;
//let new_tag = &mut self.new_tag;
None
//let value = value.as_ref().trim();
//if value.len() > 0 {
//if let Ok(value) = value.parse::<u32>() {
//if let Metadata::Music {
//tag: Some(old_tag), new_tag: Some(new_tag), ..
//} = self {
//if old_tag.$get().is_none() {
//}
//if let Some(old_value) = old_tag.$get() {
//}
//}
//}
//} else {
//}
//if let Metadata::Music { tag: Some(tag), .. } = self
//&& let Ok(value) = value.as_ref().trim().parse::<u32>()
//&& Some(value) != *$field
@ -186,14 +243,13 @@ macro_rules! metadata_field {
//*$field = Some(value);
//return Some(TagItem::new($key, ItemValue::Text(format!("{value}"))))
//}
None
}
}
};
}
metadata_field!(string: artist set_artist ItemKey::TrackArtist);
metadata_field!(number: year set_year ItemKey::Year);
metadata_field!(string: album set_album ItemKey::AlbumTitle);
metadata_field!(number: track set_track ItemKey::TrackNumber);
metadata_field!(string: title set_title ItemKey::TrackTitle);
music_tag_field!(string: artist set_artist ItemKey::TrackArtist);
music_tag_field!(number: year set_year ItemKey::Year);
music_tag_field!(string: album set_album ItemKey::AlbumTitle);
music_tag_field!(number: track set_track ItemKey::TrackNumber);
music_tag_field!(string: title set_title ItemKey::TrackTitle);