ID3v2: Consistently name abbreviated FrameValue variants

This commit is contained in:
Serial 2023-04-12 12:15:19 -04:00 committed by Alex
parent 99af322afb
commit 4a327847dc
4 changed files with 34 additions and 34 deletions

View file

@ -22,15 +22,15 @@ pub(super) fn parse_content(
Some(FrameValue::Picture(attached_picture))
},
"TXXX" => ExtendedTextFrame::parse(content, version)?.map(FrameValue::UserText),
"WXXX" => ExtendedUrlFrame::parse(content, version)?.map(FrameValue::UserURL),
"WXXX" => ExtendedUrlFrame::parse(content, version)?.map(FrameValue::UserUrl),
"COMM" => LanguageFrame::parse(content, version)?.map(|lf| FrameValue::Comment(lf.into())),
"USLT" => LanguageFrame::parse(content, version)?.map(|lf| FrameValue::UnSyncText(lf.into())),
"USLT" => LanguageFrame::parse(content, version)?.map(|lf| FrameValue::UnsynchronizedText(lf.into())),
"UFID" => UniqueFileIdentifierFrame::parse(content)?.map(FrameValue::UniqueFileIdentifier),
_ if id.starts_with('T') => TextInformationFrame::parse(content, version)?.map(FrameValue::Text),
// Apple proprietary frames
// WFED (Podcast URL), GRP1 (Grouping), MVNM (Movement Name), MVIN (Movement Number)
"WFED" | "GRP1" | "MVNM" | "MVIN" => TextInformationFrame::parse(content, version)?.map(FrameValue::Text),
_ if id.starts_with('W') => UrlLinkFrame::parse(content)?.map(FrameValue::URL),
_ if id.starts_with('W') => UrlLinkFrame::parse(content)?.map(FrameValue::Url),
"POPM" => Some(FrameValue::Popularimeter(Popularimeter::parse(content)?)),
// SYLT, GEOB, and any unknown frames
_ => Some(FrameValue::Binary(content.to_vec())),

View file

