mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-13 22:22:31 +00:00
- format changes
- change doc comments on KeyValueFrame
This commit is contained in:
parent
fe8883ccd5
commit
6a673dd057
5 changed files with 32 additions and 33 deletions
|
@ -1,9 +1,9 @@
|
||||||
use crate::error::{Id3v2Error, Id3v2ErrorKind, Result};
|
use crate::error::{Id3v2Error, Id3v2ErrorKind, Result};
|
||||||
use crate::id3::v2::frame::FrameValue;
|
use crate::id3::v2::frame::FrameValue;
|
||||||
use crate::id3::v2::items::{
|
use crate::id3::v2::items::{
|
||||||
AttachedPictureFrame, CommentFrame, ExtendedTextFrame, ExtendedUrlFrame, Popularimeter,
|
AttachedPictureFrame, CommentFrame, ExtendedTextFrame, ExtendedUrlFrame, KeyValueFrame,
|
||||||
TextInformationFrame, UniqueFileIdentifierFrame, UnsynchronizedTextFrame, UrlLinkFrame,
|
Popularimeter, TextInformationFrame, UniqueFileIdentifierFrame, UnsynchronizedTextFrame,
|
||||||
KeyValueFrame
|
UrlLinkFrame,
|
||||||
};
|
};
|
||||||
use crate::id3::v2::Id3v2Version;
|
use crate::id3::v2::Id3v2Version;
|
||||||
use crate::macros::err;
|
use crate::macros::err;
|
||||||
|
|
|
@ -4,9 +4,9 @@ pub(super) mod id;
|
||||||
pub(super) mod read;
|
pub(super) mod read;
|
||||||
|
|
||||||
use super::items::{
|
use super::items::{
|
||||||
AttachedPictureFrame, CommentFrame, ExtendedTextFrame, ExtendedUrlFrame, Popularimeter,
|
AttachedPictureFrame, CommentFrame, ExtendedTextFrame, ExtendedUrlFrame, KeyValueFrame,
|
||||||
TextInformationFrame, UniqueFileIdentifierFrame, UnsynchronizedTextFrame, UrlLinkFrame,
|
Popularimeter, TextInformationFrame, UniqueFileIdentifierFrame, UnsynchronizedTextFrame,
|
||||||
KeyValueFrame
|
UrlLinkFrame,
|
||||||
};
|
};
|
||||||
use super::util::upgrade::{upgrade_v2, upgrade_v3};
|
use super::util::upgrade::{upgrade_v2, upgrade_v3};
|
||||||
use super::Id3v2Version;
|
use super::Id3v2Version;
|
||||||
|
@ -266,9 +266,9 @@ impl From<Popularimeter> for FrameValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<KeyValueFrame> for FrameValue {
|
impl From<KeyValueFrame> for FrameValue {
|
||||||
fn from(value: KeyValueFrame) -> Self {
|
fn from(value: KeyValueFrame) -> Self {
|
||||||
Self::KeyValueFrame(value)
|
Self::KeyValueFrame(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<UniqueFileIdentifierFrame> for FrameValue {
|
impl From<UniqueFileIdentifierFrame> for FrameValue {
|
||||||
|
|
|
@ -7,17 +7,17 @@ use byteorder::ReadBytesExt;
|
||||||
|
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
/// An `ID3v2` text frame
|
/// An `ID3v2` key-value frame
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
pub struct KeyValueFrame {
|
pub struct KeyValueFrame {
|
||||||
/// The encoding of the text
|
/// The encoding of the text
|
||||||
pub encoding: TextEncoding,
|
pub encoding: TextEncoding,
|
||||||
/// The text itself
|
/// The key value pairs. Keys can be specified multiple times
|
||||||
pub values: Vec<(String, String)>,
|
pub key_value_pairs: Vec<(String, String)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyValueFrame {
|
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
|
/// 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 encoding = verify_encoding(encoding_byte, version)?;
|
||||||
|
|
||||||
let mut values = vec![];
|
|
||||||
|
|
||||||
loop {
|
let mut values = vec![];
|
||||||
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));
|
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> {
|
pub fn as_bytes(&self) -> Vec<u8> {
|
||||||
let mut content = vec![];
|
let mut content = vec![];
|
||||||
|
|
||||||
for (key, value) in &self.values {
|
for (key, value) in &self.key_value_pairs {
|
||||||
content.append(&mut encode_text(key, self.encoding, true));
|
content.append(&mut encode_text(key, self.encoding, true));
|
||||||
content.append(&mut encode_text(value, self.encoding, true));
|
content.append(&mut encode_text(value, self.encoding, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
content.insert(0, self.encoding as u8);
|
content.insert(0, self.encoding as u8);
|
||||||
content
|
content
|
||||||
|
|
|
@ -4,12 +4,12 @@ mod encapsulated_object;
|
||||||
mod extended_text_frame;
|
mod extended_text_frame;
|
||||||
mod extended_url_frame;
|
mod extended_url_frame;
|
||||||
mod identifier;
|
mod identifier;
|
||||||
|
mod key_value_frame;
|
||||||
pub(in crate::id3::v2) mod language_frame;
|
pub(in crate::id3::v2) mod language_frame;
|
||||||
mod popularimeter;
|
mod popularimeter;
|
||||||
mod sync_text;
|
mod sync_text;
|
||||||
mod text_information_frame;
|
mod text_information_frame;
|
||||||
mod url_link_frame;
|
mod url_link_frame;
|
||||||
mod key_value_frame;
|
|
||||||
|
|
||||||
pub use attached_picture_frame::AttachedPictureFrame;
|
pub use attached_picture_frame::AttachedPictureFrame;
|
||||||
pub use audio_text_frame::{scramble, AudioTextFrame, AudioTextFrameFlags};
|
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_text_frame::ExtendedTextFrame;
|
||||||
pub use extended_url_frame::ExtendedUrlFrame;
|
pub use extended_url_frame::ExtendedUrlFrame;
|
||||||
pub use identifier::UniqueFileIdentifierFrame;
|
pub use identifier::UniqueFileIdentifierFrame;
|
||||||
|
pub use key_value_frame::KeyValueFrame;
|
||||||
pub use language_frame::{CommentFrame, UnsynchronizedTextFrame};
|
pub use language_frame::{CommentFrame, UnsynchronizedTextFrame};
|
||||||
pub use popularimeter::Popularimeter;
|
pub use popularimeter::Popularimeter;
|
||||||
pub use sync_text::{SyncTextContentType, SynchronizedText, TimestampFormat};
|
pub use sync_text::{SyncTextContentType, SynchronizedText, TimestampFormat};
|
||||||
pub use text_information_frame::TextInformationFrame;
|
pub use text_information_frame::TextInformationFrame;
|
||||||
pub use url_link_frame::UrlLinkFrame;
|
pub use url_link_frame::UrlLinkFrame;
|
||||||
pub use key_value_frame::KeyValueFrame;
|
|
||||||
|
|
|
@ -788,7 +788,7 @@ impl SplitTag for Id3v2Tag {
|
||||||
FrameValue::Popularimeter(popularimeter) => {
|
FrameValue::Popularimeter(popularimeter) => {
|
||||||
ItemValue::Binary(popularimeter.as_bytes())
|
ItemValue::Binary(popularimeter.as_bytes())
|
||||||
},
|
},
|
||||||
FrameValue::KeyValueFrame(_) => {
|
FrameValue::KeyValueFrame(_) => {
|
||||||
return true; // Keep frame
|
return true; // Keep frame
|
||||||
},
|
},
|
||||||
FrameValue::Binary(binary) => ItemValue::Binary(std::mem::take(binary)),
|
FrameValue::Binary(binary) => ItemValue::Binary(std::mem::take(binary)),
|
||||||
|
|
Loading…
Reference in a new issue