[1.7.6] Cannot disable modules when using getid3_writetags

Think you found a bug in getID3()? Post here with details.
Post Reply
gokusandwich
User
Posts: 16
Joined: Wed Jan 26, 2005 12:53 am

[1.7.6] Cannot disable modules when using getid3_writetags

Post by gokusandwich » Wed Mar 22, 2006 11:19 pm

When using the getid3_writetags class (in file write.php), it is not possible to disable tag modules which you do not intend to use. For instance, I am not using Lyrics3 and apetags. However, I cannot remove the modules for these tag formats if I plan to use the getid3_writetags class to write out tags.

The simplest solution that I could come up with for this: make a member variable, $getid3, of getid3_writetags, which may be set manually before invoking getid3_writetags::WriteTags() (if the user wishes to do so).

Here is a patch which adds such functionality:

Code: Select all

--- write.php.original	2006-03-22 18:11:06.000000000 -0500
+++ write.php	2006-03-22 18:11:01.000000000 -0500
@@ -60,6 +60,8 @@
 	var $warnings           = array();        // any non-critical errors will be stored here
 	var $errors             = array();        // any critical errors will be stored here
 
+	var $getID3             = null;           // instance of getID3 class used to read the original tags
+
 	// private
 	var $ThisFileInfo; // analysis of file before writing
 
@@ -92,10 +94,28 @@
 
 		} else {
 
-			$getID3 = new getID3;
-			$getID3->encoding = $this->tag_encoding;
+			$getID3 = $this->getID3;
+			if ($getID3 == null) {
+
+				$getID3 = new getID3;
+				$this->tag_encoding = $getID3->encoding;
+			}
+			else if (!is_a($getID3, 'getID3')) {
+
+				$this->errors[] = 'getID3 property is not an instance of the getID3 class';
+				return false;
+			}
+
 			$this->ThisFileInfo = $getID3->analyze($this->filename);
 
+			// if errors occurred while analyzing the file, we should not
+			// attempt to write tags.
+			if (!empty($this->ThisFileInfo['error'])) {
+
+				$this->errors = $this->ThisFileInfo['error'];
+				return false;
+			}
+
 			// check for what file types are allowed on this fileformat
 			switch (@$this->ThisFileInfo['fileformat']) {
 				case 'mp3':

This patch also adds a check on the ['error'] field of the array returned from getID3::analyze(). If any errors occurred when analyzing the file, then the WriteTags() function will bail, placing the errors returned by analyze() in its own errors property.

(Note: I modified the patch posted above, on 2006-05-07, as there was a small mistake.)

gokusandwich
User
Posts: 16
Joined: Wed Jan 26, 2005 12:53 am

[1.7.6] Cannot disable modules when using getid3_writetags

Post by gokusandwich » Thu Apr 20, 2006 5:58 pm

Perhaps the above patch is a little too intrusive. I did not read deeply enough into the use of the ['error'] field, as returned by getID3::analyze().

This portion of the patch should probably be removed:

Code: Select all

+         // if errors occurred while analyzing the file, we should not
+         // attempt to write tags.
+         if (!empty($this->ThisFileInfo['error'])) {
+
+            $this->errors = $this->ThisFileInfo['error'];
+            return false;
+         } 
However, it seems as if there needs to be a mechanism for determining whether getID3::analyze() has failed all-together; that is, has failed to extract any valuable information because it cannot determine the file type or it has been passed a corrupt file, etc. (Or is there already a sure way to do this?).

Although, structure.txt does describe the ['error'] field by saying "if present, contains one or more fatal error messages", which would lead one to believe that, when something is present in ['error'], processing must not have returned any valuable information. Perhaps some more clarification there...?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest