id3v1, id3v2 charset encoding question

Think you found a bug in getID3()? Post here with details.
Post Reply
uno
User
Posts: 2
Joined: Sat Jan 07, 2012 12:05 am
Are you a spambot?: no

id3v1, id3v2 charset encoding question

Post by uno » Sat Jan 07, 2012 12:28 am

hi there & happy new year,
i've a short question. i'm using the following code to write my mp3 tags, nothing special so far. all data comes from a form and is valid UTF-8, but since id3v1 tags in UTF-8 are invalid according to the specs, i wonder if the encoding to ISO is done internally or if do have to take care about?

Code: Select all

                $id3 = new getID3;
                $id3->setOption(array('encoding'=>'UTF-8'));
                $w = new getid3_writetags;
                $w->tag_encoding = 'UTF-8';
                $w->filename = $some_file_name;
                $w->tagformats = array('id3v1', 'id3v2.3');
                // etc...
thanks, uno

James Heinrich
getID3() v1 developer
Posts: 1435
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: id3v1, id3v2 charset encoding question

Post by James Heinrich » Sat Jan 07, 2012 12:57 am

It's up to you to pass ISO-8859-1 data to the ID3v1 writing function.

uno
User
Posts: 2
Joined: Sat Jan 07, 2012 12:05 am
Are you a spambot?: no

Re: id3v1, id3v2 charset encoding question

Post by uno » Sat Jan 07, 2012 12:15 pm

thanks. so this would produce invalid mp3 files?

Code: Select all

$w->tag_encoding = 'UTF-8';
$w->tagformats = array('id3v1', 'id3v2.3');
$w->tag_data = $my_utf_data;
$w->WriteTags();
or did i miss the point? would that be better?

Code: Select all

// v1
$w->tag_encoding = 'ISO-8859-1';
$w->tagformats = array('id3v1');
$w->tag_data = $my_iso_v1_data;
$w->WriteTags();
//v2
$w->tag_encoding = 'UTF-8';
$w->tagformats = array('id3v2.3');
$w->tag_data = $my_utf_v2_data;
$w->WriteTags();
btw, is there a docmentation of all available methods?
thanks, uno

James Heinrich
getID3() v1 developer
Posts: 1435
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: id3v1, id3v2 charset encoding question

Post by James Heinrich » Sat Jan 07, 2012 2:03 pm

The ID3v1 writing function pays no attention to $w->tag_encoding, it just assumes the data that's passed is ISO-8859-1.
If your UTF-8 data happens to not have any multibyte characters (all within the overlapping range with ISO-8859-1) then either method would work, but the second method would be better.

I'll move this to the bug reports forum since it should really better handle the first case, but for now please handle ID3v1 separately.

Post Reply