summaryrefslogtreecommitdiff
path: root/getid3/write.metaflac.php
diff options
context:
space:
mode:
authorTheTroll <trolldev@gmail.com>2010-02-25 15:51:44 +0100
committerTheTroll <trolldev@gmail.com>2010-02-25 15:51:44 +0100
commit45ee8db7fd22ff9c9fe200802ed4e179000a5bb4 (patch)
tree228425717006ca104f9b1dc46e4b38d53ea6f7cc /getid3/write.metaflac.php
parent1d3095213541ba77015742a4c05cfcf66fd9c7e7 (diff)
downloadistreamdev-45ee8db7fd22ff9c9fe200802ed4e179000a5bb4.tar.gz
istreamdev-45ee8db7fd22ff9c9fe200802ed4e179000a5bb4.tar.bz2
Replaced mediainfo calls by getid3
Diffstat (limited to 'getid3/write.metaflac.php')
-rw-r--r--getid3/write.metaflac.php167
1 files changed, 167 insertions, 0 deletions
diff --git a/getid3/write.metaflac.php b/getid3/write.metaflac.php
new file mode 100644
index 0000000..c9521c8
--- /dev/null
+++ b/getid3/write.metaflac.php
@@ -0,0 +1,167 @@
+<?php
+/////////////////////////////////////////////////////////////////
+/// getID3() by James Heinrich <info@getid3.org> //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// write.metaflac.php //
+// module for writing metaflac tags //
+// dependencies: /helperapps/metaflac.exe //
+// ///
+/////////////////////////////////////////////////////////////////
+
+
+class getid3_write_metaflac
+{
+
+ var $filename;
+ var $tag_data;
+ var $warnings = array(); // any non-critical errors will be stored here
+ var $errors = array(); // any critical errors will be stored here
+
+ function getid3_write_metaflac() {
+ return true;
+ }
+
+ function WriteMetaFLAC() {
+
+ if (!ini_get('safe_mode')) {
+
+ // Create file with new comments
+ $tempcommentsfilename = tempnam('*', 'getID3');
+ if ($fpcomments = @fopen($tempcommentsfilename, 'wb')) {
+
+ foreach ($this->tag_data as $key => $value) {
+ foreach ($value as $commentdata) {
+ fwrite($fpcomments, $this->CleanmetaflacName($key).'='.$commentdata."\n");
+ }
+ }
+ fclose($fpcomments);
+
+ } else {
+
+ $this->errors[] = 'failed to open temporary tags file "'.$tempcommentsfilename.'", tags not written';
+ return false;
+
+ }
+
+ $oldignoreuserabort = ignore_user_abort(true);
+ if (GETID3_OS_ISWINDOWS) {
+
+ if (file_exists(GETID3_HELPERAPPSDIR.'metaflac.exe')) {
+ //$commandline = '"'.GETID3_HELPERAPPSDIR.'metaflac.exe" --no-utf8-convert --remove-all-tags --import-tags-from="'.$tempcommentsfilename.'" "'.str_replace('/', '\\', $this->filename).'"';
+ // metaflac works fine if you copy-paste the above commandline into a command prompt,
+ // but refuses to work with `backtick` if there are "doublequotes" present around BOTH
+ // the metaflac pathname and the target filename. For whatever reason...??
+ // The solution is simply ensure that the metaflac pathname has no spaces,
+ // and therefore does not need to be quoted
+
+ // On top of that, if error messages are not always captured properly under Windows
+ // To at least see if there was a problem, compare file modification timestamps before and after writing
+ clearstatcache();
+ $timestampbeforewriting = filemtime($this->filename);
+
+ $commandline = GETID3_HELPERAPPSDIR.'metaflac.exe --no-utf8-convert --remove-all-tags --import-tags-from="'.$tempcommentsfilename.'" "'.$this->filename.'" 2>&1';
+ $metaflacError = `$commandline`;
+
+ if (empty($metaflacError)) {
+ clearstatcache();
+ if ($timestampbeforewriting == filemtime($this->filename)) {
+ $metaflacError = 'File modification timestamp has not changed - it looks like the tags were not written';
+ }
+ }
+ } else {
+ $metaflacError = 'metaflac.exe not found in '.GETID3_HELPERAPPSDIR;
+ }
+
+ } else {
+
+ // It's simpler on *nix
+ $commandline = 'metaflac --no-utf8-convert --remove-all-tags --import-tags-from='.$tempcommentsfilename.' "'.$this->filename.'" 2>&1';
+ $metaflacError = `$commandline`;
+
+ }
+
+ // Remove temporary comments file
+ unlink($tempcommentsfilename);
+ ignore_user_abort($oldignoreuserabort);
+
+ if (!empty($metaflacError)) {
+
+ $this->errors[] = 'System call to metaflac failed with this message returned: '."\n\n".$metaflacError;
+ return false;
+
+ }
+
+ return true;
+ }
+
+ $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call metaflac, tags not written';
+ return false;
+ }
+
+
+ function DeleteMetaFLAC() {
+
+ if (!ini_get('safe_mode')) {
+
+ $oldignoreuserabort = ignore_user_abort(true);
+ if (GETID3_OS_ISWINDOWS) {
+
+ if (file_exists(GETID3_HELPERAPPSDIR.'metaflac.exe')) {
+ // To at least see if there was a problem, compare file modification timestamps before and after writing
+ clearstatcache();
+ $timestampbeforewriting = filemtime($this->filename);
+
+ $commandline = GETID3_HELPERAPPSDIR.'metaflac.exe --remove-all-tags "'.$this->filename.'" 2>&1';
+ $metaflacError = `$commandline`;
+
+ if (empty($metaflacError)) {
+ clearstatcache();
+ if ($timestampbeforewriting == filemtime($this->filename)) {
+ $metaflacError = 'File modification timestamp has not changed - it looks like the tags were not deleted';
+ }
+ }
+ } else {
+ $metaflacError = 'metaflac.exe not found in '.GETID3_HELPERAPPSDIR;
+ }
+
+ } else {
+
+ // It's simpler on *nix
+ $commandline = 'metaflac --remove-all-tags "'.$this->filename.'" 2>&1';
+ $metaflacError = `$commandline`;
+
+ }
+
+ ignore_user_abort($oldignoreuserabort);
+
+ if (!empty($metaflacError)) {
+ $this->errors[] = 'System call to metaflac failed with this message returned: '."\n\n".$metaflacError;
+ return false;
+ }
+ return true;
+ }
+ $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call metaflac, tags not deleted';
+ return false;
+ }
+
+
+ function CleanmetaflacName($originalcommentname) {
+ // A case-insensitive field name that may consist of ASCII 0x20 through 0x7D, 0x3D ('=') excluded.
+ // ASCII 0x41 through 0x5A inclusive (A-Z) is to be considered equivalent to ASCII 0x61 through
+ // 0x7A inclusive (a-z).
+
+ // replace invalid chars with a space, return uppercase text
+ // Thanks Chris Bolt <chris-getid3Øbolt*cx> for improving this function
+ // note: ereg_replace() replaces nulls with empty string (not space)
+ return strtoupper(ereg_replace('[^ -<>-}]', ' ', str_replace("\x00", ' ', $originalcommentname)));
+
+ }
+
+}
+
+?> \ No newline at end of file