ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
GetId3\Write\Metaflac Class Reference

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //. More...

+ Collaboration diagram for GetId3\Write\Metaflac:

Public Member Functions

 __construct ()
 
 WriteMetaFLAC ()
 
 DeleteMetaFLAC ()
 
 CleanmetaflacName ($originalcommentname)
 

Data Fields

 $filename
 
 $tag_data
 
 $warnings = array()
 
 $errors = array()
 

Detailed Description

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //.

module for writing metaflac tags

Author
James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g http://www.getid3.org helperapps/metaflac.exe

Definition at line 29 of file Metaflac.php.

Constructor & Destructor Documentation

◆ __construct()

GetId3\Write\Metaflac::__construct ( )
Returns
boolean

Definition at line 49 of file Metaflac.php.

50  {
51  return true;
52  }

Member Function Documentation

◆ CleanmetaflacName()

GetId3\Write\Metaflac::CleanmetaflacName (   $originalcommentname)
Parameters
type$originalcommentname
Returns
type

Definition at line 191 of file Metaflac.php.

Referenced by GetId3\Write\Metaflac\WriteMetaFLAC().

192  {
193  // A case-insensitive field name that may consist of ASCII 0x20 through 0x7D, 0x3D ('=') excluded.
194  // ASCII 0x41 through 0x5A inclusive (A-Z) is to be considered equivalent to ASCII 0x61 through
195  // 0x7A inclusive (a-z).
196 
197  // replace invalid chars with a space, return uppercase text
198  // Thanks Chris Bolt <chris-getid3Øbolt*cx> for improving this function
199  // note: *reg_replace() replaces nulls with empty string (not space)
200  return strtoupper(preg_replace('#[^ -<>-}]#', ' ', str_replace("\x00", ' ', $originalcommentname)));
201 
202  }
+ Here is the caller graph for this function:

◆ DeleteMetaFLAC()

GetId3\Write\Metaflac::DeleteMetaFLAC ( )
Returns
boolean

Definition at line 138 of file Metaflac.php.

References GetId3\GetId3Core\environmentIsWindows(), and GetId3\GetId3Core\getHelperAppsDir().

139  {
140  if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
141  $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call metaflac, tags not deleted';
142 
143  return false;
144  }
145 
146  $oldignoreuserabort = ignore_user_abort(true);
148 
149  if (file_exists(GetId3Core::getHelperAppsDir().'metaflac.exe')) {
150  // To at least see if there was a problem, compare file modification timestamps before and after writing
151  clearstatcache();
152  $timestampbeforewriting = filemtime($this->filename);
153 
154  $commandline = GetId3Core::getHelperAppsDir().'metaflac.exe --remove-all-tags "'.$this->filename.'" 2>&1';
155  $metaflacError = `$commandline`;
156 
157  if (empty($metaflacError)) {
158  clearstatcache();
159  if ($timestampbeforewriting == filemtime($this->filename)) {
160  $metaflacError = 'File modification timestamp has not changed - it looks like the tags were not deleted';
161  }
162  }
163  } else {
164  $metaflacError = 'metaflac.exe not found in '.GetId3Core::getHelperAppsDir();
165  }
166 
167  } else {
168 
169  // It's simpler on *nix
170  $commandline = 'metaflac --remove-all-tags "'.$this->filename.'" 2>&1';
171  $metaflacError = `$commandline`;
172 
173  }
174 
175  ignore_user_abort($oldignoreuserabort);
176 
177  if (!empty($metaflacError)) {
178  $this->errors[] = 'System call to metaflac failed with this message returned: '."\n\n".$metaflacError;
179 
180  return false;
181  }
182 
183  return true;
184  }
static environmentIsWindows()
static getHelperAppsDir()
Definition: GetId3Core.php:186
+ Here is the call graph for this function:

◆ WriteMetaFLAC()

GetId3\Write\Metaflac::WriteMetaFLAC ( )
Returns
boolean

Definition at line 58 of file Metaflac.php.

