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]
# Ape
ape = {version = "0.3.0", optional = true}
filepath = { version = "0.1.1", optional = true } # ape crate only accepts paths for some reason
# Wav
riff = {version = "1.0.1", optional = true}
# Mp3
@ -28,9 +29,9 @@ metaflac = {version = "0.2.4", optional = true}
opus_headers = {version = "0.1.2", optional = true}
# Errors
thiserror = "1.0.24"
base64 = "0.13.0"
byteorder = "1.4.3"
filepath = "0.1.1"
[features]
default = ["full"]
@ -39,7 +40,8 @@ mp4 = ["mp4ameta"]
flac = ["metaflac"]
opus = ["opus_headers"]
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"]
[dev-dependencies]

View file

@ -1,4 +1,4 @@
#![cfg(feature = "ape")]
#![cfg(feature = "monkey")]
use crate::{
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 vorbis_tag;
#[cfg(feature = "ape")]
#[cfg(feature = "monkey")]
pub use ape_tag::ApeTag;
#[cfg(feature = "id3")]
pub use id3_tag::Id3v2Tag;

View file

@ -4,7 +4,7 @@ use crate::{AudioTag, Error, Result};
use std::io::Seek;
use std::path::Path;
#[cfg(feature = "ape")]
#[cfg(feature = "monkey")]
const MAC: [u8; 3] = [77, 65, 67];
#[cfg(feature = "id3")]
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>> {
match tag_type {
#[cfg(feature = "ape")]
#[cfg(feature = "monkey")]
TagType::Ape => Ok(Box::new(ApeTag::read_from_path(path)?)),
#[cfg(feature = "id3")]
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.
#[derive(Clone, Debug, PartialEq)]
pub enum TagType {
#[cfg(feature = "ape")]
#[cfg(feature = "monkey")]
/// Common file extensions: `.ape`
Ape,
#[cfg(feature = "id3")]
@ -155,7 +155,7 @@ pub enum Id3Format {
impl TagType {
fn try_from_ext(ext: &str) -> Result<Self> {
match ext {
#[cfg(feature = "ape")]
#[cfg(feature = "monkey")]
"ape" => Ok(Self::Ape),
#[cfg(feature = "id3")]
"aiff" | "aif" => Ok(Self::Id3v2(Id3Format::Form)),
@ -180,7 +180,7 @@ impl TagType {
}
match data[0] {
#[cfg(feature = "ape")]
#[cfg(feature = "monkey")]
77 if data.starts_with(&MAC) => Ok(Self::Ape),
#[cfg(feature = "id3")]
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: target type is the same, just return self
match tag_type {
#[cfg(feature = "ape")]
#[cfg(feature = "monkey")]
TagType::Ape => Box::new(ApeTag::from(self.to_anytag())),
#[cfg(feature = "id3")]
TagType::Id3v2(_) => Box::new(Id3v2Tag::from(self.to_anytag())),