Enable M4A format support
- Use https://github.com/Saecki/rust-mp4ameta for M4A metadata Resolves https://github.com/agersant/polaris/issues/70
This commit is contained in:
parent
eb2fd23281
commit
d8b1f0c002
3 changed files with 38 additions and 0 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -1202,6 +1202,14 @@ dependencies = [
|
||||||
"failure 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"failure 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mp4ameta"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "native-tls"
|
name = "native-tls"
|
||||||
version = "0.2.4"
|
version = "0.2.4"
|
||||||
|
@ -1477,6 +1485,7 @@ dependencies = [
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"metaflac 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"metaflac 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"mp3-duration 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"mp3-duration 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"mp4ameta 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -2939,6 +2948,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
"checksum mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19"
|
"checksum mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19"
|
||||||
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
|
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
|
||||||
"checksum mp3-duration 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "eda61ba6c266cd2c7bfcea9a2719837dc062869e24e101a93c1b0873d17c2d35"
|
"checksum mp3-duration 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "eda61ba6c266cd2c7bfcea9a2719837dc062869e24e101a93c1b0873d17c2d35"
|
||||||
|
"checksum mp4ameta 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3538f327d5d3afbc25b3677f5bd1e917ae7e9d3eae2aa9c3b57bc77f0356e829"
|
||||||
"checksum native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d"
|
"checksum native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d"
|
||||||
"checksum net2 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7"
|
"checksum net2 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7"
|
||||||
"checksum notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "80ae4a7688d1fab81c5bf19c64fc8db920be8d519ce6336ed4e7efe024724dbd"
|
"checksum notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "80ae4a7688d1fab81c5bf19c64fc8db920be8d519ce6336ed4e7efe024724dbd"
|
||||||
|
|
|
@ -28,6 +28,7 @@ lewton = "0.10.1"
|
||||||
log = "0.4.5"
|
log = "0.4.5"
|
||||||
metaflac = "0.2.3"
|
metaflac = "0.2.3"
|
||||||
mp3-duration = "0.1.9"
|
mp3-duration = "0.1.9"
|
||||||
|
mp4ameta = "0.2.0"
|
||||||
pbkdf2 = "0.3"
|
pbkdf2 = "0.3"
|
||||||
rand = "0.7"
|
rand = "0.7"
|
||||||
rayon = "1.3"
|
rayon = "1.3"
|
||||||
|
|
|
@ -8,6 +8,7 @@ use mp3_duration;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use mp4ameta;
|
||||||
|
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
use crate::utils::AudioFormat;
|
use crate::utils::AudioFormat;
|
||||||
|
@ -29,6 +30,7 @@ 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::FLAC) => Some(read_flac(path)),
|
Some(AudioFormat::FLAC) => Some(read_flac(path)),
|
||||||
Some(AudioFormat::MP3) => Some(read_id3(path)),
|
Some(AudioFormat::MP3) => Some(read_id3(path)),
|
||||||
|
Some(AudioFormat::MP4) => Some(read_mp4(path)),
|
||||||
Some(AudioFormat::MPC) => Some(read_ape(path)),
|
Some(AudioFormat::MPC) => Some(read_ape(path)),
|
||||||
Some(AudioFormat::OGG) => Some(read_vorbis(path)),
|
Some(AudioFormat::OGG) => Some(read_vorbis(path)),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -203,6 +205,31 @@ fn read_flac(path: &Path) -> Result<SongTags> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "profile-index", flame)]
|
||||||
|
fn read_mp4(path: &Path) -> Result<SongTags> {
|
||||||
|
let tag = mp4ameta::Tag::read_from_path(path)?;
|
||||||
|
let mut tags = SongTags {
|
||||||
|
artist: None,
|
||||||
|
album_artist: None,
|
||||||
|
album: None,
|
||||||
|
title: None,
|
||||||
|
duration: None,
|
||||||
|
disc_number: None,
|
||||||
|
track_number: None,
|
||||||
|
year: None,
|
||||||
|
};
|
||||||
|
tags.artist = Some(tag.artist().unwrap().to_string());
|
||||||
|
tags.album_artist = Some(tag.album_artist().unwrap().to_string());
|
||||||
|
tags.album = Some(tag.album().unwrap().to_string());
|
||||||
|
tags.title = Some(tag.title().unwrap().to_string());
|
||||||
|
tags.duration = Some(tag.duration().unwrap() as u32);
|
||||||
|
tags.disc_number = tag.disk_number().0.and_then(|d| Some(d as u32));
|
||||||
|
tags.track_number = tag.track_number().0.and_then(|d| Some(d as u32));
|
||||||
|
tags.year = tag.year().unwrap().parse::<i32>().ok();
|
||||||
|
|
||||||
|
Ok(tags)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_read_metadata() {
|
fn test_read_metadata() {
|
||||||
let sample_tags = SongTags {
|
let sample_tags = SongTags {
|
||||||
|
|
Loading…
Add table
Reference in a new issue