Add support for AIFF files (#137)
The new patch in rust-id3 fixes the AIFF API, which is now used to support AIFF files.
This commit is contained in:
parent
652772ba0e
commit
ed581c57cf
7 changed files with 47 additions and 3 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1160,9 +1160,9 @@ checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "id3"
|
name = "id3"
|
||||||
version = "0.6.3"
|
version = "0.6.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f23fa956cb2f3e3e547993eb62b6f76b5babd86c3e7bb4fe1149ef192d90df51"
|
checksum = "bbe9b826aaa15b25bfb73c18ca9507a0ced87578a62376a7751dc6a510e3d244"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
|
|
|
@ -24,7 +24,7 @@ diesel_migrations = { version = "1.4", features = ["sqlite"] }
|
||||||
futures-util = { version = "0.3" }
|
futures-util = { version = "0.3" }
|
||||||
getopts = "0.2.15"
|
getopts = "0.2.15"
|
||||||
http = "0.2.2"
|
http = "0.2.2"
|
||||||
id3 = "0.6.3"
|
id3 = "0.6.4"
|
||||||
libsqlite3-sys = { version = "0.18", features = ["bundled", "bundled-windows"], optional = true }
|
libsqlite3-sys = { version = "0.18", features = ["bundled", "bundled-windows"], optional = true }
|
||||||
lewton = "0.10.1"
|
lewton = "0.10.1"
|
||||||
log = "0.4.5"
|
log = "0.4.5"
|
||||||
|
|
|
@ -59,6 +59,7 @@ 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) => Some(read_aiff(path)),
|
||||||
Some(AudioFormat::APE) => Some(read_ape(path)),
|
Some(AudioFormat::APE) => Some(read_ape(path)),
|
||||||
Some(AudioFormat::FLAC) => Some(read_flac(path)),
|
Some(AudioFormat::FLAC) => Some(read_flac(path)),
|
||||||
Some(AudioFormat::MP3) => Some(read_mp3(path)),
|
Some(AudioFormat::MP3) => Some(read_mp3(path)),
|
||||||
|
@ -99,6 +100,17 @@ fn read_mp3(path: &Path) -> Result<SongTags> {
|
||||||
Ok(song_tags)
|
Ok(song_tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_aiff(path: &Path) -> Result<SongTags> {
|
||||||
|
let tag = id3::Tag::read_from_aiff(&path).or_else(|error| {
|
||||||
|
if let Some(tag) = error.partial_tag {
|
||||||
|
Ok(tag)
|
||||||
|
} else {
|
||||||
|
Err(error)
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
Ok(tag.into())
|
||||||
|
}
|
||||||
|
|
||||||
fn read_wave(path: &Path) -> Result<SongTags> {
|
fn read_wave(path: &Path) -> Result<SongTags> {
|
||||||
let tag = id3::Tag::read_from_wav(&path).or_else(|error| {
|
let tag = id3::Tag::read_from_wav(&path).or_else(|error| {
|
||||||
if let Some(tag) = error.partial_tag {
|
if let Some(tag) = error.partial_tag {
|
||||||
|
@ -299,6 +311,10 @@ fn reads_file_metadata() {
|
||||||
duration: Some(0),
|
duration: Some(0),
|
||||||
..sample_tags.clone()
|
..sample_tags.clone()
|
||||||
};
|
};
|
||||||
|
assert_eq!(
|
||||||
|
read(Path::new("test-data/formats/sample.aif")).unwrap(),
|
||||||
|
sample_tags
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
read(Path::new("test-data/formats/sample.mp3")).unwrap(),
|
read(Path::new("test-data/formats/sample.mp3")).unwrap(),
|
||||||
mp3_sample_tag
|
mp3_sample_tag
|
||||||
|
@ -331,6 +347,11 @@ fn reads_file_metadata() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reads_embedded_artwork() {
|
fn reads_embedded_artwork() {
|
||||||
|
assert!(
|
||||||
|
read(Path::new("test-data/artwork/sample.aif"))
|
||||||
|
.unwrap()
|
||||||
|
.has_artwork
|
||||||
|
);
|
||||||
assert!(
|
assert!(
|
||||||
read(Path::new("test-data/artwork/sample.mp3"))
|
read(Path::new("test-data/artwork/sample.mp3"))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::utils::AudioFormat;
|
||||||
|
|
||||||
pub fn read(image_path: &Path) -> Result<DynamicImage> {
|
pub fn read(image_path: &Path) -> Result<DynamicImage> {
|
||||||
match utils::get_audio_format(image_path) {
|
match utils::get_audio_format(image_path) {
|
||||||
|
Some(AudioFormat::AIFF) => read_aiff(image_path),
|
||||||
Some(AudioFormat::APE) => read_ape(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),
|
||||||
|
@ -44,6 +45,12 @@ fn read_mp3(path: &Path) -> Result<DynamicImage> {
|
||||||
read_id3(&path, &tag)
|
read_id3(&path, &tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_aiff(path: &Path) -> Result<DynamicImage> {
|
||||||
|
let tag = id3::Tag::read_from_aiff(path)?;
|
||||||
|
|
||||||
|
read_id3(&path, &tag)
|
||||||
|
}
|
||||||
|
|
||||||
fn read_wave(path: &Path) -> Result<DynamicImage> {
|
fn read_wave(path: &Path) -> Result<DynamicImage> {
|
||||||
let tag = id3::Tag::read_from_wav(path)?;
|
let tag = id3::Tag::read_from_wav(path)?;
|
||||||
|
|
||||||
|
@ -99,6 +106,11 @@ fn can_read_artwork_data() {
|
||||||
.to_rgb8();
|
.to_rgb8();
|
||||||
assert_eq!(folder_img, ext_img);
|
assert_eq!(folder_img, ext_img);
|
||||||
|
|
||||||
|
let aiff_img = read(Path::new("test-data/artwork/sample.aif"))
|
||||||
|
.unwrap()
|
||||||
|
.to_rgb8();
|
||||||
|
assert_eq!(aiff_img, embedded_img);
|
||||||
|
|
||||||
let ape_img = read(Path::new("test-data/artwork/sample.ape"))
|
let ape_img = read(Path::new("test-data/artwork/sample.ape"))
|
||||||
.map(|d| d.to_rgb8())
|
.map(|d| d.to_rgb8())
|
||||||
.ok();
|
.ok();
|
||||||
|
|
11
src/utils.rs
11
src/utils.rs
|
@ -14,6 +14,7 @@ pub use crate::match_ignore_case;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum AudioFormat {
|
pub enum AudioFormat {
|
||||||
|
AIFF,
|
||||||
APE,
|
APE,
|
||||||
FLAC,
|
FLAC,
|
||||||
MP3,
|
MP3,
|
||||||
|
@ -34,6 +35,8 @@ pub fn get_audio_format(path: &Path) -> Option<AudioFormat> {
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
match extension.to_lowercase().as_str() {
|
match extension.to_lowercase().as_str() {
|
||||||
|
"aif" => Some(AudioFormat::AIFF),
|
||||||
|
"aiff" => Some(AudioFormat::AIFF),
|
||||||
"ape" => Some(AudioFormat::APE),
|
"ape" => Some(AudioFormat::APE),
|
||||||
"flac" => Some(AudioFormat::FLAC),
|
"flac" => Some(AudioFormat::FLAC),
|
||||||
"mp3" => Some(AudioFormat::MP3),
|
"mp3" => Some(AudioFormat::MP3),
|
||||||
|
@ -49,6 +52,14 @@ pub fn get_audio_format(path: &Path) -> Option<AudioFormat> {
|
||||||
#[test]
|
#[test]
|
||||||
fn can_guess_audio_format() {
|
fn can_guess_audio_format() {
|
||||||
assert_eq!(get_audio_format(Path::new("animals/🐷/my🐖file.jpg")), None);
|
assert_eq!(get_audio_format(Path::new("animals/🐷/my🐖file.jpg")), None);
|
||||||
|
assert_eq!(
|
||||||
|
get_audio_format(Path::new("animals/🐷/my🐖file.aif")),
|
||||||
|
Some(AudioFormat::AIFF)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
get_audio_format(Path::new("animals/🐷/my🐖file.aiff")),
|
||||||
|
Some(AudioFormat::AIFF)
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_audio_format(Path::new("animals/🐷/my🐖file.flac")),
|
get_audio_format(Path::new("animals/🐷/my🐖file.flac")),
|
||||||
Some(AudioFormat::FLAC)
|
Some(AudioFormat::FLAC)
|
||||||
|
|
BIN
test-data/artwork/sample.aif
Normal file
BIN
test-data/artwork/sample.aif
Normal file
Binary file not shown.
BIN
test-data/formats/sample.aif
Normal file
BIN
test-data/formats/sample.aif
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue