Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove obsolete metadata format features #97

Merged
merged 8 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ include = ["src", "Cargo.toml", "LICENSE-APACHE", "LICENSE-MIT", "benches",

[dependencies]
# Vorbis comments pictures
base64 = { version = "0.20.0", optional = true }
base64 = "0.20.0"
byteorder = "1.4.3"
# TODO: rustfmt only works with cfg_if for now (https://github.com/rust-lang/rustfmt/issues/3253)
cfg-if = "1.0.0"
Expand All @@ -30,15 +30,8 @@ once_cell = "1.16.0"
paste = "1.0.11"

[features]
default = ["mp4_ilst", "vorbis_comments", "ape", "id3v1", "id3v2", "aiff_text_chunks", "riff_info_list"]
mp4_ilst = []
vorbis_comments = ["base64"]
ape = []
id3v1 = []
id3v2 = ["flate2"]
id3v2_restrictions = []
aiff_text_chunks = []
riff_info_list = []
default = ["id3v2_compression_support"]
id3v2_compression_support = ["flate2"]

[dev-dependencies]
# WAV properties validity tests
Expand Down
2 changes: 0 additions & 2 deletions src/aac/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ pub use properties::AACProperties;
#[lofty(read_fn = "read::read_from")]
#[lofty(internal_write_module_do_not_use_anywhere_else)]
pub struct AACFile {
#[cfg(feature = "id3v2")]
#[lofty(tag_type = "ID3v2")]
pub(crate) id3v2_tag: Option<ID3v2Tag>,
#[cfg(feature = "id3v1")]
#[lofty(tag_type = "ID3v1")]
pub(crate) id3v1_tag: Option<ID3v1Tag>,
pub(crate) properties: AACProperties,
Expand Down
20 changes: 8 additions & 12 deletions src/aac/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,16 @@ where

stream_len -= u64::from(header.size);

#[cfg(feature = "id3v2")]
{
let id3v2 = parse_id3v2(reader, header)?;
if let Some(existing_tag) = &mut file.id3v2_tag {
// https://github.com/Serial-ATA/lofty-rs/issues/87
// Duplicate tags should have their frames appended to the previous
for frame in id3v2.frames {
existing_tag.insert(frame);
}
continue;
let id3v2 = parse_id3v2(reader, header)?;
if let Some(existing_tag) = &mut file.id3v2_tag {
// https://github.com/Serial-ATA/lofty-rs/issues/87
// Duplicate tags should have their frames appended to the previous
for frame in id3v2.frames {
existing_tag.insert(frame);
}
file.id3v2_tag = Some(id3v2);
continue;
}
file.id3v2_tag = Some(id3v2);

// Skip over the footer
if skip_footer {
Expand Down Expand Up @@ -91,7 +88,6 @@ where
#[allow(unused_variables)]
let ID3FindResults(header, id3v1) = find_id3v1(reader, true)?;

#[cfg(feature = "id3v1")]
if header.is_some() {
stream_len -= 128;
file.id3v1_tag = id3v1;
Expand Down
1 change: 0 additions & 1 deletion src/ape/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(feature = "ape")]
pub(super) const INVALID_KEYS: [&str; 4] = ["ID3", "TAG", "OGGS", "MP+"];

// https://wiki.hydrogenaud.io/index.php?title=APE_Tags_Header
Expand Down
11 changes: 1 addition & 10 deletions src/ape/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use byteorder::{LittleEndian, ReadBytesExt};
#[derive(Copy, Clone)]
pub(crate) struct ApeHeader {
pub(crate) size: u32,
#[cfg(feature = "ape")]
pub(crate) item_count: u32,
}

Expand All @@ -28,12 +27,8 @@ where
decode_err!(@BAIL APE, "APE tag has an invalid size (< 32)");
}

#[cfg(feature = "ape")]
let item_count = data.read_u32::<LittleEndian>()?;

#[cfg(not(feature = "ape"))]
data.seek(SeekFrom::Current(4))?;

if footer {
// No point in reading the rest of the footer, just seek back to the end of the header
data.seek(SeekFrom::Current(i64::from(size - 12).neg()))?;
Expand All @@ -54,9 +49,5 @@ where
decode_err!(@BAIL APE, "APE tag has an invalid size (> file size)");
}

Ok(ApeHeader {
size,
#[cfg(feature = "ape")]
item_count,
})
Ok(ApeHeader { size, item_count })
}
19 changes: 4 additions & 15 deletions src/ape/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,32 @@ pub(crate) mod constants;
pub(crate) mod header;
mod properties;
mod read;
pub(crate) mod tag;

#[cfg(feature = "id3v1")]
use crate::id3::v1::tag::ID3v1Tag;
#[cfg(feature = "id3v2")]
use crate::id3::v2::tag::ID3v2Tag;

use lofty_attr::LoftyFile;

// Exports

cfg_if::cfg_if! {
if #[cfg(feature = "ape")] {
pub(crate) mod tag;
pub use tag::ApeTag;
pub use tag::item::ApeItem;

pub use crate::picture::APE_PICTURE_TYPES;
}
}

pub use crate::picture::APE_PICTURE_TYPES;
pub use properties::ApeProperties;
pub use tag::item::ApeItem;
pub use tag::ApeTag;

/// An APE file
#[derive(LoftyFile)]
#[lofty(read_fn = "read::read_from")]
#[lofty(internal_write_module_do_not_use_anywhere_else)]
pub struct ApeFile {
/// An ID3v1 tag
#[cfg(feature = "id3v1")]
#[lofty(tag_type = "ID3v1")]
pub(crate) id3v1_tag: Option<ID3v1Tag>,
/// An ID3v2 tag (Not officially supported)
#[cfg(feature = "id3v2")]
#[lofty(tag_type = "ID3v2")]
pub(crate) id3v2_tag: Option<ID3v2Tag>,
/// An APEv1/v2 tag
#[cfg(feature = "ape")]
#[lofty(tag_type = "APE")]
pub(crate) ape_tag: Option<ApeTag>,
/// The file's audio properties
Expand Down
49 changes: 12 additions & 37 deletions src/ape/read.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use super::constants::APE_PREAMBLE;
use super::header::read_ape_header;
#[cfg(feature = "ape")]
use super::tag::{read::read_ape_tag, ApeTag};
use super::tag::read::read_ape_tag;
use super::tag::ApeTag;
use super::{ApeFile, ApeProperties};
use crate::error::Result;
#[cfg(feature = "id3v1")]
use crate::id3::v1::tag::ID3v1Tag;
#[cfg(feature = "id3v2")]
use crate::id3::v2::{read::parse_id3v2, tag::ID3v2Tag};
use crate::id3::v2::read::parse_id3v2;
use crate::id3::v2::tag::ID3v2Tag;
use crate::id3::{find_id3v1, find_id3v2, find_lyrics3v2, ID3FindResults};
use crate::macros::decode_err;
use crate::probe::ParseOptions;
Expand All @@ -25,11 +24,8 @@ where

let mut stream_len = end - start;

#[cfg(feature = "id3v2")]
let mut id3v2_tag: Option<ID3v2Tag> = None;
#[cfg(feature = "id3v1")]
let mut id3v1_tag: Option<ID3v1Tag> = None;
#[cfg(feature = "ape")]
let mut ape_tag: Option<ApeTag> = None;

// ID3v2 tags are unsupported in APE files, but still possible
Expand All @@ -42,13 +38,10 @@ where
stream_len -= 10;
}

#[cfg(feature = "id3v2")]
{
let reader = &mut &*content;
let reader = &mut &*content;

let id3v2 = parse_id3v2(reader, header)?;
id3v2_tag = Some(id3v2)
}
let id3v2 = parse_id3v2(reader, header)?;
id3v2_tag = Some(id3v2);
}

let mut found_mac = false;
Expand Down Expand Up @@ -83,14 +76,8 @@ where
let ape_header = read_ape_header(data, false)?;
stream_len -= u64::from(ape_header.size);

#[cfg(feature = "ape")]
{
let ape = read_ape_tag(data, ape_header)?;
ape_tag = Some(ape)
}

#[cfg(not(feature = "ape"))]
data.seek(SeekFrom::Current(ape_header.size as i64))?;
let ape = read_ape_tag(data, ape_header)?;
ape_tag = Some(ape);
},
_ => {
decode_err!(@BAIL APE, "Invalid data found while reading header, expected any of [\"MAC \", \"APETAGEX\", \"ID3\"]")
Expand All @@ -107,10 +94,7 @@ where

if id3v1_header.is_some() {
stream_len -= 128;
#[cfg(feature = "id3v1")]
{
id3v1_tag = id3v1;
}
id3v1_tag = id3v1;
}

// Next, check for a Lyrics3v2 tag, and skip over it, as it's no use to us
Expand All @@ -134,14 +118,8 @@ where
let ape_header = read_ape_header(data, true)?;
stream_len -= u64::from(ape_header.size);

#[cfg(feature = "ape")]
{
let ape = read_ape_tag(data, ape_header)?;
ape_tag = Some(ape)
}

#[cfg(not(feature = "ape"))]
data.seek(SeekFrom::Current(ape_header.size as i64))?;
let ape = read_ape_tag(data, ape_header)?;
ape_tag = Some(ape);
}

