1

I am trying to read id3 tags with id3v2lib

My code is:

ID3v2_tag* tag = load_tag(argv[1]); // Load the full tag from the file

if(!tag){
    tag = new_tag();
}

const char * t = "Matej";
ID3v2_frame* artist_frame = tag_get_artist(tag); // Get the full artist frame


ID3v2_frame* title_frame = tag_get_title(tag);
ID3v2_frame_text_content* title_content = parse_text_frame_content(title_frame);
if( title_content){
    cout << title_content->data << endl;
}

This does print title of song. However, for some files it prints unreadable garbage.

I am not sure if the file is somehow corrupted. But using eyeD3 on files that outputs garbage for title works fine.

Has anyone met with same problem? What could be the cause

Darlyn
  • 4,715
  • 12
  • 40
  • 90
  • 1
    Not familiar with the library, but does it handle UCS-2 and UTF-16 tags properly? – Retired Ninja Aug 06 '17 at 20:49
  • `ID3v2_frame_text_content` is a struct that contains a string, an encoding, and a size. It's possible the string isn't null terminated, which means you'd need to look at the size to know where to truncate the string. – MrEricSir Aug 06 '17 at 20:55
  • I am not sure if this handle UCS-2 and UTF-16 properly. When i print size it prints 36 ( ofc based on file ). when i print encoding it also prints garbage. Also trying to truncate it using title_content -> data[ title_content -> data ] = '\0'; didnt work either, also @RetiredNinja could u recommend library for this? I have tried libtag but i couldnt make it work on my ubuntu. – Darlyn Aug 06 '17 at 21:03

0 Answers0