Autoformat
This commit is contained in:
parent
a9bdb7bb2d
commit
063726f92f
2 changed files with 23 additions and 14 deletions
|
@ -71,7 +71,7 @@ use std::sync::{Arc, Mutex};
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use simplelog::{Config, TermLogger, LogLevelFilter};
|
use simplelog::{Config, TermLogger, LogLevelFilter};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use simplelog::{SimpleLogger};
|
use simplelog::SimpleLogger;
|
||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
mod config;
|
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()) {
|
if let Err(e) = TermLogger::init(log_level, Config::default()) {
|
||||||
bail!("Error starting terminal logger: {}", e);
|
bail!("Error starting terminal logger: {}", e);
|
||||||
};
|
};
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
if let Err(e) = SimpleLogger::init(log_level, Config::default()) {
|
if let Err(e) = SimpleLogger::init(log_level, Config::default()) {
|
||||||
bail!("Error starting simple logger: {}", e);
|
bail!("Error starting simple logger: {}", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,9 @@ pub fn read(path: &Path) -> Result<SongTags> {
|
||||||
|
|
||||||
fn read_id3(path: &Path) -> Result<SongTags> {
|
fn read_id3(path: &Path) -> Result<SongTags> {
|
||||||
let tag = id3::Tag::read_from_path(&path)?;
|
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 artist = tag.artist().map(|s| s.to_string());
|
||||||
let album_artist = tag.album_artist().map(|s| s.to_string());
|
let album_artist = tag.album_artist().map(|s| s.to_string());
|
||||||
|
@ -53,7 +55,7 @@ fn read_id3(path: &Path) -> Result<SongTags> {
|
||||||
album_artist: album_artist,
|
album_artist: album_artist,
|
||||||
album: album,
|
album: album,
|
||||||
title: title,
|
title: title,
|
||||||
duration: duration,
|
duration: duration,
|
||||||
disc_number: disc_number,
|
disc_number: disc_number,
|
||||||
track_number: track_number,
|
track_number: track_number,
|
||||||
year: year,
|
year: year,
|
||||||
|
@ -102,7 +104,7 @@ fn read_ape(path: &Path) -> Result<SongTags> {
|
||||||
album_artist: album_artist,
|
album_artist: album_artist,
|
||||||
album: album,
|
album: album,
|
||||||
title: title,
|
title: title,
|
||||||
duration: None,
|
duration: None,
|
||||||
disc_number: disc_number,
|
disc_number: disc_number,
|
||||||
track_number: track_number,
|
track_number: track_number,
|
||||||
year: year,
|
year: year,
|
||||||
|
@ -119,7 +121,7 @@ fn read_vorbis(path: &Path) -> Result<SongTags> {
|
||||||
album_artist: None,
|
album_artist: None,
|
||||||
album: None,
|
album: None,
|
||||||
title: None,
|
title: None,
|
||||||
duration:None,
|
duration: None,
|
||||||
disc_number: None,
|
disc_number: None,
|
||||||
track_number: None,
|
track_number: None,
|
||||||
year: None,
|
year: None,
|
||||||
|
@ -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 year = vorbis.get("DATE").and_then(|d| d[0].parse::<i32>().ok());
|
||||||
let streaminfo = tag.get_blocks(metaflac::BlockType::StreamInfo);
|
let streaminfo = tag.get_blocks(metaflac::BlockType::StreamInfo);
|
||||||
let duration = match streaminfo.first() {
|
let duration = match streaminfo.first() {
|
||||||
Some(&&metaflac::Block::StreamInfo(ref s)) => Some((s.total_samples as u32 / s.sample_rate) as u32),
|
Some(&&metaflac::Block::StreamInfo(ref s)) => {
|
||||||
_ => None
|
Some((s.total_samples as u32 / s.sample_rate) as u32)
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(SongTags {
|
Ok(SongTags {
|
||||||
|
@ -175,12 +179,19 @@ fn test_read_metadata() {
|
||||||
artist: Some("TEST ARTIST".into()),
|
artist: Some("TEST ARTIST".into()),
|
||||||
album_artist: Some("TEST ALBUM ARTIST".into()),
|
album_artist: Some("TEST ALBUM ARTIST".into()),
|
||||||
album: Some("TEST ALBUM".into()),
|
album: Some("TEST ALBUM".into()),
|
||||||
duration: None,
|
duration: None,
|
||||||
year: Some(2016),
|
year: Some(2016),
|
||||||
};
|
};
|
||||||
let flac_sample_tag = SongTags {duration: Some(0), ..sample_tags.clone()};
|
let flac_sample_tag = SongTags {
|
||||||
let mp3_sample_tag = SongTags {duration: Some(0), ..sample_tags.clone()};
|
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.mp3")).unwrap(), mp3_sample_tag);
|
||||||
assert_eq!(read(Path::new("test/sample.ogg")).unwrap(), sample_tags);
|
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue