ID3v2: Insert multi-value frames separately during Tag conversion

This commit is contained in:
Serial 2022-06-07 19:26:14 -04:00
parent 117ca51fc0
commit 2c90093aa2
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
2 changed files with 26 additions and 3 deletions

View file

@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Bitrates in properties will be rounded up, similar to FFmpeg and TagLib
- **ID3v2**: Insert multi-value frames separately when converting to `Tag`
- E.g. An artist of "foo/bar/baz" will become 3 different `TagItem`s with `ItemKey::TrackArtist`
## [0.6.3] - 2022-05-18

View file

@ -348,7 +348,7 @@ impl From<Id3v2Tag> for Tag {
let mut tag = Self::new(TagType::Id3v2);
for frame in input.frames {
'outer: for frame in input.frames {
let id = frame.id_str();
// The text pairs need some special treatment
@ -374,7 +374,16 @@ impl From<Id3v2Tag> for Tag {
FrameValue::Comment(LanguageFrame { content, .. })
| FrameValue::UnSyncText(LanguageFrame { content, .. })
| FrameValue::Text { value: content, .. }
| FrameValue::UserText(EncodedTextFrame { content, .. }) => ItemValue::Text(content),
| FrameValue::UserText(EncodedTextFrame { content, .. }) => {
for c in content.split(&['\0', '/'][..]) {
tag.items.push(TagItem::new(
item_key.clone(),
ItemValue::Text(c.to_string()),
));
}
continue 'outer;
},
FrameValue::URL(content)
| FrameValue::UserURL(EncodedTextFrame { content, .. }) => ItemValue::Locator(content),
FrameValue::Picture { picture, .. } => {
@ -478,7 +487,7 @@ mod tests {
LanguageFrame, TextEncoding,
};
use crate::tag::utils::test_utils::read_path;
use crate::{MimeType, Picture, PictureType, Tag, TagExt, TagType};
use crate::{ItemKey, MimeType, Picture, PictureType, Tag, TagExt, TagType};
fn read_tag(path: &str) -> Id3v2Tag {
let tag_bytes = crate::tag::utils::test_utils::read_path(path);
@ -853,4 +862,16 @@ mod tests {
})
)
}
#[test]
fn multi_value_frame_to_tag() {
use crate::traits::Accessor;
let mut tag = Id3v2Tag::default();
tag.set_artist(String::from("foo/bar\0baz"));
let tag: Tag = tag.into();
let collected_artists = tag.get_texts(&ItemKey::TrackArtist).collect::<Vec<_>>();
assert_eq!(&collected_artists, &["foo", "bar", "baz"])
}
}