mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-11-10 06:34:18 +00:00
No longer store artists in a Vec, and stop assuming the delimiter
Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
parent
e1101af9a7
commit
e103a481df
11 changed files with 34 additions and 84 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -333,9 +333,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "lofty_attr"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "730965dbb1c84caad9679a67cd70eaadd874fbd79eb7dda2bf369fbf80c22cee"
|
||||
checksum = "f55b7f910d0137565a5eed225d3a89efb4512b2986eebe264235bf2e890e13db"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
|
|
|
@ -30,7 +30,7 @@ base64 = "0.13.0"
|
|||
byteorder = "1.4.3"
|
||||
cfg-if = "1.0.0"
|
||||
|
||||
lofty_attr = "0.1.4"
|
||||
lofty_attr = "0.1.5"
|
||||
|
||||
[features]
|
||||
default = ["all_tags"]
|
||||
|
|
2
lofty-attr/Cargo.lock
generated
2
lofty-attr/Cargo.lock
generated
|
@ -4,7 +4,7 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "lofty_attr"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
|
|
|
@ -87,10 +87,6 @@ impl AudioTagEdit for ApeTag {
|
|||
self.set_value("Artist", artist)
|
||||
}
|
||||
|
||||
fn artists_vec(&self) -> Option<Vec<&str>> {
|
||||
self.artist_str().map(|a| a.split('/').collect())
|
||||
}
|
||||
|
||||
fn remove_artist(&mut self) {
|
||||
self.remove_key("Artist")
|
||||
}
|
||||
|
@ -140,9 +136,6 @@ impl AudioTagEdit for ApeTag {
|
|||
fn album_artist_str(&self) -> Option<&str> {
|
||||
self.get_value("Album artist")
|
||||
}
|
||||
fn album_artists_vec(&self) -> Option<Vec<&str>> {
|
||||
self.album_artist_str().map(|a| a.split('/').collect())
|
||||
}
|
||||
|
||||
fn set_album_artist(&mut self, artists: &str) {
|
||||
self.set_value("Album artist", artists)
|
||||
|
|
|
@ -101,10 +101,6 @@ impl AudioTagEdit for Id3v2Tag {
|
|||
self.inner.set_artist(artist)
|
||||
}
|
||||
|
||||
fn artists_vec(&self) -> Option<Vec<&str>> {
|
||||
self.artist_str().map(|a| a.split('/').collect())
|
||||
}
|
||||
|
||||
fn remove_artist(&mut self) {
|
||||
self.inner.remove_artist()
|
||||
}
|
||||
|
@ -160,10 +156,6 @@ impl AudioTagEdit for Id3v2Tag {
|
|||
self.inner.album_artist()
|
||||
}
|
||||
|
||||
fn album_artists_vec(&self) -> Option<Vec<&str>> {
|
||||
self.inner.album_artist().map(|a| a.split('/').collect())
|
||||
}
|
||||
|
||||
fn set_album_artist(&mut self, artists: &str) {
|
||||
self.inner.set_album_artist(artists)
|
||||
}
|
||||
|
|
|
@ -273,12 +273,6 @@ impl AudioTagEdit for OggTag {
|
|||
self.inner.get_value("ALBUMARTIST")
|
||||
}
|
||||
|
||||
fn album_artists_vec(&self) -> Option<Vec<&str>> {
|
||||
self.inner
|
||||
.get_value("ALBUMARTIST")
|
||||
.map(|a| a.split('/').collect())
|
||||
}
|
||||
|
||||
fn set_album_artist(&mut self, artist: &str) {
|
||||
self.inner.set_value("ALBUMARTIST", artist)
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ pub trait AudioTagEdit {
|
|||
fn set_artist(&mut self, artist: &str);
|
||||
|
||||
/// Splits the artist string into a `Vec`
|
||||
fn artists_vec(&self) -> Option<Vec<&str>> {
|
||||
self.artist_str().map(|a| a.split('/').collect())
|
||||
fn artists(&self, delimiter: &str) -> Option<Vec<&str>> {
|
||||
self.artist_str().map(|a| a.split(delimiter).collect())
|
||||
}
|
||||
/// Removes the artist string
|
||||
fn remove_artist(&mut self);
|
||||
|
@ -57,7 +57,7 @@ pub trait AudioTagEdit {
|
|||
fn album(&self) -> Album<'_> {
|
||||
Album {
|
||||
title: self.album_title(),
|
||||
artists: self.album_artists_vec(),
|
||||
artist: self.album_artist_str(),
|
||||
covers: self.album_covers(),
|
||||
}
|
||||
}
|
||||
|
@ -72,8 +72,9 @@ pub trait AudioTagEdit {
|
|||
/// Returns the album artist string
|
||||
fn album_artist_str(&self) -> Option<&str>;
|
||||
/// Splits the artist string into a `Vec`
|
||||
fn album_artists_vec(&self) -> Option<Vec<&str>> {
|
||||
self.album_artist_str().map(|a| a.split('/').collect())
|
||||
fn album_artists(&self, delimiter: &str) -> Option<Vec<&str>> {
|
||||
self.album_artist_str()
|
||||
.map(|a| a.split(delimiter).collect())
|
||||
}
|
||||
/// Sets the album artist string
|
||||
fn set_album_artist(&mut self, artist: &str);
|
||||
|
|
|
@ -6,7 +6,7 @@ pub struct Album<'a> {
|
|||
/// The title of the album
|
||||
pub title: Option<&'a str>,
|
||||
/// A `Vec` of the album artists
|
||||
pub artists: Option<Vec<&'a str>>,
|
||||
pub artist: Option<&'a str>,
|
||||
/// The album's covers (Front, Back)
|
||||
pub covers: (Option<Picture>, Option<Picture>),
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ impl<'a> Default for Album<'a> {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
title: None,
|
||||
artists: None,
|
||||
artist: None,
|
||||
covers: (None, None),
|
||||
}
|
||||
}
|
||||
|
@ -25,12 +25,12 @@ impl<'a> Album<'a> {
|
|||
/// Create a new `Album`
|
||||
pub fn new(
|
||||
title: Option<&'a str>,
|
||||
artists: Option<Vec<&'a str>>,
|
||||
artist: Option<&'a str>,
|
||||
covers: (Option<Picture>, Option<Picture>),
|
||||
) -> Self {
|
||||
Self {
|
||||
title,
|
||||
artists,
|
||||
artist,
|
||||
covers,
|
||||
}
|
||||
}
|
||||
|
@ -38,36 +38,24 @@ impl<'a> Album<'a> {
|
|||
pub fn with_title(title: &'a str) -> Self {
|
||||
Self {
|
||||
title: Some(title),
|
||||
artists: None,
|
||||
artist: None,
|
||||
covers: (None, None),
|
||||
}
|
||||
}
|
||||
/// Set the album artists
|
||||
pub fn set_artists(mut self, artists: Vec<&'a str>) {
|
||||
self.artists = Some(artists);
|
||||
}
|
||||
/// Appends an artist to the `artists` vec
|
||||
pub fn append_artist(mut self, artist: &'a str) {
|
||||
if let Some(mut artists) = self.artists {
|
||||
artists.push(artist)
|
||||
} else {
|
||||
self.artists = Some(vec![artist])
|
||||
}
|
||||
pub fn set_artists(&mut self, artist_str: &'a str) {
|
||||
self.artist = Some(artist_str);
|
||||
}
|
||||
/// Clears the `artists` field
|
||||
pub fn remove_artists(mut self) {
|
||||
self.artists = None
|
||||
pub fn remove_artist(mut self) {
|
||||
self.artist = None
|
||||
}
|
||||
/// Set the album cover
|
||||
pub fn set_covers(mut self, covers: (Option<Picture>, Option<Picture>)) {
|
||||
pub fn set_covers(&mut self, covers: (Option<Picture>, Option<Picture>)) {
|
||||
self.covers = covers
|
||||
}
|
||||
/// Clears the `covers` field
|
||||
pub fn remove_covers(mut self) {
|
||||
self.covers = (None, None)
|
||||
}
|
||||
/// Turns `artists` vec into a String
|
||||
pub fn artists_as_string(&self) -> Option<String> {
|
||||
self.artists.as_ref().map(|artists| artists.join("/"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ pub struct AnyTag<'a> {
|
|||
/// The track title
|
||||
pub title: Option<&'a str>,
|
||||
/// The track artists
|
||||
pub artists: Option<Vec<&'a str>>,
|
||||
pub artist: Option<&'a str>,
|
||||
/// The track [`Album`]
|
||||
pub album: Album<'a>,
|
||||
/// Collection of user comments
|
||||
|
@ -38,20 +38,9 @@ impl<'a> AnyTag<'a> {
|
|||
pub fn set_title(&mut self, title: &'a str) {
|
||||
self.title = Some(title);
|
||||
}
|
||||
/// Returns `artists`.
|
||||
pub fn artists(&self) -> Option<&[&str]> {
|
||||
self.artists.as_deref()
|
||||
}
|
||||
/// Replaces `artists`.
|
||||
pub fn set_artists(&mut self, artists: Vec<&'a str>) {
|
||||
self.artists = Some(artists)
|
||||
}
|
||||
/// Appends an artist to `artists`
|
||||
pub fn add_artist(&mut self, artist: &'a str) {
|
||||
self.artists = self.artists.clone().map(|mut a| {
|
||||
a.push(artist);
|
||||
a
|
||||
});
|
||||
/// Returns `artist`
|
||||
pub fn artist(&self) -> Option<&str> {
|
||||
self.artist
|
||||
}
|
||||
/// Returns `album`
|
||||
pub fn album(&self) -> Album {
|
||||
|
@ -86,10 +75,3 @@ impl<'a> AnyTag<'a> {
|
|||
self.total_tracks
|
||||
}
|
||||
}
|
||||
|
||||
impl AnyTag<'_> {
|
||||
/// Turns `artists` into a comma separated String
|
||||
pub fn artists_as_string(&self) -> Option<String> {
|
||||
self.artists.as_ref().map(|artists| artists.join("/"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,16 +7,16 @@ use crate::{LoftyError, Result};
|
|||
feature = "format-flac",
|
||||
))]
|
||||
use byteorder::{BigEndian, ReadBytesExt};
|
||||
#[cfg(any(
|
||||
feature = "format-id3",
|
||||
feature = "format-opus",
|
||||
feature = "format-vorbis",
|
||||
feature = "format-flac",
|
||||
feature = "format-ape",
|
||||
))]
|
||||
use std::io::{Cursor, Read};
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryFrom;
|
||||
#[cfg(any(
|
||||
feature = "format-id3",
|
||||
feature = "format-opus",
|
||||
feature = "format-vorbis",
|
||||
feature = "format-flac",
|
||||
feature = "format-ape",
|
||||
))]
|
||||
use std::io::{Cursor, Read};
|
||||
|
||||
#[cfg(feature = "format-ape")]
|
||||
pub const APE_PICTYPES: [&str; 21] = [
|
||||
|
|
|
@ -141,7 +141,7 @@ macro_rules! verify_write {
|
|||
};
|
||||
|
||||
println!("Verifying album artist");
|
||||
assert_eq!(tag.album_artists_vec(), Some(vec!["foo album artist"]));
|
||||
assert_eq!(tag.album_artist_str(), Some("foo album artist"));
|
||||
|
||||
println!("Verifying album covers");
|
||||
|
||||
|
@ -181,7 +181,7 @@ macro_rules! remove_tags {
|
|||
|
||||
println!("Removing album artists");
|
||||
tag.remove_album_artists();
|
||||
assert!(tag.album_artists_vec().is_none());
|
||||
assert!(tag.album_artist_str().is_none());
|
||||
tag.remove_album_artists();
|
||||
|
||||
println!("Removing album covers");
|
||||
|
|
Loading…
Reference in a new issue