diff --git a/Cargo.lock b/Cargo.lock index d3f9c3f7..7cc90764 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,7 +11,6 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ape" version = "0.3.0" -source = "git+https://github.com/rossnomann/rust-ape#aa0fac2e7b5e73db2c10251d9c666cc64e1de22f" dependencies = [ "byteorder", ] diff --git a/Cargo.toml b/Cargo.toml index 59c47245..7ce405ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,14 +10,14 @@ keywords = ["tags", "audio", "metadata"] categories = ["accessibility", "multimedia::audio"] [dependencies] -unicase = { version = "2.6.0", optional = true } # Ape -ape = {version = "0.3.0", optional = true, git = "https://github.com/rossnomann/rust-ape"} +ape = {path = "../rust-ape", optional = true} # Id3 id3 = {version = "0.6.4", optional = true} # De/Encoding filepath = { version = "0.1.1", optional = true } # wav/aiff only supports paths for some reason # Ogg ogg_pager = { version = "0.1.6", optional = true } +unicase = { version = "2.6.0", optional = true } # Mp4 mp4ameta = {version = "0.10.2", optional = true} # Flac @@ -37,7 +37,7 @@ format-mp4 = ["mp4ameta"] format-flac = ["metaflac"] format-opus = ["ogg_pager", "unicase"] format-vorbis = ["ogg_pager", "unicase"] -format-ape = ["ape", "unicase"] +format-ape = ["ape"] format-id3 = ["id3", "filepath"] format-aiff = [] format-riff = [] diff --git a/src/components/tags/ape_tag.rs b/src/components/tags/ape_tag.rs index 96fef160..323f45bc 100644 --- a/src/components/tags/ape_tag.rs +++ b/src/components/tags/ape_tag.rs @@ -10,7 +10,6 @@ use std::io::{Read, Seek}; use ape::Item; pub use ape::Tag as ApeInnerTag; use lofty_attr::{get_set_methods, impl_tag}; -use unicase::UniCase; #[impl_tag(ApeInnerTag, TagType::Ape)] pub struct ApeTag; @@ -29,8 +28,8 @@ impl ApeTag { } impl ApeTag { - fn get_value(&self, key: UniCase<&str>) -> Option<&str> { - if let Some(item) = self.inner.item(&key) { + fn get_value(&self, key: &str) -> Option<&str> { + if let Some(item) = self.inner.item(key) { if let ape::ItemValue::Text(val) = &item.value { return Some(&*val); } @@ -50,74 +49,71 @@ impl ApeTag { None } - fn set_value(&mut self, key: UniCase<&str>, val: V) + fn set_value(&mut self, key: &str, val: V) where V: Into, { - let item = ape::Item { + self.inner.set_item(ape::Item { key: key.to_string(), value: ape::ItemValue::Text(val.into()), - }; - - self.inner.set_item(item) + }) } - fn remove_key(&mut self, key: UniCase<&str>) { - let _ = self.inner.remove_item(&key); + fn remove_key(&mut self, key: &str) { + self.inner.remove_item(key); } } impl AudioTagEdit for ApeTag { - get_set_methods!(title, UniCase::new("Title")); - get_set_methods!(artist, UniCase::new("Artist")); - get_set_methods!(copyright, UniCase::new("Copyright")); - get_set_methods!(genre, UniCase::new("Genre")); - get_set_methods!(lyrics, UniCase::new("Lyrics")); - get_set_methods!(lyricist, UniCase::new("Lyricist")); - get_set_methods!(composer, UniCase::new("Composer")); - get_set_methods!(album_title, UniCase::new("Album")); - get_set_methods!(encoder, UniCase::new("EncoderSettings")); + 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!(encoder, "EncoderSettings"); // Album artists aren't standard? - get_set_methods!(album_artist, UniCase::new("AlbumArtist")); + get_set_methods!(album_artist, "AlbumArtist"); fn date(&self) -> Option { - self.get_value(UniCase::from("Date")) - .map(std::string::ToString::to_string) + self.get_value("Date").map(std::string::ToString::to_string) } fn set_date(&mut self, date: &str) { - self.set_value(UniCase::from("Date"), date) + self.set_value("Date", date) } fn remove_date(&mut self) { - self.remove_key(UniCase::from("Date")) + self.remove_key("Date") } fn year(&self) -> Option { - if let Some(Ok(y)) = self.get_value(UniCase::from("Year")).map(str::parse::) { + if let Some(Ok(y)) = self.get_value("Year").map(str::parse::) { return Some(y); } None } fn set_year(&mut self, year: i32) { - self.set_value(UniCase::from("Year"), year.to_string()) + self.set_value("Year", year.to_string()) } fn remove_year(&mut self) { - self.remove_key(UniCase::from("Year")) + self.remove_key("Year") } fn bpm(&self) -> Option { - if let Some(bpm) = self.get_value(UniCase::from("BPM")) { + if let Some(bpm) = self.get_value("BPM") { return bpm.parse::().ok(); } None } fn set_bpm(&mut self, bpm: u16) { - self.set_value(UniCase::from("BPM"), bpm.to_string()) + self.set_value("BPM", bpm.to_string()) } fn remove_bpm(&mut self) { - self.remove_key(UniCase::from("BPM")) + self.remove_key("BPM") } fn front_cover(&self) -> Option { @@ -135,7 +131,7 @@ impl AudioTagEdit for ApeTag { } } fn remove_front_cover(&mut self) { - self.remove_key(UniCase::from("Cover Art (Front)")) + self.remove_key("Cover Art (Front)") } fn back_cover(&self) -> Option { @@ -153,7 +149,7 @@ impl AudioTagEdit for ApeTag { } } fn remove_back_cover(&mut self) { - self.remove_key(UniCase::from("Cover Art (Back)")) + self.remove_key("Cover Art (Back)") } fn pictures(&self) -> Option> { @@ -192,7 +188,7 @@ impl AudioTagEdit for ApeTag { // Track number and total tracks are stored together as num/total? fn track_number(&self) -> Option { - let numbers = self.get_value(UniCase::from("Track")); + let numbers = self.get_value("Track"); if let Some(numbers) = numbers { let split: Vec<&str> = numbers.split('/').collect(); @@ -209,17 +205,17 @@ impl AudioTagEdit for ApeTag { fn set_track_number(&mut self, track: u32) { if let (_, Some(total)) = self.track() { let track_str = format!("{}/{}", track, total); - self.set_value(UniCase::from("Track"), track_str) + self.set_value("Track", track_str) } else { - self.set_value(UniCase::from("Track"), track.to_string()) + self.set_value("Track", track.to_string()) } } fn remove_track_number(&mut self) { - self.remove_key(UniCase::from("Track")) + self.remove_key("Track") } fn total_tracks(&self) -> Option { - let numbers = self.get_value(UniCase::from("Track")); + let numbers = self.get_value("Track"); if let Some(numbers) = numbers { let split: Vec<&str> = numbers.split('/').collect(); @@ -236,21 +232,21 @@ impl AudioTagEdit for ApeTag { fn set_total_tracks(&mut self, total_track: u32) { if let (Some(track_number), _) = self.track() { let track_str = format!("{}/{}", track_number, total_track); - self.set_value(UniCase::from("Track"), track_str) + self.set_value("Track", track_str) } else { - self.set_value(UniCase::from("Track"), format!("0/{}", total_track)) + self.set_value("Track", format!("0/{}", total_track)) } } fn remove_total_tracks(&mut self) { if let (Some(track_number), _) = self.track() { - self.set_value(UniCase::from("Track"), track_number.to_string()) + self.set_value("Track", track_number.to_string()) } else { self.remove_track_number() } } fn disc_number(&self) -> Option { - if let Some(disc_num) = self.get_value(UniCase::from("Disc")) { + if let Some(disc_num) = self.get_value("Disc") { if let Ok(num) = disc_num.parse::() { return Some(num); } @@ -259,24 +255,24 @@ impl AudioTagEdit for ApeTag { None } fn set_disc_number(&mut self, disc_number: u32) { - self.set_value(UniCase::from("Disc"), disc_number.to_string()) + self.set_value("Disc", disc_number.to_string()) } fn remove_disc_number(&mut self) { - self.remove_key(UniCase::from("Disc")); + self.remove_key("Disc"); } fn total_discs(&self) -> Option { - if let Some(Ok(num)) = self.get_value(UniCase::from("Disc")).map(str::parse::) { + if let Some(Ok(num)) = self.get_value("Disc").map(str::parse::) { return Some(num); } None } fn set_total_discs(&mut self, total_discs: u32) { - self.set_value(UniCase::from("Disc"), total_discs.to_string()) + self.set_value("Disc", total_discs.to_string()) } fn remove_total_discs(&mut self) { - self.remove_key(UniCase::from("Disc")) + self.remove_key("Disc") } fn tag_type(&self) -> TagType { @@ -284,10 +280,10 @@ impl AudioTagEdit for ApeTag { } fn get_key(&self, key: &str) -> Option<&str> { - self.get_value(UniCase::new(key)) + self.get_value(key) } fn remove_key(&mut self, key: &str) { - self.remove_key(UniCase::new(key)) + self.remove_key(key) } } diff --git a/src/components/tags/id3_tag.rs b/src/components/tags/id3_tag.rs index 17f0e3c7..628d4457 100644 --- a/src/components/tags/id3_tag.rs +++ b/src/components/tags/id3_tag.rs @@ -377,7 +377,7 @@ impl AudioTagEdit for Id3v2Tag { fn get_key(&self, key: &str) -> Option<&str> { if let Some(frame) = self.inner.get(key) { - return frame.content().text() + return frame.content().text(); } None diff --git a/src/traits.rs b/src/traits.rs index 6129c0ac..8b0a2951 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -121,7 +121,9 @@ pub trait AudioTagEdit { /// /// NOTE: keys are format-specific, it is recommended to use this in /// combination with [`tag_type`][AudioTagEdit::tag_type] if formats are unknown - fn get_key(&self, _key: &str) -> Option<&str> { None } + fn get_key(&self, _key: &str) -> Option<&str> { + None + } /// Remove's a key/value pair /// /// See [`get_key`][AudioTagEdit::get_key]'s note