- format changes

- change doc comments on KeyValueFrame
This commit is contained in:
Frieder Hannenheim 2023-07-02 15:14:49 +02:00 committed by Alex
parent fe8883ccd5
commit 6a673dd057
5 changed files with 32 additions and 33 deletions

View file

@ -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;

View file

@ -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<Popularimeter> for FrameValue {
}
impl From<KeyValueFrame> for FrameValue {
fn from(value: KeyValueFrame) -> Self {
Self::KeyValueFrame(value)
}
fn from(value: KeyValueFrame) -> Self {
Self::KeyValueFrame(value)
}
}
impl From<UniqueFileIdentifierFrame> for FrameValue {

View file

@ -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<u8> {
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

View file

@ -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;

View file

@ -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)),