@ -160,15 +160,15 @@ pub enum FrameValue {
/// Represents a "COMM" frame
Comment(CommentFrame),
/// Represents a "USLT" frame
UnSyncText(UnsynchronizedTextFrame),
UnsynchronizedText(UnsynchronizedTextFrame),
/// Represents a "T..." (excluding TXXX) frame
Text(TextInformationFrame),
/// Represents a "TXXX" frame
UserText(ExtendedTextFrame),
/// Represents a "W..." (excluding WXXX) frame
URL(UrlLinkFrame),
Url(UrlLinkFrame),
/// Represents a "WXXX" frame
UserURL(ExtendedUrlFrame),
UserUrl(ExtendedUrlFrame),
/// Represents an "APIC" or "PIC" frame
Picture(AttachedPictureFrame),
/// Represents a "POPM" frame
@ -197,7 +197,7 @@ impl TryFrom<ItemValue> for FrameValue {
})),
ItemValue::Locator(locator) => {
if TextEncoding::verify_latin1(&locator) {
Ok(FrameValue::URL(UrlLinkFrame(locator)))
Ok(FrameValue::Url(UrlLinkFrame(locator)))
} else {
Err(LoftyError::new(ErrorKind::TextDecode(
"ID3v2 URL frames must be Latin-1",
@ -217,7 +217,7 @@ impl From<CommentFrame> for FrameValue {
impl From<UnsynchronizedTextFrame> for FrameValue {
fn from(value: UnsynchronizedTextFrame) -> Self {
Self::UnSyncText(value)
Self::UnsynchronizedText(value)
}
}
@ -235,13 +235,13 @@ impl From<ExtendedTextFrame> for FrameValue {
impl From<UrlLinkFrame> for FrameValue {
fn from(value: UrlLinkFrame) -> Self {
Self::URL(value)
Self::Url(value)
}
}
impl From<ExtendedUrlFrame> for FrameValue {
fn from(value: ExtendedUrlFrame) -> Self {
Self::UserURL(value)
Self::UserUrl(value)
}
}
@ -267,11 +267,11 @@ impl FrameValue {
pub(super) fn as_bytes(&self) -> Result<Vec<u8>> {
Ok(match self {
FrameValue::Comment(comment) => comment.as_bytes()?,
FrameValue::UnSyncText(lf) => lf.as_bytes()?,
FrameValue::UnsynchronizedText(lf) => lf.as_bytes()?,
FrameValue::Text(tif) => tif.as_bytes(),
FrameValue::UserText(content) => content.as_bytes(),
FrameValue::UserURL(content) => content.as_bytes(),
FrameValue::URL(link) => link.as_bytes(),
FrameValue::UserUrl(content) => content.as_bytes(),
FrameValue::Url(link) => link.as_bytes(),
FrameValue::Picture(attached_picture) => attached_picture.as_bytes(ID3v2Version::V4)?,
FrameValue::Popularimeter(popularimeter) => popularimeter.as_bytes(),
FrameValue::Binary(binary) => binary.clone(),
@ -338,7 +338,7 @@ impl From<TagItem> for Option<Frame<'static>> {
})
},
(FrameID::Valid(ref s), ItemValue::Text(text)) if s == "USLT" => {
FrameValue::UnSyncText(UnsynchronizedTextFrame {
FrameValue::UnsynchronizedText(UnsynchronizedTextFrame {
encoding: TextEncoding::UTF8,
language: UNKNOWN_LANGUAGE,
description: EMPTY_CONTENT_DESCRIPTOR,
@ -348,7 +348,7 @@ impl From<TagItem> for Option<Frame<'static>> {
(FrameID::Valid(ref s), ItemValue::Locator(text) | ItemValue::Text(text))
if s == "WXXX" =>
{
FrameValue::UserURL(ExtendedUrlFrame {
FrameValue::UserUrl(ExtendedUrlFrame {
encoding: TextEncoding::UTF8,
description: EMPTY_CONTENT_DESCRIPTOR,
content: text,
@ -387,7 +387,7 @@ impl From<TagItem> for Option<Frame<'static>> {
},
ItemValue::Locator(locator) => {
frame_id = FrameID::Valid(Cow::Borrowed("WXXX"));
value = FrameValue::UserURL(ExtendedUrlFrame {
value = FrameValue::UserUrl(ExtendedUrlFrame {
encoding: TextEncoding::UTF8,
description: String::from(desc),
content: locator,
@ -462,7 +462,7 @@ impl<'a> TryFrom<&'a TagItem> for FrameRef<'a> {
content: text.clone(),
}),
("USLT", ItemValue::Text(text)) => {
FrameValue::UnSyncText(UnsynchronizedTextFrame {
FrameValue::UnsynchronizedText(UnsynchronizedTextFrame {
encoding: TextEncoding::UTF8,
language: UNKNOWN_LANGUAGE,
description: EMPTY_CONTENT_DESCRIPTOR,
@ -470,14 +470,14 @@ impl<'a> TryFrom<&'a TagItem> for FrameRef<'a> {
})
},
("WXXX", ItemValue::Locator(text) | ItemValue::Text(text)) => {
FrameValue::UserURL(ExtendedUrlFrame {
FrameValue::UserUrl(ExtendedUrlFrame {
encoding: TextEncoding::UTF8,
description: EMPTY_CONTENT_DESCRIPTOR,
content: text.clone(),
})
},
(locator_id, ItemValue::Locator(text)) if locator_id.len() > 4 => {
FrameValue::UserURL(ExtendedUrlFrame {
FrameValue::UserUrl(ExtendedUrlFrame {
encoding: TextEncoding::UTF8,
description: EMPTY_CONTENT_DESCRIPTOR,
content: text.clone(),
@ -519,7 +519,7 @@ impl<'a> TryFrom<&'a TagItem> for FrameRef<'a> {
},
ItemValue::Locator(locator) => {
frame_id = FrameID::Valid(Cow::Borrowed("WXXX"));
value = FrameValue::UserURL(ExtendedUrlFrame {
value = FrameValue::UserUrl(ExtendedUrlFrame {
encoding: TextEncoding::UTF8,
description: String::from(desc),
content: locator.clone(),
@ -549,7 +549,7 @@ impl<'a> TryInto<FrameValue> for &'a ItemValue {
})),
ItemValue::Locator(locator) => {
if TextEncoding::verify_latin1(locator) {
Ok(FrameValue::URL(UrlLinkFrame(locator.clone())))
Ok(FrameValue::Url(UrlLinkFrame(locator.clone())))
} else {
Err(LoftyError::new(ErrorKind::TextDecode(
"ID3v2 URL frames must be Latin-1",

View file

@ -287,7 +287,7 @@ impl ID3v2Tag {
self.frames.iter().filter_map(|f| match f {
Frame {
id: FrameID::Valid(id),
value: FrameValue::UnSyncText(val),
value: FrameValue::UnsynchronizedText(val),
..
} if id == "USLT" => Some(val),
_ => None,
@ -738,7 +738,7 @@ impl SplitTag for ID3v2Tag {
},
(
"WXXX",
FrameValue::UserURL(ExtendedUrlFrame {
FrameValue::UserUrl(ExtendedUrlFrame {
ref description,
ref content,
..
@ -785,7 +785,7 @@ impl SplitTag for ID3v2Tag {
description,
..
})
| FrameValue::UnSyncText(UnsynchronizedTextFrame {
| FrameValue::UnsynchronizedText(UnsynchronizedTextFrame {
content,
description,
..
@ -821,8 +821,8 @@ impl SplitTag for ID3v2Tag {
}
return false; // Frame consumed
},
FrameValue::URL(UrlLinkFrame(content))
| FrameValue::UserURL(ExtendedUrlFrame { content, .. }) => {
FrameValue::Url(UrlLinkFrame(content))
| FrameValue::UserUrl(ExtendedUrlFrame { content, .. }) => {
ItemValue::Locator(std::mem::take(content))
},
FrameValue::Picture(AttachedPictureFrame { picture, .. }) => {
@ -1281,7 +1281,7 @@ mod tests {
let mut tag = ID3v2Tag::default();
tag.insert(Frame {
id: FrameID::Valid(Cow::Borrowed("ABCD")),
value: FrameValue::URL(UrlLinkFrame(String::from("FOO URL"))),
value: FrameValue::Url(UrlLinkFrame(String::from("FOO URL"))),
flags: FrameFlags::default(),
});
@ -1715,7 +1715,7 @@ mod tests {
let wxxx_frame = Frame::new(
"WXXX",
FrameValue::UserURL(ExtendedUrlFrame {
FrameValue::UserUrl(ExtendedUrlFrame {
encoding: TextEncoding::UTF8,
description: String::from("BAR_URL_FRAME"),
content: String::from("bar url"),

View file

@ -26,24 +26,24 @@ where
fn verify_frame(frame: &FrameRef<'_>) -> Result<()> {
match (frame.id.as_str(), frame.value.as_ref()) {
("APIC", FrameValue::Picture { .. })
| ("USLT", FrameValue::UnSyncText(_))
| ("USLT", FrameValue::UnsynchronizedText(_))
| ("COMM", FrameValue::Comment(_))
| ("TXXX", FrameValue::UserText(_))
| ("WXXX", FrameValue::UserURL(_))
| ("WXXX", FrameValue::UserUrl(_))
| (_, FrameValue::Binary(_))
| ("UFID", FrameValue::UniqueFileIdentifier(_))
| ("WFED" | "GRP1" | "MVNM" | "MVIN", FrameValue::Text { .. }) => Ok(()),
(id, FrameValue::Text { .. }) if id.starts_with('T') => Ok(()),
(id, FrameValue::URL(_)) if id.starts_with('W') => Ok(()),
(id, FrameValue::Url(_)) if id.starts_with('W') => Ok(()),
(id, frame_value) => Err(ID3v2Error::new(ID3v2ErrorKind::BadFrame(
id.to_string(),
match frame_value {
FrameValue::Comment(_) => "Comment",
FrameValue::UnSyncText(_) => "UnSyncText",
FrameValue::UnsynchronizedText(_) => "UnSyncText",
FrameValue::Text { .. } => "Text",
FrameValue::UserText(_) => "UserText",
FrameValue::URL(_) => "URL",
FrameValue::UserURL(_) => "UserURL",
FrameValue::Url(_) => "URL",
FrameValue::UserUrl(_) => "UserURL",
FrameValue::Picture { .. } => "Picture",
FrameValue::Popularimeter(_) => "Popularimeter",
FrameValue::Binary(_) => "Binary",