Simple question: update comment tag

Post Reply
timneu22
User
Posts: 6
Joined: Thu Sep 30, 2010 8:50 pm
Are you a spambot?: no

Simple question: update comment tag

Post by timneu22 » Thu Sep 30, 2010 8:52 pm

Hello,

Sorry that I'm in a support forum, but the code makes it quite difficult for me to determine this. Can you tell me how I can simply read an mp3, update its "comment" tag, and then save it? This is the only functionality I need, and if you can provide this small code snippet I would be appreciative!

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

Re: Simple question: update comment tag

Post by James Heinrich » Sat Jan 08, 2011 10:56 pm

You have to write an entire tag. It's left to you to read in the existing data, manipulate it as you see fit (change the contents of a field, for example) and the write it back to the file.

timneu22
User
Posts: 6
Joined: Thu Sep 30, 2010 8:50 pm
Are you a spambot?: no

Re: Simple question: update comment tag

Post by timneu22 » Sat Jan 08, 2011 11:13 pm

Interesting. So what, exactly, is the purpose of things like $remove_other_tags and $overwrite_tags?

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

Re: Simple question: update comment tag

Post by James Heinrich » Sun Jan 09, 2011 3:12 am

var $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
var $remove_other_tags = false; // if true will erase remove all existing tags and only write those passed in $tagformats; if false will ignore any tags not mentioned in $tagformats

timneu22
User
Posts: 6
Joined: Thu Sep 30, 2010 8:50 pm
Are you a spambot?: no

Re: Simple question: update comment tag

Post by timneu22 » Sun Jan 09, 2011 2:27 pm

But you said I have to write the entire tag. I want to just write the comment tag. The definition of those booleans seems to contradict your first reply.

Can you provide a code example of how I would take an mp3, change its comment to "this is a comment", and rewrite all the tags of the mp3?

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

Re: Simple question: update comment tag

Post by James Heinrich » Sun Jan 09, 2011 4:31 pm

Apparently I forgot I added the feature of ($overwrite_tags == false), it's been several years since I worked on the tag-writing code.

Using an abbreviated extract of /demo/demo.write.simple.php I get:

Code: Select all

require_once('../getid3/getid3.php');
require_once('../getid3/write.php');
$getID3 = new getID3;
$tagwriter = new getid3_writetags;
$tagwriter->filename       = '/path/to/file.mp3';
$tagwriter->tagformats     = array('id3v2.3');
$tagwriter->overwrite_tags = false;
$tagwriter->tag_data['comment'] = array('this is a comment');
$tagwriter->WriteTags();
(the original demo file is better commented)
If you want to write id3v1, ape, etc you can add those into $tagwriter->tagformats. If you set $tagwriter->remove_other_tags=true then all other tag formats (id3v1, ape, lyrics3) will be stripped from the file; if $tagwriter->remove_other_tags=false then they will be left alone).

timneu22
User
Posts: 6
Joined: Thu Sep 30, 2010 8:50 pm
Are you a spambot?: no

Re: Simple question: update comment tag

Post by timneu22 » Fri Jan 14, 2011 7:02 pm

Sorry, this does not work. With this method, the comments field remains unchanged. Is it possible that $overwrite_tags prevents me from updating the one field that I actually want to update??

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

Re: Simple question: update comment tag

Post by James Heinrich » Fri Jan 14, 2011 7:38 pm

And if instead of just $tagwriter->WriteTags(); you use the more verbose example from demo.write.simple.php, what does it say?:

Code: Select all

if ($tagwriter->WriteTags()) {
	echo 'Successfully wrote tags<br>';
	if (!empty($tagwriter->warnings)) {
		echo 'There were some warnings:<br>'.implode('<br><br>', $tagwriter->warnings);
	}
} else {
	echo 'Failed to write tags!<br>'.implode('<br><br>', $tagwriter->errors);
}

timneu22
User
Posts: 6
Joined: Thu Sep 30, 2010 8:50 pm
Are you a spambot?: no

Re: Simple question: update comment tag

Post by timneu22 » Fri Jan 14, 2011 8:57 pm

WriteID3v2() failed with message(s):
Frame not allowed in ID3v2.3: ALBUM
* Frame "ALBUM" is NOT allowed
* $this->GenerateID3v2FrameData() failed for "ALBUM"
* $this->GenerateID3v2Tag() failed

timneu22
User
Posts: 6
Joined: Thu Sep 30, 2010 8:50 pm
Are you a spambot?: no

Re: Simple question: update comment tag

Post by timneu22 » Wed Sep 14, 2011 10:17 am

I cannot get this to work reliably. It should be a two-line function: update_comment( $comment) and then write back to disk.

I have upset customers because of this complete failure.

Post Reply