diff --git a/modules/taglib/src/impls/file.rs b/modules/taglib/src/impls/file.rs index 81c542b..d2b56ac 100644 --- a/modules/taglib/src/impls/file.rs +++ b/modules/taglib/src/impls/file.rs @@ -51,6 +51,7 @@ impl TagLibFile { | TagLibFileType::OggOpus | TagLibFileType::OggSpeex | TagLibFileType::OggVorbis => true, + _ => false, }; if !supported { diff --git a/modules/taglib/src/lib.rs b/modules/taglib/src/lib.rs index 23870cc..d882ca4 100644 --- a/modules/taglib/src/lib.rs +++ b/modules/taglib/src/lib.rs @@ -17,6 +17,7 @@ pub enum TagLibFileType { OggOpus = 2, OggSpeex = 3, OggVorbis = 4, + MP4 = 5, } pub use impls::file::*; diff --git a/modules/taglib/src/wrapper.cxx b/modules/taglib/src/wrapper.cxx index e990124..37c74e5 100644 --- a/modules/taglib/src/wrapper.cxx +++ b/modules/taglib/src/wrapper.cxx @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -39,6 +40,9 @@ TagLib_File *wrap_taglib_file_new_with_type(const char *filename, short taglib_t if (taglib_type == 4) { return reinterpret_cast(new TagLib::Ogg::Vorbis::File(filename)); } + if (taglib_type == 5) { + return reinterpret_cast(new TagLib::MP4::File(filename)); + } return reinterpret_cast(TagLib::FileRef::create(filename)); } diff --git a/src/commands/copy.rs b/src/commands/copy.rs index 3f735b8..2744113 100644 --- a/src/commands/copy.rs +++ b/src/commands/copy.rs @@ -222,7 +222,7 @@ fn transcode_files( ) .expect("transcode config error"); - let threads = copy_args.threads.unwrap_or(1); + let threads = copy_args.threads.unwrap_or(2); if threads > 1 { let files_copy = files.to_vec(); diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 3aad189..026bb1d 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,7 +1,7 @@ pub mod copy; #[cfg(feature = "command_genhtml")] pub mod genhtml; +pub mod presets; pub mod process; pub mod tags; pub mod transcode; -pub mod presets; diff --git a/src/commands/presets.rs b/src/commands/presets.rs index eadf471..caaa768 100644 --- a/src/commands/presets.rs +++ b/src/commands/presets.rs @@ -42,9 +42,9 @@ pub fn presets_command( let preset = match crate::utils::transcoder::presets::get_preset(x.preset) { Some(preset) => preset, None => { - println!("invalid preset specified"); - std::process::exit(1); - }, + println!("invalid preset specified"); + std::process::exit(1); + } }; match x.format { diff --git a/src/commands/process.rs b/src/commands/process.rs index fa96a7b..579bd43 100644 --- a/src/commands/process.rs +++ b/src/commands/process.rs @@ -215,7 +215,7 @@ pub fn process_command( for file in files.iter_mut() { rename_file(process_args, file); } - + #[cfg(feature = "replaygain")] if !process_args.skip_replaygain && !process_args.dry_run { println!("Adding ReplayGain Tags to Files"); diff --git a/src/utils/format_detection.rs b/src/utils/format_detection.rs index 5c8b10e..af9eca1 100644 --- a/src/utils/format_detection.rs +++ b/src/utils/format_detection.rs @@ -22,6 +22,7 @@ pub enum FileFormat { AIFF, Wav, WavPack, + M4A, } impl ToString for FileFormat { @@ -37,6 +38,7 @@ impl ToString for FileFormat { FileFormat::AIFF => "AIFF".to_string(), FileFormat::Wav => "Wav".to_string(), FileFormat::WavPack => "WavPack".to_string(), + FileFormat::M4A => "M4A (Unknown)".to_string(), } } } @@ -104,6 +106,9 @@ pub fn detect_format(path: &Path) -> Result { "audio/mpeg" => { return Ok(FileFormat::MP3); } + "audio/m4a" => { + return Ok(FileFormat::M4A); + } "audio/x-wav" => { return Ok(FileFormat::Wav); } diff --git a/src/utils/formats/handlers/mod.rs b/src/utils/formats/handlers/mod.rs index 3dfe7a9..8c04893 100644 --- a/src/utils/formats/handlers/mod.rs +++ b/src/utils/formats/handlers/mod.rs @@ -92,6 +92,8 @@ lazy_static! { "wav".to_string(), "wv".to_string(), "aiff".to_string(), + "m4a".to_string(), + "alac".to_string(), ], supported_formats: vec![ FileFormat::MP3, @@ -104,6 +106,7 @@ lazy_static! { FileFormat::Wav, FileFormat::WavPack, FileFormat::AIFF, + FileFormat::M4A, ], new: |path, file_format| -> NewHandlerFuncReturn { let handler = taglib::new_handler(path, file_format)?; @@ -122,6 +125,8 @@ lazy_static! { "wav".to_string(), "wv".to_string(), "aiff".to_string(), + "m4a".to_string(), + "alac".to_string(), ], supported_formats: vec![ FileFormat::MP3, @@ -134,6 +139,7 @@ lazy_static! { FileFormat::Wav, FileFormat::WavPack, FileFormat::AIFF, + FileFormat::M4A, ], new: |path, file_format| -> NewHandlerFuncReturn { let handler = ffprobe::new_handler(path, file_format)?; diff --git a/src/utils/formats/handlers/taglib.rs b/src/utils/formats/handlers/taglib.rs index 14cb715..1bc8072 100644 --- a/src/utils/formats/handlers/taglib.rs +++ b/src/utils/formats/handlers/taglib.rs @@ -74,10 +74,11 @@ impl FormatHandler for TaglibAudioFormat { FileFormat::OggVorbis | FileFormat::OggOpus | FileFormat::OggFLAC - | FileFormat::OggSpeex // Both "support" ReplayGain but not implemented yet - // FileFormat::Wav | - // FileFormat::WavPack + | FileFormat::OggSpeex ); + // Both "support" ReplayGain but not implemented yet + // FileFormat::Wav | + // FileFormat::WavPack } false @@ -99,20 +100,27 @@ impl FormatHandler for TaglibAudioFormat { fn set_replaygain_data(&mut self, data: ReplayGainRawData) -> Result<(), BoxedError> { if let Some(format) = self.file_format { - let oggtag = self.file.oggtag().expect("oggtag not available?"); + match format { + FileFormat::OggOpus + | FileFormat::OggVorbis + | FileFormat::OggFLAC + | FileFormat::OggSpeex => { + let oggtag = self.file.oggtag().expect("oggtag not available?"); - if format == FileFormat::OggOpus { - let data = data.to_normal(true); + if format == FileFormat::OggOpus { + let data = data.to_normal(true); - oggtag.add_field("R128_TRACK_GAIN".to_string(), data.track_gain); - } else if matches!( - format, - FileFormat::OggVorbis | FileFormat::OggFLAC | FileFormat::OggSpeex - ) { - let data = data.to_normal(false); + oggtag.add_field("R128_TRACK_GAIN".to_string(), data.track_gain); + } else { + let data = data.to_normal(false); - oggtag.add_field("REPLAYGAIN_TRACK_GAIN".to_string(), data.track_gain); - oggtag.add_field("REPLAYGAIN_TRACK_PEAK".to_string(), data.track_peak); + oggtag.add_field("REPLAYGAIN_TRACK_GAIN".to_string(), data.track_gain); + oggtag.add_field("REPLAYGAIN_TRACK_PEAK".to_string(), data.track_peak); + } + } + _ => { + panic!("setting replaygain not supported on this format"); + } } } @@ -152,6 +160,7 @@ pub fn new_handler( FileFormat::OggOpus => Some(TagLibFileType::OggOpus), FileFormat::OggFLAC => Some(TagLibFileType::OggFLAC), FileFormat::OggSpeex => Some(TagLibFileType::OggSpeex), + FileFormat::M4A => Some(TagLibFileType::MP4), _ => None, } } diff --git a/src/utils/transcoder/presets/flac.rs b/src/utils/transcoder/presets/flac.rs index cb79e2d..63afa5c 100644 --- a/src/utils/transcoder/presets/flac.rs +++ b/src/utils/transcoder/presets/flac.rs @@ -15,4 +15,4 @@ pub fn add_preset(preset_categories: &mut Vec) { }, }]), }) -} \ No newline at end of file +} diff --git a/src/utils/transcoder/presets/g726.rs b/src/utils/transcoder/presets/g726.rs index 883c7a4..c361b2d 100644 --- a/src/utils/transcoder/presets/g726.rs +++ b/src/utils/transcoder/presets/g726.rs @@ -24,4 +24,4 @@ pub fn add_presets(preset_categories: &mut Vec) { name: "g726".to_string(), presets, }); -} \ No newline at end of file +} diff --git a/src/utils/transcoder/presets/mod.rs b/src/utils/transcoder/presets/mod.rs index 59fab65..1efefd3 100644 --- a/src/utils/transcoder/presets/mod.rs +++ b/src/utils/transcoder/presets/mod.rs @@ -4,12 +4,12 @@ use string_error::into_err; use crate::utils::transcoder::types::PresetCategory; use crate::utils::transcoder::types::TranscodeConfig; +mod flac; +mod g726; mod mp3; mod opus; -mod vorbis; -mod g726; mod speex; -mod flac; +mod vorbis; mod wav; lazy_static! { diff --git a/src/utils/transcoder/presets/mp3.rs b/src/utils/transcoder/presets/mp3.rs index 779eea3..17acd2a 100644 --- a/src/utils/transcoder/presets/mp3.rs +++ b/src/utils/transcoder/presets/mp3.rs @@ -36,4 +36,4 @@ pub fn add_presets(preset_categories: &mut Vec) { name: "mp3".to_string(), presets, }); -} \ No newline at end of file +} diff --git a/src/utils/transcoder/presets/opus.rs b/src/utils/transcoder/presets/opus.rs index 23768cd..0ba3cf1 100644 --- a/src/utils/transcoder/presets/opus.rs +++ b/src/utils/transcoder/presets/opus.rs @@ -21,4 +21,4 @@ pub fn add_presets(preset_categories: &mut Vec) { name: "opus".to_string(), presets, }); -} \ No newline at end of file +} diff --git a/src/utils/transcoder/presets/vorbis.rs b/src/utils/transcoder/presets/vorbis.rs index 812eb9a..6e9e3fe 100644 --- a/src/utils/transcoder/presets/vorbis.rs +++ b/src/utils/transcoder/presets/vorbis.rs @@ -21,4 +21,4 @@ pub fn add_presets(preset_categories: &mut Vec) { name: "vorbis".to_string(), presets, }); -} \ No newline at end of file +} diff --git a/src/utils/transcoder/presets/wav.rs b/src/utils/transcoder/presets/wav.rs index 48c169c..6186a48 100644 --- a/src/utils/transcoder/presets/wav.rs +++ b/src/utils/transcoder/presets/wav.rs @@ -2,7 +2,6 @@ use crate::utils::transcoder::types::Preset; use crate::utils::transcoder::types::PresetCategory; use crate::utils::transcoder::types::TranscodeConfig; - pub fn add_preset(preset_categories: &mut Vec) { preset_categories.push(PresetCategory { name: "wav".to_string(), @@ -15,4 +14,4 @@ pub fn add_preset(preset_categories: &mut Vec) { }, }]), }) -} \ No newline at end of file +} diff --git a/src/utils/transcoder/transcoder.rs b/src/utils/transcoder/transcoder.rs index 8d36f08..0da64d2 100644 --- a/src/utils/transcoder/transcoder.rs +++ b/src/utils/transcoder/transcoder.rs @@ -57,9 +57,11 @@ pub fn transcode( width = -1; } - command_args.extend(vec!["-vf".to_string(), format!("scale={}:{}", width, height)]); + command_args.extend(vec![ + "-vf".to_string(), + format!("scale={}:{}", width, height), + ]); } - } command_args.push(dest);