mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-12 13:42:34 +00:00
Start using new get_set_methods macro
Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
parent
3b8e08ace0
commit
e1b7dce2cb
5 changed files with 24 additions and 201 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -332,9 +332,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "lofty_attr"
|
||||
version = "0.1.6"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33676f2eaa85ffe8ee898ca1e5f0e318686db1a16df9738ca83aaefca98d37fa"
|
||||
checksum = "9557c7fac9fc69a3fe44f742b9a3f8fe0bef84a5c80309a1a73a831f146ce3ad"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
|
|
|
@ -28,7 +28,7 @@ base64 = "0.13.0"
|
|||
byteorder = "1.4.3"
|
||||
cfg-if = "1.0.0"
|
||||
|
||||
lofty_attr = "0.1.6"
|
||||
lofty_attr = "0.1.7"
|
||||
|
||||
[features]
|
||||
default = ["all_tags"]
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::io::{Read, Seek};
|
|||
|
||||
use ape::Item;
|
||||
pub use ape::Tag as ApeInnerTag;
|
||||
use lofty_attr::impl_tag;
|
||||
use lofty_attr::{get_set_methods, impl_tag};
|
||||
|
||||
#[impl_tag(ApeInnerTag, TagType::Ape)]
|
||||
pub struct ApeTag;
|
||||
|
@ -67,36 +67,24 @@ impl ApeTag {
|
|||
}
|
||||
|
||||
impl AudioTagEdit for ApeTag {
|
||||
fn title(&self) -> Option<&str> {
|
||||
self.get_value("Title")
|
||||
}
|
||||
fn set_title(&mut self, title: &str) {
|
||||
self.set_value("Title", title)
|
||||
}
|
||||
fn remove_title(&mut self) {
|
||||
self.remove_key("Title")
|
||||
}
|
||||
get_set_methods!(title, "Title");
|
||||
get_set_methods!(artist, "Artist");
|
||||
get_set_methods!(copyright, "Copyright");
|
||||
get_set_methods!(genre, "Genre");
|
||||
get_set_methods!(lyrics, "Lyrics");
|
||||
get_set_methods!(lyricist, "Lyricist");
|
||||
get_set_methods!(composer, "Composer");
|
||||
get_set_methods!(album_title, "Album");
|
||||
|
||||
fn artist(&self) -> Option<&str> {
|
||||
self.get_value("Artist")
|
||||
}
|
||||
|
||||
fn set_artist(&mut self, artist: &str) {
|
||||
self.set_value("Artist", artist)
|
||||
}
|
||||
|
||||
fn remove_artist(&mut self) {
|
||||
self.remove_key("Artist")
|
||||
}
|
||||
// Album artists aren't standard?
|
||||
get_set_methods!(album_artist, "Album 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")
|
||||
}
|
||||
|
@ -115,36 +103,6 @@ impl AudioTagEdit for ApeTag {
|
|||
self.remove_key("Year")
|
||||
}
|
||||
|
||||
fn copyright(&self) -> Option<&str> {
|
||||
self.get_value("Copyright")
|
||||
}
|
||||
fn set_copyright(&mut self, copyright: &str) {
|
||||
self.set_value("Copyright", copyright)
|
||||
}
|
||||
fn remove_copyright(&mut self) {
|
||||
self.remove_key("Copyright")
|
||||
}
|
||||
|
||||
fn genre(&self) -> Option<&str> {
|
||||
self.get_value("Genre")
|
||||
}
|
||||
fn set_genre(&mut self, genre: &str) {
|
||||
self.set_value("Genre", genre)
|
||||
}
|
||||
fn remove_genre(&mut self) {
|
||||
self.remove_key("Genre")
|
||||
}
|
||||
|
||||
fn lyrics(&self) -> Option<&str> {
|
||||
self.get_value("Lyrics")
|
||||
}
|
||||
fn set_lyrics(&mut self, lyrics: &str) {
|
||||
self.set_value("Lyrics", lyrics)
|
||||
}
|
||||
fn remove_lyrics(&mut self) {
|
||||
self.remove_key("Lyrics")
|
||||
}
|
||||
|
||||
fn bpm(&self) -> Option<u16> {
|
||||
if let Some(bpm) = self.get_value("BPM") {
|
||||
return bpm.parse::<u16>().ok();
|
||||
|
@ -159,49 +117,6 @@ impl AudioTagEdit for ApeTag {
|
|||
self.remove_key("BPM")
|
||||
}
|
||||
|
||||
fn lyricist(&self) -> Option<&str> {
|
||||
self.get_value("Lyricist")
|
||||
}
|
||||
fn set_lyricist(&mut self, lyricist: &str) {
|
||||
self.set_value("Lyricist", lyricist)
|
||||
}
|
||||
fn remove_lyricist(&mut self) {
|
||||
self.remove_key("Lyricist")
|
||||
}
|
||||
|
||||
fn composer(&self) -> Option<&str> {
|
||||
self.get_value("Composer")
|
||||
}
|
||||
fn set_composer(&mut self, composer: &str) {
|
||||
self.set_value("Composer", composer)
|
||||
}
|
||||
fn remove_composer(&mut self) {
|
||||
self.remove_key("Composer")
|
||||
}
|
||||
|
||||
fn album_title(&self) -> Option<&str> {
|
||||
self.get_value("Album")
|
||||
}
|
||||
fn set_album_title(&mut self, album_title: &str) {
|
||||
self.set_value("Album", album_title)
|
||||
}
|
||||
fn remove_album_title(&mut self) {
|
||||
self.remove_key("Album")
|
||||
}
|
||||
|
||||
// Album artists aren't standard?
|
||||
fn album_artist(&self) -> Option<&str> {
|
||||
self.get_value("Album artist")
|
||||
}
|
||||
|
||||
fn set_album_artist(&mut self, artists: &str) {
|
||||
self.set_value("Album artist", artists)
|
||||
}
|
||||
|
||||
fn remove_album_artist(&mut self) {
|
||||
self.remove_key("Album artist")
|
||||
}
|
||||
|
||||
fn front_cover(&self) -> Option<Picture> {
|
||||
if let Some(val) = self.inner.item("Cover Art (Front)") {
|
||||
return self.get_picture(val);
|
||||
|
@ -209,7 +124,6 @@ impl AudioTagEdit for ApeTag {
|
|||
|
||||
None
|
||||
}
|
||||
|
||||
fn set_front_cover(&mut self, cover: Picture) {
|
||||
self.remove_front_cover();
|
||||
|
||||
|
@ -217,7 +131,6 @@ impl AudioTagEdit for ApeTag {
|
|||
self.inner.set_item(item)
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_front_cover(&mut self) {
|
||||
self.remove_key("Cover Art (Front)")
|
||||
}
|
||||
|
@ -229,7 +142,6 @@ impl AudioTagEdit for ApeTag {
|
|||
|
||||
None
|
||||
}
|
||||
|
||||
fn set_back_cover(&mut self, cover: Picture) {
|
||||
self.remove_back_cover();
|
||||
|
||||
|
@ -237,7 +149,6 @@ impl AudioTagEdit for ApeTag {
|
|||
self.inner.set_item(item)
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_back_cover(&mut self) {
|
||||
self.remove_key("Cover Art (Back)")
|
||||
}
|
||||
|
|
|
@ -94,11 +94,9 @@ impl AudioTagEdit for Id3v2Tag {
|
|||
fn artist(&self) -> Option<&str> {
|
||||
self.inner.artist()
|
||||
}
|
||||
|
||||
fn set_artist(&mut self, artist: &str) {
|
||||
self.inner.set_artist(artist)
|
||||
}
|
||||
|
||||
fn remove_artist(&mut self) {
|
||||
self.inner.remove_artist()
|
||||
}
|
||||
|
@ -120,13 +118,11 @@ impl AudioTagEdit for Id3v2Tag {
|
|||
|
||||
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();
|
||||
|
@ -247,7 +243,6 @@ impl AudioTagEdit for Id3v2Tag {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn set_front_cover(&mut self, cover: Picture) {
|
||||
self.remove_front_cover();
|
||||
|
||||
|
@ -255,7 +250,6 @@ impl AudioTagEdit for Id3v2Tag {
|
|||
self.inner.add_picture(pic)
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_front_cover(&mut self) {
|
||||
self.inner
|
||||
.remove_picture_by_type(id3::frame::PictureType::CoverFront);
|
||||
|
@ -278,7 +272,6 @@ impl AudioTagEdit for Id3v2Tag {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn set_back_cover(&mut self, cover: Picture) {
|
||||
self.remove_back_cover();
|
||||
|
||||
|
@ -286,7 +279,6 @@ impl AudioTagEdit for Id3v2Tag {
|
|||
self.inner.add_picture(pic)
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_back_cover(&mut self) {
|
||||
self.inner
|
||||
.remove_picture_by_type(id3::frame::PictureType::CoverBack);
|
||||
|
|
|
@ -20,7 +20,7 @@ use std::convert::{TryFrom, TryInto};
|
|||
use std::fs::File;
|
||||
use std::io::{Read, Seek, SeekFrom};
|
||||
|
||||
use lofty_attr::impl_tag;
|
||||
use lofty_attr::{get_set_methods, impl_tag};
|
||||
|
||||
struct OggInnerTag {
|
||||
vendor: String,
|
||||
|
@ -183,25 +183,15 @@ impl OggTag {
|
|||
}
|
||||
|
||||
impl AudioTagEdit for OggTag {
|
||||
fn title(&self) -> Option<&str> {
|
||||
self.get_value("TITLE")
|
||||
}
|
||||
fn set_title(&mut self, title: &str) {
|
||||
self.set_value("TITLE", title);
|
||||
}
|
||||
fn remove_title(&mut self) {
|
||||
self.remove_key("TITLE");
|
||||
}
|
||||
|
||||
fn artist(&self) -> Option<&str> {
|
||||
self.get_value("ARTIST")
|
||||
}
|
||||
fn set_artist(&mut self, artist: &str) {
|
||||
self.set_value("ARTIST", artist)
|
||||
}
|
||||
fn remove_artist(&mut self) {
|
||||
self.remove_key("ARTIST");
|
||||
}
|
||||
get_set_methods!(title, "TITLE");
|
||||
get_set_methods!(artist, "ARTIST");
|
||||
get_set_methods!(copyright, "COPYRIGHT");
|
||||
get_set_methods!(genre, "GENRE");
|
||||
get_set_methods!(lyrics, "LYRICS");
|
||||
get_set_methods!(lyricist, "LYRICIST");
|
||||
get_set_methods!(composer, "COMPOSER");
|
||||
get_set_methods!(album_title, "ALBUM");
|
||||
get_set_methods!(album_artist, "ALBUMARTIST");
|
||||
|
||||
fn date(&self) -> Option<String> {
|
||||
self.get_value("DATE").map(std::string::ToString::to_string)
|
||||
|
@ -227,56 +217,6 @@ impl AudioTagEdit for OggTag {
|
|||
self.remove_key("YEAR");
|
||||
}
|
||||
|
||||
fn copyright(&self) -> Option<&str> {
|
||||
self.get_value("COPYRIGHT")
|
||||
}
|
||||
fn set_copyright(&mut self, copyright: &str) {
|
||||
self.set_value("COPYRIGHT", copyright)
|
||||
}
|
||||
fn remove_copyright(&mut self) {
|
||||
self.remove_key("COPYRIGHT")
|
||||
}
|
||||
|
||||
fn genre(&self) -> Option<&str> {
|
||||
self.get_value("GENRE")
|
||||
}
|
||||
fn set_genre(&mut self, genre: &str) {
|
||||
self.set_value("GENRE", genre)
|
||||
}
|
||||
fn remove_genre(&mut self) {
|
||||
self.remove_key("GENRE")
|
||||
}
|
||||
|
||||
fn lyrics(&self) -> Option<&str> {
|
||||
self.get_value("LYRICS")
|
||||
}
|
||||
fn set_lyrics(&mut self, lyrics: &str) {
|
||||
self.set_value("LYRICS", lyrics)
|
||||
}
|
||||
fn remove_lyrics(&mut self) {
|
||||
self.remove_key("LYRICS")
|
||||
}
|
||||
|
||||
fn lyricist(&self) -> Option<&str> {
|
||||
self.get_value("LYRICIST")
|
||||
}
|
||||
fn set_lyricist(&mut self, lyricist: &str) {
|
||||
self.set_value("LYRICIST", lyricist)
|
||||
}
|
||||
fn remove_lyricist(&mut self) {
|
||||
self.remove_key("LYRICIST")
|
||||
}
|
||||
|
||||
fn composer(&self) -> Option<&str> {
|
||||
self.get_value("COMPOSER")
|
||||
}
|
||||
fn set_composer(&mut self, composer: &str) {
|
||||
self.set_value("COMPOSER", composer)
|
||||
}
|
||||
fn remove_composer(&mut self) {
|
||||
self.remove_key("COMPOSER")
|
||||
}
|
||||
|
||||
fn bpm(&self) -> Option<u16> {
|
||||
if let Some(bpm) = self.get_value("BPM") {
|
||||
return bpm.parse::<u16>().ok();
|
||||
|
@ -291,26 +231,6 @@ impl AudioTagEdit for OggTag {
|
|||
self.remove_key("BPM")
|
||||
}
|
||||
|
||||
fn album_title(&self) -> Option<&str> {
|
||||
self.get_value("ALBUM")
|
||||
}
|
||||
fn set_album_title(&mut self, title: &str) {
|
||||
self.set_value("ALBUM", title)
|
||||
}
|
||||
fn remove_album_title(&mut self) {
|
||||
self.remove_key("ALBUM");
|
||||
}
|
||||
|
||||
fn album_artist(&self) -> Option<&str> {
|
||||
self.get_value("ALBUMARTIST")
|
||||
}
|
||||
fn set_album_artist(&mut self, album_artist: &str) {
|
||||
self.set_value("ALBUMARTIST", album_artist)
|
||||
}
|
||||
fn remove_album_artist(&mut self) {
|
||||
self.remove_key("ALBUMARTIST");
|
||||
}
|
||||
|
||||
fn front_cover(&self) -> Option<Picture> {
|
||||
if let Some(p) = &self.inner.pictures {
|
||||
return p
|
||||
|
|
Loading…
Reference in a new issue