MP3: Rename MP3File to MPEGFile

This commit is contained in:
Serial 2022-07-24 16:25:08 -04:00
parent da45191187
commit 0805e6683b
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
24 changed files with 69 additions and 68 deletions

View file

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- **TaggedFile**: `tag{_mut}` no longer takes a reference to `TagType`
- **ID3v2**: `LanguageFrame`'s `lang` field has changed type - `String` -> `[u8; 3]`
- **MP3**: Renamed `MP3File` -> `MPEGFile`
## [0.7.3] - 2022-07-22

View file

@ -24,7 +24,7 @@ path = "fuzz_targets/filetype_from_buffer.rs"
[[bin]]
name = "mp3file_read_from"
path = "fuzz_targets/mp3file_read_from.rs"
path = "fuzz_targets/mpegfile_read_from.rs"
[[bin]]
name = "aifffile_read_from"

View file

@ -2,9 +2,9 @@
use std::io::Cursor;
use lofty::AudioFile;
use libfuzzer_sys::fuzz_target;
use lofty::AudioFile;
fuzz_target!(|data: Vec<u8>| {
let _ = lofty::mp3::Mp3File::read_from(&mut Cursor::new(data), false);
let _ = lofty::mp3::MPEGFile::read_from(&mut Cursor::new(data), false);
});

View file

@ -9,7 +9,7 @@ use syn::{
};
const LOFTY_FILE_TYPES: [&str; 10] = [
"AIFF", "APE", "FLAC", "MP3", "MP4", "Opus", "Vorbis", "Speex", "WAV", "WavPack",
"AIFF", "APE", "FLAC", "MPEG", "MP4", "Opus", "Vorbis", "Speex", "WAV", "WavPack",
];
#[proc_macro_derive(LoftyFile, attributes(lofty))]

View file

