Misc: Remove vorbis_comments feature

This commit is contained in:
Serial 2023-01-04 23:55:04 -05:00 committed by Alex
parent 75bcd6fac3
commit 4e87434cf2
14 changed files with 38 additions and 84 deletions

View file

@ -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"
@ -30,9 +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"]
default = ["mp4_ilst", "ape", "id3v1", "id3v2", "aiff_text_chunks", "riff_info_list"]
mp4_ilst = []
vorbis_comments = ["base64"]
ape = []
id3v1 = []
id3v2 = ["flate2"]

View file

@ -833,7 +833,6 @@ impl FileType {
},
#[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
},

View file

@ -7,12 +7,10 @@
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;
@ -37,7 +35,6 @@ pub struct FlacFile {
/// 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

View file

@ -5,13 +5,11 @@ use crate::error::Result;
use crate::id3::v2::read::parse_id3v2;
use crate::id3::{find_id3v2, ID3FindResults};
use crate::macros::decode_err;
use crate::ogg::read::read_comments;
use crate::ogg::tag::VorbisComments;
use crate::picture::Picture;
use crate::probe::ParseOptions;
use crate::properties::FileProperties;
#[cfg(feature = "vorbis_comments")]
use crate::{
ogg::{read::read_comments, tag::VorbisComments},
picture::Picture,
};
use std::io::{Read, Seek, SeekFrom};
@ -42,7 +40,6 @@ where
let mut flac_file = FlacFile {
#[cfg(feature = "id3v2")]
id3v2_tag: None,
#[cfg(feature = "vorbis_comments")]
vorbis_comments_tag: None,
properties: FileProperties::default(),
};
@ -67,7 +64,6 @@ where
let mut last_block = stream_info.last;
#[cfg(feature = "vorbis_comments")]
let mut tag = VorbisComments {
vendor: String::new(),
items: vec![],
@ -83,9 +79,7 @@ where
}
match block.ty {
#[cfg(feature = "vorbis_comments")]
4 => read_comments(&mut &*block.content, block.content.len() as u64, &mut tag)?,
#[cfg(feature = "vorbis_comments")]
6 => tag
.pictures
.push(Picture::from_flac_bytes(&block.content, false)?),
@ -93,11 +87,8 @@ where
}
}
#[cfg(feature = "vorbis_comments")]
{
flac_file.vorbis_comments_tag =
(!(tag.items.is_empty() && tag.pictures.is_empty())).then_some(tag);
}
flac_file.vorbis_comments_tag =
(!(tag.items.is_empty() && tag.pictures.is_empty())).then_some(tag);
let (stream_length, file_length) = {
let current = data.stream_position()?;

View file

@ -180,7 +180,6 @@ pub use util::text::TextEncoding;
pub use crate::traits::{Accessor, TagExt};
#[cfg(feature = "vorbis_comments")]
pub use picture::PictureInformation;
pub use lofty_attr::LoftyFile;

View file

@ -7,7 +7,9 @@ pub(crate) mod constants;
pub(crate) mod opus;
pub(crate) mod read;
pub(crate) mod speex;
pub(crate) mod tag;
pub(crate) mod vorbis;
pub(crate) mod write;
use crate::error::Result;
use crate::macros::decode_err;
@ -18,19 +20,11 @@ use ogg_pager::Page;
// Exports
cfg_if::cfg_if! {
if #[cfg(feature = "vorbis_comments")] {
pub(crate) mod write;
pub(crate) mod tag;
pub use tag::VorbisComments;
}
}
pub use opus::properties::OpusProperties;
pub use opus::OpusFile;
pub use speex::properties::SpeexProperties;
pub use speex::SpeexFile;
pub use tag::VorbisComments;
pub use vorbis::properties::VorbisProperties;
pub use vorbis::VorbisFile;

View file

