function removeArtwork($file) { $cmd = 'metaflac --remove --block-type=PICTURE "' . $file . '"'; $res = \GlobalMethods::openProcess($cmd); if ($res !== FALSE) { //As of this writing, metaflac returns an exit status of //zero (which cannot necessarily be relied upon on Windows) //and does not produce any output on success. The latter fact is //far more reliable than the exit status. if ($res['stdOut'] == '' && $res['stdErr'] == '') { return array('result' => TRUE, 'error' => NULL); } else { return array('result' => FALSE, 'error' => 'The call to `metaflac` produced output, which indicates an error condition: ' . \Utility::varToString($res)); } } else { return array('result' => FALSE, 'error' => 'The process could not be opened: ' . $cmd); } }
/** * Important: NEVER call this function on a "master" file, as it removes the * artwork from THAT file (and not a copy)! * @param string $file * @param array $tagData * @param boolean $allowBlank * @param string $coverFile * @return multitype:boolean string |multitype:boolean NULL */ function transcodeFlacToAlac($file, $tagData = array(), $allowBlank = FALSE, $coverFile = NULL) { //In avconv version 9.16 (and possibly earlier), embedded artwork with a //width or height that is not divisible by 2 will cause a failure, e.g.: //"width not divisible by 2 (1419x1419)". So, we must strip any "odd" artwork. //It's entirely possible that artwork was not copied in earlier versions, so //this error did not occur. $r = $this->tagger->removeArtwork($file); $cmd1 = 'avconv -i'; //Tag data is copied automatically. Nice!!! $pathParts = pathinfo($file); $outfile = $pathParts['dirname'] . DIRECTORY_SEPARATOR . $pathParts['filename'] . '.m4a'; $cmd1 .= ' "' . $file . '" -acodec alac "' . $outfile . '"'; $r1 = \GlobalMethods::openProcess($cmd1); if ($r1['exitCode'] == 0) { //Write the cover artwork into the file, and fail gracefully. //Note the unconventional letter-case of the executable name and its options //(which are indeed case-sensitive). if (is_string($coverFile) && strlen($coverFile) > 0) { $cmd2 = 'AtomicParsley "' . $outfile . '" --artwork "' . $coverFile . '" --overWrite'; $r2 = \GlobalMethods::openProcess($cmd2); if ($r2['exitCode'] != 0) { $e = 'The FLAC file was transcoded to an ALAC file successfully, but the album artwork could not be embedded; the command was: "' . $cmd2 . '"'; \GlobalMethods::logCriticalError($e); } } } else { $error = 'The FLAC file could not be transcoded to an ALAC file; the command was: "' . $cmd1 . '"'; return array('result' => FALSE, 'error' => $error); } return array('result' => TRUE, 'error' => NULL); }