Question about the rating field #520
-
Hi I've been trying to make a "Rating" field to store the rating of a song, however there seems to be some custom logic somewhere as when I edit the "Rating field": /// Helper function to insert custom metadata fields
fn set_custom_field(tag: &mut Tag, field_name: &str, value: &str) {
let item_key = ItemKey::Unknown(field_name.to_string());
if value.is_empty() {
tag.remove_key(&item_key);
} else {
// Create a TagItem with the custom field
let tag_item = TagItem::new(item_key, ItemValue::Text(value.to_string()));
// Use insert_unchecked for custom fields
tag.insert_unchecked(tag_item);
}
}
set_custom_field(tag, "RATING", &value.to_string()); This seems to instead of overwriting the rating field or removing it, it seems to append Using
So what is so special about this particular key? Note: my test format is |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hello! So this is an interesting one. First of all, the In your case, you can fix this by simply changing to |
Beta Was this translation helpful? Give feedback.
Hello!
So this is an interesting one. First of all, the
ItemKey
variant you're looking for is ItemKey::Popularimeter, which maps to"RATING"
for Vorbis Comments. When aVorbisComments
tag gets converted to aTag
, all of its keys will be translated to anItemKey
. So, when you initially write your customItemKey::Unknown("RATING")
, it will get written to the tag normally, but be re-read asItemKey::Popularimeter
notItemKey::Unknown("RATING")
, these are two different things.Tag::insert{_unchecked}
will check if theItemKey
matches an existing one in the tag, and since those two are different, you'll always fail that comparison and instead append an additional item to theTag
.In your case,…