@ -1,7 +1,6 @@
pub(super) mod properties;
use super::find_last_page;
#[cfg(feature = "vorbis_comments")]
use super::tag::VorbisComments;
use crate::error::Result;
use crate::file::AudioFile;
@ -21,7 +20,6 @@ pub struct OpusFile {
/// The vorbis comments contained in the file
///
/// NOTE: While a metadata packet is required, it isn't required to actually have any data.
#[cfg(feature = "vorbis_comments")]
#[lofty(tag_type = "VorbisComments")]
pub(crate) vorbis_comments_tag: VorbisComments,
/// The file's audio properties
@ -38,8 +36,11 @@ impl AudioFile for OpusFile {
let file_information = super::read::read_from(reader, OPUSHEAD, OPUSTAGS, 2)?;
Ok(Self {
properties: if parse_options.read_properties { properties::read_properties(reader, file_information.1, &file_information.2)? } else { OpusProperties::default() },
#[cfg(feature = "vorbis_comments")]
properties: if parse_options.read_properties {
properties::read_properties(reader, file_information.1, &file_information.2)?
} else {
OpusProperties::default()
},
// Safe to unwrap, a metadata packet is mandatory in Opus
vorbis_comments_tag: file_information.0.unwrap(),
})

View file

@ -1,24 +1,16 @@
#[cfg(feature = "vorbis_comments")]
use super::tag::VorbisComments;
use super::verify_signature;
use crate::error::Result;
use crate::macros::{decode_err, err};
#[cfg(feature = "vorbis_comments")]
use crate::picture::Picture;
use std::io::{Read, Seek, SeekFrom};
#[cfg(feature = "vorbis_comments")]
use byteorder::{LittleEndian, ReadBytesExt};
use ogg_pager::{Packets, PageHeader};
#[cfg(feature = "vorbis_comments")]
pub type OGGTags = (Option<VorbisComments>, PageHeader, Packets);
#[cfg(not(feature = "vorbis_comments"))]
pub type OGGTags = (Option<()>, PageHeader, Packets);
#[cfg(feature = "vorbis_comments")]
pub(crate) fn read_comments<R>(data: &mut R, mut len: u64, tag: &mut VorbisComments) -> Result<()>
where
R: Read,
@ -128,16 +120,10 @@ where
// Remove the signature from the packet
metadata_packet = &metadata_packet[comment_sig.len()..];
#[cfg(feature = "vorbis_comments")]
{
let mut tag = VorbisComments::default();
let mut tag = VorbisComments::default();
let reader = &mut metadata_packet;
read_comments(reader, reader.len() as u64, &mut tag)?;
let reader = &mut metadata_packet;
read_comments(reader, reader.len() as u64, &mut tag)?;
Ok((Some(tag), first_page_header, packets))
}
#[cfg(not(feature = "vorbis_comments"))]
Ok((None, first_page_header, packets))
Ok((Some(tag), first_page_header, packets))
}

View file

@ -1,6 +1,5 @@
pub(super) mod properties;
#[cfg(feature = "vorbis_comments")]
use super::tag::VorbisComments;
use crate::error::Result;
use crate::file::AudioFile;
@ -20,7 +19,6 @@ pub struct SpeexFile {
/// The vorbis comments contained in the file
///
/// NOTE: While a metadata packet is required, it isn't required to actually have any data.
#[cfg(feature = "vorbis_comments")]
#[lofty(tag_type = "VorbisComments")]
pub(crate) vorbis_comments_tag: VorbisComments,
/// The file's audio properties
@ -37,11 +35,14 @@ impl AudioFile for SpeexFile {
let file_information = super::read::read_from(reader, SPEEXHEADER, &[], 2)?;
Ok(Self {
properties: if parse_options.read_properties { properties::read_properties(reader, file_information.1, &file_information.2)? } else { SpeexProperties::default() },
#[cfg(feature = "vorbis_comments")]
// Safe to unwrap, a metadata packet is mandatory in Speex
vorbis_comments_tag: file_information.0.unwrap(),
})
properties: if parse_options.read_properties {
properties::read_properties(reader, file_information.1, &file_information.2)?
} else {
SpeexProperties::default()
},
// Safe to unwrap, a metadata packet is mandatory in Speex
vorbis_comments_tag: file_information.0.unwrap(),
})
}
fn properties(&self) -> &Self::Properties {

View file

@ -1,7 +1,6 @@
pub(super) mod properties;
use super::find_last_page;
#[cfg(feature = "vorbis_comments")]
use super::tag::VorbisComments;
use crate::error::Result;
use crate::file::AudioFile;
@ -21,7 +20,6 @@ pub struct VorbisFile {
/// The vorbis comments contained in the file
///
/// NOTE: While a metadata packet is required, it isn't required to actually have any data.
#[cfg(feature = "vorbis_comments")]
#[lofty(tag_type = "VorbisComments")]
pub(crate) vorbis_comments_tag: VorbisComments,
/// The file's audio properties
@ -39,8 +37,11 @@ impl AudioFile for VorbisFile {
super::read::read_from(reader, VORBIS_IDENT_HEAD, VORBIS_COMMENT_HEAD, 3)?;
Ok(Self {
properties: if parse_options.read_properties { properties::read_properties(reader, file_information.1, &file_information.2)? } else { VorbisProperties::default() },
#[cfg(feature = "vorbis_comments")]
properties: if parse_options.read_properties {
properties::read_properties(reader, file_information.1, &file_information.2)?
} else {
VorbisProperties::default()
},
// Safe to unwrap, a metadata packet is mandatory in OGG Vorbis
vorbis_comments_tag: file_information.0.unwrap(),
})

View file

@ -55,7 +55,6 @@ pub(crate) fn write_to(file: &mut File, tag: &Tag, file_type: FileType) -> Resul
write(file, &mut comments_ref, format)
}
#[cfg(feature = "vorbis_comments")]
pub(crate) fn create_comments(
packet: &mut impl Write,
count: &mut u32,
@ -82,7 +81,6 @@ pub(crate) fn create_comments(
Ok(())
}
#[cfg(feature = "vorbis_comments")]
pub(super) fn write<'a, II, IP>(
file: &mut File,
tag: &mut VorbisCommentsRef<'a, II, IP>,

View file

@ -8,19 +8,18 @@ use crate::{
use std::borrow::Cow;
use std::fmt::{Debug, Formatter};
#[cfg(any(feature = "vorbis_comments", feature = "ape", feature = "id3v2"))]
#[cfg(any(feature = "ape", feature = "id3v2"))]
use std::io::Cursor;
use std::io::Read;
#[cfg(feature = "id3v2")]
use std::io::Write;
#[cfg(any(feature = "vorbis_comments", feature = "ape"))]
#[cfg(any(feature = "ape"))]
use std::io::{Seek, SeekFrom};
#[cfg(feature = "id3v2")]
use crate::util::text::TextEncoding;
#[cfg(any(feature = "vorbis_comments"))]
use byteorder::BigEndian;
#[cfg(any(feature = "vorbis_comments", feature = "id3v2", feature = "ape"))]
#[cfg(any(feature = "id3v2", feature = "ape"))]
use byteorder::ReadBytesExt;
#[cfg(feature = "id3v2")]
use byteorder::WriteBytesExt;
@ -146,7 +145,7 @@ pub enum PictureType {
impl PictureType {
// ID3/OGG specific methods
#[cfg(any(feature = "id3v2", feature = "vorbis_comments"))]
#[cfg(any(feature = "id3v2"))]
/// Get a u8 from a `PictureType` according to ID3v2 APIC
pub fn as_u8(&self) -> u8 {
match self {
@ -175,7 +174,7 @@ impl PictureType {
}
}
#[cfg(any(feature = "id3v2", feature = "vorbis_comments"))]
#[cfg(any(feature = "id3v2"))]
/// Get a `PictureType` from a u8 according to ID3v2 APIC
pub fn from_u8(byte: u8) -> Self {
match byte {
@ -269,7 +268,6 @@ impl PictureType {
///
/// This information is necessary for FLAC's `METADATA_BLOCK_PICTURE`.
/// See [`Picture::as_flac_bytes`] for more information.
#[cfg(feature = "vorbis_comments")]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Default)]
pub struct PictureInformation {
/// The picture's width in pixels
@ -282,7 +280,6 @@ pub struct PictureInformation {
pub num_colors: u32,
}
#[cfg(feature = "vorbis_comments")]
impl PictureInformation {
/// Attempt to extract [`PictureInformation`] from a [`Picture`]
///
@ -685,7 +682,6 @@ impl Picture {
))
}
#[cfg(feature = "vorbis_comments")]
/// Convert a [`Picture`] to a base64 encoded FLAC `METADATA_BLOCK_PICTURE` String
///
/// Use `encode` to convert the picture to a base64 encoded String ([RFC 4648 §4](http://www.faqs.org/rfcs/rfc4648.html))
@ -734,7 +730,6 @@ impl Picture {
}
}
#[cfg(feature = "vorbis_comments")]
/// Get a [`Picture`] from FLAC `METADATA_BLOCK_PICTURE` bytes:
///
/// NOTE: This takes both the base64 encoded string from Vorbis comments, and
@ -754,7 +749,6 @@ impl Picture {
}
}
#[cfg(feature = "vorbis_comments")]
fn from_flac_bytes_inner(content: &[u8]) -> Result<(Self, PictureInformation)> {
use crate::macros::try_vec;

View file

@ -12,10 +12,9 @@ pub(crate) use first_key;
// This is used to create the key/ItemKey maps
//
// First comes the feature attribute, followed by the name of the map.
// First comes the name of the map.
// Ex:
//
// #[cfg(feature = "ape")]
// APE_MAP;
//
// This is followed by the key value pairs separated by `=>`, with the key being the
@ -293,7 +292,6 @@ gen_map!(
);
gen_map!(
#[cfg(feature = "vorbis_comments")]
VORBIS_MAP;
"ALBUM" => AlbumTitle,
@ -434,7 +432,6 @@ gen_item_keys!(
#[cfg(feature = "riff_info_list")]
[TagType::RIFFInfo, RIFF_INFO_MAP],
#[cfg(feature = "vorbis_comments")]
[TagType::VorbisComments, VORBIS_MAP]
];

View file

@ -10,7 +10,6 @@ use crate::id3::v1::tag::Id3v1TagRef;
use crate::id3::v2::{self, tag::Id3v2TagRef, ID3v2TagFlags};
#[cfg(feature = "mp4_ilst")]
use crate::mp4::Ilst;
#[cfg(feature = "vorbis_comments")]
use crate::ogg::tag::{create_vorbis_comments_ref, VorbisCommentsRef};
#[cfg(feature = "ape")]
use ape::tag::ApeTagRef;
@ -29,7 +28,6 @@ pub(crate) fn write_tag(tag: &Tag, file: &mut File, file_type: FileType) -> Resu
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),
#[cfg(feature = "vorbis_comments")]
FileType::Opus | FileType::Speex | FileType::Vorbis => {
crate::ogg::write::write_to(file, tag, file_type)
},
@ -63,7 +61,6 @@ pub(crate) fn dump_tag<W: Write>(tag: &Tag, writer: &mut W) -> Result<()> {
.dump_to(writer),
#[cfg(feature = "mp4_ilst")]
TagType::MP4ilst => Into::<Ilst>::into(tag.clone()).as_ref().dump_to(writer),
#[cfg(feature = "vorbis_comments")]
TagType::VorbisComments => {
let (vendor, items, pictures) = create_vorbis_comments_ref(tag);