Created
December 19, 2012 03:27
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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