mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-12 21:52:33 +00:00
Give features better names
This commit is contained in:
parent
de334cc62b
commit
6b770dc14c
10 changed files with 40 additions and 57 deletions
|
@ -37,10 +37,10 @@ filepath = "0.1.1"
|
||||||
default = ["full"]
|
default = ["full"]
|
||||||
full = ["all_tags", "duration"]
|
full = ["all_tags", "duration"]
|
||||||
mp4 = ["mp4ameta"]
|
mp4 = ["mp4ameta"]
|
||||||
mp3 = ["id3"]
|
flac = ["metaflac"]
|
||||||
wav = ["riff"]
|
opus = ["opus_headers"]
|
||||||
vorbis = ["lewton", "metaflac", "opus_headers", "ogg"]
|
vorbis = ["lewton", "ogg"]
|
||||||
all_tags = ["vorbis", "mp4", "mp3", "wav", "ape"]
|
all_tags = ["vorbis", "opus", "flac", "mp4", "id3", "riff", "ape"]
|
||||||
duration = ["mp3-duration"]
|
duration = ["mp3-duration"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// Used to determine the WAV metadata format
|
// Used to determine the WAV metadata format
|
||||||
pub const LIST_ID: &[u8; 4] = b"LIST";
|
pub const LIST_ID: &[u8; 4] = b"LIST";
|
||||||
pub const ID3_ID: &[u8; 4] = b"ID3 "; // TODO
|
|
||||||
|
|
||||||
// FourCC
|
// FourCC
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use super::constants::{ID3_ID, LIST_ID};
|
use super::constants::LIST_ID;
|
||||||
use crate::{Error, Result};
|
use crate::{Error, Result};
|
||||||
|
|
||||||
use byteorder::{LittleEndian, ReadBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::{Cursor, Read, Seek};
|
use std::io::{Cursor, Read, Seek};
|
||||||
|
@ -22,29 +23,11 @@ where
|
||||||
list = Some(child);
|
list = Some(child);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if value_bytes == ID3_ID {
|
|
||||||
#[cfg(feature = "mp3")]
|
|
||||||
{
|
|
||||||
list = Some(child);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "mp3"))]
|
|
||||||
return Err(Error::Wav(
|
|
||||||
"WAV file has an id3 tag, but `mp3` feature is not enabled.",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return if let Some(list) = list {
|
return if let Some(list) = list {
|
||||||
let mut content = list.read_contents(&mut data)?;
|
let mut content = list.read_contents(&mut data)?;
|
||||||
|
|
||||||
#[cfg(feature = "mp3")]
|
|
||||||
if &list.id().value == ID3_ID {
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
content.drain(0..4); // Get rid of the chunk ID
|
content.drain(0..4); // Get rid of the chunk ID
|
||||||
let mut cursor = Cursor::new(&*content);
|
let mut cursor = Cursor::new(&*content);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![cfg(feature = "mp3")]
|
#![cfg(feature = "id3")]
|
||||||
|
|
||||||
use crate::tag::RiffFormat;
|
use crate::tag::RiffFormat;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
|
@ -6,11 +6,11 @@ pub(crate) mod vorbis_tag;
|
||||||
|
|
||||||
#[cfg(feature = "ape")]
|
#[cfg(feature = "ape")]
|
||||||
pub use ape_tag::ApeTag;
|
pub use ape_tag::ApeTag;
|
||||||
#[cfg(feature = "mp3")]
|
#[cfg(feature = "id3")]
|
||||||
pub use id3_tag::Id3v2Tag;
|
pub use id3_tag::Id3v2Tag;
|
||||||
#[cfg(feature = "mp4")]
|
#[cfg(feature = "mp4")]
|
||||||
pub use mp4_tag::Mp4Tag;
|
pub use mp4_tag::Mp4Tag;
|
||||||
#[cfg(feature = "wav")]
|
#[cfg(feature = "riff")]
|
||||||
pub use riff_tag::RiffTag;
|
pub use riff_tag::RiffTag;
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(any(feature = "vorbis", feature = "opus", feature = "flac"))]
|
||||||
pub use vorbis_tag::VorbisTag;
|
pub use vorbis_tag::VorbisTag;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#![cfg(feature = "riff")]
|
||||||
|
|
||||||
use crate::components::logic;
|
use crate::components::logic;
|
||||||
use crate::tag::RiffFormat;
|
use crate::tag::RiffFormat;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![cfg(feature = "vorbis")]
|
#![cfg(any(feature = "vorbis", feature = "opus", feature = "flac"))]
|
||||||
|
|
||||||
use crate::components::logic;
|
use crate::components::logic;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
47
src/tag.rs
47
src/tag.rs
|
@ -5,19 +5,19 @@ use std::path::Path;
|
||||||
|
|
||||||
#[cfg(feature = "ape")]
|
#[cfg(feature = "ape")]
|
||||||
const MAC: [u8; 3] = [77, 65, 67];
|
const MAC: [u8; 3] = [77, 65, 67];
|
||||||
#[cfg(feature = "mp3")]
|
#[cfg(feature = "id3")]
|
||||||
const ID3: [u8; 3] = [73, 68, 51];
|
const ID3: [u8; 3] = [73, 68, 51];
|
||||||
#[cfg(feature = "mp4")]
|
#[cfg(feature = "mp4")]
|
||||||
const FTYP: [u8; 4] = [102, 116, 121, 112];
|
const FTYP: [u8; 4] = [102, 116, 121, 112];
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(feature = "opus")]
|
||||||
const OPUSHEAD: [u8; 8] = [79, 112, 117, 115, 72, 101, 97, 100];
|
const OPUSHEAD: [u8; 8] = [79, 112, 117, 115, 72, 101, 97, 100];
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(feature = "flac")]
|
||||||
const FLAC: [u8; 4] = [102, 76, 97, 67];
|
const FLAC: [u8; 4] = [102, 76, 97, 67];
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(any(feature = "vorbis", feature = "opus", feature = "flac"))]
|
||||||
const OGGS: [u8; 4] = [79, 103, 103, 83];
|
const OGGS: [u8; 4] = [79, 103, 103, 83];
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(feature = "vorbis")]
|
||||||
const VORBIS: [u8; 6] = [118, 111, 114, 98, 105, 115];
|
const VORBIS: [u8; 6] = [118, 111, 114, 98, 105, 115];
|
||||||
#[cfg(feature = "wav")]
|
#[cfg(feature = "riff")]
|
||||||
const RIFF: [u8; 4] = [82, 73, 70, 70];
|
const RIFF: [u8; 4] = [82, 73, 70, 70];
|
||||||
|
|
||||||
/// A builder for `Box<dyn AudioTag>`. If you do not want a trait object, you can use individual types.
|
/// A builder for `Box<dyn AudioTag>`. If you do not want a trait object, you can use individual types.
|
||||||
|
@ -77,15 +77,15 @@ impl Tag {
|
||||||
match tag_type {
|
match tag_type {
|
||||||
#[cfg(feature = "ape")]
|
#[cfg(feature = "ape")]
|
||||||
TagType::Ape => Ok(Box::new(ApeTag::read_from_path(path)?)),
|
TagType::Ape => Ok(Box::new(ApeTag::read_from_path(path)?)),
|
||||||
#[cfg(feature = "mp3")]
|
#[cfg(feature = "id3")]
|
||||||
TagType::Id3v2 | TagType::Riff(RiffFormat::ID3) => {
|
TagType::Id3v2 | TagType::Riff(RiffFormat::ID3) => {
|
||||||
Ok(Box::new(Id3v2Tag::read_from_path(path, tag_type)?))
|
Ok(Box::new(Id3v2Tag::read_from_path(path, tag_type)?))
|
||||||
},
|
},
|
||||||
#[cfg(feature = "mp4")]
|
#[cfg(feature = "mp4")]
|
||||||
TagType::Mp4 => Ok(Box::new(Mp4Tag::read_from_path(path)?)),
|
TagType::Mp4 => Ok(Box::new(Mp4Tag::read_from_path(path)?)),
|
||||||
#[cfg(feature = "wav")]
|
#[cfg(feature = "riff")]
|
||||||
TagType::Riff(RiffFormat::Info) => Ok(Box::new(RiffTag::read_from_path(path)?)),
|
TagType::Riff(RiffFormat::Info) => Ok(Box::new(RiffTag::read_from_path(path)?)),
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(any(feature = "vorbis", feature = "flac", feature = "opus"))]
|
||||||
TagType::Vorbis(format) => Ok(Box::new(VorbisTag::read_from_path(path, format.clone())?)),
|
TagType::Vorbis(format) => Ok(Box::new(VorbisTag::read_from_path(path, format.clone())?)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ pub enum TagType {
|
||||||
#[cfg(feature = "ape")]
|
#[cfg(feature = "ape")]
|
||||||
/// Common file extensions: `.ape`
|
/// Common file extensions: `.ape`
|
||||||
Ape,
|
Ape,
|
||||||
#[cfg(feature = "mp3")]
|
#[cfg(feature = "id3")]
|
||||||
/// Common file extensions: `.mp3`
|
/// Common file extensions: `.mp3`
|
||||||
Id3v2,
|
Id3v2,
|
||||||
#[cfg(feature = "mp4")]
|
#[cfg(feature = "mp4")]
|
||||||
|
@ -106,7 +106,7 @@ pub enum TagType {
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(feature = "vorbis")]
|
||||||
/// Represents multiple formats, see [`VorbisFormat`] for extensions.
|
/// Represents multiple formats, see [`VorbisFormat`] for extensions.
|
||||||
Vorbis(VorbisFormat),
|
Vorbis(VorbisFormat),
|
||||||
#[cfg(feature = "wav")]
|
#[cfg(feature = "riff")]
|
||||||
/// Represents multiple formats, see [`RiffFormat`] for extensions.
|
/// Represents multiple formats, see [`RiffFormat`] for extensions.
|
||||||
Riff(RiffFormat),
|
Riff(RiffFormat),
|
||||||
}
|
}
|
||||||
|
@ -117,21 +117,20 @@ pub enum VorbisFormat {
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(feature = "vorbis")]
|
||||||
/// Common file extensions: `.ogg, .oga`
|
/// Common file extensions: `.ogg, .oga`
|
||||||
Ogg,
|
Ogg,
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(feature = "opus")]
|
||||||
/// Common file extensions: `.opus`
|
/// Common file extensions: `.opus`
|
||||||
Opus,
|
Opus,
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(feature = "flac")]
|
||||||
/// Common file extensions: `.flac`
|
/// Common file extensions: `.flac`
|
||||||
Flac,
|
Flac,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
#[cfg(feature = "wav")]
|
#[cfg(feature = "riff")]
|
||||||
pub enum RiffFormat {
|
pub enum RiffFormat {
|
||||||
#[cfg(feature = "wav")]
|
|
||||||
/// Metadata is stored in a RIFF INFO list
|
/// Metadata is stored in a RIFF INFO list
|
||||||
Info,
|
Info,
|
||||||
#[cfg(feature = "mp3")]
|
#[cfg(feature = "id3")]
|
||||||
/// Metadata is stored in an ID3 tag
|
/// Metadata is stored in an ID3 tag
|
||||||
ID3,
|
ID3,
|
||||||
}
|
}
|
||||||
|
@ -141,17 +140,17 @@ impl TagType {
|
||||||
match ext {
|
match ext {
|
||||||
#[cfg(feature = "ape")]
|
#[cfg(feature = "ape")]
|
||||||
"ape" => Ok(Self::Ape),
|
"ape" => Ok(Self::Ape),
|
||||||
#[cfg(feature = "mp3")]
|
#[cfg(feature = "id3")]
|
||||||
"mp3" => Ok(Self::Id3v2),
|
"mp3" => Ok(Self::Id3v2),
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(feature = "opus")]
|
||||||
"opus" => Ok(Self::Vorbis(VorbisFormat::Opus)),
|
"opus" => Ok(Self::Vorbis(VorbisFormat::Opus)),
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(feature = "flac")]
|
||||||
"flac" => Ok(Self::Vorbis(VorbisFormat::Flac)),
|
"flac" => Ok(Self::Vorbis(VorbisFormat::Flac)),
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(feature = "vorbis")]
|
||||||
"ogg" | "oga" => Ok(Self::Vorbis(VorbisFormat::Ogg)),
|
"ogg" | "oga" => Ok(Self::Vorbis(VorbisFormat::Ogg)),
|
||||||
#[cfg(feature = "mp4")]
|
#[cfg(feature = "mp4")]
|
||||||
"m4a" | "m4b" | "m4p" | "m4v" | "isom" | "mp4" => Ok(Self::Mp4),
|
"m4a" | "m4b" | "m4p" | "m4v" | "isom" | "mp4" => Ok(Self::Mp4),
|
||||||
#[cfg(feature = "wav")]
|
#[cfg(all(feature = "riff", feature = "id3"))]
|
||||||
"wav" | "wave" => Ok(Self::Riff(RiffFormat::ID3)),
|
"wav" | "wave" => Ok(Self::Riff(RiffFormat::ID3)),
|
||||||
_ => Err(Error::UnsupportedFormat(ext.to_owned())),
|
_ => Err(Error::UnsupportedFormat(ext.to_owned())),
|
||||||
}
|
}
|
||||||
|
@ -164,11 +163,11 @@ impl TagType {
|
||||||
match data[0] {
|
match data[0] {
|
||||||
#[cfg(feature = "ape")]
|
#[cfg(feature = "ape")]
|
||||||
77 if data.starts_with(&MAC) => Ok(Self::Ape),
|
77 if data.starts_with(&MAC) => Ok(Self::Ape),
|
||||||
#[cfg(feature = "mp3")]
|
#[cfg(feature = "id3")]
|
||||||
73 if data.starts_with(&ID3) => Ok(Self::Id3v2),
|
73 if data.starts_with(&ID3) => Ok(Self::Id3v2),
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(feature = "flac")]
|
||||||
102 if data.starts_with(&FLAC) => Ok(Self::Vorbis(VorbisFormat::Flac)),
|
102 if data.starts_with(&FLAC) => Ok(Self::Vorbis(VorbisFormat::Flac)),
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(any(feature = "vorbis", feature = "opus"))]
|
||||||
79 if data.starts_with(&OGGS) => {
|
79 if data.starts_with(&OGGS) => {
|
||||||
if data[29..35] == VORBIS {
|
if data[29..35] == VORBIS {
|
||||||
return Ok(Self::Vorbis(VorbisFormat::Ogg));
|
return Ok(Self::Vorbis(VorbisFormat::Ogg));
|
||||||
|
@ -180,9 +179,9 @@ impl TagType {
|
||||||
|
|
||||||
Err(Error::UnknownFormat)
|
Err(Error::UnknownFormat)
|
||||||
},
|
},
|
||||||
#[cfg(feature = "wav")]
|
#[cfg(feature = "riff")]
|
||||||
82 if data.starts_with(&RIFF) => {
|
82 if data.starts_with(&RIFF) => {
|
||||||
#[cfg(feature = "mp3")]
|
#[cfg(feature = "id3")]
|
||||||
{
|
{
|
||||||
use byteorder::{LittleEndian, ReadBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
|
@ -114,13 +114,13 @@ pub trait ToAnyTag: ToAny {
|
||||||
match tag_type {
|
match tag_type {
|
||||||
#[cfg(feature = "ape")]
|
#[cfg(feature = "ape")]
|
||||||
TagType::Ape => Box::new(ApeTag::from(self.to_anytag())),
|
TagType::Ape => Box::new(ApeTag::from(self.to_anytag())),
|
||||||
#[cfg(feature = "mp3")]
|
#[cfg(feature = "id3")]
|
||||||
TagType::Id3v2 | TagType::Riff(RiffFormat::ID3) => Box::new(Id3v2Tag::from(self.to_anytag())),
|
TagType::Id3v2 | TagType::Riff(RiffFormat::ID3) => Box::new(Id3v2Tag::from(self.to_anytag())),
|
||||||
#[cfg(feature = "mp4")]
|
#[cfg(feature = "mp4")]
|
||||||
TagType::Mp4 => Box::new(Mp4Tag::from(self.to_anytag())),
|
TagType::Mp4 => Box::new(Mp4Tag::from(self.to_anytag())),
|
||||||
#[cfg(feature = "vorbis")]
|
#[cfg(any(feature = "vorbis", feature = "flac", feature = "opus"))]
|
||||||
TagType::Vorbis(_) => Box::new(VorbisTag::from(self.to_anytag())),
|
TagType::Vorbis(_) => Box::new(VorbisTag::from(self.to_anytag())),
|
||||||
#[cfg(feature = "wav")]
|
#[cfg(feature = "riff")]
|
||||||
TagType::Riff(RiffFormat::Info) => Box::new(RiffTag::from(self.to_anytag())),
|
TagType::Riff(RiffFormat::Info) => Box::new(RiffTag::from(self.to_anytag())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use lofty::{DetermineFrom, Tag, TagType, ToAnyTag, VorbisTag};
|
use lofty::{DetermineFrom, Tag, TagType, ToAnyTag, VorbisTag};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(all(feature = "mp3", feature = "vorbis"))]
|
#[cfg(all(feature = "id3", feature = "flac"))]
|
||||||
fn test_inner() {
|
fn test_inner() {
|
||||||
// New flac tag
|
// New flac tag
|
||||||
let mut innertag = metaflac::Tag::new();
|
let mut innertag = metaflac::Tag::new();
|
||||||
|
|
Loading…
Reference in a new issue