Use partial information from id3 tags that have encoding errors

This commit is contained in:
Antoine Gersant 2020-01-31 19:16:07 -08:00
parent fc36bb4cee
commit 312eb15a2b
3 changed files with 16 additions and 7 deletions

6
Cargo.lock generated
View file

@ -913,7 +913,7 @@ dependencies = [
[[package]]
name = "id3"
version = "0.3.0"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1548,7 +1548,7 @@ dependencies = [
"function_name 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"id3 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"id3 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.22.4 (registry+https://github.com/rust-lang/crates.io-index)",
"lewton 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libsqlite3-sys 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2902,7 +2902,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum hyper 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)" = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273"
"checksum hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)" = "9dbe6ed1438e1f8ad955a4701e9a944938e9519f6888d12d8558b645e247d5f6"
"checksum hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f"
"checksum id3 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96cbe2d2d42930674ef20d3f02026641d0fd62d97b2a173cc2406cedbebc069e"
"checksum id3 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fb14957c50abf15f8eabed1a3d0956d32c6f5b13b6099e7e80c76b4027fde67b"
"checksum ident_case 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e"
"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"

View file

@ -23,7 +23,7 @@ flamer = { version = "0.4", optional = true }
function_name = "0.2.0"
getopts = "0.2.15"
http = "0.2"
id3 = "0.3"
id3 = "0.4"
image = "0.22"
libsqlite3-sys = { version = "0.16", features = ["bundled-windows"] }
rustfm-scrobble = "^1"

View file

@ -48,14 +48,23 @@ fn read_id3(path: &Path) -> Result<SongTags> {
let tag = {
#[cfg(feature = "profile-index")]
let _guard = flame::start_guard("id3_tag_read");
id3::Tag::read_from_path(&path)?
match id3::Tag::read_from_path(&path) {
Ok(t) => Ok(t),
Err(e) => {
if let Some(t) = e.partial_tag {
Ok(t)
} else {
Err(e)
}
}
}?
};
let duration = {
#[cfg(feature = "profile-index")]
let _guard = flame::start_guard("mp3_duration");
mp3_duration::from_path(&path)
.map(|d| d.as_secs() as u32)
.ok()
.map(|d| d.as_secs() as u32)
.ok()
};
let artist = tag.artist().map(|s| s.to_string());