Skip to content

Instantly share code, notes, and snippets.

@jnrbsn
Created December 19, 2012 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnrbsn/4334151 to your computer and use it in GitHub Desktop.
Save jnrbsn/4334151 to your computer and use it in GitHub Desktop.
Wrapper class for AtomicParsley for setting iTunes style meta data on MPEG-4 files via PHP.
<?php
/**
* Wrapper class for AtomicParsley for setting iTunes style meta data on MPEG-4 files.
*
* Dependencies:
* - Bunsen <http://github.com/jnrbsn/bunsen>
* - AtomicParsley <http://atomicparsley.sourceforge.net/>
*/
class AtomicParsley
{
/**
* Absolute path to the AtomicParsley binary.
*/
public static $binPath = '/usr/local/bin/AtomicParsley';
/**
* Set some metadata.
*
* @param string $file The absolute path to the MPEG-4 file.
* @param array $tags An associative array of keys and values of tags to set.
*
* @return string The command that was run.
*/
public static function set($file, array $tags=array())
{
$command = self::$binPath.' '.escapeshellarg($file).' --overWrite';
foreach ($tags as $option => $value) {
if ($value === true) {
$command .= ' --'.$option;
} else if (is_int($value)) {
$command .= ' --'.$option.' '.$value;
} else {
$command .= ' --'.$option.' '.escapeshellarg($value);
}
}
$bunsen = new Bunsen;
if ($bunsen->exec($command) !== 0) {
trigger_error($bunsen->stderr(), E_USER_WARNING);
return false;
}
if (isset($tags['artwork'])) {
$tempfiles = preg_replace('/^(.*)(\.[a-z]{3,4})$/', '$1-resized-*$2', $tags['artwork']);
if (strpos($tempfiles, dirname($tags['artwork'])) === 0) {
foreach (glob($tempfiles) as $tempfile) {
unlink($tempfile);
}
}
}
return $command;
}//end set()
}//end class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment