From 4a327847dc0ae14b9ff8a74dcd52c901157dd6df Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Wed, 12 Apr 2023 12:15:19 -0400 Subject: [PATCH] ID3v2: Consistently name abbreviated `FrameValue` variants --- src/id3/v2/frame/content.rs | 6 +++--- src/id3/v2/frame/mod.rs | 36 ++++++++++++++++++------------------ src/id3/v2/tag.rs | 14 +++++++------- src/id3/v2/write/frame.rs | 12 ++++++------ 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/id3/v2/frame/content.rs b/src/id3/v2/frame/content.rs index 5c841f08..be3d5b3c 100644 --- a/src/id3/v2/frame/content.rs +++ b/src/id3/v2/frame/content.rs @@ -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())), diff --git a/src/id3/v2/frame/mod.rs b/src/id3/v2/frame/mod.rs index b7aef369..5cd89ef5 100644 --- a/src/id3/v2/frame/mod.rs +++ b/src/id3/v2/frame/mod.rs @@ -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 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 for FrameValue { impl From for FrameValue { fn from(value: UnsynchronizedTextFrame) -> Self { - Self::UnSyncText(value) + Self::UnsynchronizedText(value) } } @@ -235,13 +235,13 @@ impl From for FrameValue { impl From for FrameValue { fn from(value: UrlLinkFrame) -> Self { - Self::URL(value) + Self::Url(value) } } impl From 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> { 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 for Option> { }) }, (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 for Option> { (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 for Option> { }, 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 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", diff --git a/src/id3/v2/tag.rs b/src/id3/v2/tag.rs index 113474f6..9e9699e9 100644 --- a/src/id3/v2/tag.rs +++ b/src/id3/v2/tag.rs @@ -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"), diff --git a/src/id3/v2/write/frame.rs b/src/id3/v2/write/frame.rs index 4ef5e417..2fc6c311 100644 --- a/src/id3/v2/write/frame.rs +++ b/src/id3/v2/write/frame.rs @@ -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",