mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-11-10 06:34:18 +00:00
Add getters/setters for common tag items
This commit is contained in:
parent
e893670f35
commit
dab1fcb01b
2 changed files with 38 additions and 2 deletions
|
@ -18,7 +18,10 @@ ogg_pager = { version = "0.1.7", optional = true }
|
|||
# Mp4
|
||||
mp4ameta = {version = "0.11.0", optional = true}
|
||||
# Case insensitive keys (APE/FLAC/Opus/Vorbis)
|
||||
unicase = { version = "2.6.0", optional = true }
|
||||
unicase = { version = "2.6.0"}
|
||||
|
||||
# Quick string accessor methods for Tag
|
||||
paste = { version = "1.0.5", optional = true }
|
||||
|
||||
# Errors
|
||||
thiserror = "1.0.26"
|
||||
|
@ -28,7 +31,7 @@ byteorder = "1.4.3"
|
|||
cfg-if = "1.0.0"
|
||||
|
||||
[features]
|
||||
default = ["mp4_atoms", "vorbis_comments", "ape", "id3v1", "id3v2", "aiff_text_chunks", "riff_info_list"]
|
||||
default = ["mp4_atoms", "vorbis_comments", "ape", "id3v1", "id3v2", "aiff_text_chunks", "riff_info_list", "quick_tag_accessors"]
|
||||
mp4_atoms = []
|
||||
vorbis_comments = ["ogg_pager"]
|
||||
ape = []
|
||||
|
@ -36,6 +39,7 @@ id3v1 = []
|
|||
id3v2 = []
|
||||
aiff_text_chunks = []
|
||||
riff_info_list = []
|
||||
quick_tag_accessors = ["paste"]
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { version = "0.3", features = ["html_reports"] }
|
||||
|
|
|
@ -2,6 +2,35 @@ use super::item::ItemKey;
|
|||
use super::picture::{Picture, PictureType};
|
||||
use crate::logic::id3::v2::Id3v2Version;
|
||||
|
||||
#[cfg(feature = "quick_tag_accessors")]
|
||||
use paste::paste;
|
||||
|
||||
#[cfg(feature = "quick_tag_accessors")]
|
||||
macro_rules! common_items {
|
||||
($($item_key:ident => $name:tt),+) => {
|
||||
paste! {
|
||||
impl Tag {
|
||||
$(
|
||||
#[doc = "Gets the " $name]
|
||||
pub fn $name(&self) -> Option<&str> {
|
||||
self.get_item_ref(&ItemKey::$item_key).map(|i| i.value())
|
||||
}
|
||||
|
||||
#[doc = "Removes the " $name]
|
||||
pub fn [<remove_ $name>](&mut self) {
|
||||
self.retain(|i| i.item_key != ItemKey::$item_key)
|
||||
}
|
||||
|
||||
#[doc = "Sets the " $name]
|
||||
pub fn [<set_ $name>](&mut self, value: String) {
|
||||
self.insert_item(TagItem::new(ItemKey::$item_key, ItemValue::Text(value)));
|
||||
}
|
||||
)+
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a tag item (key/value)
|
||||
pub struct TagItem {
|
||||
item_key: ItemKey,
|
||||
|
@ -191,6 +220,9 @@ impl Tag {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "quick_tag_accessors")]
|
||||
common_items!(Artist => artist, Title => title, AlbumTitle => album_title, AlbumArtist => album_artist);
|
||||
|
||||
/// The tag's format
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum TagType {
|
||||
|
|
Loading…
Reference in a new issue