References GetId3\Write\Metaflac\CleanmetaflacName(), GetId3\GetId3Core\environmentIsWindows(), GetId3\GetId3Core\getHelperAppsDir(), and GetId3\GetId3Core\getTempDir().

59  {
60  if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
61  $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call metaflac, tags not written';
62 
63  return false;
64  }
65 
66  // Create file with new comments
67  $tempcommentsfilename = tempnam(GetId3Core::getTempDir(), 'getID3');
68  if (is_writable($tempcommentsfilename) && is_file($tempcommentsfilename) && ($fpcomments = fopen($tempcommentsfilename, 'wb'))) {
69  foreach ($this->tag_data as $key => $value) {
70  foreach ($value as $commentdata) {
71  fwrite($fpcomments, $this->CleanmetaflacName($key).'='.$commentdata."\n");
72  }
73  }
74  fclose($fpcomments);
75 
76  } else {
77  $this->errors[] = 'failed to open temporary tags file, tags not written - fopen("'.$tempcommentsfilename.'", "wb")';
78 
79  return false;
80  }
81 
82  $oldignoreuserabort = ignore_user_abort(true);
84 
85  if (file_exists(GetId3Core::getHelperAppsDir().'metaflac.exe')) {
86  //$commandline = '"'.GetId3Core::getHelperAppsDir().'metaflac.exe" --no-utf8-convert --remove-all-tags --import-tags-from="'.$tempcommentsfilename.'" "'.str_replace('/', '\\', $this->filename).'"';
87  // metaflac works fine if you copy-paste the above commandline into a command prompt,
88  // but refuses to work with `backtick` if there are "doublequotes" present around BOTH
89  // the metaflac pathname and the target filename. For whatever reason...??
90  // The solution is simply ensure that the metaflac pathname has no spaces,
91  // and therefore does not need to be quoted
92 
93  // On top of that, if error messages are not always captured properly under Windows
94  // To at least see if there was a problem, compare file modification timestamps before and after writing
95  clearstatcache();
96  $timestampbeforewriting = filemtime($this->filename);
97 
98  $commandline = GetId3Core::getHelperAppsDir().'metaflac.exe --no-utf8-convert --remove-all-tags --import-tags-from='.escapeshellarg($tempcommentsfilename).' '.escapeshellarg($this->filename).' 2>&1';
99  $metaflacError = `$commandline`;
100 
101  if (empty($metaflacError)) {
102  clearstatcache();
103  if ($timestampbeforewriting == filemtime($this->filename)) {
104  $metaflacError = 'File modification timestamp has not changed - it looks like the tags were not written';
105  }
106  }
107  } else {
108  $metaflacError = 'metaflac.exe not found in '.GetId3Core::getHelperAppsDir();
109  }
110 
111  } else {
112 
113  // It's simpler on *nix
114  $commandline = 'metaflac --no-utf8-convert --remove-all-tags --import-tags-from='.escapeshellarg($tempcommentsfilename).' '.escapeshellarg($this->filename).' 2>&1';
115  $metaflacError = `$commandline`;
116 
117  }
118 
119  // Remove temporary comments file
120  unlink($tempcommentsfilename);
121  ignore_user_abort($oldignoreuserabort);
122 
123  if (!empty($metaflacError)) {
124 
125  $this->errors[] = 'System call to metaflac failed with this message returned: '."\n\n".$metaflacError;
126 
127  return false;
128 
129  }
130 
131  return true;
132  }
static environmentIsWindows()
CleanmetaflacName($originalcommentname)
Definition: Metaflac.php:191
static getHelperAppsDir()
Definition: GetId3Core.php:186
+ Here is the call graph for this function:

Field Documentation

◆ $errors

GetId3\Write\Metaflac::$errors = array()

Definition at line 43 of file Metaflac.php.

◆ $filename

GetId3\Write\Metaflac::$filename

Definition at line 32 of file Metaflac.php.

◆ $tag_data

GetId3\Write\Metaflac::$tag_data

Definition at line 33 of file Metaflac.php.

◆ $warnings

GetId3\Write\Metaflac::$warnings = array()

Definition at line 38 of file Metaflac.php.


The documentation for this class was generated from the following file: