lofty-rs icon indicating copy to clipboard operation
lofty-rs copied to clipboard

Support for custom item values like AdvisoryRating as ItemValue

Open uklotzde opened this issue 3 years ago • 3 comments

Summary

Currently, you have to do custom pre/post-processing on the low-level tag type, because those values are not accessible from TaggedFile.

How could this information be made accessible in a generic way?

API design

No response

uklotzde avatar Jan 05 '23 09:01 uklotzde

Also applies to ItemKey::FlagCompilation.

uklotzde avatar Jan 05 '23 12:01 uklotzde

I've thought about this before, and I've been unable to come up with any good solutions. The only real blockers are ilst and ID3v2, since they have so many extras that are difficult to translate to a generic format.

Currently, when converting an ID3v2Tag -> Tag, a Popularimeter is converted to its binary representation and stored as ItemValue::Binary. This is only safe because ID3v2 is the only format that accepts both ItemKey::Popularimeter and ItemValue::Binary. It's not a perfect solution by any means, but this can be done for other items. I just don't know if there are any overlaps that break this safety.

Serial-ATA avatar Jan 05 '23 19:01 Serial-ATA

@uklotzde I just remembered this issue, and the solution could be pretty simple:

When converting to the generic format:

  • AdvisoryRating could be stored as its variant ("Explicit" | "Inoffensive" | "Clean")
  • Flag items could be stored as "1" or "0"

When converting from the generic format:

  • AdvisoryRating is determined from the variants or the Apple encoded value, so:
    • "Explicit" | "1" => AdvisoryRating::Explicit
  • Flags are simply:
    • "1" | "true" => 1
    • "0" | "false" => 0

Serial-ATA avatar Jan 08 '24 18:01 Serial-ATA

This was done for ItemKey::Flag* awhile ago, forgot to do AdvisoryRating. I'll get that in the next release.

Serial-ATA avatar Apr 21 '24 19:04 Serial-ATA