Adding or updating a tag

The place for "I can't figure out how to..." questions.
Post Reply
Mara Tatouille
User
Posts: 1
Joined: Thu Nov 20, 2008 2:31 pm

Adding or updating a tag

Post by Mara Tatouille » Thu Nov 20, 2008 2:41 pm

Hello all

I did search through the boards for a way to add or update a extended tag to an existing file, without modifying the other tags

Whereas I can get the tagwriter to create new tags with artist name, etc... I am not able to find out how to modify the current tag structure.

I can read it with the below code

Code: Select all

require_once('./getid3/getid3/getid3.php');
$getid3 = new getID3;
$getid3->encoding = 'UTF-8';

$filename = "/var/www/PersonalJesusNA.mp3";

set_time_limit (30);
$getid3->Analyze($filename);
$ArrayR= $getid3->info['id3v2']['POPM'];
$ArrayFull= $getid3->info;
So I have the full array of tags in $ArrayFull, and the array I want to modify in $ArrayR

My writing code is below

Code: Select all

$getID3 = new getID3;
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.php', __FILE__);
$TaggingFormat    = 'UTF-8';
$getID3->setOption(array('encoding'=>$TaggingFormat));
$tagwriter = new getid3_writetags;
$tagwriter->filename   = $filename;
      $tagwriter->tagformats     = array('id3v1', 'id3v2.3');
$tagwriter->overwrite_tags = true;
$tagwriter->tag_encoding   = $TaggingFormat;
$tagwriter->remove_other_tags = false;
$TagData=$ArrayFull;
$TagData['POPM'][0]['rating']=180;
echo "<PRE>\n";
print_r($TagData);
echo "</PRE>\n";
$tagwriter->tag_data    = $TagData;
$tagwriter->WriteTags();
When I try this, it should update only ['POPM'][0]['rating'] to 180 and write the tag. However, it's screwing up the tag structure completely. I end up with a near empty tag structure

Is there a guide somewhere on how to merge the existing data into the tagwriter's $tagdata? Or could someone post a snippet of code that just reads the existing tags from a file and would just copy them back (to the same file or another?

I know I'm missing something simple here, but can't find out what.

Any help appreciated.

Post Reply