Skip to content

Commit

Permalink
Fix measuring duration for MP3
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeop committed Nov 16, 2023
1 parent 27f37ab commit 3a758fe
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
63 changes: 52 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/scanner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lewton = "0.10.2"
md5 = "0.7.0"
metaflac = "0.2.5"
mockall = "0.11.4"
mp3-duration = "0.1.10"
mp4ameta = "0.11.0"

[dependencies.image]
Expand Down
7 changes: 6 additions & 1 deletion packages/scanner/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ impl MetadataExtractor for Mp3MetadataExtractor {
metadata.artist = tag.artist().map(|s| s.to_string());
metadata.title = tag.title().map(|s| s.to_string());
metadata.album = tag.album().map(|s| s.to_string());
metadata.duration = tag.duration();
let duration = mp3_duration::from_path(&path).map(|duration| duration.as_secs() as u32);

match duration {
Ok(duration) => metadata.duration = Some(duration),
Err(_) => metadata.duration = None,
}
metadata.position = tag.track();
metadata.disc = tag.disc();
metadata.year = tag.year().map(|s| s as u32);
Expand Down

0 comments on commit 3a758fe

Please sign in to comment.