Skip to content
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions examples/custom_resolver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ struct MyFile {


// Specify a tag type
#[lofty(tag_type = "ID3v2")]
#[lofty(tag_type = "Id3v2")]
// Let's say our file *always* has an ID3v2Tag present.
pub id3v2_tag: ID3v2Tag,

// Our APE tag is optional in this format, so we wrap it in an `Option`
#[lofty(tag_type = "APE")]
#[lofty(tag_type = "Ape")]
pub ape_tag: Option<ApeTag>,

// The properties field *must* be present and named as such.
Expand Down Expand Up @@ -62,13 +62,13 @@ impl FileResolver for MyFile {
// The primary `TagType` of the file, or the one most
// likely to be used with it
fn primary_tag_type() -> TagType {
TagType::ID3v2
TagType::Id3v2
}

// All of the `TagType`s this file supports, including the
// primary one.
fn supported_tag_types() -> &'static [TagType] {
&[TagType::ID3v2, TagType::APE]
&[TagType::Id3v2, TagType::Ape]
}

// This is used to guess the `FileType` when reading the file contents.
Expand Down
16 changes: 8 additions & 8 deletions lofty_attr/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -42,24 +42,24 @@ pub(crate) fn init_write_lookup(
};
}

insert!(map, APE, {
insert!(map, Ape, {
lofty::ape::tag::ApeTagRef {
read_only: false,
items: lofty::ape::tag::tagitems_into_ape(tag.items()),
}
.write_to(data)
});

insert!(map, ID3v1, {
insert!(map, Id3v1, {
Into::<lofty::id3::v1::tag::Id3v1TagRef<'_>>::into(tag).write_to(data)
});

if id3v2_strippable {
insert!(map, ID3v2, {
insert!(map, Id3v2, {
lofty::id3::v2::tag::Id3v2TagRef::empty().write_to(data)
});
} else {
insert!(map, ID3v2, {
insert!(map, Id3v2, {
lofty::id3::v2::tag::Id3v2TagRef {
flags: lofty::id3::v2::ID3v2TagFlags::default(),
frames: lofty::id3::v2::tag::tag_frames(tag),
Expand All @@ -68,14 +68,14 @@ pub(crate) fn init_write_lookup(
});
}

insert!(map, RIFFInfo, {
insert!(map, RiffInfo, {
lofty::iff::wav::tag::RIFFInfoListRef::new(lofty::iff::wav::tag::tagitems_into_riff(
tag.items(),
))
.write_to(data)
});

insert!(map, AIFFText, {
insert!(map, AiffText, {
lofty::iff::aiff::tag::AiffTextChunksRef {
name: tag.get_string(&lofty::tag::item::ItemKey::TrackTitle),
author: tag.get_string(&lofty::tag::item::ItemKey::TrackArtist),
Expand Down
2 changes: 1 addition & 1 deletion src/aac/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 3 additions & 3 deletions src/aac/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ 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 {
#[lofty(tag_type = "ID3v2")]
pub struct AacFile {
#[lofty(tag_type = "Id3v2")]
pub(crate) id3v2_tag: Option<ID3v2Tag>,
#[lofty(tag_type = "ID3v1")]
#[lofty(tag_type = "Id3v1")]
pub(crate) id3v1_tag: Option<ID3v1Tag>,
pub(crate) properties: AACProperties,
}
12 changes: 6 additions & 6 deletions src/aac/read.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ape/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>()?;
Expand All @@ -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 })
Expand Down
6 changes: 3 additions & 3 deletions src/ape/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ pub use tag::ApeTag;
#[lofty(internal_write_module_do_not_use_anywhere_else)]
pub struct ApeFile {
/// An ID3v1 tag
#[lofty(tag_type = "ID3v1")]
#[lofty(tag_type = "Id3v1")]
pub(crate) id3v1_tag: Option<ID3v1Tag>,
/// An ID3v2 tag (Not officially supported)
#[lofty(tag_type = "ID3v2")]
#[lofty(tag_type = "Id3v2")]
pub(crate) id3v2_tag: Option<ID3v2Tag>,
/// An APEv1/v2 tag
#[lofty(tag_type = "APE")]
#[lofty(tag_type = "Ape")]
pub(crate) ape_tag: Option<ApeTag>,
/// The file's audio properties
pub(crate) properties: ApeProperties,
Expand Down
16 changes: 8 additions & 8 deletions src/ape/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"
)
})?;
Expand All @@ -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)
Expand All @@ -136,15 +136,15 @@ 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>()?;

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>()?;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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>()?;
Expand All @@ -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>()?;
Expand Down
6 changes: 3 additions & 3 deletions src/ape/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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\"]")
},
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/ape/tag/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -73,8 +73,8 @@ impl TryFrom<TagItem> for ApeItem {
Self::new(
value
.item_key
.map_key(TagType::APE, false)
.ok_or_else(|| decode_err!(APE, "Attempted to convert an unsupported item key"))?
.map_key(TagType::Ape, false)
.ok_or_else(|| decode_err!(Ape, "Attempted to convert an unsupported item key"))?
.to_string(),
value.item_value,
)
Expand Down
14 changes: 7 additions & 7 deletions src/ape/tag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -317,11 +317,11 @@ impl TagExt for ApeTag {
}

fn remove_from_path<P: AsRef<Path>>(&self, path: P) -> std::result::Result<(), Self::Err> {
TagType::APE.remove_from_path(path)
TagType::Ape.remove_from_path(path)
}

fn remove_from(&self, file: &mut File) -> std::result::Result<(), Self::Err> {
TagType::APE.remove_from(file)
TagType::Ape.remove_from(file)
}

fn clear(&mut self) {
Expand Down Expand Up @@ -369,10 +369,10 @@ impl SplitTag for ApeTag {
Some(())
}

let mut tag = Tag::new(TagType::APE);
let mut tag = Tag::new(TagType::Ape);

for item in std::mem::take(&mut self.items) {
let item_key = ItemKey::from_key(TagType::APE, item.key());
let item_key = ItemKey::from_key(TagType::Ape, item.key());

// The text pairs need some special treatment
match (item_key, item.value()) {
Expand Down Expand Up @@ -475,7 +475,7 @@ pub(crate) fn tagitems_into_ape<'a>(
items: impl IntoIterator<Item = &'a TagItem>,
) -> impl Iterator<Item = ApeItemRef<'a>> {
items.into_iter().filter_map(|i| {
i.key().map_key(TagType::APE, true).map(|key| ApeItemRef {
i.key().map_key(TagType::Ape, true).map(|key| ApeItemRef {
read_only: false,
key,
value: (&i.item_value).into(),
Expand Down Expand Up @@ -606,7 +606,7 @@ mod tests {
);
}

let tag = crate::tag::utils::test_utils::create_tag(TagType::APE);
let tag = crate::tag::utils::test_utils::create_tag(TagType::Ape);

let ape_tag: ApeTag = tag.into();

Expand Down
Loading