mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-12 05:32:38 +00:00
file: Switch FileType
variants to UpperCamelCase
This commit is contained in:
parent
55ba9dccc1
commit
8920a39f93
44 changed files with 176 additions and 176 deletions
|
@ -18,7 +18,7 @@ byteorder = "1.4.3"
|
|||
# ID3 compressed frames
|
||||
flate2 = { version = "1.0.25", optional = true }
|
||||
# Proc macros
|
||||
lofty_attr = "0.6.0"
|
||||
lofty_attr = { path = "lofty_attr" }
|
||||
# Debug logging
|
||||
log = "0.4.17"
|
||||
# OGG Vorbis/Opus
|
||||
|
|
|
@ -10,10 +10,10 @@ pub(crate) fn opt_internal_file_type(
|
|||
struct_name: String,
|
||||
) -> Option<(proc_macro2::TokenStream, bool)> {
|
||||
const LOFTY_FILE_TYPES: [&str; 11] = [
|
||||
"AAC", "AIFF", "APE", "FLAC", "MPEG", "MP4", "Opus", "Vorbis", "Speex", "WAV", "WavPack",
|
||||
"Aac", "Aiff", "Ape", "Flac", "Mpeg", "Mp4", "Opus", "Vorbis", "Speex", "Wav", "WavPack",
|
||||
];
|
||||
|
||||
const ID3V2_STRIPPABLE: [&str; 2] = ["FLAC", "APE"];
|
||||
const ID3V2_STRIPPABLE: [&str; 2] = ["Flac", "Ape"];
|
||||
|
||||
let stripped = struct_name.strip_suffix("File");
|
||||
if let Some(prefix) = stripped {
|
||||
|
|
|
@ -81,7 +81,7 @@ impl ADTSHeader {
|
|||
let sample_rate_idx = (byte3 >> 2) & 0b1111;
|
||||
if sample_rate_idx == 15 {
|
||||
// 15 is forbidden
|
||||
decode_err!(@BAIL AAC, "File contains an invalid sample frequency index");
|
||||
decode_err!(@BAIL Aac, "File contains an invalid sample frequency index");
|
||||
}
|
||||
|
||||
let sample_rate = SAMPLE_RATES[sample_rate_idx as usize];
|
||||
|
|
|
@ -19,7 +19,7 @@ pub use properties::AACProperties;
|
|||
#[derive(LoftyFile, Default)]
|
||||
#[lofty(read_fn = "read::read_from")]
|
||||
#[lofty(internal_write_module_do_not_use_anywhere_else)]
|
||||
pub struct AACFile {
|
||||
pub struct AacFile {
|
||||
#[lofty(tag_type = "ID3v2")]
|
||||
pub(crate) id3v2_tag: Option<ID3v2Tag>,
|
||||
#[lofty(tag_type = "ID3v1")]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::header::{ADTSHeader, HEADER_MASK};
|
||||
use super::AACFile;
|
||||
use super::AacFile;
|
||||
use crate::error::Result;
|
||||
use crate::id3::v2::read::parse_id3v2;
|
||||
use crate::id3::v2::read_id3v2_header;
|
||||
|
@ -13,13 +13,13 @@ use std::io::{Read, Seek, SeekFrom};
|
|||
use byteorder::ReadBytesExt;
|
||||
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
pub(super) fn read_from<R>(reader: &mut R, parse_options: ParseOptions) -> Result<AACFile>
|
||||
pub(super) fn read_from<R>(reader: &mut R, parse_options: ParseOptions) -> Result<AacFile>
|
||||
where
|
||||
R: Read + Seek,
|
||||
{
|
||||
let parse_mode = parse_options.parsing_mode;
|
||||
|
||||
let mut file = AACFile::default();
|
||||
let mut file = AacFile::default();
|
||||
|
||||
let mut first_frame_header = None;
|
||||
let mut first_frame_end = 0;
|
||||
|
@ -97,18 +97,18 @@ where
|
|||
let mut first_frame_header = match first_frame_header {
|
||||
Some(header) => header,
|
||||
// The search for sync bits was unsuccessful
|
||||
None => decode_err!(@BAIL MPEG, "File contains an invalid frame"),
|
||||
None => decode_err!(@BAIL Mpeg, "File contains an invalid frame"),
|
||||
};
|
||||
|
||||
if first_frame_header.sample_rate == 0 {
|
||||
parse_mode_choice!(
|
||||
parse_mode,
|
||||
STRICT: decode_err!(@BAIL MPEG, "Sample rate is 0"),
|
||||
STRICT: decode_err!(@BAIL Mpeg, "Sample rate is 0"),
|
||||
);
|
||||
}
|
||||
|
||||
if first_frame_header.bitrate == 0 {
|
||||
parse_mode_choice!(parse_mode, STRICT: decode_err!(@BAIL MPEG, "Bitrate is 0"),);
|
||||
parse_mode_choice!(parse_mode, STRICT: decode_err!(@BAIL Mpeg, "Bitrate is 0"),);
|
||||
}
|
||||
|
||||
// Read as many frames as we can to try and fine the average bitrate
|
||||
|
|
|
@ -24,7 +24,7 @@ where
|
|||
if size < 32 {
|
||||
// If the size is < 32, something went wrong during encoding
|
||||
// The size includes the footer and all items
|
||||
decode_err!(@BAIL APE, "APE tag has an invalid size (< 32)");
|
||||
decode_err!(@BAIL Ape, "APE tag has an invalid size (< 32)");
|
||||
}
|
||||
|
||||
let item_count = data.read_u32::<LittleEndian>()?;
|
||||
|
@ -46,7 +46,7 @@ where
|
|||
|
||||
#[allow(unstable_name_collisions)]
|
||||
if u64::from(size) > data.stream_len()? {
|
||||
decode_err!(@BAIL APE, "APE tag has an invalid size (> file size)");
|
||||
decode_err!(@BAIL Ape, "APE tag has an invalid size (> file size)");
|
||||
}
|
||||
|
||||
Ok(ApeHeader { size, item_count })
|
||||
|
|
|
@ -82,7 +82,7 @@ where
|
|||
{
|
||||
let version = data
|
||||
.read_u16::<LittleEndian>()
|
||||
.map_err(|_| decode_err!(APE, "Unable to read APE tag version"))?;
|
||||
.map_err(|_| decode_err!(Ape, "Unable to read APE tag version"))?;
|
||||
|
||||
// Property reading differs between versions
|
||||
if version >= 3980 {
|
||||
|
@ -105,7 +105,7 @@ where
|
|||
let mut descriptor = [0; 46];
|
||||
data.read_exact(&mut descriptor).map_err(|_| {
|
||||
decode_err!(
|
||||
APE,
|
||||
Ape,
|
||||
"Not enough data left in reader to finish file descriptor"
|
||||
)
|
||||
})?;
|
||||
|
@ -124,7 +124,7 @@ where
|
|||
// Move on to the header
|
||||
let mut header = [0; 24];
|
||||
data.read_exact(&mut header)
|
||||
.map_err(|_| decode_err!(APE, "Not enough data left in reader to finish MAC header"))?;
|
||||
.map_err(|_| decode_err!(Ape, "Not enough data left in reader to finish MAC header"))?;
|
||||
|
||||
// Skip the first 4 bytes of the header
|
||||
// Compression type (2)
|
||||
|
@ -136,7 +136,7 @@ where
|
|||
let total_frames = header_read.read_u32::<LittleEndian>()?;
|
||||
|
||||
if total_frames == 0 {
|
||||
decode_err!(@BAIL APE, "File contains no frames");
|
||||
decode_err!(@BAIL Ape, "File contains no frames");
|
||||
}
|
||||
|
||||
let bits_per_sample = header_read.read_u16::<LittleEndian>()?;
|
||||
|
@ -144,7 +144,7 @@ where
|
|||
let channels = header_read.read_u16::<LittleEndian>()?;
|
||||
|
||||
if !(1..=32).contains(&channels) {
|
||||
decode_err!(@BAIL APE, "File has an invalid channel count (must be between 1 and 32 inclusive)");
|
||||
decode_err!(@BAIL Ape, "File has an invalid channel count (must be between 1 and 32 inclusive)");
|
||||
}
|
||||
|
||||
let sample_rate = header_read.read_u32::<LittleEndian>()?;
|
||||
|
@ -181,7 +181,7 @@ where
|
|||
// Versions < 3980 don't have a descriptor
|
||||
let mut header = [0; 26];
|
||||
data.read_exact(&mut header)
|
||||
.map_err(|_| decode_err!(APE, "Not enough data left in reader to finish MAC header"))?;
|
||||
.map_err(|_| decode_err!(Ape, "Not enough data left in reader to finish MAC header"))?;
|
||||
|
||||
// We don't need all the header data, so just make 2 slices
|
||||
let header_first = &mut &header[..8];
|
||||
|
@ -212,7 +212,7 @@ where
|
|||
let channels = header_first.read_u16::<LittleEndian>()?;
|
||||
|
||||
if !(1..=32).contains(&channels) {
|
||||
decode_err!(@BAIL APE, "File has an invalid channel count (must be between 1 and 32 inclusive)");
|
||||
decode_err!(@BAIL Ape, "File has an invalid channel count (must be between 1 and 32 inclusive)");
|
||||
}
|
||||
|
||||
let sample_rate = header_first.read_u32::<LittleEndian>()?;
|
||||
|
@ -221,7 +221,7 @@ where
|
|||
let total_frames = header_second.read_u32::<LittleEndian>()?;
|
||||
|
||||
if total_frames == 0 {
|
||||
decode_err!(@BAIL APE, "File contains no frames");
|
||||
decode_err!(@BAIL Ape, "File contains no frames");
|
||||
}
|
||||
|
||||
let final_frame_blocks = data.read_u32::<LittleEndian>()?;
|
||||
|
|
|
@ -64,13 +64,13 @@ where
|
|||
let mut remaining = [0; 4];
|
||||
data.read_exact(&mut remaining).map_err(|_| {
|
||||
decode_err!(
|
||||
APE,
|
||||
Ape,
|
||||
"Found partial APE tag, but there isn't enough data left in the reader"
|
||||
)
|
||||
})?;
|
||||
|
||||
if &remaining[..4] != b"AGEX" {
|
||||
decode_err!(@BAIL APE, "Found incomplete APE tag");
|
||||
decode_err!(@BAIL Ape, "Found incomplete APE tag");
|
||||
}
|
||||
|
||||
let ape_header = read_ape_header(data, false)?;
|
||||
|
@ -80,7 +80,7 @@ where
|
|||
ape_tag = Some(ape);
|
||||
},
|
||||
_ => {
|
||||
decode_err!(@BAIL APE, "Invalid data found while reading header, expected any of [\"MAC \", \"APETAGEX\", \"ID3\"]")
|
||||
decode_err!(@BAIL Ape, "Invalid data found while reading header, expected any of [\"MAC \", \"APETAGEX\", \"ID3\"]")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,15 +28,15 @@ impl ApeItem {
|
|||
/// * `key` contains invalid characters (must be in the range 0x20 to 0x7E, inclusive)
|
||||
pub fn new(key: String, value: ItemValue) -> Result<Self> {
|
||||
if INVALID_KEYS.contains(&&*key.to_uppercase()) {
|
||||
decode_err!(@BAIL APE, "APE tag item contains an illegal key");
|
||||
decode_err!(@BAIL Ape, "APE tag item contains an illegal key");
|
||||
}
|
||||
|
||||
if !(2..=255).contains(&key.len()) {
|
||||
decode_err!(@BAIL APE, "APE tag item key has an invalid length (< 2 || > 255)");
|
||||
decode_err!(@BAIL Ape, "APE tag item key has an invalid length (< 2 || > 255)");
|
||||
}
|
||||
|
||||
if key.chars().any(|c| !(0x20..=0x7E).contains(&(c as u32))) {
|
||||
decode_err!(@BAIL APE, "APE tag item key contains invalid characters");
|
||||
decode_err!(@BAIL Ape, "APE tag item key contains invalid characters");
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
|
@ -74,7 +74,7 @@ impl TryFrom<TagItem> for ApeItem {
|
|||
value
|
||||
.item_key
|
||||
.map_key(TagType::APE, false)
|
||||
.ok_or_else(|| decode_err!(APE, "Attempted to convert an unsupported item key"))?
|
||||
.ok_or_else(|| decode_err!(Ape, "Attempted to convert an unsupported item key"))?
|
||||
.to_string(),
|
||||
value.item_value,
|
||||
)
|
||||
|
|
|
@ -67,7 +67,7 @@ macro_rules! impl_accessor {
|
|||
/// When converting pictures, any of type [`PictureType::Undefined`](crate::PictureType::Undefined) will be discarded.
|
||||
/// For items, see [`ApeItem::new`].
|
||||
#[derive(Default, Debug, PartialEq, Eq, Clone)]
|
||||
#[tag(description = "An `APE` tag", supported_formats(APE, MPEG, WavPack))]
|
||||
#[tag(description = "An `APE` tag", supported_formats(Ape, Mpeg, WavPack))]
|
||||
pub struct ApeTag {
|
||||
/// Whether or not to mark the tag as read only
|
||||
pub read_only: bool,
|
||||
|
|
|
@ -39,10 +39,10 @@ where
|
|||
}
|
||||
|
||||
let key = String::from_utf8(key)
|
||||
.map_err(|_| decode_err!(APE, "APE tag item contains a non UTF-8 key"))?;
|
||||
.map_err(|_| decode_err!(Ape, "APE tag item contains a non UTF-8 key"))?;
|
||||
|
||||
if INVALID_KEYS.contains(&&*key.to_uppercase()) {
|
||||
decode_err!(@BAIL APE, "APE tag item contains an illegal key");
|
||||
decode_err!(@BAIL Ape, "APE tag item contains an illegal key");
|
||||
}
|
||||
|
||||
let read_only = (flags & 1) == 1;
|
||||
|
@ -58,13 +58,13 @@ where
|
|||
|
||||
let parsed_value = match item_type {
|
||||
0 => ItemValue::Text(String::from_utf8(value).map_err(|_| {
|
||||
decode_err!(APE, "Failed to convert text item into a UTF-8 string")
|
||||
decode_err!(Ape, "Failed to convert text item into a UTF-8 string")
|
||||
})?),
|
||||
1 => ItemValue::Binary(value),
|
||||
2 => ItemValue::Locator(String::from_utf8(value).map_err(|_| {
|
||||
decode_err!(APE, "Failed to convert locator item into a UTF-8 string")
|
||||
decode_err!(Ape, "Failed to convert locator item into a UTF-8 string")
|
||||
})?),
|
||||
_ => decode_err!(@BAIL APE, "APE tag item contains an invalid item type"),
|
||||
_ => decode_err!(@BAIL Ape, "APE tag item contains an invalid item type"),
|
||||
};
|
||||
|
||||
let mut item = ApeItem::new(key, parsed_value)?;
|
||||
|
|
|
@ -96,7 +96,7 @@ where
|
|||
if let Some(start) = start.checked_sub(size as usize) {
|
||||
ape_tag_location = Some(start..start + size as usize);
|
||||
} else {
|
||||
decode_err!(@BAIL APE, "File has a tag with an invalid size");
|
||||
decode_err!(@BAIL Ape, "File has a tag with an invalid size");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
76
src/file.rs
76
src/file.rs
|
@ -99,7 +99,7 @@ pub trait TaggedFileExt {
|
|||
/// # let path_to_mp3 = "tests/files/assets/minimal/full_test.mp3";
|
||||
/// let mut tagged_file = lofty::read_from_path(path_to_mp3)?;
|
||||
///
|
||||
/// assert_eq!(tagged_file.file_type(), FileType::MPEG);
|
||||
/// assert_eq!(tagged_file.file_type(), FileType::Mpeg);
|
||||
/// # Ok(()) }
|
||||
/// ```
|
||||
fn file_type(&self) -> FileType;
|
||||
|
@ -714,16 +714,16 @@ impl AudioFile for BoundTaggedFile {
|
|||
#[allow(missing_docs)]
|
||||
#[non_exhaustive]
|
||||
pub enum FileType {
|
||||
AAC,
|
||||
AIFF,
|
||||
APE,
|
||||
FLAC,
|
||||
MPEG,
|
||||
MP4,
|
||||
Aac,
|
||||
Aiff,
|
||||
Ape,
|
||||
Flac,
|
||||
Mpeg,
|
||||
Mp4,
|
||||
Opus,
|
||||
Vorbis,
|
||||
Speex,
|
||||
WAV,
|
||||
Wav,
|
||||
WavPack,
|
||||
Custom(&'static str),
|
||||
}
|
||||
|
@ -747,17 +747,17 @@ impl FileType {
|
|||
/// ```rust
|
||||
/// use lofty::{FileType, TagType};
|
||||
///
|
||||
/// let file_type = FileType::MPEG;
|
||||
/// let file_type = FileType::Mpeg;
|
||||
/// assert_eq!(file_type.primary_tag_type(), TagType::ID3v2);
|
||||
/// ```
|
||||
pub fn primary_tag_type(&self) -> TagType {
|
||||
match self {
|
||||
FileType::AIFF | FileType::MPEG | FileType::WAV | FileType::AAC => TagType::ID3v2,
|
||||
FileType::APE | FileType::WavPack => TagType::APE,
|
||||
FileType::FLAC | FileType::Opus | FileType::Vorbis | FileType::Speex => {
|
||||
FileType::Aiff | FileType::Mpeg | FileType::Wav | FileType::Aac => TagType::ID3v2,
|
||||
FileType::Ape | FileType::WavPack => TagType::APE,
|
||||
FileType::Flac | FileType::Opus | FileType::Vorbis | FileType::Speex => {
|
||||
TagType::VorbisComments
|
||||
},
|
||||
FileType::MP4 => TagType::MP4ilst,
|
||||
FileType::Mp4 => TagType::MP4ilst,
|
||||
FileType::Custom(c) => {
|
||||
let resolver = crate::resolve::lookup_resolver(c);
|
||||
resolver.primary_tag_type()
|
||||
|
@ -768,7 +768,7 @@ impl FileType {
|
|||
/// Returns if the target `FileType` supports a [`TagType`]
|
||||
///
|
||||
/// NOTE: This is feature dependent, meaning if you do not have the
|
||||
/// `id3v2` feature enabled, [`FileType::MPEG`] will return `false` for
|
||||
/// `id3v2` feature enabled, [`FileType::Mpeg`] will return `false` for
|
||||
/// [`TagType::ID3v2`].
|
||||
///
|
||||
/// # Panics
|
||||
|
@ -780,28 +780,28 @@ impl FileType {
|
|||
/// ```rust
|
||||
/// use lofty::{FileType, TagType};
|
||||
///
|
||||
/// let file_type = FileType::MPEG;
|
||||
/// 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 {
|
||||
FileType::AIFF | FileType::APE | FileType::MPEG | FileType::WAV | FileType::AAC
|
||||
FileType::Aiff | FileType::Ape | FileType::Mpeg | FileType::Wav | FileType::Aac
|
||||
if tag_type == TagType::ID3v2 =>
|
||||
{
|
||||
true
|
||||
},
|
||||
FileType::AIFF if tag_type == TagType::AIFFText => true,
|
||||
FileType::APE | FileType::MPEG | FileType::WavPack | FileType::AAC
|
||||
FileType::Aiff if tag_type == TagType::AIFFText => true,
|
||||
FileType::Ape | FileType::Mpeg | FileType::WavPack | FileType::Aac
|
||||
if tag_type == TagType::ID3v1 =>
|
||||
{
|
||||
true
|
||||
},
|
||||
FileType::APE | FileType::MPEG | FileType::WavPack if tag_type == TagType::APE => true,
|
||||
FileType::Opus | FileType::FLAC | FileType::Vorbis | FileType::Speex => {
|
||||
FileType::Ape | FileType::Mpeg | FileType::WavPack if tag_type == TagType::APE => true,
|
||||
FileType::Opus | FileType::Flac | FileType::Vorbis | FileType::Speex => {
|
||||
tag_type == TagType::VorbisComments
|
||||
},
|
||||
FileType::MP4 => tag_type == TagType::MP4ilst,
|
||||
FileType::WAV => tag_type == TagType::RIFFInfo,
|
||||
FileType::Mp4 => tag_type == TagType::MP4ilst,
|
||||
FileType::Wav => tag_type == TagType::RIFFInfo,
|
||||
FileType::Custom(c) => {
|
||||
let resolver = crate::resolve::lookup_resolver(c);
|
||||
resolver.supported_tag_types().contains(&tag_type)
|
||||
|
@ -818,7 +818,7 @@ impl FileType {
|
|||
/// use lofty::FileType;
|
||||
///
|
||||
/// let extension = "mp3";
|
||||
/// assert_eq!(FileType::from_ext(extension), Some(FileType::MPEG));
|
||||
/// assert_eq!(FileType::from_ext(extension), Some(FileType::Mpeg));
|
||||
/// ```
|
||||
pub fn from_ext<E>(ext: E) -> Option<Self>
|
||||
where
|
||||
|
@ -827,16 +827,16 @@ impl FileType {
|
|||
let ext = ext.as_ref().to_str()?.to_ascii_lowercase();
|
||||
|
||||
match ext.as_str() {
|
||||
"aac" => Some(Self::AAC),
|
||||
"ape" => Some(Self::APE),
|
||||
"aiff" | "aif" | "afc" | "aifc" => Some(Self::AIFF),
|
||||
"mp3" | "mp2" | "mp1" => Some(Self::MPEG),
|
||||
"wav" | "wave" => Some(Self::WAV),
|
||||
"aac" => Some(Self::Aac),
|
||||
"ape" => Some(Self::Ape),
|
||||
"aiff" | "aif" | "afc" | "aifc" => Some(Self::Aiff),
|
||||
"mp3" | "mp2" | "mp1" => Some(Self::Mpeg),
|
||||
"wav" | "wave" => Some(Self::Wav),
|
||||
"wv" => Some(Self::WavPack),
|
||||
"opus" => Some(Self::Opus),
|
||||
"flac" => Some(Self::FLAC),
|
||||
"flac" => Some(Self::Flac),
|
||||
"ogg" => Some(Self::Vorbis),
|
||||
"mp4" | "m4a" | "m4b" | "m4p" | "m4r" | "m4v" | "3gp" => Some(Self::MP4),
|
||||
"mp4" | "m4a" | "m4b" | "m4p" | "m4r" | "m4v" | "3gp" => Some(Self::Mp4),
|
||||
"spx" => Some(Self::Speex),
|
||||
e => {
|
||||
if let Some((ty, _)) = CUSTOM_RESOLVERS
|
||||
|
@ -862,7 +862,7 @@ impl FileType {
|
|||
/// use std::path::Path;
|
||||
///
|
||||
/// let path = Path::new("path/to/my.mp3");
|
||||
/// assert_eq!(FileType::from_path(path), Some(FileType::MPEG));
|
||||
/// assert_eq!(FileType::from_path(path), Some(FileType::Mpeg));
|
||||
/// ```
|
||||
pub fn from_path<P>(path: P) -> Option<Self>
|
||||
where
|
||||
|
@ -946,7 +946,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),
|
||||
77 if buf.starts_with(b"MAC") => Some(Self::Ape),
|
||||
255 if buf.len() >= 2 && verify_frame_sync([buf[0], buf[1]]) => {
|
||||
// ADTS and MPEG frame headers are way too similar
|
||||
|
||||
|
@ -976,16 +976,16 @@ impl FileType {
|
|||
// we can assume we have an ADTS header. Awesome!
|
||||
|
||||
if buf[1] & 0b10000 > 0 && buf[1] & 0b110 == 0 {
|
||||
return Some(Self::AAC);
|
||||
return Some(Self::Aac);
|
||||
}
|
||||
|
||||
Some(Self::MPEG)
|
||||
Some(Self::Mpeg)
|
||||
},
|
||||
70 if buf.len() >= 12 && &buf[..4] == b"FORM" => {
|
||||
let id = &buf[8..12];
|
||||
|
||||
if id == b"AIFF" || id == b"AIFC" {
|
||||
return Some(Self::AIFF);
|
||||
return Some(Self::Aiff);
|
||||
}
|
||||
|
||||
None
|
||||
|
@ -1001,16 +1001,16 @@ impl FileType {
|
|||
|
||||
None
|
||||
},
|
||||
102 if buf.starts_with(b"fLaC") => Some(Self::FLAC),
|
||||
102 if buf.starts_with(b"fLaC") => Some(Self::Flac),
|
||||
82 if buf.len() >= 12 && &buf[..4] == b"RIFF" => {
|
||||
if &buf[8..12] == b"WAVE" {
|
||||
return Some(Self::WAV);
|
||||
return Some(Self::Wav);
|
||||
}
|
||||
|
||||
None
|
||||
},
|
||||
119 if buf.len() >= 4 && &buf[..4] == b"wvpk" => Some(Self::WavPack),
|
||||
_ if buf.len() >= 8 && &buf[4..8] == b"ftyp" => Some(Self::MP4),
|
||||
_ if buf.len() >= 8 && &buf[4..8] == b"ftyp" => Some(Self::Mp4),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ impl OggPictureStorage for FlacFile {
|
|||
impl From<FlacFile> for TaggedFile {
|
||||
fn from(mut value: FlacFile) -> Self {
|
||||
TaggedFile {
|
||||
ty: FileType::FLAC,
|
||||
ty: FileType::Flac,
|
||||
properties: value.properties.into(),
|
||||
tags: {
|
||||
let mut tags = Vec::with_capacity(2);
|
||||
|
|
|
@ -24,13 +24,13 @@ where
|
|||
data.read_exact(&mut marker)?;
|
||||
|
||||
if &marker != b"fLaC" {
|
||||
decode_err!(@BAIL FLAC, "File missing \"fLaC\" stream marker");
|
||||
decode_err!(@BAIL Flac, "File missing \"fLaC\" stream marker");
|
||||
}
|
||||
|
||||
let block = Block::read(data)?;
|
||||
|
||||
if block.ty != BLOCK_ID_STREAMINFO {
|
||||
decode_err!(@BAIL FLAC, "File missing mandatory STREAMINFO block");
|
||||
decode_err!(@BAIL Flac, "File missing mandatory STREAMINFO block");
|
||||
}
|
||||
|
||||
Ok(block)
|
||||
|
@ -59,7 +59,7 @@ where
|
|||
let stream_info_len = (stream_info.end - stream_info.start) as u32;
|
||||
|
||||
if stream_info_len < 18 {
|
||||
decode_err!(@BAIL FLAC, "File has an invalid STREAMINFO block size (< 18)");
|
||||
decode_err!(@BAIL Flac, "File has an invalid STREAMINFO block size (< 18)");
|
||||
}
|
||||
|
||||
let mut last_block = stream_info.last;
|
||||
|
@ -71,12 +71,12 @@ where
|
|||
if block.content.is_empty()
|
||||
&& (block.ty != BLOCK_ID_PADDING && block.ty != BLOCK_ID_SEEKTABLE)
|
||||
{
|
||||
decode_err!(@BAIL FLAC, "Encountered a zero-sized metadata block");
|
||||
decode_err!(@BAIL Flac, "Encountered a zero-sized metadata block");
|
||||
}
|
||||
|
||||
if block.ty == BLOCK_ID_VORBIS_COMMENTS {
|
||||
if flac_file.vorbis_comments_tag.is_some() {
|
||||
decode_err!(@BAIL FLAC, "Streams are only allowed one Vorbis Comments block per stream");
|
||||
decode_err!(@BAIL Flac, "Streams are only allowed one Vorbis Comments block per stream");
|
||||
}
|
||||
|
||||
let mut vorbis_comments = VorbisComments::new();
|
||||
|
|
|
@ -54,7 +54,7 @@ macro_rules! impl_accessor {
|
|||
#[derive(Default, Debug, PartialEq, Eq, Clone)]
|
||||
#[tag(
|
||||
description = "An ID3v1 tag",
|
||||
supported_formats(AAC, APE, MPEG, WavPack)
|
||||
supported_formats(Aac, Ape, Mpeg, WavPack)
|
||||
)]
|
||||
pub struct ID3v1Tag {
|
||||
/// Track title, 30 bytes max
|
||||
|
|
|
@ -96,7 +96,7 @@ macro_rules! impl_accessor {
|
|||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
#[tag(
|
||||
description = "An `ID3v2` tag",
|
||||
supported_formats(AAC, AIFF, MPEG, WAV, read_only(FLAC, APE))
|
||||
supported_formats(Aac, Aiff, Mpeg, Wav, read_only(Flac, Ape))
|
||||
)]
|
||||
pub struct ID3v2Tag {
|
||||
flags: ID3v2TagFlags,
|
||||
|
|
|
@ -64,11 +64,11 @@ pub(crate) fn write_id3v2<'a, I: Iterator<Item = FrameRef<'a>> + Clone + 'a>(
|
|||
|
||||
match file_type {
|
||||
// Formats such as WAV and AIFF store the ID3v2 tag in an 'ID3 ' chunk rather than at the beginning of the file
|
||||
FileType::WAV => {
|
||||
FileType::Wav => {
|
||||
tag.flags.footer = false;
|
||||
return chunk_file::write_to_chunk_file::<LittleEndian>(data, &create_tag(tag)?);
|
||||
},
|
||||
FileType::AIFF => {
|
||||
FileType::Aiff => {
|
||||
tag.flags.footer = false;
|
||||
return chunk_file::write_to_chunk_file::<BigEndian>(data, &create_tag(tag)?);
|
||||
},
|
||||
|
|
|
@ -15,7 +15,7 @@ pub(super) fn read_properties(
|
|||
let channels = comm.read_u16::<BigEndian>()? as u8;
|
||||
|
||||
if channels == 0 {
|
||||
decode_err!(@BAIL AIFF, "File contains 0 channels");
|
||||
decode_err!(@BAIL Aiff, "File contains 0 channels");
|
||||
}
|
||||
|
||||
let sample_frames = comm.read_u32::<BigEndian>()?;
|
||||
|
|
|
@ -65,7 +65,7 @@ where
|
|||
},
|
||||
b"COMM" if parse_options.read_properties && comm.is_none() => {
|
||||
if chunks.size < 18 {
|
||||
decode_err!(@BAIL AIFF, "File has an invalid \"COMM\" chunk size (< 18)");
|
||||
decode_err!(@BAIL Aiff, "File has an invalid \"COMM\" chunk size (< 18)");
|
||||
}
|
||||
|
||||
comm = Some(chunks.content(data)?);
|
||||
|
@ -129,7 +129,7 @@ where
|
|||
match comm {
|
||||
Some(comm) => {
|
||||
if stream_len == 0 {
|
||||
decode_err!(@BAIL AIFF, "File does not contain a \"SSND\" chunk");
|
||||
decode_err!(@BAIL Aiff, "File does not contain a \"SSND\" chunk");
|
||||
}
|
||||
|
||||
properties = super::properties::read_properties(
|
||||
|
@ -138,7 +138,7 @@ where
|
|||
data.stream_position()?,
|
||||
)?;
|
||||
},
|
||||
None => decode_err!(@BAIL AIFF, "File does not contain a \"COMM\" chunk"),
|
||||
None => decode_err!(@BAIL Aiff, "File does not contain a \"COMM\" chunk"),
|
||||
}
|
||||
} else {
|
||||
properties = FileProperties::default();
|
||||
|
|
|
@ -57,7 +57,7 @@ pub struct Comment {
|
|||
///
|
||||
/// When converting [Comment]s, only the `text` field will be preserved.
|
||||
#[derive(Default, Clone, Debug, PartialEq, Eq)]
|
||||
#[tag(description = "`AIFF` text chunks", supported_formats(AIFF))]
|
||||
#[tag(description = "`AIFF` text chunks", supported_formats(Aiff))]
|
||||
pub struct AIFFTextChunks {
|
||||
/// The name of the piece
|
||||
pub name: Option<String>,
|
||||
|
|
|
@ -116,7 +116,7 @@ pub(super) fn read_properties(
|
|||
let channels = fmt.read_u16::<LittleEndian>()? as u8;
|
||||
|
||||
if channels == 0 {
|
||||
decode_err!(@BAIL WAV, "File contains 0 channels");
|
||||
decode_err!(@BAIL Wav, "File contains 0 channels");
|
||||
}
|
||||
|
||||
let sample_rate = fmt.read_u32::<LittleEndian>()?;
|
||||
|
@ -136,7 +136,7 @@ pub(super) fn read_properties(
|
|||
let channel_mask;
|
||||
if format_tag == EXTENSIBLE {
|
||||
if fmt.len() + 16 < 40 {
|
||||
decode_err!(@BAIL WAV, "Extensible format identified, invalid \"fmt \" chunk size found (< 40)");
|
||||
decode_err!(@BAIL Wav, "Extensible format identified, invalid \"fmt \" chunk size found (< 40)");
|
||||
}
|
||||
|
||||
// cbSize (Size of extra format information) (2)
|
||||
|
@ -157,7 +157,7 @@ pub(super) fn read_properties(
|
|||
let non_pcm = format_tag != PCM && format_tag != IEEE_FLOAT;
|
||||
|
||||
if non_pcm && total_samples == 0 {
|
||||
decode_err!(@BAIL WAV, "Non-PCM format identified, no \"fact\" chunk found");
|
||||
decode_err!(@BAIL Wav, "Non-PCM format identified, no \"fact\" chunk found");
|
||||
}
|
||||
|
||||
if bits_per_sample > 0 {
|
||||
|
|
|
@ -19,11 +19,11 @@ where
|
|||
data.read_exact(&mut id)?;
|
||||
|
||||
if &id[..4] != b"RIFF" {
|
||||
decode_err!(@BAIL WAV, "WAV file doesn't contain a RIFF chunk");
|
||||
decode_err!(@BAIL Wav, "WAV file doesn't contain a RIFF chunk");
|
||||
}
|
||||
|
||||
if &id[8..] != b"WAVE" {
|
||||
decode_err!(@BAIL WAV, "Found RIFF file, format is not WAVE");
|
||||
decode_err!(@BAIL Wav, "Found RIFF file, format is not WAVE");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -105,11 +105,11 @@ where
|
|||
|
||||
let properties = if parse_options.read_properties {
|
||||
if fmt.len() < 16 {
|
||||
decode_err!(@BAIL WAV, "File does not contain a valid \"fmt \" chunk");
|
||||
decode_err!(@BAIL Wav, "File does not contain a valid \"fmt \" chunk");
|
||||
}
|
||||
|
||||
if stream_len == 0 {
|
||||
decode_err!(@BAIL WAV, "File does not contain a \"data\" chunk");
|
||||
decode_err!(@BAIL Wav, "File does not contain a \"data\" chunk");
|
||||
}
|
||||
|
||||
let file_length = data.stream_position()?;
|
||||
|
|
|
@ -42,7 +42,7 @@ macro_rules! impl_accessor {
|
|||
/// * 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
|
||||
#[derive(Default, Debug, PartialEq, Eq, Clone)]
|
||||
#[tag(description = "A RIFF INFO LIST", supported_formats(WAV))]
|
||||
#[tag(description = "A RIFF INFO LIST", supported_formats(Wav))]
|
||||
pub struct RIFFInfoList {
|
||||
/// A collection of chunk-value pairs
|
||||
pub(crate) items: Vec<(String, String)>,
|
||||
|
|
|
@ -18,17 +18,17 @@ where
|
|||
{
|
||||
while data.stream_position()? != end && chunks.next(data).is_ok() {
|
||||
let key_str = String::from_utf8(chunks.fourcc.to_vec())
|
||||
.map_err(|_| decode_err!(WAV, "Non UTF-8 item key found in RIFF INFO"))?;
|
||||
.map_err(|_| decode_err!(Wav, "Non UTF-8 item key found in RIFF INFO"))?;
|
||||
|
||||
if !verify_key(&key_str) {
|
||||
decode_err!(@BAIL WAV, "RIFF INFO item key contains invalid characters");
|
||||
decode_err!(@BAIL Wav, "RIFF INFO item key contains invalid characters");
|
||||
}
|
||||
|
||||
tag.items.push((
|
||||
key_str,
|
||||
chunks
|
||||
.read_cstring(data)
|
||||
.map_err(|_| decode_err!(WAV, "Failed to read RIFF INFO item value"))?,
|
||||
.map_err(|_| decode_err!(Wav, "Failed to read RIFF INFO item value"))?,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ macro_rules! impl_accessor {
|
|||
///
|
||||
/// An attempt will be made to create the `TrackNumber/TrackTotal` (trkn) and `DiscNumber/DiscTotal` (disk) pairs.
|
||||
#[derive(Default, PartialEq, Debug, Clone)]
|
||||
#[tag(description = "An MP4 ilst atom", supported_formats(MP4))]
|
||||
#[tag(description = "An MP4 ilst atom", supported_formats(Mp4))]
|
||||
pub struct Ilst {
|
||||
pub(crate) atoms: Vec<Atom<'static>>,
|
||||
}
|
||||
|
|
|
@ -426,7 +426,7 @@ fn write_picture(picture: &Picture, writer: &mut Cursor<Vec<u8>>) -> Result<()>
|
|||
// We'll assume implicit (0) was the intended type
|
||||
MimeType::None => write_data(0, &picture.data, writer),
|
||||
_ => Err(FileEncodingError::new(
|
||||
FileType::MP4,
|
||||
FileType::Mp4,
|
||||
"Attempted to write an unsupported picture format",
|
||||
)
|
||||
.into()),
|
||||
|
@ -436,7 +436,7 @@ fn write_picture(picture: &Picture, writer: &mut Cursor<Vec<u8>>) -> Result<()>
|
|||
fn write_data(flags: u32, data: &[u8], writer: &mut Cursor<Vec<u8>>) -> Result<()> {
|
||||
if flags > 16_777_215 {
|
||||
return Err(FileEncodingError::new(
|
||||
FileType::MP4,
|
||||
FileType::Mp4,
|
||||
"Attempted to write a code that cannot fit in 24 bits",
|
||||
)
|
||||
.into());
|
||||
|
|
|
@ -30,7 +30,7 @@ impl Moov {
|
|||
skip_unneeded(reader, atom.extended, atom.len)?;
|
||||
}
|
||||
|
||||
moov.ok_or_else(|| decode_err!(MP4, "No \"moov\" atom found"))
|
||||
moov.ok_or_else(|| decode_err!(Mp4, "No \"moov\" atom found"))
|
||||
}
|
||||
|
||||
pub(super) fn parse<R>(reader: &mut AtomReader<R>, read_properties: bool) -> Result<Self>
|
||||
|
|
|
@ -123,7 +123,7 @@ impl TryFrom<u8> for AudioObjectType {
|
|||
44 => Ok(Self::LowDelayMpegSurround),
|
||||
45 => Ok(Self::SpatialAudioObjectCodingDialogueEnhancement),
|
||||
46 => Ok(Self::AudioSync),
|
||||
_ => decode_err!(@BAIL MP4, "Encountered an invalid audio object type"),
|
||||
_ => decode_err!(@BAIL Mp4, "Encountered an invalid audio object type"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ where
|
|||
}
|
||||
|
||||
if !audio_track {
|
||||
decode_err!(@BAIL MP4, "File contains no audio tracks");
|
||||
decode_err!(@BAIL Mp4, "File contains no audio tracks");
|
||||
}
|
||||
|
||||
let mdhd = match mdhd {
|
||||
|
@ -640,7 +640,7 @@ where
|
|||
skip_unneeded(reader, atom.extended, atom.len)?;
|
||||
}
|
||||
|
||||
decode_err!(@BAIL MP4, "Failed to find \"mdat\" atom");
|
||||
decode_err!(@BAIL Mp4, "Failed to find \"mdat\" atom");
|
||||
}
|
||||
|
||||
struct Descriptor {
|
||||
|
|
|
@ -152,7 +152,7 @@ where
|
|||
// size + identifier + major brand
|
||||
// There *should* be more, but this is all we need from it
|
||||
if atom.len < 12 {
|
||||
decode_err!(@BAIL MP4, "\"ftyp\" atom too short");
|
||||
decode_err!(@BAIL Mp4, "\"ftyp\" atom too short");
|
||||
}
|
||||
|
||||
let mut major_brand = vec![0; 4];
|
||||
|
|
|
@ -288,7 +288,7 @@ impl XingHeader {
|
|||
match &header {
|
||||
b"Xing" | b"Info" => {
|
||||
if reader_len < 16 {
|
||||
decode_err!(@BAIL MPEG, "Xing header has an invalid size (< 16)");
|
||||
decode_err!(@BAIL Mpeg, "Xing header has an invalid size (< 16)");
|
||||
}
|
||||
|
||||
let mut flags = [0; 4];
|
||||
|
@ -308,7 +308,7 @@ impl XingHeader {
|
|||
},
|
||||
b"VBRI" => {
|
||||
if reader_len < 32 {
|
||||
decode_err!(@BAIL MPEG, "VBRI header has an invalid size (< 32)");
|
||||
decode_err!(@BAIL Mpeg, "VBRI header has an invalid size (< 32)");
|
||||
}
|
||||
|
||||
// Skip 6 bytes
|
||||
|
|
|
@ -129,11 +129,11 @@ where
|
|||
let first_frame_header = match first_frame_header {
|
||||
Some(header) => header,
|
||||
// The search for sync bits was unsuccessful
|
||||
None => decode_err!(@BAIL MPEG, "File contains an invalid frame"),
|
||||
None => decode_err!(@BAIL Mpeg, "File contains an invalid frame"),
|
||||
};
|
||||
|
||||
if first_frame_header.sample_rate == 0 {
|
||||
decode_err!(@BAIL MPEG, "Sample rate is 0");
|
||||
decode_err!(@BAIL Mpeg, "Sample rate is 0");
|
||||
}
|
||||
|
||||
let first_frame_offset = first_frame_offset;
|
||||
|
|
|
@ -40,7 +40,7 @@ macro_rules! impl_accessor {
|
|||
#[derive(Default, PartialEq, Eq, Debug, Clone)]
|
||||
#[tag(
|
||||
description = "Vorbis comments",
|
||||
supported_formats(FLAC, Opus, Speex, Vorbis)
|
||||
supported_formats(Flac, Opus, Speex, Vorbis)
|
||||
)]
|
||||
pub struct VorbisComments {
|
||||
/// An identifier for the encoding software
|
||||
|
@ -521,7 +521,7 @@ where
|
|||
};
|
||||
|
||||
// FLAC has its own special writing needs :)
|
||||
if file_type == FileType::FLAC {
|
||||
if file_type == FileType::Flac {
|
||||
return crate::flac::write::write_to_inner(file, self);
|
||||
}
|
||||
|
||||
|
|
60
src/probe.rs
60
src/probe.rs
|
@ -1,4 +1,4 @@
|
|||
use crate::aac::AACFile;
|
||||
use crate::aac::AacFile;
|
||||
use crate::ape::ApeFile;
|
||||
use crate::error::Result;
|
||||
use crate::file::{AudioFile, FileType, TaggedFile};
|
||||
|
@ -142,7 +142,7 @@ pub enum ParsingMode {
|
|||
/// let probe = Probe::open("path/to/my.mp3")?;
|
||||
///
|
||||
/// // Inferred from the `mp3` extension
|
||||
/// assert_eq!(probe.file_type(), Some(FileType::MPEG));
|
||||
/// assert_eq!(probe.file_type(), Some(FileType::Mpeg));
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
|
@ -158,7 +158,7 @@ pub enum ParsingMode {
|
|||
/// let probe = Probe::open("path/to/my.mp3")?.guess_file_type()?;
|
||||
///
|
||||
/// // Inferred from the file's content
|
||||
/// assert_eq!(probe.file_type(), Some(FileType::MPEG));
|
||||
/// assert_eq!(probe.file_type(), Some(FileType::Mpeg));
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
|
@ -176,7 +176,7 @@ pub enum ParsingMode {
|
|||
/// let probe = Probe::new(Cursor::new(MAC_HEADER)).guess_file_type()?;
|
||||
///
|
||||
/// // Inferred from the MAC header
|
||||
/// assert_eq!(probe.file_type(), Some(FileType::APE));
|
||||
/// assert_eq!(probe.file_type(), Some(FileType::Ape));
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
|
@ -235,7 +235,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::MPEG);
|
||||
/// let probe = Probe::with_file_type(reader, FileType::Mpeg);
|
||||
/// # Ok(()) }
|
||||
/// ```
|
||||
pub fn with_file_type(reader: R, file_type: FileType) -> Self {
|
||||
|
@ -276,9 +276,9 @@ impl<R: Read> Probe<R> {
|
|||
/// let mut probe = Probe::new(reader);
|
||||
/// assert_eq!(probe.file_type(), None);
|
||||
///
|
||||
/// probe.set_file_type(FileType::MPEG);
|
||||
/// probe.set_file_type(FileType::Mpeg);
|
||||
///
|
||||
/// assert_eq!(probe.file_type(), Some(FileType::MPEG));
|
||||
/// assert_eq!(probe.file_type(), Some(FileType::Mpeg));
|
||||
/// # Ok(()) }
|
||||
/// ```
|
||||
pub fn set_file_type(&mut self, file_type: FileType) {
|
||||
|
@ -345,7 +345,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::MPEG));
|
||||
/// assert_eq!(probe.file_type(), Some(FileType::Mpeg));
|
||||
/// # Ok(()) }
|
||||
/// ```
|
||||
pub fn open<P>(path: P) -> Result<Self>
|
||||
|
@ -385,7 +385,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::MPEG));
|
||||
/// assert_eq!(probe.file_type(), Some(FileType::Mpeg));
|
||||
/// # Ok(()) }
|
||||
/// ```
|
||||
pub fn guess_file_type(mut self) -> std::io::Result<Self> {
|
||||
|
@ -431,8 +431,8 @@ impl<R: Read + Seek> Probe<R> {
|
|||
self.inner.seek(SeekFrom::Start(position_after_id3_block))?;
|
||||
|
||||
let file_type_after_id3_block = match &ident {
|
||||
[b'M', b'A', b'C', ..] => Ok(Some(FileType::APE)),
|
||||
b"fLaC" => Ok(Some(FileType::FLAC)),
|
||||
[b'M', b'A', b'C', ..] => Ok(Some(FileType::Ape)),
|
||||
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() => {
|
||||
// Seek back to the start of the frame sync to check if we are dealing with
|
||||
|
@ -443,9 +443,9 @@ impl<R: Read + Seek> Probe<R> {
|
|||
self.inner.read_exact(&mut buf)?;
|
||||
|
||||
if buf[1] & 0b10000 > 0 && buf[1] & 0b110 == 0 {
|
||||
Ok(Some(FileType::AAC))
|
||||
Ok(Some(FileType::Aac))
|
||||
} else {
|
||||
Ok(Some(FileType::MPEG))
|
||||
Ok(Some(FileType::Mpeg))
|
||||
}
|
||||
},
|
||||
_ => Ok(None),
|
||||
|
@ -507,15 +507,15 @@ impl<R: Read + Seek> Probe<R> {
|
|||
|
||||
match self.f_ty {
|
||||
Some(f_type) => Ok(match f_type {
|
||||
FileType::AAC => AACFile::read_from(reader, options)?.into(),
|
||||
FileType::AIFF => AiffFile::read_from(reader, options)?.into(),
|
||||
FileType::APE => ApeFile::read_from(reader, options)?.into(),
|
||||
FileType::FLAC => FlacFile::read_from(reader, options)?.into(),
|
||||
FileType::MPEG => MPEGFile::read_from(reader, options)?.into(),
|
||||
FileType::Aac => AacFile::read_from(reader, options)?.into(),
|
||||
FileType::Aiff => AiffFile::read_from(reader, options)?.into(),
|
||||
FileType::Ape => ApeFile::read_from(reader, options)?.into(),
|
||||
FileType::Flac => FlacFile::read_from(reader, options)?.into(),
|
||||
FileType::Mpeg => MPEGFile::read_from(reader, options)?.into(),
|
||||
FileType::Opus => OpusFile::read_from(reader, options)?.into(),
|
||||
FileType::Vorbis => VorbisFile::read_from(reader, options)?.into(),
|
||||
FileType::WAV => WavFile::read_from(reader, options)?.into(),
|
||||
FileType::MP4 => Mp4File::read_from(reader, options)?.into(),
|
||||
FileType::Wav => WavFile::read_from(reader, options)?.into(),
|
||||
FileType::Mp4 => Mp4File::read_from(reader, options)?.into(),
|
||||
FileType::Speex => SpeexFile::read_from(reader, options)?.into(),
|
||||
FileType::WavPack => WavPackFile::read_from(reader, options)?.into(),
|
||||
FileType::Custom(c) => {
|
||||
|
@ -615,7 +615,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::MPEG));
|
||||
assert_eq!(probe.file_type(), Some(FileType::Mpeg));
|
||||
}
|
||||
|
||||
fn test_probe(path: &str, expected_file_type_guess: FileType) {
|
||||
|
@ -638,37 +638,37 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn probe_aac() {
|
||||
test_probe("tests/files/assets/minimal/untagged.aac", FileType::AAC);
|
||||
test_probe("tests/files/assets/minimal/untagged.aac", FileType::Aac);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_aac_with_id3v2() {
|
||||
test_probe("tests/files/assets/minimal/full_test.aac", FileType::AAC);
|
||||
test_probe("tests/files/assets/minimal/full_test.aac", FileType::Aac);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_aiff() {
|
||||
test_probe("tests/files/assets/minimal/full_test.aiff", FileType::AIFF);
|
||||
test_probe("tests/files/assets/minimal/full_test.aiff", FileType::Aiff);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_ape_with_id3v2() {
|
||||
test_probe("tests/files/assets/minimal/full_test.ape", FileType::APE);
|
||||
test_probe("tests/files/assets/minimal/full_test.ape", FileType::Ape);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_flac() {
|
||||
test_probe("tests/files/assets/minimal/full_test.flac", FileType::FLAC);
|
||||
test_probe("tests/files/assets/minimal/full_test.flac", FileType::Flac);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_flac_with_id3v2() {
|
||||
test_probe("tests/files/assets/flac_with_id3v2.flac", FileType::FLAC);
|
||||
test_probe("tests/files/assets/flac_with_id3v2.flac", FileType::Flac);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_mp3_with_id3v2() {
|
||||
test_probe("tests/files/assets/minimal/full_test.mp3", FileType::MPEG);
|
||||
test_probe("tests/files/assets/minimal/full_test.mp3", FileType::Mpeg);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -690,7 +690,7 @@ mod tests {
|
|||
fn probe_mp4() {
|
||||
test_probe(
|
||||
"tests/files/assets/minimal/m4a_codec_aac.m4a",
|
||||
FileType::MP4,
|
||||
FileType::Mp4,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -698,7 +698,7 @@ mod tests {
|
|||
fn probe_wav() {
|
||||
test_probe(
|
||||
"tests/files/assets/minimal/wav_format_pcm.wav",
|
||||
FileType::WAV,
|
||||
FileType::Wav,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ impl ChannelMask {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::aac::{AACFile, AACProperties};
|
||||
use crate::aac::{AACProperties, AacFile};
|
||||
use crate::ape::{ApeFile, ApeProperties};
|
||||
use crate::flac::{FlacFile, FlacProperties};
|
||||
use crate::iff::aiff::AiffFile;
|
||||
|
@ -342,7 +342,7 @@ mod tests {
|
|||
#[test]
|
||||
fn aac_properties() {
|
||||
assert_eq!(
|
||||
get_properties::<AACFile>("tests/files/assets/minimal/full_test.aac"),
|
||||
get_properties::<AacFile>("tests/files/assets/minimal/full_test.aac"),
|
||||
AAC_PROPERTIES
|
||||
);
|
||||
}
|
||||
|
|
|
@ -652,7 +652,7 @@ impl TagType {
|
|||
};
|
||||
|
||||
let special_exceptions =
|
||||
(file_type == FileType::APE || file_type == FileType::FLAC) && *self == TagType::ID3v2;
|
||||
(file_type == FileType::Ape || file_type == FileType::Flac) && *self == TagType::ID3v2;
|
||||
|
||||
if !special_exceptions && !file_type.supports_tag_type(*self) {
|
||||
err!(UnsupportedTag);
|
||||
|
|
|
@ -19,18 +19,18 @@ use std::io::Write;
|
|||
#[allow(unreachable_patterns)]
|
||||
pub(crate) fn write_tag(tag: &Tag, file: &mut File, file_type: FileType) -> Result<()> {
|
||||
match file_type {
|
||||
FileType::AAC => aac::write::write_to(file, tag),
|
||||
FileType::AIFF => iff::aiff::write::write_to(file, tag),
|
||||
FileType::APE => ape::write::write_to(file, tag),
|
||||
FileType::FLAC => flac::write::write_to(file, tag),
|
||||
FileType::Aac => aac::write::write_to(file, tag),
|
||||
FileType::Aiff => iff::aiff::write::write_to(file, tag),
|
||||
FileType::Ape => ape::write::write_to(file, tag),
|
||||
FileType::Flac => flac::write::write_to(file, tag),
|
||||
FileType::Opus | FileType::Speex | FileType::Vorbis => {
|
||||
crate::ogg::write::write_to(file, tag, file_type)
|
||||
},
|
||||
FileType::MPEG => mpeg::write::write_to(file, tag),
|
||||
FileType::MP4 => {
|
||||
FileType::Mpeg => mpeg::write::write_to(file, tag),
|
||||
FileType::Mp4 => {
|
||||
crate::mp4::ilst::write::write_to(file, &mut Into::<Ilst>::into(tag.clone()).as_ref())
|
||||
},
|
||||
FileType::WAV => iff::wav::write::write_to(file, tag),
|
||||
FileType::Wav => iff::wav::write::write_to(file, tag),
|
||||
FileType::WavPack => wavpack::write::write_to(file, tag),
|
||||
_ => err!(UnsupportedTag),
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ fn read() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(file.file_type(), FileType::AAC);
|
||||
assert_eq!(file.file_type(), FileType::Aac);
|
||||
|
||||
// Verify the ID3v2 tag first
|
||||
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
||||
|
@ -35,7 +35,7 @@ fn read_with_junk_bytes_between_frames() {
|
|||
.unwrap();
|
||||
|
||||
// note that the file contains ID3v2 and ID3v1 data
|
||||
assert_eq!(file.file_type(), FileType::AAC);
|
||||
assert_eq!(file.file_type(), FileType::Aac);
|
||||
|
||||
let id3v2_tag = &file.tags()[0];
|
||||
assert_eq!(id3v2_tag.artist().as_deref(), Some("artist test"));
|
||||
|
@ -63,7 +63,7 @@ fn write() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(tagged_file.file_type(), FileType::AAC);
|
||||
assert_eq!(tagged_file.file_type(), FileType::Aac);
|
||||
|
||||
// ID3v2
|
||||
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");
|
||||
|
|
|
@ -13,7 +13,7 @@ fn read() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(file.file_type(), FileType::AIFF);
|
||||
assert_eq!(file.file_type(), FileType::Aiff);
|
||||
|
||||
// Verify the ID3v2 tag first
|
||||
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
||||
|
@ -33,7 +33,7 @@ fn write() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(tagged_file.file_type(), FileType::AIFF);
|
||||
assert_eq!(tagged_file.file_type(), FileType::Aiff);
|
||||
|
||||
// ID3v2
|
||||
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");
|
||||
|
|
|
@ -13,7 +13,7 @@ fn read() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(file.file_type(), FileType::APE);
|
||||
assert_eq!(file.file_type(), FileType::Ape);
|
||||
|
||||
// Verify the APEv2 tag first
|
||||
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
||||
|
@ -37,7 +37,7 @@ fn write() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(tagged_file.file_type(), FileType::APE);
|
||||
assert_eq!(tagged_file.file_type(), FileType::Ape);
|
||||
|
||||
// APEv2
|
||||
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");
|
||||
|
|
|
@ -13,7 +13,7 @@ fn read() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(file.file_type(), FileType::MP4);
|
||||
assert_eq!(file.file_type(), FileType::Mp4);
|
||||
|
||||
// Verify the ilst tag
|
||||
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
||||
|
@ -30,7 +30,7 @@ fn write() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(tagged_file.file_type(), FileType::MP4);
|
||||
assert_eq!(tagged_file.file_type(), FileType::Mp4);
|
||||
|
||||
// ilst
|
||||
crate::set_artist!(tagged_file, tag_mut, TagType::MP4ilst, "Foo artist", 1 => file, "Bar artist");
|
||||
|
|
|
@ -14,7 +14,7 @@ fn read() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(file.file_type(), FileType::MPEG);
|
||||
assert_eq!(file.file_type(), FileType::Mpeg);
|
||||
|
||||
// Verify the ID3v2 tag first
|
||||
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
||||
|
@ -35,7 +35,7 @@ fn read_with_junk_bytes_between_frames() {
|
|||
.unwrap();
|
||||
|
||||
// note that the file contains ID3v2 and ID3v1 data
|
||||
assert_eq!(file.file_type(), FileType::MPEG);
|
||||
assert_eq!(file.file_type(), FileType::Mpeg);
|
||||
|
||||
let id3v2_tag = &file.tags()[0];
|
||||
assert_eq!(id3v2_tag.artist().as_deref(), Some("artist test"));
|
||||
|
@ -59,7 +59,7 @@ fn issue_82_solidus_in_tag() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(file.file_type(), FileType::MPEG);
|
||||
assert_eq!(file.file_type(), FileType::Mpeg);
|
||||
|
||||
let id3v2_tag = &file.tags()[0];
|
||||
assert_eq!(id3v2_tag.title().as_deref(), Some("Foo / title"));
|
||||
|
@ -76,7 +76,7 @@ fn issue_87_duplicate_id3v2() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(file.file_type(), FileType::MPEG);
|
||||
assert_eq!(file.file_type(), FileType::Mpeg);
|
||||
|
||||
let id3v2_tag = &file.tags()[0];
|
||||
assert_eq!(id3v2_tag.album().as_deref(), Some("album test"));
|
||||
|
@ -99,7 +99,7 @@ fn write() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(tagged_file.file_type(), FileType::MPEG);
|
||||
assert_eq!(tagged_file.file_type(), FileType::Mpeg);
|
||||
|
||||
// ID3v2
|
||||
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");
|
||||
|
@ -137,7 +137,7 @@ fn save_to_id3v2() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(tagged_file.file_type(), FileType::MPEG);
|
||||
assert_eq!(tagged_file.file_type(), FileType::Mpeg);
|
||||
|
||||
let mut tag = Tag::new(TagType::ID3v2);
|
||||
|
||||
|
@ -175,7 +175,7 @@ fn save_number_of_track_and_disk_to_id3v2() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(tagged_file.file_type(), FileType::MPEG);
|
||||
assert_eq!(tagged_file.file_type(), FileType::Mpeg);
|
||||
|
||||
let mut tag = Tag::new(TagType::ID3v2);
|
||||
|
||||
|
@ -216,7 +216,7 @@ fn save_total_of_track_and_disk_to_id3v2() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(tagged_file.file_type(), FileType::MPEG);
|
||||
assert_eq!(tagged_file.file_type(), FileType::Mpeg);
|
||||
|
||||
let mut tag = Tag::new(TagType::ID3v2);
|
||||
|
||||
|
@ -257,7 +257,7 @@ fn save_number_pair_of_track_and_disk_to_id3v2() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(tagged_file.file_type(), FileType::MPEG);
|
||||
assert_eq!(tagged_file.file_type(), FileType::Mpeg);
|
||||
|
||||
let mut tag = Tag::new(TagType::ID3v2);
|
||||
|
||||
|
|
|
@ -28,12 +28,12 @@ fn opus_remove() {
|
|||
#[test]
|
||||
fn flac_read() {
|
||||
// FLAC does **not** require a Vorbis comment block be present, this file has one
|
||||
read("tests/files/assets/minimal/full_test.flac", FileType::FLAC)
|
||||
read("tests/files/assets/minimal/full_test.flac", FileType::Flac)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flac_write() {
|
||||
write("tests/files/assets/minimal/full_test.flac", FileType::FLAC)
|
||||
write("tests/files/assets/minimal/full_test.flac", FileType::Flac)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -13,7 +13,7 @@ fn read() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(file.file_type(), FileType::WAV);
|
||||
assert_eq!(file.file_type(), FileType::Wav);
|
||||
|
||||
// Verify the ID3v2 tag first
|
||||
crate::verify_artist!(file, primary_tag, "Foo artist", 1);
|
||||
|
@ -33,7 +33,7 @@ fn write() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(tagged_file.file_type(), FileType::WAV);
|
||||
assert_eq!(tagged_file.file_type(), FileType::Wav);
|
||||
|
||||
// ID3v2
|
||||
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");
|
||||
|
@ -80,5 +80,5 @@ fn issue_174_divide_by_zero() {
|
|||
.read()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(file.file_type(), FileType::WAV);
|
||||
assert_eq!(file.file_type(), FileType::Wav);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue