-
Notifications
You must be signed in to change notification settings - Fork 60
Description
Let's say that I do this:
tags.SetDefaultEncoding(id3v2.EncodingUTF16)
tags.SetVersion(3) // id3v2.3.0 right?I would expect that I'm using ID3v2.3.0, and that my default encoding is UTF-16 (with BOM). But it looks like tags.SetVersion(3) will overwrite my default choice:
Lines 305 to 315 in e76f9ab
| // SetVersion sets given ID3v2 version to tag. | |
| // If version is less than 3 or greater than 4, then this method will do nothing. | |
| // If tag has some frames, which are deprecated or changed in given version, | |
| // then to your notice you can delete, change or just stay them. | |
| func (tag *Tag) SetVersion(version byte) { | |
| if version < 3 || version > 4 { | |
| return | |
| } | |
| tag.version = version | |
| tag.setDefaultEncodingBasedOnVersion(version) | |
| } |
Lines 202 to 208 in e76f9ab
| func (tag *Tag) setDefaultEncodingBasedOnVersion(version byte) { | |
| if version == 4 { | |
| tag.SetDefaultEncoding(EncodingUTF8) | |
| } else { | |
| tag.SetDefaultEncoding(EncodingISO) | |
| } | |
| } |
So for now I'm just changing the order around. But I have another thought:
Why is the default for version 3 ISO-8859-1? It seems to me like it should be UTF16.
if version == 4 {
tag.SetDefaultEncoding(EncodingUTF8)
} else {
tag.SetDefaultEncoding(EncodingISO)
}I would like to advocate for replacing that choice with UTF-16 with a BOM. From the spec:
All Unicode strings use 16-bit unicode 2.0 (ISO/IEC 10646-1:1993, UCS-2). Unicode strings must begin with the Unicode BOM ($FF FE or $FE FF) to identify the byte order.
So it seems like both specs can handle that, and it can handle (almost) all characters. Using your library, my Garmin GPS displays mojibake because of this default when listening to Лигалайз or other Russian rappers.
Nitpick: UCS-2 is not UTF-16, but it should be close enough that nobody notices (maybe actually encode strings as UCS-2, or at least check that the length is exactly 2 bytes per character). Here's a really fun read on the subject: https://unascribed.com/b/2019-08-02-the-tragedy-of-ucs2.html