Incorrect encoding for the names of music files
Telegram Desktop 0.9.18
Screenshot: 1 - from telegram interface. Screenshot: 2 - from OS.
Please add support cyrillic letters in the file names.
I think TDesktop print not a filename. It's tag of your audio file. Did you try to change the tags?
@DaFri-Nochiterov The tags are read like utf-8 strings. If they are in some local encoding it will be bad :( didn't think of how to determine the encoding yet.
I've seen the same issue with UTF-8 tags. You sure that's what it's reading as, @telegramdesktop?
@Zenexer UTF-8 tags should be correct, I need an example of wrong reading of UTF-8 tags.
If it happens again I'll be sure to save a copy. I believe the files I saw were from a Spotify bot that offered previews.
On Sat, Jan 23, 2016, 4:49 AM telegramdesktop [email protected] wrote:
@Zenexer https://github.com/Zenexer UTF-8 tags should be correct, I need an example of wrong reading of UTF-8 tags.
— Reply to this email directly or view it on GitHub https://github.com/telegramdesktop/tdesktop/issues/1513#issuecomment-174166324 .
Hi. I have an example mp3 file with a bad read tags. https://drive.google.com/file/d/0BwgJlWodegEDZTNJYnNTSjNhVkE/view

v.0.9.21dev
@formatq, try manually change tags with AIMP3 Tag Editor other same software. Not sure, but it can solve this problem.
@DaFri-Nochiterov thanks for the solution. But I think there is a way to decode tags in correct encoding on the fly.
Hey there!
We're automatically closing this issue since there was no activity in this issue since 362 days ago. We therefore assume that the user has lost interest or resolved the problem on their own. Closed issues that remain inactive for a long period may get automatically locked.
Don't worry though; if this is in error, let us know with a comment and we'll be happy to reopen the issue.
Thanks!
(Please note that this is an automated comment.)
It is correct most likely. Almost a year ago some quite inadequate person contacted support saying that TDesktop is wrong in handling of mp3 tags, and it turned out that his file was not following ID3 standard. (Although he just ignored deep explanation with tldr on ID3 and samples). I can provide this explanation, but it's in Russian and I don't want to translate it.
TLDR: Please upload sample of mp3 file.
You can see that in Windows explorer these tracks have correct encoding but in telegram (desktop or mobile) I see strange characters. I attached the track with incorrect characters in zip file.
@mana71 first of all, Telegram uses tags in file and not the filename to get artist and song names.
second: Here's how macOS displays that file:

third: Let's have a look at the file you've sent -- open it in hex editor (or just hexdump it):
❯ xxd Мистер\ Малой\ -\ дЕнЕг\ д0лЖен.mp3| head -n3
00000000: 4944 3303 0000 0000 0776 5449 5432 0000 ID3......vTIT2..
00000010: 000b 0000 00ca e0e9 f4ee ede0 e2f2 fb54 ...............T
00000020: 414c 4200 0000 1500 0000 c020 e820 c120 ALB........ . .
As you can see, it starts with ID3 -- that's a magic for ID3v2. Two following bytes indicate exact version: 2.3.0. Here's the informal standard. tldr on the format:
As the tag consists of a tag header and a tag body with one or more frames, all the frames consists of a frame header followed by one or more fields containing the actual information. The layout of the frame header:
Here's what frames look like:
Frame ID $xx xx xx xx (four characters) Size $xx xx xx xx Flags $xx xx
So, for the song title (TIT2) frame:
Frame ID $54 49 54 32 (TIT2) Size $00 00 00 0B Flags $00 00 Actual data $00 CA E0 E9 F4 EE ED E0 E2 F2 FB
So, let's see how to parse Data in the Text Information Frames (which TIT2 is):
<Header for 'Text information frame', ID: "T000" - "TZZZ", excluding "TXXX" described in 4.2.2.> Text encoding $xx Information <text string according to encoding>
Ok, so now we have:
Frame ID $54 49 54 32 (TIT2) Size $00 00 00 0B Flags $00 00 Text encoding $00 Information $CA E0 E9 F4 EE ED E0 E2 F2 FB
So, what is $00?
Frames that allow different types of text encoding have a text encoding description byte directly after the frame size. If ISO-8859-1 is used this byte should be $00, if Unicode is used it should be $01. Strings dependent on encoding is represented as
, or if newlines are allowed. Any empty Unicode strings which are NULL-terminated may have the Unicode BOM followed by a Unicode NULL ($FF FE 00 00 or $FE FF 00 00).
aha, so $CA E0 E9 F4 EE ED E0 E2 F2 FB is ISO-8859-1 string!
Now, let's decode it:
In [1]: from binascii import unhexlify
In [2]: unhexlify('CAE0E9F4EEEDE0E2F2FB').decode('ISO-8859-1')
Out[2]: 'Êàéôîíàâòû'
That's exactly what macOS and TDesktop show.
Now, bonus step: what if we decode it as CP1251 -- encoding that Windows loves to use for Cyrillic languages?
In [3]: unhexlify('CAE0E9F4EEEDE0E2F2FB').decode('CP1251')
Out[3]: 'Кайфонавты'
Well, that looks like a valid name. And yet another reason to hate how windows deals with text, completely ignoring standards and not even thinking about people who use different encodings. Another format where this causes a lot of issues is ZIP archive, btw.
Feel free to comment if you find a file conforming to standards but being parsed incorrectly by TDesktop.
@mana71 and I just realized that even on your screenshot windows explorer shows those broken names.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.