mirror of
https://github.com/agersant/polaris
synced 2025-03-02 06:17:10 +00:00
Index now measures duration of mp3 files
This commit is contained in:
parent
2bd1b8220d
commit
52835c4b97
4 changed files with 50 additions and 3 deletions
41
Cargo.lock
generated
41
Cargo.lock
generated
|
@ -434,6 +434,25 @@ dependencies = [
|
|||
"backtrace 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "failure"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"backtrace 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "failure_derive"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "0.2.20"
|
||||
|
@ -857,6 +876,14 @@ dependencies = [
|
|||
"sequence_trie 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mp3-duration"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "multipart"
|
||||
version = "0.12.0"
|
||||
|
@ -1118,6 +1145,7 @@ dependencies = [
|
|||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"metaflac 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mount 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mp3-duration 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"params 0.6.0 (git+https://github.com/euclio/params?branch=update)",
|
||||
"rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1518,6 +1546,15 @@ dependencies = [
|
|||
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "synstructure"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "take"
|
||||
version = "0.1.0"
|
||||
|
@ -1851,6 +1888,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum error 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "a6e606f14042bb87cc02ef6a14db6c90ab92ed6f62d87e69377bc759fd7987cc"
|
||||
"checksum error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8"
|
||||
"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
|
||||
"checksum failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "934799b6c1de475a012a02dab0ace1ace43789ee4b99bcfbf1a2e3e8ced5de82"
|
||||
"checksum failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cdda555bb90c9bb67a3b670a0f42de8e73f5981524123ad8578aafec8ddb8b"
|
||||
"checksum flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "e6234dd4468ae5d1e2dbb06fe2b058696fdc50a339c68a393aefbf00bc81e423"
|
||||
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||
"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||
|
@ -1900,6 +1939,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
|
||||
"checksum modifier 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "41f5c9112cb662acd3b204077e0de5bc66305fa8df65c8019d5adb10e9ab6e58"
|
||||
"checksum mount 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32245731923cd096899502fc4c4317cfd09f121e80e73f7f576cf3777a824256"
|
||||
"checksum mp3-duration 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "630ddcac9d7a24f5a00b3a1a485ae7f202f61adcff1983caf3e9b8a5b6362a8e"
|
||||
"checksum multipart 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "65ea55ea673966fa285eadafb6e7fb03c7328c7bbad60bea23a483e374eeccb3"
|
||||
"checksum native-tls 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04b781c9134a954c84f0594b9ab3f5606abc516030388e8511887ef4c204a1e5"
|
||||
"checksum net2 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "3a80f842784ef6c9a958b68b7516bc7e35883c614004dd94959a4dca1b716c09"
|
||||
|
@ -1970,6 +2010,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum staticfile 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "31493480e073d52522a94cdf56269dd8eb05f99549effd1826b0271690608878"
|
||||
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
|
||||
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
|
||||
"checksum synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a761d12e6d8dcb4dcf952a7a89b475e3a9d69e4a69307e01a470977642914bd"
|
||||
"checksum take 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b157868d8ac1f56b64604539990685fa7611d8fa9e5476cf0c02cf34d32917c5"
|
||||
"checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6"
|
||||
"checksum term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fa63644f74ce96fbeb9b794f66aff2a52d601cbd5e80f4b97123e3899f4570f1"
|
||||
|
|
|
@ -20,6 +20,7 @@ iron = "0.5.1"
|
|||
lewton = "0.6.2"
|
||||
metaflac = "0.1.7"
|
||||
mount = "0.3.0"
|
||||
mp3-duration = "0.1.0"
|
||||
params = { git = "https://github.com/euclio/params", branch="update" }
|
||||
rand = "0.3.15"
|
||||
regex = "0.2.2"
|
||||
|
|
|
@ -17,6 +17,7 @@ extern crate iron;
|
|||
extern crate lewton;
|
||||
extern crate metaflac;
|
||||
extern crate mount;
|
||||
extern crate mp3_duration;
|
||||
extern crate params;
|
||||
extern crate rand;
|
||||
extern crate reqwest;
|
||||
|
|
|
@ -2,6 +2,7 @@ use ape;
|
|||
use id3;
|
||||
use lewton::inside_ogg::OggStreamReader;
|
||||
use metaflac;
|
||||
use mp3_duration;
|
||||
use regex::Regex;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
@ -33,7 +34,9 @@ pub fn read(path: &Path) -> Result<SongTags> {
|
|||
}
|
||||
|
||||
fn read_id3(path: &Path) -> Result<SongTags> {
|
||||
let tag = id3::Tag::read_from_path(path)?;
|
||||
let file = fs::File::open(path)?;
|
||||
let tag = id3::Tag::read_from(&file)?;
|
||||
let duration = mp3_duration::from_file(&file).map(|d| d.as_secs() as u32).ok();
|
||||
|
||||
let artist = tag.artist().map(|s| s.to_string());
|
||||
let album_artist = tag.album_artist().map(|s| s.to_string());
|
||||
|
@ -51,7 +54,7 @@ fn read_id3(path: &Path) -> Result<SongTags> {
|
|||
album_artist: album_artist,
|
||||
album: album,
|
||||
title: title,
|
||||
duration: None,
|
||||
duration: duration,
|
||||
disc_number: disc_number,
|
||||
track_number: track_number,
|
||||
year: year,
|
||||
|
@ -177,7 +180,8 @@ fn test_read_metadata() {
|
|||
year: Some(2016),
|
||||
};
|
||||
let flac_sample_tag = SongTags {duration: Some(0), ..sample_tags.clone()};
|
||||
assert_eq!(read(Path::new("test/sample.mp3")).unwrap(), sample_tags);
|
||||
let mp3_sample_tag = SongTags {duration: Some(0), ..sample_tags.clone()};
|
||||
assert_eq!(read(Path::new("test/sample.mp3")).unwrap(), mp3_sample_tag);
|
||||
assert_eq!(read(Path::new("test/sample.ogg")).unwrap(), sample_tags);
|
||||
assert_eq!(read(Path::new("test/sample.flac")).unwrap(), flac_sample_tag);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue