Merge remote-tracking branch 'origin/master'

This commit is contained in:
Antoine Gersant 2017-12-09 00:39:13 -08:00
commit fc9049fea5
8 changed files with 467 additions and 374 deletions

797
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -23,7 +23,7 @@ mount = "0.3.0"
params = { git = "https://github.com/euclio/params", branch="update" }
rand = "0.3.15"
regex = "0.2.2"
ring = "0.9.7"
ring = "0.11.0"
reqwest = "0.6.2"
router = "0.5.1"
secure-session = "0.2.0"

View file

@ -0,0 +1,19 @@
CREATE TEMPORARY TABLE songs_backup(id, path, parent, track_number, disc_number, title, artist, album_artist, year, album, artwork);
INSERT INTO songs_backup SELECT id, path, parent, track_number, disc_number, title, artist, album_artist, year, album, artwork FROM songs;
DROP TABLE songs;
CREATE TABLE songs (
id INTEGER PRIMARY KEY NOT NULL,
path TEXT NOT NULL,
parent TEXT NOT NULL,
track_number INTEGER,
disc_number INTEGER,
title TEXT,
artist TEXT,
album_artist TEXT,
year INTEGER,
album TEXT,
artwork TEXT,
UNIQUE(path) ON CONFLICT REPLACE
);
INSERT INTO songs SELECT * FROM songs_backup;
DROP TABLE songs_backup;

View file

@ -0,0 +1 @@
ALTER TABLE songs ADD COLUMN duration INTEGER;

Binary file not shown.

View file

@ -49,6 +49,7 @@ pub struct Song {
pub year: Option<i32>,
pub album: Option<String>,
pub artwork: Option<String>,
pub duration: Option<i32>,
}
#[derive(Debug, Queryable, Serialize)]
@ -84,6 +85,7 @@ struct NewSong {
year: Option<i32>,
album: Option<String>,
artwork: Option<String>,
duration: Option<i32>
}
#[derive(Debug, Insertable)]
@ -247,6 +249,7 @@ impl<'conn> IndexBuilder<'conn> {
disc_number: tags.disc_number.map(|n| n as i32),
track_number: tags.track_number.map(|n| n as i32),
title: tags.title,
duration: tags.duration.map(|n| n as i32),
artist: tags.artist,
album_artist: tags.album_artist,
album: tags.album,

View file

@ -10,11 +10,12 @@ use errors::*;
use utils;
use utils::AudioFormat;
#[derive(Debug, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub struct SongTags {
pub disc_number: Option<u32>,
pub track_number: Option<u32>,
pub title: Option<String>,
pub duration: Option<u32>,
pub artist: Option<String>,
pub album_artist: Option<String>,
pub album: Option<String>,
@ -50,6 +51,7 @@ fn read_id3(path: &Path) -> Result<SongTags> {
album_artist: album_artist,
album: album,
title: title,
duration: None,
disc_number: disc_number,
track_number: track_number,
year: year,
@ -98,6 +100,7 @@ fn read_ape(path: &Path) -> Result<SongTags> {
album_artist: album_artist,
album: album,
title: title,
duration: None,
disc_number: disc_number,
track_number: track_number,
year: year,
@ -114,6 +117,7 @@ fn read_vorbis(path: &Path) -> Result<SongTags> {
album_artist: None,
album: None,
title: None,
duration:None,
disc_number: None,
track_number: None,
year: None,
@ -142,11 +146,18 @@ fn read_flac(path: &Path) -> Result<SongTags> {
.get("DISCNUMBER")
.and_then(|d| d[0].parse::<u32>().ok());
let year = vorbis.get("DATE").and_then(|d| d[0].parse::<i32>().ok());
let streaminfo = tag.get_blocks(metaflac::BlockType::StreamInfo);
let duration = match streaminfo.first() {
Some(&&metaflac::Block::StreamInfo(ref s)) => Some((s.total_samples as u32 / s.sample_rate) as u32),
_ => None
};
Ok(SongTags {
artist: vorbis.artist().map(|v| v[0].clone()),
album_artist: vorbis.album_artist().map(|v| v[0].clone()),
album: vorbis.album().map(|v| v[0].clone()),
title: vorbis.title().map(|v| v[0].clone()),
duration: duration,
disc_number: disc_number,
track_number: vorbis.track(),
year: year,
@ -162,9 +173,11 @@ fn test_read_metadata() {
artist: Some("TEST ARTIST".into()),
album_artist: Some("TEST ALBUM ARTIST".into()),
album: Some("TEST ALBUM".into()),
duration: None,
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);
assert_eq!(read(Path::new("test/sample.ogg")).unwrap(), sample_tags);
assert_eq!(read(Path::new("test/sample.flac")).unwrap(), sample_tags);
assert_eq!(read(Path::new("test/sample.flac")).unwrap(), flac_sample_tag);
}

View file

@ -17,7 +17,7 @@ pub struct User {
pub admin: i32,
}
static DIGEST_ALG: &'static pbkdf2::PRF = &pbkdf2::HMAC_SHA256;
static DIGEST_ALG: &'static digest::Algorithm = &digest::SHA256;
const CREDENTIAL_LEN: usize = digest::SHA256_OUTPUT_LEN;
const HASH_ITERATIONS: u32 = 10000;
type PasswordHash = [u8; CREDENTIAL_LEN];