Support for TXXX comments in ID3v2?

Think you found a bug in getID3()? Post here with details.
Post Reply
odyssey
User
Posts: 4
Joined: Thu Aug 04, 2011 2:16 pm
Are you a spambot?: no

Support for TXXX comments in ID3v2?

Post by odyssey » Thu Aug 04, 2011 2:22 pm

I'm trying a few things with this great library (1.9.0) , but I have trouble trying to write TXXX comments to ID3v2. Is this supported at all, or am I just not doing it right?

The code I'm using is below:

Code: Select all

require_once('./getid3/getid3.php');
require_once('./getid3/write.php');

$file = "test.mp3";

$getID3 = new getID3;
$getID3->setOption(array('encoding'=>'UTF-8'));

$tagwriter = new getid3_writetags;
$tagwriter->tag_encoding = 'UTF-8';
$tagwriter->overwrite_tags = true;
$tagwriter->remove_other_tags = true;

//$tagwriter->tagformats = array('id3v2.3');
$tagwriter->tagformats = array('id3v2.3');

$tagwriter->filename = $file;

$TagData['test']='value';

$tagwriter->tag_data = $TagData;
if (!$tagwriter->WriteTags())
    echo "\nfailure - ".strip_tags(implode($tagwriter->errors))."\n";

odyssey
User
Posts: 4
Joined: Thu Aug 04, 2011 2:16 pm
Are you a spambot?: no

Re: Support for TXXX comments in ID3v2?

Post by odyssey » Mon Aug 15, 2011 3:13 pm

Okay, so I digged through the code to see if I could find anything. Obviously support for TXXX-frames seem present and also I was doing it wrong.

It looks like the correct way to write these "comments", is to do it like this:

Code: Select all

$TagData['user_text']['my_custom_field'] = "whatever value";
Unfortunately nothing happened. I can see that it indeed writes a TXXX-frame when I inspect the file, but the description-value (my_custom_field) is not written at all. It looks like the description_value is cleared somewhere, because if I set the $source_data_array['description'] (in write.id3v2.php) to a static value just before writing the file (near line 332), it works just fine.

Can someone verify this problem?

odyssey
User
Posts: 4
Joined: Thu Aug 04, 2011 2:16 pm
Are you a spambot?: no

Re: Support for TXXX comments in ID3v2?

Post by odyssey » Mon Aug 15, 2011 4:24 pm

In write.id3v2.php, I found this line:

Code: Select all

foreach ($frame_rawinputdata as $irrelevantindex => $source_data_array) {
Not sure if this is where the problem lies, but $irrelevantindex contains the description (my_custom_field) that needs to be passed on somehow, and I can't really see that it is passed in this function.

odyssey
User
Posts: 4
Joined: Thu Aug 04, 2011 2:16 pm
Are you a spambot?: no

Re: Support for TXXX comments in ID3v2?

Post by odyssey » Mon Aug 15, 2011 4:41 pm

Umm... Okay, so I guess maybe a quickpatch would be to add the following line:

Code: Select all

$source_data_array['description']=$irrelevantindex;
somewhere, maybe here:

Code: Select all

foreach ($frame_rawinputdata as $irrelevantindex => $source_data_array) {
$source_data_array['description']=$irrelevantindex;
if (getid3_id3v2::IsValidID3v2FrameName($frame_name, $this->majorversion)) {
Not sure if it would create any sideeffects or anything, but let's see now :)

fred727
User
Posts: 11
Joined: Wed Jun 08, 2016 6:20 pm
Are you a spambot?: no

Re: Support for TXXX comments in ID3v2?

Post by fred727 » Wed Jun 08, 2016 6:51 pm

Just do this way :

Code: Select all

		$tagwriter = new getid3_writetags() ;
		$tagwriter->filename = 'path.to/your.mp3' ;
		$tagwriter->tagformats = array( 'id3v2.3' ) ;
		$tagwriter->overwrite_tags    = true;    // if true will erase existing tag data and write only passed data; if false will merge passed data with existing tag data (experimental)
		$tagwriter->remove_other_tags = false;   // if true removes other tag formats (e.g. ID3v1, ID3v2, APE, Lyrics3, etc) that may be present in the file and only write the specified tag format(s). If false leaves any unspecified tag formats as-is.
		$tagwriter->tag_encoding      = 'UTF-8';
		$tagwriter->id3v2_tag_language = 'fre' ; // ISO-639-2 3-character language code : fre for French for example
		$tagwriter->tag_data = array(
			'title'                     => array( 'My Title' ),
			'album'                     => array( 'My Album' ),
			/* ... ... */
			'user_text'                 => array( "Your text here" ),
		);
		$ok = $tagwriter->WriteTags() ;

Post Reply