iff: Rename IFF tags

This commit is contained in:
Serial 2024-04-21 14:27:43 -04:00 committed by Alex
parent 46626c98e9
commit b1723cecfb
12 changed files with 64 additions and 61 deletions

View file

@ -49,6 +49,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `PictureType`
- `PictureInformation`
- `MimeType`
- **IFF** ([PR](https://github.com/Serial-ATA/lofty-rs/pull/379)):
- **AIFF**: `AIFFTextChunks` renamed to `AiffTextChunks`
- **RIFF**: `RIFFInfoList` renamed to `RiffInfoList`
### Fixed
- **Vorbis**: Fix panic when reading properties of zero-length files ([issue](https://github.com/Serial-ATA/lofty-rs/issues/342)) ([PR](https://github.com/Serial-ATA/lofty-rs/pull/365))

View file

@ -2,8 +2,8 @@ use lofty::ape::ApeTag;
use lofty::config::WriteOptions;
use lofty::id3::v1::Id3v1Tag;
use lofty::id3::v2::Id3v2Tag;
use lofty::iff::aiff::AIFFTextChunks;
use lofty::iff::wav::RIFFInfoList;
use lofty::iff::aiff::AiffTextChunks;
use lofty::iff::wav::RiffInfoList;
use lofty::mp4::Ilst;
use lofty::ogg::VorbisComments;
use lofty::picture::{MimeType, Picture, PictureType};
@ -35,7 +35,7 @@ macro_rules! bench_tag_write {
}
bench_tag_write!([
(aiff_text_chunks, AIFFTextChunks, |tag| {}),
(aiff_text_chunks, AiffTextChunks, |tag| {}),
(apev2, ApeTag, |tag| {
use lofty::ape::ApeItem;
use lofty::tag::ItemValue;
@ -103,7 +103,7 @@ bench_tag_write!([
AtomData::UTF8(String::from(ENCODER)),
));
}),
(riff_info, RIFFInfoList, |tag| {
(riff_info, RiffInfoList, |tag| {
tag.insert(String::from("ISFT"), String::from(ENCODER));
}),
(vorbis_comments, VorbisComments, |tag| {

View file

@ -94,8 +94,8 @@ impl FileType {
TagType::Id3v2 => crate::id3::v2::Id3v2Tag::SUPPORTED_FORMATS.contains(self),
TagType::Mp4Ilst => crate::mp4::Ilst::SUPPORTED_FORMATS.contains(self),
TagType::VorbisComments => crate::ogg::VorbisComments::SUPPORTED_FORMATS.contains(self),
TagType::RiffInfo => crate::iff::wav::RIFFInfoList::SUPPORTED_FORMATS.contains(self),
TagType::AiffText => crate::iff::aiff::AIFFTextChunks::SUPPORTED_FORMATS.contains(self),
TagType::RiffInfo => crate::iff::wav::RiffInfoList::SUPPORTED_FORMATS.contains(self),
TagType::AiffText => crate::iff::aiff::AiffTextChunks::SUPPORTED_FORMATS.contains(self),
}
}

View file

@ -11,7 +11,7 @@ use lofty_attr::LoftyFile;
// Exports
pub use properties::{AiffCompressionType, AiffProperties};
pub use tag::{AIFFTextChunks, Comment};
pub use tag::{AiffTextChunks, Comment};
/// An AIFF file
#[derive(LoftyFile)]
@ -20,7 +20,7 @@ pub use tag::{AIFFTextChunks, Comment};
pub struct AiffFile {
/// Any text chunks included in the file
#[lofty(tag_type = "AiffText")]
pub(crate) text_chunks_tag: Option<AIFFTextChunks>,
pub(crate) text_chunks_tag: Option<AiffTextChunks>,
/// An ID3v2 tag
#[lofty(tag_type = "Id3v2")]
pub(crate) id3v2_tag: Option<Id3v2Tag>,

View file

@ -1,5 +1,5 @@
use super::properties::AiffProperties;
use super::tag::{AIFFTextChunks, Comment};
use super::tag::{AiffTextChunks, Comment};
use super::AiffFile;
use crate::config::ParseOptions;
use crate::error::Result;
@ -59,7 +59,7 @@ where
let mut comm = None;
let mut stream_len = 0;
let mut text_chunks = AIFFTextChunks::default();
let mut text_chunks = AiffTextChunks::default();
let mut annotations = Vec::new();
let mut comments = Vec::new();
@ -168,7 +168,7 @@ where
Ok(AiffFile {
properties,
text_chunks_tag: match text_chunks {
AIFFTextChunks {
AiffTextChunks {
name: None,
author: None,
copyright: None,

View file

@ -59,7 +59,7 @@ pub struct Comment {
/// Every item with the key [`ItemKey::Comment`] will be stored as an annotation.
#[derive(Default, Clone, Debug, PartialEq, Eq)]
#[tag(description = "`AIFF` text chunks", supported_formats(Aiff))]
pub struct AIFFTextChunks {
pub struct AiffTextChunks {
/// The name of the piece
pub name: Option<String>,
/// The author of the piece
@ -78,7 +78,7 @@ pub struct AIFFTextChunks {
pub comments: Option<Vec<Comment>>,
}
impl Accessor for AIFFTextChunks {
impl Accessor for AiffTextChunks {
fn artist(&self) -> Option<Cow<'_, str>> {
self.author.as_deref().map(Cow::Borrowed)
}
@ -120,16 +120,16 @@ impl Accessor for AIFFTextChunks {
}
}
impl AIFFTextChunks {
impl AiffTextChunks {
/// Create a new empty `AIFFTextChunks`
///
/// # Examples
///
/// ```rust
/// use lofty::iff::aiff::AIFFTextChunks;
/// use lofty::iff::aiff::AiffTextChunks;
/// use lofty::tag::TagExt;
///
/// let aiff_tag = AIFFTextChunks::new();
/// let aiff_tag = AiffTextChunks::new();
/// assert!(aiff_tag.is_empty());
/// ```
pub fn new() -> Self {
@ -152,7 +152,7 @@ impl AIFFTextChunks {
}
}
impl TagExt for AIFFTextChunks {
impl TagExt for AiffTextChunks {
type Err = LoftyError;
type RefKey<'a> = &'a ItemKey;
@ -182,7 +182,7 @@ impl TagExt for AIFFTextChunks {
fn is_empty(&self) -> bool {
matches!(
self,
AIFFTextChunks {
AiffTextChunks {
name: None,
author: None,
copyright: None,
@ -235,7 +235,7 @@ impl TagExt for AIFFTextChunks {
#[derive(Debug, Clone, Default)]
pub struct SplitTagRemainder;
impl SplitTag for AIFFTextChunks {
impl SplitTag for AiffTextChunks {
type Remainder = SplitTagRemainder;
fn split_tag(self) -> (Self::Remainder, Tag) {
@ -244,15 +244,15 @@ impl SplitTag for AIFFTextChunks {
}
impl MergeTag for SplitTagRemainder {
type Merged = AIFFTextChunks;
type Merged = AiffTextChunks;
fn merge_tag(self, tag: Tag) -> Self::Merged {
tag.into()
}
}
impl From<AIFFTextChunks> for Tag {
fn from(input: AIFFTextChunks) -> Self {
impl From<AiffTextChunks> for Tag {
fn from(input: AiffTextChunks) -> Self {
let mut tag = Self::new(TagType::AiffText);
let push_item = |field: Option<String>, item_key: ItemKey, tag: &mut Tag| {
@ -284,7 +284,7 @@ impl From<AIFFTextChunks> for Tag {
}
}
impl From<Tag> for AIFFTextChunks {
impl From<Tag> for AiffTextChunks {
fn from(mut input: Tag) -> Self {
let name = input.take_strings(&ItemKey::TrackTitle).next();
let author = input.take_strings(&ItemKey::TrackArtist).next();
@ -494,7 +494,7 @@ where
#[cfg(test)]
mod tests {
use crate::config::{ParseOptions, WriteOptions};
use crate::iff::aiff::{AIFFTextChunks, Comment};
use crate::iff::aiff::{AiffTextChunks, Comment};
use crate::prelude::*;
use crate::tag::{ItemValue, Tag, TagItem, TagType};
@ -502,7 +502,7 @@ mod tests {
#[test]
fn parse_aiff_text() {
let expected_tag = AIFFTextChunks {
let expected_tag = AiffTextChunks {
name: Some(String::from("Foo title")),
author: Some(String::from("Bar artist")),
copyright: Some(String::from("Baz copyright")),
@ -612,7 +612,7 @@ mod tests {
ItemValue::Text(String::from("Quux annotation")),
));
let aiff_text: AIFFTextChunks = tag.into();
let aiff_text: AiffTextChunks = tag.into();
assert_eq!(aiff_text.name, Some(String::from("Foo title")));
assert_eq!(aiff_text.author, Some(String::from("Bar artist")));

View file

@ -10,7 +10,7 @@ use lofty_attr::LoftyFile;
// Exports
pub use crate::iff::wav::properties::{WavFormat, WavProperties};
pub use tag::RIFFInfoList;
pub use tag::RiffInfoList;
/// A WAV file
#[derive(LoftyFile)]
@ -19,7 +19,7 @@ pub use tag::RIFFInfoList;
pub struct WavFile {
/// A RIFF INFO LIST
#[lofty(tag_type = "RiffInfo")]
pub(crate) riff_info_tag: Option<RIFFInfoList>,
pub(crate) riff_info_tag: Option<RiffInfoList>,
/// An ID3v2 tag
#[lofty(tag_type = "Id3v2")]
pub(crate) id3v2_tag: Option<Id3v2Tag>,

View file

@ -1,5 +1,5 @@
use super::properties::WavProperties;
use super::tag::RIFFInfoList;
use super::tag::RiffInfoList;
use super::WavFile;
use crate::config::ParseOptions;
use crate::error::Result;
@ -45,7 +45,7 @@ where
let mut total_samples = 0_u32;
let mut fmt = Vec::new();
let mut riff_info = RIFFInfoList::default();
let mut riff_info = RiffInfoList::default();
let mut id3v2_tag: Option<Id3v2Tag> = None;
let mut chunks = Chunks::<LittleEndian>::new(file_len);

View file

@ -47,21 +47,21 @@ macro_rules! impl_accessor {
/// * It has a key that is 4 bytes in length and within the ASCII range
#[derive(Default, Debug, PartialEq, Eq, Clone)]
#[tag(description = "A RIFF INFO LIST", supported_formats(Wav))]
pub struct RIFFInfoList {
pub struct RiffInfoList {
/// A collection of chunk-value pairs
pub(crate) items: Vec<(String, String)>,
}
impl RIFFInfoList {
impl RiffInfoList {
/// Create a new empty `RIFFInfoList`
///
/// # Examples
///
/// ```rust
/// use lofty::iff::wav::RIFFInfoList;
/// use lofty::iff::wav::RiffInfoList;
/// use lofty::tag::TagExt;
///
/// let riff_info_tag = RIFFInfoList::new();
/// let riff_info_tag = RiffInfoList::new();
/// assert!(riff_info_tag.is_empty());
/// ```
pub fn new() -> Self {
@ -109,7 +109,7 @@ impl RIFFInfoList {
}
}
impl Accessor for RIFFInfoList {
impl Accessor for RiffInfoList {
impl_accessor!(
artist => "IART";
title => "INAM";
@ -167,7 +167,7 @@ impl Accessor for RIFFInfoList {
}
}
impl IntoIterator for RIFFInfoList {
impl IntoIterator for RiffInfoList {
type Item = (String, String);
type IntoIter = std::vec::IntoIter<Self::Item>;
@ -176,7 +176,7 @@ impl IntoIterator for RIFFInfoList {
}
}
impl<'a> IntoIterator for &'a RIFFInfoList {
impl<'a> IntoIterator for &'a RiffInfoList {
type Item = &'a (String, String);
type IntoIter = std::slice::Iter<'a, (String, String)>;
@ -185,7 +185,7 @@ impl<'a> IntoIterator for &'a RIFFInfoList {
}
}
impl TagExt for RIFFInfoList {
impl TagExt for RiffInfoList {
type Err = LoftyError;
type RefKey<'a> = &'a str;
@ -239,7 +239,7 @@ impl TagExt for RIFFInfoList {
#[derive(Debug, Clone, Default)]
pub struct SplitTagRemainder;
impl SplitTag for RIFFInfoList {
impl SplitTag for RiffInfoList {
type Remainder = SplitTagRemainder;
fn split_tag(self) -> (Self::Remainder, Tag) {
@ -248,15 +248,15 @@ impl SplitTag for RIFFInfoList {
}
impl MergeTag for SplitTagRemainder {
type Merged = RIFFInfoList;
type Merged = RiffInfoList;
fn merge_tag(self, tag: Tag) -> Self::Merged {
tag.into()
}
}
impl From<RIFFInfoList> for Tag {
fn from(input: RIFFInfoList) -> Self {
impl From<RiffInfoList> for Tag {
fn from(input: RiffInfoList) -> Self {
let mut tag = Self::new(TagType::RiffInfo);
for (k, v) in input.items {
@ -272,9 +272,9 @@ impl From<RIFFInfoList> for Tag {
}
}
impl From<Tag> for RIFFInfoList {
impl From<Tag> for RiffInfoList {
fn from(input: Tag) -> Self {
let mut riff_info = RIFFInfoList::default();
let mut riff_info = RiffInfoList::default();
for item in input.items {
if let ItemValue::Text(val) | ItemValue::Locator(val) = item.item_value {
@ -356,7 +356,7 @@ pub(crate) fn tagitems_into_riff<'a>(
mod tests {
use crate::config::WriteOptions;
use crate::iff::chunk::Chunks;
use crate::iff::wav::RIFFInfoList;
use crate::iff::wav::RiffInfoList;
use crate::prelude::*;
use crate::tag::{Tag, TagType};
@ -366,7 +366,7 @@ mod tests {
#[test]
fn parse_riff_info() {
let mut expected_tag = RIFFInfoList::default();
let mut expected_tag = RiffInfoList::default();
expected_tag.insert(String::from("IART"), String::from("Bar artist"));
expected_tag.insert(String::from("ICMT"), String::from("Qux comment"));
@ -376,7 +376,7 @@ mod tests {
expected_tag.insert(String::from("IPRT"), String::from("1"));
let tag = crate::tag::utils::test_utils::read_path("tests/tags/assets/test.riff");
let mut parsed_tag = RIFFInfoList::default();
let mut parsed_tag = RiffInfoList::default();
super::read::parse_riff_info(
&mut Cursor::new(&tag[..]),
@ -392,7 +392,7 @@ mod tests {
#[test]
fn riff_info_re_read() {
let tag = crate::tag::utils::test_utils::read_path("tests/tags/assets/test.riff");
let mut parsed_tag = RIFFInfoList::default();
let mut parsed_tag = RiffInfoList::default();
super::read::parse_riff_info(
&mut Cursor::new(&tag[..]),
@ -407,7 +407,7 @@ mod tests {
.dump_to(&mut writer, WriteOptions::default())
.unwrap();
let mut temp_parsed_tag = RIFFInfoList::default();
let mut temp_parsed_tag = RiffInfoList::default();
// Remove the LIST....INFO from the tag
super::read::parse_riff_info(
@ -426,7 +426,7 @@ mod tests {
let tag_bytes = crate::tag::utils::test_utils::read_path("tests/tags/assets/test.riff");
let mut reader = std::io::Cursor::new(&tag_bytes[..]);
let mut riff_info = RIFFInfoList::default();
let mut riff_info = RiffInfoList::default();
super::read::parse_riff_info(
&mut reader,
@ -445,7 +445,7 @@ mod tests {
fn tag_to_riff_info() {
let tag = crate::tag::utils::test_utils::create_tag(TagType::RiffInfo);
let riff_info: RIFFInfoList = tag.into();
let riff_info: RiffInfoList = tag.into();
assert_eq!(riff_info.get("INAM"), Some("Foo title"));
assert_eq!(riff_info.get("IART"), Some("Bar artist"));

View file

@ -1,4 +1,4 @@
use super::RIFFInfoList;
use super::RiffInfoList;
use crate::error::Result;
use crate::iff::chunk::Chunks;
use crate::macros::decode_err;
@ -12,7 +12,7 @@ pub(in crate::iff::wav) fn parse_riff_info<R>(
data: &mut R,
chunks: &mut Chunks<LittleEndian>,
end: u64,
tag: &mut RIFFInfoList,
tag: &mut RiffInfoList,
) -> Result<()>
where
R: Read + Seek,

View file

@ -72,14 +72,14 @@ mod private {
use crate::ape::ApeTag;
use crate::id3::v1::Id3v1Tag;
use crate::id3::v2::Id3v2Tag;
use crate::iff::aiff::AIFFTextChunks;
use crate::iff::wav::RIFFInfoList;
use crate::iff::aiff::AiffTextChunks;
use crate::iff::wav::RiffInfoList;
use crate::ogg::VorbisComments;
use crate::tag::Tag;
pub trait Sealed {}
impl Sealed for AIFFTextChunks {}
impl Sealed for AiffTextChunks {}
impl Sealed for crate::iff::aiff::tag::SplitTagRemainder {}
impl Sealed for ApeTag {}
@ -94,7 +94,7 @@ mod private {
impl Sealed for crate::mp4::Ilst {}
impl Sealed for crate::mp4::ilst::SplitTagRemainder {}
impl Sealed for RIFFInfoList {}
impl Sealed for RiffInfoList {}
impl Sealed for crate::iff::wav::tag::SplitTagRemainder {}
impl Sealed for Tag {}

View file

@ -155,20 +155,20 @@ mod private {
use crate::ape::ApeTag;
use crate::id3::v1::Id3v1Tag;
use crate::id3::v2::Id3v2Tag;
use crate::iff::aiff::AIFFTextChunks;
use crate::iff::wav::RIFFInfoList;
use crate::iff::aiff::AiffTextChunks;
use crate::iff::wav::RiffInfoList;
use crate::mp4::Ilst;
use crate::ogg::VorbisComments;
use crate::tag::Tag;
pub trait Sealed {}
impl Sealed for AIFFTextChunks {}
impl Sealed for AiffTextChunks {}
impl Sealed for ApeTag {}
impl Sealed for Id3v1Tag {}
impl Sealed for Id3v2Tag {}
impl Sealed for Ilst {}
impl Sealed for RIFFInfoList {}
impl Sealed for RiffInfoList {}
impl Sealed for Tag {}
impl Sealed for VorbisComments {}
}