lofty-rs
lofty-rs copied to clipboard
ID3v2 popularimeter is not populated
Reproducer
Rust version: v1.63.0 stable
cargo.toml:
[package]
name = "lofty-id3-pop"
version = "0.1.0"
edition = "2021"
[dependencies]
lofty = "0.8.0"
src/main.rs:
fn main() {
// Contents of the file
let mut example_bytes = vec![
// ID3 header - https://id3.org/id3v2.4.0-structure section 3
b'I', b'D', b'3', 0x04, 0x00, 0b00000000, 0, 0, 0, 118,
// ID3 POPM frame - https://en.wikipedia.org/wiki/ID3#ID3v2_star_rating_tag_issue
b'P', b'O', b'P', b'M', 0, 0, 0, 35, 0x00, 0x00, b'W', b'i', b'n', b'd', b'o', b'w', b's',
b' ', b'M', b'e', b'd', b'i', b'a', b' ', b'P', b'l', b'a', b'y', b'e', b'r', b' ', b'9',
b' ', b'S', b'e', b'r', b'i', b'e', b's', 0x00, 196, 0x00, 0x00, 0x00, 0x00,
];
// Pad to at least 128 bytes to support the negative seek during ID3v1 header parsing
// - https://github.com/Serial-ATA/lofty-rs/tree/1b546700d552caeb970a1751862b8b5a2585fe9c/src/mpeg/read.rs#L100
// - https://github.com/Serial-ATA/lofty-rs/tree/1b546700d552caeb970a1751862b8b5a2585fe9c/src/id3/mod.rs#L54
example_bytes.append(&mut vec![0u8; 128 - 55]);
// Write the file to disk
let path = std::env::temp_dir().join("minimal_example.mp3");
std::fs::write(&path, example_bytes).unwrap();
// Parse the file for ID3 tags
let info = lofty::read_from_path(&path, false).unwrap();
for tag in info.tags() {
if let Some(pop) = tag.get_string(&lofty::ItemKey::Popularimeter) {
println!("Found popularimeter: {pop}");
return;
}
}
panic!("No popularimeter tag found");
}
Summary
When parsing files with ID3v2 tags, such as MP3s, the Popularimeter tag is never populated.
Expected behavior
Using the supplied example:
Expected:
> cargo run
Found popularimeter: 196
Actual:
> cargo run
thread 'main' panicked at 'No popularimeter tag found', src/main.rs:28:5
Assets
No response