mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
wip: get data directly from tag
This commit is contained in:
parent
300cc8864a
commit
c3091dab7f
1 changed files with 38 additions and 35 deletions
|
|
@ -15,7 +15,7 @@ pub enum Metadata {
|
||||||
invalid: bool,
|
invalid: bool,
|
||||||
hash: Arc<str>,
|
hash: Arc<str>,
|
||||||
size: Arc<str>,
|
size: Arc<str>,
|
||||||
tag: Arc<Option<Tag>>,
|
tag: Option<Arc<Tag>>,
|
||||||
artist: Option<Arc<str>>,
|
artist: Option<Arc<str>>,
|
||||||
album: Option<Arc<str>>,
|
album: Option<Arc<str>>,
|
||||||
track: Option<u32>,
|
track: Option<u32>,
|
||||||
|
|
@ -66,7 +66,7 @@ impl Metadata {
|
||||||
key: None,
|
key: None,
|
||||||
bpm: None,
|
bpm: None,
|
||||||
invalid: false,
|
invalid: false,
|
||||||
tag: tag.map(|t|t.clone()).into(),
|
tag: tag.map(|t|t.clone().into()),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Self::new_fallback(path)
|
Self::new_fallback(path)
|
||||||
|
|
@ -130,38 +130,37 @@ impl Metadata {
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn artist (&self) -> Option<Arc<str>> {
|
}
|
||||||
match self {
|
|
||||||
Metadata::Music { artist, .. } => artist.clone(),
|
macro_rules! metadata_get_string {
|
||||||
_ => None
|
($name:ident) => {
|
||||||
}
|
impl Metadata {
|
||||||
}
|
pub fn $name (&self) -> Option<Arc<str>> {
|
||||||
pub fn year (&self) -> Option<Arc<str>> {
|
match self {
|
||||||
match self {
|
Metadata::Music { tag: Some(tag), .. } =>
|
||||||
Metadata::Music { year, .. } => year.map(|t|format!("{t}").into()).clone(),
|
tag.$name().map(|t|t.into()),
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn album (&self) -> Option<Arc<str>> {
|
|
||||||
match self {
|
|
||||||
Metadata::Music { album, .. } => album.clone(),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn title (&self) -> Option<Arc<str>> {
|
|
||||||
match self {
|
|
||||||
Metadata::Music { title, .. } => title.clone(),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn track (&self) -> Option<Arc<str>> {
|
|
||||||
match self {
|
|
||||||
Metadata::Music { track, .. } => track.map(|t|format!("{t}").into()).clone(),
|
|
||||||
_ => None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! metadata_get_number {
|
||||||
|
($name:ident) => {
|
||||||
|
impl Metadata {
|
||||||
|
pub fn $name (&self) -> Option<Arc<str>> {
|
||||||
|
match self {
|
||||||
|
Metadata::Music { tag: Some(tag), .. } =>
|
||||||
|
tag.$name().map(|t|format!("{t}").into()),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
macro_rules! metadata_set_string {
|
macro_rules! metadata_set_string {
|
||||||
($name:ident, $field:ident, $key:expr) => {
|
($name:ident, $field:ident, $key:expr) => {
|
||||||
impl Metadata {
|
impl Metadata {
|
||||||
|
|
@ -195,8 +194,12 @@ macro_rules! metadata_set_number {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata_set_string!(set_artist, artist, ItemKey::TrackArtist);
|
metadata_get_string!(artist); metadata_set_string!(set_artist, artist, ItemKey::TrackArtist);
|
||||||
metadata_set_number!(set_year, year, ItemKey::Year);
|
|
||||||
metadata_set_string!(set_album, album, ItemKey::AlbumTitle);
|
metadata_get_number!(year); metadata_set_number!(set_year, year, ItemKey::Year);
|
||||||
metadata_set_number!(set_track, track, ItemKey::TrackNumber);
|
|
||||||
metadata_set_string!(set_title, title, ItemKey::TrackTitle);
|
metadata_get_string!(album); metadata_set_string!(set_album, album, ItemKey::AlbumTitle);
|
||||||
|
|
||||||
|
metadata_get_number!(track); metadata_set_number!(set_track, track, ItemKey::TrackNumber);
|
||||||
|
|
||||||
|
metadata_get_string!(title); metadata_set_string!(set_title, title, ItemKey::TrackTitle);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue