From 6a673dd057c88089bd4252c7caf983482c9cbd38 Mon Sep 17 00:00:00 2001 From: Frieder Hannenheim Date: Sun, 2 Jul 2023 15:14:49 +0200 Subject: [PATCH] - format changes - change doc comments on KeyValueFrame --- src/id3/v2/frame/content.rs | 6 ++--- src/id3/v2/frame/mod.rs | 12 ++++----- src/id3/v2/items/key_value_frame.rs | 41 ++++++++++++++--------------- src/id3/v2/items/mod.rs | 4 +-- src/id3/v2/tag.rs | 2 +- 5 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/id3/v2/frame/content.rs b/src/id3/v2/frame/content.rs index ef00c297..04f3e110 100644 --- a/src/id3/v2/frame/content.rs +++ b/src/id3/v2/frame/content.rs @@ -1,9 +1,9 @@ use crate::error::{Id3v2Error, Id3v2ErrorKind, Result}; use crate::id3::v2::frame::FrameValue; use crate::id3::v2::items::{ - AttachedPictureFrame, CommentFrame, ExtendedTextFrame, ExtendedUrlFrame, Popularimeter, - TextInformationFrame, UniqueFileIdentifierFrame, UnsynchronizedTextFrame, UrlLinkFrame, - KeyValueFrame + AttachedPictureFrame, CommentFrame, ExtendedTextFrame, ExtendedUrlFrame, KeyValueFrame, + Popularimeter, TextInformationFrame, UniqueFileIdentifierFrame, UnsynchronizedTextFrame, + UrlLinkFrame, }; use crate::id3::v2::Id3v2Version; use crate::macros::err; diff --git a/src/id3/v2/frame/mod.rs b/src/id3/v2/frame/mod.rs index e1ac50f3..e0e9bbd0 100644 --- a/src/id3/v2/frame/mod.rs +++ b/src/id3/v2/frame/mod.rs @@ -4,9 +4,9 @@ pub(super) mod id; pub(super) mod read; use super::items::{ - AttachedPictureFrame, CommentFrame, ExtendedTextFrame, ExtendedUrlFrame, Popularimeter, - TextInformationFrame, UniqueFileIdentifierFrame, UnsynchronizedTextFrame, UrlLinkFrame, - KeyValueFrame + AttachedPictureFrame, CommentFrame, ExtendedTextFrame, ExtendedUrlFrame, KeyValueFrame, + Popularimeter, TextInformationFrame, UniqueFileIdentifierFrame, UnsynchronizedTextFrame, + UrlLinkFrame, }; use super::util::upgrade::{upgrade_v2, upgrade_v3}; use super::Id3v2Version; @@ -266,9 +266,9 @@ impl From for FrameValue { } impl From for FrameValue { - fn from(value: KeyValueFrame) -> Self { - Self::KeyValueFrame(value) - } + fn from(value: KeyValueFrame) -> Self { + Self::KeyValueFrame(value) + } } impl From for FrameValue { diff --git a/src/id3/v2/items/key_value_frame.rs b/src/id3/v2/items/key_value_frame.rs index 99b742be..7bcf983f 100644 --- a/src/id3/v2/items/key_value_frame.rs +++ b/src/id3/v2/items/key_value_frame.rs @@ -7,17 +7,17 @@ use byteorder::ReadBytesExt; use std::io::Read; -/// An `ID3v2` text frame +/// An `ID3v2` key-value frame #[derive(Clone, Debug, Eq, PartialEq, Hash)] pub struct KeyValueFrame { /// The encoding of the text pub encoding: TextEncoding, - /// The text itself - pub values: Vec<(String, String)>, + /// The key value pairs. Keys can be specified multiple times + pub key_value_pairs: Vec<(String, String)>, } impl KeyValueFrame { - /// Read an [`TextInformationFrame`] from a slice + /// Read an [`KeyValueFrame`] from a slice /// /// NOTE: This expects the frame header to have already been skipped /// @@ -37,31 +37,30 @@ impl KeyValueFrame { }; let encoding = verify_encoding(encoding_byte, version)?; - - let mut values = vec![]; - loop { - let key = decode_text(reader, encoding, true)?; - let value = decode_text(reader, encoding, true)?; - if key.bytes_read == 0 || value.bytes_read == 0 { - break; - } + let mut values = vec![]; - values.push((key.content, value.content)); - } + loop { + let key = decode_text(reader, encoding, true)?; + let value = decode_text(reader, encoding, true)?; + if key.bytes_read == 0 || value.bytes_read == 0 { + break; + } + values.push((key.content, value.content)); + } - Ok(Some(Self{ encoding, values })) + Ok(Some(Self { encoding, key_value_pairs: values })) } - /// Convert an [`TextInformationFrame`] to a byte vec + /// Convert a [`KeyValueFrame`] to a byte vec pub fn as_bytes(&self) -> Vec { let mut content = vec![]; - - for (key, value) in &self.values { - content.append(&mut encode_text(key, self.encoding, true)); - content.append(&mut encode_text(value, self.encoding, true)); - } + + for (key, value) in &self.key_value_pairs { + content.append(&mut encode_text(key, self.encoding, true)); + content.append(&mut encode_text(value, self.encoding, true)); + } content.insert(0, self.encoding as u8); content diff --git a/src/id3/v2/items/mod.rs b/src/id3/v2/items/mod.rs index 101cda37..f027c08a 100644 --- a/src/id3/v2/items/mod.rs +++ b/src/id3/v2/items/mod.rs @@ -4,12 +4,12 @@ mod encapsulated_object; mod extended_text_frame; mod extended_url_frame; mod identifier; +mod key_value_frame; pub(in crate::id3::v2) mod language_frame; mod popularimeter; mod sync_text; mod text_information_frame; mod url_link_frame; -mod key_value_frame; pub use attached_picture_frame::AttachedPictureFrame; pub use audio_text_frame::{scramble, AudioTextFrame, AudioTextFrameFlags}; @@ -17,9 +17,9 @@ pub use encapsulated_object::GeneralEncapsulatedObject; pub use extended_text_frame::ExtendedTextFrame; pub use extended_url_frame::ExtendedUrlFrame; pub use identifier::UniqueFileIdentifierFrame; +pub use key_value_frame::KeyValueFrame; pub use language_frame::{CommentFrame, UnsynchronizedTextFrame}; pub use popularimeter::Popularimeter; pub use sync_text::{SyncTextContentType, SynchronizedText, TimestampFormat}; pub use text_information_frame::TextInformationFrame; pub use url_link_frame::UrlLinkFrame; -pub use key_value_frame::KeyValueFrame; diff --git a/src/id3/v2/tag.rs b/src/id3/v2/tag.rs index 3d0bff3b..837dafff 100644 --- a/src/id3/v2/tag.rs +++ b/src/id3/v2/tag.rs @@ -788,7 +788,7 @@ impl SplitTag for Id3v2Tag { FrameValue::Popularimeter(popularimeter) => { ItemValue::Binary(popularimeter.as_bytes()) }, - FrameValue::KeyValueFrame(_) => { + FrameValue::KeyValueFrame(_) => { return true; // Keep frame }, FrameValue::Binary(binary) => ItemValue::Binary(std::mem::take(binary)),