Skip to content

Commit

Permalink
add song duration for flac files
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Dec 3, 2017
1 parent 418c8e5 commit 16ae131
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +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)) => (s.total_samples as u32 / s.sample_rate) as u32,
_ => 0
};

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: None,
duration: Some(duration),
disc_number: disc_number,
track_number: vorbis.track(),
year: year,
Expand Down

0 comments on commit 16ae131

Please sign in to comment.