#[cfg(feature = "aac")]
pub mod aac;
#[cfg(feature = "aac")]
mod aac_codebooks;
pub mod analysis;
pub mod ape;
pub mod error;
mod frame;
pub mod gain;
pub mod id3v2;
pub mod mp4meta;
pub mod replaygain;
pub use analysis::{
analyze, find_max_amplitude, is_mono, ChannelMode, MaxAmplitudeResult, Mp3Analysis, MpegVersion,
};
pub use ape::{
delete_ape_tag, read_ape_tag, read_ape_tag_from_file, write_ape_tag, ApeItem, ApeTag,
TAG_MP3GAIN_ALBUM_MINMAX, TAG_MP3GAIN_MINMAX, TAG_MP3GAIN_UNDO, TAG_REPLAYGAIN_ALBUM_GAIN,
TAG_REPLAYGAIN_ALBUM_PEAK, TAG_REPLAYGAIN_TRACK_GAIN, TAG_REPLAYGAIN_TRACK_PEAK,
};
pub use error::{Error, Result};
pub use gain::{
apply_gain, apply_gain_db, db_to_steps, peak_to_headroom_db, peak_to_pcm_sample, steps_to_db,
undo_gain, Channel, GainOptions, GAIN_STEP_DB, MAX_GAIN, MIN_GAIN,
};
pub use id3v2::{
delete_id3v2_replaygain, read_id3v2_replaygain, undo_gain_id3v2, write_id3v2_replaygain,
write_id3v2_undo, Id3v2ReplayGain,
};
use std::path::{Path, PathBuf};
pub const SUPPORTED_EXTENSIONS: &[&str] = &["mp3", "m4a", "aac", "mp4"];
pub fn is_supported_audio_path(path: &Path) -> bool {
if path
.file_name()
.and_then(|n| n.to_str())
.is_some_and(|n| n.starts_with("._"))
{
return false;
}
path.extension()
.and_then(|e| e.to_str())
.is_some_and(|ext| {
SUPPORTED_EXTENSIONS
.iter()
.any(|s| ext.eq_ignore_ascii_case(s))
})
}
pub fn collect_audio_files(dir: &Path, recursive: bool) -> Result<Vec<PathBuf>> {
let mut result = Vec::new();
collect_audio_files_into(dir, recursive, &mut result)?;
Ok(result)
}
fn collect_audio_files_into(dir: &Path, recursive: bool, result: &mut Vec<PathBuf>) -> Result<()> {
let entries = std::fs::read_dir(dir).map_err(|e| Error::io_read(dir, e))?;
for entry in entries {
let entry = entry.map_err(|e| Error::io_read(dir, e))?;
let file_type = entry.file_type().map_err(|e| Error::io_read(dir, e))?;
let path = entry.path();
if file_type.is_dir() {
if recursive {
collect_audio_files_into(&path, recursive, result)?;
}
} else if is_supported_audio_path(&path) {
result.push(path);
}
}
Ok(())
}