Skip to content

Commit

Permalink
Misc: Remove id3v2{_restrictions} features
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed Jan 5, 2023
1 parent 39c338e commit 823f931
Show file tree
Hide file tree
Showing 24 changed files with 111 additions and 202 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ once_cell = "1.16.0"
paste = "1.0.11"

[features]
default = ["id3v2"]
id3v2 = ["flate2"]
id3v2_restrictions = []
default = ["id3v2_compression_support"]
id3v2_compression_support = ["flate2"]

[dev-dependencies]
# WAV properties validity tests
Expand Down
1 change: 0 additions & 1 deletion src/aac/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ 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>,
#[lofty(tag_type = "ID3v1")]
Expand Down
19 changes: 8 additions & 11 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
2 changes: 0 additions & 2 deletions src/ape/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mod read;
pub(crate) mod tag;

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

use lofty_attr::LoftyFile;
Expand All @@ -33,7 +32,6 @@ pub struct ApeFile {
#[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
Expand Down
15 changes: 5 additions & 10 deletions src/ape/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use super::tag::ApeTag;
use super::{ApeFile, ApeProperties};
use crate::error::Result;
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 @@ -24,7 +24,6 @@ where

let mut stream_len = end - start;

#[cfg(feature = "id3v2")]
let mut id3v2_tag: Option<ID3v2Tag> = None;
let mut id3v1_tag: Option<ID3v1Tag> = None;
let mut ape_tag: Option<ApeTag> = None;
Expand All @@ -39,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 @@ -133,7 +129,6 @@ where

Ok(ApeFile {
id3v1_tag,
#[cfg(feature = "id3v2")]
id3v2_tag,
ape_tag,
properties: if parse_options.read_properties {
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
1 change: 0 additions & 1 deletion src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,6 @@ 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 =>
{
Expand Down
2 changes: 0 additions & 2 deletions src/flac/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub(crate) mod properties;
mod read;
pub(crate) mod write;

#[cfg(feature = "id3v2")]
use crate::id3::v2::tag::ID3v2Tag;
use crate::ogg::VorbisComments;
use crate::properties::FileProperties;
Expand All @@ -29,7 +28,6 @@ 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
Expand Down
11 changes: 3 additions & 8 deletions src/flac/read.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::block::Block;
use super::FlacFile;
use crate::error::Result;
#[cfg(feature = "id3v2")]
use crate::id3::v2::read::parse_id3v2;
use crate::id3::{find_id3v2, ID3FindResults};
use crate::macros::decode_err;
Expand Down Expand Up @@ -38,21 +37,17 @@ where
R: Read + Seek,
{
let mut flac_file = FlacFile {
#[cfg(feature = "id3v2")]
id3v2_tag: None,
vorbis_comments_tag: None,
properties: FileProperties::default(),
};

// It is possible for a FLAC file to contain an ID3v2 tag
if let ID3FindResults(Some(header), Some(content)) = find_id3v2(data, true)? {
#[cfg(feature = "id3v2")]
{
let reader = &mut &*content;
let reader = &mut &*content;

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

let stream_info = verify_flac(data)?;
Expand Down
2 changes: 0 additions & 2 deletions src/id3/v2/flags.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(feature = "id3v2_restrictions")]
use super::restrictions::TagRestrictions;

/// Flags that apply to the entire tag
Expand All @@ -17,7 +16,6 @@ pub struct ID3v2TagFlags {
///
/// This is calculated if the tag is written
pub crc: bool,
#[cfg(feature = "id3v2_restrictions")]
/// Restrictions on the tag, written in the extended header
///
/// In addition to being setting this flag, all restrictions must be provided. See [`TagRestrictions`]
Expand Down
6 changes: 6 additions & 0 deletions src/id3/v2/frame/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl Frame {
content = crate::id3::v2::util::unsynch_content(content.as_slice())?;
}

#[cfg(feature = "id3v2_compression_support")]
if flags.compression {
let mut decompressed = Vec::new();
flate2::Decompress::new(true)
Expand All @@ -44,6 +45,11 @@ impl Frame {
content = decompressed
}

#[cfg(not(feature = "id3v2_compression_support"))]
if flags.compression {
crate::macros::decode_err!(@BAIL ID3v2, "Encountered a compressed ID3v2 frame, support is disabled")
}

let mut content_reader = &*content;

// Get the encryption method symbol
Expand Down
58 changes: 22 additions & 36 deletions src/id3/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
//! * [Frame]
mod flags;
mod frame;
mod items;
pub(crate) mod read;
mod restrictions;
pub(crate) mod tag;
pub mod util;
pub(crate) mod write;

use crate::error::{ID3v2Error, ID3v2ErrorKind, Result};
use crate::macros::err;
Expand All @@ -18,42 +24,26 @@ use std::io::Read;

use byteorder::{BigEndian, ByteOrder, ReadBytesExt};

cfg_if::cfg_if! {
if #[cfg(feature = "id3v2")] {
pub use flags::ID3v2TagFlags;
pub use util::upgrade::{upgrade_v2, upgrade_v3};
// Exports

pub(crate) mod tag;
pub use tag::ID3v2Tag;
pub use flags::ID3v2TagFlags;
pub use util::upgrade::{upgrade_v2, upgrade_v3};

mod items;
pub use items::encoded_text_frame::EncodedTextFrame;
pub use items::language_frame::LanguageFrame;
pub use items::encapsulated_object::{GEOBInformation, GeneralEncapsulatedObject};
pub use items::sync_text::{SyncTextContentType, SyncTextInformation, SynchronizedText, TimestampFormat};
pub use tag::ID3v2Tag;

mod frame;
pub use frame::id::FrameID;
pub use frame::Frame;
pub use frame::FrameFlags;
pub use frame::FrameValue;
pub use items::encapsulated_object::{GEOBInformation, GeneralEncapsulatedObject};
pub use items::encoded_text_frame::EncodedTextFrame;
pub use items::language_frame::LanguageFrame;
pub use items::sync_text::{
SyncTextContentType, SyncTextInformation, SynchronizedText, TimestampFormat,
};

pub(crate) mod read;
pub(crate) mod write;
}
}

cfg_if::cfg_if! {
if #[cfg(feature = "id3v2_restrictions")] {
mod restrictions;
pub use restrictions::{
ImageSizeRestrictions, TagRestrictions, TagSizeRestrictions, TextSizeRestrictions,
};
}
}
pub use frame::id::FrameID;
pub use frame::{Frame, FrameFlags, FrameValue};

#[cfg(not(feature = "id3v2"))]
use flags::ID3v2TagFlags;
pub use restrictions::{
ImageSizeRestrictions, TagRestrictions, TagSizeRestrictions, TextSizeRestrictions,
};

/// The ID3v2 version
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
Expand All @@ -68,7 +58,6 @@ pub enum ID3v2Version {

#[derive(Copy, Clone)]
pub(crate) struct ID3v2Header {
#[cfg(feature = "id3v2")]
pub version: ID3v2Version,
pub flags: ID3v2TagFlags,
pub size: u32,
Expand Down Expand Up @@ -114,8 +103,7 @@ where
&& flags & 0x20 == 0x20,
footer: (version == ID3v2Version::V4 || version == ID3v2Version::V3)
&& flags & 0x10 == 0x10,
crc: false, // Retrieved later if applicable
#[cfg(feature = "id3v2_restrictions")]
crc: false, // Retrieved later if applicable
restrictions: None, // Retrieved later if applicable
};

Expand Down Expand Up @@ -150,7 +138,6 @@ where
bytes.read_exact(&mut crc)?;
}

#[cfg(feature = "id3v2_restrictions")]
if extended_flags & 0x10 == 0x10 {
// We don't care about the length byte, it is always 1
let _data_length = bytes.read_u8()?;
Expand All @@ -164,7 +151,6 @@ where
}

Ok(ID3v2Header {
#[cfg(feature = "id3v2")]
version,
flags: flags_parsed,
size,
Expand Down
Loading

0 comments on commit 823f931

Please sign in to comment.