Autoformat

This commit is contained in:
Antoine Gersant 2017-12-12 21:23:39 -08:00
parent a9bdb7bb2d
commit 063726f92f
2 changed files with 23 additions and 14 deletions

View file

@ -71,7 +71,7 @@ use std::sync::{Arc, Mutex};
use std::sync::mpsc::channel;
use simplelog::{Config, TermLogger, LogLevelFilter};
#[cfg(unix)]
use simplelog::{SimpleLogger};
use simplelog::SimpleLogger;
mod api;
mod config;
@ -126,9 +126,7 @@ fn init_log(log_level: LogLevelFilter, options: &getopts::Matches) -> Result<()>
if let Err(e) = TermLogger::init(log_level, Config::default()) {
bail!("Error starting terminal logger: {}", e);
};
}
else
{
} else {
if let Err(e) = SimpleLogger::init(log_level, Config::default()) {
bail!("Error starting simple logger: {}", e);
}

View file

@ -35,7 +35,9 @@ pub fn read(path: &Path) -> Result<SongTags> {
fn read_id3(path: &Path) -> Result<SongTags> {
let tag = id3::Tag::read_from_path(&path)?;
let duration = mp3_duration::from_path(&path).map(|d| d.as_secs() as u32).ok();
let duration = mp3_duration::from_path(&path)
.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());
@ -150,8 +152,10 @@ fn read_flac(path: &Path) -> Result<SongTags> {
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
Some(&&metaflac::Block::StreamInfo(ref s)) => {
Some((s.total_samples as u32 / s.sample_rate) as u32)
}
_ => None,
};
Ok(SongTags {
@ -178,9 +182,16 @@ fn test_read_metadata() {
duration: None,
year: Some(2016),
};
let flac_sample_tag = SongTags {duration: Some(0), ..sample_tags.clone()};
let mp3_sample_tag = SongTags {duration: Some(0), ..sample_tags.clone()};
let flac_sample_tag = SongTags {
duration: Some(0),
..sample_tags.clone()
};
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);
assert_eq!(read(Path::new("test/sample.flac")).unwrap(),
flac_sample_tag);
}