mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-11-10 14:44:22 +00:00
WAV: Properly capitalize RIFFInfoList
This commit is contained in:
parent
5a30964228
commit
f8b011bbba
10 changed files with 37 additions and 36 deletions
|
@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- **MP4**: `Ilst::track_number` has been moved to the `Accessor::track` implementation
|
- **MP4**: `Ilst::track_number` has been moved to the `Accessor::track` implementation
|
||||||
- **Tag**: Renamed `Tag::get_texts` to `Tag::get_strings`
|
- **Tag**: Renamed `Tag::get_texts` to `Tag::get_strings`
|
||||||
- **AIFF**: Renamed `AiffTextChunks` -> `AIFFTextChunks`
|
- **AIFF**: Renamed `AiffTextChunks` -> `AIFFTextChunks`
|
||||||
|
- **WAV**: Renamed `RiffInfoList` -> `RIFFInfoList`
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- **AIFF**: Fixed division by zero panic during property reading ([issue](https://github.com/Serial-ATA/lofty-rs/issues/56))
|
- **AIFF**: Fixed division by zero panic during property reading ([issue](https://github.com/Serial-ATA/lofty-rs/issues/56))
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use lofty::ape::ApeTag;
|
use lofty::ape::ApeTag;
|
||||||
use lofty::id3::v1::ID3v1Tag;
|
use lofty::id3::v1::ID3v1Tag;
|
||||||
use lofty::id3::v2::ID3v2Tag;
|
use lofty::id3::v2::ID3v2Tag;
|
||||||
use lofty::iff::{AIFFTextChunks, RiffInfoList};
|
use lofty::iff::{AIFFTextChunks, RIFFInfoList};
|
||||||
use lofty::mp4::Ilst;
|
use lofty::mp4::Ilst;
|
||||||
use lofty::ogg::VorbisComments;
|
use lofty::ogg::VorbisComments;
|
||||||
use lofty::{Accessor, TagExt};
|
use lofty::{Accessor, TagExt};
|
||||||
|
@ -27,7 +27,7 @@ bench_tag_write!(ape, ApeTag);
|
||||||
bench_tag_write!(id3v2, ID3v2Tag);
|
bench_tag_write!(id3v2, ID3v2Tag);
|
||||||
bench_tag_write!(id3v1, ID3v1Tag);
|
bench_tag_write!(id3v1, ID3v1Tag);
|
||||||
bench_tag_write!(ilst, Ilst);
|
bench_tag_write!(ilst, Ilst);
|
||||||
bench_tag_write!(riff_info, RiffInfoList);
|
bench_tag_write!(riff_info, RIFFInfoList);
|
||||||
bench_tag_write!(vorbis_comments, VorbisComments);
|
bench_tag_write!(vorbis_comments, VorbisComments);
|
||||||
|
|
||||||
fn bench_write(c: &mut Criterion) {
|
fn bench_write(c: &mut Criterion) {
|
||||||
|
|
|
@ -17,6 +17,6 @@ cfg_if::cfg_if! {
|
||||||
|
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(feature = "riff_info_list")] {
|
if #[cfg(feature = "riff_info_list")] {
|
||||||
pub use wav::tag::RiffInfoList;
|
pub use wav::tag::RIFFInfoList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ use std::io::{Read, Seek};
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(feature = "riff_info_list")] {
|
if #[cfg(feature = "riff_info_list")] {
|
||||||
pub(crate) mod tag;
|
pub(crate) mod tag;
|
||||||
use tag::RiffInfoList;
|
use tag::RIFFInfoList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ pub use crate::iff::wav::properties::{WavFormat, WavProperties};
|
||||||
pub struct WavFile {
|
pub struct WavFile {
|
||||||
#[cfg(feature = "riff_info_list")]
|
#[cfg(feature = "riff_info_list")]
|
||||||
/// A RIFF INFO LIST
|
/// A RIFF INFO LIST
|
||||||
pub(crate) riff_info: Option<RiffInfoList>,
|
pub(crate) riff_info: Option<RIFFInfoList>,
|
||||||
#[cfg(feature = "id3v2")]
|
#[cfg(feature = "id3v2")]
|
||||||
/// An ID3v2 tag
|
/// An ID3v2 tag
|
||||||
pub(crate) id3v2_tag: Option<ID3v2Tag>,
|
pub(crate) id3v2_tag: Option<ID3v2Tag>,
|
||||||
|
@ -94,6 +94,6 @@ impl WavFile {
|
||||||
id3v2_tag, ID3v2Tag;
|
id3v2_tag, ID3v2Tag;
|
||||||
|
|
||||||
#[cfg(feature = "riff_info_list")]
|
#[cfg(feature = "riff_info_list")]
|
||||||
riff_info, RiffInfoList
|
riff_info, RIFFInfoList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use super::properties::WavProperties;
|
use super::properties::WavProperties;
|
||||||
#[cfg(feature = "riff_info_list")]
|
#[cfg(feature = "riff_info_list")]
|
||||||
use super::tag::RiffInfoList;
|
use super::tag::RIFFInfoList;
|
||||||
use super::WavFile;
|
use super::WavFile;
|
||||||
use crate::error::{FileDecodingError, Result};
|
use crate::error::{FileDecodingError, Result};
|
||||||
use crate::file::FileType;
|
use crate::file::FileType;
|
||||||
|
@ -47,7 +47,7 @@ where
|
||||||
let mut fmt = Vec::new();
|
let mut fmt = Vec::new();
|
||||||
|
|
||||||
#[cfg(feature = "riff_info_list")]
|
#[cfg(feature = "riff_info_list")]
|
||||||
let mut riff_info = RiffInfoList::default();
|
let mut riff_info = RIFFInfoList::default();
|
||||||
#[cfg(feature = "id3v2")]
|
#[cfg(feature = "id3v2")]
|
||||||
let mut id3v2_tag: Option<ID3v2Tag> = None;
|
let mut id3v2_tag: Option<ID3v2Tag> = None;
|
||||||
|
|
||||||
|
|
|
@ -45,12 +45,12 @@ macro_rules! impl_accessor {
|
||||||
///
|
///
|
||||||
/// * The [`TagItem`] has a value other than [`ItemValue::Binary`](crate::ItemValue::Binary)
|
/// * The [`TagItem`] has a value other than [`ItemValue::Binary`](crate::ItemValue::Binary)
|
||||||
/// * It has a key that is 4 bytes in length and within the ASCII range
|
/// * It has a key that is 4 bytes in length and within the ASCII range
|
||||||
pub struct RiffInfoList {
|
pub struct RIFFInfoList {
|
||||||
/// A collection of chunk-value pairs
|
/// A collection of chunk-value pairs
|
||||||
pub(crate) items: Vec<(String, String)>,
|
pub(crate) items: Vec<(String, String)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RiffInfoList {
|
impl RIFFInfoList {
|
||||||
/// Get an item by key
|
/// Get an item by key
|
||||||
pub fn get(&self, key: &str) -> Option<&str> {
|
pub fn get(&self, key: &str) -> Option<&str> {
|
||||||
self.items
|
self.items
|
||||||
|
@ -90,7 +90,7 @@ impl RiffInfoList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Accessor for RiffInfoList {
|
impl Accessor for RIFFInfoList {
|
||||||
impl_accessor!(
|
impl_accessor!(
|
||||||
artist => "IART";
|
artist => "IART";
|
||||||
title => "INAM";
|
title => "INAM";
|
||||||
|
@ -132,7 +132,7 @@ impl Accessor for RiffInfoList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TagExt for RiffInfoList {
|
impl TagExt for RIFFInfoList {
|
||||||
type Err = LoftyError;
|
type Err = LoftyError;
|
||||||
|
|
||||||
fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
|
@ -144,12 +144,12 @@ impl TagExt for RiffInfoList {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_to(&self, file: &mut File) -> std::result::Result<(), Self::Err> {
|
fn save_to(&self, file: &mut File) -> std::result::Result<(), Self::Err> {
|
||||||
RiffInfoListRef::new(self.items.iter().map(|(k, v)| (k.as_str(), v.as_str())))
|
RIFFInfoListRef::new(self.items.iter().map(|(k, v)| (k.as_str(), v.as_str())))
|
||||||
.write_to(file)
|
.write_to(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dump_to<W: Write>(&self, writer: &mut W) -> std::result::Result<(), Self::Err> {
|
fn dump_to<W: Write>(&self, writer: &mut W) -> std::result::Result<(), Self::Err> {
|
||||||
RiffInfoListRef::new(self.items.iter().map(|(k, v)| (k.as_str(), v.as_str())))
|
RIFFInfoListRef::new(self.items.iter().map(|(k, v)| (k.as_str(), v.as_str())))
|
||||||
.dump_to(writer)
|
.dump_to(writer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,8 +166,8 @@ impl TagExt for RiffInfoList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<RiffInfoList> for Tag {
|
impl From<RIFFInfoList> for Tag {
|
||||||
fn from(input: RiffInfoList) -> Self {
|
fn from(input: RIFFInfoList) -> Self {
|
||||||
let mut tag = Tag::new(TagType::RIFFInfo);
|
let mut tag = Tag::new(TagType::RIFFInfo);
|
||||||
|
|
||||||
for (k, v) in input.items {
|
for (k, v) in input.items {
|
||||||
|
@ -183,9 +183,9 @@ impl From<RiffInfoList> for Tag {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Tag> for RiffInfoList {
|
impl From<Tag> for RIFFInfoList {
|
||||||
fn from(input: Tag) -> Self {
|
fn from(input: Tag) -> Self {
|
||||||
let mut riff_info = RiffInfoList::default();
|
let mut riff_info = RIFFInfoList::default();
|
||||||
|
|
||||||
for item in input.items {
|
for item in input.items {
|
||||||
if let ItemValue::Text(val) | ItemValue::Locator(val) = item.item_value {
|
if let ItemValue::Text(val) | ItemValue::Locator(val) = item.item_value {
|
||||||
|
@ -208,19 +208,19 @@ impl From<Tag> for RiffInfoList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct RiffInfoListRef<'a, I>
|
pub(crate) struct RIFFInfoListRef<'a, I>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = (&'a str, &'a str)>,
|
I: Iterator<Item = (&'a str, &'a str)>,
|
||||||
{
|
{
|
||||||
pub(crate) items: I,
|
pub(crate) items: I,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, I> RiffInfoListRef<'a, I>
|
impl<'a, I> RIFFInfoListRef<'a, I>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = (&'a str, &'a str)>,
|
I: Iterator<Item = (&'a str, &'a str)>,
|
||||||
{
|
{
|
||||||
pub(crate) fn new(items: I) -> RiffInfoListRef<'a, I> {
|
pub(crate) fn new(items: I) -> RIFFInfoListRef<'a, I> {
|
||||||
RiffInfoListRef { items }
|
RIFFInfoListRef { items }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn write_to(&mut self, file: &mut File) -> Result<()> {
|
pub(crate) fn write_to(&mut self, file: &mut File) -> Result<()> {
|
||||||
|
@ -254,7 +254,7 @@ pub(crate) fn tagitems_into_riff(items: &[TagItem]) -> impl Iterator<Item = (&st
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::iff::RiffInfoList;
|
use crate::iff::RIFFInfoList;
|
||||||
use crate::{Tag, TagExt, TagType};
|
use crate::{Tag, TagExt, TagType};
|
||||||
|
|
||||||
use crate::iff::chunk::Chunks;
|
use crate::iff::chunk::Chunks;
|
||||||
|
@ -263,7 +263,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_riff_info() {
|
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("IART"), String::from("Bar artist"));
|
||||||
expected_tag.insert(String::from("ICMT"), String::from("Qux comment"));
|
expected_tag.insert(String::from("ICMT"), String::from("Qux comment"));
|
||||||
|
@ -273,7 +273,7 @@ mod tests {
|
||||||
expected_tag.insert(String::from("IPRT"), String::from("1"));
|
expected_tag.insert(String::from("IPRT"), String::from("1"));
|
||||||
|
|
||||||
let tag = crate::tag::utils::test_utils::read_path("tests/tags/assets/test.riff");
|
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(
|
super::read::parse_riff_info(
|
||||||
&mut Cursor::new(&tag[..]),
|
&mut Cursor::new(&tag[..]),
|
||||||
|
@ -289,7 +289,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn riff_info_re_read() {
|
fn riff_info_re_read() {
|
||||||
let tag = crate::tag::utils::test_utils::read_path("tests/tags/assets/test.riff");
|
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(
|
super::read::parse_riff_info(
|
||||||
&mut Cursor::new(&tag[..]),
|
&mut Cursor::new(&tag[..]),
|
||||||
|
@ -302,7 +302,7 @@ mod tests {
|
||||||
let mut writer = Vec::new();
|
let mut writer = Vec::new();
|
||||||
parsed_tag.dump_to(&mut writer).unwrap();
|
parsed_tag.dump_to(&mut writer).unwrap();
|
||||||
|
|
||||||
let mut temp_parsed_tag = RiffInfoList::default();
|
let mut temp_parsed_tag = RIFFInfoList::default();
|
||||||
|
|
||||||
// Remove the LIST....INFO from the tag
|
// Remove the LIST....INFO from the tag
|
||||||
super::read::parse_riff_info(
|
super::read::parse_riff_info(
|
||||||
|
@ -321,7 +321,7 @@ mod tests {
|
||||||
let tag_bytes = crate::tag::utils::test_utils::read_path("tests/tags/assets/test.riff");
|
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 reader = std::io::Cursor::new(&tag_bytes[..]);
|
||||||
let mut riff_info = RiffInfoList::default();
|
let mut riff_info = RIFFInfoList::default();
|
||||||
|
|
||||||
super::read::parse_riff_info(
|
super::read::parse_riff_info(
|
||||||
&mut reader,
|
&mut reader,
|
||||||
|
@ -340,7 +340,7 @@ mod tests {
|
||||||
fn tag_to_riff_info() {
|
fn tag_to_riff_info() {
|
||||||
let tag = crate::tag::utils::test_utils::create_tag(TagType::RIFFInfo);
|
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("INAM"), Some("Foo title"));
|
||||||
assert_eq!(riff_info.get("IART"), Some("Bar artist"));
|
assert_eq!(riff_info.get("IART"), Some("Bar artist"));
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::RiffInfoList;
|
use super::RIFFInfoList;
|
||||||
use crate::error::{FileDecodingError, Result};
|
use crate::error::{FileDecodingError, Result};
|
||||||
use crate::file::FileType;
|
use crate::file::FileType;
|
||||||
use crate::iff::chunk::Chunks;
|
use crate::iff::chunk::Chunks;
|
||||||
|
@ -11,7 +11,7 @@ pub(in crate::iff::wav) fn parse_riff_info<R>(
|
||||||
data: &mut R,
|
data: &mut R,
|
||||||
chunks: &mut Chunks<LittleEndian>,
|
chunks: &mut Chunks<LittleEndian>,
|
||||||
end: u64,
|
end: u64,
|
||||||
tag: &mut RiffInfoList,
|
tag: &mut RIFFInfoList,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
where
|
where
|
||||||
R: Read + Seek,
|
R: Read + Seek,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::RiffInfoListRef;
|
use super::RIFFInfoListRef;
|
||||||
use crate::error::{ErrorKind, LoftyError, Result};
|
use crate::error::{ErrorKind, LoftyError, Result};
|
||||||
use crate::iff::chunk::Chunks;
|
use crate::iff::chunk::Chunks;
|
||||||
use crate::iff::wav::read::verify_wav;
|
use crate::iff::wav::read::verify_wav;
|
||||||
|
@ -10,7 +10,7 @@ use byteorder::{LittleEndian, WriteBytesExt};
|
||||||
|
|
||||||
pub(in crate::iff::wav) fn write_riff_info<'a, I>(
|
pub(in crate::iff::wav) fn write_riff_info<'a, I>(
|
||||||
data: &mut File,
|
data: &mut File,
|
||||||
tag: &mut RiffInfoListRef<'a, I>,
|
tag: &mut RIFFInfoListRef<'a, I>,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = (&'a str, &'a str)>,
|
I: Iterator<Item = (&'a str, &'a str)>,
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub(crate) fn write_to(data: &mut File, tag: &Tag) -> Result<()> {
|
||||||
match tag.tag_type() {
|
match tag.tag_type() {
|
||||||
#[cfg(feature = "riff_info_list")]
|
#[cfg(feature = "riff_info_list")]
|
||||||
TagType::RIFFInfo => {
|
TagType::RIFFInfo => {
|
||||||
super::tag::RiffInfoListRef::new(super::tag::tagitems_into_riff(tag.items()))
|
super::tag::RIFFInfoListRef::new(super::tag::tagitems_into_riff(tag.items()))
|
||||||
.write_to(data)
|
.write_to(data)
|
||||||
},
|
},
|
||||||
#[cfg(feature = "id3v2")]
|
#[cfg(feature = "id3v2")]
|
||||||
|
|
|
@ -16,7 +16,7 @@ use ape::tag::ApeTagRef;
|
||||||
#[cfg(feature = "aiff_text_chunks")]
|
#[cfg(feature = "aiff_text_chunks")]
|
||||||
use iff::aiff::tag::AiffTextChunksRef;
|
use iff::aiff::tag::AiffTextChunksRef;
|
||||||
#[cfg(feature = "riff_info_list")]
|
#[cfg(feature = "riff_info_list")]
|
||||||
use iff::wav::tag::RiffInfoListRef;
|
use iff::wav::tag::RIFFInfoListRef;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
@ -72,7 +72,7 @@ pub(crate) fn dump_tag<W: Write>(tag: &Tag, writer: &mut W) -> Result<()> {
|
||||||
.dump_to(writer)
|
.dump_to(writer)
|
||||||
},
|
},
|
||||||
#[cfg(feature = "riff_info_list")]
|
#[cfg(feature = "riff_info_list")]
|
||||||
TagType::RIFFInfo => RiffInfoListRef {
|
TagType::RIFFInfo => RIFFInfoListRef {
|
||||||
items: iff::wav::tag::tagitems_into_riff(tag.items()),
|
items: iff::wav::tag::tagitems_into_riff(tag.items()),
|
||||||
}
|
}
|
||||||
.dump_to(writer),
|
.dump_to(writer),
|
||||||
|
|
Loading…
Reference in a new issue