Add support for m4b format (#208)

* Add support for m4b

* Formatting

* Formatting

---------

Co-authored-by: Antoine Gersant <antoine.gersant@lesforges.org>
This commit is contained in:
duydl 2024-05-10 09:59:45 +07:00 committed by GitHub
parent 7279793d25
commit 77dc2eac23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 6 deletions

View file

@ -86,14 +86,13 @@ impl From<id3::Tag> for SongTags {
pub fn read(path: &Path) -> Option<SongTags> { pub fn read(path: &Path) -> Option<SongTags> {
let data = match utils::get_audio_format(path) { let data = match utils::get_audio_format(path) {
Some(AudioFormat::AIFF) => read_aiff(path), Some(AudioFormat::AIFF) => read_aiff(path),
Some(AudioFormat::APE) => read_ape(path),
Some(AudioFormat::FLAC) => read_flac(path), Some(AudioFormat::FLAC) => read_flac(path),
Some(AudioFormat::MP3) => read_mp3(path), Some(AudioFormat::MP3) => read_mp3(path),
Some(AudioFormat::MP4) => read_mp4(path),
Some(AudioFormat::MPC) => read_ape(path),
Some(AudioFormat::OGG) => read_vorbis(path), Some(AudioFormat::OGG) => read_vorbis(path),
Some(AudioFormat::OPUS) => read_opus(path), Some(AudioFormat::OPUS) => read_opus(path),
Some(AudioFormat::WAVE) => read_wave(path), Some(AudioFormat::WAVE) => read_wave(path),
Some(AudioFormat::APE) | Some(AudioFormat::MPC) => read_ape(path),
Some(AudioFormat::MP4) | Some(AudioFormat::M4B) => read_mp4(path),
None => return None, None => return None,
}; };
match data { match data {

View file

@ -149,14 +149,13 @@ fn generate_thumbnail(image_path: &Path, options: &Options) -> Result<DynamicIma
fn read(image_path: &Path) -> Result<DynamicImage, Error> { fn read(image_path: &Path) -> Result<DynamicImage, Error> {
match get_audio_format(image_path) { match get_audio_format(image_path) {
Some(AudioFormat::AIFF) => read_aiff(image_path), Some(AudioFormat::AIFF) => read_aiff(image_path),
Some(AudioFormat::APE) => read_ape(image_path),
Some(AudioFormat::FLAC) => read_flac(image_path), Some(AudioFormat::FLAC) => read_flac(image_path),
Some(AudioFormat::MP3) => read_mp3(image_path), Some(AudioFormat::MP3) => read_mp3(image_path),
Some(AudioFormat::MP4) => read_mp4(image_path),
Some(AudioFormat::MPC) => read_ape(image_path),
Some(AudioFormat::OGG) => read_vorbis(image_path), Some(AudioFormat::OGG) => read_vorbis(image_path),
Some(AudioFormat::OPUS) => read_opus(image_path), Some(AudioFormat::OPUS) => read_opus(image_path),
Some(AudioFormat::WAVE) => read_wave(image_path), Some(AudioFormat::WAVE) => read_wave(image_path),
Some(AudioFormat::APE) | Some(AudioFormat::MPC) => read_ape(image_path),
Some(AudioFormat::MP4) | Some(AudioFormat::M4B) => read_mp4(image_path),
None => image::open(image_path).map_err(|e| Error::Image(image_path.to_owned(), e)), None => image::open(image_path).map_err(|e| Error::Image(image_path.to_owned(), e)),
} }
} }

View file

@ -24,6 +24,7 @@ pub enum AudioFormat {
OGG, OGG,
OPUS, OPUS,
WAVE, WAVE,
M4B,
} }
pub fn get_audio_format(path: &Path) -> Option<AudioFormat> { pub fn get_audio_format(path: &Path) -> Option<AudioFormat> {
@ -46,6 +47,7 @@ pub fn get_audio_format(path: &Path) -> Option<AudioFormat> {
"ogg" => Some(AudioFormat::OGG), "ogg" => Some(AudioFormat::OGG),
"opus" => Some(AudioFormat::OPUS), "opus" => Some(AudioFormat::OPUS),
"wav" => Some(AudioFormat::WAVE), "wav" => Some(AudioFormat::WAVE),
"m4b" => Some(AudioFormat::M4B),
_ => None, _ => None,
} }
} }