Make filepath an optional dependency

Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
Serial 2021-05-16 02:47:26 -04:00
parent 7f0501d95d
commit 79cbbd5339
5 changed files with 12 additions and 10 deletions

View file

@ -12,6 +12,7 @@ categories = ["accessibility", "multimedia::audio"]
[dependencies] [dependencies]
# Ape # Ape
ape = {version = "0.3.0", optional = true} ape = {version = "0.3.0", optional = true}
filepath = { version = "0.1.1", optional = true } # ape crate only accepts paths for some reason
# Wav # Wav
riff = {version = "1.0.1", optional = true} riff = {version = "1.0.1", optional = true}
# Mp3 # Mp3
@ -28,9 +29,9 @@ metaflac = {version = "0.2.4", optional = true}
opus_headers = {version = "0.1.2", optional = true} opus_headers = {version = "0.1.2", optional = true}
# Errors # Errors
thiserror = "1.0.24" thiserror = "1.0.24"
base64 = "0.13.0" base64 = "0.13.0"
byteorder = "1.4.3" byteorder = "1.4.3"
filepath = "0.1.1"
[features] [features]
default = ["full"] default = ["full"]
@ -39,7 +40,8 @@ mp4 = ["mp4ameta"]
flac = ["metaflac"] flac = ["metaflac"]
opus = ["opus_headers"] opus = ["opus_headers"]
vorbis = ["lewton", "ogg"] vorbis = ["lewton", "ogg"]
all_tags = ["vorbis", "opus", "flac", "mp4", "id3", "riff", "ape"] monkey = ["ape", "filepath"]
all_tags = ["vorbis", "opus", "flac", "mp4", "id3", "riff", "monkey"]
duration = ["mp3-duration"] duration = ["mp3-duration"]
[dev-dependencies] [dev-dependencies]

View file

@ -1,4 +1,4 @@
#![cfg(feature = "ape")] #![cfg(feature = "monkey")]
use crate::{ use crate::{
impl_tag, Album, AnyTag, AudioTag, AudioTagEdit, AudioTagWrite, Picture, Result, TagType, impl_tag, Album, AnyTag, AudioTag, AudioTagEdit, AudioTagWrite, Picture, Result, TagType,

View file

@ -4,7 +4,7 @@ pub(crate) mod mp4_tag;
pub(crate) mod riff_tag; pub(crate) mod riff_tag;
pub(crate) mod vorbis_tag; pub(crate) mod vorbis_tag;
#[cfg(feature = "ape")] #[cfg(feature = "monkey")]
pub use ape_tag::ApeTag; pub use ape_tag::ApeTag;
#[cfg(feature = "id3")] #[cfg(feature = "id3")]
pub use id3_tag::Id3v2Tag; pub use id3_tag::Id3v2Tag;

View file

@ -4,7 +4,7 @@ use crate::{AudioTag, Error, Result};
use std::io::Seek; use std::io::Seek;
use std::path::Path; use std::path::Path;
#[cfg(feature = "ape")] #[cfg(feature = "monkey")]
const MAC: [u8; 3] = [77, 65, 67]; const MAC: [u8; 3] = [77, 65, 67];
#[cfg(feature = "id3")] #[cfg(feature = "id3")]
const ID3: [u8; 3] = [73, 68, 51]; const ID3: [u8; 3] = [73, 68, 51];
@ -90,7 +90,7 @@ impl Tag {
fn match_tag(path: impl AsRef<Path>, tag_type: TagType) -> Result<Box<dyn AudioTag>> { fn match_tag(path: impl AsRef<Path>, tag_type: TagType) -> Result<Box<dyn AudioTag>> {
match tag_type { match tag_type {
#[cfg(feature = "ape")] #[cfg(feature = "monkey")]
TagType::Ape => Ok(Box::new(ApeTag::read_from_path(path)?)), TagType::Ape => Ok(Box::new(ApeTag::read_from_path(path)?)),
#[cfg(feature = "id3")] #[cfg(feature = "id3")]
TagType::Id3v2(format) => Ok(Box::new(Id3v2Tag::read_from_path(path, &format)?)), TagType::Id3v2(format) => Ok(Box::new(Id3v2Tag::read_from_path(path, &format)?)),
@ -107,7 +107,7 @@ impl Tag {
/// The tag type, based on the file extension. /// The tag type, based on the file extension.
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum TagType { pub enum TagType {
#[cfg(feature = "ape")] #[cfg(feature = "monkey")]
/// Common file extensions: `.ape` /// Common file extensions: `.ape`
Ape, Ape,
#[cfg(feature = "id3")] #[cfg(feature = "id3")]
@ -155,7 +155,7 @@ pub enum Id3Format {
impl TagType { impl TagType {
fn try_from_ext(ext: &str) -> Result<Self> { fn try_from_ext(ext: &str) -> Result<Self> {
match ext { match ext {
#[cfg(feature = "ape")] #[cfg(feature = "monkey")]
"ape" => Ok(Self::Ape), "ape" => Ok(Self::Ape),
#[cfg(feature = "id3")] #[cfg(feature = "id3")]
"aiff" | "aif" => Ok(Self::Id3v2(Id3Format::Form)), "aiff" | "aif" => Ok(Self::Id3v2(Id3Format::Form)),
@ -180,7 +180,7 @@ impl TagType {
} }
match data[0] { match data[0] {
#[cfg(feature = "ape")] #[cfg(feature = "monkey")]
77 if data.starts_with(&MAC) => Ok(Self::Ape), 77 if data.starts_with(&MAC) => Ok(Self::Ape),
#[cfg(feature = "id3")] #[cfg(feature = "id3")]
73 if data.starts_with(&ID3) => Ok(Self::Id3v2(Id3Format::Default)), 73 if data.starts_with(&ID3) => Ok(Self::Id3v2(Id3Format::Default)),

View file

@ -169,7 +169,7 @@ pub trait ToAnyTag: ToAny {
// TODO: write a macro or something that implement this method for every tag type so that if the // TODO: write a macro or something that implement this method for every tag type so that if the
// TODO: target type is the same, just return self // TODO: target type is the same, just return self
match tag_type { match tag_type {
#[cfg(feature = "ape")] #[cfg(feature = "monkey")]
TagType::Ape => Box::new(ApeTag::from(self.to_anytag())), TagType::Ape => Box::new(ApeTag::from(self.to_anytag())),
#[cfg(feature = "id3")] #[cfg(feature = "id3")]
TagType::Id3v2(_) => Box::new(Id3v2Tag::from(self.to_anytag())), TagType::Id3v2(_) => Box::new(Id3v2Tag::from(self.to_anytag())),