let file_length = data.stream_position()?;
Expand All @@ -150,11 +128,8 @@ where
data.seek(SeekFrom::Start(mac_start))?;

Ok(ApeFile {
#[cfg(feature = "id3v1")]
id3v1_tag,
#[cfg(feature = "id3v2")]
id3v2_tag,
#[cfg(feature = "ape")]
ape_tag,
properties: if parse_options.read_properties {
super::properties::read_properties(data, stream_len, file_length)?
Expand Down
10 changes: 0 additions & 10 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,16 @@ pub enum ErrorKind {
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum ID3v2ErrorKind {
#[cfg(feature = "id3v2")]
/// Arises when an invalid picture format is parsed. Only applicable to [`ID3v2Version::V2`](crate::id3::v2::ID3v2Version::V2)
BadPictureFormat(String),
/// Arises when an invalid ID3v2 version is found
BadId3v2Version(u8, u8),
#[cfg(feature = "id3v2")]
/// Arises when a frame ID contains invalid characters (must be within `'A'..'Z'` or `'0'..'9'`)
BadFrameID,
#[cfg(feature = "id3v2")]
/// Arises when a frame doesn't have enough data
BadFrameLength,
#[cfg(feature = "id3v2")]
/// Arises when invalid data is encountered while reading an ID3v2 synchronized text frame
BadSyncText,
#[cfg(feature = "id3v2")]
/// Arises when attempting to write an invalid Frame (Bad `FrameID`/`FrameValue` pairing)
BadFrame(String, &'static str),
/// A catch-all for all remaining errors
Expand All @@ -101,22 +96,17 @@ impl Display for ID3v2ErrorKind {
"Found an invalid version (v{major}.{minor}), expected any major revision in: (2, \
3, 4)"
),
#[cfg(feature = "id3v2")]
ID3v2ErrorKind::BadFrameID => write!(f, "Failed to parse a frame ID"),
#[cfg(feature = "id3v2")]
ID3v2ErrorKind::BadFrameLength => write!(
f,
"Frame isn't long enough to extract the necessary information"
),
#[cfg(feature = "id3v2")]
ID3v2ErrorKind::BadSyncText => write!(f, "Encountered invalid data in SYLT frame"),
#[cfg(feature = "id3v2")]
ID3v2ErrorKind::BadFrame(ref frame_id, frame_value) => write!(
f,
"Attempted to write an invalid frame. ID: \"{}\", Value: \"{}\"",
frame_id, frame_value
),
#[cfg(feature = "id3v2")]
ID3v2ErrorKind::BadPictureFormat(format) => {
write!(f, "Picture: Found unexpected format \"{format}\"")
},
Expand Down
7 changes: 0 additions & 7 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,29 +817,22 @@ impl FileType {
/// ```
pub fn supports_tag_type(&self, tag_type: TagType) -> bool {
match self {
#[cfg(feature = "id3v2")]
FileType::AIFF | FileType::APE | FileType::MPEG | FileType::WAV | FileType::AAC
if tag_type == TagType::ID3v2 =>
{
true
},
#[cfg(feature = "aiff_text_chunks")]
FileType::AIFF if tag_type == TagType::AIFFText => true,
#[cfg(feature = "id3v1")]
FileType::APE | FileType::MPEG | FileType::WavPack | FileType::AAC
if tag_type == TagType::ID3v1 =>
{
true
},
#[cfg(feature = "ape")]
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
},
#[cfg(feature = "mp4_ilst")]
FileType::MP4 => tag_type == TagType::MP4ilst,
#[cfg(feature = "riff_info_list")]
FileType::WAV => tag_type == TagType::RIFFInfo,
FileType::Custom(c) => {
let resolver = crate::resolve::lookup_resolver(c);
Expand Down
5 changes: 0 additions & 5 deletions src/flac/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
pub(crate) mod block;
pub(crate) mod properties;
mod read;
#[cfg(feature = "vorbis_comments")]
pub(crate) mod write;

#[cfg(feature = "id3v2")]
use crate::id3::v2::tag::ID3v2Tag;
#[cfg(feature = "vorbis_comments")]
use crate::ogg::VorbisComments;
use crate::properties::FileProperties;

Expand All @@ -31,13 +28,11 @@ use lofty_attr::LoftyFile;
#[lofty(read_fn = "read::read_from")]
pub struct FlacFile {
/// An ID3v2 tag
#[cfg(feature = "id3v2")]
#[lofty(tag_type = "ID3v2")]
pub(crate) id3v2_tag: Option<ID3v2Tag>,
/// The vorbis comments contained in the file
///
/// NOTE: This field being `Some` does not mean the file has vorbis comments, as Picture blocks exist.
#[cfg(feature = "vorbis_comments")]
#[lofty(tag_type = "VorbisComments")]
pub(crate) vorbis_comments_tag: Option<VorbisComments>,
/// The file's audio properties
Expand Down
Loading