@ -53,7 +53,7 @@ macro_rules! impl_accessor {
/// ## Supported file types
///
/// * [`FileType::APE`](crate::FileType::APE)
/// * [`FileType::MP3`](crate::FileType::MP3)
/// * [`FileType::MP3`](crate::FileType::MPEG)
/// * [`FileType::WavPack`](crate::FileType::WavPack)
///
/// ## Item storage

View file

@ -23,7 +23,7 @@ where
let probe = Probe::new(data).guess_file_type()?;
match probe.file_type() {
Some(FileType::APE | FileType::MP3 | FileType::WavPack) => {},
Some(FileType::APE | FileType::MPEG | FileType::WavPack) => {},
_ => err!(UnsupportedTag),
}

View file

@ -68,7 +68,7 @@ impl TaggedFile {
/// # let path_to_mp3 = "tests/files/assets/minimal/full_test.mp3";
/// let mut tagged_file = lofty::read_from_path(path_to_mp3, true)?;
///
/// assert_eq!(tagged_file.file_type(), FileType::MP3);
/// assert_eq!(tagged_file.file_type(), FileType::MPEG);
/// # Ok(()) }
/// ```
pub fn file_type(&self) -> FileType {
@ -483,7 +483,7 @@ pub enum FileType {
AIFF,
APE,
FLAC,
MP3,
MPEG,
MP4,
Opus,
Vorbis,
@ -513,7 +513,7 @@ impl FileType {
/// ```rust
/// use lofty::{FileType, TagType};
///
/// let file_type = FileType::MP3;
/// let file_type = FileType::MPEG;
/// assert_eq!(file_type.primary_tag_type(), TagType::ID3v2);
/// ```
pub fn primary_tag_type(&self) -> TagType {
@ -523,12 +523,12 @@ impl FileType {
#[cfg(all(not(feature = "id3v2"), feature = "riff_info_list"))]
FileType::WAV => TagType::RIFFInfo,
#[cfg(all(not(feature = "id3v2"), feature = "id3v1"))]
FileType::MP3 => TagType::ID3v1,
FileType::MPEG => TagType::ID3v1,
#[cfg(all(not(feature = "id3v2"), not(feature = "id3v1"), feature = "ape"))]
FileType::MP3 => TagType::APE,
FileType::AIFF | FileType::MP3 | FileType::WAV => TagType::ID3v2,
FileType::MPEG => TagType::APE,
FileType::AIFF | FileType::MPEG | FileType::WAV => TagType::ID3v2,
#[cfg(all(not(feature = "ape"), feature = "id3v1"))]
FileType::MP3 | FileType::WavPack => TagType::ID3v1,
FileType::MPEG | FileType::WavPack => TagType::ID3v1,
FileType::APE | FileType::WavPack => TagType::APE,
FileType::FLAC | FileType::Opus | FileType::Vorbis | FileType::Speex => {
TagType::VorbisComments
@ -558,13 +558,13 @@ impl FileType {
/// ```rust
/// use lofty::{FileType, TagType};
///
/// let file_type = FileType::MP3;
/// let file_type = FileType::MPEG;
/// assert!(file_type.supports_tag_type(TagType::ID3v2));
/// ```
pub fn supports_tag_type(&self, tag_type: TagType) -> bool {
match self {
#[cfg(feature = "id3v2")]
FileType::AIFF | FileType::APE | FileType::MP3 | FileType::WAV
FileType::AIFF | FileType::APE | FileType::MPEG | FileType::WAV
if tag_type == TagType::ID3v2 =>
{
true
@ -572,9 +572,9 @@ impl FileType {
#[cfg(feature = "aiff_text_chunks")]
FileType::AIFF if tag_type == TagType::AIFFText => true,
#[cfg(feature = "id3v1")]
FileType::APE | FileType::MP3 | FileType::WavPack if tag_type == TagType::ID3v1 => true,
FileType::APE | FileType::MPEG | FileType::WavPack if tag_type == TagType::ID3v1 => true,
#[cfg(feature = "ape")]
FileType::APE | FileType::MP3 | FileType::WavPack if tag_type == TagType::APE => true,
FileType::APE | FileType::MPEG | FileType::WavPack if tag_type == TagType::APE => true,
#[cfg(feature = "vorbis_comments")]
FileType::Opus | FileType::FLAC | FileType::Vorbis | FileType::Speex => {
tag_type == TagType::VorbisComments
@ -605,7 +605,7 @@ impl FileType {
/// use lofty::FileType;
///
/// let extension = "mp3";
/// assert_eq!(FileType::from_ext(extension), Some(FileType::MP3));
/// assert_eq!(FileType::from_ext(extension), Some(FileType::MPEG));
/// ```
pub fn from_ext<E>(ext: E) -> Option<Self>
where
@ -616,7 +616,7 @@ impl FileType {
match ext.as_str() {
"ape" => Some(Self::APE),
"aiff" | "aif" | "afc" | "aifc" => Some(Self::AIFF),
"mp3" | "mp2" | "mp1" => Some(Self::MP3),
"mp3" | "mp2" | "mp1" => Some(Self::MPEG),
"wav" | "wave" => Some(Self::WAV),
"wv" => Some(Self::WavPack),
"opus" => Some(Self::Opus),
@ -648,7 +648,7 @@ impl FileType {
/// use std::path::Path;
///
/// let path = Path::new("path/to/my.mp3");
/// assert_eq!(FileType::from_path(path), Some(FileType::MP3));
/// assert_eq!(FileType::from_path(path), Some(FileType::MPEG));
/// ```
pub fn from_path<P>(path: P) -> Option<Self>
where
@ -733,7 +733,7 @@ impl FileType {
// Safe to index, since we return early on an empty buffer
match buf[0] {
77 if buf.starts_with(b"MAC") => Some(Self::APE),
255 if buf.len() >= 2 && verify_frame_sync([buf[0], buf[1]]) => Some(Self::MP3),
255 if buf.len() >= 2 && verify_frame_sync([buf[0], buf[1]]) => Some(Self::MPEG),
70 if buf.len() >= 12 && &buf[..4] == b"FORM" => {
let id = &buf[8..12];

View file

@ -41,7 +41,7 @@ macro_rules! impl_accessor {
/// ## Supported file types
///
/// * [`FileType::APE`](crate::FileType::APE)
/// * [`FileType::MP3`](crate::FileType::MP3)
/// * [`FileType::MP3`](crate::FileType::MPEG)
/// * [`FileType::WavPack`](crate::FileType::WavPack)
///
/// ## Conversions

View file

@ -15,7 +15,7 @@ pub(crate) fn write_id3v1(writer: &mut File, tag: &Id3v1TagRef<'_>) -> Result<()
let probe = Probe::new(writer).guess_file_type()?;
match probe.file_type() {
Some(FileType::APE | FileType::MP3 | FileType::WavPack) => {},
Some(FileType::APE | FileType::MPEG | FileType::WavPack) => {},
_ => err!(UnsupportedTag),
}

View file

@ -64,7 +64,7 @@ macro_rules! impl_accessor {
///
/// ## Supported file types
///
/// * [`FileType::MP3`](crate::FileType::MP3)
/// * [`FileType::MP3`](crate::FileType::MPEG)
/// * [`FileType::WAV`](crate::FileType::WAV)
/// * [`FileType::AIFF`](crate::FileType::AIFF)
/// * [`FileType::APE`](crate::FileType::APE) **(READ ONLY)**

View file

@ -42,7 +42,7 @@ pub(crate) fn write_id3v2<'a, I: Iterator<Item = FrameRef<'a>> + 'a>(
let data = probe.into_inner();
match file_type {
Some(FileType::APE | FileType::MP3 | FileType::FLAC) => {},
Some(FileType::APE | FileType::MPEG | FileType::FLAC) => {},
// Formats such as WAV and AIFF store the ID3v2 tag in an 'ID3 ' chunk rather than at the beginning of the file
Some(FileType::WAV) => {
tag.flags.footer = false;

View file

@ -91,7 +91,7 @@
//! ```rust
//! # use lofty::LoftyError;
//! # fn main() -> Result<(), LoftyError> {
//! use lofty::mp3::Mp3File;
//! use lofty::mp3::MPEGFile;
//! use lofty::{AudioFile, TagType};
//! use std::fs::File;
//!
@ -99,7 +99,7 @@
//! let mut file_content = File::open(path)?;
//!
//! // We are expecting an MP3 file
//! let mp3_file = Mp3File::read_from(&mut file_content, true)?;
//! let mp3_file = MPEGFile::read_from(&mut file_content, true)?;
//!
//! assert_eq!(mp3_file.properties().channels(), 2);
//!

View file

@ -309,7 +309,7 @@ impl XingHeader {
b"Xing" | b"Info" => {
if reader_len < 16 {
return Err(FileDecodingError::new(
FileType::MP3,
FileType::MPEG,
"Xing header has an invalid size (< 16)",
)
.into());
@ -336,7 +336,7 @@ impl XingHeader {
b"VBRI" => {
if reader_len < 32 {
return Err(FileDecodingError::new(
FileType::MP3,
FileType::MPEG,
"VBRI header has an invalid size (< 32)",
)
.into());

View file

@ -18,10 +18,10 @@ use crate::tag::TagType;
use lofty_attr::LoftyFile;
/// An MP3 file
#[derive(Default, LoftyFile)]
/// An MPEG file
#[derive(LoftyFile, Default)]
#[lofty(read_fn = "read::read_from")]
pub struct Mp3File {
pub struct MPEGFile {
/// An ID3v2 tag
#[cfg(feature = "id3v2")]
#[lofty(tag_type = "ID3v2")]

View file

@ -1,5 +1,5 @@
use super::header::{cmp_header, search_for_frame_sync, Header, HeaderCmpResult, XingHeader};
use super::{Mp3File, Mp3Properties};
use super::{MPEGFile, Mp3Properties};
use crate::ape::constants::APE_PREAMBLE;
use crate::ape::header::read_ape_header;
#[cfg(feature = "ape")]
@ -16,11 +16,11 @@ use std::io::{Read, Seek, SeekFrom};
use byteorder::{BigEndian, ReadBytesExt};
pub(super) fn read_from<R>(reader: &mut R, read_properties: bool) -> Result<Mp3File>
pub(super) fn read_from<R>(reader: &mut R, read_properties: bool) -> Result<MPEGFile>
where
R: Read + Seek,
{
let mut file = Mp3File::default();
let mut file = MPEGFile::default();
let mut first_frame_offset = 0;
let mut first_frame_header = None;
@ -141,7 +141,7 @@ where
None => {
// The search for sync bits was unsuccessful
return Err(FileDecodingError::new(
FileType::MP3,
FileType::MPEG,
"File contains an invalid frame",
)
.into());
@ -149,7 +149,7 @@ where
};
if first_frame_header.sample_rate == 0 {
return Err(FileDecodingError::new(FileType::MP3, "Sample rate is 0").into());
return Err(FileDecodingError::new(FileType::MPEG, "Sample rate is 0").into());
}
let first_frame_offset = first_frame_offset;

View file

@ -6,7 +6,7 @@ use crate::iff::aiff::AiffFile;
use crate::iff::wav::WavFile;
use crate::macros::err;
use crate::mp3::header::search_for_frame_sync;
use crate::mp3::Mp3File;
use crate::mp3::MPEGFile;
use crate::mp4::Mp4File;
use crate::ogg::opus::OpusFile;
use crate::ogg::speex::SpeexFile;
@ -36,7 +36,7 @@ use std::path::Path;
/// let probe = Probe::open("path/to/my.mp3")?;
///
/// // Inferred from the `mp3` extension
/// assert_eq!(probe.file_type(), Some(FileType::MP3));
/// assert_eq!(probe.file_type(), Some(FileType::MPEG));
/// # Ok(())
/// # }
/// ```
@ -52,7 +52,7 @@ use std::path::Path;
/// let probe = Probe::open("path/to/my.mp3")?.guess_file_type()?;
///
/// // Inferred from the file's content
/// assert_eq!(probe.file_type(), Some(FileType::MP3));
/// assert_eq!(probe.file_type(), Some(FileType::MPEG));
/// # Ok(())
/// # }
/// ```
@ -126,7 +126,7 @@ impl<R: Read> Probe<R> {
/// let file = File::open(my_mp3_path)?;
/// let reader = BufReader::new(file);
///
/// let probe = Probe::with_file_type(reader, FileType::MP3);
/// let probe = Probe::with_file_type(reader, FileType::MPEG);
/// # Ok(()) }
/// ```
pub fn with_file_type(reader: R, file_type: FileType) -> Self {
@ -166,9 +166,9 @@ impl<R: Read> Probe<R> {
/// let mut probe = Probe::new(reader);
/// assert_eq!(probe.file_type(), None);
///
/// probe.set_file_type(FileType::MP3);
/// probe.set_file_type(FileType::MPEG);
///
/// assert_eq!(probe.file_type(), Some(FileType::MP3));
/// assert_eq!(probe.file_type(), Some(FileType::MPEG));
/// # Ok(()) }
/// ```
pub fn set_file_type(&mut self, file_type: FileType) {
@ -213,7 +213,7 @@ impl Probe<BufReader<File>> {
/// let probe = Probe::open("path/to/my.mp3")?;
///
/// // Guessed from the "mp3" extension, see `FileType::from_ext`
/// assert_eq!(probe.file_type(), Some(FileType::MP3));
/// assert_eq!(probe.file_type(), Some(FileType::MPEG));
/// # Ok(()) }
/// ```
pub fn open<P>(path: P) -> Result<Self>
@ -252,7 +252,7 @@ impl<R: Read + Seek> Probe<R> {
/// let probe = Probe::new(reader).guess_file_type()?;
///
/// // Determined the file is MP3 from the content
/// assert_eq!(probe.file_type(), Some(FileType::MP3));
/// assert_eq!(probe.file_type(), Some(FileType::MPEG));
/// # Ok(()) }
/// ```
pub fn guess_file_type(mut self) -> std::io::Result<Self> {
@ -302,7 +302,7 @@ impl<R: Read + Seek> Probe<R> {
b"fLaC" => Ok(Some(FileType::FLAC)),
// Search for a frame sync, which may be preceded by junk
_ if search_for_frame_sync(&mut self.inner)?.is_some() => {
Ok(Some(FileType::MP3))
Ok(Some(FileType::MPEG))
},
_ => Ok(None),
};
@ -365,7 +365,7 @@ impl<R: Read + Seek> Probe<R> {
FileType::AIFF => AiffFile::read_from(reader, read_properties)?.into(),
FileType::APE => ApeFile::read_from(reader, read_properties)?.into(),
FileType::FLAC => FlacFile::read_from(reader, read_properties)?.into(),
FileType::MP3 => Mp3File::read_from(reader, read_properties)?.into(),
FileType::MPEG => MPEGFile::read_from(reader, read_properties)?.into(),
FileType::Opus => OpusFile::read_from(reader, read_properties)?.into(),
FileType::Vorbis => VorbisFile::read_from(reader, read_properties)?.into(),
FileType::WAV => WavFile::read_from(reader, read_properties)?.into(),
@ -473,7 +473,7 @@ mod tests {
let data: Vec<u8> = data.into_iter().flatten().copied().collect();
let data = std::io::Cursor::new(&data);
let probe = Probe::new(data).guess_file_type().unwrap();
assert_eq!(probe.file_type(), Some(FileType::MP3));
assert_eq!(probe.file_type(), Some(FileType::MPEG));
}
fn test_probe(path: &str, expected_file_type_guess: FileType) {
@ -516,7 +516,7 @@ mod tests {
#[test]
fn probe_mp3_with_id3v2() {
test_probe("tests/files/assets/minimal/full_test.mp3", FileType::MP3);
test_probe("tests/files/assets/minimal/full_test.mp3", FileType::MPEG);
}
#[test]

View file

@ -62,7 +62,7 @@ mod tests {
use crate::ape::{ApeFile, ApeProperties};
use crate::flac::FlacFile;
use crate::iff::{AiffFile, WavFile, WavFormat, WavProperties};
use crate::mp3::{ChannelMode, Emphasis, Layer, Mp3File, Mp3Properties, MpegVersion};
use crate::mp3::{ChannelMode, Emphasis, Layer, MPEGFile, Mp3Properties, MpegVersion};
use crate::mp4::{AudioObjectType, Mp4Codec, Mp4File, Mp4Properties};
use crate::ogg::{
OpusFile, OpusProperties, SpeexFile, SpeexProperties, VorbisFile, VorbisProperties,
@ -287,7 +287,7 @@ mod tests {
#[test]
fn mp1_properties() {
assert_eq!(
get_properties::<Mp3File>("tests/files/assets/minimal/full_test.mp1"),
get_properties::<MPEGFile>("tests/files/assets/minimal/full_test.mp1"),
MP1_PROPERTIES
)
}
@ -295,7 +295,7 @@ mod tests {
#[test]
fn mp2_properties() {
assert_eq!(
get_properties::<Mp3File>("tests/files/assets/minimal/full_test.mp2"),
get_properties::<MPEGFile>("tests/files/assets/minimal/full_test.mp2"),
MP2_PROPERTIES
)
}
@ -303,7 +303,7 @@ mod tests {
#[test]
fn mp3_properties() {
assert_eq!(
get_properties::<Mp3File>("tests/files/assets/minimal/full_test.mp3"),
get_properties::<MPEGFile>("tests/files/assets/minimal/full_test.mp3"),
MP3_PROPERTIES
)
}

View file

@ -31,7 +31,7 @@ pub(crate) fn write_tag(tag: &Tag, file: &mut File, file_type: FileType) -> Resu
FileType::FLAC | FileType::Opus | FileType::Speex | FileType::Vorbis => {
crate::ogg::write::write_to(file, tag, file_type)
},
FileType::MP3 => mp3::write::write_to(file, tag),
FileType::MPEG => mp3::write::write_to(file, tag),
#[cfg(feature = "mp4_ilst")]
FileType::MP4 => {
crate::mp4::ilst::write::write_to(file, &mut Into::<Ilst>::into(tag.clone()).as_ref())

View file

@ -7,7 +7,7 @@ fn read() {
// Here we have an MP3 file with an ID3v2, ID3v1, and an APEv2 tag
let file = lofty::read_from_path("tests/files/assets/minimal/full_test.mp3", false).unwrap();
assert_eq!(file.file_type(), FileType::MP3);
assert_eq!(file.file_type(), FileType::MPEG);
// Verify the ID3v2 tag first
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
@ -26,7 +26,7 @@ fn read_with_junk_bytes_between_frames() {
lofty::read_from_path("tests/files/assets/junk_between_id3_and_mp3.mp3", true).unwrap();
// note that the file contains ID3v2 and ID3v1 data
assert_eq!(file.file_type(), FileType::MP3);
assert_eq!(file.file_type(), FileType::MPEG);
let id3v2_tag = &file.tags()[0];
assert_eq!(id3v2_tag.artist(), Some("artist test"));
@ -49,7 +49,7 @@ fn write() {
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
assert_eq!(tagged_file.file_type(), FileType::MP3);
assert_eq!(tagged_file.file_type(), FileType::MPEG);
// ID3v2
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");

View file

@ -1,7 +1,7 @@
use lofty::ape::ApeFile;
use lofty::flac::FlacFile;
use lofty::iff::{AiffFile, WavFile};
use lofty::mp3::Mp3File;
use lofty::mp3::MPEGFile;
use lofty::mp4::Mp4File;
use lofty::AudioFile;
@ -46,9 +46,9 @@ fn zero_audio_flac() {
fn zero_audio_mp3() {
let path = "tests/files/assets/zero/zero.mp3";
// A zero-size MP3 will error, since we need MPEG frames to extract audio properties
assert!(!read_file_with_properties::<Mp3File>(path));
assert!(!read_file_with_properties::<MPEGFile>(path));
assert!(read_file_no_properties::<Mp3File>(path))
assert!(read_file_no_properties::<MPEGFile>(path))
}
#[test]

View file

@ -6,8 +6,8 @@ use std::time::Instant;
mod aifffile_read_from;
mod flacfile_read_from;
mod mp3file_read_from;
mod mp4file_read_from;
mod mpegfile_read_from;
mod opusfile_read_from;
mod pictureinformation_from_jpeg;
mod pictureinformation_from_png;

View file

@ -1,7 +0,0 @@
use crate::oom_test;
use lofty::mp3::Mp3File;
#[test]
fn oom1() {
oom_test::<Mp3File>("mp3file_read_from/oom-f8730cbfa5682ab12343ccb70de9b71a061ef4d0");
}

View file

@ -0,0 +1,7 @@
use crate::oom_test;
use lofty::mp3::MPEGFile;
#[test]
fn oom1() {
oom_test::<MPEGFile>("mpegfile_read_from/oom-f8730cbfa5682ab12343ccb70de9b71a061ef4d0");
}