mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
wip: original_tag/modified_tag
This commit is contained in:
parent
c55f50162d
commit
af8f08c765
1 changed files with 106 additions and 50 deletions
|
|
@ -12,28 +12,28 @@ use lofty::{
|
||||||
|
|
||||||
pub enum Metadata {
|
pub enum Metadata {
|
||||||
Directory {
|
Directory {
|
||||||
hash_file: Option<()>,
|
hash_file: Option<()>,
|
||||||
catalog_file: Option<()>,
|
catalog_file: Option<()>,
|
||||||
artist_file: Option<()>,
|
artist_file: Option<()>,
|
||||||
release_file: Option<()>,
|
release_file: Option<()>,
|
||||||
},
|
},
|
||||||
Music {
|
Music {
|
||||||
invalid: bool,
|
invalid: bool,
|
||||||
hash: Arc<str>,
|
hash: Arc<str>,
|
||||||
size: Arc<str>,
|
size: Arc<str>,
|
||||||
tag: Option<Arc<Tag>>,
|
original_tag: Option<Arc<Tag>>,
|
||||||
new_tag: Option<Arc<Tag>>,
|
modified_tag: Option<Arc<Tag>>,
|
||||||
},
|
},
|
||||||
Image {
|
Image {
|
||||||
invalid: bool,
|
invalid: bool,
|
||||||
hash: Arc<str>,
|
hash: Arc<str>,
|
||||||
size: Arc<str>,
|
size: Arc<str>,
|
||||||
title: Option<String>,
|
title: Option<String>,
|
||||||
author: Option<String>,
|
author: Option<String>,
|
||||||
},
|
},
|
||||||
Unknown {
|
Unknown {
|
||||||
hash: Arc<str>,
|
hash: Arc<str>,
|
||||||
size: Arc<str>,
|
size: Arc<str>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,9 +55,9 @@ impl Metadata {
|
||||||
Ok(Self::Music {
|
Ok(Self::Music {
|
||||||
hash,
|
hash,
|
||||||
size: format!("{:#>8.2}", size).into(),
|
size: format!("{:#>8.2}", size).into(),
|
||||||
tag: tag.map(|t|t.clone().into()),
|
|
||||||
new_tag: tag.map(|t|t.clone().into()),
|
|
||||||
invalid: false,
|
invalid: false,
|
||||||
|
original_tag: tag.map(|t|t.clone().into()),
|
||||||
|
modified_tag: tag.map(|t|t.clone().into()),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Self::new_fallback(path)
|
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) => {
|
(string: $get:ident $set:ident $key:expr) => {
|
||||||
impl Metadata {
|
impl Metadata {
|
||||||
pub fn $get (&self) -> Option<Arc<str>> {
|
pub fn $get (&self) -> Option<Arc<str>> {
|
||||||
if let Metadata::Music { tag: Some(tag), .. } = self {
|
if let Metadata::Music { original_tag, modified_tag, .. } = self {
|
||||||
return tag.$get().map(|t|t.into())
|
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
|
None
|
||||||
}
|
}
|
||||||
pub fn $set (&mut self, value: &impl AsRef<str>) -> Option<TagItem> {
|
pub fn $set (&mut self, value: &impl AsRef<str>) -> Option<TagItem> {
|
||||||
if let Metadata::Music { tag: Some(old_tag), new_tag, .. } = self {
|
if let Metadata::Music { original_tag, modified_tag, .. } = self {
|
||||||
if old_tag.$get().is_none() {
|
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() {
|
//let value = value.as_ref().trim();
|
||||||
if old_value != value.as_ref() {
|
//if value.len() > 0 {
|
||||||
}
|
//if old_tag.$get().is_none() {
|
||||||
}
|
//old_tag.$set(value)
|
||||||
}
|
//}
|
||||||
//match self {
|
//if let Some(old_value) = old_tag.$get() {
|
||||||
//Metadata::Music { tag: Some(tag), new_tag, .. } => {
|
//}
|
||||||
|
//} else {
|
||||||
//}
|
//}
|
||||||
//_ => None
|
}
|
||||||
//}
|
|
||||||
//let old_tag = &mut self.tag;
|
|
||||||
//let new_tag = &mut self.new_tag;
|
|
||||||
//if let Metadata::Music { tag: Some(tag), .. } = self
|
//if let Metadata::Music { tag: Some(tag), .. } = self
|
||||||
//&& Some(value.as_ref()) != tag.$get().as_deref()
|
//&& Some(value.as_ref()) != tag.$get().as_deref()
|
||||||
//{
|
//{
|
||||||
|
|
@ -161,24 +185,57 @@ macro_rules! metadata_field {
|
||||||
(number: $get:ident $set:ident $key:expr) => {
|
(number: $get:ident $set:ident $key:expr) => {
|
||||||
impl Metadata {
|
impl Metadata {
|
||||||
pub fn $get (&self) -> Option<Arc<str>> {
|
pub fn $get (&self) -> Option<Arc<str>> {
|
||||||
if let Metadata::Music { tag: Some(tag), .. } = self {
|
if let Metadata::Music { original_tag, modified_tag, .. } = self {
|
||||||
return tag.$get().map(|t|format!("{t}").into())
|
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
|
None
|
||||||
}
|
}
|
||||||
pub fn $set (&mut self, value: &impl AsRef<str>) -> Option<TagItem> {
|
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 { original_tag, modified_tag, .. } = self {
|
||||||
if let Metadata::Music { tag: Some(old_tag), new_tag, .. } = self {
|
let value = value.as_ref().trim();
|
||||||
if old_tag.$get().is_none() {
|
match (value.len(), original_tag, modified_tag) {
|
||||||
}
|
(0, Some(old_tag), Some(new_tag)) => {
|
||||||
if let Some(old_value) = old_tag.$get() {
|
},
|
||||||
if old_value != value {
|
(_, 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;
|
None
|
||||||
//let new_tag = &mut self.new_tag;
|
//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
|
//if let Metadata::Music { tag: Some(tag), .. } = self
|
||||||
//&& let Ok(value) = value.as_ref().trim().parse::<u32>()
|
//&& let Ok(value) = value.as_ref().trim().parse::<u32>()
|
||||||
//&& Some(value) != *$field
|
//&& Some(value) != *$field
|
||||||
|
|
@ -186,14 +243,13 @@ macro_rules! metadata_field {
|
||||||
//*$field = Some(value);
|
//*$field = Some(value);
|
||||||
//return Some(TagItem::new($key, ItemValue::Text(format!("{value}"))))
|
//return Some(TagItem::new($key, ItemValue::Text(format!("{value}"))))
|
||||||
//}
|
//}
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata_field!(string: artist set_artist ItemKey::TrackArtist);
|
music_tag_field!(string: artist set_artist ItemKey::TrackArtist);
|
||||||
metadata_field!(number: year set_year ItemKey::Year);
|
music_tag_field!(number: year set_year ItemKey::Year);
|
||||||
metadata_field!(string: album set_album ItemKey::AlbumTitle);
|
music_tag_field!(string: album set_album ItemKey::AlbumTitle);
|
||||||
metadata_field!(number: track set_track ItemKey::TrackNumber);
|
music_tag_field!(number: track set_track ItemKey::TrackNumber);
|
||||||
metadata_field!(string: title set_title ItemKey::TrackTitle);
|
music_tag_field!(string: title set_title ItemKey::TrackTitle);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue