diff --git a/serendipity_event_podcast/ChangeLog b/serendipity_event_podcast/ChangeLog index e43208d9..a54855dc 100644 --- a/serendipity_event_podcast/ChangeLog +++ b/serendipity_event_podcast/ChangeLog @@ -1,3 +1,6 @@ +1.37.7: + * Additional fixes for PHP 8 + 1.37.6: * Hotfixes for PHP 8 (surrim) diff --git a/serendipity_event_podcast/composer.json b/serendipity_event_podcast/composer.json new file mode 100644 index 00000000..9ce389a8 --- /dev/null +++ b/serendipity_event_podcast/composer.json @@ -0,0 +1,8 @@ +{ + "config": { + "vendor-dir": "player" + }, + "require": { + "james-heinrich/getid3": "^1.9" + } +} \ No newline at end of file diff --git a/serendipity_event_podcast/composer.lock b/serendipity_event_podcast/composer.lock new file mode 100644 index 00000000..446855c4 --- /dev/null +++ b/serendipity_event_podcast/composer.lock @@ -0,0 +1,86 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "1aca7343f11a56253e87d4b5e4ff8bfc", + "packages": [ + { + "name": "james-heinrich/getid3", + "version": "v1.9.22", + "source": { + "type": "git", + "url": "https://github.com/JamesHeinrich/getID3.git", + "reference": "45f20faa0f0a24489740392c5b512ddcc36deccd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/JamesHeinrich/getID3/zipball/45f20faa0f0a24489740392c5b512ddcc36deccd", + "reference": "45f20faa0f0a24489740392c5b512ddcc36deccd", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.0" + }, + "suggest": { + "ext-SimpleXML": "SimpleXML extension is required to analyze RIFF/WAV/BWF audio files (also requires `ext-libxml`).", + "ext-com_dotnet": "COM extension is required when loading files larger than 2GB on Windows.", + "ext-ctype": "ctype extension is required when loading files larger than 2GB on 32-bit PHP (also on 64-bit PHP on Windows) or executing `getid3_lib::CopyTagsToComments`.", + "ext-dba": "DBA extension is required to use the DBA database as a cache storage.", + "ext-exif": "EXIF extension is required for graphic modules.", + "ext-iconv": "iconv extension is required to work with different character sets (when `ext-mbstring` is not available).", + "ext-json": "JSON extension is required to analyze Apple Quicktime videos.", + "ext-libxml": "libxml extension is required to analyze RIFF/WAV/BWF audio files.", + "ext-mbstring": "mbstring extension is required to work with different character sets.", + "ext-mysql": "MySQL extension is required to use the MySQL database as a cache storage (deprecated in PHP 5.5, removed in PHP >= 7.0, use `ext-mysqli` instead).", + "ext-mysqli": "MySQLi extension is required to use the MySQL database as a cache storage.", + "ext-rar": "RAR extension is required for RAR archive module.", + "ext-sqlite3": "SQLite3 extension is required to use the SQLite3 database as a cache storage.", + "ext-xml": "XML extension is required for graphic modules to analyze the XML metadata.", + "ext-zlib": "Zlib extension is required for archive modules and compressed metadata." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9.x-dev" + } + }, + "autoload": { + "classmap": [ + "getid3/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-1.0-or-later", + "LGPL-3.0-only", + "MPL-2.0" + ], + "description": "PHP script that extracts useful information from popular multimedia file formats", + "homepage": "https://www.getid3.org/", + "keywords": [ + "codecs", + "php", + "tags" + ], + "support": { + "issues": "https://github.com/JamesHeinrich/getID3/issues", + "source": "https://github.com/JamesHeinrich/getID3/tree/v1.9.22" + }, + "time": "2022-09-29T16:41:13+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.3.0" +} diff --git a/serendipity_event_podcast/player/autoload.php b/serendipity_event_podcast/player/autoload.php new file mode 100644 index 00000000..567227b4 --- /dev/null +++ b/serendipity_event_podcast/player/autoload.php @@ -0,0 +1,12 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + * @see https://www.php-fig.org/psr/psr-0/ + * @see https://www.php-fig.org/psr/psr-4/ + */ +class ClassLoader +{ + /** @var ?string */ + private $vendorDir; + + // PSR-4 + /** + * @var array[] + * @psalm-var array> + */ + private $prefixLengthsPsr4 = array(); + /** + * @var array[] + * @psalm-var array> + */ + private $prefixDirsPsr4 = array(); + /** + * @var array[] + * @psalm-var array + */ + private $fallbackDirsPsr4 = array(); + + // PSR-0 + /** + * @var array[] + * @psalm-var array> + */ + private $prefixesPsr0 = array(); + /** + * @var array[] + * @psalm-var array + */ + private $fallbackDirsPsr0 = array(); + + /** @var bool */ + private $useIncludePath = false; + + /** + * @var string[] + * @psalm-var array + */ + private $classMap = array(); + + /** @var bool */ + private $classMapAuthoritative = false; + + /** + * @var bool[] + * @psalm-var array + */ + private $missingClasses = array(); + + /** @var ?string */ + private $apcuPrefix; + + /** + * @var self[] + */ + private static $registeredLoaders = array(); + + /** + * @param ?string $vendorDir + */ + public function __construct($vendorDir = null) + { + $this->vendorDir = $vendorDir; + } + + /** + * @return string[] + */ + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); + } + + return array(); + } + + /** + * @return array[] + * @psalm-return array> + */ + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + /** + * @return array[] + * @psalm-return array + */ + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + /** + * @return array[] + * @psalm-return array + */ + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + /** + * @return string[] Array of classname => path + * @psalm-return array + */ + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param string[] $classMap Class to filename map + * @psalm-param array $classMap + * + * @return void + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param string[]|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + * + * @return void + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param string[]|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + * + * @return void + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param string[]|string $paths The PSR-0 base directories + * + * @return void + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param string[]|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + * + * @return void + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + * + * @return void + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + * + * @return void + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + * + * @return void + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + * + * @return void + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + + if (null === $this->vendorDir) { + return; + } + + if ($prepend) { + self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders; + } else { + unset(self::$registeredLoaders[$this->vendorDir]); + self::$registeredLoaders[$this->vendorDir] = $this; + } + } + + /** + * Unregisters this instance as an autoloader. + * + * @return void + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + + if (null !== $this->vendorDir) { + unset(self::$registeredLoaders[$this->vendorDir]); + } + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return true|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + includeFile($file); + + return true; + } + + return null; + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { + return false; + } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if (false === $file && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { + // Remember that this class does not exist. + $this->missingClasses[$class] = true; + } + + return $file; + } + + /** + * Returns the currently registered loaders indexed by their corresponding vendor directories. + * + * @return self[] + */ + public static function getRegisteredLoaders() + { + return self::$registeredLoaders; + } + + /** + * @param string $class + * @param string $ext + * @return string|false + */ + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath . '\\'; + if (isset($this->prefixDirsPsr4[$search])) { + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); + foreach ($this->prefixDirsPsr4[$search] as $dir) { + if (file_exists($file = $dir . $pathEnd)) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + + return false; + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + * + * @param string $file + * @return void + * @private + */ +function includeFile($file) +{ + include $file; +} diff --git a/serendipity_event_podcast/player/composer/InstalledVersions.php b/serendipity_event_podcast/player/composer/InstalledVersions.php new file mode 100644 index 00000000..c6b54af7 --- /dev/null +++ b/serendipity_event_podcast/player/composer/InstalledVersions.php @@ -0,0 +1,352 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer; + +use Composer\Autoload\ClassLoader; +use Composer\Semver\VersionParser; + +/** + * This class is copied in every Composer installed project and available to all + * + * See also https://getcomposer.org/doc/07-runtime.md#installed-versions + * + * To require its presence, you can require `composer-runtime-api ^2.0` + * + * @final + */ +class InstalledVersions +{ + /** + * @var mixed[]|null + * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array}|array{}|null + */ + private static $installed; + + /** + * @var bool|null + */ + private static $canGetVendors; + + /** + * @var array[] + * @psalm-var array}> + */ + private static $installedByVendor = array(); + + /** + * Returns a list of all package names which are present, either by being installed, replaced or provided + * + * @return string[] + * @psalm-return list + */ + public static function getInstalledPackages() + { + $packages = array(); + foreach (self::getInstalled() as $installed) { + $packages[] = array_keys($installed['versions']); + } + + if (1 === \count($packages)) { + return $packages[0]; + } + + return array_keys(array_flip(\call_user_func_array('array_merge', $packages))); + } + + /** + * Returns a list of all package names with a specific type e.g. 'library' + * + * @param string $type + * @return string[] + * @psalm-return list + */ + public static function getInstalledPackagesByType($type) + { + $packagesByType = array(); + + foreach (self::getInstalled() as $installed) { + foreach ($installed['versions'] as $name => $package) { + if (isset($package['type']) && $package['type'] === $type) { + $packagesByType[] = $name; + } + } + } + + return $packagesByType; + } + + /** + * Checks whether the given package is installed + * + * This also returns true if the package name is provided or replaced by another package + * + * @param string $packageName + * @param bool $includeDevRequirements + * @return bool + */ + public static function isInstalled($packageName, $includeDevRequirements = true) + { + foreach (self::getInstalled() as $installed) { + if (isset($installed['versions'][$packageName])) { + return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']); + } + } + + return false; + } + + /** + * Checks whether the given package satisfies a version constraint + * + * e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call: + * + * Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3') + * + * @param VersionParser $parser Install composer/semver to have access to this class and functionality + * @param string $packageName + * @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package + * @return bool + */ + public static function satisfies(VersionParser $parser, $packageName, $constraint) + { + $constraint = $parser->parseConstraints($constraint); + $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); + + return $provided->matches($constraint); + } + + /** + * Returns a version constraint representing all the range(s) which are installed for a given package + * + * It is easier to use this via isInstalled() with the $constraint argument if you need to check + * whether a given version of a package is installed, and not just whether it exists + * + * @param string $packageName + * @return string Version constraint usable with composer/semver + */ + public static function getVersionRanges($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + $ranges = array(); + if (isset($installed['versions'][$packageName]['pretty_version'])) { + $ranges[] = $installed['versions'][$packageName]['pretty_version']; + } + if (array_key_exists('aliases', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']); + } + if (array_key_exists('replaced', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']); + } + if (array_key_exists('provided', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']); + } + + return implode(' || ', $ranges); + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present + */ + public static function getVersion($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['version'])) { + return null; + } + + return $installed['versions'][$packageName]['version']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present + */ + public static function getPrettyVersion($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['pretty_version'])) { + return null; + } + + return $installed['versions'][$packageName]['pretty_version']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference + */ + public static function getReference($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['reference'])) { + return null; + } + + return $installed['versions'][$packageName]['reference']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path. + */ + public static function getInstallPath($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @return array + * @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool} + */ + public static function getRootPackage() + { + $installed = self::getInstalled(); + + return $installed[0]['root']; + } + + /** + * Returns the raw installed.php data for custom implementations + * + * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect. + * @return array[] + * @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} + */ + public static function getRawData() + { + @trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED); + + if (null === self::$installed) { + // only require the installed.php file if this file is loaded from its dumped location, + // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 + if (substr(__DIR__, -8, 1) !== 'C') { + self::$installed = include __DIR__ . '/installed.php'; + } else { + self::$installed = array(); + } + } + + return self::$installed; + } + + /** + * Returns the raw data of all installed.php which are currently loaded for custom implementations + * + * @return array[] + * @psalm-return list}> + */ + public static function getAllRawData() + { + return self::getInstalled(); + } + + /** + * Lets you reload the static array from another file + * + * This is only useful for complex integrations in which a project needs to use + * this class but then also needs to execute another project's autoloader in process, + * and wants to ensure both projects have access to their version of installed.php. + * + * A typical case would be PHPUnit, where it would need to make sure it reads all + * the data it needs from this class, then call reload() with + * `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure + * the project in which it runs can then also use this class safely, without + * interference between PHPUnit's dependencies and the project's dependencies. + * + * @param array[] $data A vendor/composer/installed.php data set + * @return void + * + * @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $data + */ + public static function reload($data) + { + self::$installed = $data; + self::$installedByVendor = array(); + } + + /** + * @return array[] + * @psalm-return list}> + */ + private static function getInstalled() + { + if (null === self::$canGetVendors) { + self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders'); + } + + $installed = array(); + + if (self::$canGetVendors) { + foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { + if (isset(self::$installedByVendor[$vendorDir])) { + $installed[] = self::$installedByVendor[$vendorDir]; + } elseif (is_file($vendorDir.'/composer/installed.php')) { + $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php'; + if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { + self::$installed = $installed[count($installed) - 1]; + } + } + } + } + + if (null === self::$installed) { + // only require the installed.php file if this file is loaded from its dumped location, + // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 + if (substr(__DIR__, -8, 1) !== 'C') { + self::$installed = require __DIR__ . '/installed.php'; + } else { + self::$installed = array(); + } + } + $installed[] = self::$installed; + + return $installed; + } +} diff --git a/serendipity_event_podcast/player/composer/LICENSE b/serendipity_event_podcast/player/composer/LICENSE new file mode 100644 index 00000000..f27399a0 --- /dev/null +++ b/serendipity_event_podcast/player/composer/LICENSE @@ -0,0 +1,21 @@ + +Copyright (c) Nils Adermann, Jordi Boggiano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/serendipity_event_podcast/player/composer/autoload_classmap.php b/serendipity_event_podcast/player/composer/autoload_classmap.php new file mode 100644 index 00000000..4f4fddb9 --- /dev/null +++ b/serendipity_event_podcast/player/composer/autoload_classmap.php @@ -0,0 +1,98 @@ + $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.flv.php', + 'AMFStream' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.flv.php', + 'AVCSequenceParameterSetReader' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.flv.php', + 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', + 'Image_XMP' => $vendorDir . '/james-heinrich/getid3/getid3/module.tag.xmp.php', + 'getID3' => $vendorDir . '/james-heinrich/getid3/getid3/getid3.php', + 'getID3_cached_dbm' => $vendorDir . '/james-heinrich/getid3/getid3/extension.cache.dbm.php', + 'getID3_cached_mysql' => $vendorDir . '/james-heinrich/getid3/getid3/extension.cache.mysql.php', + 'getID3_cached_mysqli' => $vendorDir . '/james-heinrich/getid3/getid3/extension.cache.mysqli.php', + 'getID3_cached_sqlite3' => $vendorDir . '/james-heinrich/getid3/getid3/extension.cache.sqlite3.php', + 'getid3_aa' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.aa.php', + 'getid3_aac' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.aac.php', + 'getid3_ac3' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.ac3.php', + 'getid3_amr' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.amr.php', + 'getid3_apetag' => $vendorDir . '/james-heinrich/getid3/getid3/module.tag.apetag.php', + 'getid3_asf' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.asf.php', + 'getid3_au' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.au.php', + 'getid3_avr' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.avr.php', + 'getid3_bink' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.bink.php', + 'getid3_bmp' => $vendorDir . '/james-heinrich/getid3/getid3/module.graphic.bmp.php', + 'getid3_bonk' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.bonk.php', + 'getid3_cue' => $vendorDir . '/james-heinrich/getid3/getid3/module.misc.cue.php', + 'getid3_dsdiff' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.dsdiff.php', + 'getid3_dsf' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.dsf.php', + 'getid3_dss' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.dss.php', + 'getid3_dts' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.dts.php', + 'getid3_efax' => $vendorDir . '/james-heinrich/getid3/getid3/module.graphic.efax.php', + 'getid3_exception' => $vendorDir . '/james-heinrich/getid3/getid3/getid3.php', + 'getid3_exe' => $vendorDir . '/james-heinrich/getid3/getid3/module.misc.exe.php', + 'getid3_flac' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.flac.php', + 'getid3_flv' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.flv.php', + 'getid3_gif' => $vendorDir . '/james-heinrich/getid3/getid3/module.graphic.gif.php', + 'getid3_gzip' => $vendorDir . '/james-heinrich/getid3/getid3/module.archive.gzip.php', + 'getid3_handler' => $vendorDir . '/james-heinrich/getid3/getid3/getid3.php', + 'getid3_hpk' => $vendorDir . '/james-heinrich/getid3/getid3/module.archive.hpk.php', + 'getid3_id3v1' => $vendorDir . '/james-heinrich/getid3/getid3/module.tag.id3v1.php', + 'getid3_id3v2' => $vendorDir . '/james-heinrich/getid3/getid3/module.tag.id3v2.php', + 'getid3_iso' => $vendorDir . '/james-heinrich/getid3/getid3/module.misc.iso.php', + 'getid3_ivf' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.ivf.php', + 'getid3_jpg' => $vendorDir . '/james-heinrich/getid3/getid3/module.graphic.jpg.php', + 'getid3_la' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.la.php', + 'getid3_lib' => $vendorDir . '/james-heinrich/getid3/getid3/getid3.lib.php', + 'getid3_lpac' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.lpac.php', + 'getid3_lyrics3' => $vendorDir . '/james-heinrich/getid3/getid3/module.tag.lyrics3.php', + 'getid3_matroska' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.matroska.php', + 'getid3_midi' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.midi.php', + 'getid3_mod' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.mod.php', + 'getid3_monkey' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.monkey.php', + 'getid3_mp3' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.mp3.php', + 'getid3_mpc' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.mpc.php', + 'getid3_mpeg' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.mpeg.php', + 'getid3_msoffice' => $vendorDir . '/james-heinrich/getid3/getid3/module.misc.msoffice.php', + 'getid3_nsv' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.nsv.php', + 'getid3_ogg' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.ogg.php', + 'getid3_optimfrog' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.optimfrog.php', + 'getid3_par2' => $vendorDir . '/james-heinrich/getid3/getid3/module.misc.par2.php', + 'getid3_pcd' => $vendorDir . '/james-heinrich/getid3/getid3/module.graphic.pcd.php', + 'getid3_pdf' => $vendorDir . '/james-heinrich/getid3/getid3/module.misc.pdf.php', + 'getid3_png' => $vendorDir . '/james-heinrich/getid3/getid3/module.graphic.png.php', + 'getid3_quicktime' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.quicktime.php', + 'getid3_rar' => $vendorDir . '/james-heinrich/getid3/getid3/module.archive.rar.php', + 'getid3_real' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.real.php', + 'getid3_riff' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.riff.php', + 'getid3_rkau' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.rkau.php', + 'getid3_shorten' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.shorten.php', + 'getid3_svg' => $vendorDir . '/james-heinrich/getid3/getid3/module.graphic.svg.php', + 'getid3_swf' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.swf.php', + 'getid3_szip' => $vendorDir . '/james-heinrich/getid3/getid3/module.archive.szip.php', + 'getid3_tag_nikon_nctg' => $vendorDir . '/james-heinrich/getid3/getid3/module.tag.nikon-nctg.php', + 'getid3_tak' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.tak.php', + 'getid3_tar' => $vendorDir . '/james-heinrich/getid3/getid3/module.archive.tar.php', + 'getid3_tiff' => $vendorDir . '/james-heinrich/getid3/getid3/module.graphic.tiff.php', + 'getid3_torrent' => $vendorDir . '/james-heinrich/getid3/getid3/module.misc.torrent.php', + 'getid3_ts' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.ts.php', + 'getid3_tta' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.tta.php', + 'getid3_voc' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.voc.php', + 'getid3_vqf' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.vqf.php', + 'getid3_wavpack' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio.wavpack.php', + 'getid3_write_apetag' => $vendorDir . '/james-heinrich/getid3/getid3/write.apetag.php', + 'getid3_write_id3v1' => $vendorDir . '/james-heinrich/getid3/getid3/write.id3v1.php', + 'getid3_write_id3v2' => $vendorDir . '/james-heinrich/getid3/getid3/write.id3v2.php', + 'getid3_write_lyrics3' => $vendorDir . '/james-heinrich/getid3/getid3/write.lyrics3.php', + 'getid3_write_metaflac' => $vendorDir . '/james-heinrich/getid3/getid3/write.metaflac.php', + 'getid3_write_real' => $vendorDir . '/james-heinrich/getid3/getid3/write.real.php', + 'getid3_write_vorbiscomment' => $vendorDir . '/james-heinrich/getid3/getid3/write.vorbiscomment.php', + 'getid3_writetags' => $vendorDir . '/james-heinrich/getid3/getid3/write.php', + 'getid3_wtv' => $vendorDir . '/james-heinrich/getid3/getid3/module.audio-video.wtv.php', + 'getid3_xz' => $vendorDir . '/james-heinrich/getid3/getid3/module.archive.xz.php', + 'getid3_zip' => $vendorDir . '/james-heinrich/getid3/getid3/module.archive.zip.php', +); diff --git a/serendipity_event_podcast/player/composer/autoload_namespaces.php b/serendipity_event_podcast/player/composer/autoload_namespaces.php new file mode 100644 index 00000000..15a2ff3a --- /dev/null +++ b/serendipity_event_podcast/player/composer/autoload_namespaces.php @@ -0,0 +1,9 @@ +register(true); + + return $loader; + } +} diff --git a/serendipity_event_podcast/player/composer/autoload_static.php b/serendipity_event_podcast/player/composer/autoload_static.php new file mode 100644 index 00000000..42aa9a0d --- /dev/null +++ b/serendipity_event_podcast/player/composer/autoload_static.php @@ -0,0 +1,108 @@ + __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.flv.php', + 'AMFStream' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.flv.php', + 'AVCSequenceParameterSetReader' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.flv.php', + 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', + 'Image_XMP' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.tag.xmp.php', + 'getID3' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/getid3.php', + 'getID3_cached_dbm' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/extension.cache.dbm.php', + 'getID3_cached_mysql' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/extension.cache.mysql.php', + 'getID3_cached_mysqli' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/extension.cache.mysqli.php', + 'getID3_cached_sqlite3' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/extension.cache.sqlite3.php', + 'getid3_aa' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.aa.php', + 'getid3_aac' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.aac.php', + 'getid3_ac3' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.ac3.php', + 'getid3_amr' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.amr.php', + 'getid3_apetag' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.tag.apetag.php', + 'getid3_asf' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.asf.php', + 'getid3_au' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.au.php', + 'getid3_avr' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.avr.php', + 'getid3_bink' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.bink.php', + 'getid3_bmp' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.graphic.bmp.php', + 'getid3_bonk' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.bonk.php', + 'getid3_cue' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.misc.cue.php', + 'getid3_dsdiff' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.dsdiff.php', + 'getid3_dsf' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.dsf.php', + 'getid3_dss' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.dss.php', + 'getid3_dts' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.dts.php', + 'getid3_efax' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.graphic.efax.php', + 'getid3_exception' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/getid3.php', + 'getid3_exe' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.misc.exe.php', + 'getid3_flac' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.flac.php', + 'getid3_flv' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.flv.php', + 'getid3_gif' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.graphic.gif.php', + 'getid3_gzip' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.archive.gzip.php', + 'getid3_handler' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/getid3.php', + 'getid3_hpk' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.archive.hpk.php', + 'getid3_id3v1' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.tag.id3v1.php', + 'getid3_id3v2' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.tag.id3v2.php', + 'getid3_iso' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.misc.iso.php', + 'getid3_ivf' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.ivf.php', + 'getid3_jpg' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.graphic.jpg.php', + 'getid3_la' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.la.php', + 'getid3_lib' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/getid3.lib.php', + 'getid3_lpac' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.lpac.php', + 'getid3_lyrics3' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.tag.lyrics3.php', + 'getid3_matroska' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.matroska.php', + 'getid3_midi' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.midi.php', + 'getid3_mod' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.mod.php', + 'getid3_monkey' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.monkey.php', + 'getid3_mp3' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.mp3.php', + 'getid3_mpc' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.mpc.php', + 'getid3_mpeg' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.mpeg.php', + 'getid3_msoffice' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.misc.msoffice.php', + 'getid3_nsv' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.nsv.php', + 'getid3_ogg' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.ogg.php', + 'getid3_optimfrog' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.optimfrog.php', + 'getid3_par2' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.misc.par2.php', + 'getid3_pcd' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.graphic.pcd.php', + 'getid3_pdf' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.misc.pdf.php', + 'getid3_png' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.graphic.png.php', + 'getid3_quicktime' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.quicktime.php', + 'getid3_rar' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.archive.rar.php', + 'getid3_real' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.real.php', + 'getid3_riff' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.riff.php', + 'getid3_rkau' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.rkau.php', + 'getid3_shorten' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.shorten.php', + 'getid3_svg' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.graphic.svg.php', + 'getid3_swf' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.swf.php', + 'getid3_szip' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.archive.szip.php', + 'getid3_tag_nikon_nctg' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.tag.nikon-nctg.php', + 'getid3_tak' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.tak.php', + 'getid3_tar' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.archive.tar.php', + 'getid3_tiff' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.graphic.tiff.php', + 'getid3_torrent' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.misc.torrent.php', + 'getid3_ts' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.ts.php', + 'getid3_tta' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.tta.php', + 'getid3_voc' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.voc.php', + 'getid3_vqf' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.vqf.php', + 'getid3_wavpack' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio.wavpack.php', + 'getid3_write_apetag' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/write.apetag.php', + 'getid3_write_id3v1' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/write.id3v1.php', + 'getid3_write_id3v2' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/write.id3v2.php', + 'getid3_write_lyrics3' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/write.lyrics3.php', + 'getid3_write_metaflac' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/write.metaflac.php', + 'getid3_write_real' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/write.real.php', + 'getid3_write_vorbiscomment' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/write.vorbiscomment.php', + 'getid3_writetags' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/write.php', + 'getid3_wtv' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.audio-video.wtv.php', + 'getid3_xz' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.archive.xz.php', + 'getid3_zip' => __DIR__ . '/..' . '/james-heinrich/getid3/getid3/module.archive.zip.php', + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->classMap = ComposerStaticInit295fe9b55080d50c65b251f903ebe7f9::$classMap; + + }, null, ClassLoader::class); + } +} diff --git a/serendipity_event_podcast/player/composer/installed.json b/serendipity_event_podcast/player/composer/installed.json new file mode 100644 index 00000000..5e0ce79a --- /dev/null +++ b/serendipity_event_podcast/player/composer/installed.json @@ -0,0 +1,76 @@ +{ + "packages": [ + { + "name": "james-heinrich/getid3", + "version": "v1.9.22", + "version_normalized": "1.9.22.0", + "source": { + "type": "git", + "url": "https://github.com/JamesHeinrich/getID3.git", + "reference": "45f20faa0f0a24489740392c5b512ddcc36deccd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/JamesHeinrich/getID3/zipball/45f20faa0f0a24489740392c5b512ddcc36deccd", + "reference": "45f20faa0f0a24489740392c5b512ddcc36deccd", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.0" + }, + "suggest": { + "ext-SimpleXML": "SimpleXML extension is required to analyze RIFF/WAV/BWF audio files (also requires `ext-libxml`).", + "ext-com_dotnet": "COM extension is required when loading files larger than 2GB on Windows.", + "ext-ctype": "ctype extension is required when loading files larger than 2GB on 32-bit PHP (also on 64-bit PHP on Windows) or executing `getid3_lib::CopyTagsToComments`.", + "ext-dba": "DBA extension is required to use the DBA database as a cache storage.", + "ext-exif": "EXIF extension is required for graphic modules.", + "ext-iconv": "iconv extension is required to work with different character sets (when `ext-mbstring` is not available).", + "ext-json": "JSON extension is required to analyze Apple Quicktime videos.", + "ext-libxml": "libxml extension is required to analyze RIFF/WAV/BWF audio files.", + "ext-mbstring": "mbstring extension is required to work with different character sets.", + "ext-mysql": "MySQL extension is required to use the MySQL database as a cache storage (deprecated in PHP 5.5, removed in PHP >= 7.0, use `ext-mysqli` instead).", + "ext-mysqli": "MySQLi extension is required to use the MySQL database as a cache storage.", + "ext-rar": "RAR extension is required for RAR archive module.", + "ext-sqlite3": "SQLite3 extension is required to use the SQLite3 database as a cache storage.", + "ext-xml": "XML extension is required for graphic modules to analyze the XML metadata.", + "ext-zlib": "Zlib extension is required for archive modules and compressed metadata." + }, + "time": "2022-09-29T16:41:13+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "classmap": [ + "getid3/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-1.0-or-later", + "LGPL-3.0-only", + "MPL-2.0" + ], + "description": "PHP script that extracts useful information from popular multimedia file formats", + "homepage": "https://www.getid3.org/", + "keywords": [ + "codecs", + "php", + "tags" + ], + "support": { + "issues": "https://github.com/JamesHeinrich/getID3/issues", + "source": "https://github.com/JamesHeinrich/getID3/tree/v1.9.22" + }, + "install-path": "../james-heinrich/getid3" + } + ], + "dev": true, + "dev-package-names": [] +} diff --git a/serendipity_event_podcast/player/composer/installed.php b/serendipity_event_podcast/player/composer/installed.php new file mode 100644 index 00000000..2d3d9f02 --- /dev/null +++ b/serendipity_event_podcast/player/composer/installed.php @@ -0,0 +1,32 @@ + array( + 'name' => '__root__', + 'pretty_version' => '1.0.0+no-version-set', + 'version' => '1.0.0.0', + 'reference' => NULL, + 'type' => 'library', + 'install_path' => __DIR__ . '/../../', + 'aliases' => array(), + 'dev' => true, + ), + 'versions' => array( + '__root__' => array( + 'pretty_version' => '1.0.0+no-version-set', + 'version' => '1.0.0.0', + 'reference' => NULL, + 'type' => 'library', + 'install_path' => __DIR__ . '/../../', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'james-heinrich/getid3' => array( + 'pretty_version' => 'v1.9.22', + 'version' => '1.9.22.0', + 'reference' => '45f20faa0f0a24489740392c5b512ddcc36deccd', + 'type' => 'library', + 'install_path' => __DIR__ . '/../james-heinrich/getid3', + 'aliases' => array(), + 'dev_requirement' => false, + ), + ), +); diff --git a/serendipity_event_podcast/player/composer/platform_check.php b/serendipity_event_podcast/player/composer/platform_check.php new file mode 100644 index 00000000..7621d4ff --- /dev/null +++ b/serendipity_event_podcast/player/composer/platform_check.php @@ -0,0 +1,26 @@ += 50300)) { + $issues[] = 'Your Composer dependencies require a PHP version ">= 5.3.0". You are running ' . PHP_VERSION . '.'; +} + +if ($issues) { + if (!headers_sent()) { + header('HTTP/1.1 500 Internal Server Error'); + } + if (!ini_get('display_errors')) { + if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { + fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL); + } elseif (!headers_sent()) { + echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL; + } + } + trigger_error( + 'Composer detected issues in your platform: ' . implode(' ', $issues), + E_USER_ERROR + ); +} diff --git a/serendipity_event_podcast/player/getid3/extension.cache.mysql.php b/serendipity_event_podcast/player/getid3/extension.cache.mysql.php deleted file mode 100644 index e070d838..00000000 --- a/serendipity_event_podcast/player/getid3/extension.cache.mysql.php +++ /dev/null @@ -1,170 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// // -// extension.cache.mysql.php - part of getID3() // -// Please see readme.txt for more information // -// /// -///////////////////////////////////////////////////////////////// -// // -// This extension written by Allan Hansen // -// /// -///////////////////////////////////////////////////////////////// - - -/** -* This is a caching extension for getID3(). It works the exact same -* way as the getID3 class, but return cached information very fast -* -* Example: (see also demo.cache.mysql.php in /demo/) -* -* Normal getID3 usage (example): -* -* require_once 'getid3/getid3.php'; -* $getID3 = new getID3; -* $getID3->encoding = 'UTF-8'; -* $info1 = $getID3->analyze('file1.flac'); -* $info2 = $getID3->analyze('file2.wv'); -* -* getID3_cached usage: -* -* require_once 'getid3/getid3.php'; -* require_once 'getid3/getid3/extension.cache.mysql.php'; -* $getID3 = new getID3_cached_mysql('localhost', 'database', -* 'username', 'password'); -* $getID3->encoding = 'UTF-8'; -* $info1 = $getID3->analyze('file1.flac'); -* $info2 = $getID3->analyze('file2.wv'); -* -* -* Supported Cache Types (this extension) -* -* SQL Databases: -* -* cache_type cache_options -* ------------------------------------------------------------------- -* mysql host, database, username, password -* -* -* DBM-Style Databases: (use extension.cache.dbm) -* -* cache_type cache_options -* ------------------------------------------------------------------- -* gdbm dbm_filename, lock_filename -* ndbm dbm_filename, lock_filename -* db2 dbm_filename, lock_filename -* db3 dbm_filename, lock_filename -* db4 dbm_filename, lock_filename (PHP5 required) -* -* PHP must have write access to both dbm_filename and lock_filename. -* -* -* Recommended Cache Types -* -* Infrequent updates, many reads any DBM -* Frequent updates mysql -*/ - - -class getID3_cached_mysql extends getID3 -{ - - // private vars - var $cursor; - var $connection; - - - // public: constructor - see top of this file for cache type and cache_options - function getID3_cached_mysql($host, $database, $username, $password) { - - // Check for mysql support - if (!function_exists('mysql_pconnect')) { - throw new Exception('PHP not compiled with mysql support.'); - } - - // Connect to database - $this->connection = mysql_pconnect($host, $username, $password); - if (!$this->connection) { - throw new Exception('mysql_pconnect() failed - check permissions and spelling.'); - } - - // Select database - if (!mysql_select_db($database, $this->connection)) { - throw new Exception('Cannot use database '.$database); - } - - // Create cache table if not exists - $this->create_table(); - - // Check version number and clear cache if changed - $version = ''; - if ($this->cursor = mysql_query("SELECT `value` FROM `getid3_cache` WHERE (`filename` = '".mysql_real_escape_string(GETID3_VERSION)."') AND (`filesize` = '-1') AND (`filetime` = '-1') AND (`analyzetime` = '-1')", $this->connection)) { - list($version) = mysql_fetch_array($this->cursor); - } - if ($version != GETID3_VERSION) { - $this->clear_cache(); - } - - parent::getID3(); - } - - - - // public: clear cache - function clear_cache() { - - $this->cursor = mysql_query("DELETE FROM `getid3_cache`", $this->connection); - $this->cursor = mysql_query("INSERT INTO `getid3_cache` VALUES ('".GETID3_VERSION."', -1, -1, -1, '".GETID3_VERSION."')", $this->connection); - } - - - - // public: analyze file - function analyze($filename) { - - if (file_exists($filename)) { - - // Short-hands - $filetime = filemtime($filename); - $filesize = filesize($filename); - - // Loopup file - $result = ''; - if ($this->cursor = mysql_query("SELECT `value` FROM `getid3_cache` WHERE (`filename` = '".mysql_real_escape_string($filename)."') AND (`filesize` = '".mysql_real_escape_string($filesize)."') AND (`filetime` = '".mysql_real_escape_string($filetime)."')", $this->connection)) { - // Hit - list($result) = mysql_fetch_array($this->cursor); - return unserialize(base64_decode($result)); - } - } - - // Miss - $analysis = parent::analyze($filename); - - // Save result - if (file_exists($filename)) { - $this->cursor = mysql_query("INSERT INTO `getid3_cache` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES ('".mysql_real_escape_string($filename)."', '".mysql_real_escape_string($filesize)."', '".mysql_real_escape_string($filetime)."', '".mysql_real_escape_string(time())."', '".mysql_real_escape_string(base64_encode(serialize($analysis)))."')", $this->connection); - } - return $result; - } - - - - // private: (re)create sql table - function create_table($drop=false) { - - $this->cursor = mysql_query("CREATE TABLE IF NOT EXISTS `getid3_cache` ( - `filename` VARCHAR(255) NOT NULL DEFAULT '', - `filesize` INT(11) NOT NULL DEFAULT '0', - `filetime` INT(11) NOT NULL DEFAULT '0', - `analyzetime` INT(11) NOT NULL DEFAULT '0', - `value` TEXT NOT NULL, - PRIMARY KEY (`filename`,`filesize`,`filetime`)) TYPE=MyISAM", $this->connection); - echo mysql_error($this->connection); - } -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/getid3.lib.php b/serendipity_event_podcast/player/getid3/getid3.lib.php deleted file mode 100644 index c64df0bd..00000000 --- a/serendipity_event_podcast/player/getid3/getid3.lib.php +++ /dev/null @@ -1,1262 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// // -// getid3.lib.php - part of getID3() // -// See readme.txt for more details // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_lib -{ - - static function PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true) { - $returnstring = ''; - for ($i = 0; $i < strlen($string); $i++) { - if ($hex) { - $returnstring .= str_pad(dechex(ord($string{$i})), 2, '0', STR_PAD_LEFT); - } else { - $returnstring .= ' '.(preg_match("#[\x20-\x7E]#", $string{$i}) ? $string{$i} : '¤'); - } - if ($spaces) { - $returnstring .= ' '; - } - } - if ($htmlsafe) { - $returnstring = htmlentities($returnstring, ENT_COMPAT, LANG_CHARSET); - } - return $returnstring; - } - - static function trunc($floatnumber) { - // truncates a floating-point number at the decimal point - // returns int (if possible, otherwise float) - if ($floatnumber >= 1) { - $truncatednumber = floor($floatnumber); - } elseif ($floatnumber <= -1) { - $truncatednumber = ceil($floatnumber); - } else { - $truncatednumber = 0; - } - if (getid3_lib::intValueSupported($truncatednumber)) { - $truncatednumber = (int) $truncatednumber; - } - return $truncatednumber; - } - - - static function safe_inc(&$variable, $increment=1) { - if (isset($variable)) { - $variable += $increment; - } else { - $variable = $increment; - } - return true; - } - - static function CastAsInt($floatnum) { - // convert to float if not already - $floatnum = (float) $floatnum; - - // convert a float to type int, only if possible - if (getid3_lib::trunc($floatnum) == $floatnum) { - // it's not floating point - if (getid3_lib::intValueSupported($floatnum)) { - // it's within int range - $floatnum = (int) $floatnum; - } - } - return $floatnum; - } - - public static function intValueSupported($num) { - // check if integers are 64-bit - static $hasINT64 = null; - if ($hasINT64 === null) { // 10x faster than is_null() - $hasINT64 = is_int(pow(2, 31)); // 32-bit int are limited to (2^31)-1 - if (!$hasINT64 && !defined('PHP_INT_MIN')) { - define('PHP_INT_MIN', ~PHP_INT_MAX); - } - } - // if integers are 64-bit - no other check required - if ($hasINT64 || (($num <= PHP_INT_MAX) && ($num >= PHP_INT_MIN))) { - return true; - } - return false; - } - - static function DecimalizeFraction($fraction) { - list($numerator, $denominator) = explode('/', $fraction); - return $numerator / ($denominator ? $denominator : 1); - } - - - static function DecimalBinary2Float($binarynumerator) { - $numerator = getid3_lib::Bin2Dec($binarynumerator); - $denominator = getid3_lib::Bin2Dec('1'.str_repeat('0', strlen($binarynumerator))); - return ($numerator / $denominator); - } - - - static function NormalizeBinaryPoint($binarypointnumber, $maxbits=52) { - // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html - if (strpos($binarypointnumber, '.') === false) { - $binarypointnumber = '0.'.$binarypointnumber; - } elseif ($binarypointnumber{0} == '.') { - $binarypointnumber = '0'.$binarypointnumber; - } - $exponent = 0; - while (($binarypointnumber{0} != '1') || (substr($binarypointnumber, 1, 1) != '.')) { - if (substr($binarypointnumber, 1, 1) == '.') { - $exponent--; - $binarypointnumber = substr($binarypointnumber, 2, 1).'.'.substr($binarypointnumber, 3); - } else { - $pointpos = strpos($binarypointnumber, '.'); - $exponent += ($pointpos - 1); - $binarypointnumber = str_replace('.', '', $binarypointnumber); - $binarypointnumber = $binarypointnumber{0}.'.'.substr($binarypointnumber, 1); - } - } - $binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2, '0', STR_PAD_RIGHT); - return array('normalized'=>$binarypointnumber, 'exponent'=>(int) $exponent); - } - - - static function Float2BinaryDecimal($floatvalue) { - // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html - $maxbits = 128; // to how many bits of precision should the calculations be taken? - $intpart = getid3_lib::trunc($floatvalue); - $floatpart = abs($floatvalue - $intpart); - $pointbitstring = ''; - while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits)) { - $floatpart *= 2; - $pointbitstring .= (string) getid3_lib::trunc($floatpart); - $floatpart -= getid3_lib::trunc($floatpart); - } - $binarypointnumber = decbin($intpart).'.'.$pointbitstring; - return $binarypointnumber; - } - - - static function Float2String($floatvalue, $bits) { - // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html - switch ($bits) { - case 32: - $exponentbits = 8; - $fractionbits = 23; - break; - - case 64: - $exponentbits = 11; - $fractionbits = 52; - break; - - default: - return false; - break; - } - if ($floatvalue >= 0) { - $signbit = '0'; - } else { - $signbit = '1'; - } - $normalizedbinary = getid3_lib::NormalizeBinaryPoint(getid3_lib::Float2BinaryDecimal($floatvalue), $fractionbits); - $biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary['exponent']; // (127 or 1023) +/- exponent - $exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits, '0', STR_PAD_LEFT); - $fractionbitstring = str_pad(substr($normalizedbinary['normalized'], 2), $fractionbits, '0', STR_PAD_RIGHT); - - return getid3_lib::BigEndian2String(getid3_lib::Bin2Dec($signbit.$exponentbitstring.$fractionbitstring), $bits % 8, false); - } - - - static function LittleEndian2Float($byteword) { - return getid3_lib::BigEndian2Float(strrev($byteword)); - } - - - static function BigEndian2Float($byteword) { - // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic - // http://www.psc.edu/general/software/packages/ieee/ieee.html - // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html - - $bitword = getid3_lib::BigEndian2Bin($byteword); - if (!$bitword) { - return 0; - } - $signbit = $bitword{0}; - - switch (strlen($byteword) * 8) { - case 32: - $exponentbits = 8; - $fractionbits = 23; - break; - - case 64: - $exponentbits = 11; - $fractionbits = 52; - break; - - case 80: - // 80-bit Apple SANE format - // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/ - $exponentstring = substr($bitword, 1, 15); - $isnormalized = intval($bitword{16}); - $fractionstring = substr($bitword, 17, 63); - $exponent = pow(2, getid3_lib::Bin2Dec($exponentstring) - 16383); - $fraction = $isnormalized + getid3_lib::DecimalBinary2Float($fractionstring); - $floatvalue = $exponent * $fraction; - if ($signbit == '1') { - $floatvalue *= -1; - } - return $floatvalue; - break; - - default: - return false; - break; - } - $exponentstring = substr($bitword, 1, $exponentbits); - $fractionstring = substr($bitword, $exponentbits + 1, $fractionbits); - $exponent = getid3_lib::Bin2Dec($exponentstring); - $fraction = getid3_lib::Bin2Dec($fractionstring); - - if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) { - // Not a Number - $floatvalue = false; - } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) { - if ($signbit == '1') { - $floatvalue = '-infinity'; - } else { - $floatvalue = '+infinity'; - } - } elseif (($exponent == 0) && ($fraction == 0)) { - if ($signbit == '1') { - $floatvalue = -0; - } else { - $floatvalue = 0; - } - $floatvalue = ($signbit ? 0 : -0); - } elseif (($exponent == 0) && ($fraction != 0)) { - // These are 'unnormalized' values - $floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * getid3_lib::DecimalBinary2Float($fractionstring); - if ($signbit == '1') { - $floatvalue *= -1; - } - } elseif ($exponent != 0) { - $floatvalue = pow(2, ($exponent - (pow(2, $exponentbits - 1) - 1))) * (1 + getid3_lib::DecimalBinary2Float($fractionstring)); - if ($signbit == '1') { - $floatvalue *= -1; - } - } - return (float) $floatvalue; - } - - - static function BigEndian2Int($byteword, $synchsafe=false, $signed=false) { - $intvalue = 0; - $bytewordlen = strlen($byteword); - if ($bytewordlen == 0) { - return false; - } - for ($i = 0; $i < $bytewordlen; $i++) { - if ($synchsafe) { // disregard MSB, effectively 7-bit bytes - $intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7); - } else { - $intvalue += ord($byteword{$i}) * pow(256, ($bytewordlen - 1 - $i)); - } - } - if ($signed && !$synchsafe) { - // synchsafe ints are not allowed to be signed - if ($bytewordlen <= PHP_INT_SIZE) { - $signMaskBit = 0x80 << (8 * ($bytewordlen - 1)); - if ($intvalue & $signMaskBit) { - $intvalue = 0 - ($intvalue & ($signMaskBit - 1)); - } - } else { - throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits ('.strlen($byteword).') in getid3_lib::BigEndian2Int()'); - return false; - } - } - return getid3_lib::CastAsInt($intvalue); - } - - - static function LittleEndian2Int($byteword, $signed=false) { - return getid3_lib::BigEndian2Int(strrev($byteword), false, $signed); - } - - - static function BigEndian2Bin($byteword) { - $binvalue = ''; - $bytewordlen = strlen($byteword); - for ($i = 0; $i < $bytewordlen; $i++) { - $binvalue .= str_pad(decbin(ord($byteword{$i})), 8, '0', STR_PAD_LEFT); - } - return $binvalue; - } - - - static function BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false) { - if ($number < 0) { - throw new Exception('ERROR: getid3_lib::BigEndian2String() does not support negative numbers'); - } - $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF); - $intstring = ''; - if ($signed) { - if ($minbytes > PHP_INT_SIZE) { - throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits in getid3_lib::BigEndian2String()'); - } - $number = $number & (0x80 << (8 * ($minbytes - 1))); - } - while ($number != 0) { - $quotient = ($number / ($maskbyte + 1)); - $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring; - $number = floor($quotient); - } - return str_pad($intstring, $minbytes, "\x00", STR_PAD_LEFT); - } - - - static function Dec2Bin($number) { - while ($number >= 256) { - $bytes[] = (($number / 256) - (floor($number / 256))) * 256; - $number = floor($number / 256); - } - $bytes[] = $number; - $binstring = ''; - for ($i = 0; $i < count($bytes); $i++) { - $binstring = (($i == count($bytes) - 1) ? decbin($bytes[$i]) : str_pad(decbin($bytes[$i]), 8, '0', STR_PAD_LEFT)).$binstring; - } - return $binstring; - } - - - static function Bin2Dec($binstring, $signed=false) { - $signmult = 1; - if ($signed) { - if ($binstring{0} == '1') { - $signmult = -1; - } - $binstring = substr($binstring, 1); - } - $decvalue = 0; - for ($i = 0; $i < strlen($binstring); $i++) { - $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i); - } - return getid3_lib::CastAsInt($decvalue * $signmult); - } - - - static function Bin2String($binstring) { - // return 'hi' for input of '0110100001101001' - $string = ''; - $binstringreversed = strrev($binstring); - for ($i = 0; $i < strlen($binstringreversed); $i += 8) { - $string = chr(getid3_lib::Bin2Dec(strrev(substr($binstringreversed, $i, 8)))).$string; - } - return $string; - } - - - static function LittleEndian2String($number, $minbytes=1, $synchsafe=false) { - $intstring = ''; - while ($number > 0) { - if ($synchsafe) { - $intstring = $intstring.chr($number & 127); - $number >>= 7; - } else { - $intstring = $intstring.chr($number & 255); - $number >>= 8; - } - } - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); - } - - - static function array_merge_clobber($array1, $array2) { - // written by kcØhireability*com - // taken from http://www.php.net/manual/en/function.array-merge-recursive.php - if (!is_array($array1) || !is_array($array2)) { - return false; - } - $newarray = $array1; - foreach ($array2 as $key => $val) { - if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { - $newarray[$key] = getid3_lib::array_merge_clobber($newarray[$key], $val); - } else { - $newarray[$key] = $val; - } - } - return $newarray; - } - - - static function array_merge_noclobber($array1, $array2) { - if (!is_array($array1) || !is_array($array2)) { - return false; - } - $newarray = $array1; - foreach ($array2 as $key => $val) { - if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { - $newarray[$key] = getid3_lib::array_merge_noclobber($newarray[$key], $val); - } elseif (!isset($newarray[$key])) { - $newarray[$key] = $val; - } - } - return $newarray; - } - - - static function fileextension($filename, $numextensions=1) { - if (strstr($filename, '.')) { - $reversedfilename = strrev($filename); - $offset = 0; - for ($i = 0; $i < $numextensions; $i++) { - $offset = strpos($reversedfilename, '.', $offset + 1); - if ($offset === false) { - return ''; - } - } - return strrev(substr($reversedfilename, 0, $offset)); - } - return ''; - } - - - static function PlaytimeString($playtimeseconds) { - $sign = (($playtimeseconds < 0) ? '-' : ''); - $playtimeseconds = abs($playtimeseconds); - $contentseconds = round((($playtimeseconds / 60) - floor($playtimeseconds / 60)) * 60); - $contentminutes = floor($playtimeseconds / 60); - if ($contentseconds >= 60) { - $contentseconds -= 60; - $contentminutes++; - } - return $sign.intval($contentminutes).':'.str_pad($contentseconds, 2, 0, STR_PAD_LEFT); - } - - - static function DateMac2Unix($macdate) { - // Macintosh timestamp: seconds since 00:00h January 1, 1904 - // UNIX timestamp: seconds since 00:00h January 1, 1970 - return getid3_lib::CastAsInt($macdate - 2082844800); - } - - - static function FixedPoint8_8($rawdata) { - return getid3_lib::BigEndian2Int(substr($rawdata, 0, 1)) + (float) (getid3_lib::BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8)); - } - - - static function FixedPoint16_16($rawdata) { - return getid3_lib::BigEndian2Int(substr($rawdata, 0, 2)) + (float) (getid3_lib::BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16)); - } - - - static function FixedPoint2_30($rawdata) { - $binarystring = getid3_lib::BigEndian2Bin($rawdata); - return getid3_lib::Bin2Dec(substr($binarystring, 0, 2)) + (float) (getid3_lib::Bin2Dec(substr($binarystring, 2, 30)) / pow(2, 30)); - } - - - static function CreateDeepArray($ArrayPath, $Separator, $Value) { - // assigns $Value to a nested array path: - // $foo = getid3_lib::CreateDeepArray('/path/to/my', '/', 'file.txt') - // is the same as: - // $foo = array('path'=>array('to'=>'array('my'=>array('file.txt')))); - // or - // $foo['path']['to']['my'] = 'file.txt'; - while ($ArrayPath && ($ArrayPath{0} == $Separator)) { - $ArrayPath = substr($ArrayPath, 1); - } - if (($pos = strpos($ArrayPath, $Separator)) !== false) { - $ReturnedArray[substr($ArrayPath, 0, $pos)] = getid3_lib::CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value); - } else { - $ReturnedArray[$ArrayPath] = $Value; - } - return $ReturnedArray; - } - - static function array_max($arraydata, $returnkey=false) { - $maxvalue = false; - $maxkey = false; - foreach ($arraydata as $key => $value) { - if (!is_array($value)) { - if ($value > $maxvalue) { - $maxvalue = $value; - $maxkey = $key; - } - } - } - return ($returnkey ? $maxkey : $maxvalue); - } - - static function array_min($arraydata, $returnkey=false) { - $minvalue = false; - $minkey = false; - foreach ($arraydata as $key => $value) { - if (!is_array($value)) { - if ($value > $minvalue) { - $minvalue = $value; - $minkey = $key; - } - } - } - return ($returnkey ? $minkey : $minvalue); - } - - - // Allan Hansen - // getid3_lib::md5_data() - returns md5sum for a file from startuing position to absolute end position - static function hash_data($file, $offset, $end, $algorithm) { - if (!getid3_lib::intValueSupported($end)) { - return false; - } - switch ($algorithm) { - case 'md5': - $hash_function = 'md5_file'; - $unix_call = 'md5sum'; - $windows_call = 'md5sum.exe'; - $hash_length = 32; - break; - - case 'sha1': - $hash_function = 'sha1_file'; - $unix_call = 'sha1sum'; - $windows_call = 'sha1sum.exe'; - $hash_length = 40; - break; - - default: - throw new Exception('Invalid algorithm ('.$algorithm.') in getid3_lib::hash_data()'); - break; - } - $size = $end - $offset; - while (true) { - if (GETID3_OS_ISWINDOWS) { - - // It seems that sha1sum.exe for Windows only works on physical files, does not accept piped data - // Fall back to create-temp-file method: - if ($algorithm == 'sha1') { - break; - } - - $RequiredFiles = array('cygwin1.dll', 'head.exe', 'tail.exe', $windows_call); - foreach ($RequiredFiles as $required_file) { - if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) { - // helper apps not available - fall back to old method - break; - } - } - $commandline = GETID3_HELPERAPPSDIR.'head.exe -c '.$end.' "'.escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $file)).'" | '; - $commandline .= GETID3_HELPERAPPSDIR.'tail.exe -c '.$size.' | '; - $commandline .= GETID3_HELPERAPPSDIR.$windows_call; - - } else { - - $commandline = 'head -c'.$end.' '.escapeshellarg($file).' | '; - $commandline .= 'tail -c'.$size.' | '; - $commandline .= $unix_call; - - } - if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { - $ThisFileInfo['warning'][] = 'PHP running in Safe Mode - backtick operator not available, using slower non-system-call '.$algorithm.' algorithm'; - break; - } - return substr(`$commandline`, 0, $hash_length); - } - - // try to create a temporary file in the system temp directory - invalid dirname should force to system temp dir - if (($data_filename = tempnam(GETID3_TEMP_DIR, 'getID3')) === false) { - // can't find anywhere to create a temp file, just die - return false; - } - - // Init - $result = false; - - // copy parts of file - ob_start(); - if ($fp = fopen($file, 'rb')) { - ob_end_clean(); - ob_start(); - if ($fp_data = fopen($data_filename, 'wb')) { - fseek($fp, $offset, SEEK_SET); - $byteslefttowrite = $end - $offset; - while (($byteslefttowrite > 0) && ($buffer = fread($fp, GETID3_FREAD_BUFFER_SIZE))) { - $byteswritten = fwrite($fp_data, $buffer, $byteslefttowrite); - $byteslefttowrite -= $byteswritten; - } - fclose($fp_data); - $result = $hash_function($data_filename); - } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - } - fclose($fp); - } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - } - unlink($data_filename); - return $result; - } - - - static function iconv_fallback_int_utf8($charval) { - if ($charval < 128) { - // 0bbbbbbb - $newcharstring = chr($charval); - } elseif ($charval < 2048) { - // 110bbbbb 10bbbbbb - $newcharstring = chr(($charval >> 6) | 0xC0); - $newcharstring .= chr(($charval & 0x3F) | 0x80); - } elseif ($charval < 65536) { - // 1110bbbb 10bbbbbb 10bbbbbb - $newcharstring = chr(($charval >> 12) | 0xE0); - $newcharstring .= chr(($charval >> 6) | 0xC0); - $newcharstring .= chr(($charval & 0x3F) | 0x80); - } else { - // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb - $newcharstring = chr(($charval >> 18) | 0xF0); - $newcharstring .= chr(($charval >> 12) | 0xC0); - $newcharstring .= chr(($charval >> 6) | 0xC0); - $newcharstring .= chr(($charval & 0x3F) | 0x80); - } - return $newcharstring; - } - - // ISO-8859-1 => UTF-8 - static function iconv_fallback_iso88591_utf8($string, $bom=false) { - if (function_exists('utf8_encode')) { - return utf8_encode($string); - } - // utf8_encode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support) - $newcharstring = ''; - if ($bom) { - $newcharstring .= "\xEF\xBB\xBF"; - } - for ($i = 0; $i < strlen($string); $i++) { - $charval = ord($string{$i}); - $newcharstring .= getid3_lib::iconv_fallback_int_utf8($charval); - } - return $newcharstring; - } - - // ISO-8859-1 => UTF-16BE - static function iconv_fallback_iso88591_utf16be($string, $bom=false) { - $newcharstring = ''; - if ($bom) { - $newcharstring .= "\xFE\xFF"; - } - for ($i = 0; $i < strlen($string); $i++) { - $newcharstring .= "\x00".$string{$i}; - } - return $newcharstring; - } - - // ISO-8859-1 => UTF-16LE - static function iconv_fallback_iso88591_utf16le($string, $bom=false) { - $newcharstring = ''; - if ($bom) { - $newcharstring .= "\xFF\xFE"; - } - for ($i = 0; $i < strlen($string); $i++) { - $newcharstring .= $string{$i}."\x00"; - } - return $newcharstring; - } - - // ISO-8859-1 => UTF-16LE (BOM) - static function iconv_fallback_iso88591_utf16($string) { - return getid3_lib::iconv_fallback_iso88591_utf16le($string, true); - } - - // UTF-8 => ISO-8859-1 - static function iconv_fallback_utf8_iso88591($string) { - if (function_exists('utf8_decode')) { - return utf8_decode($string); - } - // utf8_decode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support) - $newcharstring = ''; - $offset = 0; - $stringlength = strlen($string); - while ($offset < $stringlength) { - if ((ord($string{$offset}) | 0x07) == 0xF7) { - // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) & - ((ord($string{($offset + 1)}) & 0x3F) << 12) & - ((ord($string{($offset + 2)}) & 0x3F) << 6) & - (ord($string{($offset + 3)}) & 0x3F); - $offset += 4; - } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) { - // 1110bbbb 10bbbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) & - ((ord($string{($offset + 1)}) & 0x3F) << 6) & - (ord($string{($offset + 2)}) & 0x3F); - $offset += 3; - } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) { - // 110bbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) & - (ord($string{($offset + 1)}) & 0x3F); - $offset += 2; - } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) { - // 0bbbbbbb - $charval = ord($string{$offset}); - $offset += 1; - } else { - // error? throw some kind of warning here? - $charval = false; - $offset += 1; - } - if ($charval !== false) { - $newcharstring .= (($charval < 256) ? chr($charval) : '?'); - } - } - return $newcharstring; - } - - // UTF-8 => UTF-16BE - static function iconv_fallback_utf8_utf16be($string, $bom=false) { - $newcharstring = ''; - if ($bom) { - $newcharstring .= "\xFE\xFF"; - } - $offset = 0; - $stringlength = strlen($string); - while ($offset < $stringlength) { - if ((ord($string{$offset}) | 0x07) == 0xF7) { - // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) & - ((ord($string{($offset + 1)}) & 0x3F) << 12) & - ((ord($string{($offset + 2)}) & 0x3F) << 6) & - (ord($string{($offset + 3)}) & 0x3F); - $offset += 4; - } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) { - // 1110bbbb 10bbbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) & - ((ord($string{($offset + 1)}) & 0x3F) << 6) & - (ord($string{($offset + 2)}) & 0x3F); - $offset += 3; - } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) { - // 110bbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) & - (ord($string{($offset + 1)}) & 0x3F); - $offset += 2; - } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) { - // 0bbbbbbb - $charval = ord($string{$offset}); - $offset += 1; - } else { - // error? throw some kind of warning here? - $charval = false; - $offset += 1; - } - if ($charval !== false) { - $newcharstring .= (($charval < 65536) ? getid3_lib::BigEndian2String($charval, 2) : "\x00".'?'); - } - } - return $newcharstring; - } - - // UTF-8 => UTF-16LE - static function iconv_fallback_utf8_utf16le($string, $bom=false) { - $newcharstring = ''; - if ($bom) { - $newcharstring .= "\xFF\xFE"; - } - $offset = 0; - $stringlength = strlen($string); - while ($offset < $stringlength) { - if ((ord($string{$offset}) | 0x07) == 0xF7) { - // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) & - ((ord($string{($offset + 1)}) & 0x3F) << 12) & - ((ord($string{($offset + 2)}) & 0x3F) << 6) & - (ord($string{($offset + 3)}) & 0x3F); - $offset += 4; - } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) { - // 1110bbbb 10bbbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) & - ((ord($string{($offset + 1)}) & 0x3F) << 6) & - (ord($string{($offset + 2)}) & 0x3F); - $offset += 3; - } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) { - // 110bbbbb 10bbbbbb - $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) & - (ord($string{($offset + 1)}) & 0x3F); - $offset += 2; - } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) { - // 0bbbbbbb - $charval = ord($string{$offset}); - $offset += 1; - } else { - // error? maybe throw some warning here? - $charval = false; - $offset += 1; - } - if ($charval !== false) { - $newcharstring .= (($charval < 65536) ? getid3_lib::LittleEndian2String($charval, 2) : '?'."\x00"); - } - } - return $newcharstring; - } - - // UTF-8 => UTF-16LE (BOM) - static function iconv_fallback_utf8_utf16($string) { - return getid3_lib::iconv_fallback_utf8_utf16le($string, true); - } - - // UTF-16BE => UTF-8 - static function iconv_fallback_utf16be_utf8($string) { - if (substr($string, 0, 2) == "\xFE\xFF") { - // strip BOM - $string = substr($string, 2); - } - $newcharstring = ''; - for ($i = 0; $i < strlen($string); $i += 2) { - $charval = getid3_lib::BigEndian2Int(substr($string, $i, 2)); - $newcharstring .= getid3_lib::iconv_fallback_int_utf8($charval); - } - return $newcharstring; - } - - // UTF-16LE => UTF-8 - static function iconv_fallback_utf16le_utf8($string) { - if (substr($string, 0, 2) == "\xFF\xFE") { - // strip BOM - $string = substr($string, 2); - } - $newcharstring = ''; - for ($i = 0; $i < strlen($string); $i += 2) { - $charval = getid3_lib::LittleEndian2Int(substr($string, $i, 2)); - $newcharstring .= getid3_lib::iconv_fallback_int_utf8($charval); - } - return $newcharstring; - } - - // UTF-16BE => ISO-8859-1 - static function iconv_fallback_utf16be_iso88591($string) { - if (substr($string, 0, 2) == "\xFE\xFF") { - // strip BOM - $string = substr($string, 2); - } - $newcharstring = ''; - for ($i = 0; $i < strlen($string); $i += 2) { - $charval = getid3_lib::BigEndian2Int(substr($string, $i, 2)); - $newcharstring .= (($charval < 256) ? chr($charval) : '?'); - } - return $newcharstring; - } - - // UTF-16LE => ISO-8859-1 - static function iconv_fallback_utf16le_iso88591($string) { - if (substr($string, 0, 2) == "\xFF\xFE") { - // strip BOM - $string = substr($string, 2); - } - $newcharstring = ''; - for ($i = 0; $i < strlen($string); $i += 2) { - $charval = getid3_lib::LittleEndian2Int(substr($string, $i, 2)); - $newcharstring .= (($charval < 256) ? chr($charval) : '?'); - } - return $newcharstring; - } - - // UTF-16 (BOM) => ISO-8859-1 - static function iconv_fallback_utf16_iso88591($string) { - $bom = substr($string, 0, 2); - if ($bom == "\xFE\xFF") { - return getid3_lib::iconv_fallback_utf16be_iso88591(substr($string, 2)); - } elseif ($bom == "\xFF\xFE") { - return getid3_lib::iconv_fallback_utf16le_iso88591(substr($string, 2)); - } - return $string; - } - - // UTF-16 (BOM) => UTF-8 - static function iconv_fallback_utf16_utf8($string) { - $bom = substr($string, 0, 2); - if ($bom == "\xFE\xFF") { - return getid3_lib::iconv_fallback_utf16be_utf8(substr($string, 2)); - } elseif ($bom == "\xFF\xFE") { - return getid3_lib::iconv_fallback_utf16le_utf8(substr($string, 2)); - } - return $string; - } - - static function iconv_fallback($in_charset, $out_charset, $string) { - - if ($in_charset == $out_charset) { - return $string; - } - - // iconv() availble - if (function_exists('iconv')) { - - ob_start(); - if ($converted_string = iconv($in_charset, $out_charset.'//TRANSLIT', $string)) { - ob_end_clean(); - switch ($out_charset) { - case 'ISO-8859-1': - $converted_string = rtrim($converted_string, "\x00"); - break; - } - return $converted_string; - } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - } - - // iconv() may sometimes fail with "illegal character in input string" error message - // and return an empty string, but returning the unconverted string is more useful - return $string; - } - - - // iconv() not available - static $ConversionFunctionList = array(); - if (empty($ConversionFunctionList)) { - $ConversionFunctionList['ISO-8859-1']['UTF-8'] = 'iconv_fallback_iso88591_utf8'; - $ConversionFunctionList['ISO-8859-1']['UTF-16'] = 'iconv_fallback_iso88591_utf16'; - $ConversionFunctionList['ISO-8859-1']['UTF-16BE'] = 'iconv_fallback_iso88591_utf16be'; - $ConversionFunctionList['ISO-8859-1']['UTF-16LE'] = 'iconv_fallback_iso88591_utf16le'; - $ConversionFunctionList['UTF-8']['ISO-8859-1'] = 'iconv_fallback_utf8_iso88591'; - $ConversionFunctionList['UTF-8']['UTF-16'] = 'iconv_fallback_utf8_utf16'; - $ConversionFunctionList['UTF-8']['UTF-16BE'] = 'iconv_fallback_utf8_utf16be'; - $ConversionFunctionList['UTF-8']['UTF-16LE'] = 'iconv_fallback_utf8_utf16le'; - $ConversionFunctionList['UTF-16']['ISO-8859-1'] = 'iconv_fallback_utf16_iso88591'; - $ConversionFunctionList['UTF-16']['UTF-8'] = 'iconv_fallback_utf16_utf8'; - $ConversionFunctionList['UTF-16LE']['ISO-8859-1'] = 'iconv_fallback_utf16le_iso88591'; - $ConversionFunctionList['UTF-16LE']['UTF-8'] = 'iconv_fallback_utf16le_utf8'; - $ConversionFunctionList['UTF-16BE']['ISO-8859-1'] = 'iconv_fallback_utf16be_iso88591'; - $ConversionFunctionList['UTF-16BE']['UTF-8'] = 'iconv_fallback_utf16be_utf8'; - } - if (isset($ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)])) { - $ConversionFunction = $ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)]; - return getid3_lib::$ConversionFunction($string); - } - throw new Exception('PHP does not have iconv() support - cannot convert from '.$in_charset.' to '.$out_charset); - } - - - static function MultiByteCharString2HTML($string, $charset='ISO-8859-1') { - $HTMLstring = ''; - - switch ($charset) { - case '1251': - case '1252': - case '866': - case '932': - case '936': - case '950': - case 'BIG5': - case 'BIG5-HKSCS': - case 'cp1251': - case 'cp1252': - case 'cp866': - case 'EUC-JP': - case 'EUCJP': - case 'GB2312': - case 'ibm866': - case 'ISO-8859-1': - case 'ISO-8859-15': - case 'ISO8859-1': - case 'ISO8859-15': - case 'KOI8-R': - case 'koi8-ru': - case 'koi8r': - case 'Shift_JIS': - case 'SJIS': - case 'win-1251': - case 'Windows-1251': - case 'Windows-1252': - $HTMLstring = htmlentities($string, ENT_COMPAT, $charset); - break; - - case 'UTF-8': - $strlen = strlen($string); - for ($i = 0; $i < $strlen; $i++) { - $char_ord_val = ord($string{$i}); - $charval = 0; - if ($char_ord_val < 0x80) { - $charval = $char_ord_val; - } elseif ((($char_ord_val & 0xF0) >> 4) == 0x0F && $i+3 < $strlen) { - $charval = (($char_ord_val & 0x07) << 18); - $charval += ((ord($string{++$i}) & 0x3F) << 12); - $charval += ((ord($string{++$i}) & 0x3F) << 6); - $charval += (ord($string{++$i}) & 0x3F); - } elseif ((($char_ord_val & 0xE0) >> 5) == 0x07 && $i+2 < $strlen) { - $charval = (($char_ord_val & 0x0F) << 12); - $charval += ((ord($string{++$i}) & 0x3F) << 6); - $charval += (ord($string{++$i}) & 0x3F); - } elseif ((($char_ord_val & 0xC0) >> 6) == 0x03 && $i+1 < $strlen) { - $charval = (($char_ord_val & 0x1F) << 6); - $charval += (ord($string{++$i}) & 0x3F); - } - if (($charval >= 32) && ($charval <= 127)) { - $HTMLstring .= htmlentities(chr($charval), ENT_COMPAT, LANG_CHARSET); - } else { - $HTMLstring .= '&#'.$charval.';'; - } - } - break; - - case 'UTF-16LE': - for ($i = 0; $i < strlen($string); $i += 2) { - $charval = getid3_lib::LittleEndian2Int(substr($string, $i, 2)); - if (($charval >= 32) && ($charval <= 127)) { - $HTMLstring .= chr($charval); - } else { - $HTMLstring .= '&#'.$charval.';'; - } - } - break; - - case 'UTF-16BE': - for ($i = 0; $i < strlen($string); $i += 2) { - $charval = getid3_lib::BigEndian2Int(substr($string, $i, 2)); - if (($charval >= 32) && ($charval <= 127)) { - $HTMLstring .= chr($charval); - } else { - $HTMLstring .= '&#'.$charval.';'; - } - } - break; - - default: - $HTMLstring = 'ERROR: Character set "'.$charset.'" not supported in MultiByteCharString2HTML()'; - break; - } - return $HTMLstring; - } - - - - static function RGADnameLookup($namecode) { - static $RGADname = array(); - if (empty($RGADname)) { - $RGADname[0] = 'not set'; - $RGADname[1] = 'Track Gain Adjustment'; - $RGADname[2] = 'Album Gain Adjustment'; - } - - return (isset($RGADname[$namecode]) ? $RGADname[$namecode] : ''); - } - - - static function RGADoriginatorLookup($originatorcode) { - static $RGADoriginator = array(); - if (empty($RGADoriginator)) { - $RGADoriginator[0] = 'unspecified'; - $RGADoriginator[1] = 'pre-set by artist/producer/mastering engineer'; - $RGADoriginator[2] = 'set by user'; - $RGADoriginator[3] = 'determined automatically'; - } - - return (isset($RGADoriginator[$originatorcode]) ? $RGADoriginator[$originatorcode] : ''); - } - - - static function RGADadjustmentLookup($rawadjustment, $signbit) { - $adjustment = $rawadjustment / 10; - if ($signbit == 1) { - $adjustment *= -1; - } - return (float) $adjustment; - } - - - static function RGADgainString($namecode, $originatorcode, $replaygain) { - if ($replaygain < 0) { - $signbit = '1'; - } else { - $signbit = '0'; - } - $storedreplaygain = intval(round($replaygain * 10)); - $gainstring = str_pad(decbin($namecode), 3, '0', STR_PAD_LEFT); - $gainstring .= str_pad(decbin($originatorcode), 3, '0', STR_PAD_LEFT); - $gainstring .= $signbit; - $gainstring .= str_pad(decbin($storedreplaygain), 9, '0', STR_PAD_LEFT); - - return $gainstring; - } - - static function RGADamplitude2dB($amplitude) { - return 20 * log10($amplitude); - } - - - static function GetDataImageSize($imgData, &$imageinfo) { - $GetDataImageSize = false; - if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) { - ob_start(); - if ($tmp = fopen($tempfilename, 'wb')) { - ob_end_clean(); - fwrite($tmp, $imgData); - fclose($tmp); - ob_start(); - $GetDataImageSize = GetImageSize($tempfilename, $imageinfo); - $errormessage = ob_get_contents(); - ob_end_clean(); - } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - } - unlink($tempfilename); - } - return $GetDataImageSize; - } - - static function ImageTypesLookup($imagetypeid) { - static $ImageTypesLookup = array(); - if (empty($ImageTypesLookup)) { - $ImageTypesLookup[1] = 'gif'; - $ImageTypesLookup[2] = 'jpeg'; - $ImageTypesLookup[3] = 'png'; - $ImageTypesLookup[4] = 'swf'; - $ImageTypesLookup[5] = 'psd'; - $ImageTypesLookup[6] = 'bmp'; - $ImageTypesLookup[7] = 'tiff (little-endian)'; - $ImageTypesLookup[8] = 'tiff (big-endian)'; - $ImageTypesLookup[9] = 'jpc'; - $ImageTypesLookup[10] = 'jp2'; - $ImageTypesLookup[11] = 'jpx'; - $ImageTypesLookup[12] = 'jb2'; - $ImageTypesLookup[13] = 'swc'; - $ImageTypesLookup[14] = 'iff'; - } - return (isset($ImageTypesLookup[$imagetypeid]) ? $ImageTypesLookup[$imagetypeid] : ''); - } - - static function CopyTagsToComments(&$ThisFileInfo) { - - // Copy all entries from ['tags'] into common ['comments'] - if (!empty($ThisFileInfo['tags'])) { - foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) { - foreach ($tagarray as $tagname => $tagdata) { - foreach ($tagdata as $key => $value) { - if (!empty($value)) { - if (empty($ThisFileInfo['comments'][$tagname])) { - - // fall through and append value - - } elseif ($tagtype == 'id3v1') { - - $newvaluelength = strlen(trim($value)); - foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) { - $oldvaluelength = strlen(trim($existingvalue)); - if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) { - // new value is identical but shorter-than (or equal-length to) one already in comments - skip - break 2; - } - } - - } elseif (!is_array($value)) { - - $newvaluelength = strlen(trim($value)); - foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) { - $oldvaluelength = strlen(trim($existingvalue)); - if (($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) { - $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value); - break 2; - } - } - - } - if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) { - $value = (is_string($value) ? trim($value) : $value); - $ThisFileInfo['comments'][$tagname][] = $value; - } - } - } - } - } - - // Copy to ['comments_html'] - foreach ($ThisFileInfo['comments'] as $field => $values) { - foreach ($values as $index => $value) { - if (is_array($value)) { - $ThisFileInfo['comments_html'][$field][$index] = $value; - } else { - $ThisFileInfo['comments_html'][$field][$index] = str_replace('�', '', getid3_lib::MultiByteCharString2HTML($value, $ThisFileInfo['encoding'])); - } - } - } - } - } - - - static function EmbeddedLookup($key, $begin, $end, $file, $name) { - - // Cached - static $cache; - if (isset($cache[$file][$name])) { - return (isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : ''); - } - - // Init - $keylength = strlen($key); - $line_count = $end - $begin - 7; - - // Open php file - $fp = fopen($file, 'r'); - - // Discard $begin lines - for ($i = 0; $i < ($begin + 3); $i++) { - fgets($fp, 1024); - } - - // Loop thru line - while (0 < $line_count--) { - - // Read line - $line = ltrim(fgets($fp, 1024), "\t "); - - // METHOD A: only cache the matching key - less memory but slower on next lookup of not-previously-looked-up key - //$keycheck = substr($line, 0, $keylength); - //if ($key == $keycheck) { - // $cache[$file][$name][$keycheck] = substr($line, $keylength + 1); - // break; - //} - - // METHOD B: cache all keys in this lookup - more memory but faster on next lookup of not-previously-looked-up key - //$cache[$file][$name][substr($line, 0, $keylength)] = trim(substr($line, $keylength + 1)); - $explodedLine = explode("\t", $line, 2); - $ThisKey = (isset($explodedLine[0]) ? $explodedLine[0] : ''); - $ThisValue = (isset($explodedLine[1]) ? $explodedLine[1] : ''); - $cache[$file][$name][$ThisKey] = trim($ThisValue); - } - - // Close and return - fclose($fp); - return (isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : ''); - } - - static function IncludeDependency($filename, $sourcefile, $DieOnFailure=false) { - global $GETID3_ERRORARRAY; - - if (file_exists($filename)) { - if (include_once($filename)) { - return true; - } else { - $diemessage = basename($sourcefile).' depends on '.$filename.', which has errors'; - } - } else { - $diemessage = basename($sourcefile).' depends on '.$filename.', which is missing'; - } - if ($DieOnFailure) { - throw new Exception($diemessage); - } else { - $GETID3_ERRORARRAY[] = $diemessage; - } - return false; - } - -} - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/getid3.php b/serendipity_event_podcast/player/getid3/getid3.php deleted file mode 100644 index 22fb7e16..00000000 --- a/serendipity_event_podcast/player/getid3/getid3.php +++ /dev/null @@ -1,1522 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// // -// Please see readme.txt for more information // -// /// -///////////////////////////////////////////////////////////////// - -// Defines -define('GETID3_VERSION', '1.8.5-20110218'); -define('GETID3_FREAD_BUFFER_SIZE', 16384); // read buffer size in bytes - -// attempt to define temp dir as something flexible but reliable -$temp_dir = ini_get('upload_tmp_dir'); -if ($temp_dir && (!is_dir($temp_dir) || !is_readable($temp_dir))) { - $temp_dir = ''; -} -if (!$temp_dir && function_exists('sys_get_temp_dir')) { - // PHP v5.2.1+ - // sys_get_temp_dir() may give inaccessible temp dir, e.g. with open_basedir on virtual hosts - $temp_dir = sys_get_temp_dir(); -} -$temp_dir = realpath($temp_dir); -$open_basedir = ini_get('open_basedir'); -if ($open_basedir) { - // e.g. "/var/www/vhosts/getid3.org/httpdocs/:/tmp/" - $temp_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $temp_dir); - $open_basedir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $open_basedir); - if (substr($temp_dir, -1, 1) != DIRECTORY_SEPARATOR) { - $temp_dir .= DIRECTORY_SEPARATOR; - } - $found_valid_tempdir = false; - $open_basedirs = explode(':', $open_basedir); - foreach ($open_basedirs as $basedir) { - if (substr($basedir, -1, 1) != DIRECTORY_SEPARATOR) { - $basedir .= DIRECTORY_SEPARATOR; - } - if (preg_match('#^'.preg_quote($basedir).'#', $temp_dir)) { - $found_valid_tempdir = true; - break; - } - } - if (!$found_valid_tempdir) { - $temp_dir = ''; - } - unset($open_basedirs, $found_valid_tempdir, $basedir); -} -if (!$temp_dir) { - $temp_dir = '*'; // invalid directory name should force tempnam() to use system default temp dir -} -// $temp_dir = '/something/else/'; // feel free to override temp dir here if it works better for your system -define('GETID3_TEMP_DIR', $temp_dir); -unset($open_basedir, $temp_dir); - - -// define a constant rather than looking up every time it is needed -if (!defined('GETID3_OS_ISWINDOWS')) { - if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { - define('GETID3_OS_ISWINDOWS', true); - } else { - define('GETID3_OS_ISWINDOWS', false); - } -} - -// Get base path of getID3() - ONCE -if (!defined('GETID3_INCLUDEPATH')) { - foreach (get_included_files() as $key => $val) { - if (basename($val) == 'getid3.php') { - define('GETID3_INCLUDEPATH', dirname($val).DIRECTORY_SEPARATOR); - break; - } - } -} - -// End: Defines - - -class getID3 -{ - // public: Settings - var $encoding = 'ISO-8859-1'; // CASE SENSITIVE! - i.e. (must be supported by iconv()) - // Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE - - var $encoding_id3v1 = 'ISO-8859-1'; // Should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'EUC-CN' - - var $tempdir = GETID3_TEMP_DIR; - - // public: Optional tag checks - disable for speed. - var $option_tag_id3v1 = true; // Read and process ID3v1 tags - var $option_tag_id3v2 = true; // Read and process ID3v2 tags - var $option_tag_lyrics3 = true; // Read and process Lyrics3 tags - var $option_tag_apetag = true; // Read and process APE tags - var $option_tags_process = true; // Copy tags to root key 'tags' and encode to $this->encoding - var $option_tags_html = true; // Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities - - // public: Optional tag/comment calucations - var $option_extra_info = true; // Calculate additional info such as bitrate, channelmode etc - - // public: Optional calculations - var $option_md5_data = false; // Get MD5 sum of data part - slow - var $option_md5_data_source = false; // Use MD5 of source file if availble - only FLAC and OptimFROG - var $option_sha1_data = false; // Get SHA1 sum of data part - slow - var $option_max_2gb_check = null; // Check whether file is larger than 2GB and thus not supported by 32-bit PHP - - // private - var $filename = ''; - var $startup_error = ''; - var $startup_warning = ''; - - - // public: constructor - function getID3() { - - // Check for PHP version - $required_php_version = '5.0.5'; - if (!function_exists('version_compare') || version_compare(PHP_VERSION, $required_php_version, '<')) { - // version_compare not available before PHP v4.1.0, so don't use for first version checking - $this->startup_error .= 'getID3() requires PHP v'.$required_php_version.' or higher - you are running v'.PHP_VERSION; - return false; - } - - // Check memory - $memory_limit = ini_get('memory_limit'); - if (preg_match('#([0-9]+)M#i', $memory_limit, $matches)) { - // could be stored as "16M" rather than 16777216 for example - $memory_limit = $matches[1] * 1048576; - } elseif (preg_match('#([0-9]+)G#i', $memory_limit, $matches)) { // The 'G' modifier is available since PHP 5.1.0 - // could be stored as "2G" rather than 2147483648 for example - $memory_limit = $matches[1] * 1073741824; - } - if ($memory_limit <= 0) { - // memory limits probably disabled - } elseif ($memory_limit <= 4194304) { - $this->startup_error .= 'PHP has less than 4MB available memory and will very likely run out. Increase memory_limit in php.ini'; - } elseif ($memory_limit <= 12582912) { - $this->startup_warning .= 'PHP has less than 12MB available memory and might run out if all modules are loaded. Increase memory_limit in php.ini'; - } - - // Check safe_mode off - if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { - $this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.'); - } - - if (intval(ini_get('mbstring.func_overload')) > 0) { - $this->warning('WARNING: php.ini contains "mbstring.func_overload = '.ini_get('mbstring.func_overload').'", this may break things.'); - } - - /* - // Check timezone config setting - // this is needed to prevent E_STRICT warnings with any time/date functions - if (!ini_get('date.timezone')) { - if (function_exists('date_default_timezone_set')) { // exists since PHP v5.1.0 - $this->warning('php.ini should have "date.timezone" set, but it does not. Setting timezone to "'.date_default_timezone_get().'"'); - date_default_timezone_set(date_default_timezone_get()); - } else { - $this->warning('php.ini should have "date.timezone" set, but it does not.'); - } - } - */ - - // Check for magic_quotes_runtime - if (function_exists('get_magic_quotes_runtime')) { - if (get_magic_quotes_runtime()) { - return $this->startup_error('magic_quotes_runtime must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_runtime(0) and set_magic_quotes_runtime(1).'); - } - } - - // Check for magic_quotes_gpc - if (function_exists('magic_quotes_gpc')) { - if (get_magic_quotes_gpc()) { - return $this->startup_error('magic_quotes_gpc must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_gpc(0) and set_magic_quotes_gpc(1).'); - } - } - - // Load support library - if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) { - $this->startup_error .= 'getid3.lib.php is missing or corrupt'; - } - - if ($this->option_max_2gb_check === null) { - $this->option_max_2gb_check = (PHP_INT_MAX <= 2147483647); - } - - - // Needed for Windows only: - // Define locations of helper applications for Shorten, VorbisComment, MetaFLAC - // as well as other helper functions such as head, tail, md5sum, etc - // This path cannot contain spaces, but the below code will attempt to get the - // 8.3-equivalent path automatically - // IMPORTANT: This path must include the trailing slash - if (GETID3_OS_ISWINDOWS && !defined('GETID3_HELPERAPPSDIR')) { - - $helperappsdir = GETID3_INCLUDEPATH.'..'.DIRECTORY_SEPARATOR.'helperapps'; // must not have any space in this path - - if (!is_dir($helperappsdir)) { - $this->startup_error .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist'; - } elseif (strpos(realpath($helperappsdir), ' ') !== false) { - $DirPieces = explode(DIRECTORY_SEPARATOR, realpath($helperappsdir)); - $path_so_far = array(); - foreach ($DirPieces as $key => $value) { - if (strpos($value, ' ') !== false) { - if (!empty($path_so_far)) { - $commandline = 'dir /x '.escapeshellarg(implode(DIRECTORY_SEPARATOR, $path_so_far)); - $dir_listing = `$commandline`; - $lines = explode("\n", $dir_listing); - foreach ($lines as $line) { - $line = trim($line); - if (preg_match('#^([0-9/]{10}) +([0-9:]{4,5}( [AP]M)?) +(|[0-9,]+) +([^ ]{0,11}) +(.+)$#', $line, $matches)) { - list($dummy, $date, $time, $ampm, $filesize, $shortname, $filename) = $matches; - if ((strtoupper($filesize) == '') && (strtolower($filename) == strtolower($value))) { - $value = $shortname; - } - } - } - } else { - $this->startup_error .= 'GETID3_HELPERAPPSDIR must not have any spaces in it - use 8dot3 naming convention if neccesary. You can run "dir /x" from the commandline to see the correct 8.3-style names.'; - } - } - $path_so_far[] = $value; - } - $helperappsdir = implode(DIRECTORY_SEPARATOR, $path_so_far); - } - define('GETID3_HELPERAPPSDIR', $helperappsdir.DIRECTORY_SEPARATOR); - } - - } - - - // public: setOption - function setOption($optArray) { - if (!is_array($optArray) || empty($optArray)) { - return false; - } - foreach ($optArray as $opt => $val) { - //if (isset($this, $opt) === false) { - if (isset($this->$opt) === false) { - continue; - } - $this->$opt = $val; - } - return true; - } - - - // public: analyze file - function analyze($filename) { - try { - if (!empty($this->startup_error)) { - return $this->error($this->startup_error); - } - if (!empty($this->startup_warning)) { - $this->warning($this->startup_warning); - } - - // init result array and set parameters - $this->info = array(); - $this->info['GETID3_VERSION'] = GETID3_VERSION; - - // Check encoding/iconv support - if (!function_exists('iconv') && !in_array($this->encoding, array('ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'))) { - $errormessage = 'iconv() support is needed for encodings other than ISO-8859-1, UTF-8, UTF-16LE, UTF16-BE, UTF-16. '; - if (GETID3_OS_ISWINDOWS) { - $errormessage .= 'PHP does not have iconv() support. Please enable php_iconv.dll in php.ini, and copy iconv.dll from c:/php/dlls to c:/windows/system32'; - } else { - $errormessage .= 'PHP is not compiled with iconv() support. Please recompile with the --with-iconv switch'; - } - return $this->error($errormessage); - } - - // remote files not supported - if (preg_match('/^(ht|f)tp:\/\//', $filename)) { - return $this->error('Remote files are not supported in this version of getID3() - please copy the file locally first'); - } - - $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename); - $filename = preg_replace('#(.+)'.preg_quote(DIRECTORY_SEPARATOR).'{2,}#U', '\1'.DIRECTORY_SEPARATOR, $filename); - - // open local file - if (file_exists($filename) && is_file($filename)) { - ob_start(); - if ($fp = fopen($filename, 'rb')) { - // great - ob_end_clean(); - } else { - $fopen_error = ob_get_contents(); - ob_end_clean(); - return $this->error('Could not open file "'.$filename.'" (fopen says: '.$fopen_error.')'); - } - } else { - return $this->error('Could not open "'.$filename.'" (does not exist, or is not a file)'); - } - - // set parameters - $this->info['filesize'] = filesize($filename); - - // option_max_2gb_check - if ($this->option_max_2gb_check) { - // PHP (32-bit all, and 64-bit Windows) doesn't support integers larger than 2^31 (~2GB) - // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize - // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer - $fseek = fseek($fp, 0, SEEK_END); - if (($fseek < 0) || (($this->info['filesize'] != 0) && (ftell($fp) == 0)) || - ($this->info['filesize'] < 0) || - (ftell($fp) < 0)) { - $real_filesize = false; - if (GETID3_OS_ISWINDOWS) { - $commandline = 'dir /-C "'.str_replace('/', DIRECTORY_SEPARATOR, $filename).'"'; - $dir_output = `$commandline`; - if (preg_match('#1 File\(s\)[ ]+([0-9]+) bytes#i', $dir_output, $matches)) { - $real_filesize = (float) $matches[1]; - } - } else { - $commandline = 'ls -o -g -G --time-style=long-iso '.escapeshellarg($filename); - $dir_output = `$commandline`; - if (preg_match('#([0-9]+) ([0-9]{4}-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}) '.str_replace('#', '\\#', preg_quote($filename)).'$#', $dir_output, $matches)) { - $real_filesize = (float) $matches[1]; - } - } - if ($real_filesize === false) { - unset($this->info['filesize']); - fclose($fp); - return $this->error('Unable to determine actual filesize. File is most likely larger than '.round(PHP_INT_MAX / 1073741824).'GB and is not supported by PHP.'); - } elseif (getid3_lib::intValueSupported($real_filesize)) { - unset($this->info['filesize']); - fclose($fp); - return $this->error('PHP seems to think the file is larger than '.round(PHP_INT_MAX / 1073741824).'GB, but filesystem reports it as '.number_format($real_filesize, 3).'GB, please report to info@getid3.org'); - } - $this->info['filesize'] = $real_filesize; - $this->error('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB (filesystem reports it as '.number_format($real_filesize, 3).'GB) and is not properly supported by PHP.'); - } - } - - // set more parameters - $this->info['avdataoffset'] = 0; - $this->info['avdataend'] = $this->info['filesize']; - $this->info['fileformat'] = ''; // filled in later - $this->info['audio']['dataformat'] = ''; // filled in later, unset if not used - $this->info['video']['dataformat'] = ''; // filled in later, unset if not used - $this->info['tags'] = array(); // filled in later, unset if not used - $this->info['error'] = array(); // filled in later, unset if not used - $this->info['warning'] = array(); // filled in later, unset if not used - $this->info['comments'] = array(); // filled in later, unset if not used - $this->info['encoding'] = $this->encoding; // required by id3v2 and iso modules - can be unset at the end if desired - - // set redundant parameters - might be needed in some include file - $this->info['filename'] = basename($filename); - $this->info['filepath'] = str_replace('\\', '/', realpath(dirname($filename))); - $this->info['filenamepath'] = $this->info['filepath'].'/'.$this->info['filename']; - - - // handle ID3v2 tag - done first - already at beginning of file - // ID3v2 detection (even if not parsing) is always done otherwise fileformat is much harder to detect - if ($this->option_tag_id3v2) { - - $GETID3_ERRORARRAY = &$this->info['warning']; - if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, false)) { - $tag = new getid3_id3v2($fp, $this->info); - unset($tag); - } - - } else { - - fseek($fp, 0, SEEK_SET); - $header = fread($fp, 10); - if ((substr($header, 0, 3) == 'ID3') && (strlen($header) == 10)) { - $this->info['id3v2']['header'] = true; - $this->info['id3v2']['majorversion'] = ord($header{3}); - $this->info['id3v2']['minorversion'] = ord($header{4}); - $this->info['id3v2']['headerlength'] = getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length - - $this->info['id3v2']['tag_offset_start'] = 0; - $this->info['id3v2']['tag_offset_end'] = $this->info['id3v2']['tag_offset_start'] + $this->info['id3v2']['headerlength']; - $this->info['avdataoffset'] = $this->info['id3v2']['tag_offset_end']; - } - - } - - - // handle ID3v1 tag - if ($this->option_tag_id3v1) { - if (!file_exists(GETID3_INCLUDEPATH.'module.tag.id3v1.php') || !include_once(GETID3_INCLUDEPATH.'module.tag.id3v1.php')) { - return $this->error('module.tag.id3v1.php is missing - you may disable option_tag_id3v1.'); - } - $tag = new getid3_id3v1($fp, $this->info); - unset($tag); - } - - // handle APE tag - if ($this->option_tag_apetag) { - if (!file_exists(GETID3_INCLUDEPATH.'module.tag.apetag.php') || !include_once(GETID3_INCLUDEPATH.'module.tag.apetag.php')) { - return $this->error('module.tag.apetag.php is missing - you may disable option_tag_apetag.'); - } - $tag = new getid3_apetag($fp, $this->info); - unset($tag); - } - - // handle lyrics3 tag - if ($this->option_tag_lyrics3) { - if (!file_exists(GETID3_INCLUDEPATH.'module.tag.lyrics3.php') || !include_once(GETID3_INCLUDEPATH.'module.tag.lyrics3.php')) { - return $this->error('module.tag.lyrics3.php is missing - you may disable option_tag_lyrics3.'); - } - $tag = new getid3_lyrics3($fp, $this->info); - unset($tag); - } - - // read 32 kb file data - fseek($fp, $this->info['avdataoffset'], SEEK_SET); - $formattest = fread($fp, 32774); - - // determine format - $determined_format = $this->GetFileFormat($formattest, $filename); - - // unable to determine file format - if (!$determined_format) { - fclose($fp); - return $this->error('unable to determine file format'); - } - - // check for illegal ID3 tags - if (isset($determined_format['fail_id3']) && (in_array('id3v1', $this->info['tags']) || in_array('id3v2', $this->info['tags']))) { - if ($determined_format['fail_id3'] === 'ERROR') { - fclose($fp); - return $this->error('ID3 tags not allowed on this file type.'); - } elseif ($determined_format['fail_id3'] === 'WARNING') { - $this->info['warning'][] = 'ID3 tags not allowed on this file type.'; - } - } - - // check for illegal APE tags - if (isset($determined_format['fail_ape']) && in_array('ape', $this->info['tags'])) { - if ($determined_format['fail_ape'] === 'ERROR') { - fclose($fp); - return $this->error('APE tags not allowed on this file type.'); - } elseif ($determined_format['fail_ape'] === 'WARNING') { - $this->info['warning'][] = 'APE tags not allowed on this file type.'; - } - } - - // set mime type - $this->info['mime_type'] = $determined_format['mime_type']; - - // supported format signature pattern detected, but module deleted - if (!file_exists(GETID3_INCLUDEPATH.$determined_format['include'])) { - fclose($fp); - return $this->error('Format not supported, module "'.$determined_format['include'].'" was removed.'); - } - - // module requires iconv support - if (!function_exists('iconv') && !empty($determined_format['iconv_req'])) { - return $this->error('iconv support is required for this module ('.$determined_format['include'].').'); - } - - // include module - include_once(GETID3_INCLUDEPATH.$determined_format['include']); - - // instantiate module class - $class_name = 'getid3_'.$determined_format['module']; - if (!class_exists($class_name)) { - return $this->error('Format not supported, module "'.$determined_format['include'].'" is corrupt.'); - } - if (isset($determined_format['option'])) { - $class = new $class_name($fp, $this->info, $determined_format['option']); - } else { - $class = new $class_name($fp, $this->info); - } - unset($class); - - // close file - fclose($fp); - - // process all tags - copy to 'tags' and convert charsets - if ($this->option_tags_process) { - $this->HandleAllTags(); - } - - // perform more calculations - if ($this->option_extra_info) { - $this->ChannelsBitratePlaytimeCalculations(); - $this->CalculateCompressionRatioVideo(); - $this->CalculateCompressionRatioAudio(); - $this->CalculateReplayGain(); - $this->ProcessAudioStreams(); - } - - // get the MD5 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags - if ($this->option_md5_data) { - // do not cald md5_data if md5_data_source is present - set by flac only - future MPC/SV8 too - if (!$this->option_md5_data_source || empty($this->info['md5_data_source'])) { - $this->getHashdata('md5'); - } - } - - // get the SHA1 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags - if ($this->option_sha1_data) { - $this->getHashdata('sha1'); - } - - // remove undesired keys - $this->CleanUp(); - - } catch (Exception $e) { - if (isset($this->info['error'])) { - $this->info['error'][] = 'Caught exception: '.$e->getMessage(); - } else { - $this->info['error'] = array('Caught exception: '.$e->getMessage()); - } - } - - // return info array - return $this->info; - } - - - // private: error handling - function error($message) { - $this->CleanUp(); - - $this->info['error'][] = $message; - return $this->info; - } - - - // private: warning handling - function warning($message) { - $this->info['warning'][] = $message; - return true; - } - - - // private: CleanUp - function CleanUp() { - - // remove possible empty keys - $AVpossibleEmptyKeys = array('dataformat', 'bits_per_sample', 'encoder_options', 'streams', 'bitrate'); - foreach ($AVpossibleEmptyKeys as $dummy => $key) { - if (empty($this->info['audio'][$key]) && isset($this->info['audio'][$key])) { - unset($this->info['audio'][$key]); - } - if (empty($this->info['video'][$key]) && isset($this->info['video'][$key])) { - unset($this->info['video'][$key]); - } - } - - // remove empty root keys - if (!empty($this->info)) { - foreach ($this->info as $key => $value) { - if (empty($this->info[$key]) && ($this->info[$key] !== 0) && ($this->info[$key] !== '0')) { - unset($this->info[$key]); - } - } - } - - // remove meaningless entries from unknown-format files - if (empty($this->info['fileformat'])) { - if (isset($this->info['avdataoffset'])) { - unset($this->info['avdataoffset']); - } - if (isset($this->info['avdataend'])) { - unset($this->info['avdataend']); - } - } - } - - - // return array containing information about all supported formats - function GetFileFormatArray() { - static $format_info = array(); - if (empty($format_info)) { - $format_info = array( - - // Audio formats - - // AC-3 - audio - Dolby AC-3 / Dolby Digital - 'ac3' => array( - 'pattern' => '^\x0B\x77', - 'group' => 'audio', - 'module' => 'ac3', - 'mime_type' => 'audio/ac3', - ), - - // AAC - audio - Advanced Audio Coding (AAC) - ADIF format - 'adif' => array( - 'pattern' => '^ADIF', - 'group' => 'audio', - 'module' => 'aac', - 'option' => 'adif', - 'mime_type' => 'application/octet-stream', - 'fail_ape' => 'WARNING', - ), - - - // AA - audio - Audible Audiobook - 'adts' => array( - 'pattern' => '^.{4}\x57\x90\x75\x36', - 'group' => 'audio', - 'module' => 'aa', - 'mime_type' => 'audio/audible ', - ), - - // AAC - audio - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3) - 'adts' => array( - 'pattern' => '^\xFF[\xF0-\xF1\xF8-\xF9]', - 'group' => 'audio', - 'module' => 'aac', - 'option' => 'adts', - 'mime_type' => 'application/octet-stream', - 'fail_ape' => 'WARNING', - ), - - - // AU - audio - NeXT/Sun AUdio (AU) - 'au' => array( - 'pattern' => '^\.snd', - 'group' => 'audio', - 'module' => 'au', - 'mime_type' => 'audio/basic', - ), - - // AVR - audio - Audio Visual Research - 'avr' => array( - 'pattern' => '^2BIT', - 'group' => 'audio', - 'module' => 'avr', - 'mime_type' => 'application/octet-stream', - ), - - // BONK - audio - Bonk v0.9+ - 'bonk' => array( - 'pattern' => '^\x00(BONK|INFO|META| ID3)', - 'group' => 'audio', - 'module' => 'bonk', - 'mime_type' => 'audio/xmms-bonk', - ), - - // DSS - audio - Digital Speech Standard - 'dss' => array( - 'pattern' => '^[\x02-\x03]dss', - 'group' => 'audio', - 'module' => 'dss', - 'mime_type' => 'application/octet-stream', - ), - - // DTS - audio - Dolby Theatre System - 'dts' => array( - 'pattern' => '^\x7F\xFE\x80\x01', - 'group' => 'audio', - 'module' => 'dts', - 'mime_type' => 'audio/dts', - ), - - // FLAC - audio - Free Lossless Audio Codec - 'flac' => array( - 'pattern' => '^fLaC', - 'group' => 'audio', - 'module' => 'flac', - 'mime_type' => 'audio/x-flac', - ), - - // LA - audio - Lossless Audio (LA) - 'la' => array( - 'pattern' => '^LA0[2-4]', - 'group' => 'audio', - 'module' => 'la', - 'mime_type' => 'application/octet-stream', - ), - - // LPAC - audio - Lossless Predictive Audio Compression (LPAC) - 'lpac' => array( - 'pattern' => '^LPAC', - 'group' => 'audio', - 'module' => 'lpac', - 'mime_type' => 'application/octet-stream', - ), - - // MIDI - audio - MIDI (Musical Instrument Digital Interface) - 'midi' => array( - 'pattern' => '^MThd', - 'group' => 'audio', - 'module' => 'midi', - 'mime_type' => 'audio/midi', - ), - - // MAC - audio - Monkey's Audio Compressor - 'mac' => array( - 'pattern' => '^MAC ', - 'group' => 'audio', - 'module' => 'monkey', - 'mime_type' => 'application/octet-stream', - ), - -// has been known to produce false matches in random files (e.g. JPEGs), leave out until more precise matching available -// // MOD - audio - MODule (assorted sub-formats) -// 'mod' => array( -// 'pattern' => '^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)', -// 'group' => 'audio', -// 'module' => 'mod', -// 'option' => 'mod', -// 'mime_type' => 'audio/mod', -// ), - - // MOD - audio - MODule (Impulse Tracker) - 'it' => array( - 'pattern' => '^IMPM', - 'group' => 'audio', - 'module' => 'mod', - 'option' => 'it', - 'mime_type' => 'audio/it', - ), - - // MOD - audio - MODule (eXtended Module, various sub-formats) - 'xm' => array( - 'pattern' => '^Extended Module', - 'group' => 'audio', - 'module' => 'mod', - 'option' => 'xm', - 'mime_type' => 'audio/xm', - ), - - // MOD - audio - MODule (ScreamTracker) - 's3m' => array( - 'pattern' => '^.{44}SCRM', - 'group' => 'audio', - 'module' => 'mod', - 'option' => 's3m', - 'mime_type' => 'audio/s3m', - ), - - // MPC - audio - Musepack / MPEGplus - 'mpc' => array( - 'pattern' => '^(MPCK|MP\+|[\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0])', - 'group' => 'audio', - 'module' => 'mpc', - 'mime_type' => 'audio/x-musepack', - ), - - // MP3 - audio - MPEG-audio Layer 3 (very similar to AAC-ADTS) - 'mp3' => array( - 'pattern' => '^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\x0B\x10-\x1B\x20-\x2B\x30-\x3B\x40-\x4B\x50-\x5B\x60-\x6B\x70-\x7B\x80-\x8B\x90-\x9B\xA0-\xAB\xB0-\xBB\xC0-\xCB\xD0-\xDB\xE0-\xEB\xF0-\xFB]', - 'group' => 'audio', - 'module' => 'mp3', - 'mime_type' => 'audio/mpeg', - ), - - // OFR - audio - OptimFROG - 'ofr' => array( - 'pattern' => '^(\*RIFF|OFR)', - 'group' => 'audio', - 'module' => 'optimfrog', - 'mime_type' => 'application/octet-stream', - ), - - // RKAU - audio - RKive AUdio compressor - 'rkau' => array( - 'pattern' => '^RKA', - 'group' => 'audio', - 'module' => 'rkau', - 'mime_type' => 'application/octet-stream', - ), - - // SHN - audio - Shorten - 'shn' => array( - 'pattern' => '^ajkg', - 'group' => 'audio', - 'module' => 'shorten', - 'mime_type' => 'audio/xmms-shn', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // TTA - audio - TTA Lossless Audio Compressor (http://tta.corecodec.org) - 'tta' => array( - 'pattern' => '^TTA', // could also be '^TTA(\x01|\x02|\x03|2|1)' - 'group' => 'audio', - 'module' => 'tta', - 'mime_type' => 'application/octet-stream', - ), - - // VOC - audio - Creative Voice (VOC) - 'voc' => array( - 'pattern' => '^Creative Voice File', - 'group' => 'audio', - 'module' => 'voc', - 'mime_type' => 'audio/voc', - ), - - // VQF - audio - transform-domain weighted interleave Vector Quantization Format (VQF) - 'vqf' => array( - 'pattern' => '^TWIN', - 'group' => 'audio', - 'module' => 'vqf', - 'mime_type' => 'application/octet-stream', - ), - - // WV - audio - WavPack (v4.0+) - 'wv' => array( - 'pattern' => '^wvpk', - 'group' => 'audio', - 'module' => 'wavpack', - 'mime_type' => 'application/octet-stream', - ), - - - // Audio-Video formats - - // ASF - audio/video - Advanced Streaming Format, Windows Media Video, Windows Media Audio - 'asf' => array( - 'pattern' => '^\x30\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C', - 'group' => 'audio-video', - 'module' => 'asf', - 'mime_type' => 'video/x-ms-asf', - 'iconv_req' => false, - ), - - // BINK - audio/video - Bink / Smacker - 'bink' => array( - 'pattern' => '^(BIK|SMK)', - 'group' => 'audio-video', - 'module' => 'bink', - 'mime_type' => 'application/octet-stream', - ), - - // FLV - audio/video - FLash Video - 'flv' => array( - 'pattern' => '^FLV\x01', - 'group' => 'audio-video', - 'module' => 'flv', - 'mime_type' => 'video/x-flv', - ), - - // MKAV - audio/video - Mastroka - 'matroska' => array( - 'pattern' => '^\x1A\x45\xDF\xA3', - 'group' => 'audio-video', - 'module' => 'matroska', - 'mime_type' => 'video/x-matroska', // may also be audio/x-matroska - ), - - // MPEG - audio/video - MPEG (Moving Pictures Experts Group) - 'mpeg' => array( - 'pattern' => '^\x00\x00\x01(\xBA|\xB3)', - 'group' => 'audio-video', - 'module' => 'mpeg', - 'mime_type' => 'video/mpeg', - ), - - // NSV - audio/video - Nullsoft Streaming Video (NSV) - 'nsv' => array( - 'pattern' => '^NSV[sf]', - 'group' => 'audio-video', - 'module' => 'nsv', - 'mime_type' => 'application/octet-stream', - ), - - // Ogg - audio/video - Ogg (Ogg-Vorbis, Ogg-FLAC, Speex, Ogg-Theora(*), Ogg-Tarkin(*)) - 'ogg' => array( - 'pattern' => '^OggS', - 'group' => 'audio', - 'module' => 'ogg', - 'mime_type' => 'application/ogg', - 'fail_id3' => 'WARNING', - 'fail_ape' => 'WARNING', - ), - - // QT - audio/video - Quicktime - 'quicktime' => array( - 'pattern' => '^.{4}(cmov|free|ftyp|mdat|moov|pnot|skip|wide)', - 'group' => 'audio-video', - 'module' => 'quicktime', - 'mime_type' => 'video/quicktime', - ), - - // RIFF - audio/video - Resource Interchange File Format (RIFF) / WAV / AVI / CD-audio / SDSS = renamed variant used by SmartSound QuickTracks (www.smartsound.com) / FORM = Audio Interchange File Format (AIFF) - 'riff' => array( - 'pattern' => '^(RIFF|SDSS|FORM)', - 'group' => 'audio-video', - 'module' => 'riff', - 'mime_type' => 'audio/x-wave', - 'fail_ape' => 'WARNING', - ), - - // Real - audio/video - RealAudio, RealVideo - 'real' => array( - 'pattern' => '^(\\.RMF|\\.ra)', - 'group' => 'audio-video', - 'module' => 'real', - 'mime_type' => 'audio/x-realaudio', - ), - - // SWF - audio/video - ShockWave Flash - 'swf' => array( - 'pattern' => '^(F|C)WS', - 'group' => 'audio-video', - 'module' => 'swf', - 'mime_type' => 'application/x-shockwave-flash', - ), - - - // Still-Image formats - - // BMP - still image - Bitmap (Windows, OS/2; uncompressed, RLE8, RLE4) - 'bmp' => array( - 'pattern' => '^BM', - 'group' => 'graphic', - 'module' => 'bmp', - 'mime_type' => 'image/bmp', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // GIF - still image - Graphics Interchange Format - 'gif' => array( - 'pattern' => '^GIF', - 'group' => 'graphic', - 'module' => 'gif', - 'mime_type' => 'image/gif', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // JPEG - still image - Joint Photographic Experts Group (JPEG) - 'jpg' => array( - 'pattern' => '^\xFF\xD8\xFF', - 'group' => 'graphic', - 'module' => 'jpg', - 'mime_type' => 'image/jpeg', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // PCD - still image - Kodak Photo CD - 'pcd' => array( - 'pattern' => '^.{2048}PCD_IPI\x00', - 'group' => 'graphic', - 'module' => 'pcd', - 'mime_type' => 'image/x-photo-cd', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - - // PNG - still image - Portable Network Graphics (PNG) - 'png' => array( - 'pattern' => '^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A', - 'group' => 'graphic', - 'module' => 'png', - 'mime_type' => 'image/png', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - - // SVG - still image - Scalable Vector Graphics (SVG) - 'svg' => array( - 'pattern' => '( 'graphic', - 'module' => 'svg', - 'mime_type' => 'image/svg+xml', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - - // TIFF - still image - Tagged Information File Format (TIFF) - 'tiff' => array( - 'pattern' => '^(II\x2A\x00|MM\x00\x2A)', - 'group' => 'graphic', - 'module' => 'tiff', - 'mime_type' => 'image/tiff', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - - // Data formats - - // ISO - data - International Standards Organization (ISO) CD-ROM Image - 'iso' => array( - 'pattern' => '^.{32769}CD001', - 'group' => 'misc', - 'module' => 'iso', - 'mime_type' => 'application/octet-stream', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - 'iconv_req' => false, - ), - - // RAR - data - RAR compressed data - 'rar' => array( - 'pattern' => '^Rar\!', - 'group' => 'archive', - 'module' => 'rar', - 'mime_type' => 'application/octet-stream', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // SZIP - audio/data - SZIP compressed data - 'szip' => array( - 'pattern' => '^SZ\x0A\x04', - 'group' => 'archive', - 'module' => 'szip', - 'mime_type' => 'application/octet-stream', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // TAR - data - TAR compressed data - 'tar' => array( - 'pattern' => '^.{100}[0-9\x20]{7}\x00[0-9\x20]{7}\x00[0-9\x20]{7}\x00[0-9\x20\x00]{12}[0-9\x20\x00]{12}', - 'group' => 'archive', - 'module' => 'tar', - 'mime_type' => 'application/x-tar', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // GZIP - data - GZIP compressed data - 'gz' => array( - 'pattern' => '^\x1F\x8B\x08', - 'group' => 'archive', - 'module' => 'gzip', - 'mime_type' => 'application/x-gzip', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // ZIP - data - ZIP compressed data - 'zip' => array( - 'pattern' => '^PK\x03\x04', - 'group' => 'archive', - 'module' => 'zip', - 'mime_type' => 'application/zip', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - - // Misc other formats - - // PAR2 - data - Parity Volume Set Specification 2.0 - 'par2' => array ( - 'pattern' => '^PAR2\x00PKT', - 'group' => 'misc', - 'module' => 'par2', - 'mime_type' => 'application/octet-stream', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // PDF - data - Portable Document Format - 'pdf' => array( - 'pattern' => '^\x25PDF', - 'group' => 'misc', - 'module' => 'pdf', - 'mime_type' => 'application/pdf', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // MSOFFICE - data - ZIP compressed data - 'msoffice' => array( - 'pattern' => '^\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1', // D0CF11E == DOCFILE == Microsoft Office Document - 'group' => 'misc', - 'module' => 'msoffice', - 'mime_type' => 'application/octet-stream', - 'fail_id3' => 'ERROR', - 'fail_ape' => 'ERROR', - ), - - // CUE - data - CUEsheet (index to single-file disc images) - 'cue' => array( - 'pattern' => '', // empty pattern means cannot be automatically detected, will fall through all other formats and match based on filename and very basic file contents - 'group' => 'misc', - 'module' => 'cue', - 'mime_type' => 'application/octet-stream', - ), - - ); - } - - return $format_info; - } - - - - function GetFileFormat(&$filedata, $filename='') { - // this function will determine the format of a file based on usually - // the first 2-4 bytes of the file (8 bytes for PNG, 16 bytes for JPG, - // and in the case of ISO CD image, 6 bytes offset 32kb from the start - // of the file). - - // Identify file format - loop through $format_info and detect with reg expr - foreach ($this->GetFileFormatArray() as $format_name => $info) { - // The /s switch on preg_match() forces preg_match() NOT to treat - // newline (0x0A) characters as special chars but do a binary match - if (!empty($info['pattern']) && preg_match('#'.$info['pattern'].'#s', $filedata)) { - $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php'; - return $info; - } - } - - - if (preg_match('#\.mp[123a]$#i', $filename)) { - // Too many mp3 encoders on the market put gabage in front of mpeg files - // use assume format on these if format detection failed - $GetFileFormatArray = $this->GetFileFormatArray(); - $info = $GetFileFormatArray['mp3']; - $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php'; - return $info; - } elseif (preg_match('/\.cue$/i', $filename) && preg_match('#FILE "[^"]+" (BINARY|MOTOROLA|AIFF|WAVE|MP3)#', $filedata)) { - // there's not really a useful consistent "magic" at the beginning of .cue files to identify them - // so until I think of something better, just go by filename if all other format checks fail - // and verify there's at least one instance of "TRACK xx AUDIO" in the file - $GetFileFormatArray = $this->GetFileFormatArray(); - $info = $GetFileFormatArray['cue']; - $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php'; - return $info; - } - - return false; - } - - - // converts array to $encoding charset from $this->encoding - function CharConvert(&$array, $encoding) { - - // identical encoding - end here - if ($encoding == $this->encoding) { - return; - } - - // loop thru array - foreach ($array as $key => $value) { - - // go recursive - if (is_array($value)) { - $this->CharConvert($array[$key], $encoding); - } - - // convert string - elseif (is_string($value)) { - $array[$key] = trim(getid3_lib::iconv_fallback($encoding, $this->encoding, $value)); - } - } - } - - - function HandleAllTags() { - - // key name => array (tag name, character encoding) - static $tags; - if (empty($tags)) { - $tags = array( - 'asf' => array('asf' , 'UTF-16LE'), - 'midi' => array('midi' , 'ISO-8859-1'), - 'nsv' => array('nsv' , 'ISO-8859-1'), - 'ogg' => array('vorbiscomment' , 'UTF-8'), - 'png' => array('png' , 'UTF-8'), - 'tiff' => array('tiff' , 'ISO-8859-1'), - 'quicktime' => array('quicktime' , 'UTF-8'), - 'real' => array('real' , 'ISO-8859-1'), - 'vqf' => array('vqf' , 'ISO-8859-1'), - 'zip' => array('zip' , 'ISO-8859-1'), - 'riff' => array('riff' , 'ISO-8859-1'), - 'lyrics3' => array('lyrics3' , 'ISO-8859-1'), - 'id3v1' => array('id3v1' , $this->encoding_id3v1), - 'id3v2' => array('id3v2' , 'UTF-8'), // not according to the specs (every frame can have a different encoding), but getID3() force-converts all encodings to UTF-8 - 'ape' => array('ape' , 'UTF-8'), - 'cue' => array('cue' , 'ISO-8859-1'), - ); - } - - // loop thru comments array - foreach ($tags as $comment_name => $tagname_encoding_array) { - list($tag_name, $encoding) = $tagname_encoding_array; - - // fill in default encoding type if not already present - if (isset($this->info[$comment_name]) && !isset($this->info[$comment_name]['encoding'])) { - $this->info[$comment_name]['encoding'] = $encoding; - } - - // copy comments if key name set - if (!empty($this->info[$comment_name]['comments'])) { - - foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) { - foreach ($valuearray as $key => $value) { - $value = (is_string($value) ? trim($value) : $value); - if (!empty($value) > 0) { - $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value; // do not trim!! Unicode characters will get mangled if trailing nulls are removed! - } - } - } - - if (!isset($this->info['tags'][$tag_name])) { - // comments are set but contain nothing but empty strings, so skip - continue; - } - - if ($this->option_tags_html) { - foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) { - foreach ($valuearray as $key => $value) { - if (is_string($value)) { - //$this->info['tags_html'][$tag_name][$tag_key][$key] = getid3_lib::MultiByteCharString2HTML($value, $encoding); - $this->info['tags_html'][$tag_name][$tag_key][$key] = str_replace('�', '', getid3_lib::MultiByteCharString2HTML($value, $encoding)); - } else { - $this->info['tags_html'][$tag_name][$tag_key][$key] = $value; - } - } - } - } - - $this->CharConvert($this->info['tags'][$tag_name], $encoding); // only copy gets converted! - } - - } - return true; - } - - - function getHashdata($algorithm) { - switch ($algorithm) { - case 'md5': - case 'sha1': - break; - - default: - return $this->error('bad algorithm "'.$algorithm.'" in getHashdata()'); - break; - } - - if (!empty($this->info['fileformat']) && !empty($this->info['dataformat']) && ($this->info['fileformat'] == 'ogg') && ($this->info['audio']['dataformat'] == 'vorbis')) { - - // We cannot get an identical md5_data value for Ogg files where the comments - // span more than 1 Ogg page (compared to the same audio data with smaller - // comments) using the normal getID3() method of MD5'ing the data between the - // end of the comments and the end of the file (minus any trailing tags), - // because the page sequence numbers of the pages that the audio data is on - // do not match. Under normal circumstances, where comments are smaller than - // the nominal 4-8kB page size, then this is not a problem, but if there are - // very large comments, the only way around it is to strip off the comment - // tags with vorbiscomment and MD5 that file. - // This procedure must be applied to ALL Ogg files, not just the ones with - // comments larger than 1 page, because the below method simply MD5's the - // whole file with the comments stripped, not just the portion after the - // comments block (which is the standard getID3() method. - - // The above-mentioned problem of comments spanning multiple pages and changing - // page sequence numbers likely happens for OggSpeex and OggFLAC as well, but - // currently vorbiscomment only works on OggVorbis files. - - if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { - - $this->info['warning'][] = 'Failed making system call to vorbiscomment.exe - '.$algorithm.'_data is incorrect - error returned: PHP running in Safe Mode (backtick operator not available)'; - $this->info[$algorithm.'_data'] = false; - - } else { - - // Prevent user from aborting script - $old_abort = ignore_user_abort(true); - - // Create empty file - $empty = tempnam(GETID3_TEMP_DIR, 'getID3'); - touch($empty); - - // Use vorbiscomment to make temp file without comments - $temp = tempnam(GETID3_TEMP_DIR, 'getID3'); - $file = $this->info['filenamepath']; - - if (GETID3_OS_ISWINDOWS) { - - if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) { - - $commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w -c "'.$empty.'" "'.$file.'" "'.$temp.'"'; - $VorbisCommentError = `$commandline`; - - } else { - - $VorbisCommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR; - - } - - } else { - - $commandline = 'vorbiscomment -w -c "'.$empty.'" "'.$file.'" "'.$temp.'" 2>&1'; - $commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1'; - $VorbisCommentError = `$commandline`; - - } - - if (!empty($VorbisCommentError)) { - - $this->info['warning'][] = 'Failed making system call to vorbiscomment(.exe) - '.$algorithm.'_data will be incorrect. If vorbiscomment is unavailable, please download from http://www.vorbis.com/download.psp and put in the getID3() directory. Error returned: '.$VorbisCommentError; - $this->info[$algorithm.'_data'] = false; - - } else { - - // Get hash of newly created file - switch ($algorithm) { - case 'md5': - $this->info[$algorithm.'_data'] = md5_file($temp); - break; - - case 'sha1': - $this->info[$algorithm.'_data'] = sha1_file($temp); - break; - } - } - - // Clean up - unlink($empty); - unlink($temp); - - // Reset abort setting - ignore_user_abort($old_abort); - - } - - } else { - - if (!empty($this->info['avdataoffset']) || (isset($this->info['avdataend']) && ($this->info['avdataend'] < $this->info['filesize']))) { - - // get hash from part of file - $this->info[$algorithm.'_data'] = getid3_lib::hash_data($this->info['filenamepath'], $this->info['avdataoffset'], $this->info['avdataend'], $algorithm); - - } else { - - // get hash from whole file - switch ($algorithm) { - case 'md5': - $this->info[$algorithm.'_data'] = md5_file($this->info['filenamepath']); - break; - - case 'sha1': - $this->info[$algorithm.'_data'] = sha1_file($this->info['filenamepath']); - break; - } - } - - } - return true; - } - - - function ChannelsBitratePlaytimeCalculations() { - - // set channelmode on audio - if (!isset($this->info['audio']['channels'])) { - // ignore - } elseif ($this->info['audio']['channels'] == 1) { - $this->info['audio']['channelmode'] = 'mono'; - } elseif ($this->info['audio']['channels'] == 2) { - $this->info['audio']['channelmode'] = 'stereo'; - } - - // Calculate combined bitrate - audio + video - $CombinedBitrate = 0; - $CombinedBitrate += (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : 0); - $CombinedBitrate += (isset($this->info['video']['bitrate']) ? $this->info['video']['bitrate'] : 0); - if (($CombinedBitrate > 0) && empty($this->info['bitrate'])) { - $this->info['bitrate'] = $CombinedBitrate; - } - //if ((isset($this->info['video']) && !isset($this->info['video']['bitrate'])) || (isset($this->info['audio']) && !isset($this->info['audio']['bitrate']))) { - // // for example, VBR MPEG video files cannot determine video bitrate: - // // should not set overall bitrate and playtime from audio bitrate only - // unset($this->info['bitrate']); - //} - - // video bitrate undetermined, but calculable - if (isset($this->info['video']['dataformat']) && $this->info['video']['dataformat'] && (!isset($this->info['video']['bitrate']) || ($this->info['video']['bitrate'] == 0))) { - // if video bitrate not set - if (isset($this->info['audio']['bitrate']) && ($this->info['audio']['bitrate'] > 0) && ($this->info['audio']['bitrate'] == $this->info['bitrate'])) { - // AND if audio bitrate is set to same as overall bitrate - if (isset($this->info['playtime_seconds']) && ($this->info['playtime_seconds'] > 0)) { - // AND if playtime is set - if (isset($this->info['avdataend']) && isset($this->info['avdataoffset'])) { - // AND if AV data offset start/end is known - // THEN we can calculate the video bitrate - $this->info['bitrate'] = round((($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds']); - $this->info['video']['bitrate'] = $this->info['bitrate'] - $this->info['audio']['bitrate']; - } - } - } - } - - if ((!isset($this->info['playtime_seconds']) || ($this->info['playtime_seconds'] <= 0)) && !empty($this->info['bitrate'])) { - $this->info['playtime_seconds'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['bitrate']; - } - - if (!isset($this->info['bitrate']) && !empty($this->info['playtime_seconds'])) { - $this->info['bitrate'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds']; - } - if (isset($this->info['bitrate']) && empty($this->info['audio']['bitrate']) && empty($this->info['video']['bitrate'])) { - if (isset($this->info['audio']['dataformat']) && empty($this->info['video']['resolution_x'])) { - // audio only - $this->info['audio']['bitrate'] = $this->info['bitrate']; - } elseif (isset($this->info['video']['resolution_x']) && empty($this->info['audio']['dataformat'])) { - // video only - $this->info['video']['bitrate'] = $this->info['bitrate']; - } - } - - // Set playtime string - if (!empty($this->info['playtime_seconds']) && empty($this->info['playtime_string'])) { - $this->info['playtime_string'] = getid3_lib::PlaytimeString($this->info['playtime_seconds']); - } - } - - - function CalculateCompressionRatioVideo() { - if (empty($this->info['video'])) { - return false; - } - if (empty($this->info['video']['resolution_x']) || empty($this->info['video']['resolution_y'])) { - return false; - } - if (empty($this->info['video']['bits_per_sample'])) { - return false; - } - - switch ($this->info['video']['dataformat']) { - case 'bmp': - case 'gif': - case 'jpeg': - case 'jpg': - case 'png': - case 'tiff': - $FrameRate = 1; - $PlaytimeSeconds = 1; - $BitrateCompressed = $this->info['filesize'] * 8; - break; - - default: - if (!empty($this->info['video']['frame_rate'])) { - $FrameRate = $this->info['video']['frame_rate']; - } else { - return false; - } - if (!empty($this->info['playtime_seconds'])) { - $PlaytimeSeconds = $this->info['playtime_seconds']; - } else { - return false; - } - if (!empty($this->info['video']['bitrate'])) { - $BitrateCompressed = $this->info['video']['bitrate']; - } else { - return false; - } - break; - } - $BitrateUncompressed = $this->info['video']['resolution_x'] * $this->info['video']['resolution_y'] * $this->info['video']['bits_per_sample'] * $FrameRate; - - $this->info['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed; - return true; - } - - - function CalculateCompressionRatioAudio() { - if (empty($this->info['audio']['bitrate']) || empty($this->info['audio']['channels']) || empty($this->info['audio']['sample_rate'])) { - return false; - } - $this->info['audio']['compression_ratio'] = $this->info['audio']['bitrate'] / ($this->info['audio']['channels'] * $this->info['audio']['sample_rate'] * (!empty($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : 16)); - - if (!empty($this->info['audio']['streams'])) { - foreach ($this->info['audio']['streams'] as $streamnumber => $streamdata) { - if (!empty($streamdata['bitrate']) && !empty($streamdata['channels']) && !empty($streamdata['sample_rate'])) { - $this->info['audio']['streams'][$streamnumber]['compression_ratio'] = $streamdata['bitrate'] / ($streamdata['channels'] * $streamdata['sample_rate'] * (!empty($streamdata['bits_per_sample']) ? $streamdata['bits_per_sample'] : 16)); - } - } - } - return true; - } - - - function CalculateReplayGain() { - if (isset($this->info['replay_gain'])) { - $this->info['replay_gain']['reference_volume'] = 89; - if (isset($this->info['replay_gain']['track']['adjustment'])) { - $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment']; - } - if (isset($this->info['replay_gain']['album']['adjustment'])) { - $this->info['replay_gain']['album']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['album']['adjustment']; - } - - if (isset($this->info['replay_gain']['track']['peak'])) { - $this->info['replay_gain']['track']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['track']['peak']); - } - if (isset($this->info['replay_gain']['album']['peak'])) { - $this->info['replay_gain']['album']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['album']['peak']); - } - } - return true; - } - - function ProcessAudioStreams() { - if (!empty($this->info['audio']['bitrate']) || !empty($this->info['audio']['channels']) || !empty($this->info['audio']['sample_rate'])) { - if (!isset($this->info['audio']['streams'])) { - foreach ($this->info['audio'] as $key => $value) { - if ($key != 'streams') { - $this->info['audio']['streams'][0][$key] = $value; - } - } - } - } - return true; - } - - function getid3_tempnam() { - return tempnam($this->tempdir, 'gI3'); - } - -} - - -class getid3_exception extends Exception -{ - public $message; -} - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.archive.rar.php b/serendipity_event_podcast/player/getid3/module.archive.rar.php deleted file mode 100644 index 27dcc13a..00000000 --- a/serendipity_event_podcast/player/getid3/module.archive.rar.php +++ /dev/null @@ -1,52 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.archive.rar.php // -// module for analyzing RAR files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_rar -{ - - var $option_use_rar_extension = false; - - function getid3_rar(&$fd, &$ThisFileInfo) { - - $ThisFileInfo['fileformat'] = 'rar'; - - if ($this->option_use_rar_extension === true) { - if (function_exists('rar_open')) { - if ($rp = rar_open($ThisFileInfo['filenamepath'])) { - $ThisFileInfo['rar']['files'] = array(); - $entries = rar_list($rp); - foreach ($entries as $entry) { - $ThisFileInfo['rar']['files'] = getid3_lib::array_merge_clobber($ThisFileInfo['rar']['files'], getid3_lib::CreateDeepArray($entry->getName(), '/', $entry->getUnpackedSize())); - } - rar_close($rp); - return true; - } else { - $ThisFileInfo['error'][] = 'failed to rar_open('.$ThisFileInfo['filename'].')'; - } - } else { - $ThisFileInfo['error'][] = 'RAR support does not appear to be available in this PHP installation'; - } - } else { - $ThisFileInfo['error'][] = 'PHP-RAR processing has been disabled (set $getid3_rar->option_use_rar_extension=true to enable)'; - } - return false; - - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.archive.zip.php b/serendipity_event_podcast/player/getid3/module.archive.zip.php deleted file mode 100644 index 38bc199c..00000000 --- a/serendipity_event_podcast/player/getid3/module.archive.zip.php +++ /dev/null @@ -1,419 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.archive.zip.php // -// module for analyzing pkZip files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_zip -{ - - function getid3_zip(&$fd, &$ThisFileInfo) { - - $ThisFileInfo['fileformat'] = 'zip'; - $ThisFileInfo['zip']['encoding'] = 'ISO-8859-1'; - $ThisFileInfo['zip']['files'] = array(); - - $ThisFileInfo['zip']['compressed_size'] = 0; - $ThisFileInfo['zip']['uncompressed_size'] = 0; - $ThisFileInfo['zip']['entries_count'] = 0; - - if (!getid3_lib::intValueSupported($ThisFileInfo['filesize'])) { - $ThisFileInfo['error'][] = 'File is larger than '.round(PHP_INT_MAX / 1073741824).'GB, not supported by PHP'; - return false; - } else { - $EOCDsearchData = ''; - $EOCDsearchCounter = 0; - while ($EOCDsearchCounter++ < 512) { - - fseek($fd, -128 * $EOCDsearchCounter, SEEK_END); - $EOCDsearchData = fread($fd, 128).$EOCDsearchData; - - if (strstr($EOCDsearchData, 'PK'."\x05\x06")) { - - $EOCDposition = strpos($EOCDsearchData, 'PK'."\x05\x06"); - fseek($fd, (-128 * $EOCDsearchCounter) + $EOCDposition, SEEK_END); - $ThisFileInfo['zip']['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory($fd); - - fseek($fd, $ThisFileInfo['zip']['end_central_directory']['directory_offset'], SEEK_SET); - $ThisFileInfo['zip']['entries_count'] = 0; - while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($fd)) { - $ThisFileInfo['zip']['central_directory'][] = $centraldirectoryentry; - $ThisFileInfo['zip']['entries_count']++; - $ThisFileInfo['zip']['compressed_size'] += $centraldirectoryentry['compressed_size']; - $ThisFileInfo['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size']; - - if ($centraldirectoryentry['uncompressed_size'] > 0) { - $ThisFileInfo['zip']['files'] = getid3_lib::array_merge_clobber($ThisFileInfo['zip']['files'], getid3_lib::CreateDeepArray($centraldirectoryentry['filename'], '/', $centraldirectoryentry['uncompressed_size'])); - } - } - - if ($ThisFileInfo['zip']['entries_count'] == 0) { - $ThisFileInfo['error'][] = 'No Central Directory entries found (truncated file?)'; - return false; - } - - if (!empty($ThisFileInfo['zip']['end_central_directory']['comment'])) { - $ThisFileInfo['zip']['comments']['comment'][] = $ThisFileInfo['zip']['end_central_directory']['comment']; - } - - if (isset($ThisFileInfo['zip']['central_directory'][0]['compression_method'])) { - $ThisFileInfo['zip']['compression_method'] = $ThisFileInfo['zip']['central_directory'][0]['compression_method']; - } - if (isset($ThisFileInfo['zip']['central_directory'][0]['flags']['compression_speed'])) { - $ThisFileInfo['zip']['compression_speed'] = $ThisFileInfo['zip']['central_directory'][0]['flags']['compression_speed']; - } - if (isset($ThisFileInfo['zip']['compression_method']) && ($ThisFileInfo['zip']['compression_method'] == 'store') && !isset($ThisFileInfo['zip']['compression_speed'])) { - $ThisFileInfo['zip']['compression_speed'] = 'store'; - } - - return true; - - } - } - } - - if ($this->getZIPentriesFilepointer($fd, $ThisFileInfo)) { - - // central directory couldn't be found and/or parsed - // scan through actual file data entries, recover as much as possible from probable trucated file - if ($ThisFileInfo['zip']['compressed_size'] > ($ThisFileInfo['filesize'] - 46 - 22)) { - $ThisFileInfo['error'][] = 'Warning: Truncated file! - Total compressed file sizes ('.$ThisFileInfo['zip']['compressed_size'].' bytes) is greater than filesize minus Central Directory and End Of Central Directory structures ('.($ThisFileInfo['filesize'] - 46 - 22).' bytes)'; - } - $ThisFileInfo['error'][] = 'Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete'; - foreach ($ThisFileInfo['zip']['entries'] as $key => $valuearray) { - $ThisFileInfo['zip']['files'][$valuearray['filename']] = $valuearray['uncompressed_size']; - } - return true; - - } else { - - unset($ThisFileInfo['zip']); - $ThisFileInfo['fileformat'] = ''; - $ThisFileInfo['error'][] = 'Cannot find End Of Central Directory (truncated file?)'; - return false; - - } - } - - - function getZIPHeaderFilepointerTopDown(&$fd, &$ThisFileInfo) { - $ThisFileInfo['fileformat'] = 'zip'; - - $ThisFileInfo['zip']['compressed_size'] = 0; - $ThisFileInfo['zip']['uncompressed_size'] = 0; - $ThisFileInfo['zip']['entries_count'] = 0; - - rewind($fd); - while ($fileentry = $this->ZIPparseLocalFileHeader($fd)) { - $ThisFileInfo['zip']['entries'][] = $fileentry; - $ThisFileInfo['zip']['entries_count']++; - } - if ($ThisFileInfo['zip']['entries_count'] == 0) { - $ThisFileInfo['error'][] = 'No Local File Header entries found'; - return false; - } - - $ThisFileInfo['zip']['entries_count'] = 0; - while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($fd)) { - $ThisFileInfo['zip']['central_directory'][] = $centraldirectoryentry; - $ThisFileInfo['zip']['entries_count']++; - $ThisFileInfo['zip']['compressed_size'] += $centraldirectoryentry['compressed_size']; - $ThisFileInfo['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size']; - } - if ($ThisFileInfo['zip']['entries_count'] == 0) { - $ThisFileInfo['error'][] = 'No Central Directory entries found (truncated file?)'; - return false; - } - - if ($EOCD = $this->ZIPparseEndOfCentralDirectory($fd)) { - $ThisFileInfo['zip']['end_central_directory'] = $EOCD; - } else { - $ThisFileInfo['error'][] = 'No End Of Central Directory entry found (truncated file?)'; - return false; - } - - if (!empty($ThisFileInfo['zip']['end_central_directory']['comment'])) { - $ThisFileInfo['zip']['comments']['comment'][] = $ThisFileInfo['zip']['end_central_directory']['comment']; - } - - return true; - } - - - function getZIPentriesFilepointer(&$fd, &$ThisFileInfo) { - $ThisFileInfo['zip']['compressed_size'] = 0; - $ThisFileInfo['zip']['uncompressed_size'] = 0; - $ThisFileInfo['zip']['entries_count'] = 0; - - rewind($fd); - while ($fileentry = $this->ZIPparseLocalFileHeader($fd)) { - $ThisFileInfo['zip']['entries'][] = $fileentry; - $ThisFileInfo['zip']['entries_count']++; - $ThisFileInfo['zip']['compressed_size'] += $fileentry['compressed_size']; - $ThisFileInfo['zip']['uncompressed_size'] += $fileentry['uncompressed_size']; - } - if ($ThisFileInfo['zip']['entries_count'] == 0) { - $ThisFileInfo['error'][] = 'No Local File Header entries found'; - return false; - } - - return true; - } - - - function ZIPparseLocalFileHeader(&$fd) { - $LocalFileHeader['offset'] = ftell($fd); - - $ZIPlocalFileHeader = fread($fd, 30); - - $LocalFileHeader['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 0, 4)); - if ($LocalFileHeader['raw']['signature'] != 0x04034B50) { - // invalid Local File Header Signature - fseek($fd, $LocalFileHeader['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly - return false; - } - $LocalFileHeader['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 4, 2)); - $LocalFileHeader['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 6, 2)); - $LocalFileHeader['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 8, 2)); - $LocalFileHeader['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 10, 2)); - $LocalFileHeader['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 12, 2)); - $LocalFileHeader['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 14, 4)); - $LocalFileHeader['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 18, 4)); - $LocalFileHeader['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 22, 4)); - $LocalFileHeader['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 26, 2)); - $LocalFileHeader['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 28, 2)); - - $LocalFileHeader['extract_version'] = sprintf('%1.1f', $LocalFileHeader['raw']['extract_version'] / 10); - $LocalFileHeader['host_os'] = $this->ZIPversionOSLookup(($LocalFileHeader['raw']['extract_version'] & 0xFF00) >> 8); - $LocalFileHeader['compression_method'] = $this->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']); - $LocalFileHeader['compressed_size'] = $LocalFileHeader['raw']['compressed_size']; - $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['raw']['uncompressed_size']; - $LocalFileHeader['flags'] = $this->ZIPparseGeneralPurposeFlags($LocalFileHeader['raw']['general_flags'], $LocalFileHeader['raw']['compression_method']); - $LocalFileHeader['last_modified_timestamp'] = $this->DOStime2UNIXtime($LocalFileHeader['raw']['last_mod_file_date'], $LocalFileHeader['raw']['last_mod_file_time']); - - $FilenameExtrafieldLength = $LocalFileHeader['raw']['filename_length'] + $LocalFileHeader['raw']['extra_field_length']; - if ($FilenameExtrafieldLength > 0) { - $ZIPlocalFileHeader .= fread($fd, $FilenameExtrafieldLength); - - if ($LocalFileHeader['raw']['filename_length'] > 0) { - $LocalFileHeader['filename'] = substr($ZIPlocalFileHeader, 30, $LocalFileHeader['raw']['filename_length']); - } - if ($LocalFileHeader['raw']['extra_field_length'] > 0) { - $LocalFileHeader['raw']['extra_field_data'] = substr($ZIPlocalFileHeader, 30 + $LocalFileHeader['raw']['filename_length'], $LocalFileHeader['raw']['extra_field_length']); - } - } - - $LocalFileHeader['data_offset'] = ftell($fd); - //$LocalFileHeader['compressed_data'] = fread($fd, $LocalFileHeader['raw']['compressed_size']); - fseek($fd, $LocalFileHeader['raw']['compressed_size'], SEEK_CUR); - - if ($LocalFileHeader['flags']['data_descriptor_used']) { - $DataDescriptor = fread($fd, 12); - $LocalFileHeader['data_descriptor']['crc_32'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 0, 4)); - $LocalFileHeader['data_descriptor']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 4, 4)); - $LocalFileHeader['data_descriptor']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 8, 4)); - } - - return $LocalFileHeader; - } - - - function ZIPparseCentralDirectory(&$fd) { - $CentralDirectory['offset'] = ftell($fd); - - $ZIPcentralDirectory = fread($fd, 46); - - $CentralDirectory['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 0, 4)); - if ($CentralDirectory['raw']['signature'] != 0x02014B50) { - // invalid Central Directory Signature - fseek($fd, $CentralDirectory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly - return false; - } - $CentralDirectory['raw']['create_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 4, 2)); - $CentralDirectory['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 6, 2)); - $CentralDirectory['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 8, 2)); - $CentralDirectory['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 10, 2)); - $CentralDirectory['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 12, 2)); - $CentralDirectory['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 14, 2)); - $CentralDirectory['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 16, 4)); - $CentralDirectory['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 20, 4)); - $CentralDirectory['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 24, 4)); - $CentralDirectory['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 28, 2)); - $CentralDirectory['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 30, 2)); - $CentralDirectory['raw']['file_comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 32, 2)); - $CentralDirectory['raw']['disk_number_start'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 34, 2)); - $CentralDirectory['raw']['internal_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 36, 2)); - $CentralDirectory['raw']['external_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 38, 4)); - $CentralDirectory['raw']['local_header_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 42, 4)); - - $CentralDirectory['entry_offset'] = $CentralDirectory['raw']['local_header_offset']; - $CentralDirectory['create_version'] = sprintf('%1.1f', $CentralDirectory['raw']['create_version'] / 10); - $CentralDirectory['extract_version'] = sprintf('%1.1f', $CentralDirectory['raw']['extract_version'] / 10); - $CentralDirectory['host_os'] = $this->ZIPversionOSLookup(($CentralDirectory['raw']['extract_version'] & 0xFF00) >> 8); - $CentralDirectory['compression_method'] = $this->ZIPcompressionMethodLookup($CentralDirectory['raw']['compression_method']); - $CentralDirectory['compressed_size'] = $CentralDirectory['raw']['compressed_size']; - $CentralDirectory['uncompressed_size'] = $CentralDirectory['raw']['uncompressed_size']; - $CentralDirectory['flags'] = $this->ZIPparseGeneralPurposeFlags($CentralDirectory['raw']['general_flags'], $CentralDirectory['raw']['compression_method']); - $CentralDirectory['last_modified_timestamp'] = $this->DOStime2UNIXtime($CentralDirectory['raw']['last_mod_file_date'], $CentralDirectory['raw']['last_mod_file_time']); - - $FilenameExtrafieldCommentLength = $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'] + $CentralDirectory['raw']['file_comment_length']; - if ($FilenameExtrafieldCommentLength > 0) { - $FilenameExtrafieldComment = fread($fd, $FilenameExtrafieldCommentLength); - - if ($CentralDirectory['raw']['filename_length'] > 0) { - $CentralDirectory['filename'] = substr($FilenameExtrafieldComment, 0, $CentralDirectory['raw']['filename_length']); - } - if ($CentralDirectory['raw']['extra_field_length'] > 0) { - $CentralDirectory['raw']['extra_field_data'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'], $CentralDirectory['raw']['extra_field_length']); - } - if ($CentralDirectory['raw']['file_comment_length'] > 0) { - $CentralDirectory['file_comment'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'], $CentralDirectory['raw']['file_comment_length']); - } - } - - return $CentralDirectory; - } - - function ZIPparseEndOfCentralDirectory(&$fd) { - $EndOfCentralDirectory['offset'] = ftell($fd); - - $ZIPendOfCentralDirectory = fread($fd, 22); - - $EndOfCentralDirectory['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 0, 4)); - if ($EndOfCentralDirectory['signature'] != 0x06054B50) { - // invalid End Of Central Directory Signature - fseek($fd, $EndOfCentralDirectory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly - return false; - } - $EndOfCentralDirectory['disk_number_current'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 4, 2)); - $EndOfCentralDirectory['disk_number_start_directory'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 6, 2)); - $EndOfCentralDirectory['directory_entries_this_disk'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 8, 2)); - $EndOfCentralDirectory['directory_entries_total'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 10, 2)); - $EndOfCentralDirectory['directory_size'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 12, 4)); - $EndOfCentralDirectory['directory_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 16, 4)); - $EndOfCentralDirectory['comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 20, 2)); - - if ($EndOfCentralDirectory['comment_length'] > 0) { - $EndOfCentralDirectory['comment'] = fread($fd, $EndOfCentralDirectory['comment_length']); - } - - return $EndOfCentralDirectory; - } - - - function ZIPparseGeneralPurposeFlags($flagbytes, $compressionmethod) { - $ParsedFlags['encrypted'] = (bool) ($flagbytes & 0x0001); - - switch ($compressionmethod) { - case 6: - $ParsedFlags['dictionary_size'] = (($flagbytes & 0x0002) ? 8192 : 4096); - $ParsedFlags['shannon_fano_trees'] = (($flagbytes & 0x0004) ? 3 : 2); - break; - - case 8: - case 9: - switch (($flagbytes & 0x0006) >> 1) { - case 0: - $ParsedFlags['compression_speed'] = 'normal'; - break; - case 1: - $ParsedFlags['compression_speed'] = 'maximum'; - break; - case 2: - $ParsedFlags['compression_speed'] = 'fast'; - break; - case 3: - $ParsedFlags['compression_speed'] = 'superfast'; - break; - } - break; - } - $ParsedFlags['data_descriptor_used'] = (bool) ($flagbytes & 0x0008); - - return $ParsedFlags; - } - - - function ZIPversionOSLookup($index) { - static $ZIPversionOSLookup = array( - 0 => 'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)', - 1 => 'Amiga', - 2 => 'OpenVMS', - 3 => 'Unix', - 4 => 'VM/CMS', - 5 => 'Atari ST', - 6 => 'OS/2 H.P.F.S.', - 7 => 'Macintosh', - 8 => 'Z-System', - 9 => 'CP/M', - 10 => 'Windows NTFS', - 11 => 'MVS', - 12 => 'VSE', - 13 => 'Acorn Risc', - 14 => 'VFAT', - 15 => 'Alternate MVS', - 16 => 'BeOS', - 17 => 'Tandem' - ); - - return (isset($ZIPversionOSLookup[$index]) ? $ZIPversionOSLookup[$index] : '[unknown]'); - } - - function ZIPcompressionMethodLookup($index) { - static $ZIPcompressionMethodLookup = array( - 0 => 'store', - 1 => 'shrink', - 2 => 'reduce-1', - 3 => 'reduce-2', - 4 => 'reduce-3', - 5 => 'reduce-4', - 6 => 'implode', - 7 => 'tokenize', - 8 => 'deflate', - 9 => 'deflate64', - 10 => 'PKWARE Date Compression Library Imploding' - ); - - return (isset($ZIPcompressionMethodLookup[$index]) ? $ZIPcompressionMethodLookup[$index] : '[unknown]'); - } - - function DOStime2UNIXtime($DOSdate, $DOStime) { - // wFatDate - // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format: - // Bits Contents - // 0-4 Day of the month (1-31) - // 5-8 Month (1 = January, 2 = February, and so on) - // 9-15 Year offset from 1980 (add 1980 to get actual year) - - $UNIXday = ($DOSdate & 0x001F); - $UNIXmonth = (($DOSdate & 0x01E0) >> 5); - $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980; - - // wFatTime - // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format: - // Bits Contents - // 0-4 Second divided by 2 - // 5-10 Minute (0-59) - // 11-15 Hour (0-23 on a 24-hour clock) - - $UNIXsecond = ($DOStime & 0x001F) * 2; - $UNIXminute = (($DOStime & 0x07E0) >> 5); - $UNIXhour = (($DOStime & 0xF800) >> 11); - - return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear); - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio-video.bink.php b/serendipity_event_podcast/player/getid3/module.audio-video.bink.php deleted file mode 100644 index 2ebc6fe7..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio-video.bink.php +++ /dev/null @@ -1,70 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.bink.php // -// module for analyzing Bink or Smacker audio-video files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_bink -{ - - function getid3_bink(&$fd, &$ThisFileInfo) { - -$ThisFileInfo['error'][] = 'Bink / Smacker files not properly processed by this version of getID3()'; - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $fileTypeID = fread($fd, 3); - switch ($fileTypeID) { - case 'BIK': - return $this->ParseBink($fd, $ThisFileInfo); - break; - - case 'SMK': - return $this->ParseSmacker($fd, $ThisFileInfo); - break; - - default: - $ThisFileInfo['error'][] = 'Expecting "BIK" or "SMK" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$fileTypeID.'"'; - return false; - break; - } - - return true; - - } - - function ParseBink(&$fd, &$ThisFileInfo) { - $ThisFileInfo['fileformat'] = 'bink'; - $ThisFileInfo['video']['dataformat'] = 'bink'; - - $fileData = 'BIK'.fread($fd, 13); - - $ThisFileInfo['bink']['data_size'] = getid3_lib::LittleEndian2Int(substr($fileData, 4, 4)); - $ThisFileInfo['bink']['frame_count'] = getid3_lib::LittleEndian2Int(substr($fileData, 8, 2)); - - if (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) != ($ThisFileInfo['bink']['data_size'] + 8)) { - $ThisFileInfo['error'][] = 'Probably truncated file: expecting '.$ThisFileInfo['bink']['data_size'].' bytes, found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']); - } - - return true; - } - - function ParseSmacker(&$fd, &$ThisFileInfo) { - $ThisFileInfo['fileformat'] = 'smacker'; - $ThisFileInfo['video']['dataformat'] = 'smacker'; - - return false; - } - -} - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio-video.flv.php b/serendipity_event_podcast/player/getid3/module.audio-video.flv.php deleted file mode 100644 index e5f26696..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio-video.flv.php +++ /dev/null @@ -1,718 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -// // -// FLV module by Seth Kaufman // -// // -// * version 0.1 (26 June 2005) // -// // -// minor modifications by James Heinrich // -// * version 0.1.1 (15 July 2005) // -// // -// Support for On2 VP6 codec and meta information // -// by Steve Webster // -// * version 0.2 (22 February 2006) // -// // -// Modified to not read entire file into memory // -// by James Heinrich // -// * version 0.3 (15 June 2006) // -// // -// Bugfixes for incorrectly parsed FLV dimensions // -// and incorrect parsing of onMetaTag // -// by Evgeny Moysevich // -// * version 0.4 (07 December 2007) // -// // -// Fixed parsing of audio tags and added additional codec // -// details. The duration is now read from onMetaTag (if // -// exists), rather than parsing whole file // -// by Nigel Barnes // -// * version 0.5 (21 May 2009) // -// // -// Better parsing of files with h264 video // -// by Evgeny Moysevich // -// * version 0.6 (24 May 2009) // -// // -///////////////////////////////////////////////////////////////// -// // -// module.audio-video.flv.php // -// module for analyzing Shockwave Flash Video files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - -define('GETID3_FLV_TAG_AUDIO', 8); -define('GETID3_FLV_TAG_VIDEO', 9); -define('GETID3_FLV_TAG_META', 18); - -define('GETID3_FLV_VIDEO_H263', 2); -define('GETID3_FLV_VIDEO_SCREEN', 3); -define('GETID3_FLV_VIDEO_VP6FLV', 4); -define('GETID3_FLV_VIDEO_VP6FLV_ALPHA', 5); -define('GETID3_FLV_VIDEO_SCREENV2', 6); -define('GETID3_FLV_VIDEO_H264', 7); - -define('H264_AVC_SEQUENCE_HEADER', 0); -define('H264_PROFILE_BASELINE', 66); -define('H264_PROFILE_MAIN', 77); -define('H264_PROFILE_EXTENDED', 88); -define('H264_PROFILE_HIGH', 100); -define('H264_PROFILE_HIGH10', 110); -define('H264_PROFILE_HIGH422', 122); -define('H264_PROFILE_HIGH444', 144); -define('H264_PROFILE_HIGH444_PREDICTIVE', 244); - -class getid3_flv -{ - - function getid3_flv(&$fd, &$ThisFileInfo, $ReturnAllTagData=false) { -//$start_time = microtime(true); - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - - $FLVdataLength = $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']; - $FLVheader = fread($fd, 5); - - $ThisFileInfo['fileformat'] = 'flv'; - $ThisFileInfo['flv']['header']['signature'] = substr($FLVheader, 0, 3); - $ThisFileInfo['flv']['header']['version'] = getid3_lib::BigEndian2Int(substr($FLVheader, 3, 1)); - $TypeFlags = getid3_lib::BigEndian2Int(substr($FLVheader, 4, 1)); - - if ($ThisFileInfo['flv']['header']['signature'] != 'FLV') { - $ThisFileInfo['error'][] = 'Expecting "FLV" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['flv']['header']['signature'].'"'; - unset($ThisFileInfo['flv']); - unset($ThisFileInfo['fileformat']); - return false; - } - - $ThisFileInfo['flv']['header']['hasAudio'] = (bool) ($TypeFlags & 0x04); - $ThisFileInfo['flv']['header']['hasVideo'] = (bool) ($TypeFlags & 0x01); - - $FrameSizeDataLength = getid3_lib::BigEndian2Int(fread($fd, 4)); - $FLVheaderFrameLength = 9; - if ($FrameSizeDataLength > $FLVheaderFrameLength) { - fseek($fd, $FrameSizeDataLength - $FLVheaderFrameLength, SEEK_CUR); - } -//echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'
'; - - $Duration = 0; - $found_video = false; - $found_audio = false; - $found_meta = false; - $tagParsed = 0; - while (((ftell($fd) + 16) < $ThisFileInfo['avdataend']) && ($tagParsed <= 20 || !$found_meta)) { - $ThisTagHeader = fread($fd, 16); - - $PreviousTagLength = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 0, 4)); - $TagType = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 4, 1)); - $DataLength = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 5, 3)); - $Timestamp = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 8, 3)); - $LastHeaderByte = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 15, 1)); - $NextOffset = ftell($fd) - 1 + $DataLength; - if ($Timestamp > $Duration) { - $Duration = $Timestamp; - } - -//echo __LINE__.'['.ftell($fd).']=('.$TagType.')='.number_format(microtime(true) - $start_time, 3).'
'; - - switch ($TagType) { - case GETID3_FLV_TAG_AUDIO: - if (!$found_audio) { - $found_audio = true; - $ThisFileInfo['flv']['audio']['audioFormat'] = ($LastHeaderByte >> 4) & 0x0F; - $ThisFileInfo['flv']['audio']['audioRate'] = ($LastHeaderByte >> 2) & 0x03; - $ThisFileInfo['flv']['audio']['audioSampleSize'] = ($LastHeaderByte >> 1) & 0x01; - $ThisFileInfo['flv']['audio']['audioType'] = $LastHeaderByte & 0x01; - } - break; - - case GETID3_FLV_TAG_VIDEO: - if (!$found_video) { - $found_video = true; - $ThisFileInfo['flv']['video']['videoCodec'] = $LastHeaderByte & 0x07; - - $FLVvideoHeader = fread($fd, 11); - - if ($ThisFileInfo['flv']['video']['videoCodec'] == GETID3_FLV_VIDEO_H264) { - // this code block contributed by: moysevichØgmail*com - - $AVCPacketType = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 0, 1)); - if ($AVCPacketType == H264_AVC_SEQUENCE_HEADER) { - // read AVCDecoderConfigurationRecord - $configurationVersion = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 1)); - $AVCProfileIndication = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 1)); - $profile_compatibility = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 1)); - $lengthSizeMinusOne = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 7, 1)); - $numOfSequenceParameterSets = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 8, 1)); - - if (($numOfSequenceParameterSets & 0x1F) != 0) { - // there is at least one SequenceParameterSet - // read size of the first SequenceParameterSet - //$spsSize = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 9, 2)); - $spsSize = getid3_lib::LittleEndian2Int(substr($FLVvideoHeader, 9, 2)); - // read the first SequenceParameterSet - $sps = fread($fd, $spsSize); - if (strlen($sps) == $spsSize) { // make sure that whole SequenceParameterSet was red - $spsReader = new AVCSequenceParameterSetReader($sps); - $spsReader->readData(); - $ThisFileInfo['video']['resolution_x'] = $spsReader->getWidth(); - $ThisFileInfo['video']['resolution_y'] = $spsReader->getHeight(); - } - } - } - // end: moysevichØgmail*com - - } elseif ($ThisFileInfo['flv']['video']['videoCodec'] == GETID3_FLV_VIDEO_H263) { - - $PictureSizeType = (getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 3, 2))) >> 7; - $PictureSizeType = $PictureSizeType & 0x0007; - $ThisFileInfo['flv']['header']['videoSizeType'] = $PictureSizeType; - switch ($PictureSizeType) { - case 0: - //$PictureSizeEnc = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2)); - //$PictureSizeEnc <<= 1; - //$ThisFileInfo['video']['resolution_x'] = ($PictureSizeEnc & 0xFF00) >> 8; - //$PictureSizeEnc = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 2)); - //$PictureSizeEnc <<= 1; - //$ThisFileInfo['video']['resolution_y'] = ($PictureSizeEnc & 0xFF00) >> 8; - - $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 2)); - $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2)); - $PictureSizeEnc['x'] >>= 7; - $PictureSizeEnc['y'] >>= 7; - $ThisFileInfo['video']['resolution_x'] = $PictureSizeEnc['x'] & 0xFF; - $ThisFileInfo['video']['resolution_y'] = $PictureSizeEnc['y'] & 0xFF; - break; - - case 1: - $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 3)); - $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 3)); - $PictureSizeEnc['x'] >>= 7; - $PictureSizeEnc['y'] >>= 7; - $ThisFileInfo['video']['resolution_x'] = $PictureSizeEnc['x'] & 0xFFFF; - $ThisFileInfo['video']['resolution_y'] = $PictureSizeEnc['y'] & 0xFFFF; - break; - - case 2: - $ThisFileInfo['video']['resolution_x'] = 352; - $ThisFileInfo['video']['resolution_y'] = 288; - break; - - case 3: - $ThisFileInfo['video']['resolution_x'] = 176; - $ThisFileInfo['video']['resolution_y'] = 144; - break; - - case 4: - $ThisFileInfo['video']['resolution_x'] = 128; - $ThisFileInfo['video']['resolution_y'] = 96; - break; - - case 5: - $ThisFileInfo['video']['resolution_x'] = 320; - $ThisFileInfo['video']['resolution_y'] = 240; - break; - - case 6: - $ThisFileInfo['video']['resolution_x'] = 160; - $ThisFileInfo['video']['resolution_y'] = 120; - break; - - default: - $ThisFileInfo['video']['resolution_x'] = 0; - $ThisFileInfo['video']['resolution_y'] = 0; - break; - - } - } - $ThisFileInfo['video']['pixel_aspect_ratio'] = $ThisFileInfo['video']['resolution_x'] / $ThisFileInfo['video']['resolution_y']; - } - break; - - // Meta tag - case GETID3_FLV_TAG_META: - if (!$found_meta) { - $found_meta = true; - fseek($fd, -1, SEEK_CUR); - $datachunk = fread($fd, $DataLength); - $AMFstream = new AMFStream($datachunk); - $reader = new AMFReader($AMFstream); - $eventName = $reader->readData(); - $ThisFileInfo['flv']['meta'][$eventName] = $reader->readData(); - unset($reader); - - $copykeys = array('framerate'=>'frame_rate', 'width'=>'resolution_x', 'height'=>'resolution_y', 'audiodatarate'=>'bitrate', 'videodatarate'=>'bitrate'); - foreach ($copykeys as $sourcekey => $destkey) { - if (isset($ThisFileInfo['flv']['meta']['onMetaData'][$sourcekey])) { - switch ($sourcekey) { - case 'width': - case 'height': - $ThisFileInfo['video'][$destkey] = intval(round($ThisFileInfo['flv']['meta']['onMetaData'][$sourcekey])); - break; - case 'audiodatarate': - $ThisFileInfo['audio'][$destkey] = $ThisFileInfo['flv']['meta']['onMetaData'][$sourcekey]; - break; - case 'videodatarate': - case 'frame_rate': - default: - $ThisFileInfo['video'][$destkey] = $ThisFileInfo['flv']['meta']['onMetaData'][$sourcekey]; - break; - } - } - } - } - break; - - default: - // noop - break; - } - - fseek($fd, $NextOffset, SEEK_SET); - - // Increase parsed tag count: break out of loop if more than 20 tags parsed - $tagParsed++; - } - - $ThisFileInfo['playtime_seconds'] = $Duration / 1000; - if ($ThisFileInfo['playtime_seconds'] > 0) { - $ThisFileInfo['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; - } - - if ($ThisFileInfo['flv']['header']['hasAudio']) { - $ThisFileInfo['audio']['codec'] = $this->FLVaudioFormat($ThisFileInfo['flv']['audio']['audioFormat']); - $ThisFileInfo['audio']['sample_rate'] = $this->FLVaudioRate($ThisFileInfo['flv']['audio']['audioRate']); - $ThisFileInfo['audio']['bits_per_sample'] = $this->FLVaudioBitDepth($ThisFileInfo['flv']['audio']['audioSampleSize']); - - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['flv']['audio']['audioType'] + 1; // 0=mono,1=stereo - $ThisFileInfo['audio']['lossless'] = ($ThisFileInfo['flv']['audio']['audioFormat'] ? false : true); // 0=uncompressed - $ThisFileInfo['audio']['dataformat'] = 'flv'; - } - if (!empty($ThisFileInfo['flv']['header']['hasVideo'])) { - $ThisFileInfo['video']['codec'] = $this->FLVvideoCodec($ThisFileInfo['flv']['video']['videoCodec']); - $ThisFileInfo['video']['dataformat'] = 'flv'; - $ThisFileInfo['video']['lossless'] = false; - } - - // Set information from meta - if (isset($ThisFileInfo['flv']['meta']['onMetaData']['duration'])) { - $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['flv']['meta']['onMetaData']['duration']; - $ThisFileInfo['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; - } - if (isset($ThisFileInfo['flv']['meta']['onMetaData']['audiocodecid'])) { - $ThisFileInfo['audio']['codec'] = $this->FLVaudioFormat($ThisFileInfo['flv']['meta']['onMetaData']['audiocodecid']); - } - if (isset($ThisFileInfo['flv']['meta']['onMetaData']['videocodecid'])) { - $ThisFileInfo['video']['codec'] = $this->FLVvideoCodec($ThisFileInfo['flv']['meta']['onMetaData']['videocodecid']); - } - return true; - } - - - function FLVaudioFormat($id) { - $FLVaudioFormat = array( - 0 => 'Linear PCM, platform endian', - 1 => 'ADPCM', - 2 => 'mp3', - 3 => 'Linear PCM, little endian', - 4 => 'Nellymoser 16kHz mono', - 5 => 'Nellymoser 8kHz mono', - 6 => 'Nellymoser', - 7 => 'G.711A-law logarithmic PCM', - 8 => 'G.711 mu-law logarithmic PCM', - 9 => 'reserved', - 10 => 'AAC', - 11 => false, // unknown? - 12 => false, // unknown? - 13 => false, // unknown? - 14 => 'mp3 8kHz', - 15 => 'Device-specific sound', - ); - return (isset($FLVaudioFormat[$id]) ? $FLVaudioFormat[$id] : false); - } - - function FLVaudioRate($id) { - $FLVaudioRate = array( - 0 => 5500, - 1 => 11025, - 2 => 22050, - 3 => 44100, - ); - return (isset($FLVaudioRate[$id]) ? $FLVaudioRate[$id] : false); - } - - function FLVaudioBitDepth($id) { - $FLVaudioBitDepth = array( - 0 => 8, - 1 => 16, - ); - return (isset($FLVaudioBitDepth[$id]) ? $FLVaudioBitDepth[$id] : false); - } - - function FLVvideoCodec($id) { - $FLVvideoCodec = array( - GETID3_FLV_VIDEO_H263 => 'Sorenson H.263', - GETID3_FLV_VIDEO_SCREEN => 'Screen video', - GETID3_FLV_VIDEO_VP6FLV => 'On2 VP6', - GETID3_FLV_VIDEO_VP6FLV_ALPHA => 'On2 VP6 with alpha channel', - GETID3_FLV_VIDEO_SCREENV2 => 'Screen video v2', - GETID3_FLV_VIDEO_H264 => 'Sorenson H.264', - ); - return (isset($FLVvideoCodec[$id]) ? $FLVvideoCodec[$id] : false); - } -} - -class AMFStream { - var $bytes; - var $pos; - - function AMFStream(&$bytes) { - $this->bytes =& $bytes; - $this->pos = 0; - } - - function readByte() { - return getid3_lib::BigEndian2Int(substr($this->bytes, $this->pos++, 1)); - } - - function readInt() { - return ($this->readByte() << 8) + $this->readByte(); - } - - function readLong() { - return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte(); - } - - function readDouble() { - return getid3_lib::BigEndian2Float($this->read(8)); - } - - function readUTF() { - $length = $this->readInt(); - return $this->read($length); - } - - function readLongUTF() { - $length = $this->readLong(); - return $this->read($length); - } - - function read($length) { - $val = substr($this->bytes, $this->pos, $length); - $this->pos += $length; - return $val; - } - - function peekByte() { - $pos = $this->pos; - $val = $this->readByte(); - $this->pos = $pos; - return $val; - } - - function peekInt() { - $pos = $this->pos; - $val = $this->readInt(); - $this->pos = $pos; - return $val; - } - - function peekLong() { - $pos = $this->pos; - $val = $this->readLong(); - $this->pos = $pos; - return $val; - } - - function peekDouble() { - $pos = $this->pos; - $val = $this->readDouble(); - $this->pos = $pos; - return $val; - } - - function peekUTF() { - $pos = $this->pos; - $val = $this->readUTF(); - $this->pos = $pos; - return $val; - } - - function peekLongUTF() { - $pos = $this->pos; - $val = $this->readLongUTF(); - $this->pos = $pos; - return $val; - } -} - -class AMFReader { - var $stream; - - function AMFReader(&$stream) { - $this->stream =& $stream; - } - - function readData() { - $value = null; - - $type = $this->stream->readByte(); - switch ($type) { - - // Double - case 0: - $value = $this->readDouble(); - break; - - // Boolean - case 1: - $value = $this->readBoolean(); - break; - - // String - case 2: - $value = $this->readString(); - break; - - // Object - case 3: - $value = $this->readObject(); - break; - - // null - case 6: - return null; - break; - - // Mixed array - case 8: - $value = $this->readMixedArray(); - break; - - // Array - case 10: - $value = $this->readArray(); - break; - - // Date - case 11: - $value = $this->readDate(); - break; - - // Long string - case 13: - $value = $this->readLongString(); - break; - - // XML (handled as string) - case 15: - $value = $this->readXML(); - break; - - // Typed object (handled as object) - case 16: - $value = $this->readTypedObject(); - break; - - // Long string - default: - $value = '(unknown or unsupported data type)'; - break; - } - - return $value; - } - - function readDouble() { - return $this->stream->readDouble(); - } - - function readBoolean() { - return $this->stream->readByte() == 1; - } - - function readString() { - return $this->stream->readUTF(); - } - - function readObject() { - // Get highest numerical index - ignored -// $highestIndex = $this->stream->readLong(); - - $data = array(); - - while ($key = $this->stream->readUTF()) { - $data[$key] = $this->readData(); - } - // Mixed array record ends with empty string (0x00 0x00) and 0x09 - if (($key == '') && ($this->stream->peekByte() == 0x09)) { - // Consume byte - $this->stream->readByte(); - } - return $data; - } - - function readMixedArray() { - // Get highest numerical index - ignored - $highestIndex = $this->stream->readLong(); - - $data = array(); - - while ($key = $this->stream->readUTF()) { - if (is_numeric($key)) { - $key = (float) $key; - } - $data[$key] = $this->readData(); - } - // Mixed array record ends with empty string (0x00 0x00) and 0x09 - if (($key == '') && ($this->stream->peekByte() == 0x09)) { - // Consume byte - $this->stream->readByte(); - } - - return $data; - } - - function readArray() { - $length = $this->stream->readLong(); - $data = array(); - - for ($i = 0; $i < $length; $i++) { - $data[] = $this->readData(); - } - return $data; - } - - function readDate() { - $timestamp = $this->stream->readDouble(); - $timezone = $this->stream->readInt(); - return $timestamp; - } - - function readLongString() { - return $this->stream->readLongUTF(); - } - - function readXML() { - return $this->stream->readLongUTF(); - } - - function readTypedObject() { - $className = $this->stream->readUTF(); - return $this->readObject(); - } -} - -class AVCSequenceParameterSetReader { - var $sps; - var $start = 0; - var $currentBytes = 0; - var $currentBits = 0; - var $width; - var $height; - - function AVCSequenceParameterSetReader($sps) { - $this->sps = $sps; - } - - function readData() { - $this->skipBits(8); - $this->skipBits(8); - $profile = $this->getBits(8); // read profile - $this->skipBits(16); - $this->expGolombUe(); // read sps id - if (in_array($profile, array(H264_PROFILE_HIGH, H264_PROFILE_HIGH10, H264_PROFILE_HIGH422, H264_PROFILE_HIGH444, H264_PROFILE_HIGH444_PREDICTIVE))) { - if ($this->expGolombUe() == 3) { - $this->skipBits(1); - } - $this->expGolombUe(); - $this->expGolombUe(); - $this->skipBits(1); - if ($this->getBit()) { - for ($i = 0; $i < 8; $i++) { - if ($this->getBit()) { - $size = $i < 6 ? 16 : 64; - $lastScale = 8; - $nextScale = 8; - for ($j = 0; $j < $size; $j++) { - if ($nextScale != 0) { - $deltaScale = $this->expGolombUe(); - $nextScale = ($lastScale + $deltaScale + 256) % 256; - } - if ($nextScale != 0) { - $lastScale = $nextScale; - } - } - } - } - } - } - $this->expGolombUe(); - $pocType = $this->expGolombUe(); - if ($pocType == 0) { - $this->expGolombUe(); - } elseif ($pocType == 1) { - $this->skipBits(1); - $this->expGolombSe(); - $this->expGolombSe(); - $pocCycleLength = $this->expGolombUe(); - for ($i = 0; $i < $pocCycleLength; $i++) { - $this->expGolombSe(); - } - } - $this->expGolombUe(); - $this->skipBits(1); - $this->width = ($this->expGolombUe() + 1) * 16; - $heightMap = $this->expGolombUe() + 1; - $this->height = (2 - $this->getBit()) * $heightMap * 16; - } - - function skipBits($bits) { - $newBits = $this->currentBits + $bits; - $this->currentBytes += (int)floor($newBits / 8); - $this->currentBits = $newBits % 8; - } - - function getBit() { - $result = (getid3_lib::BigEndian2Int(substr($this->sps, $this->currentBytes, 1)) >> (7 - $this->currentBits)) & 0x01; - $this->skipBits(1); - return $result; - } - - function getBits($bits) { - $result = 0; - for ($i = 0; $i < $bits; $i++) { - $result = ($result << 1) + $this->getBit(); - } - return $result; - } - - function expGolombUe() { - $significantBits = 0; - $bit = $this->getBit(); - while ($bit == 0) { - $significantBits++; - $bit = $this->getBit(); - } - return (1 << $significantBits) + $this->getBits($significantBits) - 1; - } - - function expGolombSe() { - $result = $this->expGolombUe(); - if (($result & 0x01) == 0) { - return -($result >> 1); - } else { - return ($result + 1) >> 1; - } - } - - function getWidth() { - return $this->width; - } - - function getHeight() { - return $this->height; - } -} - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio-video.mpeg.php b/serendipity_event_podcast/player/getid3/module.audio-video.mpeg.php deleted file mode 100644 index 8f487848..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio-video.mpeg.php +++ /dev/null @@ -1,292 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio-video.mpeg.php // -// module for analyzing MPEG files // -// dependencies: module.audio.mp3.php // -// /// -///////////////////////////////////////////////////////////////// - -getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); - -define('GETID3_MPEG_VIDEO_PICTURE_START', "\x00\x00\x01\x00"); -define('GETID3_MPEG_VIDEO_USER_DATA_START', "\x00\x00\x01\xB2"); -define('GETID3_MPEG_VIDEO_SEQUENCE_HEADER', "\x00\x00\x01\xB3"); -define('GETID3_MPEG_VIDEO_SEQUENCE_ERROR', "\x00\x00\x01\xB4"); -define('GETID3_MPEG_VIDEO_EXTENSION_START', "\x00\x00\x01\xB5"); -define('GETID3_MPEG_VIDEO_SEQUENCE_END', "\x00\x00\x01\xB7"); -define('GETID3_MPEG_VIDEO_GROUP_START', "\x00\x00\x01\xB8"); -define('GETID3_MPEG_AUDIO_START', "\x00\x00\x01\xC0"); - - -class getid3_mpeg -{ - - function getid3_mpeg(&$fd, &$ThisFileInfo) { - if ($ThisFileInfo['avdataend'] <= $ThisFileInfo['avdataoffset']) { - $ThisFileInfo['error'][] = '"avdataend" ('.$ThisFileInfo['avdataend'].') is unexpectedly less-than-or-equal-to "avdataoffset" ('.$ThisFileInfo['avdataoffset'].')'; - return false; - } - $ThisFileInfo['fileformat'] = 'mpeg'; - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $MPEGstreamData = fread($fd, min(100000, $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'])); - $MPEGstreamDataLength = strlen($MPEGstreamData); - - $foundVideo = true; - $VideoChunkOffset = 0; - while (substr($MPEGstreamData, $VideoChunkOffset++, 4) !== GETID3_MPEG_VIDEO_SEQUENCE_HEADER) { - if ($VideoChunkOffset >= $MPEGstreamDataLength) { - $foundVideo = false; - break; - } - } - if ($foundVideo) { - - // Start code 32 bits - // horizontal frame size 12 bits - // vertical frame size 12 bits - // pixel aspect ratio 4 bits - // frame rate 4 bits - // bitrate 18 bits - // marker bit 1 bit - // VBV buffer size 10 bits - // constrained parameter flag 1 bit - // intra quant. matrix flag 1 bit - // intra quant. matrix values 512 bits (present if matrix flag == 1) - // non-intra quant. matrix flag 1 bit - // non-intra quant. matrix values 512 bits (present if matrix flag == 1) - - $ThisFileInfo['video']['dataformat'] = 'mpeg'; - - $VideoChunkOffset += (strlen(GETID3_MPEG_VIDEO_SEQUENCE_HEADER) - 1); - - $FrameSizeDWORD = getid3_lib::BigEndian2Int(substr($MPEGstreamData, $VideoChunkOffset, 3)); - $VideoChunkOffset += 3; - - $AspectRatioFrameRateDWORD = getid3_lib::BigEndian2Int(substr($MPEGstreamData, $VideoChunkOffset, 1)); - $VideoChunkOffset += 1; - - $assortedinformation = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $VideoChunkOffset, 4)); - $VideoChunkOffset += 4; - - $ThisFileInfo['mpeg']['video']['raw']['framesize_horizontal'] = ($FrameSizeDWORD & 0xFFF000) >> 12; // 12 bits for horizontal frame size - $ThisFileInfo['mpeg']['video']['raw']['framesize_vertical'] = ($FrameSizeDWORD & 0x000FFF); // 12 bits for vertical frame size - $ThisFileInfo['mpeg']['video']['raw']['pixel_aspect_ratio'] = ($AspectRatioFrameRateDWORD & 0xF0) >> 4; - $ThisFileInfo['mpeg']['video']['raw']['frame_rate'] = ($AspectRatioFrameRateDWORD & 0x0F); - - $ThisFileInfo['mpeg']['video']['framesize_horizontal'] = $ThisFileInfo['mpeg']['video']['raw']['framesize_horizontal']; - $ThisFileInfo['mpeg']['video']['framesize_vertical'] = $ThisFileInfo['mpeg']['video']['raw']['framesize_vertical']; - - $ThisFileInfo['mpeg']['video']['pixel_aspect_ratio'] = $this->MPEGvideoAspectRatioLookup($ThisFileInfo['mpeg']['video']['raw']['pixel_aspect_ratio']); - $ThisFileInfo['mpeg']['video']['pixel_aspect_ratio_text'] = $this->MPEGvideoAspectRatioTextLookup($ThisFileInfo['mpeg']['video']['raw']['pixel_aspect_ratio']); - $ThisFileInfo['mpeg']['video']['frame_rate'] = $this->MPEGvideoFramerateLookup($ThisFileInfo['mpeg']['video']['raw']['frame_rate']); - - $ThisFileInfo['mpeg']['video']['raw']['bitrate'] = getid3_lib::Bin2Dec(substr($assortedinformation, 0, 18)); - $ThisFileInfo['mpeg']['video']['raw']['marker_bit'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 18, 1)); - $ThisFileInfo['mpeg']['video']['raw']['vbv_buffer_size'] = getid3_lib::Bin2Dec(substr($assortedinformation, 19, 10)); - $ThisFileInfo['mpeg']['video']['raw']['constrained_param_flag'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 29, 1)); - $ThisFileInfo['mpeg']['video']['raw']['intra_quant_flag'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 30, 1)); - if ($ThisFileInfo['mpeg']['video']['raw']['intra_quant_flag']) { - - // read 512 bits - $ThisFileInfo['mpeg']['video']['raw']['intra_quant'] = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $VideoChunkOffset, 64)); - $VideoChunkOffset += 64; - - $ThisFileInfo['mpeg']['video']['raw']['non_intra_quant_flag'] = (bool) getid3_lib::Bin2Dec(substr($ThisFileInfo['mpeg']['video']['raw']['intra_quant'], 511, 1)); - $ThisFileInfo['mpeg']['video']['raw']['intra_quant'] = getid3_lib::Bin2Dec(substr($assortedinformation, 31, 1)).substr(getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $VideoChunkOffset, 64)), 0, 511); - - if ($ThisFileInfo['mpeg']['video']['raw']['non_intra_quant_flag']) { - $ThisFileInfo['mpeg']['video']['raw']['non_intra_quant'] = substr($MPEGstreamData, $VideoChunkOffset, 64); - $VideoChunkOffset += 64; - } - - } else { - - $ThisFileInfo['mpeg']['video']['raw']['non_intra_quant_flag'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 31, 1)); - if ($ThisFileInfo['mpeg']['video']['raw']['non_intra_quant_flag']) { - $ThisFileInfo['mpeg']['video']['raw']['non_intra_quant'] = substr($MPEGstreamData, $VideoChunkOffset, 64); - $VideoChunkOffset += 64; - } - - } - - if ($ThisFileInfo['mpeg']['video']['raw']['bitrate'] == 0x3FFFF) { // 18 set bits - - $ThisFileInfo['warning'][] = 'This version of getID3() ['.GETID3_VERSION.'] cannot determine average bitrate of VBR MPEG video files'; - $ThisFileInfo['mpeg']['video']['bitrate_mode'] = 'vbr'; - - } else { - - $ThisFileInfo['mpeg']['video']['bitrate'] = $ThisFileInfo['mpeg']['video']['raw']['bitrate'] * 400; - $ThisFileInfo['mpeg']['video']['bitrate_mode'] = 'cbr'; - $ThisFileInfo['video']['bitrate'] = $ThisFileInfo['mpeg']['video']['bitrate']; - - } - - $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['mpeg']['video']['framesize_horizontal']; - $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['mpeg']['video']['framesize_vertical']; - $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['mpeg']['video']['frame_rate']; - $ThisFileInfo['video']['bitrate_mode'] = $ThisFileInfo['mpeg']['video']['bitrate_mode']; - $ThisFileInfo['video']['pixel_aspect_ratio'] = $ThisFileInfo['mpeg']['video']['pixel_aspect_ratio']; - $ThisFileInfo['video']['lossless'] = false; - $ThisFileInfo['video']['bits_per_sample'] = 24; - - } else { - - $ThisFileInfo['error'][] = 'Could not find start of video block in the first 100,000 bytes (or before end of file) - this might not be an MPEG-video file?'; - - } - - //0x000001B3 begins the sequence_header of every MPEG video stream. - //But in MPEG-2, this header must immediately be followed by an - //extension_start_code (0x000001B5) with a sequence_extension ID (1). - //(This extension contains all the additional MPEG-2 stuff.) - //MPEG-1 doesn't have this extension, so that's a sure way to tell the - //difference between MPEG-1 and MPEG-2 video streams. - - if (substr($MPEGstreamData, $VideoChunkOffset, 4) == GETID3_MPEG_VIDEO_EXTENSION_START) { - $ThisFileInfo['video']['codec'] = 'MPEG-2'; - } else { - $ThisFileInfo['video']['codec'] = 'MPEG-1'; - } - - - $AudioChunkOffset = 0; - while (true) { - while (substr($MPEGstreamData, $AudioChunkOffset++, 4) !== GETID3_MPEG_AUDIO_START) { - if ($AudioChunkOffset >= $MPEGstreamDataLength) { - break 2; - } - } - - for ($i = 0; $i <= 7; $i++) { - // some files have the MPEG-audio header 8 bytes after the end of the $00 $00 $01 $C0 signature, some have it up to 13 bytes (or more?) after - // I have no idea why or what the difference is, so this is a stupid hack. - // If anybody has any better idea of what's going on, please let me know - info@getid3.org - - $dummy = $ThisFileInfo; - if (getid3_mp3::decodeMPEGaudioHeader($fd, ($AudioChunkOffset + 3) + 8 + $i, $dummy, false)) { - $ThisFileInfo = $dummy; - $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; - $ThisFileInfo['audio']['lossless'] = false; - break 2; - - } - } - } - - // Temporary hack to account for interleaving overhead: - if (!empty($ThisFileInfo['video']['bitrate']) && !empty($ThisFileInfo['audio']['bitrate'])) { - $ThisFileInfo['playtime_seconds'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / ($ThisFileInfo['video']['bitrate'] + $ThisFileInfo['audio']['bitrate']); - - // Interleaved MPEG audio/video files have a certain amount of overhead that varies - // by both video and audio bitrates, and not in any sensible, linear/logarithmic patter - // Use interpolated lookup tables to approximately guess how much is overhead, because - // playtime is calculated as filesize / total-bitrate - $ThisFileInfo['playtime_seconds'] *= $this->MPEGsystemNonOverheadPercentage($ThisFileInfo['video']['bitrate'], $ThisFileInfo['audio']['bitrate']); - - //switch ($ThisFileInfo['video']['bitrate']) { - // case('5000000'): - // $multiplier = 0.93292642112380355828048824319889; - // break; - // case('5500000'): - // $multiplier = 0.93582895375200989965359777343219; - // break; - // case('6000000'): - // $multiplier = 0.93796247714820932532911373859139; - // break; - // case('7000000'): - // $multiplier = 0.9413264083635103463010117778776; - // break; - // default: - // $multiplier = 1; - // break; - //} - //$ThisFileInfo['playtime_seconds'] *= $multiplier; - //$ThisFileInfo['warning'][] = 'Interleaved MPEG audio/video playtime may be inaccurate. With current hack should be within a few seconds of accurate. Report to info@getid3.org if off by more than 10 seconds.'; - if ($ThisFileInfo['video']['bitrate'] < 50000) { - $ThisFileInfo['warning'][] = 'Interleaved MPEG audio/video playtime may be slightly inaccurate for video bitrates below 100kbps. Except in extreme low-bitrate situations, error should be less than 1%. Report to info@getid3.org if greater than this.'; - } - } - - return true; - } - - - function MPEGsystemNonOverheadPercentage($VideoBitrate, $AudioBitrate) { - $OverheadPercentage = 0; - - $AudioBitrate = max(min($AudioBitrate / 1000, 384), 32); // limit to range of 32kbps - 384kbps (should be only legal bitrates, but maybe VBR?) - $VideoBitrate = max(min($VideoBitrate / 1000, 10000), 10); // limit to range of 10kbps - 10Mbps (beyond that curves flatten anyways, no big loss) - - - //OMBB[audiobitrate] = array(video-10kbps, video-100kbps, video-1000kbps, video-10000kbps) - $OverheadMultiplierByBitrate[32] = array(0, 0.9676287944368530, 0.9802276264360310, 0.9844916183244460, 0.9852821845179940); - $OverheadMultiplierByBitrate[48] = array(0, 0.9779100089209830, 0.9787770035359320, 0.9846738664076130, 0.9852683013799960); - $OverheadMultiplierByBitrate[56] = array(0, 0.9731249855367600, 0.9776624308938040, 0.9832606361852130, 0.9843922606633340); - $OverheadMultiplierByBitrate[64] = array(0, 0.9755642683275760, 0.9795256705493390, 0.9836573009193170, 0.9851122539404470); - $OverheadMultiplierByBitrate[96] = array(0, 0.9788025247497290, 0.9798553314148700, 0.9822956869792560, 0.9834815119124690); - $OverheadMultiplierByBitrate[128] = array(0, 0.9816940050925480, 0.9821675936072120, 0.9829756927470870, 0.9839763420152050); - $OverheadMultiplierByBitrate[160] = array(0, 0.9825894094561180, 0.9820913399073960, 0.9823907143253970, 0.9832821783651570); - $OverheadMultiplierByBitrate[192] = array(0, 0.9832038474336260, 0.9825731694317960, 0.9821028622712400, 0.9828262076447620); - $OverheadMultiplierByBitrate[224] = array(0, 0.9836516298538770, 0.9824718601823890, 0.9818302180625380, 0.9823735101626480); - $OverheadMultiplierByBitrate[256] = array(0, 0.9845863022094920, 0.9837229411967540, 0.9824521662210830, 0.9828645172100790); - $OverheadMultiplierByBitrate[320] = array(0, 0.9849565280263180, 0.9837683142805110, 0.9822885275960400, 0.9824424382727190); - $OverheadMultiplierByBitrate[384] = array(0, 0.9856094774357600, 0.9844573394432720, 0.9825970399837330, 0.9824673808303890); - - $BitrateToUseMin = 32; - $BitrateToUseMax = 32; - $previousBitrate = 32; - foreach ($OverheadMultiplierByBitrate as $key => $value) { - if ($AudioBitrate >= $previousBitrate) { - $BitrateToUseMin = $previousBitrate; - } - if ($AudioBitrate < $key) { - $BitrateToUseMax = $key; - break; - } - $previousBitrate = $key; - } - $FactorA = ($BitrateToUseMax - $AudioBitrate) / ($BitrateToUseMax - $BitrateToUseMin); - - $VideoBitrateLog10 = log10($VideoBitrate); - $VideoFactorMin1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][floor($VideoBitrateLog10)]; - $VideoFactorMin2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][floor($VideoBitrateLog10)]; - $VideoFactorMax1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][ceil($VideoBitrateLog10)]; - $VideoFactorMax2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][ceil($VideoBitrateLog10)]; - $FactorV = $VideoBitrateLog10 - floor($VideoBitrateLog10); - - $OverheadPercentage = $VideoFactorMin1 * $FactorA * $FactorV; - $OverheadPercentage += $VideoFactorMin2 * (1 - $FactorA) * $FactorV; - $OverheadPercentage += $VideoFactorMax1 * $FactorA * (1 - $FactorV); - $OverheadPercentage += $VideoFactorMax2 * (1 - $FactorA) * (1 - $FactorV); - - return $OverheadPercentage; - } - - - function MPEGvideoFramerateLookup($rawframerate) { - $MPEGvideoFramerateLookup = array(0, 23.976, 24, 25, 29.97, 30, 50, 59.94, 60); - return (isset($MPEGvideoFramerateLookup[$rawframerate]) ? (float) $MPEGvideoFramerateLookup[$rawframerate] : (float) 0); - } - - function MPEGvideoAspectRatioLookup($rawaspectratio) { - $MPEGvideoAspectRatioLookup = array(0, 1, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, 0.8935, 0.9157, 0.9815, 1.0255, 1.0695, 1.0950, 1.1575, 1.2015, 0); - return (isset($MPEGvideoAspectRatioLookup[$rawaspectratio]) ? (float) $MPEGvideoAspectRatioLookup[$rawaspectratio] : (float) 0); - } - - function MPEGvideoAspectRatioTextLookup($rawaspectratio) { - $MPEGvideoAspectRatioTextLookup = array('forbidden', 'square pixels', '0.6735', '16:9, 625 line, PAL', '0.7615', '0.8055', '16:9, 525 line, NTSC', '0.8935', '4:3, 625 line, PAL, CCIR601', '0.9815', '1.0255', '1.0695', '4:3, 525 line, NTSC, CCIR601', '1.1575', '1.2015', 'reserved'); - return (isset($MPEGvideoAspectRatioTextLookup[$rawaspectratio]) ? $MPEGvideoAspectRatioTextLookup[$rawaspectratio] : ''); - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio-video.nsv.php b/serendipity_event_podcast/player/getid3/module.audio-video.nsv.php deleted file mode 100644 index dab03389..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio-video.nsv.php +++ /dev/null @@ -1,224 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.nsv.php // -// module for analyzing Nullsoft NSV files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_nsv -{ - - function getid3_nsv(&$fd, &$ThisFileInfo) { - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $NSVheader = fread($fd, 4); - - switch ($NSVheader) { - case 'NSVs': - if ($this->getNSVsHeaderFilepointer($fd, $ThisFileInfo, 0)) { - $ThisFileInfo['fileformat'] = 'nsv'; - $ThisFileInfo['audio']['dataformat'] = 'nsv'; - $ThisFileInfo['video']['dataformat'] = 'nsv'; - $ThisFileInfo['audio']['lossless'] = false; - $ThisFileInfo['video']['lossless'] = false; - } - break; - - case 'NSVf': - if ($this->getNSVfHeaderFilepointer($fd, $ThisFileInfo, 0)) { - $ThisFileInfo['fileformat'] = 'nsv'; - $ThisFileInfo['audio']['dataformat'] = 'nsv'; - $ThisFileInfo['video']['dataformat'] = 'nsv'; - $ThisFileInfo['audio']['lossless'] = false; - $ThisFileInfo['video']['lossless'] = false; - $this->getNSVsHeaderFilepointer($fd, $ThisFileInfo, $ThisFileInfo['nsv']['NSVf']['header_length']); - } - break; - - default: - $ThisFileInfo['error'][] = 'Expecting "NSVs" or "NSVf" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$NSVheader.'"'; - return false; - break; - } - - if (!isset($ThisFileInfo['nsv']['NSVf'])) { - $ThisFileInfo['warning'][] = 'NSVf header not present - cannot calculate playtime or bitrate'; - } - - return true; - } - - function getNSVsHeaderFilepointer(&$fd, &$ThisFileInfo, $fileoffset) { - fseek($fd, $fileoffset, SEEK_SET); - $NSVsheader = fread($fd, 28); - $offset = 0; - - $ThisFileInfo['nsv']['NSVs']['identifier'] = substr($NSVsheader, $offset, 4); - $offset += 4; - - if ($ThisFileInfo['nsv']['NSVs']['identifier'] != 'NSVs') { - $ThisFileInfo['error'][] = 'expected "NSVs" at offset ('.$fileoffset.'), found "'.$ThisFileInfo['nsv']['NSVs']['identifier'].'" instead'; - unset($ThisFileInfo['nsv']['NSVs']); - return false; - } - - $ThisFileInfo['nsv']['NSVs']['offset'] = $fileoffset; - - $ThisFileInfo['nsv']['NSVs']['video_codec'] = substr($NSVsheader, $offset, 4); - $offset += 4; - $ThisFileInfo['nsv']['NSVs']['audio_codec'] = substr($NSVsheader, $offset, 4); - $offset += 4; - $ThisFileInfo['nsv']['NSVs']['resolution_x'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2)); - $offset += 2; - $ThisFileInfo['nsv']['NSVs']['resolution_y'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2)); - $offset += 2; - - $ThisFileInfo['nsv']['NSVs']['framerate_index'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - //$ThisFileInfo['nsv']['NSVs']['unknown1b'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - //$ThisFileInfo['nsv']['NSVs']['unknown1c'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - //$ThisFileInfo['nsv']['NSVs']['unknown1d'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - //$ThisFileInfo['nsv']['NSVs']['unknown2a'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - //$ThisFileInfo['nsv']['NSVs']['unknown2b'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - //$ThisFileInfo['nsv']['NSVs']['unknown2c'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - //$ThisFileInfo['nsv']['NSVs']['unknown2d'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - - switch ($ThisFileInfo['nsv']['NSVs']['audio_codec']) { - case 'PCM ': - $ThisFileInfo['nsv']['NSVs']['bits_channel'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - $ThisFileInfo['nsv']['NSVs']['channels'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); - $offset += 1; - $ThisFileInfo['nsv']['NSVs']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2)); - $offset += 2; - - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['nsv']['NSVs']['sample_rate']; - break; - - case 'MP3 ': - case 'NONE': - default: - //$ThisFileInfo['nsv']['NSVs']['unknown3'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 4)); - $offset += 4; - break; - } - - $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['nsv']['NSVs']['resolution_x']; - $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['nsv']['NSVs']['resolution_y']; - $ThisFileInfo['nsv']['NSVs']['frame_rate'] = $this->NSVframerateLookup($ThisFileInfo['nsv']['NSVs']['framerate_index']); - $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['nsv']['NSVs']['frame_rate']; - $ThisFileInfo['video']['bits_per_sample'] = 24; - $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1; - - return true; - } - - function getNSVfHeaderFilepointer(&$fd, &$ThisFileInfo, $fileoffset, $getTOCoffsets=false) { - fseek($fd, $fileoffset, SEEK_SET); - $NSVfheader = fread($fd, 28); - $offset = 0; - - $ThisFileInfo['nsv']['NSVf']['identifier'] = substr($NSVfheader, $offset, 4); - $offset += 4; - - if ($ThisFileInfo['nsv']['NSVf']['identifier'] != 'NSVf') { - $ThisFileInfo['error'][] = 'expected "NSVf" at offset ('.$fileoffset.'), found "'.$ThisFileInfo['nsv']['NSVf']['identifier'].'" instead'; - unset($ThisFileInfo['nsv']['NSVf']); - return false; - } - - $ThisFileInfo['nsv']['NSVs']['offset'] = $fileoffset; - - $ThisFileInfo['nsv']['NSVf']['header_length'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); - $offset += 4; - $ThisFileInfo['nsv']['NSVf']['file_size'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); - $offset += 4; - - if ($ThisFileInfo['nsv']['NSVf']['file_size'] > $ThisFileInfo['avdataend']) { - $ThisFileInfo['warning'][] = 'truncated file - NSVf header indicates '.$ThisFileInfo['nsv']['NSVf']['file_size'].' bytes, file actually '.$ThisFileInfo['avdataend'].' bytes'; - } - - $ThisFileInfo['nsv']['NSVf']['playtime_ms'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); - $offset += 4; - $ThisFileInfo['nsv']['NSVf']['meta_size'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); - $offset += 4; - $ThisFileInfo['nsv']['NSVf']['TOC_entries_1'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); - $offset += 4; - $ThisFileInfo['nsv']['NSVf']['TOC_entries_2'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); - $offset += 4; - - if ($ThisFileInfo['nsv']['NSVf']['playtime_ms'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt NSV file: NSVf.playtime_ms == zero'; - return false; - } - - $NSVfheader .= fread($fd, $ThisFileInfo['nsv']['NSVf']['meta_size'] + (4 * $ThisFileInfo['nsv']['NSVf']['TOC_entries_1']) + (4 * $ThisFileInfo['nsv']['NSVf']['TOC_entries_2'])); - $NSVfheaderlength = strlen($NSVfheader); - $ThisFileInfo['nsv']['NSVf']['metadata'] = substr($NSVfheader, $offset, $ThisFileInfo['nsv']['NSVf']['meta_size']); - $offset += $ThisFileInfo['nsv']['NSVf']['meta_size']; - - if ($getTOCoffsets) { - $TOCcounter = 0; - while ($TOCcounter < $ThisFileInfo['nsv']['NSVf']['TOC_entries_1']) { - if ($TOCcounter < $ThisFileInfo['nsv']['NSVf']['TOC_entries_1']) { - $ThisFileInfo['nsv']['NSVf']['TOC_1'][$TOCcounter] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); - $offset += 4; - $TOCcounter++; - } - } - } - - if (trim($ThisFileInfo['nsv']['NSVf']['metadata']) != '') { - $ThisFileInfo['nsv']['NSVf']['metadata'] = str_replace('`', "\x01", $ThisFileInfo['nsv']['NSVf']['metadata']); - $CommentPairArray = explode("\x01".' ', $ThisFileInfo['nsv']['NSVf']['metadata']); - foreach ($CommentPairArray as $CommentPair) { - if (strstr($CommentPair, '='."\x01")) { - list($key, $value) = explode('='."\x01", $CommentPair, 2); - $ThisFileInfo['nsv']['comments'][strtolower($key)][] = trim(str_replace("\x01", '', $value)); - } - } - } - - $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['nsv']['NSVf']['playtime_ms'] / 1000; - $ThisFileInfo['bitrate'] = ($ThisFileInfo['nsv']['NSVf']['file_size'] * 8) / $ThisFileInfo['playtime_seconds']; - - return true; - } - - - function NSVframerateLookup($framerateindex) { - if ($framerateindex <= 127) { - return (float) $framerateindex; - } - - static $NSVframerateLookup = array(); - if (empty($NSVframerateLookup)) { - $NSVframerateLookup[129] = (float) 29.970; - $NSVframerateLookup[131] = (float) 23.976; - $NSVframerateLookup[133] = (float) 14.985; - $NSVframerateLookup[197] = (float) 59.940; - $NSVframerateLookup[199] = (float) 47.952; - } - return (isset($NSVframerateLookup[$framerateindex]) ? $NSVframerateLookup[$framerateindex] : false); - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio-video.quicktime.php b/serendipity_event_podcast/player/getid3/module.audio-video.quicktime.php deleted file mode 100644 index ebcb45e7..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio-video.quicktime.php +++ /dev/null @@ -1,1824 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio-video.quicktime.php // -// module for analyzing Quicktime and MP3-in-MP4 files // -// dependencies: module.audio.mp3.php // -// /// -///////////////////////////////////////////////////////////////// - -getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); - -class getid3_quicktime -{ - - function getid3_quicktime(&$fd, &$ThisFileInfo, $ReturnAtomData=true, $ParseAllPossibleAtoms=false) { - - $ThisFileInfo['fileformat'] = 'quicktime'; - $ThisFileInfo['quicktime']['hinting'] = false; - $ThisFileInfo['quicktime']['controller'] = 'standard'; // may be overridden if 'ctyp' atom is present - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - - $offset = 0; - $atomcounter = 0; - - while ($offset < $ThisFileInfo['avdataend']) { - if (!getid3_lib::intValueSupported($offset)) { - $ThisFileInfo['error'][] = 'Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions'; - break; - } - fseek($fd, $offset, SEEK_SET); - $AtomHeader = fread($fd, 8); - - $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4)); - $atomname = substr($AtomHeader, 4, 4); - - // 64-bit MOV patch by jlegateØktnc*com - if ($atomsize == 1) { - $atomsize = getid3_lib::BigEndian2Int(fread($fd, 8)); - } - - $ThisFileInfo['quicktime'][$atomname]['name'] = $atomname; - $ThisFileInfo['quicktime'][$atomname]['size'] = $atomsize; - $ThisFileInfo['quicktime'][$atomname]['offset'] = $offset; - - if (($offset + $atomsize) > $ThisFileInfo['avdataend']) { - $ThisFileInfo['error'][] = 'Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)'; - return false; - } - - if ($atomsize == 0) { - // Furthermore, for historical reasons the list of atoms is optionally - // terminated by a 32-bit integer set to 0. If you are writing a program - // to read user data atoms, you should allow for the terminating 0. - break; - } - switch ($atomname) { - case 'mdat': // Media DATa atom - // 'mdat' contains the actual data for the audio/video - if (($atomsize > 8) && (!isset($ThisFileInfo['avdataend_tmp']) || ($ThisFileInfo['quicktime'][$atomname]['size'] > ($ThisFileInfo['avdataend_tmp'] - $ThisFileInfo['avdataoffset'])))) { - - $ThisFileInfo['avdataoffset'] = $ThisFileInfo['quicktime'][$atomname]['offset'] + 8; - $OldAVDataEnd = $ThisFileInfo['avdataend']; - $ThisFileInfo['avdataend'] = $ThisFileInfo['quicktime'][$atomname]['offset'] + $ThisFileInfo['quicktime'][$atomname]['size']; - - if (getid3_mp3::MPEGaudioHeaderValid(getid3_mp3::MPEGaudioHeaderDecode(fread($fd, 4)))) { - getid3_mp3::getOnlyMPEGaudioInfo($fd, $ThisFileInfo, $ThisFileInfo['avdataoffset'], false); - if (isset($ThisFileInfo['mpeg']['audio'])) { - $ThisFileInfo['audio']['dataformat'] = 'mp3'; - $ThisFileInfo['audio']['codec'] = (!empty($ThisFileInfo['mpeg']['audio']['encoder']) ? $ThisFileInfo['mpeg']['audio']['encoder'] : (!empty($ThisFileInfo['mpeg']['audio']['codec']) ? $ThisFileInfo['mpeg']['audio']['codec'] : (!empty($ThisFileInfo['mpeg']['audio']['LAME']) ? 'LAME' :'mp3'))); - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate']; - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels']; - $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate']; - $ThisFileInfo['audio']['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitrate_mode']); - $ThisFileInfo['bitrate'] = $ThisFileInfo['audio']['bitrate']; - } - } - $ThisFileInfo['avdataend'] = $OldAVDataEnd; - unset($OldAVDataEnd); - - } - break; - - case 'free': // FREE space atom - case 'skip': // SKIP atom - case 'wide': // 64-bit expansion placeholder atom - // 'free', 'skip' and 'wide' are just padding, contains no useful data at all - break; - - default: - $atomHierarchy = array(); - $ThisFileInfo['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, fread($fd, $atomsize), $ThisFileInfo, $offset, $atomHierarchy, $ParseAllPossibleAtoms); - break; - } - - $offset += $atomsize; - $atomcounter++; - } - - if (!empty($ThisFileInfo['avdataend_tmp'])) { - // this value is assigned to a temp value and then erased because - // otherwise any atoms beyond the 'mdat' atom would not get parsed - $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataend_tmp']; - unset($ThisFileInfo['avdataend_tmp']); - } - - if (!isset($ThisFileInfo['bitrate']) && isset($ThisFileInfo['playtime_seconds'])) { - $ThisFileInfo['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; - } - if (isset($ThisFileInfo['bitrate']) && !isset($ThisFileInfo['audio']['bitrate']) && !isset($ThisFileInfo['quicktime']['video'])) { - $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['bitrate']; - } - if (!empty($ThisFileInfo['playtime_seconds']) && !isset($ThisFileInfo['video']['frame_rate']) && !empty($ThisFileInfo['quicktime']['stts_framecount'])) { - foreach ($ThisFileInfo['quicktime']['stts_framecount'] as $key => $samples_count) { - $samples_per_second = $samples_count / $ThisFileInfo['playtime_seconds']; - if ($samples_per_second > 240) { - // has to be audio samples - } else { - $ThisFileInfo['video']['frame_rate'] = $samples_per_second; - break; - } - } - } - if (($ThisFileInfo['audio']['dataformat'] == 'mp4') && empty($ThisFileInfo['video']['resolution_x'])) { - $ThisFileInfo['fileformat'] = 'mp4'; - $ThisFileInfo['mime_type'] = 'audio/mp4'; - unset($ThisFileInfo['video']['dataformat']); - } - - if (!$ReturnAtomData) { - unset($ThisFileInfo['quicktime']['moov']); - } - - if (empty($ThisFileInfo['audio']['dataformat']) && !empty($ThisFileInfo['quicktime']['audio'])) { - $ThisFileInfo['audio']['dataformat'] = 'quicktime'; - } - if (empty($ThisFileInfo['video']['dataformat']) && !empty($ThisFileInfo['quicktime']['video'])) { - $ThisFileInfo['video']['dataformat'] = 'quicktime'; - } - - return true; - } - - function QuicktimeParseAtom($atomname, $atomsize, $atom_data, &$ThisFileInfo, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) { - // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm - - $atomparent = array_pop($atomHierarchy); - array_push($atomHierarchy, $atomname); - $atom_structure['hierarchy'] = implode(' ', $atomHierarchy); - $atom_structure['name'] = $atomname; - $atom_structure['size'] = $atomsize; - $atom_structure['offset'] = $baseoffset; - switch ($atomname) { - case 'moov': // MOVie container atom - case 'trak': // TRAcK container atom - case 'clip': // CLIPping container atom - case 'matt': // track MATTe container atom - case 'edts': // EDiTS container atom - case 'tref': // Track REFerence container atom - case 'mdia': // MeDIA container atom - case 'minf': // Media INFormation container atom - case 'dinf': // Data INFormation container atom - case 'udta': // User DaTA container atom - case 'cmov': // Compressed MOVie container atom - case 'rmra': // Reference Movie Record Atom - case 'rmda': // Reference Movie Descriptor Atom - case 'gmhd': // Generic Media info HeaDer atom (seen on QTVR) - case 'ilst': // Item LiST container atom - $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $ThisFileInfo, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); - break; - - case 'stbl': // Sample TaBLe container atom - $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $ThisFileInfo, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); - $isVideo = false; - $framerate = 0; - $framecount = 0; - foreach ($atom_structure['subatoms'] as $key => $value_array) { - if (isset($value_array['sample_description_table'])) { - foreach ($value_array['sample_description_table'] as $key2 => $value_array2) { - if (isset($value_array2['data_format'])) { - switch ($value_array2['data_format']) { - case 'avc1': - case 'mp4v': - // video data - $isVideo = true; - break; - case 'mp4a': - // audio data - break; - } - } - } - } elseif (isset($value_array['time_to_sample_table'])) { - foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) { - if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration']) && ($value_array2['sample_duration'] > 0)) { - $framerate = round($ThisFileInfo['quicktime']['time_scale'] / $value_array2['sample_duration'], 3); - $framecount = $value_array2['sample_count']; - } - } - } - } - if ($isVideo && $framerate) { - $ThisFileInfo['quicktime']['video']['frame_rate'] = $framerate; - $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['quicktime']['video']['frame_rate']; - } - if ($isVideo && $framecount) { - $ThisFileInfo['quicktime']['video']['frame_count'] = $framecount; - } - break; - - - case 'aART': // Album ARTist - case 'catg': // CaTeGory - case 'covr': // COVeR artwork - case 'cpil': // ComPILation - case 'cprt': // CoPyRighT - case 'desc': // DESCription - case 'disk': // DISK number - case 'egid': // Episode Global ID - case 'gnre': // GeNRE - case 'keyw': // KEYWord - case 'ldes': - case 'pcst': // PodCaST - case 'pgap': // GAPless Playback - case 'purd': // PURchase Date - case 'purl': // Podcast URL - case 'rati': - case 'rndu': - case 'rpdu': - case 'rtng': // RaTiNG - case 'stik': - case 'tmpo': // TeMPO (BPM) - case 'trkn': // TRacK Number - case 'tves': // TV EpiSode - case 'tvnn': // TV Network Name - case 'tvsh': // TV SHow Name - case 'tvsn': // TV SeasoN - case 'akID': // iTunes store account type - case 'apID': - case 'atID': - case 'cmID': - case 'cnID': - case 'geID': - case 'plID': - case 'sfID': // iTunes store country - case '©alb': // ALBum - case '©art': // ARTist - case '©ART': - case '©aut': - case '©cmt': // CoMmenT - case '©com': // COMposer - case '©cpy': - case '©day': // content created year - case '©dir': - case '©ed1': - case '©ed2': - case '©ed3': - case '©ed4': - case '©ed5': - case '©ed6': - case '©ed7': - case '©ed8': - case '©ed9': - case '©enc': - case '©fmt': - case '©gen': // GENre - case '©grp': // GRouPing - case '©hst': - case '©inf': - case '©lyr': // LYRics - case '©mak': - case '©mod': - case '©nam': // full NAMe - case '©ope': - case '©PRD': - case '©prd': - case '©prf': - case '©req': - case '©src': - case '©swr': - case '©too': // encoder - case '©trk': // TRacK - case '©url': - case '©wrn': - case '©wrt': // WRiTer - case '----': // itunes specific - if ($atomparent == 'udta') { - // User data atom handler - $atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); - $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); - $atom_structure['data'] = substr($atom_data, 4); - - $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); - if (empty($ThisFileInfo['comments']['language']) || (!in_array($atom_structure['language'], $ThisFileInfo['comments']['language']))) { - $ThisFileInfo['comments']['language'][] = $atom_structure['language']; - } - } else { - // Apple item list box atom handler - $atomoffset = 0; - while ($atomoffset < strlen($atom_data)) { - $boxsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 4)); - $boxtype = substr($atom_data, $atomoffset + 4, 4); - $boxdata = substr($atom_data, $atomoffset + 8, $boxsize - 8); - - switch ($boxtype) { - case 'mean': - case 'name': - $atom_structure[$boxtype] = substr($boxdata, 4); - break; - - case 'data': - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($boxdata, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($boxdata, 1, 3)); - switch ($atom_structure['flags_raw']) { - case 0: // data flag - case 21: // tmpo/cpil flag - switch ($atomname) { - case 'cpil': - case 'pcst': - case 'pgap': - $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); - break; - - case 'tmpo': - $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 2)); - break; - - case 'disk': - case 'trkn': - $num = getid3_lib::BigEndian2Int(substr($boxdata, 10, 2)); - $num_total = getid3_lib::BigEndian2Int(substr($boxdata, 12, 2)); - $atom_structure['data'] = empty($num) ? '' : $num; - $atom_structure['data'] .= empty($num_total) ? '' : '/'.$num_total; - break; - - case 'gnre': - $GenreID = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); - $atom_structure['data'] = getid3_id3v1::LookupGenreName($GenreID - 1); - break; - - case 'rtng': - $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); - $atom_structure['data'] = $this->QuicktimeContentRatingLookup($atom_structure[$atomname]); - break; - - case 'stik': - $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); - $atom_structure['data'] = $this->QuicktimeSTIKLookup($atom_structure[$atomname]); - break; - - case 'sfID': - $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); - $atom_structure['data'] = $this->QuicktimeStoreFrontCodeLookup($atom_structure[$atomname]); - break; - - case 'egid': - case 'purl': - $atom_structure['data'] = substr($boxdata, 8); - break; - - default: - $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); - } - break; - - case 1: // text flag - case 13: // image flag - default: - $atom_structure['data'] = substr($boxdata, 8); - break; - - } - break; - - default: - $ThisFileInfo['warning'][] = 'Unknown QuickTime box type: "'.$boxtype.'" at offset '.$baseoffset; - $atom_structure['data'] = $atom_data; - - } - $atomoffset += $boxsize; - } - } - $this->CopyToAppropriateCommentsSection($atomname, $atom_structure['data'], $ThisFileInfo, $atom_structure['name']); - break; - - - case 'play': // auto-PLAY atom - $atom_structure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - - $ThisFileInfo['quicktime']['autoplay'] = $atom_structure['autoplay']; - break; - - - case 'WLOC': // Window LOCation atom - $atom_structure['location_x'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); - $atom_structure['location_y'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); - break; - - - case 'LOOP': // LOOPing atom - case 'SelO': // play SELection Only atom - case 'AllF': // play ALL Frames atom - $atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data); - break; - - - case 'name': // - case 'MCPS': // Media Cleaner PRo - case '@PRM': // adobe PReMiere version - case '@PRQ': // adobe PRemiere Quicktime version - $atom_structure['data'] = $atom_data; - break; - - - case 'cmvd': // Compressed MooV Data atom - // Code by ubergeekØubergeek*tv based on information from - // http://developer.apple.com/quicktime/icefloe/dispatch012.html - $atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); - - $CompressedFileData = substr($atom_data, 4); - ob_start(); - if ($UncompressedHeader = gzuncompress($CompressedFileData)) { - ob_end_clean(); - $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, $ThisFileInfo, 0, $atomHierarchy, $ParseAllPossibleAtoms); - } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - $ThisFileInfo['warning'][] = 'Error decompressing compressed MOV atom at offset '.$atom_structure['offset']; - } - break; - - - case 'dcom': // Data COMpression atom - $atom_structure['compression_id'] = $atom_data; - $atom_structure['compression_text'] = $this->QuicktimeDCOMLookup($atom_data); - break; - - - case 'rdrf': // Reference movie Data ReFerence atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); - $atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x000001); - - $atom_structure['reference_type_name'] = substr($atom_data, 4, 4); - $atom_structure['reference_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); - switch ($atom_structure['reference_type_name']) { - case 'url ': - $atom_structure['url'] = $this->NoNullString(substr($atom_data, 12)); - break; - - case 'alis': - $atom_structure['file_alias'] = substr($atom_data, 12); - break; - - case 'rsrc': - $atom_structure['resource_alias'] = substr($atom_data, 12); - break; - - default: - $atom_structure['data'] = substr($atom_data, 12); - break; - } - break; - - - case 'rmqu': // Reference Movie QUality atom - $atom_structure['movie_quality'] = getid3_lib::BigEndian2Int($atom_data); - break; - - - case 'rmcs': // Reference Movie Cpu Speed atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['cpu_speed_rating'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); - break; - - - case 'rmvc': // Reference Movie Version Check atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['gestalt_selector'] = substr($atom_data, 4, 4); - $atom_structure['gestalt_value_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); - $atom_structure['gestalt_value'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); - $atom_structure['gestalt_check_type'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2)); - break; - - - case 'rmcd': // Reference Movie Component check atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['component_type'] = substr($atom_data, 4, 4); - $atom_structure['component_subtype'] = substr($atom_data, 8, 4); - $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4); - $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); - $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); - $atom_structure['component_min_version'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 4)); - break; - - - case 'rmdr': // Reference Movie Data Rate atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['data_rate'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - - $atom_structure['data_rate_bps'] = $atom_structure['data_rate'] * 10; - break; - - - case 'rmla': // Reference Movie Language Atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); - - $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); - if (empty($ThisFileInfo['comments']['language']) || (!in_array($atom_structure['language'], $ThisFileInfo['comments']['language']))) { - $ThisFileInfo['comments']['language'][] = $atom_structure['language']; - } - break; - - - case 'rmla': // Reference Movie Language Atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); - break; - - - case 'ptv ': // Print To Video - defines a movie's full screen mode - // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm - $atom_structure['display_size_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); - $atom_structure['reserved_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); // hardcoded: 0x0000 - $atom_structure['reserved_2'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x0000 - $atom_structure['slide_show_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 1)); - $atom_structure['play_on_open_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 7, 1)); - - $atom_structure['flags']['play_on_open'] = (bool) $atom_structure['play_on_open_flag']; - $atom_structure['flags']['slide_show'] = (bool) $atom_structure['slide_show_flag']; - - $ptv_lookup[0] = 'normal'; - $ptv_lookup[1] = 'double'; - $ptv_lookup[2] = 'half'; - $ptv_lookup[3] = 'full'; - $ptv_lookup[4] = 'current'; - if (isset($ptv_lookup[$atom_structure['display_size_raw']])) { - $atom_structure['display_size'] = $ptv_lookup[$atom_structure['display_size_raw']]; - } else { - $ThisFileInfo['warning'][] = 'unknown "ptv " display constant ('.$atom_structure['display_size_raw'].')'; - } - break; - - - case 'stsd': // Sample Table Sample Description atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $stsdEntriesDataOffset = 8; - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['sample_description_table'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 4)); - $stsdEntriesDataOffset += 4; - $atom_structure['sample_description_table'][$i]['data_format'] = substr($atom_data, $stsdEntriesDataOffset, 4); - $stsdEntriesDataOffset += 4; - $atom_structure['sample_description_table'][$i]['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 6)); - $stsdEntriesDataOffset += 6; - $atom_structure['sample_description_table'][$i]['reference_index'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 2)); - $stsdEntriesDataOffset += 2; - $atom_structure['sample_description_table'][$i]['data'] = substr($atom_data, $stsdEntriesDataOffset, ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2)); - $stsdEntriesDataOffset += ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2); - - $atom_structure['sample_description_table'][$i]['encoder_version'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 0, 2)); - $atom_structure['sample_description_table'][$i]['encoder_revision'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 2, 2)); - $atom_structure['sample_description_table'][$i]['encoder_vendor'] = substr($atom_structure['sample_description_table'][$i]['data'], 4, 4); - - switch ($atom_structure['sample_description_table'][$i]['encoder_vendor']) { - - case "\x00\x00\x00\x00": - // audio atom - $atom_structure['sample_description_table'][$i]['audio_channels'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 2)); - $atom_structure['sample_description_table'][$i]['audio_bit_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 10, 2)); - $atom_structure['sample_description_table'][$i]['audio_compression_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 2)); - $atom_structure['sample_description_table'][$i]['audio_packet_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 14, 2)); - $atom_structure['sample_description_table'][$i]['audio_sample_rate'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 16, 4)); - - switch ($atom_structure['sample_description_table'][$i]['data_format']) { - case 'avc1': - case 'mp4v': - $ThisFileInfo['fileformat'] = 'mp4'; - $ThisFileInfo['video']['fourcc'] = $atom_structure['sample_description_table'][$i]['data_format']; - //$ThisFileInfo['warning'][] = 'This version of getID3() [v'.GETID3_VERSION.'] does not fully support MPEG-4 audio/video streams'; // 2011-02-18: why am I warning about this again? What's not supported? - break; - - case 'qtvr': - $ThisFileInfo['video']['dataformat'] = 'quicktimevr'; - break; - - case 'mp4a': - default: - $ThisFileInfo['quicktime']['audio']['codec'] = $this->QuicktimeAudioCodecLookup($atom_structure['sample_description_table'][$i]['data_format']); - $ThisFileInfo['quicktime']['audio']['sample_rate'] = $atom_structure['sample_description_table'][$i]['audio_sample_rate']; - $ThisFileInfo['quicktime']['audio']['channels'] = $atom_structure['sample_description_table'][$i]['audio_channels']; - $ThisFileInfo['quicktime']['audio']['bit_depth'] = $atom_structure['sample_description_table'][$i]['audio_bit_depth']; - $ThisFileInfo['audio']['codec'] = $ThisFileInfo['quicktime']['audio']['codec']; - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['quicktime']['audio']['sample_rate']; - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['quicktime']['audio']['channels']; - $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['quicktime']['audio']['bit_depth']; - switch ($atom_structure['sample_description_table'][$i]['data_format']) { - case 'raw ': // PCM - case 'alac': // Apple Lossless Audio Codec - $ThisFileInfo['audio']['lossless'] = true; - break; - default: - $ThisFileInfo['audio']['lossless'] = false; - break; - } - break; - } - break; - - default: - switch ($atom_structure['sample_description_table'][$i]['data_format']) { - case 'mp4s': - $ThisFileInfo['fileformat'] = 'mp4'; - break; - - default: - // video atom - $atom_structure['sample_description_table'][$i]['video_temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4)); - $atom_structure['sample_description_table'][$i]['video_spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4)); - $atom_structure['sample_description_table'][$i]['video_frame_width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2)); - $atom_structure['sample_description_table'][$i]['video_frame_height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2)); - $atom_structure['sample_description_table'][$i]['video_resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 20, 4)); - $atom_structure['sample_description_table'][$i]['video_resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4)); - $atom_structure['sample_description_table'][$i]['video_data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4)); - $atom_structure['sample_description_table'][$i]['video_frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 2)); - $atom_structure['sample_description_table'][$i]['video_encoder_name_len'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 34, 1)); - $atom_structure['sample_description_table'][$i]['video_encoder_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 35, $atom_structure['sample_description_table'][$i]['video_encoder_name_len']); - $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 66, 2)); - $atom_structure['sample_description_table'][$i]['video_color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 68, 2)); - - $atom_structure['sample_description_table'][$i]['video_pixel_color_type'] = (($atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] > 32) ? 'grayscale' : 'color'); - $atom_structure['sample_description_table'][$i]['video_pixel_color_name'] = $this->QuicktimeColorNameLookup($atom_structure['sample_description_table'][$i]['video_pixel_color_depth']); - - if ($atom_structure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') { - $ThisFileInfo['quicktime']['video']['codec_fourcc'] = $atom_structure['sample_description_table'][$i]['data_format']; - $ThisFileInfo['quicktime']['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atom_structure['sample_description_table'][$i]['data_format']); - $ThisFileInfo['quicktime']['video']['codec'] = (($atom_structure['sample_description_table'][$i]['video_encoder_name_len'] > 0) ? $atom_structure['sample_description_table'][$i]['video_encoder_name'] : $atom_structure['sample_description_table'][$i]['data_format']); - $ThisFileInfo['quicktime']['video']['color_depth'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth']; - $ThisFileInfo['quicktime']['video']['color_depth_name'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_name']; - - $ThisFileInfo['video']['codec'] = $ThisFileInfo['quicktime']['video']['codec']; - $ThisFileInfo['video']['bits_per_sample'] = $ThisFileInfo['quicktime']['video']['color_depth']; - } - $ThisFileInfo['video']['lossless'] = false; - $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1; - break; - } - break; - } - switch (strtolower($atom_structure['sample_description_table'][$i]['data_format'])) { - case 'mp4a': - $ThisFileInfo['audio']['dataformat'] = 'mp4'; - $ThisFileInfo['quicktime']['audio']['codec'] = 'mp4'; - break; - - case '3ivx': - case '3iv1': - case '3iv2': - $ThisFileInfo['video']['dataformat'] = '3ivx'; - break; - - case 'xvid': - $ThisFileInfo['video']['dataformat'] = 'xvid'; - break; - - case 'mp4v': - $ThisFileInfo['video']['dataformat'] = 'mpeg4'; - break; - - case 'divx': - case 'div1': - case 'div2': - case 'div3': - case 'div4': - case 'div5': - case 'div6': - $TDIVXileInfo['video']['dataformat'] = 'divx'; - break; - - default: - // do nothing - break; - } - unset($atom_structure['sample_description_table'][$i]['data']); - } - break; - - - case 'stts': // Sample Table Time-to-Sample atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $sttsEntriesDataOffset = 8; - //$FrameRateCalculatorArray = array(); - $frames_count = 0; - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4)); - $sttsEntriesDataOffset += 4; - $atom_structure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4)); - $sttsEntriesDataOffset += 4; - - $frames_count += $atom_structure['time_to_sample_table'][$i]['sample_count']; - - // THIS SECTION REPLACED WITH CODE IN "stbl" ATOM - //if (!empty($ThisFileInfo['quicktime']['time_scale']) && ($atom_structure['time_to_sample_table'][$i]['sample_duration'] > 0)) { - // $stts_new_framerate = $ThisFileInfo['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration']; - // if ($stts_new_framerate <= 60) { - // // some atoms have durations of "1" giving a very large framerate, which probably is not right - // $ThisFileInfo['video']['frame_rate'] = max($ThisFileInfo['video']['frame_rate'], $stts_new_framerate); - // } - //} - // - //$FrameRateCalculatorArray[($ThisFileInfo['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'])] += $atom_structure['time_to_sample_table'][$i]['sample_count']; - } - $ThisFileInfo['quicktime']['stts_framecount'][] = $frames_count; - //$sttsFramesTotal = 0; - //$sttsSecondsTotal = 0; - //foreach ($FrameRateCalculatorArray as $frames_per_second => $frame_count) { - // if (($frames_per_second > 60) || ($frames_per_second < 1)) { - // // not video FPS information, probably audio information - // $sttsFramesTotal = 0; - // $sttsSecondsTotal = 0; - // break; - // } - // $sttsFramesTotal += $frame_count; - // $sttsSecondsTotal += $frame_count / $frames_per_second; - //} - //if (($sttsFramesTotal > 0) && ($sttsSecondsTotal > 0)) { - // if (($sttsFramesTotal / $sttsSecondsTotal) > $ThisFileInfo['video']['frame_rate']) { - // $ThisFileInfo['video']['frame_rate'] = $sttsFramesTotal / $sttsSecondsTotal; - // } - //} - break; - - - case 'stss': // Sample Table Sync Sample (key frames) atom - if ($ParseAllPossibleAtoms) { - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $stssEntriesDataOffset = 8; - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stssEntriesDataOffset, 4)); - $stssEntriesDataOffset += 4; - } - } - break; - - - case 'stsc': // Sample Table Sample-to-Chunk atom - if ($ParseAllPossibleAtoms) { - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $stscEntriesDataOffset = 8; - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['sample_to_chunk_table'][$i]['first_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); - $stscEntriesDataOffset += 4; - $atom_structure['sample_to_chunk_table'][$i]['samples_per_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); - $stscEntriesDataOffset += 4; - $atom_structure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); - $stscEntriesDataOffset += 4; - } - } - break; - - - case 'stsz': // Sample Table SiZe atom - if ($ParseAllPossibleAtoms) { - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['sample_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); - $stszEntriesDataOffset = 12; - if ($atom_structure['sample_size'] == 0) { - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stszEntriesDataOffset, 4)); - $stszEntriesDataOffset += 4; - } - } - } - break; - - - case 'stco': // Sample Table Chunk Offset atom - if ($ParseAllPossibleAtoms) { - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $stcoEntriesDataOffset = 8; - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 4)); - $stcoEntriesDataOffset += 4; - } - } - break; - - - case 'co64': // Chunk Offset 64-bit (version of "stco" that supports > 2GB files) - if ($ParseAllPossibleAtoms) { - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $stcoEntriesDataOffset = 8; - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 8)); - $stcoEntriesDataOffset += 8; - } - } - break; - - - case 'dref': // Data REFerence atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $drefDataOffset = 8; - for ($i = 0; $i < $atom_structure['number_entries']; $i++) { - $atom_structure['data_references'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 4)); - $drefDataOffset += 4; - $atom_structure['data_references'][$i]['type'] = substr($atom_data, $drefDataOffset, 4); - $drefDataOffset += 4; - $atom_structure['data_references'][$i]['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 1)); - $drefDataOffset += 1; - $atom_structure['data_references'][$i]['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 3)); // hardcoded: 0x0000 - $drefDataOffset += 3; - $atom_structure['data_references'][$i]['data'] = substr($atom_data, $drefDataOffset, ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3)); - $drefDataOffset += ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3); - - $atom_structure['data_references'][$i]['flags']['self_reference'] = (bool) ($atom_structure['data_references'][$i]['flags_raw'] & 0x001); - } - break; - - - case 'gmin': // base Media INformation atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); - $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); - $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2)); - $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); - $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 2)); - $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2)); - break; - - - case 'smhd': // Sound Media information HeaDer atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); - $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); - break; - - - case 'vmhd': // Video Media information HeaDer atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); - $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); - $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); - $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2)); - $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); - - $atom_structure['flags']['no_lean_ahead'] = (bool) ($atom_structure['flags_raw'] & 0x001); - break; - - - case 'hdlr': // HanDLeR reference atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['component_type'] = substr($atom_data, 4, 4); - $atom_structure['component_subtype'] = substr($atom_data, 8, 4); - $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4); - $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); - $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); - $atom_structure['component_name'] = $this->Pascal2String(substr($atom_data, 24)); - - if (($atom_structure['component_subtype'] == 'STpn') && ($atom_structure['component_manufacturer'] == 'zzzz')) { - $ThisFileInfo['video']['dataformat'] = 'quicktimevr'; - } - break; - - - case 'mdhd': // MeDia HeaDer atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); - $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); - $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); - $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 2)); - $atom_structure['quality'] = getid3_lib::BigEndian2Int(substr($atom_data, 22, 2)); - - if ($atom_structure['time_scale'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt Quicktime file: mdhd.time_scale == zero'; - return false; - } - $ThisFileInfo['quicktime']['time_scale'] = (isset($ThisFileInfo['quicktime']['time_scale']) ? max($ThisFileInfo['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']); - - $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); - $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); - $atom_structure['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale']; - $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); - if (empty($ThisFileInfo['comments']['language']) || (!in_array($atom_structure['language'], $ThisFileInfo['comments']['language']))) { - $ThisFileInfo['comments']['language'][] = $atom_structure['language']; - } - break; - - - case 'pnot': // Preview atom - $atom_structure['modification_date'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // "standard Macintosh format" - $atom_structure['version_number'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x00 - $atom_structure['atom_type'] = substr($atom_data, 6, 4); // usually: 'PICT' - $atom_structure['atom_index'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); // usually: 0x01 - - $atom_structure['modification_date_unix'] = getid3_lib::DateMac2Unix($atom_structure['modification_date']); - break; - - - case 'crgn': // Clipping ReGioN atom - $atom_structure['region_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); // The Region size, Region boundary box, - $atom_structure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 8)); // and Clipping region data fields - $atom_structure['clipping_data'] = substr($atom_data, 10); // constitute a QuickDraw region. - break; - - - case 'load': // track LOAD settings atom - $atom_structure['preload_start_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); - $atom_structure['preload_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $atom_structure['preload_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); - $atom_structure['default_hints_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); - - $atom_structure['default_hints']['double_buffer'] = (bool) ($atom_structure['default_hints_raw'] & 0x0020); - $atom_structure['default_hints']['high_quality'] = (bool) ($atom_structure['default_hints_raw'] & 0x0100); - break; - - - case 'tmcd': // TiMe CoDe atom - case 'chap': // CHAPter list atom - case 'sync': // SYNChronization atom - case 'scpt': // tranSCriPT atom - case 'ssrc': // non-primary SouRCe atom - for ($i = 0; $i < (strlen($atom_data) % 4); $i++) { - $atom_structure['track_id'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $i * 4, 4)); - } - break; - - - case 'elst': // Edit LiST atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - for ($i = 0; $i < $atom_structure['number_entries']; $i++ ) { - $atom_structure['edit_list'][$i]['track_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 0, 4)); - $atom_structure['edit_list'][$i]['media_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 4, 4)); - $atom_structure['edit_list'][$i]['media_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 8 + ($i * 12) + 8, 4)); - } - break; - - - case 'kmat': // compressed MATte atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 - $atom_structure['matte_data_raw'] = substr($atom_data, 4); - break; - - - case 'ctab': // Color TABle atom - $atom_structure['color_table_seed'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // hardcoded: 0x00000000 - $atom_structure['color_table_flags'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x8000 - $atom_structure['color_table_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)) + 1; - for ($colortableentry = 0; $colortableentry < $atom_structure['color_table_size']; $colortableentry++) { - $atom_structure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 0, 2)); - $atom_structure['color_table'][$colortableentry]['red'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 2, 2)); - $atom_structure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 4, 2)); - $atom_structure['color_table'][$colortableentry]['blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 6, 2)); - } - break; - - - case 'mvhd': // MoVie HeaDer atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); - $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); - $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); - $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); - $atom_structure['preferred_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 20, 4)); - $atom_structure['preferred_volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 24, 2)); - $atom_structure['reserved'] = substr($atom_data, 26, 10); - $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 36, 4)); - $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4)); - $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 44, 4)); - $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 48, 4)); - $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4)); - $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 56, 4)); - $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 60, 4)); - $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4)); - $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 68, 4)); - $atom_structure['preview_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 72, 4)); - $atom_structure['preview_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 76, 4)); - $atom_structure['poster_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 80, 4)); - $atom_structure['selection_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 84, 4)); - $atom_structure['selection_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 88, 4)); - $atom_structure['current_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 92, 4)); - $atom_structure['next_track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 96, 4)); - - if ($atom_structure['time_scale'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt Quicktime file: mvhd.time_scale == zero'; - return false; - } - $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); - $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); - $ThisFileInfo['quicktime']['time_scale'] = (isset($ThisFileInfo['quicktime']['time_scale']) ? max($ThisFileInfo['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']); - $ThisFileInfo['quicktime']['display_scale'] = $atom_structure['matrix_a']; - $ThisFileInfo['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale']; - break; - - - case 'tkhd': // TracK HeaDer atom - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); - $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); - $atom_structure['trackid'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); - $atom_structure['reserved1'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); - $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); - $atom_structure['reserved2'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 8)); - $atom_structure['layer'] = getid3_lib::BigEndian2Int(substr($atom_data, 32, 2)); - $atom_structure['alternate_group'] = getid3_lib::BigEndian2Int(substr($atom_data, 34, 2)); - $atom_structure['volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 36, 2)); - $atom_structure['reserved3'] = getid3_lib::BigEndian2Int(substr($atom_data, 38, 2)); - $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4)); - $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 44, 4)); - $atom_structure['matrix_u'] = getid3_lib::FixedPoint16_16(substr($atom_data, 48, 4)); - $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4)); - $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 56, 4)); - $atom_structure['matrix_v'] = getid3_lib::FixedPoint16_16(substr($atom_data, 60, 4)); - $atom_structure['matrix_x'] = getid3_lib::FixedPoint2_30(substr($atom_data, 64, 4)); - $atom_structure['matrix_y'] = getid3_lib::FixedPoint2_30(substr($atom_data, 68, 4)); - $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 72, 4)); - $atom_structure['width'] = getid3_lib::FixedPoint16_16(substr($atom_data, 76, 4)); - $atom_structure['height'] = getid3_lib::FixedPoint16_16(substr($atom_data, 80, 4)); - - $atom_structure['flags']['enabled'] = (bool) ($atom_structure['flags_raw'] & 0x0001); - $atom_structure['flags']['in_movie'] = (bool) ($atom_structure['flags_raw'] & 0x0002); - $atom_structure['flags']['in_preview'] = (bool) ($atom_structure['flags_raw'] & 0x0004); - $atom_structure['flags']['in_poster'] = (bool) ($atom_structure['flags_raw'] & 0x0008); - $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); - $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); - - if ($atom_structure['flags']['enabled'] == 1) { - if (!isset($ThisFileInfo['video']['resolution_x']) || !isset($ThisFileInfo['video']['resolution_y'])) { - $ThisFileInfo['video']['resolution_x'] = $atom_structure['width']; - $ThisFileInfo['video']['resolution_y'] = $atom_structure['height']; - } - $ThisFileInfo['video']['resolution_x'] = max($ThisFileInfo['video']['resolution_x'], $atom_structure['width']); - $ThisFileInfo['video']['resolution_y'] = max($ThisFileInfo['video']['resolution_y'], $atom_structure['height']); - $ThisFileInfo['quicktime']['video']['resolution_x'] = $ThisFileInfo['video']['resolution_x']; - $ThisFileInfo['quicktime']['video']['resolution_y'] = $ThisFileInfo['video']['resolution_y']; - } else { - if (isset($ThisFileInfo['video']['resolution_x'])) { unset($ThisFileInfo['video']['resolution_x']); } - if (isset($ThisFileInfo['video']['resolution_y'])) { unset($ThisFileInfo['video']['resolution_y']); } - if (isset($ThisFileInfo['quicktime']['video'])) { unset($ThisFileInfo['quicktime']['video']); } - } - break; - - - case 'iods': // Initial Object DeScriptor atom - // http://www.koders.com/c/fid1FAB3E762903DC482D8A246D4A4BF9F28E049594.aspx?s=windows.h - // http://libquicktime.sourcearchive.com/documentation/1.0.2plus-pdebian/iods_8c-source.html - $offset = 0; - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 3)); - $offset += 3; - $atom_structure['mp4_iod_tag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - $atom_structure['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset); - //$offset already adjusted by quicktime_read_mp4_descr_length() - $atom_structure['object_descriptor_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); - $offset += 2; - $atom_structure['od_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - $atom_structure['scene_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - $atom_structure['audio_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - $atom_structure['video_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - $atom_structure['graphics_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - - $atom_structure['num_iods_tracks'] = ($atom_structure['length'] - 7) / 6; // 6 bytes would only be right if all tracks use 1-byte length fields - for ($i = 0; $i < $atom_structure['num_iods_tracks']; $i++) { - $atom_structure['track'][$i]['ES_ID_IncTag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); - $offset += 1; - $atom_structure['track'][$i]['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset); - //$offset already adjusted by quicktime_read_mp4_descr_length() - $atom_structure['track'][$i]['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4)); - $offset += 4; - } - - $atom_structure['audio_profile_name'] = $this->QuicktimeIODSaudioProfileName($atom_structure['audio_profile_id']); - $atom_structure['video_profile_name'] = $this->QuicktimeIODSvideoProfileName($atom_structure['video_profile_id']); - break; - - case 'meta': // METAdata atom - // http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt - /* - $NextTagPosition = strpos($atom_data, '©'); - while ($NextTagPosition < strlen($atom_data)) { - $metaItemSize = getid3_lib::BigEndian2Int(substr($atom_data, $NextTagPosition - 4, 4)) - 4; - if ($metaItemSize == -4) { - break; - } - $metaItemRaw = substr($atom_data, $NextTagPosition, $metaItemSize); - $metaItemKey = substr($metaItemRaw, 0, 4); - $metaItemData = substr($metaItemRaw, 20); - $NextTagPosition += $metaItemSize + 4; - - $this->CopyToAppropriateCommentsSection($metaItemKey, $metaItemData, $ThisFileInfo); - } - */ - $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); - $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); - $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom(substr($atom_data, 4), $ThisFileInfo, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); - break; - - case 'ftyp': // FileTYPe (?) atom (for MP4 it seems) - $atom_structure['signature'] = substr($atom_data, 0, 4); - $atom_structure['unknown_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); - $atom_structure['fourcc'] = substr($atom_data, 8, 4); - break; - - case 'mdat': // Media DATa atom - case 'free': // FREE space atom - case 'skip': // SKIP atom - case 'wide': // 64-bit expansion placeholder atom - // 'mdat' data is too big to deal with, contains no useful metadata - // 'free', 'skip' and 'wide' are just padding, contains no useful data at all - - // When writing QuickTime files, it is sometimes necessary to update an atom's size. - // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom - // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime - // puts an 8-byte placeholder atom before any atoms it may have to update the size of. - // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the - // placeholder atom can be overwritten to obtain the necessary 8 extra bytes. - // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ). - break; - - - case 'nsav': // NoSAVe atom - // http://developer.apple.com/technotes/tn/tn2038.html - $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); - break; - - case 'ctyp': // Controller TYPe atom (seen on QTVR) - // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt - // some controller names are: - // 0x00 + 'std' for linear movie - // 'none' for no controls - $atom_structure['ctyp'] = substr($atom_data, 0, 4); - $ThisFileInfo['quicktime']['controller'] = $atom_structure['ctyp']; - switch ($atom_structure['ctyp']) { - case 'qtvr': - $ThisFileInfo['video']['dataformat'] = 'quicktimevr'; - break; - } - break; - - case 'pano': // PANOrama track (seen on QTVR) - $atom_structure['pano'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); - break; - - case 'hint': // HINT track - case 'hinf': // - case 'hinv': // - case 'hnti': // - $ThisFileInfo['quicktime']['hinting'] = true; - break; - - case 'imgt': // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR) - for ($i = 0; $i < ($atom_structure['size'] - 8); $i += 4) { - $atom_structure['imgt'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4)); - } - break; - - - // Observed-but-not-handled atom types are just listed here to prevent warnings being generated - case 'FXTC': // Something to do with Adobe After Effects (?) - case 'PrmA': - case 'code': - case 'FIEL': // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html - case 'tapt': // TrackApertureModeDimensionsAID - http://developer.apple.com/documentation/QuickTime/Reference/QT7-1_Update_Reference/Constants/Constants.html - // tapt seems to be used to compute the video size [http://www.getid3.org/phpBB3/viewtopic.php?t=838] - // * http://lists.apple.com/archives/quicktime-api/2006/Aug/msg00014.html - // * http://handbrake.fr/irclogs/handbrake-dev/handbrake-dev20080128_pg2.html - case 'ctts':// STCompositionOffsetAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html - case 'cslg':// STCompositionShiftLeastGreatestAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html - case 'sdtp':// STSampleDependencyAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html - case 'stps':// STPartialSyncSampleAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html - //$atom_structure['data'] = $atom_data; - break; - - default: - $ThisFileInfo['warning'][] = 'Unknown QuickTime atom type: "'.$atomname.'" at offset '.$baseoffset; - $atom_structure['data'] = $atom_data; - break; - } - array_pop($atomHierarchy); - return $atom_structure; - } - - function QuicktimeParseContainerAtom($atom_data, &$ThisFileInfo, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) { - $atom_structure = false; - $subatomoffset = 0; - $subatomcounter = 0; - if ((strlen($atom_data) == 4) && (getid3_lib::BigEndian2Int($atom_data) == 0x00000000)) { - return false; - } - while ($subatomoffset < strlen($atom_data)) { - $subatomsize = getid3_lib::BigEndian2Int(substr($atom_data, $subatomoffset + 0, 4)); - $subatomname = substr($atom_data, $subatomoffset + 4, 4); - $subatomdata = substr($atom_data, $subatomoffset + 8, $subatomsize - 8); - if ($subatomsize == 0) { - // Furthermore, for historical reasons the list of atoms is optionally - // terminated by a 32-bit integer set to 0. If you are writing a program - // to read user data atoms, you should allow for the terminating 0. - return $atom_structure; - } - - $atom_structure[$subatomcounter] = $this->QuicktimeParseAtom($subatomname, $subatomsize, $subatomdata, $ThisFileInfo, $baseoffset + $subatomoffset, $atomHierarchy, $ParseAllPossibleAtoms); - - $subatomoffset += $subatomsize; - $subatomcounter++; - } - return $atom_structure; - } - - - function quicktime_read_mp4_descr_length($data, &$offset) { - // http://libquicktime.sourcearchive.com/documentation/2:1.0.2plus-pdebian-2build1/esds_8c-source.html - $num_bytes = 0; - $length = 0; - do { - $b = ord(substr($data, $offset++, 1)); - $length = ($length << 7) | ($b & 0x7F); - } while (($b & 0x80) && ($num_bytes++ < 4)); - return $length; - } - - - function QuicktimeLanguageLookup($languageid) { - static $QuicktimeLanguageLookup = array(); - if (empty($QuicktimeLanguageLookup)) { - $QuicktimeLanguageLookup[0] = 'English'; - $QuicktimeLanguageLookup[1] = 'French'; - $QuicktimeLanguageLookup[2] = 'German'; - $QuicktimeLanguageLookup[3] = 'Italian'; - $QuicktimeLanguageLookup[4] = 'Dutch'; - $QuicktimeLanguageLookup[5] = 'Swedish'; - $QuicktimeLanguageLookup[6] = 'Spanish'; - $QuicktimeLanguageLookup[7] = 'Danish'; - $QuicktimeLanguageLookup[8] = 'Portuguese'; - $QuicktimeLanguageLookup[9] = 'Norwegian'; - $QuicktimeLanguageLookup[10] = 'Hebrew'; - $QuicktimeLanguageLookup[11] = 'Japanese'; - $QuicktimeLanguageLookup[12] = 'Arabic'; - $QuicktimeLanguageLookup[13] = 'Finnish'; - $QuicktimeLanguageLookup[14] = 'Greek'; - $QuicktimeLanguageLookup[15] = 'Icelandic'; - $QuicktimeLanguageLookup[16] = 'Maltese'; - $QuicktimeLanguageLookup[17] = 'Turkish'; - $QuicktimeLanguageLookup[18] = 'Croatian'; - $QuicktimeLanguageLookup[19] = 'Chinese (Traditional)'; - $QuicktimeLanguageLookup[20] = 'Urdu'; - $QuicktimeLanguageLookup[21] = 'Hindi'; - $QuicktimeLanguageLookup[22] = 'Thai'; - $QuicktimeLanguageLookup[23] = 'Korean'; - $QuicktimeLanguageLookup[24] = 'Lithuanian'; - $QuicktimeLanguageLookup[25] = 'Polish'; - $QuicktimeLanguageLookup[26] = 'Hungarian'; - $QuicktimeLanguageLookup[27] = 'Estonian'; - $QuicktimeLanguageLookup[28] = 'Lettish'; - $QuicktimeLanguageLookup[28] = 'Latvian'; - $QuicktimeLanguageLookup[29] = 'Saamisk'; - $QuicktimeLanguageLookup[29] = 'Lappish'; - $QuicktimeLanguageLookup[30] = 'Faeroese'; - $QuicktimeLanguageLookup[31] = 'Farsi'; - $QuicktimeLanguageLookup[31] = 'Persian'; - $QuicktimeLanguageLookup[32] = 'Russian'; - $QuicktimeLanguageLookup[33] = 'Chinese (Simplified)'; - $QuicktimeLanguageLookup[34] = 'Flemish'; - $QuicktimeLanguageLookup[35] = 'Irish'; - $QuicktimeLanguageLookup[36] = 'Albanian'; - $QuicktimeLanguageLookup[37] = 'Romanian'; - $QuicktimeLanguageLookup[38] = 'Czech'; - $QuicktimeLanguageLookup[39] = 'Slovak'; - $QuicktimeLanguageLookup[40] = 'Slovenian'; - $QuicktimeLanguageLookup[41] = 'Yiddish'; - $QuicktimeLanguageLookup[42] = 'Serbian'; - $QuicktimeLanguageLookup[43] = 'Macedonian'; - $QuicktimeLanguageLookup[44] = 'Bulgarian'; - $QuicktimeLanguageLookup[45] = 'Ukrainian'; - $QuicktimeLanguageLookup[46] = 'Byelorussian'; - $QuicktimeLanguageLookup[47] = 'Uzbek'; - $QuicktimeLanguageLookup[48] = 'Kazakh'; - $QuicktimeLanguageLookup[49] = 'Azerbaijani'; - $QuicktimeLanguageLookup[50] = 'AzerbaijanAr'; - $QuicktimeLanguageLookup[51] = 'Armenian'; - $QuicktimeLanguageLookup[52] = 'Georgian'; - $QuicktimeLanguageLookup[53] = 'Moldavian'; - $QuicktimeLanguageLookup[54] = 'Kirghiz'; - $QuicktimeLanguageLookup[55] = 'Tajiki'; - $QuicktimeLanguageLookup[56] = 'Turkmen'; - $QuicktimeLanguageLookup[57] = 'Mongolian'; - $QuicktimeLanguageLookup[58] = 'MongolianCyr'; - $QuicktimeLanguageLookup[59] = 'Pashto'; - $QuicktimeLanguageLookup[60] = 'Kurdish'; - $QuicktimeLanguageLookup[61] = 'Kashmiri'; - $QuicktimeLanguageLookup[62] = 'Sindhi'; - $QuicktimeLanguageLookup[63] = 'Tibetan'; - $QuicktimeLanguageLookup[64] = 'Nepali'; - $QuicktimeLanguageLookup[65] = 'Sanskrit'; - $QuicktimeLanguageLookup[66] = 'Marathi'; - $QuicktimeLanguageLookup[67] = 'Bengali'; - $QuicktimeLanguageLookup[68] = 'Assamese'; - $QuicktimeLanguageLookup[69] = 'Gujarati'; - $QuicktimeLanguageLookup[70] = 'Punjabi'; - $QuicktimeLanguageLookup[71] = 'Oriya'; - $QuicktimeLanguageLookup[72] = 'Malayalam'; - $QuicktimeLanguageLookup[73] = 'Kannada'; - $QuicktimeLanguageLookup[74] = 'Tamil'; - $QuicktimeLanguageLookup[75] = 'Telugu'; - $QuicktimeLanguageLookup[76] = 'Sinhalese'; - $QuicktimeLanguageLookup[77] = 'Burmese'; - $QuicktimeLanguageLookup[78] = 'Khmer'; - $QuicktimeLanguageLookup[79] = 'Lao'; - $QuicktimeLanguageLookup[80] = 'Vietnamese'; - $QuicktimeLanguageLookup[81] = 'Indonesian'; - $QuicktimeLanguageLookup[82] = 'Tagalog'; - $QuicktimeLanguageLookup[83] = 'MalayRoman'; - $QuicktimeLanguageLookup[84] = 'MalayArabic'; - $QuicktimeLanguageLookup[85] = 'Amharic'; - $QuicktimeLanguageLookup[86] = 'Tigrinya'; - $QuicktimeLanguageLookup[87] = 'Galla'; - $QuicktimeLanguageLookup[87] = 'Oromo'; - $QuicktimeLanguageLookup[88] = 'Somali'; - $QuicktimeLanguageLookup[89] = 'Swahili'; - $QuicktimeLanguageLookup[90] = 'Ruanda'; - $QuicktimeLanguageLookup[91] = 'Rundi'; - $QuicktimeLanguageLookup[92] = 'Chewa'; - $QuicktimeLanguageLookup[93] = 'Malagasy'; - $QuicktimeLanguageLookup[94] = 'Esperanto'; - $QuicktimeLanguageLookup[128] = 'Welsh'; - $QuicktimeLanguageLookup[129] = 'Basque'; - $QuicktimeLanguageLookup[130] = 'Catalan'; - $QuicktimeLanguageLookup[131] = 'Latin'; - $QuicktimeLanguageLookup[132] = 'Quechua'; - $QuicktimeLanguageLookup[133] = 'Guarani'; - $QuicktimeLanguageLookup[134] = 'Aymara'; - $QuicktimeLanguageLookup[135] = 'Tatar'; - $QuicktimeLanguageLookup[136] = 'Uighur'; - $QuicktimeLanguageLookup[137] = 'Dzongkha'; - $QuicktimeLanguageLookup[138] = 'JavaneseRom'; - } - return (isset($QuicktimeLanguageLookup[$languageid]) ? $QuicktimeLanguageLookup[$languageid] : 'invalid'); - } - - function QuicktimeVideoCodecLookup($codecid) { - static $QuicktimeVideoCodecLookup = array(); - if (empty($QuicktimeVideoCodecLookup)) { - $QuicktimeVideoCodecLookup['.SGI'] = 'SGI'; - $QuicktimeVideoCodecLookup['3IV1'] = '3ivx MPEG-4 v1'; - $QuicktimeVideoCodecLookup['3IV2'] = '3ivx MPEG-4 v2'; - $QuicktimeVideoCodecLookup['3IVX'] = '3ivx MPEG-4'; - $QuicktimeVideoCodecLookup['8BPS'] = 'Planar RGB'; - $QuicktimeVideoCodecLookup['avc1'] = 'H.264/MPEG-4 AVC'; - $QuicktimeVideoCodecLookup['avr '] = 'AVR-JPEG'; - $QuicktimeVideoCodecLookup['b16g'] = '16Gray'; - $QuicktimeVideoCodecLookup['b32a'] = '32AlphaGray'; - $QuicktimeVideoCodecLookup['b48r'] = '48RGB'; - $QuicktimeVideoCodecLookup['b64a'] = '64ARGB'; - $QuicktimeVideoCodecLookup['base'] = 'Base'; - $QuicktimeVideoCodecLookup['clou'] = 'Cloud'; - $QuicktimeVideoCodecLookup['cmyk'] = 'CMYK'; - $QuicktimeVideoCodecLookup['cvid'] = 'Cinepak'; - $QuicktimeVideoCodecLookup['dmb1'] = 'OpenDML JPEG'; - $QuicktimeVideoCodecLookup['dvc '] = 'DVC-NTSC'; - $QuicktimeVideoCodecLookup['dvcp'] = 'DVC-PAL'; - $QuicktimeVideoCodecLookup['dvpn'] = 'DVCPro-NTSC'; - $QuicktimeVideoCodecLookup['dvpp'] = 'DVCPro-PAL'; - $QuicktimeVideoCodecLookup['fire'] = 'Fire'; - $QuicktimeVideoCodecLookup['flic'] = 'FLC'; - $QuicktimeVideoCodecLookup['gif '] = 'GIF'; - $QuicktimeVideoCodecLookup['h261'] = 'H261'; - $QuicktimeVideoCodecLookup['h263'] = 'H263'; - $QuicktimeVideoCodecLookup['IV41'] = 'Indeo4'; - $QuicktimeVideoCodecLookup['jpeg'] = 'JPEG'; - $QuicktimeVideoCodecLookup['kpcd'] = 'PhotoCD'; - $QuicktimeVideoCodecLookup['mjpa'] = 'Motion JPEG-A'; - $QuicktimeVideoCodecLookup['mjpb'] = 'Motion JPEG-B'; - $QuicktimeVideoCodecLookup['msvc'] = 'Microsoft Video1'; - $QuicktimeVideoCodecLookup['myuv'] = 'MPEG YUV420'; - $QuicktimeVideoCodecLookup['path'] = 'Vector'; - $QuicktimeVideoCodecLookup['png '] = 'PNG'; - $QuicktimeVideoCodecLookup['PNTG'] = 'MacPaint'; - $QuicktimeVideoCodecLookup['qdgx'] = 'QuickDrawGX'; - $QuicktimeVideoCodecLookup['qdrw'] = 'QuickDraw'; - $QuicktimeVideoCodecLookup['raw '] = 'RAW'; - $QuicktimeVideoCodecLookup['ripl'] = 'WaterRipple'; - $QuicktimeVideoCodecLookup['rpza'] = 'Video'; - $QuicktimeVideoCodecLookup['smc '] = 'Graphics'; - $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 1'; - $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 3'; - $QuicktimeVideoCodecLookup['syv9'] = 'Sorenson YUV9'; - $QuicktimeVideoCodecLookup['tga '] = 'Targa'; - $QuicktimeVideoCodecLookup['tiff'] = 'TIFF'; - $QuicktimeVideoCodecLookup['WRAW'] = 'Windows RAW'; - $QuicktimeVideoCodecLookup['WRLE'] = 'BMP'; - $QuicktimeVideoCodecLookup['y420'] = 'YUV420'; - $QuicktimeVideoCodecLookup['yuv2'] = 'ComponentVideo'; - $QuicktimeVideoCodecLookup['yuvs'] = 'ComponentVideoUnsigned'; - $QuicktimeVideoCodecLookup['yuvu'] = 'ComponentVideoSigned'; - } - return (isset($QuicktimeVideoCodecLookup[$codecid]) ? $QuicktimeVideoCodecLookup[$codecid] : ''); - } - - function QuicktimeAudioCodecLookup($codecid) { - static $QuicktimeAudioCodecLookup = array(); - if (empty($QuicktimeAudioCodecLookup)) { - $QuicktimeAudioCodecLookup['.mp3'] = 'Fraunhofer MPEG Layer-III alias'; - $QuicktimeAudioCodecLookup['aac '] = 'ISO/IEC 14496-3 AAC'; - $QuicktimeAudioCodecLookup['agsm'] = 'Apple GSM 10:1'; - $QuicktimeAudioCodecLookup['alac'] = 'Apple Lossless Audio Codec'; - $QuicktimeAudioCodecLookup['alaw'] = 'A-law 2:1'; - $QuicktimeAudioCodecLookup['conv'] = 'Sample Format'; - $QuicktimeAudioCodecLookup['dvca'] = 'DV'; - $QuicktimeAudioCodecLookup['dvi '] = 'DV 4:1'; - $QuicktimeAudioCodecLookup['eqal'] = 'Frequency Equalizer'; - $QuicktimeAudioCodecLookup['fl32'] = '32-bit Floating Point'; - $QuicktimeAudioCodecLookup['fl64'] = '64-bit Floating Point'; - $QuicktimeAudioCodecLookup['ima4'] = 'Interactive Multimedia Association 4:1'; - $QuicktimeAudioCodecLookup['in24'] = '24-bit Integer'; - $QuicktimeAudioCodecLookup['in32'] = '32-bit Integer'; - $QuicktimeAudioCodecLookup['lpc '] = 'LPC 23:1'; - $QuicktimeAudioCodecLookup['MAC3'] = 'Macintosh Audio Compression/Expansion (MACE) 3:1'; - $QuicktimeAudioCodecLookup['MAC6'] = 'Macintosh Audio Compression/Expansion (MACE) 6:1'; - $QuicktimeAudioCodecLookup['mixb'] = '8-bit Mixer'; - $QuicktimeAudioCodecLookup['mixw'] = '16-bit Mixer'; - $QuicktimeAudioCodecLookup['mp4a'] = 'ISO/IEC 14496-3 AAC'; - $QuicktimeAudioCodecLookup['MS'."\x00\x02"] = 'Microsoft ADPCM'; - $QuicktimeAudioCodecLookup['MS'."\x00\x11"] = 'DV IMA'; - $QuicktimeAudioCodecLookup['MS'."\x00\x55"] = 'Fraunhofer MPEG Layer III'; - $QuicktimeAudioCodecLookup['NONE'] = 'No Encoding'; - $QuicktimeAudioCodecLookup['Qclp'] = 'Qualcomm PureVoice'; - $QuicktimeAudioCodecLookup['QDM2'] = 'QDesign Music 2'; - $QuicktimeAudioCodecLookup['QDMC'] = 'QDesign Music 1'; - $QuicktimeAudioCodecLookup['ratb'] = '8-bit Rate'; - $QuicktimeAudioCodecLookup['ratw'] = '16-bit Rate'; - $QuicktimeAudioCodecLookup['raw '] = 'raw PCM'; - $QuicktimeAudioCodecLookup['sour'] = 'Sound Source'; - $QuicktimeAudioCodecLookup['sowt'] = 'signed/two\'s complement (Little Endian)'; - $QuicktimeAudioCodecLookup['str1'] = 'Iomega MPEG layer II'; - $QuicktimeAudioCodecLookup['str2'] = 'Iomega MPEG *layer II'; - $QuicktimeAudioCodecLookup['str3'] = 'Iomega MPEG **layer II'; - $QuicktimeAudioCodecLookup['str4'] = 'Iomega MPEG ***layer II'; - $QuicktimeAudioCodecLookup['twos'] = 'signed/two\'s complement (Big Endian)'; - $QuicktimeAudioCodecLookup['ulaw'] = 'mu-law 2:1'; - } - return (isset($QuicktimeAudioCodecLookup[$codecid]) ? $QuicktimeAudioCodecLookup[$codecid] : ''); - } - - function QuicktimeDCOMLookup($compressionid) { - static $QuicktimeDCOMLookup = array(); - if (empty($QuicktimeDCOMLookup)) { - $QuicktimeDCOMLookup['zlib'] = 'ZLib Deflate'; - $QuicktimeDCOMLookup['adec'] = 'Apple Compression'; - } - return (isset($QuicktimeDCOMLookup[$compressionid]) ? $QuicktimeDCOMLookup[$compressionid] : ''); - } - - function QuicktimeColorNameLookup($colordepthid) { - static $QuicktimeColorNameLookup = array(); - if (empty($QuicktimeColorNameLookup)) { - $QuicktimeColorNameLookup[1] = '2-color (monochrome)'; - $QuicktimeColorNameLookup[2] = '4-color'; - $QuicktimeColorNameLookup[4] = '16-color'; - $QuicktimeColorNameLookup[8] = '256-color'; - $QuicktimeColorNameLookup[16] = 'thousands (16-bit color)'; - $QuicktimeColorNameLookup[24] = 'millions (24-bit color)'; - $QuicktimeColorNameLookup[32] = 'millions+ (32-bit color)'; - $QuicktimeColorNameLookup[33] = 'black & white'; - $QuicktimeColorNameLookup[34] = '4-gray'; - $QuicktimeColorNameLookup[36] = '16-gray'; - $QuicktimeColorNameLookup[40] = '256-gray'; - } - return (isset($QuicktimeColorNameLookup[$colordepthid]) ? $QuicktimeColorNameLookup[$colordepthid] : 'invalid'); - } - - function QuicktimeSTIKLookup($stik) { - static $QuicktimeSTIKLookup = array(); - if (empty($QuicktimeSTIKLookup)) { - $QuicktimeSTIKLookup[0] = 'Movie'; - $QuicktimeSTIKLookup[1] = 'Normal'; - $QuicktimeSTIKLookup[2] = 'Audiobook'; - $QuicktimeSTIKLookup[5] = 'Whacked Bookmark'; - $QuicktimeSTIKLookup[6] = 'Music Video'; - $QuicktimeSTIKLookup[9] = 'Short Film'; - $QuicktimeSTIKLookup[10] = 'TV Show'; - $QuicktimeSTIKLookup[11] = 'Booklet'; - $QuicktimeSTIKLookup[14] = 'Ringtone'; - $QuicktimeSTIKLookup[21] = 'Podcast'; - } - return (isset($QuicktimeSTIKLookup[$stik]) ? $QuicktimeSTIKLookup[$stik] : 'invalid'); - } - - function QuicktimeIODSaudioProfileName($audio_profile_id) { - static $QuicktimeIODSaudioProfileNameLookup = array(); - if (empty($QuicktimeIODSaudioProfileNameLookup)) { - $QuicktimeIODSaudioProfileNameLookup = array( - 0x00 => 'ISO Reserved (0x00)', - 0x01 => 'Main Audio Profile @ Level 1', - 0x02 => 'Main Audio Profile @ Level 2', - 0x03 => 'Main Audio Profile @ Level 3', - 0x04 => 'Main Audio Profile @ Level 4', - 0x05 => 'Scalable Audio Profile @ Level 1', - 0x06 => 'Scalable Audio Profile @ Level 2', - 0x07 => 'Scalable Audio Profile @ Level 3', - 0x08 => 'Scalable Audio Profile @ Level 4', - 0x09 => 'Speech Audio Profile @ Level 1', - 0x0A => 'Speech Audio Profile @ Level 2', - 0x0B => 'Synthetic Audio Profile @ Level 1', - 0x0C => 'Synthetic Audio Profile @ Level 2', - 0x0D => 'Synthetic Audio Profile @ Level 3', - 0x0E => 'High Quality Audio Profile @ Level 1', - 0x0F => 'High Quality Audio Profile @ Level 2', - 0x10 => 'High Quality Audio Profile @ Level 3', - 0x11 => 'High Quality Audio Profile @ Level 4', - 0x12 => 'High Quality Audio Profile @ Level 5', - 0x13 => 'High Quality Audio Profile @ Level 6', - 0x14 => 'High Quality Audio Profile @ Level 7', - 0x15 => 'High Quality Audio Profile @ Level 8', - 0x16 => 'Low Delay Audio Profile @ Level 1', - 0x17 => 'Low Delay Audio Profile @ Level 2', - 0x18 => 'Low Delay Audio Profile @ Level 3', - 0x19 => 'Low Delay Audio Profile @ Level 4', - 0x1A => 'Low Delay Audio Profile @ Level 5', - 0x1B => 'Low Delay Audio Profile @ Level 6', - 0x1C => 'Low Delay Audio Profile @ Level 7', - 0x1D => 'Low Delay Audio Profile @ Level 8', - 0x1E => 'Natural Audio Profile @ Level 1', - 0x1F => 'Natural Audio Profile @ Level 2', - 0x20 => 'Natural Audio Profile @ Level 3', - 0x21 => 'Natural Audio Profile @ Level 4', - 0x22 => 'Mobile Audio Internetworking Profile @ Level 1', - 0x23 => 'Mobile Audio Internetworking Profile @ Level 2', - 0x24 => 'Mobile Audio Internetworking Profile @ Level 3', - 0x25 => 'Mobile Audio Internetworking Profile @ Level 4', - 0x26 => 'Mobile Audio Internetworking Profile @ Level 5', - 0x27 => 'Mobile Audio Internetworking Profile @ Level 6', - 0x28 => 'AAC Profile @ Level 1', - 0x29 => 'AAC Profile @ Level 2', - 0x2A => 'AAC Profile @ Level 4', - 0x2B => 'AAC Profile @ Level 5', - 0x2C => 'High Efficiency AAC Profile @ Level 2', - 0x2D => 'High Efficiency AAC Profile @ Level 3', - 0x2E => 'High Efficiency AAC Profile @ Level 4', - 0x2F => 'High Efficiency AAC Profile @ Level 5', - 0xFE => 'Not part of MPEG-4 audio profiles', - 0xFF => 'No audio capability required', - ); - } - return (isset($QuicktimeIODSaudioProfileNameLookup[$audio_profile_id]) ? $QuicktimeIODSaudioProfileNameLookup[$audio_profile_id] : 'ISO Reserved / User Private'); - } - - - function QuicktimeIODSvideoProfileName($video_profile_id) { - static $QuicktimeIODSvideoProfileNameLookup = array(); - if (empty($QuicktimeIODSvideoProfileNameLookup)) { - $QuicktimeIODSvideoProfileNameLookup = array( - 0x00 => 'Reserved (0x00) Profile', - 0x01 => 'Simple Profile @ Level 1', - 0x02 => 'Simple Profile @ Level 2', - 0x03 => 'Simple Profile @ Level 3', - 0x08 => 'Simple Profile @ Level 0', - 0x10 => 'Simple Scalable Profile @ Level 0', - 0x11 => 'Simple Scalable Profile @ Level 1', - 0x12 => 'Simple Scalable Profile @ Level 2', - 0x15 => 'AVC/H264 Profile', - 0x21 => 'Core Profile @ Level 1', - 0x22 => 'Core Profile @ Level 2', - 0x32 => 'Main Profile @ Level 2', - 0x33 => 'Main Profile @ Level 3', - 0x34 => 'Main Profile @ Level 4', - 0x42 => 'N-bit Profile @ Level 2', - 0x51 => 'Scalable Texture Profile @ Level 1', - 0x61 => 'Simple Face Animation Profile @ Level 1', - 0x62 => 'Simple Face Animation Profile @ Level 2', - 0x63 => 'Simple FBA Profile @ Level 1', - 0x64 => 'Simple FBA Profile @ Level 2', - 0x71 => 'Basic Animated Texture Profile @ Level 1', - 0x72 => 'Basic Animated Texture Profile @ Level 2', - 0x81 => 'Hybrid Profile @ Level 1', - 0x82 => 'Hybrid Profile @ Level 2', - 0x91 => 'Advanced Real Time Simple Profile @ Level 1', - 0x92 => 'Advanced Real Time Simple Profile @ Level 2', - 0x93 => 'Advanced Real Time Simple Profile @ Level 3', - 0x94 => 'Advanced Real Time Simple Profile @ Level 4', - 0xA1 => 'Core Scalable Profile @ Level1', - 0xA2 => 'Core Scalable Profile @ Level2', - 0xA3 => 'Core Scalable Profile @ Level3', - 0xB1 => 'Advanced Coding Efficiency Profile @ Level 1', - 0xB2 => 'Advanced Coding Efficiency Profile @ Level 2', - 0xB3 => 'Advanced Coding Efficiency Profile @ Level 3', - 0xB4 => 'Advanced Coding Efficiency Profile @ Level 4', - 0xC1 => 'Advanced Core Profile @ Level 1', - 0xC2 => 'Advanced Core Profile @ Level 2', - 0xD1 => 'Advanced Scalable Texture @ Level1', - 0xD2 => 'Advanced Scalable Texture @ Level2', - 0xE1 => 'Simple Studio Profile @ Level 1', - 0xE2 => 'Simple Studio Profile @ Level 2', - 0xE3 => 'Simple Studio Profile @ Level 3', - 0xE4 => 'Simple Studio Profile @ Level 4', - 0xE5 => 'Core Studio Profile @ Level 1', - 0xE6 => 'Core Studio Profile @ Level 2', - 0xE7 => 'Core Studio Profile @ Level 3', - 0xE8 => 'Core Studio Profile @ Level 4', - 0xF0 => 'Advanced Simple Profile @ Level 0', - 0xF1 => 'Advanced Simple Profile @ Level 1', - 0xF2 => 'Advanced Simple Profile @ Level 2', - 0xF3 => 'Advanced Simple Profile @ Level 3', - 0xF4 => 'Advanced Simple Profile @ Level 4', - 0xF5 => 'Advanced Simple Profile @ Level 5', - 0xF7 => 'Advanced Simple Profile @ Level 3b', - 0xF8 => 'Fine Granularity Scalable Profile @ Level 0', - 0xF9 => 'Fine Granularity Scalable Profile @ Level 1', - 0xFA => 'Fine Granularity Scalable Profile @ Level 2', - 0xFB => 'Fine Granularity Scalable Profile @ Level 3', - 0xFC => 'Fine Granularity Scalable Profile @ Level 4', - 0xFD => 'Fine Granularity Scalable Profile @ Level 5', - 0xFE => 'Not part of MPEG-4 Visual profiles', - 0xFF => 'No visual capability required', - ); - } - return (isset($QuicktimeIODSvideoProfileNameLookup[$video_profile_id]) ? $QuicktimeIODSvideoProfileNameLookup[$video_profile_id] : 'ISO Reserved Profile'); - } - - - function QuicktimeContentRatingLookup($rtng) { - static $QuicktimeContentRatingLookup = array(); - if (empty($QuicktimeContentRatingLookup)) { - $QuicktimeContentRatingLookup[0] = 'None'; - $QuicktimeContentRatingLookup[2] = 'Clean'; - $QuicktimeContentRatingLookup[4] = 'Explicit'; - } - return (isset($QuicktimeContentRatingLookup[$rtng]) ? $QuicktimeContentRatingLookup[$rtng] : 'invalid'); - } - - function QuicktimeStoreAccountTypeLookup($akid) { - static $QuicktimeStoreAccountTypeLookup = array(); - if (empty($QuicktimeStoreAccountTypeLookup)) { - $QuicktimeStoreAccountTypeLookup[0] = 'iTunes'; - $QuicktimeStoreAccountTypeLookup[1] = 'AOL'; - } - return (isset($QuicktimeStoreAccountTypeLookup[$akid]) ? $QuicktimeStoreAccountTypeLookup[$akid] : 'invalid'); - } - - function QuicktimeStoreFrontCodeLookup($sfid) { - static $QuicktimeStoreFrontCodeLookup = array(); - if (empty($QuicktimeStoreFrontCodeLookup)) { - $QuicktimeStoreFrontCodeLookup[143460] = 'Australia'; - $QuicktimeStoreFrontCodeLookup[143445] = 'Austria'; - $QuicktimeStoreFrontCodeLookup[143446] = 'Belgium'; - $QuicktimeStoreFrontCodeLookup[143455] = 'Canada'; - $QuicktimeStoreFrontCodeLookup[143458] = 'Denmark'; - $QuicktimeStoreFrontCodeLookup[143447] = 'Finland'; - $QuicktimeStoreFrontCodeLookup[143442] = 'France'; - $QuicktimeStoreFrontCodeLookup[143443] = 'Germany'; - $QuicktimeStoreFrontCodeLookup[143448] = 'Greece'; - $QuicktimeStoreFrontCodeLookup[143449] = 'Ireland'; - $QuicktimeStoreFrontCodeLookup[143450] = 'Italy'; - $QuicktimeStoreFrontCodeLookup[143462] = 'Japan'; - $QuicktimeStoreFrontCodeLookup[143451] = 'Luxembourg'; - $QuicktimeStoreFrontCodeLookup[143452] = 'Netherlands'; - $QuicktimeStoreFrontCodeLookup[143461] = 'New Zealand'; - $QuicktimeStoreFrontCodeLookup[143457] = 'Norway'; - $QuicktimeStoreFrontCodeLookup[143453] = 'Portugal'; - $QuicktimeStoreFrontCodeLookup[143454] = 'Spain'; - $QuicktimeStoreFrontCodeLookup[143456] = 'Sweden'; - $QuicktimeStoreFrontCodeLookup[143459] = 'Switzerland'; - $QuicktimeStoreFrontCodeLookup[143444] = 'United Kingdom'; - $QuicktimeStoreFrontCodeLookup[143441] = 'United States'; - } - return (isset($QuicktimeStoreCountryCodeLookup[$sfid]) ? $QuicktimeStoreCountryCodeLookup[$sfid] : 'invalid'); - } - - function CopyToAppropriateCommentsSection($keyname, $data, &$ThisFileInfo, $boxname='') { - static $handyatomtranslatorarray = array(); - if (empty($handyatomtranslatorarray)) { - $handyatomtranslatorarray['©cpy'] = 'copyright'; - $handyatomtranslatorarray['©day'] = 'creation_date'; // iTunes 4.0 - $handyatomtranslatorarray['©dir'] = 'director'; - $handyatomtranslatorarray['©ed1'] = 'edit1'; - $handyatomtranslatorarray['©ed2'] = 'edit2'; - $handyatomtranslatorarray['©ed3'] = 'edit3'; - $handyatomtranslatorarray['©ed4'] = 'edit4'; - $handyatomtranslatorarray['©ed5'] = 'edit5'; - $handyatomtranslatorarray['©ed6'] = 'edit6'; - $handyatomtranslatorarray['©ed7'] = 'edit7'; - $handyatomtranslatorarray['©ed8'] = 'edit8'; - $handyatomtranslatorarray['©ed9'] = 'edit9'; - $handyatomtranslatorarray['©fmt'] = 'format'; - $handyatomtranslatorarray['©inf'] = 'information'; - $handyatomtranslatorarray['©prd'] = 'producer'; - $handyatomtranslatorarray['©prf'] = 'performers'; - $handyatomtranslatorarray['©req'] = 'system_requirements'; - $handyatomtranslatorarray['©src'] = 'source_credit'; - $handyatomtranslatorarray['©wrt'] = 'writer'; - - // http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt - $handyatomtranslatorarray['©nam'] = 'title'; // iTunes 4.0 - $handyatomtranslatorarray['©cmt'] = 'comment'; // iTunes 4.0 - $handyatomtranslatorarray['©wrn'] = 'warning'; - $handyatomtranslatorarray['©hst'] = 'host_computer'; - $handyatomtranslatorarray['©mak'] = 'make'; - $handyatomtranslatorarray['©mod'] = 'model'; - $handyatomtranslatorarray['©PRD'] = 'product'; - $handyatomtranslatorarray['©swr'] = 'software'; - $handyatomtranslatorarray['©aut'] = 'author'; - $handyatomtranslatorarray['©ART'] = 'artist'; - $handyatomtranslatorarray['©trk'] = 'track'; - $handyatomtranslatorarray['©alb'] = 'album'; // iTunes 4.0 - $handyatomtranslatorarray['©com'] = 'comment'; - $handyatomtranslatorarray['©gen'] = 'genre'; // iTunes 4.0 - $handyatomtranslatorarray['©ope'] = 'composer'; - $handyatomtranslatorarray['©url'] = 'url'; - $handyatomtranslatorarray['©enc'] = 'encoder'; - - // http://atomicparsley.sourceforge.net/mpeg-4files.html - $handyatomtranslatorarray['©art'] = 'artist'; // iTunes 4.0 - $handyatomtranslatorarray['aART'] = 'album_artist'; - $handyatomtranslatorarray['trkn'] = 'track_number'; // iTunes 4.0 - $handyatomtranslatorarray['disk'] = 'disc_number'; // iTunes 4.0 - $handyatomtranslatorarray['gnre'] = 'genre'; // iTunes 4.0 - $handyatomtranslatorarray['©too'] = 'encoder'; // iTunes 4.0 - $handyatomtranslatorarray['tmpo'] = 'bpm'; // iTunes 4.0 - $handyatomtranslatorarray['cprt'] = 'copyright'; // iTunes 4.0? - $handyatomtranslatorarray['cpil'] = 'compilation'; // iTunes 4.0 - $handyatomtranslatorarray['covr'] = 'artwork'; // iTunes 4.0 - $handyatomtranslatorarray['rtng'] = 'rating'; // iTunes 4.0 - $handyatomtranslatorarray['©grp'] = 'grouping'; // iTunes 4.2 - $handyatomtranslatorarray['stik'] = 'stik'; // iTunes 4.9 - $handyatomtranslatorarray['pcst'] = 'podcast'; // iTunes 4.9 - $handyatomtranslatorarray['catg'] = 'category'; // iTunes 4.9 - $handyatomtranslatorarray['keyw'] = 'keyword'; // iTunes 4.9 - $handyatomtranslatorarray['purl'] = 'podcast_url'; // iTunes 4.9 - $handyatomtranslatorarray['egid'] = 'episode_guid'; // iTunes 4.9 - $handyatomtranslatorarray['desc'] = 'description'; // iTunes 5.0 - $handyatomtranslatorarray['©lyr'] = 'lyrics'; // iTunes 5.0 - $handyatomtranslatorarray['tvnn'] = 'tv_network_name'; // iTunes 6.0 - $handyatomtranslatorarray['tvsh'] = 'tv_show_name'; // iTunes 6.0 - $handyatomtranslatorarray['tvsn'] = 'tv_season'; // iTunes 6.0 - $handyatomtranslatorarray['tves'] = 'tv_episode'; // iTunes 6.0 - $handyatomtranslatorarray['purd'] = 'purchase_date'; // iTunes 6.0.2 - $handyatomtranslatorarray['pgap'] = 'gapless_playback'; // iTunes 7.0 - - // http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt - - - - // boxnames: - $handyatomtranslatorarray['iTunSMPB'] = 'iTunSMPB'; - $handyatomtranslatorarray['iTunNORM'] = 'iTunNORM'; - $handyatomtranslatorarray['Encoding Params'] = 'Encoding Params'; - $handyatomtranslatorarray['replaygain_track_gain'] = 'replaygain_track_gain'; - $handyatomtranslatorarray['replaygain_track_peak'] = 'replaygain_track_peak'; - $handyatomtranslatorarray['replaygain_track_minmax'] = 'replaygain_track_minmax'; - $handyatomtranslatorarray['MusicIP PUID'] = 'MusicIP PUID'; - $handyatomtranslatorarray['MusicBrainz Artist Id'] = 'MusicBrainz Artist Id'; - $handyatomtranslatorarray['MusicBrainz Album Id'] = 'MusicBrainz Album Id'; - $handyatomtranslatorarray['MusicBrainz Album Artist Id'] = 'MusicBrainz Album Artist Id'; - $handyatomtranslatorarray['MusicBrainz Track Id'] = 'MusicBrainz Track Id'; - $handyatomtranslatorarray['MusicBrainz Disc Id'] = 'MusicBrainz Disc Id'; - } - if ($boxname && ($boxname != $keyname) && isset($handyatomtranslatorarray[$boxname])) { - $ThisFileInfo['quicktime']['comments'][$handyatomtranslatorarray[$boxname]][] = $data; - } elseif (isset($handyatomtranslatorarray[$keyname])) { - $ThisFileInfo['quicktime']['comments'][$handyatomtranslatorarray[$keyname]][] = $data; - } - - return true; - } - - function NoNullString($nullterminatedstring) { - // remove the single null terminator on null terminated strings - if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === "\x00") { - return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1); - } - return $nullterminatedstring; - } - - function Pascal2String($pascalstring) { - // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string - return substr($pascalstring, 1); - } - -} - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio-video.riff.php b/serendipity_event_podcast/player/getid3/module.audio-video.riff.php deleted file mode 100644 index 64b160e1..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio-video.riff.php +++ /dev/null @@ -1,2315 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio-video.riff.php // -// module for analyzing RIFF files // -// multiple formats supported by this module: // -// Wave, AVI, AIFF/AIFC, (MP3,AC3)/RIFF, Wavpack v3, 8SVX // -// dependencies: module.audio.mp3.php // -// module.audio.ac3.php (optional) // -// module.audio.dts.php (optional) // -// /// -///////////////////////////////////////////////////////////////// - -getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); - -class getid3_riff -{ - - function getid3_riff(&$fd, &$ThisFileInfo) { - - // initialize these values to an empty array, otherwise they default to NULL - // and you can't append array values to a NULL value - $ThisFileInfo['riff'] = array('raw'=>array()); - - // Shortcuts - $thisfile_riff = &$ThisFileInfo['riff']; - $thisfile_riff_raw = &$thisfile_riff['raw']; - $thisfile_audio = &$ThisFileInfo['audio']; - $thisfile_video = &$ThisFileInfo['video']; - $thisfile_audio_dataformat = &$thisfile_audio['dataformat']; - $thisfile_riff_audio = &$thisfile_riff['audio']; - $thisfile_riff_video = &$thisfile_riff['video']; - - - $Original['avdataoffset'] = $ThisFileInfo['avdataoffset']; - $Original['avdataend'] = $ThisFileInfo['avdataend']; - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $RIFFheader = fread($fd, 12); - $RIFFsubtype = substr($RIFFheader, 8, 4); - switch (substr($RIFFheader, 0, 4)) { - case 'FORM': - $ThisFileInfo['fileformat'] = 'aiff'; - $thisfile_riff['header_size'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($RIFFheader, 4, 4)); - $thisfile_riff[$RIFFsubtype] = getid3_riff::ParseRIFF($fd, $ThisFileInfo['avdataoffset'] + 12, $ThisFileInfo['avdataoffset'] + $thisfile_riff['header_size'], $ThisFileInfo); - break; - - case 'RIFF': // AVI, WAV, etc - case 'SDSS': // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com) - case 'RMP3': // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s - $ThisFileInfo['fileformat'] = 'riff'; - $thisfile_riff['header_size'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($RIFFheader, 4, 4)); - if ($RIFFsubtype == 'RMP3') { - // RMP3 is identical to WAVE, just renamed. Used by [unknown program] when creating RIFF-MP3s - $RIFFsubtype = 'WAVE'; - } - $thisfile_riff[$RIFFsubtype] = getid3_riff::ParseRIFF($fd, $ThisFileInfo['avdataoffset'] + 12, $ThisFileInfo['avdataoffset'] + $thisfile_riff['header_size'], $ThisFileInfo); - - $nextRIFFoffset = $Original['avdataoffset'] + 8 + $thisfile_riff['header_size']; // 8 = "RIFF" + 32-bit offset - while ($nextRIFFoffset < $ThisFileInfo['filesize']) { - if (!getid3_lib::intValueSupported($nextRIFFoffset + 1024)) { - $ThisFileInfo['error'][] = 'AVI extends beyond '.round(PHP_INT_MAX / 1073741824).'GB and PHP filesystem functions cannot read that far, playtime is probably wrong'; - $ThisFileInfo['warning'][] = '[avdataend] value may be incorrect, multiple AVIX chunks may be present'; - break; - } else { - fseek($fd, $nextRIFFoffset, SEEK_SET); - $nextRIFFheader = fread($fd, 12); - $nextRIFFheaderID = substr($nextRIFFheader, 0, 4); - $nextRIFFsize = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($nextRIFFheader, 4, 4)); - $nextRIFFtype = substr($nextRIFFheader, 8, 4); - $chunkdata = array(); - $chunkdata['offset'] = $nextRIFFoffset + 8; - $chunkdata['size'] = $nextRIFFsize; - $nextRIFFoffset = $chunkdata['offset'] + $chunkdata['size']; - switch ($nextRIFFheaderID) { - case 'RIFF': - $ThisFileInfo['avdataend'] = $nextRIFFoffset; - if (!getid3_lib::intValueSupported($ThisFileInfo['avdataend'])) { - $ThisFileInfo['error'][] = 'AVI extends beyond '.round(PHP_INT_MAX / 1073741824).'GB and PHP filesystem functions cannot read that far, playtime is probably wrong'; - $ThisFileInfo['warning'][] = '[avdataend] value may be incorrect, multiple AVIX chunks may be present'; - } - $chunkdata['chunks'] = getid3_riff::ParseRIFF($fd, $chunkdata['offset'] + 4, $chunkdata['offset'] + $chunkdata['size'], $ThisFileInfo); - - if (!isset($thisfile_riff[$nextRIFFtype])) { - $thisfile_riff[$nextRIFFtype] = array(); - } - $thisfile_riff[$nextRIFFtype][] = $chunkdata; - break; - case 'JUNK': - // ignore - $thisfile_riff[$nextRIFFheaderID][] = $chunkdata; - break; - default: - if ($ThisFileInfo['filesize'] == ($chunkdata['offset'] - 8 + 128)) { - $DIVXTAG = $nextRIFFheader.fread($fd, 128 - 12); - if (substr($DIVXTAG, -7) == 'DIVXTAG') { - // DIVXTAG is supposed to be inside an IDVX chunk in a LIST chunk, but some bad encoders just slap it on the end of a file - $thisfile_riff['DIVXTAG'] = $this->ParseDIVXTAG($DIVXTAG); - foreach ($thisfile_riff['DIVXTAG'] as $key => $value) { - if ($value && !preg_match('#_id$#', $key)) { - $thisfile_riff['comments'][$key][] = $value; - } - } - break 2; - } - } - $ThisFileInfo['warning'][] = 'expecting "RIFF" or "JUNK" at '.$nextRIFFoffset.', found '.substr($nextRIFFheader, 0, 4).' - skipping rest of file'; - break 2; - } - } - } - if ($RIFFsubtype == 'WAVE') { - $thisfile_riff_WAVE = &$thisfile_riff['WAVE']; - } - break; - - default: - $ThisFileInfo['error'][] = 'Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$RIFFsubtype.'" instead'; - unset($ThisFileInfo['fileformat']); - return false; - break; - } - - $streamindex = 0; - switch ($RIFFsubtype) { - case 'WAVE': - if (empty($thisfile_audio['bitrate_mode'])) { - $thisfile_audio['bitrate_mode'] = 'cbr'; - } - if (empty($thisfile_audio_dataformat)) { - $thisfile_audio_dataformat = 'wav'; - } - - if (isset($thisfile_riff_WAVE['data'][0]['offset'])) { - $ThisFileInfo['avdataoffset'] = $thisfile_riff_WAVE['data'][0]['offset'] + 8; - $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $thisfile_riff_WAVE['data'][0]['size']; - } - if (isset($thisfile_riff_WAVE['fmt '][0]['data'])) { - - $thisfile_riff_audio[$streamindex] = getid3_riff::RIFFparseWAVEFORMATex($thisfile_riff_WAVE['fmt '][0]['data']); - $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag']; - if (!isset($thisfile_riff_audio[$streamindex]['bitrate']) || ($thisfile_riff_audio[$streamindex]['bitrate'] == 0)) { - $ThisFileInfo['error'][] = 'Corrupt RIFF file: bitrate_audio == zero'; - return false; - } - $thisfile_riff_raw['fmt '] = $thisfile_riff_audio[$streamindex]['raw']; - unset($thisfile_riff_audio[$streamindex]['raw']); - $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex]; - - $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]); - if (substr($thisfile_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') { - $ThisFileInfo['warning'][] = 'Audio codec = '.$thisfile_audio['codec']; - } - $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate']; - - $ThisFileInfo['playtime_seconds'] = (float) ((($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $thisfile_audio['bitrate']); - - $thisfile_audio['lossless'] = false; - if (isset($thisfile_riff_WAVE['data'][0]['offset']) && isset($thisfile_riff_raw['fmt ']['wFormatTag'])) { - switch ($thisfile_riff_raw['fmt ']['wFormatTag']) { - - case 0x0001: // PCM - $thisfile_audio['lossless'] = true; - break; - - case 0x2000: // AC-3 - $thisfile_audio_dataformat = 'ac3'; - break; - - default: - // do nothing - break; - - } - } - $thisfile_audio['streams'][$streamindex]['wformattag'] = $thisfile_audio['wformattag']; - $thisfile_audio['streams'][$streamindex]['bitrate_mode'] = $thisfile_audio['bitrate_mode']; - $thisfile_audio['streams'][$streamindex]['lossless'] = $thisfile_audio['lossless']; - $thisfile_audio['streams'][$streamindex]['dataformat'] = $thisfile_audio_dataformat; - } - - if (isset($thisfile_riff_WAVE['rgad'][0]['data'])) { - - // shortcuts - $rgadData = &$thisfile_riff_WAVE['rgad'][0]['data']; - $thisfile_riff_raw['rgad'] = array('track'=>array(), 'album'=>array()); - $thisfile_riff_raw_rgad = &$thisfile_riff_raw['rgad']; - $thisfile_riff_raw_rgad_track = &$thisfile_riff_raw_rgad['track']; - $thisfile_riff_raw_rgad_album = &$thisfile_riff_raw_rgad['album']; - - $thisfile_riff_raw_rgad['fPeakAmplitude'] = getid3_lib::LittleEndian2Float(substr($rgadData, 0, 4)); - $thisfile_riff_raw_rgad['nRadioRgAdjust'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($rgadData, 4, 2)); - $thisfile_riff_raw_rgad['nAudiophileRgAdjust'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($rgadData, 6, 2)); - - $nRadioRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT); - $nAudiophileRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT); - $thisfile_riff_raw_rgad_track['name'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3)); - $thisfile_riff_raw_rgad_track['originator'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3)); - $thisfile_riff_raw_rgad_track['signbit'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1)); - $thisfile_riff_raw_rgad_track['adjustment'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9)); - $thisfile_riff_raw_rgad_album['name'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3)); - $thisfile_riff_raw_rgad_album['originator'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3)); - $thisfile_riff_raw_rgad_album['signbit'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1)); - $thisfile_riff_raw_rgad_album['adjustment'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9)); - - $thisfile_riff['rgad']['peakamplitude'] = $thisfile_riff_raw_rgad['fPeakAmplitude']; - if (($thisfile_riff_raw_rgad_track['name'] != 0) && ($thisfile_riff_raw_rgad_track['originator'] != 0)) { - $thisfile_riff['rgad']['track']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_track['name']); - $thisfile_riff['rgad']['track']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_track['originator']); - $thisfile_riff['rgad']['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_track['adjustment'], $thisfile_riff_raw_rgad_track['signbit']); - } - if (($thisfile_riff_raw_rgad_album['name'] != 0) && ($thisfile_riff_raw_rgad_album['originator'] != 0)) { - $thisfile_riff['rgad']['album']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_album['name']); - $thisfile_riff['rgad']['album']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_album['originator']); - $thisfile_riff['rgad']['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_album['adjustment'], $thisfile_riff_raw_rgad_album['signbit']); - } - } - - if (isset($thisfile_riff_WAVE['fact'][0]['data'])) { - $thisfile_riff_raw['fact']['NumberOfSamples'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_WAVE['fact'][0]['data'], 0, 4)); - - // This should be a good way of calculating exact playtime, - // but some sample files have had incorrect number of samples, - // so cannot use this method - - // if (!empty($thisfile_riff_raw['fmt ']['nSamplesPerSec'])) { - // $ThisFileInfo['playtime_seconds'] = (float) $thisfile_riff_raw['fact']['NumberOfSamples'] / $thisfile_riff_raw['fmt ']['nSamplesPerSec']; - // } - } - if (!empty($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'])) { - $thisfile_audio['bitrate'] = getid3_lib::CastAsInt($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'] * 8); - } - - if (isset($thisfile_riff_WAVE['bext'][0]['data'])) { - // shortcut - $thisfile_riff_WAVE_bext_0 = &$thisfile_riff_WAVE['bext'][0]; - - $thisfile_riff_WAVE_bext_0['title'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 0, 256)); - $thisfile_riff_WAVE_bext_0['author'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 256, 32)); - $thisfile_riff_WAVE_bext_0['reference'] = trim(substr($thisfile_riff_WAVE_bext_0['data'], 288, 32)); - $thisfile_riff_WAVE_bext_0['origin_date'] = substr($thisfile_riff_WAVE_bext_0['data'], 320, 10); - $thisfile_riff_WAVE_bext_0['origin_time'] = substr($thisfile_riff_WAVE_bext_0['data'], 330, 8); - $thisfile_riff_WAVE_bext_0['time_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 338, 8)); - $thisfile_riff_WAVE_bext_0['bwf_version'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 346, 1)); - $thisfile_riff_WAVE_bext_0['reserved'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 347, 254)); - $thisfile_riff_WAVE_bext_0['coding_history'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_bext_0['data'], 601))); - if (preg_match('#^([0-9]{4}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_date'], $matches_bext_date)) { - if (preg_match('#^([0-9]{2}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_time'], $matches_bext_time)) { - list($dummy, $bext_timestamp['year'], $bext_timestamp['month'], $bext_timestamp['day']) = $matches_bext_date; - list($dummy, $bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second']) = $matches_bext_time; - $thisfile_riff_WAVE_bext_0['origin_date_unix'] = gmmktime($bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second'], $bext_timestamp['month'], $bext_timestamp['day'], $bext_timestamp['year']); - } else { - $ThisFileInfo['warning'][] = 'RIFF.WAVE.BEXT.origin_time is invalid'; - } - } else { - $ThisFileInfo['warning'][] = 'RIFF.WAVE.BEXT.origin_date is invalid'; - } - $thisfile_riff['comments']['author'][] = $thisfile_riff_WAVE_bext_0['author']; - $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_bext_0['title']; - } - - if (isset($thisfile_riff_WAVE['MEXT'][0]['data'])) { - // shortcut - $thisfile_riff_WAVE_MEXT_0 = &$thisfile_riff_WAVE['MEXT'][0]; - - $thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 0, 2)); - $thisfile_riff_WAVE_MEXT_0['flags']['homogenous'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0001); - if ($thisfile_riff_WAVE_MEXT_0['flags']['homogenous']) { - $thisfile_riff_WAVE_MEXT_0['flags']['padding'] = ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0002) ? false : true; - $thisfile_riff_WAVE_MEXT_0['flags']['22_or_44'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0004); - $thisfile_riff_WAVE_MEXT_0['flags']['free_format'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0008); - - $thisfile_riff_WAVE_MEXT_0['nominal_frame_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 2, 2)); - } - $thisfile_riff_WAVE_MEXT_0['anciliary_data_length'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 6, 2)); - $thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 8, 2)); - $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_left'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0001); - $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_free'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0002); - $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_right'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0004); - } - - if (isset($thisfile_riff_WAVE['cart'][0]['data'])) { - // shortcut - $thisfile_riff_WAVE_cart_0 = &$thisfile_riff_WAVE['cart'][0]; - - $thisfile_riff_WAVE_cart_0['version'] = substr($thisfile_riff_WAVE_cart_0['data'], 0, 4); - $thisfile_riff_WAVE_cart_0['title'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 4, 64)); - $thisfile_riff_WAVE_cart_0['artist'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 68, 64)); - $thisfile_riff_WAVE_cart_0['cut_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 132, 64)); - $thisfile_riff_WAVE_cart_0['client_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 196, 64)); - $thisfile_riff_WAVE_cart_0['category'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 260, 64)); - $thisfile_riff_WAVE_cart_0['classification'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 324, 64)); - $thisfile_riff_WAVE_cart_0['out_cue'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 388, 64)); - $thisfile_riff_WAVE_cart_0['start_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 452, 10)); - $thisfile_riff_WAVE_cart_0['start_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 462, 8)); - $thisfile_riff_WAVE_cart_0['end_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 470, 10)); - $thisfile_riff_WAVE_cart_0['end_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 480, 8)); - $thisfile_riff_WAVE_cart_0['producer_app_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 488, 64)); - $thisfile_riff_WAVE_cart_0['producer_app_version'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 552, 64)); - $thisfile_riff_WAVE_cart_0['user_defined_text'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 616, 64)); - $thisfile_riff_WAVE_cart_0['zero_db_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 680, 4), true); - for ($i = 0; $i < 8; $i++) { - $thisfile_riff_WAVE_cart_0['post_time'][$i]['usage_fourcc'] = substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8), 4); - $thisfile_riff_WAVE_cart_0['post_time'][$i]['timer_value'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8) + 4, 4)); - } - $thisfile_riff_WAVE_cart_0['url'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 748, 1024)); - $thisfile_riff_WAVE_cart_0['tag_text'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_cart_0['data'], 1772))); - - $thisfile_riff['comments']['artist'][] = $thisfile_riff_WAVE_cart_0['artist']; - $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_cart_0['title']; - } - - if (isset($thisfile_riff_WAVE['SNDM'][0]['data'])) { - // SoundMiner metadata - - // shortcuts - $thisfile_riff_WAVE_SNDM_0 = &$thisfile_riff_WAVE['SNDM'][0]; - $thisfile_riff_WAVE_SNDM_0_data = &$thisfile_riff_WAVE_SNDM_0['data']; - $SNDM_startoffset = 0; - $SNDM_endoffset = $thisfile_riff_WAVE_SNDM_0['size']; - - while ($SNDM_startoffset < $SNDM_endoffset) { - $SNDM_thisTagOffset = 0; - $SNDM_thisTagSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4)); - $SNDM_thisTagOffset += 4; - $SNDM_thisTagKey = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4); - $SNDM_thisTagOffset += 4; - $SNDM_thisTagDataSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2)); - $SNDM_thisTagOffset += 2; - $SNDM_thisTagDataFlags = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2)); - $SNDM_thisTagOffset += 2; - $SNDM_thisTagDataText = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, $SNDM_thisTagDataSize); - $SNDM_thisTagOffset += $SNDM_thisTagDataSize; - - if ($SNDM_thisTagSize != (4 + 4 + 2 + 2 + $SNDM_thisTagDataSize)) { - $ThisFileInfo['warning'][] = 'RIFF.WAVE.SNDM.data contains tag not expected length (expected: '.$SNDM_thisTagSize.', found: '.(4 + 4 + 2 + 2 + $SNDM_thisTagDataSize).') at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')'; - break; - } elseif ($SNDM_thisTagSize <= 0) { - $ThisFileInfo['warning'][] = 'RIFF.WAVE.SNDM.data contains zero-size tag at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')'; - break; - } - $SNDM_startoffset += $SNDM_thisTagSize; - - $thisfile_riff_WAVE_SNDM_0['parsed_raw'][$SNDM_thisTagKey] = $SNDM_thisTagDataText; - if ($parsedkey = $this->RIFFwaveSNDMtagLookup($SNDM_thisTagKey)) { - $thisfile_riff_WAVE_SNDM_0['parsed'][$parsedkey] = $SNDM_thisTagDataText; - } else { - $ThisFileInfo['warning'][] = 'RIFF.WAVE.SNDM contains unknown tag "'.$SNDM_thisTagKey.'" at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')'; - } - } - - $tagmapping = array( - 'tracktitle'=>'title', - 'category' =>'genre', - 'cdtitle' =>'album', - 'tracktitle'=>'title', - ); - foreach ($tagmapping as $fromkey => $tokey) { - if (isset($thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey])) { - $thisfile_riff['comments'][$tokey][] = $thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey]; - } - } - } - - if (!isset($thisfile_audio['bitrate']) && isset($thisfile_riff_audio[$streamindex]['bitrate'])) { - $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate']; - $ThisFileInfo['playtime_seconds'] = (float) ((($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $thisfile_audio['bitrate']); - } - - if (!empty($ThisFileInfo['wavpack'])) { - $thisfile_audio_dataformat = 'wavpack'; - $thisfile_audio['bitrate_mode'] = 'vbr'; - $thisfile_audio['encoder'] = 'WavPack v'.$ThisFileInfo['wavpack']['version']; - - // Reset to the way it was - RIFF parsing will have messed this up - $ThisFileInfo['avdataend'] = $Original['avdataend']; - $thisfile_audio['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; - - fseek($fd, $ThisFileInfo['avdataoffset'] - 44, SEEK_SET); - $RIFFdata = fread($fd, 44); - $OrignalRIFFheaderSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8; - $OrignalRIFFdataSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44; - - if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) { - $ThisFileInfo['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize); - fseek($fd, $ThisFileInfo['avdataend'], SEEK_SET); - $RIFFdata .= fread($fd, $OrignalRIFFheaderSize - $OrignalRIFFdataSize); - } - - // move the data chunk after all other chunks (if any) - // so that the RIFF parser doesn't see EOF when trying - // to skip over the data chunk - $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8); - getid3_riff::ParseRIFFdata($RIFFdata, $ThisFileInfo); - } - - if (isset($thisfile_riff_raw['fmt ']['wFormatTag'])) { - switch ($thisfile_riff_raw['fmt ']['wFormatTag']) { - case 0x08AE: // ClearJump LiteWave - $thisfile_audio['bitrate_mode'] = 'vbr'; - $thisfile_audio_dataformat = 'litewave'; - - //typedef struct tagSLwFormat { - // WORD m_wCompFormat; // low byte defines compression method, high byte is compression flags - // DWORD m_dwScale; // scale factor for lossy compression - // DWORD m_dwBlockSize; // number of samples in encoded blocks - // WORD m_wQuality; // alias for the scale factor - // WORD m_wMarkDistance; // distance between marks in bytes - // WORD m_wReserved; - // - // //following paramters are ignored if CF_FILESRC is not set - // DWORD m_dwOrgSize; // original file size in bytes - // WORD m_bFactExists; // indicates if 'fact' chunk exists in the original file - // DWORD m_dwRiffChunkSize; // riff chunk size in the original file - // - // PCMWAVEFORMAT m_OrgWf; // original wave format - // }SLwFormat, *PSLwFormat; - - // shortcut - $thisfile_riff['litewave']['raw'] = array(); - $thisfile_riff_litewave = &$thisfile_riff['litewave']; - $thisfile_riff_litewave_raw = &$thisfile_riff_litewave['raw']; - - $thisfile_riff_litewave_raw['compression_method'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 18, 1)); - $thisfile_riff_litewave_raw['compression_flags'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 19, 1)); - $thisfile_riff_litewave_raw['m_dwScale'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 20, 4)); - $thisfile_riff_litewave_raw['m_dwBlockSize'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 24, 4)); - $thisfile_riff_litewave_raw['m_wQuality'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 28, 2)); - $thisfile_riff_litewave_raw['m_wMarkDistance'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 30, 2)); - $thisfile_riff_litewave_raw['m_wReserved'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 32, 2)); - $thisfile_riff_litewave_raw['m_dwOrgSize'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 34, 4)); - $thisfile_riff_litewave_raw['m_bFactExists'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 38, 2)); - $thisfile_riff_litewave_raw['m_dwRiffChunkSize'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], 40, 4)); - - //$thisfile_riff_litewave['quality_factor'] = intval(round((2000 - $thisfile_riff_litewave_raw['m_dwScale']) / 20)); - $thisfile_riff_litewave['quality_factor'] = $thisfile_riff_litewave_raw['m_wQuality']; - - $thisfile_riff_litewave['flags']['raw_source'] = ($thisfile_riff_litewave_raw['compression_flags'] & 0x01) ? false : true; - $thisfile_riff_litewave['flags']['vbr_blocksize'] = ($thisfile_riff_litewave_raw['compression_flags'] & 0x02) ? false : true; - $thisfile_riff_litewave['flags']['seekpoints'] = (bool) ($thisfile_riff_litewave_raw['compression_flags'] & 0x04); - - $thisfile_audio['lossless'] = (($thisfile_riff_litewave_raw['m_wQuality'] == 100) ? true : false); - $thisfile_audio['encoder_options'] = '-q'.$thisfile_riff_litewave['quality_factor']; - break; - - default: - break; - } - } - if ($ThisFileInfo['avdataend'] > $ThisFileInfo['filesize']) { - switch (!empty($thisfile_audio_dataformat) ? $thisfile_audio_dataformat : '') { - case 'wavpack': // WavPack - case 'lpac': // LPAC - case 'ofr': // OptimFROG - case 'ofs': // OptimFROG DualStream - // lossless compressed audio formats that keep original RIFF headers - skip warning - break; - - case 'litewave': - if (($ThisFileInfo['avdataend'] - $ThisFileInfo['filesize']) == 1) { - // LiteWave appears to incorrectly *not* pad actual output file - // to nearest WORD boundary so may appear to be short by one - // byte, in which case - skip warning - } else { - // Short by more than one byte, throw warning - $ThisFileInfo['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset'])).' bytes)'; - $ThisFileInfo['avdataend'] = $ThisFileInfo['filesize']; - } - break; - - default: - if ((($ThisFileInfo['avdataend'] - $ThisFileInfo['filesize']) == 1) && (($thisfile_riff[$RIFFsubtype]['data'][0]['size'] % 2) == 0) && ((($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset']) % 2) == 1)) { - // output file appears to be incorrectly *not* padded to nearest WORD boundary - // Output less severe warning - $ThisFileInfo['warning'][] = 'File should probably be padded to nearest WORD boundary, but it is not (expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset']).' therefore short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset'])).' bytes)'; - $ThisFileInfo['avdataend'] = $ThisFileInfo['filesize']; - } else { - // Short by more than one byte, throw warning - $ThisFileInfo['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset'])).' bytes)'; - $ThisFileInfo['avdataend'] = $ThisFileInfo['filesize']; - } - break; - } - } - if (!empty($ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes'])) { - if ((($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) - $ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes']) == 1) { - $ThisFileInfo['avdataend']--; - $ThisFileInfo['warning'][] = 'Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored'; - } - } - if (isset($thisfile_audio_dataformat) && ($thisfile_audio_dataformat == 'ac3')) { - unset($thisfile_audio['bits_per_sample']); - if (!empty($ThisFileInfo['ac3']['bitrate']) && ($ThisFileInfo['ac3']['bitrate'] != $thisfile_audio['bitrate'])) { - $thisfile_audio['bitrate'] = $ThisFileInfo['ac3']['bitrate']; - } - } - break; - - case 'AVI ': - $thisfile_video['bitrate_mode'] = 'vbr'; // maybe not, but probably - $thisfile_video['dataformat'] = 'avi'; - $ThisFileInfo['mime_type'] = 'video/avi'; - - if (isset($thisfile_riff[$RIFFsubtype]['movi']['offset'])) { - $ThisFileInfo['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['movi']['offset'] + 8; - if (isset($thisfile_riff['AVIX'])) { - $ThisFileInfo['avdataend'] = $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['offset'] + $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['size']; - } else { - $ThisFileInfo['avdataend'] = $thisfile_riff['AVI ']['movi']['offset'] + $thisfile_riff['AVI ']['movi']['size']; - } - if ($ThisFileInfo['avdataend'] > $ThisFileInfo['filesize']) { - $ThisFileInfo['warning'][] = 'Probably truncated file - expecting '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' bytes of data, only found '.($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset']).' (short by '.($ThisFileInfo['avdataend'] - $ThisFileInfo['filesize']).' bytes)'; - $ThisFileInfo['avdataend'] = $ThisFileInfo['filesize']; - } - } - - if (isset($thisfile_riff['AVI ']['hdrl']['strl']['indx'])) { - //$bIndexType = array( - // 0x00 => 'AVI_INDEX_OF_INDEXES', - // 0x01 => 'AVI_INDEX_OF_CHUNKS', - // 0x80 => 'AVI_INDEX_IS_DATA', - //); - //$bIndexSubtype = array( - // 0x01 => array( - // 0x01 => 'AVI_INDEX_2FIELD', - // ), - //); - foreach ($thisfile_riff['AVI ']['hdrl']['strl']['indx'] as $streamnumber => $steamdataarray) { - $thisfile_riff_avi_hdrl_strl_indx_stream_data = &$thisfile_riff['AVI ']['hdrl']['strl']['indx'][$streamnumber]['data']; - - $thisfile_riff_raw['indx'][$streamnumber]['wLongsPerEntry'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 0, 2)); - $thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 2, 1)); - $thisfile_riff_raw['indx'][$streamnumber]['bIndexType'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 3, 1)); - $thisfile_riff_raw['indx'][$streamnumber]['nEntriesInUse'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 4, 4)); - $thisfile_riff_raw['indx'][$streamnumber]['dwChunkId'] = substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 8, 4); - $thisfile_riff_raw['indx'][$streamnumber]['dwReserved'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_avi_hdrl_strl_indx_stream_data, 12, 4)); - - //$thisfile_riff_raw['indx'][$streamnumber]['bIndexType_name'] = $bIndexType[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']]; - //$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType_name'] = $bIndexSubtype[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']][$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType']]; - - unset($thisfile_riff_avi_hdrl_strl_indx_stream_data); - } - } - if (isset($thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'])) { - $avihData = $thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data']; - - // shortcut - $thisfile_riff_raw['avih'] = array(); - $thisfile_riff_raw_avih = &$thisfile_riff_raw['avih']; - - $thisfile_riff_raw_avih['dwMicroSecPerFrame'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 0, 4)); // frame display rate (or 0L) - if ($thisfile_riff_raw_avih['dwMicroSecPerFrame'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt RIFF file: avih.dwMicroSecPerFrame == zero'; - return false; - } - $thisfile_riff_raw_avih['dwMaxBytesPerSec'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 4, 4)); // max. transfer rate - $thisfile_riff_raw_avih['dwPaddingGranularity'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 8, 4)); // pad to multiples of this size; normally 2K. - $thisfile_riff_raw_avih['dwFlags'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 12, 4)); // the ever-present flags - $thisfile_riff_raw_avih['dwTotalFrames'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 16, 4)); // # frames in file - $thisfile_riff_raw_avih['dwInitialFrames'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 20, 4)); - $thisfile_riff_raw_avih['dwStreams'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 24, 4)); - $thisfile_riff_raw_avih['dwSuggestedBufferSize'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 28, 4)); - $thisfile_riff_raw_avih['dwWidth'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 32, 4)); - $thisfile_riff_raw_avih['dwHeight'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 36, 4)); - $thisfile_riff_raw_avih['dwScale'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 40, 4)); - $thisfile_riff_raw_avih['dwRate'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 44, 4)); - $thisfile_riff_raw_avih['dwStart'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 48, 4)); - $thisfile_riff_raw_avih['dwLength'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($avihData, 52, 4)); - - $thisfile_riff_raw_avih['flags']['hasindex'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000010); - $thisfile_riff_raw_avih['flags']['mustuseindex'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000020); - $thisfile_riff_raw_avih['flags']['interleaved'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000100); - $thisfile_riff_raw_avih['flags']['trustcktype'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00000800); - $thisfile_riff_raw_avih['flags']['capturedfile'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00010000); - $thisfile_riff_raw_avih['flags']['copyrighted'] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & 0x00020010); - - // shortcut - $thisfile_riff_video[$streamindex] = array(); - $thisfile_riff_video_current = &$thisfile_riff_video[$streamindex]; - - if ($thisfile_riff_raw_avih['dwWidth'] > 0) { - $thisfile_riff_video_current['frame_width'] = $thisfile_riff_raw_avih['dwWidth']; - $thisfile_video['resolution_x'] = $thisfile_riff_video_current['frame_width']; - } - if ($thisfile_riff_raw_avih['dwHeight'] > 0) { - $thisfile_riff_video_current['frame_height'] = $thisfile_riff_raw_avih['dwHeight']; - $thisfile_video['resolution_y'] = $thisfile_riff_video_current['frame_height']; - } - if ($thisfile_riff_raw_avih['dwTotalFrames'] > 0) { - $thisfile_riff_video_current['total_frames'] = $thisfile_riff_raw_avih['dwTotalFrames']; - $thisfile_video['total_frames'] = $thisfile_riff_video_current['total_frames']; - } - - $thisfile_riff_video_current['frame_rate'] = round(1000000 / $thisfile_riff_raw_avih['dwMicroSecPerFrame'], 3); - $thisfile_video['frame_rate'] = $thisfile_riff_video_current['frame_rate']; - } - if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) { - if (is_array($thisfile_riff['AVI ']['hdrl']['strl']['strh'])) { - for ($i = 0; $i < count($thisfile_riff['AVI ']['hdrl']['strl']['strh']); $i++) { - if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) { - $strhData = $thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data']; - $strhfccType = substr($strhData, 0, 4); - - if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'])) { - $strfData = $thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data']; - - // shortcut - $thisfile_riff_raw_strf_strhfccType_streamindex = &$thisfile_riff_raw['strf'][$strhfccType][$streamindex]; - - switch ($strhfccType) { - case 'auds': - $thisfile_audio['bitrate_mode'] = 'cbr'; - $thisfile_audio_dataformat = 'wav'; - if (isset($thisfile_riff_audio) && is_array($thisfile_riff_audio)) { - $streamindex = count($thisfile_riff_audio); - } - - $thisfile_riff_audio[$streamindex] = getid3_riff::RIFFparseWAVEFORMATex($strfData); - $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag']; - - // shortcut - $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex]; - $thisfile_audio_streams_currentstream = &$thisfile_audio['streams'][$streamindex]; - - if ($thisfile_audio_streams_currentstream['bits_per_sample'] == 0) { - unset($thisfile_audio_streams_currentstream['bits_per_sample']); - } - $thisfile_audio_streams_currentstream['wformattag'] = $thisfile_audio_streams_currentstream['raw']['wFormatTag']; - unset($thisfile_audio_streams_currentstream['raw']); - - // shortcut - $thisfile_riff_raw['strf'][$strhfccType][$streamindex] = $thisfile_riff_audio[$streamindex]['raw']; - - unset($thisfile_riff_audio[$streamindex]['raw']); - $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]); - - $thisfile_audio['lossless'] = false; - switch ($thisfile_riff_raw_strf_strhfccType_streamindex['wFormatTag']) { - case 0x0001: // PCM - $thisfile_audio_dataformat = 'wav'; - $thisfile_audio['lossless'] = true; - break; - - case 0x0050: // MPEG Layer 2 or Layer 1 - $thisfile_audio_dataformat = 'mp2'; // Assume Layer-2 - break; - - case 0x0055: // MPEG Layer 3 - $thisfile_audio_dataformat = 'mp3'; - break; - - case 0x00FF: // AAC - $thisfile_audio_dataformat = 'aac'; - break; - - case 0x0161: // Windows Media v7 / v8 / v9 - case 0x0162: // Windows Media Professional v9 - case 0x0163: // Windows Media Lossess v9 - $thisfile_audio_dataformat = 'wma'; - break; - - case 0x2000: // AC-3 - $thisfile_audio_dataformat = 'ac3'; - break; - - case 0x2001: // DTS - $thisfile_audio_dataformat = 'dts'; - break; - - default: - $thisfile_audio_dataformat = 'wav'; - break; - } - $thisfile_audio_streams_currentstream['dataformat'] = $thisfile_audio_dataformat; - $thisfile_audio_streams_currentstream['lossless'] = $thisfile_audio['lossless']; - $thisfile_audio_streams_currentstream['bitrate_mode'] = $thisfile_audio['bitrate_mode']; - break; - - - case 'iavs': - case 'vids': - // shortcut - $thisfile_riff_raw['strh'][$i] = array(); - $thisfile_riff_raw_strh_current = &$thisfile_riff_raw['strh'][$i]; - - $thisfile_riff_raw_strh_current['fccType'] = substr($strhData, 0, 4); // same as $strhfccType; - $thisfile_riff_raw_strh_current['fccHandler'] = substr($strhData, 4, 4); - $thisfile_riff_raw_strh_current['dwFlags'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 8, 4)); // Contains AVITF_* flags - $thisfile_riff_raw_strh_current['wPriority'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 12, 2)); - $thisfile_riff_raw_strh_current['wLanguage'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 14, 2)); - $thisfile_riff_raw_strh_current['dwInitialFrames'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 16, 4)); - $thisfile_riff_raw_strh_current['dwScale'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 20, 4)); - $thisfile_riff_raw_strh_current['dwRate'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 24, 4)); - $thisfile_riff_raw_strh_current['dwStart'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 28, 4)); - $thisfile_riff_raw_strh_current['dwLength'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 32, 4)); - $thisfile_riff_raw_strh_current['dwSuggestedBufferSize'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 36, 4)); - $thisfile_riff_raw_strh_current['dwQuality'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 40, 4)); - $thisfile_riff_raw_strh_current['dwSampleSize'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 44, 4)); - $thisfile_riff_raw_strh_current['rcFrame'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strhData, 48, 4)); - - $thisfile_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strh_current['fccHandler']); - $thisfile_video['fourcc'] = $thisfile_riff_raw_strh_current['fccHandler']; - if (!$thisfile_riff_video_current['codec'] && isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) && getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) { - $thisfile_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']); - $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']; - } - $thisfile_video['codec'] = $thisfile_riff_video_current['codec']; - $thisfile_video['pixel_aspect_ratio'] = (float) 1; - switch ($thisfile_riff_raw_strh_current['fccHandler']) { - case 'HFYU': // Huffman Lossless Codec - case 'IRAW': // Intel YUV Uncompressed - case 'YUY2': // Uncompressed YUV 4:2:2 - $thisfile_video['lossless'] = true; - break; - - default: - $thisfile_video['lossless'] = false; - break; - } - - switch ($strhfccType) { - case 'vids': - $thisfile_riff_raw_strf_strhfccType_streamindex = getid3_riff::ParseBITMAPINFOHEADER(substr($strfData, 0, 40), ($ThisFileInfo['fileformat'] == 'riff')); - //$thisfile_riff_raw_strf_strhfccType_streamindex['biSize'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 0, 4)); // number of bytes required by the BITMAPINFOHEADER structure - //$thisfile_riff_raw_strf_strhfccType_streamindex['biWidth'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 4, 4)); // width of the bitmap in pixels - //$thisfile_riff_raw_strf_strhfccType_streamindex['biHeight'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 8, 4)); // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner - //$thisfile_riff_raw_strf_strhfccType_streamindex['biPlanes'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 12, 2)); // number of color planes on the target device. In most cases this value must be set to 1 - //$thisfile_riff_raw_strf_strhfccType_streamindex['biBitCount'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 14, 2)); // Specifies the number of bits per pixels - //$thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'] = substr($strfData, 16, 4); // - //$thisfile_riff_raw_strf_strhfccType_streamindex['biSizeImage'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 20, 4)); // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures) - //$thisfile_riff_raw_strf_strhfccType_streamindex['biXPelsPerMeter'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 24, 4)); // horizontal resolution, in pixels per metre, of the target device - //$thisfile_riff_raw_strf_strhfccType_streamindex['biYPelsPerMeter'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 28, 4)); // vertical resolution, in pixels per metre, of the target device - //$thisfile_riff_raw_strf_strhfccType_streamindex['biClrUsed'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 32, 4)); // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression - //$thisfile_riff_raw_strf_strhfccType_streamindex['biClrImportant'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($strfData, 36, 4)); // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important - - $thisfile_video['bits_per_sample'] = $thisfile_riff_raw_strf_strhfccType_streamindex['biBitCount']; - - if ($thisfile_riff_video_current['codec'] == 'DV') { - $thisfile_riff_video_current['dv_type'] = 2; - } - break; - - case 'iavs': - $thisfile_riff_video_current['dv_type'] = 1; - break; - } - break; - - default: - $ThisFileInfo['warning'][] = 'Unhandled fccType for stream ('.$i.'): "'.$strhfccType.'"'; - break; - - } - } - } - - if (isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) && getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) { - - $thisfile_riff_video_current['codec'] = getid3_riff::RIFFfourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']); - $thisfile_video['codec'] = $thisfile_riff_video_current['codec']; - $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']; - - switch ($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) { - case 'HFYU': // Huffman Lossless Codec - case 'IRAW': // Intel YUV Uncompressed - case 'YUY2': // Uncompressed YUV 4:2:2 - $thisfile_video['lossless'] = true; - $thisfile_video['bits_per_sample'] = 24; - break; - - default: - $thisfile_video['lossless'] = false; - $thisfile_video['bits_per_sample'] = 24; - break; - } - - } - } - } - } - break; - - case 'CDDA': - $thisfile_audio['bitrate_mode'] = 'cbr'; - $thisfile_audio_dataformat = 'cda'; - $thisfile_audio['lossless'] = true; - unset($ThisFileInfo['mime_type']); - - $ThisFileInfo['avdataoffset'] = 44; - - if (isset($thisfile_riff['CDDA']['fmt '][0]['data'])) { - // shortcut - $thisfile_riff_CDDA_fmt_0 = &$thisfile_riff['CDDA']['fmt '][0]; - - $thisfile_riff_CDDA_fmt_0['unknown1'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0['data'], 0, 2)); - $thisfile_riff_CDDA_fmt_0['track_num'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0['data'], 2, 2)); - $thisfile_riff_CDDA_fmt_0['disc_id'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0['data'], 4, 4)); - $thisfile_riff_CDDA_fmt_0['start_offset_frame'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0['data'], 8, 4)); - $thisfile_riff_CDDA_fmt_0['playtime_frames'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0['data'], 12, 4)); - $thisfile_riff_CDDA_fmt_0['unknown6'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0['data'], 16, 4)); - $thisfile_riff_CDDA_fmt_0['unknown7'] = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($thisfile_riff_CDDA_fmt_0['data'], 20, 4)); - - $thisfile_riff_CDDA_fmt_0['start_offset_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['start_offset_frame'] / 75; - $thisfile_riff_CDDA_fmt_0['playtime_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['playtime_frames'] / 75; - $ThisFileInfo['comments']['track'] = $thisfile_riff_CDDA_fmt_0['track_num']; - $ThisFileInfo['playtime_seconds'] = $thisfile_riff_CDDA_fmt_0['playtime_seconds']; - - // hardcoded data for CD-audio - $thisfile_audio['sample_rate'] = 44100; - $thisfile_audio['channels'] = 2; - $thisfile_audio['bits_per_sample'] = 16; - $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $thisfile_audio['channels'] * $thisfile_audio['bits_per_sample']; - $thisfile_audio['bitrate_mode'] = 'cbr'; - } - break; - - - case 'AIFF': - case 'AIFC': - $thisfile_audio['bitrate_mode'] = 'cbr'; - $thisfile_audio_dataformat = 'aiff'; - $thisfile_audio['lossless'] = true; - $ThisFileInfo['mime_type'] = 'audio/x-aiff'; - - if (isset($thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'])) { - $ThisFileInfo['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'] + 8; - $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['SSND'][0]['size']; - if ($ThisFileInfo['avdataend'] > $ThisFileInfo['filesize']) { - if (($ThisFileInfo['avdataend'] == ($ThisFileInfo['filesize'] + 1)) && (($ThisFileInfo['filesize'] % 2) == 1)) { - // structures rounded to 2-byte boundary, but dumb encoders - // forget to pad end of file to make this actually work - } else { - $ThisFileInfo['warning'][] = 'Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['SSND'][0]['size'].' bytes of audio data, only '.($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset']).' bytes found'; - } - $ThisFileInfo['avdataend'] = $ThisFileInfo['filesize']; - } - } - - if (isset($thisfile_riff[$RIFFsubtype]['COMM'][0]['data'])) { - - // shortcut - $thisfile_riff_RIFFsubtype_COMM_0_data = &$thisfile_riff[$RIFFsubtype]['COMM'][0]['data']; - - $thisfile_riff_audio['channels'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 0, 2), true); - $thisfile_riff_audio['total_samples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 2, 4), false); - $thisfile_riff_audio['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 6, 2), true); - $thisfile_riff_audio['sample_rate'] = (int) getid3_lib::BigEndian2Float(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 8, 10)); - - if ($thisfile_riff[$RIFFsubtype]['COMM'][0]['size'] > 18) { - $thisfile_riff_audio['codec_fourcc'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 18, 4); - $CodecNameSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 22, 1), false); - $thisfile_riff_audio['codec_name'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 23, $CodecNameSize); - switch ($thisfile_riff_audio['codec_name']) { - case 'NONE': - $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)'; - $thisfile_audio['lossless'] = true; - break; - - case '': - switch ($thisfile_riff_audio['codec_fourcc']) { - // http://developer.apple.com/qa/snd/snd07.html - case 'sowt': - $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Little-Endian PCM'; - $thisfile_audio['lossless'] = true; - break; - - case 'twos': - $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Big-Endian PCM'; - $thisfile_audio['lossless'] = true; - break; - - default: - break; - } - break; - - default: - $thisfile_audio['codec'] = $thisfile_riff_audio['codec_name']; - $thisfile_audio['lossless'] = false; - break; - } - } - - $thisfile_audio['channels'] = $thisfile_riff_audio['channels']; - if ($thisfile_riff_audio['bits_per_sample'] > 0) { - $thisfile_audio['bits_per_sample'] = $thisfile_riff_audio['bits_per_sample']; - } - $thisfile_audio['sample_rate'] = $thisfile_riff_audio['sample_rate']; - if ($thisfile_audio['sample_rate'] == 0) { - $ThisFileInfo['error'][] = 'Corrupted AIFF file: sample_rate == zero'; - return false; - } - $ThisFileInfo['playtime_seconds'] = $thisfile_riff_audio['total_samples'] / $thisfile_audio['sample_rate']; - } - - if (isset($thisfile_riff[$RIFFsubtype]['COMT'])) { - $offset = 0; - $CommentCount = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false); - $offset += 2; - for ($i = 0; $i < $CommentCount; $i++) { - $ThisFileInfo['comments_raw'][$i]['timestamp'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 4), false); - $offset += 4; - $ThisFileInfo['comments_raw'][$i]['marker_id'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), true); - $offset += 2; - $CommentLength = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false); - $offset += 2; - $ThisFileInfo['comments_raw'][$i]['comment'] = substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, $CommentLength); - $offset += $CommentLength; - - $ThisFileInfo['comments_raw'][$i]['timestamp_unix'] = getid3_lib::DateMac2Unix($ThisFileInfo['comments_raw'][$i]['timestamp']); - $thisfile_riff['comments']['comment'][] = $ThisFileInfo['comments_raw'][$i]['comment']; - } - } - - $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment'); - foreach ($CommentsChunkNames as $key => $value) { - if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) { - $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data']; - } - } - break; - - case '8SVX': - $thisfile_audio['bitrate_mode'] = 'cbr'; - $thisfile_audio_dataformat = '8svx'; - $thisfile_audio['bits_per_sample'] = 8; - $thisfile_audio['channels'] = 1; // overridden below, if need be - $ThisFileInfo['mime_type'] = 'audio/x-aiff'; - - if (isset($thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'])) { - $ThisFileInfo['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'] + 8; - $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['BODY'][0]['size']; - if ($ThisFileInfo['avdataend'] > $ThisFileInfo['filesize']) { - $ThisFileInfo['warning'][] = 'Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['BODY'][0]['size'].' bytes of audio data, only '.($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset']).' bytes found'; - } - } - - if (isset($thisfile_riff[$RIFFsubtype]['VHDR'][0]['offset'])) { - // shortcut - $thisfile_riff_RIFFsubtype_VHDR_0 = &$thisfile_riff[$RIFFsubtype]['VHDR'][0]; - - $thisfile_riff_RIFFsubtype_VHDR_0['oneShotHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 0, 4)); - $thisfile_riff_RIFFsubtype_VHDR_0['repeatHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 4, 4)); - $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerHiCycle'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 8, 4)); - $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 12, 2)); - $thisfile_riff_RIFFsubtype_VHDR_0['ctOctave'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 14, 1)); - $thisfile_riff_RIFFsubtype_VHDR_0['sCompression'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 15, 1)); - $thisfile_riff_RIFFsubtype_VHDR_0['Volume'] = getid3_lib::FixedPoint16_16(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 16, 4)); - - $thisfile_audio['sample_rate'] = $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec']; - - switch ($thisfile_riff_RIFFsubtype_VHDR_0['sCompression']) { - case 0: - $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)'; - $thisfile_audio['lossless'] = true; - $ActualBitsPerSample = 8; - break; - - case 1: - $thisfile_audio['codec'] = 'Fibonacci-delta encoding'; - $thisfile_audio['lossless'] = false; - $ActualBitsPerSample = 4; - break; - - default: - $ThisFileInfo['warning'][] = 'Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "'.sCompression.'"'; - break; - } - } - - if (isset($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'])) { - $ChannelsIndex = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'], 0, 4)); - switch ($ChannelsIndex) { - case 6: // Stereo - $thisfile_audio['channels'] = 2; - break; - - case 2: // Left channel only - case 4: // Right channel only - $thisfile_audio['channels'] = 1; - break; - - default: - $ThisFileInfo['warning'][] = 'Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "'.$ChannelsIndex.'"'; - break; - } - - } - - $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment'); - foreach ($CommentsChunkNames as $key => $value) { - if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) { - $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data']; - } - } - - $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $ActualBitsPerSample * $thisfile_audio['channels']; - if (!empty($thisfile_audio['bitrate'])) { - $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / ($thisfile_audio['bitrate'] / 8); - } - break; - - - case 'CDXA': - $ThisFileInfo['mime_type'] = 'video/mpeg'; - if (!empty($thisfile_riff['CDXA']['data'][0]['size'])) { - $GETID3_ERRORARRAY = &$ThisFileInfo['warning']; - if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.mpeg.php', __FILE__, false)) { - $dummy = $ThisFileInfo; - $dummy['error'] = array(); - $mpeg_scanner = new getid3_mpeg($fd, $dummy); - if (empty($dummy['error'])) { - $ThisFileInfo['audio'] = $dummy['audio']; - $ThisFileInfo['video'] = $dummy['video']; - $ThisFileInfo['mpeg'] = $dummy['mpeg']; - $ThisFileInfo['warning'] = $dummy['warning']; - } - unset($mpeg_scanner); - } - } - break; - - - default: - $ThisFileInfo['error'][] = 'Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA), found "'.$RIFFsubtype.'" instead'; - unset($ThisFileInfo['fileformat']); - break; - } - - if (isset($thisfile_riff_raw['fmt ']['wFormatTag']) && ($thisfile_riff_raw['fmt ']['wFormatTag'] == 1)) { - // http://www.mega-nerd.com/erikd/Blog/Windiots/dts.html - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $FirstFourBytes = fread($fd, 4); - if (preg_match('/^\xFF\x1F\x00\xE8/s', $FirstFourBytes)) { - // DTSWAV - $thisfile_audio_dataformat = 'dts'; - } elseif (preg_match('/^\x7F\xFF\x80\x01/s', $FirstFourBytes)) { - // DTS, but this probably shouldn't happen - $thisfile_audio_dataformat = 'dts'; - } - } - - - if (isset($thisfile_riff_WAVE['DISP']) && is_array($thisfile_riff_WAVE['DISP'])) { - $thisfile_riff['comments']['title'][] = trim(substr($thisfile_riff_WAVE['DISP'][count($thisfile_riff_WAVE['DISP']) - 1]['data'], 4)); - } - if (isset($thisfile_riff_WAVE['INFO']) && is_array($thisfile_riff_WAVE['INFO'])) { - $this->RIFFcommentsParse($thisfile_riff_WAVE['INFO'], $thisfile_riff['comments']); - } - if (isset($thisfile_riff['AVI ']['INFO']) && is_array($thisfile_riff['AVI ']['INFO'])) { - $this->RIFFcommentsParse($thisfile_riff['AVI ']['INFO'], $thisfile_riff['comments']); - } - - if (empty($thisfile_audio['encoder']) && !empty($ThisFileInfo['mpeg']['audio']['LAME']['short_version'])) { - $thisfile_audio['encoder'] = $ThisFileInfo['mpeg']['audio']['LAME']['short_version']; - } - - if (!isset($ThisFileInfo['playtime_seconds'])) { - $ThisFileInfo['playtime_seconds'] = 0; - } - if (isset($thisfile_riff_raw['strh'][0]['dwLength']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) { - // needed for >2GB AVIs where 'avih' chunk only lists number of frames in that chunk, not entire movie - $ThisFileInfo['playtime_seconds'] = $thisfile_riff_raw['strh'][0]['dwLength'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000); - } elseif (isset($thisfile_riff_raw['avih']['dwTotalFrames']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) { - $ThisFileInfo['playtime_seconds'] = $thisfile_riff_raw['avih']['dwTotalFrames'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000); - } - - if ($ThisFileInfo['playtime_seconds'] > 0) { - if (isset($thisfile_riff_audio) && isset($thisfile_riff_video)) { - - if (!isset($ThisFileInfo['bitrate'])) { - $ThisFileInfo['bitrate'] = ((($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds']) * 8); - } - - } elseif (isset($thisfile_riff_audio) && !isset($thisfile_riff_video)) { - - if (!isset($thisfile_audio['bitrate'])) { - $thisfile_audio['bitrate'] = ((($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds']) * 8); - } - - } elseif (!isset($thisfile_riff_audio) && isset($thisfile_riff_video)) { - - if (!isset($thisfile_video['bitrate'])) { - $thisfile_video['bitrate'] = ((($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds']) * 8); - } - - } - } - - - if (isset($thisfile_riff_video) && isset($thisfile_audio['bitrate']) && ($thisfile_audio['bitrate'] > 0) && ($ThisFileInfo['playtime_seconds'] > 0)) { - - $ThisFileInfo['bitrate'] = ((($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds']) * 8); - $thisfile_audio['bitrate'] = 0; - $thisfile_video['bitrate'] = $ThisFileInfo['bitrate']; - foreach ($thisfile_riff_audio as $channelnumber => $audioinfoarray) { - $thisfile_video['bitrate'] -= $audioinfoarray['bitrate']; - $thisfile_audio['bitrate'] += $audioinfoarray['bitrate']; - } - if ($thisfile_video['bitrate'] <= 0) { - unset($thisfile_video['bitrate']); - } - if ($thisfile_audio['bitrate'] <= 0) { - unset($thisfile_audio['bitrate']); - } - } - - if (isset($ThisFileInfo['mpeg']['audio'])) { - $thisfile_audio_dataformat = 'mp'.$ThisFileInfo['mpeg']['audio']['layer']; - $thisfile_audio['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate']; - $thisfile_audio['channels'] = $ThisFileInfo['mpeg']['audio']['channels']; - $thisfile_audio['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate']; - $thisfile_audio['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitrate_mode']); - if (!empty($ThisFileInfo['mpeg']['audio']['codec'])) { - $thisfile_audio['codec'] = $ThisFileInfo['mpeg']['audio']['codec'].' '.$thisfile_audio['codec']; - } - if (!empty($thisfile_audio['streams'])) { - foreach ($thisfile_audio['streams'] as $streamnumber => $streamdata) { - if ($streamdata['dataformat'] == $thisfile_audio_dataformat) { - $thisfile_audio['streams'][$streamnumber]['sample_rate'] = $thisfile_audio['sample_rate']; - $thisfile_audio['streams'][$streamnumber]['channels'] = $thisfile_audio['channels']; - $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate']; - $thisfile_audio['streams'][$streamnumber]['bitrate_mode'] = $thisfile_audio['bitrate_mode']; - $thisfile_audio['streams'][$streamnumber]['codec'] = $thisfile_audio['codec']; - } - } - } - $thisfile_audio['encoder_options'] = getid3_mp3::GuessEncoderOptions($ThisFileInfo); - } - - - if (!empty($thisfile_riff_raw['fmt ']['wBitsPerSample']) && ($thisfile_riff_raw['fmt ']['wBitsPerSample'] > 0)) { - switch ($thisfile_audio_dataformat) { - case 'ac3': - // ignore bits_per_sample - break; - - default: - $thisfile_audio['bits_per_sample'] = $thisfile_riff_raw['fmt ']['wBitsPerSample']; - break; - } - } - - - if (empty($thisfile_riff_raw)) { - unset($thisfile_riff['raw']); - } - if (empty($thisfile_riff_audio)) { - unset($thisfile_riff['audio']); - } - if (empty($thisfile_riff_video)) { - unset($thisfile_riff['video']); - } - - return true; - } - - - static function RIFFcommentsParse(&$RIFFinfoArray, &$CommentsTargetArray) { - $RIFFinfoKeyLookup = array( - 'IARL'=>'archivallocation', - 'IART'=>'artist', - 'ICDS'=>'costumedesigner', - 'ICMS'=>'commissionedby', - 'ICMT'=>'comment', - 'ICNT'=>'country', - 'ICOP'=>'copyright', - 'ICRD'=>'creationdate', - 'IDIM'=>'dimensions', - 'IDIT'=>'digitizationdate', - 'IDPI'=>'resolution', - 'IDST'=>'distributor', - 'IEDT'=>'editor', - 'IENG'=>'engineers', - 'IFRM'=>'accountofparts', - 'IGNR'=>'genre', - 'IKEY'=>'keywords', - 'ILGT'=>'lightness', - 'ILNG'=>'language', - 'IMED'=>'orignalmedium', - 'IMUS'=>'composer', - 'INAM'=>'title', - 'IPDS'=>'productiondesigner', - 'IPLT'=>'palette', - 'IPRD'=>'product', - 'IPRO'=>'producer', - 'IPRT'=>'part', - 'IRTD'=>'rating', - 'ISBJ'=>'subject', - 'ISFT'=>'software', - 'ISGN'=>'secondarygenre', - 'ISHP'=>'sharpness', - 'ISRC'=>'sourcesupplier', - 'ISRF'=>'digitizationsource', - 'ISTD'=>'productionstudio', - 'ISTR'=>'starring', - 'ITCH'=>'encoded_by', - 'IWEB'=>'url', - 'IWRI'=>'writer' - ); - foreach ($RIFFinfoKeyLookup as $key => $value) { - if (isset($RIFFinfoArray[$key])) { - foreach ($RIFFinfoArray[$key] as $commentid => $commentdata) { - if (trim($commentdata['data']) != '') { - if (isset($CommentsTargetArray[$value])) { - $CommentsTargetArray[$value][] = trim($commentdata['data']); - } else { - $CommentsTargetArray[$value] = array(trim($commentdata['data'])); - } - } - } - } - } - return true; - } - - static function ParseRIFF(&$fd, $startoffset, $maxoffset, &$ThisFileInfo) { - $maxoffset = min($maxoffset, $ThisFileInfo['avdataend']); - - $RIFFchunk = false; - $FoundAllChunksWeNeed = false; - - if (($startoffset < 0) || !getid3_lib::intValueSupported($startoffset)) { - $ThisFileInfo['warning'][] = 'Unable to ParseRIFF() at '.$startoffset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions'; - return false; - } - $max_usable_offset = min(PHP_INT_MAX - 1024, $maxoffset); - if ($maxoffset > $max_usable_offset) { - $ThisFileInfo['warning'][] = 'ParseRIFF() may return incomplete data for chunk starting at '.$startoffset.' because beyond it extends to '.$maxoffset.', which is beyond the '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions'; - } - fseek($fd, $startoffset, SEEK_SET); - - while (ftell($fd) < $max_usable_offset) { - $chunknamesize = fread($fd, 8); - $chunkname = substr($chunknamesize, 0, 4); - $chunksize = getid3_riff::EitherEndian2Int($ThisFileInfo, substr($chunknamesize, 4, 4)); - if (strlen($chunkname) < 4) { - $ThisFileInfo['error'][] = 'Expecting chunk name at offset '.(ftell($fd) - 4).' but found nothing. Aborting RIFF parsing.'; - break; - } - if ($chunksize == 0) { - if ($chunkname == 'JUNK') { - // we'll allow zero-size JUNK frames - } else { - $ThisFileInfo['warning'][] = 'Chunk size at offset '.(ftell($fd) - 4).' is zero. Aborting RIFF parsing.'; - break; - } - } - if (($chunksize % 2) != 0) { - // all structures are packed on word boundaries - $chunksize++; - } - - switch ($chunkname) { - case 'LIST': - $listname = fread($fd, 4); - if (preg_match('#^(movi|rec )$#i', $listname)) { - $RIFFchunk[$listname]['offset'] = ftell($fd) - 4; - $RIFFchunk[$listname]['size'] = $chunksize; - - if ($FoundAllChunksWeNeed) { - - // skip over - - } else { - - $WhereWeWere = ftell($fd); - $AudioChunkHeader = fread($fd, 12); - $AudioChunkStreamNum = substr($AudioChunkHeader, 0, 2); - $AudioChunkStreamType = substr($AudioChunkHeader, 2, 2); - $AudioChunkSize = getid3_lib::LittleEndian2Int(substr($AudioChunkHeader, 4, 4)); - - if ($AudioChunkStreamType == 'wb') { - $FirstFourBytes = substr($AudioChunkHeader, 8, 4); - if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', $FirstFourBytes)) { - // MP3 - if (getid3_mp3::MPEGaudioHeaderBytesValid($FirstFourBytes)) { - $dummy = $ThisFileInfo; - $dummy['avdataoffset'] = ftell($fd) - 4; - $dummy['avdataend'] = ftell($fd) + $AudioChunkSize; - getid3_mp3::getOnlyMPEGaudioInfo($fd, $dummy, $dummy['avdataoffset'], false); - if (isset($dummy['mpeg']['audio'])) { - $ThisFileInfo = $dummy; - $ThisFileInfo['audio']['dataformat'] = 'mp'.$ThisFileInfo['mpeg']['audio']['layer']; - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate']; - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels']; - $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate']; - $ThisFileInfo['bitrate'] = $ThisFileInfo['audio']['bitrate']; - $ThisFileInfo['audio']['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitrate_mode']); - } - unset($dummy); - } - - } elseif (preg_match('/^\x0B\x77/s', $FirstFourBytes)) { - - // AC3 - $GETID3_ERRORARRAY = &$ThisFileInfo['warning']; - if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, false)) { - - $dummy = $ThisFileInfo; - $dummy['avdataoffset'] = ftell($fd) - 4; - $dummy['avdataend'] = ftell($fd) + $AudioChunkSize; - $dummy['error'] = array(); - $ac3_tag = new getid3_ac3($fd, $dummy); - if (empty($dummy['error'])) { - $ThisFileInfo['audio'] = $dummy['audio']; - $ThisFileInfo['ac3'] = $dummy['ac3']; - $ThisFileInfo['warning'] = $dummy['warning']; - } - unset($ac3_tag); - - } - - } - - } - - $FoundAllChunksWeNeed = true; - fseek($fd, $WhereWeWere, SEEK_SET); - - } - fseek($fd, $chunksize - 4, SEEK_CUR); - - //} elseif (preg_match('#^[0-9]{2}(wb|pc|dc|db)$#i', $listname)) { - // - // // data chunk, ignore - // - } else { - - if (!isset($RIFFchunk[$listname])) { - $RIFFchunk[$listname] = array(); - } - $LISTchunkParent = $listname; - $LISTchunkMaxOffset = ftell($fd) - 4 + $chunksize; - if ($parsedChunk = getid3_riff::ParseRIFF($fd, ftell($fd), ftell($fd) + $chunksize - 4, $ThisFileInfo)) { - $RIFFchunk[$listname] = array_merge_recursive($RIFFchunk[$listname], $parsedChunk); - } - - } - break; - - default: - if (preg_match('#^[0-9]{2}(wb|pc|dc|db)$#', $chunkname)) { - $nextoffset = ftell($fd) + $chunksize; - if (($nextoffset < 0) || !getid3_lib::intValueSupported($nextoffset)) { - $ThisFileInfo['warning'][] = 'Unable to parse chunk at offset '.$nextoffset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions'; - break 2; - } - fseek($fd, $nextoffset, SEEK_SET); - break; - } - $thisindex = 0; - if (isset($RIFFchunk[$chunkname]) && is_array($RIFFchunk[$chunkname])) { - $thisindex = count($RIFFchunk[$chunkname]); - } - $RIFFchunk[$chunkname][$thisindex]['offset'] = ftell($fd) - 8; - $RIFFchunk[$chunkname][$thisindex]['size'] = $chunksize; - switch ($chunkname) { - case 'data': - $ThisFileInfo['avdataoffset'] = ftell($fd); - $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $chunksize; - - $RIFFdataChunkContentsTest = fread($fd, 36); - - if ((strlen($RIFFdataChunkContentsTest) > 0) && preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', substr($RIFFdataChunkContentsTest, 0, 4))) { - - // Probably is MP3 data - if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($RIFFdataChunkContentsTest, 0, 4))) { - - $dummy = $ThisFileInfo; // copy info array, only use if there's no error - $getid3_mp3 = new getid3_mp3($fd, $dummy); - $dummy = $ThisFileInfo; // copy info array, only use if there's no error - $getid3_mp3->getOnlyMPEGaudioInfo($fd, $dummy, $RIFFchunk[$chunkname][$thisindex]['offset'], false); - - // use dummy array unless error - if (empty($dummy['error'])) { - $ThisFileInfo = $dummy; - } - } - - } elseif ((strlen($RIFFdataChunkContentsTest) > 0) && (substr($RIFFdataChunkContentsTest, 0, 2) == "\x0B\x77")) { - - // This is probably AC-3 data - $GETID3_ERRORARRAY = &$ThisFileInfo['warning']; - if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, false)) { - - $dummy = $ThisFileInfo; - $dummy['avdataoffset'] = $RIFFchunk[$chunkname][$thisindex]['offset']; - $dummy['avdataend'] = $dummy['avdataoffset'] + $RIFFchunk[$chunkname][$thisindex]['size']; - $dummy['error'] = array(); - - $ac3_tag = new getid3_ac3($fd, $dummy); - if (empty($dummy['error'])) { - $ThisFileInfo['audio'] = $dummy['audio']; - $ThisFileInfo['ac3'] = $dummy['ac3']; - $ThisFileInfo['warning'] = $dummy['warning']; - } - unset($ac3_tag); - - } - - } elseif ((strlen($RIFFdataChunkContentsTest) > 0) && (substr($RIFFdataChunkContentsTest, 8, 2) == "\x77\x0B")) { - - // Dolby Digital WAV - // AC-3 content, but not encoded in same format as normal AC-3 file - // For one thing, byte order is swapped - - $GETID3_ERRORARRAY = &$ThisFileInfo['warning']; - if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, false)) { - - // ok to use tmpfile here - only 56 bytes - if ($fd_temp = tmpfile()) { - - for ($i = 0; $i < 28; $i += 2) { - // swap byte order - fwrite($fd_temp, substr($RIFFdataChunkContentsTest, 8 + $i + 1, 1)); - fwrite($fd_temp, substr($RIFFdataChunkContentsTest, 8 + $i + 0, 1)); - } - - $dummy = $ThisFileInfo; - $dummy['avdataoffset'] = 0; - $dummy['avdataend'] = 20; - $dummy['error'] = array(); - $ac3_tag = new getid3_ac3($fd_temp, $dummy); - fclose($fd_temp); - if (empty($dummy['error'])) { - $ThisFileInfo['audio'] = $dummy['audio']; - $ThisFileInfo['ac3'] = $dummy['ac3']; - $ThisFileInfo['warning'] = $dummy['warning']; - } else { - $ThisFileInfo['error'][] = 'Errors parsing DolbyDigital WAV: '.explode(';', $dummy['error']); - } - unset($ac3_tag); - - } else { - - $ThisFileInfo['error'][] = 'Could not create temporary file to analyze DolbyDigital WAV'; - - } - - } - - } elseif ((strlen($RIFFdataChunkContentsTest) > 0) && (substr($RIFFdataChunkContentsTest, 0, 4) == 'wvpk')) { - - // This is WavPack data - $ThisFileInfo['wavpack']['offset'] = $RIFFchunk[$chunkname][$thisindex]['offset']; - $ThisFileInfo['wavpack']['size'] = getid3_lib::LittleEndian2Int(substr($RIFFdataChunkContentsTest, 4, 4)); - getid3_riff::RIFFparseWavPackHeader(substr($RIFFdataChunkContentsTest, 8, 28), $ThisFileInfo); - - } else { - - // This is some other kind of data (quite possibly just PCM) - // do nothing special, just skip it - - } - $nextoffset = $RIFFchunk[$chunkname][$thisindex]['offset'] + 8 + $chunksize; - if (($nextoffset < 0) || !getid3_lib::intValueSupported($nextoffset)) { - $ThisFileInfo['warning'][] = 'Unable to parse chunk at offset '.$nextoffset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions'; - break 3; - } - fseek($fd, $RIFFchunk[$chunkname][$thisindex]['offset'] + 8 + $chunksize, SEEK_SET); - break; - - case 'bext': - case 'cart': - case 'fmt ': - case 'strh': - case 'strf': - case 'indx': - case 'MEXT': - case 'DISP': - // always read data in - $RIFFchunk[$chunkname][$thisindex]['data'] = fread($fd, $chunksize); - break; - - case 'JUNK': - // never read data in - $nextoffset = ftell($fd) + $chunksize; - if (($nextoffset < 0) || !getid3_lib::intValueSupported($nextoffset)) { - $ThisFileInfo['warning'][] = 'Unable to parse chunk at offset '.$nextoffset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions'; - break 3; - } - fseek($fd, $nextoffset, SEEK_SET); - break; - - default: - if (!preg_match('#^[0-9]{2}(wb|pc|dc|db)$#', $chunkname) && !empty($LISTchunkParent) && (($RIFFchunk[$chunkname][$thisindex]['offset'] + $RIFFchunk[$chunkname][$thisindex]['size']) <= $LISTchunkMaxOffset)) { - $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['offset'] = $RIFFchunk[$chunkname][$thisindex]['offset']; - $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['size'] = $RIFFchunk[$chunkname][$thisindex]['size']; - unset($RIFFchunk[$chunkname][$thisindex]['offset']); - unset($RIFFchunk[$chunkname][$thisindex]['size']); - if (isset($RIFFchunk[$chunkname][$thisindex]) && empty($RIFFchunk[$chunkname][$thisindex])) { - unset($RIFFchunk[$chunkname][$thisindex]); - } - if (isset($RIFFchunk[$chunkname]) && empty($RIFFchunk[$chunkname])) { - unset($RIFFchunk[$chunkname]); - } - $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['data'] = fread($fd, $chunksize); - } elseif (($chunksize > 0) && ($chunksize < 2048)) { - // only read data in if smaller than 2kB - $RIFFchunk[$chunkname][$thisindex]['data'] = fread($fd, $chunksize); - } else { - $nextoffset = ftell($fd) + $chunksize; - if (($nextoffset < 0) || !getid3_lib::intValueSupported($nextoffset)) { - $ThisFileInfo['warning'][] = 'Unable to parse chunk at offset '.$nextoffset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions'; - break 3; - } - fseek($fd, $nextoffset, SEEK_SET); - } - break; - } - break; - - } - - } - - return $RIFFchunk; - } - - - static function ParseRIFFdata(&$RIFFdata, &$ThisFileInfo) { - if ($RIFFdata) { - - $tempfile = tempnam(GETID3_TEMP_DIR, 'getID3'); - $fp_temp = fopen($tempfile, 'wb'); - $RIFFdataLength = strlen($RIFFdata); - $NewLengthString = getid3_lib::LittleEndian2String($RIFFdataLength, 4); - for ($i = 0; $i < 4; $i++) { - $RIFFdata{$i + 4} = $NewLengthString{$i}; - } - fwrite($fp_temp, $RIFFdata); - fclose($fp_temp); - - $fp_temp = fopen($tempfile, 'rb'); - $dummy = array('filesize'=>$RIFFdataLength, 'filenamepath'=>$ThisFileInfo['filenamepath'], 'tags'=>$ThisFileInfo['tags'], 'avdataoffset'=>0, 'avdataend'=>$RIFFdataLength, 'warning'=>$ThisFileInfo['warning'], 'error'=>$ThisFileInfo['error'], 'comments'=>$ThisFileInfo['comments'], 'audio'=>(isset($ThisFileInfo['audio']) ? $ThisFileInfo['audio'] : array()), 'video'=>(isset($ThisFileInfo['video']) ? $ThisFileInfo['video'] : array())); - $riff = new getid3_riff($fp_temp, $dummy); - $ThisFileInfo['riff'] = $dummy['riff']; - $ThisFileInfo['warning'] = $dummy['warning']; - $ThisFileInfo['error'] = $dummy['error']; - $ThisFileInfo['tags'] = $dummy['tags']; - $ThisFileInfo['comments'] = $dummy['comments']; - unset($riff); - fclose($fp_temp); - unlink($tempfile); - return true; - } - return false; - } - - - static function RIFFparseWAVEFORMATex($WaveFormatExData) { - // shortcut - $WaveFormatEx['raw'] = array(); - $WaveFormatEx_raw = &$WaveFormatEx['raw']; - - $WaveFormatEx_raw['wFormatTag'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 0, 2)); - $WaveFormatEx_raw['nChannels'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 2, 2)); - $WaveFormatEx_raw['nSamplesPerSec'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 4, 4)); - $WaveFormatEx_raw['nAvgBytesPerSec'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 8, 4)); - $WaveFormatEx_raw['nBlockAlign'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 12, 2)); - $WaveFormatEx_raw['wBitsPerSample'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 14, 2)); - if (strlen($WaveFormatExData) > 16) { - $WaveFormatEx_raw['cbSize'] = getid3_lib::LittleEndian2Int(substr($WaveFormatExData, 16, 2)); - } - - $WaveFormatEx['codec'] = getid3_riff::RIFFwFormatTagLookup($WaveFormatEx_raw['wFormatTag']); - $WaveFormatEx['channels'] = $WaveFormatEx_raw['nChannels']; - $WaveFormatEx['sample_rate'] = $WaveFormatEx_raw['nSamplesPerSec']; - $WaveFormatEx['bitrate'] = $WaveFormatEx_raw['nAvgBytesPerSec'] * 8; - $WaveFormatEx['bits_per_sample'] = $WaveFormatEx_raw['wBitsPerSample']; - - return $WaveFormatEx; - } - - - static function RIFFparseWavPackHeader($WavPackChunkData, &$ThisFileInfo) { - // typedef struct { - // char ckID [4]; - // long ckSize; - // short version; - // short bits; // added for version 2.00 - // short flags, shift; // added for version 3.00 - // long total_samples, crc, crc2; - // char extension [4], extra_bc, extras [3]; - // } WavpackHeader; - - // shortcut - $ThisFileInfo['wavpack'] = array(); - $thisfile_wavpack = &$ThisFileInfo['wavpack']; - - $thisfile_wavpack['version'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 0, 2)); - if ($thisfile_wavpack['version'] >= 2) { - $thisfile_wavpack['bits'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 2, 2)); - } - if ($thisfile_wavpack['version'] >= 3) { - $thisfile_wavpack['flags_raw'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 4, 2)); - $thisfile_wavpack['shift'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 6, 2)); - $thisfile_wavpack['total_samples'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 8, 4)); - $thisfile_wavpack['crc1'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 12, 4)); - $thisfile_wavpack['crc2'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 16, 4)); - $thisfile_wavpack['extension'] = substr($WavPackChunkData, 20, 4); - $thisfile_wavpack['extra_bc'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 24, 1)); - for ($i = 0; $i <= 2; $i++) { - $thisfile_wavpack['extras'][] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 25 + $i, 1)); - } - - // shortcut - $thisfile_wavpack['flags'] = array(); - $thisfile_wavpack_flags = &$thisfile_wavpack['flags']; - - $thisfile_wavpack_flags['mono'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000001); - $thisfile_wavpack_flags['fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000002); - $thisfile_wavpack_flags['raw_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000004); - $thisfile_wavpack_flags['calc_noise'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000008); - $thisfile_wavpack_flags['high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000010); - $thisfile_wavpack_flags['3_byte_samples'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000020); - $thisfile_wavpack_flags['over_20_bits'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000040); - $thisfile_wavpack_flags['use_wvc'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000080); - $thisfile_wavpack_flags['noiseshaping'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000100); - $thisfile_wavpack_flags['very_fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000200); - $thisfile_wavpack_flags['new_high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000400); - $thisfile_wavpack_flags['cancel_extreme'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000800); - $thisfile_wavpack_flags['cross_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x001000); - $thisfile_wavpack_flags['new_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x002000); - $thisfile_wavpack_flags['joint_stereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x004000); - $thisfile_wavpack_flags['extra_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x008000); - $thisfile_wavpack_flags['override_noiseshape'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x010000); - $thisfile_wavpack_flags['override_jointstereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x020000); - $thisfile_wavpack_flags['copy_source_filetime'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x040000); - $thisfile_wavpack_flags['create_exe'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x080000); - } - - return true; - } - - static function ParseBITMAPINFOHEADER($BITMAPINFOHEADER, $littleEndian=true) { - // yes it's ugly to instantiate a getid3_lib object here, suggested alternative please? - $getid3_lib = new getid3_lib(); - $functionname = ($littleEndian ? 'LittleEndian2Int' : 'BigEndian2Int'); - $parsed['biSize'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 0, 4)); // number of bytes required by the BITMAPINFOHEADER structure - $parsed['biWidth'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 4, 4)); // width of the bitmap in pixels - $parsed['biHeight'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 8, 4)); // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner - $parsed['biPlanes'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 12, 2)); // number of color planes on the target device. In most cases this value must be set to 1 - $parsed['biBitCount'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 14, 2)); // Specifies the number of bits per pixels - $parsed['fourcc'] = substr($BITMAPINFOHEADER, 16, 4); // compression identifier - $parsed['biSizeImage'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 20, 4)); // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures) - $parsed['biXPelsPerMeter'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 24, 4)); // horizontal resolution, in pixels per metre, of the target device - $parsed['biYPelsPerMeter'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 28, 4)); // vertical resolution, in pixels per metre, of the target device - $parsed['biClrUsed'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 32, 4)); // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression - $parsed['biClrImportant'] = $getid3_lib->$functionname(substr($BITMAPINFOHEADER, 36, 4)); // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important - return $parsed; - } - - static function ParseDIVXTAG($DIVXTAG) { - // structure from "IDivX" source, Form1.frm, by "Greg Frazier of Daemonic Software Group", email: gfrazier@icestorm.net, web: http://dsg.cjb.net/ - // source available at http://files.divx-digest.com/download/c663efe7ef8ad2e90bf4af4d3ea6188a/on0SWN2r/edit/IDivX.zip - // 'Byte Layout: '1111111111111111 - // '32 for Movie - 1 '1111111111111111 - // '28 for Author - 6 '6666666666666666 - // '4 for year - 2 '6666666666662222 - // '3 for genre - 3 '7777777777777777 - // '48 for Comments - 7 '7777777777777777 - // '1 for Rating - 4 '7777777777777777 - // '5 for Future Additions - 0 '333400000DIVXTAG - // '128 bytes total - - static $DIVXTAGgenre = array( - 0 => 'Action', - 1 => 'Action/Adventure', - 2 => 'Adventure', - 3 => 'Adult', - 4 => 'Anime', - 5 => 'Cartoon', - 6 => 'Claymation', - 7 => 'Comedy', - 8 => 'Commercial', - 9 => 'Documentary', - 10 => 'Drama', - 11 => 'Home Video', - 12 => 'Horror', - 13 => 'Infomercial', - 14 => 'Interactive', - 15 => 'Mystery', - 16 => 'Music Video', - 17 => 'Other', - 18 => 'Religion', - 19 => 'Sci Fi', - 20 => 'Thriller', - 21 => 'Western', - ); - static $DIVXTAGrating = array( - 0=>'Unrated', - 1=>'G', - 2=>'PG', - 3=>'PG-13', - 4=>'R', - 5=>'NC-17' - ); - - $parsed['title'] = trim(substr($DIVXTAG, 0, 32)); - $parsed['artist'] = trim(substr($DIVXTAG, 32, 28)); - $parsed['year'] = intval(trim(substr($DIVXTAG, 60, 4))); - $parsed['comment'] = trim(substr($DIVXTAG, 64, 48)); - $parsed['genre_id'] = intval(trim(substr($DIVXTAG, 112, 3))); - $parsed['rating_id'] = ord(substr($DIVXTAG, 115, 1)); - //$parsed['padding'] = substr($DIVXTAG, 116, 5); // 5-byte null - //$parsed['magic'] = substr($DIVXTAG, 121, 7); // "DIVXTAG" - - $parsed['genre'] = (isset($DIVXTAGgenre[$parsed['genre_id']]) ? $DIVXTAGgenre[$parsed['genre_id']] : $parsed['genre_id']); - $parsed['rating'] = (isset($DIVXTAGrating[$parsed['rating_id']]) ? $DIVXTAGrating[$parsed['rating_id']] : $parsed['rating_id']); - return $parsed; - } - - static function RIFFwaveSNDMtagLookup($tagshortname) { - $begin = __LINE__; - - /** This is not a comment! - - ©kwd keywords - ©BPM bpm - ©trt tracktitle - ©des description - ©gen category - ©fin featuredinstrument - ©LID longid - ©bex bwdescription - ©pub publisher - ©cdt cdtitle - ©alb library - ©com composer - - */ - - return getid3_lib::EmbeddedLookup($tagshortname, $begin, __LINE__, __FILE__, 'riff-sndm'); - } - - static function RIFFwFormatTagLookup($wFormatTag) { - - $begin = __LINE__; - - /** This is not a comment! - - 0x0000 Microsoft Unknown Wave Format - 0x0001 Pulse Code Modulation (PCM) - 0x0002 Microsoft ADPCM - 0x0003 IEEE Float - 0x0004 Compaq Computer VSELP - 0x0005 IBM CVSD - 0x0006 Microsoft A-Law - 0x0007 Microsoft mu-Law - 0x0008 Microsoft DTS - 0x0010 OKI ADPCM - 0x0011 Intel DVI/IMA ADPCM - 0x0012 Videologic MediaSpace ADPCM - 0x0013 Sierra Semiconductor ADPCM - 0x0014 Antex Electronics G.723 ADPCM - 0x0015 DSP Solutions DigiSTD - 0x0016 DSP Solutions DigiFIX - 0x0017 Dialogic OKI ADPCM - 0x0018 MediaVision ADPCM - 0x0019 Hewlett-Packard CU - 0x0020 Yamaha ADPCM - 0x0021 Speech Compression Sonarc - 0x0022 DSP Group TrueSpeech - 0x0023 Echo Speech EchoSC1 - 0x0024 Audiofile AF36 - 0x0025 Audio Processing Technology APTX - 0x0026 AudioFile AF10 - 0x0027 Prosody 1612 - 0x0028 LRC - 0x0030 Dolby AC2 - 0x0031 Microsoft GSM 6.10 - 0x0032 MSNAudio - 0x0033 Antex Electronics ADPCME - 0x0034 Control Resources VQLPC - 0x0035 DSP Solutions DigiREAL - 0x0036 DSP Solutions DigiADPCM - 0x0037 Control Resources CR10 - 0x0038 Natural MicroSystems VBXADPCM - 0x0039 Crystal Semiconductor IMA ADPCM - 0x003A EchoSC3 - 0x003B Rockwell ADPCM - 0x003C Rockwell Digit LK - 0x003D Xebec - 0x0040 Antex Electronics G.721 ADPCM - 0x0041 G.728 CELP - 0x0042 MSG723 - 0x0050 MPEG Layer-2 or Layer-1 - 0x0052 RT24 - 0x0053 PAC - 0x0055 MPEG Layer-3 - 0x0059 Lucent G.723 - 0x0060 Cirrus - 0x0061 ESPCM - 0x0062 Voxware - 0x0063 Canopus Atrac - 0x0064 G.726 ADPCM - 0x0065 G.722 ADPCM - 0x0066 DSAT - 0x0067 DSAT Display - 0x0069 Voxware Byte Aligned - 0x0070 Voxware AC8 - 0x0071 Voxware AC10 - 0x0072 Voxware AC16 - 0x0073 Voxware AC20 - 0x0074 Voxware MetaVoice - 0x0075 Voxware MetaSound - 0x0076 Voxware RT29HW - 0x0077 Voxware VR12 - 0x0078 Voxware VR18 - 0x0079 Voxware TQ40 - 0x0080 Softsound - 0x0081 Voxware TQ60 - 0x0082 MSRT24 - 0x0083 G.729A - 0x0084 MVI MV12 - 0x0085 DF G.726 - 0x0086 DF GSM610 - 0x0088 ISIAudio - 0x0089 Onlive - 0x0091 SBC24 - 0x0092 Dolby AC3 SPDIF - 0x0093 MediaSonic G.723 - 0x0094 Aculab PLC Prosody 8kbps - 0x0097 ZyXEL ADPCM - 0x0098 Philips LPCBB - 0x0099 Packed - 0x00FF AAC - 0x0100 Rhetorex ADPCM - 0x0101 IBM mu-law - 0x0102 IBM A-law - 0x0103 IBM AVC Adaptive Differential Pulse Code Modulation (ADPCM) - 0x0111 Vivo G.723 - 0x0112 Vivo Siren - 0x0123 Digital G.723 - 0x0125 Sanyo LD ADPCM - 0x0130 Sipro Lab Telecom ACELP NET - 0x0131 Sipro Lab Telecom ACELP 4800 - 0x0132 Sipro Lab Telecom ACELP 8V3 - 0x0133 Sipro Lab Telecom G.729 - 0x0134 Sipro Lab Telecom G.729A - 0x0135 Sipro Lab Telecom Kelvin - 0x0140 Windows Media Video V8 - 0x0150 Qualcomm PureVoice - 0x0151 Qualcomm HalfRate - 0x0155 Ring Zero Systems TUB GSM - 0x0160 Microsoft Audio 1 - 0x0161 Windows Media Audio V7 / V8 / V9 - 0x0162 Windows Media Audio Professional V9 - 0x0163 Windows Media Audio Lossless V9 - 0x0200 Creative Labs ADPCM - 0x0202 Creative Labs Fastspeech8 - 0x0203 Creative Labs Fastspeech10 - 0x0210 UHER Informatic GmbH ADPCM - 0x0220 Quarterdeck - 0x0230 I-link Worldwide VC - 0x0240 Aureal RAW Sport - 0x0250 Interactive Products HSX - 0x0251 Interactive Products RPELP - 0x0260 Consistent Software CS2 - 0x0270 Sony SCX - 0x0300 Fujitsu FM Towns Snd - 0x0400 BTV Digital - 0x0401 Intel Music Coder - 0x0450 QDesign Music - 0x0680 VME VMPCM - 0x0681 AT&T Labs TPC - 0x08AE ClearJump LiteWave - 0x1000 Olivetti GSM - 0x1001 Olivetti ADPCM - 0x1002 Olivetti CELP - 0x1003 Olivetti SBC - 0x1004 Olivetti OPR - 0x1100 Lernout & Hauspie Codec (0x1100) - 0x1101 Lernout & Hauspie CELP Codec (0x1101) - 0x1102 Lernout & Hauspie SBC Codec (0x1102) - 0x1103 Lernout & Hauspie SBC Codec (0x1103) - 0x1104 Lernout & Hauspie SBC Codec (0x1104) - 0x1400 Norris - 0x1401 AT&T ISIAudio - 0x1500 Soundspace Music Compression - 0x181C VoxWare RT24 Speech - 0x1FC4 NCT Soft ALF2CD (www.nctsoft.com) - 0x2000 Dolby AC3 - 0x2001 Dolby DTS - 0x2002 WAVE_FORMAT_14_4 - 0x2003 WAVE_FORMAT_28_8 - 0x2004 WAVE_FORMAT_COOK - 0x2005 WAVE_FORMAT_DNET - 0x674F Ogg Vorbis 1 - 0x6750 Ogg Vorbis 2 - 0x6751 Ogg Vorbis 3 - 0x676F Ogg Vorbis 1+ - 0x6770 Ogg Vorbis 2+ - 0x6771 Ogg Vorbis 3+ - 0x7A21 GSM-AMR (CBR, no SID) - 0x7A22 GSM-AMR (VBR, including SID) - 0xFFFE WAVE_FORMAT_EXTENSIBLE - 0xFFFF WAVE_FORMAT_DEVELOPMENT - - */ - - return getid3_lib::EmbeddedLookup('0x'.str_pad(strtoupper(dechex($wFormatTag)), 4, '0', STR_PAD_LEFT), $begin, __LINE__, __FILE__, 'riff-wFormatTag'); - - } - - - static function RIFFfourccLookup($fourcc) { - - $begin = __LINE__; - - /** This is not a comment! - - swot http://developer.apple.com/qa/snd/snd07.html - ____ No Codec (____) - _BIT BI_BITFIELDS (Raw RGB) - _JPG JPEG compressed - _PNG PNG compressed W3C/ISO/IEC (RFC-2083) - _RAW Full Frames (Uncompressed) - _RGB Raw RGB Bitmap - _RL4 RLE 4bpp RGB - _RL8 RLE 8bpp RGB - 3IV1 3ivx MPEG-4 v1 - 3IV2 3ivx MPEG-4 v2 - 3IVX 3ivx MPEG-4 - AASC Autodesk Animator - ABYR Kensington ?ABYR? - AEMI Array Microsystems VideoONE MPEG1-I Capture - AFLC Autodesk Animator FLC - AFLI Autodesk Animator FLI - AMPG Array Microsystems VideoONE MPEG - ANIM Intel RDX (ANIM) - AP41 AngelPotion Definitive - ASV1 Asus Video v1 - ASV2 Asus Video v2 - ASVX Asus Video 2.0 (audio) - AUR2 AuraVision Aura 2 Codec - YUV 4:2:2 - AURA AuraVision Aura 1 Codec - YUV 4:1:1 - AVDJ Independent JPEG Group\'s codec (AVDJ) - AVRN Independent JPEG Group\'s codec (AVRN) - AYUV 4:4:4 YUV (AYUV) - AZPR Quicktime Apple Video (AZPR) - BGR Raw RGB32 - BLZ0 Blizzard DivX MPEG-4 - BTVC Conexant Composite Video - BINK RAD Game Tools Bink Video - BT20 Conexant Prosumer Video - BTCV Conexant Composite Video Codec - BW10 Data Translation Broadway MPEG Capture - CC12 Intel YUV12 - CDVC Canopus DV - CFCC Digital Processing Systems DPS Perception - CGDI Microsoft Office 97 Camcorder Video - CHAM Winnov Caviara Champagne - CJPG Creative WebCam JPEG - CLJR Cirrus Logic YUV 4:1:1 - CMYK Common Data Format in Printing (Colorgraph) - CPLA Weitek 4:2:0 YUV Planar - CRAM Microsoft Video 1 (CRAM) - cvid Radius Cinepak - CVID Radius Cinepak - CWLT Microsoft Color WLT DIB - CYUV Creative Labs YUV - CYUY ATI YUV - D261 H.261 - D263 H.263 - DIB Device Independent Bitmap - DIV1 FFmpeg OpenDivX - DIV2 Microsoft MPEG-4 v1/v2 - DIV3 DivX ;-) MPEG-4 v3.x Low-Motion - DIV4 DivX ;-) MPEG-4 v3.x Fast-Motion - DIV5 DivX MPEG-4 v5.x - DIV6 DivX ;-) (MS MPEG-4 v3.x) - DIVX DivX MPEG-4 v4 (OpenDivX / Project Mayo) - divx DivX MPEG-4 - DMB1 Matrox Rainbow Runner hardware MJPEG - DMB2 Paradigm MJPEG - DSVD ?DSVD? - DUCK Duck TrueMotion 1.0 - DPS0 DPS/Leitch Reality Motion JPEG - DPSC DPS/Leitch PAR Motion JPEG - DV25 Matrox DVCPRO codec - DV50 Matrox DVCPRO50 codec - DVC IEC 61834 and SMPTE 314M (DVC/DV Video) - DVCP IEC 61834 and SMPTE 314M (DVC/DV Video) - DVHD IEC Standard DV 1125 lines @ 30fps / 1250 lines @ 25fps - DVMA Darim Vision DVMPEG (dummy for MPEG compressor) (www.darvision.com) - DVSL IEC Standard DV compressed in SD (SDL) - DVAN ?DVAN? - DVE2 InSoft DVE-2 Videoconferencing - dvsd IEC 61834 and SMPTE 314M DVC/DV Video - DVSD IEC 61834 and SMPTE 314M DVC/DV Video - DVX1 Lucent DVX1000SP Video Decoder - DVX2 Lucent DVX2000S Video Decoder - DVX3 Lucent DVX3000S Video Decoder - DX50 DivX v5 - DXT1 Microsoft DirectX Compressed Texture (DXT1) - DXT2 Microsoft DirectX Compressed Texture (DXT2) - DXT3 Microsoft DirectX Compressed Texture (DXT3) - DXT4 Microsoft DirectX Compressed Texture (DXT4) - DXT5 Microsoft DirectX Compressed Texture (DXT5) - DXTC Microsoft DirectX Compressed Texture (DXTC) - DXTn Microsoft DirectX Compressed Texture (DXTn) - EM2V Etymonix MPEG-2 I-frame (www.etymonix.com) - EKQ0 Elsa ?EKQ0? - ELK0 Elsa ?ELK0? - ESCP Eidos Escape - ETV1 eTreppid Video ETV1 - ETV2 eTreppid Video ETV2 - ETVC eTreppid Video ETVC - FLIC Autodesk FLI/FLC Animation - FRWT Darim Vision Forward Motion JPEG (www.darvision.com) - FRWU Darim Vision Forward Uncompressed (www.darvision.com) - FLJP D-Vision Field Encoded Motion JPEG - FRWA SoftLab-Nsk Forward Motion JPEG w/ alpha channel - FRWD SoftLab-Nsk Forward Motion JPEG - FVF1 Iterated Systems Fractal Video Frame - GLZW Motion LZW (gabest@freemail.hu) - GPEG Motion JPEG (gabest@freemail.hu) - GWLT Microsoft Greyscale WLT DIB - H260 Intel ITU H.260 Videoconferencing - H261 Intel ITU H.261 Videoconferencing - H262 Intel ITU H.262 Videoconferencing - H263 Intel ITU H.263 Videoconferencing - H264 Intel ITU H.264 Videoconferencing - H265 Intel ITU H.265 Videoconferencing - H266 Intel ITU H.266 Videoconferencing - H267 Intel ITU H.267 Videoconferencing - H268 Intel ITU H.268 Videoconferencing - H269 Intel ITU H.269 Videoconferencing - HFYU Huffman Lossless Codec - HMCR Rendition Motion Compensation Format (HMCR) - HMRR Rendition Motion Compensation Format (HMRR) - I263 FFmpeg I263 decoder - IF09 Indeo YVU9 ("YVU9 with additional delta-frame info after the U plane") - IUYV Interlaced version of UYVY (www.leadtools.com) - IY41 Interlaced version of Y41P (www.leadtools.com) - IYU1 12 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard - IYU2 24 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard - IYUV Planar YUV format (8-bpp Y plane, followed by 8-bpp 2×2 U and V planes) - i263 Intel ITU H.263 Videoconferencing (i263) - I420 Intel Indeo 4 - IAN Intel Indeo 4 (RDX) - ICLB InSoft CellB Videoconferencing - IGOR Power DVD - IJPG Intergraph JPEG - ILVC Intel Layered Video - ILVR ITU-T H.263+ - IPDV I-O Data Device Giga AVI DV Codec - IR21 Intel Indeo 2.1 - IRAW Intel YUV Uncompressed - IV30 Intel Indeo 3.0 - IV31 Intel Indeo 3.1 - IV32 Ligos Indeo 3.2 - IV33 Ligos Indeo 3.3 - IV34 Ligos Indeo 3.4 - IV35 Ligos Indeo 3.5 - IV36 Ligos Indeo 3.6 - IV37 Ligos Indeo 3.7 - IV38 Ligos Indeo 3.8 - IV39 Ligos Indeo 3.9 - IV40 Ligos Indeo Interactive 4.0 - IV41 Ligos Indeo Interactive 4.1 - IV42 Ligos Indeo Interactive 4.2 - IV43 Ligos Indeo Interactive 4.3 - IV44 Ligos Indeo Interactive 4.4 - IV45 Ligos Indeo Interactive 4.5 - IV46 Ligos Indeo Interactive 4.6 - IV47 Ligos Indeo Interactive 4.7 - IV48 Ligos Indeo Interactive 4.8 - IV49 Ligos Indeo Interactive 4.9 - IV50 Ligos Indeo Interactive 5.0 - JBYR Kensington ?JBYR? - JPEG Still Image JPEG DIB - JPGL Pegasus Lossless Motion JPEG - KMVC Team17 Software Karl Morton\'s Video Codec - LSVM Vianet Lighting Strike Vmail (Streaming) (www.vianet.com) - LEAD LEAD Video Codec - Ljpg LEAD MJPEG Codec - MDVD Alex MicroDVD Video (hacked MS MPEG-4) (www.tiasoft.de) - MJPA Morgan Motion JPEG (MJPA) (www.morgan-multimedia.com) - MJPB Morgan Motion JPEG (MJPB) (www.morgan-multimedia.com) - MMES Matrox MPEG-2 I-frame - MP2v Microsoft S-Mpeg 4 version 1 (MP2v) - MP42 Microsoft S-Mpeg 4 version 2 (MP42) - MP43 Microsoft S-Mpeg 4 version 3 (MP43) - MP4S Microsoft S-Mpeg 4 version 3 (MP4S) - MP4V FFmpeg MPEG-4 - MPG1 FFmpeg MPEG 1/2 - MPG2 FFmpeg MPEG 1/2 - MPG3 FFmpeg DivX ;-) (MS MPEG-4 v3) - MPG4 Microsoft MPEG-4 - MPGI Sigma Designs MPEG - MPNG PNG images decoder - MSS1 Microsoft Windows Screen Video - MSZH LCL (Lossless Codec Library) (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm) - M261 Microsoft H.261 - M263 Microsoft H.263 - M4S2 Microsoft Fully Compliant MPEG-4 v2 simple profile (M4S2) - m4s2 Microsoft Fully Compliant MPEG-4 v2 simple profile (m4s2) - MC12 ATI Motion Compensation Format (MC12) - MCAM ATI Motion Compensation Format (MCAM) - MJ2C Morgan Multimedia Motion JPEG2000 - mJPG IBM Motion JPEG w/ Huffman Tables - MJPG Microsoft Motion JPEG DIB - MP42 Microsoft MPEG-4 (low-motion) - MP43 Microsoft MPEG-4 (fast-motion) - MP4S Microsoft MPEG-4 (MP4S) - mp4s Microsoft MPEG-4 (mp4s) - MPEG Chromatic Research MPEG-1 Video I-Frame - MPG4 Microsoft MPEG-4 Video High Speed Compressor - MPGI Sigma Designs MPEG - MRCA FAST Multimedia Martin Regen Codec - MRLE Microsoft Run Length Encoding - MSVC Microsoft Video 1 - MTX1 Matrox ?MTX1? - MTX2 Matrox ?MTX2? - MTX3 Matrox ?MTX3? - MTX4 Matrox ?MTX4? - MTX5 Matrox ?MTX5? - MTX6 Matrox ?MTX6? - MTX7 Matrox ?MTX7? - MTX8 Matrox ?MTX8? - MTX9 Matrox ?MTX9? - MV12 Motion Pixels Codec (old) - MWV1 Aware Motion Wavelets - nAVI SMR Codec (hack of Microsoft MPEG-4) (IRC #shadowrealm) - NT00 NewTek LightWave HDTV YUV w/ Alpha (www.newtek.com) - NUV1 NuppelVideo - NTN1 Nogatech Video Compression 1 - NVS0 nVidia GeForce Texture (NVS0) - NVS1 nVidia GeForce Texture (NVS1) - NVS2 nVidia GeForce Texture (NVS2) - NVS3 nVidia GeForce Texture (NVS3) - NVS4 nVidia GeForce Texture (NVS4) - NVS5 nVidia GeForce Texture (NVS5) - NVT0 nVidia GeForce Texture (NVT0) - NVT1 nVidia GeForce Texture (NVT1) - NVT2 nVidia GeForce Texture (NVT2) - NVT3 nVidia GeForce Texture (NVT3) - NVT4 nVidia GeForce Texture (NVT4) - NVT5 nVidia GeForce Texture (NVT5) - PIXL MiroXL, Pinnacle PCTV - PDVC I-O Data Device Digital Video Capture DV codec - PGVV Radius Video Vision - PHMO IBM Photomotion - PIM1 MPEG Realtime (Pinnacle Cards) - PIM2 Pegasus Imaging ?PIM2? - PIMJ Pegasus Imaging Lossless JPEG - PVEZ Horizons Technology PowerEZ - PVMM PacketVideo Corporation MPEG-4 - PVW2 Pegasus Imaging Wavelet Compression - Q1.0 Q-Team\'s QPEG 1.0 (www.q-team.de) - Q1.1 Q-Team\'s QPEG 1.1 (www.q-team.de) - QPEG Q-Team QPEG 1.0 - qpeq Q-Team QPEG 1.1 - RGB Raw BGR32 - RGBA Raw RGB w/ Alpha - RMP4 REALmagic MPEG-4 (unauthorized XVID copy) (www.sigmadesigns.com) - ROQV Id RoQ File Video Decoder - RPZA Quicktime Apple Video (RPZA) - RUD0 Rududu video codec (http://rududu.ifrance.com/rududu/) - RV10 RealVideo 1.0 (aka RealVideo 5.0) - RV13 RealVideo 1.0 (RV13) - RV20 RealVideo G2 - RV30 RealVideo 8 - RV40 RealVideo 9 - RGBT Raw RGB w/ Transparency - RLE Microsoft Run Length Encoder - RLE4 Run Length Encoded (4bpp, 16-color) - RLE8 Run Length Encoded (8bpp, 256-color) - RT21 Intel Indeo RealTime Video 2.1 - rv20 RealVideo G2 - rv30 RealVideo 8 - RVX Intel RDX (RVX ) - SMC Apple Graphics (SMC ) - SP54 Logitech Sunplus Sp54 Codec for Mustek GSmart Mini 2 - SPIG Radius Spigot - SVQ3 Sorenson Video 3 (Apple Quicktime 5) - s422 Tekram VideoCap C210 YUV 4:2:2 - SDCC Sun Communication Digital Camera Codec - SFMC CrystalNet Surface Fitting Method - SMSC Radius SMSC - SMSD Radius SMSD - smsv WorldConnect Wavelet Video - SPIG Radius Spigot - SPLC Splash Studios ACM Audio Codec (www.splashstudios.net) - SQZ2 Microsoft VXTreme Video Codec V2 - STVA ST Microelectronics CMOS Imager Data (Bayer) - STVB ST Microelectronics CMOS Imager Data (Nudged Bayer) - STVC ST Microelectronics CMOS Imager Data (Bunched) - STVX ST Microelectronics CMOS Imager Data (Extended CODEC Data Format) - STVY ST Microelectronics CMOS Imager Data (Extended CODEC Data Format with Correction Data) - SV10 Sorenson Video R1 - SVQ1 Sorenson Video - T420 Toshiba YUV 4:2:0 - TM2A Duck TrueMotion Archiver 2.0 (www.duck.com) - TVJP Pinnacle/Truevision Targa 2000 board (TVJP) - TVMJ Pinnacle/Truevision Targa 2000 board (TVMJ) - TY0N Tecomac Low-Bit Rate Codec (www.tecomac.com) - TY2C Trident Decompression Driver - TLMS TeraLogic Motion Intraframe Codec (TLMS) - TLST TeraLogic Motion Intraframe Codec (TLST) - TM20 Duck TrueMotion 2.0 - TM2X Duck TrueMotion 2X - TMIC TeraLogic Motion Intraframe Codec (TMIC) - TMOT Horizons Technology TrueMotion S - tmot Horizons TrueMotion Video Compression - TR20 Duck TrueMotion RealTime 2.0 - TSCC TechSmith Screen Capture Codec - TV10 Tecomac Low-Bit Rate Codec - TY2N Trident ?TY2N? - U263 UB Video H.263/H.263+/H.263++ Decoder - UMP4 UB Video MPEG 4 (www.ubvideo.com) - UYNV Nvidia UYVY packed 4:2:2 - UYVP Evans & Sutherland YCbCr 4:2:2 extended precision - UCOD eMajix.com ClearVideo - ULTI IBM Ultimotion - UYVY UYVY packed 4:2:2 - V261 Lucent VX2000S - VIFP VFAPI Reader Codec (www.yks.ne.jp/~hori/) - VIV1 FFmpeg H263+ decoder - VIV2 Vivo H.263 - VQC2 Vector-quantised codec 2 (research) http://eprints.ecs.soton.ac.uk/archive/00001310/01/VTC97-js.pdf) - VTLP Alaris VideoGramPiX - VYU9 ATI YUV (VYU9) - VYUY ATI YUV (VYUY) - V261 Lucent VX2000S - V422 Vitec Multimedia 24-bit YUV 4:2:2 Format - V655 Vitec Multimedia 16-bit YUV 4:2:2 Format - VCR1 ATI Video Codec 1 - VCR2 ATI Video Codec 2 - VCR3 ATI VCR 3.0 - VCR4 ATI VCR 4.0 - VCR5 ATI VCR 5.0 - VCR6 ATI VCR 6.0 - VCR7 ATI VCR 7.0 - VCR8 ATI VCR 8.0 - VCR9 ATI VCR 9.0 - VDCT Vitec Multimedia Video Maker Pro DIB - VDOM VDOnet VDOWave - VDOW VDOnet VDOLive (H.263) - VDTZ Darim Vison VideoTizer YUV - VGPX Alaris VideoGramPiX - VIDS Vitec Multimedia YUV 4:2:2 CCIR 601 for V422 - VIVO Vivo H.263 v2.00 - vivo Vivo H.263 - VIXL Miro/Pinnacle Video XL - VLV1 VideoLogic/PURE Digital Videologic Capture - VP30 On2 VP3.0 - VP31 On2 VP3.1 - VX1K Lucent VX1000S Video Codec - VX2K Lucent VX2000S Video Codec - VXSP Lucent VX1000SP Video Codec - WBVC Winbond W9960 - WHAM Microsoft Video 1 (WHAM) - WINX Winnov Software Compression - WJPG AverMedia Winbond JPEG - WMV1 Windows Media Video V7 - WMV2 Windows Media Video V8 - WMV3 Windows Media Video V9 - WNV1 Winnov Hardware Compression - XYZP Extended PAL format XYZ palette (www.riff.org) - x263 Xirlink H.263 - XLV0 NetXL Video Decoder - XMPG Xing MPEG (I-Frame only) - XVID XviD MPEG-4 (www.xvid.org) - XXAN ?XXAN? - YU92 Intel YUV (YU92) - YUNV Nvidia Uncompressed YUV 4:2:2 - YUVP Extended PAL format YUV palette (www.riff.org) - Y211 YUV 2:1:1 Packed - Y411 YUV 4:1:1 Packed - Y41B Weitek YUV 4:1:1 Planar - Y41P Brooktree PC1 YUV 4:1:1 Packed - Y41T Brooktree PC1 YUV 4:1:1 with transparency - Y42B Weitek YUV 4:2:2 Planar - Y42T Brooktree UYUV 4:2:2 with transparency - Y422 ADS Technologies Copy of UYVY used in Pyro WebCam firewire camera - Y800 Simple, single Y plane for monochrome images - Y8 Grayscale video - YC12 Intel YUV 12 codec - YUV8 Winnov Caviar YUV8 - YUV9 Intel YUV9 - YUY2 Uncompressed YUV 4:2:2 - YUYV Canopus YUV - YV12 YVU12 Planar - YVU9 Intel YVU9 Planar (8-bpp Y plane, followed by 8-bpp 4x4 U and V planes) - YVYU YVYU 4:2:2 Packed - ZLIB Lossless Codec Library zlib compression (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm) - ZPEG Metheus Video Zipper - - */ - - return getid3_lib::EmbeddedLookup($fourcc, $begin, __LINE__, __FILE__, 'riff-fourcc'); - } - - - static function EitherEndian2Int(&$ThisFileInfo, $byteword, $signed=false) { - if ($ThisFileInfo['fileformat'] == 'riff') { - return getid3_lib::LittleEndian2Int($byteword, $signed); - } - return getid3_lib::BigEndian2Int($byteword, false, $signed); - } - -} - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio-video.swf.php b/serendipity_event_podcast/player/getid3/module.audio-video.swf.php deleted file mode 100644 index 43b8641f..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio-video.swf.php +++ /dev/null @@ -1,150 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio-video.swf.php // -// module for analyzing Shockwave Flash files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_swf -{ - - function getid3_swf(&$fd, &$ThisFileInfo, $ReturnAllTagData=false) { -//$start_time = microtime(true); - $ThisFileInfo['fileformat'] = 'swf'; - $ThisFileInfo['video']['dataformat'] = 'swf'; - - // http://www.openswf.org/spec/SWFfileformat.html - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - - $SWFfileData = fread($fd, $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']); // 8 + 2 + 2 + max(9) bytes NOT including Frame_Size RECT data - - $ThisFileInfo['swf']['header']['signature'] = substr($SWFfileData, 0, 3); - switch ($ThisFileInfo['swf']['header']['signature']) { - case 'FWS': - $ThisFileInfo['swf']['header']['compressed'] = false; - break; - - case 'CWS': - $ThisFileInfo['swf']['header']['compressed'] = true; - break; - - default: - $ThisFileInfo['error'][] = 'Expecting "FWS" or "CWS" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['swf']['header']['signature'].'"'; - unset($ThisFileInfo['swf']); - unset($ThisFileInfo['fileformat']); - return false; - break; - } - $ThisFileInfo['swf']['header']['version'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 3, 1)); - $ThisFileInfo['swf']['header']['length'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 4, 4)); - - if ($ThisFileInfo['swf']['header']['compressed']) { - - $SWFHead = substr($SWFfileData, 0, 8); - $SWFfileData = substr($SWFfileData, 8); - ob_start(); - if ($decompressed = gzuncompress($SWFfileData)) { - - ob_end_clean(); - $SWFfileData = $SWFHead.$decompressed; - - } else { - - $errormessage = ob_get_contents(); - ob_end_clean(); - $ThisFileInfo['error'][] = 'Error decompressing compressed SWF data ('.strlen($SWFfileData).' bytes compressed, should be '.($ThisFileInfo['swf']['header']['length'] - 8).' bytes uncompressed)'; - return false; - - } - - } - - $FrameSizeBitsPerValue = (ord(substr($SWFfileData, 8, 1)) & 0xF8) >> 3; - $FrameSizeDataLength = ceil((5 + (4 * $FrameSizeBitsPerValue)) / 8); - $FrameSizeDataString = str_pad(decbin(ord(substr($SWFfileData, 8, 1)) & 0x07), 3, '0', STR_PAD_LEFT); - for ($i = 1; $i < $FrameSizeDataLength; $i++) { - $FrameSizeDataString .= str_pad(decbin(ord(substr($SWFfileData, 8 + $i, 1))), 8, '0', STR_PAD_LEFT); - } - list($X1, $X2, $Y1, $Y2) = explode("\n", wordwrap($FrameSizeDataString, $FrameSizeBitsPerValue, "\n", 1)); - $ThisFileInfo['swf']['header']['frame_width'] = getid3_lib::Bin2Dec($X2); - $ThisFileInfo['swf']['header']['frame_height'] = getid3_lib::Bin2Dec($Y2); - - // http://www-lehre.informatik.uni-osnabrueck.de/~fbstark/diplom/docs/swf/Flash_Uncovered.htm - // Next in the header is the frame rate, which is kind of weird. - // It is supposed to be stored as a 16bit integer, but the first byte - // (or last depending on how you look at it) is completely ignored. - // Example: 0x000C -> 0x0C -> 12 So the frame rate is 12 fps. - - // Byte at (8 + $FrameSizeDataLength) is always zero and ignored - $ThisFileInfo['swf']['header']['frame_rate'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 9 + $FrameSizeDataLength, 1)); - $ThisFileInfo['swf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 10 + $FrameSizeDataLength, 2)); - - $ThisFileInfo['video']['frame_rate'] = $ThisFileInfo['swf']['header']['frame_rate']; - $ThisFileInfo['video']['resolution_x'] = intval(round($ThisFileInfo['swf']['header']['frame_width'] / 20)); - $ThisFileInfo['video']['resolution_y'] = intval(round($ThisFileInfo['swf']['header']['frame_height'] / 20)); - $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1; - - if (($ThisFileInfo['swf']['header']['frame_count'] > 0) && ($ThisFileInfo['swf']['header']['frame_rate'] > 0)) { - $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['swf']['header']['frame_count'] / $ThisFileInfo['swf']['header']['frame_rate']; - } -//echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'
'; - - - // SWF tags - - $CurrentOffset = 12 + $FrameSizeDataLength; - $SWFdataLength = strlen($SWFfileData); - - while ($CurrentOffset < $SWFdataLength) { -//echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'
'; - - $TagIDTagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 2)); - $TagID = ($TagIDTagLength & 0xFFFC) >> 6; - $TagLength = ($TagIDTagLength & 0x003F); - $CurrentOffset += 2; - if ($TagLength == 0x3F) { - $TagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 4)); - $CurrentOffset += 4; - } - - unset($TagData); - $TagData['offset'] = $CurrentOffset; - $TagData['size'] = $TagLength; - $TagData['id'] = $TagID; - $TagData['data'] = substr($SWFfileData, $CurrentOffset, $TagLength); - switch ($TagID) { - case 0: // end of movie - break 2; - - case 9: // Set background color - //$ThisFileInfo['swf']['tags'][] = $TagData; - $ThisFileInfo['swf']['bgcolor'] = strtoupper(str_pad(dechex(getid3_lib::BigEndian2Int($TagData['data'])), 6, '0', STR_PAD_LEFT)); - break; - - default: - if ($ReturnAllTagData) { - $ThisFileInfo['swf']['tags'][] = $TagData; - } - break; - } - - $CurrentOffset += $TagLength; - } - - return true; - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.aa.php b/serendipity_event_podcast/player/getid3/module.audio.aa.php deleted file mode 100644 index 77ed4839..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.aa.php +++ /dev/null @@ -1,58 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.aa.php // -// module for analyzing Audible Audiobook files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_aa -{ - - function getid3_aa(&$fd, &$ThisFileInfo) { - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $AAheader = fread($fd, 8); - - $magic = "\x57\x90\x75\x36"; - if (substr($AAheader, 4, 4) != $magic) { - $ThisFileInfo['error'][] = 'Expecting "'.PrintHexBytes($magic).'" at offset '.$ThisFileInfo['avdataoffset'].', found "'.PrintHexBytes(substr($AAheader, 4, 4)).'"'; - return false; - } - - // shortcut - $ThisFileInfo['aa'] = array(); - $thisfile_au = &$ThisFileInfo['aa']; - - $ThisFileInfo['fileformat'] = 'aa'; - $ThisFileInfo['audio']['dataformat'] = 'aa'; - $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; // is it? - $thisfile_au['encoding'] = 'ISO-8859-1'; - - $thisfile_au['filesize'] = getid3_lib::BigEndian2Int(substr($AUheader, 0, 4)); - if ($thisfile_au['filesize'] > ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'])) { - $ThisFileInfo['warning'][] = 'Possible truncated file - expecting "'.$thisfile_au['filesize'].'" bytes of data, only found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' bytes"'; - } - - $ThisFileInfo['audio']['bits_per_sample'] = 16; // is it? - $ThisFileInfo['audio']['sample_rate'] = $thisfile_au['sample_rate']; - $ThisFileInfo['audio']['channels'] = $thisfile_au['channels']; - - //$ThisFileInfo['playtime_seconds'] = 0; - //$ThisFileInfo['audio']['bitrate'] = 0; - - return true; - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.aac.php b/serendipity_event_podcast/player/getid3/module.audio.aac.php deleted file mode 100644 index 269e4215..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.aac.php +++ /dev/null @@ -1,541 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.aac.php // -// module for analyzing AAC Audio files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_aac -{ - - // new combined constructor - function getid3_aac(&$fd, &$ThisFileInfo, $option) { - if ($option === 'adif') { - $this->getAACADIFheaderFilepointer($fd, $ThisFileInfo); - } elseif ($option === 'adts') { - $this->getAACADTSheaderFilepointer($fd, $ThisFileInfo); - } - return true; - } - - - - function getAACADIFheaderFilepointer(&$fd, &$ThisFileInfo) { - $ThisFileInfo['fileformat'] = 'aac'; - $ThisFileInfo['audio']['dataformat'] = 'aac'; - $ThisFileInfo['audio']['lossless'] = false; - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $AACheader = fread($fd, 1024); - $offset = 0; - - if (substr($AACheader, 0, 4) == 'ADIF') { - - // http://faac.sourceforge.net/wiki/index.php?page=ADIF - - // http://libmpeg.org/mpeg4/doc/w2203tfs.pdf - // adif_header() { - // adif_id 32 - // copyright_id_present 1 - // if( copyright_id_present ) - // copyright_id 72 - // original_copy 1 - // home 1 - // bitstream_type 1 - // bitrate 23 - // num_program_config_elements 4 - // for (i = 0; i < num_program_config_elements + 1; i++ ) { - // if( bitstream_type == '0' ) - // adif_buffer_fullness 20 - // program_config_element() - // } - // } - - $AACheaderBitstream = getid3_lib::BigEndian2Bin($AACheader); - $bitoffset = 0; - - $ThisFileInfo['aac']['header_type'] = 'ADIF'; - $bitoffset += 32; - $ThisFileInfo['aac']['header']['mpeg_version'] = 4; - - $ThisFileInfo['aac']['header']['copyright'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1'); - $bitoffset += 1; - if ($ThisFileInfo['aac']['header']['copyright']) { - $ThisFileInfo['aac']['header']['copyright_id'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 72)); - $bitoffset += 72; - } - $ThisFileInfo['aac']['header']['original_copy'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1'); - $bitoffset += 1; - $ThisFileInfo['aac']['header']['home'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1'); - $bitoffset += 1; - $ThisFileInfo['aac']['header']['is_vbr'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) == '1'); - $bitoffset += 1; - if ($ThisFileInfo['aac']['header']['is_vbr']) { - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; - $ThisFileInfo['aac']['header']['bitrate_max'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23)); - $bitoffset += 23; - } else { - $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; - $ThisFileInfo['aac']['header']['bitrate'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23)); - $bitoffset += 23; - $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['aac']['header']['bitrate']; - } - if ($ThisFileInfo['audio']['bitrate'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt AAC file: bitrate_audio == zero'; - return false; - } - $ThisFileInfo['aac']['header']['num_program_configs'] = 1 + getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - - for ($i = 0; $i < $ThisFileInfo['aac']['header']['num_program_configs']; $i++) { - // http://www.audiocoding.com/wiki/index.php?page=program_config_element - - // buffer_fullness 20 - - // element_instance_tag 4 - // object_type 2 - // sampling_frequency_index 4 - // num_front_channel_elements 4 - // num_side_channel_elements 4 - // num_back_channel_elements 4 - // num_lfe_channel_elements 2 - // num_assoc_data_elements 3 - // num_valid_cc_elements 4 - // mono_mixdown_present 1 - // mono_mixdown_element_number 4 if mono_mixdown_present == 1 - // stereo_mixdown_present 1 - // stereo_mixdown_element_number 4 if stereo_mixdown_present == 1 - // matrix_mixdown_idx_present 1 - // matrix_mixdown_idx 2 if matrix_mixdown_idx_present == 1 - // pseudo_surround_enable 1 if matrix_mixdown_idx_present == 1 - // for (i = 0; i < num_front_channel_elements; i++) { - // front_element_is_cpe[i] 1 - // front_element_tag_select[i] 4 - // } - // for (i = 0; i < num_side_channel_elements; i++) { - // side_element_is_cpe[i] 1 - // side_element_tag_select[i] 4 - // } - // for (i = 0; i < num_back_channel_elements; i++) { - // back_element_is_cpe[i] 1 - // back_element_tag_select[i] 4 - // } - // for (i = 0; i < num_lfe_channel_elements; i++) { - // lfe_element_tag_select[i] 4 - // } - // for (i = 0; i < num_assoc_data_elements; i++) { - // assoc_data_element_tag_select[i] 4 - // } - // for (i = 0; i < num_valid_cc_elements; i++) { - // cc_element_is_ind_sw[i] 1 - // valid_cc_element_tag_select[i] 4 - // } - // byte_alignment() VAR - // comment_field_bytes 8 - // for (i = 0; i < comment_field_bytes; i++) { - // comment_field_data[i] 8 - // } - - if (!$ThisFileInfo['aac']['header']['is_vbr']) { - $ThisFileInfo['aac']['program_configs'][$i]['buffer_fullness'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 20)); - $bitoffset += 20; - } - $ThisFileInfo['aac']['program_configs'][$i]['element_instance_tag'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - $ThisFileInfo['aac']['program_configs'][$i]['object_type'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); - $bitoffset += 2; - $ThisFileInfo['aac']['program_configs'][$i]['sampling_frequency_index'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - $ThisFileInfo['aac']['program_configs'][$i]['num_front_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - $ThisFileInfo['aac']['program_configs'][$i]['num_side_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - $ThisFileInfo['aac']['program_configs'][$i]['num_back_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - $ThisFileInfo['aac']['program_configs'][$i]['num_lfe_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); - $bitoffset += 2; - $ThisFileInfo['aac']['program_configs'][$i]['num_assoc_data_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 3)); - $bitoffset += 3; - $ThisFileInfo['aac']['program_configs'][$i]['num_valid_cc_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - $ThisFileInfo['aac']['program_configs'][$i]['mono_mixdown_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - if ($ThisFileInfo['aac']['program_configs'][$i]['mono_mixdown_present']) { - $ThisFileInfo['aac']['program_configs'][$i]['mono_mixdown_element_number'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - $ThisFileInfo['aac']['program_configs'][$i]['stereo_mixdown_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - if ($ThisFileInfo['aac']['program_configs'][$i]['stereo_mixdown_present']) { - $ThisFileInfo['aac']['program_configs'][$i]['stereo_mixdown_element_number'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - $ThisFileInfo['aac']['program_configs'][$i]['matrix_mixdown_idx_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - if ($ThisFileInfo['aac']['program_configs'][$i]['matrix_mixdown_idx_present']) { - $ThisFileInfo['aac']['program_configs'][$i]['matrix_mixdown_idx'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); - $bitoffset += 2; - $ThisFileInfo['aac']['program_configs'][$i]['pseudo_surround_enable'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - } - for ($j = 0; $j < $ThisFileInfo['aac']['program_configs'][$i]['num_front_channel_elements']; $j++) { - $ThisFileInfo['aac']['program_configs'][$i]['front_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - $ThisFileInfo['aac']['program_configs'][$i]['front_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - for ($j = 0; $j < $ThisFileInfo['aac']['program_configs'][$i]['num_side_channel_elements']; $j++) { - $ThisFileInfo['aac']['program_configs'][$i]['side_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - $ThisFileInfo['aac']['program_configs'][$i]['side_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - for ($j = 0; $j < $ThisFileInfo['aac']['program_configs'][$i]['num_back_channel_elements']; $j++) { - $ThisFileInfo['aac']['program_configs'][$i]['back_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - $ThisFileInfo['aac']['program_configs'][$i]['back_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - for ($j = 0; $j < $ThisFileInfo['aac']['program_configs'][$i]['num_lfe_channel_elements']; $j++) { - $ThisFileInfo['aac']['program_configs'][$i]['lfe_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - for ($j = 0; $j < $ThisFileInfo['aac']['program_configs'][$i]['num_assoc_data_elements']; $j++) { - $ThisFileInfo['aac']['program_configs'][$i]['assoc_data_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - for ($j = 0; $j < $ThisFileInfo['aac']['program_configs'][$i]['num_valid_cc_elements']; $j++) { - $ThisFileInfo['aac']['program_configs'][$i]['cc_element_is_ind_sw'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - $ThisFileInfo['aac']['program_configs'][$i]['valid_cc_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - } - - $bitoffset = ceil($bitoffset / 8) * 8; - - $ThisFileInfo['aac']['program_configs'][$i]['comment_field_bytes'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 8)); - $bitoffset += 8; - $ThisFileInfo['aac']['program_configs'][$i]['comment_field'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 8 * $ThisFileInfo['aac']['program_configs'][$i]['comment_field_bytes'])); - $bitoffset += 8 * $ThisFileInfo['aac']['program_configs'][$i]['comment_field_bytes']; - - - $ThisFileInfo['aac']['header']['profile_text'] = $this->AACprofileLookup($ThisFileInfo['aac']['program_configs'][$i]['object_type'], $ThisFileInfo['aac']['header']['mpeg_version']); - $ThisFileInfo['aac']['program_configs'][$i]['sampling_frequency'] = $this->AACsampleRateLookup($ThisFileInfo['aac']['program_configs'][$i]['sampling_frequency_index']); - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['aac']['program_configs'][$i]['sampling_frequency']; - $ThisFileInfo['audio']['channels'] = $this->AACchannelCountCalculate($ThisFileInfo['aac']['program_configs'][$i]); - if ($ThisFileInfo['aac']['program_configs'][$i]['comment_field']) { - $ThisFileInfo['aac']['comments'][] = $ThisFileInfo['aac']['program_configs'][$i]['comment_field']; - } - } - $ThisFileInfo['playtime_seconds'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['audio']['bitrate']; - - $ThisFileInfo['audio']['encoder_options'] = $ThisFileInfo['aac']['header_type'].' '.$ThisFileInfo['aac']['header']['profile_text']; - - - - return true; - - } else { - - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['aac']); - $ThisFileInfo['error'][] = 'AAC-ADIF synch not found at offset '.$ThisFileInfo['avdataoffset'].' (expected "ADIF", found "'.substr($AACheader, 0, 4).'" instead)'; - return false; - - } - - } - - - function getAACADTSheaderFilepointer(&$fd, &$ThisFileInfo, $MaxFramesToScan=1000000, $ReturnExtendedInfo=false) { - // based loosely on code from AACfile by Jurgen Faul - // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html - - - // http://faac.sourceforge.net/wiki/index.php?page=ADTS - - // * ADTS Fixed Header: these don't change from frame to frame - // syncword 12 always: '111111111111' - // ID 1 0: MPEG-4, 1: MPEG-2 - // layer 2 always: '00' - // protection_absent 1 - // profile 2 - // sampling_frequency_index 4 - // private_bit 1 - // channel_configuration 3 - // original/copy 1 - // home 1 - // emphasis 2 only if ID == 0 (ie MPEG-4) - - // * ADTS Variable Header: these can change from frame to frame - // copyright_identification_bit 1 - // copyright_identification_start 1 - // aac_frame_length 13 length of the frame including header (in bytes) - // adts_buffer_fullness 11 0x7FF indicates VBR - // no_raw_data_blocks_in_frame 2 - - // * ADTS Error check - // crc_check 16 only if protection_absent == 0 - - $byteoffset = 0; - $framenumber = 0; - - // Init bit pattern array - static $decbin = array(); - - // Populate $bindec - for ($i = 0; $i < 256; $i++) { - $decbin[chr($i)] = str_pad(decbin($i), 8, '0', STR_PAD_LEFT); - } - - // used to calculate bitrate below - $BitrateCache = array(); - - - while (true) { - // breaks out when end-of-file encountered, or invalid data found, - // or MaxFramesToScan frames have been scanned - - if (!getid3_lib::intValueSupported($byteoffset)) { - $ThisFileInfo['warning'][] = 'Unable to parse AAC file beyond '.ftell($fd).' (PHP does not support file operations beyond '.round(PHP_INT_MAX / 1073741824).'GB)'; - return false; - } - fseek($fd, $byteoffset, SEEK_SET); - - // First get substring - $substring = fread($fd, 10); - $substringlength = strlen($substring); - if ($substringlength != 10) { - $ThisFileInfo['error'][] = 'Failed to read 10 bytes at offset '.(ftell($fd) - $substringlength).' (only read '.$substringlength.' bytes)'; - return false; - } - - // Initialise $AACheaderBitstream - $AACheaderBitstream = ''; - - // Loop thru substring chars - for ($i = 0; $i < 10; $i++) { - $AACheaderBitstream .= $decbin[$substring{$i}]; - } - - $bitoffset = 0; - - $synctest = bindec(substr($AACheaderBitstream, $bitoffset, 12)); - - $bitoffset += 12; - if ($synctest != 0x0FFF) { - $ThisFileInfo['error'][] = 'Synch pattern (0x0FFF) not found at offset '.(ftell($fd) - 10).' (found 0x0'.strtoupper(dechex($synctest)).' instead)'; - if ($ThisFileInfo['fileformat'] == 'aac') { - return true; - } - return false; - } - - // Gather info for first frame only - this takes time to do 1000 times! - if ($framenumber > 0) { - - if (!$AACheaderBitstream[$bitoffset]) { - - // MPEG-4 - $bitoffset += 20; - - } else { - - // MPEG-2 - $bitoffset += 18; - - } - - } else { - - $ThisFileInfo['aac']['header_type'] = 'ADTS'; - $ThisFileInfo['aac']['header']['synch'] = $synctest; - $ThisFileInfo['fileformat'] = 'aac'; - $ThisFileInfo['audio']['dataformat'] = 'aac'; - - $ThisFileInfo['aac']['header']['mpeg_version'] = ((substr($AACheaderBitstream, $bitoffset, 1) == '0') ? 4 : 2); - $bitoffset += 1; - $ThisFileInfo['aac']['header']['layer'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); - $bitoffset += 2; - if ($ThisFileInfo['aac']['header']['layer'] != 0) { - $ThisFileInfo['error'][] = 'Layer error - expected 0x00, found 0x'.dechex($ThisFileInfo['aac']['header']['layer']).' instead'; - return false; - } - $ThisFileInfo['aac']['header']['crc_present'] = ((substr($AACheaderBitstream, $bitoffset, 1) == '0') ? true : false); - $bitoffset += 1; - $ThisFileInfo['aac']['header']['profile_id'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); - $bitoffset += 2; - $ThisFileInfo['aac']['header']['profile_text'] = $this->AACprofileLookup($ThisFileInfo['aac']['header']['profile_id'], $ThisFileInfo['aac']['header']['mpeg_version']); - - $ThisFileInfo['aac']['header']['sample_frequency_index'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); - $bitoffset += 4; - $ThisFileInfo['aac']['header']['sample_frequency'] = $this->AACsampleRateLookup($ThisFileInfo['aac']['header']['sample_frequency_index']); - if ($ThisFileInfo['aac']['header']['sample_frequency'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt AAC file: sample_frequency == zero'; - return false; - } - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['aac']['header']['sample_frequency']; - - $ThisFileInfo['aac']['header']['private'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - $ThisFileInfo['aac']['header']['channel_configuration'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 3)); - $bitoffset += 3; - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['aac']['header']['channel_configuration']; - $ThisFileInfo['aac']['header']['original'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - $ThisFileInfo['aac']['header']['home'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - - if ($ThisFileInfo['aac']['header']['mpeg_version'] == 4) { - $ThisFileInfo['aac']['header']['emphasis'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); - $bitoffset += 2; - } - - if ($ReturnExtendedInfo) { - - $ThisFileInfo['aac'][$framenumber]['copyright_id_bit'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - $ThisFileInfo['aac'][$framenumber]['copyright_id_start'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); - $bitoffset += 1; - - } else { - - $bitoffset += 2; - - } - - } - - $FrameLength = bindec(substr($AACheaderBitstream, $bitoffset, 13)); - - if (!isset($BitrateCache[$FrameLength])) { - $BitrateCache[$FrameLength] = ($ThisFileInfo['aac']['header']['sample_frequency'] / 1024) * $FrameLength * 8; - } - getid3_lib::safe_inc($ThisFileInfo['aac']['bitrate_distribution'][$BitrateCache[$FrameLength]], 1); - - $ThisFileInfo['aac'][$framenumber]['aac_frame_length'] = $FrameLength; - $bitoffset += 13; - $ThisFileInfo['aac'][$framenumber]['adts_buffer_fullness'] = bindec(substr($AACheaderBitstream, $bitoffset, 11)); - $bitoffset += 11; - if ($ThisFileInfo['aac'][$framenumber]['adts_buffer_fullness'] == 0x07FF) { - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; - } else { - $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; - } - $ThisFileInfo['aac'][$framenumber]['num_raw_data_blocks'] = bindec(substr($AACheaderBitstream, $bitoffset, 2)); - $bitoffset += 2; - - if ($ThisFileInfo['aac']['header']['crc_present']) { - //$ThisFileInfo['aac'][$framenumber]['crc'] = bindec(substr($AACheaderBitstream, $bitoffset, 16)); - $bitoffset += 16; - } - - if (!$ReturnExtendedInfo) { - unset($ThisFileInfo['aac'][$framenumber]); - } - - $byteoffset += $FrameLength; - if ((++$framenumber < $MaxFramesToScan) && (($byteoffset + 10) < $ThisFileInfo['avdataend'])) { - - // keep scanning - - } else { - - $ThisFileInfo['aac']['frames'] = $framenumber; - $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] / $byteoffset) * (($framenumber * 1024) / $ThisFileInfo['aac']['header']['sample_frequency']); // (1 / % of file scanned) * (samples / (samples/sec)) = seconds - if ($ThisFileInfo['playtime_seconds'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt AAC file: playtime_seconds == zero'; - return false; - } - $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; - ksort($ThisFileInfo['aac']['bitrate_distribution']); - - $ThisFileInfo['audio']['encoder_options'] = $ThisFileInfo['aac']['header_type'].' '.$ThisFileInfo['aac']['header']['profile_text']; - - return true; - - } - } - // should never get here. - } - - function AACsampleRateLookup($samplerateid) { - static $AACsampleRateLookup = array(); - if (empty($AACsampleRateLookup)) { - $AACsampleRateLookup[0] = 96000; - $AACsampleRateLookup[1] = 88200; - $AACsampleRateLookup[2] = 64000; - $AACsampleRateLookup[3] = 48000; - $AACsampleRateLookup[4] = 44100; - $AACsampleRateLookup[5] = 32000; - $AACsampleRateLookup[6] = 24000; - $AACsampleRateLookup[7] = 22050; - $AACsampleRateLookup[8] = 16000; - $AACsampleRateLookup[9] = 12000; - $AACsampleRateLookup[10] = 11025; - $AACsampleRateLookup[11] = 8000; - $AACsampleRateLookup[12] = 0; - $AACsampleRateLookup[13] = 0; - $AACsampleRateLookup[14] = 0; - $AACsampleRateLookup[15] = 0; - } - return (isset($AACsampleRateLookup[$samplerateid]) ? $AACsampleRateLookup[$samplerateid] : 'invalid'); - } - - function AACprofileLookup($profileid, $mpegversion) { - static $AACprofileLookup = array(); - if (empty($AACprofileLookup)) { - $AACprofileLookup[2][0] = 'Main profile'; - $AACprofileLookup[2][1] = 'Low Complexity profile (LC)'; - $AACprofileLookup[2][2] = 'Scalable Sample Rate profile (SSR)'; - $AACprofileLookup[2][3] = '(reserved)'; - $AACprofileLookup[4][0] = 'AAC_MAIN'; - $AACprofileLookup[4][1] = 'AAC_LC'; - $AACprofileLookup[4][2] = 'AAC_SSR'; - $AACprofileLookup[4][3] = 'AAC_LTP'; - } - return (isset($AACprofileLookup[$mpegversion][$profileid]) ? $AACprofileLookup[$mpegversion][$profileid] : 'invalid'); - } - - function AACchannelCountCalculate($program_configs) { - $channels = 0; - for ($i = 0; $i < $program_configs['num_front_channel_elements']; $i++) { - $channels++; - if ($program_configs['front_element_is_cpe'][$i]) { - // each front element is channel pair (CPE = Channel Pair Element) - $channels++; - } - } - for ($i = 0; $i < $program_configs['num_side_channel_elements']; $i++) { - $channels++; - if ($program_configs['side_element_is_cpe'][$i]) { - // each side element is channel pair (CPE = Channel Pair Element) - $channels++; - } - } - for ($i = 0; $i < $program_configs['num_back_channel_elements']; $i++) { - $channels++; - if ($program_configs['back_element_is_cpe'][$i]) { - // each back element is channel pair (CPE = Channel Pair Element) - $channels++; - } - } - for ($i = 0; $i < $program_configs['num_lfe_channel_elements']; $i++) { - $channels++; - } - return $channels; - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.ac3.php b/serendipity_event_podcast/player/getid3/module.audio.ac3.php deleted file mode 100644 index 9809a47c..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.ac3.php +++ /dev/null @@ -1,497 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.ac3.php // -// module for analyzing AC-3 (aka Dolby Digital) audio files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_ac3 -{ - - function getid3_ac3(&$fd, &$ThisFileInfo) { - - ///AH - $ThisFileInfo['ac3']['raw']['bsi'] = array(); - $thisfile_ac3 = &$ThisFileInfo['ac3']; - $thisfile_ac3_raw = &$thisfile_ac3['raw']; - $thisfile_ac3_raw_bsi = &$thisfile_ac3_raw['bsi']; - - - // http://www.atsc.org/standards/a_52a.pdf - - $ThisFileInfo['fileformat'] = 'ac3'; - $ThisFileInfo['audio']['dataformat'] = 'ac3'; - $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; - $ThisFileInfo['audio']['lossless'] = false; - - // An AC-3 serial coded audio bit stream is made up of a sequence of synchronization frames - // Each synchronization frame contains 6 coded audio blocks (AB), each of which represent 256 - // new audio samples per channel. A synchronization information (SI) header at the beginning - // of each frame contains information needed to acquire and maintain synchronization. A - // bit stream information (BSI) header follows SI, and contains parameters describing the coded - // audio service. The coded audio blocks may be followed by an auxiliary data (Aux) field. At the - // end of each frame is an error check field that includes a CRC word for error detection. An - // additional CRC word is located in the SI header, the use of which, by a decoder, is optional. - // - // syncinfo() | bsi() | AB0 | AB1 | AB2 | AB3 | AB4 | AB5 | Aux | CRC - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $AC3header['syncinfo'] = fread($fd, 5); - $thisfile_ac3_raw['synchinfo']['synchword'] = substr($AC3header['syncinfo'], 0, 2); - - if ($thisfile_ac3_raw['synchinfo']['synchword'] != "\x0B\x77") { - - $ThisFileInfo['error'][] = 'Expecting "\x0B\x77" at offset '.$ThisFileInfo['avdataoffset'].', found \x'.strtoupper(dechex($AC3header['syncinfo']{0})).'\x'.strtoupper(dechex($AC3header['syncinfo']{1})).' instead'; - unset($thisfile_ac3); - return false; - - } else { - - // syncinfo() { - // syncword 16 - // crc1 16 - // fscod 2 - // frmsizecod 6 - // } /* end of syncinfo */ - - $thisfile_ac3_raw['synchinfo']['crc1'] = getid3_lib::LittleEndian2Int(substr($AC3header['syncinfo'], 2, 2)); - $ac3_synchinfo_fscod_frmsizecod = getid3_lib::LittleEndian2Int(substr($AC3header['syncinfo'], 4, 1)); - $thisfile_ac3_raw['synchinfo']['fscod'] = ($ac3_synchinfo_fscod_frmsizecod & 0xC0) >> 6; - $thisfile_ac3_raw['synchinfo']['frmsizecod'] = ($ac3_synchinfo_fscod_frmsizecod & 0x3F); - - $thisfile_ac3['sample_rate'] = $this->AC3sampleRateCodeLookup($thisfile_ac3_raw['synchinfo']['fscod']); - if ($thisfile_ac3_raw['synchinfo']['fscod'] <= 3) { - $ThisFileInfo['audio']['sample_rate'] = $thisfile_ac3['sample_rate']; - } - - $thisfile_ac3['frame_length'] = $this->AC3frameSizeLookup($thisfile_ac3_raw['synchinfo']['frmsizecod'], $thisfile_ac3_raw['synchinfo']['fscod']); - $thisfile_ac3['bitrate'] = $this->AC3bitrateLookup($thisfile_ac3_raw['synchinfo']['frmsizecod']); - $ThisFileInfo['audio']['bitrate'] = $thisfile_ac3['bitrate']; - - $AC3header['bsi'] = getid3_lib::BigEndian2Bin(fread($fd, 15)); - $ac3_bsi_offset = 0; - - $thisfile_ac3_raw_bsi['bsid'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5)); - $ac3_bsi_offset += 5; - if ($thisfile_ac3_raw_bsi['bsid'] > 8) { - // Decoders which can decode version 8 will thus be able to decode version numbers less than 8. - // If this standard is extended by the addition of additional elements or features, a value of bsid greater than 8 will be used. - // Decoders built to this version of the standard will not be able to decode versions with bsid greater than 8. - $ThisFileInfo['error'][] = 'Bit stream identification is version '.$thisfile_ac3_raw_bsi['bsid'].', but getID3() only understands up to version 8'; - unset($thisfile_ac3); - return false; - } - - $thisfile_ac3_raw_bsi['bsmod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 3)); - $ac3_bsi_offset += 3; - $thisfile_ac3_raw_bsi['acmod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 3)); - $ac3_bsi_offset += 3; - - $thisfile_ac3['service_type'] = $this->AC3serviceTypeLookup($thisfile_ac3_raw_bsi['bsmod'], $thisfile_ac3_raw_bsi['acmod']); - $ac3_coding_mode = $this->AC3audioCodingModeLookup($thisfile_ac3_raw_bsi['acmod']); - foreach($ac3_coding_mode as $key => $value) { - $thisfile_ac3[$key] = $value; - } - switch ($thisfile_ac3_raw_bsi['acmod']) { - case 0: - case 1: - $ThisFileInfo['audio']['channelmode'] = 'mono'; - break; - case 3: - case 4: - $ThisFileInfo['audio']['channelmode'] = 'stereo'; - break; - default: - $ThisFileInfo['audio']['channelmode'] = 'surround'; - break; - } - $ThisFileInfo['audio']['channels'] = $thisfile_ac3['num_channels']; - - if ($thisfile_ac3_raw_bsi['acmod'] & 0x01) { - // If the lsb of acmod is a 1, center channel is in use and cmixlev follows in the bit stream. - $thisfile_ac3_raw_bsi['cmixlev'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2)); - $ac3_bsi_offset += 2; - $thisfile_ac3['center_mix_level'] = $this->AC3centerMixLevelLookup($thisfile_ac3_raw_bsi['cmixlev']); - } - - if ($thisfile_ac3_raw_bsi['acmod'] & 0x04) { - // If the msb of acmod is a 1, surround channels are in use and surmixlev follows in the bit stream. - $thisfile_ac3_raw_bsi['surmixlev'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2)); - $ac3_bsi_offset += 2; - $thisfile_ac3['surround_mix_level'] = $this->AC3surroundMixLevelLookup($thisfile_ac3_raw_bsi['surmixlev']); - } - - if ($thisfile_ac3_raw_bsi['acmod'] == 0x02) { - // When operating in the two channel mode, this 2-bit code indicates whether or not the program has been encoded in Dolby Surround. - $thisfile_ac3_raw_bsi['dsurmod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2)); - $ac3_bsi_offset += 2; - $thisfile_ac3['dolby_surround_mode'] = $this->AC3dolbySurroundModeLookup($thisfile_ac3_raw_bsi['dsurmod']); - } - - $thisfile_ac3_raw_bsi['lfeon'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1)); - $ac3_bsi_offset += 1; - $thisfile_ac3['lfe_enabled'] = $thisfile_ac3_raw_bsi['lfeon']; - if ($thisfile_ac3_raw_bsi['lfeon']) { - //$ThisFileInfo['audio']['channels']++; - $ThisFileInfo['audio']['channels'] .= '.1'; - } - - $thisfile_ac3['channels_enabled'] = $this->AC3channelsEnabledLookup($thisfile_ac3_raw_bsi['acmod'], $thisfile_ac3_raw_bsi['lfeon']); - - // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1–31. - // The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent. - $thisfile_ac3_raw_bsi['dialnorm'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5)); - $ac3_bsi_offset += 5; - $thisfile_ac3['dialogue_normalization'] = '-'.$thisfile_ac3_raw_bsi['dialnorm'].'dB'; - - $thisfile_ac3_raw_bsi['compre_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1)); - $ac3_bsi_offset += 1; - if ($thisfile_ac3_raw_bsi['compre_flag']) { - $thisfile_ac3_raw_bsi['compr'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 8)); - $ac3_bsi_offset += 8; - $thisfile_ac3['heavy_compression'] = $this->AC3heavyCompression($thisfile_ac3_raw_bsi['compr']); - } - - $thisfile_ac3_raw_bsi['langcode_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1)); - $ac3_bsi_offset += 1; - if ($thisfile_ac3_raw_bsi['langcode_flag']) { - $thisfile_ac3_raw_bsi['langcod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 8)); - $ac3_bsi_offset += 8; - } - - $thisfile_ac3_raw_bsi['audprodie'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1)); - $ac3_bsi_offset += 1; - if ($thisfile_ac3_raw_bsi['audprodie']) { - $thisfile_ac3_raw_bsi['mixlevel'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5)); - $ac3_bsi_offset += 5; - $thisfile_ac3_raw_bsi['roomtyp'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2)); - $ac3_bsi_offset += 2; - - $thisfile_ac3['mixing_level'] = (80 + $thisfile_ac3_raw_bsi['mixlevel']).'dB'; - $thisfile_ac3['room_type'] = $this->AC3roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp']); - } - - if ($thisfile_ac3_raw_bsi['acmod'] == 0x00) { - // If acmod is 0, then two completely independent program channels (dual mono) - // are encoded into the bit stream, and are referenced as Ch1, Ch2. In this case, - // a number of additional items are present in BSI or audblk to fully describe Ch2. - - - // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1–31. - // The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent. - $thisfile_ac3_raw_bsi['dialnorm2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5)); - $ac3_bsi_offset += 5; - $thisfile_ac3['dialogue_normalization2'] = '-'.$thisfile_ac3_raw_bsi['dialnorm2'].'dB'; - - $thisfile_ac3_raw_bsi['compre_flag2'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1)); - $ac3_bsi_offset += 1; - if ($thisfile_ac3_raw_bsi['compre_flag2']) { - $thisfile_ac3_raw_bsi['compr2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 8)); - $ac3_bsi_offset += 8; - $thisfile_ac3['heavy_compression2'] = $this->AC3heavyCompression($thisfile_ac3_raw_bsi['compr2']); - } - - $thisfile_ac3_raw_bsi['langcode_flag2'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1)); - $ac3_bsi_offset += 1; - if ($thisfile_ac3_raw_bsi['langcode_flag2']) { - $thisfile_ac3_raw_bsi['langcod2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 8)); - $ac3_bsi_offset += 8; - } - - $thisfile_ac3_raw_bsi['audprodie2'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1)); - $ac3_bsi_offset += 1; - if ($thisfile_ac3_raw_bsi['audprodie2']) { - $thisfile_ac3_raw_bsi['mixlevel2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5)); - $ac3_bsi_offset += 5; - $thisfile_ac3_raw_bsi['roomtyp2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2)); - $ac3_bsi_offset += 2; - - $thisfile_ac3['mixing_level2'] = (80 + $thisfile_ac3_raw_bsi['mixlevel2']).'dB'; - $thisfile_ac3['room_type2'] = $this->AC3roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp2']); - } - - } - - $thisfile_ac3_raw_bsi['copyright'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1)); - $ac3_bsi_offset += 1; - - $thisfile_ac3_raw_bsi['original'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1)); - $ac3_bsi_offset += 1; - - $thisfile_ac3_raw_bsi['timecode1_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1)); - $ac3_bsi_offset += 1; - if ($thisfile_ac3_raw_bsi['timecode1_flag']) { - $thisfile_ac3_raw_bsi['timecode1'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 14)); - $ac3_bsi_offset += 14; - } - - $thisfile_ac3_raw_bsi['timecode2_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1)); - $ac3_bsi_offset += 1; - if ($thisfile_ac3_raw_bsi['timecode2_flag']) { - $thisfile_ac3_raw_bsi['timecode2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 14)); - $ac3_bsi_offset += 14; - } - - $thisfile_ac3_raw_bsi['addbsi_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1)); - $ac3_bsi_offset += 1; - if ($thisfile_ac3_raw_bsi['addbsi_flag']) { - $thisfile_ac3_raw_bsi['addbsi_length'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 6)); - $ac3_bsi_offset += 6; - - $AC3header['bsi'] .= getid3_lib::BigEndian2Bin(fread($fd, $thisfile_ac3_raw_bsi['addbsi_length'])); - - $thisfile_ac3_raw_bsi['addbsi_data'] = substr($AC3header['bsi'], $ac3_bsi_offset, $thisfile_ac3_raw_bsi['addbsi_length'] * 8); - $ac3_bsi_offset += $thisfile_ac3_raw_bsi['addbsi_length'] * 8; - } - - } - - return true; - } - - - function AC3sampleRateCodeLookup($fscod) { - static $AC3sampleRateCodeLookup = array( - 0 => 48000, - 1 => 44100, - 2 => 32000, - 3 => 'reserved' // If the reserved code is indicated, the decoder should not attempt to decode audio and should mute. - ); - return (isset($AC3sampleRateCodeLookup[$fscod]) ? $AC3sampleRateCodeLookup[$fscod] : false); - } - - function AC3serviceTypeLookup($bsmod, $acmod) { - static $AC3serviceTypeLookup = array(); - if (empty($AC3serviceTypeLookup)) { - for ($i = 0; $i <= 7; $i++) { - $AC3serviceTypeLookup[0][$i] = 'main audio service: complete main (CM)'; - $AC3serviceTypeLookup[1][$i] = 'main audio service: music and effects (ME)'; - $AC3serviceTypeLookup[2][$i] = 'associated service: visually impaired (VI)'; - $AC3serviceTypeLookup[3][$i] = 'associated service: hearing impaired (HI)'; - $AC3serviceTypeLookup[4][$i] = 'associated service: dialogue (D)'; - $AC3serviceTypeLookup[5][$i] = 'associated service: commentary (C)'; - $AC3serviceTypeLookup[6][$i] = 'associated service: emergency (E)'; - } - - $AC3serviceTypeLookup[7][1] = 'associated service: voice over (VO)'; - for ($i = 2; $i <= 7; $i++) { - $AC3serviceTypeLookup[7][$i] = 'main audio service: karaoke'; - } - } - return (isset($AC3serviceTypeLookup[$bsmod][$acmod]) ? $AC3serviceTypeLookup[$bsmod][$acmod] : false); - } - - function AC3audioCodingModeLookup($acmod) { - static $AC3audioCodingModeLookup = array(); - if (empty($AC3audioCodingModeLookup)) { - // array(channel configuration, # channels (not incl LFE), channel order) - $AC3audioCodingModeLookup = array ( - 0 => array('channel_config'=>'1+1', 'num_channels'=>2, 'channel_order'=>'Ch1,Ch2'), - 1 => array('channel_config'=>'1/0', 'num_channels'=>1, 'channel_order'=>'C'), - 2 => array('channel_config'=>'2/0', 'num_channels'=>2, 'channel_order'=>'L,R'), - 3 => array('channel_config'=>'3/0', 'num_channels'=>3, 'channel_order'=>'L,C,R'), - 4 => array('channel_config'=>'2/1', 'num_channels'=>3, 'channel_order'=>'L,R,S'), - 5 => array('channel_config'=>'3/1', 'num_channels'=>4, 'channel_order'=>'L,C,R,S'), - 6 => array('channel_config'=>'2/2', 'num_channels'=>4, 'channel_order'=>'L,R,SL,SR'), - 7 => array('channel_config'=>'3/2', 'num_channels'=>5, 'channel_order'=>'L,C,R,SL,SR') - ); - } - return (isset($AC3audioCodingModeLookup[$acmod]) ? $AC3audioCodingModeLookup[$acmod] : false); - } - - function AC3centerMixLevelLookup($cmixlev) { - static $AC3centerMixLevelLookup; - if (empty($AC3centerMixLevelLookup)) { - $AC3centerMixLevelLookup = array( - 0 => pow(2, -3.0 / 6), // 0.707 (–3.0 dB) - 1 => pow(2, -4.5 / 6), // 0.595 (–4.5 dB) - 2 => pow(2, -6.0 / 6), // 0.500 (–6.0 dB) - 3 => 'reserved' - ); - } - return (isset($AC3centerMixLevelLookup[$cmixlev]) ? $AC3centerMixLevelLookup[$cmixlev] : false); - } - - function AC3surroundMixLevelLookup($surmixlev) { - static $AC3surroundMixLevelLookup; - if (empty($AC3surroundMixLevelLookup)) { - $AC3surroundMixLevelLookup = array( - 0 => pow(2, -3.0 / 6), - 1 => pow(2, -6.0 / 6), - 2 => 0, - 3 => 'reserved' - ); - } - return (isset($AC3surroundMixLevelLookup[$surmixlev]) ? $AC3surroundMixLevelLookup[$surmixlev] : false); - } - - function AC3dolbySurroundModeLookup($dsurmod) { - static $AC3dolbySurroundModeLookup = array( - 0 => 'not indicated', - 1 => 'Not Dolby Surround encoded', - 2 => 'Dolby Surround encoded', - 3 => 'reserved' - ); - return (isset($AC3dolbySurroundModeLookup[$dsurmod]) ? $AC3dolbySurroundModeLookup[$dsurmod] : false); - } - - function AC3channelsEnabledLookup($acmod, $lfeon) { - $AC3channelsEnabledLookup = array( - 'ch1'=>(bool) ($acmod == 0), - 'ch2'=>(bool) ($acmod == 0), - 'left'=>(bool) ($acmod > 1), - 'right'=>(bool) ($acmod > 1), - 'center'=>(bool) ($acmod & 0x01), - 'surround_mono'=>false, - 'surround_left'=>false, - 'surround_right'=>false, - 'lfe'=>$lfeon); - switch ($acmod) { - case 4: - case 5: - $AC3channelsEnabledLookup['surround_mono'] = true; - break; - case 6: - case 7: - $AC3channelsEnabledLookup['surround_left'] = true; - $AC3channelsEnabledLookup['surround_right'] = true; - break; - } - return $AC3channelsEnabledLookup; - } - - function AC3heavyCompression($compre) { - // The first four bits indicate gain changes in 6.02dB increments which can be - // implemented with an arithmetic shift operation. The following four bits - // indicate linear gain changes, and require a 5-bit multiply. - // We will represent the two 4-bit fields of compr as follows: - // X0 X1 X2 X3 . Y4 Y5 Y6 Y7 - // The meaning of the X values is most simply described by considering X to represent a 4-bit - // signed integer with values from –8 to +7. The gain indicated by X is then (X + 1) * 6.02 dB. The - // following table shows this in detail. - - // Meaning of 4 msb of compr - // 7 +48.16 dB - // 6 +42.14 dB - // 5 +36.12 dB - // 4 +30.10 dB - // 3 +24.08 dB - // 2 +18.06 dB - // 1 +12.04 dB - // 0 +6.02 dB - // -1 0 dB - // -2 –6.02 dB - // -3 –12.04 dB - // -4 –18.06 dB - // -5 –24.08 dB - // -6 –30.10 dB - // -7 –36.12 dB - // -8 –42.14 dB - - $fourbit = str_pad(decbin(($compre & 0xF0) >> 4), 4, '0', STR_PAD_LEFT); - if ($fourbit{0} == '1') { - $log_gain = -8 + bindec(substr($fourbit, 1)); - } else { - $log_gain = bindec(substr($fourbit, 1)); - } - $log_gain = ($log_gain + 1) * getid3_lib::RGADamplitude2dB(2); - - // The value of Y is a linear representation of a gain change of up to –6 dB. Y is considered to - // be an unsigned fractional integer, with a leading value of 1, or: 0.1 Y4 Y5 Y6 Y7 (base 2). Y can - // represent values between 0.111112 (or 31/32) and 0.100002 (or 1/2). Thus, Y can represent gain - // changes from –0.28 dB to –6.02 dB. - - $lin_gain = (16 + ($compre & 0x0F)) / 32; - - // The combination of X and Y values allows compr to indicate gain changes from - // 48.16 – 0.28 = +47.89 dB, to - // –42.14 – 6.02 = –48.16 dB. - - return $log_gain - $lin_gain; - } - - function AC3roomTypeLookup($roomtyp) { - static $AC3roomTypeLookup = array( - 0 => 'not indicated', - 1 => 'large room, X curve monitor', - 2 => 'small room, flat monitor', - 3 => 'reserved' - ); - return (isset($AC3roomTypeLookup[$roomtyp]) ? $AC3roomTypeLookup[$roomtyp] : false); - } - - function AC3frameSizeLookup($frmsizecod, $fscod) { - $padding = (bool) ($frmsizecod % 2); - $framesizeid = floor($frmsizecod / 2); - - static $AC3frameSizeLookup = array(); - if (empty($AC3frameSizeLookup)) { - $AC3frameSizeLookup = array ( - 0 => array(128, 138, 192), - 1 => array(40, 160, 174, 240), - 2 => array(48, 192, 208, 288), - 3 => array(56, 224, 242, 336), - 4 => array(64, 256, 278, 384), - 5 => array(80, 320, 348, 480), - 6 => array(96, 384, 416, 576), - 7 => array(112, 448, 486, 672), - 8 => array(128, 512, 556, 768), - 9 => array(160, 640, 696, 960), - 10 => array(192, 768, 834, 1152), - 11 => array(224, 896, 974, 1344), - 12 => array(256, 1024, 1114, 1536), - 13 => array(320, 1280, 1392, 1920), - 14 => array(384, 1536, 1670, 2304), - 15 => array(448, 1792, 1950, 2688), - 16 => array(512, 2048, 2228, 3072), - 17 => array(576, 2304, 2506, 3456), - 18 => array(640, 2560, 2786, 3840) - ); - } - if (($fscod == 1) && $padding) { - // frame lengths are padded by 1 word (16 bits) at 44100 - $AC3frameSizeLookup[$frmsizecod] += 2; - } - return (isset($AC3frameSizeLookup[$framesizeid][$fscod]) ? $AC3frameSizeLookup[$framesizeid][$fscod] : false); - } - - function AC3bitrateLookup($frmsizecod) { - $framesizeid = floor($frmsizecod / 2); - - static $AC3bitrateLookup = array( - 0 => 32000, - 1 => 40000, - 2 => 48000, - 3 => 56000, - 4 => 64000, - 5 => 80000, - 6 => 96000, - 7 => 112000, - 8 => 128000, - 9 => 160000, - 10 => 192000, - 11 => 224000, - 12 => 256000, - 13 => 320000, - 14 => 384000, - 15 => 448000, - 16 => 512000, - 17 => 576000, - 18 => 640000 - ); - return (isset($AC3bitrateLookup[$framesizeid]) ? $AC3bitrateLookup[$framesizeid] : false); - } - - -} - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.avr.php b/serendipity_event_podcast/player/getid3/module.audio.avr.php deleted file mode 100644 index 60994397..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.avr.php +++ /dev/null @@ -1,125 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.avr.php // -// module for analyzing AVR Audio files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_avr -{ - - function getid3_avr(&$fd, &$ThisFileInfo) { - - // http://cui.unige.ch/OSG/info/AudioFormats/ap11.html - // http://www.btinternet.com/~AnthonyJ/Atari/programming/avr_format.html - // offset type length name comments - // --------------------------------------------------------------------- - // 0 char 4 ID format ID == "2BIT" - // 4 char 8 name sample name (unused space filled with 0) - // 12 short 1 mono/stereo 0=mono, -1 (0xFFFF)=stereo - // With stereo, samples are alternated, - // the first voice is the left : - // (LRLRLRLRLRLRLRLRLR...) - // 14 short 1 resolution 8, 12 or 16 (bits) - // 16 short 1 signed or not 0=unsigned, -1 (0xFFFF)=signed - // 18 short 1 loop or not 0=no loop, -1 (0xFFFF)=loop on - // 20 short 1 MIDI note 0xFFnn, where 0 <= nn <= 127 - // 0xFFFF means "no MIDI note defined" - // 22 byte 1 Replay speed Frequence in the Replay software - // 0=5.485 Khz, 1=8.084 Khz, 2=10.971 Khz, - // 3=16.168 Khz, 4=21.942 Khz, 5=32.336 Khz - // 6=43.885 Khz, 7=47.261 Khz - // -1 (0xFF)=no defined Frequence - // 23 byte 3 sample rate in Hertz - // 26 long 1 size in bytes (2 * bytes in stereo) - // 30 long 1 loop begin 0 for no loop - // 34 long 1 loop size equal to 'size' for no loop - // 38 short 2 Reserved, MIDI keyboard split */ - // 40 short 2 Reserved, sample compression */ - // 42 short 2 Reserved */ - // 44 char 20; Additional filename space, used if (name[7] != 0) - // 64 byte 64 user data - // 128 bytes ? sample data (12 bits samples are coded on 16 bits: - // 0000 xxxx xxxx xxxx) - // --------------------------------------------------------------------- - - // Note that all values are in motorola (big-endian) format, and that long is - // assumed to be 4 bytes, and short 2 bytes. - // When reading the samples, you should handle both signed and unsigned data, - // and be prepared to convert 16->8 bit, or mono->stereo if needed. To convert - // 8-bit data between signed/unsigned just add 127 to the sample values. - // Simularly for 16-bit data you should add 32769 - - $ThisFileInfo['fileformat'] = 'avr'; - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $AVRheader = fread($fd, 128); - - $ThisFileInfo['avr']['raw']['magic'] = substr($AVRheader, 0, 4); - if ($ThisFileInfo['avr']['raw']['magic'] != '2BIT') { - $ThisFileInfo['error'][] = 'Expecting "2BIT" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['avr']['raw']['magic'].'"'; - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['avr']); - return false; - } - $ThisFileInfo['avdataoffset'] += 128; - - $ThisFileInfo['avr']['sample_name'] = rtrim(substr($AVRheader, 4, 8)); - $ThisFileInfo['avr']['raw']['mono'] = getid3_lib::BigEndian2Int(substr($AVRheader, 12, 2)); - $ThisFileInfo['avr']['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($AVRheader, 14, 2)); - $ThisFileInfo['avr']['raw']['signed'] = getid3_lib::BigEndian2Int(substr($AVRheader, 16, 2)); - $ThisFileInfo['avr']['raw']['loop'] = getid3_lib::BigEndian2Int(substr($AVRheader, 18, 2)); - $ThisFileInfo['avr']['raw']['midi'] = getid3_lib::BigEndian2Int(substr($AVRheader, 20, 2)); - $ThisFileInfo['avr']['raw']['replay_freq'] = getid3_lib::BigEndian2Int(substr($AVRheader, 22, 1)); - $ThisFileInfo['avr']['sample_rate'] = getid3_lib::BigEndian2Int(substr($AVRheader, 23, 3)); - $ThisFileInfo['avr']['sample_length'] = getid3_lib::BigEndian2Int(substr($AVRheader, 26, 4)); - $ThisFileInfo['avr']['loop_start'] = getid3_lib::BigEndian2Int(substr($AVRheader, 30, 4)); - $ThisFileInfo['avr']['loop_end'] = getid3_lib::BigEndian2Int(substr($AVRheader, 34, 4)); - $ThisFileInfo['avr']['midi_split'] = getid3_lib::BigEndian2Int(substr($AVRheader, 38, 2)); - $ThisFileInfo['avr']['sample_compression'] = getid3_lib::BigEndian2Int(substr($AVRheader, 40, 2)); - $ThisFileInfo['avr']['reserved'] = getid3_lib::BigEndian2Int(substr($AVRheader, 42, 2)); - $ThisFileInfo['avr']['sample_name_extra'] = rtrim(substr($AVRheader, 44, 20)); - $ThisFileInfo['avr']['comment'] = rtrim(substr($AVRheader, 64, 64)); - - $ThisFileInfo['avr']['flags']['stereo'] = (($ThisFileInfo['avr']['raw']['mono'] == 0) ? false : true); - $ThisFileInfo['avr']['flags']['signed'] = (($ThisFileInfo['avr']['raw']['signed'] == 0) ? false : true); - $ThisFileInfo['avr']['flags']['loop'] = (($ThisFileInfo['avr']['raw']['loop'] == 0) ? false : true); - - $ThisFileInfo['avr']['midi_notes'] = array(); - if (($ThisFileInfo['avr']['raw']['midi'] & 0xFF00) != 0xFF00) { - $ThisFileInfo['avr']['midi_notes'][] = ($ThisFileInfo['avr']['raw']['midi'] & 0xFF00) >> 8; - } - if (($ThisFileInfo['avr']['raw']['midi'] & 0x00FF) != 0x00FF) { - $ThisFileInfo['avr']['midi_notes'][] = ($ThisFileInfo['avr']['raw']['midi'] & 0x00FF); - } - - if (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) != ($ThisFileInfo['avr']['sample_length'] * (($ThisFileInfo['avr']['bits_per_sample'] == 8) ? 1 : 2))) { - $ThisFileInfo['warning'][] = 'Probable truncated file: expecting '.($ThisFileInfo['avr']['sample_length'] * (($ThisFileInfo['avr']['bits_per_sample'] == 8) ? 1 : 2)).' bytes of audio data, found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']); - } - - $ThisFileInfo['audio']['dataformat'] = 'avr'; - $ThisFileInfo['audio']['lossless'] = true; - $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; - $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['avr']['bits_per_sample']; - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['avr']['sample_rate']; - $ThisFileInfo['audio']['channels'] = ($ThisFileInfo['avr']['flags']['stereo'] ? 2 : 1); - $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avr']['sample_length'] / $ThisFileInfo['audio']['channels']) / $ThisFileInfo['avr']['sample_rate']; - $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avr']['sample_length'] * (($ThisFileInfo['avr']['bits_per_sample'] == 8) ? 8 : 16)) / $ThisFileInfo['playtime_seconds']; - - - return true; - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.bonk.php b/serendipity_event_podcast/player/getid3/module.audio.bonk.php deleted file mode 100644 index cab2ff59..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.bonk.php +++ /dev/null @@ -1,221 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.la.php // -// module for analyzing BONK audio files // -// dependencies: module.tag.id3v2.php (optional) // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_bonk -{ - function getid3_bonk(&$fd, &$ThisFileInfo) { - - // shortcut - $ThisFileInfo['bonk'] = array(); - $thisfile_bonk = &$ThisFileInfo['bonk']; - - $thisfile_bonk['dataoffset'] = $ThisFileInfo['avdataoffset']; - $thisfile_bonk['dataend'] = $ThisFileInfo['avdataend']; - - if (!getid3_lib::intValueSupported($thisfile_bonk['dataend'])) { - - $ThisFileInfo['warning'][] = 'Unable to parse BONK file from end (v0.6+ preferred method) because PHP filesystem functions only support up to '.round(PHP_INT_MAX / 1073741824).'GB'; - - } else { - - // scan-from-end method, for v0.6 and higher - fseek($fd, $thisfile_bonk['dataend'] - 8, SEEK_SET); - $PossibleBonkTag = fread($fd, 8); - while ($this->BonkIsValidTagName(substr($PossibleBonkTag, 4, 4), true)) { - $BonkTagSize = getid3_lib::LittleEndian2Int(substr($PossibleBonkTag, 0, 4)); - fseek($fd, 0 - $BonkTagSize, SEEK_CUR); - $BonkTagOffset = ftell($fd); - $TagHeaderTest = fread($fd, 5); - if (($TagHeaderTest{0} != "\x00") || (substr($PossibleBonkTag, 4, 4) != strtolower(substr($PossibleBonkTag, 4, 4)))) { - $ThisFileInfo['error'][] = 'Expecting "Ø'.strtoupper(substr($PossibleBonkTag, 4, 4)).'" at offset '.$BonkTagOffset.', found "'.$TagHeaderTest.'"'; - return false; - } - $BonkTagName = substr($TagHeaderTest, 1, 4); - - $thisfile_bonk[$BonkTagName]['size'] = $BonkTagSize; - $thisfile_bonk[$BonkTagName]['offset'] = $BonkTagOffset; - $this->HandleBonkTags($fd, $BonkTagName, $ThisFileInfo); - $NextTagEndOffset = $BonkTagOffset - 8; - if ($NextTagEndOffset < $thisfile_bonk['dataoffset']) { - if (empty($ThisFileInfo['audio']['encoder'])) { - $ThisFileInfo['audio']['encoder'] = 'Extended BONK v0.9+'; - } - return true; - } - fseek($fd, $NextTagEndOffset, SEEK_SET); - $PossibleBonkTag = fread($fd, 8); - } - - } - - // seek-from-beginning method for v0.4 and v0.5 - if (empty($thisfile_bonk['BONK'])) { - fseek($fd, $thisfile_bonk['dataoffset'], SEEK_SET); - do { - $TagHeaderTest = fread($fd, 5); - switch ($TagHeaderTest) { - case "\x00".'BONK': - if (empty($ThisFileInfo['audio']['encoder'])) { - $ThisFileInfo['audio']['encoder'] = 'BONK v0.4'; - } - break; - - case "\x00".'INFO': - $ThisFileInfo['audio']['encoder'] = 'Extended BONK v0.5'; - break; - - default: - break 2; - } - $BonkTagName = substr($TagHeaderTest, 1, 4); - $thisfile_bonk[$BonkTagName]['size'] = $thisfile_bonk['dataend'] - $thisfile_bonk['dataoffset']; - $thisfile_bonk[$BonkTagName]['offset'] = $thisfile_bonk['dataoffset']; - $this->HandleBonkTags($fd, $BonkTagName, $ThisFileInfo); - - } while (true); - } - - // parse META block for v0.6 - v0.8 - if (empty($thisfile_bonk['INFO']) && isset($thisfile_bonk['META']['tags']['info'])) { - fseek($fd, $thisfile_bonk['META']['tags']['info'], SEEK_SET); - $TagHeaderTest = fread($fd, 5); - if ($TagHeaderTest == "\x00".'INFO') { - $ThisFileInfo['audio']['encoder'] = 'Extended BONK v0.6 - v0.8'; - - $BonkTagName = substr($TagHeaderTest, 1, 4); - $thisfile_bonk[$BonkTagName]['size'] = $thisfile_bonk['dataend'] - $thisfile_bonk['dataoffset']; - $thisfile_bonk[$BonkTagName]['offset'] = $thisfile_bonk['dataoffset']; - $this->HandleBonkTags($fd, $BonkTagName, $ThisFileInfo); - } - } - - if (empty($ThisFileInfo['audio']['encoder'])) { - $ThisFileInfo['audio']['encoder'] = 'Extended BONK v0.9+'; - } - if (empty($thisfile_bonk['BONK'])) { - unset($ThisFileInfo['bonk']); - } - return true; - - } - - function HandleBonkTags(&$fd, &$BonkTagName, &$ThisFileInfo) { - - switch ($BonkTagName) { - case 'BONK': - // shortcut - $thisfile_bonk_BONK = &$ThisFileInfo['bonk']['BONK']; - - $BonkData = "\x00".'BONK'.fread($fd, 17); - $thisfile_bonk_BONK['version'] = getid3_lib::LittleEndian2Int(substr($BonkData, 5, 1)); - $thisfile_bonk_BONK['number_samples'] = getid3_lib::LittleEndian2Int(substr($BonkData, 6, 4)); - $thisfile_bonk_BONK['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BonkData, 10, 4)); - - $thisfile_bonk_BONK['channels'] = getid3_lib::LittleEndian2Int(substr($BonkData, 14, 1)); - $thisfile_bonk_BONK['lossless'] = (bool) getid3_lib::LittleEndian2Int(substr($BonkData, 15, 1)); - $thisfile_bonk_BONK['joint_stereo'] = (bool) getid3_lib::LittleEndian2Int(substr($BonkData, 16, 1)); - $thisfile_bonk_BONK['number_taps'] = getid3_lib::LittleEndian2Int(substr($BonkData, 17, 2)); - $thisfile_bonk_BONK['downsampling_ratio'] = getid3_lib::LittleEndian2Int(substr($BonkData, 19, 1)); - $thisfile_bonk_BONK['samples_per_packet'] = getid3_lib::LittleEndian2Int(substr($BonkData, 20, 2)); - - $ThisFileInfo['avdataoffset'] = $thisfile_bonk_BONK['offset'] + 5 + 17; - $ThisFileInfo['avdataend'] = $thisfile_bonk_BONK['offset'] + $thisfile_bonk_BONK['size']; - - $ThisFileInfo['fileformat'] = 'bonk'; - $ThisFileInfo['audio']['dataformat'] = 'bonk'; - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; // assumed - $ThisFileInfo['audio']['channels'] = $thisfile_bonk_BONK['channels']; - $ThisFileInfo['audio']['sample_rate'] = $thisfile_bonk_BONK['sample_rate']; - $ThisFileInfo['audio']['channelmode'] = ($thisfile_bonk_BONK['joint_stereo'] ? 'joint stereo' : 'stereo'); - $ThisFileInfo['audio']['lossless'] = $thisfile_bonk_BONK['lossless']; - $ThisFileInfo['audio']['codec'] = 'bonk'; - - $ThisFileInfo['playtime_seconds'] = $thisfile_bonk_BONK['number_samples'] / ($thisfile_bonk_BONK['sample_rate'] * $thisfile_bonk_BONK['channels']); - if ($ThisFileInfo['playtime_seconds'] > 0) { - $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['bonk']['dataend'] - $ThisFileInfo['bonk']['dataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; - } - break; - - case 'INFO': - // shortcut - $thisfile_bonk_INFO = &$ThisFileInfo['bonk']['INFO']; - - $thisfile_bonk_INFO['version'] = getid3_lib::LittleEndian2Int(fread($fd, 1)); - $thisfile_bonk_INFO['entries_count'] = 0; - $NextInfoDataPair = fread($fd, 5); - if (!$this->BonkIsValidTagName(substr($NextInfoDataPair, 1, 4))) { - while (!feof($fd)) { - //$CurrentSeekInfo['offset'] = getid3_lib::LittleEndian2Int(substr($NextInfoDataPair, 0, 4)); - //$CurrentSeekInfo['nextbit'] = getid3_lib::LittleEndian2Int(substr($NextInfoDataPair, 4, 1)); - //$thisfile_bonk_INFO[] = $CurrentSeekInfo; - - $NextInfoDataPair = fread($fd, 5); - if ($this->BonkIsValidTagName(substr($NextInfoDataPair, 1, 4))) { - fseek($fd, -5, SEEK_CUR); - break; - } - $thisfile_bonk_INFO['entries_count']++; - } - } - break; - - case 'META': - $BonkData = "\x00".'META'.fread($fd, $ThisFileInfo['bonk']['META']['size'] - 5); - $ThisFileInfo['bonk']['META']['version'] = getid3_lib::LittleEndian2Int(substr($BonkData, 5, 1)); - - $MetaTagEntries = floor(((strlen($BonkData) - 8) - 6) / 8); // BonkData - xxxxmeta - ØMETA - $offset = 6; - for ($i = 0; $i < $MetaTagEntries; $i++) { - $MetaEntryTagName = substr($BonkData, $offset, 4); - $offset += 4; - $MetaEntryTagOffset = getid3_lib::LittleEndian2Int(substr($BonkData, $offset, 4)); - $offset += 4; - $ThisFileInfo['bonk']['META']['tags'][$MetaEntryTagName] = $MetaEntryTagOffset; - } - break; - - case ' ID3': - $ThisFileInfo['audio']['encoder'] = 'Extended BONK v0.9+'; - - // ID3v2 checking is optional - if (class_exists('getid3_id3v2')) { - $ThisFileInfo['bonk'][' ID3']['valid'] = new getid3_id3v2($fd, $ThisFileInfo, $ThisFileInfo['bonk'][' ID3']['offset'] + 2); - } - break; - - default: - $ThisFileInfo['warning'][] = 'Unexpected Bonk tag "'.$BonkTagName.'" at offset '.$ThisFileInfo['bonk'][$BonkTagName]['offset']; - break; - - } - } - - function BonkIsValidTagName($PossibleBonkTag, $ignorecase=false) { - static $BonkIsValidTagName = array('BONK', 'INFO', ' ID3', 'META'); - foreach ($BonkIsValidTagName as $validtagname) { - if ($validtagname == $PossibleBonkTag) { - return true; - } elseif ($ignorecase && (strtolower($validtagname) == strtolower($PossibleBonkTag))) { - return true; - } - } - return false; - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.dss.php b/serendipity_event_podcast/player/getid3/module.audio.dss.php deleted file mode 100644 index 030f14a7..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.dss.php +++ /dev/null @@ -1,74 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.dss.php // -// module for analyzing Digital Speech Standard (DSS) files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_dss -{ - - function getid3_dss(&$fd, &$ThisFileInfo) { - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $DSSheader = fread($fd, 1256); - - if (!preg_match('#^(\x02|\x03)dss', $DSSheader)) { - $ThisFileInfo['error'][] = 'Expecting "[x02-x03]dss" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($DSSheader, 0, 4).'"'; - return false; - } - - // some structure information taken from http://cpansearch.perl.org/src/RGIBSON/Audio-DSS-0.02/lib/Audio/DSS.pm - - // shortcut - $ThisFileInfo['dss'] = array(); - $thisfile_dss = &$ThisFileInfo['dss']; - - $ThisFileInfo['fileformat'] = 'dss'; - $ThisFileInfo['audio']['dataformat'] = 'dss'; - $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; - //$thisfile_dss['encoding'] = 'ISO-8859-1'; - - $thisfile_dss['version'] = ord(substr($DSSheader, 0, 1)); - $thisfile_dss['date_create'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 38, 12)); - $thisfile_dss['date_complete'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 50, 12)); - //$thisfile_dss['length'] = intval(substr($DSSheader, 62, 6)); // I thought time was in seconds, it's actually HHMMSS - $thisfile_dss['length'] = intval((substr($DSSheader, 62, 2) * 3600) + (substr($DSSheader, 64, 2) * 60) + substr($DSSheader, 66, 2)); - $thisfile_dss['priority'] = ord(substr($DSSheader, 793, 1)); - $thisfile_dss['comments'] = trim(substr($DSSheader, 798, 100)); - - - //$ThisFileInfo['audio']['bits_per_sample'] = ?; - //$ThisFileInfo['audio']['sample_rate'] = ?; - $ThisFileInfo['audio']['channels'] = 1; - - $ThisFileInfo['playtime_seconds'] = $thisfile_dss['length']; - $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['filesize'] * 8) / $ThisFileInfo['playtime_seconds']; - - return true; - } - - function DSSdateStringToUnixDate($datestring) { - $y = substr($datestring, 0, 2); - $m = substr($datestring, 2, 2); - $d = substr($datestring, 4, 2); - $h = substr($datestring, 6, 2); - $i = substr($datestring, 8, 2); - $s = substr($datestring, 10, 2); - $y += (($y < 95) ? 2000 : 1900); - return mktime($h, $i, $s, $m, $d, $y); - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.dts.php b/serendipity_event_podcast/player/getid3/module.audio.dts.php deleted file mode 100644 index 17488012..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.dts.php +++ /dev/null @@ -1,239 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.dts.php // -// module for analyzing DTS Audio files // -// dependencies: NONE // -// // -///////////////////////////////////////////////////////////////// - - -class getid3_dts -{ - - function getid3_dts(&$fd, &$ThisFileInfo) { - // Specs taken from "DTS Coherent Acoustics;Core and Extensions, ETSI TS 102 114 V1.2.1 (2002-12)" - // (http://pda.etsi.org/pda/queryform.asp) - // With thanks to Gambit http://mac.sourceforge.net/atl/ - - $ThisFileInfo['fileformat'] = 'dts'; - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $DTSheader = fread($fd, 16); - - $ThisFileInfo['dts']['raw']['magic'] = getid3_lib::BigEndian2Int(substr($DTSheader, 0, 4)); - if ($ThisFileInfo['dts']['raw']['magic'] != 0x7FFE8001) { - $ThisFileInfo['error'][] = 'Expecting "0x7FFE8001" at offset '.$ThisFileInfo['avdataoffset'].', found "0x'.str_pad(strtoupper(dechex($ThisFileInfo['dts']['raw']['magic'])), 8, '0', STR_PAD_LEFT).'"'; - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['dts']); - return false; - } - - $fhBS = getid3_lib::BigEndian2Bin(substr($DTSheader, 4, 12)); - $bsOffset = 0; - $ThisFileInfo['dts']['raw']['frame_type'] = bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1; - $ThisFileInfo['dts']['raw']['deficit_samples'] = bindec(substr($fhBS, $bsOffset, 5)); $bsOffset += 5; - $ThisFileInfo['dts']['flags']['crc_present'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1; - $ThisFileInfo['dts']['raw']['pcm_sample_blocks'] = bindec(substr($fhBS, $bsOffset, 7)); $bsOffset += 7; - $ThisFileInfo['dts']['raw']['frame_byte_size'] = bindec(substr($fhBS, $bsOffset, 14)); $bsOffset += 14; - $ThisFileInfo['dts']['raw']['channel_arrangement'] = bindec(substr($fhBS, $bsOffset, 6)); $bsOffset += 6; - $ThisFileInfo['dts']['raw']['sample_frequency'] = bindec(substr($fhBS, $bsOffset, 4)); $bsOffset += 4; - $ThisFileInfo['dts']['raw']['bitrate'] = bindec(substr($fhBS, $bsOffset, 5)); $bsOffset += 5; - $ThisFileInfo['dts']['flags']['embedded_downmix'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1; - $ThisFileInfo['dts']['flags']['dynamicrange'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1; - $ThisFileInfo['dts']['flags']['timestamp'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1; - $ThisFileInfo['dts']['flags']['auxdata'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1; - $ThisFileInfo['dts']['flags']['hdcd'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1; - $ThisFileInfo['dts']['raw']['extension_audio'] = bindec(substr($fhBS, $bsOffset, 3)); $bsOffset += 3; - $ThisFileInfo['dts']['flags']['extended_coding'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1; - $ThisFileInfo['dts']['flags']['audio_sync_insertion'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1; - $ThisFileInfo['dts']['raw']['lfe_effects'] = bindec(substr($fhBS, $bsOffset, 2)); $bsOffset += 2; - $ThisFileInfo['dts']['flags']['predictor_history'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1; - if ($ThisFileInfo['dts']['flags']['crc_present']) { - $ThisFileInfo['dts']['raw']['crc16'] = bindec(substr($fhBS, $bsOffset, 16)); $bsOffset += 16; - } - $ThisFileInfo['dts']['flags']['mri_perfect_reconst'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1; - $ThisFileInfo['dts']['raw']['encoder_soft_version'] = bindec(substr($fhBS, $bsOffset, 4)); $bsOffset += 4; - $ThisFileInfo['dts']['raw']['copy_history'] = bindec(substr($fhBS, $bsOffset, 2)); $bsOffset += 2; - $ThisFileInfo['dts']['raw']['bits_per_sample'] = bindec(substr($fhBS, $bsOffset, 2)); $bsOffset += 2; - $ThisFileInfo['dts']['flags']['surround_es'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1; - $ThisFileInfo['dts']['flags']['front_sum_diff'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1; - $ThisFileInfo['dts']['flags']['surround_sum_diff'] = (bool) bindec(substr($fhBS, $bsOffset, 1)); $bsOffset += 1; - $ThisFileInfo['dts']['raw']['dialog_normalization'] = bindec(substr($fhBS, $bsOffset, 4)); $bsOffset += 4; - - - $ThisFileInfo['dts']['bitrate'] = $this->DTSbitrateLookup($ThisFileInfo['dts']['raw']['bitrate']); - $ThisFileInfo['dts']['bits_per_sample'] = $this->DTSbitPerSampleLookup($ThisFileInfo['dts']['raw']['bits_per_sample']); - $ThisFileInfo['dts']['sample_rate'] = $this->DTSsampleRateLookup($ThisFileInfo['dts']['raw']['sample_frequency']); - $ThisFileInfo['dts']['dialog_normalization'] = $this->DTSdialogNormalization($ThisFileInfo['dts']['raw']['dialog_normalization'], $ThisFileInfo['dts']['raw']['encoder_soft_version']); - $ThisFileInfo['dts']['flags']['lossless'] = (($ThisFileInfo['dts']['raw']['bitrate'] == 31) ? true : false); - $ThisFileInfo['dts']['bitrate_mode'] = (($ThisFileInfo['dts']['raw']['bitrate'] == 30) ? 'vbr' : 'cbr'); - $ThisFileInfo['dts']['channels'] = $this->DTSnumChannelsLookup($ThisFileInfo['dts']['raw']['channel_arrangement']); - $ThisFileInfo['dts']['channel_arrangement'] = $this->DTSchannelArrangementLookup($ThisFileInfo['dts']['raw']['channel_arrangement']); - - $ThisFileInfo['audio']['dataformat'] = 'dts'; - $ThisFileInfo['audio']['lossless'] = $ThisFileInfo['dts']['flags']['lossless']; - $ThisFileInfo['audio']['bitrate_mode'] = $ThisFileInfo['dts']['bitrate_mode']; - $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['dts']['bits_per_sample']; - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['dts']['sample_rate']; - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['dts']['channels']; - $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['dts']['bitrate']; - if (isset($ThisFileInfo['avdataend'])) { - $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / ($ThisFileInfo['dts']['bitrate'] / 8); - } - - return true; - } - - function DTSbitrateLookup($index) { - $DTSbitrateLookup = array( - 0 => 32000, - 1 => 56000, - 2 => 64000, - 3 => 96000, - 4 => 112000, - 5 => 128000, - 6 => 192000, - 7 => 224000, - 8 => 256000, - 9 => 320000, - 10 => 384000, - 11 => 448000, - 12 => 512000, - 13 => 576000, - 14 => 640000, - 15 => 768000, - 16 => 960000, - 17 => 1024000, - 18 => 1152000, - 19 => 1280000, - 20 => 1344000, - 21 => 1408000, - 22 => 1411200, - 23 => 1472000, - 24 => 1536000, - 25 => 1920000, - 26 => 2048000, - 27 => 3072000, - 28 => 3840000, - 29 => 'open', - 30 => 'variable', - 31 => 'lossless' - ); - return (isset($DTSbitrateLookup[$index]) ? $DTSbitrateLookup[$index] : false); - } - - function DTSsampleRateLookup($index) { - $DTSsampleRateLookup = array( - 0 => 'invalid', - 1 => 8000, - 2 => 16000, - 3 => 32000, - 4 => 'invalid', - 5 => 'invalid', - 6 => 11025, - 7 => 22050, - 8 => 44100, - 9 => 'invalid', - 10 => 'invalid', - 11 => 12000, - 12 => 24000, - 13 => 48000, - 14 => 'invalid', - 15 => 'invalid' - ); - return (isset($DTSsampleRateLookup[$index]) ? $DTSsampleRateLookup[$index] : false); - } - - function DTSbitPerSampleLookup($index) { - $DTSbitPerSampleLookup = array( - 0 => 16, - 1 => 20, - 2 => 24, - 3 => 24, - ); - return (isset($DTSbitPerSampleLookup[$index]) ? $DTSbitPerSampleLookup[$index] : false); - } - - function DTSnumChannelsLookup($index) { - switch ($index) { - case 0: - return 1; - break; - case 1: - case 2: - case 3: - case 4: - return 2; - break; - case 5: - case 6: - return 3; - break; - case 7: - case 8: - return 4; - break; - case 9: - return 5; - break; - case 10: - case 11: - case 12: - return 6; - break; - case 13: - return 7; - break; - case 14: - case 15: - return 8; - break; - } - return false; - } - - function DTSchannelArrangementLookup($index) { - $DTSchannelArrangementLookup = array( - 0 => 'A', - 1 => 'A + B (dual mono)', - 2 => 'L + R (stereo)', - 3 => '(L+R) + (L-R) (sum-difference)', - 4 => 'LT + RT (left and right total)', - 5 => 'C + L + R', - 6 => 'L + R + S', - 7 => 'C + L + R + S', - 8 => 'L + R + SL + SR', - 9 => 'C + L + R + SL + SR', - 10 => 'CL + CR + L + R + SL + SR', - 11 => 'C + L + R+ LR + RR + OV', - 12 => 'CF + CR + LF + RF + LR + RR', - 13 => 'CL + C + CR + L + R + SL + SR', - 14 => 'CL + CR + L + R + SL1 + SL2 + SR1 + SR2', - 15 => 'CL + C+ CR + L + R + SL + S + SR', - ); - return (isset($DTSchannelArrangementLookup[$index]) ? $DTSchannelArrangementLookup[$index] : 'user-defined'); - } - - function DTSdialogNormalization($index, $version) { - switch ($version) { - case 7: - return 0 - $index; - break; - case 6: - return 0 - 16 - $index; - break; - } - return false; - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.flac.php b/serendipity_event_podcast/player/getid3/module.audio.flac.php deleted file mode 100644 index 60d7f78c..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.flac.php +++ /dev/null @@ -1,403 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.flac.php // -// module for analyzing FLAC and OggFLAC audio files // -// dependencies: module.audio.ogg.php // -// /// -///////////////////////////////////////////////////////////////// - - -getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, true); - -class getid3_flac -{ - - function getid3_flac(&$fd, &$ThisFileInfo) { - // http://flac.sourceforge.net/format.html - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $StreamMarker = fread($fd, 4); - if ($StreamMarker != 'fLaC') { - $ThisFileInfo['error'][] = 'Expecting "fLaC" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$StreamMarker.'"'; - return false; - } - $ThisFileInfo['fileformat'] = 'flac'; - $ThisFileInfo['audio']['dataformat'] = 'flac'; - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; - $ThisFileInfo['audio']['lossless'] = true; - - return getid3_flac::FLACparseMETAdata($fd, $ThisFileInfo); - } - - - static function FLACparseMETAdata(&$fd, &$ThisFileInfo) { - - do { - $METAdataBlockOffset = ftell($fd); - $METAdataBlockHeader = fread($fd, 4); - $METAdataLastBlockFlag = (bool) (getid3_lib::BigEndian2Int(substr($METAdataBlockHeader, 0, 1)) & 0x80); - $METAdataBlockType = getid3_lib::BigEndian2Int(substr($METAdataBlockHeader, 0, 1)) & 0x7F; - $METAdataBlockLength = getid3_lib::BigEndian2Int(substr($METAdataBlockHeader, 1, 3)); - $METAdataBlockTypeText = getid3_flac::FLACmetaBlockTypeLookup($METAdataBlockType); - - if ($METAdataBlockLength < 0) { - $ThisFileInfo['error'][] = 'corrupt or invalid METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$METAdataBlockType.') at offset '.$METAdataBlockOffset; - break; - } - - $ThisFileInfo['flac'][$METAdataBlockTypeText]['raw'] = array(); - $ThisFileInfo_flac_METAdataBlockTypeText_raw = &$ThisFileInfo['flac'][$METAdataBlockTypeText]['raw']; - - $ThisFileInfo_flac_METAdataBlockTypeText_raw['offset'] = $METAdataBlockOffset; - $ThisFileInfo_flac_METAdataBlockTypeText_raw['last_meta_block'] = $METAdataLastBlockFlag; - $ThisFileInfo_flac_METAdataBlockTypeText_raw['block_type'] = $METAdataBlockType; - $ThisFileInfo_flac_METAdataBlockTypeText_raw['block_type_text'] = $METAdataBlockTypeText; - $ThisFileInfo_flac_METAdataBlockTypeText_raw['block_length'] = $METAdataBlockLength; - ob_start(); - $ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'] = fread($fd, $METAdataBlockLength); - $errormessage = ob_get_contents(); - ob_end_clean(); - $ThisFileInfo['avdataoffset'] = ftell($fd); - - switch ($METAdataBlockTypeText) { - case 'STREAMINFO': // 0x00 - if (!getid3_flac::FLACparseSTREAMINFO($ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'], $ThisFileInfo)) { - return false; - } - break; - - case 'PADDING': // 0x01 - // ignore - break; - - case 'APPLICATION': // 0x02 - if (!getid3_flac::FLACparseAPPLICATION($ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'], $ThisFileInfo)) { - return false; - } - break; - - case 'SEEKTABLE': // 0x03 - if (!getid3_flac::FLACparseSEEKTABLE($ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'], $ThisFileInfo)) { - return false; - } - break; - - case 'VORBIS_COMMENT': // 0x04 - $OldOffset = ftell($fd); - fseek($fd, 0 - $METAdataBlockLength, SEEK_CUR); - getid3_ogg::ParseVorbisCommentsFilepointer($fd, $ThisFileInfo); - fseek($fd, $OldOffset, SEEK_SET); - break; - - case 'CUESHEET': // 0x05 - if (!getid3_flac::FLACparseCUESHEET($ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'], $ThisFileInfo)) { - return false; - } - break; - - case 'PICTURE': // 0x06 - if (!getid3_flac::FLACparsePICTURE($ThisFileInfo_flac_METAdataBlockTypeText_raw['block_data'], $ThisFileInfo)) { - return false; - } - break; - - default: - $ThisFileInfo['warning'][] = 'Unhandled METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$METAdataBlockType.') at offset '.$METAdataBlockOffset; - break; - } - - } while ($METAdataLastBlockFlag === false); - - - if (isset($ThisFileInfo['flac']['STREAMINFO'])) { - $ThisFileInfo['flac']['compressed_audio_bytes'] = $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']; - $ThisFileInfo['flac']['uncompressed_audio_bytes'] = $ThisFileInfo['flac']['STREAMINFO']['samples_stream'] * $ThisFileInfo['flac']['STREAMINFO']['channels'] * ($ThisFileInfo['flac']['STREAMINFO']['bits_per_sample'] / 8); - if ($ThisFileInfo['flac']['uncompressed_audio_bytes'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt FLAC file: uncompressed_audio_bytes == zero'; - return false; - } - $ThisFileInfo['flac']['compression_ratio'] = $ThisFileInfo['flac']['compressed_audio_bytes'] / $ThisFileInfo['flac']['uncompressed_audio_bytes']; - } - - // set md5_data_source - built into flac 0.5+ - if (isset($ThisFileInfo['flac']['STREAMINFO']['audio_signature'])) { - - if ($ThisFileInfo['flac']['STREAMINFO']['audio_signature'] === str_repeat("\x00", 16)) { - - $ThisFileInfo['warning'][] = 'FLAC STREAMINFO.audio_signature is null (known issue with libOggFLAC)'; - - } else { - - $ThisFileInfo['md5_data_source'] = ''; - $md5 = $ThisFileInfo['flac']['STREAMINFO']['audio_signature']; - for ($i = 0; $i < strlen($md5); $i++) { - $ThisFileInfo['md5_data_source'] .= str_pad(dechex(ord($md5{$i})), 2, '00', STR_PAD_LEFT); - } - if (!preg_match('/^[0-9a-f]{32}$/', $ThisFileInfo['md5_data_source'])) { - unset($ThisFileInfo['md5_data_source']); - } - - } - - } - - $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['flac']['STREAMINFO']['bits_per_sample']; - if ($ThisFileInfo['audio']['bits_per_sample'] == 8) { - // special case - // must invert sign bit on all data bytes before MD5'ing to match FLAC's calculated value - // MD5sum calculates on unsigned bytes, but FLAC calculated MD5 on 8-bit audio data as signed - $ThisFileInfo['warning'][] = 'FLAC calculates MD5 data strangely on 8-bit audio, so the stored md5_data_source value will not match the decoded WAV file'; - } - if (!empty($ThisFileInfo['ogg']['vendor'])) { - $ThisFileInfo['audio']['encoder'] = $ThisFileInfo['ogg']['vendor']; - } - - return true; - } - - static function FLACmetaBlockTypeLookup($blocktype) { - static $FLACmetaBlockTypeLookup = array(); - if (empty($FLACmetaBlockTypeLookup)) { - $FLACmetaBlockTypeLookup[0] = 'STREAMINFO'; - $FLACmetaBlockTypeLookup[1] = 'PADDING'; - $FLACmetaBlockTypeLookup[2] = 'APPLICATION'; - $FLACmetaBlockTypeLookup[3] = 'SEEKTABLE'; - $FLACmetaBlockTypeLookup[4] = 'VORBIS_COMMENT'; - $FLACmetaBlockTypeLookup[5] = 'CUESHEET'; - $FLACmetaBlockTypeLookup[6] = 'PICTURE'; - } - return (isset($FLACmetaBlockTypeLookup[$blocktype]) ? $FLACmetaBlockTypeLookup[$blocktype] : 'reserved'); - } - - static function FLACapplicationIDLookup($applicationid) { - static $FLACapplicationIDLookup = array(); - if (empty($FLACapplicationIDLookup)) { - // http://flac.sourceforge.net/id.html - $FLACapplicationIDLookup[0x46746F6C] = 'flac-tools'; // 'Ftol' - $FLACapplicationIDLookup[0x46746F6C] = 'Sound Font FLAC'; // 'SFFL' - } - return (isset($FLACapplicationIDLookup[$applicationid]) ? $FLACapplicationIDLookup[$applicationid] : 'reserved'); - } - - static function FLACpictureTypeLookup($type_id) { - static $lookup = array ( - 0 => 'Other', - 1 => '32x32 pixels \'file icon\' (PNG only)', - 2 => 'Other file icon', - 3 => 'Cover (front)', - 4 => 'Cover (back)', - 5 => 'Leaflet page', - 6 => 'Media (e.g. label side of CD)', - 7 => 'Lead artist/lead performer/soloist', - 8 => 'Artist/performer', - 9 => 'Conductor', - 10 => 'Band/Orchestra', - 11 => 'Composer', - 12 => 'Lyricist/text writer', - 13 => 'Recording Location', - 14 => 'During recording', - 15 => 'During performance', - 16 => 'Movie/video screen capture', - 17 => 'A bright coloured fish', - 18 => 'Illustration', - 19 => 'Band/artist logotype', - 20 => 'Publisher/Studio logotype', - ); - return (isset($lookup[$type_id]) ? $lookup[$type_id] : 'reserved'); - } - - static function FLACparseSTREAMINFO($METAdataBlockData, &$ThisFileInfo) { - $offset = 0; - $ThisFileInfo['flac']['STREAMINFO']['min_block_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 2)); - $offset += 2; - $ThisFileInfo['flac']['STREAMINFO']['max_block_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 2)); - $offset += 2; - $ThisFileInfo['flac']['STREAMINFO']['min_frame_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 3)); - $offset += 3; - $ThisFileInfo['flac']['STREAMINFO']['max_frame_size'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 3)); - $offset += 3; - - $SampleRateChannelsSampleBitsStreamSamples = getid3_lib::BigEndian2Bin(substr($METAdataBlockData, $offset, 8)); - $ThisFileInfo['flac']['STREAMINFO']['sample_rate'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 0, 20)); - $ThisFileInfo['flac']['STREAMINFO']['channels'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 20, 3)) + 1; - $ThisFileInfo['flac']['STREAMINFO']['bits_per_sample'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 23, 5)) + 1; - $ThisFileInfo['flac']['STREAMINFO']['samples_stream'] = getid3_lib::Bin2Dec(substr($SampleRateChannelsSampleBitsStreamSamples, 28, 36)); - $offset += 8; - - $ThisFileInfo['flac']['STREAMINFO']['audio_signature'] = substr($METAdataBlockData, $offset, 16); - $offset += 16; - - if (!empty($ThisFileInfo['flac']['STREAMINFO']['sample_rate'])) { - - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['flac']['STREAMINFO']['sample_rate']; - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['flac']['STREAMINFO']['channels']; - $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['flac']['STREAMINFO']['bits_per_sample']; - $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['flac']['STREAMINFO']['samples_stream'] / $ThisFileInfo['flac']['STREAMINFO']['sample_rate']; - if ($ThisFileInfo['playtime_seconds'] > 0) { - $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; - } - - } else { - - $ThisFileInfo['error'][] = 'Corrupt METAdata block: STREAMINFO'; - return false; - - } - - unset($ThisFileInfo['flac']['STREAMINFO']['raw']); - - return true; - } - - - static function FLACparseAPPLICATION($METAdataBlockData, &$ThisFileInfo) { - $offset = 0; - $ApplicationID = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 4)); - $offset += 4; - $ThisFileInfo['flac']['APPLICATION'][$ApplicationID]['name'] = getid3_flac::FLACapplicationIDLookup($ApplicationID); - $ThisFileInfo['flac']['APPLICATION'][$ApplicationID]['data'] = substr($METAdataBlockData, $offset); - $offset = $METAdataBlockLength; - - unset($ThisFileInfo['flac']['APPLICATION']['raw']); - - return true; - } - - - static function FLACparseSEEKTABLE($METAdataBlockData, &$ThisFileInfo) { - $offset = 0; - $METAdataBlockLength = strlen($METAdataBlockData); - $placeholderpattern = str_repeat("\xFF", 8); - while ($offset < $METAdataBlockLength) { - $SampleNumberString = substr($METAdataBlockData, $offset, 8); - $offset += 8; - if ($SampleNumberString == $placeholderpattern) { - - // placeholder point - getid3_lib::safe_inc($ThisFileInfo['flac']['SEEKTABLE']['placeholders'], 1); - $offset += 10; - - } else { - - $SampleNumber = getid3_lib::BigEndian2Int($SampleNumberString); - $ThisFileInfo['flac']['SEEKTABLE'][$SampleNumber]['offset'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 8)); - $offset += 8; - $ThisFileInfo['flac']['SEEKTABLE'][$SampleNumber]['samples'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 2)); - $offset += 2; - - } - } - - unset($ThisFileInfo['flac']['SEEKTABLE']['raw']); - - return true; - } - - static function FLACparseCUESHEET($METAdataBlockData, &$ThisFileInfo) { - $offset = 0; - $ThisFileInfo['flac']['CUESHEET']['media_catalog_number'] = trim(substr($METAdataBlockData, $offset, 128), "\0"); - $offset += 128; - $ThisFileInfo['flac']['CUESHEET']['lead_in_samples'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 8)); - $offset += 8; - $ThisFileInfo['flac']['CUESHEET']['flags']['is_cd'] = (bool) (getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1)) & 0x80); - $offset += 1; - - $offset += 258; // reserved - - $ThisFileInfo['flac']['CUESHEET']['number_tracks'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1)); - $offset += 1; - - for ($track = 0; $track < $ThisFileInfo['flac']['CUESHEET']['number_tracks']; $track++) { - $TrackSampleOffset = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 8)); - $offset += 8; - $TrackNumber = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1)); - $offset += 1; - - $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['sample_offset'] = $TrackSampleOffset; - - $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['isrc'] = substr($METAdataBlockData, $offset, 12); - $offset += 12; - - $TrackFlagsRaw = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1)); - $offset += 1; - $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['is_audio'] = (bool) ($TrackFlagsRaw & 0x80); - $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['pre_emphasis'] = (bool) ($TrackFlagsRaw & 0x40); - - $offset += 13; // reserved - - $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points'] = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1)); - $offset += 1; - - for ($index = 0; $index < $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points']; $index++) { - $IndexSampleOffset = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 8)); - $offset += 8; - $IndexNumber = getid3_lib::BigEndian2Int(substr($METAdataBlockData, $offset, 1)); - $offset += 1; - - $offset += 3; // reserved - - $ThisFileInfo['flac']['CUESHEET']['tracks'][$TrackNumber]['indexes'][$IndexNumber] = $IndexSampleOffset; - } - } - - unset($ThisFileInfo['flac']['CUESHEET']['raw']); - - return true; - } - - - static function FLACparsePICTURE($meta_data_block_data, &$ThisFileInfo) { - $picture = &$ThisFileInfo['flac']['PICTURE'][sizeof($ThisFileInfo['flac']['PICTURE']) - 1]; - - $offset = 0; - - $picture['typeid'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); - $picture['type'] = getid3_flac::FLACpictureTypeLookup($picture['typeid']); - $offset += 4; - - $length = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); - $offset += 4; - - $picture['mime_type'] = substr($meta_data_block_data, $offset, $length); - $offset += $length; - - $length = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); - $offset += 4; - - $picture['description'] = substr($meta_data_block_data, $offset, $length); - $offset += $length; - - $picture['width'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); - $offset += 4; - - $picture['height'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); - $offset += 4; - - $picture['color_depth'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); - $offset += 4; - - $picture['colors_indexed'] = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); - $offset += 4; - - $length = getid3_lib::BigEndian2Int(substr($meta_data_block_data, $offset, 4)); - $offset += 4; - - $picture['image_data'] = substr($meta_data_block_data, $offset, $length); - $offset += $length; - $picture['data_length'] = strlen($picture['image_data']); - - unset($ThisFileInfo['flac']['PICTURE']['raw']); - - return true; - } -} - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.la.php b/serendipity_event_podcast/player/getid3/module.audio.la.php deleted file mode 100644 index fe2caa64..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.la.php +++ /dev/null @@ -1,228 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.la.php // -// module for analyzing LA (LosslessAudio) audio files // -// dependencies: module.audio.riff.php // -// /// -///////////////////////////////////////////////////////////////// - -getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); - -class getid3_la -{ - - function getid3_la(&$fd, &$ThisFileInfo) { - $offset = 0; - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $rawdata = fread($fd, GETID3_FREAD_BUFFER_SIZE); - - switch (substr($rawdata, $offset, 4)) { - case 'LA02': - case 'LA03': - case 'LA04': - $ThisFileInfo['fileformat'] = 'la'; - $ThisFileInfo['audio']['dataformat'] = 'la'; - $ThisFileInfo['audio']['lossless'] = true; - - $ThisFileInfo['la']['version_major'] = (int) substr($rawdata, $offset + 2, 1); - $ThisFileInfo['la']['version_minor'] = (int) substr($rawdata, $offset + 3, 1); - $ThisFileInfo['la']['version'] = (float) $ThisFileInfo['la']['version_major'] + ($ThisFileInfo['la']['version_minor'] / 10); - $offset += 4; - - $ThisFileInfo['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; - if ($ThisFileInfo['la']['uncompressed_size'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt LA file: uncompressed_size == zero'; - return false; - } - - $WAVEchunk = substr($rawdata, $offset, 4); - if ($WAVEchunk !== 'WAVE') { - $ThisFileInfo['error'][] = 'Expected "WAVE" ('.getid3_lib::PrintHexBytes('WAVE').') at offset '.$offset.', found "'.$WAVEchunk.'" ('.getid3_lib::PrintHexBytes($WAVEchunk).') instead.'; - return false; - } - $offset += 4; - - $ThisFileInfo['la']['fmt_size'] = 24; - if ($ThisFileInfo['la']['version'] >= 0.3) { - - $ThisFileInfo['la']['fmt_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $ThisFileInfo['la']['header_size'] = 49 + $ThisFileInfo['la']['fmt_size'] - 24; - $offset += 4; - - } else { - - // version 0.2 didn't support additional data blocks - $ThisFileInfo['la']['header_size'] = 41; - - } - - $fmt_chunk = substr($rawdata, $offset, 4); - if ($fmt_chunk !== 'fmt ') { - $ThisFileInfo['error'][] = 'Expected "fmt " ('.getid3_lib::PrintHexBytes('fmt ').') at offset '.$offset.', found "'.$fmt_chunk.'" ('.getid3_lib::PrintHexBytes($fmt_chunk).') instead.'; - return false; - } - $offset += 4; - $fmt_size = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; - - $ThisFileInfo['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); - $offset += 2; - - $ThisFileInfo['la']['channels'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); - $offset += 2; - if ($ThisFileInfo['la']['channels'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt LA file: channels == zero'; - return false; - } - - $ThisFileInfo['la']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; - if ($ThisFileInfo['la']['sample_rate'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt LA file: sample_rate == zero'; - return false; - } - - $ThisFileInfo['la']['bytes_per_second'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; - $ThisFileInfo['la']['bytes_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); - $offset += 2; - $ThisFileInfo['la']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); - $offset += 2; - - $ThisFileInfo['la']['samples'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; - - $ThisFileInfo['la']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 1)); - $offset += 1; - $ThisFileInfo['la']['flags']['seekable'] = (bool) ($ThisFileInfo['la']['raw']['flags'] & 0x01); - if ($ThisFileInfo['la']['version'] >= 0.4) { - $ThisFileInfo['la']['flags']['high_compression'] = (bool) ($ThisFileInfo['la']['raw']['flags'] & 0x02); - } - - $ThisFileInfo['la']['original_crc'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; - - // mikeØbevin*de - // Basically, the blocksize/seekevery are 61440/19 in La0.4 and 73728/16 - // in earlier versions. A seekpoint is added every blocksize * seekevery - // samples, so 4 * int(totalSamples / (blockSize * seekEvery)) should - // give the number of bytes used for the seekpoints. Of course, if seeking - // is disabled, there are no seekpoints stored. - if ($ThisFileInfo['la']['version'] >= 0.4) { - $ThisFileInfo['la']['blocksize'] = 61440; - $ThisFileInfo['la']['seekevery'] = 19; - } else { - $ThisFileInfo['la']['blocksize'] = 73728; - $ThisFileInfo['la']['seekevery'] = 16; - } - - $ThisFileInfo['la']['seekpoint_count'] = 0; - if ($ThisFileInfo['la']['flags']['seekable']) { - $ThisFileInfo['la']['seekpoint_count'] = floor($ThisFileInfo['la']['samples'] / ($ThisFileInfo['la']['blocksize'] * $ThisFileInfo['la']['seekevery'])); - - for ($i = 0; $i < $ThisFileInfo['la']['seekpoint_count']; $i++) { - $ThisFileInfo['la']['seekpoints'][] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; - } - } - - if ($ThisFileInfo['la']['version'] >= 0.3) { - - // Following the main header information, the program outputs all of the - // seekpoints. Following these is what I called the 'footer start', - // i.e. the position immediately after the La audio data is finished. - $ThisFileInfo['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); - $offset += 4; - - if ($ThisFileInfo['la']['footerstart'] > $ThisFileInfo['filesize']) { - $ThisFileInfo['warning'][] = 'FooterStart value points to offset '.$ThisFileInfo['la']['footerstart'].' which is beyond end-of-file ('.$ThisFileInfo['filesize'].')'; - $ThisFileInfo['la']['footerstart'] = $ThisFileInfo['filesize']; - } - - } else { - - // La v0.2 didn't have FooterStart value - $ThisFileInfo['la']['footerstart'] = $ThisFileInfo['avdataend']; - - } - - if ($ThisFileInfo['la']['footerstart'] < $ThisFileInfo['avdataend']) { - if ($RIFFtempfilename = tempnam(GETID3_TEMP_DIR, 'id3')) { - if ($RIFF_fp = fopen($RIFFtempfilename, 'w+b')) { - $RIFFdata = 'WAVE'; - if ($ThisFileInfo['la']['version'] == 0.2) { - $RIFFdata .= substr($rawdata, 12, 24); - } else { - $RIFFdata .= substr($rawdata, 16, 24); - } - if ($ThisFileInfo['la']['footerstart'] < $ThisFileInfo['avdataend']) { - fseek($fd, $ThisFileInfo['la']['footerstart'], SEEK_SET); - $RIFFdata .= fread($fd, $ThisFileInfo['avdataend'] - $ThisFileInfo['la']['footerstart']); - } - $RIFFdata = 'RIFF'.getid3_lib::LittleEndian2String(strlen($RIFFdata), 4, false).$RIFFdata; - fwrite($RIFF_fp, $RIFFdata, strlen($RIFFdata)); - $dummy = $ThisFileInfo; - $dummy['filesize'] = strlen($RIFFdata); - $dummy['avdataoffset'] = 0; - $dummy['avdataend'] = $dummy['filesize']; - - $riff = new getid3_riff($RIFF_fp, $dummy); - if (empty($dummy['error'])) { - $ThisFileInfo['riff'] = $dummy['riff']; - } else { - $ThisFileInfo['warning'][] = 'Error parsing RIFF portion of La file: '.implode($dummy['error']); - } - unset($riff); - unset($dummy); - fclose($RIFF_fp); - } - unlink($RIFFtempfilename); - } - } - - // $ThisFileInfo['avdataoffset'] should be zero to begin with, but just in case it's not, include the addition anyway - $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $ThisFileInfo['la']['footerstart']; - $ThisFileInfo['avdataoffset'] = $ThisFileInfo['avdataoffset'] + $offset; - - //$ThisFileInfo['la']['codec'] = RIFFwFormatTagLookup($ThisFileInfo['la']['raw']['format']); - $ThisFileInfo['la']['compression_ratio'] = (float) (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['la']['uncompressed_size']); - $ThisFileInfo['playtime_seconds'] = (float) ($ThisFileInfo['la']['samples'] / $ThisFileInfo['la']['sample_rate']) / $ThisFileInfo['la']['channels']; - if ($ThisFileInfo['playtime_seconds'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt LA file: playtime_seconds == zero'; - return false; - } - - $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds']; - //$ThisFileInfo['audio']['codec'] = $ThisFileInfo['la']['codec']; - $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['la']['bits_per_sample']; - break; - - default: - if (substr($rawdata, $offset, 2) == 'LA') { - $ThisFileInfo['error'][] = 'This version of getID3() (v'.GETID3_VERSION.') doesn\'t support LA version '.substr($rawdata, $offset + 2, 1).'.'.substr($rawdata, $offset + 3, 1).' which this appears to be - check http://getid3.sourceforge.net for updates.'; - } else { - $ThisFileInfo['error'][] = 'Not a LA (Lossless-Audio) file'; - } - return false; - break; - } - - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['la']['channels']; - $ThisFileInfo['audio']['sample_rate'] = (int) $ThisFileInfo['la']['sample_rate']; - $ThisFileInfo['audio']['encoder'] = 'LA v'.$ThisFileInfo['la']['version']; - - return true; - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.lpac.php b/serendipity_event_podcast/player/getid3/module.audio.lpac.php deleted file mode 100644 index 3c044921..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.lpac.php +++ /dev/null @@ -1,126 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.lpac.php // -// module for analyzing LPAC Audio files // -// dependencies: module.audio-video.riff.php // -// /// -///////////////////////////////////////////////////////////////// - -getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); - -class getid3_lpac -{ - - function getid3_lpac(&$fd, &$ThisFileInfo) { - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $LPACheader = fread($fd, 14); - if (substr($LPACheader, 0, 4) != 'LPAC') { - $ThisFileInfo['error'][] = 'Expected "LPAC" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$StreamMarker.'"'; - return false; - } - $ThisFileInfo['avdataoffset'] += 14; - - $ThisFileInfo['fileformat'] = 'lpac'; - $ThisFileInfo['audio']['dataformat'] = 'lpac'; - $ThisFileInfo['audio']['lossless'] = true; - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; - - $ThisFileInfo['lpac']['file_version'] = getid3_lib::BigEndian2Int(substr($LPACheader, 4, 1)); - $flags['audio_type'] = getid3_lib::BigEndian2Int(substr($LPACheader, 5, 1)); - $ThisFileInfo['lpac']['total_samples']= getid3_lib::BigEndian2Int(substr($LPACheader, 6, 4)); - $flags['parameters'] = getid3_lib::BigEndian2Int(substr($LPACheader, 10, 4)); - - $ThisFileInfo['lpac']['flags']['is_wave'] = (bool) ($flags['audio_type'] & 0x40); - $ThisFileInfo['lpac']['flags']['stereo'] = (bool) ($flags['audio_type'] & 0x04); - $ThisFileInfo['lpac']['flags']['24_bit'] = (bool) ($flags['audio_type'] & 0x02); - $ThisFileInfo['lpac']['flags']['16_bit'] = (bool) ($flags['audio_type'] & 0x01); - - if ($ThisFileInfo['lpac']['flags']['24_bit'] && $ThisFileInfo['lpac']['flags']['16_bit']) { - $ThisFileInfo['warning'][] = '24-bit and 16-bit flags cannot both be set'; - } - - $ThisFileInfo['lpac']['flags']['fast_compress'] = (bool) ($flags['parameters'] & 0x40000000); - $ThisFileInfo['lpac']['flags']['random_access'] = (bool) ($flags['parameters'] & 0x08000000); - $ThisFileInfo['lpac']['block_length'] = pow(2, (($flags['parameters'] & 0x07000000) >> 24)) * 256; - $ThisFileInfo['lpac']['flags']['adaptive_prediction_order'] = (bool) ($flags['parameters'] & 0x00800000); - $ThisFileInfo['lpac']['flags']['adaptive_quantization'] = (bool) ($flags['parameters'] & 0x00400000); - $ThisFileInfo['lpac']['flags']['joint_stereo'] = (bool) ($flags['parameters'] & 0x00040000); - $ThisFileInfo['lpac']['quantization'] = ($flags['parameters'] & 0x00001F00) >> 8; - $ThisFileInfo['lpac']['max_prediction_order'] = ($flags['parameters'] & 0x0000003F); - - if ($ThisFileInfo['lpac']['flags']['fast_compress'] && ($ThisFileInfo['lpac']['max_prediction_order'] != 3)) { - $ThisFileInfo['warning'][] = 'max_prediction_order expected to be "3" if fast_compress is true, actual value is "'.$ThisFileInfo['lpac']['max_prediction_order'].'"'; - } - switch ($ThisFileInfo['lpac']['file_version']) { - case 6: - if ($ThisFileInfo['lpac']['flags']['adaptive_quantization']) { - $ThisFileInfo['warning'][] = 'adaptive_quantization expected to be false in LPAC file stucture v6, actually true'; - } - if ($ThisFileInfo['lpac']['quantization'] != 20) { - $ThisFileInfo['warning'][] = 'Quantization expected to be 20 in LPAC file stucture v6, actually '.$ThisFileInfo['lpac']['flags']['Q']; - } - break; - - default: - //$ThisFileInfo['warning'][] = 'This version of getID3() only supports LPAC file format version 6, this file is version '.$ThisFileInfo['lpac']['file_version'].' - please report to info@getid3.org'; - break; - } - - $dummy = $ThisFileInfo; - $riff = new getid3_riff($fd, $dummy); - unset($riff); - $ThisFileInfo['avdataoffset'] = $dummy['avdataoffset']; - $ThisFileInfo['riff'] = $dummy['riff']; - $ThisFileInfo['error'] = $dummy['error']; - $ThisFileInfo['warning'] = $dummy['warning']; - $ThisFileInfo['lpac']['comments']['comment'] = $dummy['comments']; - $ThisFileInfo['audio']['sample_rate'] = $dummy['audio']['sample_rate']; - - $ThisFileInfo['audio']['channels'] = ($ThisFileInfo['lpac']['flags']['stereo'] ? 2 : 1); - - if ($ThisFileInfo['lpac']['flags']['24_bit']) { - $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['riff']['audio'][0]['bits_per_sample']; - } elseif ($ThisFileInfo['lpac']['flags']['16_bit']) { - $ThisFileInfo['audio']['bits_per_sample'] = 16; - } else { - $ThisFileInfo['audio']['bits_per_sample'] = 8; - } - - if ($ThisFileInfo['lpac']['flags']['fast_compress']) { - // fast - $ThisFileInfo['audio']['encoder_options'] = '-1'; - } else { - switch ($ThisFileInfo['lpac']['max_prediction_order']) { - case 20: // simple - $ThisFileInfo['audio']['encoder_options'] = '-2'; - break; - case 30: // medium - $ThisFileInfo['audio']['encoder_options'] = '-3'; - break; - case 40: // high - $ThisFileInfo['audio']['encoder_options'] = '-4'; - break; - case 60: // extrahigh - $ThisFileInfo['audio']['encoder_options'] = '-5'; - break; - } - } - - $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['lpac']['total_samples'] / $ThisFileInfo['audio']['sample_rate']; - $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; - - return true; - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.mod.php b/serendipity_event_podcast/player/getid3/module.audio.mod.php deleted file mode 100644 index d5d3ea12..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.mod.php +++ /dev/null @@ -1,101 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.mod.php // -// module for analyzing MOD Audio files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_mod -{ - - // new combined constructor - function getid3_mod(&$fd, &$ThisFileInfo, $option) { - - if ($option === 'mod') { - $this->getMODheaderFilepointer($fd, $ThisFileInfo); - } - elseif ($option === 'xm') { - $this->getXMheaderFilepointer($fd, $ThisFileInfo); - } - elseif ($option === 'it') { - $this->getITheaderFilepointer($fd, $ThisFileInfo); - } - elseif ($option === 's3m') { - $this->getS3MheaderFilepointer($fd, $ThisFileInfo); - } - } - - - function getMODheaderFilepointer(&$fd, &$ThisFileInfo) { - - fseek($fd, $ThisFileInfo['avdataoffset'] + 1080); - $FormatID = fread($fd, 4); - if (!preg_match('#^(M.K.|[5-9]CHN|[1-3][0-9]CH)$#', $FormatID)) { - $ThisFileInfo['error'][] = 'This is not a known type of MOD file'; - return false; - } - - $ThisFileInfo['fileformat'] = 'mod'; - - $ThisFileInfo['error'][] = 'MOD parsing not enabled in this version of getID3()'; - return false; - } - - function getXMheaderFilepointer(&$fd, &$ThisFileInfo) { - - fseek($fd, $ThisFileInfo['avdataoffset']); - $FormatID = fread($fd, 15); - if (!preg_match('#^Extended Module$#', $FormatID)) { - $ThisFileInfo['error'][] = 'This is not a known type of XM-MOD file'; - return false; - } - - $ThisFileInfo['fileformat'] = 'xm'; - - $ThisFileInfo['error'][] = 'XM-MOD parsing not enabled in this version of getID3()'; - return false; - } - - function getS3MheaderFilepointer(&$fd, &$ThisFileInfo) { - - fseek($fd, $ThisFileInfo['avdataoffset'] + 44); - $FormatID = fread($fd, 4); - if (!preg_match('#^SCRM$#', $FormatID)) { - $ThisFileInfo['error'][] = 'This is not a ScreamTracker MOD file'; - return false; - } - - $ThisFileInfo['fileformat'] = 's3m'; - - $ThisFileInfo['error'][] = 'ScreamTracker parsing not enabled in this version of getID3()'; - return false; - } - - function getITheaderFilepointer(&$fd, &$ThisFileInfo) { - - fseek($fd, $ThisFileInfo['avdataoffset']); - $FormatID = fread($fd, 4); - if (!preg_match('#^IMPM$#', $FormatID)) { - $ThisFileInfo['error'][] = 'This is not an ImpulseTracker MOD file'; - return false; - } - - $ThisFileInfo['fileformat'] = 'it'; - - $ThisFileInfo['error'][] = 'ImpulseTracker parsing not enabled in this version of getID3()'; - return false; - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.ogg.php b/serendipity_event_podcast/player/getid3/module.audio.ogg.php deleted file mode 100644 index 968f0b58..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.ogg.php +++ /dev/null @@ -1,574 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.ogg.php // -// module for analyzing Ogg Vorbis, OggFLAC and Speex files // -// dependencies: module.audio.flac.php // -// /// -///////////////////////////////////////////////////////////////// - -getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.flac.php', __FILE__, true); - -class getid3_ogg -{ - - function getid3_ogg(&$fd, &$ThisFileInfo) { - - $ThisFileInfo['fileformat'] = 'ogg'; - - // Warn about illegal tags - only vorbiscomments are allowed - if (isset($ThisFileInfo['id3v2'])) { - $ThisFileInfo['warning'][] = 'Illegal ID3v2 tag present.'; - } - if (isset($ThisFileInfo['id3v1'])) { - $ThisFileInfo['warning'][] = 'Illegal ID3v1 tag present.'; - } - if (isset($ThisFileInfo['ape'])) { - $ThisFileInfo['warning'][] = 'Illegal APE tag present.'; - } - - - // Page 1 - Stream Header - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - - $oggpageinfo = getid3_ogg::ParseOggPageHeader($fd); - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; - - if (ftell($fd) >= GETID3_FREAD_BUFFER_SIZE) { - $ThisFileInfo['error'][] = 'Could not find start of Ogg page in the first '.GETID3_FREAD_BUFFER_SIZE.' bytes (this might not be an Ogg-Vorbis file?)'; - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['ogg']); - return false; - } - - $filedata = fread($fd, $oggpageinfo['page_length']); - $filedataoffset = 0; - - if (substr($filedata, 0, 4) == 'fLaC') { - - $ThisFileInfo['audio']['dataformat'] = 'flac'; - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; - $ThisFileInfo['audio']['lossless'] = true; - - } elseif (substr($filedata, 1, 6) == 'vorbis') { - - $this->ParseVorbisPageHeader($filedata, $filedataoffset, $ThisFileInfo, $oggpageinfo); - - } elseif (substr($filedata, 0, 8) == 'Speex ') { - - // http://www.speex.org/manual/node10.html - - $ThisFileInfo['audio']['dataformat'] = 'speex'; - $ThisFileInfo['mime_type'] = 'audio/speex'; - $ThisFileInfo['audio']['bitrate_mode'] = 'abr'; - $ThisFileInfo['audio']['lossless'] = false; - - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_string'] = substr($filedata, $filedataoffset, 8); // hard-coded to 'Speex ' - $filedataoffset += 8; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version'] = substr($filedata, $filedataoffset, 20); - $filedataoffset += 20; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version_id'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['header_size'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['rate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode_bitstream_version'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['nb_channels'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['bitrate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['framesize'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['vbr'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['frames_per_packet'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['extra_headers'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['reserved1'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['reserved2'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - - $ThisFileInfo['speex']['speex_version'] = trim($ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version']); - $ThisFileInfo['speex']['sample_rate'] = $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['rate']; - $ThisFileInfo['speex']['channels'] = $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['nb_channels']; - $ThisFileInfo['speex']['vbr'] = (bool) $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['vbr']; - $ThisFileInfo['speex']['band_type'] = getid3_ogg::SpeexBandModeLookup($ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode']); - - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['speex']['sample_rate']; - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['speex']['channels']; - if ($ThisFileInfo['speex']['vbr']) { - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; - } - - } else { - - $ThisFileInfo['error'][] = 'Expecting either "Speex " or "vorbis" identifier strings, found neither'; - unset($ThisFileInfo['ogg']); - unset($ThisFileInfo['mime_type']); - return false; - - } - - - // Page 2 - Comment Header - - $oggpageinfo = getid3_ogg::ParseOggPageHeader($fd); - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; - - switch ($ThisFileInfo['audio']['dataformat']) { - - case 'vorbis': - $filedata = fread($fd, $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int(substr($filedata, 0, 1)); - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, 1, 6); // hard-coded to 'vorbis' - - getid3_ogg::ParseVorbisCommentsFilepointer($fd, $ThisFileInfo); - break; - - case 'flac': - if (!getid3_flac::FLACparseMETAdata($fd, $ThisFileInfo)) { - $ThisFileInfo['error'][] = 'Failed to parse FLAC headers'; - return false; - } - break; - - case 'speex': - fseek($fd, $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length'], SEEK_CUR); - getid3_ogg::ParseVorbisCommentsFilepointer($fd, $ThisFileInfo); - break; - - } - - - - // Last Page - Number of Samples - - if (!getid3_lib::intValueSupported($ThisFileInfo['avdataend'])) { - - $ThisFileInfo['warning'][] = 'Unable to parse Ogg end chunk file (PHP does not support file operations beyond '.round(PHP_INT_MAX / 1073741824).'GB)'; - - } else { - - fseek($fd, max($ThisFileInfo['avdataend'] - GETID3_FREAD_BUFFER_SIZE, 0), SEEK_SET); - $LastChunkOfOgg = strrev(fread($fd, GETID3_FREAD_BUFFER_SIZE)); - if ($LastOggSpostion = strpos($LastChunkOfOgg, 'SggO')) { - fseek($fd, $ThisFileInfo['avdataend'] - ($LastOggSpostion + strlen('SggO')), SEEK_SET); - $ThisFileInfo['avdataend'] = ftell($fd); - $ThisFileInfo['ogg']['pageheader']['eos'] = getid3_ogg::ParseOggPageHeader($fd); - $ThisFileInfo['ogg']['samples'] = $ThisFileInfo['ogg']['pageheader']['eos']['pcm_abs_position']; - if ($ThisFileInfo['ogg']['samples'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt Ogg file: eos.number of samples == zero'; - return false; - } - $ThisFileInfo['ogg']['bitrate_average'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / ($ThisFileInfo['ogg']['samples'] / $ThisFileInfo['audio']['sample_rate']); - } - - } - - if (!empty($ThisFileInfo['ogg']['bitrate_average'])) { - $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['ogg']['bitrate_average']; - } elseif (!empty($ThisFileInfo['ogg']['bitrate_nominal'])) { - $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['ogg']['bitrate_nominal']; - } elseif (!empty($ThisFileInfo['ogg']['bitrate_min']) && !empty($ThisFileInfo['ogg']['bitrate_max'])) { - $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['ogg']['bitrate_min'] + $ThisFileInfo['ogg']['bitrate_max']) / 2; - } - if (isset($ThisFileInfo['audio']['bitrate']) && !isset($ThisFileInfo['playtime_seconds'])) { - if ($ThisFileInfo['audio']['bitrate'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt Ogg file: bitrate_audio == zero'; - return false; - } - $ThisFileInfo['playtime_seconds'] = (float) ((($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['audio']['bitrate']); - } - - if (isset($ThisFileInfo['ogg']['vendor'])) { - $ThisFileInfo['audio']['encoder'] = preg_replace('/^Encoded with /', '', $ThisFileInfo['ogg']['vendor']); - - // Vorbis only - if ($ThisFileInfo['audio']['dataformat'] == 'vorbis') { - - // Vorbis 1.0 starts with Xiph.Org - if (preg_match('/^Xiph.Org/', $ThisFileInfo['audio']['encoder'])) { - - if ($ThisFileInfo['audio']['bitrate_mode'] == 'abr') { - - // Set -b 128 on abr files - $ThisFileInfo['audio']['encoder_options'] = '-b '.round($ThisFileInfo['ogg']['bitrate_nominal'] / 1000); - - } elseif (($ThisFileInfo['audio']['bitrate_mode'] == 'vbr') && ($ThisFileInfo['audio']['channels'] == 2) && ($ThisFileInfo['audio']['sample_rate'] >= 44100) && ($ThisFileInfo['audio']['sample_rate'] <= 48000)) { - // Set -q N on vbr files - $ThisFileInfo['audio']['encoder_options'] = '-q '.$this->get_quality_from_nominal_bitrate($ThisFileInfo['ogg']['bitrate_nominal']); - - } - } - - if (empty($ThisFileInfo['audio']['encoder_options']) && !empty($ThisFileInfo['ogg']['bitrate_nominal'])) { - $ThisFileInfo['audio']['encoder_options'] = 'Nominal bitrate: '.intval(round($ThisFileInfo['ogg']['bitrate_nominal'] / 1000)).'kbps'; - } - } - } - - return true; - } - - static function ParseVorbisPageHeader(&$filedata, &$filedataoffset, &$ThisFileInfo, &$oggpageinfo) { - $ThisFileInfo['audio']['dataformat'] = 'vorbis'; - $ThisFileInfo['audio']['lossless'] = false; - - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, $filedataoffset, 6); // hard-coded to 'vorbis' - $filedataoffset += 6; - $ThisFileInfo['ogg']['bitstreamversion'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['numberofchannels'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['ogg']['numberofchannels']; - $ThisFileInfo['ogg']['samplerate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - if ($ThisFileInfo['ogg']['samplerate'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt Ogg file: sample rate == zero'; - return false; - } - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['ogg']['samplerate']; - $ThisFileInfo['ogg']['samples'] = 0; // filled in later - $ThisFileInfo['ogg']['bitrate_average'] = 0; // filled in later - $ThisFileInfo['ogg']['bitrate_max'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['bitrate_nominal'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['bitrate_min'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $ThisFileInfo['ogg']['blocksize_small'] = pow(2, getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)) & 0x0F); - $ThisFileInfo['ogg']['blocksize_large'] = pow(2, (getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)) & 0xF0) >> 4); - $ThisFileInfo['ogg']['stop_bit'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); // must be 1, marks end of packet - - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; // overridden if actually abr - if ($ThisFileInfo['ogg']['bitrate_max'] == 0xFFFFFFFF) { - unset($ThisFileInfo['ogg']['bitrate_max']); - $ThisFileInfo['audio']['bitrate_mode'] = 'abr'; - } - if ($ThisFileInfo['ogg']['bitrate_nominal'] == 0xFFFFFFFF) { - unset($ThisFileInfo['ogg']['bitrate_nominal']); - } - if ($ThisFileInfo['ogg']['bitrate_min'] == 0xFFFFFFFF) { - unset($ThisFileInfo['ogg']['bitrate_min']); - $ThisFileInfo['audio']['bitrate_mode'] = 'abr'; - } - return true; - } - - static function ParseOggPageHeader(&$fd) { - // http://xiph.org/ogg/vorbis/doc/framing.html - $oggheader['page_start_offset'] = ftell($fd); // where we started from in the file - - $filedata = fread($fd, GETID3_FREAD_BUFFER_SIZE); - $filedataoffset = 0; - while ((substr($filedata, $filedataoffset++, 4) != 'OggS')) { - if ((ftell($fd) - $oggheader['page_start_offset']) >= GETID3_FREAD_BUFFER_SIZE) { - // should be found before here - return false; - } - if ((($filedataoffset + 28) > strlen($filedata)) || (strlen($filedata) < 28)) { - if (feof($fd) || (($filedata .= fread($fd, GETID3_FREAD_BUFFER_SIZE)) === false)) { - // get some more data, unless eof, in which case fail - return false; - } - } - } - $filedataoffset += strlen('OggS') - 1; // page, delimited by 'OggS' - - $oggheader['stream_structver'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $oggheader['flags_raw'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $oggheader['flags']['fresh'] = (bool) ($oggheader['flags_raw'] & 0x01); // fresh packet - $oggheader['flags']['bos'] = (bool) ($oggheader['flags_raw'] & 0x02); // first page of logical bitstream (bos) - $oggheader['flags']['eos'] = (bool) ($oggheader['flags_raw'] & 0x04); // last page of logical bitstream (eos) - - $oggheader['pcm_abs_position'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); - $filedataoffset += 8; - $oggheader['stream_serialno'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $oggheader['page_seqno'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $oggheader['page_checksum'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); - $filedataoffset += 4; - $oggheader['page_segments'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $oggheader['page_length'] = 0; - for ($i = 0; $i < $oggheader['page_segments']; $i++) { - $oggheader['segment_table'][$i] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); - $filedataoffset += 1; - $oggheader['page_length'] += $oggheader['segment_table'][$i]; - } - $oggheader['header_end_offset'] = $oggheader['page_start_offset'] + $filedataoffset; - $oggheader['page_end_offset'] = $oggheader['header_end_offset'] + $oggheader['page_length']; - fseek($fd, $oggheader['header_end_offset'], SEEK_SET); - - return $oggheader; - } - - - static function ParseVorbisCommentsFilepointer(&$fd, &$ThisFileInfo) { - - $OriginalOffset = ftell($fd); - $CommentStartOffset = $OriginalOffset; - $commentdataoffset = 0; - $VorbisCommentPage = 1; - - switch ($ThisFileInfo['audio']['dataformat']) { - case 'vorbis': - $CommentStartOffset = $ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage]['page_start_offset']; // Second Ogg page, after header block - fseek($fd, $CommentStartOffset, SEEK_SET); - $commentdataoffset = 27 + $ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage]['page_segments']; - $commentdata = fread($fd, getid3_ogg::OggPageSegmentLength($ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage], 1) + $commentdataoffset); - - $commentdataoffset += (strlen('vorbis') + 1); - break; - - case 'flac': - fseek($fd, $ThisFileInfo['flac']['VORBIS_COMMENT']['raw']['offset'] + 4, SEEK_SET); - $commentdata = fread($fd, $ThisFileInfo['flac']['VORBIS_COMMENT']['raw']['block_length']); - break; - - case 'speex': - $CommentStartOffset = $ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage]['page_start_offset']; // Second Ogg page, after header block - fseek($fd, $CommentStartOffset, SEEK_SET); - $commentdataoffset = 27 + $ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage]['page_segments']; - $commentdata = fread($fd, getid3_ogg::OggPageSegmentLength($ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage], 1) + $commentdataoffset); - break; - - default: - return false; - break; - } - - $VendorSize = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4)); - $commentdataoffset += 4; - - $ThisFileInfo['ogg']['vendor'] = substr($commentdata, $commentdataoffset, $VendorSize); - $commentdataoffset += $VendorSize; - - $CommentsCount = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4)); - $commentdataoffset += 4; - $ThisFileInfo['avdataoffset'] = $CommentStartOffset + $commentdataoffset; - - $basicfields = array('TITLE', 'ARTIST', 'ALBUM', 'TRACKNUMBER', 'GENRE', 'DATE', 'DESCRIPTION', 'COMMENT'); - $ThisFileInfo_ogg_comments_raw = &$ThisFileInfo['ogg']['comments_raw']; - for ($i = 0; $i < $CommentsCount; $i++) { - - $ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] = $CommentStartOffset + $commentdataoffset; - - if (ftell($fd) < ($ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] + 4)) { - $VorbisCommentPage++; - - $oggpageinfo = getid3_ogg::ParseOggPageHeader($fd); - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; - - // First, save what we haven't read yet - $AsYetUnusedData = substr($commentdata, $commentdataoffset); - - // Then take that data off the end - $commentdata = substr($commentdata, 0, $commentdataoffset); - - // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct - $commentdata .= str_repeat("\x00", 27 + $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); - $commentdataoffset += (27 + $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); - - // Finally, stick the unused data back on the end - $commentdata .= $AsYetUnusedData; - - //$commentdata .= fread($fd, $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); - $commentdata .= fread($fd, getid3_ogg::OggPageSegmentLength($ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage], 1)); - - } - $ThisFileInfo_ogg_comments_raw[$i]['size'] = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4)); - - // replace avdataoffset with position just after the last vorbiscomment - $ThisFileInfo['avdataoffset'] = $ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] + $ThisFileInfo_ogg_comments_raw[$i]['size'] + 4; - - $commentdataoffset += 4; - while ((strlen($commentdata) - $commentdataoffset) < $ThisFileInfo_ogg_comments_raw[$i]['size']) { - if (($ThisFileInfo_ogg_comments_raw[$i]['size'] > $ThisFileInfo['avdataend']) || ($ThisFileInfo_ogg_comments_raw[$i]['size'] < 0)) { - $ThisFileInfo['warning'][] = 'Invalid Ogg comment size (comment #'.$i.', claims to be '.number_format($ThisFileInfo_ogg_comments_raw[$i]['size']).' bytes) - aborting reading comments'; - break 2; - } - - $VorbisCommentPage++; - - $oggpageinfo = getid3_ogg::ParseOggPageHeader($fd); - $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; - - // First, save what we haven't read yet - $AsYetUnusedData = substr($commentdata, $commentdataoffset); - - // Then take that data off the end - $commentdata = substr($commentdata, 0, $commentdataoffset); - - // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct - $commentdata .= str_repeat("\x00", 27 + $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); - $commentdataoffset += (27 + $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); - - // Finally, stick the unused data back on the end - $commentdata .= $AsYetUnusedData; - - //$commentdata .= fread($fd, $ThisFileInfo['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); - if (!isset($ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage])) { - $ThisFileInfo['warning'][] = 'undefined Vorbis Comment page "'.$VorbisCommentPage.'" at offset '.ftell($fd); - break; - } - $readlength = getid3_ogg::OggPageSegmentLength($ThisFileInfo['ogg']['pageheader'][$VorbisCommentPage], 1); - if ($readlength <= 0) { - $ThisFileInfo['warning'][] = 'invalid length Vorbis Comment page "'.$VorbisCommentPage.'" at offset '.ftell($fd); - break; - } - $commentdata .= fread($fd, $readlength); - - //$filebaseoffset += $oggpageinfo['header_end_offset'] - $oggpageinfo['page_start_offset']; - } - $commentstring = substr($commentdata, $commentdataoffset, $ThisFileInfo_ogg_comments_raw[$i]['size']); - $commentdataoffset += $ThisFileInfo_ogg_comments_raw[$i]['size']; - - if (!$commentstring) { - - // no comment? - $ThisFileInfo['warning'][] = 'Blank Ogg comment ['.$i.']'; - - } elseif (strstr($commentstring, '=')) { - - $commentexploded = explode('=', $commentstring, 2); - $ThisFileInfo_ogg_comments_raw[$i]['key'] = strtoupper($commentexploded[0]); - $ThisFileInfo_ogg_comments_raw[$i]['value'] = (isset($commentexploded[1]) ? $commentexploded[1] : ''); - $ThisFileInfo_ogg_comments_raw[$i]['data'] = base64_decode($ThisFileInfo_ogg_comments_raw[$i]['value']); - - if (preg_match('#^(BM|GIF|\xFF\xD8\xFF|\x89\x50\x4E\x47\x0D\x0A\x1A\x0A|II\x2A\x00|MM\x00\x2A)#s', $ThisFileInfo_ogg_comments_raw[$i]['data'])) { - $imageinfo = array(); - $imagechunkcheck = getid3_lib::GetDataImageSize($ThisFileInfo_ogg_comments_raw[$i]['data'], $imageinfo); - unset($imageinfo); - if (!empty($imagechunkcheck)) { - $ThisFileInfo_ogg_comments_raw[$i]['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]); - if ($ThisFileInfo_ogg_comments_raw[$i]['image_mime'] && ($ThisFileInfo_ogg_comments_raw[$i]['image_mime'] != 'application/octet-stream')) { - unset($ThisFileInfo_ogg_comments_raw[$i]['value']); - } - } - } - if (isset($ThisFileInfo_ogg_comments_raw[$i]['value'])) { - unset($ThisFileInfo_ogg_comments_raw[$i]['data']); - $ThisFileInfo['ogg']['comments'][strtolower($ThisFileInfo_ogg_comments_raw[$i]['key'])][] = $ThisFileInfo_ogg_comments_raw[$i]['value']; - } else { - $ThisFileInfo['ogg']['comments']['picture'][] = array('data'=>$ThisFileInfo_ogg_comments_raw[$i]['data'], 'image_mime'=>$ThisFileInfo_ogg_comments_raw[$i]['image_mime']); - } - - } else { - - $ThisFileInfo['warning'][] = '[known problem with CDex >= v1.40, < v1.50b7] Invalid Ogg comment name/value pair ['.$i.']: '.$commentstring; - - } - } - - - // Replay Gain Adjustment - // http://privatewww.essex.ac.uk/~djmrob/replaygain/ - if (isset($ThisFileInfo['ogg']['comments']) && is_array($ThisFileInfo['ogg']['comments'])) { - foreach ($ThisFileInfo['ogg']['comments'] as $index => $commentvalue) { - switch ($index) { - case 'rg_audiophile': - case 'replaygain_album_gain': - $ThisFileInfo['replay_gain']['album']['adjustment'] = (double) $commentvalue[0]; - unset($ThisFileInfo['ogg']['comments'][$index]); - break; - - case 'rg_radio': - case 'replaygain_track_gain': - $ThisFileInfo['replay_gain']['track']['adjustment'] = (double) $commentvalue[0]; - unset($ThisFileInfo['ogg']['comments'][$index]); - break; - - case 'replaygain_album_peak': - $ThisFileInfo['replay_gain']['album']['peak'] = (double) $commentvalue[0]; - unset($ThisFileInfo['ogg']['comments'][$index]); - break; - - case 'rg_peak': - case 'replaygain_track_peak': - $ThisFileInfo['replay_gain']['track']['peak'] = (double) $commentvalue[0]; - unset($ThisFileInfo['ogg']['comments'][$index]); - break; - - - default: - // do nothing - break; - } - } - } - - fseek($fd, $OriginalOffset, SEEK_SET); - - return true; - } - - static function SpeexBandModeLookup($mode) { - static $SpeexBandModeLookup = array(); - if (empty($SpeexBandModeLookup)) { - $SpeexBandModeLookup[0] = 'narrow'; - $SpeexBandModeLookup[1] = 'wide'; - $SpeexBandModeLookup[2] = 'ultra-wide'; - } - return (isset($SpeexBandModeLookup[$mode]) ? $SpeexBandModeLookup[$mode] : null); - } - - - static function OggPageSegmentLength($OggInfoArray, $SegmentNumber=1) { - for ($i = 0; $i < $SegmentNumber; $i++) { - $segmentlength = 0; - foreach ($OggInfoArray['segment_table'] as $key => $value) { - $segmentlength += $value; - if ($value < 255) { - break; - } - } - } - return $segmentlength; - } - - - static function get_quality_from_nominal_bitrate($nominal_bitrate) { - - // decrease precision - $nominal_bitrate = $nominal_bitrate / 1000; - - if ($nominal_bitrate < 128) { - // q-1 to q4 - $qval = ($nominal_bitrate - 64) / 16; - } elseif ($nominal_bitrate < 256) { - // q4 to q8 - $qval = $nominal_bitrate / 32; - } elseif ($nominal_bitrate < 320) { - // q8 to q9 - $qval = ($nominal_bitrate + 256) / 64; - } else { - // q9 to q10 - $qval = ($nominal_bitrate + 1300) / 180; - } - //return $qval; // 5.031324 - //return intval($qval); // 5 - return round($qval, 1); // 5 or 4.9 - } - -} - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.rkau.php b/serendipity_event_podcast/player/getid3/module.audio.rkau.php deleted file mode 100644 index 0e344d43..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.rkau.php +++ /dev/null @@ -1,92 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.shorten.php // -// module for analyzing Shorten Audio files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_rkau -{ - - function getid3_rkau(&$fd, &$ThisFileInfo) { - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $RKAUHeader = fread($fd, 20); - if (substr($RKAUHeader, 0, 3) != 'RKA') { - $ThisFileInfo['error'][] = 'Expecting "RKA" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($RKAUHeader, 0, 3).'"'; - return false; - } - - $ThisFileInfo['fileformat'] = 'rkau'; - $ThisFileInfo['audio']['dataformat'] = 'rkau'; - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; - - $ThisFileInfo['rkau']['raw']['version'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 3, 1)); - $ThisFileInfo['rkau']['version'] = '1.'.str_pad($ThisFileInfo['rkau']['raw']['version'] & 0x0F, 2, '0', STR_PAD_LEFT); - if (($ThisFileInfo['rkau']['version'] > 1.07) || ($ThisFileInfo['rkau']['version'] < 1.06)) { - $ThisFileInfo['error'][] = 'This version of getID3() can only parse RKAU files v1.06 and 1.07 (this file is v'.$ThisFileInfo['rkau']['version'].')'; - unset($ThisFileInfo['rkau']); - return false; - } - - $ThisFileInfo['rkau']['source_bytes'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 4, 4)); - $ThisFileInfo['rkau']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 8, 4)); - $ThisFileInfo['rkau']['channels'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 12, 1)); - $ThisFileInfo['rkau']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 13, 1)); - - $ThisFileInfo['rkau']['raw']['quality'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 14, 1)); - $this->RKAUqualityLookup($ThisFileInfo['rkau']); - - $ThisFileInfo['rkau']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 15, 1)); - $ThisFileInfo['rkau']['flags']['joint_stereo'] = (bool) (!($ThisFileInfo['rkau']['raw']['flags'] & 0x01)); - $ThisFileInfo['rkau']['flags']['streaming'] = (bool) ($ThisFileInfo['rkau']['raw']['flags'] & 0x02); - $ThisFileInfo['rkau']['flags']['vrq_lossy_mode'] = (bool) ($ThisFileInfo['rkau']['raw']['flags'] & 0x04); - - if ($ThisFileInfo['rkau']['flags']['streaming']) { - $ThisFileInfo['avdataoffset'] += 20; - $ThisFileInfo['rkau']['compressed_bytes'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 16, 4)); - } else { - $ThisFileInfo['avdataoffset'] += 16; - $ThisFileInfo['rkau']['compressed_bytes'] = $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'] - 1; - } - // Note: compressed_bytes does not always equal what appears to be the actual number of compressed bytes, - // sometimes it's more, sometimes less. No idea why(?) - - $ThisFileInfo['audio']['lossless'] = $ThisFileInfo['rkau']['lossless']; - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['rkau']['channels']; - $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['rkau']['bits_per_sample']; - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['rkau']['sample_rate']; - - $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['rkau']['source_bytes'] / ($ThisFileInfo['rkau']['sample_rate'] * $ThisFileInfo['rkau']['channels'] * ($ThisFileInfo['rkau']['bits_per_sample'] / 8)); - $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['rkau']['compressed_bytes'] * 8) / $ThisFileInfo['playtime_seconds']; - - return true; - - } - - - function RKAUqualityLookup(&$RKAUdata) { - $level = ($RKAUdata['raw']['quality'] & 0xF0) >> 4; - $quality = $RKAUdata['raw']['quality'] & 0x0F; - - $RKAUdata['lossless'] = (($quality == 0) ? true : false); - $RKAUdata['compression_level'] = $level + 1; - if (!$RKAUdata['lossless']) { - $RKAUdata['quality_setting'] = $quality; - } - - return true; - } - -} - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.tta.php b/serendipity_event_podcast/player/getid3/module.audio.tta.php deleted file mode 100644 index 903de6bf..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.tta.php +++ /dev/null @@ -1,107 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.tta.php // -// module for analyzing TTA Audio files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_tta -{ - - function getid3_tta(&$fd, &$ThisFileInfo) { - - $ThisFileInfo['fileformat'] = 'tta'; - $ThisFileInfo['audio']['dataformat'] = 'tta'; - $ThisFileInfo['audio']['lossless'] = true; - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $ttaheader = fread($fd, 26); - - $ThisFileInfo['tta']['magic'] = substr($ttaheader, 0, 3); - if ($ThisFileInfo['tta']['magic'] != 'TTA') { - $ThisFileInfo['error'][] = 'Expecting "TTA" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['tta']['magic'].'"'; - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['audio']); - unset($ThisFileInfo['tta']); - return false; - } - - switch ($ttaheader{3}) { - case "\x01": // TTA v1.x - case "\x02": // TTA v1.x - case "\x03": // TTA v1.x - // "It was the demo-version of the TTA encoder. There is no released format with such header. TTA encoder v1 is not supported about a year." - $ThisFileInfo['tta']['major_version'] = 1; - $ThisFileInfo['avdataoffset'] += 16; - - $ThisFileInfo['tta']['compression_level'] = ord($ttaheader{3}); - $ThisFileInfo['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); - $ThisFileInfo['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2)); - $ThisFileInfo['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 4)); - $ThisFileInfo['tta']['samples_per_channel'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12, 4)); - - $ThisFileInfo['audio']['encoder_options'] = '-e'.$ThisFileInfo['tta']['compression_level']; - $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['tta']['samples_per_channel'] / $ThisFileInfo['tta']['sample_rate']; - break; - - case '2': // TTA v2.x - // "I have hurried to release the TTA 2.0 encoder. Format documentation is removed from our site. This format still in development. Please wait the TTA2 format, encoder v4." - $ThisFileInfo['tta']['major_version'] = 2; - $ThisFileInfo['avdataoffset'] += 20; - - $ThisFileInfo['tta']['compression_level'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); - $ThisFileInfo['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2)); - $ThisFileInfo['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 2)); - $ThisFileInfo['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 10, 2)); - $ThisFileInfo['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12, 4)); - $ThisFileInfo['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 16, 4)); - - $ThisFileInfo['audio']['encoder_options'] = '-e'.$ThisFileInfo['tta']['compression_level']; - $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['tta']['data_length'] / $ThisFileInfo['tta']['sample_rate']; - break; - - case '1': // TTA v3.x - // "This is a first stable release of the TTA format. It will be supported by the encoders v3 or higher." - $ThisFileInfo['tta']['major_version'] = 3; - $ThisFileInfo['avdataoffset'] += 26; - - $ThisFileInfo['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); // getid3_riff::RIFFwFormatTagLookup() - $ThisFileInfo['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2)); - $ThisFileInfo['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 2)); - $ThisFileInfo['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 10, 4)); - $ThisFileInfo['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 14, 4)); - $ThisFileInfo['tta']['crc32_footer'] = substr($ttaheader, 18, 4); - $ThisFileInfo['tta']['seek_point'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 22, 4)); - - $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['tta']['data_length'] / $ThisFileInfo['tta']['sample_rate']; - break; - - default: - $ThisFileInfo['error'][] = 'This version of getID3() only knows how to handle TTA v1 and v2 - it may not work correctly with this file which appears to be TTA v'.$ttaheader{3}; - return false; - break; - } - - $ThisFileInfo['audio']['encoder'] = 'TTA v'.$ThisFileInfo['tta']['major_version']; - $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['tta']['bits_per_sample']; - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['tta']['sample_rate']; - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['tta']['channels']; - $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; - - return true; - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.vqf.php b/serendipity_event_podcast/player/getid3/module.audio.vqf.php deleted file mode 100644 index 49d4e851..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.vqf.php +++ /dev/null @@ -1,159 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.vqf.php // -// module for analyzing VQF audio files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_vqf -{ - function getid3_vqf(&$fd, &$ThisFileInfo) { - // based loosely on code from TTwinVQ by Jurgen Faul - // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html - - $ThisFileInfo['fileformat'] = 'vqf'; - $ThisFileInfo['audio']['dataformat'] = 'vqf'; - $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; - $ThisFileInfo['audio']['lossless'] = false; - - // shortcut - $ThisFileInfo['vqf']['raw'] = array(); - $thisfile_vqf = &$ThisFileInfo['vqf']; - $thisfile_vqf_raw = &$thisfile_vqf['raw']; - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $VQFheaderData = fread($fd, 16); - - $offset = 0; - $thisfile_vqf_raw['header_tag'] = substr($VQFheaderData, $offset, 4); - if ($thisfile_vqf_raw['header_tag'] != 'TWIN') { - $ThisFileInfo['error'][] = 'Expecting "TWIN" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$thisfile_vqf_raw['header_tag'].'"'; - unset($ThisFileInfo['vqf']); - unset($ThisFileInfo['fileformat']); - return false; - } - $offset += 4; - $thisfile_vqf_raw['version'] = substr($VQFheaderData, $offset, 8); - $offset += 8; - $thisfile_vqf_raw['size'] = getid3_lib::BigEndian2Int(substr($VQFheaderData, $offset, 4)); - $offset += 4; - - while (ftell($fd) < $ThisFileInfo['avdataend']) { - - $ChunkBaseOffset = ftell($fd); - $chunkoffset = 0; - $ChunkData = fread($fd, 8); - $ChunkName = substr($ChunkData, $chunkoffset, 4); - if ($ChunkName == 'DATA') { - $ThisFileInfo['avdataoffset'] = $ChunkBaseOffset; - break; - } - $chunkoffset += 4; - $ChunkSize = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); - $chunkoffset += 4; - if ($ChunkSize > ($ThisFileInfo['avdataend'] - ftell($fd))) { - $ThisFileInfo['error'][] = 'Invalid chunk size ('.$ChunkSize.') for chunk "'.$ChunkName.'" at offset '.$ChunkBaseOffset; - break; - } - if ($ChunkSize > 0) { - $ChunkData .= fread($fd, $ChunkSize); - } - - switch ($ChunkName) { - case 'COMM': - // shortcut - $thisfile_vqf['COMM'] = array(); - $thisfile_vqf_COMM = &$thisfile_vqf['COMM']; - - $thisfile_vqf_COMM['channel_mode'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); - $chunkoffset += 4; - $thisfile_vqf_COMM['bitrate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); - $chunkoffset += 4; - $thisfile_vqf_COMM['sample_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); - $chunkoffset += 4; - $thisfile_vqf_COMM['security_level'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); - $chunkoffset += 4; - - $ThisFileInfo['audio']['channels'] = $thisfile_vqf_COMM['channel_mode'] + 1; - $ThisFileInfo['audio']['sample_rate'] = $this->VQFchannelFrequencyLookup($thisfile_vqf_COMM['sample_rate']); - $ThisFileInfo['audio']['bitrate'] = $thisfile_vqf_COMM['bitrate'] * 1000; - $ThisFileInfo['audio']['encoder_options'] = 'CBR' . ceil($ThisFileInfo['audio']['bitrate']/1000); - - if ($ThisFileInfo['audio']['bitrate'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt VQF file: bitrate_audio == zero'; - return false; - } - break; - - case 'NAME': - case 'AUTH': - case '(c) ': - case 'FILE': - case 'COMT': - case 'ALBM': - $thisfile_vqf['comments'][$this->VQFcommentNiceNameLookup($ChunkName)][] = trim(substr($ChunkData, 8)); - break; - - case 'DSIZ': - $thisfile_vqf['DSIZ'] = getid3_lib::BigEndian2Int(substr($ChunkData, 8, 4)); - break; - - default: - $ThisFileInfo['warning'][] = 'Unhandled chunk type "'.$ChunkName.'" at offset '.$ChunkBaseOffset; - break; - } - } - - $ThisFileInfo['playtime_seconds'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['audio']['bitrate']; - - if (isset($thisfile_vqf['DSIZ']) && (($thisfile_vqf['DSIZ'] != ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'] - strlen('DATA'))))) { - switch ($thisfile_vqf['DSIZ']) { - case 0: - case 1: - $ThisFileInfo['warning'][] = 'Invalid DSIZ value "'.$thisfile_vqf['DSIZ'].'". This is known to happen with VQF files encoded by Ahead Nero, and seems to be its way of saying this is TwinVQF v'.($thisfile_vqf['DSIZ'] + 1).'.0'; - $ThisFileInfo['audio']['encoder'] = 'Ahead Nero'; - break; - - default: - $ThisFileInfo['warning'][] = 'Probable corrupted file - should be '.$thisfile_vqf['DSIZ'].' bytes, actually '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'] - strlen('DATA')); - break; - } - } - - return true; - } - - function VQFchannelFrequencyLookup($frequencyid) { - static $VQFchannelFrequencyLookup = array( - 11 => 11025, - 22 => 22050, - 44 => 44100 - ); - return (isset($VQFchannelFrequencyLookup[$frequencyid]) ? $VQFchannelFrequencyLookup[$frequencyid] : $frequencyid * 1000); - } - - function VQFcommentNiceNameLookup($shortname) { - static $VQFcommentNiceNameLookup = array( - 'NAME' => 'title', - 'AUTH' => 'artist', - '(c) ' => 'copyright', - 'FILE' => 'filename', - 'COMT' => 'comment', - 'ALBM' => 'album' - ); - return (isset($VQFcommentNiceNameLookup[$shortname]) ? $VQFcommentNiceNameLookup[$shortname] : $shortname); - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.wavpack.php b/serendipity_event_podcast/player/getid3/module.audio.wavpack.php deleted file mode 100644 index 7cdb861d..00000000 --- a/serendipity_event_podcast/player/getid3/module.audio.wavpack.php +++ /dev/null @@ -1,391 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.audio.wavpack.php // -// module for analyzing WavPack v4.0+ Audio files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_wavpack -{ - - function getid3_wavpack(&$fd, &$ThisFileInfo) { - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - - while (true) { - - $wavpackheader = fread($fd, 32); - - if (ftell($fd) >= $ThisFileInfo['avdataend']) { - break; - } elseif (feof($fd)) { - break; - } elseif ( - isset($ThisFileInfo['wavpack']['blockheader']['total_samples']) && - isset($ThisFileInfo['wavpack']['blockheader']['block_samples']) && - ($ThisFileInfo['wavpack']['blockheader']['total_samples'] > 0) && - ($ThisFileInfo['wavpack']['blockheader']['block_samples'] > 0) && - (!isset($ThisFileInfo['wavpack']['riff_trailer_size']) || ($ThisFileInfo['wavpack']['riff_trailer_size'] <= 0)) && - ((isset($ThisFileInfo['wavpack']['config_flags']['md5_checksum']) && ($ThisFileInfo['wavpack']['config_flags']['md5_checksum'] === false)) || !empty($ThisFileInfo['md5_data_source']))) { - break; - } - - $blockheader_offset = ftell($fd) - 32; - $blockheader_magic = substr($wavpackheader, 0, 4); - $blockheader_size = getid3_lib::LittleEndian2Int(substr($wavpackheader, 4, 4)); - - if ($blockheader_magic != 'wvpk') { - $ThisFileInfo['error'][] = 'Expecting "wvpk" at offset '.$blockheader_offset.', found "'.$blockheader_magic.'"'; - switch (isset($ThisFileInfo['audio']['dataformat']) ? $ThisFileInfo['audio']['dataformat'] : '') { - case 'wavpack': - case 'wvc': - break; - default: - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['audio']); - unset($ThisFileInfo['wavpack']); - break; - } - return false; - } - - - if (empty($ThisFileInfo['wavpack']['blockheader']['block_samples']) || - empty($ThisFileInfo['wavpack']['blockheader']['total_samples']) || - ($ThisFileInfo['wavpack']['blockheader']['block_samples'] <= 0) || - ($ThisFileInfo['wavpack']['blockheader']['total_samples'] <= 0)) { - // Also, it is possible that the first block might not have - // any samples (block_samples == 0) and in this case you should skip blocks - // until you find one with samples because the other information (like - // total_samples) are not guaranteed to be correct until (block_samples > 0) - - // Finally, I have defined a format for files in which the length is not known - // (for example when raw files are created using pipes). In these cases - // total_samples will be -1 and you must seek to the final block to determine - // the total number of samples. - - - $ThisFileInfo['audio']['dataformat'] = 'wavpack'; - $ThisFileInfo['fileformat'] = 'wavpack'; - $ThisFileInfo['audio']['lossless'] = true; - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; - - $ThisFileInfo['wavpack']['blockheader']['offset'] = $blockheader_offset; - $ThisFileInfo['wavpack']['blockheader']['magic'] = $blockheader_magic; - $ThisFileInfo['wavpack']['blockheader']['size'] = $blockheader_size; - - if ($ThisFileInfo['wavpack']['blockheader']['size'] >= 0x100000) { - $ThisFileInfo['error'][] = 'Expecting WavPack block size less than "0x100000", found "'.$ThisFileInfo['wavpack']['blockheader']['size'].'" at offset '.$ThisFileInfo['wavpack']['blockheader']['offset']; - switch (isset($ThisFileInfo['audio']['dataformat']) ? $ThisFileInfo['audio']['dataformat'] : '') { - case 'wavpack': - case 'wvc': - break; - default: - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['audio']); - unset($ThisFileInfo['wavpack']); - break; - } - return false; - } - - $ThisFileInfo['wavpack']['blockheader']['minor_version'] = ord($wavpackheader{8}); - $ThisFileInfo['wavpack']['blockheader']['major_version'] = ord($wavpackheader{9}); - - if (($ThisFileInfo['wavpack']['blockheader']['major_version'] != 4) || - (($ThisFileInfo['wavpack']['blockheader']['minor_version'] < 4) && - ($ThisFileInfo['wavpack']['blockheader']['minor_version'] > 16))) { - $ThisFileInfo['error'][] = 'Expecting WavPack version between "4.2" and "4.16", found version "'.$ThisFileInfo['wavpack']['blockheader']['major_version'].'.'.$ThisFileInfo['wavpack']['blockheader']['minor_version'].'" at offset '.$ThisFileInfo['wavpack']['blockheader']['offset']; - switch (isset($ThisFileInfo['audio']['dataformat']) ? $ThisFileInfo['audio']['dataformat'] : '') { - case 'wavpack': - case 'wvc': - break; - default: - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['audio']); - unset($ThisFileInfo['wavpack']); - break; - } - return false; - } - - $ThisFileInfo['wavpack']['blockheader']['track_number'] = ord($wavpackheader{10}); // unused - $ThisFileInfo['wavpack']['blockheader']['index_number'] = ord($wavpackheader{11}); // unused - $ThisFileInfo['wavpack']['blockheader']['total_samples'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 12, 4)); - $ThisFileInfo['wavpack']['blockheader']['block_index'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 16, 4)); - $ThisFileInfo['wavpack']['blockheader']['block_samples'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 20, 4)); - $ThisFileInfo['wavpack']['blockheader']['flags_raw'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 24, 4)); - $ThisFileInfo['wavpack']['blockheader']['crc'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 28, 4)); - - $ThisFileInfo['wavpack']['blockheader']['flags']['bytes_per_sample'] = 1 + ($ThisFileInfo['wavpack']['blockheader']['flags_raw'] & 0x00000003); - $ThisFileInfo['wavpack']['blockheader']['flags']['mono'] = (bool) ($ThisFileInfo['wavpack']['blockheader']['flags_raw'] & 0x00000004); - $ThisFileInfo['wavpack']['blockheader']['flags']['hybrid'] = (bool) ($ThisFileInfo['wavpack']['blockheader']['flags_raw'] & 0x00000008); - $ThisFileInfo['wavpack']['blockheader']['flags']['joint_stereo'] = (bool) ($ThisFileInfo['wavpack']['blockheader']['flags_raw'] & 0x00000010); - $ThisFileInfo['wavpack']['blockheader']['flags']['cross_decorrelation'] = (bool) ($ThisFileInfo['wavpack']['blockheader']['flags_raw'] & 0x00000020); - $ThisFileInfo['wavpack']['blockheader']['flags']['hybrid_noiseshape'] = (bool) ($ThisFileInfo['wavpack']['blockheader']['flags_raw'] & 0x00000040); - $ThisFileInfo['wavpack']['blockheader']['flags']['ieee_32bit_float'] = (bool) ($ThisFileInfo['wavpack']['blockheader']['flags_raw'] & 0x00000080); - $ThisFileInfo['wavpack']['blockheader']['flags']['int_32bit'] = (bool) ($ThisFileInfo['wavpack']['blockheader']['flags_raw'] & 0x00000100); - $ThisFileInfo['wavpack']['blockheader']['flags']['hybrid_bitrate_noise'] = (bool) ($ThisFileInfo['wavpack']['blockheader']['flags_raw'] & 0x00000200); - $ThisFileInfo['wavpack']['blockheader']['flags']['hybrid_balance_noise'] = (bool) ($ThisFileInfo['wavpack']['blockheader']['flags_raw'] & 0x00000400); - $ThisFileInfo['wavpack']['blockheader']['flags']['multichannel_initial'] = (bool) ($ThisFileInfo['wavpack']['blockheader']['flags_raw'] & 0x00000800); - $ThisFileInfo['wavpack']['blockheader']['flags']['multichannel_final'] = (bool) ($ThisFileInfo['wavpack']['blockheader']['flags_raw'] & 0x00001000); - - $ThisFileInfo['audio']['lossless'] = !$ThisFileInfo['wavpack']['blockheader']['flags']['hybrid']; - } - - while (!feof($fd) && (ftell($fd) < ($blockheader_offset + $blockheader_size + 8))) { - - $metablock = array('offset'=>ftell($fd)); - $metablockheader = fread($fd, 2); - if (feof($fd)) { - break; - } - $metablock['id'] = ord($metablockheader{0}); - $metablock['function_id'] = ($metablock['id'] & 0x3F); - $metablock['function_name'] = $this->WavPackMetablockNameLookup($metablock['function_id']); - - // The 0x20 bit in the id of the meta subblocks (which is defined as - // ID_OPTIONAL_DATA) is a permanent part of the id. The idea is that - // if a decoder encounters an id that it does not know about, it uses - // that "ID_OPTIONAL_DATA" flag to determine what to do. If it is set - // then the decoder simply ignores the metadata, but if it is zero - // then the decoder should quit because it means that an understanding - // of the metadata is required to correctly decode the audio. - $metablock['non_decoder'] = (bool) ($metablock['id'] & 0x20); - - $metablock['padded_data'] = (bool) ($metablock['id'] & 0x40); - $metablock['large_block'] = (bool) ($metablock['id'] & 0x80); - if ($metablock['large_block']) { - $metablockheader .= fread($fd, 2); - } - $metablock['size'] = getid3_lib::LittleEndian2Int(substr($metablockheader, 1)) * 2; // size is stored in words - $metablock['data'] = null; - - if ($metablock['size'] > 0) { - - switch ($metablock['function_id']) { - case 0x21: // ID_RIFF_HEADER - case 0x22: // ID_RIFF_TRAILER - case 0x23: // ID_REPLAY_GAIN - case 0x24: // ID_CUESHEET - case 0x25: // ID_CONFIG_BLOCK - case 0x26: // ID_MD5_CHECKSUM - $metablock['data'] = fread($fd, $metablock['size']); - - if ($metablock['padded_data']) { - // padded to the nearest even byte - $metablock['size']--; - $metablock['data'] = substr($metablock['data'], 0, -1); - } - break; - - case 0x00: // ID_DUMMY - case 0x01: // ID_ENCODER_INFO - case 0x02: // ID_DECORR_TERMS - case 0x03: // ID_DECORR_WEIGHTS - case 0x04: // ID_DECORR_SAMPLES - case 0x05: // ID_ENTROPY_VARS - case 0x06: // ID_HYBRID_PROFILE - case 0x07: // ID_SHAPING_WEIGHTS - case 0x08: // ID_FLOAT_INFO - case 0x09: // ID_INT32_INFO - case 0x0A: // ID_WV_BITSTREAM - case 0x0B: // ID_WVC_BITSTREAM - case 0x0C: // ID_WVX_BITSTREAM - case 0x0D: // ID_CHANNEL_INFO - fseek($fd, $metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size'], SEEK_SET); - break; - - default: - $ThisFileInfo['warning'][] = 'Unexpected metablock type "0x'.str_pad(dechex($metablock['function_id']), 2, '0', STR_PAD_LEFT).'" at offset '.$metablock['offset']; - fseek($fd, $metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size'], SEEK_SET); - break; - } - - switch ($metablock['function_id']) { - case 0x21: // ID_RIFF_HEADER - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); - $original_wav_filesize = getid3_lib::LittleEndian2Int(substr($metablock['data'], 4, 4)); - getid3_riff::ParseRIFFdata($metablock['data'], $ParsedRIFFheader); - $metablock['riff'] = $ParsedRIFFheader['riff']; - $metablock['riff']['original_filesize'] = $original_wav_filesize; - $ThisFileInfo['wavpack']['riff_trailer_size'] = $original_wav_filesize - $metablock['riff']['WAVE']['data'][0]['size'] - $metablock['riff']['header_size']; - - $ThisFileInfo['audio']['sample_rate'] = $ParsedRIFFheader['riff']['raw']['fmt ']['nSamplesPerSec']; - $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['wavpack']['blockheader']['total_samples'] / $ThisFileInfo['audio']['sample_rate']; - - // Safe RIFF header in case there's a RIFF footer later - $metablockRIFFheader = $metablock['data']; - break; - - - case 0x22: // ID_RIFF_TRAILER - $metablockRIFFfooter = $metablockRIFFheader.$metablock['data']; - getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); - - $ftell_old = ftell($fd); - $startoffset = $metablock['offset'] + ($metablock['large_block'] ? 4 : 2); - $ParsedRIFFfooter = array('avdataend'=>$ThisFileInfo['avdataend'], 'fileformat'=>'riff', 'error'=>array(), 'warning'=>array()); - $metablock['riff'] = getid3_riff::ParseRIFF($fd, $startoffset, $startoffset + $metablock['size'], $ParsedRIFFfooter); - fseek($fd, $ftell_old, SEEK_SET); - - if (!empty($metablock['riff']['INFO'])) { - getid3_riff::RIFFcommentsParse($metablock['riff']['INFO'], $metablock['comments']); - $ThisFileInfo['tags']['riff'] = $metablock['comments']; - } - break; - - - case 0x23: // ID_REPLAY_GAIN - $ThisFileInfo['warning'][] = 'WavPack "Replay Gain" contents not yet handled by getID3() in metablock at offset '.$metablock['offset']; - break; - - - case 0x24: // ID_CUESHEET - $ThisFileInfo['warning'][] = 'WavPack "Cuesheet" contents not yet handled by getID3() in metablock at offset '.$metablock['offset']; - break; - - - case 0x25: // ID_CONFIG_BLOCK - $metablock['flags_raw'] = getid3_lib::LittleEndian2Int(substr($metablock['data'], 0, 3)); - - $metablock['flags']['adobe_mode'] = (bool) ($metablock['flags_raw'] & 0x000001); // "adobe" mode for 32-bit floats - $metablock['flags']['fast_flag'] = (bool) ($metablock['flags_raw'] & 0x000002); // fast mode - $metablock['flags']['very_fast_flag'] = (bool) ($metablock['flags_raw'] & 0x000004); // double fast - $metablock['flags']['high_flag'] = (bool) ($metablock['flags_raw'] & 0x000008); // high quality mode - $metablock['flags']['very_high_flag'] = (bool) ($metablock['flags_raw'] & 0x000010); // double high (not used yet) - $metablock['flags']['bitrate_kbps'] = (bool) ($metablock['flags_raw'] & 0x000020); // bitrate is kbps, not bits / sample - $metablock['flags']['auto_shaping'] = (bool) ($metablock['flags_raw'] & 0x000040); // automatic noise shaping - $metablock['flags']['shape_override'] = (bool) ($metablock['flags_raw'] & 0x000080); // shaping mode specified - $metablock['flags']['joint_override'] = (bool) ($metablock['flags_raw'] & 0x000100); // joint-stereo mode specified - $metablock['flags']['copy_time'] = (bool) ($metablock['flags_raw'] & 0x000200); // copy file-time from source - $metablock['flags']['create_exe'] = (bool) ($metablock['flags_raw'] & 0x000400); // create executable - $metablock['flags']['create_wvc'] = (bool) ($metablock['flags_raw'] & 0x000800); // create correction file - $metablock['flags']['optimize_wvc'] = (bool) ($metablock['flags_raw'] & 0x001000); // maximize bybrid compression - $metablock['flags']['quality_mode'] = (bool) ($metablock['flags_raw'] & 0x002000); // psychoacoustic quality mode - $metablock['flags']['raw_flag'] = (bool) ($metablock['flags_raw'] & 0x004000); // raw mode (not implemented yet) - $metablock['flags']['calc_noise'] = (bool) ($metablock['flags_raw'] & 0x008000); // calc noise in hybrid mode - $metablock['flags']['lossy_mode'] = (bool) ($metablock['flags_raw'] & 0x010000); // obsolete (for information) - $metablock['flags']['extra_mode'] = (bool) ($metablock['flags_raw'] & 0x020000); // extra processing mode - $metablock['flags']['skip_wvx'] = (bool) ($metablock['flags_raw'] & 0x040000); // no wvx stream w/ floats & big ints - $metablock['flags']['md5_checksum'] = (bool) ($metablock['flags_raw'] & 0x080000); // compute & store MD5 signature - $metablock['flags']['quiet_mode'] = (bool) ($metablock['flags_raw'] & 0x100000); // don't report progress % - - $ThisFileInfo['wavpack']['config_flags'] = $metablock['flags']; - - - $ThisFileInfo['audio']['encoder_options'] = ''; - if ($ThisFileInfo['wavpack']['blockheader']['flags']['hybrid']) { - $ThisFileInfo['audio']['encoder_options'] .= ' -b???'; - } - $ThisFileInfo['audio']['encoder_options'] .= ($metablock['flags']['adobe_mode'] ? ' -a' : ''); - $ThisFileInfo['audio']['encoder_options'] .= ($metablock['flags']['optimize_wvc'] ? ' -cc' : ''); - $ThisFileInfo['audio']['encoder_options'] .= ($metablock['flags']['create_exe'] ? ' -e' : ''); - $ThisFileInfo['audio']['encoder_options'] .= ($metablock['flags']['fast_flag'] ? ' -f' : ''); - $ThisFileInfo['audio']['encoder_options'] .= ($metablock['flags']['joint_override'] ? ' -j?' : ''); - $ThisFileInfo['audio']['encoder_options'] .= ($metablock['flags']['high_flag'] ? ' -h' : ''); - $ThisFileInfo['audio']['encoder_options'] .= ($metablock['flags']['md5_checksum'] ? ' -m' : ''); - $ThisFileInfo['audio']['encoder_options'] .= ($metablock['flags']['calc_noise'] ? ' -n' : ''); - $ThisFileInfo['audio']['encoder_options'] .= ($metablock['flags']['shape_override'] ? ' -s?' : ''); - $ThisFileInfo['audio']['encoder_options'] .= ($metablock['flags']['extra_mode'] ? ' -x?' : ''); - if (!empty($ThisFileInfo['audio']['encoder_options'])) { - $ThisFileInfo['audio']['encoder_options'] = trim($ThisFileInfo['audio']['encoder_options']); - } elseif (isset($ThisFileInfo['audio']['encoder_options'])) { - unset($ThisFileInfo['audio']['encoder_options']); - } - break; - - - case 0x26: // ID_MD5_CHECKSUM - if (strlen($metablock['data']) == 16) { - $ThisFileInfo['md5_data_source'] = strtolower(getid3_lib::PrintHexBytes($metablock['data'], true, false, false)); - } else { - $ThisFileInfo['warning'][] = 'Expecting 16 bytes of WavPack "MD5 Checksum" in metablock at offset '.$metablock['offset'].', but found '.strlen($metablock['data']).' bytes'; - } - break; - - - case 0x00: // ID_DUMMY - case 0x01: // ID_ENCODER_INFO - case 0x02: // ID_DECORR_TERMS - case 0x03: // ID_DECORR_WEIGHTS - case 0x04: // ID_DECORR_SAMPLES - case 0x05: // ID_ENTROPY_VARS - case 0x06: // ID_HYBRID_PROFILE - case 0x07: // ID_SHAPING_WEIGHTS - case 0x08: // ID_FLOAT_INFO - case 0x09: // ID_INT32_INFO - case 0x0A: // ID_WV_BITSTREAM - case 0x0B: // ID_WVC_BITSTREAM - case 0x0C: // ID_WVX_BITSTREAM - case 0x0D: // ID_CHANNEL_INFO - unset($metablock); - break; - } - - } - if (!empty($metablock)) { - $ThisFileInfo['wavpack']['metablocks'][] = $metablock; - } - - } - - } - - $ThisFileInfo['audio']['encoder'] = 'WavPack v'.$ThisFileInfo['wavpack']['blockheader']['major_version'].'.'.str_pad($ThisFileInfo['wavpack']['blockheader']['minor_version'], 2, '0', STR_PAD_LEFT); - $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['wavpack']['blockheader']['flags']['bytes_per_sample'] * 8; - $ThisFileInfo['audio']['channels'] = ($ThisFileInfo['wavpack']['blockheader']['flags']['mono'] ? 1 : 2); - - if (!empty($ThisFileInfo['playtime_seconds'])) { - - $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; - - } else { - - $ThisFileInfo['audio']['dataformat'] = 'wvc'; - - } - - return true; - } - - - function WavPackMetablockNameLookup(&$id) { - static $WavPackMetablockNameLookup = array( - 0x00 => 'Dummy', - 0x01 => 'Encoder Info', - 0x02 => 'Decorrelation Terms', - 0x03 => 'Decorrelation Weights', - 0x04 => 'Decorrelation Samples', - 0x05 => 'Entropy Variables', - 0x06 => 'Hybrid Profile', - 0x07 => 'Shaping Weights', - 0x08 => 'Float Info', - 0x09 => 'Int32 Info', - 0x0A => 'WV Bitstream', - 0x0B => 'WVC Bitstream', - 0x0C => 'WVX Bitstream', - 0x0D => 'Channel Info', - 0x21 => 'RIFF header', - 0x22 => 'RIFF trailer', - 0x23 => 'Replay Gain', - 0x24 => 'Cuesheet', - 0x25 => 'Config Block', - 0x26 => 'MD5 Checksum', - ); - return (isset($WavPackMetablockNameLookup[$id]) ? $WavPackMetablockNameLookup[$id] : ''); - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.graphic.gif.php b/serendipity_event_podcast/player/getid3/module.graphic.gif.php deleted file mode 100644 index 986ada30..00000000 --- a/serendipity_event_podcast/player/getid3/module.graphic.gif.php +++ /dev/null @@ -1,183 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.graphic.gif.php // -// module for analyzing GIF Image files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_gif -{ - - function getid3_gif(&$fd, &$ThisFileInfo) { - $ThisFileInfo['fileformat'] = 'gif'; - $ThisFileInfo['video']['dataformat'] = 'gif'; - $ThisFileInfo['video']['lossless'] = true; - $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1; - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $GIFheader = fread($fd, 13); - $offset = 0; - - $ThisFileInfo['gif']['header']['raw']['identifier'] = substr($GIFheader, $offset, 3); - $offset += 3; - - if ($ThisFileInfo['gif']['header']['raw']['identifier'] != 'GIF') { - $ThisFileInfo['error'][] = 'Expecting "GIF" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['gif']['header']['raw']['identifier'].'"'; - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['gif']); - return false; - } - - $ThisFileInfo['gif']['header']['raw']['version'] = substr($GIFheader, $offset, 3); - $offset += 3; - $ThisFileInfo['gif']['header']['raw']['width'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 2)); - $offset += 2; - $ThisFileInfo['gif']['header']['raw']['height'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 2)); - $offset += 2; - $ThisFileInfo['gif']['header']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1)); - $offset += 1; - $ThisFileInfo['gif']['header']['raw']['bg_color_index'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1)); - $offset += 1; - $ThisFileInfo['gif']['header']['raw']['aspect_ratio'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1)); - $offset += 1; - - $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['gif']['header']['raw']['width']; - $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['gif']['header']['raw']['height']; - $ThisFileInfo['gif']['version'] = $ThisFileInfo['gif']['header']['raw']['version']; - $ThisFileInfo['gif']['header']['flags']['global_color_table'] = (bool) ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x80); - if ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x80) { - // Number of bits per primary color available to the original image, minus 1 - $ThisFileInfo['gif']['header']['bits_per_pixel'] = 3 * ((($ThisFileInfo['gif']['header']['raw']['flags'] & 0x70) >> 4) + 1); - } else { - $ThisFileInfo['gif']['header']['bits_per_pixel'] = 0; - } - $ThisFileInfo['gif']['header']['flags']['global_color_sorted'] = (bool) ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x40); - if ($ThisFileInfo['gif']['header']['flags']['global_color_table']) { - // the number of bytes contained in the Global Color Table. To determine that - // actual size of the color table, raise 2 to [the value of the field + 1] - $ThisFileInfo['gif']['header']['global_color_size'] = pow(2, ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x07) + 1); - $ThisFileInfo['video']['bits_per_sample'] = ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x07) + 1; - } else { - $ThisFileInfo['gif']['header']['global_color_size'] = 0; - } - if ($ThisFileInfo['gif']['header']['raw']['aspect_ratio'] != 0) { - // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64 - $ThisFileInfo['gif']['header']['aspect_ratio'] = ($ThisFileInfo['gif']['header']['raw']['aspect_ratio'] + 15) / 64; - } - -// if ($ThisFileInfo['gif']['header']['flags']['global_color_table']) { -// $GIFcolorTable = fread($fd, 3 * $ThisFileInfo['gif']['header']['global_color_size']); -// $offset = 0; -// for ($i = 0; $i < $ThisFileInfo['gif']['header']['global_color_size']; $i++) { -// $red = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1)); -// $green = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1)); -// $blue = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1)); -// $ThisFileInfo['gif']['global_color_table'][$i] = (($red << 16) | ($green << 8) | ($blue)); -// } -// } -// -// // Image Descriptor -// while (!feof($fd)) { -// $NextBlockTest = fread($fd, 1); -// switch ($NextBlockTest) { -// -// case ',': // ',' - Image separator character -// -// $ImageDescriptorData = $NextBlockTest.fread($fd, 9); -// $ImageDescriptor = array(); -// $ImageDescriptor['image_left'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 1, 2)); -// $ImageDescriptor['image_top'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 3, 2)); -// $ImageDescriptor['image_width'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 5, 2)); -// $ImageDescriptor['image_height'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 7, 2)); -// $ImageDescriptor['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 9, 1)); -// $ImageDescriptor['flags']['use_local_color_map'] = (bool) ($ImageDescriptor['flags_raw'] & 0x80); -// $ImageDescriptor['flags']['image_interlaced'] = (bool) ($ImageDescriptor['flags_raw'] & 0x40); -// $ThisFileInfo['gif']['image_descriptor'][] = $ImageDescriptor; -// -// if ($ImageDescriptor['flags']['use_local_color_map']) { -// -// $ThisFileInfo['warning'][] = 'This version of getID3() cannot parse local color maps for GIFs'; -// return true; -// -// } -//echo 'Start of raster data: '.ftell($fd).'
'; -// $RasterData = array(); -// $RasterData['code_size'] = getid3_lib::LittleEndian2Int(fread($fd, 1)); -// $RasterData['block_byte_count'] = getid3_lib::LittleEndian2Int(fread($fd, 1)); -// $ThisFileInfo['gif']['raster_data'][count($ThisFileInfo['gif']['image_descriptor']) - 1] = $RasterData; -// -// $CurrentCodeSize = $RasterData['code_size'] + 1; -// for ($i = 0; $i < pow(2, $RasterData['code_size']); $i++) { -// $DefaultDataLookupTable[$i] = chr($i); -// } -// $DefaultDataLookupTable[pow(2, $RasterData['code_size']) + 0] = ''; // Clear Code -// $DefaultDataLookupTable[pow(2, $RasterData['code_size']) + 1] = ''; // End Of Image Code -// -// -// $NextValue = $this->GetLSBits($fd, $CurrentCodeSize); -// echo 'Clear Code: '.$NextValue.'
'; -// -// $NextValue = $this->GetLSBits($fd, $CurrentCodeSize); -// echo 'First Color: '.$NextValue.'
'; -// -// $Prefix = $NextValue; -//$i = 0; -// while ($i++ < 20) { -// $NextValue = $this->GetLSBits($fd, $CurrentCodeSize); -// echo $NextValue.'
'; -// } -//return true; -// break; -// -// case '!': -// // GIF Extension Block -// $ExtensionBlockData = $NextBlockTest.fread($fd, 2); -// $ExtensionBlock = array(); -// $ExtensionBlock['function_code'] = getid3_lib::LittleEndian2Int(substr($ExtensionBlockData, 1, 1)); -// $ExtensionBlock['byte_length'] = getid3_lib::LittleEndian2Int(substr($ExtensionBlockData, 2, 1)); -// $ExtensionBlock['data'] = fread($fd, $ExtensionBlock['byte_length']); -// $ThisFileInfo['gif']['extension_blocks'][] = $ExtensionBlock; -// break; -// -// case ';': -// $ThisFileInfo['gif']['terminator_offset'] = ftell($fd) - 1; -// // GIF Terminator -// break; -// -// default: -// break; -// -// -// } -// } - - return true; - } - - - function GetLSBits($fd, $bits) { - static $bitbuffer = ''; - while (strlen($bitbuffer) < $bits) { -//echo 'Read another byte: '.ftell($fd).'
'; - $bitbuffer = str_pad(decbin(ord(fread($fd, 1))), 8, '0', STR_PAD_LEFT).$bitbuffer; - } - - $value = bindec(substr($bitbuffer, 0 - $bits)); - $bitbuffer = substr($bitbuffer, 0, 0 - $bits); - - return $value; - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.graphic.svg.php b/serendipity_event_podcast/player/getid3/module.graphic.svg.php deleted file mode 100644 index 65bdbacb..00000000 --- a/serendipity_event_podcast/player/getid3/module.graphic.svg.php +++ /dev/null @@ -1,102 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.graphic.svg.php // -// module for analyzing SVG Image files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_svg -{ - - - function getid3_svg(&$fd, &$ThisFileInfo) { - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - - $SVGheader = fread($fd, 4096); - if (preg_match('#\<\?xml([^\>]+)\?\>#i', $SVGheader, $matches)) { - $ThisFileInfo['svg']['xml']['raw'] = $matches; - } - if (preg_match('#\<\!DOCTYPE([^\>]+)\>#i', $SVGheader, $matches)) { - $ThisFileInfo['svg']['doctype']['raw'] = $matches; - } - if (preg_match('#\]+)\>#i', $SVGheader, $matches)) { - $ThisFileInfo['svg']['svg']['raw'] = $matches; - } - if (isset($ThisFileInfo['svg']['svg']['raw'])) { - - $sections_to_fix = array('xml', 'doctype', 'svg'); - foreach ($sections_to_fix as $section_to_fix) { - if (!isset($ThisFileInfo['svg'][$section_to_fix])) { - continue; - } - $section_data = array(); - while (preg_match('/ "([^"]+)"/', $ThisFileInfo['svg'][$section_to_fix]['raw'][1], $matches)) { - $section_data[] = $matches[1]; - $ThisFileInfo['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $ThisFileInfo['svg'][$section_to_fix]['raw'][1]); - } - while (preg_match('/([^\s]+)="([^"]+)"/', $ThisFileInfo['svg'][$section_to_fix]['raw'][1], $matches)) { - $section_data[] = $matches[0]; - $ThisFileInfo['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $ThisFileInfo['svg'][$section_to_fix]['raw'][1]); - } - $section_data = array_merge($section_data, preg_split('/[\s,]+/', $ThisFileInfo['svg'][$section_to_fix]['raw'][1])); - foreach ($section_data as $keyvaluepair) { - $keyvaluepair = trim($keyvaluepair); - if ($keyvaluepair) { - $keyvalueexploded = explode('=', $keyvaluepair); - $key = (isset($keyvalueexploded[0]) ? $keyvalueexploded[0] : ''); - $value = (isset($keyvalueexploded[1]) ? $keyvalueexploded[1] : ''); - $ThisFileInfo['svg'][$section_to_fix]['sections'][$key] = trim($value, '"'); - } - } - } - - $ThisFileInfo['fileformat'] = 'svg'; - $ThisFileInfo['video']['dataformat'] = 'svg'; - $ThisFileInfo['video']['lossless'] = true; - //$ThisFileInfo['video']['bits_per_sample'] = 24; - $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1; - - if (!empty($ThisFileInfo['svg']['svg']['sections']['width'])) { - $ThisFileInfo['svg']['width'] = intval($ThisFileInfo['svg']['svg']['sections']['width']); - } - if (!empty($ThisFileInfo['svg']['svg']['sections']['height'])) { - $ThisFileInfo['svg']['height'] = intval($ThisFileInfo['svg']['svg']['sections']['height']); - } - if (!empty($ThisFileInfo['svg']['svg']['sections']['version'])) { - $ThisFileInfo['svg']['version'] = $ThisFileInfo['svg']['svg']['sections']['version']; - } - if (!isset($ThisFileInfo['svg']['version']) && isset($ThisFileInfo['svg']['doctype']['sections'])) { - foreach ($ThisFileInfo['svg']['doctype']['sections'] as $key => $value) { - if (preg_match('#//W3C//DTD SVG ([0-9\.]+)//#i', $key, $matches)) { - $ThisFileInfo['svg']['version'] = $matches[1]; - break; - } - } - } - - if (!empty($ThisFileInfo['svg']['width'])) { - $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['svg']['width']; - } - if (!empty($ThisFileInfo['svg']['height'])) { - $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['svg']['height']; - } - - return true; - } - $ThisFileInfo['error'][] = 'Did not find expected tag'; - return false; - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.graphic.tiff.php b/serendipity_event_podcast/player/getid3/module.graphic.tiff.php deleted file mode 100644 index 971dc552..00000000 --- a/serendipity_event_podcast/player/getid3/module.graphic.tiff.php +++ /dev/null @@ -1,226 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.archive.tiff.php // -// module for analyzing TIFF files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_tiff -{ - - function getid3_tiff(&$fd, &$ThisFileInfo) { - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $TIFFheader = fread($fd, 4); - - switch (substr($TIFFheader, 0, 2)) { - case 'II': - $ThisFileInfo['tiff']['byte_order'] = 'Intel'; - break; - case 'MM': - $ThisFileInfo['tiff']['byte_order'] = 'Motorola'; - break; - default: - $ThisFileInfo['error'][] = 'Invalid TIFF byte order identifier ('.substr($TIFFheader, 0, 2).') at offset '.$ThisFileInfo['avdataoffset']; - return false; - break; - } - - $ThisFileInfo['fileformat'] = 'tiff'; - $ThisFileInfo['video']['dataformat'] = 'tiff'; - $ThisFileInfo['video']['lossless'] = true; - $ThisFileInfo['tiff']['ifd'] = array(); - $CurrentIFD = array(); - - $FieldTypeByteLength = array(1=>1, 2=>1, 3=>2, 4=>4, 5=>8); - - $nextIFDoffset = $this->TIFFendian2Int(fread($fd, 4), $ThisFileInfo['tiff']['byte_order']); - - while ($nextIFDoffset > 0) { - - $CurrentIFD['offset'] = $nextIFDoffset; - - fseek($fd, $ThisFileInfo['avdataoffset'] + $nextIFDoffset, SEEK_SET); - $CurrentIFD['fieldcount'] = $this->TIFFendian2Int(fread($fd, 2), $ThisFileInfo['tiff']['byte_order']); - - for ($i = 0; $i < $CurrentIFD['fieldcount']; $i++) { - $CurrentIFD['fields'][$i]['raw']['tag'] = $this->TIFFendian2Int(fread($fd, 2), $ThisFileInfo['tiff']['byte_order']); - $CurrentIFD['fields'][$i]['raw']['type'] = $this->TIFFendian2Int(fread($fd, 2), $ThisFileInfo['tiff']['byte_order']); - $CurrentIFD['fields'][$i]['raw']['length'] = $this->TIFFendian2Int(fread($fd, 4), $ThisFileInfo['tiff']['byte_order']); - $CurrentIFD['fields'][$i]['raw']['offset'] = fread($fd, 4); - - switch ($CurrentIFD['fields'][$i]['raw']['type']) { - case 1: // BYTE An 8-bit unsigned integer. - if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) { - $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['offset'], 0, 1), $ThisFileInfo['tiff']['byte_order']); - } else { - $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $ThisFileInfo['tiff']['byte_order']); - } - break; - - case 2: // ASCII 8-bit bytes that store ASCII codes; the last byte must be null. - if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) { - $CurrentIFD['fields'][$i]['value'] = substr($CurrentIFD['fields'][$i]['raw']['offset'], 3); - } else { - $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $ThisFileInfo['tiff']['byte_order']); - } - break; - - case 3: // SHORT A 16-bit (2-byte) unsigned integer. - if ($CurrentIFD['fields'][$i]['raw']['length'] <= 2) { - $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['offset'], 0, 2), $ThisFileInfo['tiff']['byte_order']); - } else { - $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $ThisFileInfo['tiff']['byte_order']); - } - break; - - case 4: // LONG A 32-bit (4-byte) unsigned integer. - if ($CurrentIFD['fields'][$i]['raw']['length'] <= 1) { - $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $ThisFileInfo['tiff']['byte_order']); - } else { - $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['offset'], $ThisFileInfo['tiff']['byte_order']); - } - break; - - case 5: // RATIONAL Two LONG_s: the first represents the numerator of a fraction, the second the denominator. - break; - } - } - - $ThisFileInfo['tiff']['ifd'][] = $CurrentIFD; - $CurrentIFD = array(); - $nextIFDoffset = $this->TIFFendian2Int(fread($fd, 4), $ThisFileInfo['tiff']['byte_order']); - - } - - foreach ($ThisFileInfo['tiff']['ifd'] as $IFDid => $IFDarray) { - foreach ($IFDarray['fields'] as $key => $fieldarray) { - switch ($fieldarray['raw']['tag']) { - case 256: // ImageWidth - case 257: // ImageLength - case 258: // BitsPerSample - case 259: // Compression - if (!isset($fieldarray['value'])) { - fseek($fd, $fieldarray['offset'], SEEK_SET); - $ThisFileInfo['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = fread($fd, $fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]); - - } - break; - - case 270: // ImageDescription - case 271: // Make - case 272: // Model - case 305: // Software - case 306: // DateTime - case 315: // Artist - case 316: // HostComputer - if (isset($fieldarray['value'])) { - $ThisFileInfo['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $fieldarray['value']; - } else { - fseek($fd, $fieldarray['offset'], SEEK_SET); - $ThisFileInfo['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = fread($fd, $fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]); - - } - break; - } - switch ($fieldarray['raw']['tag']) { - case 256: // ImageWidth - $ThisFileInfo['video']['resolution_x'] = $fieldarray['value']; - break; - - case 257: // ImageLength - $ThisFileInfo['video']['resolution_y'] = $fieldarray['value']; - break; - - case 258: // BitsPerSample - if (isset($fieldarray['value'])) { - $ThisFileInfo['video']['bits_per_sample'] = $fieldarray['value']; - } else { - $ThisFileInfo['video']['bits_per_sample'] = 0; - for ($i = 0; $i < $fieldarray['raw']['length']; $i++) { - $ThisFileInfo['video']['bits_per_sample'] += $this->TIFFendian2Int(substr($ThisFileInfo['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'], $i * $FieldTypeByteLength[$fieldarray['raw']['type']], $FieldTypeByteLength[$fieldarray['raw']['type']]), $ThisFileInfo['tiff']['byte_order']); - } - } - break; - - case 259: // Compression - $ThisFileInfo['video']['codec'] = $this->TIFFcompressionMethod($fieldarray['value']); - break; - - case 270: // ImageDescription - case 271: // Make - case 272: // Model - case 305: // Software - case 306: // DateTime - case 315: // Artist - case 316: // HostComputer - $TIFFcommentName = $this->TIFFcommentName($fieldarray['raw']['tag']); - if (isset($ThisFileInfo['tiff']['comments'][$TIFFcommentName])) { - $ThisFileInfo['tiff']['comments'][$TIFFcommentName][] = $ThisFileInfo['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data']; - } else { - $ThisFileInfo['tiff']['comments'][$TIFFcommentName] = array($ThisFileInfo['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data']); - } - break; - - default: - break; - } - } - } - - return true; - } - - - function TIFFendian2Int($bytestring, $byteorder) { - if ($byteorder == 'Intel') { - return getid3_lib::LittleEndian2Int($bytestring); - } elseif ($byteorder == 'Motorola') { - return getid3_lib::BigEndian2Int($bytestring); - } - return false; - } - - function TIFFcompressionMethod($id) { - static $TIFFcompressionMethod = array(); - if (empty($TIFFcompressionMethod)) { - $TIFFcompressionMethod = array( - 1 => 'Uncompressed', - 2 => 'Huffman', - 3 => 'Fax - CCITT 3', - 5 => 'LZW', - 32773 => 'PackBits', - ); - } - return (isset($TIFFcompressionMethod[$id]) ? $TIFFcompressionMethod[$id] : 'unknown/invalid ('.$id.')'); - } - - function TIFFcommentName($id) { - static $TIFFcommentName = array(); - if (empty($TIFFcommentName)) { - $TIFFcommentName = array( - 270 => 'imagedescription', - 271 => 'make', - 272 => 'model', - 305 => 'software', - 306 => 'datetime', - 315 => 'artist', - 316 => 'hostcomputer', - ); - } - return (isset($TIFFcommentName[$id]) ? $TIFFcommentName[$id] : 'unknown/invalid ('.$id.')'); - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.misc.doc.php b/serendipity_event_podcast/player/getid3/module.misc.doc.php deleted file mode 100644 index cb65abf2..00000000 --- a/serendipity_event_podcast/player/getid3/module.misc.doc.php +++ /dev/null @@ -1,32 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.archive.doc.php // -// module for analyzing MS Office (.doc, .xls, etc) files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_doc -{ - - function getid3_doc(&$fd, &$ThisFileInfo) { - - $ThisFileInfo['fileformat'] = 'doc'; - - $ThisFileInfo['error'][] = 'MS Office (.doc, .xls, etc) parsing not enabled in this version of getID3()'; - return false; - - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.misc.exe.php b/serendipity_event_podcast/player/getid3/module.misc.exe.php deleted file mode 100644 index 8c6bfcf9..00000000 --- a/serendipity_event_podcast/player/getid3/module.misc.exe.php +++ /dev/null @@ -1,59 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.misc.exe.php // -// module for analyzing EXE files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_exe -{ - - function getid3_exe(&$fd, &$ThisFileInfo) { - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $EXEheader = fread($fd, 28); - - if (substr($EXEheader, 0, 2) != 'MZ') { - $ThisFileInfo['error'][] = 'Expecting "MZ" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($EXEheader, 0, 2).'" instead.'; - return false; - } - - $ThisFileInfo['fileformat'] = 'exe'; - $ThisFileInfo['exe']['mz']['magic'] = 'MZ'; - - $ThisFileInfo['exe']['mz']['raw']['last_page_size'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 2, 2)); - $ThisFileInfo['exe']['mz']['raw']['page_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 4, 2)); - $ThisFileInfo['exe']['mz']['raw']['relocation_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 6, 2)); - $ThisFileInfo['exe']['mz']['raw']['header_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 8, 2)); - $ThisFileInfo['exe']['mz']['raw']['min_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 10, 2)); - $ThisFileInfo['exe']['mz']['raw']['max_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 12, 2)); - $ThisFileInfo['exe']['mz']['raw']['initial_ss'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 14, 2)); - $ThisFileInfo['exe']['mz']['raw']['initial_sp'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 16, 2)); - $ThisFileInfo['exe']['mz']['raw']['checksum'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 18, 2)); - $ThisFileInfo['exe']['mz']['raw']['cs_ip'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 20, 4)); - $ThisFileInfo['exe']['mz']['raw']['relocation_table_offset'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 24, 2)); - $ThisFileInfo['exe']['mz']['raw']['overlay_number'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 26, 2)); - - $ThisFileInfo['exe']['mz']['byte_size'] = (($ThisFileInfo['exe']['mz']['raw']['page_count'] - 1)) * 512 + $ThisFileInfo['exe']['mz']['raw']['last_page_size']; - $ThisFileInfo['exe']['mz']['header_size'] = $ThisFileInfo['exe']['mz']['raw']['header_paragraphs'] * 16; - $ThisFileInfo['exe']['mz']['memory_minimum'] = $ThisFileInfo['exe']['mz']['raw']['min_memory_paragraphs'] * 16; - $ThisFileInfo['exe']['mz']['memory_recommended'] = $ThisFileInfo['exe']['mz']['raw']['max_memory_paragraphs'] * 16; - -$ThisFileInfo['error'][] = 'EXE parsing not enabled in this version of getID3()'; -return false; - - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.misc.msoffice.php b/serendipity_event_podcast/player/getid3/module.misc.msoffice.php deleted file mode 100644 index d12f02d4..00000000 --- a/serendipity_event_podcast/player/getid3/module.misc.msoffice.php +++ /dev/null @@ -1,38 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.archive.doc.php // -// module for analyzing MS Office (.doc, .xls, etc) files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_msoffice -{ - - function getid3_msoffice(&$fd, &$ThisFileInfo) { - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $DOCFILEheader = fread($fd, 8); - $magic = "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"; - if (substr($DOCFILEheader, 0, 8) != $magic) { - $ThisFileInfo['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at '.$ThisFileInfo['avdataoffset'].', found '.getid3_lib::PrintHexBytes(substr($DOCFILEheader, 0, 8)).' instead.'; - return false; - } - $ThisFileInfo['fileformat'] = 'msoffice'; - -$ThisFileInfo['error'][] = 'MS Office (.doc, .xls, etc) parsing not enabled in this version of getID3() [v'.GETID3_VERSION.']'; -return false; - - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.misc.pdf.php b/serendipity_event_podcast/player/getid3/module.misc.pdf.php deleted file mode 100644 index c6e3294b..00000000 --- a/serendipity_event_podcast/player/getid3/module.misc.pdf.php +++ /dev/null @@ -1,32 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.misc.pdf.php // -// module for analyzing PDF files // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - - -class getid3_pdf -{ - - function getid3_pdf(&$fd, &$ThisFileInfo) { - - $ThisFileInfo['fileformat'] = 'pdf'; - - $ThisFileInfo['error'][] = 'PDF parsing not enabled in this version of getID3()'; - return false; - - } - -} - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.tag.apetag.php b/serendipity_event_podcast/player/getid3/module.tag.apetag.php deleted file mode 100644 index aba0ea0e..00000000 --- a/serendipity_event_podcast/player/getid3/module.tag.apetag.php +++ /dev/null @@ -1,332 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// module.tag.apetag.php // -// module for analyzing APE tags // -// dependencies: NONE // -// /// -///////////////////////////////////////////////////////////////// - -class getid3_apetag -{ - - function getid3_apetag(&$fd, &$ThisFileInfo, $overrideendoffset=0) { - - if (!getid3_lib::intValueSupported($ThisFileInfo['filesize'])) { - $ThisFileInfo['warning'][] = 'Unable to check for APEtags because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; - return false; - } - - $id3v1tagsize = 128; - $apetagheadersize = 32; - $lyrics3tagsize = 10; - - if ($overrideendoffset == 0) { - - fseek($fd, 0 - $id3v1tagsize - $apetagheadersize - $lyrics3tagsize, SEEK_END); - $APEfooterID3v1 = fread($fd, $id3v1tagsize + $apetagheadersize + $lyrics3tagsize); - - //if (preg_match('/APETAGEX.{24}TAG.{125}$/i', $APEfooterID3v1)) { - if (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $id3v1tagsize - $apetagheadersize, 8) == 'APETAGEX') { - - // APE tag found before ID3v1 - $ThisFileInfo['ape']['tag_offset_end'] = $ThisFileInfo['filesize'] - $id3v1tagsize; - - //} elseif (preg_match('/APETAGEX.{24}$/i', $APEfooterID3v1)) { - } elseif (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $apetagheadersize, 8) == 'APETAGEX') { - - // APE tag found, no ID3v1 - $ThisFileInfo['ape']['tag_offset_end'] = $ThisFileInfo['filesize']; - - } - - } else { - - fseek($fd, $overrideendoffset - $apetagheadersize, SEEK_SET); - if (fread($fd, 8) == 'APETAGEX') { - $ThisFileInfo['ape']['tag_offset_end'] = $overrideendoffset; - } - - } - if (!isset($ThisFileInfo['ape']['tag_offset_end'])) { - - // APE tag not found - unset($ThisFileInfo['ape']); - return false; - - } - - // shortcut - $thisfile_ape = &$ThisFileInfo['ape']; - - fseek($fd, $thisfile_ape['tag_offset_end'] - $apetagheadersize, SEEK_SET); - $APEfooterData = fread($fd, 32); - if (!($thisfile_ape['footer'] = $this->parseAPEheaderFooter($APEfooterData))) { - $ThisFileInfo['error'][] = 'Error parsing APE footer at offset '.$thisfile_ape['tag_offset_end']; - return false; - } - - if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) { - fseek($fd, $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'] - $apetagheadersize, SEEK_SET); - $thisfile_ape['tag_offset_start'] = ftell($fd); - $APEtagData = fread($fd, $thisfile_ape['footer']['raw']['tagsize'] + $apetagheadersize); - } else { - $thisfile_ape['tag_offset_start'] = $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize']; - fseek($fd, $thisfile_ape['tag_offset_start'], SEEK_SET); - $APEtagData = fread($fd, $thisfile_ape['footer']['raw']['tagsize']); - } - $ThisFileInfo['avdataend'] = $thisfile_ape['tag_offset_start']; - - if (isset($ThisFileInfo['id3v1']['tag_offset_start']) && ($ThisFileInfo['id3v1']['tag_offset_start'] < $thisfile_ape['tag_offset_end'])) { - $ThisFileInfo['warning'][] = 'ID3v1 tag information ignored since it appears to be a false synch in APEtag data'; - unset($ThisFileInfo['id3v1']); - foreach ($ThisFileInfo['warning'] as $key => $value) { - if ($value == 'Some ID3v1 fields do not use NULL characters for padding') { - unset($ThisFileInfo['warning'][$key]); - sort($ThisFileInfo['warning']); - break; - } - } - } - - $offset = 0; - if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) { - if ($thisfile_ape['header'] = $this->parseAPEheaderFooter(substr($APEtagData, 0, $apetagheadersize))) { - $offset += $apetagheadersize; - } else { - $ThisFileInfo['error'][] = 'Error parsing APE header at offset '.$thisfile_ape['tag_offset_start']; - return false; - } - } - - // shortcut - $ThisFileInfo['replay_gain'] = array(); - $thisfile_replaygain = &$ThisFileInfo['replay_gain']; - - for ($i = 0; $i < $thisfile_ape['footer']['raw']['tag_items']; $i++) { - $value_size = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4)); - $offset += 4; - $item_flags = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4)); - $offset += 4; - if (strstr(substr($APEtagData, $offset), "\x00") === false) { - $ThisFileInfo['error'][] = 'Cannot find null-byte (0x00) seperator between ItemKey #'.$i.' and value. ItemKey starts '.$offset.' bytes into the APE tag, at file offset '.($thisfile_ape['tag_offset_start'] + $offset); - return false; - } - $ItemKeyLength = strpos($APEtagData, "\x00", $offset) - $offset; - $item_key = strtolower(substr($APEtagData, $offset, $ItemKeyLength)); - - // shortcut - $thisfile_ape['items'][$item_key] = array(); - $thisfile_ape_items_current = &$thisfile_ape['items'][$item_key]; - - $thisfile_ape_items_current['offset'] = $thisfile_ape['tag_offset_start'] + $offset; - - $offset += ($ItemKeyLength + 1); // skip 0x00 terminator - $thisfile_ape_items_current['data'] = substr($APEtagData, $offset, $value_size); - $offset += $value_size; - - $thisfile_ape_items_current['flags'] = $this->parseAPEtagFlags($item_flags); - switch ($thisfile_ape_items_current['flags']['item_contents_raw']) { - case 0: // UTF-8 - case 3: // Locator (URL, filename, etc), UTF-8 encoded - $thisfile_ape_items_current['data'] = explode("\x00", trim($thisfile_ape_items_current['data'])); - break; - - default: // binary data - break; - } - - switch (strtolower($item_key)) { - case 'replaygain_track_gain': - $thisfile_replaygain['track']['adjustment'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero! - $thisfile_replaygain['track']['originator'] = 'unspecified'; - break; - - case 'replaygain_track_peak': - $thisfile_replaygain['track']['peak'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero! - $thisfile_replaygain['track']['originator'] = 'unspecified'; - if ($thisfile_replaygain['track']['peak'] <= 0) { - $ThisFileInfo['warning'][] = 'ReplayGain Track peak from APEtag appears invalid: '.$thisfile_replaygain['track']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")'; - } - break; - - case 'replaygain_album_gain': - $thisfile_replaygain['album']['adjustment'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero! - $thisfile_replaygain['album']['originator'] = 'unspecified'; - break; - - case 'replaygain_album_peak': - $thisfile_replaygain['album']['peak'] = (float) str_replace(',', '.', $thisfile_ape_items_current['data'][0]); // float casting will see "0,95" as zero! - $thisfile_replaygain['album']['originator'] = 'unspecified'; - if ($thisfile_replaygain['album']['peak'] <= 0) { - $ThisFileInfo['warning'][] = 'ReplayGain Album peak from APEtag appears invalid: '.$thisfile_replaygain['album']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")'; - } - break; - - case 'mp3gain_undo': - list($mp3gain_undo_left, $mp3gain_undo_right, $mp3gain_undo_wrap) = explode(',', $thisfile_ape_items_current['data'][0]); - $thisfile_replaygain['mp3gain']['undo_left'] = intval($mp3gain_undo_left); - $thisfile_replaygain['mp3gain']['undo_right'] = intval($mp3gain_undo_right); - $thisfile_replaygain['mp3gain']['undo_wrap'] = (($mp3gain_undo_wrap == 'Y') ? true : false); - break; - - case 'mp3gain_minmax': - list($mp3gain_globalgain_min, $mp3gain_globalgain_max) = explode(',', $thisfile_ape_items_current['data'][0]); - $thisfile_replaygain['mp3gain']['globalgain_track_min'] = intval($mp3gain_globalgain_min); - $thisfile_replaygain['mp3gain']['globalgain_track_max'] = intval($mp3gain_globalgain_max); - break; - - case 'mp3gain_album_minmax': - list($mp3gain_globalgain_album_min, $mp3gain_globalgain_album_max) = explode(',', $thisfile_ape_items_current['data'][0]); - $thisfile_replaygain['mp3gain']['globalgain_album_min'] = intval($mp3gain_globalgain_album_min); - $thisfile_replaygain['mp3gain']['globalgain_album_max'] = intval($mp3gain_globalgain_album_max); - break; - - case 'tracknumber': - if (is_array($thisfile_ape_items_current['data'])) { - foreach ($thisfile_ape_items_current['data'] as $comment) { - $thisfile_ape['comments']['track'][] = $comment; - } - } - break; - - case 'cover art (artist)': - case 'cover art (back)': - case 'cover art (band logo)': - case 'cover art (band)': - case 'cover art (colored fish)': - case 'cover art (composer)': - case 'cover art (conductor)': - case 'cover art (front)': - case 'cover art (icon)': - case 'cover art (illustration)': - case 'cover art (lead)': - case 'cover art (leaflet)': - case 'cover art (lyricist)': - case 'cover art (media)': - case 'cover art (movie scene)': - case 'cover art (other icon)': - case 'cover art (other)': - case 'cover art (performance)': - case 'cover art (publisher logo)': - case 'cover art (recording)': - case 'cover art (studio)': - // list of possible cover arts from http://taglib-sharp.sourcearchive.com/documentation/2.0.3.0-2/Ape_2Tag_8cs-source.html - list($thisfile_ape_items_current['filename'], $thisfile_ape_items_current['data']) = explode("\x00", $thisfile_ape_items_current['data'], 2); - $thisfile_ape_items_current['dataoffset'] = $thisfile_ape_items_current['offset'] + strlen($thisfile_ape_items_current['filename']."\x00"); - - $thisfile_ape_items_current['image_mime'] = ''; - $imageinfo = array(); - $imagechunkcheck = getid3_lib::GetDataImageSize($thisfile_ape_items_current['data'], $imageinfo); - $thisfile_ape_items_current['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]); - - if (!isset($ThisFileInfo['ape']['comments']['picture'])) { - $ThisFileInfo['ape']['comments']['picture'] = array(); - } - $ThisFileInfo['ape']['comments']['picture'][] = array('data'=>$thisfile_ape_items_current['data'], 'image_mime'=>$thisfile_ape_items_current['image_mime']); - break; - - default: - if (is_array($thisfile_ape_items_current['data'])) { - foreach ($thisfile_ape_items_current['data'] as $comment) { - $thisfile_ape['comments'][strtolower($item_key)][] = $comment; - } - } - break; - } - - } - if (empty($thisfile_replaygain)) { - unset($ThisFileInfo['replay_gain']); - } - - return true; - } - - function parseAPEheaderFooter($APEheaderFooterData) { - // http://www.uni-jena.de/~pfk/mpp/sv8/apeheader.html - - // shortcut - $headerfooterinfo['raw'] = array(); - $headerfooterinfo_raw = &$headerfooterinfo['raw']; - - $headerfooterinfo_raw['footer_tag'] = substr($APEheaderFooterData, 0, 8); - if ($headerfooterinfo_raw['footer_tag'] != 'APETAGEX') { - return false; - } - $headerfooterinfo_raw['version'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 8, 4)); - $headerfooterinfo_raw['tagsize'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 12, 4)); - $headerfooterinfo_raw['tag_items'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 16, 4)); - $headerfooterinfo_raw['global_flags'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 20, 4)); - $headerfooterinfo_raw['reserved'] = substr($APEheaderFooterData, 24, 8); - - $headerfooterinfo['tag_version'] = $headerfooterinfo_raw['version'] / 1000; - if ($headerfooterinfo['tag_version'] >= 2) { - $headerfooterinfo['flags'] = $this->parseAPEtagFlags($headerfooterinfo_raw['global_flags']); - } - return $headerfooterinfo; - } - - function parseAPEtagFlags($rawflagint) { - // "Note: APE Tags 1.0 do not use any of the APE Tag flags. - // All are set to zero on creation and ignored on reading." - // http://www.uni-jena.de/~pfk/mpp/sv8/apetagflags.html - $flags['header'] = (bool) ($rawflagint & 0x80000000); - $flags['footer'] = (bool) ($rawflagint & 0x40000000); - $flags['this_is_header'] = (bool) ($rawflagint & 0x20000000); - $flags['item_contents_raw'] = ($rawflagint & 0x00000006) >> 1; - $flags['read_only'] = (bool) ($rawflagint & 0x00000001); - - $flags['item_contents'] = $this->APEcontentTypeFlagLookup($flags['item_contents_raw']); - - return $flags; - } - - function APEcontentTypeFlagLookup($contenttypeid) { - static $APEcontentTypeFlagLookup = array( - 0 => 'utf-8', - 1 => 'binary', - 2 => 'external', - 3 => 'reserved' - ); - return (isset($APEcontentTypeFlagLookup[$contenttypeid]) ? $APEcontentTypeFlagLookup[$contenttypeid] : 'invalid'); - } - - function APEtagItemIsUTF8Lookup($itemkey) { - static $APEtagItemIsUTF8Lookup = array( - 'title', - 'subtitle', - 'artist', - 'album', - 'debut album', - 'publisher', - 'conductor', - 'track', - 'composer', - 'comment', - 'copyright', - 'publicationright', - 'file', - 'year', - 'record date', - 'record location', - 'genre', - 'media', - 'related', - 'isrc', - 'abstract', - 'language', - 'bibliography' - ); - return in_array(strtolower($itemkey), $APEtagItemIsUTF8Lookup); - } - -} - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/write.real.php b/serendipity_event_podcast/player/getid3/write.real.php deleted file mode 100644 index a64368e9..00000000 --- a/serendipity_event_podcast/player/getid3/write.real.php +++ /dev/null @@ -1,303 +0,0 @@ - // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // -///////////////////////////////////////////////////////////////// -// // -// write.real.php // -// module for writing RealAudio/RealVideo tags // -// dependencies: module.tag.real.php // -// /// -///////////////////////////////////////////////////////////////// - -class getid3_write_real -{ - var $filename; - var $tag_data = array(); - var $warnings = array(); // any non-critical errors will be stored here - var $errors = array(); // any critical errors will be stored here - var $paddedlength = 512; // minimum length of CONT tag in bytes - - function getid3_write_real() { - return true; - } - - function WriteReal() { - // File MUST be writeable - CHMOD(646) at least - if (is_writeable($this->filename)) { - ob_start(); - if ($fp_source = fopen($this->filename, 'r+b')) { - - ob_end_clean(); - // Initialize getID3 engine - $getID3 = new getID3; - $OldThisFileInfo = $getID3->analyze($this->filename); - if (empty($OldThisFileInfo['real']['chunks']) && !empty($OldThisFileInfo['real']['old_ra_header'])) { - $this->errors[] = 'Cannot write Real tags on old-style file format'; - fclose($fp_source); - return false; - } - - if (empty($OldThisFileInfo['real']['chunks'])) { - $this->errors[] = 'Cannot write Real tags because cannot find DATA chunk in file'; - fclose($fp_source); - return false; - } - foreach ($OldThisFileInfo['real']['chunks'] as $chunknumber => $chunkarray) { - $oldChunkInfo[$chunkarray['name']] = $chunkarray; - } - if (!empty($oldChunkInfo['CONT']['length'])) { - $this->paddedlength = max($oldChunkInfo['CONT']['length'], $this->paddedlength); - } - - $new_CONT_tag_data = $this->GenerateCONTchunk(); - $new_PROP_tag_data = $this->GeneratePROPchunk($OldThisFileInfo['real']['chunks'], $new_CONT_tag_data); - $new__RMF_tag_data = $this->GenerateRMFchunk($OldThisFileInfo['real']['chunks']); - - if (isset($oldChunkInfo['.RMF']['length']) && ($oldChunkInfo['.RMF']['length'] == strlen($new__RMF_tag_data))) { - fseek($fp_source, $oldChunkInfo['.RMF']['offset'], SEEK_SET); - fwrite($fp_source, $new__RMF_tag_data); - } else { - $this->errors[] = 'new .RMF tag ('.strlen($new__RMF_tag_data).' bytes) different length than old .RMF tag ('.$oldChunkInfo['.RMF']['length'].' bytes)'; - fclose($fp_source); - return false; - } - - if (isset($oldChunkInfo['PROP']['length']) && ($oldChunkInfo['PROP']['length'] == strlen($new_PROP_tag_data))) { - fseek($fp_source, $oldChunkInfo['PROP']['offset'], SEEK_SET); - fwrite($fp_source, $new_PROP_tag_data); - } else { - $this->errors[] = 'new PROP tag ('.strlen($new_PROP_tag_data).' bytes) different length than old PROP tag ('.$oldChunkInfo['PROP']['length'].' bytes)'; - fclose($fp_source); - return false; - } - - if (isset($oldChunkInfo['CONT']['length']) && ($oldChunkInfo['CONT']['length'] == strlen($new_CONT_tag_data))) { - - // new data length is same as old data length - just overwrite - fseek($fp_source, $oldChunkInfo['CONT']['offset'], SEEK_SET); - fwrite($fp_source, $new_CONT_tag_data); - fclose($fp_source); - return true; - - } else { - - if (empty($oldChunkInfo['CONT'])) { - // no existing CONT chunk - $BeforeOffset = $oldChunkInfo['DATA']['offset']; - $AfterOffset = $oldChunkInfo['DATA']['offset']; - } else { - // new data is longer than old data - $BeforeOffset = $oldChunkInfo['CONT']['offset']; - $AfterOffset = $oldChunkInfo['CONT']['offset'] + $oldChunkInfo['CONT']['length']; - } - if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) { - ob_start(); - if ($fp_temp = fopen($tempfilename, 'wb')) { - - rewind($fp_source); - fwrite($fp_temp, fread($fp_source, $BeforeOffset)); - fwrite($fp_temp, $new_CONT_tag_data); - fseek($fp_source, $AfterOffset, SEEK_SET); - while ($buffer = fread($fp_source, GETID3_FREAD_BUFFER_SIZE)) { - fwrite($fp_temp, $buffer, strlen($buffer)); - } - fclose($fp_temp); - - if (copy($tempfilename, $this->filename)) { - unlink($tempfilename); - fclose($fp_source); - return true; - } - unlink($tempfilename); - $this->errors[] = 'FAILED: copy('.$tempfilename.', '.$this->filename.') - '.strip_tags(ob_get_contents()); - - } else { - - $this->errors[] = 'Could not open '.$tempfilename.' mode "wb" - '.strip_tags(ob_get_contents()); - - } - ob_end_clean(); - } - fclose($fp_source); - return false; - - } - - - } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - $this->errors[] = 'Could not open '.$this->filename.' mode "r+b"'; - return false; - } - } - $this->errors[] = 'File is not writeable: '.$this->filename; - return false; - } - - function GenerateRMFchunk(&$chunks) { - $oldCONTexists = false; - foreach ($chunks as $key => $chunk) { - $chunkNameKeys[$chunk['name']] = $key; - if ($chunk['name'] == 'CONT') { - $oldCONTexists = true; - } - } - $newHeadersCount = $chunks[$chunkNameKeys['.RMF']]['headers_count'] + ($oldCONTexists ? 0 : 1); - - $RMFchunk = "\x00\x00"; // object version - $RMFchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['.RMF']]['file_version'], 4); - $RMFchunk .= getid3_lib::BigEndian2String($newHeadersCount, 4); - - $RMFchunk = '.RMF'.getid3_lib::BigEndian2String(strlen($RMFchunk) + 8, 4).$RMFchunk; // .RMF chunk identifier + chunk length - return $RMFchunk; - } - - function GeneratePROPchunk(&$chunks, &$new_CONT_tag_data) { - $old_CONT_length = 0; - $old_DATA_offset = 0; - $old_INDX_offset = 0; - foreach ($chunks as $key => $chunk) { - $chunkNameKeys[$chunk['name']] = $key; - if ($chunk['name'] == 'CONT') { - $old_CONT_length = $chunk['length']; - } elseif ($chunk['name'] == 'DATA') { - if (!$old_DATA_offset) { - $old_DATA_offset = $chunk['offset']; - } - } elseif ($chunk['name'] == 'INDX') { - if (!$old_INDX_offset) { - $old_INDX_offset = $chunk['offset']; - } - } - } - $CONTdelta = strlen($new_CONT_tag_data) - $old_CONT_length; - - $PROPchunk = "\x00\x00"; // object version - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['max_bit_rate'], 4); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['avg_bit_rate'], 4); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['max_packet_size'], 4); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['avg_packet_size'], 4); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['num_packets'], 4); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['duration'], 4); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['preroll'], 4); - $PROPchunk .= getid3_lib::BigEndian2String(max(0, $old_INDX_offset + $CONTdelta), 4); - $PROPchunk .= getid3_lib::BigEndian2String(max(0, $old_DATA_offset + $CONTdelta), 4); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['num_streams'], 2); - $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['flags_raw'], 2); - - $PROPchunk = 'PROP'.getid3_lib::BigEndian2String(strlen($PROPchunk) + 8, 4).$PROPchunk; // PROP chunk identifier + chunk length - return $PROPchunk; - } - - function GenerateCONTchunk() { - foreach ($this->tag_data as $key => $value) { - // limit each value to 0xFFFF bytes - $this->tag_data[$key] = substr($value, 0, 65535); - } - - $CONTchunk = "\x00\x00"; // object version - - $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['title']) ? strlen($this->tag_data['title']) : 0), 2); - $CONTchunk .= (!empty($this->tag_data['title']) ? strlen($this->tag_data['title']) : ''); - - $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['artist']) ? strlen($this->tag_data['artist']) : 0), 2); - $CONTchunk .= (!empty($this->tag_data['artist']) ? strlen($this->tag_data['artist']) : ''); - - $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['copyright']) ? strlen($this->tag_data['copyright']) : 0), 2); - $CONTchunk .= (!empty($this->tag_data['copyright']) ? strlen($this->tag_data['copyright']) : ''); - - $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['comment']) ? strlen($this->tag_data['comment']) : 0), 2); - $CONTchunk .= (!empty($this->tag_data['comment']) ? strlen($this->tag_data['comment']) : ''); - - if ($this->paddedlength > (strlen($CONTchunk) + 8)) { - $CONTchunk .= str_repeat("\x00", $this->paddedlength - strlen($CONTchunk) - 8); - } - - $CONTchunk = 'CONT'.getid3_lib::BigEndian2String(strlen($CONTchunk) + 8, 4).$CONTchunk; // CONT chunk identifier + chunk length - - return $CONTchunk; - } - - function RemoveReal() { - // File MUST be writeable - CHMOD(646) at least - if (is_writeable($this->filename)) { - ob_start(); - if ($fp_source = fopen($this->filename, 'r+b')) { - - ob_end_clean(); - // Initialize getID3 engine - $getID3 = new getID3; - $OldThisFileInfo = $getID3->analyze($this->filename); - if (empty($OldThisFileInfo['real']['chunks']) && !empty($OldThisFileInfo['real']['old_ra_header'])) { - $this->errors[] = 'Cannot remove Real tags from old-style file format'; - fclose($fp_source); - return false; - } - - if (empty($OldThisFileInfo['real']['chunks'])) { - $this->errors[] = 'Cannot remove Real tags because cannot find DATA chunk in file'; - fclose($fp_source); - return false; - } - foreach ($OldThisFileInfo['real']['chunks'] as $chunknumber => $chunkarray) { - $oldChunkInfo[$chunkarray['name']] = $chunkarray; - } - - if (empty($oldChunkInfo['CONT'])) { - // no existing CONT chunk - fclose($fp_source); - return true; - } - - $BeforeOffset = $oldChunkInfo['CONT']['offset']; - $AfterOffset = $oldChunkInfo['CONT']['offset'] + $oldChunkInfo['CONT']['length']; - if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) { - ob_start(); - if ($fp_temp = fopen($tempfilename, 'wb')) { - - rewind($fp_source); - fwrite($fp_temp, fread($fp_source, $BeforeOffset)); - fseek($fp_source, $AfterOffset, SEEK_SET); - while ($buffer = fread($fp_source, GETID3_FREAD_BUFFER_SIZE)) { - fwrite($fp_temp, $buffer, strlen($buffer)); - } - fclose($fp_temp); - - if (copy($tempfilename, $this->filename)) { - unlink($tempfilename); - fclose($fp_source); - return true; - } - unlink($tempfilename); - $this->errors[] = 'FAILED: copy('.$tempfilename.', '.$this->filename.') - '.strip_tags(ob_get_contents()); - - } else { - - $this->errors[] = 'Could not open '.$tempfilename.' mode "wb" - '.strip_tags(ob_get_contents()); - - } - ob_end_clean(); - } - fclose($fp_source); - return false; - - - } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - $this->errors[] = 'Could not open '.$this->filename.' mode "r+b"'; - return false; - } - } - $this->errors[] = 'File is not writeable: '.$this->filename; - return false; - } - -} - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/README.md b/serendipity_event_podcast/player/james-heinrich/getid3/README.md new file mode 100644 index 00000000..b967df5e --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/README.md @@ -0,0 +1,617 @@ +getID3() by James Heinrich () +=== +**Available at or ** + +getID3() is released under multiple licenses. You may choose from the following licenses, and use getID3 according to the terms of the license most suitable to your project. + +**GNU GPL:** + +* [v3](https://gnu.org/licenses/gpl.html) + +* [v2](https://gnu.org/licenses/old-licenses/gpl-2.0.html) + +* [v1](https://gnu.org/licenses/old-licenses/gpl-1.0.html) + +**GNU LGPL:** + +* [v3](https://gnu.org/licenses/lgpl.html) + +**Mozilla MPL:** + +* [v2](https://www.mozilla.org/MPL/2.0/) + +**getID3 Commercial License:** + +* [gCL](https://www.getid3.org/#gCL) (payment required) + +* * * +Copies of each of the above licenses are included in the `licenses/` +directory of the getID3 distribution. + +If you want to donate, there is a link on for PayPal donations. + + + +Quick Start +=== + +**Q:** How can I check that getID3() works on my server/files? + +**A:** Unzip getID3() to a directory, then access `/demos/demo.browse.php` + + + +Support +=== + +**Q:** I have a question, or I found a bug. What do I do? + +**A:** The preferred method of support requests and/or bug reports is the forum at + + + +Sourceforge Notification +=== + +It's highly recommended that you sign up for notification from +Sourceforge for when new versions are released. Please visit: + +and click the little "monitor package" icon/link. If you're +previously signed up for the mailing list, be aware that it has +been discontinued, only the automated Sourceforge notification +will be used from now on. + + + +What does getID3() do? +=== + +Reads & parses (to varying degrees): + ++ tags: + * APE (v1 and v2) + * ID3v1 (& ID3v1.1) + * ID3v2 (v2.4, v2.3, v2.2) + * Lyrics3 (v1 & v2) + ++ audio-lossy: + * MP3/MP2/MP1 + * MPC / Musepack + * Ogg (Vorbis, OggFLAC, Speex, Opus) + * AAC / MP4 + * AC3 + * DTS + * RealAudio + * Speex + * DSS + * VQF + ++ audio-lossless: + * AIFF + * AU + * Bonk + * CD-audio (*.cda) + * FLAC + * LA (Lossless Audio) + * LiteWave + * LPAC + * MIDI + * Monkey's Audio + * OptimFROG + * RKAU + * Shorten + * Tom's lossless Audio Kompressor (TAK) + * TTA + * VOC + * WAV (RIFF) + * WavPack + ++ audio-video: + * ASF: ASF, Windows Media Audio (WMA), Windows Media Video (WMV) + * AVI (RIFF) + * Flash + * Matroska (MKV) + * MPEG-1 / MPEG-2 + * NSV (Nullsoft Streaming Video) + * Quicktime (including MP4) + * RealVideo + ++ still image: + * BMP + * GIF + * JPEG + * PNG + * TIFF + * SWF (Flash) + * PhotoCD + ++ data: + * ISO-9660 CD-ROM image (directory structure) + * SZIP (limited support) + * ZIP (directory structure) + * TAR + * CUE + + ++ Writes: + * ID3v1 (& ID3v1.1) + * ID3v2 (v2.3 & v2.4) + * VorbisComment on OggVorbis + * VorbisComment on FLAC (not OggFLAC) + * APE v2 + * Lyrics3 (delete only) + + + +Requirements +=== + +* PHP 4.2.0 up to 5.2.x for getID3() 1.7.x (and earlier) +* PHP 5.0.5 (or higher) for getID3() 1.8.x (and up) +* PHP 5.0.5 (or higher) for getID3() 2.0.x (and up) +* at least 4MB memory for PHP. 8MB or more is highly recommended. + 12MB is required with all modules loaded. + +Installation +=== +The preferred method is via [composer](https://getcomposer.org/). Follow the installation [instructions](https://getcomposer.org/doc/00-intro.md) if you do not already have composer installed. + +Once composer is installed, execute the following command in your project root to install this library: + +``` +composer require james-heinrich/getid3 +``` + +Usage +=== + +See /demos/demo.basic.php for a very basic use of getID3() with no +fancy output, just scanning one file. + +See structure.txt for the returned data structure. + +**For an example of a complete directory-browsing, file-scanning implementation of getID3(), please run /demos/demo.browse.php** + +See /demos/demo.mysql.php for a sample recursive scanning code that +scans every file in a given directory, and all sub-directories, stores +the results in a database and allows various analysis / maintenance +operations + +To analyze remote files over HTTP or FTP you need to copy the file +locally first before running getID3(). Your code would look something +like this: + +``` php +analyze($localtempfilename); + // Delete temporary file + unlink($localtempfilename); + } + fclose($fp_remote); +} + +``` + + +**See /demos/demo.write.php for how to write tags.** + +What does the returned data structure look like? +=== + +See structure.txt + +It is recommended that you look at the output of +/demos/demo.browse.php scanning the file(s) you're interested in to +confirm what data is actually returned for any particular filetype in +general, and your files in particular, as the actual data returned +may vary considerably depending on what information is available in +the file itself. + + + +Notes +=== + +getID3() 1.x: +--- +If the format parser encounters a critical problem, it will return +something in `$fileinfo['error']`, describing the encountered error. If +a less critical error or notice is generated it will appear in +`$fileinfo['warning']`. Both keys may contain more than one warning or +error. If something is returned in ['error'] then the file was not +correctly parsed and returned data may or may not be correct and/or +complete. If something is returned in `['warning']` (and not `['error']`) +then the data that is returned is OK - usually getID3() is reporting +errors in the file that have been worked around due to known bugs in +other programs. Some warnings may indicate that the data that is +returned is OK but that some data could not be extracted due to +errors in the file. + +getID3() 2.x: +--- +See above except errors are thrown (so you will only get one error). + +Disclaimer +=== + +getID3() has been tested on many systems, on many types of files, +under many operating systems, and is generally believe to be stable +and safe. That being said, there is still the chance there is an +undiscovered and/or unfixed bug that may potentially corrupt your +file, especially within the writing functions. By using getID3() you +agree that it's not my fault if any of your files are corrupted. +In fact, I'm not liable for anything :) + +License +=== + +GNU General Public License - see license.txt + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to: +Free Software Foundation, Inc. +59 Temple Place - Suite 330 +Boston, MA 02111-1307, USA. + +FAQ: +--- +**Q:** Can I use getID3() in my program? Do I need a commercial license? + +**A:** You're generally free to use getID3 however you see fit. The only + case in which you would require a commercial license is if you're + selling your closed-source program that integrates getID3. If you + sell your program including a copy of getID3, that's fine as long + as you include a copy of the sourcecode when you sell it. Or you + can distribute your code without getID3 and say "download it from + getid3.sourceforge.net" + + + +Why is it called "getID3()" if it does so much more than just that? +=== + +v0.1 did in fact just do that. I don't have a copy of code that old, but I +could essentially write it today with a one-line function: + +``` php +function getID3($filename) { return unpack('a3TAG/a30title/a30artist/a30album/a4year/a28comment/c1track/c1genreid', substr(file_get_contents($filename), -128)); } + +``` + + +Future Plans +=== + + +* Better support for MP4 container format +* Scan for appended ID3v2 tag at end of file per ID3v2.4 specs (Section 5.0) +* Support for JPEG-2000 (http://www.morgan-multimedia.com/jpeg2000_overview.htm) +* Support for MOD (mod/stm/s3m/it/xm/mtm/ult/669) +* Support for ACE (thanks Vince) +* Support for Ogg other than Vorbis, Speex and OggFlac (ie. Ogg+Xvid) +* Ability to create Xing/LAME VBR header for VBR MP3s that are missing VBR header +* Ability to "clean" ID3v2 padding (replace invalid padding with valid padding) +* Warn if MP3s change version mid-stream (in full-scan mode) +* check for corrupt/broken mid-file MP3 streams in histogram scan +* Support for lossless-compression formats + (http://www.firstpr.com.au/audiocomp/lossless/#Links) + (http://compression.ca/act-sound.html) + (http://web.inter.nl.net/users/hvdh/lossless/lossless.htm) +* Support for RIFF-INFO chunks + * http://lotto.st-andrews.ac.uk/~njh/tag_interchange.html + (thanks Nick Humfrey ) + * http://abcavi.narod.ru/sof/abcavi/infotags.htm + (thanks Kibi) +* Better support for Bink video +* http://www.hr/josip/DSP/AudioFile2.html +* http://www.pcisys.net/~melanson/codecs/ +* Detect mp3PRO +* Support for PSD +* Support for JPC +* Support for JP2 +* Support for JPX +* Support for JB2 +* Support for IFF +* Support for ICO +* Support for ANI +* Support for EXE (comments, author, etc) (thanks p*quaedackersØplanet*nl) +* Support for DVD-IFO (region, subtitles, aspect ratio, etc) + (thanks p*quaedackersØplanet*nl) +* More complete support for SWF - parsing encapsulated MP3 and/or JPEG content + (thanks n8n8Øyahoo*com) +* Support for a2b +* Optional scan-through-frames for AVI verification + (thanks rockcohenØmassive-interactive*nl) +* Support for TTF (thanks infoØbutterflyx*com) +* Support for DSS (https://www.getid3.org/phpBB3/viewtopic.php?t=171) +* Support for SMAF (http://smaf-yamaha.com/what/demo.html) + https://www.getid3.org/phpBB3/viewtopic.php?t=182 +* Support for AMR (https://www.getid3.org/phpBB3/viewtopic.php?t=195) +* Support for 3gpp (https://www.getid3.org/phpBB3/viewtopic.php?t=195) +* Support for ID4 (http://www.wackysoft.cjb.net grizlyY2KØhotmail*com) +* Parse XML data returned in Ogg comments +* Parse XML data from Quicktime SMIL metafiles (klausrathØmac*com) +* ID3v2 genre string creator function +* More complete parsing of JPG +* Support for all old-style ASF packets +* ASF/WMA/WMV tag writing +* Parse declared T??? ID3v2 text information frames, where appropriate + (thanks Christian Fritz for the idea) +* Recognize encoder: + http://www.guerillasoft.com/EncSpot2/index.html + http://ff123.net/identify.html + http://www.hydrogenaudio.org/?act=ST&f=16&t=9414 + http://www.hydrogenaudio.org/?showtopic=11785 +* Support for other OS/2 bitmap structures: Bitmap Array('BA'), + Color Icon('CI'), Color Pointer('CP'), Icon('IC'), Pointer ('PT') + http://netghost.narod.ru/gff/graphics/summary/os2bmp.htm +* Support for WavPack RAW mode +* ASF/WMA/WMV data packet parsing +* ID3v2FrameFlagsLookupTagAlter() +* ID3v2FrameFlagsLookupFileAlter() +* obey ID3v2 tag alter/preserve/discard rules +* http://www.geocities.com/SiliconValley/Sector/9654/Softdoc/Illyrium/Aolyr.htm +* proper checking for LINK/LNK frame validity in ID3v2 writing +* proper checking for ASPI-TLEN frame validity in ID3v2 writing +* proper checking for COMR frame validity in ID3v2 writing +* http://www.geocities.co.jp/SiliconValley-Oakland/3664/index.html +* decode GEOB ID3v2 structure as encoded by RealJukebox, + decode NCON ID3v2 structure as encoded by MusicMatch + (probably won't happen - the formats are proprietary) + + + +Known Bugs/Issues in getID3() that may be fixed eventually +=== + + +* Cannot determine bitrate for MPEG video with VBR video data + (need documentation) +* Interlace/progressive cannot be determined for MPEG video + (need documentation) +* MIDI playtime is sometimes inaccurate +* AAC-RAW mode files cannot be identified +* WavPack-RAW mode files cannot be identified +* mp4 files report lots of "Unknown QuickTime atom type" + (need documentation) +* Encrypted ASF/WMA/WMV files warn about "unhandled GUID + ASF_Content_Encryption_Object" +* Bitrate split between audio and video cannot be calculated for + NSV, only the total bitrate. (need documentation) +* All Ogg formats (Vorbis, OggFLAC, Speex) are affected by the + problem of large VorbisComments spanning multiple Ogg pages, but + but only OggVorbis files can be processed with vorbiscomment. +* The version of "head" supplied with Mac OS 10.2.8 (maybe other + versions too) does only understands a single option (-n) and + therefore fails. getID3 ignores this and returns wrong md5_data. + + + +Known Bugs/Issues in getID3() that cannot be fixed +--- + + +* 32-bit PHP installations only: + Files larger than 2GB cannot always be parsed fully by getID3() + due to limitations in the 32-bit PHP filesystem functions. + NOTE: Since v1.7.8b3 there is partial support for larger-than- + 2GB files, most of which will parse OK, as long as no critical + data is located beyond the 2GB offset. + Known will-work: + * all file formats on 64-bit PHP + * ZIP (format doesn't support files >2GB) + * FLAC (current encoders don't support files >2GB) + Known will-not-work: + * ID3v1 tags (always located at end-of-file) + * Lyrics3 tags (always located at end-of-file) + * APE tags (always located at end-of-file) + Maybe-will-work: + * Quicktime (will work if needed metadata is before 2GB offset, + that is if the file has been hinted/optimized for streaming) + * RIFF.WAV (should work fine, but gives warnings about not being + able to parse all chunks) + * RIFF.AVI (playtime will probably be wrong, is only based on + "movi" chunk that fits in the first 2GB, should issue error + to show that playtime is incorrect. Other data should be mostly + correct, assuming that data is constant throughout the file) + + + +Known Bugs/Issues in other programs +--- + + +* Windows Media Player (up to v11) and iTunes (up to v10+) do + not correctly handle ID3v2.3 tags with UTF-16BE+BOM + encoding (they assume the data is UTF-16LE+BOM and either + crash (WMP) or output Asian character set (iTunes) +* Winamp (up to v2.80 at least) does not support ID3v2.4 tags, + only ID3v2.3 + see: http://forums.winamp.com/showthread.php?postid=387524 +* Some versions of Helium2 (www.helium2.com) do not write + ID3v2.4-compliant Frame Sizes, even though the tag is marked + as ID3v2.4) (detected by getID3()) +* MP3ext V3.3.17 places a non-compliant padding string at the end + of the ID3v2 header. This is supposedly fixed in v3.4b21 but + only if you manually add a registry key. This fix is not yet + confirmed. (detected by getID3()) +* CDex v1.40 (fixed by v1.50b7) writes non-compliant Ogg comment + strings, supposed to be in the format "NAME=value" but actually + written just "value" (detected by getID3()) +* Oggenc 0.9-rc3 flags the encoded file as ABR whether it's + actually ABR or VBR. +* iTunes (versions "X v2.0.3", "v3.0.1" are known-guilty, probably + other versions are too) writes ID3v2.3 comment tags using a + frame name 'COM ' which is not valid for ID3v2.3+ (it's an + ID3v2.2-style frame name) (detected by getID3()) +* MP2enc does not encode mono CBR MP2 files properly (half speed + sound and double playtime) +* MP2enc does not encode mono VBR MP2 files properly (actually + encoded as stereo) +* tooLAME does not encode mono VBR MP2 files properly (actually + encoded as stereo) +* AACenc encodes files in VBR mode (actually ABR) even if CBR is + specified +* AAC/ADIF - bitrate_mode = cbr for vbr files +* LAME 3.90-3.92 prepends one frame of null data (space for the + LAME/VBR header, but it never gets written) when encoding in CBR + mode with the DLL +* Ahead Nero encodes TwinVQF with a DSIZ value (which is supposed + to be the filesize in bytes) of "0" for TwinVQF v1.0 and "1" for + TwinVQF v2.0 (detected by getID3()) +* Ahead Nero encodes TwinVQF files 1 second shorter than they + should be +* AAC-ADTS files are always actually encoded VBR, even if CBR mode + is specified (the CBR-mode switches on the encoder enable ABR + mode, not CBR as such, but it's not possible to tell the + difference between such ABR files and true VBR) +* STREAMINFO.audio_signature in OggFLAC is always null. "The reason + it's like that is because there is no seeking support in + libOggFLAC yet, so it has no way to go back and write the + computed sum after encoding. Seeking support in Ogg FLAC is the + #1 item for the next release." - Josh Coalson (FLAC developer) + NOTE: getID3() will calculate md5_data in a method similar to + other file formats, but that value cannot be compared to the + md5_data value from FLAC data in a FLAC file format. +* STREAMINFO.audio_signature is not calculated in FLAC v0.3.0 & + v0.4.0 - getID3() will calculate md5_data in a method similar to + other file formats, but that value cannot be compared to the + md5_data value from FLAC v0.5.0+ +* RioPort (various versions including 2.0 and 3.11) tags ID3v2 with + a WCOM frame that has no data portion +* Earlier versions of Coolplayer adds illegal ID3 tags to Ogg Vorbis + files, thus making them corrupt. +* Meracl ID3 Tag Writer v1.3.4 (and older) incorrectly truncates the + last byte of data from an MP3 file when appending a new ID3v1 tag. + (detected by getID3()) +* Lossless-Audio files encoded with and without the -noseek switch + do actually differ internally and therefore cannot match md5_data +* iTunes has been known to append a new ID3v1 tag on the end of an + existing ID3v1 tag when ID3v2 tag is also present + (detected by getID3()) +* MediaMonkey may write a blank RGAD ID3v2 frame but put actual + replay gain adjustments in a series of user-defined TXXX frames + (detected and handled by getID3() since v1.9.2) + + + + +Reference material: +=== + +[www.id3.org](http://www.id3.org) material now mirrored at + +* http://www.id3.org/id3v2.4.0-structure.txt +* http://www.id3.org/id3v2.4.0-frames.txt +* http://www.id3.org/id3v2.4.0-changes.txt +* http://www.id3.org/id3v2.3.0.txt +* http://www.id3.org/id3v2-00.txt +* http://www.id3.org/mp3frame.html +* http://minnie.tuhs.org/pipermail/mp3encoder/2001-January/001800.html +* http://www.dv.co.yu/mpgscript/mpeghdr.htm +* http://www.mp3-tech.org/programmer/frame_header.html +* http://users.belgacom.net/gc247244/extra/tag.html +* http://gabriel.mp3-tech.org/mp3infotag.html +* http://www.id3.org/iso4217.html +* http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-1.TXT +* http://www.xiph.org/ogg/vorbis/doc/framing.html +* http://www.xiph.org/ogg/vorbis/doc/v-comment.html +* http://leknor.com/code/php/class.ogg.php.txt +* http://www.id3.org/iso639-2.html +* http://www.id3.org/lyrics3.html +* http://www.id3.org/lyrics3200.html +* http://www.psc.edu/general/software/packages/ieee/ieee.html +* http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html +* http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html +* http://www.jmcgowan.com/avi.html +* http://www.wotsit.org/ +* http://www.herdsoft.com/ti/davincie/davp3xo2.htm +* http://www.mathdogs.com/vorbis-illuminated/bitstream-appendix.html +* "Standard MIDI File Format" by Dustin Caldwell (from www.wotsit.org) +* http://midistudio.com/Help/GMSpecs_Patches.htm +* http://www.xiph.org/archives/vorbis/200109/0459.html +* http://www.replaygain.org/ +* http://www.lossless-audio.com/ +* http://download.microsoft.com/download/winmediatech40/Doc/1.0/WIN98MeXP/EN-US/ASF_Specification_v.1.0.exe +* http://mediaxw.sourceforge.net/files/doc/Active%20Streaming%20Format%20(ASF)%201.0%20Specification.pdf +* http://www.uni-jena.de/~pfk/mpp/sv8/ (archived at http://www.hydrogenaudio.org/musepack/klemm/www.personal.uni-jena.de/~pfk/mpp/sv8/) +* http://jfaul.de/atl/ +* http://www.uni-jena.de/~pfk/mpp/ (archived at http://www.hydrogenaudio.org/musepack/klemm/www.personal.uni-jena.de/~pfk/mpp/) +* http://www.libpng.org/pub/png/spec/png-1.2-pdg.html +* http://www.real.com/devzone/library/creating/rmsdk/doc/rmff.htm +* http://www.fastgraph.com/help/bmp_os2_header_format.html +* http://netghost.narod.ru/gff/graphics/summary/os2bmp.htm +* http://flac.sourceforge.net/format.html +* http://www.research.att.com/projects/mpegaudio/mpeg2.html +* http://www.audiocoding.com/wiki/index.php?page=AAC +* http://libmpeg.org/mpeg4/doc/w2203tfs.pdf +* http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt +* http://developer.apple.com/techpubs/quicktime/qtdevdocs/RM/frameset.htm +* http://www.nullsoft.com/nsv/ +* http://www.wotsit.org/download.asp?f=iso9660 +* http://sandbox.mc.edu/~bennet/cs110/tc/tctod.html +* http://www.cdroller.com/htm/readdata.html +* http://www.speex.org/manual/node10.html +* http://www.harmony-central.com/Computer/Programming/aiff-file-format.doc +* http://www.faqs.org/rfcs/rfc2361.html +* http://ghido.shelter.ro/ +* http://www.ebu.ch/tech_t3285.pdf +* http://www.sr.se/utveckling/tu/bwf +* http://ftp.aessc.org/pub/aes46-2002.pdf +* http://cartchunk.org:8080/ +* http://www.broadcastpapers.com/radio/cartchunk01.htm +* http://www.hr/josip/DSP/AudioFile2.html +* http://home.attbi.com/~chris.bagwell/AudioFormats-11.html +* http://www.pure-mac.com/extkey.html +* http://cesnet.dl.sourceforge.net/sourceforge/bonkenc/bonk-binary-format-0.9.txt +* http://www.headbands.com/gspot/ +* http://www.openswf.org/spec/SWFfileformat.html +* http://j-faul.virtualave.net/ +* http://www.btinternet.com/~AnthonyJ/Atari/programming/avr_format.html +* http://cui.unige.ch/OSG/info/AudioFormats/ap11.html +* http://sswf.sourceforge.net/SWFalexref.html +* http://www.geocities.com/xhelmboyx/quicktime/formats/qti-layout.txt +* http://www-lehre.informatik.uni-osnabrueck.de/~fbstark/diplom/docs/swf/Flash_Uncovered.htm +* http://developer.apple.com/quicktime/icefloe/dispatch012.html +* http://www.csdn.net/Dev/Format/graphics/PCD.htm +* http://tta.iszf.irk.ru/ +* http://www.atsc.org/standards/a_52a.pdf +* http://www.alanwood.net/unicode/ +* http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html +* http://www.its.msstate.edu/net/real/reports/config/tags.stats +* http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt +* http://brennan.young.net/Comp/LiveStage/things.html +* http://www.multiweb.cz/twoinches/MP3inside.htm +* http://www.geocities.co.jp/SiliconValley-Oakland/3664/alittle.html#GenreExtended +* http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/ +* http://www.unicode.org/unicode/faq/utf_bom.html +* http://tta.corecodec.org/?menu=format +* http://www.scvi.net/nsvformat.htm +* http://pda.etsi.org/pda/queryform.asp +* http://cpansearch.perl.org/src/RGIBSON/Audio-DSS-0.02/lib/Audio/DSS.pm +* http://trac.musepack.net/trac/wiki/SV8Specification +* http://wyday.com/cuesharp/specification.php +* http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html +* http://wiki.hydrogenaud.io/index.php?title=TAK diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/changelog.txt b/serendipity_event_podcast/player/james-heinrich/getid3/changelog.txt new file mode 100644 index 00000000..e6a6e586 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/changelog.txt @@ -0,0 +1,3034 @@ +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich // +// available at http://getid3.sourceforge.net // +// or https://www.getid3.org // +// also https://github.com/JamesHeinrich/getID3 // +///////////////////////////////////////////////////////////////// +// // +// changelog.txt - part of getID3() // +// See readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + + » denotes a major feature addition/change + ¤ denotes a change in the returned structure + ! denotes a cry for help from developers +* Bugfix: denotes a fixed bug + +Version History +=============== + +1.9.22: [2022-09-29] James Heinrich :: 1.9.22-202207161647 + * bugfix #387 fails to detect h265 video codec (QuickTime) + * bugfix #385 Quicktime extended atom size + * bugfix #378 AAC bitrate cache warning + * bugfix #376 simplexml_load_string improvments + * bugfix #374 MOD improved SoundTracker support + * bugfix #371 fragmented MP4 unsupported warning + * bugfix #369 fix remote URLs pattern + * bugfix #366 change @error-suppress to isset (quicktime) + * bugfix #365 ZIP array offset on value of type int + * bugfix #364 add support for ANIMEXTS1.0 in GIF files + * bugfix #363 ASF improve support of Header Extension Object data + * bugfix #362 version update for ramsey/composer-install + * bugfix #359 MPEG-2 aspect ratio divide-by-zero + * bugfix #358 free format mp3 bitrate + * bugfix #355 undefined array key in ID3v2 chapters + * bugfix #352 avoid false detection of Musepack format + * bugfix #351 Incorrect length passed to fread on a flac file + * bugfix #348 more targeted usage of clearstatcache calls + * bugfix #347 fixed reported by PHPStan v0.12.99 + * bugfix QuickTime support 'ID32' frame (ID3v2 inside QT) + * bugfix fix various PHP 8.1 issues + * bugfix PDF prevent undefined index + +1.9.21: [2021-09-22] James Heinrich :: 1.9.21-202109171300 + » add support for RIFF.guan + ¤ add ID3v1 genres 148-191 + ¤ torrent files easy access key + * bugfix #342 demo.mysqli.php XSS + * bugfix #340 default quicktime.ReturnAtomData=false + * bugfix #338 improved transliterated tag merging + * bugfix #337 PHP 8.1 compatibility + * bugfix #335 PHP 8.1 compatibility + * bugfix #330 QuicktimeContentRatingLookup 'rtng' + * bugfix #328 throw exception if a resource seek fails + * bugfix #326 improved temporary path detection + * bugfix #325 INF/NAN constants instead of float/string + * bugfix #324 Nikon-specific atoms in QuickTime + * bugfix #321 prevent errors on corrupt JPEGs + * bugfix #319 prevent error in ZIP contents MIME detect + * bugfix #315 ID3v2 USLT check for data length + * bugfix #308 silence libxml deprecation warning + * bugfix #304 undefined index: comments + * bugfix #299 decbin type error in PHP8 + * bugfix #298 error scanning WAV via file pointer + * bugfix #294 replace IMG_JPG with IMAGETYPE_JPEG + * bugfix #292 PDFs take long time to parse + * bugfix #291 divzero QuickTime with no playable content + * bugfix #290 detect ID3v1 on minimal example files + * bugfix #289 avoid crash on invalid TIFF + * bugfix #287 mp3 CBR detected as VBR + * bugfix #286 corrupt mp3 can cause slow scanning + * bugfix #284 allow "0" as a value in tags + * bugfix #283 array offset on value of type int + * bugfix #277 ID3v2 add new Turkish Lira TRY + * bugfix #270 demo.mysqli.php LONGBLOB + * bugfix #266 fix possible endless loop on PNG + * bugfix #257 undefined variables + * bugfix #207 improved LAME version string parsing + +1.9.20: [2020-06-30] James Heinrich :: 1.9.20-202006061653 + » add support for DSDIFF audio + » add support for TAK lossess audio + » add support for IVF video + » add detection support for EPUB files + » add detection support for HPK archives + » add demo.mysqli.php, remove demo.mysql.php + ¤ QuickTime.uuid now returned as an array (may contain multiple entries) + ¤ improved PDF support, including page count + * bugfix (G:247) array_min incorrect return value + * bugfix (G:242) filepointer analysis errors + * bugfix (G:238) comments_html may not match comments + * bugfix (G:235) prevent disclosing paths when accessing modules directly + * bugfix (G:233) Quicktime duplicate attached images + * bugfix (G:229) Quicktime timestamps easy access + * bugfix (G:228) master.zip did not contain demos + * bugfix (G:227) Quicktime check subatoms data length + * bugfix (G:226) uuid parsing based on UUID + * bugfix (G:225) use comments_html content already generated by modules + * bugfix (G:223) ID3v2 slashed genre names + * bugfix (G:222) demo.browse filesystem character encoding + * bugfix (G:221) option_tags_html=false ignored + * bugfix (G:219) Quicktime.UUID now parsed more discriminately for XML and other data types + * bugfix (G:218) QuickTime not copying covr to comments + * bugfix (G:217) mp3 array offsets of type bool + * bugfix (G:216) ID3v2.write allow WMP rating in POPM + * bugfix (G:210) PHP 7.4 deprecated get_magic_quotes + * bugfix: Quicktime detect null-terminated strings used where Pascal strings should be + * bugfix: Quicktime GPS uninitialized array keys + +1.9.19: [2019-12-17] James Heinrich :: 1.9.19-201912131005 + » add placeholder support for WTV (Windows Recorded TV Show) + * bugfix (G:210) PHP 7.4 deprecated get_magic_quotes + * bugfix (G:207) improved LAME version string parsing + * bugfix (G:206) inverted logic in CopyTagsToComments + * bugfix (G:203) use getimagesizefromstring if available + * Quicktime decode 'uuid' atom for 360fly cameras + +1.9.18: [2019-07-24] James Heinrich :: 1.9.18-201907240906 + * bugfix (G:198) use native hash functions instead of obsolete external binaries + * bugfix (G:194) PHP 7.4 compatibility: fix deprecated curly brace array access + * bugfix (G:191) unsupported operand types module.audio.ac3.php:763 + * bugfix (G:189) false UTF-16 and no termination strings + * bugfix (G:188) add support for DS2 v8 + * bugfix (G:187) RIFF.WAVE.scot parsing + * bugfix (G:184) invalid regex pattern (ID3v1) + * bugfix (G:183) reduced information for GIF files with $option_extra_info=false + * bugfix (G:175) mp4 max buffer size + * bugfix (G:174) TIFF parsing improvements + * bugfix (G:121) trailing nulls in ID3v2 strings + * standardize "track" -> "track_number" + +1.9.17: [2019-02-07] James Heinrich :: 1.9.17-201902071234 + * bugfix (G:178) HandleAllTags should skip "picture" + * bugfix (G:177) error checking for reading more than PHP memory_limit + * bugfix (G:176) improved mp3 detection in remote-file demo + * bugfix (G:173) Add filepointer option to analyze/openfile function + * bugfix (G:170) Add support for WXXX (URL) and APIC (attached picture) subframes inside ID3v2 chapters + * bugfix: write.id3v2 year field + * bugfix: mp3.APE permit optional " dB" in ReplayGain tags + * placeholder support for .xz file format + +1.9.16: [2018-10-17] James Heinrich :: 1.9.16-201810171314 + * bugfix (G:168) Ogg FLAC not parsed + * bugfix (G:163) invalid MP3 header error on VBR + * bugfix (G:162) prevent writing multiple ID3v2 versions + * bugfix (G:161) MP3 VBR header duration + * bugfix (G:160) OggOpus duration sometimes incorrect + * bugfix (G:157) quicktime GPS invalid argument + * bugfix (G:148) MPEG-2 aspect ratio + * bugfix (G:147) Quicktime fourcc codec name lookup + * bugfix (G:147) Quicktime audio/video bitrate guessing + * bugfix (G:145) incompatible variable types + * bugfix (G:139) Quicktime islt subatoms >5 + * bugfix (G:137) ID3v2 semi-numeric genres + * bugfix (G:136) ID3v2 unsynchronised typo + * bugfix (#2514) FLAC zero-byte block header + * bugfix (#2488) MIME types (FLAC, WAV, gzip) + * bugfix (#2468) Quicktime video rotation + * bugfix (#2207) metaflac + attached pictures + * bugfix (#2151) improved demo UNC filename support + * bugfix (#1966) fread fail when PHP memory_limit -1 + * bugfix (#1908) Quicktime rotation detection (using matrix values) + * bugfix (#1908) Quicktime "rcif" and "dscp" atoms + * bugfix (#1900) demo.joinmp3 cut from end + * security: avoid disabled demo reflection + * TIFF: expand list of named tags, expose as 'tag_name' key for all entries + * Quicktime: parse some GoPro-specific data + * helperapps (Windows): updated vorbiscomment.exe, metaflac.exe to v1.3.2 + * add more image formats supported by getimagesize() + +1.9.15: [2017-10-26] James Heinrich :: 1.9.15-201709291043 + » (G:108) add basic APNG support + » (G:107) add basic WebP support + * return RIFF.WAV.CART comments in merged comments section + * add support for QuickTime 'loci' chunk + * bugfix: (#2124) support for Quicktime/MP4 "chpl" (CHaPter List) atom + * bugfix: (G:128) undefinied bsmod in module.ac3 + * bugfix: (#2114) possible issue with UTF8 filenames and metaflac + * bugfix: (G:123) remove MySQL engine and collation from create table + * bugfix: (#2066) fix AAC MIME type, remove video key for audio-only files + * bugfix: (G:111) QuickTime stsd number_entries deadlock + * bugfix: (G:110) PHP memory limit with space + * bugfix: (G:109) improved animated GIF support + * bugfix: (#1966) GPS track in QuickTime + +1.9.14: [2017-03-27] James Heinrich + » Add experimental support for E-AC3 + * bugfix (G:105): RIFF.WAVE.iXML multiple TIMESTAMP_SAMPLE_RATE + * bugfix (G:95): improperly initialized error/warning keys + * bugfix (G:94): ID3v2 write support for TXXX + * bugfix (G:93): all errors or warnings should pass through class method + +1.9.13: [2016-12-14] James Heinrich + * bugfix (G:89): ID3v2.4 custom genres with slashes + * bugfix (G:88): large QuickTime files exceed PHP memory limit + * bugfix (G:87): ID3v2 write GRID data not working properly + * bugfix (G:86): Increase autoloading definitions + * bugfix (G:84): ID3v2 available writable frames list + * bugfix (G:82): ID3v2 datetime logic + * bugfix (G:80): attempt to autodetect ID3v1 encoding + * bugfix (G:77): add partial support of DSSv6 + * bugfix (G:76): add mysqli version of caching extension + * bugfix (G:75): mysql cache max key length + * bugfix (G:71): custom error handler to catch exif_read_data() errors + * bugfix (G:71): add support for mb_convert_encoding + * bugfix (G:70): ID3v2 POPM / UFID + * bugfix (G:68): workaround broken iTunes ID3v2 + * bugfix (G:48): Quicktime set MIME to video/mp4 where applicable + * bugfix (#1930) fread on pipes + * bugfix (#1926) relax ID3v2.IsValidURL check + +1.9.12: [2016-03-02] James Heinrich + » Add support for Direct Stream Digital (DSD) / + DSD Storage Facility (DSF) file format + » Add detection (not parsing) of WebP image format + * bugfix (#1910): Quicktime embedded images + +1.9.11: [2015-12-24] James Heinrich + * bugfix (G:64): update constructor syntax for PHP 7 + * bugfix (G:62): infinite loop in large PNG files + * bugfix (G:61): ID3v2 remove BOM from frame descriptions + * bugfix (G:60): missing "break" in module.audio-video.quicktime.php + * bugfix (G:59): .gitignore comments + * bugfix (G:58): inconsistency in relation to module.tag.id3v2.php + * bugfix (G:57): comparing instead of assign + * bugfix (G:56): unsupported MIME type "audio/x-wave" + * bugfix (G:55): readme.md variable reference + * bugfix (G:54): QuickTime false 1000fps + * bugfix (G:53): Quicktime / ID3v2 multiple genres + * bugfix (G:52): sys_get_temp_dir in GetDataImageSize + * bugfix (#1903): Quicktime meta atom not parsed + * demo.joinmp3.php enhancements + * m4b (audiobook) chapters not parsed correctly + * sqlite3 caching not working + +1.9.10: [2015-09-14] James Heinrich + * bugfix (G:49): Declaration of getID3_cached_sqlite3 + * bugfix (#1892): extension.cache.mysql + * bugfix (#1891): duplicate default clause [Quicktime] + * bugfix (G:41): incorrect MP3 playtime + * bugfix: iconv problems on musl with //TRANSLIT + * Add arguments to analyze() for original filesize (and filename) + * ID3v2 simplify handling of multiple genres + * Corrected merging of multiple genres for ID3v2 + * getid3_lib::GetDataImageSize return false on error + +1.9.9: [2014-12-18] James Heinrich + » Added basic support for OggOpus + » Add ID3v2 CHAP + CTOC support + * Add composer autoloader + * bugfix: removed non-printable ASCII in comment + * bugfix: possible memory leak in OggFLAC + * bugfix: sys_get_temp_dir undefined before PHP 5.2.1 + * bugfix: improved fix for XXE security issue (CVE-2014-2053) + (thanks nacinØwordpress*org) + * bugfix: G:25 ID3v2 LINK utf8_encode not defined + * bugfix: G:22 ID3v2 TXXX description encoding + * bugfix: #1855 - copy image height/width/etc to comments + * bugfix: #1855 - PHP errors in badly written APE/ID3v2 tags + * bugfix: #1845 - Quicktime parsing with no PHP memory_limit + * bugfix: #1828 - ID3v2 writing unknown frame names + +1.9.8: [2014-05-11] James Heinrich + » Add support for AMR (Adaptive Multi-Rate audio codec) + new file: module.audio.amr.php + » Added composer.json, registered on packagist.org + * Added workaround for PHP Bug #39923 (undefined constant IMG_JPG) + * Bugfix: (#1813) avoid running out of memory when parsing large + Quicktime files + * Bugfix: (#1812) potential unwanted high-ASCII characters in errors + * Bugfix: close potential XXE security issue (CVE-2014-2053) + * Bugfix: (G:10) Avoid warnings from realpath() if SAFE MODE is enabled + * Bugfix: (G:12) If [tags] data contains an array of strings then html + encoding did not take place. + * Bugfix: (G:12) IPTC character set not specified + * Bugfix: possible divide by zero error in FLV module + * Bugfix: possible undefined key in ID3v2 + * Bugfix: possible undefined key in MPEG video files + * Bugfix: demo.browse to use character set consistently + +1.9.7: [2013-07-05] James Heinrich + * Bugfix: [module.audio-video.quicktime.php] track languages set + with 15-bit-encoded ISO639-2 language codes not parsed correctly + * Bugfix: (#1717) QuickTime atom hierarchy broken + * Bugfix: (#1716) truncate MIDI file could cause infinite loop + * Bugfix: all source files converted to UTF-8 + +1.9.6: [2013-06-03] James Heinrich + » getID3() is now licensed under GPL / LGPL / MozillaPL / gCL + See license.txt for more details. + * Bugfix: (#1550) Quicktime video track sample description parsed + incorrectly + * Bugfix: (#1550) Quicktime matrix U/V/W values calculated incorrectly + * [demo.browse] disable edit-tag and delete-file links by default + * Bugfix: option_max_2gb_check should issue warning not error on >2GB + +1.9.5: [2013-02-20] James Heinrich, Dmitry Arkhipov + » DTS-in-WAV now properly supported + ¤ DSS files return additional data in new keys, and some existing + keys have been renamed + * Bugfix: open_basedir not parsed correctly under Windows + (thanks yannick*jamontØgmail*com) + * Bugfix: [demo/demo.browse] might not display file or directory name + on PHP >=5.4.0 if filename not UTF-8 friendly + * Bugfix: [demo/demo.zip] could read more uncompressed data than + required; fail to read file if local data descriptor not set; + some wrong include files were listed; improved error message display + * Bugfix: [module.audio-video.riff] INFO comment chunks with null name + chunk not parsed correctly + * Bugfix: [module.archive.gz] gzip files with filename stored may have + filename reduplicated in [gzip][files] output + * Bugfix: [module.archive.zip] data_descriptor not parsed correctly + * Bugfix: [module.archive.zip] some newer compression methods unknown + * Bugfix: [module.archive.zip] not all flags parsed + * Bugfix: [module.archive.zip] local file header not parsed correctly + if file has zero values for compressed_size in Local File Header + * Bugfix: (#1493) better support for >2GB filesize on 32-bit Linux + * Bugfix: (#1474) unneccesary call to GetDataImageSize in JPEG module + * Bugfix: (#1470) GIF files falsely detected as TS format + * Bugfix: (#1431) Matroska did not parse PixelCrop* / DisplayUnit + (thanks jgerberØwikimedia*org) + * Bugfix: (#1430) split ID3v2 text values on null separator + * Bugfix: (#1426) MS Office 2007 file format now recognized as zip.msoffice + * Bugfix: (#1423) optimized CreateDeepArray function + * Bugfix: (#1415) add support for DS2 variant of DSS + +1.9.4b1: [2012-10-05] James Heinrich, Dmitry Arkhipov, Karl G. Holz + » New module: extension.cache.sqlite3.php (by Karl G. Holz) + » New demo: demos/getid3.demo.dirscan.php (by Karl G. Holz) + » PHP5 standards improvements (thanks phansysØgmail*com) + » more reliable >4GB file size parsing using COM (if available) + Scripting.FileSystemObject rather than parsing `dir` output + * added support for FLAC inside Matroska (audio bitrate cannot + be determined in this case) + * XMP module now returns all tags, not just whitelisted ones + * (#1297) Added detection of MPEG Transport Stream files. + Stub module.audio-video.ts.php incomplete + * (#1383) removed unneeded ?> tags (thanks daveØholyfield*info) + * Bugfix: XMP returns attributes array not just value strings + * Bugfix: (#1369) ID3v2 IPLS contents not parsed + * Bugfix: (#1357) demo.mysql.php mysql_table_exists() failed + * Bugfix: (#1355) copy Foobar2000 QuickTime tags to [comments] + * Bugfix: (#1351) QuickTime files with zero-sized atom boxes + could cause infinite loop + * Bugfix: (#1343) FLAC attached pictures Ogg not handled + * Bugfix: (#1343) ID3v2 inside WAV "id3 " chunk not handled + * Bugfix: (#1315) BMP detection was broken + * Bugfix: (#1309) ID3v2.2 content_group_description (TT2) did + not copy to same place as ID3v2.3/ID3v2.4 (TIT2) + * Bugfix: (#1308) [playtime_string] could show hh:mm:60 + * Bugfix: (#1306) extension.cache.mysql.php keyword TYPE->ENGINE + * Bugfix: (#1295) missing video information if QuickTime file has + disabled tracks + * Bugfix: (#1275) MD5/SHA1 data hashes not working properly + under Windows + + +1.9.3: [2011-12-13] Dmitry Arkhipov, James Heinrich + * Matroska module improved: + 1. Added support for A_MS/ACM audio codec + 2. Fixed issues in tags, cues, chapters and clusters parsing + 3. Fixed almost all errors with track_data_offset, errors + still may occur with Xiph data lacing + 4. Optimized audio/video streams population with usage of the + official default values for missing elements + 5. Audio/video keys are now populated with data from the + default stream, not from the first one as before + 6. Full WebM support + * Bugfix: demo.browse would not pop up warnings when clicked + if warning contains apostrophe/single-quote character + * Bugfix: (#1269) ID3v1 genre typo "Trash"->"Thrash" Metal + + +1.9.2: [2011-12-08] James Heinrich, Dmitry Arkhipov + » significant rewrite to module.audio-video.matroska.php + ¤ (#1256) ID3 tags in AIFF 'ID3 ' chunks now parsed + ¤ (#1039) iXML data in WAV files now returned and parsed into + [riff][WAVE][iXML][0][data] and [riff][WAVE][iXML][0][parsed] + ¤ [playtime_string] now returns M:SS if less than 1 hour, and + H:MM:SS if 1 hour or longer + * Bugfix: (#1266) variable tablename: extension.cache.mysql.php + * Bugfix: (#1265) unescaped # in regex in write.id3v2.php + * Bugfix: (#1252) MediaMonkey writes blank ID3v2 RGAD frames + and puts replay-gain values in TXXX frames + * Bugfix: (#1251) FLV playtime could be inaccurate for longer + files where meta frame is present but meta-playtime is zero + * Bugfix: (#1216) show hex values of unknown atom names + * Bugfix: (#1215) undefined variable in PrintHexBytes() + * Bugfix: FLV audio bitrate was returning kbps not bps + * Bugfix: missing ) in write.real.php::RemoveReal() + * Bugfix: replace $this::VERSION with getID3::VERSION in + extension.cache.*.php + + +1.9.1: [2011-08-10] James Heinrich + ¤ ASF Extended Header Object data now (partially) parsed + * Default getID3 encoding now set to UTF-8 not ISO-8859-1 + * Bugfix: (#1212) truncated Matroska files may result in + infinite loop and memory exhaustion + * Bugfix: (#1203) parse RIFF JUNK chunks for version strings + * Bugfix: (#1201) multi-byte characters strings incorrectly + displayed by table_var_dump() in demo.browse.php + * Bugfix: (#1199) prevent PHP warning on malformed ID3v2 APIC + * Bugfix: (#1196) typo in module.audio-video.quicktime.php + * Bugfix: (#1195) QuicktimeStoreFrontCodeLookup() broken + * Bugfix: (#1194) mp4 embedded images not handled correctly + * Bugfix: (#1193) [image_mime] key not set fo WM/picture data + * Bugfix: (#1193) ASF Extended Header Object Metadata Library + now parsed for embedded images and handled per usual style + * Bugfix: (#1190) demo.mimeonly.php was broken since v1.9.0 + * Bugfix: ID3v2 comment is now called 'comment' not 'comments' + * Bugfix: AVI unknown codec fourcc would be reported as blank + * Bugfix: AVI zero-size JUNK chunk would give warning + + +1.9.0: [2011-06-20] James Heinrich + » changed all module classes to have proper constructors + with the actual analysis code moved to function Analyze() + * removed unnecessary ob_* calls, replaced with appropriate + checks and judicious use of @ error suppression + ¤ GETID3_VERSION constant replaced with $getID3->version() + ¤ picture data is now returned only in the original source + location and [comments][picture], it is no longer replicated + in [comments_html], [tags] or [tags_html] + ¤ Matroska tags are now returned in [comments] as per normal + ¤ Matroska tags are better supported, including pictures + ¤ GPS data in MP4 files (e.g. iPhone) is now parsed (#1157) + ¤ Matroska audio/video tracks with a default flag, the default + stream flag is now copied to [audio|video][streams] (#1147) + ¤ Nikon-specific data (NCDT atom) in Quicktime videos now parsed + ¤ QuickTime atoms 'meta' and 'data' now (mostly) parsed + * Bugfix: remove false warning of junk data on WAV+ID3v1 + * Bugfix: DolbyDigitalWAV files returned wrong audio bitrate + * Bugfix: large attachment data in Matroska tags were not + returned completely. + * Bugfix: wrong image_mime used for images in demo.browse.php + * Bugfix: broken preg_match in module.audio.dss.php + * Bugfix: Lyrics3 end offset was off by 1 + * Bugfix: audio channelmode could be wrong for 2 channels + (e.g. joint stereo reported as stereo) + * Bugfix: MultiByteCharString2HTML() would return empty string + if passed float or int value, now casts to string first + * Bugfix: FLAC.picture was not returning under [data] + + [image_mime] per standardized format + * Bugfix: BigEndian2Int() could incorrectly return negative + signed synchsafe integer instead of casting to float + * Bugfix: (#1177) ID3v2.4 extended headers were broken + * Bugfix: (#1173) some MIDI files not completely parsed + * Bugfix: (#1171) change helperapps error to nonblocking warning + * Bugfix: (#1170) possible infinite loop in FLV module + * Bugfix: (#1169) $this reference in static function (ID3v2) + * Bugfix: (#1156) demo.mysql.php not working + * Bugfix: (#1153) badly-tagged files could produce invalid + argument errors in module.tag.xmp.php + * Bugfix: (#1152) add error-suppression to iconv() calls + * Bugfix: (#1151) AAC-ADTS files could sometimes not find sync + * Bugfix: (#1136) last character of unicode tags (e.g. ASF) + was being truncated + * Bugfix: (#1133) write.id3v2.php IsValidURL() was broken + * Bugfix: (#1126) ID3v2.POPM field was being clobbered + * Bugfix: (#999, #1154) ID3v2 UFID data was missing + + +1.8.5: [2011-02-18] James Heinrich + » support >2GB files on 64-bit PHP + - note current unofficial 64-bit PHP builds for Windows + do not actually support 64-bit integers so are still + subject to normal 32-bit limits (2GB) for file functions + » PHP v5.0.5 now minimum required version. + Removed obsolte functions from getid3.lib.php: + md5_file, sha1_file, image_type_to_mime_type + » IDivX tags now parsed on AVI files + ¤ embedded image data is returned inside [comments][picture] + in a 2-element array (data, image_mime) for all formats + * $this->overwrite_tags=false is now known to be buggy and + has been disabled for this version until a full review + of tag writing can be completed. Certainly affects ID3v2, + the other writable tag formats may or may not be broken + * getID3 constructor no longer checks for (or sets) timezone + * demo.browse.php now shows cover art as inline images + rather than dumped to separate files + * [audio][streams][x][language] now set when known + * Bugfix: RIFF-AVI "JUNK" chunks are now parsed properly, + including zero-sized ones (no more false errors) + * Bugfix: msoffice documents now return correct error message + * Bugfix: demo.browse.php now encodes data according to + current page encoding (default=UTF-8) + * Bugfix: (#1120) sometimes incorrect ID3v2 genre parsing + * Bugfix: (#1116) possibly incorrect warnings (or lack of) + for RIFFs > 2GB. + * Bugfix: (#1115) wrong RIFFtype in RIFF files + * Bugfix: (#1114) wrong MIME type may be set for Matroska + * Bugfix: (#1113) support DSS v3 files + * Bugfix: (#1111) cover art in APE tags now supported + * Bugfix: (#1091) RemoveID3v1() unitialized variables + * Bugfix: (# 504) do not set Quicktime resolution if + 'tkhd' atom is disabled + * Bugfix: (# 95) return [quicktime][controller] if known + + +1.8.4: [2011-02-03] James Heinrich + * change default encoding in ID3v2 writing to UTF16-LE+BOM + (or ISO-8859-1 where possible) for better compatability + with broken versions of Windows Media Player and iTunes + * Bugfix: [FLV] incorrect overall bitrate in some files + * Bugfix: (#1102) missing parentheses in write[.id3v2].php + * Bugfix: (#510) undefined IsValidDottedIP() in write.id3v2.php + + +1.8.3: [2011-01-18] James Heinrich + » magic_quotes_gpc must now be disabled to use getID3 + » replace all error-suppressing @$variable calls with + isset() or empty() as appropriate for some configurations + where @ does not act to suppress warnings of undefined + variables (e.g. support forum thread #798) + * remove SafeStripSlashes() and FixTextFields functions + * [quicktime] use fourcc if codec name zero-length + * [quicktime] support "iods" atom + * Bugfix: (#1099) sometimes incorrect detection of safe_mode + * Bugfix: (#1095) more robust setting of temp dir + * Bugfix: (#1093) add support for ClusterSimpleBlock to + prevent "Undefined index: track_data_offsets" errors + in Matroska files + * Bugfix: [riff] prevent errors when RIFF.WAVE.BEXT chunk + contains null date/time (thanks moysevichØgmail*com) + * Bugfix: [quicktime] prevent divide-by-zero errors if + time_to_sample_table has zero-sample entry + (thanks moysevichØgmail*com) + + +1.8.2: [2010-12-06] James Heinrich + * include startup warning for PHP < v5 + * magic_quotes_runtime must now be disabled to use getID3 + ¤ MusicBrainz / AmpliFIND data more accessible in returned data + from Quicktime-style files (e.g. MP4/AAC) + * Bugfix: (#1079) wrong encoding might be used for ID3v2 + text data, and/or garbage data prepended before text + data; DataLengthIndicator value was being ignored + * Bugfix: (#1055) clearer warnings on non-EXIF contents in + JPEG [APP1] + * Bugfix: (#999) ID3v2 UFID data was missing + + +1.8.1: [2010-11-25] James Heinrich + * replaced calls to deprecated mysql_escape_string() with + mysql_real_escape_string() + * Bugfix: (#1072) memory limit not handled correctly if + in gigabytes in php.ini (e.g. "2G") + * Bugfix: (#1068) wrong encoding for Quicktime tags + * Bugfix: (#1040) possible infinite loop in genre parsing + * Bugfix: (#1036) helperapps directory not resolving 8.3 + path names correctly + * Bugfix: (#1023) dbm cache extension not correctly handling + types other than "db3" + * Bugfix: (#1023) mysql cache extension now base64_encodes + data to make binary-safe. Existing cached data must be + purged from your database cache + * Bugfix: (#1007) ClosestStandardMP3Bitrate() not selecting + most appropriate value + * Bugfix: (#996) inefficient and buggy ID3v1 and ID3v2 + genre parsing + * Bugfix: (#974) track number handled incorrectly in + demo.write.php + * Bugfix: (#969) tempnam() calls failing with open_basedir + * Bugfix: (#955) UTF-16LE text files could be falsely + identified as corrupt mp3 files + * Bugfix: (#877) detect if mbstring.func_overload is set in php.ini + * Bugfix: (#858) PHP safe_mode setting in php.ini incorrectly + handled if set to "Off" + * Bugfix: (#838) prevent warnings with assorted unhandled + Quicktime atoms + + +1.8.0: [2010-11-23] James Heinrich + » Changes required for PHP v5.3+ compatability, including: + - change ereg* functions to preg_* equivalents + - declare functions static as needed + note: users of PHP v4.x may need to stay with getID3 v1.7.x + » Added CUE (cuesheet) support + new file: module.misc.cue.php + (thanks Nigel Barnes ngbarnesØhotmail*com) + » Added XMP (Adobe Extensible Metadata Platform) support + currently used with module.graphic.jpg.php + new file: module.tag.xmp.php + (thanks Nigel Barnes ngbarnesØhotmail*com) + ¤ [jpg][exif][GPS][computed] now exists when possible with + calculated values (decimal latitude, longitude, altitude, time) + ¤ Prevent clobbering WMA artist with albumartist value; added WMA + partofset tag; added WMA tag picture data to WMA comments + (thanks ngbarnesØhotmail*com) + ¤ RIFF.WAVE.SNDM (SoundMiner) metadata now parsed + (thanks emerrittØwbgu*bgsu*edu) + ¤ FLAC embedded pictures now return [data_length] key + (thanks darrenburnhillØhotmail*com) + * added support for a number of new comment atom types added in + iTunes v4.0-v7.0 (thanks ngbarnesØhotmail*com) + * demo.browse.php now shows video resolution and framerate (if no + artist or title info present) + * additional FLV details parsed, may be faster as well + (thanks ngbarnesØhotmail*com) + * Bugfix: DSS files longer than 60 seconds had wrong playtime + * Bugfix: possible empty array encountered in APE tags + (thanks csnaitsirchØweb*de) + * Bugfix: prevent fatal error when calling BigEndian2Int() on + zero-length string (thanks taylor*fausakØgmail*com) + * Bugfix: prevent errors when parsing invalid Vorbis comments + (thanks dr*dieselØgmail*com) + * Bugfix: files could not be analyzed from Windows shares + (e.g. \\SERVER\Directory\Filename.mp3) + * Bugfix: RAR file opening should use 'filenamepath' + (thanks adrien*gibratØgmail*com) + * Bugfix: [asf][codec_list_object][codec_entries][x][description] + not containing expected comma-seperated values no longer aborts + (thanks larry_globusØyahoo*com) + * Bugfix: [id3v2] UFID was not returning data + (thanks joostØdecock*org) + +1.7.9: [2009-03-08] James Heinrich + » Added DSS (Digital Speech Standard) support + new file: module.audio.dss.php + (thanks luke*wilkinsØdtsam*com) + » Added MPC (Musepack) SV8 support + (thanks WaldoMonster) + ¤ some MPC [header] keys renamed to be the same between SV7/SV8 + ¤ start aligning demos CSS styling with v2.x styles + new file: demos/getid3.css + ¤ JPEG now returns parsed IPTC tags in [iptc] + ¤ getid3_lib::GetDataImageSize now requires $imageinfo parameter + ¤ better support for Matroska files with AC3/DTS/MP3/OGG audio + (support still lacking for AAC) + ¤ standardize ID3v2 TCMP key to 'part_of_a_set' between reading + and writing (thanks aaron_stormØyahoo*com) + ¤ added ID3v2 keys 'TCMP','TCP' to for writing iTunes-style tags + (thanks aaron_stormØyahoo*com) + ¤ back-ported PICTURE tag handling in FLAC tags + (thanks WaldoMonster) + ¤ added alternate method to get [video][frame_rate] from QuickTime + * added partial support for "TCMP"/"TCP" ID3v2 frames (iTunes + non-standard part-of-a-compilation tag) + (thanks aaron_stormØyahoo*com) + * slightly improved scanning through FLV files speed + (thanks franki) + * faster Matroska scanning by stopping at cluster chunks once + needed header chunks are found (much faster for large files) + * added workaround for broken tagging programs that miss terminating + null byte for numeric ID3v2.4 genres + (thanks yam655Øgmail*com) + * Bugfix: MultiByteCharString2HTML() did not escape common HTML + special characters like & and ? + * Bugfix: cleaned up some malformed HTML errors in demo.browse.php + * Bugfix: under Windows files >2GB might not be processed due to + "dir" command not finding file with double directory slashes + * Bugfix: "MODule (assorted sub-formats)" was falsely matching + some random files (e.g. JPEGs) (thanks qwertywin) + * Bugfix: suppress PHP_notice on failed SWF-compressed + decompression failure (thanks mkron) + + +1.7.8b3: [2008-07-13] James Heinrich + » Experimental partial support for files > 2GB (gets filesize + from shell call to "dir" or "ls", parse files with PHP only + up to 2GB limit). See readme.txt for details on what formats + work properly and other limitations + » Initial support for Matroska. Has only been tested with a + limited number of sample files, please report any bugs + » Experimental support for PHP-RAR reading. Known buggy, disabled + by default, enable with care + ¤ getid3_lib::CastAsInt() now returns ints up to 2^31 (not 2^30) + ¤ Quicktime: [video] now returns [frame_rate] and [fourcc] for MP4 + video files + * MP3: headerless VBR files now only have up to 10 blocks of 5000 + frames each scanned by default and bitrate extrapolated from that + distribution for speed (thanks glau*stuffØridiculousprods*com) + * Quicktime: support "co64" atom + * SWF: lower memory use when compressed SWF files processed + (thanks doughammondØblueyonder*co*uk) + * Bugfix: FLV height and width was calculated incorrectly + (thanks moysevichØgmail*com) + * Bugfix: FLV GETID3_FLV_TAG_META parsed incorrectly + (thanks moysevichØgmail*com) + * Bugfix: Quicktime: 'tkhd' matrix_v and matrix_d were switched + (thanks rjjmoroØhotmail*com) + * Bugfix: Quicktime: frame_rate was often incorrect for MP4 video + * Bugfix: getid3_lib::CastAsInt returned -2147483648 when passed + 2147483648 (0x80000000) + + +1.7.8b2: [2007-10-15] James Heinrich, Allan Hansen + * Video bitrate now calculated even if not explicitly stated in + file metadata, but if overall and audio bitrates are known + * Bugfix: 'comments_html' missing last letter in id3v2 tags. + * Bugfix: module objects (e.g. getid3_riff) that are instantiated + in other modules are explicitly disposed once no longer needed. + * Bugfix: some AVI files were not returning audio information + because "strh" chunk was not being read in + * Bugfix: asf [audio][][dataformat] should be set + to "wma" but wasn't + * Bugfix: [mpeg][audio][bitrate_mode] should always be one of + ("cbr", "vbr", "abr") but wasn't for some values in + LAMEvbrMethodLookup() + * Bugfix: MP3 audio in AVI files could show "cbr" instead of + correct audio bitrate_mode, and audio bitrate could be slightly + incorrect if multiple files were scanned in a loop (scanning + single files produced correct values). + * Bugfix: remove [audio/video][bitrate] key if falsely set to zero + * Bugfix: PlaytimeString returned non-matching value for negative + playtimes (which shouldn't happen either, but now they're at + least shown correctly, if they happen due to other bugs) + * Bugfix: Several ASF header values are invalid if the broadcast + flag is set, getID3() now calculates these values in other + ways if the broadcast flag is set (thanks fletchØpobox*com) + * Bugfix: lyrics3-flags-lyrics field was always false, and there + never was a lyrics3-flags-timestamp field present even though + the lyrics3-raw-IND field consisted of "10" (lyrics present, + timestamp not present). (thanks i*f*schulzØweb*de) + * Bugfix: TAR.GZ files produce PHP errors when + option_gzip_parse_contents == true in module.archive.gzip.php + (thanks alan*harderØsun*com) + + +1.7.8b1: [2007-01-08] Allan Hansen + » Major update to readme.txt + » PHP 4.2.0 required + » Tagwriter requires metaflac 1.1.1+ in order to write FLAC tags. + » Removed broken and non-fixable tagwriting module for real format. + ! Developers please help fix the above module: + https://www.getid3.org/phpBB3/viewtopic.php?t=677 + » Avoided security issues with demo.browse.php, demo.write.php and + demo.mysql.php. These demos are now disabled by default and has + to be enabled in the source. + * Bugfix: id3v2 genre broken since 1.7.7. + » Added DTS module (module.audio.dts.php) + ¤ ASF/WMV files now return largest video stream dimensions in + [video][resolution_x] and [video][resolution_y] + * Bugfix: Minor issues with midi module (avoid PHP_NOTICE). + * Bugfix: Minor issues with lyrics3 (avoid PHP_NOTICE). + * Bugfix: PHP_NOTICE issues in MultiByteCharString2HTML() + * Bugfix: PHP_NOTICE issue in BigEndian2Float() + * Bugfix: fread() zero bytes issue in real module. + * Bugfix: ASF module returned mime type video/x-ms-wma instead of + video/x-ms-wmv for certain FourCCs. + * Bugfix: PHP_NOTICE issues with broken ID3v2 tag/garbage. + * Bugfix: PNG module broken in regards to gIFg and gIFx chunks. + » Removed detection of short filenames 8dot3 under windows, as + it only worked for English versions of windows and has other + problems. + * Bugfix: Some CBR MP3 files detected as VBR with plenty of warnings. + * Bugfix: PHP_NOTICE issues in MP3 module. + * Bugfix: Quicktime returned incorrect frame rate. + * Bugfix: DivByZero on zero length FLV files. + * Bugfix: PHP_NOTICE one some FLV files. + * Bugfix: ID3v2 UTF-8/16 encoded frames terminated by \x00 + * Bugfix: ID3v2 LINK frames iconv error. + * Bugfix: ID3v2 padding length calculated incorrectly. + * Bugfix: ID3v2.3 extended headers non-conformance + » SVG file detection. + » Added SVG user module (user_modules/module.graphic.svg.php). + Thanks to Roan Horning. + » PAR2 file detection (no parsing) + * Bugfix: Wave files being detected as MP3. + * Bugfix: ASF padding offset bug. + * Bugfix: Shorten module not working for wav files with fmt + chunks <> 16 bytes. + ¤ RIFF: Zero sized chunk invokes warning instead of error. + ¤ FLAC: Removed some ['raw'] keys. + ¤ MPC: Mime type returned: audio/x-musepack + +1.7.7: [2006-06-25] Allan Hansen + * Bugfix: AAC static bitrate cache wrong result when parsing + several files. + * Bugfix: Do not return NULL video bitrate for ASF v3. + * Bugfix: getid3_lib::GetImageSize() broken => JPG module broken. + * Bugfix: Encoder options should now be returned with correct + "--alt-preset n" / "--alt-preset cbr n" when scanning more files. + * Bugfix: Shorten module not escapeshellarg() filenames (UNIX only). + * Bugfix: Filenames not escapeshellarg() for md5_data and + sha1_data (UNIX only). + * Bugfix: UNIX: head and tail called with -cNNN instead of "-c NNN". + » Added detection support for PDF and MS Office documents + (*.doc, *.xls, *.pps, etc) (thanks zeromassmediaØgmail*com) + ¤ Bugfix: ID3v2 "TDRC" frame now used as "year" in comments if TYER + unavailable (TYER is deprecated in ID3v2.4) + (thanks matthiasØpanczyk*org) + ¤ Removed GETID3_OS_DIRSLASH, replaced with DIRECTORY_SEPARATOR + * Bugfix: added LAME preset guessing for presets 410,420,440,490 + (thanks adminØlogbud*com) + * Bugfix: Added escapeshellarg() call in getid3_lib::hash_data + (thanks towbØgmx*net) + » TAR module no longer reads entire file into memory + » FLV module no longer reads entire file into memory + * Bugfix: added LAME preset guessing for presets 410,420,440,490 + (thanks adminØlogbud*com) + * Bugfix: Added escapeshellarg() call in getid3_lib::hash_data + (thanks towbØgmx*net) + * Bugfix: Error message when padding in FLAC files were used up. + * Bugfix: Shorten module not working under windows. + ¤ Bugfix: gmmktime() instead of mktime(). + ¤ Using gmmktime() instead of mktime() in ISO, ZIP, PNG and RIFF + modules to avoid E_STRICT notices with PHP5.1+. + * Bugfix: ['comments_html'] and ['comments'] contains different + value when having multiple tags (one of them ID3v1) and the + long field names. + +1.7.6: [2006-03-12] James Heinrich + * Rewrote getid3_lib::GetDataImageSize() to use GetImageSize() + instead of using code by filØrezox*com + * Bugfix: incorrect dimensions from disabled Quicktime tracks + (thanks m-1Øgmx*net) + * Bugfix: ['codec'] key warning in module.audio-video.asf.php + (thanks niel*archerØblueyonder*co*uk) + * Bugfix: undefined array in write.php + (thanks drewishØkatherinehouse*com) + * Bugfix: DeleteAPEtag() incorrectly failing when no tag present + (thanks drewishØkatherinehouse*com) + * Bugfix: ID3v2 writing frames with URL fields failing when URL + is not in ISO-8859-1 (thanks drewishØkatherinehouse*com) + * Bugfix: PHP notices on bad ID3v2 frames + (thanks cw264701Øohiou*edu) + * Bugfix: audio & video bitrates sometimes wrong in ASF files + (thanks kris_kauperØexcite*com) + +1.7.5: [2005-12-29] James Heinrich + » Added FLV (FLash Video) support -- new file: + module.audio-video.flv.php + (thanks Seth Kaufman for code) + » Real tags can now be written (previous Real tag writing + code was not supposed to be in public releases, as it + was not complete) + » GETID3_HELPERAPPSDIR now autodetected under Windows + ¤ ASF lyrics now returned under [comments][lyrics] + * Bugfix: removed "--lowpass xxxxx" info from guessed + LAME presets when source frequency <= 32kHz + * Bugfix: ID3v2 extended header errors + * Bugfix: missing ob_end_clean() in write.id3v2.php + (thanks rasherØgmail*com) + +1.7.4: [2005-05-04] James Heinrich + ¤ Added ['quicktime']['hinting'] key (boolean) + (thanks jonØwebignition*net) + * Bugfix: major UTF-8 to UTF-16/ISO-8859-1 conversion + bug (empty string returned) when using iconv_fallback + (thanks chrisØfmgp*com) + * Bugfix: Missing 'lossless' key in RIFF-WAV + (thanks bobbfwedØcomcast*net) + +1.7.3: [2005-04-22] James Heinrich + » Added TAR support -- new file: module.archive.tar.php + (thanks Mike Mozolin for code!) + » Added GZIP support -- new file: module.archive.gzip.php + (thanks Mike Mozolin for code!) + * Bugfix: demo.browse.php now displays embedded images + internally instead of passing local filename as IMG + SRC (should allow demo.browse.php to correctly show + embedded images over a network) + (thanks patpowermanØhotmail*com) + * Bugfix: minor UTF-8 display issues in demo.browse.php + * Bugfix: demo.browse.php now works even if the evil + setting magic_quotes_gpc is turned on + (thanks patpowermanØhotmail*com) + * Bugfix: incorrect MIDI playtime for some files + (thanks joelØoneporpoise*com) + * Bugfix: 'url_source' typo in module.tag.id3v2.php + (thanks richardlynchØusers*sourceforge*net) + * Bugfix: Quicktime 'mvhd' matrix values were wrong + (thanks webØbobbymac*net) + ¤ ID3v2 now returns xx/yy for ['track'] (if + available), with xx in ['tracknum'] and yy in + ['totaltracks']. Previously ['tracknum'] was not + available and ['track'] had only xx. + Bugfixes and improvements to /demo/demo.mysql.php: + - remix/version parsed from tags and stored in + database, can be used when renaming files + - track number can be used for renaming files + + +1.7.2: [2004-10-18] Allan Hansen + » Added support for WavPack v4.0+ + (thanks ahØartemis*dk) + » Removed code for parsing EXE files + (thanks ahØartemis*dk) + Removed file: module.misc.exe.php + * Bugfix: Large ID3v2 tags inside ASF not parsed + properly under PHP5. + * Bugfix: Certain Wavpack3 files failed under PHP5 due + to new undocumented tmpfile() limit (same problem as + above). + * Bugfix: New iTunes crashes PHP - temp fix - no tags + on those files. + * Bugfix: ['nsv']['NSVs']['framerate_index'] might be + wrong (thanks ahØartemis*dk) + * Bugfix: transparent color was wrong from truecolor + PNG (thanks ahØartemis*dk) + * Bugfix: Changed MPC SV7 header size from 30 to 28, + this will change hash values for MPC files + (thanks ahØartemis*dk) + * Bugfix: Changed MPC SV4-6 header size from 28 to 8, + this will change hash values for MPC files + (thanks ahØartemis*dk) + ¤ Trim/unset wavpack encoder_options to match 2.0.0b2 + output. + ¤ Commented-out unknown/unused values in NSV and ISO + modules (thanks ahØartemis*dk) + + +1.7.1b1: [July-26-2004] James Heinrich + » Added support for Apple Lossless Audio Codec + » Added support for RealAudio Lossless + » Added support for TTA v3 + » Added support for TIFF + New file: /getid3/module.graphic.tiff.php + » Modified iconv_fallback to work with UTF-8, UTF-16, UTF-16LE, + UTF-16BE and ISO-8859-1 even if iconv() and/or XML support is + not available. This means that iconv() is no longer required + for most users of getID3() + (thanks Jeremia, khleeØbitpass*com) + » Added support for Monkey's Audio v3.98+ (thanks ahØartemis*dk) + » Included new demo showing most-basic getID3() usage + New file: /demos/demo.basic.php + * Bugfix: LAME3.94+ presets cached incorrectly if multiple files + are scanned in one batch and first file is LAME3.93 or earlier + (thanks enoyandØyahoo*com) + * Bugfix: Added warning if compressed ID3v2 frame decompression + fails. (thanks Mike Billings) + * Bugfix: Assorted small fixes to ensure compatability with PHP5 + * Bugfix: ID3v1 genre "Blues" could not be written + (thanks Jeremia) + * Bugfix: ['bitrate_mode'] typo in module.audio-video.real.php + (thanks asukakenjiØusers*sourceforge*net) + * Bugfix: ['zip']['files'] is now populated with filenames even + if End Of Central Directory couldn't be parsed + * Bugfix: ['audio']['lossless'] was incorrect for FLAC + (thanks WaldoMonster) + * Bugfix: MD5 File was incorrect in directory browse mode for + /demo/getid3.browse.php + * Bugfix: PHP v5 compatability changes (float array keys, fread() + calls with zero data length) + (thanks getid3Øjsc*pp*ru) + * Bugfix: was dying if on compressed ID3v2 frames if + gzuncompress() function was unavailable + * Bugfix: ['vqf']['COMM'] was always empty + * Bugfix: MIDI playtime was missing for single-track MIDI files + * Bugfix: removed � characters from ['comments_html'] + (thanks p*quaedackersØplanet*nl) + * Bugfix: improved MIDI playtime accuracy + (thanks joelØoneporpoise*com) + * Bugfix: BMP subtypes 4 and 5 were not being identified + * Bugfix: frame_rate in AVI was incorrectly truncated to integer + * Bugfix: FLAC cuesheet track index was incorrect + (thanks tetsuo*yokozukaØoperamail*com) + ¤ ['quicktime']['display_scale'] now contains the playback scale + multiplier for QuickTime movies - a movie set to playback at + double-size will have "2" here. Other values are "1" and "0.5" + ¤ Added LAME preset guessing for --preset medium with v3.90.3 + (thanks phwipØfish*co*uk) + ¤ Added $encoding_id3v1 to allow for ID3v1 encodings other than + the standard ISO-8859-1 + ¤ Default AVI video bitrate_mode is now 'vbr' + (thanks eltoderØpisem*net) + Force getID3() to abort if Shorten files have ID3 or APE tags + (thanks ahØartemis*dk) + Editable textbox for parent directory in demo.browse.php + (thanks eltoderØpisem*net) + + +1.7.0-hotfix [2004-03-17] Allan Hansen + (hotfix version released by Allan Hansen) + * Bugfix: PHP 4.1.x compatiblity - fgets($fp) => fgets($fp, 1024) + * Bugfix: Added default charset to TextEncodingNameLookup() in + module.tag.id3v2.php + Ø Removed option_no_iconv + iconv() support is only a requirement for WMA/WMW/ASF, and for + destination encodings other than ISO-8859-1 and UTF-8, iconv is + not needed otherwise. New 'iconv_req' in GetFileFormatArray() + only set for WMA/WMV/ASF. analyze() now refuses to analyse + WMA/ASF file if iconv is not present. + iconv_fallback() only dies on internal errors not missing iconv() + + +1.7.0: [January-19-2004] James Heinrich + » Added support for RIFF/CDXA files (MPEG video in RIFF container + format (thanks chrisØdigitekdesign*com) + » Added support for TTA v2 (thanks ahØartemis*dk) + ¤ ID3v2 unsynchronisation scheme disabled by default because most + tag-reading programs cannot read unsynchronised tags. Can be + overridden by setting id3v2_use_unsynchronisation to true. + (thanks mikeØdelusion*org) + ¤ extention.*.php renamed to extension.*.php + (thanks tp62Øcornell*edu) + ¤ /demo/demo.check.php renamed to /demo/demo.browse.php + ¤ Added id3v2_paddedlength configuration parameter to WriteTags() + and renamed tag_language to id3v2_tag_language + ¤ MPEG audio layers are now represented as 1, 2 or 3 instead of + 'I', 'II', or 'III' + ¤ Added [audio][wformattag] and [video][fourcc] for WAV and AVI + ¤ Added [audio][streams] which contains one entry for each audio + stream present in the file (usually only one). The data is a + copy of what is usually found in [audio]. If there are multiple + audio streams then [audio] will contain a sum of the bitrates + of all audio streams, and the data format of the first stream + (if streams are of different data types) + ¤ Added BruteForce mode to mp3 scanning. Disabled by default as + it is extremely slow and only files that are broken enough to + not really play will gain any benefit from this. + ¤ Suppress '--resample xxxxx' appended to encoder options for mp3 + with low-quality presets for default sampling frequencies + ¤ Enhanced LAME preset guessing for pre-3.93 with a better lookup + table, --resample/--lowpass guessing (thanks phwipØfish*co*uk) + ¤ RIFF files with non-MP3 contents no longer have + [audio][encoder_options] set + ¤ Added [audio][encoder_options] to audio formats where possible + (including LiteWave, LPAC, OptimFROG, TTA) + ¤ Moved [quantization] and [max_prediction_order] from + [lpac][flags] to just [lpac] + ¤ WavPack flags are now parsed into [wavpack][flags] + * Bugfix: APEtags with ReplayGain information stored with comma- + seperated decimal values (ie "0,95" instead of "0.95") were + giving wrong peak and gain values + * Bugfix: Filesize > 2GB not always detected correctly + * Bugfix: Some ID3v2 frames had data key unset incorrectly + (thanks chrisØdigitekdesign*com) + * Bugfix: Warnings on empty-strings-only comments + * Bugfix: ID3v2 tag writing may have had incorrect padding length + if padded length less than current ID3v2 tag length and + merge_existing_data is false (thanks mikeØdelusion*org) + * Bugfix: hash_data() for SHA1 was broken under Windows + * Bugfix: BigEndian2Float()/LittleEndian2Float() were broken + * Bugfix: LAME header calculated track peaks were incorrect for + LAME3.94a15 and earlier + * Bugfix: AVIs with VBR MP3 audio data reported incorrect bitrate + and bitrate_mode + * Bugfix: AVIs sometimes had incorrect or missing video and total + bitrates + * Bugifx: AVIs sometimes had incorrect ['avdataend'] and + therefore also incorrect data hashes (md5_data, sha1_data) + * Bugfix: ID3v1 genreid no longer returned for Unknown genre + * Bugfix: ID3v1 SCMPX genres were broken + Modified LAME header parsing to correctly process peak track + value for LAME3.94a16+ (thanks Gabriel) + md5_file() and sha1_file() now work under Windows in PHP < 4.2.0 + and 4.3.0 respectively with helper apps + Default md5_data() tempfile location is now system temp directory + instead of same directory as file (thanks towbØtiscali*de) + Improved list of RIFF ['INFO'] comment key translations + More helpful error message when GETID3_HELPERAPPSDIR has spaces + /demo/demo.browse.php now autogets both MD5 and SHA1 hashes for + files < 50MB + Replaced PHP_OS comparisons with GETID3_OS_ISWINDOWS define + (thanks necroticØusers*sourceforge*net) + + +1.7.0b5: [December-29-2003] James Heinrich + » Windows only: Various binary files are now required for some + file formats, especially for tag writing, as well as md5sum + (and other) calculations. These binaries are now stored in the + directory defined as GETID3_HELPERAPPSDIR in getid3.php + (default is /helperapps/ parallel to /getid3/). + Note: This directory must not have any spaces in the pathname. + All neccesary files are available as a seperate download. + See /helperapps/readme.txt for more information + New file: /helperapps/readme.txt + » Unified tag-writing interface for all tag formats + New file: /getid3/write.php + /getid3/write.apetag.php + /getid3/write.id3v1.php + /getid3/write.id3v2.php + /getid3/write.lyrics3.php + /getid3/write.metaflac.php + /getid3/write.vorbiscomment.php + » Added support for Shorten - requires shorten binary (head.exe + is also required under Windows). + New file: /getid3/module.audio.shorten.php + » Added support for RKAU + New file: /getid3/module.audio.rkau.php + » Added (minimal) support for SZIP + New file: /getid3/module.archive.szip.php + » Added MySQL caching extention (thanks ahØartemis*dk) + New file: /getid3/extention.cache.mysql.php + » Added DBM caching extention (thanks ahØartemis*dk) + New file: /getid3/extention.cache.dbm.php + » Added sha1_data hash option (thanks ahØartemis*dk) + » Added option to allow getID3() to skip ID3v2 without parsing it + for faster scanning when ID3v2 data is not required. If you + want to enable this feature delete /getid3/module.tag.id3v2.php + (thanks ahØartemis*dk) + ¤ 8-bit WAV data now calculates MD5 checksums as normal, not + converting to signed data as before, so stored md5_data_source + in FLAC files will no longer match md5_data for the equivalent + decoded 8-bit WAV. A warning will be generated for 8-bit FLAC + files + ¤ Added option_no_iconv option to allow getID3() to work + partially without iconv() support enabled in PHP + (thanks ahØartemis*dk) + ¤ All '*_ascii' keys removed for ASF/WMA/WMV files + ¤ All 'ascii*' keys removed for ID3v2 tags + ¤ Ogg filetypes now return MIME of "application/ogg" instead of + the previous "application/x-ogg" + (thanks blakewattersØusers*sourceforge*net) + ¤ Force contents of ['id3v2']['comments'] to UTF-8 format from + whatever encoding each frame may have (text encoding can vary + from frame to frame in ID3v2) + ¤ MP3Gain information from APE tags suppressed from ['tags'] and + parsed into ['replay_gain'] + ¤ ReplayGain information (all formats) changed from "Radio" and + "Audiophile" to "Track" and "Album" respectively + ¤ ['volume'] and ['max_noclip_gain'] are now available in both + ['replay_gain']['track'] and ['replay_gain']['album'] for all + formats that calculate ReplayGain. + ¤ ['video']['total_frames'] is available for AVIs + ¤ All parsed ID3v2 frame data is now in ['id3v2'][XXXX][#] + (previously some frame types would have numeric array keys if + multiple instances of that frame type were allowed and other + frame types would not) + ¤ ASF/WMA "WM/Picture" images are now parsed in the same manner + as ID3v2 with the image (ex JPEG) data returned in [data] + rather than [value] + * Bugfix: Optional tag processing options were being ignored (ie + ID3v1 still processed even if option_tag_id3v1 == false) + (thanks ahØartemis*dk) + * Bugfix: fixed MultiByteCharString2HTML() for UTF-8 + * Bugfix: Quicktime files not always reporting video frame_rate + * Bugfix: False ID3v1 synch patterns in APE or Lyrics3 tags are + now detected and incorrect ID3v1 data not returned + (thanks sebastian_maresØusers*sourceforge*net for the idea) + * Bugfix: WMA9 Lossless now reported as lossless + * Bugfix: two typos in ID3v1 genre list + * Bugfix: MPEG-2/2.5 ABR/VBR MP3 files had doubled playtime + * Bugfix: MPEG-2/2.5 LayerII (ie MP2: 24/22.05/16kHz) files were + not detected due to incorrect frame length calculation + * Bugfix: MPEG LayerI files were not detected due to incorrect + frame length calculation (must be multiple of slot length) + Added alternative md5_data via system call - twice as fast. Needs + "getID3()-WindowsSupport" to work under Windows. + (thanks ahØartemis*dk) + ID3v2.4 compressed frames are now supported + php_uname() calls changed to use PHP_OS constant + Added SCMPX extensions to ID3v1 genres (0xF0-0xFE) + Obfuscated contributor email address in changelog and sourcecode + Added memory-saving EmbeddedLookup() function for lookup tables + in RIFF and ID3v2 modules (thanks ahØartemis*dk) + Major memory patches to many modules by using + $var = &$INFO_ARRAY_AT_SOME_INDEX + in place of large multi-dimensional array declarations. + Memory saved: RIFF: ~200kB; ID3v2: ~475kB; ASF: ~50kB etc. + (thanks ahØartemis*dk) + + +1.7.0b4: [November-19-2003] James Heinrich + » Support added for MPC files with old SV4-SV6 structure + » RealVideo now properly supported with resolution, framerate, etc + (thanks jcsston) + » RealAudio files with old-style file format (v2-v4) are now + fully supported + » Support added for DolbyDigital WAV files (thanks ahØartemis*dk) + ¤ ['RIFF'] is now ['riff'] to conform to make all root key names + lowercase + ¤ ['OFR'] is now ['ofr'] to conform to make all root key names + lowercase + ¤ ['tags_html'] is now available as a copy of ['tags'] but + with all text replaced with an HTML version of all characters + above chr(127), translated according to whatever the encoding + of the source tag is, in the HTML form Ӓ + ¤ CopyTagsToComments() is now available in getid3_lib + ¤ QuicktimeVR files now return a ['video']['dataformat'] of + 'quicktimevr' instead of 'quicktime' (thanks gtsØtsu*biz) + ¤ Quicktime video files with DivX, Xvid, 3ivx or MPEG4 video + streams now return those names as ['video']['dataformat'] + ¤ MPEG video files are now identified with ['video']['codec'] set + to either 'MPEG-1' or 'MPEG-2' (rather than just 'MPEG'). If you + see a file wrongly identified, please report it! + (thanks fccHandler) + ¤ All bitrate values in ['mpeg']['audio'] is now reported in bps + rather than kbps (ie 128000 instead of 128) for consistancy + ¤ AVIs with MP2 audio now report ['audio']['dataformat'] as 'mp2' + rather than 'wav' (thanks metalbrainØnetian*com) + ¤ Added ['md5_data_source'] for OptimFROG + ¤ AC3 in RIFF-WAV now identified with ['audio']['dataformat'] + returning 'ac3' + ¤ WavPack ['extra_bc'] now returned as integer + ¤ WavPack ['extras'] now returned as 3-element array of integers + ¤ MP3 ['audio']['encoder options'] now returns 'VBR' or 'CBR' only + (no bitrate) if no LAME preset is used, or 'VBR q??' where ?? is + a number 0-100 for Fraunhofer-encoded VBR MP3s + * Bugfix: VBR MP3s could have incorrect bitrate reported + * Bugfix: Quicktime files with MP4 audio were not returning + ['video']['dataformat'] (thanks robØmassive-interactive*nl) + * Bugfix: strpad vs str_pad typo in module.riff.php + (thanks nicojunØusers*sourceforge*net) + * Bugfix: ReplayGain information was often wrong for MPC files + * Bugfix: MD5 and other post-TAIL chunks were not being processed + in module.audio.optimfrog.php + * Bugfix: Undefined variable in table_var_dump() in demo/check.php + * Bugfix: QuickTime files now only return information in [audio] + or [video] if those exist in the file + * Bugfix: WavPack no longer tries to read entire compressed data + chunk + * Bugfix: Properly handle VBR MP3s with "Info" (rather than + "Xing") header frame. foobar2000 adds this to MP3 files when + "Fix MP3 Header" function is used (thanks ahØartemis*dk) + * Bugfix: Fraunhofer VBRI headers for MP3s were assuming 2-byte + entries for TOC rather than using stride, and were ignoring the + scaling value. (thanks sebastianØmaresweb*net) + Several QuickTime atoms have been added to an exclusion list + because they have been observed, but I have no idea what they + are supposed to do so I can't add real support for them, but + they should not generate warnings (robØmassive-interactive*nl) + Old MPC encoder (before v1.06) was return as v0.00, now returned + as 'Buschmann v1.7.0-v1.7.9 or Klemm v0.90-v1.05' + (thanks ahØartemis*dk) + Added check for magic_quotes_runtime and code to disable it if + neccesary (thanks stefan*kischkelØt-online*de) + Added 3ivx fourCCs to module.audio-video.quicktime.php + MP3 and AC3 streams are now parsed when contained inside RIFF-WAV + or RIFF-AVI container formats + Better detection of named presets in LAME 3.93/3.94 + + +1.7.0b3: [October-17-2003] James Heinrich + » AC-3 (aka Dolby Digital) is now supported. + New file: /getid3/module.audio.ac3.php + * Bugfix: ID3v2-writing function Unsynchronise() was broken, which + made ID3v2 tag containing binary data (typically pictures) get + corrupted. (thanks t*coombesØbendigo*vic*gov*au, + i*kuehlbornØndh*net, mikeØdelusion*org, mikeØftl*com) + * Bugfix: Zip comments now returned as array instead of string, + as they're supposed to be. + * Bugfix: Quicktime/MP4 files may have reported extremely low + bitrates (thanks spunkØdasspunk*com) + Improved double-ID3v1 check to prevent false detection when string + "TAG" is present in APE or Lyrics3 + Fixed /demo/simple.php + Fixed /demo/joinmp3.php + Fixed /demo/mimeonly.php + Fixed /demo/write.php + + +1.7.0b2: [October-15-2003] James Heinrich + » TTA Lossless Audio Compressor format now supported. + (http://tta.iszf.irk.ru) + New file: /getid3/module.graphic.tta.php + » PhotoCD (PCD) format now supported. Image data for the three + lowest resolutions (192x128, 384x256, 768x512) can be optionally + extracted. + New file: /getid3/module.graphic.pcd.php + ¤ RIFF-MP3 files now should return the same ['md5_data'] as the + identical MP3 file outside the RIFF container + ¤ Name of LAME preset used (if available, needs LAME v3.90+) + returned in ['mpeg']['audio']['LAME']['preset_used'] and also as + part of ['audio']['encoder_options'] + ¤ VQF module now sets ['audio']['encoder_options'] to i.e. CBR96 + ¤ MP3 module now sets ['audio']['encoder_options'] on CBR files + and all LAME-encoded files + ¤ MPC module now sets ['audio']['encoder_options'] + ¤ Monkey module now sets ['audio']['encoder_options'] + ¤ AAC module now sets ['audio']['encoder_options'] to profile name + ¤ ASF module now sets ['audio']['encoder_options'] + ¤ Ogg module adds ['audio']['encoder_options'] -b 128 on + Ogg Vorbis 1.0+ ABR files + ¤ Ogg module adds ['audio']['encoder_options'] -q N on + Ogg Vorbis 1.0+ VBR files 44k/48k sample rate/stereo files only. + ¤ Ogg module ['audio']['encoder_options'] "Nominal birate: 80k" to + other Ogg Vorbis files. + ¤ ID3v2 track number now returned as string (with leading zeros, + if present in data) rather than integer (thanks Plamen) + ¤ ASF module returns ['asf']['comments']['encoding_time_unix'] if + available (from WM/EncodingTime) + ¤ Fixed /demo/mysql.php and added some new features: + - encoder options + - ID3v2 "Encoded By" + - non-empty comments + - total entries in database summary (totals & averages) + - database version update + * Bugfix: 'UNICODE' iconv() charset changed to 'UTF-16LE' or + 'UTF-16BE' as appropriate + * Bugfix: iconv_fallback() function created in case iconv() fails + * Bugfix: fixed MD5 calls in demo/check.php + * Bugfix: reenabled detection of APE + Lyrics3 tags in same file + * Bugfix: ASF module now returns ID3v1 genre as string instead of + number - patch from Eugene Toder. + * Bugfix: ASF module now reads non-standard field names, + i.e. "date" as well as WM/Year - patch from Eugene Toder. + * Bugfix: ASF module now returns genre as-is if it is not a + standard ID3v1 genre (thanks wonderboy) + * Bugfix: Eliminated false-synch problem in MP3 module + * Bugfix: Fixed missing root ['bitrate'] for most formats + * Bugfix: ['audio']['compression_ration'] missing for MPC + (thanks WaldoMonster) + * Bugfix: NSV module died in 1.7.0b1 + * Bugfix: ASF module died in 1.7.0b1 when WM/Picture preset + * Bugfix: ASF tracknumber incorrect when specified by WM/Track + rather than WM/TrackNumber (thanks jgriffiniiiØhotmail*com) + * Bugfix: MPEG audio+video playtime should now be pretty accurate + (ie within 0.1% variation at most) + (thanks mgrimmØhealthtvchannel*org) + * Bugfix: ID3v2 not being copied to ['tags'] in some cases + * Bugfix: LAME CBR files with Info tag were being incorrectly + flagged as VBR (thanks Jojo) + * Bugfix: LAME tag not being detected for LAME 3.90 (original) + Changed regex pattern match for MP3 to include 3rd byte for more + reliable/accurate pattern matching + Added duplicate-ID3v1 tag checking (two ID3v1 tags, one after the + other) that has been known to occur with iTunes + (thanks towbØtiscali*de) + Added instructions for enabling iconv() support under Windows + Removed some unneccesary debugging code + Suppressed duplicate PHP warnings for missing include files + Included some missing dependencies in various files + /demo/audioinfo.class.php now copies ['audio']['encoder_options'] + + +1.7.0b1: [2003-09-28] Allan Hansen + This beta version was not made by James Heinrich. It was made by + Allan Hansen - please send bug reports on this + beta directly to me. + + James Heinrich will release 1.7.0 final, but it may take some time + to work out the bugs from the major rewrite. + + This version could be called getID3lite. It makes a lot of checks + optional and makes it easy to remove support for undesired formats + + It also is more library-like. Older versions of getID3() declared + an incredible amount of global scope functions and defined several + constants. 1.7.0beta1 still declares constants, but they are all + prepended by GETID3_. It declares no global scope functions - they + are all wrapped into classes. + + » Made getID3() depend on iconv library: compile PHP --with-iconv + » Created new directory structure + Moved all demos to demos/ + Moved all getID3() files to getid3/ + Renamed most files to module.something + Changed header in all module.something to explain what they do + Simply remove all modules you don't need + Wrapped all modules into classes + * Bugfix: Implemented misc patches from Eugene Toder + * Bugfix: Implemented misc patches from "six" + ¤ Added root key 'encoding' + ¤ Added prefix GETID3_ to all defined constants. + ¤ Wrapped getid3.php into getid3 class + ¤ Wrapped getid3.functions.php into getid3_lib class + Removed unused functions + Moved several functions away from getid3.functions.php and + into the files where they are actually used. + Renamed getid3.functions.php to getid3.lib.php + Moved getid3.rgad.php functions into getid3_lib + Moved getid3.getimagesize.php funcitons ingo getid3_lib + ¤ Moved getid3.ogginfo.php into ogg module + ¤ Combined GetTagOnly() and GetAllFileInfo() in method analyze + ¤ Removed redundant and unuseful root keys + 'file_modified_time' == filemtime($filename) + 'md5_file' == md5_file($filename) + 'exist' == file_exists($filename) + ¤ Changed root key ['tags'] from array of string to array of array + of comments. + Simplified code for detecting base path. + Removed ob_ from InitializeFilepointerArray(). That was really a + ugly HACK to get output from fopen. If user want the reason, + he should open the file himself! + Checking for APE tags before lyrics3 - makes Lyrics3 not depend + on APE tag. It seems to work on my test file. + Changed ['error'] and ['warning'] in multiple files to append to + array instead of appending to string. That simplified code in + getid3.php too. + Simplified clean-up procedure: simply remove all empty root keys + Setting tags in individual modules instead of main getid3.php + Made Bonk and ASF modules non-dependent on id3 modules - id3 + optional. + Rewrote HandleAllTags() - simplified and convert comments to + desired encoding. + Replaced all calls to RoughTranslateUnicodeToASCII() in ASF module + with a TrimConvert() method. This uses iconv() for conversion. + It also converts from UNICODE instead of UTF-16BE, as the spec + says it should. + Replaced all calls to RoughTranslateUnicodeToASCII() in id3v2 + module with iconv(). id3v2 module also reads + $ThisFileInfo['encoding'] and converts all comments to this + format. All other formats just add their comments in their + native charset, but every comment field in id3v2 can have a + different encoding, so this is needed. + Did same thing as above with ISO module. However - it does not + work. I need to find out how to specify big-endian unicode != + UNICODING encoding name given to iconv(). + Built-in assume mp3 format in getid3.php + Temporarily nuked root key ['comments'] and CopyCommentsToRoot() + Updated demo/audioinfo.class.php + Updated demo/check.php - some thing don't work! + Other demos are out of order! + + +1.6.5: [October-06-2003] James Heinrich + » Added support for LiteWave (thanks supportØclearjump*com) + Ø Split out speedup info from ['OFR']['OFR']['compression'] into + ['OFR']['OFR']['speedup'] + Ø If EXIF functions for JPEG not available, now warning not error + Ø ID3v2 track number now returned as string (with leading zeros, + if present in data) rather than integer (thanks Plamen) + * Bugfix: now correctly parses cbSize element of WAVEFORMATEX + structure (thanks supportØclearjump*com) + * Bugfix: ASF module now reads non-standard field names, + i.e. "date" as well as WM/Year - patch from Eugene Toder. + * Bugfix: ASF module now returns genre as-is if it is not a + standard ID3v1 genre (thanks wonderboy) + * Bugfix: ['audio']['compression_ration'] missing for MPC + (thanks WaldoMonster) + Prevent infinite loop in MP3 histogram if framelength == 0 + Added wFormatTag values 0x00FF and 0x2001 - 0x2005 + (thanks steveØheadbands*com) + Added "twos" and "sowt" FourCCs for Mac AIFC + + +1.6.4: [June-30-2003] James Heinrich + » Added support for free-format MP3s + (thanks Sebastian Mares for the idea) + » Compressed (Flash 6+) SWF files are now handled properly + (thanks alan*cheungØalumni*ust*hk) + » Added DeleteLyrics3() to getid3.lyrics3.php + » Added FixID3v1Padding() to getid3.putid3.php + » Added new simple MP3-splicing sample file + (thanks tommybobØmailandnews*com for the idea) + New file: getid3.demo.joinmp3.php + » Moved all contents of getid3.putid3.php into either + getid3.id3v1.php or getid3.id3v2.php or getid3.functions.php as + appropriate + Removed file: getid3.putid3.php + ¤ ['error'] and ['warning'] keys now return as arrays, not strings + ¤ New root key for all files: ['file_modified_time'] (UNIX time) + ¤ getid3.demo.scandir.php renamed to getid3.demo.mysql.php + ¤ New demo file returns the MIME type only for a single file + (thanks adminØe-tones*co*uk for the idea) + New file: getid3.demo.mimeonly.php + ¤ Added check for valid ID3v1 padding (strings should be padded + with null characters but some taggers incorrectly use spaces). + A warning will be generated if padding is invalid. New boolean + key ['id3v1']['padding_valid'] indicates padding validity. + ¤ CleanUpGetAllMP3info() removes more useless root keys for + unknown-format files + ¤ Extended LAME information in ['mpeg']['audio']['LAME'] is now + only returned for LAME v3.90+ + ¤ LAME-encoded MP3s now return + ['mpeg']['audio']['LAME']['long_version'] as well as + ['mpeg']['audio']['LAME']['short_version'] - these are identical + in LAME v3.90+ but older versions will report longer more + detailed version information if available + ¤ New Lyrics3 values: ['lyrics3']['raw']['offset_start'] and + ['lyrics3']['raw']['offset_end'] + ¤ New optional parameter on getAPEtagFilepointer() to scan from a + defined offset rather than end-of-file to allow scanning of APE + tags before Lyrics3 tags + ¤ ['tag_offset_start'] and ['tag_offset_end'] are now present in + ['ape'], ['lyrics3'], ['id3v1'] and ['id3v2'] + ¤ Numerous changes to the returned structure and content for La + files, including parsing the seektable (if applicable) and + parsing RIFF data occuring after the end of the compressed audio + data (notably RIFF comments) + (thanks mikeØbevin*de) + ¤ getSWFHeaderFilepointer() now has optional 3rd parameter + $ReturnAllTagData (default == false) which if set to true will + return data on all tags in ['swf']['tags'] + ¤ ['swf']['bgcolor'] now returns the 6-character string + representing the background color in HTML hex color format + (thanks ubergeekØubergeek*tv) + ¤ ['swf']['header']['frame_delay'] is no longer returned + ¤ getQuicktimeHeaderFilepointer() now has two additional optional + parameters: $ReturnAtomData (default == true) and + $ParseAllPossibleAtoms (default == false). Setting + $ReturnAtomData to false will reduce the size of the returned + data array by unsetting ['quicktime']['moov'] before returning. + Leaving $ParseAllPossibleAtoms as false now suppresses parsing + of several atom types that contain very large tables of data + that are not typically useful. Atom type suppressed are: + stts, stss, stsc, stsz, and stco + (thanks ubergeekØubergeek*tv) + ¤ ['fileformat'] no longer set to 'id3' if ID3v1 or ID3v2 tag + detected but no other data format recognized + * Bugfix: La files now return the correct values for + ['avdataoffset'] and ['avdataend'] and therefore the correct + values for ['md5_data'] - note that ['md5_data'] values will not + match values from previous versions of getID3() - the previous + versions were incorrect + (thanks mikeØbevin*de) + * Bugfix: A temporary file was being created in the web server's + root directory (not DocumentRoot) each time ['md5_data'] was + calculated, and not removed due to lack of permissions. Temp + file is now created (as it was supposed to be) in the directory + of the file being examined, or the system temp directory, and + properly removed when done. + * Bugfix: Several incorrect values were being returned inside + ['mpeg']['audio']['LAME'] (thanks bouvigneØmp3-tech*org) + * Bugfix: SWF frame rates values were usually incorrect. + (thanks alan.cheungØalumni*ust*hk and ubergeekØubergeek*tv) + * Bugfix: ID3v2.2 files always flagged 4 bytes of invalid padding + (thanks marcaØmac*com) + * Bugfix: Lyrics3 without ID3v1 was not working properly + * Bugfix: Lyrics3, APE & ID3v1 can all now exist in the same file. + A warning is issued if APE comes after Lyrics3 (because Lyrics3- + aware taggers probably are not APE-aware and therefore won't be + able to find the Lyrics3 tag) (thanks mp3gainØhotmail*com) + * Bugfix: WriteAPEtag() now writes the APE tag before any Lyrics3 + tags (if present) and removes any incorrect ones that are after + existing Lyrics3 tags (thanks mp3gainØhotmail*com) + * Bugfix: RIFF-WAVE file with incorrect NumberOfSamples values in + the 'fact' chunk no longer cause incorrect playtime calculation + (thanks stprasadØindusnetworks*com) + * Bugfix: getid3.demo.simple.php had undefined variables if the + file needed to be deep-scanned with assumeFormat + * Bugfix: fixed previously-incorrect ['avdataend'] values for APE + and Lyrics3 tags in some cases, which in some cases means that + ['md5_data'] is different than previously (now correct) + Much-improved detection of AAC-ADTS, which also means MP3 + format detection should now be nearly twice as fast + Truncated AVIs and WAVs are now reported + Number of new features and bugfixes in getid3.demo.mysql.php + Quicktime 'meta' atoms now parsed, so Quicktime MP4 files can now + return artist, title, album, etc (thanks spunkØdasspunk*com) + Consolidated all comments processing functions (processing the + ['comments'] and ['tags'] keys) into HandleAllTags() which now + also checks to ensure that APE tags are really better than ID3v2 + before using them in ['comments'] + Known issue with Meracl ID3 Tag Writer v1.3.4 truncating last byte + of MP3 file when appending new ID3v1 tag now specifically noted + (rather than generic Probably Truncated File message) + getid3.demo.mysql.php now stores last-modified time for each file + getid3.demo.mysql.php is now case-sensitive for filenames + getid3.demo.mysql.php can generate M3U playlists of any of the + groups of files it can select (duplicate filenames, tag types, + etc.) + getid3.demo.mysql.php can now find mismatched tag contents and + filenames + getid3.demo.check.php now shows total number of errors & warnings + GetFileFormatArray() now matches actual patterns for MP3 files + based on the first two bytes of the file, rather than just the + first one + Simplified DeleteAPEtag() and made it work properly with Lyrics3 + + +1.6.3: [May-17-2003] James Heinrich + » Added support for Bonk (thanks ahØartemis*dk) + New file: getid3.bonk.php + » Added support for AVR (thanks ahØartemis*dk) + New file: getid3.avr.php + ¤ Contents of getid3.id3.php moved to getid3.id3v1.php + Removed file: getid3.id3.php + ¤ Contents of getid3.frames.php moved to getid3.id3v2.php + Removed file: getid3.frames.php + ¤ Returned data structure documentation improved and updated and + now stored in getid3.structure.txt rather than getid3.readme.txt + New file: getid3.structure.txt + ¤ Now including the GNU General Public License in the distribution + as getid3.license.txt + New file: getid3.license.txt + ¤ Added new, optional, parameter to WriteAPEtag() (and also + GenerateAPEtag()) which must be set to TRUE if the values you + are passing are already UTF8-encoded, otherwise all data is + encoded to UTF8 by default. For all ASCII/ANSI data this value + should be left at the defaul value of FALSE. + ¤ Added third, optional, parameter to getID3v2Filepointer() - + $StartingOffset (default == 0) which can parse an ID3v2 tag + in a file at a position other than the start-of-file. + ¤ ['video']['pixel_aspect_ratio'] now returned when known + ¤ AVI files with WMA audio now return ['audio']['dataformat'] + of 'wma' rather than 'wav' + ¤ ASF-WMA files now return the artist value from WM/AlbumArtist + in ['comments']['artist'] (thanks msibbaldØsaebauld*com) + ¤ ASF-WMA files now return the 'author' value from + ['asf']['content_description'] in ['comments']['artist'] + instead of ['comments']['author'] + ¤ ASF-WMA files now return the 'description' value from + ['asf']['content_description'] in ['comments']['comment'] + instead of ['comments']['description'] + * Bugfix: APE tag writing with multiple values for a tag (more + than one ARTIST for example) was not being correctly written + (thanks ahØartemis*dk) + * Bugfix: CreateDeepArray() was returning an empty-string key as + the top-level returned value - ['iso']['files'] now directly + contains the file listing without an empty array in between. + * Bugfix: ID3v2 genreid was not being returned in some cases. + * Bugfix: APEv1 tags would generate error messages + * Bugfix: APE tags would sometimes show phantom second entry for + each item (title, artist, etc) with no data + * Bugfix: APE tag writing was not UTF8-encoding the data - + non-ASCII characters (above chr(127)) were being incorrectly + stored (thanks ahØartemis*dk) + * Bugfix: getid3.demo.scandir.php had undefined function error + * Bugfix: getid3.demo.scandir.php would not display list of files + with no tags + Added link to getid3.demo.check.php from list of specific-tags + files in getid3.demo.scandir.php + + +1.6.2: [May-04-2003] James Heinrich + » New official mirror site for getID3() - https://www.getid3.org + » Added basic support for SWF (Flash) (thanks n8n8Øyahoo*com) + New file: getid3.swf.php + » Added experimental support for parsing the audio portion of + MPEG-video files. I don't have any actual documentation for + this, so this part is experimental and not guaranteed accurate, + but it seems to be working OK as far as I have been able to test + it. Bug reports (or even better - documentation!) are welcome at + info@getid3.org + » Added new simple directory-scanning sample file + New file: getid3.demo.simple.php + » getid3.demo.write.php now writes APE tags as well. + ¤ Renamed getid3.write.php to getid3.demo.write.php + ¤ Renamed audioinfo.class.php to getid3.demo.audioinfo.class.php + ¤ getid3.php now automatically includes the getid3.functions.php + function library file, no need to include it seperately. + ¤ getLyrics3Filepointer() has been changed to be consistant with + all the other similar function structures - the parameters have + changed. The old function has been renamed to getLyrics3Data() + ¤ Added DeleteAPEtag() function to getid3.ape.php + ¤ HandleID3v1Tag() now only handles ID3v1. Lyrics3 processing is + now done by HandleLyrics3Tag() + ¤ If BitrateHistogram is enabled in getOnlyMPEGaudioInfo() it now + also returns ['mpeg']['audio']['version_distribution'] showing + the number of frames of each MPEG version (1, 2 or 2.5) - all + frames *should* be of the same MPEG version + ¤ getID3v1Filepointer() always returns TRUE now, even if it didn't + find a valid ID3v1 tag + ¤ getOnlyMPEGaudioInfo() now looks for MPEG sync in the first 128k + bytes rather than the first 64k bytes + ¤ Added dummy function GetAllMP3info() to generate warning not to + use that deprecated function. + ¤ ['video']['codec'] is now 'MPEG' for all MPEG video files (this + will change to 'MPEG-1' or 'MPEG-2' as soon as I figure out how + to determine that) (thanks jigalØspill*nl) + ¤ ['mpeg']['audio']['LAME']['mp3_gain'] renamed to + ['mpeg']['audio']['LAME']['mp3_gain_db'] (gain in dB) + ¤ Added ['mpeg']['audio']['LAME']['mp3_gain_factor'] (gain as a + multiplication factor) + ¤ Added support for Preset and Surround Info bytes from LAME VBR + tag (http://gabriel.mp3-tech.org/mp3infotag.html) + * Bugfix: APE tag writing would put the string 'Array' for all + values rather than the actual data (thanks ahØartemis*dk) + * Bugfix: Warning now generated for VBR MPEG-video files because + getID3() cannot determine average bitrate. If you know of + documentation that would tell me how to do this, please email + info@getid3.org + * Bugfix: Replay Gain values from Vorbis comments are now + returned in ['replay_gain'] (and not in ['comments']) + (thanks ahØartemis*dk) + * Bugfix: Replay Gain values from APE comments are now correctly + returned in ['replay_gain'] (thanks ahØartemis*dk) + * Bugfix: getid3.demo.check.php is now case-insensitive when + assuming a format for a corrupted file if standard detection + does not identify the file type. + * Bugfix: RIFF comments were overwriting/suppressing ID3 comments + for RIFF-MP3 files (thanks wmØwofuer*com) + * Bugfix: RIFF-MP3 files with 'RMP3' chunks instead of 'WAVE' were + not being correctly identified. + * Bugfix: ID3v2 padding shorter than the length of an ID3v2 frame + header was not correctly detected + * Bugfix: getid3.demo.check.php now does in-depth scanning for MP2 + and MP1 files the same as for MP3 files based on file extension + if a MPEG-audio structure isn't found immediately at the start + of the file + * Bugfix: removed condition where RIFF-WAV was being scanned for + MPEG-audio signature when it shouldn't be present (non-MP3 WAV) + * Bugfix: ASF files were not always showing correct audio datatype + * Bugfix: array_merge_clobber() and array_merge_noclobber() were + not being conditionally defined in getid3.functions.php + (thanks rich.martinØreden-anders*com) + * Bugfix: stream_numbers was not being correctly returned in + bitrate_mutual_exclusion_object chunks of ASF files + * Bugfix: Added support for 24kHz and 12kHz audio in ASF files + * Bugfix: Removed possible undefined offset error in MP3s where + cannot find synch before end of file + * Bugfix: Removed potential out-of-memory crash situation when + parsing Real files with chunks larger than the available memory + (thanks jigalØspill*nl) + * Bugfix: ID3v1 was incorrectly taking precedence over ID3v2 in + the ['comments'] array (thanks lionelflØwanadoo*fr) + * Bugfix: No longer calculates overall bitrate and playtime for + VBR MPEG video files based on the audio bitrate. + * Bugfix: AssumeFormat was not working properly + Added summary footer line to getid3.demo.check.php + Added '.mpeg' to the list of assume-format-from-filenames list in + getid3.demo.check.php + MPEG-video files now more reliably detected + A number of additional features have been added to + getid3.demo.scandir.php + Added many RIFF-AVI audio types and fourcc video types to the + lookup functions in getid3.riff.php + Now identifes files with Lyrics3 v1 tags that are of incorrect + length (v1 Lyrics3 is supposed to be 5100 bytes long, but + [unknown program] writes variable-length tags (which is illegal + for Lyrics3 v1)). getID3() now correctly parses these tags and + issues a warning. + Split GetFileFormat() to GetFileFormat() and GetFileFormatArray() + HTML colors in getid3.demo.check.php are now defined as constant + variables at the top of the file (if you want to change them) + Added support for OptimFROG v4.50x (non-alpha) (new header fields) + (thanks floringhidoØyahoo*com) + Added support for Lossless Audio v0.4 (thanks mikeØbevin*de) + + +1.6.1: [March-03-2003] James Heinrich + » Added support for writing APE v2. + WriteAPEtag() in getid3.ape.php + NOTE: APE v1 writing support will *not* be added to future + versions of getID3() + (thanks ahØartemis*dk and adamØphysco*com for the idea) + » Added support for AIFF (Audio Interchange File Format) including + AIFF, AIFC and 8SVX (thanks ahØartemis*dk for the idea) + Removed file: getid3.aiff.php + » Added support for OptimFROG (v4.50a and v4.2x) + (thanks ahØartemis*dk for the idea) + New file: getid3.optimfrog.php + » Added support for WavPack (thanks ahØartemis*dk for the idea) + » Added support for LPAC (thanks ahØartemis*dk for the idea) + » Added support for NeXT/Sun .au format + New file: getid3.au.php + » Added support for Creative SoundBlaster VOC format + New file: getid3.voc.php + » Added support for the BWF (Broadcast Wave File) RIFF chunks + "bext" and "MEXT" (thanks Ryan and njhØsurgeradio*co*uk) + » Added support for the CART (Broadcast Wave File) RIFF chunks + (thanks Ryan) + » Added getid3.demo.scandir.php - a sample recursive scanning demo + that scans every file in a given directory, and all sub- + directories, and stores the resulting data in MySQL database, + and then displays a list of duplicate files based on md5_data + ¤ ['md5_data_source'] now contains the MD5 value for the original + uncompressed data for formats that store that information + (currently only FLAC v0.5+). ['md5_data'] (if chosen to be + calculated) will contain the calculated MD5 value for the + compressed file. To check if 2 files are identical in every way, + including all comments: compare ['md5_file']. To check if two + files were compressed from the same source file: compare + ['md5_data_source']. To check if the compressed audio/video data + of two files is identical, even if comments or even the + container file format is different (MP3 in RIFF container, + FLAC in Ogg container, etc): compare ['md5_data']. + ¤ ['md5_data'] for 8-bit WAV files is now calculated based on a + converted version of the data from unsigned to signed (MSB + inverted) to match the MD5 value calculated by FLAC + ¤ New optional parameter added to GetAllFileInfo() - + $MD5dataIfMD5SourceKnown (default: false). If false the md5_data + value will NOT be calculated for files (such as FLAC) that have + ['md5_data_source'] set, even if $MD5data == true. + (thanks ahØartemis*dk) + ¤ getid3.check.php renamed to getid3.demo.check.php + ¤ Added GetTagOnly() function to getid3.php - similar to + GetAllFileInfo() except only takes a filename as a parameter and + only returns ID3v2, APE, Lyrics3 and ID3v1 tag information - no + attempt is made to parse the data contents of the file at all. + (thanks Phil for the idea) + ¤ Added ['audio']['lossless'] and ['video']['lossless'] for all + formats (when known). Both are boolean values - true means the + data is lossless-compressed, false means the data is lossy- + compressed. + ¤ Added ['audio']['compression_ratio'] and/or + ['video']['compression_ratio'] for all formats. Returns a number + (usually) less than 1, where 1 represents no compression and 0.5 + represents a compressed file half the size of the original file + ¤ Added ['video']['bits_per_sample'] to all video formats (when + known) + ¤ Added ['video']['frame_rate'] to all video formats (when known) + ¤ ['fileformat'] set to 'mp1' or 'mp2' instead of 'mp3' when + ['audio']['dataformat'] is one of those (thanks ahØartemis*dk) + ¤ Added 4th parameter to md5_data(), $invertsign, which will invert + the MSB of each byte before MD5'ing. This is needed for 8-bit + WAV files because FLAC calculates the stored MD5 value on + signed data rather than the original byte values. ['md5_data'] + of an 8-bit WAV will now match the ['md5_data_source'] value + (thanks lichvarmØphoenix*inf*upol*cz) + ¤ ['ape']['items']['data'] and ['ape']['items']['data_ascii'] now + contains an array of values, if the tag contains UTF-8 text (as + opposed to binary data) + ¤ ['mpeg']['audio']['bitratemode'] renamed to + ['mpeg']['audio']['bitrate_mode'] + * Bugfix: Removed potential bug that could replace all MP3 file + contents with only the new ID3v2 tag in getid3.putid3.php + * Bugfix: md5_data values calculated for RIFF (WAV, AVI) files + were incorrect (thanks ahØartemis*dk) + * Bugfix: MP3 data in an MP4 wrapper fileformat could not identify + bitrate (thanks ahØartemis*dk) + * Bugfix: ['audio'] and/or ['video'] keys would sometimes get + removed even if not empty + * Bugfix: Prevented creation of null entries in + ['RIFF']['WAVE']['INFO'] if a comment entry was not present + * Bugfix: Potential infinite-loop condition in getid3.ogg.php + (thanks afshin.behniaØsbcglobal*net) + * Bugfix: Ogg files with illegal ID3v1 (and/or APE or Lyrics3) + tags were not finding the last Ogg page + (thanks afshin.behniaØsbcglobal*net) + * Bugfix: replay-gain values not properly set from LAME tag + * Bugfix: RIFF-MP3 had incorrect md5_data + * Bugfix: the LAME DLL CBR problem of not re-writing the LAME + frame at the beginning of the data is now detected for MP3s + with ID3v2 tags as well + * Bugfix: APE tags with multiple values (ie multiple entries in + the "artist" tag) are now shown properly in ['ape']['items'] + * Bugfix: fixed condition where APE tag with no ID3v1 tag could be + mistaken for APE tag with ID3v1 (and incorrectly parsed) + * Bugfix: added warning if ID3v2 frame has zero-length data + (thanks cmassetØclubinternet*fr) + * Bugfix: getid3.frames.php looking for non-existant key in USER + frames + Improved detection of RIFF-MP3 data. [unknown program] encodes + RIFF-WAV data with a chunk name of 'RMP3' instead of the + standard 'RIFF' + Encoder now returned in both ['comments'] and ['audio']['encoder'] + for RIFF-WAV files with an INFO.ISFT chunk + Generate a warning for FLAC files encoded with v0.3 or v0.4 + because audio_signature is not calculated during encoding + (thanks ahØartemis*dk) + Modified getid3.check.php to display md5_data_source as well as + md5_file and md5_data if display-MD5 mode is selected + Modified getid3.check.php to assume-format based on file extension + in browse mode if fileformat is found to be 'id3' (formerly only + if the fileformat was null) + Changed scaling of BitrateColor() from representing 1-256kbps to + representing 1-768kbps for better display of high-bitrate files, + specifically lossless-compressed CD-audio (FLAC, LA, etc) + + +1.6.0: [January-30-2003] James Heinrich + » Added support for OggFLAC (FLAC data stored in an Ogg container) + (thanks ahØartemis*dk for the idea) + » Added support for Speex (the data stored in an Ogg container) + » Comments are now available in the root 2-dimensional array + ['comments'] - each entry in this array will contain one or more + strings. For example, if there are two artists then + ['comments']['artist'][0] will contain the first one and + ['comments']['artist'][1] the other. All keys are forced + lowercase. Comments will be stored in the ['comments'] array in + this order of precedence: + 1) Native format tags (ASF, VQF, NSV, RIFF, Quicktime, Vorbis) + 2) APE tags + 3) ID3v2 + 4) Lyrics3 + 5) ID3v1 + Lower-priority tags will not overwrite or append existing values + of higher-priority tags (for example, 'artist' in ID3v1 will be + ignored if already specified in APE), but missing values will be + filled in (for example, if 'album' is specified in ID3v2 but not + in APE, it will be included in the ['comments'] array). + Note: Root keys (['title'], ['artist'], etc) are NOT available + in this or future versions of getID3(). + (thanks ahØartemis*dk) + » MD5 hashes are now available for all formats for both the entire + file (['md5_file']) and the portion of the file containing only + the audio/video data, stripped of all prepended/appended tags + like ID3v2, ID3v1, APE, etc - ['md5_data'] + (thanks ahØartemis*dk for alternate md5_file() function that + runs on UNIX system running PHP < 4.2.0) + NOTE: Ogg files require the use of vorbiscomment to obtain the + md5_data value. vorbiscomment must be downloaded from + http://www.vorbis.com/download.psp and placed in the getID3() + directory. All Ogg formats (Vorbis, OggFLAC, Speex) are affected + by this problem, but only OggVorbis files can be processed with + vorbiscomment. OggFLAC and Speex files will be processed by + getID3(), but this may result in an incorrect value for md5_data + in the event that VorbisComments are larger than 1 page (4-8kB). + NOTE: md5_data for Ogg will not work if PHP is running in Safe + Mode + » There is now a wrapper class available, written by Allan Hansen, + which should simplify extracting most common basic information + (such as format, bitrate, comments). + New file: audioinfo.class.php + » OggWrite() in getid3.ogginfo.php has been replaced with a new + version that uses vorbiscomment to write the comments, because + of a reported bug that can corrupt OggVorbis files such they + cannot be played. + NOTE: Ogg comment writing now requires the use of vorbiscomment + which must be downloaded from http://www.vorbis.com/download.psp + and placed in the getID3() directory. + NOTE: Ogg comment writing will not work if PHP is running in + Safe Mode + ¤ New root key ['tags'] is now always returned for all formats. + It is an array that may contain any of: + * Native format tags: 'vqf', 'riff', 'vorbiscomment', 'asf', + 'nsv', 'real', 'midi', 'zip', 'quicktime' + * Appended data tags: 'ape', 'lyrics3', 'id3v2', 'id3v1' + ¤ New root key ['audio'] is an array containing any or all of: + codec, channels, channelmode, bitrate, bits_per_sample, + dataformat, bitrate_mode, sample_rate, encoder + Note: This replaces several root keys, including: + bitrate_audio, bits_per_sample, frequency, channels + ¤ New root key ['video'] is an array containing any or all of: + bitrate_mode, bitrate, codec, resolution_x, resolution_y, + resolution_y, frame_rate, encoder + Note: This replaces several root keys, including: + bitrate_video, resolution_x, resolution_y, frame_rate + ¤ ['id3']['id3v1'] has moved to ['id3v1'] + ¤ ['id3']['id3v2'] has moved to ['id3v2'] + ¤ ['audiodataoffset'] and ['audiodataend'] have been renamed to + ['avdataoffset'] and ['avdataend'] respectively + ¤ GetAllMP3info() has been changed to GetAllFileInfo() with a + different parameter list ($allowedFormats is no longer a + parameter). Check your code where you're calling + GetAllMP3Info() - you will need to change both the function + name and the parameter list if you pass more than 2 parameters + ¤ All formats now return ['audio']['dataformat'] and/or + ['video']['dataformat'] where appropriate - this goes along with + ['fileformat'] - ['fileformat'] will return the actual structure + of the file, whereas ['dataformat'] will return the format of + the data inside that structure. For example, an Ogg file can + contain Vobis data (normal), or it can contain FLAC data in the + Ogg container format. In that case, ['fileformat'] would be + 'ogg', but ['dataformat'] would be 'flac'. + Note: this means that WAV and AVI files now return a + ['fileformat'] of 'riff' rather than 'wav' or 'avi'. + ¤ ['filesize'] is no longer returned for files larger than 2GB + because PHP does not support large file access. Attempting to + parse a file larger than 2GB will result in a message stored in + ['error'] and ['filesize'] not set. + ¤ APEtag, ID3v1, and ID3v2 are now supported on ALL multimedia + files - even if illegal by format. Ogg will return warning if + ID3/APE tags are present. (thanks ahØartemis*dk) + ¤ All files: non-critical errors are now returned in the root key + ['warning'] rather than ['error'] (only critical errors that + prevent getID3() from correctly parsing the file are returned in + ['error'] (thanks ahØartemis*dk) + ¤ Renamed all references to $MP3fileInfo to $ThisFileInfo + ¤ Joliet now supported for ISO-9660. + ['iso']['supplementary_volume_descriptor'] is now returned, if + available, and ['iso']['files'] will contain ASCII equivalents + of the Unicode directory structure & filenames stored. + ¤ Moved Monkey's Audio code from getid3.ape.php to seperate file. + New file: getid3.monkey.php + ¤ Added new keys for ISO-9660: ['name_ascii'] for directories, + ['file_identifier_ascii'] for files + ¤ Added root key ['track'] for CD-audio files + ¤ Ogg/Vorbis-comment files now have comments returned inside + ['ogg']['comments_common'] as an array of strings, rather than + simple strings in ['ogg'] + ¤ Quicktime files now have comments returned inside + ['quicktime']['comments'] as an array of strings, rather than + simple strings in ['quicktime'] + ¤ ['mime_type'] is a new root key returned for all supported + formats (thanks ahØartemis*dk) + ¤ ['fileformat'] now returns 'mp1' instead of 'mp3' for MPEG-1 + layer-I audio files (thanks ahØartemis*dk) + ¤ ['mpeg']['audio']['bitratemode'] now returns lowercase + ¤ MPEG-4 audio files which consist of MP3 data wrapped in a + Quicktime fileformat will now return the usual data in + ['mpeg']['audio'] + ¤ Type-1 DV AVIs are now supported + ¤ DV AVIs will return 1 or 2 in ['RIFF']['video'][x]['dv_type'] + ¤ Changed ['fileformat'] from 'mpg' to 'mpeg' for MPEG video files + ¤ ASF comments are now stored in ['asf']['comments'] instead of + ['asf'] + ¤ RealMedia chunk data is now returned inside ['real']['chunks'] + instead of ['real'] + ¤ ['replay_gain'] now properly populated from APE tags + ¤ Added support for ASF_Old_ASF_Index_Object in ASF files + (thanks ahØartemis*dk) + ¤ AAC-ADTS files now return ['aac']['bitrate_distribution'] + ¤ ParseVorbisComments() has been replaced with + ParseVorbisCommentsFilepointer() (with different parameters) + ¤ All references to any key ['frequency'] are now ['sample_rate'] + ¤ Moved ID3v2 comments from ['id3v2'] into common root + ['comments'] structure, and now returns more values than before + * Bugfix: ['iso']['files'] and ['zip']['files'] could potentially + contain duplicate entries (in a numeric-indexed array) for files + if the directory structure specifies files multiple times. + Entries are now guaranteed unique, with the last entry for the + file overwriting any former ones. + * Bugfix: RIFF parsing had numerous issues, including: + - large AVIs would take a very very long time to parse + - chunks with odd (not even) sizes would cause the parser fail + - video and/or audio codecs not always identified + The ParseRIFF() function has been completely rewritten and fixes + all known issues with RIFF parsing. Users are, however, + encouraged to double-check output of any parsed (AVI/WAV/CDDA) + files. + * Bugfix: Modified getid3.riff.php to return correct total + bitrates for AVIs with multiple audio streams + * Bugfix: GetFileFormat() was not creating array structure + correctly (thanks ahØartemis*dk) + * Bugfix: LAME tag for MP3s can only specify up to 255kbps, so any + files with actual CBR bitrate of >=256 were reported incorrectly + * Bugfix: Lyrics3 synched lyrics were not being correctly returned + * Bugfix: CreateDeepArray() was broken for non-nested cases, which + meant ZIP and ISO ['files'] structures were broken + * Bugfix: Incorrect pattern matching for ZIP files meant no zip + files were being detected as such + * Bugfix: AAC-ADIF was returning an incorrect number of channels + (too few) in some cases (thanks ahØartemis*dk) + * Bugfix: Vorbis comments were returning an incorrect value for + ['dataoffset'] in some cases + * Bugfix: MPEG video ['marker_bit'] and ['vbv_buffer_size'] were + incorrect + * Bugfix: ['playtime_string'] could potentially have a value of + x minutes and 60 seconds (ie 3:60 instead of 4:00) + Added support for FLAC cuesheets (FLAC 1.1.0+) + (thanks ahØartemis*dk) + Improved parsing speed in MP3, MP2 and AAC (thanks ahØartemis*dk) + Extra error-checking added to try and identify corrupt files for + most audio formats (thanks ahØartemis*dk) + More accurate playtime calculation for RealMedia + (thanks ahØartemis*dk) + Changed all relevant files to use ['audiodataoffset'] and + ['audiodataend'] rather than ['filesize'] where appropriate + (thanks ahØartemis*dk) + Added text encoding type 255 as a duplicate of UTF-16BE but with + Big-Endian rather than Little-Endian byte order + Added many RIFF-AVI audio types and fourcc video types to the + lookup functions in getid3.riff.php + Added numerous new known GUIDs to getid3.asf.php + Added PoweredBygetID3() function to easily get a "powered by" + string with the current getID3() version. + Added "Morgan Multimedia Motion JPEG2000" (MJ2C), "DivX v5" (DX50) + and "XviD" (XVID) codecs to list of known codecs in + getid3.riff.php + Changed GETID3_INCLUDEPATH path seperators to forced / + (from \ for Windows) + Modified getid3.check.php to only change \ directory seperators to + / on Windows operating systems + Modified getid3.check.php to handle larger-than-2GB files (which + now do not return a filesize) + Modified getid3.check.php to handle ['dataformat_audio'] and + ['dataformat_video'] + Modified getid3.check.php to show a list of present tags in one + column rather than one column for each of ID3v1, ID3v2, etc + Modified getid3.check.php to show MD5 values. Initially disabled + but can be enabled for a directory with a click. md5_file is + always calculated when displaying detailed info about a single + file; md5_data is calculated if the file is < 50MB + Modified getid3.check.php to show errors and warnings. Details are + visible with a mouseover or a click. + Changed getid3.check.php to use SafeStripSlashes instead of a + manual conditional directory name replacement for special + characters + Added sample recursive scanning sample code to getid3.readme.txt + (thanks lipisinØmail*ru for the idea) + + +1.5.7: [January-10-2003] James Heinrich + » Added support for ISO 9660 (CD-ROM image) format. Most-useful + data is directory structure returned under ['iso']['files'] + Note: Only ISO-9660 supported, not (yet) Joliet extension + (thanks nebula_djØsofthome*net for the idea) + New file: getid3.iso.php + ¤ ZIP files are now parsed by getID3() itself without relying on + built-in PHP functions and/or ZZipLib support. + (thanks Vince for the idea) + ¤ ZIP files now return a simple directory listing with filename + and filesize info only under ['zip']['files']. + Note: empty subdirectories will note appear in here, only files + and non-empty subdirectories. Information for all entries, + including empty subdirectories, is available under + ['zip']['central_directory'] (or under ['zip']['entries'] if the + Central Directory cannot be located (usually due to a trucated + file). + ¤ RIFF-WAV files with MP3 data (or MP3s with RIFF headers, if you + want to think of it that way) now have the MPEG audio portion + scanned and the usual data returned in ['mpeg']['audio'] if the + RIFF audio codec has wFormatTag of "85" (identified by getID3() + as "MPEG Layer 3") + (thanks ahØartemis*dk for the idea) + ¤ EXIF data (if present) is returned for JPEG files under + ['jpg']['exif'] (thanks nebula_djØsofthome*net) + ¤ ['filepath'] now returned for all files with the directory part + of the full filename. + ¤ ['filenamepath'] is now returned for all files (equivalent to + ['filepath'].'/'.['filename']) + * Bugfix: ['id3']['id3v2'][]['dataoffset'] was wrong + * Bugfix: MP3s tagged with iTunes have an invalid comment field + frame name ('COM ' - should be 'COMM') but the data is valid + otherwise; the frame is now renamed to 'COMM' and parsed + normally (with the error noted in ['error']) + (thanks kheller2Ømac*com for the sample file) + * Bugfix: Some ASF/WMA audio files were not being identified as + any format (thanks ahØartemis*dk) + * Bugfix: Warning now generated and ASCII format assumed for + invalid text encoding values in ID3v2 + * Bugfix: Changed ZIP detection pattern from 'PK' to 'PK\x04\x03' + * Bugfix: Ogg/FLAC files with large Vorbis comments were dying in + an infinite loop with lots of error messages due to missing $fd + parameter on ParseVorbisComments() (thanks ahØartemis*dk) + * Bugfix: ['data'] and ['image_mime'] were being returned for all + Ogg comments even if they were not images for versions of PHP + that have image_type_to_mime_type() built in (ie PHP 4.3.0+) + + +1.5.6: [December-31-2002] James Heinrich + » Added support for NSV (Nullsoft Streaming Video) + (www.nullsoft.com/nsv/) + (thanks demonØsoundplanet*com for the idea) + New file: getid3.nsv.php + » Added support for CD-audio track files (track01.cda etc) + ¤ Added standard ['frame_rate'] root value when known (AVI, NSV, + MPEG-video) + ¤ ASF files now report ['fileformat'] of: + 'wmv' when Windows Media Video codec v7/v8/v9 is used; + 'wma' when any 'Windows Media Audio' named audio codec is used + and no video stream is present; + 'asf' in all other cases (audio-only, video-only, or both) + ¤ Removed support for ZIP functions (will be rewritten to not + require ZZIPlib support in future versions) + ¤ Added function SafeStripSlashes() as a drop-in replacement for + stripslashes(), but that only strips slashes if magic_quotes_gpc + is set + ¤ Removed support for remote file scanning (HTTP / FTP) + ¤ Added ['aac']['frames'] (number of AAC frames in file) + ¤ Added ['mpeg']['audio']['frame_count'] when a bitrate histogram + is created + ¤ Average bitrate for VBR MP3/MP2 is calculated from actual counts + of frames of various bitrates (rather than relying on the header + values or filesize) when a bitrate histogram is created + ¤ RecursiveFrameScanning() split out into seperate function + (getid3.mp3.php) + ¤ Removed old function getMP3header() from getid3.mp3.php + ¤ Changed default MPEG_VALID_CHECK_FRAMES (number of mp3 frames + scanned to ensure a valid audio sequence has been located) from + 10 to 25. This means scanning will be slightly slower, but more + reliable/accurate + * Bugfix: ID3v2.2 - valid frame names not correctly detected + (thanks maeckerØweb*de for the sample file) + * Bugfix: ID3v2.2 - valid padding not correctly detected + (thanks maeckerØweb*de for the sample file) + * Bugfix: MIDI files with flat key signatures were not being + correctly reported (thanks alexleeisØshaw*ca for sample file) + * Bugfix: now returns message in ['error'] if file does not exist + * Bugfix: ['RIFF']['video'][x]['codec'] wasn't always being + correctly populated + * Bugfix: ['bitrate'] was incorrect for multi-stream RealMedia + * Bugfix: ['playtime_seconds'] was sometimes null or incorrect + for multi-stream RealMedia + * Bugfix: ChannelTypeID was incorrect in RVA2 ID3v2.4 frames + * Bugfix: Fixed potential divide-by-zero error for corrupt FLAC + files (thanks ahØartemis*dk) + * Bugfix: AAC-ADTS was not returning ['bitrate_mode'] unless + $ReturnExtendedInfo was TRUE (thanks ahØartemis*dk) + * Bugfix: LAME-encoded CBR MP3s now properly identified as CBR + with correct bitrate (thanks ahØartemis*dk) + * Bugfix: VBR MP2 (or headerless MP3) is now identified as VBR + rather than CBR. Note: to obtain VBR bitrate for headerless + files, the entire file is scanned and a histogram distribution + of bitrates is created, and the average bitrate calculated from + that. (thanks ahØartemis*dk for sample file) + Added support for DSIZ chunks in VQF, and checks to make sure size + of audio data matches DSIZ value, if present + (thanks ahØartemis*dk for sample file) + Rewrote GetAllMP3info() - removed some unneccesary code, changed + format-detection routine from ParseAsThisFormat() to + GetFileFormat() to allow for more flexible format parsing + (needed for ISO CD-ROM images, helpful for Quicktime and others) + Changed references in all files from string-cast indexes: ["$i"] + to non-cast indexes: [$i] where appropriate + Put a sans-serif 9pt style on all text in getid3.check.php + getAACADTSheaderFilepointer() now return TRUE if synch is lost + after the first frame has been successfully parsed (previously + it would return FALSE if synch was lost at any time, meaning the + file is most likely MP3, which was incorrect) + (thanks ahØartemis*dk for sample file) + Speed improvement code changes to getid3.mp3.php (up to 24% faster + in some cases) (thanks ahØartemis*dk for the code) + Changed all include_once() to require_once() + + +1.5.5: [November-25-2002] James Heinrich + » Added support for La (Lossless Audio - www.lossless-audio.com) + (thanks ahØartemis*dk for the idea) + New file: getid3.la.php + ¤ Moved lookup functions from getid3.lookup.php to the files where + they are used. + New file: getid3.id3.php + New file: getid3.rgad.php + Removed file: getid3.lookup.php + ¤ getID3v1Filepointer() returns FALSE if ID3v1 tag not found + ¤ Added new paramter "ReturnExtendedInfo" to the function + getAACADTSheaderFilepointer() in getid3.aac.php which now + defaults to FALSE - if TRUE then the data for every frame is + returned (containing aac_frame_length, adts_buffer_fullness and + num_raw_data_blocks, which aren't usually very useful). Speed + improvement with FALSE is about 35%. + ¤ Now returns fopen() errors in ['error'], for example if a remote + file is not accessible. + ¤ Changed default number of MP3 audio frames to scan to determine + if a valid stream has been found from 5 to 10, now also defined + as a constant at the top of getid3.mp3.php This will result in + slightly slower MP3 parsing, but greater reliability in + detecting false/invalid/corrupted VBR headers. + ¤ fopen() errors now displayed in getid3.putid3.php + (thanks miguel.dieckmannØhamburg*de) + ¤ Added 4th parameter to decodeMPEGaudioHeader() $ScanAsCBR which + will force an MP3 audio frame sequence to be force-scanned in + CBR mode. You should never need to call this directly, it's only + used internally to scan for MP3 files that have an illegal VBR + header with CBR data. (thanks fletchØpobox*com) + * Bugfix: ASF_Marker_Object in getid3.asf.php was always returning + an error in non-existant "reserved_1" and failing + * Bugfix: VBR bitrate calculations in getid3.mp3.php only occur if + ['mpeg']['audio']['VBR_frames'] is defined. + (thanks fletchØpobox*com) + * Bugfix: getid3.putid3.php no longer deletes original MP3 if + ID3v2 tag writing fails (thanks miguel*dieckmannØhamburg*de) + * Bugfix: incorrect order of if-statement error messages in + getid3.putid3.php (thanks miguel*dieckmannØhamburg*de) + getid3.asf.php now notes the error and continues parsing rather + than failing when it encounters an error parsing a chunk + Now actually scan 1000 frames for AAC ADTS as reported in the + v1.5.4 changelog, rather than 100. (thanks ahØartemis*dk) + Improved scanning speed in getAACADTSheaderFilepointer() by ~30% + (thanks ahØartemis*dk for the fix) + Added FileSizeNiceDisplay() function to getid3.functions.php for + formatting filesize output in kB, MB, GB, etc. + + +1.5.4: [October-07-2002] James Heinrich + » Added support for Quicktime. + New file: getid3.quicktime.php + » Added support for AAC files, both ADTS and ADIF header formats. + ADIF format is a pain because it's very similar to standard MP3 + header format, and it's hard to distinguish between the two. I + have tried to make the detection accurate, but I have a limited + number of AAC test files to play with so if you have an AAC file + that gets detected as MP3/MP2 (or vice-versa), please send me + the details via email at infoØgetid3Øorg + ADTS format is very slow to parse because to get the bitrate of + VBR files the whole file has to be stepped through frame by + frame (getID3() scans up to the first 1000 frames and assumes + that to be close enough). + Note: I would suggest commenting out support for AAC (see top of + GetAllMP3info() function in getid3.php) unless you need it. + (thanks jfaulØgmx*de for the idea and sample Delphi source code) + New file: getid3.aac.php + » Added bitrate distribution analysis option for MP3 VBR files. A + new boolean parameter for getOnlyMPEGaudioInfo() enabled this + feature which steps through the MP3 file frame by frame and + counts how many frames of each bitrate exist. This information + is returned in ['mpeg']['audio']['bitrate_distribution'] + Caution: this feature is very inefficient for large files and + takes a very long time and does lots of disk I/O. Use with care. + ¤ Changed layout of allowedFormats in GetAllMP3info() function in + getid3.php to allow easy removal of support for any of the + supported format. As stated above, I recommend commenting out + AAC unless needed. + ¤ Added ['flac']['compressed_audio_bytes'], + ['flac']['uncompressed_audio_bytes'], and + ['flac']['compression_ratio'] + ¤ Replaced FXPT2DOT30toFloat() function with FixedPoint2_30() + * Bugfix: getid3.mpc.php was slightly miscalculating the number of + samples, therefore also bitrate and playtime + (thanks ahØartemis*dk for the fix) + * Bugfix: MonkeyCompressionLevelNameLookup() didn't know about + 'insane' compression (thanks ahØartemis*dk for the fix) + * Bugfix: MonkeySamplesPerFrame() was incorrect for MAC v3.95+ + (thanks ahØartemis*dk for the fix) + * Bugfix: getid3.check.php wasn't processing the assumeFormat + directive when (register_globals == off) + * Bugfix: detecting of synch pattern for MP3 files with invalid + data at the beginning wasn't always correct, also meant possible + incorrect bitrate/duration/etc info for such corrupt files. + getid3.functions.php now includes a replacement utf8_decode() + function for those PHP installations that are not configured + with the --with-xml option. (thanks stephaneØtekartists*com) + + +1.5.3: [September-30-2002] James Heinrich + » Added support for VQF. (thanks mtØmansonthomas*com for the idea) + New file: getid3.vqf.php + » Added support for FLAC. Comments, if present, are returned under + ['ogg'] because they follow the Ogg Vorbis structure standard. + New file: getid3.flac.php + ¤ OS/2-format bitmaps are now correctly interpreted. The format of + the bitmap is now returned in ['bmp']['type_os'] and + ['bmp']['type_version']. OS/2 bitmaps can be v1 or v2, Windows + can be v1, v4 or v5 + + +1.5.2: [September-25-2002] James Heinrich + » Support for RealMedia (audio & video) added + Note: only tested on G2 and v5 audio and video files - if anyone + has older and/or newer sample files, please test it and/or send + me the sample files. + (thanks stephaneØtekartists*com for idea) + New file: getid3.real.php + » Support for BMP added. Palette and pixel data can optionally be + extracted as well - this is slow and generally unneccesary, but + the option is there if you need it. Also includes PlotBMP() + which will take the extracted pixel data and output it as a true + color PNG. This function requires GD v2.0+ + Note: Untested on 16-bit and 32-bit BMPs because I couldn't find + any sample files - if you know of a program that can create such + files, please email infoØgetid3Øorg + Note: Support for RGB (uncompressed), RLE8 and RLE4 is included + and tested. BITFIELDS support is also included for 16- & 32-bit + formats, but it's untested, so if anybody has any test files + please send them to infoØgetid3Øorg + Note: Support currently only for Windows-format BMPs, and trying + to parse an OS/2-format bitmap leads to unpredictable/invalid + results. + New file: getid3.bmp.php + » PNG now fully parsed, including all information chunks + New file: getid3.png.php + ¤ Support for GIF/JPG/PNG moved to seperate files and expanded, + including standard ['resolution_x'] and ['resolution_y'] as well + as more thorough parsing of header information + New file: getid3.gif.php + New file: getid3.jpg.php + table_var_dump() simplified and now outputs {-style character + entities for characters outside the normal alphanumeric range + CleanOggCommentName() changed to a regular expression + (thanks chris-getid3Øbolt*cx for rewriting the function) + + +1.5.1: [September-20-2002] James Heinrich + » Added support for MPEGplus/Musepack SV7. ['fileformat'] is 'SV7' + for version 7 files (versions 4, 5 ,6 and 8 are not supported + yet, but will be of ['fileformat'] SV4, SV5, SV6 and SV8) when + they are supported (thanks Christian Fritz for the idea) + New file: getid3.mpc.php + ¤ ['bitrate_audio'], ['bitrate_video'], ['bitrate_mode'], + ['channels'], ['resolution_x'], and ['resolution_y'] keys added + for all appropriate formats + ¤ Ogg files with a COVERART comment now save and display the + attached image the same way as is done with ID3v2 APICs + ¤ ['ogg']['comments'][n]['data'] and + ['ogg']['comments'][n]['dataoffset'] is now returned for all + comments. ['ogg']['comments'][n]['data'] is only useful if + the field is supposed to contain binary data. It is a + base64_decode()'d version of ['value']. + ['ogg']['comments'][n]['dataoffset'] is the byte offset in the + file at which the 'COMMENTNAME=value string' starts, not the + start of just 'value' + ¤ ['ogg']['comments'][n]['image_mime'] is now returned if + ['ogg']['comments'][n]['data'] contains valid image data. + ¤ More than 3 Ogg pages may now be read in, if the comment data + is longer than 1 page (usually about 4kB) + ¤ ['fileformat'] is now 'mp2' rather than 'mp3' if it's MPEG-1, + Layer-II audio + ¤ ASF bitrates now calculated even if stream_bitrate_properties + object not present + ¤ ['asf']['stream_properties_object'] is now a numeric-key array + with one entry for each stream - the key being the stream number + ¤ ['replay_gain'] is returned for all audio formats that support + it (MP3-LAME, ID3v2, Ogg) (thanks Christian Fritz for the idea) + ¤ ['mpeg']['audio']['LAME']['RGAD']['radio_replay_gain'] is now + ['mpeg']['audio']['LAME']['RGAD']['radio'] (same for audiophile) + ¤ ASF/WMA files now use WM/Track to get track number from if + WM/TrackNumber is not available (thanks stephaneØtekartists*com) + ¤ ASF/WMV files now returns ['year'] and ['asf']['year'] + ¤ ASV/WMV files now use ['content_description']['description'] for + the ['comment'] field (thanks stephaneØtekartists*com) + ¤ ['track'] is now always returned as an integer + * Bugfix: Ogg comments that are larger than one data page (usually + about 4kB) are now correctly parsed (thanks Christian Fritz) + * Bugfix: Ogg comment data is now UTF8-decoded + * Bugfix: Ogg comment writing now UTF8-encodes the data + * Bugfix: playtime for ASF files was off by (usually + between 3 and 12 seconds) + * Bugfix: ['asf']['stream_properties_objects']['flags'] data was + possibly incorrect + * Bugfix: ASF Padding Object was overwriting + Stream Bitrate Properties Object data (now returned correctly in + ['asf']['padding_object'] + * Bugfix: ASF Marker Object Reserved_2 field was incorrect + * Bugfix: ASF Bitrate Mutual Exclusion Object had incorrect stream + numbers + Warning displayed if incorrectly-formatted Ogg comment is present + (known to be an issue with CDex v1.40, but fixed by v1.50b7) + (thanks Christian Fritz) + Ogg comment writing now checks for valid comment names + Added bitrate column in getid3.check.php, and added some formatting + (font, colour) + Performance tweaks using bitwise math instead of binary string + operations + + +1.5.0: [September-18-2002] James Heinrich + » Ogg comment writing support added. getid3.write.php has been + updated to allow for writing comment tags to both MP3 and Ogg. + Big thanks to Chris Bolt for writing the + OggWrite() function and offering it for inclusion in getID3() + New file: getid3.ogginfo.php + » Support for Monkey's Audio and APE tag added. + (thanks Christian Fritz for the idea) + New file: getid3.ape.php + ['fileformat'] now returns 'mac' for Monkey's Audio files, or + 'ape' for files with an APE tag (Monkey's Audio or other format) + » getid3.thumbnail.php has been removed from the distribution and + the table_var_dump() function now outputs APICs as seperate + files in the same directory as the analyzed file. This should + make the image-displaying more reliable as well as reduce + complexity. The naming convention for the images is + filename.ext.[byte offset of APIC data].[jpg|gif|png] + If anybody still has any problems with corrupted images please + let me know at infoØgetid3Øorg + » Support for extended Xing/LAME tag + (see http://users.belgacom.net/gc247244/extra/tag.html) + Data is returned in ['mpeg']['audio']['LAME'] + ¤ ['ogg']['tracknumber'] has been renamed to ['ogg']['track'] and + ['track'] is now returned in the root of the array + ¤ ['ogg']['pageheader'][n]['flag'] has been renamed to + ['ogg']['pageheader'][n]['flags'] and the unprocessed flag byte + is available in ['ogg']['pageheader'][n]['flags_raw'] + ¤ ['frequency'] is now returned for WAVE files in the root of the + array (thanks danielØelectroteque*org) + ¤ ASF files now return codec, bitrate, resolution, etc information + under ['asf']['video_media'] or ['asf']['audio_media'] + * Bugfix: RVA2 and EQU2 writing in getid3.putid3.php were + incorrectly writing Volume Adjustment field + * Bugfix: EQU2 in getid3.frames.php was reading Volume Adjustment + as unsigned integer instead of signed integer + * Bugfix: handling of remote files over HTTP & FTP was broken + (thanks Vince) + * Bugfix: incorrect handling of some ASF packets + ASF/Windows Media format now more fully parsed, including Index + Objects + Added several new fourCC video codecs + + +1.4.3: [September-15-2002] James Heinrich + » Now parses ASF / WMV / WMA files + ¤ New file: getid3.asf.php + * Bugfix: RoughTranslateUnicodeToASCII() would return nothing + if didn't find a terminator it was expecting + Added FILETIMEtoUNIXtime() function (for converting 64-bit + Microsoft FILETIME timestamps, used in ASF files and elsewhere, + to UNIX Epoch timestamps) + Added GUIDtoBytestring() and BytestringToGUID() functions + + +1.4.2: [September-12-2002] James Heinrich + » getID3() now requires PHP v4.1.0 or higher because it now is + designed to work with register_globals = off and the new auto- + globals ($_GET, $_SERVER, etc). + * Bugfix: VBR MP3 files with Fraunhofer-style VBR header were not + being correctly detected in most cases + (thanks dkushnerØoddcast*com and mikeØftl*com for sample files) + * Bugfix: IsValidTextEncoding() was broken + * Bugfix: Add stripslashes($EditorFilename) to getid3.write.php + (writing was broken for files with ' or " in the filename) + (thanks mikeØftl*com and kthejoker) + * Bugfix: If there is garbage data between a valid VBR header + frame and a sequence of valid MPEG-audio frames the VBR data is + no longer discarded. (thanks to mikeØftl*com for sample + Fraunhofer-style VBR file produced with MusicMatch v7.2) + ¤ Changed variable system to work with (register_globals = off) + ¤ Moved relevant code into seperate PlaytimeString() function + ¤ Added nl2br() to table_var_dump() for cleaner output + ¤ Now returns the following keys from Fraunhofer-VBR files: + ['VBR_seek_offsets'], ['VBR_seek_offsets_stride'], + ['VBR_offsets_relative'] and ['VBR_offsets_absolute'] + ¤ Added ID3v1matchesID3v2() function and implemented in + getid3.check.php (thanks to "Guest" in the forums for the idea) + Changed amount of data read in getid3.getimagesize.php from 10kB + to entire file. (thanks mikeØftl*com) + Wrapped function_exists() checks around function definitions in + getid3.functions.php + Fixed a lot of E_WARNING and E_NOTICE situations, especially in + ID3-writing code (getid3.putid3.php, etc) + Added checks to make sure all needed data is available for writing + ID3v2 tags + + +1.4.1b5: [May-30-2002] James Heinrich + * Bugfix: Unsynchronise() was broken, now fixed + (thanks mikeØftl*com) + * Bugfix: GenerateID3v2Tag() now correctly uses non-synchsafe + integers for frame size descriptors in ID3v2.3 and ID3v2.2 + (thanks mikeØftl*com) + ¤ Added ['artist'], ['title'], etc keys to root of returned + array to provide a common place to access any returned info + from any file type. Currently gets info from ID3v1, ID3v2, + Ogg, and RIFF/WAVE. Possible returned keys are: + title, artist, album, year, genre, comment, track + ¤ Modified LookupGenre() function to search for either genre based + on numeric ID, or now reverse lookup as well + ¤ Added ['artist'], ['title'], etc keys to ['RIFF'] information + if info tags are present + Added functionality to attach a picture to the ID3v2 tag in + getid3.write.php + Sorted genres into alphabetical order (special 3 at end of list) + in getid3.write.php + Changed the comment-edit field in getid3.write.php to a multi-line +
'.htmlentities(print_r($ThisFileInfo['comments'], true), ENT_SUBSTITUTE).'
'; + +/* if you want to see ALL the output, uncomment this line: */ +//echo '
'.htmlentities(print_r($ThisFileInfo, true), ENT_SUBSTITUTE).'
'; + + diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.browse.php b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.browse.php new file mode 100644 index 00000000..ea735c32 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.browse.php @@ -0,0 +1,622 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// /demo/demo.browse.php - part of getID3() // +// Sample script for browsing/scanning files and displaying // +// information returned by getID3() // +// see readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__)); + + +define('GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK', false); // if enabled, shows "edit" links (to /demos/demo.write.php) to allow ID3/APE/etc tag editing on applicable file types +define('GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK', false); // if enabled, shows "delete" links to delete files from the browse interface +define('GETID3_DEMO_BROWSE_ALLOW_MD5_LINK', false); // if enabled, shows "enable" link for MD5 hashes for file/data/source + +///////////////////////////////////////////////////////////////// +// die if magic_quotes_runtime or magic_quotes_gpc are set +if (version_compare(PHP_VERSION, '7.4.0', '<')) { // get_magic_quotes_runtime / get_magic_quotes_gpc functions give deprecation warnings in PHP v7.4 + if (function_exists('get_magic_quotes_runtime') && get_magic_quotes_runtime()) { + die('magic_quotes_runtime is enabled, getID3 will not run.'); + } + if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { + die('magic_quotes_gpc is enabled, getID3 will not run.'); + } +} +///////////////////////////////////////////////////////////////// + +require_once('../getid3/getid3.php'); + +$PageEncoding = 'UTF-8'; +$FileSystemEncoding = ((GETID3_OS_ISWINDOWS && version_compare(PHP_VERSION, '7.1.0', '<')) ? 'Windows-1252' : 'UTF-8'); +$writescriptfilename = 'demo.write.php'; + +// Needed for windows only. Leave commented-out to auto-detect, only define here if auto-detection does not work properly +//define('GETID3_HELPERAPPSDIR', 'C:\\helperapps\\'); + +// Initialize getID3 engine +$getID3 = new getID3; +$getID3->setOption(array( + 'encoding' => $PageEncoding, + 'options_audiovideo_quicktime_ReturnAtomData' => true, +)); + +$getID3checkColor_Head = 'CCCCDD'; +$getID3checkColor_DirectoryLight = 'FFCCCC'; +$getID3checkColor_DirectoryDark = 'EEBBBB'; +$getID3checkColor_FileLight = 'EEEEEE'; +$getID3checkColor_FileDark = 'DDDDDD'; +$getID3checkColor_UnknownLight = 'CCCCFF'; +$getID3checkColor_UnknownDark = 'BBBBDD'; + + +/////////////////////////////////////////////////////////////////////////////// + + +header('Content-Type: text/html; charset='.$PageEncoding); +echo ''; +echo ''; +echo 'getID3() - /demo/demo.browse.php (sample script)'; +echo ''; +echo ''; +echo ''; + +if (isset($_REQUEST['deletefile']) && GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK) { + if (file_exists($_REQUEST['deletefile'])) { + if (unlink($_REQUEST['deletefile'])) { + $deletefilemessage = 'Successfully deleted '.$_REQUEST['deletefile']; + } else { + $deletefilemessage = 'FAILED to delete '.$_REQUEST['deletefile'].' - error deleting file'; + } + } else { + $deletefilemessage = 'FAILED to delete '.$_REQUEST['deletefile'].' - file does not exist'; + } + if (isset($_REQUEST['noalert'])) { + echo ''.htmlentities($deletefilemessage, ENT_QUOTES).'
'; + } else { + echo ''; + } +} + + +if (isset($_REQUEST['filename'])) { + + if (!file_exists($_REQUEST['filename']) || !is_file($_REQUEST['filename'])) { + die(getid3_lib::iconv_fallback($FileSystemEncoding, $PageEncoding, $_REQUEST['filename'].' does not exist')); + } + $starttime = microtime(true); + + //$getID3->setOption(array( + // 'option_md5_data' => $AutoGetHashes, + // 'option_sha1_data' => $AutoGetHashes, + //)); + $ThisFileInfo = $getID3->analyze($_REQUEST['filename']); + $AutoGetHashes = (bool) (isset($ThisFileInfo['filesize']) && ($ThisFileInfo['filesize'] > 0) && ($ThisFileInfo['filesize'] < (50 * 1048576))); // auto-get md5_data, md5_file, sha1_data, sha1_file if filesize < 50MB, and NOT zero (which may indicate a file>2GB) + $AutoGetHashes = ($AutoGetHashes && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK); + if ($AutoGetHashes) { + $ThisFileInfo['md5_file'] = md5_file($_REQUEST['filename']); + $ThisFileInfo['sha1_file'] = sha1_file($_REQUEST['filename']); + } + + + $getID3->CopyTagsToComments($ThisFileInfo); + + $listdirectory = dirname($_REQUEST['filename']); + $listdirectory = realpath($listdirectory); // get rid of /../../ references + + if (GETID3_OS_ISWINDOWS) { + // this mostly just gives a consistant look to Windows and *nix filesystems + // (windows uses \ as directory seperator, *nix uses /) + $listdirectory = str_replace(DIRECTORY_SEPARATOR, '/', $listdirectory.'/'); + } + + if (preg_match('#^(ht|f)tp://#', $_REQUEST['filename'])) { + echo 'Cannot browse remote filesystems
'; + } else { + echo 'Browse: '.getid3_lib::iconv_fallback($FileSystemEncoding, $PageEncoding, $listdirectory).'
'; + } + + getid3_lib::ksort_recursive($ThisFileInfo); + echo table_var_dump($ThisFileInfo, false, $PageEncoding); + $endtime = microtime(true); + echo 'File parsed in '.number_format($endtime - $starttime, 3).' seconds.
'; + +} else { + + $listdirectory = (isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.'); + $listdirectory = getid3_lib::truepath($listdirectory); // get rid of /../../ references + $currentfulldir = str_replace(DIRECTORY_SEPARATOR, '/', $listdirectory).'/'; // this mostly just gives a consistant look to Windows and *nix filesystems: (Windows uses \ as directory seperator, *nix uses /) + + ob_start(); + if ($handle = opendir($listdirectory)) { + + ob_end_clean(); + echo str_repeat(' ', 300); // IE buffers the first 300 or so chars, making this progressive display useless - fill the buffer with spaces + echo 'Processing'; + + $starttime = microtime(true); + + $TotalScannedUnknownFiles = 0; + $TotalScannedKnownFiles = 0; + $TotalScannedPlaytimeFiles = 0; + $TotalScannedBitrateFiles = 0; + $TotalScannedFilesize = 0; + $TotalScannedPlaytime = 0; + $TotalScannedBitrate = 0; + $FilesWithWarnings = 0; + $FilesWithErrors = 0; + + while ($file = readdir($handle)) { + $currentfilename = $listdirectory.'/'.$file; + set_time_limit(30); // allocate another 30 seconds to process this file - should go much quicker than this unless intense processing (like bitrate histogram analysis) is enabled + echo ' .'; // progress indicator dot + flush(); // make sure the dot is shown, otherwise it's useless + switch ($file) { + case '..': + $ParentDir = realpath($file.'/..').'/'; + if (GETID3_OS_ISWINDOWS) { + $ParentDir = str_replace(DIRECTORY_SEPARATOR, '/', $ParentDir); + } + $DirectoryContents[$currentfulldir]['dir'][$file]['filename'] = $ParentDir; + continue 2; + break; + + case '.': + // ignore + continue 2; + break; + } + // symbolic-link-resolution enhancements by davidbullock×´ech-center*com + $TargetObject = realpath($currentfilename); // Find actual file path, resolve if it's a symbolic link + $TargetObjectType = filetype($TargetObject); // Check file type without examining extension + + if ($TargetObjectType == 'dir') { + + $DirectoryContents[$currentfulldir]['dir'][$file]['filename'] = $file; + + } elseif ($TargetObjectType == 'file') { + + $getID3->setOption(array('option_md5_data' => (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK))); + $fileinformation = $getID3->analyze($currentfilename); + + $getID3->CopyTagsToComments($fileinformation); + + $TotalScannedFilesize += (isset($fileinformation['filesize']) ? $fileinformation['filesize'] : 0); + + if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) { + $fileinformation['md5_file'] = md5_file($currentfilename); + } + + if (!empty($fileinformation['fileformat'])) { + $DirectoryContents[$currentfulldir]['known'][$file] = $fileinformation; + $TotalScannedPlaytime += (isset($fileinformation['playtime_seconds']) ? $fileinformation['playtime_seconds'] : 0); + $TotalScannedBitrate += (isset($fileinformation['bitrate']) ? $fileinformation['bitrate'] : 0); + $TotalScannedKnownFiles++; + } else { + $DirectoryContents[$currentfulldir]['other'][$file] = $fileinformation; + $DirectoryContents[$currentfulldir]['other'][$file]['playtime_string'] = '-'; + $TotalScannedUnknownFiles++; + } + if (isset($fileinformation['playtime_seconds']) && ($fileinformation['playtime_seconds'] > 0)) { + $TotalScannedPlaytimeFiles++; + } + if (isset($fileinformation['bitrate']) && ($fileinformation['bitrate'] > 0)) { + $TotalScannedBitrateFiles++; + } + + } else { + + echo '
Unknown filesystem entry: "'.htmlentities($currentfilename, ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'"
'; + + } + } + $endtime = microtime(true); + closedir($handle); + echo 'done
'; + echo 'Directory scanned in '.number_format($endtime - $starttime, 2).' seconds.
'; + flush(); + + $columnsintable = 14; + echo ''; + + echo ''; + $rowcounter = 0; + foreach ($DirectoryContents as $dirname => $val) { + if (isset($DirectoryContents[$dirname]['dir']) && is_array($DirectoryContents[$dirname]['dir'])) { + uksort($DirectoryContents[$dirname]['dir'], 'MoreNaturalSort'); + foreach ($DirectoryContents[$dirname]['dir'] as $filename => $fileinfo) { + echo ''; + if ($filename == '..') { + echo ''; + } else { + $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $FileSystemEncoding); // do filesystems always return filenames in ISO-8859-1? + $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename)); + echo ''; + } + echo ''; + } + } + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) { + echo ''; + echo ''; + echo ''; + } else { + echo ''; + } + echo ''; + echo ''; + echo (GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK ? '' : ''); + echo (GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK ? '' : ''); + echo ''; + + if (isset($DirectoryContents[$dirname]['known']) && is_array($DirectoryContents[$dirname]['known'])) { + uksort($DirectoryContents[$dirname]['known'], 'MoreNaturalSort'); + foreach ($DirectoryContents[$dirname]['known'] as $filename => $fileinfo) { + echo ''; + $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $FileSystemEncoding); // do filesystems always return filenames in ISO-8859-1? + $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename)); + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + if (isset($_REQUEST['ShowMD5']) && GETID3_DEMO_BROWSE_ALLOW_MD5_LINK) { + echo ''; + echo ''; + echo ''; + } else { + echo ''; + } + echo ''; + + echo ''; + + if (GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK) { + echo ''; + } + if (GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK) { + echo ''; + } + echo ''; + } + } + + if (isset($DirectoryContents[$dirname]['other']) && is_array($DirectoryContents[$dirname]['other'])) { + uksort($DirectoryContents[$dirname]['other'], 'MoreNaturalSort'); + foreach ($DirectoryContents[$dirname]['other'] as $filename => $fileinfo) { + echo ''; + $escaped_filename = htmlentities($filename, ENT_SUBSTITUTE, $PageEncoding); + $escaped_filename = ($escaped_filename ? $escaped_filename : rawurlencode($filename)); + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; // Artist + echo ''; // Title + echo ''; // MD5_data + echo ''; // Tags + + //echo ''; // Warning/Error + echo ''; + + if (GETID3_DEMO_BROWSE_ALLOW_EDIT_LINK) { + echo ''; // Edit + } + if (GETID3_DEMO_BROWSE_ALLOW_DELETE_LINK) { + echo ''; + } + echo ''; + } + } + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
Files in '.getid3_lib::iconv_fallback($FileSystemEncoding, $PageEncoding, $currentfulldir).'
'; + echo '
'; + echo 'Parent directory: '; + echo ' '; + echo '
'.$escaped_filename.'
FilenameFile SizeFormatPlaytimeBitrateArtistTitleMD5 File (File) (disable)MD5 Data (File) (disable)MD5 Data (Source) (disable)MD5 Data'.(GETID3_DEMO_BROWSE_ALLOW_MD5_LINK ?' (enable)' : '').'TagsErrors & WarningsEditDelete
'.$escaped_filename.' '.number_format($fileinfo['filesize']).' '.NiceDisplayFiletypeFormat($fileinfo).' '.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '-').' '.(isset($fileinfo['bitrate']) ? BitrateText($fileinfo['bitrate'] / 1000, 0, ((isset($fileinfo['audio']['bitrate_mode']) && ($fileinfo['audio']['bitrate_mode'] == 'vbr')) ? true : false)) : '-').' '.(isset($fileinfo['comments_html']['artist']) ? implode('
', $fileinfo['comments_html']['artist']) : ((isset($fileinfo['video']['resolution_x']) && isset($fileinfo['video']['resolution_y'])) ? $fileinfo['video']['resolution_x'].'x'.$fileinfo['video']['resolution_y'] : '')).'
 '.(isset($fileinfo['comments_html']['title']) ? implode('
', $fileinfo['comments_html']['title']) : (isset($fileinfo['video']['frame_rate']) ? number_format($fileinfo['video']['frame_rate'], 3).'fps' : '')).'
'.(isset($fileinfo['md5_file']) ? $fileinfo['md5_file'] : ' ').''.(isset($fileinfo['md5_data']) ? $fileinfo['md5_data'] : ' ').''.(isset($fileinfo['md5_data_source']) ? $fileinfo['md5_data_source'] : ' ').'- '.(!empty($fileinfo['tags']) ? implode(', ', array_keys($fileinfo['tags'])) : '').' '; + if (!empty($fileinfo['warning'])) { + $FilesWithWarnings++; + echo 'warning
'; + } + if (!empty($fileinfo['error'])) { + $FilesWithErrors++; + echo 'error
'; + } + echo '
 '; + $fileinfo['fileformat'] = (isset($fileinfo['fileformat']) ? $fileinfo['fileformat'] : ''); + switch ($fileinfo['fileformat']) { + case 'mp3': + case 'mp2': + case 'mp1': + case 'flac': + case 'mpc': + case 'real': + echo 'edit tags'; + break; + case 'ogg': + if (isset($fileinfo['audio']['dataformat']) && ($fileinfo['audio']['dataformat'] == 'vorbis')) { + echo 'edit tags'; + } + break; + default: + break; + } + echo ' delete
'.$escaped_filename.' '.(isset($fileinfo['filesize']) ? number_format($fileinfo['filesize']) : '-').' '.NiceDisplayFiletypeFormat($fileinfo).' '.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '-').' '.(isset($fileinfo['bitrate']) ? BitrateText($fileinfo['bitrate'] / 1000) : '-').'      '; + if (!empty($fileinfo['warning'])) { + $FilesWithWarnings++; + echo 'warning
'; + } + if (!empty($fileinfo['error'])) { + if ($fileinfo['error'][0] != 'unable to determine file format') { + $FilesWithErrors++; + echo 'error
'; + } + } + echo '
  delete
Average:'.number_format($TotalScannedFilesize / max($TotalScannedKnownFiles, 1)).' '.getid3_lib::PlaytimeString($TotalScannedPlaytime / max($TotalScannedPlaytimeFiles, 1)).''.BitrateText(round(($TotalScannedBitrate / 1000) / max($TotalScannedBitrateFiles, 1))).'
Identified Files:'.number_format($TotalScannedKnownFiles).'   Errors:'.number_format($FilesWithErrors).'
Unknown Files:'.number_format($TotalScannedUnknownFiles).'   Warnings:'.number_format($FilesWithWarnings).'
'; + echo '
Total:'.number_format($TotalScannedFilesize).' '.getid3_lib::PlaytimeString($TotalScannedPlaytime).' 
'; + } else { + $errormessage = ob_get_contents(); + ob_end_clean(); + echo 'ERROR: Could not open directory: '.htmlentities($currentfulldir, ENT_QUOTES | ENT_SUBSTITUTE, $PageEncoding).'
'; + //echo $errormessage.'
'; // uncomment for debugging + } +} +echo PoweredBygetID3().'
'; +echo ''; + + +///////////////////////////////////////////////////////////////// + + +function RemoveAccents($string) { + // Revised version by markstewardרotmail*com + // Again revised by James Heinrich (19-June-2006) + return strtr( + strtr( + $string, + "\x8A\x8E\x9A\x9E\x9F\xC0\xC1\xC2\xC3\xC4\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFF", + 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy' + ), + array( + "\xDE" => 'TH', + "\xFE" => 'th', + "\xD0" => 'DH', + "\xF0" => 'dh', + "\xDF" => 'ss', + "\x8C" => 'OE', + "\x9C" => 'oe', + "\xC6" => 'AE', + "\xE6" => 'ae', + "\xB5" => 'u' + ) + ); +} + + +function BitrateColor($bitrate, $BitrateMaxScale=768) { + // $BitrateMaxScale is bitrate of maximum-quality color (bright green) + // below this is gradient, above is solid green + + $bitrate *= (256 / $BitrateMaxScale); // scale from 1-[768]kbps to 1-256 + $bitrate = round(min(max($bitrate, 1), 256)); + $bitrate--; // scale from 1-256kbps to 0-255kbps + + $Rcomponent = max(255 - ($bitrate * 2), 0); + $Gcomponent = max(($bitrate * 2) - 255, 0); + if ($bitrate > 127) { + $Bcomponent = max((255 - $bitrate) * 2, 0); + } else { + $Bcomponent = max($bitrate * 2, 0); + } + return str_pad(dechex($Rcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Gcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Bcomponent), 2, '0', STR_PAD_LEFT); +} + +function BitrateText($bitrate, $decimals=0, $vbr=false) { + return ''.number_format($bitrate, $decimals).' kbps'; +} + +function string_var_dump($variable) { + if (version_compare(PHP_VERSION, '4.3.0', '>=')) { + return print_r($variable, true); + } + ob_start(); + var_dump($variable); + $dumpedvariable = ob_get_contents(); + ob_end_clean(); + return $dumpedvariable; +} + +function table_var_dump($variable, $wrap_in_td=false, $encoding='') { + global $FileSystemEncoding; + $encoding = ($encoding ? $encoding : $FileSystemEncoding); + $returnstring = ''; + switch (gettype($variable)) { + case 'array': + $returnstring .= ($wrap_in_td ? '' : ''); + $returnstring .= ''; + foreach ($variable as $key => $value) { + $returnstring .= ''."\n"; + $returnstring .= ''."\n".''."\n"; + } else { + $returnstring .= ''."\n".''."\n"; + } + } else { + $returnstring .= ''."\n".table_var_dump($value, true, $encoding).''."\n"; + } + } + $returnstring .= '
'.str_replace("\x00", ' ', $key).''.gettype($value); + if (is_array($value)) { + $returnstring .= ' ('.count($value).')'; + } elseif (is_string($value)) { + $returnstring .= ' ('.strlen($value).')'; + } + //if (($key == 'data') && isset($variable['image_mime']) && isset($variable['dataoffset'])) { + if (($key == 'data') && isset($variable['image_mime'])) { + $imageinfo = array(); + if ($imagechunkcheck = getid3_lib::GetDataImageSize($value, $imageinfo)) { + $returnstring .= '
invalid image data
'."\n"; + $returnstring .= ($wrap_in_td ? ''."\n" : ''); + break; + + case 'boolean': + $returnstring .= ($wrap_in_td ? '' : '').($variable ? 'TRUE' : 'FALSE').($wrap_in_td ? ''."\n" : ''); + break; + + case 'integer': + $returnstring .= ($wrap_in_td ? '' : '').$variable.($wrap_in_td ? ''."\n" : ''); + break; + + case 'double': + case 'float': + $returnstring .= ($wrap_in_td ? '' : '').$variable.($wrap_in_td ? ''."\n" : ''); + break; + + case 'object': + case 'null': + $returnstring .= ($wrap_in_td ? '' : '').string_var_dump($variable).($wrap_in_td ? ''."\n" : ''); + break; + + case 'string': + $returnstring = htmlentities($variable, ENT_QUOTES | ENT_SUBSTITUTE, $encoding); + $returnstring = ($wrap_in_td ? '' : '').nl2br($returnstring).($wrap_in_td ? ''."\n" : ''); + break; + + default: + $imageinfo = array(); + if (($imagechunkcheck = getid3_lib::GetDataImageSize($variable, $imageinfo)) && ($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) { + $returnstring .= ($wrap_in_td ? '' : ''); + $returnstring .= ''; + $returnstring .= ''."\n"; + $returnstring .= ''."\n"; + $returnstring .= ''."\n"; + $returnstring .= '
type'.image_type_to_mime_type($imagechunkcheck[2]).'
width'.number_format($imagechunkcheck[0]).' px
height'.number_format($imagechunkcheck[1]).' px
size'.number_format(strlen($variable)).' bytes
'."\n"; + $returnstring .= ($wrap_in_td ? ''."\n" : ''); + } else { + $returnstring .= ($wrap_in_td ? '' : '').nl2br(htmlspecialchars(str_replace("\x00", ' ', $variable))).($wrap_in_td ? ''."\n" : ''); + } + break; + } + return $returnstring; +} + + +function NiceDisplayFiletypeFormat(&$fileinfo) { + + if (empty($fileinfo['fileformat'])) { + return '-'; + } + + $output = $fileinfo['fileformat']; + if (empty($fileinfo['video']['dataformat']) && empty($fileinfo['audio']['dataformat'])) { + return $output; // 'gif' + } + if (empty($fileinfo['video']['dataformat']) && !empty($fileinfo['audio']['dataformat'])) { + if ($fileinfo['fileformat'] == $fileinfo['audio']['dataformat']) { + return $output; // 'mp3' + } + $output .= '.'.$fileinfo['audio']['dataformat']; // 'ogg.flac' + return $output; + } + if (!empty($fileinfo['video']['dataformat']) && empty($fileinfo['audio']['dataformat'])) { + if ($fileinfo['fileformat'] == $fileinfo['video']['dataformat']) { + return $output; // 'mpeg' + } + $output .= '.'.$fileinfo['video']['dataformat']; // 'riff.avi' + return $output; + } + if ($fileinfo['video']['dataformat'] == $fileinfo['audio']['dataformat']) { + if ($fileinfo['fileformat'] == $fileinfo['video']['dataformat']) { + return $output; // 'real' + } + $output .= '.'.$fileinfo['video']['dataformat']; // any examples? + return $output; + } + $output .= '.'.$fileinfo['video']['dataformat']; + $output .= '.'.$fileinfo['audio']['dataformat']; // asf.wmv.wma + return $output; + +} + +function MoreNaturalSort($ar1, $ar2) { + if ($ar1 === $ar2) { + return 0; + } + $len1 = strlen($ar1); + $len2 = strlen($ar2); + $shortest = min($len1, $len2); + if (substr($ar1, 0, $shortest) === substr($ar2, 0, $shortest)) { + // the shorter argument is the beginning of the longer one, like "str" and "string" + if ($len1 < $len2) { + return -1; + } elseif ($len1 > $len2) { + return 1; + } + return 0; + } + $ar1 = RemoveAccents(strtolower(trim($ar1))); + $ar2 = RemoveAccents(strtolower(trim($ar2))); + $translatearray = array('\''=>'', '"'=>'', '_'=>' ', '('=>'', ')'=>'', '-'=>' ', ' '=>' ', '.'=>'', ','=>''); + foreach ($translatearray as $key => $val) { + $ar1 = str_replace($key, $val, $ar1); + $ar2 = str_replace($key, $val, $ar2); + } + + if ($ar1 < $ar2) { + return -1; + } elseif ($ar1 > $ar2) { + return 1; + } + return 0; +} + +/** + * @param string $string + * + * @return mixed + */ +function PoweredBygetID3($string='') { + global $getID3; + if (!$string) { + $string = '
Powered by getID3() v
https://www.getid3.org/

Running on PHP v'.PHP_VERSION.' ('.(8 * PHP_INT_SIZE).'-bit, '.(defined('PHP_OS_FAMILY') ? PHP_OS_FAMILY : PHP_OS).')
'; + } + return str_replace('', $getID3->version(), $string); +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.cache.dbm.php b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.cache.dbm.php new file mode 100644 index 00000000..ba1e28ec --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.cache.dbm.php @@ -0,0 +1,30 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// /demo/demo.cache.dbm.php - part of getID3() // +// Sample script demonstrating the use of the DBM caching // +// extension for getID3() // +// see readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__)); + + +require_once('../getid3/getid3.php'); +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'extension.cache.dbm.php', __FILE__, true); + +$getID3 = new getID3_cached_dbm('db3', '/zimweb/test/test.dbm', '/zimweb/test/test.lock'); + +$r = $getID3->analyze('/path/to/files/filename.mp3'); + +echo '
';
+var_dump($r);
+echo '
'; + +// uncomment to clear cache +// $getID3->clear_cache(); diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.cache.mysql.php b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.cache.mysql.php new file mode 100644 index 00000000..54246b79 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.cache.mysql.php @@ -0,0 +1,31 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// /demo/demo.cache.mysql.php - part of getID3() // +// Sample script demonstrating the use of the DBM caching // +// extension for getID3() // +// see readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__)); + + +require_once('../getid3/getid3.php'); +require_once('../getid3/getid3.lib.php'); +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'extension.cache.mysql.php', __FILE__, true); + +$getID3 = new getID3_cached_mysql('localhost', 'database', 'username', 'password'); + +$r = $getID3->analyze('/path/to/files/filename.mp3'); + +echo '
';
+var_dump($r);
+echo '
'; + +// uncomment to clear cache +//$getID3->clear_cache(); diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.dirscan.php b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.dirscan.php new file mode 100644 index 00000000..f3b87103 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.dirscan.php @@ -0,0 +1,260 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// /demo/demo.dirscan.php - part of getID3() // +// Directory Scanning and Caching CLI tool for batch media // +// file processing with getID3() // +// by Karl G. Holz // +// /// +///////////////////////////////////////////////////////////////// + +die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__)); + + +/** +* This is a directory scanning and caching cli tool for getID3(). +* +* use like so for the default sqlite3 database, which is hidden: +* +* cd +* php /demo.dirscan.php +* +* or +* +* php /demo.dirscan.php +* +* Supported Cache Types (this extension) +* +* SQL Databases: +* +* cache_type +* ------------------------------------------------------------------- +* mysql + +$cache='mysql'; +$database['host']=''; +$database['database']=''; +$database['username']=''; +$database['password']=''; +$database['table']=''; + +* sqlite3 + +$cache='sqlite3'; +$database['table']='getid3_cache'; +$database['hide']=true; + +*/ +$dir = $_SERVER['PWD']; +$media = array('mp4', 'm4v', 'mov', 'mp3', 'm4a', 'jpg', 'png', 'gif'); +$database = array(); +/** +* configure the database bellow +*/ +// sqlite3 +$cache = 'sqlite3'; +$database['table'] = 'getid3_cache'; +$database['hide'] = true; +/** + * mysql +$cache = 'mysql'; +$database['host'] = ''; +$database['database'] = ''; +$database['username'] = ''; +$database['password'] = ''; +$database['table'] = ''; +*/ + +/** +* id3 tags class file +*/ +require_once(dirname(__FILE__).'/getid3.php'); +/** +* dirscan scans all directories for files that match your selected filetypes into the cache database +* this is useful for a lot of media files +* +* +* @package dirscan +* @author Karl Holz +* +*/ + +class dirscan { + /** + * type_brace() * Might not work on Solaris and other non GNU systems * + * + * Configures a filetype list for use with glob searches, + * will match uppercase or lowercase extensions only, no mixing + * @param string $dir directory to use + * @param mixed $search cvs list of extentions or an array + * @return string or null if checks fail + */ + private function type_brace($dir, $search=array()) { + $dir = str_replace(array('///', '//'), array('/', '/'), $dir); + if (!is_dir($dir)) { + return null; + } + if (!is_array($search)) { + $e = explode(',', $search); + } elseif (count($search) < 1) { + return null; + } else { + $e = $search; + } + $ext = array(); + foreach ($e as $new) { + $ext[] = strtolower(trim($new)); + $ext[] = strtoupper(trim($new)); + } + $b = $dir.'/*.{'.implode(',', $ext).'}'; + return $b; + } + + /** + * this function will search 4 levels deep for directories + * will return null on failure + * @param string $root + * @return array return an array of dirs under root + * @todo figure out how to block tabo directories with ease + */ + private function getDirs($root) { + switch ($root) { // return null on tabo directories, add as needed -> case {dir to block }: this is not perfect yet + case '/': + case '/var': + case '/etc': + case '/home': + case '/usr': + case '/root': + case '/private/etc': + case '/private/var': + case '/etc/apache2': + case '/home': + case '/tmp': + case '/var/log': + return null; + break; + default: // scan 4 directories deep + if (!is_dir($root)) { + return null; + } + $dirs = array_merge(glob($root.'/*', GLOB_ONLYDIR), glob($root.'/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*/*/*/*', GLOB_ONLYDIR), glob($root.'/*/*/*/*/*/*/*', GLOB_ONLYDIR)); + break; + } + if (count($dirs) < 1) { + $dirs = array($root); + } + return $dirs; + } + + /** + * file_check() check the number of file that are found that match the brace search + * + * @param string $search + * @return mixed + */ + private function file_check($search) { + $t = array(); + $s = glob($search, GLOB_BRACE); + foreach ($s as $file) { + $t[] = str_replace(array('///', '//'), array('/', '/'), $file); + } + if (count($t) > 0) { + return $t; + } + return null; + } + + function getTime() { + return microtime(true); + // old method for PHP < 5 + //$a = explode(' ', microtime()); + //return (double) $a[0] + $a[1]; + } + + + /** + * + * @param string $dir + * @param mixed $match search type name extentions, can be an array or csv list + * @param string $cache caching extention, select one of sqlite3, mysql, dbm + * @param array $opt database options, + */ + function scan_files($dir, $match, $cache='sqlite3', $opt=array('table'=>'getid3_cache', 'hide'=>true)) { + $Start = self::getTime(); + switch ($cache) { // load the caching module + case 'sqlite3': + if (!class_exists('getID3_cached_sqlite3')) { + require_once(dirname(__FILE__)).'/extension.cache.sqlite3.php'; + } + $id3 = new getID3_cached_sqlite3($opt['table'], $opt['hide']); + break; + case 'mysql': + if (!class_exists('getID3_cached_mysql')) { + require_once(dirname(__FILE__)).'/extension.cache.mysql.php'; + } + $id3 = new getID3_cached_mysql($opt['host'], $opt['database'], $opt['username'], $opt['password'], $opt['table']); + break; + // I'll leave this for some one else + //case 'dbm': + // if (!class_exists('getID3_cached_dbm')) { + // require_once(dirname(__FILE__)).'/extension.cache.dbm.php'; + // } + // die(' This has not be implemented, sorry for the inconvenience'); + // break; + default: + die(' You have selected an Invalid cache type, only "sqlite3" and "mysql" are valid'."\n"); + break; + } + $count = array('dir'=>0, 'file'=>0); + $dirs = self::getDirs($dir); + if ($dirs !== null) { + foreach ($dirs as $d) { + echo ' Scanning: '.$d."\n"; + $search = self::type_brace($d, $match); + if ($search !== null) { + $files = self::file_check($search); + if ($files !== null) { + foreach ($files as $f) { + echo ' * Analyzing '.$f.' '."\n"; + $id3->analyze($f); + $count['file']++; + } + $count['dir']++; + } else { + echo 'Failed to get files '."\n"; + } + } else { + echo 'Failed to create match string '."\n"; + } + } + echo '**************************************'."\n"; + echo '* Finished Scanning your directories '."\n*\n"; + echo '* Directories '.$count['dir']."\n"; + echo '* Files '.$count['file']."\n"; + $End = self::getTime(); + $t = number_format(($End - $Start) / 60, 2); + echo '* Time taken to scan '.$dir.' '.$t.' min '."\n"; + echo '**************************************'."\n"; + } else { + echo ' failed to get directories '."\n"; + } + } +} + +if (PHP_SAPI === 'cli') { + if (count($argv) == 2) { + if (is_dir($argv[1])) { + $dir = $argv[1]; + } + if (count(explode(',', $argv[2])) > 0) { + $media = $arg[2]; + } + } + echo ' * Starting to scan directory: '.$dir."\n"; + echo ' * Using default media types: '.implode(',', $media)."\n"; + dirscan::scan_files($dir, $media, $cache, $database); +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.joinmp3.php b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.joinmp3.php new file mode 100644 index 00000000..5047d9df --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.joinmp3.php @@ -0,0 +1,137 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// /demo/demo.joinmp3.php - part of getID3() // +// Sample script for splicing two or more MP3s together into // +// one file. Does not attempt to fix VBR header frames. // +// Can also be used to extract portion from single file. // +// Note: all joined MP3s need to be the same sample rate. // +// see readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__)); + + +// sample usage: +// $FilenameOut = 'combined.mp3'; +// $FilenamesIn[] = 'first.mp3'; // filename with no start/length parameters +// $FilenamesIn[] = array('second.mp3', 0, 0); // filename with zero for start/length is the same as not specified (start = beginning, length = full duration) +// $FilenamesIn[] = array('third.mp3', 0, 10); // extract first 10 seconds of audio +// $FilenamesIn[] = array('fourth.mp3', -10, 0); // extract last 10 seconds of audio +// $FilenamesIn[] = array('fifth.mp3', 10, 0); // extract everything except first 10 seconds of audio +// $FilenamesIn[] = array('sixth.mp3', 0, -10); // extract everything except last 10 seconds of audio +// if (CombineMultipleMP3sTo($FilenameOut, $FilenamesIn)) { +// echo 'Successfully copied '.implode(' + ', $FilenamesIn).' to '.$FilenameOut; +// } else { +// echo 'Failed to copy '.implode(' + ', $FilenamesIn).' to '.$FilenameOut; +// } +// +// Could also be called like this to extract portion from single file: +// CombineMultipleMP3sTo('sample.mp3', array(array('input.mp3', 0, 30))); // extract first 30 seconds of audio + + +function CombineMultipleMP3sTo($FilenameOut, $FilenamesIn) { + + foreach ($FilenamesIn as $nextinputfilename) { + if (is_array($nextinputfilename)) { + $nextinputfilename = $nextinputfilename[0]; + } + if (!is_readable($nextinputfilename)) { + echo 'Cannot read "'.$nextinputfilename.'"
'; + return false; + } + } + if ((file_exists($FilenameOut) && !is_writeable($FilenameOut)) || (!file_exists($FilenameOut) && !is_writeable(dirname($FilenameOut)))) { + echo 'Cannot write "'.$FilenameOut.'"
'; + return false; + } + + require_once(dirname(__FILE__).'/../getid3/getid3.php'); + ob_start(); + if ($fp_output = fopen($FilenameOut, 'wb')) { + + ob_end_clean(); + // Initialize getID3 engine + $getID3 = new getID3; + foreach ($FilenamesIn as $nextinputfilename) { + $startoffset = 0; + $length_seconds = 0; + if (is_array($nextinputfilename)) { + @list($nextinputfilename, $startoffset, $length_seconds) = $nextinputfilename; + } + $CurrentFileInfo = $getID3->analyze($nextinputfilename); + if ($CurrentFileInfo['fileformat'] == 'mp3') { + + ob_start(); + if ($fp_source = fopen($nextinputfilename, 'rb')) { + + ob_end_clean(); + $CurrentOutputPosition = ftell($fp_output); + + // copy audio data from first file + $start_offset_bytes = $CurrentFileInfo['avdataoffset']; + if ($startoffset > 0) { // start X seconds from start of audio + $start_offset_bytes = $CurrentFileInfo['avdataoffset'] + round(($CurrentFileInfo['bitrate'] / 8) * $startoffset); + } elseif ($startoffset < 0) { // start X seconds from end of audio + $start_offset_bytes = $CurrentFileInfo['avdataend'] + round(($CurrentFileInfo['bitrate'] / 8) * $startoffset); + } + $start_offset_bytes = max($CurrentFileInfo['avdataoffset'], min($CurrentFileInfo['avdataend'], $start_offset_bytes)); + + $end_offset_bytes = $CurrentFileInfo['avdataend']; + if ($length_seconds > 0) { // set end offset to X seconds from start of audio + $end_offset_bytes = $start_offset_bytes + round(($CurrentFileInfo['bitrate'] / 8) * $length_seconds); + } elseif ($length_seconds < 0) { // set end offset to X seconds from end of audio + $end_offset_bytes = $CurrentFileInfo['avdataend'] + round(($CurrentFileInfo['bitrate'] / 8) * $length_seconds); + } + $end_offset_bytes = max($CurrentFileInfo['avdataoffset'], min($CurrentFileInfo['avdataend'], $end_offset_bytes)); + + if ($end_offset_bytes <= $start_offset_bytes) { + echo 'failed to copy '.$nextinputfilename.' from '.$startoffset.'-seconds start for '.$length_seconds.'-seconds length (not enough data)'; + fclose($fp_source); + fclose($fp_output); + return false; + } + + fseek($fp_source, $start_offset_bytes, SEEK_SET); + while (!feof($fp_source) && (ftell($fp_source) < $end_offset_bytes)) { + fwrite($fp_output, fread($fp_source, min(32768, $end_offset_bytes - ftell($fp_source)))); + } + fclose($fp_source); + + } else { + + $errormessage = ob_get_contents(); + ob_end_clean(); + echo 'failed to open '.$nextinputfilename.' for reading'; + fclose($fp_output); + return false; + + } + + } else { + + echo $nextinputfilename.' is not MP3 format'; + fclose($fp_output); + return false; + + } + + } + + } else { + + $errormessage = ob_get_contents(); + ob_end_clean(); + echo 'failed to open '.$FilenameOut.' for writing'; + return false; + + } + + fclose($fp_output); + return true; +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.mimeonly.php b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.mimeonly.php new file mode 100644 index 00000000..408afa1e --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.mimeonly.php @@ -0,0 +1,73 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// /demo/demo.mimeonly.php - part of getID3() // +// Sample script for scanning a single file and returning only // +// the MIME information // +// see readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__)); + + +echo ''; +echo 'getID3 demos - MIME type only'; + +if (!empty($_REQUEST['filename'])) { + + echo 'The file "'.htmlentities($_REQUEST['filename']).'" has a MIME type of "'.htmlentities(GetMIMEtype($_REQUEST['filename'])).'"'; + +} else { + + echo 'Usage: '.htmlentities($_SERVER['PHP_SELF']).'?filename=filename.ext'; + +} + + +function GetMIMEtype($filename) { + $filename = realpath($filename); + if (!file_exists($filename)) { + echo 'File does not exist: "'.htmlentities($filename).'"
'; + return ''; + } elseif (!is_readable($filename)) { + echo 'File is not readable: "'.htmlentities($filename).'"
'; + return ''; + } + + // include getID3() library (can be in a different directory if full path is specified) + require_once('../getid3/getid3.php'); + // Initialize getID3 engine + $getID3 = new getID3; + + $DeterminedMIMEtype = ''; + if ($fp = fopen($filename, 'rb')) { + $getID3->openfile($filename); + if (empty($getID3->info['error'])) { + + // ID3v2 is the only tag format that might be prepended in front of files, and it's non-trivial to skip, easier just to parse it and know where to skip to + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); + $getid3_id3v2 = new getid3_id3v2($getID3); + $getid3_id3v2->Analyze(); + + fseek($fp, $getID3->info['avdataoffset'], SEEK_SET); + $formattest = fread($fp, 16); // 16 bytes is sufficient for any format except ISO CD-image + fclose($fp); + + $DeterminedFormatInfo = $getID3->GetFileFormat($formattest); + $DeterminedMIMEtype = $DeterminedFormatInfo['mime_type']; + + } else { + echo 'Failed to getID3->openfile "'.htmlentities($filename).'"
'; + } + } else { + echo 'Failed to fopen "'.htmlentities($filename).'"
'; + } + return $DeterminedMIMEtype; +} + +echo ''; diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.mp3header.php b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.mp3header.php new file mode 100644 index 00000000..222fe40e --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.mp3header.php @@ -0,0 +1,2886 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// /demo/demo.mp3header.php - part of getID3() // +// Sample script for decoding MP3 header bytes // +// see readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__)); + + +if (!function_exists('PrintHexBytes')) { + function PrintHexBytes($string) { + $returnstring = ''; + for ($i = 0; $i < strlen($string); $i++) { + $returnstring .= str_pad(dechex(ord(substr($string, $i, 1))), 2, '0', STR_PAD_LEFT).' '; + } + return $returnstring; + } +} + +if (!function_exists('PrintTextBytes')) { + function PrintTextBytes($string) { + $returnstring = ''; + for ($i = 0; $i < strlen($string); $i++) { + if (ord(substr($string, $i, 1)) <= 31) { + $returnstring .= ' '; + } else { + $returnstring .= ' '.substr($string, $i, 1).' '; + } + } + return $returnstring; + } +} + +if (!function_exists('table_var_dump')) { + function table_var_dump($variable) { + $returnstring = ''; + switch (gettype($variable)) { + case 'array': + $returnstring .= ''; + foreach ($variable as $key => $value) { + $returnstring .= ''; + $returnstring .= ''; + } else { + $returnstring .= ''; + } + } else { + $returnstring .= ''; + } + } + $returnstring .= '
'.str_replace(chr(0), ' ', $key).''.gettype($value); + if (is_array($value)) { + $returnstring .= ' ('.count($value).')'; + } elseif (is_string($value)) { + $returnstring .= ' ('.strlen($value).')'; + } + if (($key == 'data') && isset($variable['image_mime']) && isset($variable['dataoffset'])) { + require_once(GETID3_INCLUDEPATH.'getid3.getimagesize.php'); + $imageinfo = array(); + if ($imagechunkcheck = GetDataImageSize($value, $imageinfo)) { + $DumpedImageSRC = (!empty($_REQUEST['filename']) ? $_REQUEST['filename'] : '.getid3').'.'.$variable['dataoffset'].'.'.image_type_to_mime_type($imagechunkcheck[2]); + if ($tempimagefile = fopen($DumpedImageSRC, 'wb')) { + fwrite($tempimagefile, $value); + fclose($tempimagefile); + } + $returnstring .= '
invalid image data
'.table_var_dump($value).'
'; + break; + + case 'boolean': + $returnstring .= ($variable ? 'TRUE' : 'FALSE'); + break; + + case 'integer': + case 'double': + case 'float': + $returnstring .= $variable; + break; + + case 'object': + case 'null': + $returnstring .= string_var_dump($variable); + break; + + case 'string': + $variable = str_replace(chr(0), ' ', $variable); + $varlen = strlen($variable); + for ($i = 0; $i < $varlen; $i++) { + if (preg_match('#['.chr(0x0A).chr(0x0D).' -;0-9A-Za-z]#', $variable[$i])) { + $returnstring .= $variable[$i]; + } else { + $returnstring .= '&#'.str_pad(ord($variable[$i]), 3, '0', STR_PAD_LEFT).';'; + } + } + $returnstring = nl2br($returnstring); + break; + + default: + require_once(GETID3_INCLUDEPATH.'getid3.getimagesize.php'); + $imageinfo = array(); + if (($imagechunkcheck = GetDataImageSize(substr($variable, 0, 32768), $imageinfo)) && ($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) { + $returnstring .= ''; + $returnstring .= ''; + $returnstring .= ''; + $returnstring .= ''; + $returnstring .= '
type'.image_type_to_mime_type($imagechunkcheck[2]).'
width'.number_format($imagechunkcheck[0]).' px
height'.number_format($imagechunkcheck[1]).' px
size'.number_format(strlen($variable)).' bytes
'; + } else { + $returnstring .= nl2br(htmlspecialchars(str_replace(chr(0), ' ', $variable))); + } + break; + } + return $returnstring; + } +} + +if (!function_exists('string_var_dump')) { + function string_var_dump($variable) { + if (version_compare(PHP_VERSION, '4.3.0', '>=')) { + return print_r($variable, true); + } + ob_start(); + var_dump($variable); + $dumpedvariable = ob_get_contents(); + ob_end_clean(); + return $dumpedvariable; + } +} + +if (!function_exists('fileextension')) { + function fileextension($filename, $numextensions=1) { + if (strstr($filename, '.')) { + $reversedfilename = strrev($filename); + $offset = 0; + for ($i = 0; $i < $numextensions; $i++) { + $offset = strpos($reversedfilename, '.', $offset + 1); + if ($offset === false) { + return ''; + } + } + return strrev(substr($reversedfilename, 0, $offset)); + } + return ''; + } +} + +if (!function_exists('RemoveAccents')) { + function RemoveAccents($string) { + // return strtr($string, 'ŠŒŽšœžŸ¥µÀÃÂÃÄÅÆÇÈÉÊËÌÃÃŽÃÃÑÒÓÔÕÖØÙÚÛÜÃßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ', 'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy'); + // Revised version by marksteward@hotmail.com + return strtr(strtr($string, 'ŠŽšžŸÀÃÂÃÄÅÇÈÉÊËÌÃÃŽÃÑÒÓÔÕÖØÙÚÛÜÃàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'), array('Þ' => 'TH', 'þ' => 'th', 'Ã' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'ÂŒ' => 'OE', 'Âœ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u')); + } +} + +if (!function_exists('MoreNaturalSort')) { + function MoreNaturalSort($ar1, $ar2) { + if ($ar1 === $ar2) { + return 0; + } + $len1 = strlen($ar1); + $len2 = strlen($ar2); + $shortest = min($len1, $len2); + if (substr($ar1, 0, $shortest) === substr($ar2, 0, $shortest)) { + // the shorter argument is the beginning of the longer one, like "str" and "string" + if ($len1 < $len2) { + return -1; + } elseif ($len1 > $len2) { + return 1; + } + return 0; + } + $ar1 = RemoveAccents(strtolower(trim($ar1))); + $ar2 = RemoveAccents(strtolower(trim($ar2))); + $translatearray = array('\''=>'', '"'=>'', '_'=>' ', '('=>'', ')'=>'', '-'=>' ', ' '=>' ', '.'=>'', ','=>''); + foreach ($translatearray as $key => $val) { + $ar1 = str_replace($key, $val, $ar1); + $ar2 = str_replace($key, $val, $ar2); + } + + if ($ar1 < $ar2) { + return -1; + } elseif ($ar1 > $ar2) { + return 1; + } + return 0; + } +} + +if (!function_exists('trunc')) { + function trunc($floatnumber) { + // truncates a floating-point number at the decimal point + // returns int (if possible, otherwise float) + if ($floatnumber >= 1) { + $truncatednumber = floor($floatnumber); + } elseif ($floatnumber <= -1) { + $truncatednumber = ceil($floatnumber); + } else { + $truncatednumber = 0; + } + if ($truncatednumber <= pow(2, 30)) { + $truncatednumber = (int) $truncatednumber; + } + return $truncatednumber; + } +} + +if (!function_exists('CastAsInt')) { + function CastAsInt($floatnum) { + // convert to float if not already + $floatnum = (float) $floatnum; + + // convert a float to type int, only if possible + if (trunc($floatnum) == $floatnum) { + // it's not floating point + if ($floatnum <= pow(2, 30)) { + // it's within int range + $floatnum = (int) $floatnum; + } + } + return $floatnum; + } +} + +if (!function_exists('getmicrotime')) { + function getmicrotime() { + list($usec, $sec) = explode(' ', microtime()); + return ((float) $usec + (float) $sec); + } +} + +if (!function_exists('DecimalBinary2Float')) { + function DecimalBinary2Float($binarynumerator) { + $numerator = Bin2Dec($binarynumerator); + $denominator = Bin2Dec(str_repeat('1', strlen($binarynumerator))); + return ($numerator / $denominator); + } +} + +if (!function_exists('NormalizeBinaryPoint')) { + function NormalizeBinaryPoint($binarypointnumber, $maxbits=52) { + // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html + if (strpos($binarypointnumber, '.') === false) { + $binarypointnumber = '0.'.$binarypointnumber; + } elseif ($binarypointnumber[0] == '.') { + $binarypointnumber = '0'.$binarypointnumber; + } + $exponent = 0; + while (($binarypointnumber[0] != '1') || (substr($binarypointnumber, 1, 1) != '.')) { + if (substr($binarypointnumber, 1, 1) == '.') { + $exponent--; + $binarypointnumber = substr($binarypointnumber, 2, 1).'.'.substr($binarypointnumber, 3); + } else { + $pointpos = strpos($binarypointnumber, '.'); + $exponent += ($pointpos - 1); + $binarypointnumber = str_replace('.', '', $binarypointnumber); + $binarypointnumber = $binarypointnumber[0].'.'.substr($binarypointnumber, 1); + } + } + $binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2, '0', STR_PAD_RIGHT); + return array('normalized'=>$binarypointnumber, 'exponent'=>(int) $exponent); + } +} + +if (!function_exists('Float2BinaryDecimal')) { + function Float2BinaryDecimal($floatvalue) { + // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html + $maxbits = 128; // to how many bits of precision should the calculations be taken? + $intpart = trunc($floatvalue); + $floatpart = abs($floatvalue - $intpart); + $pointbitstring = ''; + while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits)) { + $floatpart *= 2; + $pointbitstring .= (string) trunc($floatpart); + $floatpart -= trunc($floatpart); + } + $binarypointnumber = decbin($intpart).'.'.$pointbitstring; + return $binarypointnumber; + } +} + +if (!function_exists('Float2String')) { + function Float2String($floatvalue, $bits) { + // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html + switch ($bits) { + case 32: + $exponentbits = 8; + $fractionbits = 23; + break; + + case 64: + $exponentbits = 11; + $fractionbits = 52; + break; + + default: + return false; + break; + } + if ($floatvalue >= 0) { + $signbit = '0'; + } else { + $signbit = '1'; + } + $normalizedbinary = NormalizeBinaryPoint(Float2BinaryDecimal($floatvalue), $fractionbits); + $biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary['exponent']; // (127 or 1023) +/- exponent + $exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits, '0', STR_PAD_LEFT); + $fractionbitstring = str_pad(substr($normalizedbinary['normalized'], 2), $fractionbits, '0', STR_PAD_RIGHT); + + return BigEndian2String(Bin2Dec($signbit.$exponentbitstring.$fractionbitstring), $bits % 8, false); + } +} + +if (!function_exists('LittleEndian2Float')) { + function LittleEndian2Float($byteword) { + return BigEndian2Float(strrev($byteword)); + } +} + +if (!function_exists('BigEndian2Float')) { + function BigEndian2Float($byteword) { + // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic + // http://www.psc.edu/general/software/packages/ieee/ieee.html + // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html + + $bitword = BigEndian2Bin($byteword); + $signbit = $bitword[0]; + + switch (strlen($byteword) * 8) { + case 32: + $exponentbits = 8; + $fractionbits = 23; + break; + + case 64: + $exponentbits = 11; + $fractionbits = 52; + break; + + case 80: + $exponentbits = 16; + $fractionbits = 64; + break; + + default: + return false; + break; + } + $exponentstring = substr($bitword, 1, $exponentbits - 1); + $fractionstring = substr($bitword, $exponentbits, $fractionbits); + $exponent = Bin2Dec($exponentstring); + $fraction = Bin2Dec($fractionstring); + + if (($exponentbits == 16) && ($fractionbits == 64)) { + // 80-bit + // As used in Apple AIFF for sample_rate + // A bit of a hack, but it works ;) + return pow(2, ($exponent - 16382)) * DecimalBinary2Float($fractionstring); + } + + + if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) { + // Not a Number + $floatvalue = false; + } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) { + if ($signbit == '1') { + $floatvalue = '-infinity'; + } else { + $floatvalue = '+infinity'; + } + } elseif (($exponent == 0) && ($fraction == 0)) { + if ($signbit == '1') { + $floatvalue = -0; + } else { + $floatvalue = 0; + } + $floatvalue = ($signbit ? 0 : -0); + } elseif (($exponent == 0) && ($fraction != 0)) { + // These are 'unnormalized' values + $floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * DecimalBinary2Float($fractionstring); + if ($signbit == '1') { + $floatvalue *= -1; + } + } elseif ($exponent != 0) { + $floatvalue = pow(2, ($exponent - (pow(2, $exponentbits - 1) - 1))) * (1 + DecimalBinary2Float($fractionstring)); + if ($signbit == '1') { + $floatvalue *= -1; + } + } + return (float) $floatvalue; + } +} + +if (!function_exists('BigEndian2Int')) { + function BigEndian2Int($byteword, $synchsafe=false, $signed=false) { + $intvalue = 0; + $bytewordlen = strlen($byteword); + for ($i = 0; $i < $bytewordlen; $i++) { + if ($synchsafe) { // disregard MSB, effectively 7-bit bytes + $intvalue = $intvalue | (ord($byteword[$i]) & 0x7F) << (($bytewordlen - 1 - $i) * 7); + } else { + $intvalue += ord($byteword[$i]) * pow(256, ($bytewordlen - 1 - $i)); + } + } + if ($signed && !$synchsafe) { + // synchsafe ints are not allowed to be signed + switch ($bytewordlen) { + case 1: + case 2: + case 3: + case 4: + $signmaskbit = 0x80 << (8 * ($bytewordlen - 1)); + if ($intvalue & $signmaskbit) { + $intvalue = 0 - ($intvalue & ($signmaskbit - 1)); + } + break; + + default: + die('ERROR: Cannot have signed integers larger than 32-bits in BigEndian2Int()'); + break; + } + } + return CastAsInt($intvalue); + } +} + +if (!function_exists('LittleEndian2Int')) { + function LittleEndian2Int($byteword, $signed=false) { + return BigEndian2Int(strrev($byteword), false, $signed); + } +} + +if (!function_exists('BigEndian2Bin')) { + function BigEndian2Bin($byteword) { + $binvalue = ''; + $bytewordlen = strlen($byteword); + for ($i = 0; $i < $bytewordlen; $i++) { + $binvalue .= str_pad(decbin(ord($byteword[$i])), 8, '0', STR_PAD_LEFT); + } + return $binvalue; + } +} + +if (!function_exists('BigEndian2String')) { + function BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false) { + if ($number < 0) { + return false; + } + $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF); + $intstring = ''; + if ($signed) { + if ($minbytes > 4) { + die('ERROR: Cannot have signed integers larger than 32-bits in BigEndian2String()'); + } + $number = $number & (0x80 << (8 * ($minbytes - 1))); + } + while ($number != 0) { + $quotient = ($number / ($maskbyte + 1)); + $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring; + $number = floor($quotient); + } + return str_pad($intstring, $minbytes, chr(0), STR_PAD_LEFT); + } +} + +if (!function_exists('Dec2Bin')) { + function Dec2Bin($number) { + while ($number >= 256) { + $bytes[] = (($number / 256) - (floor($number / 256))) * 256; + $number = floor($number / 256); + } + $bytes[] = $number; + $binstring = ''; + foreach ($bytes as $i => $byte) { + $binstring = (($i == count($bytes) - 1) ? decbin($byte) : str_pad(decbin($byte), 8, '0', STR_PAD_LEFT)).$binstring; + } + return $binstring; + } +} + +if (!function_exists('Bin2Dec')) { + function Bin2Dec($binstring) { + $decvalue = 0; + for ($i = 0; $i < strlen($binstring); $i++) { + $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i); + } + return CastAsInt($decvalue); + } +} + +if (!function_exists('Bin2String')) { + function Bin2String($binstring) { + // return 'hi' for input of '0110100001101001' + $string = ''; + $binstringreversed = strrev($binstring); + for ($i = 0; $i < strlen($binstringreversed); $i += 8) { + $string = chr(Bin2Dec(strrev(substr($binstringreversed, $i, 8)))).$string; + } + return $string; + } +} + +if (!function_exists('LittleEndian2String')) { + function LittleEndian2String($number, $minbytes=1, $synchsafe=false) { + $intstring = ''; + while ($number > 0) { + if ($synchsafe) { + $intstring = $intstring.chr($number & 127); + $number >>= 7; + } else { + $intstring = $intstring.chr($number & 255); + $number >>= 8; + } + } + return str_pad($intstring, $minbytes, chr(0), STR_PAD_RIGHT); + } +} + +if (!function_exists('Bool2IntString')) { + function Bool2IntString($intvalue) { + return ($intvalue ? '1' : '0'); + } +} + +if (!function_exists('IntString2Bool')) { + function IntString2Bool($char) { + if ($char == '1') { + return true; + } elseif ($char == '0') { + return false; + } + return null; + } +} + +if (!function_exists('InverseBoolean')) { + function InverseBoolean($value) { + return ($value ? false : true); + } +} + +if (!function_exists('DeUnSynchronise')) { + function DeUnSynchronise($data) { + return str_replace(chr(0xFF).chr(0x00), chr(0xFF), $data); + } +} + +if (!function_exists('Unsynchronise')) { + function Unsynchronise($data) { + // Whenever a false synchronisation is found within the tag, one zeroed + // byte is inserted after the first false synchronisation byte. The + // format of a correct sync that should be altered by ID3 encoders is as + // follows: + // %11111111 111xxxxx + // And should be replaced with: + // %11111111 00000000 111xxxxx + // This has the side effect that all $FF 00 combinations have to be + // altered, so they won't be affected by the decoding process. Therefore + // all the $FF 00 combinations have to be replaced with the $FF 00 00 + // combination during the unsynchronisation. + + $data = str_replace(chr(0xFF).chr(0x00), chr(0xFF).chr(0x00).chr(0x00), $data); + $unsyncheddata = ''; + for ($i = 0; $i < strlen($data); $i++) { + $thischar = $data[$i]; + $unsyncheddata .= $thischar; + if ($thischar == chr(255)) { + $nextchar = ord(substr($data, $i + 1, 1)); + if (($nextchar | 0xE0) == 0xE0) { + // previous byte = 11111111, this byte = 111????? + $unsyncheddata .= chr(0); + } + } + } + return $unsyncheddata; + } +} + +if (!function_exists('is_hash')) { + function is_hash($var) { + // written by dev-null@christophe.vg + // taken from http://www.php.net/manual/en/function.array-merge-recursive.php + if (is_array($var)) { + $keys = array_keys($var); + $all_num = true; + foreach ($keys as $key) { + if (is_string($key)) { + return true; + } + } + } + return false; + } +} + +if (!function_exists('array_join_merge')) { + function array_join_merge($arr1, $arr2) { + // written by dev-null@christophe.vg + // taken from http://www.php.net/manual/en/function.array-merge-recursive.php + if (is_array($arr1) && is_array($arr2)) { + // the same -> merge + $new_array = array(); + + if (is_hash($arr1) && is_hash($arr2)) { + // hashes -> merge based on keys + $keys = array_merge(array_keys($arr1), array_keys($arr2)); + foreach ($keys as $key) { + $arr1[$key] = (isset($arr1[$key]) ? $arr1[$key] : ''); + $arr2[$key] = (isset($arr2[$key]) ? $arr2[$key] : ''); + $new_array[$key] = array_join_merge($arr1[$key], $arr2[$key]); + } + } else { + // two real arrays -> merge + $new_array = array_reverse(array_unique(array_reverse(array_merge($arr1,$arr2)))); + } + return $new_array; + } else { + // not the same ... take new one if defined, else the old one stays + return $arr2 ? $arr2 : $arr1; + } + } +} + +if (!function_exists('array_merge_clobber')) { + function array_merge_clobber($array1, $array2) { + // written by kc@hireability.com + // taken from http://www.php.net/manual/en/function.array-merge-recursive.php + if (!is_array($array1) || !is_array($array2)) { + return false; + } + $newarray = $array1; + foreach ($array2 as $key => $val) { + if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { + $newarray[$key] = array_merge_clobber($newarray[$key], $val); + } else { + $newarray[$key] = $val; + } + } + return $newarray; + } +} + +if (!function_exists('array_merge_noclobber')) { + function array_merge_noclobber($array1, $array2) { + if (!is_array($array1) || !is_array($array2)) { + return false; + } + $newarray = $array1; + foreach ($array2 as $key => $val) { + if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { + $newarray[$key] = array_merge_noclobber($newarray[$key], $val); + } elseif (!isset($newarray[$key])) { + $newarray[$key] = $val; + } + } + return $newarray; + } +} + +if (!function_exists('RoughTranslateUnicodeToASCII')) { + function RoughTranslateUnicodeToASCII($rawdata, $frame_textencoding) { + // rough translation of data for application that can't handle Unicode data + + $tempstring = ''; + switch ($frame_textencoding) { + case 0: // ISO-8859-1. Terminated with $00. + $asciidata = $rawdata; + break; + + case 1: // UTF-16 encoded Unicode with BOM. Terminated with $00 00. + $asciidata = $rawdata; + if (substr($asciidata, 0, 2) == chr(0xFF).chr(0xFE)) { + // remove BOM, only if present (it should be, but...) + $asciidata = substr($asciidata, 2); + } + if (substr($asciidata, strlen($asciidata) - 2, 2) == chr(0).chr(0)) { + $asciidata = substr($asciidata, 0, strlen($asciidata) - 2); // remove terminator, only if present (it should be, but...) + } + for ($i = 0; $i < strlen($asciidata); $i += 2) { + if ((ord($asciidata[$i]) <= 0x7F) || (ord($asciidata[$i]) >= 0xA0)) { + $tempstring .= $asciidata[$i]; + } else { + $tempstring .= '?'; + } + } + $asciidata = $tempstring; + break; + + case 2: // UTF-16BE encoded Unicode without BOM. Terminated with $00 00. + $asciidata = $rawdata; + if (substr($asciidata, strlen($asciidata) - 2, 2) == chr(0).chr(0)) { + $asciidata = substr($asciidata, 0, strlen($asciidata) - 2); // remove terminator, only if present (it should be, but...) + } + for ($i = 0; $i < strlen($asciidata); $i += 2) { + if ((ord($asciidata[$i]) <= 0x7F) || (ord($asciidata[$i]) >= 0xA0)) { + $tempstring .= $asciidata[$i]; + } else { + $tempstring .= '?'; + } + } + $asciidata = $tempstring; + break; + + case 3: // UTF-8 encoded Unicode. Terminated with $00. + $asciidata = utf8_decode($rawdata); + break; + + case 255: // Unicode, Big-Endian. Terminated with $00 00. + $asciidata = $rawdata; + if (substr($asciidata, strlen($asciidata) - 2, 2) == chr(0).chr(0)) { + $asciidata = substr($asciidata, 0, strlen($asciidata) - 2); // remove terminator, only if present (it should be, but...) + } + for ($i = 0; ($i + 1) < strlen($asciidata); $i += 2) { + if ((ord($asciidata[($i + 1)]) <= 0x7F) || (ord($asciidata[($i + 1)]) >= 0xA0)) { + $tempstring .= $asciidata[($i + 1)]; + } else { + $tempstring .= '?'; + } + } + $asciidata = $tempstring; + break; + + + default: + // shouldn't happen, but in case $frame_textencoding is not 1 <= $frame_textencoding <= 4 + // just pass the data through unchanged. + $asciidata = $rawdata; + break; + } + if (substr($asciidata, strlen($asciidata) - 1, 1) == chr(0)) { + // remove null terminator, if present + $asciidata = NoNullString($asciidata); + } + return $asciidata; + // return str_replace(chr(0), '', $asciidata); // just in case any nulls slipped through + } +} + +if (!function_exists('PlaytimeString')) { + function PlaytimeString($playtimeseconds) { + $contentseconds = round((($playtimeseconds / 60) - floor($playtimeseconds / 60)) * 60); + $contentminutes = floor($playtimeseconds / 60); + if ($contentseconds >= 60) { + $contentseconds -= 60; + $contentminutes++; + } + return number_format($contentminutes).':'.str_pad($contentseconds, 2, 0, STR_PAD_LEFT); + } +} + +if (!function_exists('CloseMatch')) { + function CloseMatch($value1, $value2, $tolerance) { + return (abs($value1 - $value2) <= $tolerance); + } +} + +if (!function_exists('ID3v1matchesID3v2')) { + function ID3v1matchesID3v2($id3v1, $id3v2) { + + $requiredindices = array('title', 'artist', 'album', 'year', 'genre', 'comment'); + foreach ($requiredindices as $requiredindex) { + if (!isset($id3v1["$requiredindex"])) { + $id3v1["$requiredindex"] = ''; + } + if (!isset($id3v2["$requiredindex"])) { + $id3v2["$requiredindex"] = ''; + } + } + + if (trim($id3v1['title']) != trim(substr($id3v2['title'], 0, 30))) { + return false; + } + if (trim($id3v1['artist']) != trim(substr($id3v2['artist'], 0, 30))) { + return false; + } + if (trim($id3v1['album']) != trim(substr($id3v2['album'], 0, 30))) { + return false; + } + if (trim($id3v1['year']) != trim(substr($id3v2['year'], 0, 4))) { + return false; + } + if (trim($id3v1['genre']) != trim($id3v2['genre'])) { + return false; + } + if (isset($id3v1['track_number'])) { + if (!isset($id3v1['track_number']) || (trim($id3v1['track_number']) != trim($id3v2['track_number']))) { + return false; + } + if (trim($id3v1['comment']) != trim(substr($id3v2['comment'], 0, 28))) { + return false; + } + } else { + if (trim($id3v1['comment']) != trim(substr($id3v2['comment'], 0, 30))) { + return false; + } + } + return true; + } +} + +if (!function_exists('FILETIMEtoUNIXtime')) { + function FILETIMEtoUNIXtime($FILETIME, $round=true) { + // FILETIME is a 64-bit unsigned integer representing + // the number of 100-nanosecond intervals since January 1, 1601 + // UNIX timestamp is number of seconds since January 1, 1970 + // 116444736000000000 = 10000000 * 60 * 60 * 24 * 365 * 369 + 89 leap days + if ($round) { + return round(($FILETIME - 116444736000000000) / 10000000); + } + return ($FILETIME - 116444736000000000) / 10000000; + } +} + +if (!function_exists('GUIDtoBytestring')) { + function GUIDtoBytestring($GUIDstring) { + // Microsoft defines these 16-byte (128-bit) GUIDs in the strangest way: + // first 4 bytes are in little-endian order + // next 2 bytes are appended in little-endian order + // next 2 bytes are appended in little-endian order + // next 2 bytes are appended in big-endian order + // next 6 bytes are appended in big-endian order + + // AaBbCcDd-EeFf-GgHh-IiJj-KkLlMmNnOoPp is stored as this 16-byte string: + // $Dd $Cc $Bb $Aa $Ff $Ee $Hh $Gg $Ii $Jj $Kk $Ll $Mm $Nn $Oo $Pp + + $hexbytecharstring = chr(hexdec(substr($GUIDstring, 6, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 4, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 2, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 0, 2))); + + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 11, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 9, 2))); + + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 16, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 14, 2))); + + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 19, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 21, 2))); + + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 24, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 26, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 28, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 30, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 32, 2))); + $hexbytecharstring .= chr(hexdec(substr($GUIDstring, 34, 2))); + + return $hexbytecharstring; + } +} + +if (!function_exists('BytestringToGUID')) { + function BytestringToGUID($Bytestring) { + $GUIDstring = str_pad(dechex(ord($Bytestring[3])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[2])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[1])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[0])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= '-'; + $GUIDstring .= str_pad(dechex(ord($Bytestring[5])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[4])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= '-'; + $GUIDstring .= str_pad(dechex(ord($Bytestring[7])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[6])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= '-'; + $GUIDstring .= str_pad(dechex(ord($Bytestring[8])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[9])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= '-'; + $GUIDstring .= str_pad(dechex(ord($Bytestring[10])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[11])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[12])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[13])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[14])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[15])), 2, '0', STR_PAD_LEFT); + + return strtoupper($GUIDstring); + } +} + +if (!function_exists('BitrateColor')) { + function BitrateColor($bitrate) { + $bitrate /= 3; // scale from 1-768kbps to 1-256kbps + $bitrate--; // scale from 1-256kbps to 0-255kbps + $bitrate = max($bitrate, 0); + $bitrate = min($bitrate, 255); + //$bitrate = max($bitrate, 32); + //$bitrate = min($bitrate, 143); + //$bitrate = ($bitrate * 2) - 32; + + $Rcomponent = max(255 - ($bitrate * 2), 0); + $Gcomponent = max(($bitrate * 2) - 255, 0); + if ($bitrate > 127) { + $Bcomponent = max((255 - $bitrate) * 2, 0); + } else { + $Bcomponent = max($bitrate * 2, 0); + } + return str_pad(dechex($Rcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Gcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Bcomponent), 2, '0', STR_PAD_LEFT); + } +} + +if (!function_exists('BitrateText')) { + function BitrateText($bitrate) { + return ''.round($bitrate).' kbps'; + } +} + +if (!function_exists('image_type_to_mime_type')) { + function image_type_to_mime_type($imagetypeid) { + // only available in PHP v4.3.0+ + static $image_type_to_mime_type = array(); + if (empty($image_type_to_mime_type)) { + $image_type_to_mime_type[1] = 'image/gif'; // GIF + $image_type_to_mime_type[2] = 'image/jpeg'; // JPEG + $image_type_to_mime_type[3] = 'image/png'; // PNG + $image_type_to_mime_type[4] = 'application/x-shockwave-flash'; // Flash + $image_type_to_mime_type[5] = 'image/psd'; // PSD + $image_type_to_mime_type[6] = 'image/bmp'; // BMP + $image_type_to_mime_type[7] = 'image/tiff'; // TIFF: little-endian (Intel) + $image_type_to_mime_type[8] = 'image/tiff'; // TIFF: big-endian (Motorola) + //$image_type_to_mime_type[9] = 'image/jpc'; // JPC + //$image_type_to_mime_type[10] = 'image/jp2'; // JPC + //$image_type_to_mime_type[11] = 'image/jpx'; // JPC + //$image_type_to_mime_type[12] = 'image/jb2'; // JPC + $image_type_to_mime_type[13] = 'application/x-shockwave-flash'; // Shockwave + $image_type_to_mime_type[14] = 'image/iff'; // IFF + } + return (isset($image_type_to_mime_type[$imagetypeid]) ? $image_type_to_mime_type[$imagetypeid] : 'application/octet-stream'); + } +} + +if (!function_exists('utf8_decode')) { + // PHP has this function built-in if it's configured with the --with-xml option + // This version of the function is only provided in case XML isn't installed + function utf8_decode($utf8text) { + // http://www.php.net/manual/en/function.utf8-encode.php + // bytes bits representation + // 1 7 0bbbbbbb + // 2 11 110bbbbb 10bbbbbb + // 3 16 1110bbbb 10bbbbbb 10bbbbbb + // 4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb + + $utf8length = strlen($utf8text); + $decodedtext = ''; + for ($i = 0; $i < $utf8length; $i++) { + if ((ord($utf8text[$i]) & 0x80) == 0) { + $decodedtext .= $utf8text[$i]; + } elseif ((ord($utf8text[$i]) & 0xF0) == 0xF0) { + $decodedtext .= '?'; + $i += 3; + } elseif ((ord($utf8text[$i]) & 0xE0) == 0xE0) { + $decodedtext .= '?'; + $i += 2; + } elseif ((ord($utf8text[$i]) & 0xC0) == 0xC0) { + // 2 11 110bbbbb 10bbbbbb + $decodedchar = Bin2Dec(substr(Dec2Bin(ord($utf8text[$i])), 3, 5).substr(Dec2Bin(ord($utf8text[($i + 1)])), 2, 6)); + if ($decodedchar <= 255) { + $decodedtext .= chr($decodedchar); + } else { + $decodedtext .= '?'; + } + $i += 1; + } + } + return $decodedtext; + } +} + +if (!function_exists('DateMac2Unix')) { + function DateMac2Unix($macdate) { + // Macintosh timestamp: seconds since 00:00h January 1, 1904 + // UNIX timestamp: seconds since 00:00h January 1, 1970 + return CastAsInt($macdate - 2082844800); + } +} + + +if (!function_exists('FixedPoint8_8')) { + function FixedPoint8_8($rawdata) { + return BigEndian2Int(substr($rawdata, 0, 1)) + (float) (BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8)); + } +} + + +if (!function_exists('FixedPoint16_16')) { + function FixedPoint16_16($rawdata) { + return BigEndian2Int(substr($rawdata, 0, 2)) + (float) (BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16)); + } +} + + +if (!function_exists('FixedPoint2_30')) { + function FixedPoint2_30($rawdata) { + $binarystring = BigEndian2Bin($rawdata); + return Bin2Dec(substr($binarystring, 0, 2)) + (float) (Bin2Dec(substr($binarystring, 2, 30)) / pow(2, 30)); + } +} + + +if (!function_exists('Pascal2String')) { + function Pascal2String($pascalstring) { + // Pascal strings have 1 byte at the beginning saying how many chars are in the string + return substr($pascalstring, 1); + } +} + +if (!function_exists('NoNullString')) { + function NoNullString($nullterminatedstring) { + // remove the single null terminator on null terminated strings + if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === chr(0)) { + return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1); + } + return $nullterminatedstring; + } +} + +if (!function_exists('FileSizeNiceDisplay')) { + function FileSizeNiceDisplay($filesize, $precision=2) { + if ($filesize < 1000) { + $sizeunit = 'bytes'; + $precision = 0; + } else { + $filesize /= 1024; + $sizeunit = 'kB'; + } + if ($filesize >= 1000) { + $filesize /= 1024; + $sizeunit = 'MB'; + } + if ($filesize >= 1000) { + $filesize /= 1024; + $sizeunit = 'GB'; + } + return number_format($filesize, $precision).' '.$sizeunit; + } +} + +if (!function_exists('DOStime2UNIXtime')) { + function DOStime2UNIXtime($DOSdate, $DOStime) { + // wFatDate + // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format: + // Bits Contents + // 0-4 Day of the month (1-31) + // 5-8 Month (1 = January, 2 = February, and so on) + // 9-15 Year offset from 1980 (add 1980 to get actual year) + + $UNIXday = ($DOSdate & 0x001F); + $UNIXmonth = (($DOSdate & 0x01E0) >> 5); + $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980; + + // wFatTime + // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format: + // Bits Contents + // 0-4 Second divided by 2 + // 5-10 Minute (0-59) + // 11-15 Hour (0-23 on a 24-hour clock) + + $UNIXsecond = ($DOStime & 0x001F) * 2; + $UNIXminute = (($DOStime & 0x07E0) >> 5); + $UNIXhour = (($DOStime & 0xF800) >> 11); + + return mktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear); + } +} + +if (!function_exists('CreateDeepArray')) { + function CreateDeepArray($ArrayPath, $Separator, $Value) { + // assigns $Value to a nested array path: + // $foo = CreateDeepArray('/path/to/my', '/', 'file.txt') + // is the same as: + // $foo = array('path'=>array('to'=>'array('my'=>array('file.txt')))); + // or + // $foo['path']['to']['my'] = 'file.txt'; + while ($ArrayPath[0] == $Separator) { + $ArrayPath = substr($ArrayPath, 1); + } + if (($pos = strpos($ArrayPath, $Separator)) !== false) { + $ReturnedArray[substr($ArrayPath, 0, $pos)] = CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value); + } else { + $ReturnedArray["$ArrayPath"] = $Value; + } + return $ReturnedArray; + } +} + +if (!function_exists('md5_data')) { + // Allan Hansen + // md5_data() - returns md5sum for a file from startuing position to absolute end position + + function md5_data($file, $offset, $end, $invertsign=false) { + // first try and create a temporary file in the same directory as the file being scanned + if (($dataMD5filename = tempnam(dirname($file), preg_replace('#[^[:alnum:]]#i', '', basename($file)))) === false) { + // if that fails, create a temporary file in the system temp directory + if (($dataMD5filename = tempnam('/tmp', 'getID3')) === false) { + // if that fails, create a temporary file in the current directory + if (($dataMD5filename = tempnam('.', preg_replace('#[^[:alnum:]]#i', '', basename($file)))) === false) { + // can't find anywhere to create a temp file, just die + return false; + } + } + } + $md5 = false; + set_time_limit(max(filesize($file) / 1000000, 30)); + + // copy parts of file + ob_start(); + if ($fp = fopen($file, 'rb')) { + ob_end_clean(); + + ob_start(); + if ($MD5fp = fopen($dataMD5filename, 'wb')) { + + ob_end_clean(); + if ($invertsign) { + // Load conversion lookup strings for 8-bit unsigned->signed conversion below + $from = ''; + $to = ''; + for ($i = 0; $i < 128; $i++) { + $from .= chr($i); + $to .= chr($i + 128); + } + for ($i = 128; $i < 256; $i++) { + $from .= chr($i); + $to .= chr($i - 128); + } + } + + fseek($fp, $offset, SEEK_SET); + $byteslefttowrite = $end - $offset; + while (($byteslefttowrite > 0) && ($buffer = fread($fp, 32768))) { + if ($invertsign) { + // Possibly FLAC-specific (?) + // FLAC calculates the MD5sum of the source data of 8-bit files + // not on the actual byte values in the source file, but of those + // values converted from unsigned to signed, or more specifcally, + // with the MSB inverted. ex: 01 -> 81; F5 -> 75; etc + + // Therefore, 8-bit WAV data has to be converted before getting the + // md5_data value so as to match the FLAC value + + // Flip the MSB for each byte in the buffer before copying + $buffer = strtr($buffer, $from, $to); + } + $byteswritten = fwrite($MD5fp, $buffer, $byteslefttowrite); + $byteslefttowrite -= $byteswritten; + } + fclose($MD5fp); + $md5 = md5_file($dataMD5filename); + + } else { + $errormessage = ob_get_contents(); + ob_end_clean(); + } + fclose($fp); + + } else { + $errormessage = ob_get_contents(); + ob_end_clean(); + } + unlink($dataMD5filename); + return $md5; + } +} + +if (!function_exists('TwosCompliment2Decimal')) { + function TwosCompliment2Decimal($BinaryValue) { + // http://sandbox.mc.edu/~bennet/cs110/tc/tctod.html + // First check if the number is negative or positive by looking at the sign bit. + // If it is positive, simply convert it to decimal. + // If it is negative, make it positive by inverting the bits and adding one. + // Then, convert the result to decimal. + // The negative of this number is the value of the original binary. + + if ($BinaryValue & 0x80) { + + // negative number + return (0 - ((~$BinaryValue & 0xFF) + 1)); + + } else { + + // positive number + return $BinaryValue; + + } + + } +} + +if (!function_exists('LastArrayElement')) { + function LastArrayElement($MyArray) { + if (!is_array($MyArray)) { + return false; + } + if (empty($MyArray)) { + return null; + } + foreach ($MyArray as $key => $value) { + } + return $value; + } +} + +if (!function_exists('safe_inc')) { + function safe_inc(&$variable, $increment=1) { + if (isset($variable)) { + $variable += $increment; + } else { + $variable = $increment; + } + return true; + } +} + +if (!function_exists('CalculateCompressionRatioVideo')) { + function CalculateCompressionRatioVideo(&$ThisFileInfo) { + if (empty($ThisFileInfo['video'])) { + return false; + } + if (empty($ThisFileInfo['video']['resolution_x']) || empty($ThisFileInfo['video']['resolution_y'])) { + return false; + } + if (empty($ThisFileInfo['video']['bits_per_sample'])) { + return false; + } + + switch ($ThisFileInfo['video']['dataformat']) { + case 'bmp': + case 'gif': + case 'jpeg': + case 'jpg': + case 'png': + case 'tiff': + $FrameRate = 1; + $PlaytimeSeconds = 1; + $BitrateCompressed = $ThisFileInfo['filesize'] * 8; + break; + + default: + if (!empty($ThisFileInfo['video']['frame_rate'])) { + $FrameRate = $ThisFileInfo['video']['frame_rate']; + } else { + return false; + } + if (!empty($ThisFileInfo['playtime_seconds'])) { + $PlaytimeSeconds = $ThisFileInfo['playtime_seconds']; + } else { + return false; + } + if (!empty($ThisFileInfo['video']['bitrate'])) { + $BitrateCompressed = $ThisFileInfo['video']['bitrate']; + } else { + return false; + } + break; + } + $BitrateUncompressed = $ThisFileInfo['video']['resolution_x'] * $ThisFileInfo['video']['resolution_y'] * $ThisFileInfo['video']['bits_per_sample'] * $FrameRate; + + $ThisFileInfo['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed; + return true; + } +} + +if (!function_exists('CalculateCompressionRatioAudio')) { + function CalculateCompressionRatioAudio(&$ThisFileInfo) { + if (empty($ThisFileInfo['audio']['bitrate']) || empty($ThisFileInfo['audio']['channels']) || empty($ThisFileInfo['audio']['sample_rate']) || empty($ThisFileInfo['audio']['bits_per_sample'])) { + return false; + } + $ThisFileInfo['audio']['compression_ratio'] = $ThisFileInfo['audio']['bitrate'] / ($ThisFileInfo['audio']['channels'] * $ThisFileInfo['audio']['sample_rate'] * $ThisFileInfo['audio']['bits_per_sample']); + return true; + } +} + +if (!function_exists('IsValidMIMEstring')) { + function IsValidMIMEstring($mimestring) { + if ((strlen($mimestring) >= 3) && (strpos($mimestring, '/') > 0) && (strpos($mimestring, '/') < (strlen($mimestring) - 1))) { + return true; + } + return false; + } +} + +if (!function_exists('IsWithinBitRange')) { + function IsWithinBitRange($number, $maxbits, $signed=false) { + if ($signed) { + if (($number > (0 - pow(2, $maxbits - 1))) && ($number <= pow(2, $maxbits - 1))) { + return true; + } + } else { + if (($number >= 0) && ($number <= pow(2, $maxbits))) { + return true; + } + } + return false; + } +} + +if (!function_exists('safe_parse_url')) { + function safe_parse_url($url) { + ob_start(); + $parts = parse_url($url); + $errormessage = ob_get_contents(); + ob_end_clean(); + $parts['scheme'] = (isset($parts['scheme']) ? $parts['scheme'] : ''); + $parts['host'] = (isset($parts['host']) ? $parts['host'] : ''); + $parts['user'] = (isset($parts['user']) ? $parts['user'] : ''); + $parts['pass'] = (isset($parts['pass']) ? $parts['pass'] : ''); + $parts['path'] = (isset($parts['path']) ? $parts['path'] : ''); + $parts['query'] = (isset($parts['query']) ? $parts['query'] : ''); + return $parts; + } +} + +if (!function_exists('IsValidURL')) { + function IsValidURL($url, $allowUserPass=false) { + if ($url == '') { + return false; + } + if ($allowUserPass !== true) { + if (strstr($url, '@')) { + // in the format http://user:pass@example.com or http://user@example.com + // but could easily be somebody incorrectly entering an email address in place of a URL + return false; + } + } + if ($parts = safe_parse_url($url)) { + if (($parts['scheme'] != 'http') && ($parts['scheme'] != 'https') && ($parts['scheme'] != 'ftp') && ($parts['scheme'] != 'gopher')) { + return false; + } elseif (!preg_match("#^[[:alnum:]]([-.]?[0-9a-z])*\.[a-z]{2,3}#i$", $parts['host'], $regs) && !preg_match('#^[0-9]{1,3}(\.[0-9]{1,3}){3}$#', $parts['host'])) { + return false; + } elseif (!preg_match("#^([[:alnum:]-]|[\_])*$#i", $parts['user'], $regs)) { + return false; + } elseif (!preg_match("#^([[:alnum:]-]|[\_])*$#i", $parts['pass'], $regs)) { + return false; + } elseif (!preg_match("#^[[:alnum:]/_\.@~-]*$#i", $parts['path'], $regs)) { + return false; + } elseif (!preg_match("#^[[:alnum:]?&=+:;_()%#/,\.-]*$#i", $parts['query'], $regs)) { + return false; + } else { + return true; + } + } + return false; + } +} + +echo '
'; +echo 'Enter 4 hex bytes of MPEG-audio header (ie FF FA 92 44)
'; +echo ''; +echo '
'; +echo '
'; + +echo '
'; +echo 'Generate a MPEG-audio 4-byte header from these values:
'; +echo ''; + +$MPEGgenerateValues = array( + 'version' => array('1', '2', '2.5'), + 'layer' => array('I', 'II', 'III'), + 'protection' => array('Y', 'N'), + 'bitrate' => array('free', '8', '16', '24', '32', '40', '48', '56', '64', '80', '96', '112', '128', '144', '160', '176', '192', '224', '256', '288', '320', '352', '384', '416', '448'), + 'frequency' => array('8000', '11025', '12000', '16000', '22050', '24000', '32000', '44100', '48000'), + 'padding' => array('Y', 'N'), + 'private' => array('Y', 'N'), + 'channelmode' => array('stereo', 'joint stereo', 'dual channel', 'mono'), + 'modeextension' => array('none', 'IS', 'MS', 'IS+MS', '4-31', '8-31', '12-31', '16-31'), + 'copyright' => array('Y', 'N'), + 'original' => array('Y', 'N'), + 'emphasis' => array('none', '50/15ms', 'CCIT J.17'), +); + +foreach ($MPEGgenerateValues as $name => $dataarray) { + echo ''; +} + +if (isset($_POST['bitrate'])) { + echo ''; +} +echo '
'.$name.':
Frame Length:'.(int) MPEGaudioFrameLength($_POST['bitrate'], $_POST['version'], $_POST['layer'], (($_POST['padding'] == 'Y') ? '1' : '0'), $_POST['frequency']).'
'; +echo '
'; +echo '
'; + + +if (isset($_POST['Analyze']) && $_POST['HeaderHexBytes']) { + + $headerbytearray = explode(' ', $_POST['HeaderHexBytes']); + if (count($headerbytearray) != 4) { + die('Invalid byte pattern'); + } + $headerstring = ''; + foreach ($headerbytearray as $textbyte) { + $headerstring .= chr(hexdec($textbyte)); + } + + $MP3fileInfo['error'] = ''; + + $MPEGheaderRawArray = MPEGaudioHeaderDecode(substr($headerstring, 0, 4)); + + if (MPEGaudioHeaderValid($MPEGheaderRawArray, true)) { + + $MP3fileInfo['raw'] = $MPEGheaderRawArray; + + $MP3fileInfo['version'] = MPEGaudioVersionLookup($MP3fileInfo['raw']['version']); + $MP3fileInfo['layer'] = MPEGaudioLayerLookup($MP3fileInfo['raw']['layer']); + $MP3fileInfo['protection'] = MPEGaudioCRCLookup($MP3fileInfo['raw']['protection']); + $MP3fileInfo['bitrate'] = MPEGaudioBitrateLookup($MP3fileInfo['version'], $MP3fileInfo['layer'], $MP3fileInfo['raw']['bitrate']); + $MP3fileInfo['frequency'] = MPEGaudioFrequencyLookup($MP3fileInfo['version'], $MP3fileInfo['raw']['sample_rate']); + $MP3fileInfo['padding'] = (bool) $MP3fileInfo['raw']['padding']; + $MP3fileInfo['private'] = (bool) $MP3fileInfo['raw']['private']; + $MP3fileInfo['channelmode'] = MPEGaudioChannelModeLookup($MP3fileInfo['raw']['channelmode']); + $MP3fileInfo['channels'] = (($MP3fileInfo['channelmode'] == 'mono') ? 1 : 2); + $MP3fileInfo['modeextension'] = MPEGaudioModeExtensionLookup($MP3fileInfo['layer'], $MP3fileInfo['raw']['modeextension']); + $MP3fileInfo['copyright'] = (bool) $MP3fileInfo['raw']['copyright']; + $MP3fileInfo['original'] = (bool) $MP3fileInfo['raw']['original']; + $MP3fileInfo['emphasis'] = MPEGaudioEmphasisLookup($MP3fileInfo['raw']['emphasis']); + + if ($MP3fileInfo['protection']) { + $MP3fileInfo['crc'] = BigEndian2Int(substr($headerstring, 4, 2)); + } + + if ($MP3fileInfo['frequency'] > 0) { + $MP3fileInfo['framelength'] = MPEGaudioFrameLength($MP3fileInfo['bitrate'], $MP3fileInfo['version'], $MP3fileInfo['layer'], (int) $MP3fileInfo['padding'], $MP3fileInfo['frequency']); + } + if ($MP3fileInfo['bitrate'] != 'free') { + $MP3fileInfo['bitrate'] *= 1000; + } + + } else { + + $MP3fileInfo['error'] .= "\n".'Invalid MPEG audio header'; + + } + + if (!$MP3fileInfo['error']) { + unset($MP3fileInfo['error']); + } + + echo table_var_dump($MP3fileInfo); + +} elseif (isset($_POST['Generate'])) { + + // AAAA AAAA AAAB BCCD EEEE FFGH IIJJ KLMM + + $headerbitstream = '11111111111'; // A - Frame sync (all bits set) + + $MPEGversionLookup = array('2.5'=>'00', '2'=>'10', '1'=>'11'); + $headerbitstream .= $MPEGversionLookup[$_POST['version']]; // B - MPEG Audio version ID + + $MPEGlayerLookup = array('III'=>'01', 'II'=>'10', 'I'=>'11'); + $headerbitstream .= $MPEGlayerLookup[$_POST['layer']]; // C - Layer description + + $headerbitstream .= (($_POST['protection'] == 'Y') ? '0' : '1'); // D - Protection bit + + $MPEGaudioBitrateLookup['1']['I'] = array('free'=>'0000', '32'=>'0001', '64'=>'0010', '96'=>'0011', '128'=>'0100', '160'=>'0101', '192'=>'0110', '224'=>'0111', '256'=>'1000', '288'=>'1001', '320'=>'1010', '352'=>'1011', '384'=>'1100', '416'=>'1101', '448'=>'1110'); + $MPEGaudioBitrateLookup['1']['II'] = array('free'=>'0000', '32'=>'0001', '48'=>'0010', '56'=>'0011', '64'=>'0100', '80'=>'0101', '96'=>'0110', '112'=>'0111', '128'=>'1000', '160'=>'1001', '192'=>'1010', '224'=>'1011', '256'=>'1100', '320'=>'1101', '384'=>'1110'); + $MPEGaudioBitrateLookup['1']['III'] = array('free'=>'0000', '32'=>'0001', '40'=>'0010', '48'=>'0011', '56'=>'0100', '64'=>'0101', '80'=>'0110', '96'=>'0111', '112'=>'1000', '128'=>'1001', '160'=>'1010', '192'=>'1011', '224'=>'1100', '256'=>'1101', '320'=>'1110'); + $MPEGaudioBitrateLookup['2']['I'] = array('free'=>'0000', '32'=>'0001', '48'=>'0010', '56'=>'0011', '64'=>'0100', '80'=>'0101', '96'=>'0110', '112'=>'0111', '128'=>'1000', '144'=>'1001', '160'=>'1010', '176'=>'1011', '192'=>'1100', '224'=>'1101', '256'=>'1110'); + $MPEGaudioBitrateLookup['2']['II'] = array('free'=>'0000', '8'=>'0001', '16'=>'0010', '24'=>'0011', '32'=>'0100', '40'=>'0101', '48'=>'0110', '56'=>'0111', '64'=>'1000', '80'=>'1001', '96'=>'1010', '112'=>'1011', '128'=>'1100', '144'=>'1101', '160'=>'1110'); + $MPEGaudioBitrateLookup['2']['III'] = $MPEGaudioBitrateLookup['2']['II']; + $MPEGaudioBitrateLookup['2.5']['I'] = $MPEGaudioBitrateLookup['2']['I']; + $MPEGaudioBitrateLookup['2.5']['II'] = $MPEGaudioBitrateLookup['2']['II']; + $MPEGaudioBitrateLookup['2.5']['III'] = $MPEGaudioBitrateLookup['2']['II']; + if (isset($MPEGaudioBitrateLookup[$_POST['version']][$_POST['layer']][$_POST['bitrate']])) { + $headerbitstream .= $MPEGaudioBitrateLookup[$_POST['version']][$_POST['layer']][$_POST['bitrate']]; // E - Bitrate index + } else { + die('Invalid Bitrate'); + } + + $MPEGaudioFrequencyLookup['1'] = array('44100'=>'00', '48000'=>'01', '32000'=>'10'); + $MPEGaudioFrequencyLookup['2'] = array('22050'=>'00', '24000'=>'01', '16000'=>'10'); + $MPEGaudioFrequencyLookup['2.5'] = array('11025'=>'00', '12000'=>'01', '8000'=>'10'); + if (isset($MPEGaudioFrequencyLookup[$_POST['version']][$_POST['frequency']])) { + $headerbitstream .= $MPEGaudioFrequencyLookup[$_POST['version']][$_POST['frequency']]; // F - Sampling rate frequency index + } else { + die('Invalid Frequency'); + } + + $headerbitstream .= (($_POST['padding'] == 'Y') ? '1' : '0'); // G - Padding bit + + $headerbitstream .= (($_POST['private'] == 'Y') ? '1' : '0'); // H - Private bit + + $MPEGaudioChannelModeLookup = array('stereo'=>'00', 'joint stereo'=>'01', 'dual channel'=>'10', 'mono'=>'11'); + $headerbitstream .= $MPEGaudioChannelModeLookup[$_POST['channelmode']]; // I - Channel Mode + + $MPEGaudioModeExtensionLookup['I'] = array('4-31'=>'00', '8-31'=>'01', '12-31'=>'10', '16-31'=>'11'); + $MPEGaudioModeExtensionLookup['II'] = $MPEGaudioModeExtensionLookup['I']; + $MPEGaudioModeExtensionLookup['III'] = array('none'=>'00', 'IS'=>'01', 'MS'=>'10', 'IS+MS'=>'11'); + if ($_POST['channelmode'] != 'joint stereo') { + $headerbitstream .= '00'; + } elseif (isset($MPEGaudioModeExtensionLookup[$_POST['layer']][$_POST['modeextension']])) { + $headerbitstream .= $MPEGaudioModeExtensionLookup[$_POST['layer']][$_POST['modeextension']]; // J - Mode extension (Only if Joint stereo) + } else { + die('Invalid Mode Extension'); + } + + $headerbitstream .= (($_POST['copyright'] == 'Y') ? '1' : '0'); // K - Copyright + + $headerbitstream .= (($_POST['original'] == 'Y') ? '1' : '0'); // L - Original + + $MPEGaudioEmphasisLookup = array('none'=>'00', '50/15ms'=>'01', 'CCIT J.17'=>'11'); + if (isset($MPEGaudioEmphasisLookup[$_POST['emphasis']])) { + $headerbitstream .= $MPEGaudioEmphasisLookup[$_POST['emphasis']]; // M - Emphasis + } else { + die('Invalid Emphasis'); + } + + echo strtoupper(str_pad(dechex(bindec(substr($headerbitstream, 0, 8))), 2, '0', STR_PAD_LEFT)).' '; + echo strtoupper(str_pad(dechex(bindec(substr($headerbitstream, 8, 8))), 2, '0', STR_PAD_LEFT)).' '; + echo strtoupper(str_pad(dechex(bindec(substr($headerbitstream, 16, 8))), 2, '0', STR_PAD_LEFT)).' '; + echo strtoupper(str_pad(dechex(bindec(substr($headerbitstream, 24, 8))), 2, '0', STR_PAD_LEFT)).'
'; + +} + +function MPEGaudioVersionLookup($rawversion) { + $MPEGaudioVersionLookup = array('2.5', FALSE, '2', '1'); + return (isset($MPEGaudioVersionLookup["$rawversion"]) ? $MPEGaudioVersionLookup["$rawversion"] : FALSE); +} + +function MPEGaudioLayerLookup($rawlayer) { + $MPEGaudioLayerLookup = array(FALSE, 'III', 'II', 'I'); + return (isset($MPEGaudioLayerLookup["$rawlayer"]) ? $MPEGaudioLayerLookup["$rawlayer"] : FALSE); +} + +function MPEGaudioBitrateLookup($version, $layer, $rawbitrate) { + static $MPEGaudioBitrateLookup; + if (empty($MPEGaudioBitrateLookup)) { + $MPEGaudioBitrateLookup = MPEGaudioBitrateArray(); + } + return (isset($MPEGaudioBitrateLookup["$version"]["$layer"]["$rawbitrate"]) ? $MPEGaudioBitrateLookup["$version"]["$layer"]["$rawbitrate"] : FALSE); +} + +function MPEGaudioFrequencyLookup($version, $rawfrequency) { + static $MPEGaudioFrequencyLookup; + if (empty($MPEGaudioFrequencyLookup)) { + $MPEGaudioFrequencyLookup = MPEGaudioFrequencyArray(); + } + return (isset($MPEGaudioFrequencyLookup["$version"]["$rawfrequency"]) ? $MPEGaudioFrequencyLookup["$version"]["$rawfrequency"] : FALSE); +} + +function MPEGaudioChannelModeLookup($rawchannelmode) { + $MPEGaudioChannelModeLookup = array('stereo', 'joint stereo', 'dual channel', 'mono'); + return (isset($MPEGaudioChannelModeLookup["$rawchannelmode"]) ? $MPEGaudioChannelModeLookup["$rawchannelmode"] : FALSE); +} + +function MPEGaudioModeExtensionLookup($layer, $rawmodeextension) { + $MPEGaudioModeExtensionLookup['I'] = array('4-31', '8-31', '12-31', '16-31'); + $MPEGaudioModeExtensionLookup['II'] = array('4-31', '8-31', '12-31', '16-31'); + $MPEGaudioModeExtensionLookup['III'] = array('', 'IS', 'MS', 'IS+MS'); + return (isset($MPEGaudioModeExtensionLookup["$layer"]["$rawmodeextension"]) ? $MPEGaudioModeExtensionLookup["$layer"]["$rawmodeextension"] : FALSE); +} + +function MPEGaudioEmphasisLookup($rawemphasis) { + $MPEGaudioEmphasisLookup = array('none', '50/15ms', FALSE, 'CCIT J.17'); + return (isset($MPEGaudioEmphasisLookup["$rawemphasis"]) ? $MPEGaudioEmphasisLookup["$rawemphasis"] : FALSE); +} + +function MPEGaudioCRCLookup($CRCbit) { + // inverse boolean cast :) + if ($CRCbit == '0') { + return TRUE; + } else { + return FALSE; + } +} + +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich // +// available at http://getid3.sourceforge.net /// +// or https://www.getid3.org /// +///////////////////////////////////////////////////////////////// +// // +// getid3.mp3.php - part of getID3() // +// See getid3.readme.txt for more details // +// // +///////////////////////////////////////////////////////////////// + +// number of frames to scan to determine if MPEG-audio sequence is valid +// Lower this number to 5-20 for faster scanning +// Increase this number to 50+ for most accurate detection of valid VBR/CBR +// mpeg-audio streams +define('MPEG_VALID_CHECK_FRAMES', 35); + +function getMP3headerFilepointer(&$fd, &$ThisFileInfo) { + + getOnlyMPEGaudioInfo($fd, $ThisFileInfo, $ThisFileInfo['avdataoffset']); + + if (isset($ThisFileInfo['mpeg']['audio']['bitrate_mode'])) { + $ThisFileInfo['audio']['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitrate_mode']); + } + + if (((isset($ThisFileInfo['id3v2']) && ($ThisFileInfo['avdataoffset'] > $ThisFileInfo['id3v2']['headerlength'])) || (!isset($ThisFileInfo['id3v2']) && ($ThisFileInfo['avdataoffset'] > 0)))) { + + $ThisFileInfo['warning'] .= "\n".'Unknown data before synch '; + if (isset($ThisFileInfo['id3v2']['headerlength'])) { + $ThisFileInfo['warning'] .= '(ID3v2 header ends at '.$ThisFileInfo['id3v2']['headerlength'].', then '.($ThisFileInfo['avdataoffset'] - $ThisFileInfo['id3v2']['headerlength']).' bytes garbage, '; + } else { + $ThisFileInfo['warning'] .= '(should be at beginning of file, '; + } + $ThisFileInfo['warning'] .= 'synch detected at '.$ThisFileInfo['avdataoffset'].')'; + if ($ThisFileInfo['audio']['bitrate_mode'] == 'cbr') { + if (!empty($ThisFileInfo['id3v2']['headerlength']) && (($ThisFileInfo['avdataoffset'] - $ThisFileInfo['id3v2']['headerlength']) == $ThisFileInfo['mpeg']['audio']['framelength'])) { + $ThisFileInfo['warning'] .= '. This is a known problem with some versions of LAME (3.91, 3.92) DLL in CBR mode.'; + $ThisFileInfo['audio']['codec'] = 'LAME'; + } elseif (empty($ThisFileInfo['id3v2']['headerlength']) && ($ThisFileInfo['avdataoffset'] == $ThisFileInfo['mpeg']['audio']['framelength'])) { + $ThisFileInfo['warning'] .= '. This is a known problem with some versions of LAME (3.91, 3.92) DLL in CBR mode.'; + $ThisFileInfo['audio']['codec'] = 'LAME'; + } + } + + } + + if (isset($ThisFileInfo['mpeg']['audio']['layer']) && ($ThisFileInfo['mpeg']['audio']['layer'] == 'II')) { + $ThisFileInfo['audio']['dataformat'] = 'mp2'; + } elseif (isset($ThisFileInfo['mpeg']['audio']['layer']) && ($ThisFileInfo['mpeg']['audio']['layer'] == 'I')) { + $ThisFileInfo['audio']['dataformat'] = 'mp1'; + } + if ($ThisFileInfo['fileformat'] == 'mp3') { + switch ($ThisFileInfo['audio']['dataformat']) { + case 'mp1': + case 'mp2': + case 'mp3': + $ThisFileInfo['fileformat'] = $ThisFileInfo['audio']['dataformat']; + break; + + default: + $ThisFileInfo['warning'] .= "\n".'Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$ThisFileInfo['audio']['dataformat'].'"'; + break; + } + } + + if (empty($ThisFileInfo['fileformat'])) { + $ThisFileInfo['error'] .= "\n".'Synch not found'; + unset($ThisFileInfo['fileformat']); + unset($ThisFileInfo['audio']['bitrate_mode']); + unset($ThisFileInfo['avdataoffset']); + unset($ThisFileInfo['avdataend']); + return false; + } + + $ThisFileInfo['mime_type'] = 'audio/mpeg'; + $ThisFileInfo['audio']['lossless'] = false; + + // Calculate playtime + if (!isset($ThisFileInfo['playtime_seconds']) && isset($ThisFileInfo['audio']['bitrate']) && ($ThisFileInfo['audio']['bitrate'] > 0)) { + $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate']; + } + + if (isset($ThisFileInfo['mpeg']['audio']['LAME'])) { + $ThisFileInfo['audio']['codec'] = 'LAME'; + if (!empty($ThisFileInfo['mpeg']['audio']['LAME']['long_version'])) { + $ThisFileInfo['audio']['encoder'] = trim($ThisFileInfo['mpeg']['audio']['LAME']['long_version']); + } + } + + return true; +} + + +function decodeMPEGaudioHeader($fd, $offset, &$ThisFileInfo, $recursivesearch=true, $ScanAsCBR=false, $FastMPEGheaderScan=false) { + + static $MPEGaudioVersionLookup; + static $MPEGaudioLayerLookup; + static $MPEGaudioBitrateLookup; + static $MPEGaudioFrequencyLookup; + static $MPEGaudioChannelModeLookup; + static $MPEGaudioModeExtensionLookup; + static $MPEGaudioEmphasisLookup; + if (empty($MPEGaudioVersionLookup)) { + $MPEGaudioVersionLookup = MPEGaudioVersionArray(); + $MPEGaudioLayerLookup = MPEGaudioLayerArray(); + $MPEGaudioBitrateLookup = MPEGaudioBitrateArray(); + $MPEGaudioFrequencyLookup = MPEGaudioFrequencyArray(); + $MPEGaudioChannelModeLookup = MPEGaudioChannelModeArray(); + $MPEGaudioModeExtensionLookup = MPEGaudioModeExtensionArray(); + $MPEGaudioEmphasisLookup = MPEGaudioEmphasisArray(); + } + + if ($offset >= $ThisFileInfo['avdataend']) { + $ThisFileInfo['error'] .= "\n".'end of file encounter looking for MPEG synch'; + return false; + } + fseek($fd, $offset, SEEK_SET); + $headerstring = fread($fd, 1441); // worse-case max length = 32kHz @ 320kbps layer 3 = 1441 bytes/frame + + // MP3 audio frame structure: + // $aa $aa $aa $aa [$bb $bb] $cc... + // where $aa..$aa is the four-byte mpeg-audio header (below) + // $bb $bb is the optional 2-byte CRC + // and $cc... is the audio data + + $head4 = substr($headerstring, 0, 4); + + static $MPEGaudioHeaderDecodeCache = array(); + if (isset($MPEGaudioHeaderDecodeCache[$head4])) { + $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4]; + } else { + $MPEGheaderRawArray = MPEGaudioHeaderDecode($head4); + $MPEGaudioHeaderDecodeCache[$head4] = $MPEGheaderRawArray; + } + + static $MPEGaudioHeaderValidCache = array(); + + // Not in cache + if (!isset($MPEGaudioHeaderValidCache[$head4])) { + $MPEGaudioHeaderValidCache[$head4] = MPEGaudioHeaderValid($MPEGheaderRawArray); + } + + if ($MPEGaudioHeaderValidCache[$head4]) { + $ThisFileInfo['mpeg']['audio']['raw'] = $MPEGheaderRawArray; + } else { + $ThisFileInfo['error'] .= "\n".'Invalid MPEG audio header at offset '.$offset; + return false; + } + + if (!$FastMPEGheaderScan) { + + $ThisFileInfo['mpeg']['audio']['version'] = $MPEGaudioVersionLookup[$ThisFileInfo['mpeg']['audio']['raw']['version']]; + $ThisFileInfo['mpeg']['audio']['layer'] = $MPEGaudioLayerLookup[$ThisFileInfo['mpeg']['audio']['raw']['layer']]; + + $ThisFileInfo['mpeg']['audio']['channelmode'] = $MPEGaudioChannelModeLookup[$ThisFileInfo['mpeg']['audio']['raw']['channelmode']]; + $ThisFileInfo['mpeg']['audio']['channels'] = (($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') ? 1 : 2); + $ThisFileInfo['mpeg']['audio']['sample_rate'] = $MPEGaudioFrequencyLookup[$ThisFileInfo['mpeg']['audio']['version']][$ThisFileInfo['mpeg']['audio']['raw']['sample_rate']]; + $ThisFileInfo['mpeg']['audio']['protection'] = !$ThisFileInfo['mpeg']['audio']['raw']['protection']; + $ThisFileInfo['mpeg']['audio']['private'] = (bool) $ThisFileInfo['mpeg']['audio']['raw']['private']; + $ThisFileInfo['mpeg']['audio']['modeextension'] = $MPEGaudioModeExtensionLookup[$ThisFileInfo['mpeg']['audio']['layer']][$ThisFileInfo['mpeg']['audio']['raw']['modeextension']]; + $ThisFileInfo['mpeg']['audio']['copyright'] = (bool) $ThisFileInfo['mpeg']['audio']['raw']['copyright']; + $ThisFileInfo['mpeg']['audio']['original'] = (bool) $ThisFileInfo['mpeg']['audio']['raw']['original']; + $ThisFileInfo['mpeg']['audio']['emphasis'] = $MPEGaudioEmphasisLookup[$ThisFileInfo['mpeg']['audio']['raw']['emphasis']]; + + $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels']; + $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate']; + + if ($ThisFileInfo['mpeg']['audio']['protection']) { + $ThisFileInfo['mpeg']['audio']['crc'] = BigEndian2Int(substr($headerstring, 4, 2)); + } + + } + + if ($ThisFileInfo['mpeg']['audio']['raw']['bitrate'] == 15) { + // http://www.hydrogenaudio.org/?act=ST&f=16&t=9682&st=0 + $ThisFileInfo['warning'] .= "\n".'Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1'; + $ThisFileInfo['mpeg']['audio']['raw']['bitrate'] = 0; + } + $ThisFileInfo['mpeg']['audio']['padding'] = (bool) $ThisFileInfo['mpeg']['audio']['raw']['padding']; + $ThisFileInfo['mpeg']['audio']['bitrate'] = $MPEGaudioBitrateLookup[$ThisFileInfo['mpeg']['audio']['version']][$ThisFileInfo['mpeg']['audio']['layer']][$ThisFileInfo['mpeg']['audio']['raw']['bitrate']]; + + if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') && ($offset == $ThisFileInfo['avdataoffset'])) { + // only skip multiple frame check if free-format bitstream found at beginning of file + // otherwise is quite possibly simply corrupted data + $recursivesearch = false; + } + + // For Layer II there are some combinations of bitrate and mode which are not allowed. + if (!$FastMPEGheaderScan && ($ThisFileInfo['mpeg']['audio']['layer'] == 'II')) { + + $ThisFileInfo['audio']['dataformat'] = 'mp2'; + switch ($ThisFileInfo['mpeg']['audio']['channelmode']) { + + case 'mono': + if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') || ($ThisFileInfo['mpeg']['audio']['bitrate'] <= 192)) { + // these are ok + } else { + $ThisFileInfo['error'] .= "\n".$ThisFileInfo['mpeg']['audio']['bitrate'].'kbps not allowed in Layer II, '.$ThisFileInfo['mpeg']['audio']['channelmode'].'.'; + return false; + } + break; + + case 'stereo': + case 'joint stereo': + case 'dual channel': + if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') || ($ThisFileInfo['mpeg']['audio']['bitrate'] == 64) || ($ThisFileInfo['mpeg']['audio']['bitrate'] >= 96)) { + // these are ok + } else { + $ThisFileInfo['error'] .= "\n".$ThisFileInfo['mpeg']['audio']['bitrate'].'kbps not allowed in Layer II, '.$ThisFileInfo['mpeg']['audio']['channelmode'].'.'; + return false; + } + break; + + } + + } + + + if ($ThisFileInfo['audio']['sample_rate'] > 0) { + $ThisFileInfo['mpeg']['audio']['framelength'] = MPEGaudioFrameLength($ThisFileInfo['mpeg']['audio']['bitrate'], $ThisFileInfo['mpeg']['audio']['version'], $ThisFileInfo['mpeg']['audio']['layer'], (int) $ThisFileInfo['mpeg']['audio']['padding'], $ThisFileInfo['audio']['sample_rate']); + } + + if ($ThisFileInfo['mpeg']['audio']['bitrate'] != 'free') { + + $ThisFileInfo['audio']['bitrate'] = 1000 * $ThisFileInfo['mpeg']['audio']['bitrate']; + + if (isset($ThisFileInfo['mpeg']['audio']['framelength'])) { + $nextframetestoffset = $offset + $ThisFileInfo['mpeg']['audio']['framelength']; + } else { + $ThisFileInfo['error'] .= "\n".'Frame at offset('.$offset.') is has an invalid frame length.'; + return false; + } + + } + + $ExpectedNumberOfAudioBytes = 0; + + //////////////////////////////////////////////////////////////////////////////////// + // Variable-bitrate headers + + if (substr($headerstring, 4 + 32, 4) == 'VBRI') { + // Fraunhofer VBR header is hardcoded 'VBRI' at offset 0x24 (36) + // specs taken from http://minnie.tuhs.org/pipermail/mp3encoder/2001-January/001800.html + + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'vbr'; + $ThisFileInfo['mpeg']['audio']['VBR_method'] = 'Fraunhofer'; + $ThisFileInfo['audio']['codec'] = 'Fraunhofer'; + + $SideInfoData = substr($headerstring, 4 + 2, 32); + + $FraunhoferVBROffset = 36; + + $ThisFileInfo['mpeg']['audio']['VBR_encoder_version'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 4, 2)); + $ThisFileInfo['mpeg']['audio']['VBR_encoder_delay'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 6, 2)); + $ThisFileInfo['mpeg']['audio']['VBR_quality'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 8, 2)); + $ThisFileInfo['mpeg']['audio']['VBR_bytes'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 10, 4)); + $ThisFileInfo['mpeg']['audio']['VBR_frames'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 14, 4)); + $ThisFileInfo['mpeg']['audio']['VBR_seek_offsets'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 18, 2)); + //$ThisFileInfo['mpeg']['audio']['reserved'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 20, 4)); // hardcoded $00 $01 $00 $02 - purpose unknown + $ThisFileInfo['mpeg']['audio']['VBR_seek_offsets_stride'] = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 24, 2)); + + $ExpectedNumberOfAudioBytes = $ThisFileInfo['mpeg']['audio']['VBR_bytes']; + + $previousbyteoffset = $offset; + for ($i = 0; $i < $ThisFileInfo['mpeg']['audio']['VBR_seek_offsets']; $i++) { + $Fraunhofer_OffsetN = BigEndian2Int(substr($headerstring, $FraunhoferVBROffset, 2)); + $FraunhoferVBROffset += 2; + $ThisFileInfo['mpeg']['audio']['VBR_offsets_relative'][$i] = $Fraunhofer_OffsetN; + $ThisFileInfo['mpeg']['audio']['VBR_offsets_absolute'][$i] = $Fraunhofer_OffsetN + $previousbyteoffset; + $previousbyteoffset += $Fraunhofer_OffsetN; + } + + + } else { + + // Xing VBR header is hardcoded 'Xing' at a offset 0x0D (13), 0x15 (21) or 0x24 (36) + // depending on MPEG layer and number of channels + + if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { + if ($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') { + // MPEG-1 (mono) + $VBRidOffset = 4 + 17; // 0x15 + $SideInfoData = substr($headerstring, 4 + 2, 17); + } else { + // MPEG-1 (stereo, joint-stereo, dual-channel) + $VBRidOffset = 4 + 32; // 0x24 + $SideInfoData = substr($headerstring, 4 + 2, 32); + } + } else { // 2 or 2.5 + if ($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') { + // MPEG-2, MPEG-2.5 (mono) + $VBRidOffset = 4 + 9; // 0x0D + $SideInfoData = substr($headerstring, 4 + 2, 9); + } else { + // MPEG-2, MPEG-2.5 (stereo, joint-stereo, dual-channel) + $VBRidOffset = 4 + 17; // 0x15 + $SideInfoData = substr($headerstring, 4 + 2, 17); + } + } + + if ((substr($headerstring, $VBRidOffset, strlen('Xing')) == 'Xing') || (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Info')) { + // 'Xing' is traditional Xing VBR frame + // 'Info' is LAME-encoded CBR (This was done to avoid CBR files to be recognized as traditional Xing VBR files by some decoders.) + + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'vbr'; + $ThisFileInfo['mpeg']['audio']['VBR_method'] = 'Xing'; + + $ThisFileInfo['mpeg']['audio']['xing_flags_raw'] = BigEndian2Int(substr($headerstring, $VBRidOffset + 4, 4)); + + $ThisFileInfo['mpeg']['audio']['xing_flags']['frames'] = (bool) ($ThisFileInfo['mpeg']['audio']['xing_flags_raw'] & 0x00000001); + $ThisFileInfo['mpeg']['audio']['xing_flags']['bytes'] = (bool) ($ThisFileInfo['mpeg']['audio']['xing_flags_raw'] & 0x00000002); + $ThisFileInfo['mpeg']['audio']['xing_flags']['toc'] = (bool) ($ThisFileInfo['mpeg']['audio']['xing_flags_raw'] & 0x00000004); + $ThisFileInfo['mpeg']['audio']['xing_flags']['vbr_scale'] = (bool) ($ThisFileInfo['mpeg']['audio']['xing_flags_raw'] & 0x00000008); + + if ($ThisFileInfo['mpeg']['audio']['xing_flags']['frames']) { + $ThisFileInfo['mpeg']['audio']['VBR_frames'] = BigEndian2Int(substr($headerstring, $VBRidOffset + 8, 4)); + } + if ($ThisFileInfo['mpeg']['audio']['xing_flags']['bytes']) { + $ThisFileInfo['mpeg']['audio']['VBR_bytes'] = BigEndian2Int(substr($headerstring, $VBRidOffset + 12, 4)); + } + + if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') && !empty($ThisFileInfo['mpeg']['audio']['VBR_frames']) && !empty($ThisFileInfo['mpeg']['audio']['VBR_bytes'])) { + $framelengthfloat = $ThisFileInfo['mpeg']['audio']['VBR_bytes'] / $ThisFileInfo['mpeg']['audio']['VBR_frames']; + if ($ThisFileInfo['mpeg']['audio']['layer'] == 'I') { + // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12 + $ThisFileInfo['audio']['bitrate'] = ((($framelengthfloat / 4) - intval($ThisFileInfo['mpeg']['audio']['padding'])) * $ThisFileInfo['mpeg']['audio']['sample_rate']) / 12; + } else { + // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144 + $ThisFileInfo['audio']['bitrate'] = (($framelengthfloat - intval($ThisFileInfo['mpeg']['audio']['padding'])) * $ThisFileInfo['mpeg']['audio']['sample_rate']) / 144; + } + $ThisFileInfo['mpeg']['audio']['framelength'] = floor($framelengthfloat); + } + + if ($ThisFileInfo['mpeg']['audio']['xing_flags']['toc']) { + $LAMEtocData = substr($headerstring, $VBRidOffset + 16, 100); + for ($i = 0; $i < 100; $i++) { + $ThisFileInfo['mpeg']['audio']['toc'][$i] = ord($LAMEtocData[$i]); + } + } + if ($ThisFileInfo['mpeg']['audio']['xing_flags']['vbr_scale']) { + $ThisFileInfo['mpeg']['audio']['VBR_scale'] = BigEndian2Int(substr($headerstring, $VBRidOffset + 116, 4)); + } + + // http://gabriel.mp3-tech.org/mp3infotag.html + if (substr($headerstring, $VBRidOffset + 120, 4) == 'LAME') { + $ThisFileInfo['mpeg']['audio']['LAME']['long_version'] = substr($headerstring, $VBRidOffset + 120, 20); + $ThisFileInfo['mpeg']['audio']['LAME']['short_version'] = substr($ThisFileInfo['mpeg']['audio']['LAME']['long_version'], 0, 9); + $ThisFileInfo['mpeg']['audio']['LAME']['long_version'] = rtrim($ThisFileInfo['mpeg']['audio']['LAME']['long_version'], "\x55\xAA"); + + if ($ThisFileInfo['mpeg']['audio']['LAME']['short_version'] >= 'LAME3.90.') { + + // It the LAME tag was only introduced in LAME v3.90 + // http://www.hydrogenaudio.org/?act=ST&f=15&t=9933 + + // Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html + // are assuming a 'Xing' identifier offset of 0x24, which is the case for + // MPEG-1 non-mono, but not for other combinations + $LAMEtagOffsetContant = $VBRidOffset - 0x24; + + // byte $9B VBR Quality + // This field is there to indicate a quality level, although the scale was not precised in the original Xing specifications. + // Actually overwrites original Xing bytes + unset($ThisFileInfo['mpeg']['audio']['VBR_scale']); + $ThisFileInfo['mpeg']['audio']['LAME']['vbr_quality'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0x9B, 1)); + + // bytes $9C-$A4 Encoder short VersionString + $ThisFileInfo['mpeg']['audio']['LAME']['short_version'] = substr($headerstring, $LAMEtagOffsetContant + 0x9C, 9); + $ThisFileInfo['mpeg']['audio']['LAME']['long_version'] = $ThisFileInfo['mpeg']['audio']['LAME']['short_version']; + + // byte $A5 Info Tag revision + VBR method + $LAMEtagRevisionVBRmethod = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA5, 1)); + + $ThisFileInfo['mpeg']['audio']['LAME']['tag_revision'] = ($LAMEtagRevisionVBRmethod & 0xF0) >> 4; + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['vbr_method'] = $LAMEtagRevisionVBRmethod & 0x0F; + $ThisFileInfo['mpeg']['audio']['LAME']['vbr_method'] = LAMEvbrMethodLookup($ThisFileInfo['mpeg']['audio']['LAME']['raw']['vbr_method']); + + // byte $A6 Lowpass filter value + $ThisFileInfo['mpeg']['audio']['LAME']['lowpass_frequency'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100; + + // bytes $A7-$AE Replay Gain + // http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html + // bytes $A7-$AA : 32 bit floating point "Peak signal amplitude" + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] = BigEndian2Float(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4)); + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAB, 2)); + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAD, 2)); + + if ($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] == 0) { + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] = false; + } + + if ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] != 0) { + require_once(GETID3_INCLUDEPATH.'getid3.rgad.php'); + + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['name'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] & 0xE000) >> 13; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['originator'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] & 0x1C00) >> 10; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['sign_bit'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] & 0x0200) >> 9; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['gain_adjust'] = $ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_radio'] & 0x01FF; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['name'] = RGADnameLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['name']); + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['originator'] = RGADoriginatorLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['originator']); + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['gain_db'] = RGADadjustmentLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['gain_adjust'], $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['raw']['sign_bit']); + + if ($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] !== false) { + $ThisFileInfo['replay_gain']['radio']['peak'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude']; + } + $ThisFileInfo['replay_gain']['radio']['originator'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['originator']; + $ThisFileInfo['replay_gain']['radio']['adjustment'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['radio']['gain_db']; + } + if ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] != 0) { + require_once(GETID3_INCLUDEPATH.'getid3.rgad.php'); + + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['name'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] & 0xE000) >> 13; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['originator'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] & 0x1C00) >> 10; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['sign_bit'] = ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] & 0x0200) >> 9; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['gain_adjust'] = $ThisFileInfo['mpeg']['audio']['LAME']['raw']['RGAD_audiophile'] & 0x01FF; + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['name'] = RGADnameLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['name']); + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['originator'] = RGADoriginatorLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['originator']); + $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['gain_db'] = RGADadjustmentLookup($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['gain_adjust'], $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['raw']['sign_bit']); + + if ($ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude'] !== false) { + $ThisFileInfo['replay_gain']['audiophile']['peak'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['peak_amplitude']; + } + $ThisFileInfo['replay_gain']['audiophile']['originator'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['originator']; + $ThisFileInfo['replay_gain']['audiophile']['adjustment'] = $ThisFileInfo['mpeg']['audio']['LAME']['RGAD']['audiophile']['gain_db']; + } + + + // byte $AF Encoding flags + ATH Type + $EncodingFlagsATHtype = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAF, 1)); + $ThisFileInfo['mpeg']['audio']['LAME']['encoding_flags']['nspsytune'] = (bool) ($EncodingFlagsATHtype & 0x10); + $ThisFileInfo['mpeg']['audio']['LAME']['encoding_flags']['nssafejoint'] = (bool) ($EncodingFlagsATHtype & 0x20); + $ThisFileInfo['mpeg']['audio']['LAME']['encoding_flags']['nogap_next'] = (bool) ($EncodingFlagsATHtype & 0x40); + $ThisFileInfo['mpeg']['audio']['LAME']['encoding_flags']['nogap_prev'] = (bool) ($EncodingFlagsATHtype & 0x80); + $ThisFileInfo['mpeg']['audio']['LAME']['ath_type'] = $EncodingFlagsATHtype & 0x0F; + + // byte $B0 if ABR {specified bitrate} else {minimal bitrate} + $ABRbitrateMinBitrate = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB0, 1)); + if ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['vbr_method'] == 2) { // Average BitRate (ABR) + $ThisFileInfo['mpeg']['audio']['LAME']['bitrate_abr'] = $ABRbitrateMinBitrate; + } elseif ($ABRbitrateMinBitrate > 0) { // Variable BitRate (VBR) - minimum bitrate + $ThisFileInfo['mpeg']['audio']['LAME']['bitrate_min'] = $ABRbitrateMinBitrate; + } + + // bytes $B1-$B3 Encoder delays + $EncoderDelays = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB1, 3)); + $ThisFileInfo['mpeg']['audio']['LAME']['encoder_delay'] = ($EncoderDelays & 0xFFF000) >> 12; + $ThisFileInfo['mpeg']['audio']['LAME']['end_padding'] = $EncoderDelays & 0x000FFF; + + // byte $B4 Misc + $MiscByte = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB4, 1)); + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['noise_shaping'] = ($MiscByte & 0x03); + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['stereo_mode'] = ($MiscByte & 0x1C) >> 2; + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['not_optimal_quality'] = ($MiscByte & 0x20) >> 5; + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['source_sample_freq'] = ($MiscByte & 0xC0) >> 6; + $ThisFileInfo['mpeg']['audio']['LAME']['noise_shaping'] = $ThisFileInfo['mpeg']['audio']['LAME']['raw']['noise_shaping']; + $ThisFileInfo['mpeg']['audio']['LAME']['stereo_mode'] = LAMEmiscStereoModeLookup($ThisFileInfo['mpeg']['audio']['LAME']['raw']['stereo_mode']); + $ThisFileInfo['mpeg']['audio']['LAME']['not_optimal_quality'] = (bool) $ThisFileInfo['mpeg']['audio']['LAME']['raw']['not_optimal_quality']; + $ThisFileInfo['mpeg']['audio']['LAME']['source_sample_freq'] = LAMEmiscSourceSampleFrequencyLookup($ThisFileInfo['mpeg']['audio']['LAME']['raw']['source_sample_freq']); + + // byte $B5 MP3 Gain + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['mp3_gain'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB5, 1), false, true); + $ThisFileInfo['mpeg']['audio']['LAME']['mp3_gain_db'] = 1.5 * $ThisFileInfo['mpeg']['audio']['LAME']['raw']['mp3_gain']; + $ThisFileInfo['mpeg']['audio']['LAME']['mp3_gain_factor'] = pow(2, ($ThisFileInfo['mpeg']['audio']['LAME']['mp3_gain_db'] / 6)); + + // bytes $B6-$B7 Preset and surround info + $PresetSurroundBytes = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB6, 2)); + // Reserved = ($PresetSurroundBytes & 0xC000); + $ThisFileInfo['mpeg']['audio']['LAME']['raw']['surround_info'] = ($PresetSurroundBytes & 0x3800); + $ThisFileInfo['mpeg']['audio']['LAME']['surround_info'] = LAMEsurroundInfoLookup($ThisFileInfo['mpeg']['audio']['LAME']['raw']['surround_info']); + $ThisFileInfo['mpeg']['audio']['LAME']['preset_used_id'] = ($PresetSurroundBytes & 0x07FF); + + // bytes $B8-$BB MusicLength + $ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB8, 4)); + $ExpectedNumberOfAudioBytes = (($ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes'] > 0) ? $ThisFileInfo['mpeg']['audio']['LAME']['audio_bytes'] : $ThisFileInfo['mpeg']['audio']['VBR_bytes']); + + // bytes $BC-$BD MusicCRC + $ThisFileInfo['mpeg']['audio']['LAME']['music_crc'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBC, 2)); + + // bytes $BE-$BF CRC-16 of Info Tag + $ThisFileInfo['mpeg']['audio']['LAME']['lame_tag_crc'] = BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBE, 2)); + + + // LAME CBR + if ($ThisFileInfo['mpeg']['audio']['LAME']['raw']['vbr_method'] == 1) { + + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'cbr'; + if (empty($ThisFileInfo['mpeg']['audio']['bitrate']) || ($ThisFileInfo['mpeg']['audio']['LAME']['bitrate_min'] != 255)) { + $ThisFileInfo['mpeg']['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['LAME']['bitrate_min']; + } + + } + + } + } + + } else { + + // not Fraunhofer or Xing VBR methods, most likely CBR (but could be VBR with no header) + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'cbr'; + if ($recursivesearch) { + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'vbr'; + if (RecursiveFrameScanning($fd, $ThisFileInfo, $offset, $nextframetestoffset, true)) { + $recursivesearch = false; + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'cbr'; + } + if ($ThisFileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr') { + $ThisFileInfo['warning'] .= "\n".'VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.'; + } + } + + } + + } + + if (($ExpectedNumberOfAudioBytes > 0) && ($ExpectedNumberOfAudioBytes != ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']))) { + if (($ExpectedNumberOfAudioBytes - ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'])) == 1) { + $ThisFileInfo['warning'] .= "\n".'Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)'; + } elseif ($ExpectedNumberOfAudioBytes > ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'])) { + $ThisFileInfo['warning'] .= "\n".'Probable truncated file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, only found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' (short by '.($ExpectedNumberOfAudioBytes - ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'])).' bytes)'; + } else { + $ThisFileInfo['warning'] .= "\n".'Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' ('.(($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)'; + } + } + + if (($ThisFileInfo['mpeg']['audio']['bitrate'] == 'free') && empty($ThisFileInfo['audio']['bitrate'])) { + if (($offset == $ThisFileInfo['avdataoffset']) && empty($ThisFileInfo['mpeg']['audio']['VBR_frames'])) { + $framebytelength = FreeFormatFrameLength($fd, $offset, $ThisFileInfo, true); + if ($framebytelength > 0) { + $ThisFileInfo['mpeg']['audio']['framelength'] = $framebytelength; + if ($ThisFileInfo['mpeg']['audio']['layer'] == 'I') { + // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12 + $ThisFileInfo['audio']['bitrate'] = ((($framebytelength / 4) - intval($ThisFileInfo['mpeg']['audio']['padding'])) * $ThisFileInfo['mpeg']['audio']['sample_rate']) / 12; + } else { + // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144 + $ThisFileInfo['audio']['bitrate'] = (($framebytelength - intval($ThisFileInfo['mpeg']['audio']['padding'])) * $ThisFileInfo['mpeg']['audio']['sample_rate']) / 144; + } + } else { + $ThisFileInfo['error'] .= "\n".'Error calculating frame length of free-format MP3 without Xing/LAME header'; + } + } + } + + if (($ThisFileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr') && isset($ThisFileInfo['mpeg']['audio']['VBR_frames']) && ($ThisFileInfo['mpeg']['audio']['VBR_frames'] > 1)) { + $ThisFileInfo['mpeg']['audio']['VBR_frames']--; // don't count the Xing / VBRI frame + if (($ThisFileInfo['mpeg']['audio']['version'] == '1') && ($ThisFileInfo['mpeg']['audio']['layer'] == 'I')) { + $ThisFileInfo['mpeg']['audio']['VBR_bitrate'] = ((($ThisFileInfo['mpeg']['audio']['VBR_bytes'] / $ThisFileInfo['mpeg']['audio']['VBR_frames']) * 8) * ($ThisFileInfo['audio']['sample_rate'] / 384)) / 1000; + } elseif ((($ThisFileInfo['mpeg']['audio']['version'] == '2') || ($ThisFileInfo['mpeg']['audio']['version'] == '2.5')) && ($ThisFileInfo['mpeg']['audio']['layer'] == 'III')) { + $ThisFileInfo['mpeg']['audio']['VBR_bitrate'] = ((($ThisFileInfo['mpeg']['audio']['VBR_bytes'] / $ThisFileInfo['mpeg']['audio']['VBR_frames']) * 8) * ($ThisFileInfo['audio']['sample_rate'] / 576)) / 1000; + } else { + $ThisFileInfo['mpeg']['audio']['VBR_bitrate'] = ((($ThisFileInfo['mpeg']['audio']['VBR_bytes'] / $ThisFileInfo['mpeg']['audio']['VBR_frames']) * 8) * ($ThisFileInfo['audio']['sample_rate'] / 1152)) / 1000; + } + if ($ThisFileInfo['mpeg']['audio']['VBR_bitrate'] > 0) { + $ThisFileInfo['audio']['bitrate'] = 1000 * $ThisFileInfo['mpeg']['audio']['VBR_bitrate']; + $ThisFileInfo['mpeg']['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['VBR_bitrate']; // to avoid confusion + } + } + + // End variable-bitrate headers + //////////////////////////////////////////////////////////////////////////////////// + + if ($recursivesearch) { + + if (!RecursiveFrameScanning($fd, $ThisFileInfo, $offset, $nextframetestoffset, $ScanAsCBR)) { + return false; + } + + } + + + //if (false) { + // // experimental side info parsing section - not returning anything useful yet + // + // $SideInfoBitstream = BigEndian2Bin($SideInfoData); + // $SideInfoOffset = 0; + // + // if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { + // if ($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') { + // // MPEG-1 (mono) + // $ThisFileInfo['mpeg']['audio']['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 9); + // $SideInfoOffset += 9; + // $SideInfoOffset += 5; + // } else { + // // MPEG-1 (stereo, joint-stereo, dual-channel) + // $ThisFileInfo['mpeg']['audio']['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 9); + // $SideInfoOffset += 9; + // $SideInfoOffset += 3; + // } + // } else { // 2 or 2.5 + // if ($ThisFileInfo['mpeg']['audio']['channelmode'] == 'mono') { + // // MPEG-2, MPEG-2.5 (mono) + // $ThisFileInfo['mpeg']['audio']['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 8); + // $SideInfoOffset += 8; + // $SideInfoOffset += 1; + // } else { + // // MPEG-2, MPEG-2.5 (stereo, joint-stereo, dual-channel) + // $ThisFileInfo['mpeg']['audio']['side_info']['main_data_begin'] = substr($SideInfoBitstream, $SideInfoOffset, 8); + // $SideInfoOffset += 8; + // $SideInfoOffset += 2; + // } + // } + // + // if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { + // for ($channel = 0; $channel < $ThisFileInfo['audio']['channels']; $channel++) { + // for ($scfsi_band = 0; $scfsi_band < 4; $scfsi_band++) { + // $ThisFileInfo['mpeg']['audio']['scfsi'][$channel][$scfsi_band] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 2; + // } + // } + // } + // for ($granule = 0; $granule < (($ThisFileInfo['mpeg']['audio']['version'] == '1') ? 2 : 1); $granule++) { + // for ($channel = 0; $channel < $ThisFileInfo['audio']['channels']; $channel++) { + // $ThisFileInfo['mpeg']['audio']['part2_3_length'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 12); + // $SideInfoOffset += 12; + // $ThisFileInfo['mpeg']['audio']['big_values'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9); + // $SideInfoOffset += 9; + // $ThisFileInfo['mpeg']['audio']['global_gain'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 8); + // $SideInfoOffset += 8; + // if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { + // $ThisFileInfo['mpeg']['audio']['scalefac_compress'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 4); + // $SideInfoOffset += 4; + // } else { + // $ThisFileInfo['mpeg']['audio']['scalefac_compress'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9); + // $SideInfoOffset += 9; + // } + // $ThisFileInfo['mpeg']['audio']['window_switching_flag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // + // if ($ThisFileInfo['mpeg']['audio']['window_switching_flag'][$granule][$channel] == '1') { + // + // $ThisFileInfo['mpeg']['audio']['block_type'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 2); + // $SideInfoOffset += 2; + // $ThisFileInfo['mpeg']['audio']['mixed_block_flag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // + // for ($region = 0; $region < 2; $region++) { + // $ThisFileInfo['mpeg']['audio']['table_select'][$granule][$channel][$region] = substr($SideInfoBitstream, $SideInfoOffset, 5); + // $SideInfoOffset += 5; + // } + // $ThisFileInfo['mpeg']['audio']['table_select'][$granule][$channel][2] = 0; + // + // for ($window = 0; $window < 3; $window++) { + // $ThisFileInfo['mpeg']['audio']['subblock_gain'][$granule][$channel][$window] = substr($SideInfoBitstream, $SideInfoOffset, 3); + // $SideInfoOffset += 3; + // } + // + // } else { + // + // for ($region = 0; $region < 3; $region++) { + // $ThisFileInfo['mpeg']['audio']['table_select'][$granule][$channel][$region] = substr($SideInfoBitstream, $SideInfoOffset, 5); + // $SideInfoOffset += 5; + // } + // + // $ThisFileInfo['mpeg']['audio']['region0_count'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 4); + // $SideInfoOffset += 4; + // $ThisFileInfo['mpeg']['audio']['region1_count'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 3); + // $SideInfoOffset += 3; + // $ThisFileInfo['mpeg']['audio']['block_type'][$granule][$channel] = 0; + // } + // + // if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { + // $ThisFileInfo['mpeg']['audio']['preflag'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // } + // $ThisFileInfo['mpeg']['audio']['scalefac_scale'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // $ThisFileInfo['mpeg']['audio']['count1table_select'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 1); + // $SideInfoOffset += 1; + // } + // } + //} + + return true; +} + +function RecursiveFrameScanning(&$fd, &$ThisFileInfo, &$offset, &$nextframetestoffset, $ScanAsCBR) { + for ($i = 0; $i < MPEG_VALID_CHECK_FRAMES; $i++) { + // check next MPEG_VALID_CHECK_FRAMES frames for validity, to make sure we haven't run across a false synch + if (($nextframetestoffset + 4) >= $ThisFileInfo['avdataend']) { + // end of file + return true; + } + + $nextframetestarray = array('error'=>'', 'warning'=>'', 'avdataend'=>$ThisFileInfo['avdataend'], 'avdataoffset'=>$ThisFileInfo['avdataoffset']); + if (decodeMPEGaudioHeader($fd, $nextframetestoffset, $nextframetestarray, false)) { + if ($ScanAsCBR) { + // force CBR mode, used for trying to pick out invalid audio streams with + // valid(?) VBR headers, or VBR streams with no VBR header + if (!isset($nextframetestarray['mpeg']['audio']['bitrate']) || !isset($ThisFileInfo['mpeg']['audio']['bitrate']) || ($nextframetestarray['mpeg']['audio']['bitrate'] != $ThisFileInfo['mpeg']['audio']['bitrate'])) { + return false; + } + } + + + // next frame is OK, get ready to check the one after that + if (isset($nextframetestarray['mpeg']['audio']['framelength']) && ($nextframetestarray['mpeg']['audio']['framelength'] > 0)) { + $nextframetestoffset += $nextframetestarray['mpeg']['audio']['framelength']; + } else { + $ThisFileInfo['error'] .= "\n".'Frame at offset ('.$offset.') is has an invalid frame length.'; + return false; + } + + } else { + + // next frame is not valid, note the error and fail, so scanning can contiue for a valid frame sequence + $ThisFileInfo['error'] .= "\n".'Frame at offset ('.$offset.') is valid, but the next one at ('.$nextframetestoffset.') is not.'; + + return false; + } + } + return true; +} + +function FreeFormatFrameLength($fd, $offset, &$ThisFileInfo, $deepscan=false) { + fseek($fd, $offset, SEEK_SET); + $MPEGaudioData = fread($fd, 32768); + + $SyncPattern1 = substr($MPEGaudioData, 0, 4); + // may be different pattern due to padding + $SyncPattern2 = $SyncPattern1[0].$SyncPattern1[1].chr(ord($SyncPattern1[2]) | 0x02).$SyncPattern1[3]; + if ($SyncPattern2 === $SyncPattern1) { + $SyncPattern2 = $SyncPattern1[0].$SyncPattern1[1].chr(ord($SyncPattern1[2]) & 0xFD).$SyncPattern1[3]; + } + + $framelength = false; + $framelength1 = strpos($MPEGaudioData, $SyncPattern1, 4); + $framelength2 = strpos($MPEGaudioData, $SyncPattern2, 4); + if ($framelength1 > 4) { + $framelength = $framelength1; + } + if (($framelength2 > 4) && ($framelength2 < $framelength1)) { + $framelength = $framelength2; + } + if (!$framelength) { + + // LAME 3.88 has a different value for modeextension on the first frame vs the rest + $framelength1 = strpos($MPEGaudioData, substr($SyncPattern1, 0, 3), 4); + $framelength2 = strpos($MPEGaudioData, substr($SyncPattern2, 0, 3), 4); + + if ($framelength1 > 4) { + $framelength = $framelength1; + } + if (($framelength2 > 4) && ($framelength2 < $framelength1)) { + $framelength = $framelength2; + } + if (!$framelength) { + $ThisFileInfo['error'] .= "\n".'Cannot find next free-format synch pattern ('.PrintHexBytes($SyncPattern1).' or '.PrintHexBytes($SyncPattern2).') after offset '.$offset; + return false; + } else { + $ThisFileInfo['warning'] .= "\n".'ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)'; + $ThisFileInfo['audio']['codec'] = 'LAME'; + $ThisFileInfo['audio']['encoder'] = 'LAME3.88'; + $SyncPattern1 = substr($SyncPattern1, 0, 3); + $SyncPattern2 = substr($SyncPattern2, 0, 3); + } + } + + if ($deepscan) { + + $ActualFrameLengthValues = array(); + $nextoffset = $offset + $framelength; + while ($nextoffset < ($ThisFileInfo['avdataend'] - 6)) { + fseek($fd, $nextoffset - 1, SEEK_SET); + $NextSyncPattern = fread($fd, 6); + if ((substr($NextSyncPattern, 1, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 1, strlen($SyncPattern2)) == $SyncPattern2)) { + // good - found where expected + $ActualFrameLengthValues[] = $framelength; + } elseif ((substr($NextSyncPattern, 0, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 0, strlen($SyncPattern2)) == $SyncPattern2)) { + // ok - found one byte earlier than expected (last frame wasn't padded, first frame was) + $ActualFrameLengthValues[] = ($framelength - 1); + $nextoffset--; + } elseif ((substr($NextSyncPattern, 2, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 2, strlen($SyncPattern2)) == $SyncPattern2)) { + // ok - found one byte later than expected (last frame was padded, first frame wasn't) + $ActualFrameLengthValues[] = ($framelength + 1); + $nextoffset++; + } else { + $ThisFileInfo['error'] .= "\n".'Did not find expected free-format sync pattern at offset '.$nextoffset; + return false; + } + $nextoffset += $framelength; + } + if (count($ActualFrameLengthValues) > 0) { + $framelength = round(array_sum($ActualFrameLengthValues) / count($ActualFrameLengthValues)); + } + } + return $framelength; +} + + +function getOnlyMPEGaudioInfo($fd, &$ThisFileInfo, $avdataoffset, $BitrateHistogram=false) { + // looks for synch, decodes MPEG audio header + + fseek($fd, $avdataoffset, SEEK_SET); + $header = ''; + $SynchSeekOffset = 0; + + if (!defined('CONST_FF')) { + define('CONST_FF', chr(0xFF)); + define('CONST_E0', chr(0xE0)); + } + + static $MPEGaudioVersionLookup; + static $MPEGaudioLayerLookup; + static $MPEGaudioBitrateLookup; + if (empty($MPEGaudioVersionLookup)) { + $MPEGaudioVersionLookup = MPEGaudioVersionArray(); + $MPEGaudioLayerLookup = MPEGaudioLayerArray(); + $MPEGaudioBitrateLookup = MPEGaudioBitrateArray(); + + } + + $header_len = strlen($header) - round(32768 / 2); + while (true) { + + if (($SynchSeekOffset > $header_len) && (($avdataoffset + $SynchSeekOffset) < $ThisFileInfo['avdataend']) && !feof($fd)) { + + if ($SynchSeekOffset > 131072) { + // if a synch's not found within the first 128k bytes, then give up + $ThisFileInfo['error'] .= "\n".'could not find valid MPEG synch within the first 131072 bytes'; + if (isset($ThisFileInfo['audio']['bitrate'])) { + unset($ThisFileInfo['audio']['bitrate']); + } + if (isset($ThisFileInfo['mpeg']['audio'])) { + unset($ThisFileInfo['mpeg']['audio']); + } + if (isset($ThisFileInfo['mpeg']) && (!is_array($ThisFileInfo['mpeg']) || (count($ThisFileInfo['mpeg']) == 0))) { + unset($ThisFileInfo['mpeg']); + } + return false; + + } elseif ($header .= fread($fd, 32768)) { + + // great + $header_len = strlen($header) - round(32768 / 2); + + } else { + + $ThisFileInfo['error'] .= "\n".'could not find valid MPEG synch before end of file'; + if (isset($ThisFileInfo['audio']['bitrate'])) { + unset($ThisFileInfo['audio']['bitrate']); + } + if (isset($ThisFileInfo['mpeg']['audio'])) { + unset($ThisFileInfo['mpeg']['audio']); + } + if (isset($ThisFileInfo['mpeg']) && (!is_array($ThisFileInfo['mpeg']) || (count($ThisFileInfo['mpeg']) == 0))) { + unset($ThisFileInfo['mpeg']); + } + return false; + + } + } + + if (($SynchSeekOffset + 1) >= strlen($header)) { + $ThisFileInfo['error'] .= "\n".'could not find valid MPEG synch before end of file'; + return false; + } + + if (($header[$SynchSeekOffset] == CONST_FF) && ($header[($SynchSeekOffset + 1)] > CONST_E0)) { // synch detected + + if (!isset($FirstFrameThisfileInfo) && !isset($ThisFileInfo['mpeg']['audio'])) { + $FirstFrameThisfileInfo = $ThisFileInfo; + $FirstFrameAVDataOffset = $avdataoffset + $SynchSeekOffset; + if (!decodeMPEGaudioHeader($fd, $avdataoffset + $SynchSeekOffset, $FirstFrameThisfileInfo, false)) { + // if this is the first valid MPEG-audio frame, save it in case it's a VBR header frame and there's + // garbage between this frame and a valid sequence of MPEG-audio frames, to be restored below + unset($FirstFrameThisfileInfo); + } + } + $dummy = $ThisFileInfo; // only overwrite real data if valid header found + + if (decodeMPEGaudioHeader($fd, $avdataoffset + $SynchSeekOffset, $dummy, true)) { + + $ThisFileInfo = $dummy; + $ThisFileInfo['avdataoffset'] = $avdataoffset + $SynchSeekOffset; + switch ($ThisFileInfo['fileformat']) { + case '': + case 'id3': + case 'ape': + case 'mp3': + $ThisFileInfo['fileformat'] = 'mp3'; + $ThisFileInfo['audio']['dataformat'] = 'mp3'; + } + if (isset($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode']) && ($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr')) { + if (!CloseMatch($ThisFileInfo['audio']['bitrate'], $FirstFrameThisfileInfo['audio']['bitrate'], 1)) { + // If there is garbage data between a valid VBR header frame and a sequence + // of valid MPEG-audio frames the VBR data is no longer discarded. + $ThisFileInfo = $FirstFrameThisfileInfo; + $ThisFileInfo['avdataoffset'] = $FirstFrameAVDataOffset; + $ThisFileInfo['fileformat'] = 'mp3'; + $ThisFileInfo['audio']['dataformat'] = 'mp3'; + $dummy = $ThisFileInfo; + unset($dummy['mpeg']['audio']); + $GarbageOffsetStart = $FirstFrameAVDataOffset + $FirstFrameThisfileInfo['mpeg']['audio']['framelength']; + $GarbageOffsetEnd = $avdataoffset + $SynchSeekOffset; + if (decodeMPEGaudioHeader($fd, $GarbageOffsetEnd, $dummy, true, true)) { + + $ThisFileInfo = $dummy; + $ThisFileInfo['avdataoffset'] = $GarbageOffsetEnd; + $ThisFileInfo['warning'] .= "\n".'apparently-valid VBR header not used because could not find '.MPEG_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.'), but did find valid CBR stream starting at '.$GarbageOffsetEnd; + + } else { + + $ThisFileInfo['warning'] .= "\n".'using data from VBR header even though could not find '.MPEG_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.')'; + + } + } + } + + if (isset($ThisFileInfo['mpeg']['audio']['bitrate_mode']) && ($ThisFileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr') && !isset($ThisFileInfo['mpeg']['audio']['VBR_method'])) { + // VBR file with no VBR header + $BitrateHistogram = true; + } + + if ($BitrateHistogram) { + + $ThisFileInfo['mpeg']['audio']['stereo_distribution'] = array('stereo'=>0, 'joint stereo'=>0, 'dual channel'=>0, 'mono'=>0); + $ThisFileInfo['mpeg']['audio']['version_distribution'] = array('1'=>0, '2'=>0, '2.5'=>0); + + if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { + if ($ThisFileInfo['mpeg']['audio']['layer'] == 'III') { + $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32=>0, 40=>0, 48=>0, 56=>0, 64=>0, 80=>0, 96=>0, 112=>0, 128=>0, 160=>0, 192=>0, 224=>0, 256=>0, 320=>0); + } elseif ($ThisFileInfo['mpeg']['audio']['layer'] == 'II') { + $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32=>0, 48=>0, 56=>0, 64=>0, 80=>0, 96=>0, 112=>0, 128=>0, 160=>0, 192=>0, 224=>0, 256=>0, 320=>0, 384=>0); + } elseif ($ThisFileInfo['mpeg']['audio']['layer'] == 'I') { + $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32=>0, 64=>0, 96=>0, 128=>0, 160=>0, 192=>0, 224=>0, 256=>0, 288=>0, 320=>0, 352=>0, 384=>0, 416=>0, 448=>0); + } + } elseif ($ThisFileInfo['mpeg']['audio']['layer'] == 'I') { + $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32=>0, 48=>0, 56=>0, 64=>0, 80=>0, 96=>0, 112=>0, 128=>0, 144=>0, 160=>0, 176=>0, 192=>0, 224=>0, 256=>0); + } else { + $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 8=>0, 16=>0, 24=>0, 32=>0, 40=>0, 48=>0, 56=>0, 64=>0, 80=>0, 96=>0, 112=>0, 128=>0, 144=>0, 160=>0); + } + + $dummy = array('error'=>$ThisFileInfo['error'], 'warning'=>$ThisFileInfo['warning'], 'avdataend'=>$ThisFileInfo['avdataend'], 'avdataoffset'=>$ThisFileInfo['avdataoffset']); + $synchstartoffset = $ThisFileInfo['avdataoffset']; + + $FastMode = false; + while (decodeMPEGaudioHeader($fd, $synchstartoffset, $dummy, false, false, $FastMode)) { + $FastMode = true; + $thisframebitrate = $MPEGaudioBitrateLookup[$MPEGaudioVersionLookup[$dummy['mpeg']['audio']['raw']['version']]][$MPEGaudioLayerLookup[$dummy['mpeg']['audio']['raw']['layer']]][$dummy['mpeg']['audio']['raw']['bitrate']]; + + $ThisFileInfo['mpeg']['audio']['bitrate_distribution'][$thisframebitrate]++; + $ThisFileInfo['mpeg']['audio']['stereo_distribution'][$dummy['mpeg']['audio']['channelmode']]++; + $ThisFileInfo['mpeg']['audio']['version_distribution'][$dummy['mpeg']['audio']['version']]++; + if (empty($dummy['mpeg']['audio']['framelength'])) { + $ThisFileInfo['warning'] .= "\n".'Invalid/missing framelength in histogram analysis - aborting'; +$synchstartoffset += 4; +// return false; + } + $synchstartoffset += $dummy['mpeg']['audio']['framelength']; + } + + $bittotal = 0; + $framecounter = 0; + foreach ($ThisFileInfo['mpeg']['audio']['bitrate_distribution'] as $bitratevalue => $bitratecount) { + $framecounter += $bitratecount; + if ($bitratevalue != 'free') { + $bittotal += ($bitratevalue * $bitratecount); + } + } + if ($framecounter == 0) { + $ThisFileInfo['error'] .= "\n".'Corrupt MP3 file: framecounter == zero'; + return false; + } + $ThisFileInfo['mpeg']['audio']['frame_count'] = $framecounter; + $ThisFileInfo['mpeg']['audio']['bitrate'] = 1000 * ($bittotal / $framecounter); + + $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate']; + + + // Definitively set VBR vs CBR, even if the Xing/LAME/VBRI header says differently + $distinct_bitrates = 0; + foreach ($ThisFileInfo['mpeg']['audio']['bitrate_distribution'] as $bitrate_value => $bitrate_count) { + if ($bitrate_count > 0) { + $distinct_bitrates++; + } + } + if ($distinct_bitrates > 1) { + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'vbr'; + } else { + $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'cbr'; + } + $ThisFileInfo['audio']['bitrate_mode'] = $ThisFileInfo['mpeg']['audio']['bitrate_mode']; + + } + + break; // exit while() + } + } + + $SynchSeekOffset++; + if (($avdataoffset + $SynchSeekOffset) >= $ThisFileInfo['avdataend']) { + // end of file/data + + if (empty($ThisFileInfo['mpeg']['audio'])) { + + $ThisFileInfo['error'] .= "\n".'could not find valid MPEG synch before end of file'; + if (isset($ThisFileInfo['audio']['bitrate'])) { + unset($ThisFileInfo['audio']['bitrate']); + } + if (isset($ThisFileInfo['mpeg']['audio'])) { + unset($ThisFileInfo['mpeg']['audio']); + } + if (isset($ThisFileInfo['mpeg']) && (!is_array($ThisFileInfo['mpeg']) || empty($ThisFileInfo['mpeg']))) { + unset($ThisFileInfo['mpeg']); + } + return false; + + } + break; + } + + } + $ThisFileInfo['audio']['bits_per_sample'] = 16; + $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels']; + $ThisFileInfo['audio']['channelmode'] = $ThisFileInfo['mpeg']['audio']['channelmode']; + $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate']; + return true; +} + + +function MPEGaudioVersionArray() { + static $MPEGaudioVersion = array('2.5', false, '2', '1'); + return $MPEGaudioVersion; +} + +function MPEGaudioLayerArray() { + static $MPEGaudioLayer = array(false, 'III', 'II', 'I'); + return $MPEGaudioLayer; +} + +function MPEGaudioBitrateArray() { + static $MPEGaudioBitrate; + if (empty($MPEGaudioBitrate)) { + $MPEGaudioBitrate['1']['I'] = array('free', 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448); + $MPEGaudioBitrate['1']['II'] = array('free', 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384); + $MPEGaudioBitrate['1']['III'] = array('free', 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320); + $MPEGaudioBitrate['2']['I'] = array('free', 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256); + $MPEGaudioBitrate['2']['II'] = array('free', 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160); + $MPEGaudioBitrate['2']['III'] = $MPEGaudioBitrate['2']['II']; + $MPEGaudioBitrate['2.5']['I'] = $MPEGaudioBitrate['2']['I']; + $MPEGaudioBitrate['2.5']['II'] = $MPEGaudioBitrate['2']['II']; + $MPEGaudioBitrate['2.5']['III'] = $MPEGaudioBitrate['2']['III']; + } + return $MPEGaudioBitrate; +} + +function MPEGaudioFrequencyArray() { + static $MPEGaudioFrequency; + if (empty($MPEGaudioFrequency)) { + $MPEGaudioFrequency['1'] = array(44100, 48000, 32000); + $MPEGaudioFrequency['2'] = array(22050, 24000, 16000); + $MPEGaudioFrequency['2.5'] = array(11025, 12000, 8000); + } + return $MPEGaudioFrequency; +} + +function MPEGaudioChannelModeArray() { + static $MPEGaudioChannelMode = array('stereo', 'joint stereo', 'dual channel', 'mono'); + return $MPEGaudioChannelMode; +} + +function MPEGaudioModeExtensionArray() { + static $MPEGaudioModeExtension; + if (empty($MPEGaudioModeExtension)) { + $MPEGaudioModeExtension['I'] = array('4-31', '8-31', '12-31', '16-31'); + $MPEGaudioModeExtension['II'] = array('4-31', '8-31', '12-31', '16-31'); + $MPEGaudioModeExtension['III'] = array('', 'IS', 'MS', 'IS+MS'); + } + return $MPEGaudioModeExtension; +} + +function MPEGaudioEmphasisArray() { + static $MPEGaudioEmphasis = array('none', '50/15ms', false, 'CCIT J.17'); + return $MPEGaudioEmphasis; +} + + +function MPEGaudioHeaderBytesValid($head4) { + return MPEGaudioHeaderValid(MPEGaudioHeaderDecode($head4)); +} + +function MPEGaudioHeaderValid($rawarray, $echoerrors=false) { + + if (($rawarray['synch'] & 0x0FFE) != 0x0FFE) { + return false; + } + + static $MPEGaudioVersionLookup; + static $MPEGaudioLayerLookup; + static $MPEGaudioBitrateLookup; + static $MPEGaudioFrequencyLookup; + static $MPEGaudioChannelModeLookup; + static $MPEGaudioModeExtensionLookup; + static $MPEGaudioEmphasisLookup; + if (empty($MPEGaudioVersionLookup)) { + $MPEGaudioVersionLookup = MPEGaudioVersionArray(); + $MPEGaudioLayerLookup = MPEGaudioLayerArray(); + $MPEGaudioBitrateLookup = MPEGaudioBitrateArray(); + $MPEGaudioFrequencyLookup = MPEGaudioFrequencyArray(); + $MPEGaudioChannelModeLookup = MPEGaudioChannelModeArray(); + $MPEGaudioModeExtensionLookup = MPEGaudioModeExtensionArray(); + $MPEGaudioEmphasisLookup = MPEGaudioEmphasisArray(); + } + + if (isset($MPEGaudioVersionLookup[$rawarray['version']])) { + $decodedVersion = $MPEGaudioVersionLookup[$rawarray['version']]; + } else { + if ($echoerrors) { + echo "\n".'invalid Version ('.$rawarray['version'].')'; + } + return false; + } + if (isset($MPEGaudioLayerLookup[$rawarray['layer']])) { + $decodedLayer = $MPEGaudioLayerLookup[$rawarray['layer']]; + } else { + if ($echoerrors) { + echo "\n".'invalid Layer ('.$rawarray['layer'].')'; + } + return false; + } + if (!isset($MPEGaudioBitrateLookup[$decodedVersion][$decodedLayer][$rawarray['bitrate']])) { + if ($echoerrors) { + echo "\n".'invalid Bitrate ('.$rawarray['bitrate'].')'; + } + if ($rawarray['bitrate'] == 15) { + // known issue in LAME 3.90 - 3.93.1 where free-format has bitrate ID of 15 instead of 0 + // let it go through here otherwise file will not be identified + } else { + return false; + } + } + if (!isset($MPEGaudioFrequencyLookup[$decodedVersion][$rawarray['sample_rate']])) { + if ($echoerrors) { + echo "\n".'invalid Frequency ('.$rawarray['sample_rate'].')'; + } + return false; + } + if (!isset($MPEGaudioChannelModeLookup[$rawarray['channelmode']])) { + if ($echoerrors) { + echo "\n".'invalid ChannelMode ('.$rawarray['channelmode'].')'; + } + return false; + } + if (!isset($MPEGaudioModeExtensionLookup[$decodedLayer][$rawarray['modeextension']])) { + if ($echoerrors) { + echo "\n".'invalid Mode Extension ('.$rawarray['modeextension'].')'; + } + return false; + } + if (!isset($MPEGaudioEmphasisLookup[$rawarray['emphasis']])) { + if ($echoerrors) { + echo "\n".'invalid Emphasis ('.$rawarray['emphasis'].')'; + } + return false; + } + // These are just either set or not set, you can't mess that up :) + // $rawarray['protection']; + // $rawarray['padding']; + // $rawarray['private']; + // $rawarray['copyright']; + // $rawarray['original']; + + return true; +} + +function MPEGaudioHeaderDecode($Header4Bytes) { + // AAAA AAAA AAAB BCCD EEEE FFGH IIJJ KLMM + // A - Frame sync (all bits set) + // B - MPEG Audio version ID + // C - Layer description + // D - Protection bit + // E - Bitrate index + // F - Sampling rate frequency index + // G - Padding bit + // H - Private bit + // I - Channel Mode + // J - Mode extension (Only if Joint stereo) + // K - Copyright + // L - Original + // M - Emphasis + + if (strlen($Header4Bytes) != 4) { + return false; + } + + $MPEGrawHeader['synch'] = (BigEndian2Int(substr($Header4Bytes, 0, 2)) & 0xFFE0) >> 4; + $MPEGrawHeader['version'] = (ord($Header4Bytes[1]) & 0x18) >> 3; // BB + $MPEGrawHeader['layer'] = (ord($Header4Bytes[1]) & 0x06) >> 1; // CC + $MPEGrawHeader['protection'] = (ord($Header4Bytes[1]) & 0x01); // D + $MPEGrawHeader['bitrate'] = (ord($Header4Bytes[2]) & 0xF0) >> 4; // EEEE + $MPEGrawHeader['sample_rate'] = (ord($Header4Bytes[2]) & 0x0C) >> 2; // FF + $MPEGrawHeader['padding'] = (ord($Header4Bytes[2]) & 0x02) >> 1; // G + $MPEGrawHeader['private'] = (ord($Header4Bytes[2]) & 0x01); // H + $MPEGrawHeader['channelmode'] = (ord($Header4Bytes[3]) & 0xC0) >> 6; // II + $MPEGrawHeader['modeextension'] = (ord($Header4Bytes[3]) & 0x30) >> 4; // JJ + $MPEGrawHeader['copyright'] = (ord($Header4Bytes[3]) & 0x08) >> 3; // K + $MPEGrawHeader['original'] = (ord($Header4Bytes[3]) & 0x04) >> 2; // L + $MPEGrawHeader['emphasis'] = (ord($Header4Bytes[3]) & 0x03); // MM + + return $MPEGrawHeader; +} + +function MPEGaudioFrameLength(&$bitrate, &$version, &$layer, $padding, &$samplerate) { + static $AudioFrameLengthCache = array(); + + if (!isset($AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate])) { + $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = false; + if ($bitrate != 'free') { + + if ($version == '1') { + + if ($layer == 'I') { + + // For Layer I slot is 32 bits long + $FrameLengthCoefficient = 48; + $SlotLength = 4; + + } else { // Layer II / III + + // for Layer II and Layer III slot is 8 bits long. + $FrameLengthCoefficient = 144; + $SlotLength = 1; + + } + + } else { // MPEG-2 / MPEG-2.5 + + if ($layer == 'I') { + + // For Layer I slot is 32 bits long + $FrameLengthCoefficient = 24; + $SlotLength = 4; + + } elseif ($layer == 'II') { + + // for Layer II and Layer III slot is 8 bits long. + $FrameLengthCoefficient = 144; + $SlotLength = 1; + + } else { // III + + // for Layer II and Layer III slot is 8 bits long. + $FrameLengthCoefficient = 72; + $SlotLength = 1; + + } + + } + + // FrameLengthInBytes = ((Coefficient * BitRate) / SampleRate) + Padding + // http://66.96.216.160/cgi-bin/YaBB.pl?board=c&action=display&num=1018474068 + // -> [Finding the next frame synch] on www.r3mix.net forums if the above link goes dead + if ($samplerate > 0) { + $NewFramelength = ($FrameLengthCoefficient * $bitrate * 1000) / $samplerate; + $NewFramelength = floor($NewFramelength / $SlotLength) * $SlotLength; // round to next-lower multiple of SlotLength (1 byte for Layer II/III, 4 bytes for Layer I) + if ($padding) { + $NewFramelength += $SlotLength; + } + $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = (int) $NewFramelength; + } + } + } + return $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate]; +} + +function LAMEvbrMethodLookup($VBRmethodID) { + static $LAMEvbrMethodLookup = array(); + if (empty($LAMEvbrMethodLookup)) { + $LAMEvbrMethodLookup[0x00] = 'unknown'; + $LAMEvbrMethodLookup[0x01] = 'cbr'; + $LAMEvbrMethodLookup[0x02] = 'abr'; + $LAMEvbrMethodLookup[0x03] = 'vbr-old / vbr-rh'; + $LAMEvbrMethodLookup[0x04] = 'vbr-mtrh'; + $LAMEvbrMethodLookup[0x05] = 'vbr-new / vbr-mt'; + } + return (isset($LAMEvbrMethodLookup[$VBRmethodID]) ? $LAMEvbrMethodLookup[$VBRmethodID] : ''); +} + +function LAMEmiscStereoModeLookup($StereoModeID) { + static $LAMEmiscStereoModeLookup = array(); + if (empty($LAMEmiscStereoModeLookup)) { + $LAMEmiscStereoModeLookup[0] = 'mono'; + $LAMEmiscStereoModeLookup[1] = 'stereo'; + $LAMEmiscStereoModeLookup[2] = 'dual'; + $LAMEmiscStereoModeLookup[3] = 'joint'; + $LAMEmiscStereoModeLookup[4] = 'forced'; + $LAMEmiscStereoModeLookup[5] = 'auto'; + $LAMEmiscStereoModeLookup[6] = 'intensity'; + $LAMEmiscStereoModeLookup[7] = 'other'; + } + return (isset($LAMEmiscStereoModeLookup[$StereoModeID]) ? $LAMEmiscStereoModeLookup[$StereoModeID] : ''); +} + +function LAMEmiscSourceSampleFrequencyLookup($SourceSampleFrequencyID) { + static $LAMEmiscSourceSampleFrequencyLookup = array(); + if (empty($LAMEmiscSourceSampleFrequencyLookup)) { + $LAMEmiscSourceSampleFrequencyLookup[0] = '<= 32 kHz'; + $LAMEmiscSourceSampleFrequencyLookup[1] = '44.1 kHz'; + $LAMEmiscSourceSampleFrequencyLookup[2] = '48 kHz'; + $LAMEmiscSourceSampleFrequencyLookup[3] = '> 48kHz'; + } + return (isset($LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID]) ? $LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID] : ''); +} + +function LAMEsurroundInfoLookup($SurroundInfoID) { + static $LAMEsurroundInfoLookup = array(); + if (empty($LAMEsurroundInfoLookup)) { + $LAMEsurroundInfoLookup[0] = 'no surround info'; + $LAMEsurroundInfoLookup[1] = 'DPL encoding'; + $LAMEsurroundInfoLookup[2] = 'DPL2 encoding'; + $LAMEsurroundInfoLookup[3] = 'Ambisonic encoding'; + } + return (isset($LAMEsurroundInfoLookup[$SurroundInfoID]) ? $LAMEsurroundInfoLookup[$SurroundInfoID] : 'reserved'); +} + +for ($i = 0x00; $i <= 0xFF; $i++) { + $head4 = "\xFF\xFE".chr($i)."\x00"; + $isvalid = MPEGaudioHeaderBytesValid($head4); + echo '
'.str_pad(strtoupper(dechex($i)), 2, '0', STR_PAD_LEFT).' = '.htmlentities(chr($i)).' = '.($isvalid ? 'valid' : 'INVALID').'
'; +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.mysqli.php b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.mysqli.php new file mode 100644 index 00000000..c0ab530d --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.mysqli.php @@ -0,0 +1,2208 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// /demo/demo.mysqli.php - part of getID3() // +// Sample script for recursively scanning directories and // +// storing the results in a database // +// see readme.txt for more details // +// updated to mysqli by sarang /// +///////////////////////////////////////////////////////////////// + +die('Due to a security issue, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__)); + + +// OPTIONS: +$getid3_demo_mysqli_encoding_getid3 = 'UTF-8'; +$getid3_demo_mysqli_encoding_mysqli = 'utf8'; // https://dev.mysql.com/doc/refman/8.0/en/charset-charsets.html +$getid3_demo_mysqli_md5_data = false; // All data hashes are by far the slowest part of scanning, recommended to leave disabled +$getid3_demo_mysqli_md5_file = false; + +define('GETID3_DB_HOST', 'localhost'); +define('GETID3_DB_USER', 'root'); +define('GETID3_DB_PASS', 'password'); +define('GETID3_DB_DB', 'getid3'); +define('GETID3_DB_TABLE', 'files'); + +// CREATE DATABASE `getid3`; + +ob_start(); +if ($con = mysqli_connect(GETID3_DB_HOST, GETID3_DB_USER, GETID3_DB_PASS)){ + // great +} else { + $errormessage = ob_get_contents(); + ob_end_clean(); + die('Could not connect to MySQL host:
'.mysqli_error($con).'
'); +} + +if (mysqli_select_db($con, GETID3_DB_DB)){ + // great +} else { + $errormessage = ob_get_contents(); + ob_end_clean(); + die('Could not select database:
'.mysqli_error($con).'
'); +} +ob_end_clean(); + +if (!mysqli_set_charset($con, $getid3_demo_mysqli_encoding_mysqli)) { + die('Could not mysqli_set_charset('.htmlentities($getid3_demo_mysqli_encoding_mysqli).')'); +} + +$getid3PHP_filename = realpath('../getid3/getid3.php'); +if (!file_exists($getid3PHP_filename) || !include_once($getid3PHP_filename)) { + die('Cannot open '.$getid3PHP_filename); +} +// Initialize getID3 engine +$getID3 = new getID3; +$getID3->setOption(array( + 'option_md5_data' => $getid3_demo_mysqli_md5_data, + 'encoding' => $getid3_demo_mysqli_encoding_getid3, +)); + + +function RemoveAccents($string) { + // Revised version by markstewardØhotmail*com + return strtr(strtr($string, 'ŠŽšžŸÀÃÂÃÄÅÇÈÉÊËÌÃÃŽÃÑÒÓÔÕÖØÙÚÛÜÃàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'), array('Þ' => 'TH', 'þ' => 'th', 'Ã' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'ÂŒ' => 'OE', 'Âœ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u')); +} + +function BitrateColor($bitrate, $BitrateMaxScale=768) { + // $BitrateMaxScale is bitrate of maximum-quality color (bright green) + // below this is gradient, above is solid green + + $bitrate *= (256 / $BitrateMaxScale); // scale from 1-[768]kbps to 1-256 + $bitrate = round(min(max($bitrate, 1), 256)); + $bitrate--; // scale from 1-256kbps to 0-255kbps + + $Rcomponent = max(255 - ($bitrate * 2), 0); + $Gcomponent = max(($bitrate * 2) - 255, 0); + if ($bitrate > 127) { + $Bcomponent = max((255 - $bitrate) * 2, 0); + } else { + $Bcomponent = max($bitrate * 2, 0); + } + return str_pad(dechex($Rcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Gcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Bcomponent), 2, '0', STR_PAD_LEFT); +} + +function BitrateText($bitrate, $decimals=0) { + return ''.number_format($bitrate, $decimals).' kbps'; +} + +function fileextension($filename, $numextensions=1) { + if (strstr($filename, '.')) { + $reversedfilename = strrev($filename); + $offset = 0; + for ($i = 0; $i < $numextensions; $i++) { + $offset = strpos($reversedfilename, '.', $offset + 1); + if ($offset === false) { + return ''; + } + } + return strrev(substr($reversedfilename, 0, $offset)); + } + return ''; +} + +function RenameFileFromTo($from, $to, &$results) { + $success = true; + if ($from === $to) { + $results = 'Source and Destination filenames identical
FAILED to rename'; + } elseif (!file_exists($from)) { + $results = 'Source file does not exist
FAILED to rename'; + } elseif (file_exists($to) && (strtolower($from) !== strtolower($to))) { + $results = 'Destination file already exists
FAILED to rename'; + } else { + ob_start(); + if (rename($from, $to)) { + ob_end_clean(); + $SQLquery = 'DELETE'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $from).'")'; + mysqli_query_safe($con, $SQLquery); + $results = 'Successfully renamed'; + } else { + $errormessage = ob_get_contents(); + ob_end_clean(); + $results = '
FAILED to rename'; + $success = false; + } + } + $results .= ' from:
'.$from.'
to:
'.$to.'

'; + return $success; +} + +if (!empty($_REQUEST['renamefilefrom']) && !empty($_REQUEST['renamefileto'])) { + + $results = ''; + RenameFileFromTo($_REQUEST['renamefilefrom'], $_REQUEST['renamefileto'], $results); + echo $results; + exit; + +} elseif (!empty($_REQUEST['m3ufilename'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + echo WindowsShareSlashTranslate($_REQUEST['m3ufilename'])."\n"; + exit; + +} elseif (!isset($_REQUEST['m3u']) && !isset($_REQUEST['m3uartist']) && !isset($_REQUEST['m3utitle'])) { + + echo ''; + echo 'getID3() demo - /demo/mysql.php'; + +} + + +function WindowsShareSlashTranslate($filename) { + if (substr($filename, 0, 2) == '//') { + return str_replace('/', '\\', $filename); + } + return $filename; +} + +function mysqli_query_safe($con, $SQLquery) { + static $TimeSpentQuerying = 0; + if ($SQLquery === null) { + return $TimeSpentQuerying; + } + $starttime = microtime(true); + $result = mysqli_query($con, $SQLquery); + $TimeSpentQuerying += (microtime(true) - $starttime); + if (mysqli_error($con)) { + die('
SQL error:
'.htmlentities(mysqli_error($con)).'

'.htmlentities($SQLquery, ENT_SUBSTITUTE).'
'); + } + return $result; +} + +function mysqli_table_exists($con, $tablename) { + return (bool) mysqli_query($con, 'DESCRIBE '.$tablename); +} + +function AcceptableExtensions($fileformat, $audio_dataformat='', $video_dataformat='') { + static $AcceptableExtensionsAudio = array(); + if (empty($AcceptableExtensionsAudio)) { + $AcceptableExtensionsAudio['mp3']['mp3'] = array('mp3'); + $AcceptableExtensionsAudio['mp2']['mp2'] = array('mp2'); + $AcceptableExtensionsAudio['mp1']['mp1'] = array('mp1'); + $AcceptableExtensionsAudio['asf']['asf'] = array('asf'); + $AcceptableExtensionsAudio['asf']['wma'] = array('wma'); + $AcceptableExtensionsAudio['riff']['mp3'] = array('wav'); + $AcceptableExtensionsAudio['riff']['wav'] = array('wav'); + } + static $AcceptableExtensionsVideo = array(); + if (empty($AcceptableExtensionsVideo)) { + $AcceptableExtensionsVideo['mp3']['mp3'] = array('mp3'); + $AcceptableExtensionsVideo['mp2']['mp2'] = array('mp2'); + $AcceptableExtensionsVideo['mp1']['mp1'] = array('mp1'); + $AcceptableExtensionsVideo['asf']['asf'] = array('asf'); + $AcceptableExtensionsVideo['asf']['wmv'] = array('wmv'); + $AcceptableExtensionsVideo['gif']['gif'] = array('gif'); + $AcceptableExtensionsVideo['jpg']['jpg'] = array('jpg'); + $AcceptableExtensionsVideo['png']['png'] = array('png'); + $AcceptableExtensionsVideo['bmp']['bmp'] = array('bmp'); + } + if (!empty($video_dataformat)) { + return (isset($AcceptableExtensionsVideo[$fileformat][$video_dataformat]) ? $AcceptableExtensionsVideo[$fileformat][$video_dataformat] : array()); + } else { + return (isset($AcceptableExtensionsAudio[$fileformat][$audio_dataformat]) ? $AcceptableExtensionsAudio[$fileformat][$audio_dataformat] : array()); + } +} + + +if (!empty($_REQUEST['scan'])) { + if (mysqli_table_exists($con, GETID3_DB_TABLE)) { + $SQLquery = 'DROP TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + mysqli_query_safe($con, $SQLquery); + } +} +if (!mysqli_table_exists($con, GETID3_DB_TABLE)) { + $SQLquery = "CREATE TABLE `".mysqli_real_escape_string($con, GETID3_DB_TABLE)."` ("; + $SQLquery .= "`ID` int(11) unsigned NOT NULL auto_increment"; + $SQLquery .= ", `filename` text NOT NULL"; + $SQLquery .= ", `last_modified` int(11) NOT NULL default '0'"; + $SQLquery .= ", `md5_file` varchar(32) NOT NULL default ''"; + $SQLquery .= ", `md5_data` varchar(32) NOT NULL default ''"; + $SQLquery .= ", `md5_data_source` varchar(32) NOT NULL default ''"; + $SQLquery .= ", `filesize` int(10) unsigned NOT NULL default '0'"; + $SQLquery .= ", `fileformat` varchar(255) NOT NULL default ''"; + $SQLquery .= ", `audio_dataformat` varchar(255) NOT NULL default ''"; + $SQLquery .= ", `video_dataformat` varchar(255) NOT NULL default ''"; + $SQLquery .= ", `audio_bitrate` float NOT NULL default '0'"; + $SQLquery .= ", `video_bitrate` float NOT NULL default '0'"; + $SQLquery .= ", `playtime_seconds` varchar(255) NOT NULL default ''"; + $SQLquery .= ", `tags` varchar(255) NOT NULL default ''"; + $SQLquery .= ", `artist` varchar(255) NOT NULL default ''"; + $SQLquery .= ", `title` varchar(255) NOT NULL default ''"; + $SQLquery .= ", `remix` varchar(255) NOT NULL default ''"; + $SQLquery .= ", `album` varchar(255) NOT NULL default ''"; + $SQLquery .= ", `genre` varchar(255) NOT NULL default ''"; + $SQLquery .= ", `comment` text NOT NULL"; + $SQLquery .= ", `track` varchar(7) NOT NULL default ''"; + $SQLquery .= ", `comments_all` longblob NOT NULL"; + $SQLquery .= ", `comments_id3v2` longblob NOT NULL"; + $SQLquery .= ", `comments_ape` longblob NOT NULL"; + $SQLquery .= ", `comments_lyrics3` longblob NOT NULL"; + $SQLquery .= ", `comments_id3v1` blob NOT NULL"; + $SQLquery .= ", `warning` longtext NOT NULL"; + $SQLquery .= ", `error` longtext NOT NULL"; + $SQLquery .= ", `track_volume` float NOT NULL default '0'"; + $SQLquery .= ", `encoder_options` varchar(255) NOT NULL default ''"; + $SQLquery .= ", `vbr_method` varchar(255) NOT NULL default ''"; + $SQLquery .= ", PRIMARY KEY (`ID`)"; + $SQLquery .= ")"; + mysqli_query_safe($con, $SQLquery); +} + +$ExistingTableFields = array(); +$result = mysqli_query_safe($con, 'DESCRIBE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'); +while ($row = mysqli_fetch_array($result)) { + $ExistingTableFields[$row['Field']] = $row; +} +if (!isset($ExistingTableFields['encoder_options'])) { // Added in 1.7.0b2 + echo 'adding field `encoder_options`
'; + mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `encoder_options` VARCHAR(255) default "" NOT NULL AFTER `error`'); + mysqli_query_safe($con, 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'); +} +if (isset($ExistingTableFields['track']) && ($ExistingTableFields['track']['Type'] != 'varchar(7)')) { // Changed in 1.7.0b2 + echo 'changing field `track` to VARCHAR(7)
'; + mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `track` `track` VARCHAR(7) default "" NOT NULL'); + mysqli_query_safe($con, 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'); +} +if (!isset($ExistingTableFields['track_volume'])) { // Added in 1.7.0b5 + echo '

WARNING! You should erase your database and rescan everything because the comment storing has been changed since the last version


'; + echo 'adding field `track_volume`
'; + mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `track_volume` FLOAT NOT NULL AFTER `error`'); + mysqli_query_safe($con, 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'); +} +if (!isset($ExistingTableFields['remix'])) { // Added in 1.7.3b1 + echo 'adding field `encoder_options`, `alternate_name`, `parody`
'; + mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `remix` VARCHAR(255) default "" NOT NULL AFTER `title`'); + mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `alternate_name` VARCHAR(255) default "" NOT NULL AFTER `track`'); + mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `parody` VARCHAR(255) default "" NOT NULL AFTER `alternate_name`'); + mysqli_query_safe($con, 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'); +} +if (isset($ExistingTableFields['comments_all']) && ($ExistingTableFields['comments_all']['Type'] != 'longblob')) { // Changed to "longtext" in 1.9.0, changed to "longblob" in 1.9.20-202010140821 + echo 'changing comments fields from text to longtext
'; + // no need to change id3v1 + mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_all` `comments_all` LONGBLOB NOT NULL'); + mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_id3v2` `comments_id3v2` LONGBLOB NOT NULL'); + mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_ape` `comments_ape` LONGBLOB NOT NULL'); + mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_lyrics3` `comments_lyrics3` LONGBLOB NOT NULL'); + mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_id3v1` `comments_id3v1` BLOB NOT NULL'); + mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `warning` `warning` LONGTEXT NOT NULL'); + mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `error` `error` LONGTEXT NOT NULL'); +} + + +function SynchronizeAllTags($filename, $synchronizefrom='all', $synchronizeto='A12', &$errors = array()) { + global $getID3; + + set_time_limit(30); + + $ThisFileInfo = $getID3->analyze($filename); + $getID3->CopyTagsToComments($ThisFileInfo); + + if ($synchronizefrom == 'all') { + $SourceArray = (!empty($ThisFileInfo['comments']) ? $ThisFileInfo['comments'] : array()); + } elseif (!empty($ThisFileInfo['tags'][$synchronizefrom])) { + $SourceArray = (!empty($ThisFileInfo['tags'][$synchronizefrom]) ? $ThisFileInfo['tags'][$synchronizefrom] : array()); + } else { + die('ERROR: $ThisFileInfo[tags]['.$synchronizefrom.'] does not exist'); + } + + $SQLquery = 'DELETE'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $filename).'")'; + mysqli_query_safe($con, $SQLquery); + + + $TagFormatsToWrite = array(); + if ((strpos($synchronizeto, '2') !== false) && ($synchronizefrom != 'id3v2')) { + $TagFormatsToWrite[] = 'id3v2.3'; + } + if ((strpos($synchronizeto, 'A') !== false) && ($synchronizefrom != 'ape')) { + $TagFormatsToWrite[] = 'ape'; + } + if ((strpos($synchronizeto, 'L') !== false) && ($synchronizefrom != 'lyrics3')) { + $TagFormatsToWrite[] = 'lyrics3'; + } + if ((strpos($synchronizeto, '1') !== false) && ($synchronizefrom != 'id3v1')) { + $TagFormatsToWrite[] = 'id3v1'; + } + + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.php', __FILE__, true); + $tagwriter = new getid3_writetags; + $tagwriter->filename = $filename; + $tagwriter->tagformats = $TagFormatsToWrite; + $tagwriter->overwrite_tags = true; + $tagwriter->tag_encoding = $getID3->encoding; + $tagwriter->tag_data = $SourceArray; + + if ($tagwriter->WriteTags()) { + $errors = $tagwriter->errors; + return true; + } + $errors = $tagwriter->errors; + return false; +} + +$IgnoreNoTagFormats = array('', 'png', 'jpg', 'gif', 'bmp', 'swf', 'pdf', 'zip', 'rar', 'mid', 'mod', 'xm', 'it', 's3m'); + +if (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan']) || !empty($_REQUEST['rescanerrors'])) { + + $SQLquery = 'DELETE'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` = "")'; + mysqli_query_safe($con, $SQLquery); + + $FilesInDir = array(); + + if (!empty($_REQUEST['rescanerrors'])) { + + echo 'abort
'; + + echo 'Re-scanning all media files already in database that had errors and/or warnings in last scan
'; + + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`error` <> "")'; + $SQLquery .= ' OR (`warning` <> "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + while ($row = mysqli_fetch_array($result)) { + + if (!file_exists($row['filename'])) { + echo 'File missing: '.$row['filename'].'
'; + $SQLquery = 'DELETE'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $row['filename']).'")'; + mysqli_query_safe($con, $SQLquery); + } else { + $FilesInDir[] = $row['filename']; + } + + } + + } elseif (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan'])) { + + echo 'abort
'; + + echo 'Scanning all media files in '.str_replace('\\', '/', realpath(!empty($_REQUEST['scan']) ? $_REQUEST['scan'] : $_REQUEST['newscan'])).' (and subdirectories)
'; + + $SQLquery = 'SELECT COUNT(*) AS `num`, `filename`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' GROUP BY `filename`'; + $SQLquery .= ' HAVING (`num` > 1)'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = mysqli_query_safe($con, $SQLquery); + $DupesDeleted = 0; + while ($row = mysqli_fetch_array($result)) { + set_time_limit(30); + $SQLquery = 'DELETE'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE `filename` LIKE "'.mysqli_real_escape_string($con, $row['filename']).'"'; + mysqli_query_safe($con, $SQLquery); + $DupesDeleted++; + } + if ($DupesDeleted > 0) { + echo 'Deleted '.number_format($DupesDeleted).' duplicate filenames
'; + } + + if (!empty($_REQUEST['newscan'])) { + $AlreadyInDatabase = array(); + set_time_limit(60); + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + while ($row = mysqli_fetch_array($result)) { + //$AlreadyInDatabase[] = strtolower($row['filename']); + $AlreadyInDatabase[] = $row['filename']; + } + } + + $DirectoriesToScan = array(!empty($_REQUEST['scan']) ? $_REQUEST['scan'] : $_REQUEST['newscan']); + $DirectoriesScanned = array(); + while (count($DirectoriesToScan) > 0) { + foreach ($DirectoriesToScan as $DirectoryKey => $startingdir) { + if ($dir = opendir($startingdir)) { + set_time_limit(30); + echo ''.str_replace('\\', '/', $startingdir).'
'; + flush(); + while (($file = readdir($dir)) !== false) { + if (($file != '.') && ($file != '..')) { + $RealPathName = realpath($startingdir.'/'.$file); + if (is_dir($RealPathName)) { + if (!in_array($RealPathName, $DirectoriesScanned) && !in_array($RealPathName, $DirectoriesToScan)) { + $DirectoriesToScan[] = $RealPathName; + } + } elseif (is_file($RealPathName)) { + if (!empty($_REQUEST['newscan'])) { + if (!in_array(str_replace('\\', '/', $RealPathName), $AlreadyInDatabase)) { + $FilesInDir[] = $RealPathName; + } + } elseif (!empty($_REQUEST['scan'])) { + $FilesInDir[] = $RealPathName; + } + } + } + } + closedir($dir); + } else { + echo '
Failed to open directory "'.htmlentities($startingdir).'"

'; + } + $DirectoriesScanned[] = $startingdir; + unset($DirectoriesToScan[$DirectoryKey]); + } + } + echo 'List of files to scan complete (added '.number_format(count($FilesInDir)).' files to scan)
'; + flush(); + } + + $FilesInDir = array_unique($FilesInDir); + sort($FilesInDir); + + $starttime = time(); + $rowcounter = 0; + $totaltoprocess = count($FilesInDir); + + foreach ($FilesInDir as $filename) { + set_time_limit(300); + + echo '
'.date('H:i:s').' ['.number_format(++$rowcounter).' / '.number_format($totaltoprocess).'] '.str_replace('\\', '/', $filename); + + $ThisFileInfo = $getID3->analyze($filename); + $getID3->CopyTagsToComments($ThisFileInfo); + + if (file_exists($filename)) { + $ThisFileInfo['file_modified_time'] = filemtime($filename); + $ThisFileInfo['md5_file'] = ($getid3_demo_mysqli_md5_file ? md5_file($filename) : ''); + } + + if (empty($ThisFileInfo['fileformat'])) { + + echo ' (unknown file type)'; + + } else { + + if (!empty($ThisFileInfo['error'])) { + echo ' (errors)'; + } elseif (!empty($ThisFileInfo['warning'])) { + echo ' (warnings)'; + } else { + echo ' (OK)'; + } + + $this_track_track = ''; + if (!empty($ThisFileInfo['comments']['track_number'])) { + foreach ($ThisFileInfo['comments']['track_number'] as $key => $value) { + if (strlen($value) > strlen($this_track_track)) { + $this_track_track = str_pad($value, 2, '0', STR_PAD_LEFT); + } + } + if (preg_match('#^([0-9]+)/([0-9]+)$#', $this_track_track, $matches)) { + // change "1/5"->"01/05", "3/12"->"03/12", etc + $this_track_track = str_pad($matches[1], 2, '0', STR_PAD_LEFT).'/'.str_pad($matches[2], 2, '0', STR_PAD_LEFT); + } + } + + $this_track_remix = ''; + $this_track_title = ''; + if (!empty($ThisFileInfo['comments']['title'])) { + foreach ($ThisFileInfo['comments']['title'] as $possible_title) { + if (strlen($possible_title) > strlen($this_track_title)) { + $this_track_title = $possible_title; + } + } + } + + $ParenthesesPairs = array('()', '[]', '{}'); + foreach ($ParenthesesPairs as $pair) { + if (preg_match_all('/(.*) '.preg_quote($pair[0]).'(([^'.preg_quote($pair).']*[\- '.preg_quote($pair[0]).'])?(cut|dub|edit|version|live|reprise|[a-z]*mix))'.preg_quote($pair[1]).'/iU', $this_track_title, $matches)) { + $this_track_title = $matches[1][0]; + $this_track_remix = implode("\t", $matches[2]); + } + } + + + + if (!empty($_REQUEST['rescanerrors'])) { + + $SQLquery = 'UPDATE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` SET '; + $SQLquery .= ' `last_modified` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['file_modified_time'] ) ? $ThisFileInfo['file_modified_time'] : '').'"'; + $SQLquery .= ', `md5_file` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_file'] ) ? $ThisFileInfo['md5_file'] : '').'"'; + $SQLquery .= ', `md5_data` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_data'] ) ? $ThisFileInfo['md5_data'] : '').'"'; + $SQLquery .= ', `md5_data_source` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_data_source'] ) ? $ThisFileInfo['md5_data_source'] : '').'"'; + $SQLquery .= ', `filesize` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['filesize'] ) ? $ThisFileInfo['filesize'] : 0).'"'; + $SQLquery .= ', `fileformat` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['fileformat'] ) ? $ThisFileInfo['fileformat'] : '').'"'; + $SQLquery .= ', `audio_dataformat` = "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['audio']['dataformat'] ) ? $ThisFileInfo['audio']['dataformat'] : '').'"'; + $SQLquery .= ', `video_dataformat` = "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['video']['dataformat'] ) ? $ThisFileInfo['video']['dataformat'] : '').'"'; + $SQLquery .= ', `vbr_method` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['mpeg']['audio']['VBR_method'] ) ? $ThisFileInfo['mpeg']['audio']['VBR_method'] : '').'"'; + $SQLquery .= ', `audio_bitrate` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['audio']['bitrate'] ) ? floatval($ThisFileInfo['audio']['bitrate']) : 0).'"'; + $SQLquery .= ', `video_bitrate` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['video']['bitrate'] ) ? floatval($ThisFileInfo['video']['bitrate']) : 0).'"'; + $SQLquery .= ', `playtime_seconds` = "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['playtime_seconds'] ) ? floatval($ThisFileInfo['playtime_seconds']) : 0).'"'; + $SQLquery .= ', `track_volume` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['replay_gain']['track']['volume']) ? floatval($ThisFileInfo['replay_gain']['track']['volume']) : 0).'"'; + $SQLquery .= ', `comments_all` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments'] ) ? serialize($ThisFileInfo['comments']) : '').'"'; + $SQLquery .= ', `comments_id3v2` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['id3v2'] ) ? serialize($ThisFileInfo['tags']['id3v2']) : '').'"'; + $SQLquery .= ', `comments_ape` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['ape'] ) ? serialize($ThisFileInfo['tags']['ape']) : '').'"'; + $SQLquery .= ', `comments_lyrics3` = "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['lyrics3'] ) ? serialize($ThisFileInfo['tags']['lyrics3']) : '').'"'; + $SQLquery .= ', `comments_id3v1` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['id3v1'] ) ? serialize($ThisFileInfo['tags']['id3v1']) : '').'"'; + $SQLquery .= ', `warning` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['warning'] ) ? implode("\t", $ThisFileInfo['warning']) : '').'"'; + $SQLquery .= ', `error` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['error'] ) ? implode("\t", $ThisFileInfo['error']) : '').'"'; + $SQLquery .= ', `album` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['album'] ) ? implode("\t", $ThisFileInfo['comments']['album']) : '').'"'; + $SQLquery .= ', `genre` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['genre'] ) ? implode("\t", $ThisFileInfo['comments']['genre']) : '').'"'; + $SQLquery .= ', `comment` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['comment'] ) ? implode("\t", $ThisFileInfo['comments']['comment']) : '').'"'; + $SQLquery .= ', `artist` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['artist'] ) ? implode("\t", $ThisFileInfo['comments']['artist']) : '').'"'; + $SQLquery .= ', `tags` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['tags'] ) ? implode("\t", array_keys($ThisFileInfo['tags'])) : '').'"'; + $SQLquery .= ', `encoder_options` = "'. mysqli_real_escape_string($con, trim((!empty($ThisFileInfo['audio']['encoder']) ? $ThisFileInfo['audio']['encoder'] : '').' '.(!empty($ThisFileInfo['audio']['encoder_options']) ? $ThisFileInfo['audio']['encoder_options'] : ''))).'"'; + $SQLquery .= ', `title` = "'. mysqli_real_escape_string($con, $this_track_title).'"'; + $SQLquery .= ', `remix` = "'. mysqli_real_escape_string($con, $this_track_remix).'"'; + $SQLquery .= ', `track` = "'. mysqli_real_escape_string($con, $this_track_track).'"'; + $SQLquery .= ' WHERE (`filename` = "'. mysqli_real_escape_string($con, isset($ThisFileInfo['filenamepath']) ? $ThisFileInfo['filenamepath'] : '').'")'; + + } elseif (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan'])) { + + $SQLquery = 'INSERT INTO `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` (`filename`, `last_modified`, `md5_file`, `md5_data`, `md5_data_source`, `filesize`, `fileformat`, `audio_dataformat`, `video_dataformat`, `audio_bitrate`, `video_bitrate`, `playtime_seconds`, `tags`, `artist`, `title`, `remix`, `album`, `genre`, `comment`, `track`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`, `warning`, `error`, `track_volume`, `encoder_options`, `vbr_method`) VALUES ('; + $SQLquery .= '"'.mysqli_real_escape_string($con, !empty($ThisFileInfo['filenamepath'] ) ? $ThisFileInfo['filenamepath'] : '').'"'; // filename + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['file_modified_time'] ) ? $ThisFileInfo['file_modified_time'] : '').'"'; // last_modified + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_file'] ) ? $ThisFileInfo['md5_file'] : '').'"'; // md5_file + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_data'] ) ? $ThisFileInfo['md5_data'] : '').'"'; // md5_data + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_data_source'] ) ? $ThisFileInfo['md5_data_source'] : '').'"'; // md5_data_source + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['filesize'] ) ? $ThisFileInfo['filesize'] : 0).'"'; // filesize + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['fileformat'] ) ? $ThisFileInfo['fileformat'] : '').'"'; // fileformat + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['audio']['dataformat'] ) ? $ThisFileInfo['audio']['dataformat'] : '').'"'; // audio_dataformat + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['video']['dataformat'] ) ? $ThisFileInfo['video']['dataformat'] : '').'"'; // video_dataformat + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['audio']['bitrate'] ) ? floatval($ThisFileInfo['audio']['bitrate']) : 0).'"'; // audio_bitrate + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['video']['bitrate'] ) ? floatval($ThisFileInfo['video']['bitrate']) : 0).'"'; // video_bitrate + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['playtime_seconds'] ) ? floatval($ThisFileInfo['playtime_seconds']) : 0).'"'; // playtime_seconds + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags'] ) ? implode("\t", array_keys($ThisFileInfo['tags'])) : '').'"'; // tags + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['artist'] ) ? implode("\t", $ThisFileInfo['comments']['artist']) : '').'"'; // artist + $SQLquery .= ', "'.mysqli_real_escape_string($con, $this_track_title ).'"'; // title + $SQLquery .= ', "'.mysqli_real_escape_string($con, $this_track_remix ).'"'; // remix + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['album'] ) ? implode("\t", $ThisFileInfo['comments']['album']) : '').'"'; // album + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['genre'] ) ? implode("\t", $ThisFileInfo['comments']['genre']) : '').'"'; // genre + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['comment'] ) ? implode("\t", $ThisFileInfo['comments']['comment']) : '').'"'; // comment + $SQLquery .= ', "'.mysqli_real_escape_string($con, $this_track_track ).'"'; // track + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments'] ) ? serialize($ThisFileInfo['comments']) : '').'"'; // comments_all + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['id3v2'] ) ? serialize($ThisFileInfo['tags']['id3v2']) : '').'"'; // comments_id3v2 + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['ape'] ) ? serialize($ThisFileInfo['tags']['ape']) : '').'"'; // comments_ape + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['lyrics3'] ) ? serialize($ThisFileInfo['tags']['lyrics3']) : '').'"'; // comments_lyrics3 + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['id3v1'] ) ? serialize($ThisFileInfo['tags']['id3v1']) : '').'"'; // comments_id3v1 + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['warning'] ) ? implode("\t", $ThisFileInfo['warning']) : '').'"'; // warning + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['error'] ) ? implode("\t", $ThisFileInfo['error']) : '').'"'; // error + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['replay_gain']['track']['volume']) ? floatval($ThisFileInfo['replay_gain']['track']['volume']) : 0).'"'; // track_volume + $SQLquery .= ', "'.mysqli_real_escape_string($con, trim((!empty($ThisFileInfo['audio']['encoder']) ? $ThisFileInfo['audio']['encoder'] : '').' '.(!empty($ThisFileInfo['audio']['encoder_options']) ? $ThisFileInfo['audio']['encoder_options'] : ''))).'"'; // encoder_options + $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['mpeg']['audio']['LAME']) ? 'LAME' : (!empty($ThisFileInfo['mpeg']['audio']['VBR_method']) ? $ThisFileInfo['mpeg']['audio']['VBR_method'] : '')).'"'; // vbr_method + $SQLquery .= ')'; + } + flush(); + mysqli_query_safe($con, $SQLquery); + } + + } + + $SQLquery = 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + mysqli_query_safe($con, $SQLquery); + + echo '
Done scanning!
'; + +} elseif (!empty($_REQUEST['missingtrackvolume'])) { + + $MissingTrackVolumeFilesScanned = 0; + $MissingTrackVolumeFilesAdjusted = 0; + $MissingTrackVolumeFilesDeleted = 0; + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`track_volume` = 0)'; + $SQLquery .= ' AND (`audio_bitrate` > 0)'; + $result = mysqli_query_safe($con, $SQLquery); + echo 'Scanning 0 / '.number_format(mysqli_num_rows($result)).' files for track volume information:
'; + while ($row = mysqli_fetch_array($result)) { + set_time_limit(30); + echo '. '; + flush(); + if (file_exists($row['filename'])) { + + $ThisFileInfo = $getID3->analyze($row['filename']); + if (!empty($ThisFileInfo['replay_gain']['track']['volume'])) { + $MissingTrackVolumeFilesAdjusted++; + $SQLquery = 'UPDATE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' SET `track_volume` = "'.$ThisFileInfo['replay_gain']['track']['volume'].'"'; + $SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $row['filename']).'")'; + mysqli_query_safe($con, $SQLquery); + } + + } else { + + $MissingTrackVolumeFilesDeleted++; + $SQLquery = 'DELETE'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $row['filename']).'")'; + mysqli_query_safe($con, $SQLquery); + + } + } + echo '
Scanned '.number_format($MissingTrackVolumeFilesScanned).' files with no track volume information.
'; + echo 'Found track volume information for '.number_format($MissingTrackVolumeFilesAdjusted).' of them (could not find info for '.number_format($MissingTrackVolumeFilesScanned - $MissingTrackVolumeFilesAdjusted).' files; deleted '.number_format($MissingTrackVolumeFilesDeleted).' records of missing files)
'; + +} elseif (!empty($_REQUEST['deadfilescheck'])) { + + $SQLquery = 'SELECT COUNT(*) AS `num`, `filename`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' GROUP BY `filename`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = mysqli_query_safe($con, $SQLquery); + $DupesDeleted = 0; + while ($row = mysqli_fetch_array($result)) { + set_time_limit(30); + if ($row['num'] <= 1) { + break; + } + echo '
'.htmlentities($row['filename']).' (duplicate)'; + $SQLquery = 'DELETE'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE `filename` LIKE "'.mysqli_real_escape_string($con, $row['filename']).'"'; + mysqli_query_safe($con, $SQLquery); + $DupesDeleted++; + } + if ($DupesDeleted > 0) { + echo '
Deleted '.number_format($DupesDeleted).' duplicate filenames
'; + } + + $SQLquery = 'SELECT `filename`, `filesize`, `last_modified`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + $totalchecked = 0; + $totalremoved = 0; + $previousdir = ''; + while ($row = mysqli_fetch_array($result)) { + $totalchecked++; + set_time_limit(30); + $reason = ''; + if (!file_exists($row['filename'])) { + $reason = 'deleted'; + } elseif (filesize($row['filename']) != $row['filesize']) { + $reason = 'filesize changed'; + } elseif (filemtime($row['filename']) != $row['last_modified']) { + if (abs(filemtime($row['filename']) - $row['last_modified']) != 3600) { + // off by exactly one hour == daylight savings time + $reason = 'last-modified time changed'; + } + } + + $thisdir = dirname($row['filename']); + if ($reason) { + + $totalremoved++; + echo '
'.htmlentities($row['filename']).' ('.$reason.')'; + flush(); + $SQLquery = 'DELETE'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $row['filename']).'")'; + mysqli_query_safe($con, $SQLquery); + + } elseif ($thisdir != $previousdir) { + + echo '. '; + flush(); + + } + $previousdir = $thisdir; + } + + echo '
'.number_format($totalremoved).' of '.number_format($totalchecked).' files in database no longer exist, or have been altered since last scan. Removed from database.
'; + +} elseif (!empty($_REQUEST['encodedbydistribution'])) { + + if (!empty($_REQUEST['m3u'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + + $SQLquery = 'SELECT `filename`, `comments_id3v2`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`encoder_options` = "'.mysqli_real_escape_string($con, $_REQUEST['encodedbydistribution']).'")'; + $result = mysqli_query_safe($con, $SQLquery); + $NonBlankEncodedBy = ''; + $BlankEncodedBy = ''; + while ($row = mysqli_fetch_array($result)) { + set_time_limit(30); + $CommentArray = unserialize($row['comments_id3v2']); + if (isset($CommentArray['encoded_by'][0])) { + $NonBlankEncodedBy .= WindowsShareSlashTranslate($row['filename'])."\n"; + } else { + $BlankEncodedBy .= WindowsShareSlashTranslate($row['filename'])."\n"; + } + } + echo $NonBlankEncodedBy; + echo $BlankEncodedBy; + exit; + + } elseif (!empty($_REQUEST['showfiles'])) { + + echo 'show all
'; + echo ''; + + $SQLquery = 'SELECT `filename`, `comments_id3v2`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $result = mysqli_query_safe($con, $SQLquery); + while ($row = mysqli_fetch_array($result)) { + set_time_limit(30); + $CommentArray = unserialize($row['comments_id3v2']); + if (($_REQUEST['encodedbydistribution'] == '%') || (!empty($CommentArray['encoded_by'][0]) && ($_REQUEST['encodedbydistribution'] == $CommentArray['encoded_by'][0]))) { + echo ''; + echo ''; + } + } + echo '
m3u'.htmlentities($row['filename']).'
'; + + } else { + + $SQLquery = 'SELECT `encoder_options`, `comments_id3v2`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' ORDER BY (`encoder_options` LIKE "LAME%") DESC, (`encoder_options` LIKE "CBR%") DESC'; + $result = mysqli_query_safe($con, $SQLquery); + $EncodedBy = array(); + while ($row = mysqli_fetch_array($result)) { + set_time_limit(30); + $CommentArray = unserialize($row['comments_id3v2']); + if (isset($CommentArray['encoded_by'][0])) { + if (isset($EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]])) { + $EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]]++; + } else { + $EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]] = 1; + } + } + } + echo '.m3u version
'; + echo ''; + foreach ($EncodedBy as $key => $value) { + echo ''; + echo ''; + echo ''; + } + echo '
m3uEncoder OptionsEncoded By (ID3v2)
m3u'.$key.''; + arsort($value); + foreach ($value as $string => $count) { + echo ''; + echo ''; + } + echo '
'.number_format($count).' '.$string.'
'; + + } + +} elseif (!empty($_REQUEST['audiobitrates'])) { + + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); + $BitrateDistribution = array(); + $SQLquery = 'SELECT ROUND(audio_bitrate / 1000) AS `RoundBitrate`, COUNT(*) AS `num`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`audio_bitrate` > 0)'; + $SQLquery .= ' GROUP BY `RoundBitrate`'; + $result = mysqli_query_safe($con, $SQLquery); + while ($row = mysqli_fetch_array($result)) { + $this_bitrate = getid3_mp3::ClosestStandardMP3Bitrate($row['RoundBitrate'] * 1000); + if (isset($BitrateDistribution[$this_bitrate])) { + $BitrateDistribution[$this_bitrate] += $row['num']; + } else { + $BitrateDistribution[$this_bitrate] = $row['num']; + } + } + + echo ''; + echo ''; + foreach ($BitrateDistribution as $Bitrate => $Count) { + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
BitrateCount
'.round($Bitrate / 1000).' kbps'.number_format($Count).'
'; + + +} elseif (!empty($_REQUEST['emptygenres'])) { + + $SQLquery = 'SELECT `fileformat`, `filename`, `genre`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`genre` = "")'; + $SQLquery .= ' OR (`genre` = "Unknown")'; + $SQLquery .= ' OR (`genre` = "Other")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + + if (!empty($_REQUEST['m3u'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysqli_fetch_array($result)) { + if (!in_array($row['fileformat'], $IgnoreNoTagFormats)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + } + exit; + + } else { + + echo '.m3u version
'; + $EmptyGenreCounter = 0; + echo ''; + echo ''; + while ($row = mysqli_fetch_array($result)) { + if (!in_array($row['fileformat'], $IgnoreNoTagFormats)) { + $EmptyGenreCounter++; + echo ''; + echo ''; + echo ''; + echo ''; + } + } + echo '
m3ufilename
m3u'.htmlentities($row['filename']).'
'; + echo ''.number_format($EmptyGenreCounter).' files with empty genres'; + + } + +} elseif (!empty($_REQUEST['nonemptycomments'])) { + + $SQLquery = 'SELECT `filename`, `comment`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`comment` <> "")'; + $SQLquery .= ' ORDER BY `comment` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + + if (!empty($_REQUEST['m3u'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysqli_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + + } else { + + $NonEmptyCommentsCounter = 0; + echo '.m3u version
'; + echo ''; + echo ''; + while ($row = mysqli_fetch_array($result)) { + $NonEmptyCommentsCounter++; + echo ''; + echo ''; + echo ''; + if (strlen(trim($row['comment'])) > 0) { + echo ''; + } else { + echo ''; + } + echo ''; + } + echo '
m3ufilenamecomments
m3u'.htmlentities($row['filename']).''.htmlentities($row['comment']).'space
'; + echo ''.number_format($NonEmptyCommentsCounter).' files with non-empty comments'; + + } + +} elseif (!empty($_REQUEST['trackzero'])) { + + $SQLquery = 'SELECT `filename`, `track`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`track` <> "")'; + $SQLquery .= ' AND ((`track` < "1")'; + $SQLquery .= ' OR (`track` > "99"))'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + + if (!empty($_REQUEST['m3u'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysqli_fetch_array($result)) { + if ((strlen($row['track_number']) > 0) && ($row['track_number'] < 1) || ($row['track_number'] > 99)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + } + exit; + + } else { + + echo '.m3u version
'; + $TrackZeroCounter = 0; + echo ''; + echo ''; + while ($row = mysqli_fetch_array($result)) { + if ((strlen($row['track_number']) > 0) && ($row['track_number'] < 1) || ($row['track_number'] > 99)) { + $TrackZeroCounter++; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + } + echo '
m3ufilenametrack
m3u'.htmlentities($row['filename']).''.htmlentities($row['track_number']).'
'; + echo ''.number_format($TrackZeroCounter).' files with track "zero"'; + + } + + +} elseif (!empty($_REQUEST['titlefeat'])) { + + $SQLquery = 'SELECT `filename`, `title`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`title` LIKE "%feat.%")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + + if (!empty($_REQUEST['m3u'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysqli_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + + } else { + + echo ''.number_format(mysqli_num_rows($result)).' files with "feat." in the title (instead of the artist)

'; + echo '.m3u version
'; + echo ''; + echo ''; + while ($row = mysqli_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
m3ufilenametitle
m3u'.htmlentities($row['filename']).''.preg_replace('#(feat\. .*)#i', '\\1', htmlentities($row['title'])).'
'; + + } + + +} elseif (!empty($_REQUEST['tracknoalbum'])) { + + $SQLquery = 'SELECT `filename`, `track`, `album`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`track` <> "")'; + $SQLquery .= ' AND (`album` = "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + + if (!empty($_REQUEST['m3u'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysqli_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + + } else { + + echo ''.number_format(mysqli_num_rows($result)).' files with a track number, but no album

'; + echo '.m3u version
'; + echo ''; + echo ''; + while ($row = mysqli_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
m3ufilenametrackalbum
m3u'.htmlentities($row['filename']).''.htmlentities($row['track_number']).''.htmlentities($row['album']).'
'; + + } + + +} elseif (!empty($_REQUEST['synchronizetagsfrom']) && !empty($_REQUEST['filename'])) { + + echo 'Applying new tags from '.$_REQUEST['synchronizetagsfrom'].' in '.htmlentities($_REQUEST['filename']).'
    '; + $errors = array(); + if (SynchronizeAllTags($_REQUEST['filename'], $_REQUEST['synchronizetagsfrom'], 'A12', $errors)) { + echo '
  • Sucessfully wrote tags
  • '; + } else { + echo '
  • Tag writing had errors:
    • '.implode('
    • ', $errors).'
  • '; + } + echo '
'; + + +} elseif (!empty($_REQUEST['unsynchronizedtags'])) { + + $NotOKfiles = 0; + $Autofixedfiles = 0; + $FieldsToCompare = array('title', 'artist', 'album', 'year', 'genre', 'comment', 'track_number'); + $TagsToCompare = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false); + $ID3v1FieldLengths = array('title'=>30, 'artist'=>30, 'album'=>30, 'year'=>4, 'genre'=>99, 'comment'=>28); + if (strpos($_REQUEST['unsynchronizedtags'], '2') !== false) { + $TagsToCompare['id3v2'] = true; + } + if (strpos($_REQUEST['unsynchronizedtags'], 'A') !== false) { + $TagsToCompare['ape'] = true; + } + if (strpos($_REQUEST['unsynchronizedtags'], 'L') !== false) { + $TagsToCompare['lyrics3'] = true; + } + if (strpos($_REQUEST['unsynchronizedtags'], '1') !== false) { + $TagsToCompare['id3v1'] = true; + } + + echo 'Auto-fix empty tags

'; + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + if ($TagsToCompare['id3v2']) { + echo ''; + } + if ($TagsToCompare['ape']) { + echo ''; + } + if ($TagsToCompare['lyrics3']) { + echo ''; + } + if ($TagsToCompare['id3v1']) { + echo ''; + } + echo ''; + + $SQLquery = 'SELECT `filename`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` = "mp3")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + $lastdir = ''; + $serializedCommentsFields = array('all', 'id3v2', 'ape', 'lyrics3', 'id3v1'); + while ($row = mysqli_fetch_array($result)) { + set_time_limit(30); + if ($lastdir != dirname($row['filename'])) { + echo ''; + flush(); + } + + $FileOK = true; + $Mismatched = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false); + $SemiMatched = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false); + $EmptyTags = array('id3v2'=>true, 'ape'=>true, 'lyrics3'=>true, 'id3v1'=>true); + + foreach ($serializedCommentsFields as $field) { + $Comments[$field] = array(); + ob_start(); + if ($unserialized = unserialize($row['comments_'.$field])) { + $Comments[$field] = $unserialized; + } + $errormessage = ob_get_contents(); + ob_end_clean(); + } + + if (isset($Comments['ape']['tracknumber'])) { + $Comments['ape']['track_number'] = $Comments['ape']['tracknumber']; + unset($Comments['ape']['tracknumber']); + } + if (isset($Comments['ape']['track'])) { + $Comments['ape']['track_number'] = $Comments['ape']['track']; + unset($Comments['ape']['track']); + } + if (!empty($Comments['all']['track'])) { + $besttrack = ''; + foreach ($Comments['all']['track'] as $key => $value) { + if (strlen($value) > strlen($besttrack)) { + $besttrack = $value; + } + } + $Comments['all']['track_number'] = array(0=>$besttrack); + } + + $ThisLine = ''; + $ThisLine .= ''; + $ThisLine .= ''; + $tagvalues = ''; + foreach ($FieldsToCompare as $fieldname) { + $tagvalues .= $fieldname.' = '.(!empty($Comments['all'][$fieldname]) ? implode(" \n", $Comments['all'][$fieldname]) : '')." \n"; + } + $ThisLine .= ''; + foreach ($TagsToCompare as $tagtype => $CompareThisTagType) { + if ($CompareThisTagType) { + $tagvalues = ''; + foreach ($FieldsToCompare as $fieldname) { + + if ($tagtype == 'id3v1') { + + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true); + if (($fieldname == 'genre') && !empty($Comments['all'][$fieldname][0]) && !getid3_id3v1::LookupGenreID($Comments['all'][$fieldname][0])) { + + // non-standard genres can never match, so just ignore + $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; + + } elseif ($fieldname == 'comment') { + + if (isset($Comments[$tagtype][$fieldname][0]) && isset($Comments['all'][$fieldname][0]) && (rtrim(substr($Comments[$tagtype][$fieldname][0], 0, 28)) != rtrim(substr($Comments['all'][$fieldname][0], 0, 28)))) { + $tagvalues .= $fieldname.' = [['.$Comments[$tagtype][$fieldname][0].']]'."\n"; + if (trim(strtolower(RemoveAccents(substr($Comments[$tagtype][$fieldname][0], 0, 28)))) == trim(strtolower(RemoveAccents(substr($Comments['all'][$fieldname][0], 0, 28))))) { + $SemiMatched[$tagtype] = true; + } else { + $Mismatched[$tagtype] = true; + } + $FileOK = false; + } else { + $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; + } + + } elseif ($fieldname == 'track_number') { + + // intval('01/20') == intval('1') + $trackA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : ''); + $trackB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : ''); + if (intval($trackA) != intval($trackB)) { + $tagvalues .= $fieldname.' = [['.$trackA.']]'."\n"; + $Mismatched[$tagtype] = true; + $FileOK = false; + } else { + $tagvalues .= $fieldname.' = '.$trackA."\n"; + } + + } elseif ((isset($Comments[$tagtype][$fieldname][0]) ? rtrim(substr($Comments[$tagtype][$fieldname][0], 0, 30)) : '') != (isset($Comments['all'][$fieldname][0]) ? rtrim(substr($Comments['all'][$fieldname][0], 0, 30)) : '')) { + + $tagvalues .= $fieldname.' = [['.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '').']]'."\n"; + if (strtolower(RemoveAccents(trim(substr((isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : ''), 0, 30)))) == strtolower(RemoveAccents(trim(substr((isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : ''), 0, 30))))) { + $SemiMatched[$tagtype] = true; + } else { + $Mismatched[$tagtype] = true; + } + $FileOK = false; + if (!empty($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { + $EmptyTags[$tagtype] = false; + } + + } else { + + $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; + if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { + $EmptyTags[$tagtype] = false; + } + + } + + } elseif (($tagtype == 'ape') && ($fieldname == 'year')) { + + if (((isset($Comments['ape']['date'][0]) ? $Comments['ape']['date'][0] : '') != (isset($Comments['all']['year'][0]) ? $Comments['all']['year'][0] : '')) && ((isset($Comments['ape']['year'][0]) ? $Comments['ape']['year'][0] : '') != (isset($Comments['all']['year'][0]) ? $Comments['all']['year'][0] : ''))) { + + $tagvalues .= $fieldname.' = [['.(isset($Comments['ape']['date'][0]) ? $Comments['ape']['date'][0] : '').']]'."\n"; + $Mismatched[$tagtype] = true; + $FileOK = false; + if (isset($Comments['ape']['date'][0]) && (strlen(trim($Comments['ape']['date'][0])) > 0)) { + $EmptyTags[$tagtype] = false; + } + + } else { + + $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; + if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { + $EmptyTags[$tagtype] = false; + } + + } + + } elseif (($fieldname == 'genre') && !empty($Comments['all'][$fieldname]) && !empty($Comments[$tagtype][$fieldname]) && in_array($Comments[$tagtype][$fieldname][0], $Comments['all'][$fieldname])) { + + $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; + if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { + $EmptyTags[$tagtype] = false; + } + + } elseif ((isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '') != (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : '')) { + + $skiptracknumberfield = false; + switch ($fieldname) { + case 'track': + case 'tracknumber': + case 'track_number': + $trackA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : ''); + $trackB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : ''); + if (intval($trackA) == intval($trackB)) { + $skiptracknumberfield = true; + } + break; + } + if (!$skiptracknumberfield) { + $tagvalues .= $fieldname.' = [['.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '').']]'."\n"; + $tagA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : ''); + $tagB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : ''); + if (trim(strtolower(RemoveAccents($tagA))) == trim(strtolower(RemoveAccents($tagB)))) { + $SemiMatched[$tagtype] = true; + } else { + $Mismatched[$tagtype] = true; + } + $FileOK = false; + if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { + $EmptyTags[$tagtype] = false; + } + } + + } else { + + $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n"; + if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) { + $EmptyTags[$tagtype] = false; + } + + } + } + + if ($EmptyTags[$tagtype]) { + $FileOK = false; + $ThisLine .= ''; + } + } + $ThisLine .= ''; + + if (!$FileOK) { + $NotOKfiles++; + + echo ''; + flush(); + + if (!empty($_REQUEST['autofix'])) { + + $AnyMismatched = false; + foreach ($Mismatched as $key => $value) { + if ($value && ($EmptyTags["$key"] === false)) { + $AnyMismatched = true; + } + } + if ($AnyMismatched && empty($_REQUEST['autofixforcesource'])) { + + echo $ThisLine; + + } else { + + $TagsToSynch = ''; + foreach ($EmptyTags as $key => $value) { + if ($value) { + switch ($key) { + case 'id3v1': + $TagsToSynch .= '1'; + break; + case 'id3v2': + $TagsToSynch .= '2'; + break; + case 'ape': + $TagsToSynch .= 'A'; + break; + } + } + } + + $autofixforcesource = (!empty($_REQUEST['autofixforcesource']) ? $_REQUEST['autofixforcesource'] : 'all'); + $TagsToSynch = (!empty($_REQUEST['autofixforcedest']) ? $_REQUEST['autofixforcedest'] : $TagsToSynch); + + $errors = array(); + if (SynchronizeAllTags($row['filename'], $autofixforcesource, $TagsToSynch, $errors)) { + $Autofixedfiles++; + echo ''; + } else { + echo ''; + } + echo ''; + echo ''; + } + + } else { + + echo $ThisLine; + + } + } + } + + echo '
ViewFilenameCombinedID3v2APELyrics3ID3v1
view'.htmlentities($row['filename']).'all'; + } elseif ($SemiMatched[$tagtype]) { + $ThisLine .= ''; + } elseif ($Mismatched[$tagtype]) { + $ThisLine .= ''; + } else { + $ThisLine .= ''; + } + $ThisLine .= ''.$tagtype.''; + $ThisLine .= '
 '; + echo ''.htmlentities($row['filename']).''; + echo ''; + echo '
'.$TagsToSynch.'

'; + echo ''; + echo 'Found '.number_format($NotOKfiles).' files with unsynchronized tags, and auto-fixed '.number_format($Autofixedfiles).' of them.'; + +} elseif (!empty($_REQUEST['filenamepattern'])) { + + $patterns['A'] = 'artist'; + $patterns['T'] = 'title'; + $patterns['M'] = 'album'; + $patterns['N'] = 'track'; + $patterns['G'] = 'genre'; + $patterns['R'] = 'remix'; + + $FieldsToUse = explode(' ', wordwrap(preg_replace('#[^A-Z]#i', '', $_REQUEST['filenamepattern']), 1, ' ', 1)); + //$FieldsToUse = explode(' ', wordwrap($_REQUEST['filenamepattern'], 1, ' ', 1)); + foreach ($FieldsToUse as $FieldID) { + $FieldNames[] = $patterns["$FieldID"]; + } + + $SQLquery = 'SELECT `filename`, `fileformat`, '.implode(', ', $FieldNames); + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + echo 'Files that do not match naming pattern: (auto-fix)
'; + echo ''; + echo ''; + $nonmatchingfilenames = 0; + $Pattern = $_REQUEST['filenamepattern']; + $PatternLength = strlen($Pattern); + while ($row = mysqli_fetch_array($result)) { + set_time_limit(10); + $PatternFilename = ''; + for ($i = 0; $i < $PatternLength; $i++) { + if (isset($patterns[$Pattern[$i]])) { + $PatternFilename .= trim(strtr($row[$patterns[$Pattern[$i]]], ':\\*<>|', ';-¤«»¦'), ' '); + } else { + $PatternFilename .= $Pattern[$i]; + } + } + + // Replace "~" with "-" if characters immediately before and after are both numbers, + // "/" has been replaced with "~" above which is good for multi-song medley dividers, + // but for things like 24/7, 7/8ths, etc it looks better if it's 24-7, 7-8ths, etc. + $PatternFilename = preg_replace('#([ a-z]+)/([ a-z]+)#i', '\\1~\\2', $PatternFilename); + $PatternFilename = str_replace('/', '×', $PatternFilename); + + $PatternFilename = str_replace('?', '¿', $PatternFilename); + $PatternFilename = str_replace(' "', ' “', $PatternFilename); + $PatternFilename = str_replace('("', '(“', $PatternFilename); + $PatternFilename = str_replace('-"', '-“', $PatternFilename); + $PatternFilename = str_replace('" ', '” ', $PatternFilename.' '); + $PatternFilename = str_replace('"', '”', $PatternFilename); + $PatternFilename = str_replace(' ', ' ', $PatternFilename); + + + $ParenthesesPairs = array('()', '[]', '{}'); + foreach ($ParenthesesPairs as $pair) { + + // multiple remixes are stored tab-seperated in the database. + // change "{2000 Version\tSomebody Remix}" into "{2000 Version} {Somebody Remix}" + while (preg_match('#^(.*)'.preg_quote($pair[0]).'([^'.preg_quote($pair[1]).']*)('."\t".')([^'.preg_quote($pair[0]).']*)'.preg_quote($pair[1]).'#', $PatternFilename, $matches)) { + $PatternFilename = $matches[1].$pair[0].$matches[2].$pair[1].' '.$pair[0].$matches[4].$pair[1]; + } + + // remove empty parenthesized pairs (probably where no track numbers, remix version, etc) + $PatternFilename = preg_replace('#'.preg_quote($pair).'#', '', $PatternFilename); + + // "[01] - Title With No Artist.mp3" ==> "[01] Title With No Artist.mp3" + $PatternFilename = preg_replace('#'.preg_quote($pair[1]).' +\- #', $pair[1].' ', $PatternFilename); + + } + + // get rid of leading & trailing spaces if end items (artist or title for example) are missing + $PatternFilename = trim($PatternFilename, ' -'); + + if (!$PatternFilename) { + // no tags to create a filename from -- skip this file + continue; + } + $PatternFilename .= '.'.$row['fileformat']; + + $ActualFilename = basename($row['filename']); + if ($ActualFilename != $PatternFilename) { + + $NotMatchedReasons = ''; + if (strtolower($ActualFilename) === strtolower($PatternFilename)) { + $NotMatchedReasons .= 'Aa '; + } elseif (RemoveAccents($ActualFilename) === RemoveAccents($PatternFilename)) { + $NotMatchedReasons .= 'ée '; + } + + + $actualExt = '.'.fileextension($ActualFilename); + $patternExt = '.'.fileextension($PatternFilename); + $ActualFilenameNoExt = (($actualExt != '.') ? substr($ActualFilename, 0, 0 - strlen($actualExt)) : $ActualFilename); + $PatternFilenameNoExt = (($patternExt != '.') ? substr($PatternFilename, 0, 0 - strlen($patternExt)) : $PatternFilename); + + if (strpos($PatternFilenameNoExt, $ActualFilenameNoExt) !== false) { + $DifferenceBoldedName = str_replace($ActualFilenameNoExt, ''.$ActualFilenameNoExt.'', $PatternFilenameNoExt); + } else { + $ShortestNameLength = min(strlen($ActualFilenameNoExt), strlen($PatternFilenameNoExt)); + for ($DifferenceOffset = 0; $DifferenceOffset < $ShortestNameLength; $DifferenceOffset++) { + if ($ActualFilenameNoExt[$DifferenceOffset] !== $PatternFilenameNoExt[$DifferenceOffset]) { + break; + } + } + $DifferenceBoldedName = ''.substr($PatternFilenameNoExt, 0, $DifferenceOffset).''.substr($PatternFilenameNoExt, $DifferenceOffset); + } + $DifferenceBoldedName .= (($actualExt == $patternExt) ? ''.$patternExt.'' : $patternExt); + + + echo ''; + echo ''; + echo ''; + echo ''; + + if (!empty($_REQUEST['autofix'])) { + + $results = ''; + if (RenameFileFromTo($row['filename'], dirname($row['filename']).'/'.$PatternFilename, $results)) { + echo ''; + + + } else { + + echo ''; + + } + echo ''; + + $nonmatchingfilenames++; + } + } + echo '
viewWhyActual filename
(click to play/edit file)
Correct filename (based on tags)'.(empty($_REQUEST['autofix']) ? '
(click to rename file to this)' : '').'
view '.$NotMatchedReasons.''.htmlentities($ActualFilename).''; + } else { + echo ''; + } + echo ''.$DifferenceBoldedName.''; + echo ''.$DifferenceBoldedName.'

'; + echo 'Found '.number_format($nonmatchingfilenames).' files that do not match naming pattern
'; + + +} elseif (!empty($_REQUEST['encoderoptionsdistribution'])) { + + if (isset($_REQUEST['showtagfiles'])) { + $SQLquery = 'SELECT `filename`, `encoder_options` FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`encoder_options` LIKE "'.mysqli_real_escape_string($con, $_REQUEST['showtagfiles']).'")'; + $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + + if (!empty($_REQUEST['m3u'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysqli_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + + } else { + + echo 'Show all Encoder Options
'; + echo 'Files with Encoder Options '.htmlentities($_REQUEST['showtagfiles']).':
'; + echo ''; + while ($row = mysqli_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
'.htmlentities($row['filename']).''.$row['encoder_options'].'
'; + + } + + } elseif (!isset($_REQUEST['m3u'])) { + + $SQLquery = 'SELECT `encoder_options`, COUNT(*) AS `num` FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' GROUP BY `encoder_options`'; + $SQLquery .= ' ORDER BY (`encoder_options` LIKE "LAME%") DESC, (`encoder_options` LIKE "CBR%") DESC, `num` DESC, `encoder_options` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + echo 'Files with Encoder Options:
'; + echo ''; + echo ''; + while ($row = mysqli_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
Encoder OptionsCountM3U
'.$row['encoder_options'].''.number_format($row['num']).'m3u

'; + + } + +} elseif (!empty($_REQUEST['tagtypes'])) { + + if (!isset($_REQUEST['m3u'])) { + $SQLquery = 'SELECT `tags`, COUNT(*) AS `num` FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' GROUP BY `tags`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = mysqli_query_safe($con, $SQLquery); + echo 'Files with tags:
'; + echo ''; + echo ''; + while ($row = mysqli_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
TagsCountM3U
'.$row['tags'].''.number_format($row['num']).'m3u

'; + } + + if (isset($_REQUEST['showtagfiles'])) { + $SQLquery = 'SELECT `filename`, `tags` FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`tags` LIKE "'.mysqli_real_escape_string($con, $_REQUEST['showtagfiles']).'")'; + $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + + if (!empty($_REQUEST['m3u'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysqli_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + + } else { + + echo ''; + while ($row = mysqli_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
'.htmlentities($row['filename']).''.$row['tags'].'
'; + + } + } + + +} elseif (!empty($_REQUEST['md5datadupes'])) { + + $OtherFormats = ''; + $AVFormats = ''; + + $SQLquery = 'SELECT `md5_data`, `filename`, COUNT(*) AS `num`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`md5_data` <> "")'; + $SQLquery .= ' GROUP BY `md5_data`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = mysqli_query_safe($con, $SQLquery); + while (($row = mysqli_fetch_array($result)) && ($row['num'] > 1)) { + set_time_limit(30); + + $filenames = array(); + $tags = array(); + $md5_data = array(); + $SQLquery = 'SELECT `fileformat`, `filename`, `tags`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`md5_data` = "'.mysqli_real_escape_string($con, $row['md5_data']).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result2 = mysqli_query_safe($con, $SQLquery); + while ($row2 = mysqli_fetch_array($result2)) { + $thisfileformat = $row2['fileformat']; + $filenames[] = $row2['filename']; + $tags[] = $row2['tags']; + $md5_data[] = $row['md5_data']; + } + + $thisline = ''; + $thisline .= ''.implode('
', $md5_data).''; + $thisline .= ''.implode('
', $tags).''; + $thisline .= ''.implode('
', $filenames).''; + $thisline .= ''; + + if (in_array($thisfileformat, $IgnoreNoTagFormats)) { + $OtherFormats .= $thisline; + } else { + $AVFormats .= $thisline; + } + } + echo 'Duplicated MD5_DATA (Audio/Video files):'; + echo $AVFormats.'

'; + echo 'Duplicated MD5_DATA (Other files):'; + echo $OtherFormats.'

'; + + +} elseif (!empty($_REQUEST['artisttitledupes'])) { + + if (isset($_REQUEST['m3uartist']) && isset($_REQUEST['m3utitle'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`artist` = "'.mysqli_real_escape_string($con, $_REQUEST['m3uartist']).'")'; + $SQLquery .= ' AND (`title` = "'.mysqli_real_escape_string($con, $_REQUEST['m3utitle']).'")'; + $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + while ($row = mysqli_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + + } + + $SQLquery = 'SELECT `artist`, `title`, `filename`, COUNT(*) AS `num`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`artist` <> "")'; + $SQLquery .= ' AND (`title` <> "")'; + $SQLquery .= ' GROUP BY `artist`, `title`'.(!empty($_REQUEST['samemix']) ? ', `remix`' : ''); + $SQLquery .= ' ORDER BY `num` DESC, `artist` ASC, `title` ASC, `playtime_seconds` ASC, `remix` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + $uniquetitles = 0; + $uniquefiles = 0; + + if (!empty($_REQUEST['m3u'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while (($row = mysqli_fetch_array($result)) && ($row['num'] > 1)) { + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`artist` = "'.mysqli_real_escape_string($con, $row['artist']).'")'; + $SQLquery .= ' AND (`title` = "'.mysqli_real_escape_string($con, $row['title']).'")'; + if (!empty($_REQUEST['samemix'])) { + $SQLquery .= ' AND (`remix` = "'.mysqli_real_escape_string($con, $row['remix']).'")'; + } + $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; + $result2 = mysqli_query_safe($con, $SQLquery); + while ($row2 = mysqli_fetch_array($result2)) { + echo WindowsShareSlashTranslate($row2['filename'])."\n"; + } + } + exit; + + } else { + + echo 'Duplicated aritst + title: (Identical Mix/Version only)
'; + echo '(.m3u version)
'; + echo ''; + echo ''; + + while (($row = mysqli_fetch_array($result)) && ($row['num'] > 1)) { + $uniquetitles++; + set_time_limit(30); + + $filenames = array(); + $artists = array(); + $titles = array(); + $remixes = array(); + $bitrates = array(); + $playtimes = array(); + $SQLquery = 'SELECT `filename`, `artist`, `title`, `remix`, `audio_bitrate`, `vbr_method`, `playtime_seconds`, `encoder_options`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`artist` = "'.mysqli_real_escape_string($con, $row['artist']).'")'; + $SQLquery .= ' AND (`title` = "'.mysqli_real_escape_string($con, $row['title']).'")'; + $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; + $result2 = mysqli_query_safe($con, $SQLquery); + while ($row2 = mysqli_fetch_array($result2)) { + $uniquefiles++; + $filenames[] = $row2['filename']; + $artists[] = $row2['artist']; + $titles[] = $row2['title']; + $remixes[] = $row2['remix']; + if ($row2['vbr_method']) { + $bitrates[] = ''.BitrateText($row2['audio_bitrate'] / 1000).''; + } else { + $bitrates[] = BitrateText($row2['audio_bitrate'] / 1000); + } + $playtimes[] = getid3_lib::PlaytimeString($row2['playtime_seconds']); + } + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + echo ''; + + echo ''; + } + + } + echo '
 ArtistTitleVersion  Filename
'; + foreach ($filenames as $file) { + echo 'delete
'; + } + echo '
'; + foreach ($filenames as $file) { + echo 'play
'; + } + echo '
play all'.implode('
', $artists).'
'.implode('
', $titles).'
'.implode('
', $remixes).'
'.implode('
', $bitrates).'
'.implode('
', $playtimes).'
'; + foreach ($filenames as $file) { + echo ''; + } + echo '
'.dirname($file).'/'.basename($file).'
'; + echo number_format($uniquefiles).' files with '.number_format($uniquetitles).' unique aritst + title
'; + echo '
'; + +} elseif (!empty($_REQUEST['filetypelist'])) { + + list($fileformat, $audioformat) = explode('|', $_REQUEST['filetypelist']); + $SQLquery = 'SELECT `filename`, `fileformat`, `audio_dataformat`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` = "'.mysqli_real_escape_string($con, $fileformat).'")'; + $SQLquery .= ' AND (`audio_dataformat` = "'.mysqli_real_escape_string($con, $audioformat).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + echo 'Files of format '.$fileformat.'.'.$audioformat.':'; + echo ''; + while ($row = mysqli_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
fileaudiofilename
'.$row['fileformat'].''.$row['audio_dataformat'].''.htmlentities($row['filename']).'

'; + +} elseif (!empty($_REQUEST['trackinalbum'])) { + + $SQLquery = 'SELECT `filename`, `album`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`album` LIKE "% [%")'; + $SQLquery .= ' ORDER BY `album` ASC, `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + if (!empty($_REQUEST['m3u'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysqli_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + + } elseif (!empty($_REQUEST['autofix'])) { + + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true); + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); + + while ($row = mysqli_fetch_array($result)) { + set_time_limit(30); + $ThisFileInfo = $getID3->analyze($filename); + $getID3->CopyTagsToComments($ThisFileInfo); + + if (!empty($ThisFileInfo['tags'])) { + + $Album = trim(str_replace(strstr($ThisFileInfo['comments']['album'][0], ' ['), '', $ThisFileInfo['comments']['album'][0])); + $Track = (string) intval(str_replace(' [', '', str_replace(']', '', strstr($ThisFileInfo['comments']['album'][0], ' [')))); + if ($Track == '0') { + $Track = ''; + } + if ($Album && $Track) { + echo '
'.htmlentities($row['filename']).'
'; + echo ''.htmlentities($Album).' (track #'.$Track.')
'; + echo 'ID3v2: '.(RemoveID3v2($row['filename'], false) ? 'removed' : 'REMOVAL FAILED!').', '; + $WriteID3v1_title = (isset($ThisFileInfo['comments']['title'][0]) ? $ThisFileInfo['comments']['title'][0] : ''); + $WriteID3v1_artist = (isset($ThisFileInfo['comments']['artist'][0]) ? $ThisFileInfo['comments']['artist'][0] : ''); + $WriteID3v1_year = (isset($ThisFileInfo['comments']['year'][0]) ? $ThisFileInfo['comments']['year'][0] : ''); + $WriteID3v1_comment = (isset($ThisFileInfo['comments']['comment'][0]) ? $ThisFileInfo['comments']['comment'][0] : ''); + $WriteID3v1_genreid = (isset($ThisFileInfo['comments']['genreid'][0]) ? $ThisFileInfo['comments']['genreid'][0] : ''); + echo 'ID3v1: '.(WriteID3v1($row['filename'], $WriteID3v1_title, $WriteID3v1_artist, $Album, $WriteID3v1_year, $WriteID3v1_comment, $WriteID3v1_genreid, $Track, false) ? 'updated' : 'UPDATE FAILED').'
'; + } else { + echo ' . '; + } + + } else { + + echo '
FAILED
'.htmlentities($row['filename']).'
'; + + } + flush(); + } + + } else { + + echo ''.number_format(mysqli_num_rows($result)).' files with [??]-format track numbers in album field:
'; + if (mysqli_num_rows($result) > 0) { + echo '(.m3u version)
'; + echo 'Try to auto-fix
'; + echo ''; + while ($row = mysqli_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
'.$row['album'].''.htmlentities($row['filename']).'
'; + } + echo '
'; + + } + +} elseif (!empty($_REQUEST['fileextensions'])) { + + $SQLquery = 'SELECT `filename`, `fileformat`, `audio_dataformat`, `video_dataformat`, `tags`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + $invalidextensionfiles = 0; + $invalidextensionline = ''; + $invalidextensionline .= ''; + while ($row = mysqli_fetch_array($result)) { + set_time_limit(30); + + $acceptableextensions = AcceptableExtensions($row['fileformat'], $row['audio_dataformat'], $row['video_dataformat']); + $actualextension = strtolower(fileextension($row['filename'])); + if ($acceptableextensions && !in_array($actualextension, $acceptableextensions)) { + $invalidextensionfiles++; + + $invalidextensionline .= ''; + $invalidextensionline .= ''; + $invalidextensionline .= ''; + $invalidextensionline .= ''; + $invalidextensionline .= ''; + $invalidextensionline .= ''; + $invalidextensionline .= ''; + $invalidextensionline .= ''; + $invalidextensionline .= ''; + } + } + $invalidextensionline .= '
fileaudiovideotagsactualcorrectfilename
'.$row['fileformat'].''.$row['audio_dataformat'].''.$row['video_dataformat'].''.$row['tags'].''.$actualextension.''.implode('; ', $acceptableextensions).''.htmlentities($row['filename']).'

'; + echo number_format($invalidextensionfiles).' files with incorrect filename extension:
'; + echo $invalidextensionline; + +} elseif (isset($_REQUEST['genredistribution'])) { + + if (!empty($_REQUEST['m3u'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (BINARY `genre` = "'.$_REQUEST['genredistribution'].'")'; + $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + while ($row = mysqli_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + + } else { + + if ($_REQUEST['genredistribution'] == '%') { + + $SQLquery = 'SELECT COUNT(*) AS `num`, `genre`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' GROUP BY `genre`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = mysqli_query_safe($con, $SQLquery); + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true); + echo ''; + echo ''; + while ($row = mysqli_fetch_array($result)) { + $GenreID = getid3_id3v1::LookupGenreID($row['genre']); + if (is_numeric($GenreID)) { + echo ''; + } else { + echo ''; + } + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
CountGenrem3u
'.number_format($row['num']).''.str_replace("\t", '
', $row['genre']).'
.m3u

'; + + } else { + + $SQLquery = 'SELECT `filename`, `genre`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`genre` LIKE "'.mysqli_real_escape_string($con, $_REQUEST['genredistribution']).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + echo 'All Genres
'; + echo ''; + echo ''; + while ($row = mysqli_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
Genrem3uFilename
'.str_replace("\t", '
', $row['genre']).'
m3u'.htmlentities($row['filename']).'

'; + + } + + + } + +} elseif (!empty($_REQUEST['formatdistribution'])) { + + $SQLquery = 'SELECT `fileformat`, `audio_dataformat`, COUNT(*) AS `num`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' GROUP BY `fileformat`, `audio_dataformat`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = mysqli_query_safe($con, $SQLquery); + echo 'File format distribution:'; + echo ''; + while ($row = mysqli_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
NumberFormat
'.number_format($row['num']).''.($row['fileformat'] ? $row['fileformat'] : 'unknown').(($row['audio_dataformat'] && ($row['audio_dataformat'] != $row['fileformat'])) ? '.'.$row['audio_dataformat'] : '').'

'; + +} elseif (!empty($_REQUEST['errorswarnings'])) { + + $SQLquery = 'SELECT `filename`, `error`, `warning`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`error` <> "")'; + $SQLquery .= ' OR (`warning` <> "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + + if (!empty($_REQUEST['m3u'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + while ($row = mysqli_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + + } else { + + echo number_format(mysqli_num_rows($result)).' files with errors or warnings:
'; + echo '(.m3u version)
'; + echo ''; + echo ''; + while ($row = mysqli_fetch_array($result)) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + } + echo '
FilenameErrorWarning
'.htmlentities($row['filename']).''.(!empty($row['error']) ? '
  • '.str_replace("\t", '
  • ', htmlentities($row['error'])).'
  • ' : ' ').'
    '.(!empty($row['warning']) ? '
  • '.str_replace("\t", '
  • ', htmlentities($row['warning'])).'
  • ' : ' ').'

    '; + +} elseif (!empty($_REQUEST['fixid3v1padding'])) { + + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.id3v1.php', __FILE__, true); + $id3v1_writer = new getid3_write_id3v1; + + $SQLquery = 'SELECT `filename`, `error`, `warning`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` = "mp3")'; + $SQLquery .= ' AND (`warning` <> "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + $totaltofix = mysqli_num_rows($result); + $rowcounter = 0; + while ($row = mysqli_fetch_array($result)) { + set_time_limit(30); + if (strpos($row['warning'], 'Some ID3v1 fields do not use NULL characters for padding') !== false) { + set_time_limit(30); + $id3v1_writer->filename = $row['filename']; + echo ($id3v1_writer->FixID3v1Padding() ? 'fixed - ' : 'error - '); + } else { + echo 'No error? - '; + } + echo '['.++$rowcounter.' / '.$totaltofix.'] '; + echo htmlentities($row['filename']).'
    '; + flush(); + } + +} elseif (!empty($_REQUEST['vbrmethod'])) { + + if ($_REQUEST['vbrmethod'] == '1') { + + $SQLquery = 'SELECT COUNT(*) AS `num`, `vbr_method`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' GROUP BY `vbr_method`'; + $SQLquery .= ' ORDER BY `vbr_method`'; + $result = mysqli_query_safe($con, $SQLquery); + echo 'VBR methods:'; + echo ''; + while ($row = mysqli_fetch_array($result)) { + echo ''; + echo ''; + if ($row['vbr_method']) { + echo ''; + } else { + echo ''; + } + echo ''; + } + echo '
    CountVBR Method
    '.htmlentities(number_format($row['num'])).''.htmlentities($row['vbr_method']).'CBR
    '; + + } else { + + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`vbr_method` = "'.mysqli_real_escape_string($con, $_REQUEST['vbrmethod']).'")'; + $result = mysqli_query_safe($con, $SQLquery); + echo number_format(mysqli_num_rows($result)).' files with VBR_method of "'.$_REQUEST['vbrmethod'].'":'; + while ($row = mysqli_fetch_array($result)) { + echo ''; + echo ''; + } + echo '
    m3u'.htmlentities($row['filename']).'
    '; + + } + echo '
    '; + +} elseif (!empty($_REQUEST['correctcase'])) { + + $SQLquery = 'SELECT `filename`, `fileformat`'; + $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; + $SQLquery .= ' WHERE (`fileformat` <> "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = mysqli_query_safe($con, $SQLquery); + echo 'Copy and paste the following into a DOS batch file. You may have to run this script more than once to catch all the changes (remember to scan for deleted/changed files and rescan directory between scans)
    '; + echo '
    ';
    +	$lastdir = '';
    +	while ($row = mysqli_fetch_array($result)) {
    +		set_time_limit(30);
    +		$CleanedFilename = CleanUpFileName($row['filename']);
    +		if ($row['filename'] != $CleanedFilename) {
    +			if (strtolower($lastdir) != strtolower(str_replace('/', '\\', dirname($row['filename'])))) {
    +				$lastdir = str_replace('/', '\\', dirname($row['filename']));
    +				echo 'cd "'.$lastdir.'"'."\n";
    +			}
    +			echo 'ren "'.basename($row['filename']).'" "'.basename(CleanUpFileName($row['filename'])).'"'."\n";
    +		}
    +	}
    +	echo '
    '; + echo '
    '; + +} + +function CleanUpFileName($filename) { + $DirectoryName = dirname($filename); + $FileExtension = fileextension(basename($filename)); + $BaseFilename = basename($filename, '.'.$FileExtension); + + $BaseFilename = strtolower($BaseFilename); + $BaseFilename = str_replace('_', ' ', $BaseFilename); + //$BaseFilename = str_replace('-', ' - ', $BaseFilename); + $BaseFilename = str_replace('(', ' (', $BaseFilename); + $BaseFilename = str_replace('( ', '(', $BaseFilename); + $BaseFilename = str_replace(')', ') ', $BaseFilename); + $BaseFilename = str_replace(' )', ')', $BaseFilename); + $BaseFilename = str_replace(' \'\'', ' “', $BaseFilename); + $BaseFilename = str_replace('\'\' ', '” ', $BaseFilename); + $BaseFilename = str_replace(' vs ', ' vs. ', $BaseFilename); + while (strstr($BaseFilename, ' ') !== false) { + $BaseFilename = str_replace(' ', ' ', $BaseFilename); + } + $BaseFilename = trim($BaseFilename); + + return $DirectoryName.'/'.BetterUCwords($BaseFilename).'.'.strtolower($FileExtension); +} + +function BetterUCwords($string) { + $stringlength = strlen($string); + + $string[0] = strtoupper($string[0]); + for ($i = 1; $i < $stringlength; $i++) { + if (($string[$i - 1] == '\'') && ($i > 1) && (($string[$i - 2] == 'O') || ($string[$i - 2] == ' '))) { + // O'Clock, 'Em + $string[$i] = strtoupper($string[$i]); + } elseif (preg_match('#^[\'A-Za-z0-9À-ÿ]$#', $string[$i - 1])) { + $string[$i] = strtolower($string[$i]); + } else { + $string[$i] = strtoupper($string[$i]); + } + } + + static $LowerCaseWords = array('vs.', 'feat.'); + static $UpperCaseWords = array('DJ', 'USA', 'II', 'MC', 'CD', 'TV', '\'N\''); + + $OutputListOfWords = array(); + $ListOfWords = explode(' ', $string); + foreach ($ListOfWords as $ThisWord) { + if (in_array(strtolower(str_replace('(', '', $ThisWord)), $LowerCaseWords)) { + $ThisWord = strtolower($ThisWord); + } elseif (in_array(strtoupper(str_replace('(', '', $ThisWord)), $UpperCaseWords)) { + $ThisWord = strtoupper($ThisWord); + } elseif ((substr($ThisWord, 0, 2) == 'Mc') && (strlen($ThisWord) > 2)) { + $ThisWord[2] = strtoupper($ThisWord[2]); + } elseif ((substr($ThisWord, 0, 3) == 'Mac') && (strlen($ThisWord) > 3)) { + $ThisWord[3] = strtoupper($ThisWord[3]); + } + $OutputListOfWords[] = $ThisWord; + } + $UCstring = implode(' ', $OutputListOfWords); + $UCstring = str_replace(' From “', ' from “', $UCstring); + $UCstring = str_replace(' \'n\' ', ' \'N\' ', $UCstring); + + return $UCstring; +} + + + +echo '
    '; +echo 'Warning: Scanning a new directory will erase all previous entries in the database!
    '; +echo 'Directory: '; +echo ''; +echo '
    '; +echo '
    '; +echo 'Re-scanning a new directory will only add new, previously unscanned files into the list (and not erase the database).
    '; +echo 'Directory: '; +echo ''; +echo '

    '; +echo ''; + +$SQLquery = 'SELECT COUNT(*) AS `TotalFiles`, SUM(`playtime_seconds`) AS `TotalPlaytime`, SUM(`filesize`) AS `TotalFilesize`, AVG(`playtime_seconds`) AS `AvgPlaytime`, AVG(`filesize`) AS `AvgFilesize`, AVG(`audio_bitrate` + `video_bitrate`) AS `AvgBitrate`'; +$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`'; +$result = mysqli_query_safe($con, $SQLquery); +if ($row = mysqli_fetch_array($result)) { + echo '
    '; + echo '
    '; + echo 'Spent '.number_format(mysqli_query_safe($con, null), 3).' seconds querying the database
    '; + echo '
    '; + echo 'Currently in the database:'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
    Total Files'.number_format($row['TotalFiles']).'
    Total Filesize'.number_format($row['TotalFilesize'] / 1048576).' MB
    Total Playtime'.number_format($row['TotalPlaytime'] / 3600, 1).' hours
    Average Filesize'.number_format($row['AvgFilesize'] / 1048576, 1).' MB
    Average Playtime'.getid3_lib::PlaytimeString($row['AvgPlaytime']).'
    Average Bitrate'.BitrateText($row['AvgBitrate'] / 1000, 1).'
    '; + echo '
    '; +} + +echo ''; diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.simple.php b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.simple.php new file mode 100644 index 00000000..8ac18c0c --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.simple.php @@ -0,0 +1,54 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// /demo/demo.simple.php - part of getID3() // +// Sample script for scanning a single directory and // +// displaying a few pieces of information for each file // +// see readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__)); + + +echo ''; +echo 'getID3() - /demo/demo.simple.php (sample script)'; +echo ''; +echo ''; + +// include getID3() library (can be in a different directory if full path is specified) +require_once('../getid3/getid3.php'); + +// Initialize getID3 engine +$getID3 = new getID3; + +$DirectoryToScan = '/change/to/directory/you/want/to/scan'; // change to whatever directory you want to scan +$dir = opendir($DirectoryToScan); +echo ''; +echo ''; +while (($file = readdir($dir)) !== false) { + $FullFileName = realpath($DirectoryToScan.'/'.$file); + if ((substr($file, 0, 1) != '.') && is_file($FullFileName)) { + set_time_limit(30); + + $ThisFileInfo = $getID3->analyze($FullFileName); + + $getID3->CopyTagsToComments($ThisFileInfo); + + // output desired information in whatever format you want + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } +} +echo '
    FilenameArtistTitleBitratePlaytime
    '.htmlentities($ThisFileInfo['filenamepath']).'' .htmlentities(!empty($ThisFileInfo['comments_html']['artist']) ? implode('
    ', $ThisFileInfo['comments_html']['artist']) : chr(160)).'
    ' .htmlentities(!empty($ThisFileInfo['comments_html']['title']) ? implode('
    ', $ThisFileInfo['comments_html']['title']) : chr(160)).'
    '.htmlentities(!empty($ThisFileInfo['audio']['bitrate']) ? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps' : chr(160)).''.htmlentities(!empty($ThisFileInfo['playtime_string']) ? $ThisFileInfo['playtime_string'] : chr(160)).'
    '; + +echo ''; diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.simple.write.php b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.simple.write.php new file mode 100644 index 00000000..ad607608 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.simple.write.php @@ -0,0 +1,61 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// /demo/demo.simple.write.php - part of getID3() // +// Sample script showing basic syntax for writing tags // +// see readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__)); + + +$TextEncoding = 'UTF-8'; + +require_once('../getid3/getid3.php'); +// Initialize getID3 engine +$getID3 = new getID3; +$getID3->setOption(array('encoding'=>$TextEncoding)); + +require_once('../getid3/write.php'); +// Initialize getID3 tag-writing module +$tagwriter = new getid3_writetags; +//$tagwriter->filename = '/path/to/file.mp3'; +$tagwriter->filename = 'c:/file.mp3'; + +//$tagwriter->tagformats = array('id3v1', 'id3v2.3'); +$tagwriter->tagformats = array('id3v2.3'); + +// set various options (optional) +$tagwriter->overwrite_tags = true; // if true will erase existing tag data and write only passed data; if false will merge passed data with existing tag data (experimental) +$tagwriter->remove_other_tags = false; // if true removes other tag formats (e.g. ID3v1, ID3v2, APE, Lyrics3, etc) that may be present in the file and only write the specified tag format(s). If false leaves any unspecified tag formats as-is. +$tagwriter->tag_encoding = $TextEncoding; +$tagwriter->remove_other_tags = true; + +// populate data array +$TagData = array( + 'title' => array('My Song'), + 'artist' => array('The Artist'), + 'album' => array('Greatest Hits'), + 'year' => array('2004'), + 'genre' => array('Rock'), + 'comment' => array('excellent!'), + 'track_number' => array('04/16'), + 'popularimeter' => array('email'=>'user@example.net', 'rating'=>128, 'data'=>0), + 'unique_file_identifier' => array('ownerid'=>'user@example.net', 'data'=>md5(time())), +); +$tagwriter->tag_data = $TagData; + +// write tags +if ($tagwriter->WriteTags()) { + echo 'Successfully wrote tags
    '; + if (!empty($tagwriter->warnings)) { + echo 'There were some warnings:
    '.implode('

    ', $tagwriter->warnings); + } +} else { + echo 'Failed to write tags!
    '.implode('

    ', $tagwriter->errors); +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.write.php b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.write.php new file mode 100644 index 00000000..67955592 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.write.php @@ -0,0 +1,262 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// /demo/demo.write.php - part of getID3() // +// sample script for demonstrating writing ID3v1 and ID3v2 // +// tags for MP3, or Ogg comment tags for Ogg Vorbis // +// see readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__)); + + +$TaggingFormat = 'UTF-8'; + +header('Content-Type: text/html; charset='.$TaggingFormat); +echo ''; +echo 'getID3() - Sample tag writer'; + +require_once('../getid3/getid3.php'); +// Initialize getID3 engine +$getID3 = new getID3; +$getID3->setOption(array('encoding'=>$TaggingFormat)); + +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.php', __FILE__, true); + +$browsescriptfilename = 'demo.browse.php'; + +$Filename = (isset($_REQUEST['Filename']) ? $_REQUEST['Filename'] : ''); + + + +if (isset($_POST['WriteTags'])) { + + $TagFormatsToWrite = (isset($_POST['TagFormatsToWrite']) ? $_POST['TagFormatsToWrite'] : array()); + if (!empty($TagFormatsToWrite)) { + echo 'starting to write tag(s)
    '; + + $tagwriter = new getid3_writetags; + $tagwriter->filename = $Filename; + $tagwriter->tagformats = $TagFormatsToWrite; + $tagwriter->overwrite_tags = false; + $tagwriter->tag_encoding = $TaggingFormat; + if (!empty($_POST['remove_other_tags'])) { + $tagwriter->remove_other_tags = true; + } + + $commonkeysarray = array('Title', 'Artist', 'Album', 'Year', 'Comment'); + foreach ($commonkeysarray as $key) { + if (!empty($_POST[$key])) { + $TagData[strtolower($key)][] = $_POST[$key]; + } + } + if (!empty($_POST['Genre'])) { + $TagData['genre'][] = $_POST['Genre']; + } + if (!empty($_POST['GenreOther'])) { + $TagData['genre'][] = $_POST['GenreOther']; + } + if (!empty($_POST['Track'])) { + $TagData['track_number'][] = $_POST['Track'].(!empty($_POST['TracksTotal']) ? '/'.$_POST['TracksTotal'] : ''); + } + + if (!empty($_FILES['userfile']['tmp_name'])) { + if (in_array('id3v2.4', $tagwriter->tagformats) || in_array('id3v2.3', $tagwriter->tagformats) || in_array('id3v2.2', $tagwriter->tagformats)) { + if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { + if ($APICdata = file_get_contents($_FILES['userfile']['tmp_name'])) { + + if ($exif_imagetype = exif_imagetype($_FILES['userfile']['tmp_name'])) { + + $TagData['attached_picture'][0]['data'] = $APICdata; + $TagData['attached_picture'][0]['picturetypeid'] = $_POST['APICpictureType']; + $TagData['attached_picture'][0]['description'] = $_FILES['userfile']['name']; + $TagData['attached_picture'][0]['mime'] = image_type_to_mime_type($exif_imagetype); + + } else { + echo 'invalid image format (only GIF, JPEG, PNG)
    '; + } + } else { + echo 'cannot open '.htmlentities($_FILES['userfile']['tmp_name']).'
    '; + } + } else { + echo '!is_uploaded_file('.htmlentities($_FILES['userfile']['tmp_name']).')
    '; + } + } else { + echo 'WARNING: Can only embed images for ID3v2
    '; + } + } + + $tagwriter->tag_data = $TagData; + if ($tagwriter->WriteTags()) { + echo 'Successfully wrote tags
    '; + if (!empty($tagwriter->warnings)) { + echo 'There were some warnings:
    '.implode('

    ', $tagwriter->warnings).''; + } + } else { + echo 'Failed to write tags!
    '.implode('

    ', $tagwriter->errors).'
    '; + } + + } else { + + echo 'WARNING: no tag formats selected for writing - nothing written'; + + } + echo '
    '; + +} + + +echo '
    Sample tag editor/writer
    '; +echo 'Browse current directory
    '; +if (!empty($Filename)) { + echo 'Start Over

    '; + echo '
    '; + echo ''; + echo ''; + if (file_exists($Filename)) { + + // Initialize getID3 engine + $getID3 = new getID3; + $OldThisFileInfo = $getID3->analyze($Filename); + getid3_lib::CopyTagsToComments($OldThisFileInfo); + + switch ($OldThisFileInfo['fileformat']) { + case 'mp3': + case 'mp2': + case 'mp1': + $ValidTagTypes = array('id3v1', 'id3v2.3', 'ape'); + break; + + case 'mpc': + $ValidTagTypes = array('ape'); + break; + + case 'ogg': + if (!empty($OldThisFileInfo['audio']['dataformat']) && ($OldThisFileInfo['audio']['dataformat'] == 'flac')) { + //$ValidTagTypes = array('metaflac'); + // metaflac doesn't (yet) work with OggFLAC files + $ValidTagTypes = array(); + } else { + $ValidTagTypes = array('vorbiscomment'); + } + break; + + case 'flac': + $ValidTagTypes = array('metaflac'); + break; + + case 'real': + $ValidTagTypes = array('real'); + break; + + default: + $ValidTagTypes = array(); + break; + } + echo ''; + echo ''; + echo ''; + echo ''; + + $TracksTotal = ''; + $TrackNumber = ''; + if (!empty($OldThisFileInfo['comments']['track_number']) && is_array($OldThisFileInfo['comments']['track_number'])) { + $RawTrackNumberArray = $OldThisFileInfo['comments']['track_number']; + } elseif (!empty($OldThisFileInfo['comments']['track_number']) && is_array($OldThisFileInfo['comments']['track_number'])) { + $RawTrackNumberArray = $OldThisFileInfo['comments']['track_number']; + } else { + $RawTrackNumberArray = array(); + } + foreach ($RawTrackNumberArray as $key => $value) { + if (strlen($value) > strlen($TrackNumber)) { + // ID3v1 may store track as "3" but ID3v2/APE would store as "03/16" + $TrackNumber = $value; + } + } + if (strstr($TrackNumber, '/')) { + list($TrackNumber, $TracksTotal) = explode('/', $TrackNumber); + } + echo ''; + + $ArrayOfGenresTemp = getid3_id3v1::ArrayOfGenres(); // get the array of genres + foreach ($ArrayOfGenresTemp as $key => $value) { // change keys to match displayed value + $ArrayOfGenres[$value] = $value; + } + unset($ArrayOfGenresTemp); // remove temporary array + unset($ArrayOfGenres['Cover']); // take off these special cases + unset($ArrayOfGenres['Remix']); + unset($ArrayOfGenres['Unknown']); + $ArrayOfGenres[''] = '- Unknown -'; // Add special cases back in with renamed key/value + $ArrayOfGenres['Cover'] = '-Cover-'; + $ArrayOfGenres['Remix'] = '-Remix-'; + asort($ArrayOfGenres); // sort into alphabetical order + echo ''; + + echo ''; + + echo ''; + + echo ''; + echo ''; + + } else { + + echo ''; + + } + echo '
    Filename:'.$Filename.'
    Title
    Artist
    Album
    Year
    Track of
    Genre
    Write Tags'; + foreach ($ValidTagTypes as $ValidTagType) { + echo ''.$ValidTagType.'
    '; + } + if (count($ValidTagTypes) > 1) { + echo '
    Remove non-selected tag formats when writing new tag
    '; + } + echo '
    Comment
    Picture
    (ID3v2 only)

    '; + echo '
    '; + echo '
    Error'.htmlentities($Filename).' does not exist
    '; + echo '
    '; + +} + +echo ''; diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.zip.php b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.zip.php new file mode 100644 index 00000000..204ce43d --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/demos/demo.zip.php @@ -0,0 +1,102 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// /demo/demo.zip.php - part of getID3() // +// Sample script how to use getID3() to decompress zip files // +// see readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +die('For security reasons, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__)); + + +function UnzipFileContents($filename, &$errors) { + $errors = array(); + $DecompressedFileContents = array(); + if (!class_exists('getID3')) { + $errors[] = 'class getID3 not defined, please include getid3.php'; + } elseif (include_once('module.archive.zip.php')) { + $getid3 = new getID3(); + $getid3->info['filesize'] = filesize($filename); + ob_start(); + if ($getid3->fp = fopen($filename, 'rb')) { + ob_end_clean(); + $getid3_zip = new getid3_zip($getid3); + $getid3_zip->analyze(); + if (($getid3->info['fileformat'] == 'zip') && !empty($getid3->info['zip']['files'])) { + if (!empty($getid3->info['zip']['central_directory'])) { + $ZipDirectoryToWalk = $getid3->info['zip']['central_directory']; + } elseif (!empty($getid3->info['zip']['entries'])) { + $ZipDirectoryToWalk = $getid3->info['zip']['entries']; + } else { + $errors[] = 'failed to parse ZIP attachment "'.$filename.'" (no central directory)
    '; + fclose($getid3->fp); + return false; + } + foreach ($ZipDirectoryToWalk as $key => $valuearray) { + fseek($getid3->fp, $valuearray['entry_offset'], SEEK_SET); + $LocalFileHeader = $getid3_zip->ZIPparseLocalFileHeader(); + if ($LocalFileHeader['flags']['encrypted']) { + // password-protected + $DecompressedFileContents[$valuearray['filename']] = ''; + } else { + fseek($getid3->fp, $LocalFileHeader['data_offset'], SEEK_SET); + $compressedFileData = ''; + while ((strlen($compressedFileData) < $LocalFileHeader['compressed_size']) && !feof($getid3->fp)) { + $compressedFileData .= fread($getid3->fp, 32768); + } + switch ($LocalFileHeader['raw']['compression_method']) { + case 0: // store - great, just copy data unchanged + $uncompressedFileData = $compressedFileData; + break; + + case 8: // deflate + ob_start(); + $uncompressedFileData = gzinflate($compressedFileData); + $gzinflate_errors = trim(strip_tags(ob_get_contents())); + ob_end_clean(); + if ($gzinflate_errors) { + $errors[] = 'gzinflate() failed for file ['.$LocalFileHeader['filename'].']: "'.$gzinflate_errors.'"'; + continue 2; + } + break; + + case 1: // shrink + case 2: // reduce-1 + case 3: // reduce-2 + case 4: // reduce-3 + case 5: // reduce-4 + case 6: // implode + case 7: // tokenize + case 9: // deflate64 + case 10: // PKWARE Date Compression Library Imploding + $DecompressedFileContents[$valuearray['filename']] = ''; + $errors[] = 'unsupported ZIP compression method ('.$LocalFileHeader['raw']['compression_method'].' = '.$getid3_zip->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']).')'; + continue 2; + + default: + $DecompressedFileContents[$valuearray['filename']] = ''; + $errors[] = 'unknown ZIP compression method ('.$LocalFileHeader['raw']['compression_method'].')'; + continue 2; + } + $DecompressedFileContents[$valuearray['filename']] = $uncompressedFileData; + unset($compressedFileData); + } + } + } else { + $errors[] = $filename.' does not appear to be a zip file'; + } + } else { + $error_message = ob_get_contents(); + ob_end_clean(); + $errors[] = 'failed to fopen('.$filename.', rb): '.$error_message; + } + } else { + $errors[] = 'failed to include_once(module.archive.zip.php)'; + } + return $DecompressedFileContents; +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/demos/getid3.css b/serendipity_event_podcast/player/james-heinrich/getid3/demos/getid3.css new file mode 100644 index 00000000..c59d1a03 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/demos/getid3.css @@ -0,0 +1,171 @@ +/** +* Common elements +*/ + +body { + font: 12px Verdana, sans-serif; + background-color: white; + color: black; + margin-top: 6px; + margin-bottom: 30px; + margin-left: 12px; + margin-right: 12px; +} + +h1 { + font: bold 18px Verdana, sans-serif; + line-height: 26px; + margin-top: 12px; + margin-bottom: 15px; + margin-left: 0; + margin-right: 7px; + background-color: #e6eaf6; + padding-left: 10px; + padding-top: 2px; + padding-bottom: 4px; +} + +h3 { + font: bold 13px Verdana, sans-serif; + line-height: 26px; + margin-top: 12px; + margin-bottom: 0; + margin-left: 0; + margin-right: 7px; + padding-left: 4px; +} + +ul { + margin-top: 0; +} + +p, li { + font: 9pt/135% sans-serif; + margin-top: 1px; + margin-bottom: 0; +} + +a, a:link, a:visited { + color: #0000cc; +} + +hr { + height: 0; + border: solid gray 0; + border-top-width: thin; + width: 700px; +} + +table.table td { + font: 9pt sans-serif; + padding-top: 1px; + padding-bottom: 1px; + padding-left: 5px; + padding-right: 5px; +} + +table.table td.header { + background-color: #cccccc; + padding-top: 2px; + padding-bottom: 2px; + font-weight: bold; +} + +table.table tr.even_files { + background-color: #fefefe; +} + +table.table tr.odd_files { + background-color: #e9e9e9; +} + +table.dump { + border-top: solid 1px #cccccc; + border-left: solid 1px #cccccc; + margin: 2px; +} + +table.dump td { + font: 9pt sans-serif; + padding-top: 1px; + padding-bottom: 1px; + padding-left: 5px; + padding-right: 5px; + border-right: solid 1px #cccccc; + border-bottom: solid 1px #cccccc; +} + +td.dump_string { + font-weight: bold; + color: #006600; + font-family: Zawgyi-One,sans-serif; +} + +td.dump_integer { + color: #CC0000; + font-weight: bold; +} + +td.dump_double { + color: #FF9900; + font-weight: bold; +} + +td.dump_boolean { + color: #0000FF; + font-weight: bold; +} + +.error { + color: red +} + + +/** +* Tool Tips +*/ + +.tooltip { + font: 9pt sans-serif; + background: #ffffe1; + color: black; + border: black 1px solid; + margin: 2px; + padding: 7px; + position: absolute; + top: 10px; + left: 10px; + z-index: 10000; + visibility: hidden; +} + +.tooltip p { + margin-top: -2px; + margin-bottom: 4px; +} + + +/** +* Forms +*/ + +table.form td { + font: 9pt/135% sans-serif; + padding: 2px; +} + +select, input { + font: 9pt/135% sans-serif; +} + +.select, .field { + width: 260px; +} + +#sel_field { + width: 85px; +} + +.button { + margin-top: 10px; +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/demos/index.php b/serendipity_event_podcast/player/james-heinrich/getid3/demos/index.php new file mode 100644 index 00000000..23bab141 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/demos/index.php @@ -0,0 +1,23 @@ + +getID3 demos + + + +In this directory are a number of examples of how to use getID3().
    +If you don't know what to run, take a look at demo.browse.php +
    +Other demos: + + diff --git a/serendipity_event_podcast/player/getid3/dependencies.txt b/serendipity_event_podcast/player/james-heinrich/getid3/dependencies.txt similarity index 89% rename from serendipity_event_podcast/player/getid3/dependencies.txt rename to serendipity_event_podcast/player/james-heinrich/getid3/dependencies.txt index 34a72ba8..73354de4 100644 --- a/serendipity_event_podcast/player/getid3/dependencies.txt +++ b/serendipity_event_podcast/player/james-heinrich/getid3/dependencies.txt @@ -1,7 +1,8 @@ ///////////////////////////////////////////////////////////////// /// getID3() by James Heinrich // // available at http://getid3.sourceforge.net // -// or http://www.getid3.org // +// or https://www.getid3.org // +// also https://github.com/JamesHeinrich/getID3 // ///////////////////////////////////////////////////////////////// // // // dependencies.txt - part of getID3() // diff --git a/serendipity_event_podcast/player/getid3/extension.cache.dbm.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/extension.cache.dbm.php similarity index 76% rename from serendipity_event_podcast/player/getid3/extension.cache.dbm.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/extension.cache.dbm.php index a85cb0cc..bf94ef18 100644 --- a/serendipity_event_podcast/player/getid3/extension.cache.dbm.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/extension.cache.dbm.php @@ -1,16 +1,17 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // // // // extension.cache.dbm.php - part of getID3() // // Please see readme.txt for more information // // /// ///////////////////////////////////////////////////////////////// // // -// This extension written by Allan Hansen // +// This extension written by Allan Hansen // // /// ///////////////////////////////////////////////////////////////// @@ -71,9 +72,37 @@ class getID3_cached_dbm extends getID3 { + /** + * @var resource + */ + private $dba; - // public: constructor - see top of this file for cache type and cache_options - function getID3_cached_dbm($cache_type, $dbm_filename, $lock_filename) { + /** + * @var resource|bool + */ + private $lock; + + /** + * @var string + */ + private $cache_type; + + /** + * @var string + */ + private $dbm_filename; + + /** + * constructor - see top of this file for cache type and cache_options + * + * @param string $cache_type + * @param string $dbm_filename + * @param string $lock_filename + * + * @throws Exception + * @throws getid3_exception + */ + public function __construct($cache_type, $dbm_filename, $lock_filename) { // Check for dba extension if (!extension_loaded('dba')) { @@ -120,7 +149,7 @@ class getID3_cached_dbm extends getID3 } // Insert getID3 version number - dba_insert(GETID3_VERSION, GETID3_VERSION, $this->dba); + dba_insert(getID3::VERSION, getID3::VERSION, $this->dba); } // Init misc values @@ -131,17 +160,19 @@ class getID3_cached_dbm extends getID3 register_shutdown_function(array($this, '__destruct')); // Check version number and clear cache if changed - if (dba_fetch(GETID3_VERSION, $this->dba) != GETID3_VERSION) { + if (dba_fetch(getID3::VERSION, $this->dba) != getID3::VERSION) { $this->clear_cache(); } - parent::getID3(); + parent::__construct(); } - // public: destuctor - function __destruct() { + /** + * destructor + */ + public function __destruct() { // Close dbm file dba_close($this->dba); @@ -155,8 +186,12 @@ class getID3_cached_dbm extends getID3 - // public: clear cache - function clear_cache() { + /** + * clear cache + * + * @throws Exception + */ + public function clear_cache() { // Close dbm file dba_close($this->dba); @@ -169,7 +204,7 @@ class getID3_cached_dbm extends getID3 } // Insert getID3 version number - dba_insert(GETID3_VERSION, GETID3_VERSION, $this->dba); + dba_insert(getID3::VERSION, getID3::VERSION, $this->dba); // Re-register shutdown function register_shutdown_function(array($this, '__destruct')); @@ -177,9 +212,19 @@ class getID3_cached_dbm extends getID3 - // public: analyze file - function analyze($filename) { + /** + * clear cache + * + * @param string $filename + * @param int $filesize + * @param string $original_filename + * @param resource $fp + * + * @return mixed + */ + public function analyze($filename, $filesize=null, $original_filename='', $fp=null) { + $key = null; if (file_exists($filename)) { // Calc key filename::mod_time::size - should be unique @@ -195,10 +240,10 @@ class getID3_cached_dbm extends getID3 } // Miss - $result = parent::analyze($filename); + $result = parent::analyze($filename, $filesize, $original_filename, $fp); // Save result - if (file_exists($filename)) { + if (isset($key) && file_exists($filename)) { dba_insert($key, serialize($result), $this->dba); } @@ -206,6 +251,3 @@ class getID3_cached_dbm extends getID3 } } - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/extension.cache.mysql.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/extension.cache.mysql.php new file mode 100644 index 00000000..6444bcd1 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/extension.cache.mysql.php @@ -0,0 +1,227 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// extension.cache.mysql.php - part of getID3() // +// Please see readme.txt for more information // +// /// +///////////////////////////////////////////////////////////////// +// // +// This extension written by Allan Hansen // +// Table name mod by Carlo Capocasa // +// /// +///////////////////////////////////////////////////////////////// + + +/** +* This is a caching extension for getID3(). It works the exact same +* way as the getID3 class, but return cached information very fast +* +* Example: (see also demo.cache.mysql.php in /demo/) +* +* Normal getID3 usage (example): +* +* require_once 'getid3/getid3.php'; +* $getID3 = new getID3; +* $getID3->encoding = 'UTF-8'; +* $info1 = $getID3->analyze('file1.flac'); +* $info2 = $getID3->analyze('file2.wv'); +* +* getID3_cached usage: +* +* require_once 'getid3/getid3.php'; +* require_once 'getid3/getid3/extension.cache.mysql.php'; +* // 5th parameter (tablename) is optional, default is 'getid3_cache' +* $getID3 = new getID3_cached_mysql('localhost', 'database', 'username', 'password', 'tablename'); +* $getID3->encoding = 'UTF-8'; +* $info1 = $getID3->analyze('file1.flac'); +* $info2 = $getID3->analyze('file2.wv'); +* +* +* Supported Cache Types (this extension) +* +* SQL Databases: +* +* cache_type cache_options +* ------------------------------------------------------------------- +* mysql host, database, username, password +* +* +* DBM-Style Databases: (use extension.cache.dbm) +* +* cache_type cache_options +* ------------------------------------------------------------------- +* gdbm dbm_filename, lock_filename +* ndbm dbm_filename, lock_filename +* db2 dbm_filename, lock_filename +* db3 dbm_filename, lock_filename +* db4 dbm_filename, lock_filename (PHP5 required) +* +* PHP must have write access to both dbm_filename and lock_filename. +* +* +* Recommended Cache Types +* +* Infrequent updates, many reads any DBM +* Frequent updates mysql +*/ + + +class getID3_cached_mysql extends getID3 +{ + /** + * @var resource + */ + private $cursor; + + /** + * @var resource + */ + private $connection; + + /** + * @var string + */ + private $table; + + + /** + * constructor - see top of this file for cache type and cache_options + * + * @param string $host + * @param string $database + * @param string $username + * @param string $password + * @param string $table + * + * @throws Exception + * @throws getid3_exception + */ + public function __construct($host, $database, $username, $password, $table='getid3_cache') { + + // Check for mysql support + if (!function_exists('mysql_pconnect')) { + throw new Exception('PHP not compiled with mysql support.'); + } + + // Connect to database + $this->connection = mysql_pconnect($host, $username, $password); + if (!$this->connection) { + throw new Exception('mysql_pconnect() failed - check permissions and spelling.'); + } + + // Select database + if (!mysql_select_db($database, $this->connection)) { + throw new Exception('Cannot use database '.$database); + } + + // Set table + $this->table = $table; + + // Create cache table if not exists + $this->create_table(); + + // Check version number and clear cache if changed + $version = ''; + $SQLquery = 'SELECT `value`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string($this->table).'`'; + $SQLquery .= ' WHERE (`filename` = \''.mysql_real_escape_string(getID3::VERSION).'\')'; + $SQLquery .= ' AND (`filesize` = -1)'; + $SQLquery .= ' AND (`filetime` = -1)'; + $SQLquery .= ' AND (`analyzetime` = -1)'; + if ($this->cursor = mysql_query($SQLquery, $this->connection)) { + list($version) = mysql_fetch_array($this->cursor); + } + if ($version != getID3::VERSION) { + $this->clear_cache(); + } + + parent::__construct(); + } + + + + /** + * clear cache + */ + public function clear_cache() { + + $this->cursor = mysql_query('DELETE FROM `'.mysql_real_escape_string($this->table).'`', $this->connection); + $this->cursor = mysql_query('INSERT INTO `'.mysql_real_escape_string($this->table).'` VALUES (\''.getID3::VERSION.'\', -1, -1, -1, \''.getID3::VERSION.'\')', $this->connection); + } + + + + /** + * analyze file + * + * @param string $filename + * @param int $filesize + * @param string $original_filename + * @param resource $fp + * + * @return mixed + */ + public function analyze($filename, $filesize=null, $original_filename='', $fp=null) { + + $filetime = 0; + if (file_exists($filename)) { + + // Short-hands + $filetime = filemtime($filename); + $filesize = filesize($filename); + + // Lookup file + $SQLquery = 'SELECT `value`'; + $SQLquery .= ' FROM `'.mysql_real_escape_string($this->table).'`'; + $SQLquery .= ' WHERE (`filename` = \''.mysql_real_escape_string($filename).'\')'; + $SQLquery .= ' AND (`filesize` = \''.mysql_real_escape_string($filesize).'\')'; + $SQLquery .= ' AND (`filetime` = \''.mysql_real_escape_string($filetime).'\')'; + $this->cursor = mysql_query($SQLquery, $this->connection); + if (mysql_num_rows($this->cursor) > 0) { + // Hit + list($result) = mysql_fetch_array($this->cursor); + return unserialize(base64_decode($result)); + } + } + + // Miss + $analysis = parent::analyze($filename, $filesize, $original_filename, $fp); + + // Save result + if (file_exists($filename)) { + $SQLquery = 'INSERT INTO `'.mysql_real_escape_string($this->table).'` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES ('; + $SQLquery .= '\''.mysql_real_escape_string($filename).'\''; + $SQLquery .= ', \''.mysql_real_escape_string($filesize).'\''; + $SQLquery .= ', \''.mysql_real_escape_string($filetime).'\''; + $SQLquery .= ', \''.mysql_real_escape_string(time() ).'\''; + $SQLquery .= ', \''.mysql_real_escape_string(base64_encode(serialize($analysis))).'\')'; + $this->cursor = mysql_query($SQLquery, $this->connection); + } + return $analysis; + } + + + + /** + * (re)create sql table + * + * @param bool $drop + */ + private function create_table($drop=false) { + + $SQLquery = 'CREATE TABLE IF NOT EXISTS `'.mysql_real_escape_string($this->table).'` ('; + $SQLquery .= '`filename` VARCHAR(990) NOT NULL DEFAULT \'\''; + $SQLquery .= ', `filesize` INT(11) NOT NULL DEFAULT \'0\''; + $SQLquery .= ', `filetime` INT(11) NOT NULL DEFAULT \'0\''; + $SQLquery .= ', `analyzetime` INT(11) NOT NULL DEFAULT \'0\''; + $SQLquery .= ', `value` LONGTEXT NOT NULL'; + $SQLquery .= ', PRIMARY KEY (`filename`, `filesize`, `filetime`))'; + $this->cursor = mysql_query($SQLquery, $this->connection); + echo mysql_error($this->connection); + } +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/extension.cache.mysqli.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/extension.cache.mysqli.php new file mode 100644 index 00000000..cee2c53d --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/extension.cache.mysqli.php @@ -0,0 +1,263 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// extension.cache.mysqli.php - part of getID3() // +// Please see readme.txt for more information // +// // +///////////////////////////////////////////////////////////////// +// // +// This extension written by Allan Hansen // +// Table name mod by Carlo Capocasa // +// /// +///////////////////////////////////////////////////////////////// + + +/** +* This is a caching extension for getID3(). It works the exact same +* way as the getID3 class, but return cached information very fast +* +* Example: (see also demo.cache.mysql.php in /demo/) +* +* Normal getID3 usage (example): +* +* require_once 'getid3/getid3.php'; +* $getID3 = new getID3; +* $getID3->encoding = 'UTF-8'; +* $info1 = $getID3->analyze('file1.flac'); +* $info2 = $getID3->analyze('file2.wv'); +* +* getID3_cached usage: +* +* require_once 'getid3/getid3.php'; +* require_once 'getid3/getid3/extension.cache.mysqli.php'; +* // 5th parameter (tablename) is optional, default is 'getid3_cache' +* $getID3 = new getID3_cached_mysqli('localhost', 'database', 'username', 'password', 'tablename'); +* $getID3->encoding = 'UTF-8'; +* $info1 = $getID3->analyze('file1.flac'); +* $info2 = $getID3->analyze('file2.wv'); +* +* +* Supported Cache Types (this extension) +* +* SQL Databases: +* +* cache_type cache_options +* ------------------------------------------------------------------- +* mysqli host, database, username, password +* +* +* DBM-Style Databases: (use extension.cache.dbm) +* +* cache_type cache_options +* ------------------------------------------------------------------- +* gdbm dbm_filename, lock_filename +* ndbm dbm_filename, lock_filename +* db2 dbm_filename, lock_filename +* db3 dbm_filename, lock_filename +* db4 dbm_filename, lock_filename (PHP5 required) +* +* PHP must have write access to both dbm_filename and lock_filename. +* +* +* Recommended Cache Types +* +* Infrequent updates, many reads any DBM +* Frequent updates mysqli +*/ + +class getID3_cached_mysqli extends getID3 +{ + /** + * @var mysqli + */ + private $mysqli; + + /** + * @var mysqli_result + */ + private $cursor; + + /** + * @var string + */ + private $table; + + /** + * @var bool + */ + private $db_structure_check; + + + /** + * constructor - see top of this file for cache type and cache_options + * + * @param string $host + * @param string $database + * @param string $username + * @param string $password + * @param string $table + * + * @throws Exception + * @throws getid3_exception + */ + public function __construct($host, $database, $username, $password, $table='getid3_cache') { + + // Check for mysqli support + if (!function_exists('mysqli_connect')) { + throw new Exception('PHP not compiled with mysqli support.'); + } + + // Connect to database + $this->mysqli = new mysqli($host, $username, $password); + if ($this->mysqli->connect_error) { + throw new Exception('Connect Error (' . $this->mysqli->connect_errno . ') ' . $this->mysqli->connect_error); + } + + // Select database + if (!$this->mysqli->select_db($database)) { + throw new Exception('Cannot use database '.$database); + } + + // Set table + $this->table = $table; + + // Create cache table if not exists + $this->create_table(); + + $this->db_structure_check = true; // set to false if you know your table structure has already been migrated to use `hash` as the primary key to avoid + $this->migrate_db_structure(); + + // Check version number and clear cache if changed + $version = ''; + $SQLquery = 'SELECT `value`'; + $SQLquery .= ' FROM `'.$this->mysqli->real_escape_string($this->table).'`'; + $SQLquery .= ' WHERE (`filename` = \''.$this->mysqli->real_escape_string(getID3::VERSION).'\')'; + $SQLquery .= ' AND (`hash` = \'getID3::VERSION\')'; + if ($this->cursor = $this->mysqli->query($SQLquery)) { + list($version) = $this->cursor->fetch_array(); + } + if ($version != getID3::VERSION) { + $this->clear_cache(); + } + + parent::__construct(); + } + + + /** + * clear cache + */ + public function clear_cache() { + $this->mysqli->query('TRUNCATE TABLE `'.$this->mysqli->real_escape_string($this->table).'`'); + $this->mysqli->query('INSERT INTO `'.$this->mysqli->real_escape_string($this->table).'` (`hash`, `filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES (\'getID3::VERSION\', \''.getID3::VERSION.'\', -1, -1, -1, \''.getID3::VERSION.'\')'); + } + + + /** + * migrate database structure if needed + */ + public function migrate_db_structure() { + // Check for table structure + if ($this->db_structure_check) { + $SQLquery = 'SHOW COLUMNS'; + $SQLquery .= ' FROM `'.$this->mysqli->real_escape_string($this->table).'`'; + $SQLquery .= ' LIKE \'hash\''; + $this->cursor = $this->mysqli->query($SQLquery); + if ($this->cursor->num_rows == 0) { + // table has not been migrated, add column, add hashes, change index + $SQLquery = 'ALTER TABLE `getid3_cache` DROP PRIMARY KEY, ADD `hash` CHAR(32) NOT NULL DEFAULT \'\' FIRST, ADD PRIMARY KEY(`hash`)'; + $this->mysqli->query($SQLquery); + + $SQLquery = 'UPDATE `getid3_cache` SET'; + $SQLquery .= ' `hash` = MD5(`filename`, `filesize`, `filetime`)'; + $SQLquery .= ' WHERE (`filesize` > -1)'; + $this->mysqli->query($SQLquery); + + $SQLquery = 'UPDATE `getid3_cache` SET'; + $SQLquery .= ' `hash` = \'getID3::VERSION\''; + $SQLquery .= ' WHERE (`filesize` = -1)'; + $SQLquery .= ' AND (`filetime` = -1)'; + $SQLquery .= ' AND (`filetime` = -1)'; + $this->mysqli->query($SQLquery); + } + } + } + + + /** + * analyze file + * + * @param string $filename + * @param int $filesize + * @param string $original_filename + * @param resource $fp + * + * @return mixed + */ + public function analyze($filename, $filesize=null, $original_filename='', $fp=null) { + + $filetime = 0; + if (file_exists($filename)) { + + // Short-hands + $filetime = filemtime($filename); + $filesize = filesize($filename); + + // Lookup file + $SQLquery = 'SELECT `value`'; + $SQLquery .= ' FROM `'.$this->mysqli->real_escape_string($this->table).'`'; + $SQLquery .= ' WHERE (`hash` = \''.$this->mysqli->real_escape_string(md5($filename.$filesize.$filetime)).'\')'; + $this->cursor = $this->mysqli->query($SQLquery); + if ($this->cursor->num_rows > 0) { + // Hit + list($result) = $this->cursor->fetch_array(); + return unserialize(base64_decode($result)); + } + } + + // Miss + $analysis = parent::analyze($filename, $filesize, $original_filename, $fp); + + // Save result + if (file_exists($filename)) { + $SQLquery = 'INSERT INTO `'.$this->mysqli->real_escape_string($this->table).'` (`hash`, `filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES ('; + $SQLquery .= '\''.$this->mysqli->real_escape_string(md5($filename.$filesize.$filetime)).'\''; + $SQLquery .= ', \''.$this->mysqli->real_escape_string($filename).'\''; + $SQLquery .= ', \''.$this->mysqli->real_escape_string($filesize).'\''; + $SQLquery .= ', \''.$this->mysqli->real_escape_string($filetime).'\''; + $SQLquery .= ', UNIX_TIMESTAMP()'; + $SQLquery .= ', \''.$this->mysqli->real_escape_string(base64_encode(serialize($analysis))).'\''; + $SQLquery .= ')'; + $this->cursor = $this->mysqli->query($SQLquery); + } + return $analysis; + } + + + /** + * (re)create mysqli table + * + * @param bool $drop + */ + private function create_table($drop=false) { + if ($drop) { + $SQLquery = 'DROP TABLE IF EXISTS `'.$this->mysqli->real_escape_string($this->table).'`'; + $this->mysqli->query($SQLquery); + } + $SQLquery = 'CREATE TABLE IF NOT EXISTS `'.$this->mysqli->real_escape_string($this->table).'` ('; + $SQLquery .= '`hash` CHAR(32) NOT NULL DEFAULT \'\''; + $SQLquery .= ', `filename` VARCHAR(1000) NOT NULL DEFAULT \'\''; + $SQLquery .= ', `filesize` INT(11) NOT NULL DEFAULT \'0\''; + $SQLquery .= ', `filetime` INT(11) NOT NULL DEFAULT \'0\''; + $SQLquery .= ', `analyzetime` INT(11) NOT NULL DEFAULT \'0\''; + $SQLquery .= ', `value` LONGTEXT NOT NULL'; + $SQLquery .= ', PRIMARY KEY (`hash`))'; + $this->cursor = $this->mysqli->query($SQLquery); + echo $this->mysqli->error; + } +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/extension.cache.sqlite3.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/extension.cache.sqlite3.php new file mode 100644 index 00000000..dbcc72aa --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/extension.cache.sqlite3.php @@ -0,0 +1,297 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// extension.cache.mysqli.php - part of getID3() // +// Please see readme.txt for more information // +// // +///////////////////////////////////////////////////////////////// +// // +// extension.cache.sqlite3.php - part of getID3() // +// Please see readme.txt for more information // +// // +///////////////////////////////////////////////////////////////// +/// // +// MySQL extension written by Allan Hansen // +// Table name mod by Carlo Capocasa // +// MySQL extension was reworked for SQLite3 by // +// Karl G. Holz // +// /// +///////////////////////////////////////////////////////////////// + +/** +* This is a caching extension for getID3(). It works the exact same +* way as the getID3 class, but return cached information much faster +* +* Normal getID3 usage (example): +* +* require_once 'getid3/getid3.php'; +* $getID3 = new getID3; +* $getID3->encoding = 'UTF-8'; +* $info1 = $getID3->analyze('file1.flac'); +* $info2 = $getID3->analyze('file2.wv'); +* +* getID3_cached usage: +* +* require_once 'getid3/getid3.php'; +* require_once 'getid3/extension.cache.sqlite3.php'; +* // all parameters are optional, defaults are: +* $getID3 = new getID3_cached_sqlite3($table='getid3_cache', $hide=FALSE); +* $getID3->encoding = 'UTF-8'; +* $info1 = $getID3->analyze('file1.flac'); +* $info2 = $getID3->analyze('file2.wv'); +* +* +* Supported Cache Types (this extension) +* +* SQL Databases: +* +* cache_type cache_options +* ------------------------------------------------------------------- +* mysql host, database, username, password +* +* sqlite3 table='getid3_cache', hide=false (PHP5) +* +* +* *** database file will be stored in the same directory as this script, +* *** webserver must have write access to that directory! +* *** set $hide to TRUE to prefix db file with .ht to pervent access from web client +* *** this is a default setting in the Apache configuration: +* +* The following lines prevent .htaccess and .htpasswd files from being viewed by Web clients. +* +* +* Order allow,deny +* Deny from all +* Satisfy all +* +* +******************************************************************************** +* +* ------------------------------------------------------------------- +* DBM-Style Databases: (use extension.cache.dbm) +* +* cache_type cache_options +* ------------------------------------------------------------------- +* gdbm dbm_filename, lock_filename +* ndbm dbm_filename, lock_filename +* db2 dbm_filename, lock_filename +* db3 dbm_filename, lock_filename +* db4 dbm_filename, lock_filename (PHP5 required) +* +* PHP must have write access to both dbm_filename and lock_filename. +* +* Recommended Cache Types +* +* Infrequent updates, many reads any DBM +* Frequent updates mysql +******************************************************************************** +* +* IMHO this is still a bit slow, I'm using this with MP4/MOV/ M4v files +* there is a plan to add directory scanning and analyzing to make things work much faster +* +* +*/ +class getID3_cached_sqlite3 extends getID3 +{ + /** + * hold the sqlite db + * + * @var SQLite3 Resource + */ + private $db; + + /** + * table to use for caching + * + * @var string $table + */ + private $table; + + /** + * @param string $table holds name of sqlite table + * @param boolean $hide + * + * @throws getid3_exception + * @throws Exception + */ + public function __construct($table='getid3_cache', $hide=false) { + // Check for SQLite3 support + if (!function_exists('sqlite_open')) { + throw new Exception('PHP not compiled with SQLite3 support.'); + } + + $this->table = $table; // Set table + $file = dirname(__FILE__).'/'.basename(__FILE__, 'php').'sqlite'; + if ($hide) { + $file = dirname(__FILE__).'/.ht.'.basename(__FILE__, 'php').'sqlite'; + } + $this->db = new SQLite3($file); + $db = $this->db; + $this->create_table(); // Create cache table if not exists + $version = ''; + $sql = $this->getQuery('version_check'); + $stmt = $db->prepare($sql); + $stmt->bindValue(':filename', getID3::VERSION, SQLITE3_TEXT); + $result = $stmt->execute(); + list($version) = $result->fetchArray(); + if ($version != getID3::VERSION) { // Check version number and clear cache if changed + $this->clear_cache(); + } + parent::__construct(); + } + + /** + * close the database connection + */ + public function __destruct() { + $db=$this->db; + $db->close(); + } + + /** + * clear the cache + * + * @return SQLite3Result + */ + private function clear_cache() { + $db = $this->db; + $sql = $this->getQuery('delete_cache'); + $db->exec($sql); + $sql = $this->getQuery('set_version'); + $stmt = $db->prepare($sql); + $stmt->bindValue(':filename', getID3::VERSION, SQLITE3_TEXT); + $stmt->bindValue(':dirname', getID3::VERSION, SQLITE3_TEXT); + $stmt->bindValue(':val', getID3::VERSION, SQLITE3_TEXT); + return $stmt->execute(); + } + + /** + * analyze file and cache them, if cached pull from the db + * + * @param string $filename + * @param integer $filesize + * @param string $original_filename + * @param resource $fp + * + * @return mixed|false + */ + public function analyze($filename, $filesize=null, $original_filename='', $fp=null) { + if (!file_exists($filename)) { + return false; + } + // items to track for caching + $filetime = filemtime($filename); + $filesize_real = filesize($filename); + // this will be saved for a quick directory lookup of analized files + // ... why do 50 seperate sql quries when you can do 1 for the same result + $dirname = dirname($filename); + // Lookup file + $db = $this->db; + $sql = $this->getQuery('get_id3_data'); + $stmt = $db->prepare($sql); + $stmt->bindValue(':filename', $filename, SQLITE3_TEXT); + $stmt->bindValue(':filesize', $filesize_real, SQLITE3_INTEGER); + $stmt->bindValue(':filetime', $filetime, SQLITE3_INTEGER); + $res = $stmt->execute(); + list($result) = $res->fetchArray(); + if (count($result) > 0 ) { + return unserialize(base64_decode($result)); + } + // if it hasn't been analyzed before, then do it now + $analysis = parent::analyze($filename, $filesize, $original_filename, $fp); + // Save result + $sql = $this->getQuery('cache_file'); + $stmt = $db->prepare($sql); + $stmt->bindValue(':filename', $filename, SQLITE3_TEXT); + $stmt->bindValue(':dirname', $dirname, SQLITE3_TEXT); + $stmt->bindValue(':filesize', $filesize_real, SQLITE3_INTEGER); + $stmt->bindValue(':filetime', $filetime, SQLITE3_INTEGER); + $stmt->bindValue(':atime', time(), SQLITE3_INTEGER); + $stmt->bindValue(':val', base64_encode(serialize($analysis)), SQLITE3_TEXT); + $res = $stmt->execute(); + return $analysis; + } + + /** + * create data base table + * this is almost the same as MySQL, with the exception of the dirname being added + * + * @return bool + */ + private function create_table() { + $db = $this->db; + $sql = $this->getQuery('make_table'); + return $db->exec($sql); + } + + /** + * get cached directory + * + * This function is not in the MySQL extention, it's ment to speed up requesting multiple files + * which is ideal for podcasting, playlists, etc. + * + * @param string $dir directory to search the cache database for + * + * @return array return an array of matching id3 data + */ + public function get_cached_dir($dir) { + $db = $this->db; + $rows = array(); + $sql = $this->getQuery('get_cached_dir'); + $stmt = $db->prepare($sql); + $stmt->bindValue(':dirname', $dir, SQLITE3_TEXT); + $res = $stmt->execute(); + while ($row=$res->fetchArray()) { + $rows[] = unserialize(base64_decode($row)); + } + return $rows; + } + + /** + * returns NULL if query is not found + * + * @param string $name + * + * @return null|string + */ + public function getQuery($name) + { + switch ($name) { + case 'version_check': + return "SELECT val FROM $this->table WHERE filename = :filename AND filesize = '-1' AND filetime = '-1' AND analyzetime = '-1'"; + case 'delete_cache': + return "DELETE FROM $this->table"; + case 'set_version': + return "INSERT INTO $this->table (filename, dirname, filesize, filetime, analyzetime, val) VALUES (:filename, :dirname, -1, -1, -1, :val)"; + case 'get_id3_data': + return "SELECT val FROM $this->table WHERE filename = :filename AND filesize = :filesize AND filetime = :filetime"; + case 'cache_file': + return "INSERT INTO $this->table (filename, dirname, filesize, filetime, analyzetime, val) VALUES (:filename, :dirname, :filesize, :filetime, :atime, :val)"; + case 'make_table': + return "CREATE TABLE IF NOT EXISTS $this->table (filename VARCHAR(255) DEFAULT '', dirname VARCHAR(255) DEFAULT '', filesize INT(11) DEFAULT '0', filetime INT(11) DEFAULT '0', analyzetime INT(11) DEFAULT '0', val text, PRIMARY KEY (filename, filesize, filetime))"; + case 'get_cached_dir': + return "SELECT val FROM $this->table WHERE dirname = :dirname"; + default: + return null; + } + } + + /** + * use the magical __get() for sql queries + * + * access as easy as $this->{case name}, returns NULL if query is not found + * + * @param string $name + * + * @return string + * @deprecated use getQuery() instead + */ + public function __get($name) { + return $this->getQuery($name); + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/getid3.lib.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/getid3.lib.php new file mode 100644 index 00000000..ba7a8e68 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/getid3.lib.php @@ -0,0 +1,1838 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// getid3.lib.php - part of getID3() // +// see readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +if(!defined('GETID3_LIBXML_OPTIONS') && defined('LIBXML_VERSION')) { + if(LIBXML_VERSION >= 20621) { + define('GETID3_LIBXML_OPTIONS', LIBXML_NOENT | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_COMPACT); + } else { + define('GETID3_LIBXML_OPTIONS', LIBXML_NOENT | LIBXML_NONET | LIBXML_NOWARNING); + } +} + +class getid3_lib +{ + /** + * @param string $string + * @param bool $hex + * @param bool $spaces + * @param string|bool $htmlencoding + * + * @return string + */ + public static function PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8') { + $returnstring = ''; + for ($i = 0; $i < strlen($string); $i++) { + if ($hex) { + $returnstring .= str_pad(dechex(ord($string[$i])), 2, '0', STR_PAD_LEFT); + } else { + $returnstring .= ' '.(preg_match("#[\x20-\x7E]#", $string[$i]) ? $string[$i] : '¤'); + } + if ($spaces) { + $returnstring .= ' '; + } + } + if (!empty($htmlencoding)) { + if ($htmlencoding === true) { + $htmlencoding = 'UTF-8'; // prior to getID3 v1.9.0 the function's 4th parameter was boolean + } + $returnstring = htmlentities($returnstring, ENT_QUOTES, $htmlencoding); + } + return $returnstring; + } + + /** + * Truncates a floating-point number at the decimal point. + * + * @param float $floatnumber + * + * @return float|int returns int (if possible, otherwise float) + */ + public static function trunc($floatnumber) { + if ($floatnumber >= 1) { + $truncatednumber = floor($floatnumber); + } elseif ($floatnumber <= -1) { + $truncatednumber = ceil($floatnumber); + } else { + $truncatednumber = 0; + } + if (self::intValueSupported($truncatednumber)) { + $truncatednumber = (int) $truncatednumber; + } + return $truncatednumber; + } + + /** + * @param int|null $variable + * @param int $increment + * + * @return bool + */ + public static function safe_inc(&$variable, $increment=1) { + if (isset($variable)) { + $variable += $increment; + } else { + $variable = $increment; + } + return true; + } + + /** + * @param int|float $floatnum + * + * @return int|float + */ + public static function CastAsInt($floatnum) { + // convert to float if not already + $floatnum = (float) $floatnum; + + // convert a float to type int, only if possible + if (self::trunc($floatnum) == $floatnum) { + // it's not floating point + if (self::intValueSupported($floatnum)) { + // it's within int range + $floatnum = (int) $floatnum; + } + } + return $floatnum; + } + + /** + * @param int $num + * + * @return bool + */ + public static function intValueSupported($num) { + // check if integers are 64-bit + static $hasINT64 = null; + if ($hasINT64 === null) { // 10x faster than is_null() + $hasINT64 = is_int(pow(2, 31)); // 32-bit int are limited to (2^31)-1 + if (!$hasINT64 && !defined('PHP_INT_MIN')) { + define('PHP_INT_MIN', ~PHP_INT_MAX); + } + } + // if integers are 64-bit - no other check required + if ($hasINT64 || (($num <= PHP_INT_MAX) && ($num >= PHP_INT_MIN))) { + return true; + } + return false; + } + + /** + * @param string $fraction + * + * @return float + */ + public static function DecimalizeFraction($fraction) { + list($numerator, $denominator) = explode('/', $fraction); + return $numerator / ($denominator ? $denominator : 1); + } + + /** + * @param string $binarynumerator + * + * @return float + */ + public static function DecimalBinary2Float($binarynumerator) { + $numerator = self::Bin2Dec($binarynumerator); + $denominator = self::Bin2Dec('1'.str_repeat('0', strlen($binarynumerator))); + return ($numerator / $denominator); + } + + /** + * @link http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html + * + * @param string $binarypointnumber + * @param int $maxbits + * + * @return array + */ + public static function NormalizeBinaryPoint($binarypointnumber, $maxbits=52) { + if (strpos($binarypointnumber, '.') === false) { + $binarypointnumber = '0.'.$binarypointnumber; + } elseif ($binarypointnumber[0] == '.') { + $binarypointnumber = '0'.$binarypointnumber; + } + $exponent = 0; + while (($binarypointnumber[0] != '1') || (substr($binarypointnumber, 1, 1) != '.')) { + if (substr($binarypointnumber, 1, 1) == '.') { + $exponent--; + $binarypointnumber = substr($binarypointnumber, 2, 1).'.'.substr($binarypointnumber, 3); + } else { + $pointpos = strpos($binarypointnumber, '.'); + $exponent += ($pointpos - 1); + $binarypointnumber = str_replace('.', '', $binarypointnumber); + $binarypointnumber = $binarypointnumber[0].'.'.substr($binarypointnumber, 1); + } + } + $binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2, '0', STR_PAD_RIGHT); + return array('normalized'=>$binarypointnumber, 'exponent'=>(int) $exponent); + } + + /** + * @link http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html + * + * @param float $floatvalue + * + * @return string + */ + public static function Float2BinaryDecimal($floatvalue) { + $maxbits = 128; // to how many bits of precision should the calculations be taken? + $intpart = self::trunc($floatvalue); + $floatpart = abs($floatvalue - $intpart); + $pointbitstring = ''; + while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits)) { + $floatpart *= 2; + $pointbitstring .= (string) self::trunc($floatpart); + $floatpart -= self::trunc($floatpart); + } + $binarypointnumber = decbin($intpart).'.'.$pointbitstring; + return $binarypointnumber; + } + + /** + * @link http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html + * + * @param float $floatvalue + * @param int $bits + * + * @return string|false + */ + public static function Float2String($floatvalue, $bits) { + $exponentbits = 0; + $fractionbits = 0; + switch ($bits) { + case 32: + $exponentbits = 8; + $fractionbits = 23; + break; + + case 64: + $exponentbits = 11; + $fractionbits = 52; + break; + + default: + return false; + } + if ($floatvalue >= 0) { + $signbit = '0'; + } else { + $signbit = '1'; + } + $normalizedbinary = self::NormalizeBinaryPoint(self::Float2BinaryDecimal($floatvalue), $fractionbits); + $biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary['exponent']; // (127 or 1023) +/- exponent + $exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits, '0', STR_PAD_LEFT); + $fractionbitstring = str_pad(substr($normalizedbinary['normalized'], 2), $fractionbits, '0', STR_PAD_RIGHT); + + return self::BigEndian2String(self::Bin2Dec($signbit.$exponentbitstring.$fractionbitstring), $bits % 8, false); + } + + /** + * @param string $byteword + * + * @return float|false + */ + public static function LittleEndian2Float($byteword) { + return self::BigEndian2Float(strrev($byteword)); + } + + /** + * ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic + * + * @link https://web.archive.org/web/20120325162206/http://www.psc.edu/general/software/packages/ieee/ieee.php + * @link http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html + * + * @param string $byteword + * + * @return float|false + */ + public static function BigEndian2Float($byteword) { + $bitword = self::BigEndian2Bin($byteword); + if (!$bitword) { + return 0; + } + $signbit = $bitword[0]; + $floatvalue = 0; + $exponentbits = 0; + $fractionbits = 0; + + switch (strlen($byteword) * 8) { + case 32: + $exponentbits = 8; + $fractionbits = 23; + break; + + case 64: + $exponentbits = 11; + $fractionbits = 52; + break; + + case 80: + // 80-bit Apple SANE format + // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/ + $exponentstring = substr($bitword, 1, 15); + $isnormalized = intval($bitword[16]); + $fractionstring = substr($bitword, 17, 63); + $exponent = pow(2, self::Bin2Dec($exponentstring) - 16383); + $fraction = $isnormalized + self::DecimalBinary2Float($fractionstring); + $floatvalue = $exponent * $fraction; + if ($signbit == '1') { + $floatvalue *= -1; + } + return $floatvalue; + + default: + return false; + } + $exponentstring = substr($bitword, 1, $exponentbits); + $fractionstring = substr($bitword, $exponentbits + 1, $fractionbits); + $exponent = self::Bin2Dec($exponentstring); + $fraction = self::Bin2Dec($fractionstring); + + if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) { + // Not a Number + $floatvalue = NAN; + } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) { + if ($signbit == '1') { + $floatvalue = -INF; + } else { + $floatvalue = INF; + } + } elseif (($exponent == 0) && ($fraction == 0)) { + if ($signbit == '1') { + $floatvalue = -0.0; + } else { + $floatvalue = 0.0; + } + } elseif (($exponent == 0) && ($fraction != 0)) { + // These are 'unnormalized' values + $floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * self::DecimalBinary2Float($fractionstring); + if ($signbit == '1') { + $floatvalue *= -1; + } + } elseif ($exponent != 0) { + $floatvalue = pow(2, ($exponent - (pow(2, $exponentbits - 1) - 1))) * (1 + self::DecimalBinary2Float($fractionstring)); + if ($signbit == '1') { + $floatvalue *= -1; + } + } + return (float) $floatvalue; + } + + /** + * @param string $byteword + * @param bool $synchsafe + * @param bool $signed + * + * @return int|float|false + * @throws Exception + */ + public static function BigEndian2Int($byteword, $synchsafe=false, $signed=false) { + $intvalue = 0; + $bytewordlen = strlen($byteword); + if ($bytewordlen == 0) { + return false; + } + for ($i = 0; $i < $bytewordlen; $i++) { + if ($synchsafe) { // disregard MSB, effectively 7-bit bytes + //$intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7); // faster, but runs into problems past 2^31 on 32-bit systems + $intvalue += (ord($byteword[$i]) & 0x7F) * pow(2, ($bytewordlen - 1 - $i) * 7); + } else { + $intvalue += ord($byteword[$i]) * pow(256, ($bytewordlen - 1 - $i)); + } + } + if ($signed && !$synchsafe) { + // synchsafe ints are not allowed to be signed + if ($bytewordlen <= PHP_INT_SIZE) { + $signMaskBit = 0x80 << (8 * ($bytewordlen - 1)); + if ($intvalue & $signMaskBit) { + $intvalue = 0 - ($intvalue & ($signMaskBit - 1)); + } + } else { + throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits ('.strlen($byteword).') in self::BigEndian2Int()'); + } + } + return self::CastAsInt($intvalue); + } + + /** + * @param string $byteword + * @param bool $signed + * + * @return int|float|false + */ + public static function LittleEndian2Int($byteword, $signed=false) { + return self::BigEndian2Int(strrev($byteword), false, $signed); + } + + /** + * @param string $byteword + * + * @return string + */ + public static function LittleEndian2Bin($byteword) { + return self::BigEndian2Bin(strrev($byteword)); + } + + /** + * @param string $byteword + * + * @return string + */ + public static function BigEndian2Bin($byteword) { + $binvalue = ''; + $bytewordlen = strlen($byteword); + for ($i = 0; $i < $bytewordlen; $i++) { + $binvalue .= str_pad(decbin(ord($byteword[$i])), 8, '0', STR_PAD_LEFT); + } + return $binvalue; + } + + /** + * @param int $number + * @param int $minbytes + * @param bool $synchsafe + * @param bool $signed + * + * @return string + * @throws Exception + */ + public static function BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false) { + if ($number < 0) { + throw new Exception('ERROR: self::BigEndian2String() does not support negative numbers'); + } + $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF); + $intstring = ''; + if ($signed) { + if ($minbytes > PHP_INT_SIZE) { + throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits in self::BigEndian2String()'); + } + $number = $number & (0x80 << (8 * ($minbytes - 1))); + } + while ($number != 0) { + $quotient = ($number / ($maskbyte + 1)); + $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring; + $number = floor($quotient); + } + return str_pad($intstring, $minbytes, "\x00", STR_PAD_LEFT); + } + + /** + * @param int $number + * + * @return string + */ + public static function Dec2Bin($number) { + if (!is_numeric($number)) { + // https://github.com/JamesHeinrich/getID3/issues/299 + trigger_error('TypeError: Dec2Bin(): Argument #1 ($number) must be numeric, '.gettype($number).' given', E_USER_WARNING); + return ''; + } + $bytes = array(); + while ($number >= 256) { + $bytes[] = (int) (($number / 256) - (floor($number / 256))) * 256; + $number = floor($number / 256); + } + $bytes[] = (int) $number; + $binstring = ''; + foreach ($bytes as $i => $byte) { + $binstring = (($i == count($bytes) - 1) ? decbin($byte) : str_pad(decbin($byte), 8, '0', STR_PAD_LEFT)).$binstring; + } + return $binstring; + } + + /** + * @param string $binstring + * @param bool $signed + * + * @return int|float + */ + public static function Bin2Dec($binstring, $signed=false) { + $signmult = 1; + if ($signed) { + if ($binstring[0] == '1') { + $signmult = -1; + } + $binstring = substr($binstring, 1); + } + $decvalue = 0; + for ($i = 0; $i < strlen($binstring); $i++) { + $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i); + } + return self::CastAsInt($decvalue * $signmult); + } + + /** + * @param string $binstring + * + * @return string + */ + public static function Bin2String($binstring) { + // return 'hi' for input of '0110100001101001' + $string = ''; + $binstringreversed = strrev($binstring); + for ($i = 0; $i < strlen($binstringreversed); $i += 8) { + $string = chr(self::Bin2Dec(strrev(substr($binstringreversed, $i, 8)))).$string; + } + return $string; + } + + /** + * @param int $number + * @param int $minbytes + * @param bool $synchsafe + * + * @return string + */ + public static function LittleEndian2String($number, $minbytes=1, $synchsafe=false) { + $intstring = ''; + while ($number > 0) { + if ($synchsafe) { + $intstring = $intstring.chr($number & 127); + $number >>= 7; + } else { + $intstring = $intstring.chr($number & 255); + $number >>= 8; + } + } + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); + } + + /** + * @param mixed $array1 + * @param mixed $array2 + * + * @return array|false + */ + public static function array_merge_clobber($array1, $array2) { + // written by kcØhireability*com + // taken from http://www.php.net/manual/en/function.array-merge-recursive.php + if (!is_array($array1) || !is_array($array2)) { + return false; + } + $newarray = $array1; + foreach ($array2 as $key => $val) { + if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { + $newarray[$key] = self::array_merge_clobber($newarray[$key], $val); + } else { + $newarray[$key] = $val; + } + } + return $newarray; + } + + /** + * @param mixed $array1 + * @param mixed $array2 + * + * @return array|false + */ + public static function array_merge_noclobber($array1, $array2) { + if (!is_array($array1) || !is_array($array2)) { + return false; + } + $newarray = $array1; + foreach ($array2 as $key => $val) { + if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) { + $newarray[$key] = self::array_merge_noclobber($newarray[$key], $val); + } elseif (!isset($newarray[$key])) { + $newarray[$key] = $val; + } + } + return $newarray; + } + + /** + * @param mixed $array1 + * @param mixed $array2 + * + * @return array|false|null + */ + public static function flipped_array_merge_noclobber($array1, $array2) { + if (!is_array($array1) || !is_array($array2)) { + return false; + } + # naturally, this only works non-recursively + $newarray = array_flip($array1); + foreach (array_flip($array2) as $key => $val) { + if (!isset($newarray[$key])) { + $newarray[$key] = count($newarray); + } + } + return array_flip($newarray); + } + + /** + * @param array $theArray + * + * @return bool + */ + public static function ksort_recursive(&$theArray) { + ksort($theArray); + foreach ($theArray as $key => $value) { + if (is_array($value)) { + self::ksort_recursive($theArray[$key]); + } + } + return true; + } + + /** + * @param string $filename + * @param int $numextensions + * + * @return string + */ + public static function fileextension($filename, $numextensions=1) { + if (strstr($filename, '.')) { + $reversedfilename = strrev($filename); + $offset = 0; + for ($i = 0; $i < $numextensions; $i++) { + $offset = strpos($reversedfilename, '.', $offset + 1); + if ($offset === false) { + return ''; + } + } + return strrev(substr($reversedfilename, 0, $offset)); + } + return ''; + } + + /** + * @param int $seconds + * + * @return string + */ + public static function PlaytimeString($seconds) { + $sign = (($seconds < 0) ? '-' : ''); + $seconds = round(abs($seconds)); + $H = (int) floor( $seconds / 3600); + $M = (int) floor(($seconds - (3600 * $H) ) / 60); + $S = (int) round( $seconds - (3600 * $H) - (60 * $M) ); + return $sign.($H ? $H.':' : '').($H ? str_pad($M, 2, '0', STR_PAD_LEFT) : intval($M)).':'.str_pad($S, 2, 0, STR_PAD_LEFT); + } + + /** + * @param int $macdate + * + * @return int|float + */ + public static function DateMac2Unix($macdate) { + // Macintosh timestamp: seconds since 00:00h January 1, 1904 + // UNIX timestamp: seconds since 00:00h January 1, 1970 + return self::CastAsInt($macdate - 2082844800); + } + + /** + * @param string $rawdata + * + * @return float + */ + public static function FixedPoint8_8($rawdata) { + return self::BigEndian2Int(substr($rawdata, 0, 1)) + (float) (self::BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8)); + } + + /** + * @param string $rawdata + * + * @return float + */ + public static function FixedPoint16_16($rawdata) { + return self::BigEndian2Int(substr($rawdata, 0, 2)) + (float) (self::BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16)); + } + + /** + * @param string $rawdata + * + * @return float + */ + public static function FixedPoint2_30($rawdata) { + $binarystring = self::BigEndian2Bin($rawdata); + return self::Bin2Dec(substr($binarystring, 0, 2)) + (float) (self::Bin2Dec(substr($binarystring, 2, 30)) / pow(2, 30)); + } + + + /** + * @param string $ArrayPath + * @param string $Separator + * @param mixed $Value + * + * @return array + */ + public static function CreateDeepArray($ArrayPath, $Separator, $Value) { + // assigns $Value to a nested array path: + // $foo = self::CreateDeepArray('/path/to/my', '/', 'file.txt') + // is the same as: + // $foo = array('path'=>array('to'=>'array('my'=>array('file.txt')))); + // or + // $foo['path']['to']['my'] = 'file.txt'; + $ArrayPath = ltrim($ArrayPath, $Separator); + $ReturnedArray = array(); + if (($pos = strpos($ArrayPath, $Separator)) !== false) { + $ReturnedArray[substr($ArrayPath, 0, $pos)] = self::CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value); + } else { + $ReturnedArray[$ArrayPath] = $Value; + } + return $ReturnedArray; + } + + /** + * @param array $arraydata + * @param bool $returnkey + * + * @return int|false + */ + public static function array_max($arraydata, $returnkey=false) { + $maxvalue = false; + $maxkey = false; + foreach ($arraydata as $key => $value) { + if (!is_array($value)) { + if (($maxvalue === false) || ($value > $maxvalue)) { + $maxvalue = $value; + $maxkey = $key; + } + } + } + return ($returnkey ? $maxkey : $maxvalue); + } + + /** + * @param array $arraydata + * @param bool $returnkey + * + * @return int|false + */ + public static function array_min($arraydata, $returnkey=false) { + $minvalue = false; + $minkey = false; + foreach ($arraydata as $key => $value) { + if (!is_array($value)) { + if (($minvalue === false) || ($value < $minvalue)) { + $minvalue = $value; + $minkey = $key; + } + } + } + return ($returnkey ? $minkey : $minvalue); + } + + /** + * @param string $XMLstring + * + * @return array|false + */ + public static function XML2array($XMLstring) { + if (function_exists('simplexml_load_string') && function_exists('libxml_disable_entity_loader')) { + // http://websec.io/2012/08/27/Preventing-XEE-in-PHP.html + // https://core.trac.wordpress.org/changeset/29378 + // This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading is + // disabled by default, but is still needed when LIBXML_NOENT is used. + $loader = @libxml_disable_entity_loader(true); + $XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', GETID3_LIBXML_OPTIONS); + $return = self::SimpleXMLelement2array($XMLobject); + @libxml_disable_entity_loader($loader); + return $return; + } + return false; + } + + /** + * @param SimpleXMLElement|array|mixed $XMLobject + * + * @return mixed + */ + public static function SimpleXMLelement2array($XMLobject) { + if (!is_object($XMLobject) && !is_array($XMLobject)) { + return $XMLobject; + } + $XMLarray = $XMLobject instanceof SimpleXMLElement ? get_object_vars($XMLobject) : $XMLobject; + foreach ($XMLarray as $key => $value) { + $XMLarray[$key] = self::SimpleXMLelement2array($value); + } + return $XMLarray; + } + + /** + * Returns checksum for a file from starting position to absolute end position. + * + * @param string $file + * @param int $offset + * @param int $end + * @param string $algorithm + * + * @return string|false + * @throws getid3_exception + */ + public static function hash_data($file, $offset, $end, $algorithm) { + if (!self::intValueSupported($end)) { + return false; + } + if (!in_array($algorithm, array('md5', 'sha1'))) { + throw new getid3_exception('Invalid algorithm ('.$algorithm.') in self::hash_data()'); + } + + $size = $end - $offset; + + $fp = fopen($file, 'rb'); + fseek($fp, $offset); + $ctx = hash_init($algorithm); + while ($size > 0) { + $buffer = fread($fp, min($size, getID3::FREAD_BUFFER_SIZE)); + hash_update($ctx, $buffer); + $size -= getID3::FREAD_BUFFER_SIZE; + } + $hash = hash_final($ctx); + fclose($fp); + + return $hash; + } + + /** + * @param string $filename_source + * @param string $filename_dest + * @param int $offset + * @param int $length + * + * @return bool + * @throws Exception + * + * @deprecated Unused, may be removed in future versions of getID3 + */ + public static function CopyFileParts($filename_source, $filename_dest, $offset, $length) { + if (!self::intValueSupported($offset + $length)) { + throw new Exception('cannot copy file portion, it extends beyond the '.round(PHP_INT_MAX / 1073741824).'GB limit'); + } + if (is_readable($filename_source) && is_file($filename_source) && ($fp_src = fopen($filename_source, 'rb'))) { + if (($fp_dest = fopen($filename_dest, 'wb'))) { + if (fseek($fp_src, $offset) == 0) { + $byteslefttowrite = $length; + while (($byteslefttowrite > 0) && ($buffer = fread($fp_src, min($byteslefttowrite, getID3::FREAD_BUFFER_SIZE)))) { + $byteswritten = fwrite($fp_dest, $buffer, $byteslefttowrite); + $byteslefttowrite -= $byteswritten; + } + fclose($fp_dest); + return true; + } else { + fclose($fp_src); + throw new Exception('failed to seek to offset '.$offset.' in '.$filename_source); + } + } else { + throw new Exception('failed to create file for writing '.$filename_dest); + } + } else { + throw new Exception('failed to open file for reading '.$filename_source); + } + } + + /** + * @param int $charval + * + * @return string + */ + public static function iconv_fallback_int_utf8($charval) { + if ($charval < 128) { + // 0bbbbbbb + $newcharstring = chr($charval); + } elseif ($charval < 2048) { + // 110bbbbb 10bbbbbb + $newcharstring = chr(($charval >> 6) | 0xC0); + $newcharstring .= chr(($charval & 0x3F) | 0x80); + } elseif ($charval < 65536) { + // 1110bbbb 10bbbbbb 10bbbbbb + $newcharstring = chr(($charval >> 12) | 0xE0); + $newcharstring .= chr(($charval >> 6) | 0xC0); + $newcharstring .= chr(($charval & 0x3F) | 0x80); + } else { + // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb + $newcharstring = chr(($charval >> 18) | 0xF0); + $newcharstring .= chr(($charval >> 12) | 0xC0); + $newcharstring .= chr(($charval >> 6) | 0xC0); + $newcharstring .= chr(($charval & 0x3F) | 0x80); + } + return $newcharstring; + } + + /** + * ISO-8859-1 => UTF-8 + * + * @param string $string + * @param bool $bom + * + * @return string + */ + public static function iconv_fallback_iso88591_utf8($string, $bom=false) { + if (function_exists('utf8_encode')) { + return utf8_encode($string); + } + // utf8_encode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support) + $newcharstring = ''; + if ($bom) { + $newcharstring .= "\xEF\xBB\xBF"; + } + for ($i = 0; $i < strlen($string); $i++) { + $charval = ord($string[$i]); + $newcharstring .= self::iconv_fallback_int_utf8($charval); + } + return $newcharstring; + } + + /** + * ISO-8859-1 => UTF-16BE + * + * @param string $string + * @param bool $bom + * + * @return string + */ + public static function iconv_fallback_iso88591_utf16be($string, $bom=false) { + $newcharstring = ''; + if ($bom) { + $newcharstring .= "\xFE\xFF"; + } + for ($i = 0; $i < strlen($string); $i++) { + $newcharstring .= "\x00".$string[$i]; + } + return $newcharstring; + } + + /** + * ISO-8859-1 => UTF-16LE + * + * @param string $string + * @param bool $bom + * + * @return string + */ + public static function iconv_fallback_iso88591_utf16le($string, $bom=false) { + $newcharstring = ''; + if ($bom) { + $newcharstring .= "\xFF\xFE"; + } + for ($i = 0; $i < strlen($string); $i++) { + $newcharstring .= $string[$i]."\x00"; + } + return $newcharstring; + } + + /** + * ISO-8859-1 => UTF-16LE (BOM) + * + * @param string $string + * + * @return string + */ + public static function iconv_fallback_iso88591_utf16($string) { + return self::iconv_fallback_iso88591_utf16le($string, true); + } + + /** + * UTF-8 => ISO-8859-1 + * + * @param string $string + * + * @return string + */ + public static function iconv_fallback_utf8_iso88591($string) { + if (function_exists('utf8_decode')) { + return utf8_decode($string); + } + // utf8_decode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support) + $newcharstring = ''; + $offset = 0; + $stringlength = strlen($string); + while ($offset < $stringlength) { + if ((ord($string[$offset]) | 0x07) == 0xF7) { + // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x07) << 18) & + ((ord($string[($offset + 1)]) & 0x3F) << 12) & + ((ord($string[($offset + 2)]) & 0x3F) << 6) & + (ord($string[($offset + 3)]) & 0x3F); + $offset += 4; + } elseif ((ord($string[$offset]) | 0x0F) == 0xEF) { + // 1110bbbb 10bbbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x0F) << 12) & + ((ord($string[($offset + 1)]) & 0x3F) << 6) & + (ord($string[($offset + 2)]) & 0x3F); + $offset += 3; + } elseif ((ord($string[$offset]) | 0x1F) == 0xDF) { + // 110bbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x1F) << 6) & + (ord($string[($offset + 1)]) & 0x3F); + $offset += 2; + } elseif ((ord($string[$offset]) | 0x7F) == 0x7F) { + // 0bbbbbbb + $charval = ord($string[$offset]); + $offset += 1; + } else { + // error? throw some kind of warning here? + $charval = false; + $offset += 1; + } + if ($charval !== false) { + $newcharstring .= (($charval < 256) ? chr($charval) : '?'); + } + } + return $newcharstring; + } + + /** + * UTF-8 => UTF-16BE + * + * @param string $string + * @param bool $bom + * + * @return string + */ + public static function iconv_fallback_utf8_utf16be($string, $bom=false) { + $newcharstring = ''; + if ($bom) { + $newcharstring .= "\xFE\xFF"; + } + $offset = 0; + $stringlength = strlen($string); + while ($offset < $stringlength) { + if ((ord($string[$offset]) | 0x07) == 0xF7) { + // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x07) << 18) & + ((ord($string[($offset + 1)]) & 0x3F) << 12) & + ((ord($string[($offset + 2)]) & 0x3F) << 6) & + (ord($string[($offset + 3)]) & 0x3F); + $offset += 4; + } elseif ((ord($string[$offset]) | 0x0F) == 0xEF) { + // 1110bbbb 10bbbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x0F) << 12) & + ((ord($string[($offset + 1)]) & 0x3F) << 6) & + (ord($string[($offset + 2)]) & 0x3F); + $offset += 3; + } elseif ((ord($string[$offset]) | 0x1F) == 0xDF) { + // 110bbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x1F) << 6) & + (ord($string[($offset + 1)]) & 0x3F); + $offset += 2; + } elseif ((ord($string[$offset]) | 0x7F) == 0x7F) { + // 0bbbbbbb + $charval = ord($string[$offset]); + $offset += 1; + } else { + // error? throw some kind of warning here? + $charval = false; + $offset += 1; + } + if ($charval !== false) { + $newcharstring .= (($charval < 65536) ? self::BigEndian2String($charval, 2) : "\x00".'?'); + } + } + return $newcharstring; + } + + /** + * UTF-8 => UTF-16LE + * + * @param string $string + * @param bool $bom + * + * @return string + */ + public static function iconv_fallback_utf8_utf16le($string, $bom=false) { + $newcharstring = ''; + if ($bom) { + $newcharstring .= "\xFF\xFE"; + } + $offset = 0; + $stringlength = strlen($string); + while ($offset < $stringlength) { + if ((ord($string[$offset]) | 0x07) == 0xF7) { + // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x07) << 18) & + ((ord($string[($offset + 1)]) & 0x3F) << 12) & + ((ord($string[($offset + 2)]) & 0x3F) << 6) & + (ord($string[($offset + 3)]) & 0x3F); + $offset += 4; + } elseif ((ord($string[$offset]) | 0x0F) == 0xEF) { + // 1110bbbb 10bbbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x0F) << 12) & + ((ord($string[($offset + 1)]) & 0x3F) << 6) & + (ord($string[($offset + 2)]) & 0x3F); + $offset += 3; + } elseif ((ord($string[$offset]) | 0x1F) == 0xDF) { + // 110bbbbb 10bbbbbb + $charval = ((ord($string[($offset + 0)]) & 0x1F) << 6) & + (ord($string[($offset + 1)]) & 0x3F); + $offset += 2; + } elseif ((ord($string[$offset]) | 0x7F) == 0x7F) { + // 0bbbbbbb + $charval = ord($string[$offset]); + $offset += 1; + } else { + // error? maybe throw some warning here? + $charval = false; + $offset += 1; + } + if ($charval !== false) { + $newcharstring .= (($charval < 65536) ? self::LittleEndian2String($charval, 2) : '?'."\x00"); + } + } + return $newcharstring; + } + + /** + * UTF-8 => UTF-16LE (BOM) + * + * @param string $string + * + * @return string + */ + public static function iconv_fallback_utf8_utf16($string) { + return self::iconv_fallback_utf8_utf16le($string, true); + } + + /** + * UTF-16BE => UTF-8 + * + * @param string $string + * + * @return string + */ + public static function iconv_fallback_utf16be_utf8($string) { + if (substr($string, 0, 2) == "\xFE\xFF") { + // strip BOM + $string = substr($string, 2); + } + $newcharstring = ''; + for ($i = 0; $i < strlen($string); $i += 2) { + $charval = self::BigEndian2Int(substr($string, $i, 2)); + $newcharstring .= self::iconv_fallback_int_utf8($charval); + } + return $newcharstring; + } + + /** + * UTF-16LE => UTF-8 + * + * @param string $string + * + * @return string + */ + public static function iconv_fallback_utf16le_utf8($string) { + if (substr($string, 0, 2) == "\xFF\xFE") { + // strip BOM + $string = substr($string, 2); + } + $newcharstring = ''; + for ($i = 0; $i < strlen($string); $i += 2) { + $charval = self::LittleEndian2Int(substr($string, $i, 2)); + $newcharstring .= self::iconv_fallback_int_utf8($charval); + } + return $newcharstring; + } + + /** + * UTF-16BE => ISO-8859-1 + * + * @param string $string + * + * @return string + */ + public static function iconv_fallback_utf16be_iso88591($string) { + if (substr($string, 0, 2) == "\xFE\xFF") { + // strip BOM + $string = substr($string, 2); + } + $newcharstring = ''; + for ($i = 0; $i < strlen($string); $i += 2) { + $charval = self::BigEndian2Int(substr($string, $i, 2)); + $newcharstring .= (($charval < 256) ? chr($charval) : '?'); + } + return $newcharstring; + } + + /** + * UTF-16LE => ISO-8859-1 + * + * @param string $string + * + * @return string + */ + public static function iconv_fallback_utf16le_iso88591($string) { + if (substr($string, 0, 2) == "\xFF\xFE") { + // strip BOM + $string = substr($string, 2); + } + $newcharstring = ''; + for ($i = 0; $i < strlen($string); $i += 2) { + $charval = self::LittleEndian2Int(substr($string, $i, 2)); + $newcharstring .= (($charval < 256) ? chr($charval) : '?'); + } + return $newcharstring; + } + + /** + * UTF-16 (BOM) => ISO-8859-1 + * + * @param string $string + * + * @return string + */ + public static function iconv_fallback_utf16_iso88591($string) { + $bom = substr($string, 0, 2); + if ($bom == "\xFE\xFF") { + return self::iconv_fallback_utf16be_iso88591(substr($string, 2)); + } elseif ($bom == "\xFF\xFE") { + return self::iconv_fallback_utf16le_iso88591(substr($string, 2)); + } + return $string; + } + + /** + * UTF-16 (BOM) => UTF-8 + * + * @param string $string + * + * @return string + */ + public static function iconv_fallback_utf16_utf8($string) { + $bom = substr($string, 0, 2); + if ($bom == "\xFE\xFF") { + return self::iconv_fallback_utf16be_utf8(substr($string, 2)); + } elseif ($bom == "\xFF\xFE") { + return self::iconv_fallback_utf16le_utf8(substr($string, 2)); + } + return $string; + } + + /** + * @param string $in_charset + * @param string $out_charset + * @param string $string + * + * @return string + * @throws Exception + */ + public static function iconv_fallback($in_charset, $out_charset, $string) { + + if ($in_charset == $out_charset) { + return $string; + } + + // mb_convert_encoding() available + if (function_exists('mb_convert_encoding')) { + if ((strtoupper($in_charset) == 'UTF-16') && (substr($string, 0, 2) != "\xFE\xFF") && (substr($string, 0, 2) != "\xFF\xFE")) { + // if BOM missing, mb_convert_encoding will mishandle the conversion, assume UTF-16BE and prepend appropriate BOM + $string = "\xFF\xFE".$string; + } + if ((strtoupper($in_charset) == 'UTF-16') && (strtoupper($out_charset) == 'UTF-8')) { + if (($string == "\xFF\xFE") || ($string == "\xFE\xFF")) { + // if string consists of only BOM, mb_convert_encoding will return the BOM unmodified + return ''; + } + } + if ($converted_string = @mb_convert_encoding($string, $out_charset, $in_charset)) { + switch ($out_charset) { + case 'ISO-8859-1': + $converted_string = rtrim($converted_string, "\x00"); + break; + } + return $converted_string; + } + return $string; + + // iconv() available + } elseif (function_exists('iconv')) { + if ($converted_string = @iconv($in_charset, $out_charset.'//TRANSLIT', $string)) { + switch ($out_charset) { + case 'ISO-8859-1': + $converted_string = rtrim($converted_string, "\x00"); + break; + } + return $converted_string; + } + + // iconv() may sometimes fail with "illegal character in input string" error message + // and return an empty string, but returning the unconverted string is more useful + return $string; + } + + + // neither mb_convert_encoding or iconv() is available + static $ConversionFunctionList = array(); + if (empty($ConversionFunctionList)) { + $ConversionFunctionList['ISO-8859-1']['UTF-8'] = 'iconv_fallback_iso88591_utf8'; + $ConversionFunctionList['ISO-8859-1']['UTF-16'] = 'iconv_fallback_iso88591_utf16'; + $ConversionFunctionList['ISO-8859-1']['UTF-16BE'] = 'iconv_fallback_iso88591_utf16be'; + $ConversionFunctionList['ISO-8859-1']['UTF-16LE'] = 'iconv_fallback_iso88591_utf16le'; + $ConversionFunctionList['UTF-8']['ISO-8859-1'] = 'iconv_fallback_utf8_iso88591'; + $ConversionFunctionList['UTF-8']['UTF-16'] = 'iconv_fallback_utf8_utf16'; + $ConversionFunctionList['UTF-8']['UTF-16BE'] = 'iconv_fallback_utf8_utf16be'; + $ConversionFunctionList['UTF-8']['UTF-16LE'] = 'iconv_fallback_utf8_utf16le'; + $ConversionFunctionList['UTF-16']['ISO-8859-1'] = 'iconv_fallback_utf16_iso88591'; + $ConversionFunctionList['UTF-16']['UTF-8'] = 'iconv_fallback_utf16_utf8'; + $ConversionFunctionList['UTF-16LE']['ISO-8859-1'] = 'iconv_fallback_utf16le_iso88591'; + $ConversionFunctionList['UTF-16LE']['UTF-8'] = 'iconv_fallback_utf16le_utf8'; + $ConversionFunctionList['UTF-16BE']['ISO-8859-1'] = 'iconv_fallback_utf16be_iso88591'; + $ConversionFunctionList['UTF-16BE']['UTF-8'] = 'iconv_fallback_utf16be_utf8'; + } + if (isset($ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)])) { + $ConversionFunction = $ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)]; + return self::$ConversionFunction($string); + } + throw new Exception('PHP does not has mb_convert_encoding() or iconv() support - cannot convert from '.$in_charset.' to '.$out_charset); + } + + /** + * @param mixed $data + * @param string $charset + * + * @return mixed + */ + public static function recursiveMultiByteCharString2HTML($data, $charset='ISO-8859-1') { + if (is_string($data)) { + return self::MultiByteCharString2HTML($data, $charset); + } elseif (is_array($data)) { + $return_data = array(); + foreach ($data as $key => $value) { + $return_data[$key] = self::recursiveMultiByteCharString2HTML($value, $charset); + } + return $return_data; + } + // integer, float, objects, resources, etc + return $data; + } + + /** + * @param string|int|float $string + * @param string $charset + * + * @return string + */ + public static function MultiByteCharString2HTML($string, $charset='ISO-8859-1') { + $string = (string) $string; // in case trying to pass a numeric (float, int) string, would otherwise return an empty string + $HTMLstring = ''; + + switch (strtolower($charset)) { + case '1251': + case '1252': + case '866': + case '932': + case '936': + case '950': + case 'big5': + case 'big5-hkscs': + case 'cp1251': + case 'cp1252': + case 'cp866': + case 'euc-jp': + case 'eucjp': + case 'gb2312': + case 'ibm866': + case 'iso-8859-1': + case 'iso-8859-15': + case 'iso8859-1': + case 'iso8859-15': + case 'koi8-r': + case 'koi8-ru': + case 'koi8r': + case 'shift_jis': + case 'sjis': + case 'win-1251': + case 'windows-1251': + case 'windows-1252': + $HTMLstring = htmlentities($string, ENT_COMPAT, $charset); + break; + + case 'utf-8': + $strlen = strlen($string); + for ($i = 0; $i < $strlen; $i++) { + $char_ord_val = ord($string[$i]); + $charval = 0; + if ($char_ord_val < 0x80) { + $charval = $char_ord_val; + } elseif ((($char_ord_val & 0xF0) >> 4) == 0x0F && $i+3 < $strlen) { + $charval = (($char_ord_val & 0x07) << 18); + $charval += ((ord($string[++$i]) & 0x3F) << 12); + $charval += ((ord($string[++$i]) & 0x3F) << 6); + $charval += (ord($string[++$i]) & 0x3F); + } elseif ((($char_ord_val & 0xE0) >> 5) == 0x07 && $i+2 < $strlen) { + $charval = (($char_ord_val & 0x0F) << 12); + $charval += ((ord($string[++$i]) & 0x3F) << 6); + $charval += (ord($string[++$i]) & 0x3F); + } elseif ((($char_ord_val & 0xC0) >> 6) == 0x03 && $i+1 < $strlen) { + $charval = (($char_ord_val & 0x1F) << 6); + $charval += (ord($string[++$i]) & 0x3F); + } + if (($charval >= 32) && ($charval <= 127)) { + $HTMLstring .= htmlentities(chr($charval)); + } else { + $HTMLstring .= '&#'.$charval.';'; + } + } + break; + + case 'utf-16le': + for ($i = 0; $i < strlen($string); $i += 2) { + $charval = self::LittleEndian2Int(substr($string, $i, 2)); + if (($charval >= 32) && ($charval <= 127)) { + $HTMLstring .= chr($charval); + } else { + $HTMLstring .= '&#'.$charval.';'; + } + } + break; + + case 'utf-16be': + for ($i = 0; $i < strlen($string); $i += 2) { + $charval = self::BigEndian2Int(substr($string, $i, 2)); + if (($charval >= 32) && ($charval <= 127)) { + $HTMLstring .= chr($charval); + } else { + $HTMLstring .= '&#'.$charval.';'; + } + } + break; + + default: + $HTMLstring = 'ERROR: Character set "'.$charset.'" not supported in MultiByteCharString2HTML()'; + break; + } + return $HTMLstring; + } + + /** + * @param int $namecode + * + * @return string + */ + public static function RGADnameLookup($namecode) { + static $RGADname = array(); + if (empty($RGADname)) { + $RGADname[0] = 'not set'; + $RGADname[1] = 'Track Gain Adjustment'; + $RGADname[2] = 'Album Gain Adjustment'; + } + + return (isset($RGADname[$namecode]) ? $RGADname[$namecode] : ''); + } + + /** + * @param int $originatorcode + * + * @return string + */ + public static function RGADoriginatorLookup($originatorcode) { + static $RGADoriginator = array(); + if (empty($RGADoriginator)) { + $RGADoriginator[0] = 'unspecified'; + $RGADoriginator[1] = 'pre-set by artist/producer/mastering engineer'; + $RGADoriginator[2] = 'set by user'; + $RGADoriginator[3] = 'determined automatically'; + } + + return (isset($RGADoriginator[$originatorcode]) ? $RGADoriginator[$originatorcode] : ''); + } + + /** + * @param int $rawadjustment + * @param int $signbit + * + * @return float + */ + public static function RGADadjustmentLookup($rawadjustment, $signbit) { + $adjustment = (float) $rawadjustment / 10; + if ($signbit == 1) { + $adjustment *= -1; + } + return $adjustment; + } + + /** + * @param int $namecode + * @param int $originatorcode + * @param int $replaygain + * + * @return string + */ + public static function RGADgainString($namecode, $originatorcode, $replaygain) { + if ($replaygain < 0) { + $signbit = '1'; + } else { + $signbit = '0'; + } + $storedreplaygain = intval(round($replaygain * 10)); + $gainstring = str_pad(decbin($namecode), 3, '0', STR_PAD_LEFT); + $gainstring .= str_pad(decbin($originatorcode), 3, '0', STR_PAD_LEFT); + $gainstring .= $signbit; + $gainstring .= str_pad(decbin($storedreplaygain), 9, '0', STR_PAD_LEFT); + + return $gainstring; + } + + /** + * @param float $amplitude + * + * @return float + */ + public static function RGADamplitude2dB($amplitude) { + return 20 * log10($amplitude); + } + + /** + * @param string $imgData + * @param array $imageinfo + * + * @return array|false + */ + public static function GetDataImageSize($imgData, &$imageinfo=array()) { + if (PHP_VERSION_ID >= 50400) { + $GetDataImageSize = @getimagesizefromstring($imgData, $imageinfo); + if ($GetDataImageSize === false || !isset($GetDataImageSize[0], $GetDataImageSize[1])) { + return false; + } + $GetDataImageSize['height'] = $GetDataImageSize[0]; + $GetDataImageSize['width'] = $GetDataImageSize[1]; + return $GetDataImageSize; + } + static $tempdir = ''; + if (empty($tempdir)) { + if (function_exists('sys_get_temp_dir')) { + $tempdir = sys_get_temp_dir(); // https://github.com/JamesHeinrich/getID3/issues/52 + } + + // yes this is ugly, feel free to suggest a better way + if (include_once(dirname(__FILE__).'/getid3.php')) { + $getid3_temp = new getID3(); + if ($getid3_temp_tempdir = $getid3_temp->tempdir) { + $tempdir = $getid3_temp_tempdir; + } + unset($getid3_temp, $getid3_temp_tempdir); + } + } + $GetDataImageSize = false; + if ($tempfilename = tempnam($tempdir, 'gI3')) { + if (is_writable($tempfilename) && is_file($tempfilename) && ($tmp = fopen($tempfilename, 'wb'))) { + fwrite($tmp, $imgData); + fclose($tmp); + $GetDataImageSize = @getimagesize($tempfilename, $imageinfo); + if (($GetDataImageSize === false) || !isset($GetDataImageSize[0]) || !isset($GetDataImageSize[1])) { + return false; + } + $GetDataImageSize['height'] = $GetDataImageSize[0]; + $GetDataImageSize['width'] = $GetDataImageSize[1]; + } + unlink($tempfilename); + } + return $GetDataImageSize; + } + + /** + * @param string $mime_type + * + * @return string + */ + public static function ImageExtFromMime($mime_type) { + // temporary way, works OK for now, but should be reworked in the future + return str_replace(array('image/', 'x-', 'jpeg'), array('', '', 'jpg'), $mime_type); + } + + /** + * @param array $ThisFileInfo + * @param bool $option_tags_html default true (just as in the main getID3 class) + * + * @return bool + */ + public static function CopyTagsToComments(&$ThisFileInfo, $option_tags_html=true) { + // Copy all entries from ['tags'] into common ['comments'] + if (!empty($ThisFileInfo['tags'])) { + + // Some tag types can only support limited character sets and may contain data in non-standard encoding (usually ID3v1) + // and/or poorly-transliterated tag values that are also in tag formats that do support full-range character sets + // To make the output more user-friendly, process the potentially-problematic tag formats last to enhance the chance that + // the first entries in [comments] are the most correct and the "bad" ones (if any) come later. + // https://github.com/JamesHeinrich/getID3/issues/338 + $processLastTagTypes = array('id3v1','riff'); + foreach ($processLastTagTypes as $processLastTagType) { + if (isset($ThisFileInfo['tags'][$processLastTagType])) { + // bubble ID3v1 to the end, if present to aid in detecting bad ID3v1 encodings + $temp = $ThisFileInfo['tags'][$processLastTagType]; + unset($ThisFileInfo['tags'][$processLastTagType]); + $ThisFileInfo['tags'][$processLastTagType] = $temp; + unset($temp); + } + } + foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) { + foreach ($tagarray as $tagname => $tagdata) { + foreach ($tagdata as $key => $value) { + if (!empty($value)) { + if (empty($ThisFileInfo['comments'][$tagname])) { + + // fall through and append value + + } elseif ($tagtype == 'id3v1') { + + $newvaluelength = strlen(trim($value)); + foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) { + $oldvaluelength = strlen(trim($existingvalue)); + if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) { + // new value is identical but shorter-than (or equal-length to) one already in comments - skip + break 2; + } + + if (function_exists('mb_convert_encoding')) { + if (trim($value) == trim(substr(mb_convert_encoding($existingvalue, $ThisFileInfo['id3v1']['encoding'], $ThisFileInfo['encoding']), 0, 30))) { + // value stored in ID3v1 appears to be probably the multibyte value transliterated (badly) into ISO-8859-1 in ID3v1. + // As an example, Foobar2000 will do this if you tag a file with Chinese or Arabic or Cyrillic or something that doesn't fit into ISO-8859-1 the ID3v1 will consist of mostly "?" characters, one per multibyte unrepresentable character + break 2; + } + } + } + + } elseif (!is_array($value)) { + + $newvaluelength = strlen(trim($value)); + $newvaluelengthMB = mb_strlen(trim($value)); + foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) { + $oldvaluelength = strlen(trim($existingvalue)); + $oldvaluelengthMB = mb_strlen(trim($existingvalue)); + if (($newvaluelengthMB == $oldvaluelengthMB) && ($existingvalue == getid3_lib::iconv_fallback('UTF-8', 'ASCII', $value))) { + // https://github.com/JamesHeinrich/getID3/issues/338 + // check for tags containing extended characters that may have been forced into limited-character storage (e.g. UTF8 values into ASCII) + // which will usually display unrepresentable characters as "?" + $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value); + break; + } + if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) { + $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value); + break; + } + } + + } + if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) { + $value = (is_string($value) ? trim($value) : $value); + if (!is_int($key) && !ctype_digit($key)) { + $ThisFileInfo['comments'][$tagname][$key] = $value; + } else { + if (!isset($ThisFileInfo['comments'][$tagname])) { + $ThisFileInfo['comments'][$tagname] = array($value); + } else { + $ThisFileInfo['comments'][$tagname][] = $value; + } + } + } + } + } + } + } + + // attempt to standardize spelling of returned keys + if (!empty($ThisFileInfo['comments'])) { + $StandardizeFieldNames = array( + 'tracknumber' => 'track_number', + 'track' => 'track_number', + ); + foreach ($StandardizeFieldNames as $badkey => $goodkey) { + if (array_key_exists($badkey, $ThisFileInfo['comments']) && !array_key_exists($goodkey, $ThisFileInfo['comments'])) { + $ThisFileInfo['comments'][$goodkey] = $ThisFileInfo['comments'][$badkey]; + unset($ThisFileInfo['comments'][$badkey]); + } + } + } + + if ($option_tags_html) { + // Copy ['comments'] to ['comments_html'] + if (!empty($ThisFileInfo['comments'])) { + foreach ($ThisFileInfo['comments'] as $field => $values) { + if ($field == 'picture') { + // pictures can take up a lot of space, and we don't need multiple copies of them + // let there be a single copy in [comments][picture], and not elsewhere + continue; + } + foreach ($values as $index => $value) { + if (is_array($value)) { + $ThisFileInfo['comments_html'][$field][$index] = $value; + } else { + $ThisFileInfo['comments_html'][$field][$index] = str_replace('�', '', self::MultiByteCharString2HTML($value, $ThisFileInfo['encoding'])); + } + } + } + } + } + + } + return true; + } + + /** + * @param string $key + * @param int $begin + * @param int $end + * @param string $file + * @param string $name + * + * @return string + */ + public static function EmbeddedLookup($key, $begin, $end, $file, $name) { + + // Cached + static $cache; + if (isset($cache[$file][$name])) { + return (isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : ''); + } + + // Init + $keylength = strlen($key); + $line_count = $end - $begin - 7; + + // Open php file + $fp = fopen($file, 'r'); + + // Discard $begin lines + for ($i = 0; $i < ($begin + 3); $i++) { + fgets($fp, 1024); + } + + // Loop thru line + while (0 < $line_count--) { + + // Read line + $line = ltrim(fgets($fp, 1024), "\t "); + + // METHOD A: only cache the matching key - less memory but slower on next lookup of not-previously-looked-up key + //$keycheck = substr($line, 0, $keylength); + //if ($key == $keycheck) { + // $cache[$file][$name][$keycheck] = substr($line, $keylength + 1); + // break; + //} + + // METHOD B: cache all keys in this lookup - more memory but faster on next lookup of not-previously-looked-up key + //$cache[$file][$name][substr($line, 0, $keylength)] = trim(substr($line, $keylength + 1)); + $explodedLine = explode("\t", $line, 2); + $ThisKey = (isset($explodedLine[0]) ? $explodedLine[0] : ''); + $ThisValue = (isset($explodedLine[1]) ? $explodedLine[1] : ''); + $cache[$file][$name][$ThisKey] = trim($ThisValue); + } + + // Close and return + fclose($fp); + return (isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : ''); + } + + /** + * @param string $filename + * @param string $sourcefile + * @param bool $DieOnFailure + * + * @return bool + * @throws Exception + */ + public static function IncludeDependency($filename, $sourcefile, $DieOnFailure=false) { + global $GETID3_ERRORARRAY; + + if (file_exists($filename)) { + if (include_once($filename)) { + return true; + } else { + $diemessage = basename($sourcefile).' depends on '.$filename.', which has errors'; + } + } else { + $diemessage = basename($sourcefile).' depends on '.$filename.', which is missing'; + } + if ($DieOnFailure) { + throw new Exception($diemessage); + } else { + $GETID3_ERRORARRAY[] = $diemessage; + } + return false; + } + + /** + * @param string $string + * + * @return string + */ + public static function trimNullByte($string) { + return trim($string, "\x00"); + } + + /** + * @param string $path + * + * @return float|bool + */ + public static function getFileSizeSyscall($path) { + $commandline = null; + $filesize = false; + + if (GETID3_OS_ISWINDOWS) { + if (class_exists('COM')) { // From PHP 5.3.15 and 5.4.5, COM and DOTNET is no longer built into the php core.you have to add COM support in php.ini: + $filesystem = new COM('Scripting.FileSystemObject'); + $file = $filesystem->GetFile($path); + $filesize = $file->Size(); + unset($filesystem, $file); + } else { + $commandline = 'for %I in ('.escapeshellarg($path).') do @echo %~zI'; + } + } else { + $commandline = 'ls -l '.escapeshellarg($path).' | awk \'{print $5}\''; + } + if (isset($commandline)) { + $output = trim(`$commandline`); + if (ctype_digit($output)) { + $filesize = (float) $output; + } + } + return $filesize; + } + + /** + * @param string $filename + * + * @return string|false + */ + public static function truepath($filename) { + // 2017-11-08: this could use some improvement, patches welcome + if (preg_match('#^(\\\\\\\\|//)[a-z0-9]#i', $filename, $matches)) { + // PHP's built-in realpath function does not work on UNC Windows shares + $goodpath = array(); + foreach (explode('/', str_replace('\\', '/', $filename)) as $part) { + if ($part == '.') { + continue; + } + if ($part == '..') { + if (count($goodpath)) { + array_pop($goodpath); + } else { + // cannot step above this level, already at top level + return false; + } + } else { + $goodpath[] = $part; + } + } + return implode(DIRECTORY_SEPARATOR, $goodpath); + } + return realpath($filename); + } + + /** + * Workaround for Bug #37268 (https://bugs.php.net/bug.php?id=37268) + * + * @param string $path A path. + * @param string $suffix If the name component ends in suffix this will also be cut off. + * + * @return string + */ + public static function mb_basename($path, $suffix = '') { + $splited = preg_split('#/#', rtrim($path, '/ ')); + return substr(basename('X'.$splited[count($splited) - 1], $suffix), 1); + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/getid3.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/getid3.php new file mode 100644 index 00000000..5e955304 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/getid3.php @@ -0,0 +1,2474 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// // +// Please see readme.txt for more information // +// /// +///////////////////////////////////////////////////////////////// + +// define a constant rather than looking up every time it is needed +if (!defined('GETID3_OS_ISWINDOWS')) { + define('GETID3_OS_ISWINDOWS', (stripos(PHP_OS, 'WIN') === 0)); +} +// Get base path of getID3() - ONCE +if (!defined('GETID3_INCLUDEPATH')) { + define('GETID3_INCLUDEPATH', dirname(__FILE__).DIRECTORY_SEPARATOR); +} +if (!defined('ENT_SUBSTITUTE')) { // PHP5.3 adds ENT_IGNORE, PHP5.4 adds ENT_SUBSTITUTE + define('ENT_SUBSTITUTE', (defined('ENT_IGNORE') ? ENT_IGNORE : 8)); +} + +/* +https://www.getid3.org/phpBB3/viewtopic.php?t=2114 +If you are running into a the problem where filenames with special characters are being handled +incorrectly by external helper programs (e.g. metaflac), notably with the special characters removed, +and you are passing in the filename in UTF8 (typically via a HTML form), try uncommenting this line: +*/ +//setlocale(LC_CTYPE, 'en_US.UTF-8'); + +// attempt to define temp dir as something flexible but reliable +$temp_dir = ini_get('upload_tmp_dir'); +if ($temp_dir && (!is_dir($temp_dir) || !is_readable($temp_dir))) { + $temp_dir = ''; +} +if (!$temp_dir && function_exists('sys_get_temp_dir')) { // sys_get_temp_dir added in PHP v5.2.1 + // sys_get_temp_dir() may give inaccessible temp dir, e.g. with open_basedir on virtual hosts + $temp_dir = sys_get_temp_dir(); +} +$temp_dir = @realpath($temp_dir); // see https://github.com/JamesHeinrich/getID3/pull/10 +$open_basedir = ini_get('open_basedir'); +if ($open_basedir) { + // e.g. "/var/www/vhosts/getid3.org/httpdocs/:/tmp/" + $temp_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $temp_dir); + $open_basedir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $open_basedir); + if (substr($temp_dir, -1, 1) != DIRECTORY_SEPARATOR) { + $temp_dir .= DIRECTORY_SEPARATOR; + } + $found_valid_tempdir = false; + $open_basedirs = explode(PATH_SEPARATOR, $open_basedir); + foreach ($open_basedirs as $basedir) { + if (substr($basedir, -1, 1) != DIRECTORY_SEPARATOR) { + $basedir .= DIRECTORY_SEPARATOR; + } + if (strpos($temp_dir, $basedir) === 0) { + $found_valid_tempdir = true; + break; + } + } + if (!$found_valid_tempdir) { + $temp_dir = ''; + } + unset($open_basedirs, $found_valid_tempdir, $basedir); +} +if (!$temp_dir) { + $temp_dir = '*'; // invalid directory name should force tempnam() to use system default temp dir +} +// $temp_dir = '/something/else/'; // feel free to override temp dir here if it works better for your system +if (!defined('GETID3_TEMP_DIR')) { + define('GETID3_TEMP_DIR', $temp_dir); +} +unset($open_basedir, $temp_dir); + +// End: Defines + + +class getID3 +{ + /* + * Settings + */ + + /** + * CASE SENSITIVE! - i.e. (must be supported by iconv()). Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE + * + * @var string + */ + public $encoding = 'UTF-8'; + + /** + * Should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'EUC-CN' or 'CP1252' + * + * @var string + */ + public $encoding_id3v1 = 'ISO-8859-1'; + + /** + * ID3v1 should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'Windows-1251' or 'KOI8-R'. If true attempt to detect these encodings, but may return incorrect values for some tags actually in ISO-8859-1 encoding + * + * @var bool + */ + public $encoding_id3v1_autodetect = false; + + /* + * Optional tag checks - disable for speed. + */ + + /** + * Read and process ID3v1 tags + * + * @var bool + */ + public $option_tag_id3v1 = true; + + /** + * Read and process ID3v2 tags + * + * @var bool + */ + public $option_tag_id3v2 = true; + + /** + * Read and process Lyrics3 tags + * + * @var bool + */ + public $option_tag_lyrics3 = true; + + /** + * Read and process APE tags + * + * @var bool + */ + public $option_tag_apetag = true; + + /** + * Copy tags to root key 'tags' and encode to $this->encoding + * + * @var bool + */ + public $option_tags_process = true; + + /** + * Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities + * + * @var bool + */ + public $option_tags_html = true; + + /* + * Optional tag/comment calculations + */ + + /** + * Calculate additional info such as bitrate, channelmode etc + * + * @var bool + */ + public $option_extra_info = true; + + /* + * Optional handling of embedded attachments (e.g. images) + */ + + /** + * Defaults to true (ATTACHMENTS_INLINE) for backward compatibility + * + * @var bool|string + */ + public $option_save_attachments = true; + + /* + * Optional calculations + */ + + /** + * Get MD5 sum of data part - slow + * + * @var bool + */ + public $option_md5_data = false; + + /** + * Use MD5 of source file if available - only FLAC and OptimFROG + * + * @var bool + */ + public $option_md5_data_source = false; + + /** + * Get SHA1 sum of data part - slow + * + * @var bool + */ + public $option_sha1_data = false; + + /** + * Check whether file is larger than 2GB and thus not supported by 32-bit PHP (null: auto-detect based on + * PHP_INT_MAX) + * + * @var bool|null + */ + public $option_max_2gb_check; + + /** + * Read buffer size in bytes + * + * @var int + */ + public $option_fread_buffer_size = 32768; + + + + // module-specific options + + /** archive.rar + * if true use PHP RarArchive extension, if false (non-extension parsing not yet written in getID3) + * + * @var bool + */ + public $options_archive_rar_use_php_rar_extension = true; + + /** archive.gzip + * Optional file list - disable for speed. + * Decode gzipped files, if possible, and parse recursively (.tar.gz for example). + * + * @var bool + */ + public $options_archive_gzip_parse_contents = false; + + /** audio.midi + * if false only parse most basic information, much faster for some files but may be inaccurate + * + * @var bool + */ + public $options_audio_midi_scanwholefile = true; + + /** audio.mp3 + * Forces getID3() to scan the file byte-by-byte and log all the valid audio frame headers - extremely slow, + * unrecommended, but may provide data from otherwise-unusable files. + * + * @var bool + */ + public $options_audio_mp3_allow_bruteforce = false; + + /** audio.mp3 + * number of frames to scan to determine if MPEG-audio sequence is valid + * Lower this number to 5-20 for faster scanning + * Increase this number to 50+ for most accurate detection of valid VBR/CBR mpeg-audio streams + * + * @var int + */ + public $options_audio_mp3_mp3_valid_check_frames = 50; + + /** audio.wavpack + * Avoid scanning all frames (break after finding ID_RIFF_HEADER and ID_CONFIG_BLOCK, + * significantly faster for very large files but other data may be missed + * + * @var bool + */ + public $options_audio_wavpack_quick_parsing = false; + + /** audio-video.flv + * Break out of the loop if too many frames have been scanned; only scan this + * many if meta frame does not contain useful duration. + * + * @var int + */ + public $options_audiovideo_flv_max_frames = 100000; + + /** audio-video.matroska + * If true, do not return information about CLUSTER chunks, since there's a lot of them + * and they're not usually useful [default: TRUE]. + * + * @var bool + */ + public $options_audiovideo_matroska_hide_clusters = true; + + /** audio-video.matroska + * True to parse the whole file, not only header [default: FALSE]. + * + * @var bool + */ + public $options_audiovideo_matroska_parse_whole_file = false; + + /** audio-video.quicktime + * return all parsed data from all atoms if true, otherwise just returned parsed metadata + * + * @var bool + */ + public $options_audiovideo_quicktime_ReturnAtomData = false; + + /** audio-video.quicktime + * return all parsed data from all atoms if true, otherwise just returned parsed metadata + * + * @var bool + */ + public $options_audiovideo_quicktime_ParseAllPossibleAtoms = false; + + /** audio-video.swf + * return all parsed tags if true, otherwise do not return tags not parsed by getID3 + * + * @var bool + */ + public $options_audiovideo_swf_ReturnAllTagData = false; + + /** graphic.bmp + * return BMP palette + * + * @var bool + */ + public $options_graphic_bmp_ExtractPalette = false; + + /** graphic.bmp + * return image data + * + * @var bool + */ + public $options_graphic_bmp_ExtractData = false; + + /** graphic.png + * If data chunk is larger than this do not read it completely (getID3 only needs the first + * few dozen bytes for parsing). + * + * @var int + */ + public $options_graphic_png_max_data_bytes = 10000000; + + /** misc.pdf + * return full details of PDF Cross-Reference Table (XREF) + * + * @var bool + */ + public $options_misc_pdf_returnXREF = false; + + /** misc.torrent + * Assume all .torrent files are less than 1MB and just read entire thing into memory for easy processing. + * Override this value if you need to process files larger than 1MB + * + * @var int + */ + public $options_misc_torrent_max_torrent_filesize = 1048576; + + + + // Public variables + + /** + * Filename of file being analysed. + * + * @var string + */ + public $filename; + + /** + * Filepointer to file being analysed. + * + * @var resource + */ + public $fp; + + /** + * Result array. + * + * @var array + */ + public $info; + + /** + * @var string + */ + public $tempdir = GETID3_TEMP_DIR; + + /** + * @var int + */ + public $memory_limit = 0; + + /** + * @var string + */ + protected $startup_error = ''; + + /** + * @var string + */ + protected $startup_warning = ''; + + const VERSION = '1.9.22-202207161647'; + const FREAD_BUFFER_SIZE = 32768; + + const ATTACHMENTS_NONE = false; + const ATTACHMENTS_INLINE = true; + + /** + * @throws getid3_exception + */ + public function __construct() { + + // Check for PHP version + $required_php_version = '5.3.0'; + if (version_compare(PHP_VERSION, $required_php_version, '<')) { + $this->startup_error .= 'getID3() requires PHP v'.$required_php_version.' or higher - you are running v'.PHP_VERSION."\n"; + return; + } + + // Check memory + $memoryLimit = ini_get('memory_limit'); + if (preg_match('#([0-9]+) ?M#i', $memoryLimit, $matches)) { + // could be stored as "16M" rather than 16777216 for example + $memoryLimit = $matches[1] * 1048576; + } elseif (preg_match('#([0-9]+) ?G#i', $memoryLimit, $matches)) { // The 'G' modifier is available since PHP 5.1.0 + // could be stored as "2G" rather than 2147483648 for example + $memoryLimit = $matches[1] * 1073741824; + } + $this->memory_limit = $memoryLimit; + + if ($this->memory_limit <= 0) { + // memory limits probably disabled + } elseif ($this->memory_limit <= 4194304) { + $this->startup_error .= 'PHP has less than 4MB available memory and will very likely run out. Increase memory_limit in php.ini'."\n"; + } elseif ($this->memory_limit <= 12582912) { + $this->startup_warning .= 'PHP has less than 12MB available memory and might run out if all modules are loaded. Increase memory_limit in php.ini'."\n"; + } + + // Check safe_mode off + if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { + $this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.'); + } + + if (($mbstring_func_overload = (int) ini_get('mbstring.func_overload')) && ($mbstring_func_overload & 0x02)) { + // http://php.net/manual/en/mbstring.overload.php + // "mbstring.func_overload in php.ini is a positive value that represents a combination of bitmasks specifying the categories of functions to be overloaded. It should be set to 1 to overload the mail() function. 2 for string functions, 4 for regular expression functions" + // getID3 cannot run when string functions are overloaded. It doesn't matter if mail() or ereg* functions are overloaded since getID3 does not use those. + $this->startup_error .= 'WARNING: php.ini contains "mbstring.func_overload = '.ini_get('mbstring.func_overload').'", getID3 cannot run with this setting (bitmask 2 (string functions) cannot be set). Recommended to disable entirely.'."\n"; + } + + // check for magic quotes in PHP < 7.4.0 (when these functions became deprecated) + if (version_compare(PHP_VERSION, '7.4.0', '<')) { + // Check for magic_quotes_runtime + if (function_exists('get_magic_quotes_runtime')) { + if (get_magic_quotes_runtime()) { + $this->startup_error .= 'magic_quotes_runtime must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_runtime(0) and set_magic_quotes_runtime(1).'."\n"; + } + } + // Check for magic_quotes_gpc + if (function_exists('get_magic_quotes_gpc')) { + if (get_magic_quotes_gpc()) { + $this->startup_error .= 'magic_quotes_gpc must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_gpc(0) and set_magic_quotes_gpc(1).'."\n"; + } + } + } + + // Load support library + if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) { + $this->startup_error .= 'getid3.lib.php is missing or corrupt'."\n"; + } + + if ($this->option_max_2gb_check === null) { + $this->option_max_2gb_check = (PHP_INT_MAX <= 2147483647); + } + + + // Needed for Windows only: + // Define locations of helper applications for Shorten, VorbisComment, MetaFLAC + // as well as other helper functions such as head, etc + // This path cannot contain spaces, but the below code will attempt to get the + // 8.3-equivalent path automatically + // IMPORTANT: This path must include the trailing slash + if (GETID3_OS_ISWINDOWS && !defined('GETID3_HELPERAPPSDIR')) { + + $helperappsdir = GETID3_INCLUDEPATH.'..'.DIRECTORY_SEPARATOR.'helperapps'; // must not have any space in this path + + if (!is_dir($helperappsdir)) { + $this->startup_warning .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist'."\n"; + } elseif (strpos(realpath($helperappsdir), ' ') !== false) { + $DirPieces = explode(DIRECTORY_SEPARATOR, realpath($helperappsdir)); + $path_so_far = array(); + foreach ($DirPieces as $key => $value) { + if (strpos($value, ' ') !== false) { + if (!empty($path_so_far)) { + $commandline = 'dir /x '.escapeshellarg(implode(DIRECTORY_SEPARATOR, $path_so_far)); + $dir_listing = `$commandline`; + $lines = explode("\n", $dir_listing); + foreach ($lines as $line) { + $line = trim($line); + if (preg_match('#^([0-9/]{10}) +([0-9:]{4,5}( [AP]M)?) +(|[0-9,]+) +([^ ]{0,11}) +(.+)$#', $line, $matches)) { + list($dummy, $date, $time, $ampm, $filesize, $shortname, $filename) = $matches; + if ((strtoupper($filesize) == '') && (strtolower($filename) == strtolower($value))) { + $value = $shortname; + } + } + } + } else { + $this->startup_warning .= 'GETID3_HELPERAPPSDIR must not have any spaces in it - use 8dot3 naming convention if neccesary. You can run "dir /x" from the commandline to see the correct 8.3-style names.'."\n"; + } + } + $path_so_far[] = $value; + } + $helperappsdir = implode(DIRECTORY_SEPARATOR, $path_so_far); + } + define('GETID3_HELPERAPPSDIR', $helperappsdir.DIRECTORY_SEPARATOR); + } + + if (!empty($this->startup_error)) { + echo $this->startup_error; + throw new getid3_exception($this->startup_error); + } + } + + /** + * @return string + */ + public function version() { + return self::VERSION; + } + + /** + * @return int + */ + public function fread_buffer_size() { + return $this->option_fread_buffer_size; + } + + /** + * @param array $optArray + * + * @return bool + */ + public function setOption($optArray) { + if (!is_array($optArray) || empty($optArray)) { + return false; + } + foreach ($optArray as $opt => $val) { + if (isset($this->$opt) === false) { + continue; + } + $this->$opt = $val; + } + return true; + } + + /** + * @param string $filename + * @param int $filesize + * @param resource $fp + * + * @return bool + * + * @throws getid3_exception + */ + public function openfile($filename, $filesize=null, $fp=null) { + try { + if (!empty($this->startup_error)) { + throw new getid3_exception($this->startup_error); + } + if (!empty($this->startup_warning)) { + foreach (explode("\n", $this->startup_warning) as $startup_warning) { + $this->warning($startup_warning); + } + } + + // init result array and set parameters + $this->filename = $filename; + $this->info = array(); + $this->info['GETID3_VERSION'] = $this->version(); + $this->info['php_memory_limit'] = (($this->memory_limit > 0) ? $this->memory_limit : false); + + // remote files not supported + if (preg_match('#^(ht|f)tps?://#', $filename)) { + throw new getid3_exception('Remote files are not supported - please copy the file locally first'); + } + + $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename); + //$filename = preg_replace('#(?fp = fopen($filename, 'rb'))) { // see https://www.getid3.org/phpBB3/viewtopic.php?t=1720 + if (($fp != null) && ((get_resource_type($fp) == 'file') || (get_resource_type($fp) == 'stream'))) { + $this->fp = $fp; + } elseif ((is_readable($filename) || file_exists($filename)) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) { + // great + } else { + $errormessagelist = array(); + if (!is_readable($filename)) { + $errormessagelist[] = '!is_readable'; + } + if (!is_file($filename)) { + $errormessagelist[] = '!is_file'; + } + if (!file_exists($filename)) { + $errormessagelist[] = '!file_exists'; + } + if (empty($errormessagelist)) { + $errormessagelist[] = 'fopen failed'; + } + throw new getid3_exception('Could not open "'.$filename.'" ('.implode('; ', $errormessagelist).')'); + } + + $this->info['filesize'] = (!is_null($filesize) ? $filesize : filesize($filename)); + // set redundant parameters - might be needed in some include file + // filenames / filepaths in getID3 are always expressed with forward slashes (unix-style) for both Windows and other to try and minimize confusion + $filename = str_replace('\\', '/', $filename); + $this->info['filepath'] = str_replace('\\', '/', realpath(dirname($filename))); + $this->info['filename'] = getid3_lib::mb_basename($filename); + $this->info['filenamepath'] = $this->info['filepath'].'/'.$this->info['filename']; + + // set more parameters + $this->info['avdataoffset'] = 0; + $this->info['avdataend'] = $this->info['filesize']; + $this->info['fileformat'] = ''; // filled in later + $this->info['audio']['dataformat'] = ''; // filled in later, unset if not used + $this->info['video']['dataformat'] = ''; // filled in later, unset if not used + $this->info['tags'] = array(); // filled in later, unset if not used + $this->info['error'] = array(); // filled in later, unset if not used + $this->info['warning'] = array(); // filled in later, unset if not used + $this->info['comments'] = array(); // filled in later, unset if not used + $this->info['encoding'] = $this->encoding; // required by id3v2 and iso modules - can be unset at the end if desired + + // option_max_2gb_check + if ($this->option_max_2gb_check) { + // PHP (32-bit all, and 64-bit Windows) doesn't support integers larger than 2^31 (~2GB) + // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize + // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer + $fseek = fseek($this->fp, 0, SEEK_END); + if (($fseek < 0) || (($this->info['filesize'] != 0) && (ftell($this->fp) == 0)) || + ($this->info['filesize'] < 0) || + (ftell($this->fp) < 0)) { + $real_filesize = getid3_lib::getFileSizeSyscall($this->info['filenamepath']); + + if ($real_filesize === false) { + unset($this->info['filesize']); + fclose($this->fp); + throw new getid3_exception('Unable to determine actual filesize. File is most likely larger than '.round(PHP_INT_MAX / 1073741824).'GB and is not supported by PHP.'); + } elseif (getid3_lib::intValueSupported($real_filesize)) { + unset($this->info['filesize']); + fclose($this->fp); + throw new getid3_exception('PHP seems to think the file is larger than '.round(PHP_INT_MAX / 1073741824).'GB, but filesystem reports it as '.number_format($real_filesize / 1073741824, 3).'GB, please report to info@getid3.org'); + } + $this->info['filesize'] = $real_filesize; + $this->warning('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB (filesystem reports it as '.number_format($real_filesize / 1073741824, 3).'GB) and is not properly supported by PHP.'); + } + } + + return true; + + } catch (Exception $e) { + $this->error($e->getMessage()); + } + return false; + } + + /** + * analyze file + * + * @param string $filename + * @param int $filesize + * @param string $original_filename + * @param resource $fp + * + * @return array + */ + public function analyze($filename, $filesize=null, $original_filename='', $fp=null) { + try { + if (!$this->openfile($filename, $filesize, $fp)) { + return $this->info; + } + + // Handle tags + foreach (array('id3v2'=>'id3v2', 'id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3') as $tag_name => $tag_key) { + $option_tag = 'option_tag_'.$tag_name; + if ($this->$option_tag) { + $this->include_module('tag.'.$tag_name); + try { + $tag_class = 'getid3_'.$tag_name; + $tag = new $tag_class($this); + $tag->Analyze(); + } + catch (getid3_exception $e) { + throw $e; + } + } + } + if (isset($this->info['id3v2']['tag_offset_start'])) { + $this->info['avdataoffset'] = max($this->info['avdataoffset'], $this->info['id3v2']['tag_offset_end']); + } + foreach (array('id3v1'=>'id3v1', 'apetag'=>'ape', 'lyrics3'=>'lyrics3') as $tag_name => $tag_key) { + if (isset($this->info[$tag_key]['tag_offset_start'])) { + $this->info['avdataend'] = min($this->info['avdataend'], $this->info[$tag_key]['tag_offset_start']); + } + } + + // ID3v2 detection (NOT parsing), even if ($this->option_tag_id3v2 == false) done to make fileformat easier + if (!$this->option_tag_id3v2) { + fseek($this->fp, 0); + $header = fread($this->fp, 10); + if ((substr($header, 0, 3) == 'ID3') && (strlen($header) == 10)) { + $this->info['id3v2']['header'] = true; + $this->info['id3v2']['majorversion'] = ord($header[3]); + $this->info['id3v2']['minorversion'] = ord($header[4]); + $this->info['avdataoffset'] += getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length + } + } + + // read 32 kb file data + fseek($this->fp, $this->info['avdataoffset']); + $formattest = fread($this->fp, 32774); + + // determine format + $determined_format = $this->GetFileFormat($formattest, ($original_filename ? $original_filename : $filename)); + + // unable to determine file format + if (!$determined_format) { + fclose($this->fp); + return $this->error('unable to determine file format'); + } + + // check for illegal ID3 tags + if (isset($determined_format['fail_id3']) && (in_array('id3v1', $this->info['tags']) || in_array('id3v2', $this->info['tags']))) { + if ($determined_format['fail_id3'] === 'ERROR') { + fclose($this->fp); + return $this->error('ID3 tags not allowed on this file type.'); + } elseif ($determined_format['fail_id3'] === 'WARNING') { + $this->warning('ID3 tags not allowed on this file type.'); + } + } + + // check for illegal APE tags + if (isset($determined_format['fail_ape']) && in_array('ape', $this->info['tags'])) { + if ($determined_format['fail_ape'] === 'ERROR') { + fclose($this->fp); + return $this->error('APE tags not allowed on this file type.'); + } elseif ($determined_format['fail_ape'] === 'WARNING') { + $this->warning('APE tags not allowed on this file type.'); + } + } + + // set mime type + $this->info['mime_type'] = $determined_format['mime_type']; + + // supported format signature pattern detected, but module deleted + if (!file_exists(GETID3_INCLUDEPATH.$determined_format['include'])) { + fclose($this->fp); + return $this->error('Format not supported, module "'.$determined_format['include'].'" was removed.'); + } + + // module requires mb_convert_encoding/iconv support + // Check encoding/iconv support + if (!empty($determined_format['iconv_req']) && !function_exists('mb_convert_encoding') && !function_exists('iconv') && !in_array($this->encoding, array('ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'))) { + $errormessage = 'mb_convert_encoding() or iconv() support is required for this module ('.$determined_format['include'].') for encodings other than ISO-8859-1, UTF-8, UTF-16LE, UTF16-BE, UTF-16. '; + if (GETID3_OS_ISWINDOWS) { + $errormessage .= 'PHP does not have mb_convert_encoding() or iconv() support. Please enable php_mbstring.dll / php_iconv.dll in php.ini, and copy php_mbstring.dll / iconv.dll from c:/php/dlls to c:/windows/system32'; + } else { + $errormessage .= 'PHP is not compiled with mb_convert_encoding() or iconv() support. Please recompile with the --enable-mbstring / --with-iconv switch'; + } + return $this->error($errormessage); + } + + // include module + include_once(GETID3_INCLUDEPATH.$determined_format['include']); + + // instantiate module class + $class_name = 'getid3_'.$determined_format['module']; + if (!class_exists($class_name)) { + return $this->error('Format not supported, module "'.$determined_format['include'].'" is corrupt.'); + } + $class = new $class_name($this); + + // set module-specific options + foreach (get_object_vars($this) as $getid3_object_vars_key => $getid3_object_vars_value) { + if (preg_match('#^options_([^_]+)_([^_]+)_(.+)$#i', $getid3_object_vars_key, $matches)) { + list($dummy, $GOVgroup, $GOVmodule, $GOVsetting) = $matches; + $GOVgroup = (($GOVgroup == 'audiovideo') ? 'audio-video' : $GOVgroup); // variable names can only contain 0-9a-z_ so standardize here + if (($GOVgroup == $determined_format['group']) && ($GOVmodule == $determined_format['module'])) { + $class->$GOVsetting = $getid3_object_vars_value; + } + } + } + + $class->Analyze(); + unset($class); + + // close file + fclose($this->fp); + + // process all tags - copy to 'tags' and convert charsets + if ($this->option_tags_process) { + $this->HandleAllTags(); + } + + // perform more calculations + if ($this->option_extra_info) { + $this->ChannelsBitratePlaytimeCalculations(); + $this->CalculateCompressionRatioVideo(); + $this->CalculateCompressionRatioAudio(); + $this->CalculateReplayGain(); + $this->ProcessAudioStreams(); + } + + // get the MD5 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags + if ($this->option_md5_data) { + // do not calc md5_data if md5_data_source is present - set by flac only - future MPC/SV8 too + if (!$this->option_md5_data_source || empty($this->info['md5_data_source'])) { + $this->getHashdata('md5'); + } + } + + // get the SHA1 sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags + if ($this->option_sha1_data) { + $this->getHashdata('sha1'); + } + + // remove undesired keys + $this->CleanUp(); + + } catch (Exception $e) { + $this->error('Caught exception: '.$e->getMessage()); + } + + // return info array + return $this->info; + } + + + /** + * Error handling. + * + * @param string $message + * + * @return array + */ + public function error($message) { + $this->CleanUp(); + if (!isset($this->info['error'])) { + $this->info['error'] = array(); + } + $this->info['error'][] = $message; + return $this->info; + } + + + /** + * Warning handling. + * + * @param string $message + * + * @return bool + */ + public function warning($message) { + $this->info['warning'][] = $message; + return true; + } + + + /** + * @return bool + */ + private function CleanUp() { + + // remove possible empty keys + $AVpossibleEmptyKeys = array('dataformat', 'bits_per_sample', 'encoder_options', 'streams', 'bitrate'); + foreach ($AVpossibleEmptyKeys as $dummy => $key) { + if (empty($this->info['audio'][$key]) && isset($this->info['audio'][$key])) { + unset($this->info['audio'][$key]); + } + if (empty($this->info['video'][$key]) && isset($this->info['video'][$key])) { + unset($this->info['video'][$key]); + } + } + + // remove empty root keys + if (!empty($this->info)) { + foreach ($this->info as $key => $value) { + if (empty($this->info[$key]) && ($this->info[$key] !== 0) && ($this->info[$key] !== '0')) { + unset($this->info[$key]); + } + } + } + + // remove meaningless entries from unknown-format files + if (empty($this->info['fileformat'])) { + if (isset($this->info['avdataoffset'])) { + unset($this->info['avdataoffset']); + } + if (isset($this->info['avdataend'])) { + unset($this->info['avdataend']); + } + } + + // remove possible duplicated identical entries + if (!empty($this->info['error'])) { + $this->info['error'] = array_values(array_unique($this->info['error'])); + } + if (!empty($this->info['warning'])) { + $this->info['warning'] = array_values(array_unique($this->info['warning'])); + } + + // remove "global variable" type keys + unset($this->info['php_memory_limit']); + + return true; + } + + /** + * Return array containing information about all supported formats. + * + * @return array + */ + public function GetFileFormatArray() { + static $format_info = array(); + if (empty($format_info)) { + $format_info = array( + + // Audio formats + + // AC-3 - audio - Dolby AC-3 / Dolby Digital + 'ac3' => array( + 'pattern' => '^\\x0B\\x77', + 'group' => 'audio', + 'module' => 'ac3', + 'mime_type' => 'audio/ac3', + ), + + // AAC - audio - Advanced Audio Coding (AAC) - ADIF format + 'adif' => array( + 'pattern' => '^ADIF', + 'group' => 'audio', + 'module' => 'aac', + 'mime_type' => 'audio/aac', + 'fail_ape' => 'WARNING', + ), + +/* + // AA - audio - Audible Audiobook + 'aa' => array( + 'pattern' => '^.{4}\\x57\\x90\\x75\\x36', + 'group' => 'audio', + 'module' => 'aa', + 'mime_type' => 'audio/audible', + ), +*/ + // AAC - audio - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3) + 'adts' => array( + 'pattern' => '^\\xFF[\\xF0-\\xF1\\xF8-\\xF9]', + 'group' => 'audio', + 'module' => 'aac', + 'mime_type' => 'audio/aac', + 'fail_ape' => 'WARNING', + ), + + + // AU - audio - NeXT/Sun AUdio (AU) + 'au' => array( + 'pattern' => '^\\.snd', + 'group' => 'audio', + 'module' => 'au', + 'mime_type' => 'audio/basic', + ), + + // AMR - audio - Adaptive Multi Rate + 'amr' => array( + 'pattern' => '^\\x23\\x21AMR\\x0A', // #!AMR[0A] + 'group' => 'audio', + 'module' => 'amr', + 'mime_type' => 'audio/amr', + ), + + // AVR - audio - Audio Visual Research + 'avr' => array( + 'pattern' => '^2BIT', + 'group' => 'audio', + 'module' => 'avr', + 'mime_type' => 'application/octet-stream', + ), + + // BONK - audio - Bonk v0.9+ + 'bonk' => array( + 'pattern' => '^\\x00(BONK|INFO|META| ID3)', + 'group' => 'audio', + 'module' => 'bonk', + 'mime_type' => 'audio/xmms-bonk', + ), + + // DSF - audio - Direct Stream Digital (DSD) Storage Facility files (DSF) - https://en.wikipedia.org/wiki/Direct_Stream_Digital + 'dsf' => array( + 'pattern' => '^DSD ', // including trailing space: 44 53 44 20 + 'group' => 'audio', + 'module' => 'dsf', + 'mime_type' => 'audio/dsd', + ), + + // DSS - audio - Digital Speech Standard + 'dss' => array( + 'pattern' => '^[\\x02-\\x08]ds[s2]', + 'group' => 'audio', + 'module' => 'dss', + 'mime_type' => 'application/octet-stream', + ), + + // DSDIFF - audio - Direct Stream Digital Interchange File Format + 'dsdiff' => array( + 'pattern' => '^FRM8', + 'group' => 'audio', + 'module' => 'dsdiff', + 'mime_type' => 'audio/dsd', + ), + + // DTS - audio - Dolby Theatre System + 'dts' => array( + 'pattern' => '^\\x7F\\xFE\\x80\\x01', + 'group' => 'audio', + 'module' => 'dts', + 'mime_type' => 'audio/dts', + ), + + // FLAC - audio - Free Lossless Audio Codec + 'flac' => array( + 'pattern' => '^fLaC', + 'group' => 'audio', + 'module' => 'flac', + 'mime_type' => 'audio/flac', + ), + + // LA - audio - Lossless Audio (LA) + 'la' => array( + 'pattern' => '^LA0[2-4]', + 'group' => 'audio', + 'module' => 'la', + 'mime_type' => 'application/octet-stream', + ), + + // LPAC - audio - Lossless Predictive Audio Compression (LPAC) + 'lpac' => array( + 'pattern' => '^LPAC', + 'group' => 'audio', + 'module' => 'lpac', + 'mime_type' => 'application/octet-stream', + ), + + // MIDI - audio - MIDI (Musical Instrument Digital Interface) + 'midi' => array( + 'pattern' => '^MThd', + 'group' => 'audio', + 'module' => 'midi', + 'mime_type' => 'audio/midi', + ), + + // MAC - audio - Monkey's Audio Compressor + 'mac' => array( + 'pattern' => '^MAC ', + 'group' => 'audio', + 'module' => 'monkey', + 'mime_type' => 'audio/x-monkeys-audio', + ), + + + // MOD - audio - MODule (SoundTracker) + 'mod' => array( + //'pattern' => '^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)', // has been known to produce false matches in random files (e.g. JPEGs), leave out until more precise matching available + 'pattern' => '^.{1080}(M\\.K\\.)', + 'group' => 'audio', + 'module' => 'mod', + 'option' => 'mod', + 'mime_type' => 'audio/mod', + ), + + // MOD - audio - MODule (Impulse Tracker) + 'it' => array( + 'pattern' => '^IMPM', + 'group' => 'audio', + 'module' => 'mod', + //'option' => 'it', + 'mime_type' => 'audio/it', + ), + + // MOD - audio - MODule (eXtended Module, various sub-formats) + 'xm' => array( + 'pattern' => '^Extended Module', + 'group' => 'audio', + 'module' => 'mod', + //'option' => 'xm', + 'mime_type' => 'audio/xm', + ), + + // MOD - audio - MODule (ScreamTracker) + 's3m' => array( + 'pattern' => '^.{44}SCRM', + 'group' => 'audio', + 'module' => 'mod', + //'option' => 's3m', + 'mime_type' => 'audio/s3m', + ), + + // MPC - audio - Musepack / MPEGplus + 'mpc' => array( + 'pattern' => '^(MPCK|MP\\+)', + 'group' => 'audio', + 'module' => 'mpc', + 'mime_type' => 'audio/x-musepack', + ), + + // MP3 - audio - MPEG-audio Layer 3 (very similar to AAC-ADTS) + 'mp3' => array( + 'pattern' => '^\\xFF[\\xE2-\\xE7\\xF2-\\xF7\\xFA-\\xFF][\\x00-\\x0B\\x10-\\x1B\\x20-\\x2B\\x30-\\x3B\\x40-\\x4B\\x50-\\x5B\\x60-\\x6B\\x70-\\x7B\\x80-\\x8B\\x90-\\x9B\\xA0-\\xAB\\xB0-\\xBB\\xC0-\\xCB\\xD0-\\xDB\\xE0-\\xEB\\xF0-\\xFB]', + 'group' => 'audio', + 'module' => 'mp3', + 'mime_type' => 'audio/mpeg', + ), + + // OFR - audio - OptimFROG + 'ofr' => array( + 'pattern' => '^(\\*RIFF|OFR)', + 'group' => 'audio', + 'module' => 'optimfrog', + 'mime_type' => 'application/octet-stream', + ), + + // RKAU - audio - RKive AUdio compressor + 'rkau' => array( + 'pattern' => '^RKA', + 'group' => 'audio', + 'module' => 'rkau', + 'mime_type' => 'application/octet-stream', + ), + + // SHN - audio - Shorten + 'shn' => array( + 'pattern' => '^ajkg', + 'group' => 'audio', + 'module' => 'shorten', + 'mime_type' => 'audio/xmms-shn', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + // TAK - audio - Tom's lossless Audio Kompressor + 'tak' => array( + 'pattern' => '^tBaK', + 'group' => 'audio', + 'module' => 'tak', + 'mime_type' => 'application/octet-stream', + ), + + // TTA - audio - TTA Lossless Audio Compressor (http://tta.corecodec.org) + 'tta' => array( + 'pattern' => '^TTA', // could also be '^TTA(\\x01|\\x02|\\x03|2|1)' + 'group' => 'audio', + 'module' => 'tta', + 'mime_type' => 'application/octet-stream', + ), + + // VOC - audio - Creative Voice (VOC) + 'voc' => array( + 'pattern' => '^Creative Voice File', + 'group' => 'audio', + 'module' => 'voc', + 'mime_type' => 'audio/voc', + ), + + // VQF - audio - transform-domain weighted interleave Vector Quantization Format (VQF) + 'vqf' => array( + 'pattern' => '^TWIN', + 'group' => 'audio', + 'module' => 'vqf', + 'mime_type' => 'application/octet-stream', + ), + + // WV - audio - WavPack (v4.0+) + 'wv' => array( + 'pattern' => '^wvpk', + 'group' => 'audio', + 'module' => 'wavpack', + 'mime_type' => 'application/octet-stream', + ), + + + // Audio-Video formats + + // ASF - audio/video - Advanced Streaming Format, Windows Media Video, Windows Media Audio + 'asf' => array( + 'pattern' => '^\\x30\\x26\\xB2\\x75\\x8E\\x66\\xCF\\x11\\xA6\\xD9\\x00\\xAA\\x00\\x62\\xCE\\x6C', + 'group' => 'audio-video', + 'module' => 'asf', + 'mime_type' => 'video/x-ms-asf', + 'iconv_req' => false, + ), + + // BINK - audio/video - Bink / Smacker + 'bink' => array( + 'pattern' => '^(BIK|SMK)', + 'group' => 'audio-video', + 'module' => 'bink', + 'mime_type' => 'application/octet-stream', + ), + + // FLV - audio/video - FLash Video + 'flv' => array( + 'pattern' => '^FLV[\\x01]', + 'group' => 'audio-video', + 'module' => 'flv', + 'mime_type' => 'video/x-flv', + ), + + // IVF - audio/video - IVF + 'ivf' => array( + 'pattern' => '^DKIF', + 'group' => 'audio-video', + 'module' => 'ivf', + 'mime_type' => 'video/x-ivf', + ), + + // MKAV - audio/video - Mastroka + 'matroska' => array( + 'pattern' => '^\\x1A\\x45\\xDF\\xA3', + 'group' => 'audio-video', + 'module' => 'matroska', + 'mime_type' => 'video/x-matroska', // may also be audio/x-matroska + ), + + // MPEG - audio/video - MPEG (Moving Pictures Experts Group) + 'mpeg' => array( + 'pattern' => '^\\x00\\x00\\x01[\\xB3\\xBA]', + 'group' => 'audio-video', + 'module' => 'mpeg', + 'mime_type' => 'video/mpeg', + ), + + // NSV - audio/video - Nullsoft Streaming Video (NSV) + 'nsv' => array( + 'pattern' => '^NSV[sf]', + 'group' => 'audio-video', + 'module' => 'nsv', + 'mime_type' => 'application/octet-stream', + ), + + // Ogg - audio/video - Ogg (Ogg-Vorbis, Ogg-FLAC, Speex, Ogg-Theora(*), Ogg-Tarkin(*)) + 'ogg' => array( + 'pattern' => '^OggS', + 'group' => 'audio', + 'module' => 'ogg', + 'mime_type' => 'application/ogg', + 'fail_id3' => 'WARNING', + 'fail_ape' => 'WARNING', + ), + + // QT - audio/video - Quicktime + 'quicktime' => array( + 'pattern' => '^.{4}(cmov|free|ftyp|mdat|moov|pnot|skip|wide)', + 'group' => 'audio-video', + 'module' => 'quicktime', + 'mime_type' => 'video/quicktime', + ), + + // RIFF - audio/video - Resource Interchange File Format (RIFF) / WAV / AVI / CD-audio / SDSS = renamed variant used by SmartSound QuickTracks (www.smartsound.com) / FORM = Audio Interchange File Format (AIFF) + 'riff' => array( + 'pattern' => '^(RIFF|SDSS|FORM)', + 'group' => 'audio-video', + 'module' => 'riff', + 'mime_type' => 'audio/wav', + 'fail_ape' => 'WARNING', + ), + + // Real - audio/video - RealAudio, RealVideo + 'real' => array( + 'pattern' => '^\\.(RMF|ra)', + 'group' => 'audio-video', + 'module' => 'real', + 'mime_type' => 'audio/x-realaudio', + ), + + // SWF - audio/video - ShockWave Flash + 'swf' => array( + 'pattern' => '^(F|C)WS', + 'group' => 'audio-video', + 'module' => 'swf', + 'mime_type' => 'application/x-shockwave-flash', + ), + + // TS - audio/video - MPEG-2 Transport Stream + 'ts' => array( + 'pattern' => '^(\\x47.{187}){10,}', // packets are 188 bytes long and start with 0x47 "G". Check for at least 10 packets matching this pattern + 'group' => 'audio-video', + 'module' => 'ts', + 'mime_type' => 'video/MP2T', + ), + + // WTV - audio/video - Windows Recorded TV Show + 'wtv' => array( + 'pattern' => '^\\xB7\\xD8\\x00\\x20\\x37\\x49\\xDA\\x11\\xA6\\x4E\\x00\\x07\\xE9\\x5E\\xAD\\x8D', + 'group' => 'audio-video', + 'module' => 'wtv', + 'mime_type' => 'video/x-ms-wtv', + ), + + + // Still-Image formats + + // BMP - still image - Bitmap (Windows, OS/2; uncompressed, RLE8, RLE4) + 'bmp' => array( + 'pattern' => '^BM', + 'group' => 'graphic', + 'module' => 'bmp', + 'mime_type' => 'image/bmp', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + // GIF - still image - Graphics Interchange Format + 'gif' => array( + 'pattern' => '^GIF', + 'group' => 'graphic', + 'module' => 'gif', + 'mime_type' => 'image/gif', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + // JPEG - still image - Joint Photographic Experts Group (JPEG) + 'jpg' => array( + 'pattern' => '^\\xFF\\xD8\\xFF', + 'group' => 'graphic', + 'module' => 'jpg', + 'mime_type' => 'image/jpeg', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + // PCD - still image - Kodak Photo CD + 'pcd' => array( + 'pattern' => '^.{2048}PCD_IPI\\x00', + 'group' => 'graphic', + 'module' => 'pcd', + 'mime_type' => 'image/x-photo-cd', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + + // PNG - still image - Portable Network Graphics (PNG) + 'png' => array( + 'pattern' => '^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A', + 'group' => 'graphic', + 'module' => 'png', + 'mime_type' => 'image/png', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + + // SVG - still image - Scalable Vector Graphics (SVG) + 'svg' => array( + 'pattern' => '( 'graphic', + 'module' => 'svg', + 'mime_type' => 'image/svg+xml', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + + // TIFF - still image - Tagged Information File Format (TIFF) + 'tiff' => array( + 'pattern' => '^(II\\x2A\\x00|MM\\x00\\x2A)', + 'group' => 'graphic', + 'module' => 'tiff', + 'mime_type' => 'image/tiff', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + + // EFAX - still image - eFax (TIFF derivative) + 'efax' => array( + 'pattern' => '^\\xDC\\xFE', + 'group' => 'graphic', + 'module' => 'efax', + 'mime_type' => 'image/efax', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + + // Data formats + + // ISO - data - International Standards Organization (ISO) CD-ROM Image + 'iso' => array( + 'pattern' => '^.{32769}CD001', + 'group' => 'misc', + 'module' => 'iso', + 'mime_type' => 'application/octet-stream', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + 'iconv_req' => false, + ), + + // HPK - data - HPK compressed data + 'hpk' => array( + 'pattern' => '^BPUL', + 'group' => 'archive', + 'module' => 'hpk', + 'mime_type' => 'application/octet-stream', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + // RAR - data - RAR compressed data + 'rar' => array( + 'pattern' => '^Rar\\!', + 'group' => 'archive', + 'module' => 'rar', + 'mime_type' => 'application/vnd.rar', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + // SZIP - audio/data - SZIP compressed data + 'szip' => array( + 'pattern' => '^SZ\\x0A\\x04', + 'group' => 'archive', + 'module' => 'szip', + 'mime_type' => 'application/octet-stream', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + // TAR - data - TAR compressed data + 'tar' => array( + 'pattern' => '^.{100}[0-9\\x20]{7}\\x00[0-9\\x20]{7}\\x00[0-9\\x20]{7}\\x00[0-9\\x20\\x00]{12}[0-9\\x20\\x00]{12}', + 'group' => 'archive', + 'module' => 'tar', + 'mime_type' => 'application/x-tar', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + // GZIP - data - GZIP compressed data + 'gz' => array( + 'pattern' => '^\\x1F\\x8B\\x08', + 'group' => 'archive', + 'module' => 'gzip', + 'mime_type' => 'application/gzip', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + // ZIP - data - ZIP compressed data + 'zip' => array( + 'pattern' => '^PK\\x03\\x04', + 'group' => 'archive', + 'module' => 'zip', + 'mime_type' => 'application/zip', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + // XZ - data - XZ compressed data + 'xz' => array( + 'pattern' => '^\\xFD7zXZ\\x00', + 'group' => 'archive', + 'module' => 'xz', + 'mime_type' => 'application/x-xz', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + + // Misc other formats + + // PAR2 - data - Parity Volume Set Specification 2.0 + 'par2' => array ( + 'pattern' => '^PAR2\\x00PKT', + 'group' => 'misc', + 'module' => 'par2', + 'mime_type' => 'application/octet-stream', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + // PDF - data - Portable Document Format + 'pdf' => array( + 'pattern' => '^\\x25PDF', + 'group' => 'misc', + 'module' => 'pdf', + 'mime_type' => 'application/pdf', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + // MSOFFICE - data - ZIP compressed data + 'msoffice' => array( + 'pattern' => '^\\xD0\\xCF\\x11\\xE0\\xA1\\xB1\\x1A\\xE1', // D0CF11E == DOCFILE == Microsoft Office Document + 'group' => 'misc', + 'module' => 'msoffice', + 'mime_type' => 'application/octet-stream', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + // TORRENT - .torrent + 'torrent' => array( + 'pattern' => '^(d8\\:announce|d7\\:comment)', + 'group' => 'misc', + 'module' => 'torrent', + 'mime_type' => 'application/x-bittorrent', + 'fail_id3' => 'ERROR', + 'fail_ape' => 'ERROR', + ), + + // CUE - data - CUEsheet (index to single-file disc images) + 'cue' => array( + 'pattern' => '', // empty pattern means cannot be automatically detected, will fall through all other formats and match based on filename and very basic file contents + 'group' => 'misc', + 'module' => 'cue', + 'mime_type' => 'application/octet-stream', + ), + + ); + } + + return $format_info; + } + + /** + * @param string $filedata + * @param string $filename + * + * @return mixed|false + */ + public function GetFileFormat(&$filedata, $filename='') { + // this function will determine the format of a file based on usually + // the first 2-4 bytes of the file (8 bytes for PNG, 16 bytes for JPG, + // and in the case of ISO CD image, 6 bytes offset 32kb from the start + // of the file). + + // Identify file format - loop through $format_info and detect with reg expr + foreach ($this->GetFileFormatArray() as $format_name => $info) { + // The /s switch on preg_match() forces preg_match() NOT to treat + // newline (0x0A) characters as special chars but do a binary match + if (!empty($info['pattern']) && preg_match('#'.$info['pattern'].'#s', $filedata)) { + $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php'; + return $info; + } + } + + + if (preg_match('#\\.mp[123a]$#i', $filename)) { + // Too many mp3 encoders on the market put garbage in front of mpeg files + // use assume format on these if format detection failed + $GetFileFormatArray = $this->GetFileFormatArray(); + $info = $GetFileFormatArray['mp3']; + $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php'; + return $info; + } elseif (preg_match('#\\.mp[cp\\+]$#i', $filename) && preg_match('#[\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0]#s', $filedata)) { + // old-format (SV4-SV6) Musepack header that has a very loose pattern match and could falsely match other data (e.g. corrupt mp3) + // only enable this pattern check if the filename ends in .mpc/mpp/mp+ + $GetFileFormatArray = $this->GetFileFormatArray(); + $info = $GetFileFormatArray['mpc']; + $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php'; + return $info; + } elseif (preg_match('#\\.cue$#i', $filename) && preg_match('#FILE "[^"]+" (BINARY|MOTOROLA|AIFF|WAVE|MP3)#', $filedata)) { + // there's not really a useful consistent "magic" at the beginning of .cue files to identify them + // so until I think of something better, just go by filename if all other format checks fail + // and verify there's at least one instance of "TRACK xx AUDIO" in the file + $GetFileFormatArray = $this->GetFileFormatArray(); + $info = $GetFileFormatArray['cue']; + $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php'; + return $info; + } + + return false; + } + + /** + * Converts array to $encoding charset from $this->encoding. + * + * @param array $array + * @param string $encoding + */ + public function CharConvert(&$array, $encoding) { + + // identical encoding - end here + if ($encoding == $this->encoding) { + return; + } + + // loop thru array + foreach ($array as $key => $value) { + + // go recursive + if (is_array($value)) { + $this->CharConvert($array[$key], $encoding); + } + + // convert string + elseif (is_string($value)) { + $array[$key] = trim(getid3_lib::iconv_fallback($encoding, $this->encoding, $value)); + } + } + } + + /** + * @return bool + */ + public function HandleAllTags() { + + // key name => array (tag name, character encoding) + static $tags; + if (empty($tags)) { + $tags = array( + 'asf' => array('asf' , 'UTF-16LE'), + 'midi' => array('midi' , 'ISO-8859-1'), + 'nsv' => array('nsv' , 'ISO-8859-1'), + 'ogg' => array('vorbiscomment' , 'UTF-8'), + 'png' => array('png' , 'UTF-8'), + 'tiff' => array('tiff' , 'ISO-8859-1'), + 'quicktime' => array('quicktime' , 'UTF-8'), + 'real' => array('real' , 'ISO-8859-1'), + 'vqf' => array('vqf' , 'ISO-8859-1'), + 'zip' => array('zip' , 'ISO-8859-1'), + 'riff' => array('riff' , 'ISO-8859-1'), + 'lyrics3' => array('lyrics3' , 'ISO-8859-1'), + 'id3v1' => array('id3v1' , $this->encoding_id3v1), + 'id3v2' => array('id3v2' , 'UTF-8'), // not according to the specs (every frame can have a different encoding), but getID3() force-converts all encodings to UTF-8 + 'ape' => array('ape' , 'UTF-8'), + 'cue' => array('cue' , 'ISO-8859-1'), + 'matroska' => array('matroska' , 'UTF-8'), + 'flac' => array('vorbiscomment' , 'UTF-8'), + 'divxtag' => array('divx' , 'ISO-8859-1'), + 'iptc' => array('iptc' , 'ISO-8859-1'), + 'dsdiff' => array('dsdiff' , 'ISO-8859-1'), + ); + } + + // loop through comments array + foreach ($tags as $comment_name => $tagname_encoding_array) { + list($tag_name, $encoding) = $tagname_encoding_array; + + // fill in default encoding type if not already present + if (isset($this->info[$comment_name]) && !isset($this->info[$comment_name]['encoding'])) { + $this->info[$comment_name]['encoding'] = $encoding; + } + + // copy comments if key name set + if (!empty($this->info[$comment_name]['comments'])) { + foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) { + foreach ($valuearray as $key => $value) { + if (is_string($value)) { + $value = trim($value, " \r\n\t"); // do not trim nulls from $value!! Unicode characters will get mangled if trailing nulls are removed! + } + if (isset($value) && $value !== "") { + if (!is_numeric($key)) { + $this->info['tags'][trim($tag_name)][trim($tag_key)][$key] = $value; + } else { + $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value; + } + } + } + if ($tag_key == 'picture') { + // pictures can take up a lot of space, and we don't need multiple copies of them; let there be a single copy in [comments][picture], and not elsewhere + unset($this->info[$comment_name]['comments'][$tag_key]); + } + } + + if (!isset($this->info['tags'][$tag_name])) { + // comments are set but contain nothing but empty strings, so skip + continue; + } + + $this->CharConvert($this->info['tags'][$tag_name], $this->info[$comment_name]['encoding']); // only copy gets converted! + + if ($this->option_tags_html) { + foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) { + if ($tag_key == 'picture') { + // Do not to try to convert binary picture data to HTML + // https://github.com/JamesHeinrich/getID3/issues/178 + continue; + } + $this->info['tags_html'][$tag_name][$tag_key] = getid3_lib::recursiveMultiByteCharString2HTML($valuearray, $this->info[$comment_name]['encoding']); + } + } + + } + + } + + // pictures can take up a lot of space, and we don't need multiple copies of them; let there be a single copy in [comments][picture], and not elsewhere + if (!empty($this->info['tags'])) { + $unset_keys = array('tags', 'tags_html'); + foreach ($this->info['tags'] as $tagtype => $tagarray) { + foreach ($tagarray as $tagname => $tagdata) { + if ($tagname == 'picture') { + foreach ($tagdata as $key => $tagarray) { + $this->info['comments']['picture'][] = $tagarray; + if (isset($tagarray['data']) && isset($tagarray['image_mime'])) { + if (isset($this->info['tags'][$tagtype][$tagname][$key])) { + unset($this->info['tags'][$tagtype][$tagname][$key]); + } + if (isset($this->info['tags_html'][$tagtype][$tagname][$key])) { + unset($this->info['tags_html'][$tagtype][$tagname][$key]); + } + } + } + } + } + foreach ($unset_keys as $unset_key) { + // remove possible empty keys from (e.g. [tags][id3v2][picture]) + if (empty($this->info[$unset_key][$tagtype]['picture'])) { + unset($this->info[$unset_key][$tagtype]['picture']); + } + if (empty($this->info[$unset_key][$tagtype])) { + unset($this->info[$unset_key][$tagtype]); + } + if (empty($this->info[$unset_key])) { + unset($this->info[$unset_key]); + } + } + // remove duplicate copy of picture data from (e.g. [id3v2][comments][picture]) + if (isset($this->info[$tagtype]['comments']['picture'])) { + unset($this->info[$tagtype]['comments']['picture']); + } + if (empty($this->info[$tagtype]['comments'])) { + unset($this->info[$tagtype]['comments']); + } + if (empty($this->info[$tagtype])) { + unset($this->info[$tagtype]); + } + } + } + return true; + } + + /** + * Calls getid3_lib::CopyTagsToComments() but passes in the option_tags_html setting from this instance of getID3 + * + * @param array $ThisFileInfo + * + * @return bool + */ + public function CopyTagsToComments(&$ThisFileInfo) { + return getid3_lib::CopyTagsToComments($ThisFileInfo, $this->option_tags_html); + } + + /** + * @param string $algorithm + * + * @return array|bool + */ + public function getHashdata($algorithm) { + switch ($algorithm) { + case 'md5': + case 'sha1': + break; + + default: + return $this->error('bad algorithm "'.$algorithm.'" in getHashdata()'); + } + + if (!empty($this->info['fileformat']) && !empty($this->info['dataformat']) && ($this->info['fileformat'] == 'ogg') && ($this->info['audio']['dataformat'] == 'vorbis')) { + + // We cannot get an identical md5_data value for Ogg files where the comments + // span more than 1 Ogg page (compared to the same audio data with smaller + // comments) using the normal getID3() method of MD5'ing the data between the + // end of the comments and the end of the file (minus any trailing tags), + // because the page sequence numbers of the pages that the audio data is on + // do not match. Under normal circumstances, where comments are smaller than + // the nominal 4-8kB page size, then this is not a problem, but if there are + // very large comments, the only way around it is to strip off the comment + // tags with vorbiscomment and MD5 that file. + // This procedure must be applied to ALL Ogg files, not just the ones with + // comments larger than 1 page, because the below method simply MD5's the + // whole file with the comments stripped, not just the portion after the + // comments block (which is the standard getID3() method. + + // The above-mentioned problem of comments spanning multiple pages and changing + // page sequence numbers likely happens for OggSpeex and OggFLAC as well, but + // currently vorbiscomment only works on OggVorbis files. + + if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { + + $this->warning('Failed making system call to vorbiscomment.exe - '.$algorithm.'_data is incorrect - error returned: PHP running in Safe Mode (backtick operator not available)'); + $this->info[$algorithm.'_data'] = false; + + } else { + + // Prevent user from aborting script + $old_abort = ignore_user_abort(true); + + // Create empty file + $empty = tempnam(GETID3_TEMP_DIR, 'getID3'); + touch($empty); + + // Use vorbiscomment to make temp file without comments + $temp = tempnam(GETID3_TEMP_DIR, 'getID3'); + $file = $this->info['filenamepath']; + + if (GETID3_OS_ISWINDOWS) { + + if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) { + + $commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w -c "'.$empty.'" "'.$file.'" "'.$temp.'"'; + $VorbisCommentError = `$commandline`; + + } else { + + $VorbisCommentError = 'vorbiscomment.exe not found in '.GETID3_HELPERAPPSDIR; + + } + + } else { + + $commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1'; + $VorbisCommentError = `$commandline`; + + } + + if (!empty($VorbisCommentError)) { + + $this->warning('Failed making system call to vorbiscomment(.exe) - '.$algorithm.'_data will be incorrect. If vorbiscomment is unavailable, please download from http://www.vorbis.com/download.psp and put in the getID3() directory. Error returned: '.$VorbisCommentError); + $this->info[$algorithm.'_data'] = false; + + } else { + + // Get hash of newly created file + switch ($algorithm) { + case 'md5': + $this->info[$algorithm.'_data'] = md5_file($temp); + break; + + case 'sha1': + $this->info[$algorithm.'_data'] = sha1_file($temp); + break; + } + } + + // Clean up + unlink($empty); + unlink($temp); + + // Reset abort setting + ignore_user_abort($old_abort); + + } + + } else { + + if (!empty($this->info['avdataoffset']) || (isset($this->info['avdataend']) && ($this->info['avdataend'] < $this->info['filesize']))) { + + // get hash from part of file + $this->info[$algorithm.'_data'] = getid3_lib::hash_data($this->info['filenamepath'], $this->info['avdataoffset'], $this->info['avdataend'], $algorithm); + + } else { + + // get hash from whole file + switch ($algorithm) { + case 'md5': + $this->info[$algorithm.'_data'] = md5_file($this->info['filenamepath']); + break; + + case 'sha1': + $this->info[$algorithm.'_data'] = sha1_file($this->info['filenamepath']); + break; + } + } + + } + return true; + } + + public function ChannelsBitratePlaytimeCalculations() { + + // set channelmode on audio + if (!empty($this->info['audio']['channelmode']) || !isset($this->info['audio']['channels'])) { + // ignore + } elseif ($this->info['audio']['channels'] == 1) { + $this->info['audio']['channelmode'] = 'mono'; + } elseif ($this->info['audio']['channels'] == 2) { + $this->info['audio']['channelmode'] = 'stereo'; + } + + // Calculate combined bitrate - audio + video + $CombinedBitrate = 0; + $CombinedBitrate += (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : 0); + $CombinedBitrate += (isset($this->info['video']['bitrate']) ? $this->info['video']['bitrate'] : 0); + if (($CombinedBitrate > 0) && empty($this->info['bitrate'])) { + $this->info['bitrate'] = $CombinedBitrate; + } + //if ((isset($this->info['video']) && !isset($this->info['video']['bitrate'])) || (isset($this->info['audio']) && !isset($this->info['audio']['bitrate']))) { + // // for example, VBR MPEG video files cannot determine video bitrate: + // // should not set overall bitrate and playtime from audio bitrate only + // unset($this->info['bitrate']); + //} + + // video bitrate undetermined, but calculable + if (isset($this->info['video']['dataformat']) && $this->info['video']['dataformat'] && (!isset($this->info['video']['bitrate']) || ($this->info['video']['bitrate'] == 0))) { + // if video bitrate not set + if (isset($this->info['audio']['bitrate']) && ($this->info['audio']['bitrate'] > 0) && ($this->info['audio']['bitrate'] == $this->info['bitrate'])) { + // AND if audio bitrate is set to same as overall bitrate + if (isset($this->info['playtime_seconds']) && ($this->info['playtime_seconds'] > 0)) { + // AND if playtime is set + if (isset($this->info['avdataend']) && isset($this->info['avdataoffset'])) { + // AND if AV data offset start/end is known + // THEN we can calculate the video bitrate + $this->info['bitrate'] = round((($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds']); + $this->info['video']['bitrate'] = $this->info['bitrate'] - $this->info['audio']['bitrate']; + } + } + } + } + + if ((!isset($this->info['playtime_seconds']) || ($this->info['playtime_seconds'] <= 0)) && !empty($this->info['bitrate'])) { + $this->info['playtime_seconds'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['bitrate']; + } + + if (!isset($this->info['bitrate']) && !empty($this->info['playtime_seconds'])) { + $this->info['bitrate'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['playtime_seconds']; + } + if (isset($this->info['bitrate']) && empty($this->info['audio']['bitrate']) && empty($this->info['video']['bitrate'])) { + if (isset($this->info['audio']['dataformat']) && empty($this->info['video']['resolution_x'])) { + // audio only + $this->info['audio']['bitrate'] = $this->info['bitrate']; + } elseif (isset($this->info['video']['resolution_x']) && empty($this->info['audio']['dataformat'])) { + // video only + $this->info['video']['bitrate'] = $this->info['bitrate']; + } + } + + // Set playtime string + if (!empty($this->info['playtime_seconds']) && empty($this->info['playtime_string'])) { + $this->info['playtime_string'] = getid3_lib::PlaytimeString($this->info['playtime_seconds']); + } + } + + /** + * @return bool + */ + public function CalculateCompressionRatioVideo() { + if (empty($this->info['video'])) { + return false; + } + if (empty($this->info['video']['resolution_x']) || empty($this->info['video']['resolution_y'])) { + return false; + } + if (empty($this->info['video']['bits_per_sample'])) { + return false; + } + + switch ($this->info['video']['dataformat']) { + case 'bmp': + case 'gif': + case 'jpeg': + case 'jpg': + case 'png': + case 'tiff': + $FrameRate = 1; + $PlaytimeSeconds = 1; + $BitrateCompressed = $this->info['filesize'] * 8; + break; + + default: + if (!empty($this->info['video']['frame_rate'])) { + $FrameRate = $this->info['video']['frame_rate']; + } else { + return false; + } + if (!empty($this->info['playtime_seconds'])) { + $PlaytimeSeconds = $this->info['playtime_seconds']; + } else { + return false; + } + if (!empty($this->info['video']['bitrate'])) { + $BitrateCompressed = $this->info['video']['bitrate']; + } else { + return false; + } + break; + } + $BitrateUncompressed = $this->info['video']['resolution_x'] * $this->info['video']['resolution_y'] * $this->info['video']['bits_per_sample'] * $FrameRate; + + $this->info['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed; + return true; + } + + /** + * @return bool + */ + public function CalculateCompressionRatioAudio() { + if (empty($this->info['audio']['bitrate']) || empty($this->info['audio']['channels']) || empty($this->info['audio']['sample_rate']) || !is_numeric($this->info['audio']['sample_rate'])) { + return false; + } + $this->info['audio']['compression_ratio'] = $this->info['audio']['bitrate'] / ($this->info['audio']['channels'] * $this->info['audio']['sample_rate'] * (!empty($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : 16)); + + if (!empty($this->info['audio']['streams'])) { + foreach ($this->info['audio']['streams'] as $streamnumber => $streamdata) { + if (!empty($streamdata['bitrate']) && !empty($streamdata['channels']) && !empty($streamdata['sample_rate'])) { + $this->info['audio']['streams'][$streamnumber]['compression_ratio'] = $streamdata['bitrate'] / ($streamdata['channels'] * $streamdata['sample_rate'] * (!empty($streamdata['bits_per_sample']) ? $streamdata['bits_per_sample'] : 16)); + } + } + } + return true; + } + + /** + * @return bool + */ + public function CalculateReplayGain() { + if (isset($this->info['replay_gain'])) { + if (!isset($this->info['replay_gain']['reference_volume'])) { + $this->info['replay_gain']['reference_volume'] = 89.0; + } + if (isset($this->info['replay_gain']['track']['adjustment'])) { + $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment']; + } + if (isset($this->info['replay_gain']['album']['adjustment'])) { + $this->info['replay_gain']['album']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['album']['adjustment']; + } + + if (isset($this->info['replay_gain']['track']['peak'])) { + $this->info['replay_gain']['track']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['track']['peak']); + } + if (isset($this->info['replay_gain']['album']['peak'])) { + $this->info['replay_gain']['album']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['album']['peak']); + } + } + return true; + } + + /** + * @return bool + */ + public function ProcessAudioStreams() { + if (!empty($this->info['audio']['bitrate']) || !empty($this->info['audio']['channels']) || !empty($this->info['audio']['sample_rate'])) { + if (!isset($this->info['audio']['streams'])) { + foreach ($this->info['audio'] as $key => $value) { + if ($key != 'streams') { + $this->info['audio']['streams'][0][$key] = $value; + } + } + } + } + return true; + } + + /** + * @return string|bool + */ + public function getid3_tempnam() { + return tempnam($this->tempdir, 'gI3'); + } + + /** + * @param string $name + * + * @return bool + * + * @throws getid3_exception + */ + public function include_module($name) { + //if (!file_exists($this->include_path.'module.'.$name.'.php')) { + if (!file_exists(GETID3_INCLUDEPATH.'module.'.$name.'.php')) { + throw new getid3_exception('Required module.'.$name.'.php is missing.'); + } + include_once(GETID3_INCLUDEPATH.'module.'.$name.'.php'); + return true; + } + + /** + * @param string $filename + * + * @return bool + */ + public static function is_writable ($filename) { + $ret = is_writable($filename); + if (!$ret) { + $perms = fileperms($filename); + $ret = ($perms & 0x0080) || ($perms & 0x0010) || ($perms & 0x0002); + } + return $ret; + } + +} + + +abstract class getid3_handler +{ + + /** + * @var getID3 + */ + protected $getid3; // pointer + + /** + * Analyzing filepointer or string. + * + * @var bool + */ + protected $data_string_flag = false; + + /** + * String to analyze. + * + * @var string + */ + protected $data_string = ''; + + /** + * Seek position in string. + * + * @var int + */ + protected $data_string_position = 0; + + /** + * String length. + * + * @var int + */ + protected $data_string_length = 0; + + /** + * @var string + */ + private $dependency_to; + + /** + * getid3_handler constructor. + * + * @param getID3 $getid3 + * @param string $call_module + */ + public function __construct(getID3 $getid3, $call_module=null) { + $this->getid3 = $getid3; + + if ($call_module) { + $this->dependency_to = str_replace('getid3_', '', $call_module); + } + } + + /** + * Analyze from file pointer. + * + * @return bool + */ + abstract public function Analyze(); + + /** + * Analyze from string instead. + * + * @param string $string + */ + public function AnalyzeString($string) { + // Enter string mode + $this->setStringMode($string); + + // Save info + $saved_avdataoffset = $this->getid3->info['avdataoffset']; + $saved_avdataend = $this->getid3->info['avdataend']; + $saved_filesize = (isset($this->getid3->info['filesize']) ? $this->getid3->info['filesize'] : null); // may be not set if called as dependency without openfile() call + + // Reset some info + $this->getid3->info['avdataoffset'] = 0; + $this->getid3->info['avdataend'] = $this->getid3->info['filesize'] = $this->data_string_length; + + // Analyze + $this->Analyze(); + + // Restore some info + $this->getid3->info['avdataoffset'] = $saved_avdataoffset; + $this->getid3->info['avdataend'] = $saved_avdataend; + $this->getid3->info['filesize'] = $saved_filesize; + + // Exit string mode + $this->data_string_flag = false; + } + + /** + * @param string $string + */ + public function setStringMode($string) { + $this->data_string_flag = true; + $this->data_string = $string; + $this->data_string_length = strlen($string); + } + + /** + * @return int|bool + */ + protected function ftell() { + if ($this->data_string_flag) { + return $this->data_string_position; + } + return ftell($this->getid3->fp); + } + + /** + * @param int $bytes + * + * @return string|false + * + * @throws getid3_exception + */ + protected function fread($bytes) { + if ($this->data_string_flag) { + $this->data_string_position += $bytes; + return substr($this->data_string, $this->data_string_position - $bytes, $bytes); + } + if ($bytes == 0) { + return ''; + } elseif ($bytes < 0) { + throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().')', 10); + } + $pos = $this->ftell() + $bytes; + if (!getid3_lib::intValueSupported($pos)) { + throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') because beyond PHP filesystem limit', 10); + } + + //return fread($this->getid3->fp, $bytes); + /* + * https://www.getid3.org/phpBB3/viewtopic.php?t=1930 + * "I found out that the root cause for the problem was how getID3 uses the PHP system function fread(). + * It seems to assume that fread() would always return as many bytes as were requested. + * However, according the PHP manual (http://php.net/manual/en/function.fread.php), this is the case only with regular local files, but not e.g. with Linux pipes. + * The call may return only part of the requested data and a new call is needed to get more." + */ + $contents = ''; + do { + //if (($this->getid3->memory_limit > 0) && ($bytes > $this->getid3->memory_limit)) { + if (($this->getid3->memory_limit > 0) && (($bytes / $this->getid3->memory_limit) > 0.99)) { // enable a more-fuzzy match to prevent close misses generating errors like "PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 33554464 bytes)" + throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') that is more than available PHP memory ('.$this->getid3->memory_limit.')', 10); + } + $part = fread($this->getid3->fp, $bytes); + $partLength = strlen($part); + $bytes -= $partLength; + $contents .= $part; + } while (($bytes > 0) && ($partLength > 0)); + return $contents; + } + + /** + * @param int $bytes + * @param int $whence + * + * @return int + * + * @throws getid3_exception + */ + protected function fseek($bytes, $whence=SEEK_SET) { + if ($this->data_string_flag) { + switch ($whence) { + case SEEK_SET: + $this->data_string_position = $bytes; + break; + + case SEEK_CUR: + $this->data_string_position += $bytes; + break; + + case SEEK_END: + $this->data_string_position = $this->data_string_length + $bytes; + break; + } + return 0; // fseek returns 0 on success + } + + $pos = $bytes; + if ($whence == SEEK_CUR) { + $pos = $this->ftell() + $bytes; + } elseif ($whence == SEEK_END) { + $pos = $this->getid3->info['filesize'] + $bytes; + } + if (!getid3_lib::intValueSupported($pos)) { + throw new getid3_exception('cannot fseek('.$pos.') because beyond PHP filesystem limit', 10); + } + + // https://github.com/JamesHeinrich/getID3/issues/327 + $result = fseek($this->getid3->fp, $bytes, $whence); + if ($result !== 0) { // fseek returns 0 on success + throw new getid3_exception('cannot fseek('.$pos.'). resource/stream does not appear to support seeking', 10); + } + return $result; + } + + /** + * @return string|false + * + * @throws getid3_exception + */ + protected function fgets() { + // must be able to handle CR/LF/CRLF but not read more than one lineend + $buffer = ''; // final string we will return + $prevchar = ''; // save previously-read character for end-of-line checking + if ($this->data_string_flag) { + while (true) { + $thischar = substr($this->data_string, $this->data_string_position++, 1); + if (($prevchar == "\r") && ($thischar != "\n")) { + // read one byte too many, back up + $this->data_string_position--; + break; + } + $buffer .= $thischar; + if ($thischar == "\n") { + break; + } + if ($this->data_string_position >= $this->data_string_length) { + // EOF + break; + } + $prevchar = $thischar; + } + + } else { + + // Ideally we would just use PHP's fgets() function, however... + // it does not behave consistently with regards to mixed line endings, may be system-dependent + // and breaks entirely when given a file with mixed \r vs \n vs \r\n line endings (e.g. some PDFs) + //return fgets($this->getid3->fp); + while (true) { + $thischar = fgetc($this->getid3->fp); + if (($prevchar == "\r") && ($thischar != "\n")) { + // read one byte too many, back up + fseek($this->getid3->fp, -1, SEEK_CUR); + break; + } + $buffer .= $thischar; + if ($thischar == "\n") { + break; + } + if (feof($this->getid3->fp)) { + break; + } + $prevchar = $thischar; + } + + } + return $buffer; + } + + /** + * @return bool + */ + protected function feof() { + if ($this->data_string_flag) { + return $this->data_string_position >= $this->data_string_length; + } + return feof($this->getid3->fp); + } + + /** + * @param string $module + * + * @return bool + */ + final protected function isDependencyFor($module) { + return $this->dependency_to == $module; + } + + /** + * @param string $text + * + * @return bool + */ + protected function error($text) { + $this->getid3->info['error'][] = $text; + + return false; + } + + /** + * @param string $text + * + * @return bool + */ + protected function warning($text) { + return $this->getid3->warning($text); + } + + /** + * @param string $text + */ + protected function notice($text) { + // does nothing for now + } + + /** + * @param string $name + * @param int $offset + * @param int $length + * @param string $image_mime + * + * @return string|null + * + * @throws Exception + * @throws getid3_exception + */ + public function saveAttachment($name, $offset, $length, $image_mime=null) { + $fp_dest = null; + $dest = null; + try { + + // do not extract at all + if ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_NONE) { + + $attachment = null; // do not set any + + // extract to return array + } elseif ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_INLINE) { + + $this->fseek($offset); + $attachment = $this->fread($length); // get whole data in one pass, till it is anyway stored in memory + if ($attachment === false || strlen($attachment) != $length) { + throw new Exception('failed to read attachment data'); + } + + // assume directory path is given + } else { + + // set up destination path + $dir = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->getid3->option_save_attachments), DIRECTORY_SEPARATOR); + if (!is_dir($dir) || !getID3::is_writable($dir)) { // check supplied directory + throw new Exception('supplied path ('.$dir.') does not exist, or is not writable'); + } + $dest = $dir.DIRECTORY_SEPARATOR.$name.($image_mime ? '.'.getid3_lib::ImageExtFromMime($image_mime) : ''); + + // create dest file + if (($fp_dest = fopen($dest, 'wb')) == false) { + throw new Exception('failed to create file '.$dest); + } + + // copy data + $this->fseek($offset); + $buffersize = ($this->data_string_flag ? $length : $this->getid3->fread_buffer_size()); + $bytesleft = $length; + while ($bytesleft > 0) { + if (($buffer = $this->fread(min($buffersize, $bytesleft))) === false || ($byteswritten = fwrite($fp_dest, $buffer)) === false || ($byteswritten === 0)) { + throw new Exception($buffer === false ? 'not enough data to read' : 'failed to write to destination file, may be not enough disk space'); + } + $bytesleft -= $byteswritten; + } + + fclose($fp_dest); + $attachment = $dest; + + } + + } catch (Exception $e) { + + // close and remove dest file if created + if (isset($fp_dest) && is_resource($fp_dest)) { + fclose($fp_dest); + } + + if (isset($dest) && file_exists($dest)) { + unlink($dest); + } + + // do not set any is case of error + $attachment = null; + $this->warning('Failed to extract attachment '.$name.': '.$e->getMessage()); + + } + + // seek to the end of attachment + $this->fseek($offset + $length); + + return $attachment; + } + +} + + +class getid3_exception extends Exception +{ + public $message; +} diff --git a/serendipity_event_podcast/player/getid3/module.archive.gzip.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.gzip.php similarity index 56% rename from serendipity_event_podcast/player/getid3/module.archive.gzip.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.gzip.php index 244ceade..d7577811 100644 --- a/serendipity_event_podcast/player/getid3/module.archive.gzip.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.gzip.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.archive.gzip.php // @@ -14,34 +15,50 @@ ///////////////////////////////////////////////////////////////// // // // Module originally written by // -// Mike Mozolin // +// Mike Mozolin // // // ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_gzip { +class getid3_gzip extends getid3_handler +{ + /** + * Optional file list - disable for speed. + * Decode gzipped files, if possible, and parse recursively (.tar.gz for example). + * + * @var bool + */ + public $parse_contents = false; - // public: Optional file list - disable for speed. - var $option_gzip_parse_contents = false; // decode gzipped files, if possible, and parse recursively (.tar.gz for example) + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_gzip(&$fd, &$ThisFileInfo) { - $ThisFileInfo['fileformat'] = 'gzip'; + $info['fileformat'] = 'gzip'; $start_length = 10; $unpack_header = 'a1id1/a1id2/a1cmethod/a1flags/a4mtime/a1xflags/a1os'; //+---+---+---+---+---+---+---+---+---+---+ //|ID1|ID2|CM |FLG| MTIME |XFL|OS | //+---+---+---+---+---+---+---+---+---+---+ - ob_start(); - fseek($fd, 0); - $buffer = fread($fd, $ThisFileInfo['filesize']); - $errormessage = ob_get_contents(); - ob_end_clean(); + + if ($info['php_memory_limit'] && ($info['filesize'] > $info['php_memory_limit'])) { + $this->error('File is too large ('.number_format($info['filesize']).' bytes) to read into memory (limit: '.number_format($info['php_memory_limit'] / 1048576).'MB)'); + return false; + } + $this->fseek(0); + $buffer = $this->fread($info['filesize']); $arr_members = explode("\x1F\x8B\x08", $buffer); + $num_members = 0; while (true) { $is_wrong_members = false; - $num_members = intval(count($arr_members)); + $num_members = count($arr_members); for ($i = 0; $i < $num_members; $i++) { if (strlen($arr_members[$i]) == 0) { continue; @@ -51,7 +68,7 @@ class getid3_gzip { $attr = unpack($unpack_header, substr($buf, 0, $start_length)); if (!$this->get_os_type(ord($attr['os']))) { // Merge member with previous if wrong OS type - $arr_members[$i - 1] .= $buf; + $arr_members[($i - 1)] .= $buf; $arr_members[$i] = ''; $is_wrong_members = true; continue; @@ -62,37 +79,37 @@ class getid3_gzip { } } - $ThisFileInfo['gzip']['files'] = array(); + $info['gzip']['files'] = array(); $fpointer = 0; $idx = 0; - for ($i = 0; $i < $num_members; $i++) { - if (strlen($arr_members[$i]) == 0) { + foreach ($arr_members as $member) { + if (strlen($member) == 0) { continue; } - $thisThisFileInfo = &$ThisFileInfo['gzip']['member_header'][++$idx]; + $thisInfo = &$info['gzip']['member_header'][++$idx]; - $buff = "\x1F\x8B\x08".$arr_members[$i]; + $buff = "\x1F\x8B\x08". $member; $attr = unpack($unpack_header, substr($buff, 0, $start_length)); - $thisThisFileInfo['filemtime'] = getid3_lib::LittleEndian2Int($attr['mtime']); - $thisThisFileInfo['raw']['id1'] = ord($attr['cmethod']); - $thisThisFileInfo['raw']['id2'] = ord($attr['cmethod']); - $thisThisFileInfo['raw']['cmethod'] = ord($attr['cmethod']); - $thisThisFileInfo['raw']['os'] = ord($attr['os']); - $thisThisFileInfo['raw']['xflags'] = ord($attr['xflags']); - $thisThisFileInfo['raw']['flags'] = ord($attr['flags']); + $thisInfo['filemtime'] = getid3_lib::LittleEndian2Int($attr['mtime']); + $thisInfo['raw']['id1'] = ord($attr['cmethod']); + $thisInfo['raw']['id2'] = ord($attr['cmethod']); + $thisInfo['raw']['cmethod'] = ord($attr['cmethod']); + $thisInfo['raw']['os'] = ord($attr['os']); + $thisInfo['raw']['xflags'] = ord($attr['xflags']); + $thisInfo['raw']['flags'] = ord($attr['flags']); - $thisThisFileInfo['flags']['crc16'] = (bool) ($thisThisFileInfo['raw']['flags'] & 0x02); - $thisThisFileInfo['flags']['extra'] = (bool) ($thisThisFileInfo['raw']['flags'] & 0x04); - $thisThisFileInfo['flags']['filename'] = (bool) ($thisThisFileInfo['raw']['flags'] & 0x08); - $thisThisFileInfo['flags']['comment'] = (bool) ($thisThisFileInfo['raw']['flags'] & 0x10); + $thisInfo['flags']['crc16'] = (bool) ($thisInfo['raw']['flags'] & 0x02); + $thisInfo['flags']['extra'] = (bool) ($thisInfo['raw']['flags'] & 0x04); + $thisInfo['flags']['filename'] = (bool) ($thisInfo['raw']['flags'] & 0x08); + $thisInfo['flags']['comment'] = (bool) ($thisInfo['raw']['flags'] & 0x10); - $thisThisFileInfo['compression'] = $this->get_xflag_type($thisThisFileInfo['raw']['xflags']); + $thisInfo['compression'] = $this->get_xflag_type($thisInfo['raw']['xflags']); - $thisThisFileInfo['os'] = $this->get_os_type($thisThisFileInfo['raw']['os']); - if (!$thisThisFileInfo['os']) { - $ThisFileInfo['error'][] = 'Read error on gzip file'; + $thisInfo['os'] = $this->get_os_type($thisInfo['raw']['os']); + if (!$thisInfo['os']) { + $this->error('Read error on gzip file'); return false; } @@ -102,12 +119,12 @@ class getid3_gzip { //+---+---+=================================+ //| XLEN |...XLEN bytes of "extra field"...| //+---+---+=================================+ - if ($thisThisFileInfo['flags']['extra']) { + if ($thisInfo['flags']['extra']) { $w_xlen = substr($buff, $fpointer, 2); $xlen = getid3_lib::LittleEndian2Int($w_xlen); $fpointer += 2; - $thisThisFileInfo['raw']['xfield'] = substr($buff, $fpointer, $xlen); + $thisInfo['raw']['xfield'] = substr($buff, $fpointer, $xlen); // Extra SubFields //+---+---+---+---+==================================+ //|SI1|SI2| LEN |... LEN bytes of subfield data ...| @@ -136,14 +153,15 @@ class getid3_gzip { //|...original file name, zero-terminated...| //+=========================================+ // GZIP files may have only one file, with no filename, so assume original filename is current filename without .gz - $thisThisFileInfo['filename'] = preg_replace('#\.gz$#i', '', $ThisFileInfo['filename']); - if ($thisThisFileInfo['flags']['filename']) { + $thisInfo['filename'] = preg_replace('#\\.gz$#i', '', $info['filename']); + if ($thisInfo['flags']['filename']) { + $thisInfo['filename'] = ''; while (true) { if (ord($buff[$fpointer]) == 0) { $fpointer++; break; } - $thisThisFileInfo['filename'] .= $buff[$fpointer]; + $thisInfo['filename'] .= $buff[$fpointer]; $fpointer++; } } @@ -151,13 +169,13 @@ class getid3_gzip { //+===================================+ //|...file comment, zero-terminated...| //+===================================+ - if ($thisThisFileInfo['flags']['comment']) { + if ($thisInfo['flags']['comment']) { while (true) { if (ord($buff[$fpointer]) == 0) { $fpointer++; break; } - $thisThisFileInfo['comment'] .= $buff[$fpointer]; + $thisInfo['comment'] .= $buff[$fpointer]; $fpointer++; } } @@ -165,23 +183,23 @@ class getid3_gzip { //+---+---+ //| CRC16 | //+---+---+ - if ($thisThisFileInfo['flags']['crc16']) { + if ($thisInfo['flags']['crc16']) { $w_crc = substr($buff, $fpointer, 2); - $thisThisFileInfo['crc16'] = getid3_lib::LittleEndian2Int($w_crc); + $thisInfo['crc16'] = getid3_lib::LittleEndian2Int($w_crc); $fpointer += 2; } // bit 0 - FLG.FTEXT - //if ($thisThisFileInfo['raw']['flags'] & 0x01) { + //if ($thisInfo['raw']['flags'] & 0x01) { // Ignored... //} // bits 5, 6, 7 - reserved - $thisThisFileInfo['crc32'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 8, 4)); - $thisThisFileInfo['filesize'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 4)); + $thisInfo['crc32'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 8, 4)); + $thisInfo['filesize'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 4)); - $ThisFileInfo['gzip']['files'] = getid3_lib::array_merge_clobber($ThisFileInfo['gzip']['files'], getid3_lib::CreateDeepArray($thisThisFileInfo['filename'], '/', $thisThisFileInfo['filesize'])); + $info['gzip']['files'] = getid3_lib::array_merge_clobber($info['gzip']['files'], getid3_lib::CreateDeepArray($thisInfo['filename'], '/', $thisInfo['filesize'])); - if ($this->option_gzip_parse_contents) { + if ($this->parse_contents) { // Try to inflate GZip $csize = 0; $inflated = ''; @@ -193,13 +211,13 @@ class getid3_gzip { $inflated = gzinflate($cdata); // Calculate CRC32 for inflated content - $thisThisFileInfo['crc32_valid'] = (bool) (sprintf('%u', crc32($inflated)) == $thisThisFileInfo['crc32']); + $thisInfo['crc32_valid'] = sprintf('%u', crc32($inflated)) == $thisInfo['crc32']; // determine format $formattest = substr($inflated, 0, 32774); - $newgetID3 = new getID3(); - $determined_format = $newgetID3->GetFileFormat($formattest); - unset($newgetID3); + $getid3_temp = new getID3(); + $determined_format = $getid3_temp->GetFileFormat($formattest); + unset($getid3_temp); // file format is determined $determined_format['module'] = (isset($determined_format['module']) ? $determined_format['module'] : ''); @@ -209,20 +227,21 @@ class getid3_gzip { if (file_exists(GETID3_INCLUDEPATH.$determined_format['include']) && include_once(GETID3_INCLUDEPATH.$determined_format['include'])) { if (($temp_tar_filename = tempnam(GETID3_TEMP_DIR, 'getID3')) === false) { // can't find anywhere to create a temp file, abort - $ThisFileInfo['error'][] = 'Unable to create temp file to parse TAR inside GZIP file'; + $this->error('Unable to create temp file to parse TAR inside GZIP file'); break; } if ($fp_temp_tar = fopen($temp_tar_filename, 'w+b')) { fwrite($fp_temp_tar, $inflated); - rewind($fp_temp_tar); - $getid3_tar = new getid3_tar($fp_temp_tar, $dummy); - $ThisFileInfo['gzip']['member_header'][$idx]['tar'] = $dummy['tar']; - unset($dummy); - unset($getid3_tar); fclose($fp_temp_tar); + $getid3_temp = new getID3(); + $getid3_temp->openfile($temp_tar_filename); + $getid3_tar = new getid3_tar($getid3_temp); + $getid3_tar->Analyze(); + $info['gzip']['member_header'][$idx]['tar'] = $getid3_temp->info['tar']; + unset($getid3_temp, $getid3_tar); unlink($temp_tar_filename); } else { - $ThisFileInfo['error'][] = 'Unable to fopen() temp file to parse TAR inside GZIP file'; + $this->error('Unable to fopen() temp file to parse TAR inside GZIP file'); break; } } @@ -233,14 +252,22 @@ class getid3_gzip { // unknown or unhandled format break; } + } else { + $this->warning('PHP is not compiled with gzinflate() support. Please enable PHP Zlib extension or recompile with the --with-zlib switch'); } } } return true; } - // Converts the OS type - function get_os_type($key) { + /** + * Converts the OS type. + * + * @param string $key + * + * @return string + */ + public function get_os_type($key) { static $os_type = array( '0' => 'FAT filesystem (MS-DOS, OS/2, NT/Win32)', '1' => 'Amiga', @@ -261,8 +288,14 @@ class getid3_gzip { return (isset($os_type[$key]) ? $os_type[$key] : ''); } - // Converts the eXtra FLags - function get_xflag_type($key) { + /** + * Converts the eXtra FLags. + * + * @param string $key + * + * @return string + */ + public function get_xflag_type($key) { static $xflag_type = array( '0' => 'unknown', '2' => 'maximum compression', @@ -272,4 +305,3 @@ class getid3_gzip { } } -?> diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.hpk.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.hpk.php new file mode 100644 index 00000000..328dbd59 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.hpk.php @@ -0,0 +1,92 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.archive.hpk.php // +// module for analyzing HPK files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_hpk extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'hpk'; + + $this->fseek($info['avdataoffset']); + $HPKheader = $this->fread(36); + + if (substr($HPKheader, 0, 4) == 'BPUL') { + + $info['hpk']['header']['signature'] = substr($HPKheader, 0, 4); + $info['hpk']['header']['data_offset'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 4, 4)); + $info['hpk']['header']['fragments_per_file'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 8, 4)); + //$info['hpk']['header']['unknown1'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 12, 4)); + $info['hpk']['header']['fragments_residual_offset'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 16, 4)); + $info['hpk']['header']['fragments_residual_count'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 20, 4)); + //$info['hpk']['header']['unknown2'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 24, 4)); + $info['hpk']['header']['fragmented_filesystem_offset'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 28, 4)); + $info['hpk']['header']['fragmented_filesystem_length'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 32, 4)); + + $info['hpk']['header']['filesystem_entries'] = $info['hpk']['header']['fragmented_filesystem_length'] / ($info['hpk']['header']['fragments_per_file'] * 8); + $this->fseek($info['hpk']['header']['fragmented_filesystem_offset']); + for ($i = 0; $i < $info['hpk']['header']['filesystem_entries']; $i++) { + $offset = getid3_lib::LittleEndian2Int($this->fread(4)); + $length = getid3_lib::LittleEndian2Int($this->fread(4)); + $info['hpk']['filesystem'][$i] = array('offset' => $offset, 'length' => $length); + } + +$this->error('HPK parsing incomplete (and mostly broken) in this version of getID3() ['.$this->getid3->version().']'); + +/* + $filename = ''; + $dirs = array(); + foreach ($info['hpk']['filesystem'] as $key => $filesystemdata) { + $this->fseek($filesystemdata['offset']); + $first4 = $this->fread(4); + if (($first4 == 'LZ4 ') || ($first4 == 'ZLIB')) { + // actual data, ignore + $info['hpk']['toc'][$key] = array( + 'filename' => ltrim(implode('/', $dirs).'/'.$filename, '/'), + 'offset' => $filesystemdata['offset'], + 'length' => $filesystemdata['length'], + ); + $filename = ''; + $dirs = array(); + } else { + $fragment_index = getid3_lib::LittleEndian2Int($first4); + $fragment_type = getid3_lib::LittleEndian2Int($this->fread(4)); // file = 0, directory = 1 + $name_length = getid3_lib::LittleEndian2Int($this->fread(2)); + if ($fragment_type == 1) { + $dirs[] = $this->fread($name_length); + } else { + $filename = $this->fread($name_length); + } + } + } +*/ + + } else { + $this->error('Expecting "BPUL" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($HPKheader, 0, 4)).'"'); + return false; + } + + return true; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.rar.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.rar.php new file mode 100644 index 00000000..f80219c3 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.rar.php @@ -0,0 +1,61 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.archive.rar.php // +// module for analyzing RAR files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_rar extends getid3_handler +{ + /** + * if true use PHP RarArchive extension, if false (non-extension parsing not yet written in getID3) + * + * @var bool + */ + public $use_php_rar_extension = true; + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'rar'; + + if ($this->use_php_rar_extension === true) { + if (function_exists('rar_open')) { + if ($rp = rar_open($info['filenamepath'])) { + $info['rar']['files'] = array(); + $entries = rar_list($rp); + foreach ($entries as $entry) { + $info['rar']['files'] = getid3_lib::array_merge_clobber($info['rar']['files'], getid3_lib::CreateDeepArray($entry->getName(), '/', $entry->getUnpackedSize())); + } + rar_close($rp); + return true; + } else { + $this->error('failed to rar_open('.$info['filename'].')'); + } + } else { + $this->error('RAR support does not appear to be available in this PHP installation'); + } + } else { + $this->error('PHP-RAR processing has been disabled (set $getid3_rar->use_php_rar_extension=true to enable)'); + } + return false; + + } + +} diff --git a/serendipity_event_podcast/player/getid3/module.archive.szip.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.szip.php similarity index 65% rename from serendipity_event_podcast/player/getid3/module.archive.szip.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.szip.php index 2513c85c..8647967c 100644 --- a/serendipity_event_podcast/player/getid3/module.archive.szip.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.szip.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.archive.szip.php // @@ -13,37 +14,43 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_szip +class getid3_szip extends getid3_handler { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_szip(&$fd, &$ThisFileInfo) { - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $SZIPHeader = fread($fd, 6); - if (substr($SZIPHeader, 0, 4) != 'SZ'."\x0A\x04") { - $ThisFileInfo['error'][] = 'Expecting "SZ[x0A][x04]" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($SZIPHeader, 0, 4).'"'; + $this->fseek($info['avdataoffset']); + $SZIPHeader = $this->fread(6); + if (substr($SZIPHeader, 0, 4) != "SZ\x0A\x04") { + $this->error('Expecting "53 5A 0A 04" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($SZIPHeader, 0, 4)).'"'); return false; } + $info['fileformat'] = 'szip'; + $info['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 4, 1)); + $info['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 5, 1)); + $this->error('SZIP parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + return false; - $ThisFileInfo['fileformat'] = 'szip'; - - $ThisFileInfo['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 4, 1)); - $ThisFileInfo['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 5, 1)); - - while (!feof($fd)) { - $NextBlockID = fread($fd, 2); + while (!$this->feof()) { + $NextBlockID = $this->fread(2); switch ($NextBlockID) { case 'SZ': // Note that szip files can be concatenated, this has the same effect as // concatenating the files. this also means that global header blocks // might be present between directory/data blocks. - fseek($fd, 4, SEEK_CUR); + $this->fseek(4, SEEK_CUR); break; case 'BH': - $BHheaderbytes = getid3_lib::BigEndian2Int(fread($fd, 3)); - $BHheaderdata = fread($fd, $BHheaderbytes); + $BHheaderbytes = getid3_lib::BigEndian2Int($this->fread(3)); + $BHheaderdata = $this->fread($BHheaderbytes); $BHheaderoffset = 0; while (strpos($BHheaderdata, "\x00", $BHheaderoffset) > 0) { //filename as \0 terminated string (empty string indicates end) @@ -79,7 +86,7 @@ class getid3_szip $BHdataArray['access_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); $BHheaderoffset += 4; - $ThisFileInfo['szip']['BH'][] = $BHdataArray; + $info['szip']['BH'][] = $BHdataArray; } break; @@ -93,5 +100,3 @@ class getid3_szip } } - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.archive.tar.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.tar.php similarity index 77% rename from serendipity_event_podcast/player/getid3/module.archive.tar.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.tar.php index fafbbcb7..f8aed795 100644 --- a/serendipity_event_podcast/player/getid3/module.archive.tar.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.tar.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.archive.tar.php // @@ -14,26 +15,31 @@ ///////////////////////////////////////////////////////////////// // // // Module originally written by // -// Mike Mozolin // +// Mike Mozolin // // // ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_tar { +class getid3_tar extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_tar(&$fd, &$ThisFileInfo) { - $ThisFileInfo['fileformat'] = 'tar'; - $ThisFileInfo['tar']['files'] = array(); + $info['fileformat'] = 'tar'; + $info['tar']['files'] = array(); $unpack_header = 'a100fname/a8mode/a8uid/a8gid/a12size/a12mtime/a8chksum/a1typflag/a100lnkname/a6magic/a2ver/a32uname/a32gname/a8devmaj/a8devmin/a155prefix'; $null_512k = str_repeat("\x00", 512); // end-of-file marker - ob_start(); - fseek($fd, 0); - $errormessage = ob_get_contents(); - ob_end_clean(); - while (!feof($fd)) { - $buffer = fread($fd, 512); + $this->fseek(0); + while (!feof($this->getid3->fp)) { + $buffer = $this->fread(512); if (strlen($buffer) < 512) { break; } @@ -41,13 +47,13 @@ class getid3_tar { // check the block $checksum = 0; for ($i = 0; $i < 148; $i++) { - $checksum += ord($buffer{$i}); + $checksum += ord($buffer[$i]); } for ($i = 148; $i < 156; $i++) { $checksum += ord(' '); } for ($i = 156; $i < 512; $i++) { - $checksum += ord($buffer{$i}); + $checksum += ord($buffer[$i]); } $attr = unpack($unpack_header, $buffer); $name = (isset($attr['fname'] ) ? trim($attr['fname'] ) : ''); @@ -82,27 +88,27 @@ class getid3_tar { } // Read to the next chunk - fseek($fd, $size, SEEK_CUR); + $this->fseek($size, SEEK_CUR); $diff = $size % 512; if ($diff != 0) { // Padding, throw away - fseek($fd, (512 - $diff), SEEK_CUR); + $this->fseek((512 - $diff), SEEK_CUR); } // Protect against tar-files with garbage at the end if ($name == '') { break; } - $ThisFileInfo['tar']['file_details'][$name] = array ( + $info['tar']['file_details'][$name] = array ( 'name' => $name, 'mode_raw' => $mode, - 'mode' => getid3_tar::display_perms($mode), + 'mode' => self::display_perms($mode), 'uid' => $uid, 'gid' => $gid, 'size' => $size, 'mtime' => $mtime, 'chksum' => $chksum, - 'typeflag' => getid3_tar::get_flag_type($typflag), + 'typeflag' => self::get_flag_type($typflag), 'linkname' => $lnkname, 'magic' => $magic, 'version' => $ver, @@ -111,13 +117,19 @@ class getid3_tar { 'devmajor' => $devmaj, 'devminor' => $devmin ); - $ThisFileInfo['tar']['files'] = getid3_lib::array_merge_clobber($ThisFileInfo['tar']['files'], getid3_lib::CreateDeepArray($ThisFileInfo['tar']['file_details'][$name]['name'], '/', $size)); + $info['tar']['files'] = getid3_lib::array_merge_clobber($info['tar']['files'], getid3_lib::CreateDeepArray($info['tar']['file_details'][$name]['name'], '/', $size)); } return true; } - // Parses the file mode to file permissions - function display_perms($mode) { + /** + * Parses the file mode to file permissions. + * + * @param int $mode + * + * @return string + */ + public function display_perms($mode) { // Determine Type if ($mode & 0x1000) $type='p'; // FIFO pipe elseif ($mode & 0x2000) $type='c'; // Character special @@ -129,6 +141,9 @@ class getid3_tar { else $type='u'; // UNKNOWN // Determine permissions + $owner = array(); + $group = array(); + $world = array(); $owner['read'] = (($mode & 00400) ? 'r' : '-'); $owner['write'] = (($mode & 00200) ? 'w' : '-'); $owner['execute'] = (($mode & 00100) ? 'x' : '-'); @@ -151,8 +166,14 @@ class getid3_tar { return $s; } - // Converts the file type - function get_flag_type($typflag) { + /** + * Converts the file type. + * + * @param string $typflag + * + * @return mixed|string + */ + public function get_flag_type($typflag) { static $flag_types = array( '0' => 'LF_NORMAL', '1' => 'LF_LINK', @@ -174,5 +195,3 @@ class getid3_tar { } } - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.xz.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.xz.php new file mode 100644 index 00000000..dbbc067b --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.xz.php @@ -0,0 +1,44 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.archive.xz.php // +// module for analyzing XZ files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_xz extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + $xzheader = $this->fread(6); + + // https://tukaani.org/xz/xz-file-format-1.0.4.txt + $info['xz']['stream_header']['magic'] = substr($xzheader, 0, 6); + if ($info['xz']['stream_header']['magic'] != "\xFD".'7zXZ'."\x00") { + $this->error('Invalid XZ stream header magic (expecting FD 37 7A 58 5A 00, found '.getid3_lib::PrintHexBytes($info['xz']['stream_header']['magic']).') at offset '.$info['avdataoffset']); + return false; + } + $info['fileformat'] = 'xz'; + $this->error('XZ parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + return false; + + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.zip.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.zip.php new file mode 100644 index 00000000..ffd196df --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.archive.zip.php @@ -0,0 +1,573 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.archive.zip.php // +// module for analyzing pkZip files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_zip extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'zip'; + $info['zip']['encoding'] = 'ISO-8859-1'; + $info['zip']['files'] = array(); + + $info['zip']['compressed_size'] = 0; + $info['zip']['uncompressed_size'] = 0; + $info['zip']['entries_count'] = 0; + + if (!getid3_lib::intValueSupported($info['filesize'])) { + $this->error('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB, not supported by PHP'); + return false; + } else { + $EOCDsearchData = ''; + $EOCDsearchCounter = 0; + while ($EOCDsearchCounter++ < 512) { + + $this->fseek(-128 * $EOCDsearchCounter, SEEK_END); + $EOCDsearchData = $this->fread(128).$EOCDsearchData; + + if (strstr($EOCDsearchData, 'PK'."\x05\x06")) { + + $EOCDposition = strpos($EOCDsearchData, 'PK'."\x05\x06"); + $this->fseek((-128 * $EOCDsearchCounter) + $EOCDposition, SEEK_END); + $info['zip']['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory(); + + $this->fseek($info['zip']['end_central_directory']['directory_offset']); + $info['zip']['entries_count'] = 0; + while ($centraldirectoryentry = $this->ZIPparseCentralDirectory()) { + $info['zip']['central_directory'][] = $centraldirectoryentry; + $info['zip']['entries_count']++; + $info['zip']['compressed_size'] += $centraldirectoryentry['compressed_size']; + $info['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size']; + + //if ($centraldirectoryentry['uncompressed_size'] > 0) { zero-byte files are valid + if (!empty($centraldirectoryentry['filename'])) { + $info['zip']['files'] = getid3_lib::array_merge_clobber($info['zip']['files'], getid3_lib::CreateDeepArray($centraldirectoryentry['filename'], '/', $centraldirectoryentry['uncompressed_size'])); + } + } + + if ($info['zip']['entries_count'] == 0) { + $this->error('No Central Directory entries found (truncated file?)'); + return false; + } + + if (!empty($info['zip']['end_central_directory']['comment'])) { + $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment']; + } + + if (isset($info['zip']['central_directory'][0]['compression_method'])) { + $info['zip']['compression_method'] = $info['zip']['central_directory'][0]['compression_method']; + } + if (isset($info['zip']['central_directory'][0]['flags']['compression_speed'])) { + $info['zip']['compression_speed'] = $info['zip']['central_directory'][0]['flags']['compression_speed']; + } + if (isset($info['zip']['compression_method']) && ($info['zip']['compression_method'] == 'store') && !isset($info['zip']['compression_speed'])) { + $info['zip']['compression_speed'] = 'store'; + } + + // secondary check - we (should) already have all the info we NEED from the Central Directory above, but scanning each + // Local File Header entry will + foreach ($info['zip']['central_directory'] as $central_directory_entry) { + $this->fseek($central_directory_entry['entry_offset']); + if ($fileentry = $this->ZIPparseLocalFileHeader()) { + $info['zip']['entries'][] = $fileentry; + } else { + $this->warning('Error parsing Local File Header at offset '.$central_directory_entry['entry_offset']); + } + } + + // check for EPUB files + if (!empty($info['zip']['entries'][0]['filename']) && + ($info['zip']['entries'][0]['filename'] == 'mimetype') && + ($info['zip']['entries'][0]['compression_method'] == 'store') && + ($info['zip']['entries'][0]['uncompressed_size'] == 20) && + isset($info['zip']['entries'][0]['data_offset'])) { + // http://idpf.org/epub/30/spec/epub30-ocf.html + // "3.3 OCF ZIP Container Media Type Identification + // OCF ZIP Containers must include a mimetype file as the first file in the Container, and the contents of this file must be the MIME type string application/epub+zip. + // The contents of the mimetype file must not contain any leading padding or whitespace, must not begin with the Unicode signature (or Byte Order Mark), + // and the case of the MIME type string must be exactly as presented above. The mimetype file additionally must be neither compressed nor encrypted, + // and there must not be an extra field in its ZIP header." + $this->fseek($info['zip']['entries'][0]['data_offset']); + if ($this->fread(20) == 'application/epub+zip') { + $info['fileformat'] = 'zip.epub'; + $info['mime_type'] = 'application/epub+zip'; + } + } + + // check for Office Open XML files (e.g. .docx, .xlsx) + if (!empty($info['zip']['files']['[Content_Types].xml']) && + !empty($info['zip']['files']['_rels']['.rels']) && + !empty($info['zip']['files']['docProps']['app.xml']) && + !empty($info['zip']['files']['docProps']['core.xml'])) { + // http://technet.microsoft.com/en-us/library/cc179224.aspx + $info['fileformat'] = 'zip.msoffice'; + if (!empty($info['zip']['files']['ppt'])) { + $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; + } elseif (!empty($info['zip']['files']['xl'])) { + $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + } elseif (!empty($info['zip']['files']['word'])) { + $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; + } + } + + return true; + } + } + } + + if (!$this->getZIPentriesFilepointer()) { + unset($info['zip']); + $info['fileformat'] = ''; + $this->error('Cannot find End Of Central Directory (truncated file?)'); + return false; + } + + // central directory couldn't be found and/or parsed + // scan through actual file data entries, recover as much as possible from probable trucated file + if ($info['zip']['compressed_size'] > ($info['filesize'] - 46 - 22)) { + $this->error('Warning: Truncated file! - Total compressed file sizes ('.$info['zip']['compressed_size'].' bytes) is greater than filesize minus Central Directory and End Of Central Directory structures ('.($info['filesize'] - 46 - 22).' bytes)'); + } + $this->error('Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete'); + foreach ($info['zip']['entries'] as $key => $valuearray) { + $info['zip']['files'][$valuearray['filename']] = $valuearray['uncompressed_size']; + } + return true; + } + + /** + * @return bool + */ + public function getZIPHeaderFilepointerTopDown() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'zip'; + + $info['zip']['compressed_size'] = 0; + $info['zip']['uncompressed_size'] = 0; + $info['zip']['entries_count'] = 0; + + rewind($this->getid3->fp); + while ($fileentry = $this->ZIPparseLocalFileHeader()) { + $info['zip']['entries'][] = $fileentry; + $info['zip']['entries_count']++; + } + if ($info['zip']['entries_count'] == 0) { + $this->error('No Local File Header entries found'); + return false; + } + + $info['zip']['entries_count'] = 0; + while ($centraldirectoryentry = $this->ZIPparseCentralDirectory()) { + $info['zip']['central_directory'][] = $centraldirectoryentry; + $info['zip']['entries_count']++; + $info['zip']['compressed_size'] += $centraldirectoryentry['compressed_size']; + $info['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size']; + } + if ($info['zip']['entries_count'] == 0) { + $this->error('No Central Directory entries found (truncated file?)'); + return false; + } + + if ($EOCD = $this->ZIPparseEndOfCentralDirectory()) { + $info['zip']['end_central_directory'] = $EOCD; + } else { + $this->error('No End Of Central Directory entry found (truncated file?)'); + return false; + } + + if (!empty($info['zip']['end_central_directory']['comment'])) { + $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment']; + } + + return true; + } + + /** + * @return bool + */ + public function getZIPentriesFilepointer() { + $info = &$this->getid3->info; + + $info['zip']['compressed_size'] = 0; + $info['zip']['uncompressed_size'] = 0; + $info['zip']['entries_count'] = 0; + + rewind($this->getid3->fp); + while ($fileentry = $this->ZIPparseLocalFileHeader()) { + $info['zip']['entries'][] = $fileentry; + $info['zip']['entries_count']++; + $info['zip']['compressed_size'] += $fileentry['compressed_size']; + $info['zip']['uncompressed_size'] += $fileentry['uncompressed_size']; + } + if ($info['zip']['entries_count'] == 0) { + $this->error('No Local File Header entries found'); + return false; + } + + return true; + } + + /** + * @return array|false + */ + public function ZIPparseLocalFileHeader() { + $LocalFileHeader = array(); + $LocalFileHeader['offset'] = $this->ftell(); + + $ZIPlocalFileHeader = $this->fread(30); + + $LocalFileHeader['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 0, 4)); + if ($LocalFileHeader['raw']['signature'] != 0x04034B50) { // "PK\x03\x04" + // invalid Local File Header Signature + $this->fseek($LocalFileHeader['offset']); // seek back to where filepointer originally was so it can be handled properly + return false; + } + $LocalFileHeader['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 4, 2)); + $LocalFileHeader['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 6, 2)); + $LocalFileHeader['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 8, 2)); + $LocalFileHeader['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 10, 2)); + $LocalFileHeader['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 12, 2)); + $LocalFileHeader['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 14, 4)); + $LocalFileHeader['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 18, 4)); + $LocalFileHeader['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 22, 4)); + $LocalFileHeader['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 26, 2)); + $LocalFileHeader['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 28, 2)); + + $LocalFileHeader['extract_version'] = sprintf('%1.1f', $LocalFileHeader['raw']['extract_version'] / 10); + $LocalFileHeader['host_os'] = $this->ZIPversionOSLookup(($LocalFileHeader['raw']['extract_version'] & 0xFF00) >> 8); + $LocalFileHeader['compression_method'] = $this->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']); + $LocalFileHeader['compressed_size'] = $LocalFileHeader['raw']['compressed_size']; + $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['raw']['uncompressed_size']; + $LocalFileHeader['flags'] = $this->ZIPparseGeneralPurposeFlags($LocalFileHeader['raw']['general_flags'], $LocalFileHeader['raw']['compression_method']); + $LocalFileHeader['last_modified_timestamp'] = $this->DOStime2UNIXtime($LocalFileHeader['raw']['last_mod_file_date'], $LocalFileHeader['raw']['last_mod_file_time']); + + $FilenameExtrafieldLength = $LocalFileHeader['raw']['filename_length'] + $LocalFileHeader['raw']['extra_field_length']; + if ($FilenameExtrafieldLength > 0) { + $ZIPlocalFileHeader .= $this->fread($FilenameExtrafieldLength); + + if ($LocalFileHeader['raw']['filename_length'] > 0) { + $LocalFileHeader['filename'] = substr($ZIPlocalFileHeader, 30, $LocalFileHeader['raw']['filename_length']); + } + if ($LocalFileHeader['raw']['extra_field_length'] > 0) { + $LocalFileHeader['raw']['extra_field_data'] = substr($ZIPlocalFileHeader, 30 + $LocalFileHeader['raw']['filename_length'], $LocalFileHeader['raw']['extra_field_length']); + } + } + + if ($LocalFileHeader['compressed_size'] == 0) { + // *Could* be a zero-byte file + // But could also be a file written on the fly that didn't know compressed filesize beforehand. + // Correct compressed filesize should be in the data_descriptor located after this file data, and also in Central Directory (at end of zip file) + if (!empty($this->getid3->info['zip']['central_directory'])) { + foreach ($this->getid3->info['zip']['central_directory'] as $central_directory_entry) { + if ($central_directory_entry['entry_offset'] == $LocalFileHeader['offset']) { + if ($central_directory_entry['compressed_size'] > 0) { + // overwrite local zero value (but not ['raw']'compressed_size']) so that seeking for data_descriptor (and next file entry) works correctly + $LocalFileHeader['compressed_size'] = $central_directory_entry['compressed_size']; + } + break; + } + } + } + + } + $LocalFileHeader['data_offset'] = $this->ftell(); + $this->fseek($LocalFileHeader['compressed_size'], SEEK_CUR); // this should (but may not) match value in $LocalFileHeader['raw']['compressed_size'] -- $LocalFileHeader['compressed_size'] could have been overwritten above with value from Central Directory + + if ($LocalFileHeader['flags']['data_descriptor_used']) { + $DataDescriptor = $this->fread(16); + $LocalFileHeader['data_descriptor']['signature'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 0, 4)); + if ($LocalFileHeader['data_descriptor']['signature'] != 0x08074B50) { // "PK\x07\x08" + $this->getid3->warning('invalid Local File Header Data Descriptor Signature at offset '.($this->ftell() - 16).' - expecting 08 07 4B 50, found '.getid3_lib::PrintHexBytes(substr($DataDescriptor, 0, 4))); + $this->fseek($LocalFileHeader['offset']); // seek back to where filepointer originally was so it can be handled properly + return false; + } + $LocalFileHeader['data_descriptor']['crc_32'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 4, 4)); + $LocalFileHeader['data_descriptor']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 8, 4)); + $LocalFileHeader['data_descriptor']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 12, 4)); + if (!$LocalFileHeader['raw']['compressed_size'] && $LocalFileHeader['data_descriptor']['compressed_size']) { + foreach ($this->getid3->info['zip']['central_directory'] as $central_directory_entry) { + if ($central_directory_entry['entry_offset'] == $LocalFileHeader['offset']) { + if ($LocalFileHeader['data_descriptor']['compressed_size'] == $central_directory_entry['compressed_size']) { + // $LocalFileHeader['compressed_size'] already set from Central Directory + } else { + $this->warning('conflicting compressed_size from data_descriptor ('.$LocalFileHeader['data_descriptor']['compressed_size'].') vs Central Directory ('.$central_directory_entry['compressed_size'].') for file at offset '.$LocalFileHeader['offset']); + } + + if ($LocalFileHeader['data_descriptor']['uncompressed_size'] == $central_directory_entry['uncompressed_size']) { + $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['data_descriptor']['uncompressed_size']; + } else { + $this->warning('conflicting uncompressed_size from data_descriptor ('.$LocalFileHeader['data_descriptor']['uncompressed_size'].') vs Central Directory ('.$central_directory_entry['uncompressed_size'].') for file at offset '.$LocalFileHeader['offset']); + } + break; + } + } + } + } + return $LocalFileHeader; + } + + /** + * @return array|false + */ + public function ZIPparseCentralDirectory() { + $CentralDirectory = array(); + $CentralDirectory['offset'] = $this->ftell(); + + $ZIPcentralDirectory = $this->fread(46); + + $CentralDirectory['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 0, 4)); + if ($CentralDirectory['raw']['signature'] != 0x02014B50) { + // invalid Central Directory Signature + $this->fseek($CentralDirectory['offset']); // seek back to where filepointer originally was so it can be handled properly + return false; + } + $CentralDirectory['raw']['create_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 4, 2)); + $CentralDirectory['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 6, 2)); + $CentralDirectory['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 8, 2)); + $CentralDirectory['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 10, 2)); + $CentralDirectory['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 12, 2)); + $CentralDirectory['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 14, 2)); + $CentralDirectory['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 16, 4)); + $CentralDirectory['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 20, 4)); + $CentralDirectory['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 24, 4)); + $CentralDirectory['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 28, 2)); + $CentralDirectory['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 30, 2)); + $CentralDirectory['raw']['file_comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 32, 2)); + $CentralDirectory['raw']['disk_number_start'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 34, 2)); + $CentralDirectory['raw']['internal_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 36, 2)); + $CentralDirectory['raw']['external_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 38, 4)); + $CentralDirectory['raw']['local_header_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 42, 4)); + + $CentralDirectory['entry_offset'] = $CentralDirectory['raw']['local_header_offset']; + $CentralDirectory['create_version'] = sprintf('%1.1f', $CentralDirectory['raw']['create_version'] / 10); + $CentralDirectory['extract_version'] = sprintf('%1.1f', $CentralDirectory['raw']['extract_version'] / 10); + $CentralDirectory['host_os'] = $this->ZIPversionOSLookup(($CentralDirectory['raw']['extract_version'] & 0xFF00) >> 8); + $CentralDirectory['compression_method'] = $this->ZIPcompressionMethodLookup($CentralDirectory['raw']['compression_method']); + $CentralDirectory['compressed_size'] = $CentralDirectory['raw']['compressed_size']; + $CentralDirectory['uncompressed_size'] = $CentralDirectory['raw']['uncompressed_size']; + $CentralDirectory['flags'] = $this->ZIPparseGeneralPurposeFlags($CentralDirectory['raw']['general_flags'], $CentralDirectory['raw']['compression_method']); + $CentralDirectory['last_modified_timestamp'] = $this->DOStime2UNIXtime($CentralDirectory['raw']['last_mod_file_date'], $CentralDirectory['raw']['last_mod_file_time']); + + $FilenameExtrafieldCommentLength = $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'] + $CentralDirectory['raw']['file_comment_length']; + if ($FilenameExtrafieldCommentLength > 0) { + $FilenameExtrafieldComment = $this->fread($FilenameExtrafieldCommentLength); + + if ($CentralDirectory['raw']['filename_length'] > 0) { + $CentralDirectory['filename'] = substr($FilenameExtrafieldComment, 0, $CentralDirectory['raw']['filename_length']); + } + if ($CentralDirectory['raw']['extra_field_length'] > 0) { + $CentralDirectory['raw']['extra_field_data'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'], $CentralDirectory['raw']['extra_field_length']); + } + if ($CentralDirectory['raw']['file_comment_length'] > 0) { + $CentralDirectory['file_comment'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'], $CentralDirectory['raw']['file_comment_length']); + } + } + + return $CentralDirectory; + } + + /** + * @return array|false + */ + public function ZIPparseEndOfCentralDirectory() { + $EndOfCentralDirectory = array(); + $EndOfCentralDirectory['offset'] = $this->ftell(); + + $ZIPendOfCentralDirectory = $this->fread(22); + + $EndOfCentralDirectory['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 0, 4)); + if ($EndOfCentralDirectory['signature'] != 0x06054B50) { + // invalid End Of Central Directory Signature + $this->fseek($EndOfCentralDirectory['offset']); // seek back to where filepointer originally was so it can be handled properly + return false; + } + $EndOfCentralDirectory['disk_number_current'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 4, 2)); + $EndOfCentralDirectory['disk_number_start_directory'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 6, 2)); + $EndOfCentralDirectory['directory_entries_this_disk'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 8, 2)); + $EndOfCentralDirectory['directory_entries_total'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 10, 2)); + $EndOfCentralDirectory['directory_size'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 12, 4)); + $EndOfCentralDirectory['directory_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 16, 4)); + $EndOfCentralDirectory['comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 20, 2)); + + if ($EndOfCentralDirectory['comment_length'] > 0) { + $EndOfCentralDirectory['comment'] = $this->fread($EndOfCentralDirectory['comment_length']); + } + + return $EndOfCentralDirectory; + } + + /** + * @param int $flagbytes + * @param int $compressionmethod + * + * @return array + */ + public static function ZIPparseGeneralPurposeFlags($flagbytes, $compressionmethod) { + // https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip-printable.html + $ParsedFlags = array(); + $ParsedFlags['encrypted'] = (bool) ($flagbytes & 0x0001); + // 0x0002 -- see below + // 0x0004 -- see below + $ParsedFlags['data_descriptor_used'] = (bool) ($flagbytes & 0x0008); + $ParsedFlags['enhanced_deflation'] = (bool) ($flagbytes & 0x0010); + $ParsedFlags['compressed_patched_data'] = (bool) ($flagbytes & 0x0020); + $ParsedFlags['strong_encryption'] = (bool) ($flagbytes & 0x0040); + // 0x0080 - unused + // 0x0100 - unused + // 0x0200 - unused + // 0x0400 - unused + $ParsedFlags['language_encoding'] = (bool) ($flagbytes & 0x0800); + // 0x1000 - reserved + $ParsedFlags['mask_header_values'] = (bool) ($flagbytes & 0x2000); + // 0x4000 - reserved + // 0x8000 - reserved + + switch ($compressionmethod) { + case 6: + $ParsedFlags['dictionary_size'] = (($flagbytes & 0x0002) ? 8192 : 4096); + $ParsedFlags['shannon_fano_trees'] = (($flagbytes & 0x0004) ? 3 : 2); + break; + + case 8: + case 9: + switch (($flagbytes & 0x0006) >> 1) { + case 0: + $ParsedFlags['compression_speed'] = 'normal'; + break; + case 1: + $ParsedFlags['compression_speed'] = 'maximum'; + break; + case 2: + $ParsedFlags['compression_speed'] = 'fast'; + break; + case 3: + $ParsedFlags['compression_speed'] = 'superfast'; + break; + } + break; + } + + return $ParsedFlags; + } + + /** + * @param int $index + * + * @return string + */ + public static function ZIPversionOSLookup($index) { + static $ZIPversionOSLookup = array( + 0 => 'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)', + 1 => 'Amiga', + 2 => 'OpenVMS', + 3 => 'Unix', + 4 => 'VM/CMS', + 5 => 'Atari ST', + 6 => 'OS/2 H.P.F.S.', + 7 => 'Macintosh', + 8 => 'Z-System', + 9 => 'CP/M', + 10 => 'Windows NTFS', + 11 => 'MVS', + 12 => 'VSE', + 13 => 'Acorn Risc', + 14 => 'VFAT', + 15 => 'Alternate MVS', + 16 => 'BeOS', + 17 => 'Tandem', + 18 => 'OS/400', + 19 => 'OS/X (Darwin)', + ); + + return (isset($ZIPversionOSLookup[$index]) ? $ZIPversionOSLookup[$index] : '[unknown]'); + } + + /** + * @param int $index + * + * @return string + */ + public static function ZIPcompressionMethodLookup($index) { + // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/ZIP.html + static $ZIPcompressionMethodLookup = array( + 0 => 'store', + 1 => 'shrink', + 2 => 'reduce-1', + 3 => 'reduce-2', + 4 => 'reduce-3', + 5 => 'reduce-4', + 6 => 'implode', + 7 => 'tokenize', + 8 => 'deflate', + 9 => 'deflate64', + 10 => 'Imploded (old IBM TERSE)', + 11 => 'RESERVED[11]', + 12 => 'BZIP2', + 13 => 'RESERVED[13]', + 14 => 'LZMA (EFS)', + 15 => 'RESERVED[15]', + 16 => 'RESERVED[16]', + 17 => 'RESERVED[17]', + 18 => 'IBM TERSE (new)', + 19 => 'IBM LZ77 z Architecture (PFS)', + 96 => 'JPEG recompressed', + 97 => 'WavPack compressed', + 98 => 'PPMd version I, Rev 1', + ); + + return (isset($ZIPcompressionMethodLookup[$index]) ? $ZIPcompressionMethodLookup[$index] : '[unknown]'); + } + + /** + * @param int $DOSdate + * @param int $DOStime + * + * @return int + */ + public static function DOStime2UNIXtime($DOSdate, $DOStime) { + // wFatDate + // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format: + // Bits Contents + // 0-4 Day of the month (1-31) + // 5-8 Month (1 = January, 2 = February, and so on) + // 9-15 Year offset from 1980 (add 1980 to get actual year) + + $UNIXday = ($DOSdate & 0x001F); + $UNIXmonth = (($DOSdate & 0x01E0) >> 5); + $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980; + + // wFatTime + // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format: + // Bits Contents + // 0-4 Second divided by 2 + // 5-10 Minute (0-59) + // 11-15 Hour (0-23 on a 24-hour clock) + + $UNIXsecond = ($DOStime & 0x001F) * 2; + $UNIXminute = (($DOStime & 0x07E0) >> 5); + $UNIXhour = (($DOStime & 0xF800) >> 11); + + return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear); + } + +} diff --git a/serendipity_event_podcast/player/getid3/module.audio-video.asf.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.asf.php similarity index 64% rename from serendipity_event_podcast/player/getid3/module.audio-video.asf.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.asf.php index ca9ace0e..e83de754 100644 --- a/serendipity_event_podcast/player/getid3/module.audio-video.asf.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.asf.php @@ -1,10 +1,10 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.audio-video.asf.php // @@ -13,26 +13,57 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); -$GUIDarray = getid3_asf::KnownGUIDs(); -foreach ($GUIDarray as $GUIDname => $hexstringvalue) { - // initialize all GUID constants - define($GUIDname, getid3_asf::GUIDtoBytestring($hexstringvalue)); -} - - - -class getid3_asf +class getid3_asf extends getid3_handler { + protected static $ASFIndexParametersObjectIndexSpecifiersIndexTypes = array( + 1 => 'Nearest Past Data Packet', + 2 => 'Nearest Past Media Object', + 3 => 'Nearest Past Cleanpoint' + ); - function getid3_asf(&$fd, &$ThisFileInfo) { + protected static $ASFMediaObjectIndexParametersObjectIndexSpecifiersIndexTypes = array( + 1 => 'Nearest Past Data Packet', + 2 => 'Nearest Past Media Object', + 3 => 'Nearest Past Cleanpoint', + 0xFF => 'Frame Number Offset' + ); + + protected static $ASFTimecodeIndexParametersObjectIndexSpecifiersIndexTypes = array( + 2 => 'Nearest Past Media Object', + 3 => 'Nearest Past Cleanpoint' + ); + + /** + * @param getID3 $getid3 + */ + public function __construct(getID3 $getid3) { + parent::__construct($getid3); // extends getid3_handler::__construct() + + // initialize all GUID constants + $GUIDarray = $this->KnownGUIDs(); + foreach ($GUIDarray as $GUIDname => $hexstringvalue) { + if (!defined($GUIDname)) { + define($GUIDname, $this->GUIDtoBytestring($hexstringvalue)); + } + } + } + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; // Shortcuts - $thisfile_audio = &$ThisFileInfo['audio']; - $thisfile_video = &$ThisFileInfo['video']; - $ThisFileInfo['asf'] = array(); - $thisfile_asf = &$ThisFileInfo['asf']; + $thisfile_audio = &$info['audio']; + $thisfile_video = &$info['video']; + $info['asf'] = array(); + $thisfile_asf = &$info['asf']; $thisfile_asf['comments'] = array(); $thisfile_asf_comments = &$thisfile_asf['comments']; $thisfile_asf['header_object'] = array(); @@ -59,30 +90,31 @@ class getid3_asf // Reserved1 BYTE 8 // hardcoded: 0x01 // Reserved2 BYTE 8 // hardcoded: 0x02 - $ThisFileInfo['fileformat'] = 'asf'; + $info['fileformat'] = 'asf'; - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $HeaderObjectData = fread($fd, 30); + $this->fseek($info['avdataoffset']); + $HeaderObjectData = $this->fread(30); $thisfile_asf_headerobject['objectid'] = substr($HeaderObjectData, 0, 16); $thisfile_asf_headerobject['objectid_guid'] = $this->BytestringToGUID($thisfile_asf_headerobject['objectid']); if ($thisfile_asf_headerobject['objectid'] != GETID3_ASF_Header_Object) { - $ThisFileInfo['warning'][] = 'ASF header GUID {'.$this->BytestringToGUID($thisfile_asf_headerobject['objectid']).'} does not match expected "GETID3_ASF_Header_Object" GUID {'.$this->BytestringToGUID(GETID3_ASF_Header_Object).'}'; - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['asf']); - return false; - break; + unset($info['fileformat'], $info['asf']); + return $this->error('ASF header GUID {'.$this->BytestringToGUID($thisfile_asf_headerobject['objectid']).'} does not match expected "GETID3_ASF_Header_Object" GUID {'.$this->BytestringToGUID(GETID3_ASF_Header_Object).'}'); } $thisfile_asf_headerobject['objectsize'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 16, 8)); $thisfile_asf_headerobject['headerobjects'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 24, 4)); $thisfile_asf_headerobject['reserved1'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 28, 1)); $thisfile_asf_headerobject['reserved2'] = getid3_lib::LittleEndian2Int(substr($HeaderObjectData, 29, 1)); - $ASFHeaderData = fread($fd, $thisfile_asf_headerobject['objectsize'] - 30); + $NextObjectOffset = $this->ftell(); + $ASFHeaderData = $this->fread($thisfile_asf_headerobject['objectsize'] - 30); $offset = 0; + $thisfile_asf_streambitratepropertiesobject = array(); + $thisfile_asf_codeclistobject = array(); + $StreamPropertiesObjectData = array(); for ($HeaderObjectsCounter = 0; $HeaderObjectsCounter < $thisfile_asf_headerobject['headerobjects']; $HeaderObjectsCounter++) { - $NextObjectGUID = substr($ASFHeaderData, $offset, 16); + $NextObjectGUID = substr($ASFHeaderData, $offset, 16); $offset += 16; $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID); $NextObjectSize = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8)); @@ -113,6 +145,7 @@ class getid3_asf $thisfile_asf['file_properties_object'] = array(); $thisfile_asf_filepropertiesobject = &$thisfile_asf['file_properties_object']; + $thisfile_asf_filepropertiesobject['offset'] = $NextObjectOffset + $offset; $thisfile_asf_filepropertiesobject['objectid'] = $NextObjectGUID; $thisfile_asf_filepropertiesobject['objectid_guid'] = $NextObjectGUIDtext; $thisfile_asf_filepropertiesobject['objectsize'] = $NextObjectSize; @@ -157,10 +190,10 @@ class getid3_asf } else { // broadcast flag NOT set, perform calculations - $ThisFileInfo['playtime_seconds'] = ($thisfile_asf_filepropertiesobject['play_duration'] / 10000000) - ($thisfile_asf_filepropertiesobject['preroll'] / 1000); + $info['playtime_seconds'] = ($thisfile_asf_filepropertiesobject['play_duration'] / 10000000) - ($thisfile_asf_filepropertiesobject['preroll'] / 1000); - //$ThisFileInfo['bitrate'] = $thisfile_asf_filepropertiesobject['max_bitrate']; - $ThisFileInfo['bitrate'] = ((isset($thisfile_asf_filepropertiesobject['filesize']) ? $thisfile_asf_filepropertiesobject['filesize'] : $ThisFileInfo['filesize']) * 8) / $ThisFileInfo['playtime_seconds']; + //$info['bitrate'] = $thisfile_asf_filepropertiesobject['max_bitrate']; + $info['bitrate'] = ((isset($thisfile_asf_filepropertiesobject['filesize']) ? $thisfile_asf_filepropertiesobject['filesize'] : $info['filesize']) * 8) / $info['playtime_seconds']; } break; @@ -186,6 +219,7 @@ class getid3_asf // stream number isn't known until halfway through decoding the structure, hence it // it is decoded to a temporary variable and then stuck in the appropriate index later + $StreamPropertiesObjectData['offset'] = $NextObjectOffset + $offset; $StreamPropertiesObjectData['objectid'] = $NextObjectGUID; $StreamPropertiesObjectData['objectid_guid'] = $NextObjectGUIDtext; $StreamPropertiesObjectData['objectsize'] = $NextObjectSize; @@ -218,7 +252,7 @@ class getid3_asf $thisfile_audio['dataformat'] = (!empty($thisfile_audio['dataformat']) ? $thisfile_audio['dataformat'] : 'asf'); $thisfile_audio['bitrate_mode'] = (!empty($thisfile_audio['bitrate_mode']) ? $thisfile_audio['bitrate_mode'] : 'cbr'); - $audiodata = getid3_riff::RIFFparseWAVEFORMATex(substr($StreamPropertiesObjectData['type_specific_data'], 0, 16)); + $audiodata = getid3_riff::parseWAVEFORMATex(substr($StreamPropertiesObjectData['type_specific_data'], 0, 16)); unset($audiodata['raw']); $thisfile_audio = getid3_lib::array_merge_noclobber($audiodata, $thisfile_audio); break; @@ -253,6 +287,7 @@ class getid3_asf $thisfile_asf['header_extension_object'] = array(); $thisfile_asf_headerextensionobject = &$thisfile_asf['header_extension_object']; + $thisfile_asf_headerextensionobject['offset'] = $NextObjectOffset + $offset; $thisfile_asf_headerextensionobject['objectid'] = $NextObjectGUID; $thisfile_asf_headerextensionobject['objectid_guid'] = $NextObjectGUIDtext; $thisfile_asf_headerextensionobject['objectsize'] = $NextObjectSize; @@ -260,20 +295,25 @@ class getid3_asf $offset += 16; $thisfile_asf_headerextensionobject['reserved_1_guid'] = $this->BytestringToGUID($thisfile_asf_headerextensionobject['reserved_1']); if ($thisfile_asf_headerextensionobject['reserved_1'] != GETID3_ASF_Reserved_1) { - $ThisFileInfo['warning'][] = 'header_extension_object.reserved_1 GUID ('.$this->BytestringToGUID($thisfile_asf_headerextensionobject['reserved_1']).') does not match expected "GETID3_ASF_Reserved_1" GUID ('.$this->BytestringToGUID(GETID3_ASF_Reserved_1).')'; + $this->warning('header_extension_object.reserved_1 GUID ('.$this->BytestringToGUID($thisfile_asf_headerextensionobject['reserved_1']).') does not match expected "GETID3_ASF_Reserved_1" GUID ('.$this->BytestringToGUID(GETID3_ASF_Reserved_1).')'); //return false; break; } $thisfile_asf_headerextensionobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); $offset += 2; if ($thisfile_asf_headerextensionobject['reserved_2'] != 6) { - $ThisFileInfo['warning'][] = 'header_extension_object.reserved_2 ('.getid3_lib::PrintHexBytes($thisfile_asf_headerextensionobject['reserved_2']).') does not match expected value of "6"'; + $this->warning('header_extension_object.reserved_2 ('.$thisfile_asf_headerextensionobject['reserved_2'].') does not match expected value of "6"'); //return false; break; } $thisfile_asf_headerextensionobject['extension_data_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); $offset += 4; $thisfile_asf_headerextensionobject['extension_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_headerextensionobject['extension_data_size']); + $unhandled_sections = 0; + $thisfile_asf_headerextensionobject['extension_data_parsed'] = $this->HeaderExtensionObjectDataParse($thisfile_asf_headerextensionobject['extension_data'], $unhandled_sections); + if ($unhandled_sections === 0) { + unset($thisfile_asf_headerextensionobject['extension_data']); + } $offset += $thisfile_asf_headerextensionobject['extension_data_size']; break; @@ -295,8 +335,10 @@ class getid3_asf // shortcut $thisfile_asf['codec_list_object'] = array(); + /** @var mixed[] $thisfile_asf_codeclistobject */ $thisfile_asf_codeclistobject = &$thisfile_asf['codec_list_object']; + $thisfile_asf_codeclistobject['offset'] = $NextObjectOffset + $offset; $thisfile_asf_codeclistobject['objectid'] = $NextObjectGUID; $thisfile_asf_codeclistobject['objectid_guid'] = $NextObjectGUIDtext; $thisfile_asf_codeclistobject['objectsize'] = $NextObjectSize; @@ -304,11 +346,14 @@ class getid3_asf $offset += 16; $thisfile_asf_codeclistobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_codeclistobject['reserved']); if ($thisfile_asf_codeclistobject['reserved'] != $this->GUIDtoBytestring('86D15241-311D-11D0-A3A4-00A0C90348F6')) { - $ThisFileInfo['warning'][] = 'codec_list_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_codeclistobject['reserved']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {86D15241-311D-11D0-A3A4-00A0C90348F6}'; + $this->warning('codec_list_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_codeclistobject['reserved']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {86D15241-311D-11D0-A3A4-00A0C90348F6}'); //return false; break; } $thisfile_asf_codeclistobject['codec_entries_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); + if ($thisfile_asf_codeclistobject['codec_entries_count'] > 0) { + $thisfile_asf_codeclistobject['codec_entries'] = array(); + } $offset += 4; for ($CodecEntryCounter = 0; $CodecEntryCounter < $thisfile_asf_codeclistobject['codec_entries_count']; $CodecEntryCounter++) { // shortcut @@ -317,7 +362,7 @@ class getid3_asf $thisfile_asf_codeclistobject_codecentries_current['type_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); $offset += 2; - $thisfile_asf_codeclistobject_codecentries_current['type'] = $this->ASFCodecListObjectTypeLookup($thisfile_asf_codeclistobject_codecentries_current['type_raw']); + $thisfile_asf_codeclistobject_codecentries_current['type'] = self::codecListObjectTypeLookup($thisfile_asf_codeclistobject_codecentries_current['type_raw']); $CodecNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character $offset += 2; @@ -337,19 +382,19 @@ class getid3_asf if ($thisfile_asf_codeclistobject_codecentries_current['type_raw'] == 2) { // audio codec if (strpos($thisfile_asf_codeclistobject_codecentries_current['description'], ',') === false) { - $ThisFileInfo['warning'][] = '[asf][codec_list_object][codec_entries]['.$CodecEntryCounter.'][description] expected to contain comma-seperated list of parameters: "'.$thisfile_asf_codeclistobject_codecentries_current['description'].'"'; + $this->warning('[asf][codec_list_object][codec_entries]['.$CodecEntryCounter.'][description] expected to contain comma-separated list of parameters: "'.$thisfile_asf_codeclistobject_codecentries_current['description'].'"'); } else { list($AudioCodecBitrate, $AudioCodecFrequency, $AudioCodecChannels) = explode(',', $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description'])); $thisfile_audio['codec'] = $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['name']); if (!isset($thisfile_audio['bitrate']) && strstr($AudioCodecBitrate, 'kbps')) { - $thisfile_audio['bitrate'] = (int) (trim(str_replace('kbps', '', $AudioCodecBitrate)) * 1000); + $thisfile_audio['bitrate'] = (int) trim(str_replace('kbps', '', $AudioCodecBitrate)) * 1000; } //if (!isset($thisfile_video['bitrate']) && isset($thisfile_audio['bitrate']) && isset($thisfile_asf['file_properties_object']['max_bitrate']) && ($thisfile_asf_codeclistobject['codec_entries_count'] > 1)) { - if (empty($thisfile_video['bitrate']) && !empty($thisfile_audio['bitrate']) && !empty($ThisFileInfo['bitrate'])) { + if (empty($thisfile_video['bitrate']) && !empty($thisfile_audio['bitrate']) && !empty($info['bitrate'])) { //$thisfile_video['bitrate'] = $thisfile_asf['file_properties_object']['max_bitrate'] - $thisfile_audio['bitrate']; - $thisfile_video['bitrate'] = $ThisFileInfo['bitrate'] - $thisfile_audio['bitrate']; + $thisfile_video['bitrate'] = $info['bitrate'] - $thisfile_audio['bitrate']; } $AudioCodecFrequency = (int) trim(str_replace('kHz', '', $AudioCodecFrequency)); @@ -400,7 +445,7 @@ class getid3_asf break; default: - $ThisFileInfo['warning'][] = 'unknown frequency: "'.$AudioCodecFrequency.'" ('.$this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description']).')'; + $this->warning('unknown frequency: "'.$AudioCodecFrequency.'" ('.$this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description']).')'); break; } @@ -438,6 +483,7 @@ class getid3_asf $thisfile_asf['script_command_object'] = array(); $thisfile_asf_scriptcommandobject = &$thisfile_asf['script_command_object']; + $thisfile_asf_scriptcommandobject['offset'] = $NextObjectOffset + $offset; $thisfile_asf_scriptcommandobject['objectid'] = $NextObjectGUID; $thisfile_asf_scriptcommandobject['objectid_guid'] = $NextObjectGUIDtext; $thisfile_asf_scriptcommandobject['objectsize'] = $NextObjectSize; @@ -445,7 +491,7 @@ class getid3_asf $offset += 16; $thisfile_asf_scriptcommandobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_scriptcommandobject['reserved']); if ($thisfile_asf_scriptcommandobject['reserved'] != $this->GUIDtoBytestring('4B1ACBE3-100B-11D0-A39B-00A0C90348F6')) { - $ThisFileInfo['warning'][] = 'script_command_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_scriptcommandobject['reserved']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {4B1ACBE3-100B-11D0-A39B-00A0C90348F6}'; + $this->warning('script_command_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_scriptcommandobject['reserved']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {4B1ACBE3-100B-11D0-A39B-00A0C90348F6}'); //return false; break; } @@ -496,6 +542,7 @@ class getid3_asf $thisfile_asf['marker_object'] = array(); $thisfile_asf_markerobject = &$thisfile_asf['marker_object']; + $thisfile_asf_markerobject['offset'] = $NextObjectOffset + $offset; $thisfile_asf_markerobject['objectid'] = $NextObjectGUID; $thisfile_asf_markerobject['objectid_guid'] = $NextObjectGUIDtext; $thisfile_asf_markerobject['objectsize'] = $NextObjectSize; @@ -503,7 +550,7 @@ class getid3_asf $offset += 16; $thisfile_asf_markerobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_markerobject['reserved']); if ($thisfile_asf_markerobject['reserved'] != $this->GUIDtoBytestring('4CFEDB20-75F6-11CF-9C0F-00A0C90349CB')) { - $ThisFileInfo['warning'][] = 'marker_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_markerobject['reserved_1']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {4CFEDB20-75F6-11CF-9C0F-00A0C90349CB}'; + $this->warning('marker_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_markerobject['reserved']).'} does not match expected "GETID3_ASF_Reserved_1" GUID {4CFEDB20-75F6-11CF-9C0F-00A0C90349CB}'); break; } $thisfile_asf_markerobject['markers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4)); @@ -511,7 +558,7 @@ class getid3_asf $thisfile_asf_markerobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); $offset += 2; if ($thisfile_asf_markerobject['reserved_2'] != 0) { - $ThisFileInfo['warning'][] = 'marker_object.reserved_2 ('.getid3_lib::PrintHexBytes($thisfile_asf_markerobject['reserved_2']).') does not match expected value of "0"'; + $this->warning('marker_object.reserved_2 ('.$thisfile_asf_markerobject['reserved_2'].') does not match expected value of "0"'); break; } $thisfile_asf_markerobject['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); @@ -554,6 +601,7 @@ class getid3_asf $thisfile_asf['bitrate_mutual_exclusion_object'] = array(); $thisfile_asf_bitratemutualexclusionobject = &$thisfile_asf['bitrate_mutual_exclusion_object']; + $thisfile_asf_bitratemutualexclusionobject['offset'] = $NextObjectOffset + $offset; $thisfile_asf_bitratemutualexclusionobject['objectid'] = $NextObjectGUID; $thisfile_asf_bitratemutualexclusionobject['objectid_guid'] = $NextObjectGUIDtext; $thisfile_asf_bitratemutualexclusionobject['objectsize'] = $NextObjectSize; @@ -561,7 +609,7 @@ class getid3_asf $thisfile_asf_bitratemutualexclusionobject['reserved_guid'] = $this->BytestringToGUID($thisfile_asf_bitratemutualexclusionobject['reserved']); $offset += 16; if (($thisfile_asf_bitratemutualexclusionobject['reserved'] != GETID3_ASF_Mutex_Bitrate) && ($thisfile_asf_bitratemutualexclusionobject['reserved'] != GETID3_ASF_Mutex_Unknown)) { - $ThisFileInfo['warning'][] = 'bitrate_mutual_exclusion_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_bitratemutualexclusionobject['reserved']).'} does not match expected "GETID3_ASF_Mutex_Bitrate" GUID {'.$this->BytestringToGUID(GETID3_ASF_Mutex_Bitrate).'} or "GETID3_ASF_Mutex_Unknown" GUID {'.$this->BytestringToGUID(GETID3_ASF_Mutex_Unknown).'}'; + $this->warning('bitrate_mutual_exclusion_object.reserved GUID {'.$this->BytestringToGUID($thisfile_asf_bitratemutualexclusionobject['reserved']).'} does not match expected "GETID3_ASF_Mutex_Bitrate" GUID {'.$this->BytestringToGUID(GETID3_ASF_Mutex_Bitrate).'} or "GETID3_ASF_Mutex_Unknown" GUID {'.$this->BytestringToGUID(GETID3_ASF_Mutex_Unknown).'}'); //return false; break; } @@ -586,6 +634,7 @@ class getid3_asf $thisfile_asf['error_correction_object'] = array(); $thisfile_asf_errorcorrectionobject = &$thisfile_asf['error_correction_object']; + $thisfile_asf_errorcorrectionobject['offset'] = $NextObjectOffset + $offset; $thisfile_asf_errorcorrectionobject['objectid'] = $NextObjectGUID; $thisfile_asf_errorcorrectionobject['objectid_guid'] = $NextObjectGUIDtext; $thisfile_asf_errorcorrectionobject['objectsize'] = $NextObjectSize; @@ -621,7 +670,7 @@ class getid3_asf break; default: - $ThisFileInfo['warning'][] = 'error_correction_object.error_correction_type GUID {'.$this->BytestringToGUID($thisfile_asf_errorcorrectionobject['reserved']).'} does not match expected "GETID3_ASF_No_Error_Correction" GUID {'.$this->BytestringToGUID(GETID3_ASF_No_Error_Correction).'} or "GETID3_ASF_Audio_Spread" GUID {'.$this->BytestringToGUID(GETID3_ASF_Audio_Spread).'}'; + $this->warning('error_correction_object.error_correction_type GUID {'.$this->BytestringToGUID($thisfile_asf_errorcorrectionobject['error_correction_type']).'} does not match expected "GETID3_ASF_No_Error_Correction" GUID {'.$this->BytestringToGUID(GETID3_ASF_No_Error_Correction).'} or "GETID3_ASF_Audio_Spread" GUID {'.$this->BytestringToGUID(GETID3_ASF_Audio_Spread).'}'); //return false; break; } @@ -648,6 +697,7 @@ class getid3_asf $thisfile_asf['content_description_object'] = array(); $thisfile_asf_contentdescriptionobject = &$thisfile_asf['content_description_object']; + $thisfile_asf_contentdescriptionobject['offset'] = $NextObjectOffset + $offset; $thisfile_asf_contentdescriptionobject['objectid'] = $NextObjectGUID; $thisfile_asf_contentdescriptionobject['objectid_guid'] = $NextObjectGUIDtext; $thisfile_asf_contentdescriptionobject['objectsize'] = $NextObjectSize; @@ -703,6 +753,7 @@ class getid3_asf $thisfile_asf['extended_content_description_object'] = array(); $thisfile_asf_extendedcontentdescriptionobject = &$thisfile_asf['extended_content_description_object']; + $thisfile_asf_extendedcontentdescriptionobject['offset'] = $NextObjectOffset + $offset; $thisfile_asf_extendedcontentdescriptionobject['objectid'] = $NextObjectGUID; $thisfile_asf_extendedcontentdescriptionobject['objectid_guid'] = $NextObjectGUIDtext; $thisfile_asf_extendedcontentdescriptionobject['objectsize'] = $NextObjectSize; @@ -711,7 +762,7 @@ class getid3_asf for ($ExtendedContentDescriptorsCounter = 0; $ExtendedContentDescriptorsCounter < $thisfile_asf_extendedcontentdescriptionobject['content_descriptors_count']; $ExtendedContentDescriptorsCounter++) { // shortcut $thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter] = array(); - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current = &$thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter]; + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current = &$thisfile_asf_extendedcontentdescriptionobject['content_descriptors'][$ExtendedContentDescriptorsCounter]; $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['base_offset'] = $offset + 30; $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)); @@ -743,7 +794,7 @@ class getid3_asf break; default: - $ThisFileInfo['warning'][] = 'extended_content_description.content_descriptors.'.$ExtendedContentDescriptorsCounter.'.value_type is invalid ('.$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'].')'; + $this->warning('extended_content_description.content_descriptors.'.$ExtendedContentDescriptorsCounter.'.value_type is invalid ('.$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'].')'); //return false; break; } @@ -772,17 +823,17 @@ class getid3_asf case 'wm/tracknumber': case 'tracknumber': // be careful casting to int: casting unicode strings to int gives unexpected results (stops parsing at first non-numeric character) - $thisfile_asf_comments['track'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])); - foreach ($thisfile_asf_comments['track'] as $key => $value) { + $thisfile_asf_comments['track_number'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])); + foreach ($thisfile_asf_comments['track_number'] as $key => $value) { if (preg_match('/^[0-9\x00]+$/', $value)) { - $thisfile_asf_comments['track'][$key] = intval(str_replace("\x00", '', $value)); + $thisfile_asf_comments['track_number'][$key] = intval(str_replace("\x00", '', $value)); } } break; case 'wm/track': - if (empty($thisfile_asf_comments['track'])) { - $thisfile_asf_comments['track'] = array(1 + $this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])); + if (empty($thisfile_asf_comments['track_number'])) { + $thisfile_asf_comments['track_number'] = array(1 + (int) $this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'])); } break; @@ -805,22 +856,14 @@ class getid3_asf break; case 'id3': - // id3v2 module might not be loaded - if (class_exists('getid3_id3v2')) { - $tempfile = tempnam(GETID3_TEMP_DIR, 'getID3'); - $tempfilehandle = fopen($tempfile, "wb"); - $tempThisfileInfo = array('encoding'=>$ThisFileInfo['encoding']); - fwrite($tempfilehandle, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); - fclose($tempfilehandle); + $this->getid3->include_module('tag.id3v2'); - $tempfilehandle = fopen($tempfile, "rb"); - $id3 = new getid3_id3v2($tempfilehandle, $tempThisfileInfo); - unset($id3); - fclose($tempfilehandle); - unlink($tempfile); + $getid3_id3v2 = new getid3_id3v2($this->getid3); + $getid3_id3v2->AnalyzeString($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); + unset($getid3_id3v2); - $ThisFileInfo['id3v2'] = $tempThisfileInfo['id3v2']; - unset($tempThisfileInfo); + if ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'] > 1024) { + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = ''; } break; @@ -830,18 +873,16 @@ class getid3_asf break; case 'wm/picture': - //typedef struct _WMPicture{ - // LPWSTR pwszMIMEType; - // BYTE bPictureType; - // LPWSTR pwszDescription; - // DWORD dwDataLen; - // BYTE* pbData; - //} WM_PICTURE; - + $WMpicture = $this->ASF_WMpicture($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']); + foreach ($WMpicture as $key => $value) { + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current[$key] = $value; + } + unset($WMpicture); +/* $wm_picture_offset = 0; $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 1)); $wm_picture_offset += 1; - $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type'] = $this->WMpictureTypeLookup($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id']); + $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type'] = self::WMpictureTypeLookup($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_type_id']); $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 4)); $wm_picture_offset += 4; @@ -873,7 +914,8 @@ class getid3_asf if (!isset($thisfile_asf_comments['picture'])) { $thisfile_asf_comments['picture'] = array(); } - $thisfile_asf_comments['picture'][] = array('data'=>$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'], 'mime_type'=>$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime']); + $thisfile_asf_comments['picture'][] = array('data'=>$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'], 'image_mime'=>$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime']); +*/ break; default: @@ -909,6 +951,7 @@ class getid3_asf $thisfile_asf['stream_bitrate_properties_object'] = array(); $thisfile_asf_streambitratepropertiesobject = &$thisfile_asf['stream_bitrate_properties_object']; + $thisfile_asf_streambitratepropertiesobject['offset'] = $NextObjectOffset + $offset; $thisfile_asf_streambitratepropertiesobject['objectid'] = $NextObjectGUID; $thisfile_asf_streambitratepropertiesobject['objectid_guid'] = $NextObjectGUIDtext; $thisfile_asf_streambitratepropertiesobject['objectsize'] = $NextObjectSize; @@ -934,6 +977,7 @@ class getid3_asf $thisfile_asf['padding_object'] = array(); $thisfile_asf_paddingobject = &$thisfile_asf['padding_object']; + $thisfile_asf_paddingobject['offset'] = $NextObjectOffset + $offset; $thisfile_asf_paddingobject['objectid'] = $NextObjectGUID; $thisfile_asf_paddingobject['objectid_guid'] = $NextObjectGUIDtext; $thisfile_asf_paddingobject['objectsize'] = $NextObjectSize; @@ -951,26 +995,26 @@ class getid3_asf default: // Implementations shall ignore any standard or non-standard object that they do not know how to handle. if ($this->GUIDname($NextObjectGUIDtext)) { - $ThisFileInfo['warning'][] = 'unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8); + $this->warning('unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8)); } else { - $ThisFileInfo['warning'][] = 'unknown GUID {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8); + $this->warning('unknown GUID {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8)); } $offset += ($NextObjectSize - 16 - 8); break; } } - if (isset($thisfile_asf_streambitrateproperties['bitrate_records_count'])) { + if (isset($thisfile_asf_streambitratepropertiesobject['bitrate_records_count'])) { $ASFbitrateAudio = 0; $ASFbitrateVideo = 0; - for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitrateproperties['bitrate_records_count']; $BitrateRecordsCounter++) { + for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitratepropertiesobject['bitrate_records_count']; $BitrateRecordsCounter++) { if (isset($thisfile_asf_codeclistobject['codec_entries'][$BitrateRecordsCounter])) { switch ($thisfile_asf_codeclistobject['codec_entries'][$BitrateRecordsCounter]['type_raw']) { case 1: - $ASFbitrateVideo += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate']; + $ASFbitrateVideo += $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['bitrate']; break; case 2: - $ASFbitrateAudio += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate']; + $ASFbitrateAudio += $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['bitrate']; break; default: @@ -1011,7 +1055,7 @@ class getid3_asf $audiomediaoffset = 0; - $thisfile_asf_audiomedia_currentstream = getid3_riff::RIFFparseWAVEFORMATex(substr($streamdata['type_specific_data'], $audiomediaoffset, 16)); + $thisfile_asf_audiomedia_currentstream = getid3_riff::parseWAVEFORMATex(substr($streamdata['type_specific_data'], $audiomediaoffset, 16)); $audiomediaoffset += 16; $thisfile_audio['lossless'] = false; @@ -1119,7 +1163,7 @@ class getid3_asf } } - $thisfile_asf_videomedia_currentstream['format_data']['codec'] = getid3_riff::RIFFfourccLookup($thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc']); + $thisfile_asf_videomedia_currentstream['format_data']['codec'] = getid3_riff::fourccLookup($thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc']); $thisfile_video['streams'][$streamnumber]['fourcc'] = $thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc']; $thisfile_video['streams'][$streamnumber]['codec'] = $thisfile_asf_videomedia_currentstream['format_data']['codec']; @@ -1134,8 +1178,8 @@ class getid3_asf } } - while (ftell($fd) < $ThisFileInfo['avdataend']) { - $NextObjectDataHeader = fread($fd, 24); + while ($this->ftell() < $info['avdataend']) { + $NextObjectDataHeader = $this->fread(24); $offset = 0; $NextObjectGUID = substr($NextObjectDataHeader, 0, 16); $offset += 16; @@ -1157,7 +1201,7 @@ class getid3_asf $thisfile_asf['data_object'] = array(); $thisfile_asf_dataobject = &$thisfile_asf['data_object']; - $DataObjectData = $NextObjectDataHeader.fread($fd, 50 - 24); + $DataObjectData = $NextObjectDataHeader.$this->fread(50 - 24); $offset = 24; $thisfile_asf_dataobject['objectid'] = $NextObjectGUID; @@ -1172,7 +1216,7 @@ class getid3_asf $thisfile_asf_dataobject['reserved'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 2)); $offset += 2; if ($thisfile_asf_dataobject['reserved'] != 0x0101) { - $ThisFileInfo['warning'][] = 'data_object.reserved ('.getid3_lib::PrintHexBytes($thisfile_asf_dataobject['reserved']).') does not match expected value of "0x0101"'; + $this->warning('data_object.reserved (0x'.sprintf('%04X', $thisfile_asf_dataobject['reserved']).') does not match expected value of "0x0101"'); //return false; break; } @@ -1185,9 +1229,9 @@ class getid3_asf // * * Error Correction Present bits 1 // If set, use Opaque Data Packet structure, else use Payload structure // * Error Correction Data - $ThisFileInfo['avdataoffset'] = ftell($fd); - fseek($fd, ($thisfile_asf_dataobject['objectsize'] - 50), SEEK_CUR); // skip actual audio/video data - $ThisFileInfo['avdataend'] = ftell($fd); + $info['avdataoffset'] = $this->ftell(); + $this->fseek(($thisfile_asf_dataobject['objectsize'] - 50), SEEK_CUR); // skip actual audio/video data + $info['avdataend'] = $this->ftell(); break; case GETID3_ASF_Simple_Index_Object: @@ -1207,7 +1251,7 @@ class getid3_asf $thisfile_asf['simple_index_object'] = array(); $thisfile_asf_simpleindexobject = &$thisfile_asf['simple_index_object']; - $SimpleIndexObjectData = $NextObjectDataHeader.fread($fd, 56 - 24); + $SimpleIndexObjectData = $NextObjectDataHeader.$this->fread(56 - 24); $offset = 24; $thisfile_asf_simpleindexobject['objectid'] = $NextObjectGUID; @@ -1224,7 +1268,7 @@ class getid3_asf $thisfile_asf_simpleindexobject['index_entries_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4)); $offset += 4; - $IndexEntriesData = $SimpleIndexObjectData.fread($fd, 6 * $thisfile_asf_simpleindexobject['index_entries_count']); + $IndexEntriesData = $SimpleIndexObjectData.$this->fread(6 * $thisfile_asf_simpleindexobject['index_entries_count']); for ($IndexEntriesCounter = 0; $IndexEntriesCounter < $thisfile_asf_simpleindexobject['index_entries_count']; $IndexEntriesCounter++) { $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_number'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4)); $offset += 4; @@ -1261,7 +1305,7 @@ class getid3_asf $thisfile_asf['asf_index_object'] = array(); $thisfile_asf_asfindexobject = &$thisfile_asf['asf_index_object']; - $ASFIndexObjectData = $NextObjectDataHeader.fread($fd, 34 - 24); + $ASFIndexObjectData = $NextObjectDataHeader.$this->fread(34 - 24); $offset = 24; $thisfile_asf_asfindexobject['objectid'] = $NextObjectGUID; @@ -1275,7 +1319,7 @@ class getid3_asf $thisfile_asf_asfindexobject['index_blocks_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4)); $offset += 4; - $ASFIndexObjectData .= fread($fd, 4 * $thisfile_asf_asfindexobject['index_specifiers_count']); + $ASFIndexObjectData .= $this->fread(4 * $thisfile_asf_asfindexobject['index_specifiers_count']); for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) { $IndexSpecifierStreamNumber = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2)); $offset += 2; @@ -1285,17 +1329,17 @@ class getid3_asf $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type_text'] = $this->ASFIndexObjectIndexTypeLookup($thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type']); } - $ASFIndexObjectData .= fread($fd, 4); + $ASFIndexObjectData .= $this->fread(4); $thisfile_asf_asfindexobject['index_entry_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4)); $offset += 4; - $ASFIndexObjectData .= fread($fd, 8 * $thisfile_asf_asfindexobject['index_specifiers_count']); + $ASFIndexObjectData .= $this->fread(8 * $thisfile_asf_asfindexobject['index_specifiers_count']); for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) { $thisfile_asf_asfindexobject['block_positions'][$IndexSpecifiersCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 8)); $offset += 8; } - $ASFIndexObjectData .= fread($fd, 4 * $thisfile_asf_asfindexobject['index_specifiers_count'] * $thisfile_asf_asfindexobject['index_entry_count']); + $ASFIndexObjectData .= $this->fread(4 * $thisfile_asf_asfindexobject['index_specifiers_count'] * $thisfile_asf_asfindexobject['index_entry_count']); for ($IndexEntryCounter = 0; $IndexEntryCounter < $thisfile_asf_asfindexobject['index_entry_count']; $IndexEntryCounter++) { for ($IndexSpecifiersCounter = 0; $IndexSpecifiersCounter < $thisfile_asf_asfindexobject['index_specifiers_count']; $IndexSpecifiersCounter++) { $thisfile_asf_asfindexobject['offsets'][$IndexSpecifiersCounter][$IndexEntryCounter] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4)); @@ -1308,11 +1352,11 @@ class getid3_asf default: // Implementations shall ignore any standard or non-standard object that they do not know how to handle. if ($this->GUIDname($NextObjectGUIDtext)) { - $ThisFileInfo['warning'][] = 'unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF body at offset '.($offset - 16 - 8); + $this->warning('unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF body at offset '.($offset - 16 - 8)); } else { - $ThisFileInfo['warning'][] = 'unknown GUID {'.$NextObjectGUIDtext.'} in ASF body at offset '.(ftell($fd) - 16 - 8); + $this->warning('unknown GUID {'.$NextObjectGUIDtext.'} in ASF body at offset '.($this->ftell() - 16 - 8)); } - fseek($fd, ($NextObjectSize - 16 - 8), SEEK_CUR); + $this->fseek(($NextObjectSize - 16 - 8), SEEK_CUR); break; } } @@ -1330,7 +1374,7 @@ class getid3_asf case 'WMVP': case 'WVP2': $thisfile_video['dataformat'] = 'wmv'; - $ThisFileInfo['mime_type'] = 'video/x-ms-wmv'; + $info['mime_type'] = 'video/x-ms-wmv'; break; case 'MP42': @@ -1338,7 +1382,7 @@ class getid3_asf case 'MP4S': case 'mp4s': $thisfile_video['dataformat'] = 'asf'; - $ThisFileInfo['mime_type'] = 'video/x-ms-asf'; + $info['mime_type'] = 'video/x-ms-asf'; break; default: @@ -1346,8 +1390,8 @@ class getid3_asf case 1: if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) { $thisfile_video['dataformat'] = 'wmv'; - if ($ThisFileInfo['mime_type'] == 'video/x-ms-asf') { - $ThisFileInfo['mime_type'] = 'video/x-ms-wmv'; + if ($info['mime_type'] == 'video/x-ms-asf') { + $info['mime_type'] = 'video/x-ms-wmv'; } } break; @@ -1355,8 +1399,8 @@ class getid3_asf case 2: if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) { $thisfile_audio['dataformat'] = 'wma'; - if ($ThisFileInfo['mime_type'] == 'video/x-ms-asf') { - $ThisFileInfo['mime_type'] = 'audio/x-ms-wma'; + if ($info['mime_type'] == 'video/x-ms-asf') { + $info['mime_type'] = 'audio/x-ms-wma'; } } break; @@ -1394,14 +1438,14 @@ class getid3_asf break; default: - $ThisFileInfo['warning'][] = 'Unknown streamtype: [codec_list_object][codec_entries]['.$streamnumber.'][type_raw] == '.$streamdata['type_raw']; + $this->warning('Unknown streamtype: [codec_list_object][codec_entries]['.$streamnumber.'][type_raw] == '.$streamdata['type_raw']); break; } } } - if (isset($ThisFileInfo['audio'])) { + if (isset($info['audio'])) { $thisfile_audio['lossless'] = (isset($thisfile_audio['lossless']) ? $thisfile_audio['lossless'] : false); $thisfile_audio['dataformat'] = (!empty($thisfile_audio['dataformat']) ? $thisfile_audio['dataformat'] : 'asf'); } @@ -1411,157 +1455,176 @@ class getid3_asf $thisfile_video['dataformat'] = (!empty($thisfile_video['dataformat']) ? $thisfile_video['dataformat'] : 'asf'); } if (!empty($thisfile_video['streams'])) { - $thisfile_video['streams']['resolution_x'] = 0; - $thisfile_video['streams']['resolution_y'] = 0; + $thisfile_video['resolution_x'] = 0; + $thisfile_video['resolution_y'] = 0; foreach ($thisfile_video['streams'] as $key => $valuearray) { - if (($valuearray['resolution_x'] > $thisfile_video['streams']['resolution_x']) || ($valuearray['resolution_y'] > $thisfile_video['streams']['resolution_y'])) { + if (($valuearray['resolution_x'] > $thisfile_video['resolution_x']) || ($valuearray['resolution_y'] > $thisfile_video['resolution_y'])) { $thisfile_video['resolution_x'] = $valuearray['resolution_x']; $thisfile_video['resolution_y'] = $valuearray['resolution_y']; } } } - $ThisFileInfo['bitrate'] = (isset($thisfile_audio['bitrate']) ? $thisfile_audio['bitrate'] : 0) + (isset($thisfile_video['bitrate']) ? $thisfile_video['bitrate'] : 0); + $info['bitrate'] = 0 + (isset($thisfile_audio['bitrate']) ? $thisfile_audio['bitrate'] : 0) + (isset($thisfile_video['bitrate']) ? $thisfile_video['bitrate'] : 0); - if ((!isset($ThisFileInfo['playtime_seconds']) || ($ThisFileInfo['playtime_seconds'] <= 0)) && ($ThisFileInfo['bitrate'] > 0)) { - $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['filesize'] - $ThisFileInfo['avdataoffset']) / ($ThisFileInfo['bitrate'] / 8); + if ((!isset($info['playtime_seconds']) || ($info['playtime_seconds'] <= 0)) && ($info['bitrate'] > 0)) { + $info['playtime_seconds'] = ($info['filesize'] - $info['avdataoffset']) / ($info['bitrate'] / 8); } return true; } - static function ASFCodecListObjectTypeLookup($CodecListType) { - static $ASFCodecListObjectTypeLookup = array(); - if (empty($ASFCodecListObjectTypeLookup)) { - $ASFCodecListObjectTypeLookup[0x0001] = 'Video Codec'; - $ASFCodecListObjectTypeLookup[0x0002] = 'Audio Codec'; - $ASFCodecListObjectTypeLookup[0xFFFF] = 'Unknown Codec'; - } + /** + * @param int $CodecListType + * + * @return string + */ + public static function codecListObjectTypeLookup($CodecListType) { + static $lookup = array( + 0x0001 => 'Video Codec', + 0x0002 => 'Audio Codec', + 0xFFFF => 'Unknown Codec' + ); - return (isset($ASFCodecListObjectTypeLookup[$CodecListType]) ? $ASFCodecListObjectTypeLookup[$CodecListType] : 'Invalid Codec Type'); + return (isset($lookup[$CodecListType]) ? $lookup[$CodecListType] : 'Invalid Codec Type'); } - static function KnownGUIDs() { - static $GUIDarray = array(); - if (empty($GUIDarray)) { - $GUIDarray['GETID3_ASF_Extended_Stream_Properties_Object'] = '14E6A5CB-C672-4332-8399-A96952065B5A'; - $GUIDarray['GETID3_ASF_Padding_Object'] = '1806D474-CADF-4509-A4BA-9AABCB96AAE8'; - $GUIDarray['GETID3_ASF_Payload_Ext_Syst_Pixel_Aspect_Ratio'] = '1B1EE554-F9EA-4BC8-821A-376B74E4C4B8'; - $GUIDarray['GETID3_ASF_Script_Command_Object'] = '1EFB1A30-0B62-11D0-A39B-00A0C90348F6'; - $GUIDarray['GETID3_ASF_No_Error_Correction'] = '20FB5700-5B55-11CF-A8FD-00805F5C442B'; - $GUIDarray['GETID3_ASF_Content_Branding_Object'] = '2211B3FA-BD23-11D2-B4B7-00A0C955FC6E'; - $GUIDarray['GETID3_ASF_Content_Encryption_Object'] = '2211B3FB-BD23-11D2-B4B7-00A0C955FC6E'; - $GUIDarray['GETID3_ASF_Digital_Signature_Object'] = '2211B3FC-BD23-11D2-B4B7-00A0C955FC6E'; - $GUIDarray['GETID3_ASF_Extended_Content_Encryption_Object'] = '298AE614-2622-4C17-B935-DAE07EE9289C'; - $GUIDarray['GETID3_ASF_Simple_Index_Object'] = '33000890-E5B1-11CF-89F4-00A0C90349CB'; - $GUIDarray['GETID3_ASF_Degradable_JPEG_Media'] = '35907DE0-E415-11CF-A917-00805F5C442B'; - $GUIDarray['GETID3_ASF_Payload_Extension_System_Timecode'] = '399595EC-8667-4E2D-8FDB-98814CE76C1E'; - $GUIDarray['GETID3_ASF_Binary_Media'] = '3AFB65E2-47EF-40F2-AC2C-70A90D71D343'; - $GUIDarray['GETID3_ASF_Timecode_Index_Object'] = '3CB73FD0-0C4A-4803-953D-EDF7B6228F0C'; - $GUIDarray['GETID3_ASF_Metadata_Library_Object'] = '44231C94-9498-49D1-A141-1D134E457054'; - $GUIDarray['GETID3_ASF_Reserved_3'] = '4B1ACBE3-100B-11D0-A39B-00A0C90348F6'; - $GUIDarray['GETID3_ASF_Reserved_4'] = '4CFEDB20-75F6-11CF-9C0F-00A0C90349CB'; - $GUIDarray['GETID3_ASF_Command_Media'] = '59DACFC0-59E6-11D0-A3AC-00A0C90348F6'; - $GUIDarray['GETID3_ASF_Header_Extension_Object'] = '5FBF03B5-A92E-11CF-8EE3-00C00C205365'; - $GUIDarray['GETID3_ASF_Media_Object_Index_Parameters_Obj'] = '6B203BAD-3F11-4E84-ACA8-D7613DE2CFA7'; - $GUIDarray['GETID3_ASF_Header_Object'] = '75B22630-668E-11CF-A6D9-00AA0062CE6C'; - $GUIDarray['GETID3_ASF_Content_Description_Object'] = '75B22633-668E-11CF-A6D9-00AA0062CE6C'; - $GUIDarray['GETID3_ASF_Error_Correction_Object'] = '75B22635-668E-11CF-A6D9-00AA0062CE6C'; - $GUIDarray['GETID3_ASF_Data_Object'] = '75B22636-668E-11CF-A6D9-00AA0062CE6C'; - $GUIDarray['GETID3_ASF_Web_Stream_Media_Subtype'] = '776257D4-C627-41CB-8F81-7AC7FF1C40CC'; - $GUIDarray['GETID3_ASF_Stream_Bitrate_Properties_Object'] = '7BF875CE-468D-11D1-8D82-006097C9A2B2'; - $GUIDarray['GETID3_ASF_Language_List_Object'] = '7C4346A9-EFE0-4BFC-B229-393EDE415C85'; - $GUIDarray['GETID3_ASF_Codec_List_Object'] = '86D15240-311D-11D0-A3A4-00A0C90348F6'; - $GUIDarray['GETID3_ASF_Reserved_2'] = '86D15241-311D-11D0-A3A4-00A0C90348F6'; - $GUIDarray['GETID3_ASF_File_Properties_Object'] = '8CABDCA1-A947-11CF-8EE4-00C00C205365'; - $GUIDarray['GETID3_ASF_File_Transfer_Media'] = '91BD222C-F21C-497A-8B6D-5AA86BFC0185'; - $GUIDarray['GETID3_ASF_Old_RTP_Extension_Data'] = '96800C63-4C94-11D1-837B-0080C7A37F95'; - $GUIDarray['GETID3_ASF_Advanced_Mutual_Exclusion_Object'] = 'A08649CF-4775-4670-8A16-6E35357566CD'; - $GUIDarray['GETID3_ASF_Bandwidth_Sharing_Object'] = 'A69609E6-517B-11D2-B6AF-00C04FD908E9'; - $GUIDarray['GETID3_ASF_Reserved_1'] = 'ABD3D211-A9BA-11cf-8EE6-00C00C205365'; - $GUIDarray['GETID3_ASF_Bandwidth_Sharing_Exclusive'] = 'AF6060AA-5197-11D2-B6AF-00C04FD908E9'; - $GUIDarray['GETID3_ASF_Bandwidth_Sharing_Partial'] = 'AF6060AB-5197-11D2-B6AF-00C04FD908E9'; - $GUIDarray['GETID3_ASF_JFIF_Media'] = 'B61BE100-5B4E-11CF-A8FD-00805F5C442B'; - $GUIDarray['GETID3_ASF_Stream_Properties_Object'] = 'B7DC0791-A9B7-11CF-8EE6-00C00C205365'; - $GUIDarray['GETID3_ASF_Video_Media'] = 'BC19EFC0-5B4D-11CF-A8FD-00805F5C442B'; - $GUIDarray['GETID3_ASF_Audio_Spread'] = 'BFC3CD50-618F-11CF-8BB2-00AA00B4E220'; - $GUIDarray['GETID3_ASF_Metadata_Object'] = 'C5F8CBEA-5BAF-4877-8467-AA8C44FA4CCA'; - $GUIDarray['GETID3_ASF_Payload_Ext_Syst_Sample_Duration'] = 'C6BD9450-867F-4907-83A3-C77921B733AD'; - $GUIDarray['GETID3_ASF_Group_Mutual_Exclusion_Object'] = 'D1465A40-5A79-4338-B71B-E36B8FD6C249'; - $GUIDarray['GETID3_ASF_Extended_Content_Description_Object'] = 'D2D0A440-E307-11D2-97F0-00A0C95EA850'; - $GUIDarray['GETID3_ASF_Stream_Prioritization_Object'] = 'D4FED15B-88D3-454F-81F0-ED5C45999E24'; - $GUIDarray['GETID3_ASF_Payload_Ext_System_Content_Type'] = 'D590DC20-07BC-436C-9CF7-F3BBFBF1A4DC'; - $GUIDarray['GETID3_ASF_Old_File_Properties_Object'] = 'D6E229D0-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_ASF_Header_Object'] = 'D6E229D1-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_ASF_Data_Object'] = 'D6E229D2-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Index_Object'] = 'D6E229D3-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Stream_Properties_Object'] = 'D6E229D4-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Content_Description_Object'] = 'D6E229D5-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Script_Command_Object'] = 'D6E229D6-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Marker_Object'] = 'D6E229D7-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Component_Download_Object'] = 'D6E229D8-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Stream_Group_Object'] = 'D6E229D9-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Scalable_Object'] = 'D6E229DA-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Prioritization_Object'] = 'D6E229DB-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Bitrate_Mutual_Exclusion_Object'] = 'D6E229DC-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Inter_Media_Dependency_Object'] = 'D6E229DD-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Rating_Object'] = 'D6E229DE-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Index_Parameters_Object'] = 'D6E229DF-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Color_Table_Object'] = 'D6E229E0-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Language_List_Object'] = 'D6E229E1-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Audio_Media'] = 'D6E229E2-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Video_Media'] = 'D6E229E3-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Image_Media'] = 'D6E229E4-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Timecode_Media'] = 'D6E229E5-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Text_Media'] = 'D6E229E6-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_MIDI_Media'] = 'D6E229E7-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Command_Media'] = 'D6E229E8-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_No_Error_Concealment'] = 'D6E229EA-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Scrambled_Audio'] = 'D6E229EB-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_No_Color_Table'] = 'D6E229EC-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_SMPTE_Time'] = 'D6E229ED-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_ASCII_Text'] = 'D6E229EE-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Unicode_Text'] = 'D6E229EF-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_HTML_Text'] = 'D6E229F0-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_URL_Command'] = 'D6E229F1-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Filename_Command'] = 'D6E229F2-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_ACM_Codec'] = 'D6E229F3-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_VCM_Codec'] = 'D6E229F4-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_QuickTime_Codec'] = 'D6E229F5-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_DirectShow_Transform_Filter'] = 'D6E229F6-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_DirectShow_Rendering_Filter'] = 'D6E229F7-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_No_Enhancement'] = 'D6E229F8-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Unknown_Enhancement_Type'] = 'D6E229F9-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Temporal_Enhancement'] = 'D6E229FA-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Spatial_Enhancement'] = 'D6E229FB-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Quality_Enhancement'] = 'D6E229FC-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Number_of_Channels_Enhancement'] = 'D6E229FD-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Frequency_Response_Enhancement'] = 'D6E229FE-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Media_Object'] = 'D6E229FF-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Mutex_Language'] = 'D6E22A00-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Mutex_Bitrate'] = 'D6E22A01-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Mutex_Unknown'] = 'D6E22A02-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_ASF_Placeholder_Object'] = 'D6E22A0E-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Old_Data_Unit_Extension_Object'] = 'D6E22A0F-35DA-11D1-9034-00A0C90349BE'; - $GUIDarray['GETID3_ASF_Web_Stream_Format'] = 'DA1E6B13-8359-4050-B398-388E965BF00C'; - $GUIDarray['GETID3_ASF_Payload_Ext_System_File_Name'] = 'E165EC0E-19ED-45D7-B4A7-25CBD1E28E9B'; - $GUIDarray['GETID3_ASF_Marker_Object'] = 'F487CD01-A951-11CF-8EE6-00C00C205365'; - $GUIDarray['GETID3_ASF_Timecode_Index_Parameters_Object'] = 'F55E496D-9797-4B5D-8C8B-604DFE9BFB24'; - $GUIDarray['GETID3_ASF_Audio_Media'] = 'F8699E40-5B4D-11CF-A8FD-00805F5C442B'; - $GUIDarray['GETID3_ASF_Media_Object_Index_Object'] = 'FEB103F8-12AD-4C64-840F-2A1D2F7AD48C'; - $GUIDarray['GETID3_ASF_Alt_Extended_Content_Encryption_Obj'] = 'FF889EF1-ADEE-40DA-9E71-98704BB928CE'; - } + /** + * @return array + */ + public static function KnownGUIDs() { + static $GUIDarray = array( + 'GETID3_ASF_Extended_Stream_Properties_Object' => '14E6A5CB-C672-4332-8399-A96952065B5A', + 'GETID3_ASF_Padding_Object' => '1806D474-CADF-4509-A4BA-9AABCB96AAE8', + 'GETID3_ASF_Payload_Ext_Syst_Pixel_Aspect_Ratio' => '1B1EE554-F9EA-4BC8-821A-376B74E4C4B8', + 'GETID3_ASF_Script_Command_Object' => '1EFB1A30-0B62-11D0-A39B-00A0C90348F6', + 'GETID3_ASF_No_Error_Correction' => '20FB5700-5B55-11CF-A8FD-00805F5C442B', + 'GETID3_ASF_Content_Branding_Object' => '2211B3FA-BD23-11D2-B4B7-00A0C955FC6E', + 'GETID3_ASF_Content_Encryption_Object' => '2211B3FB-BD23-11D2-B4B7-00A0C955FC6E', + 'GETID3_ASF_Digital_Signature_Object' => '2211B3FC-BD23-11D2-B4B7-00A0C955FC6E', + 'GETID3_ASF_Extended_Content_Encryption_Object' => '298AE614-2622-4C17-B935-DAE07EE9289C', + 'GETID3_ASF_Simple_Index_Object' => '33000890-E5B1-11CF-89F4-00A0C90349CB', + 'GETID3_ASF_Degradable_JPEG_Media' => '35907DE0-E415-11CF-A917-00805F5C442B', + 'GETID3_ASF_Payload_Extension_System_Timecode' => '399595EC-8667-4E2D-8FDB-98814CE76C1E', + 'GETID3_ASF_Binary_Media' => '3AFB65E2-47EF-40F2-AC2C-70A90D71D343', + 'GETID3_ASF_Timecode_Index_Object' => '3CB73FD0-0C4A-4803-953D-EDF7B6228F0C', + 'GETID3_ASF_Metadata_Library_Object' => '44231C94-9498-49D1-A141-1D134E457054', + 'GETID3_ASF_Reserved_3' => '4B1ACBE3-100B-11D0-A39B-00A0C90348F6', + 'GETID3_ASF_Reserved_4' => '4CFEDB20-75F6-11CF-9C0F-00A0C90349CB', + 'GETID3_ASF_Command_Media' => '59DACFC0-59E6-11D0-A3AC-00A0C90348F6', + 'GETID3_ASF_Header_Extension_Object' => '5FBF03B5-A92E-11CF-8EE3-00C00C205365', + 'GETID3_ASF_Media_Object_Index_Parameters_Obj' => '6B203BAD-3F11-4E84-ACA8-D7613DE2CFA7', + 'GETID3_ASF_Header_Object' => '75B22630-668E-11CF-A6D9-00AA0062CE6C', + 'GETID3_ASF_Content_Description_Object' => '75B22633-668E-11CF-A6D9-00AA0062CE6C', + 'GETID3_ASF_Error_Correction_Object' => '75B22635-668E-11CF-A6D9-00AA0062CE6C', + 'GETID3_ASF_Data_Object' => '75B22636-668E-11CF-A6D9-00AA0062CE6C', + 'GETID3_ASF_Web_Stream_Media_Subtype' => '776257D4-C627-41CB-8F81-7AC7FF1C40CC', + 'GETID3_ASF_Stream_Bitrate_Properties_Object' => '7BF875CE-468D-11D1-8D82-006097C9A2B2', + 'GETID3_ASF_Language_List_Object' => '7C4346A9-EFE0-4BFC-B229-393EDE415C85', + 'GETID3_ASF_Codec_List_Object' => '86D15240-311D-11D0-A3A4-00A0C90348F6', + 'GETID3_ASF_Reserved_2' => '86D15241-311D-11D0-A3A4-00A0C90348F6', + 'GETID3_ASF_File_Properties_Object' => '8CABDCA1-A947-11CF-8EE4-00C00C205365', + 'GETID3_ASF_File_Transfer_Media' => '91BD222C-F21C-497A-8B6D-5AA86BFC0185', + 'GETID3_ASF_Old_RTP_Extension_Data' => '96800C63-4C94-11D1-837B-0080C7A37F95', + 'GETID3_ASF_Advanced_Mutual_Exclusion_Object' => 'A08649CF-4775-4670-8A16-6E35357566CD', + 'GETID3_ASF_Bandwidth_Sharing_Object' => 'A69609E6-517B-11D2-B6AF-00C04FD908E9', + 'GETID3_ASF_Reserved_1' => 'ABD3D211-A9BA-11cf-8EE6-00C00C205365', + 'GETID3_ASF_Bandwidth_Sharing_Exclusive' => 'AF6060AA-5197-11D2-B6AF-00C04FD908E9', + 'GETID3_ASF_Bandwidth_Sharing_Partial' => 'AF6060AB-5197-11D2-B6AF-00C04FD908E9', + 'GETID3_ASF_JFIF_Media' => 'B61BE100-5B4E-11CF-A8FD-00805F5C442B', + 'GETID3_ASF_Stream_Properties_Object' => 'B7DC0791-A9B7-11CF-8EE6-00C00C205365', + 'GETID3_ASF_Video_Media' => 'BC19EFC0-5B4D-11CF-A8FD-00805F5C442B', + 'GETID3_ASF_Audio_Spread' => 'BFC3CD50-618F-11CF-8BB2-00AA00B4E220', + 'GETID3_ASF_Metadata_Object' => 'C5F8CBEA-5BAF-4877-8467-AA8C44FA4CCA', + 'GETID3_ASF_Payload_Ext_Syst_Sample_Duration' => 'C6BD9450-867F-4907-83A3-C77921B733AD', + 'GETID3_ASF_Group_Mutual_Exclusion_Object' => 'D1465A40-5A79-4338-B71B-E36B8FD6C249', + 'GETID3_ASF_Extended_Content_Description_Object' => 'D2D0A440-E307-11D2-97F0-00A0C95EA850', + 'GETID3_ASF_Stream_Prioritization_Object' => 'D4FED15B-88D3-454F-81F0-ED5C45999E24', + 'GETID3_ASF_Payload_Ext_System_Content_Type' => 'D590DC20-07BC-436C-9CF7-F3BBFBF1A4DC', + 'GETID3_ASF_Old_File_Properties_Object' => 'D6E229D0-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_ASF_Header_Object' => 'D6E229D1-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_ASF_Data_Object' => 'D6E229D2-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Index_Object' => 'D6E229D3-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Stream_Properties_Object' => 'D6E229D4-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Content_Description_Object' => 'D6E229D5-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Script_Command_Object' => 'D6E229D6-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Marker_Object' => 'D6E229D7-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Component_Download_Object' => 'D6E229D8-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Stream_Group_Object' => 'D6E229D9-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Scalable_Object' => 'D6E229DA-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Prioritization_Object' => 'D6E229DB-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Bitrate_Mutual_Exclusion_Object' => 'D6E229DC-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Inter_Media_Dependency_Object' => 'D6E229DD-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Rating_Object' => 'D6E229DE-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Index_Parameters_Object' => 'D6E229DF-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Color_Table_Object' => 'D6E229E0-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Language_List_Object' => 'D6E229E1-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Audio_Media' => 'D6E229E2-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Video_Media' => 'D6E229E3-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Image_Media' => 'D6E229E4-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Timecode_Media' => 'D6E229E5-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Text_Media' => 'D6E229E6-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_MIDI_Media' => 'D6E229E7-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Command_Media' => 'D6E229E8-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_No_Error_Concealment' => 'D6E229EA-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Scrambled_Audio' => 'D6E229EB-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_No_Color_Table' => 'D6E229EC-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_SMPTE_Time' => 'D6E229ED-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_ASCII_Text' => 'D6E229EE-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Unicode_Text' => 'D6E229EF-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_HTML_Text' => 'D6E229F0-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_URL_Command' => 'D6E229F1-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Filename_Command' => 'D6E229F2-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_ACM_Codec' => 'D6E229F3-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_VCM_Codec' => 'D6E229F4-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_QuickTime_Codec' => 'D6E229F5-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_DirectShow_Transform_Filter' => 'D6E229F6-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_DirectShow_Rendering_Filter' => 'D6E229F7-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_No_Enhancement' => 'D6E229F8-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Unknown_Enhancement_Type' => 'D6E229F9-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Temporal_Enhancement' => 'D6E229FA-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Spatial_Enhancement' => 'D6E229FB-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Quality_Enhancement' => 'D6E229FC-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Number_of_Channels_Enhancement' => 'D6E229FD-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Frequency_Response_Enhancement' => 'D6E229FE-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Media_Object' => 'D6E229FF-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Mutex_Language' => 'D6E22A00-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Mutex_Bitrate' => 'D6E22A01-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Mutex_Unknown' => 'D6E22A02-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_ASF_Placeholder_Object' => 'D6E22A0E-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Old_Data_Unit_Extension_Object' => 'D6E22A0F-35DA-11D1-9034-00A0C90349BE', + 'GETID3_ASF_Web_Stream_Format' => 'DA1E6B13-8359-4050-B398-388E965BF00C', + 'GETID3_ASF_Payload_Ext_System_File_Name' => 'E165EC0E-19ED-45D7-B4A7-25CBD1E28E9B', + 'GETID3_ASF_Marker_Object' => 'F487CD01-A951-11CF-8EE6-00C00C205365', + 'GETID3_ASF_Timecode_Index_Parameters_Object' => 'F55E496D-9797-4B5D-8C8B-604DFE9BFB24', + 'GETID3_ASF_Audio_Media' => 'F8699E40-5B4D-11CF-A8FD-00805F5C442B', + 'GETID3_ASF_Media_Object_Index_Object' => 'FEB103F8-12AD-4C64-840F-2A1D2F7AD48C', + 'GETID3_ASF_Alt_Extended_Content_Encryption_Obj' => 'FF889EF1-ADEE-40DA-9E71-98704BB928CE', + 'GETID3_ASF_Index_Placeholder_Object' => 'D9AADE20-7C17-4F9C-BC28-8555DD98E2A2', // https://metacpan.org/dist/Audio-WMA/source/WMA.pm + 'GETID3_ASF_Compatibility_Object' => '26F18B5D-4584-47EC-9F5F-0E651F0452C9', // https://metacpan.org/dist/Audio-WMA/source/WMA.pm + 'GETID3_ASF_Media_Object_Index_Parameters_Object'=> '6B203BAD-3F11-48E4-ACA8-D7613DE2CFA7', + ); return $GUIDarray; } - static function GUIDname($GUIDstring) { + /** + * @param string $GUIDstring + * + * @return string|false + */ + public static function GUIDname($GUIDstring) { static $GUIDarray = array(); if (empty($GUIDarray)) { - $GUIDarray = getid3_asf::KnownGUIDs(); + $GUIDarray = self::KnownGUIDs(); } return array_search($GUIDstring, $GUIDarray); } - static function ASFIndexObjectIndexTypeLookup($id) { + /** + * @param int $id + * + * @return string + */ + public static function ASFIndexObjectIndexTypeLookup($id) { static $ASFIndexObjectIndexTypeLookup = array(); if (empty($ASFIndexObjectIndexTypeLookup)) { $ASFIndexObjectIndexTypeLookup[1] = 'Nearest Past Data Packet'; @@ -1571,7 +1634,12 @@ class getid3_asf return (isset($ASFIndexObjectIndexTypeLookup[$id]) ? $ASFIndexObjectIndexTypeLookup[$id] : 'invalid'); } - static function GUIDtoBytestring($GUIDstring) { + /** + * @param string $GUIDstring + * + * @return string + */ + public static function GUIDtoBytestring($GUIDstring) { // Microsoft defines these 16-byte (128-bit) GUIDs in the strangest way: // first 4 bytes are in little-endian order // next 2 bytes are appended in little-endian order @@ -1606,32 +1674,43 @@ class getid3_asf return $hexbytecharstring; } - static function BytestringToGUID($Bytestring) { - $GUIDstring = str_pad(dechex(ord($Bytestring{3})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{2})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{1})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{0})), 2, '0', STR_PAD_LEFT); + /** + * @param string $Bytestring + * + * @return string + */ + public static function BytestringToGUID($Bytestring) { + $GUIDstring = str_pad(dechex(ord($Bytestring[3])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[2])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[1])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[0])), 2, '0', STR_PAD_LEFT); $GUIDstring .= '-'; - $GUIDstring .= str_pad(dechex(ord($Bytestring{5})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{4})), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[5])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[4])), 2, '0', STR_PAD_LEFT); $GUIDstring .= '-'; - $GUIDstring .= str_pad(dechex(ord($Bytestring{7})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{6})), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[7])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[6])), 2, '0', STR_PAD_LEFT); $GUIDstring .= '-'; - $GUIDstring .= str_pad(dechex(ord($Bytestring{8})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{9})), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[8])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[9])), 2, '0', STR_PAD_LEFT); $GUIDstring .= '-'; - $GUIDstring .= str_pad(dechex(ord($Bytestring{10})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{11})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{12})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{13})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{14})), 2, '0', STR_PAD_LEFT); - $GUIDstring .= str_pad(dechex(ord($Bytestring{15})), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[10])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[11])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[12])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[13])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[14])), 2, '0', STR_PAD_LEFT); + $GUIDstring .= str_pad(dechex(ord($Bytestring[15])), 2, '0', STR_PAD_LEFT); return strtoupper($GUIDstring); } - static function FILETIMEtoUNIXtime($FILETIME, $round=true) { + /** + * @param int $FILETIME + * @param bool $round + * + * @return float|int + */ + public static function FILETIMEtoUNIXtime($FILETIME, $round=true) { // FILETIME is a 64-bit unsigned integer representing // the number of 100-nanosecond intervals since January 1, 1601 // UNIX timestamp is number of seconds since January 1, 1970 @@ -1642,40 +1721,517 @@ class getid3_asf return ($FILETIME - 116444736000000000) / 10000000; } - static function WMpictureTypeLookup($WMpictureType) { - static $WMpictureTypeLookup = array(); - if (empty($WMpictureTypeLookup)) { - $WMpictureTypeLookup[0x03] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Front Cover'); - $WMpictureTypeLookup[0x04] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Back Cover'); - $WMpictureTypeLookup[0x00] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'User Defined'); - $WMpictureTypeLookup[0x05] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Leaflet Page'); - $WMpictureTypeLookup[0x06] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Media Label'); - $WMpictureTypeLookup[0x07] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Lead Artist'); - $WMpictureTypeLookup[0x08] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Artist'); - $WMpictureTypeLookup[0x09] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Conductor'); - $WMpictureTypeLookup[0x0A] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Band'); - $WMpictureTypeLookup[0x0B] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Composer'); - $WMpictureTypeLookup[0x0C] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Lyricist'); - $WMpictureTypeLookup[0x0D] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Recording Location'); - $WMpictureTypeLookup[0x0E] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'During Recording'); - $WMpictureTypeLookup[0x0F] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'During Performance'); - $WMpictureTypeLookup[0x10] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Video Screen Capture'); - $WMpictureTypeLookup[0x12] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Illustration'); - $WMpictureTypeLookup[0x13] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Band Logotype'); - $WMpictureTypeLookup[0x14] = getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-16LE', 'Publisher Logotype'); + /** + * @param int $WMpictureType + * + * @return string + */ + public static function WMpictureTypeLookup($WMpictureType) { + static $lookup = null; + if ($lookup === null) { + $lookup = array( + 0x03 => 'Front Cover', + 0x04 => 'Back Cover', + 0x00 => 'User Defined', + 0x05 => 'Leaflet Page', + 0x06 => 'Media Label', + 0x07 => 'Lead Artist', + 0x08 => 'Artist', + 0x09 => 'Conductor', + 0x0A => 'Band', + 0x0B => 'Composer', + 0x0C => 'Lyricist', + 0x0D => 'Recording Location', + 0x0E => 'During Recording', + 0x0F => 'During Performance', + 0x10 => 'Video Screen Capture', + 0x12 => 'Illustration', + 0x13 => 'Band Logotype', + 0x14 => 'Publisher Logotype' + ); + $lookup = array_map(function($str) { + return getid3_lib::iconv_fallback('UTF-8', 'UTF-16LE', $str); + }, $lookup); } - return (isset($WMpictureTypeLookup[$WMpictureType]) ? $WMpictureTypeLookup[$WMpictureType] : ''); + + return (isset($lookup[$WMpictureType]) ? $lookup[$WMpictureType] : ''); } + /** + * @param string $asf_header_extension_object_data + * @param int $unhandled_sections + * + * @return array + */ + public function HeaderExtensionObjectDataParse(&$asf_header_extension_object_data, &$unhandled_sections) { + // https://web.archive.org/web/20140419205228/http://msdn.microsoft.com/en-us/library/bb643323.aspx - // Remove terminator 00 00 and convert UNICODE to Latin-1 - static function TrimConvert($string) { - return trim(getid3_lib::iconv_fallback('UTF-16LE', 'ISO-8859-1', getid3_asf::TrimTerm($string)), ' '); + $offset = 0; + $objectOffset = 0; + $HeaderExtensionObjectParsed = array(); + while ($objectOffset < strlen($asf_header_extension_object_data)) { + $offset = $objectOffset; + $thisObject = array(); + + $thisObject['guid'] = substr($asf_header_extension_object_data, $offset, 16); + $offset += 16; + $thisObject['guid_text'] = $this->BytestringToGUID($thisObject['guid']); + $thisObject['guid_name'] = $this->GUIDname($thisObject['guid_text']); + + $thisObject['size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 8)); + $offset += 8; + if ($thisObject['size'] <= 0) { + break; + } + + switch ($thisObject['guid']) { + case GETID3_ASF_Extended_Stream_Properties_Object: + $thisObject['start_time'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 8)); + $offset += 8; + $thisObject['start_time_unix'] = $this->FILETIMEtoUNIXtime($thisObject['start_time']); + + $thisObject['end_time'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 8)); + $offset += 8; + $thisObject['end_time_unix'] = $this->FILETIMEtoUNIXtime($thisObject['end_time']); + + $thisObject['data_bitrate'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['buffer_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['initial_buffer_fullness'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['alternate_data_bitrate'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['alternate_buffer_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['alternate_initial_buffer_fullness'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['maximum_object_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['flags_raw'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + $thisObject['flags']['reliable'] = (bool) $thisObject['flags_raw'] & 0x00000001; + $thisObject['flags']['seekable'] = (bool) $thisObject['flags_raw'] & 0x00000002; + $thisObject['flags']['no_cleanpoints'] = (bool) $thisObject['flags_raw'] & 0x00000004; + $thisObject['flags']['resend_live_cleanpoints'] = (bool) $thisObject['flags_raw'] & 0x00000008; + + $thisObject['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $thisObject['stream_language_id_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $thisObject['average_time_per_frame'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 8)); + $offset += 8; + + $thisObject['stream_name_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $thisObject['payload_extension_system_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + for ($i = 0; $i < $thisObject['stream_name_count']; $i++) { + $streamName = array(); + + $streamName['language_id_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $streamName['stream_name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $streamName['stream_name'] = substr($asf_header_extension_object_data, $offset, $streamName['stream_name_length']); + $offset += $streamName['stream_name_length']; + + $thisObject['stream_names'][$i] = $streamName; + } + + for ($i = 0; $i < $thisObject['payload_extension_system_count']; $i++) { + $payloadExtensionSystem = array(); + + $payloadExtensionSystem['extension_system_id'] = substr($asf_header_extension_object_data, $offset, 16); + $offset += 16; + $payloadExtensionSystem['extension_system_id_text'] = $this->BytestringToGUID($payloadExtensionSystem['extension_system_id']); + + $payloadExtensionSystem['extension_system_size'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + if ($payloadExtensionSystem['extension_system_size'] <= 0) { + break 2; + } + + $payloadExtensionSystem['extension_system_info_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $payloadExtensionSystem['extension_system_info'] = substr($asf_header_extension_object_data, $offset, $payloadExtensionSystem['extension_system_info_length']); + $offset += $payloadExtensionSystem['extension_system_info_length']; + + $thisObject['payload_extension_systems'][$i] = $payloadExtensionSystem; + } + + break; + + case GETID3_ASF_Advanced_Mutual_Exclusion_Object: + $thisObject['exclusion_type'] = substr($asf_header_extension_object_data, $offset, 16); + $offset += 16; + $thisObject['exclusion_type_text'] = $this->BytestringToGUID($thisObject['exclusion_type']); + + $thisObject['stream_numbers_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + for ($i = 0; $i < $thisObject['stream_numbers_count']; $i++) { + $thisObject['stream_numbers'][$i] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + } + + break; + + case GETID3_ASF_Stream_Prioritization_Object: + $thisObject['priority_records_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + for ($i = 0; $i < $thisObject['priority_records_count']; $i++) { + $priorityRecord = array(); + + $priorityRecord['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $priorityRecord['flags_raw'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + $priorityRecord['flags']['mandatory'] = (bool) $priorityRecord['flags_raw'] & 0x00000001; + + $thisObject['priority_records'][$i] = $priorityRecord; + } + + break; + + case GETID3_ASF_Padding_Object: + // padding, skip it + break; + + case GETID3_ASF_Metadata_Object: + $thisObject['description_record_counts'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + for ($i = 0; $i < $thisObject['description_record_counts']; $i++) { + $descriptionRecord = array(); + + $descriptionRecord['reserved_1'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); // must be zero + $offset += 2; + + $descriptionRecord['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $descriptionRecord['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $descriptionRecord['data_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + $descriptionRecord['data_type_text'] = self::metadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']); + + $descriptionRecord['data_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $descriptionRecord['name'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['name_length']); + $offset += $descriptionRecord['name_length']; + + $descriptionRecord['data'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['data_length']); + $offset += $descriptionRecord['data_length']; + switch ($descriptionRecord['data_type']) { + case 0x0000: // Unicode string + break; + + case 0x0001: // BYTE array + // do nothing + break; + + case 0x0002: // BOOL + $descriptionRecord['data'] = (bool) getid3_lib::LittleEndian2Int($descriptionRecord['data']); + break; + + case 0x0003: // DWORD + case 0x0004: // QWORD + case 0x0005: // WORD + $descriptionRecord['data'] = getid3_lib::LittleEndian2Int($descriptionRecord['data']); + break; + + case 0x0006: // GUID + $descriptionRecord['data_text'] = $this->BytestringToGUID($descriptionRecord['data']); + break; + } + + $thisObject['description_record'][$i] = $descriptionRecord; + } + break; + + case GETID3_ASF_Language_List_Object: + $thisObject['language_id_record_counts'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + for ($i = 0; $i < $thisObject['language_id_record_counts']; $i++) { + $languageIDrecord = array(); + + $languageIDrecord['language_id_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 1)); + $offset += 1; + + $languageIDrecord['language_id'] = substr($asf_header_extension_object_data, $offset, $languageIDrecord['language_id_length']); + $offset += $languageIDrecord['language_id_length']; + + $thisObject['language_id_record'][$i] = $languageIDrecord; + } + break; + + case GETID3_ASF_Metadata_Library_Object: + $thisObject['description_records_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + for ($i = 0; $i < $thisObject['description_records_count']; $i++) { + $descriptionRecord = array(); + + $descriptionRecord['language_list_index'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $descriptionRecord['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $descriptionRecord['name_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $descriptionRecord['data_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + $descriptionRecord['data_type_text'] = self::metadataLibraryObjectDataTypeLookup($descriptionRecord['data_type']); + + $descriptionRecord['data_length'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $descriptionRecord['name'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['name_length']); + $offset += $descriptionRecord['name_length']; + + $descriptionRecord['data'] = substr($asf_header_extension_object_data, $offset, $descriptionRecord['data_length']); + $offset += $descriptionRecord['data_length']; + + if (preg_match('#^WM/Picture$#', str_replace("\x00", '', trim($descriptionRecord['name'])))) { + $WMpicture = $this->ASF_WMpicture($descriptionRecord['data']); + foreach ($WMpicture as $key => $value) { + $descriptionRecord['data'] = $WMpicture; + } + unset($WMpicture); + } + + $thisObject['description_record'][$i] = $descriptionRecord; + } + break; + + case GETID3_ASF_Index_Parameters_Object: + $thisObject['index_entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['index_specifiers_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + for ($i = 0; $i < $thisObject['index_specifiers_count']; $i++) { + $indexSpecifier = array(); + + $indexSpecifier['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $indexSpecifier['index_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + $indexSpecifier['index_type_text'] = isset(static::$ASFIndexParametersObjectIndexSpecifiersIndexTypes[$indexSpecifier['index_type']]) + ? static::$ASFIndexParametersObjectIndexSpecifiersIndexTypes[$indexSpecifier['index_type']] + : 'invalid' + ; + + $thisObject['index_specifiers'][$i] = $indexSpecifier; + } + + break; + + case GETID3_ASF_Media_Object_Index_Parameters_Object: + $thisObject['index_entry_count_interval'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['index_specifiers_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + for ($i = 0; $i < $thisObject['index_specifiers_count']; $i++) { + $indexSpecifier = array(); + + $indexSpecifier['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $indexSpecifier['index_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + $indexSpecifier['index_type_text'] = isset(static::$ASFMediaObjectIndexParametersObjectIndexSpecifiersIndexTypes[$indexSpecifier['index_type']]) + ? static::$ASFMediaObjectIndexParametersObjectIndexSpecifiersIndexTypes[$indexSpecifier['index_type']] + : 'invalid' + ; + + $thisObject['index_specifiers'][$i] = $indexSpecifier; + } + + break; + + case GETID3_ASF_Timecode_Index_Parameters_Object: + // 4.11 Timecode Index Parameters Object (mandatory only if TIMECODE index is present in file, 0 or 1) + // Field name Field type Size (bits) + // Object ID GUID 128 // GUID for the Timecode Index Parameters Object - ASF_Timecode_Index_Parameters_Object + // Object Size QWORD 64 // Specifies the size, in bytes, of the Timecode Index Parameters Object. Valid values are at least 34 bytes. + // Index Entry Count Interval DWORD 32 // This value is ignored for the Timecode Index Parameters Object. + // Index Specifiers Count WORD 16 // Specifies the number of entries in the Index Specifiers list. Valid values are 1 and greater. + // Index Specifiers array of: varies // + // * Stream Number WORD 16 // Specifies the stream number that the Index Specifiers refer to. Valid values are between 1 and 127. + // * Index Type WORD 16 // Specifies the type of index. Values are defined as follows (1 is not a valid value): + // 2 = Nearest Past Media Object - indexes point to the closest data packet containing an entire video frame or the first fragment of a video frame + // 3 = Nearest Past Cleanpoint - indexes point to the closest data packet containing an entire video frame (or first fragment of a video frame) that is a key frame. + // Nearest Past Media Object is the most common value + + $thisObject['index_entry_count_interval'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 4)); + $offset += 4; + + $thisObject['index_specifiers_count'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + for ($i = 0; $i < $thisObject['index_specifiers_count']; $i++) { + $indexSpecifier = array(); + + $indexSpecifier['stream_number'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + + $indexSpecifier['index_type'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 2)); + $offset += 2; + $indexSpecifier['index_type_text'] = isset(static::$ASFTimecodeIndexParametersObjectIndexSpecifiersIndexTypes[$indexSpecifier['index_type']]) + ? static::$ASFTimecodeIndexParametersObjectIndexSpecifiersIndexTypes[$indexSpecifier['index_type']] + : 'invalid' + ; + + $thisObject['index_specifiers'][$i] = $indexSpecifier; + } + + break; + + case GETID3_ASF_Compatibility_Object: + $thisObject['profile'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 1)); + $offset += 1; + + $thisObject['mode'] = getid3_lib::LittleEndian2Int(substr($asf_header_extension_object_data, $offset, 1)); + $offset += 1; + + break; + + default: + $unhandled_sections++; + if ($this->GUIDname($thisObject['guid_text'])) { + $this->warning('unhandled Header Extension Object GUID "'.$this->GUIDname($thisObject['guid_text']).'" {'.$thisObject['guid_text'].'} at offset '.($offset - 16 - 8)); + } else { + $this->warning('unknown Header Extension Object GUID {'.$thisObject['guid_text'].'} in at offset '.($offset - 16 - 8)); + } + break; + } + $HeaderExtensionObjectParsed[] = $thisObject; + + $objectOffset += $thisObject['size']; + } + return $HeaderExtensionObjectParsed; } + /** + * @param int $id + * + * @return string + */ + public static function metadataLibraryObjectDataTypeLookup($id) { + static $lookup = array( + 0x0000 => 'Unicode string', // The data consists of a sequence of Unicode characters + 0x0001 => 'BYTE array', // The type of the data is implementation-specific + 0x0002 => 'BOOL', // The data is 2 bytes long and should be interpreted as a 16-bit unsigned integer. Only 0x0000 or 0x0001 are permitted values + 0x0003 => 'DWORD', // The data is 4 bytes long and should be interpreted as a 32-bit unsigned integer + 0x0004 => 'QWORD', // The data is 8 bytes long and should be interpreted as a 64-bit unsigned integer + 0x0005 => 'WORD', // The data is 2 bytes long and should be interpreted as a 16-bit unsigned integer + 0x0006 => 'GUID', // The data is 16 bytes long and should be interpreted as a 128-bit GUID + ); + return (isset($lookup[$id]) ? $lookup[$id] : 'invalid'); + } - // Remove terminator 00 00 - static function TrimTerm($string) { + /** + * @param string $data + * + * @return array + */ + public function ASF_WMpicture(&$data) { + //typedef struct _WMPicture{ + // LPWSTR pwszMIMEType; + // BYTE bPictureType; + // LPWSTR pwszDescription; + // DWORD dwDataLen; + // BYTE* pbData; + //} WM_PICTURE; + + $WMpicture = array(); + + $offset = 0; + $WMpicture['image_type_id'] = getid3_lib::LittleEndian2Int(substr($data, $offset, 1)); + $offset += 1; + $WMpicture['image_type'] = self::WMpictureTypeLookup($WMpicture['image_type_id']); + $WMpicture['image_size'] = getid3_lib::LittleEndian2Int(substr($data, $offset, 4)); + $offset += 4; + + $WMpicture['image_mime'] = ''; + do { + $next_byte_pair = substr($data, $offset, 2); + $offset += 2; + $WMpicture['image_mime'] .= $next_byte_pair; + } while ($next_byte_pair !== "\x00\x00"); + + $WMpicture['image_description'] = ''; + do { + $next_byte_pair = substr($data, $offset, 2); + $offset += 2; + $WMpicture['image_description'] .= $next_byte_pair; + } while ($next_byte_pair !== "\x00\x00"); + + $WMpicture['dataoffset'] = $offset; + $WMpicture['data'] = substr($data, $offset); + + $imageinfo = array(); + $WMpicture['image_mime'] = ''; + $imagechunkcheck = getid3_lib::GetDataImageSize($WMpicture['data'], $imageinfo); + unset($imageinfo); + if (!empty($imagechunkcheck)) { + $WMpicture['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]); + } + if (!isset($this->getid3->info['asf']['comments']['picture'])) { + $this->getid3->info['asf']['comments']['picture'] = array(); + } + $this->getid3->info['asf']['comments']['picture'][] = array('data'=>$WMpicture['data'], 'image_mime'=>$WMpicture['image_mime']); + + return $WMpicture; + } + + /** + * Remove terminator 00 00 and convert UTF-16LE to Latin-1. + * + * @param string $string + * + * @return string + */ + public static function TrimConvert($string) { + return trim(getid3_lib::iconv_fallback('UTF-16LE', 'ISO-8859-1', self::TrimTerm($string)), ' '); + } + + /** + * Remove terminator 00 00. + * + * @param string $string + * + * @return string + */ + public static function TrimTerm($string) { // remove terminator, only if present (it should be, but...) if (substr($string, -2) === "\x00\x00") { $string = substr($string, 0, -2); @@ -1683,7 +2239,4 @@ class getid3_asf return $string; } - } - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.bink.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.bink.php new file mode 100644 index 00000000..b59ec674 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.bink.php @@ -0,0 +1,76 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.bink.php // +// module for analyzing Bink or Smacker audio-video files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_bink extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->error('Bink / Smacker files not properly processed by this version of getID3() ['.$this->getid3->version().']'); + + $this->fseek($info['avdataoffset']); + $fileTypeID = $this->fread(3); + switch ($fileTypeID) { + case 'BIK': + return $this->ParseBink(); + + case 'SMK': + return $this->ParseSmacker(); + + default: + $this->error('Expecting "BIK" or "SMK" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($fileTypeID).'"'); + return false; + } + } + + /** + * @return bool + */ + public function ParseBink() { + $info = &$this->getid3->info; + $info['fileformat'] = 'bink'; + $info['video']['dataformat'] = 'bink'; + + $fileData = 'BIK'.$this->fread(13); + + $info['bink']['data_size'] = getid3_lib::LittleEndian2Int(substr($fileData, 4, 4)); + $info['bink']['frame_count'] = getid3_lib::LittleEndian2Int(substr($fileData, 8, 2)); + + if (($info['avdataend'] - $info['avdataoffset']) != ($info['bink']['data_size'] + 8)) { + $this->error('Probably truncated file: expecting '.$info['bink']['data_size'].' bytes, found '.($info['avdataend'] - $info['avdataoffset'])); + } + + return true; + } + + /** + * @return bool + */ + public function ParseSmacker() { + $info = &$this->getid3->info; + $info['fileformat'] = 'smacker'; + $info['video']['dataformat'] = 'smacker'; + + return true; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.flv.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.flv.php new file mode 100644 index 00000000..3b59e596 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.flv.php @@ -0,0 +1,910 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio-video.flv.php // +// module for analyzing Shockwave Flash Video files // +// dependencies: NONE // +// // +///////////////////////////////////////////////////////////////// +// // +// FLV module by Seth Kaufman // +// // +// * version 0.1 (26 June 2005) // +// // +// * version 0.1.1 (15 July 2005) // +// minor modifications by James Heinrich // +// // +// * version 0.2 (22 February 2006) // +// Support for On2 VP6 codec and meta information // +// by Steve Webster // +// // +// * version 0.3 (15 June 2006) // +// Modified to not read entire file into memory // +// by James Heinrich // +// // +// * version 0.4 (07 December 2007) // +// Bugfixes for incorrectly parsed FLV dimensions // +// and incorrect parsing of onMetaTag // +// by Evgeny Moysevich // +// // +// * version 0.5 (21 May 2009) // +// Fixed parsing of audio tags and added additional codec // +// details. The duration is now read from onMetaTag (if // +// exists), rather than parsing whole file // +// by Nigel Barnes // +// // +// * version 0.6 (24 May 2009) // +// Better parsing of files with h264 video // +// by Evgeny Moysevich // +// // +// * version 0.6.1 (30 May 2011) // +// prevent infinite loops in expGolombUe() // +// // +// * version 0.7.0 (16 Jul 2013) // +// handle GETID3_FLV_VIDEO_VP6FLV_ALPHA // +// improved AVCSequenceParameterSetReader::readData() // +// by Xander Schouwerwou // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +define('GETID3_FLV_TAG_AUDIO', 8); +define('GETID3_FLV_TAG_VIDEO', 9); +define('GETID3_FLV_TAG_META', 18); + +define('GETID3_FLV_VIDEO_H263', 2); +define('GETID3_FLV_VIDEO_SCREEN', 3); +define('GETID3_FLV_VIDEO_VP6FLV', 4); +define('GETID3_FLV_VIDEO_VP6FLV_ALPHA', 5); +define('GETID3_FLV_VIDEO_SCREENV2', 6); +define('GETID3_FLV_VIDEO_H264', 7); + +define('H264_AVC_SEQUENCE_HEADER', 0); +define('H264_PROFILE_BASELINE', 66); +define('H264_PROFILE_MAIN', 77); +define('H264_PROFILE_EXTENDED', 88); +define('H264_PROFILE_HIGH', 100); +define('H264_PROFILE_HIGH10', 110); +define('H264_PROFILE_HIGH422', 122); +define('H264_PROFILE_HIGH444', 144); +define('H264_PROFILE_HIGH444_PREDICTIVE', 244); + +class getid3_flv extends getid3_handler +{ + const magic = 'FLV'; + + /** + * Break out of the loop if too many frames have been scanned; only scan this + * many if meta frame does not contain useful duration. + * + * @var int + */ + public $max_frames = 100000; + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + + $FLVdataLength = $info['avdataend'] - $info['avdataoffset']; + $FLVheader = $this->fread(5); + + $info['fileformat'] = 'flv'; + $info['flv']['header']['signature'] = substr($FLVheader, 0, 3); + $info['flv']['header']['version'] = getid3_lib::BigEndian2Int(substr($FLVheader, 3, 1)); + $TypeFlags = getid3_lib::BigEndian2Int(substr($FLVheader, 4, 1)); + + if ($info['flv']['header']['signature'] != self::magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes(self::magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['flv']['header']['signature']).'"'); + unset($info['flv'], $info['fileformat']); + return false; + } + + $info['flv']['header']['hasAudio'] = (bool) ($TypeFlags & 0x04); + $info['flv']['header']['hasVideo'] = (bool) ($TypeFlags & 0x01); + + $FrameSizeDataLength = getid3_lib::BigEndian2Int($this->fread(4)); + $FLVheaderFrameLength = 9; + if ($FrameSizeDataLength > $FLVheaderFrameLength) { + $this->fseek($FrameSizeDataLength - $FLVheaderFrameLength, SEEK_CUR); + } + $Duration = 0; + $found_video = false; + $found_audio = false; + $found_meta = false; + $found_valid_meta_playtime = false; + $tagParseCount = 0; + $info['flv']['framecount'] = array('total'=>0, 'audio'=>0, 'video'=>0); + $flv_framecount = &$info['flv']['framecount']; + while ((($this->ftell() + 16) < $info['avdataend']) && (($tagParseCount++ <= $this->max_frames) || !$found_valid_meta_playtime)) { + $ThisTagHeader = $this->fread(16); + + $PreviousTagLength = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 0, 4)); + $TagType = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 4, 1)); + $DataLength = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 5, 3)); + $Timestamp = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 8, 3)); + $LastHeaderByte = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 15, 1)); + $NextOffset = $this->ftell() - 1 + $DataLength; + if ($Timestamp > $Duration) { + $Duration = $Timestamp; + } + + $flv_framecount['total']++; + switch ($TagType) { + case GETID3_FLV_TAG_AUDIO: + $flv_framecount['audio']++; + if (!$found_audio) { + $found_audio = true; + $info['flv']['audio']['audioFormat'] = ($LastHeaderByte >> 4) & 0x0F; + $info['flv']['audio']['audioRate'] = ($LastHeaderByte >> 2) & 0x03; + $info['flv']['audio']['audioSampleSize'] = ($LastHeaderByte >> 1) & 0x01; + $info['flv']['audio']['audioType'] = $LastHeaderByte & 0x01; + } + break; + + case GETID3_FLV_TAG_VIDEO: + $flv_framecount['video']++; + if (!$found_video) { + $found_video = true; + $info['flv']['video']['videoCodec'] = $LastHeaderByte & 0x07; + + $FLVvideoHeader = $this->fread(11); + $PictureSizeEnc = array(); + + if ($info['flv']['video']['videoCodec'] == GETID3_FLV_VIDEO_H264) { + // this code block contributed by: moysevichØgmail*com + + $AVCPacketType = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 0, 1)); + if ($AVCPacketType == H264_AVC_SEQUENCE_HEADER) { + // read AVCDecoderConfigurationRecord + $configurationVersion = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 1)); + $AVCProfileIndication = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 1)); + $profile_compatibility = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 1)); + $lengthSizeMinusOne = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 7, 1)); + $numOfSequenceParameterSets = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 8, 1)); + + if (($numOfSequenceParameterSets & 0x1F) != 0) { + // there is at least one SequenceParameterSet + // read size of the first SequenceParameterSet + //$spsSize = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 9, 2)); + $spsSize = getid3_lib::LittleEndian2Int(substr($FLVvideoHeader, 9, 2)); + // read the first SequenceParameterSet + $sps = $this->fread($spsSize); + if (strlen($sps) == $spsSize) { // make sure that whole SequenceParameterSet was red + $spsReader = new AVCSequenceParameterSetReader($sps); + $spsReader->readData(); + $info['video']['resolution_x'] = $spsReader->getWidth(); + $info['video']['resolution_y'] = $spsReader->getHeight(); + } + } + } + // end: moysevichØgmail*com + + } elseif ($info['flv']['video']['videoCodec'] == GETID3_FLV_VIDEO_H263) { + + $PictureSizeType = (getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 3, 2))) >> 7; + $PictureSizeType = $PictureSizeType & 0x0007; + $info['flv']['header']['videoSizeType'] = $PictureSizeType; + switch ($PictureSizeType) { + case 0: + //$PictureSizeEnc = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2)); + //$PictureSizeEnc <<= 1; + //$info['video']['resolution_x'] = ($PictureSizeEnc & 0xFF00) >> 8; + //$PictureSizeEnc = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 2)); + //$PictureSizeEnc <<= 1; + //$info['video']['resolution_y'] = ($PictureSizeEnc & 0xFF00) >> 8; + + $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 2)) >> 7; + $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2)) >> 7; + $info['video']['resolution_x'] = $PictureSizeEnc['x'] & 0xFF; + $info['video']['resolution_y'] = $PictureSizeEnc['y'] & 0xFF; + break; + + case 1: + $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 4, 3)) >> 7; + $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 3)) >> 7; + $info['video']['resolution_x'] = $PictureSizeEnc['x'] & 0xFFFF; + $info['video']['resolution_y'] = $PictureSizeEnc['y'] & 0xFFFF; + break; + + case 2: + $info['video']['resolution_x'] = 352; + $info['video']['resolution_y'] = 288; + break; + + case 3: + $info['video']['resolution_x'] = 176; + $info['video']['resolution_y'] = 144; + break; + + case 4: + $info['video']['resolution_x'] = 128; + $info['video']['resolution_y'] = 96; + break; + + case 5: + $info['video']['resolution_x'] = 320; + $info['video']['resolution_y'] = 240; + break; + + case 6: + $info['video']['resolution_x'] = 160; + $info['video']['resolution_y'] = 120; + break; + + default: + $info['video']['resolution_x'] = 0; + $info['video']['resolution_y'] = 0; + break; + + } + + } elseif ($info['flv']['video']['videoCodec'] == GETID3_FLV_VIDEO_VP6FLV_ALPHA) { + + /* contributed by schouwerwouØgmail*com */ + if (!isset($info['video']['resolution_x'])) { // only when meta data isn't set + $PictureSizeEnc['x'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 2)); + $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 7, 2)); + $info['video']['resolution_x'] = ($PictureSizeEnc['x'] & 0xFF) << 3; + $info['video']['resolution_y'] = ($PictureSizeEnc['y'] & 0xFF) << 3; + } + /* end schouwerwouØgmail*com */ + + } + if (!empty($info['video']['resolution_x']) && !empty($info['video']['resolution_y'])) { + $info['video']['pixel_aspect_ratio'] = $info['video']['resolution_x'] / $info['video']['resolution_y']; + } + } + break; + + // Meta tag + case GETID3_FLV_TAG_META: + if (!$found_meta) { + $found_meta = true; + $this->fseek(-1, SEEK_CUR); + $datachunk = $this->fread($DataLength); + $AMFstream = new AMFStream($datachunk); + $reader = new AMFReader($AMFstream); + $eventName = $reader->readData(); + $info['flv']['meta'][$eventName] = $reader->readData(); + unset($reader); + + $copykeys = array('framerate'=>'frame_rate', 'width'=>'resolution_x', 'height'=>'resolution_y', 'audiodatarate'=>'bitrate', 'videodatarate'=>'bitrate'); + foreach ($copykeys as $sourcekey => $destkey) { + if (isset($info['flv']['meta']['onMetaData'][$sourcekey])) { + switch ($sourcekey) { + case 'width': + case 'height': + $info['video'][$destkey] = intval(round($info['flv']['meta']['onMetaData'][$sourcekey])); + break; + case 'audiodatarate': + $info['audio'][$destkey] = getid3_lib::CastAsInt(round($info['flv']['meta']['onMetaData'][$sourcekey] * 1000)); + break; + case 'videodatarate': + case 'frame_rate': + default: + $info['video'][$destkey] = $info['flv']['meta']['onMetaData'][$sourcekey]; + break; + } + } + } + if (!empty($info['flv']['meta']['onMetaData']['duration'])) { + $found_valid_meta_playtime = true; + } + } + break; + + default: + // noop + break; + } + $this->fseek($NextOffset); + } + + $info['playtime_seconds'] = $Duration / 1000; + if ($info['playtime_seconds'] > 0) { + $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + } + + if ($info['flv']['header']['hasAudio']) { + $info['audio']['codec'] = self::audioFormatLookup($info['flv']['audio']['audioFormat']); + $info['audio']['sample_rate'] = self::audioRateLookup($info['flv']['audio']['audioRate']); + $info['audio']['bits_per_sample'] = self::audioBitDepthLookup($info['flv']['audio']['audioSampleSize']); + + $info['audio']['channels'] = $info['flv']['audio']['audioType'] + 1; // 0=mono,1=stereo + $info['audio']['lossless'] = ($info['flv']['audio']['audioFormat'] ? false : true); // 0=uncompressed + $info['audio']['dataformat'] = 'flv'; + } + if (!empty($info['flv']['header']['hasVideo'])) { + $info['video']['codec'] = self::videoCodecLookup($info['flv']['video']['videoCodec']); + $info['video']['dataformat'] = 'flv'; + $info['video']['lossless'] = false; + } + + // Set information from meta + if (!empty($info['flv']['meta']['onMetaData']['duration'])) { + $info['playtime_seconds'] = $info['flv']['meta']['onMetaData']['duration']; + $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + } + if (isset($info['flv']['meta']['onMetaData']['audiocodecid'])) { + $info['audio']['codec'] = self::audioFormatLookup($info['flv']['meta']['onMetaData']['audiocodecid']); + } + if (isset($info['flv']['meta']['onMetaData']['videocodecid'])) { + $info['video']['codec'] = self::videoCodecLookup($info['flv']['meta']['onMetaData']['videocodecid']); + } + return true; + } + + /** + * @param int $id + * + * @return string|false + */ + public static function audioFormatLookup($id) { + static $lookup = array( + 0 => 'Linear PCM, platform endian', + 1 => 'ADPCM', + 2 => 'mp3', + 3 => 'Linear PCM, little endian', + 4 => 'Nellymoser 16kHz mono', + 5 => 'Nellymoser 8kHz mono', + 6 => 'Nellymoser', + 7 => 'G.711A-law logarithmic PCM', + 8 => 'G.711 mu-law logarithmic PCM', + 9 => 'reserved', + 10 => 'AAC', + 11 => 'Speex', + 12 => false, // unknown? + 13 => false, // unknown? + 14 => 'mp3 8kHz', + 15 => 'Device-specific sound', + ); + return (isset($lookup[$id]) ? $lookup[$id] : false); + } + + /** + * @param int $id + * + * @return int|false + */ + public static function audioRateLookup($id) { + static $lookup = array( + 0 => 5500, + 1 => 11025, + 2 => 22050, + 3 => 44100, + ); + return (isset($lookup[$id]) ? $lookup[$id] : false); + } + + /** + * @param int $id + * + * @return int|false + */ + public static function audioBitDepthLookup($id) { + static $lookup = array( + 0 => 8, + 1 => 16, + ); + return (isset($lookup[$id]) ? $lookup[$id] : false); + } + + /** + * @param int $id + * + * @return string|false + */ + public static function videoCodecLookup($id) { + static $lookup = array( + GETID3_FLV_VIDEO_H263 => 'Sorenson H.263', + GETID3_FLV_VIDEO_SCREEN => 'Screen video', + GETID3_FLV_VIDEO_VP6FLV => 'On2 VP6', + GETID3_FLV_VIDEO_VP6FLV_ALPHA => 'On2 VP6 with alpha channel', + GETID3_FLV_VIDEO_SCREENV2 => 'Screen video v2', + GETID3_FLV_VIDEO_H264 => 'Sorenson H.264', + ); + return (isset($lookup[$id]) ? $lookup[$id] : false); + } +} + +class AMFStream +{ + /** + * @var string + */ + public $bytes; + + /** + * @var int + */ + public $pos; + + /** + * @param string $bytes + */ + public function __construct(&$bytes) { + $this->bytes =& $bytes; + $this->pos = 0; + } + + /** + * @return int + */ + public function readByte() { // 8-bit + return ord(substr($this->bytes, $this->pos++, 1)); + } + + /** + * @return int + */ + public function readInt() { // 16-bit + return ($this->readByte() << 8) + $this->readByte(); + } + + /** + * @return int + */ + public function readLong() { // 32-bit + return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte(); + } + + /** + * @return float|false + */ + public function readDouble() { + return getid3_lib::BigEndian2Float($this->read(8)); + } + + /** + * @return string + */ + public function readUTF() { + $length = $this->readInt(); + return $this->read($length); + } + + /** + * @return string + */ + public function readLongUTF() { + $length = $this->readLong(); + return $this->read($length); + } + + /** + * @param int $length + * + * @return string + */ + public function read($length) { + $val = substr($this->bytes, $this->pos, $length); + $this->pos += $length; + return $val; + } + + /** + * @return int + */ + public function peekByte() { + $pos = $this->pos; + $val = $this->readByte(); + $this->pos = $pos; + return $val; + } + + /** + * @return int + */ + public function peekInt() { + $pos = $this->pos; + $val = $this->readInt(); + $this->pos = $pos; + return $val; + } + + /** + * @return int + */ + public function peekLong() { + $pos = $this->pos; + $val = $this->readLong(); + $this->pos = $pos; + return $val; + } + + /** + * @return float|false + */ + public function peekDouble() { + $pos = $this->pos; + $val = $this->readDouble(); + $this->pos = $pos; + return $val; + } + + /** + * @return string + */ + public function peekUTF() { + $pos = $this->pos; + $val = $this->readUTF(); + $this->pos = $pos; + return $val; + } + + /** + * @return string + */ + public function peekLongUTF() { + $pos = $this->pos; + $val = $this->readLongUTF(); + $this->pos = $pos; + return $val; + } +} + +class AMFReader +{ + /** + * @var AMFStream + */ + public $stream; + + /** + * @param AMFStream $stream + */ + public function __construct(AMFStream $stream) { + $this->stream = $stream; + } + + /** + * @return mixed + */ + public function readData() { + $value = null; + + $type = $this->stream->readByte(); + switch ($type) { + + // Double + case 0: + $value = $this->readDouble(); + break; + + // Boolean + case 1: + $value = $this->readBoolean(); + break; + + // String + case 2: + $value = $this->readString(); + break; + + // Object + case 3: + $value = $this->readObject(); + break; + + // null + case 6: + return null; + + // Mixed array + case 8: + $value = $this->readMixedArray(); + break; + + // Array + case 10: + $value = $this->readArray(); + break; + + // Date + case 11: + $value = $this->readDate(); + break; + + // Long string + case 13: + $value = $this->readLongString(); + break; + + // XML (handled as string) + case 15: + $value = $this->readXML(); + break; + + // Typed object (handled as object) + case 16: + $value = $this->readTypedObject(); + break; + + // Long string + default: + $value = '(unknown or unsupported data type)'; + break; + } + + return $value; + } + + /** + * @return float|false + */ + public function readDouble() { + return $this->stream->readDouble(); + } + + /** + * @return bool + */ + public function readBoolean() { + return $this->stream->readByte() == 1; + } + + /** + * @return string + */ + public function readString() { + return $this->stream->readUTF(); + } + + /** + * @return array + */ + public function readObject() { + // Get highest numerical index - ignored +// $highestIndex = $this->stream->readLong(); + + $data = array(); + $key = null; + + while ($key = $this->stream->readUTF()) { + $data[$key] = $this->readData(); + } + // Mixed array record ends with empty string (0x00 0x00) and 0x09 + if (($key == '') && ($this->stream->peekByte() == 0x09)) { + // Consume byte + $this->stream->readByte(); + } + return $data; + } + + /** + * @return array + */ + public function readMixedArray() { + // Get highest numerical index - ignored + $highestIndex = $this->stream->readLong(); + + $data = array(); + $key = null; + + while ($key = $this->stream->readUTF()) { + if (is_numeric($key)) { + $key = (int) $key; + } + $data[$key] = $this->readData(); + } + // Mixed array record ends with empty string (0x00 0x00) and 0x09 + if (($key == '') && ($this->stream->peekByte() == 0x09)) { + // Consume byte + $this->stream->readByte(); + } + + return $data; + } + + /** + * @return array + */ + public function readArray() { + $length = $this->stream->readLong(); + $data = array(); + + for ($i = 0; $i < $length; $i++) { + $data[] = $this->readData(); + } + return $data; + } + + /** + * @return float|false + */ + public function readDate() { + $timestamp = $this->stream->readDouble(); + $timezone = $this->stream->readInt(); + return $timestamp; + } + + /** + * @return string + */ + public function readLongString() { + return $this->stream->readLongUTF(); + } + + /** + * @return string + */ + public function readXML() { + return $this->stream->readLongUTF(); + } + + /** + * @return array + */ + public function readTypedObject() { + $className = $this->stream->readUTF(); + return $this->readObject(); + } +} + +class AVCSequenceParameterSetReader +{ + /** + * @var string + */ + public $sps; + public $start = 0; + public $currentBytes = 0; + public $currentBits = 0; + + /** + * @var int + */ + public $width; + + /** + * @var int + */ + public $height; + + /** + * @param string $sps + */ + public function __construct($sps) { + $this->sps = $sps; + } + + public function readData() { + $this->skipBits(8); + $this->skipBits(8); + $profile = $this->getBits(8); // read profile + if ($profile > 0) { + $this->skipBits(8); + $level_idc = $this->getBits(8); // level_idc + $this->expGolombUe(); // seq_parameter_set_id // sps + $this->expGolombUe(); // log2_max_frame_num_minus4 + $picOrderType = $this->expGolombUe(); // pic_order_cnt_type + if ($picOrderType == 0) { + $this->expGolombUe(); // log2_max_pic_order_cnt_lsb_minus4 + } elseif ($picOrderType == 1) { + $this->skipBits(1); // delta_pic_order_always_zero_flag + $this->expGolombSe(); // offset_for_non_ref_pic + $this->expGolombSe(); // offset_for_top_to_bottom_field + $num_ref_frames_in_pic_order_cnt_cycle = $this->expGolombUe(); // num_ref_frames_in_pic_order_cnt_cycle + for ($i = 0; $i < $num_ref_frames_in_pic_order_cnt_cycle; $i++) { + $this->expGolombSe(); // offset_for_ref_frame[ i ] + } + } + $this->expGolombUe(); // num_ref_frames + $this->skipBits(1); // gaps_in_frame_num_value_allowed_flag + $pic_width_in_mbs_minus1 = $this->expGolombUe(); // pic_width_in_mbs_minus1 + $pic_height_in_map_units_minus1 = $this->expGolombUe(); // pic_height_in_map_units_minus1 + + $frame_mbs_only_flag = $this->getBits(1); // frame_mbs_only_flag + if ($frame_mbs_only_flag == 0) { + $this->skipBits(1); // mb_adaptive_frame_field_flag + } + $this->skipBits(1); // direct_8x8_inference_flag + $frame_cropping_flag = $this->getBits(1); // frame_cropping_flag + + $frame_crop_left_offset = 0; + $frame_crop_right_offset = 0; + $frame_crop_top_offset = 0; + $frame_crop_bottom_offset = 0; + + if ($frame_cropping_flag) { + $frame_crop_left_offset = $this->expGolombUe(); // frame_crop_left_offset + $frame_crop_right_offset = $this->expGolombUe(); // frame_crop_right_offset + $frame_crop_top_offset = $this->expGolombUe(); // frame_crop_top_offset + $frame_crop_bottom_offset = $this->expGolombUe(); // frame_crop_bottom_offset + } + $this->skipBits(1); // vui_parameters_present_flag + // etc + + $this->width = (($pic_width_in_mbs_minus1 + 1) * 16) - ($frame_crop_left_offset * 2) - ($frame_crop_right_offset * 2); + $this->height = ((2 - $frame_mbs_only_flag) * ($pic_height_in_map_units_minus1 + 1) * 16) - ($frame_crop_top_offset * 2) - ($frame_crop_bottom_offset * 2); + } + } + + /** + * @param int $bits + */ + public function skipBits($bits) { + $newBits = $this->currentBits + $bits; + $this->currentBytes += (int)floor($newBits / 8); + $this->currentBits = $newBits % 8; + } + + /** + * @return int + */ + public function getBit() { + $result = (getid3_lib::BigEndian2Int(substr($this->sps, $this->currentBytes, 1)) >> (7 - $this->currentBits)) & 0x01; + $this->skipBits(1); + return $result; + } + + /** + * @param int $bits + * + * @return int + */ + public function getBits($bits) { + $result = 0; + for ($i = 0; $i < $bits; $i++) { + $result = ($result << 1) + $this->getBit(); + } + return $result; + } + + /** + * @return int + */ + public function expGolombUe() { + $significantBits = 0; + $bit = $this->getBit(); + while ($bit == 0) { + $significantBits++; + $bit = $this->getBit(); + + if ($significantBits > 31) { + // something is broken, this is an emergency escape to prevent infinite loops + return 0; + } + } + return (1 << $significantBits) + $this->getBits($significantBits) - 1; + } + + /** + * @return int + */ + public function expGolombSe() { + $result = $this->expGolombUe(); + if (($result & 0x01) == 0) { + return -($result >> 1); + } else { + return ($result + 1) >> 1; + } + } + + /** + * @return int + */ + public function getWidth() { + return $this->width; + } + + /** + * @return int + */ + public function getHeight() { + return $this->height; + } +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.ivf.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.ivf.php new file mode 100644 index 00000000..293cc99b --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.ivf.php @@ -0,0 +1,81 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.ivf.php // +// module for analyzing IVF audio-video files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_ivf extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'ivf'; + $info['video']['dataformat'] = 'ivf'; + + $this->fseek($info['avdataoffset']); + $IVFheader = $this->fread(32); + + if (substr($IVFheader, 0, 4) == 'DKIF') { + + // https://wiki.multimedia.cx/index.php/IVF + $info['ivf']['header']['signature'] = substr($IVFheader, 0, 4); + $info['ivf']['header']['version'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 4, 2)); // should be 0 + $info['ivf']['header']['headersize'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 6, 2)); + $info['ivf']['header']['fourcc'] = substr($IVFheader, 8, 4); + $info['ivf']['header']['resolution_x'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 12, 2)); + $info['ivf']['header']['resolution_y'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 14, 2)); + $info['ivf']['header']['timebase_numerator'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 16, 4)); + $info['ivf']['header']['timebase_denominator'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 20, 4)); + $info['ivf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 24, 4)); + //$info['ivf']['header']['reserved'] = substr($IVFheader, 28, 4); + + $info['ivf']['header']['frame_rate'] = (float) $info['ivf']['header']['timebase_numerator'] / $info['ivf']['header']['timebase_denominator']; + + if ($info['ivf']['header']['version'] > 0) { + $this->warning('Expecting IVF header version 0, found version '.$info['ivf']['header']['version'].', results may not be accurate'); + } + + $info['video']['resolution_x'] = $info['ivf']['header']['resolution_x']; + $info['video']['resolution_y'] = $info['ivf']['header']['resolution_y']; + $info['video']['codec'] = $info['ivf']['header']['fourcc']; + + $info['ivf']['frame_count'] = 0; + $timestamp = 0; + while (!$this->feof()) { + if ($frameheader = $this->fread(12)) { + $framesize = getid3_lib::LittleEndian2Int(substr($frameheader, 0, 4)); // size of frame in bytes (not including the 12-byte header) + $timestamp = getid3_lib::LittleEndian2Int(substr($frameheader, 4, 8)); // 64-bit presentation timestamp + $this->fseek($framesize, SEEK_CUR); + $info['ivf']['frame_count']++; + } + } + if ($info['ivf']['frame_count']) { + $info['playtime_seconds'] = $timestamp / 100000; + $info['video']['frame_rate'] = (float) $info['ivf']['frame_count'] / $info['playtime_seconds']; + } + + } else { + $this->error('Expecting "DKIF" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($IVFheader, 0, 4)).'"'); + return false; + } + + return true; + } + +} diff --git a/serendipity_event_podcast/player/getid3/module.audio-video.matroska.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.matroska.php similarity index 50% rename from serendipity_event_podcast/player/getid3/module.audio-video.matroska.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.matroska.php index 47f7afa6..128e614e 100644 --- a/serendipity_event_podcast/player/getid3/module.audio-video.matroska.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.matroska.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.audio-video.matriska.php // @@ -13,10 +14,13 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} define('EBML_ID_CHAPTERS', 0x0043A770); // [10][43][A7][70] -- A system to define basic menus and partition data. For more detailed information, look at the Chapters Explanation. define('EBML_ID_SEEKHEAD', 0x014D9B74); // [11][4D][9B][74] -- Contains the position of other level 1 elements. -define('EBML_ID_TAGS', 0x0254C367); // [12][54][C3][67] -- Element containing elements specific to Tracks/Chapters. A list of valid tags can be found here. +define('EBML_ID_TAGS', 0x0254C367); // [12][54][C3][67] -- Element containing elements specific to Tracks/Chapters. A list of valid tags can be found . define('EBML_ID_INFO', 0x0549A966); // [15][49][A9][66] -- Contains miscellaneous general information and statistics on the file. define('EBML_ID_TRACKS', 0x0654AE6B); // [16][54][AE][6B] -- A top-level block of information with many tracks described. define('EBML_ID_SEGMENT', 0x08538067); // [18][53][80][67] -- This element contains all other top-level (level 1) elements. Typically a Matroska file is composed of 1 segment. @@ -71,7 +75,7 @@ define('EBML_ID_FILEREFERRAL', 0x0675); // [46][75] -- define('EBML_ID_FILEDESCRIPTION', 0x067E); // [46][7E] -- A human-friendly name for the attached file. define('EBML_ID_FILEUID', 0x06AE); // [46][AE] -- Unique ID representing the file, as random as possible. define('EBML_ID_CONTENTENCALGO', 0x07E1); // [47][E1] -- The encryption algorithm used. The value '0' means that the contents have not been encrypted but only signed. Predefined values: -define('EBML_ID_CONTENTENCKEYID', 0x07E2); // [47][E2] -- For public key algorithms this is the ID of the public key the the data was encrypted with. +define('EBML_ID_CONTENTENCKEYID', 0x07E2); // [47][E2] -- For public key algorithms this is the ID of the public key the data was encrypted with. define('EBML_ID_CONTENTSIGNATURE', 0x07E3); // [47][E3] -- A cryptographic signature of the contents. define('EBML_ID_CONTENTSIGKEYID', 0x07E4); // [47][E4] -- This is the ID of the private key the data was signed with. define('EBML_ID_CONTENTSIGALGO', 0x07E5); // [47][E5] -- The algorithm used for the signature. A value of '0' means that the contents have not been signed but only encrypted. Predefined values: @@ -89,7 +93,8 @@ define('EBML_ID_CUEBLOCKNUMBER', 0x1378); // [53][78] -- define('EBML_ID_TRACKOFFSET', 0x137F); // [53][7F] -- A value to add to the Block's Timecode. This can be used to adjust the playback offset of a track. define('EBML_ID_SEEKID', 0x13AB); // [53][AB] -- The binary ID corresponding to the element name. define('EBML_ID_SEEKPOSITION', 0x13AC); // [53][AC] -- The position of the element in the segment in octets (0 = first level 1 element). -define('EBML_ID_STEREOMODE', 0x13B8); // [53][B8] -- Stereo-3D video mode on 2 bits (0: mono, 1: right eye, 2: left eye, 3: both eyes). +define('EBML_ID_STEREOMODE', 0x13B8); // [53][B8] -- Stereo-3D video mode. +define('EBML_ID_OLDSTEREOMODE', 0x13B9); // [53][B9] -- Bogus StereoMode value used in old versions of libmatroska. DO NOT USE. (0: mono, 1: right eye, 2: left eye, 3: both eyes). define('EBML_ID_PIXELCROPBOTTOM', 0x14AA); // [54][AA] -- The number of video pixels to remove at the bottom of the image (for HDTV content). define('EBML_ID_DISPLAYWIDTH', 0x14B0); // [54][B0] -- Width of the video frames to display. define('EBML_ID_DISPLAYUNIT', 0x14B2); // [54][B2] -- Type of the unit for DisplayWidth/Height (0: pixels, 1: centimeters, 2: inches). @@ -111,7 +116,7 @@ define('EBML_ID_TARGETS', 0x23C0); // [63][C0] -- define('EBML_ID_CHAPTERPHYSICALEQUIV', 0x23C3); // [63][C3] -- Specify the physical equivalent of this ChapterAtom like "DVD" (60) or "SIDE" (50), see complete list of values. define('EBML_ID_TAGCHAPTERUID', 0x23C4); // [63][C4] -- A unique ID to identify the Chapter(s) the tags belong to. If the value is 0 at this level, the tags apply to all chapters in the Segment. define('EBML_ID_TAGTRACKUID', 0x23C5); // [63][C5] -- A unique ID to identify the Track(s) the tags belong to. If the value is 0 at this level, the tags apply to all tracks in the Segment. -define('EBML_ID_ATTACHMENTUID', 0x23C6); // [63][C6] -- A unique ID to identify the Attachment(s) the tags belong to. If the value is 0 at this level, the tags apply to all the attachments in the Segment. +define('EBML_ID_TAGATTACHMENTUID', 0x23C6); // [63][C6] -- A unique ID to identify the Attachment(s) the tags belong to. If the value is 0 at this level, the tags apply to all the attachments in the Segment. define('EBML_ID_TAGEDITIONUID', 0x23C9); // [63][C9] -- A unique ID to identify the EditionEntry(s) the tags belong to. If the value is 0 at this level, the tags apply to all editions in the Segment. define('EBML_ID_TARGETTYPE', 0x23CA); // [63][CA] -- An informational string that can be used to display the logical level of the target like "ALBUM", "TRACK", "MOVIE", "CHAPTER", etc (see TargetType). define('EBML_ID_TRACKTRANSLATE', 0x2624); // [66][24] -- The track identification for the given Chapter Codec. @@ -205,198 +210,462 @@ define('EBML_ID_CLUSTERREFERENCEBLOCK', 0x7B); // [FB] -- define('EBML_ID_CLUSTERREFERENCEVIRTUAL', 0x7D); // [FD] -- Relative position of the data that should be in position of the virtual block. -class getid3_matroska +/** +* @tutorial http://www.matroska.org/technical/specs/index.html +* +* @todo Rewrite EBML parser to reduce it's size and honor default element values +* @todo After rewrite implement stream size calculation, that will provide additional useful info and enable AAC/FLAC audio bitrate detection +*/ +class getid3_matroska extends getid3_handler { - var $read_buffer_size = 32768; // size of read buffer, 32kB is default - var $hide_clusters = true; // if true, do not return information about CLUSTER chunks, since there's a lot of them and they're not usually useful - var $warnings = array(); + /** + * If true, do not return information about CLUSTER chunks, since there's a lot of them + * and they're not usually useful [default: TRUE]. + * + * @var bool + */ + public $hide_clusters = true; - function getid3_matroska(&$fd, &$ThisFileInfo) { + /** + * True to parse the whole file, not only header [default: FALSE]. + * + * @var bool + */ + public $parse_whole_file = false; - // http://www.matroska.org/technical/specs/index.html#EBMLBasics - $offset = $ThisFileInfo['avdataoffset']; - $EBMLdata = ''; - $EBMLdata_offset = $offset; + /* + * Private parser settings/placeholders. + */ + private $EBMLbuffer = ''; + private $EBMLbuffer_offset = 0; + private $EBMLbuffer_length = 0; + private $current_offset = 0; + private $unuseful_elements = array(EBML_ID_CRC32, EBML_ID_VOID); - if (!getid3_lib::intValueSupported($ThisFileInfo['avdataend'])) { - $this->warnings[] = 'This version of getID3() may or may not correctly handle Matroska files larger than '.round(PHP_INT_MAX / 1073741824).'GB'; + /** + * @return bool + */ + public function Analyze() + { + $info = &$this->getid3->info; + + // parse container + try { + $this->parseEBML($info); + } catch (Exception $e) { + $this->error('EBML parser: '.$e->getMessage()); } - while ($offset < $ThisFileInfo['avdataend']) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - - $top_element_offset = $offset; - $top_element_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $top_element_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - if ($top_element_length === false) { - $this->warnings[] = 'invalid chunk length at '.$top_element_offset; - $offset = pow(2, 63); - break; + // calculate playtime + if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) { + foreach ($info['matroska']['info'] as $key => $infoarray) { + if (isset($infoarray['Duration'])) { + // TimecodeScale is how many nanoseconds each Duration unit is + $info['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000); + break; + } } - $top_element_endoffset = $offset + $top_element_length; - switch ($top_element_id) { - case EBML_ID_EBML: - $ThisFileInfo['fileformat'] = 'matroska'; - $ThisFileInfo['matroska']['header']['offset'] = $top_element_offset; - $ThisFileInfo['matroska']['header']['length'] = $top_element_length; + } - while ($offset < $top_element_endoffset) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $element_data = array(); - $element_data_offset = $offset; - $element_data['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $element_data['id_name'] = $this->EBMLidName($element_data['id']); - $element_data['length'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $end_offset = $offset + $element_data['length']; + // extract tags + if (isset($info['matroska']['tags']) && is_array($info['matroska']['tags'])) { + foreach ($info['matroska']['tags'] as $key => $infoarray) { + $this->ExtractCommentsSimpleTag($infoarray); + } + } - switch ($element_data['id']) { - case EBML_ID_VOID: // padding, ignore + // process tracks + if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) { + foreach ($info['matroska']['tracks']['tracks'] as $key => $trackarray) { + + $track_info = array(); + $track_info['dataformat'] = self::CodecIDtoCommonName($trackarray['CodecID']); + $track_info['default'] = (isset($trackarray['FlagDefault']) ? $trackarray['FlagDefault'] : true); + if (isset($trackarray['Name'])) { $track_info['name'] = $trackarray['Name']; } + + switch ($trackarray['TrackType']) { + + case 1: // Video + $track_info['resolution_x'] = $trackarray['PixelWidth']; + $track_info['resolution_y'] = $trackarray['PixelHeight']; + $track_info['display_unit'] = self::displayUnit(isset($trackarray['DisplayUnit']) ? $trackarray['DisplayUnit'] : 0); + $track_info['display_x'] = (isset($trackarray['DisplayWidth']) ? $trackarray['DisplayWidth'] : $trackarray['PixelWidth']); + $track_info['display_y'] = (isset($trackarray['DisplayHeight']) ? $trackarray['DisplayHeight'] : $trackarray['PixelHeight']); + + if (isset($trackarray['PixelCropBottom'])) { $track_info['crop_bottom'] = $trackarray['PixelCropBottom']; } + if (isset($trackarray['PixelCropTop'])) { $track_info['crop_top'] = $trackarray['PixelCropTop']; } + if (isset($trackarray['PixelCropLeft'])) { $track_info['crop_left'] = $trackarray['PixelCropLeft']; } + if (isset($trackarray['PixelCropRight'])) { $track_info['crop_right'] = $trackarray['PixelCropRight']; } + if (isset($trackarray['DefaultDuration'])) { $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3); } + if (isset($trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; } + + switch ($trackarray['CodecID']) { + case 'V_MS/VFW/FOURCC': + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); + + $parsed = getid3_riff::ParseBITMAPINFOHEADER($trackarray['CodecPrivate']); + $track_info['codec'] = getid3_riff::fourccLookup($parsed['fourcc']); + $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed; break; + + /*case 'V_MPEG4/ISO/AVC': + $h264['profile'] = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 1, 1)); + $h264['level'] = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 3, 1)); + $rn = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 4, 1)); + $h264['NALUlength'] = ($rn & 3) + 1; + $rn = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], 5, 1)); + $nsps = ($rn & 31); + $offset = 6; + for ($i = 0; $i < $nsps; $i ++) { + $length = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 2)); + $h264['SPS'][] = substr($trackarray['CodecPrivate'], $offset + 2, $length); + $offset += 2 + $length; + } + $npps = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 1)); + $offset += 1; + for ($i = 0; $i < $npps; $i ++) { + $length = getid3_lib::BigEndian2Int(substr($trackarray['CodecPrivate'], $offset, 2)); + $h264['PPS'][] = substr($trackarray['CodecPrivate'], $offset + 2, $length); + $offset += 2 + $length; + } + $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $h264; + break;*/ + } + + $info['video']['streams'][$trackarray['TrackUID']] = $track_info; + break; + + case 2: // Audio + $track_info['sample_rate'] = (isset($trackarray['SamplingFrequency']) ? $trackarray['SamplingFrequency'] : 8000.0); + $track_info['channels'] = (isset($trackarray['Channels']) ? $trackarray['Channels'] : 1); + $track_info['language'] = (isset($trackarray['Language']) ? $trackarray['Language'] : 'eng'); + if (isset($trackarray['BitDepth'])) { $track_info['bits_per_sample'] = $trackarray['BitDepth']; } + if (isset($trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; } + + switch ($trackarray['CodecID']) { + case 'A_PCM/INT/LIT': + case 'A_PCM/INT/BIG': + $track_info['bitrate'] = $track_info['sample_rate'] * $track_info['channels'] * $trackarray['BitDepth']; + break; + + case 'A_AC3': + case 'A_EAC3': + case 'A_DTS': + case 'A_MPEG/L3': + case 'A_MPEG/L2': + case 'A_FLAC': + $module_dataformat = ($track_info['dataformat'] == 'mp2' ? 'mp3' : ($track_info['dataformat'] == 'eac3' ? 'ac3' : $track_info['dataformat'])); + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.'.$module_dataformat.'.php', __FILE__, true); + + if (!isset($info['matroska']['track_data_offsets'][$trackarray['TrackNumber']])) { + $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because $info[matroska][track_data_offsets]['.$trackarray['TrackNumber'].'] not set'); + break; + } + + // create temp instance + $getid3_temp = new getID3(); + if ($track_info['dataformat'] != 'flac') { + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + } + $getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset']; + if ($track_info['dataformat'][0] == 'm' || $track_info['dataformat'] == 'flac') { + $getid3_temp->info['avdataend'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'] + $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['length']; + } + + // analyze + $class = 'getid3_'.$module_dataformat; + $header_data_key = $track_info['dataformat'][0] == 'm' ? 'mpeg' : $track_info['dataformat']; + $getid3_audio = new $class($getid3_temp, __CLASS__); + if ($track_info['dataformat'] == 'flac') { + $getid3_audio->AnalyzeString($trackarray['CodecPrivate']); + } + else { + $getid3_audio->Analyze(); + } + if (!empty($getid3_temp->info[$header_data_key])) { + $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info[$header_data_key]; + if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) { + foreach ($getid3_temp->info['audio'] as $sub_key => $value) { + $track_info[$sub_key] = $value; + } + } + } + else { + $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because '.$class.'::Analyze() failed at offset '.$getid3_temp->info['avdataoffset']); + } + + // copy errors and warnings + if (!empty($getid3_temp->info['error'])) { + foreach ($getid3_temp->info['error'] as $newerror) { + $this->warning($class.'() says: ['.$newerror.']'); + } + } + if (!empty($getid3_temp->info['warning'])) { + foreach ($getid3_temp->info['warning'] as $newerror) { + $this->warning($class.'() says: ['.$newerror.']'); + } + } + unset($getid3_temp, $getid3_audio); + break; + + case 'A_AAC': + case 'A_AAC/MPEG2/LC': + case 'A_AAC/MPEG2/LC/SBR': + case 'A_AAC/MPEG4/LC': + case 'A_AAC/MPEG4/LC/SBR': + $this->warning($trackarray['CodecID'].' audio data contains no header, audio/video bitrates can\'t be calculated'); + break; + + case 'A_VORBIS': + if (!isset($trackarray['CodecPrivate'])) { + $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data not set'); + break; + } + $vorbis_offset = strpos($trackarray['CodecPrivate'], 'vorbis', 1); + if ($vorbis_offset === false) { + $this->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data does not contain "vorbis" keyword'); + break; + } + $vorbis_offset -= 1; + + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, true); + + // create temp instance + $getid3_temp = new getID3(); + + // analyze + $getid3_ogg = new getid3_ogg($getid3_temp); + $oggpageinfo['page_seqno'] = 0; + $getid3_ogg->ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset, $oggpageinfo); + if (!empty($getid3_temp->info['ogg'])) { + $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info['ogg']; + if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) { + foreach ($getid3_temp->info['audio'] as $sub_key => $value) { + $track_info[$sub_key] = $value; + } + } + } + + // copy errors and warnings + if (!empty($getid3_temp->info['error'])) { + foreach ($getid3_temp->info['error'] as $newerror) { + $this->warning('getid3_ogg() says: ['.$newerror.']'); + } + } + if (!empty($getid3_temp->info['warning'])) { + foreach ($getid3_temp->info['warning'] as $newerror) { + $this->warning('getid3_ogg() says: ['.$newerror.']'); + } + } + + if (!empty($getid3_temp->info['ogg']['bitrate_nominal'])) { + $track_info['bitrate'] = $getid3_temp->info['ogg']['bitrate_nominal']; + } + unset($getid3_temp, $getid3_ogg, $oggpageinfo, $vorbis_offset); + break; + + case 'A_MS/ACM': + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); + + $parsed = getid3_riff::parseWAVEFORMATex($trackarray['CodecPrivate']); + foreach ($parsed as $sub_key => $value) { + if ($sub_key != 'raw') { + $track_info[$sub_key] = $value; + } + } + $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed; + break; + + default: + $this->warning('Unhandled audio type "'.(isset($trackarray['CodecID']) ? $trackarray['CodecID'] : '').'"'); + break; + } + + $info['audio']['streams'][$trackarray['TrackUID']] = $track_info; + break; + } + } + + if (!empty($info['video']['streams'])) { + $info['video'] = self::getDefaultStreamInfo($info['video']['streams']); + } + if (!empty($info['audio']['streams'])) { + $info['audio'] = self::getDefaultStreamInfo($info['audio']['streams']); + } + } + + // process attachments + if (isset($info['matroska']['attachments']) && $this->getid3->option_save_attachments !== getID3::ATTACHMENTS_NONE) { + foreach ($info['matroska']['attachments'] as $i => $entry) { + if (strpos($entry['FileMimeType'], 'image/') === 0 && !empty($entry['FileData'])) { + $info['matroska']['comments']['picture'][] = array('data' => $entry['FileData'], 'image_mime' => $entry['FileMimeType'], 'filename' => $entry['FileName']); + } + } + } + + // determine mime type + if (!empty($info['video']['streams'])) { + $info['mime_type'] = ($info['matroska']['doctype'] == 'webm' ? 'video/webm' : 'video/x-matroska'); + } elseif (!empty($info['audio']['streams'])) { + $info['mime_type'] = ($info['matroska']['doctype'] == 'webm' ? 'audio/webm' : 'audio/x-matroska'); + } elseif (isset($info['mime_type'])) { + unset($info['mime_type']); + } + + // use _STATISTICS_TAGS if available to set audio/video bitrates + if (!empty($info['matroska']['tags'])) { + $_STATISTICS_byTrackUID = array(); + foreach ($info['matroska']['tags'] as $key1 => $value1) { + if (!empty($value1['Targets']['TagTrackUID'][0]) && !empty($value1['SimpleTag'])) { + foreach ($value1['SimpleTag'] as $key2 => $value2) { + if (!empty($value2['TagName']) && isset($value2['TagString'])) { + $_STATISTICS_byTrackUID[$value1['Targets']['TagTrackUID'][0]][$value2['TagName']] = $value2['TagString']; + } + } + } + } + foreach (array('audio','video') as $avtype) { + if (!empty($info[$avtype]['streams'])) { + foreach ($info[$avtype]['streams'] as $trackUID => $trackdata) { + if (!isset($trackdata['bitrate']) && !empty($_STATISTICS_byTrackUID[$trackUID]['BPS'])) { + $info[$avtype]['streams'][$trackUID]['bitrate'] = (int) $_STATISTICS_byTrackUID[$trackUID]['BPS']; + @$info[$avtype]['bitrate'] += $info[$avtype]['streams'][$trackUID]['bitrate']; + } + } + } + } + } + + return true; + } + + /** + * @param array $info + */ + private function parseEBML(&$info) { + // http://www.matroska.org/technical/specs/index.html#EBMLBasics + $this->current_offset = $info['avdataoffset']; + + while ($this->getEBMLelement($top_element, $info['avdataend'])) { + switch ($top_element['id']) { + + case EBML_ID_EBML: + $info['matroska']['header']['offset'] = $top_element['offset']; + $info['matroska']['header']['length'] = $top_element['length']; + + while ($this->getEBMLelement($element_data, $top_element['end'], true)) { + switch ($element_data['id']) { + case EBML_ID_EBMLVERSION: case EBML_ID_EBMLREADVERSION: case EBML_ID_EBMLMAXIDLENGTH: case EBML_ID_EBMLMAXSIZELENGTH: case EBML_ID_DOCTYPEVERSION: case EBML_ID_DOCTYPEREADVERSION: - $element_data['data'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $element_data['length'])); + $element_data['data'] = getid3_lib::BigEndian2Int($element_data['data']); break; + case EBML_ID_DOCTYPE: - $element_data['data'] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $element_data['length']), "\x00"); + $element_data['data'] = getid3_lib::trimNullByte($element_data['data']); + $info['matroska']['doctype'] = $element_data['data']; + $info['fileformat'] = $element_data['data']; break; + default: - $this->warnings[] = 'Unhandled track.video element ['.basename(__FILE__).':'.__LINE__.'] ('.$element_data['id'].'::'.$element_data['id_name'].') at '.$element_data_offset; + $this->unhandledElement('header', __LINE__, $element_data); break; } - $offset = $end_offset; - $ThisFileInfo['matroska']['header']['elements'][] = $element_data; + + unset($element_data['offset'], $element_data['end']); + $info['matroska']['header']['elements'][] = $element_data; } break; - case EBML_ID_SEGMENT: - $ThisFileInfo['matroska']['segment'][0]['offset'] = $top_element_offset; - $ThisFileInfo['matroska']['segment'][0]['length'] = $top_element_length; + $info['matroska']['segment'][0]['offset'] = $top_element['offset']; + $info['matroska']['segment'][0]['length'] = $top_element['length']; - $segment_key = -1; - while ($offset < $ThisFileInfo['avdataend']) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - - $element_data = array(); - $element_data['offset'] = $offset; - $element_data['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $element_data['id_name'] = $this->EBMLidName($element_data['id']); - $element_data['length'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - if ($element_data['length'] === false) { - $this->warnings[] = 'invalid chunk length at '.$element_data['offset']; - //$offset = pow(2, 63); - $offset = $ThisFileInfo['avdataend']; - break; + while ($this->getEBMLelement($element_data, $top_element['end'])) { + if ($element_data['id'] != EBML_ID_CLUSTER || !$this->hide_clusters) { // collect clusters only if required + $info['matroska']['segments'][] = $element_data; } - $element_end = $offset + $element_data['length']; switch ($element_data['id']) { - //case EBML_ID_CLUSTER: - // // too many cluster entries, probably not useful - // break; - case false: - $this->warnings[] = 'invalid ID at '.$element_data['offset']; - $offset = $element_end; - continue 3; - default: - $ThisFileInfo['matroska']['segments'][] = $element_data; - break; - } - $segment_key++; - switch ($element_data['id']) { - case EBML_ID_SEEKHEAD: // Contains the position of other level 1 elements - while ($offset < $element_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $seek_entry = array(); - $seek_entry['offset'] = $offset; - $seek_entry['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $seek_entry['id_name'] = $this->EBMLidName($seek_entry['id']); - $seek_entry['length'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $seek_end_offset = $offset + $seek_entry['length']; + case EBML_ID_SEEKHEAD: // Contains the position of other level 1 elements. + + while ($this->getEBMLelement($seek_entry, $element_data['end'])) { switch ($seek_entry['id']) { + case EBML_ID_SEEK: // Contains a single seek entry to an EBML element - while ($offset < $seek_end_offset) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $value = substr($EBMLdata, $offset - $EBMLdata_offset, $length); - $offset += $length; - switch ($id) { + while ($this->getEBMLelement($sub_seek_entry, $seek_entry['end'], true)) { + + switch ($sub_seek_entry['id']) { + case EBML_ID_SEEKID: - $dummy = 0; - $seek_entry['target_id'] = $this->readEBMLint($value, $dummy); - $seek_entry['target_name'] = $this->EBMLidName($seek_entry['target_id']); + $seek_entry['target_id'] = self::EBML2Int($sub_seek_entry['data']); + $seek_entry['target_name'] = self::EBMLidName($seek_entry['target_id']); break; + case EBML_ID_SEEKPOSITION: - $seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($value); + $seek_entry['target_offset'] = $element_data['offset'] + getid3_lib::BigEndian2Int($sub_seek_entry['data']); break; + default: - $ThisFileInfo['error'][] = 'Unhandled segment ['.basename(__FILE__).':'.__LINE__.'] ('.$id.') at '.$offset; + $this->unhandledElement('seekhead.seek', __LINE__, $sub_seek_entry); } break; - } } - $ThisFileInfo['matroska']['seek'][] = $seek_entry; - //switch ($seek_entry['target_id']) { - // case EBML_ID_CLUSTER: - // // too many cluster seek points, probably not useful - // break; - // default: - // $ThisFileInfo['matroska']['seek'][] = $seek_entry; - // break; - //} + if (!isset($seek_entry['target_id'])) { + $this->warning('seek_entry[target_id] unexpectedly not set at '.$seek_entry['offset']); + break; + } + if (($seek_entry['target_id'] != EBML_ID_CLUSTER) || !$this->hide_clusters) { // collect clusters only if required + $info['matroska']['seek'][] = $seek_entry; + } break; + default: - $this->warnings[] = 'Unhandled seekhead element ['.basename(__FILE__).':'.__LINE__.'] ('.$seek_entry['id'].') at '.$offset; + $this->unhandledElement('seekhead', __LINE__, $seek_entry); break; } - $offset = $seek_end_offset; } break; - case EBML_ID_TRACKS: // information about all tracks in segment - $ThisFileInfo['matroska']['tracks'] = $element_data; - while ($offset < $element_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $track_entry = array(); - $track_entry['offset'] = $offset; - $track_entry['id'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $track_entry['id_name'] = $this->EBMLidName($track_entry['id']); - $track_entry['length'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $track_entry_endoffset = $offset + $track_entry['length']; + case EBML_ID_TRACKS: // A top-level block of information with many tracks described. + $info['matroska']['tracks'] = $element_data; + + while ($this->getEBMLelement($track_entry, $element_data['end'])) { switch ($track_entry['id']) { + case EBML_ID_TRACKENTRY: //subelements: Describes a track with all elements. - while ($offset < $track_entry_endoffset) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $subelement_offset = $offset; - $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $subelement_idname = $this->EBMLidName($subelement_id); - $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $subelement_end = $offset + $subelement_length; - switch ($subelement_id) { - case EBML_ID_TRACKNUMBER: + + while ($this->getEBMLelement($subelement, $track_entry['end'], array(EBML_ID_VIDEO, EBML_ID_AUDIO, EBML_ID_CONTENTENCODINGS, EBML_ID_CODECPRIVATE))) { + switch ($subelement['id']) { + case EBML_ID_TRACKUID: + $track_entry[$subelement['id_name']] = getid3_lib::PrintHexBytes($subelement['data'], true, false); + break; + case EBML_ID_TRACKNUMBER: case EBML_ID_TRACKTYPE: case EBML_ID_MINCACHE: case EBML_ID_MAXCACHE: case EBML_ID_MAXBLOCKADDITIONID: case EBML_ID_DEFAULTDURATION: // nanoseconds per frame - $track_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length)); + $track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); break; case EBML_ID_TRACKTIMECODESCALE: - $track_entry[$subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length)); + $track_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']); break; case EBML_ID_CODECID: case EBML_ID_LANGUAGE: case EBML_ID_NAME: case EBML_ID_CODECNAME: + $track_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); + break; + case EBML_ID_CODECPRIVATE: - $track_entry[$subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "\x00"); + $track_entry[$subelement['id_name']] = $this->readEBMLelementData($subelement['length'], true); break; case EBML_ID_FLAGENABLED: @@ -404,21 +673,16 @@ class getid3_matroska case EBML_ID_FLAGFORCED: case EBML_ID_FLAGLACING: case EBML_ID_CODECDECODEALL: - $track_entry[$subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length)); + $track_entry[$subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($subelement['data']); break; case EBML_ID_VIDEO: - while ($offset < $subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_offset = $offset; - $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_idname = $this->EBMLidName($sub_subelement_id); - $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_end = $offset + $sub_subelement_length; - switch ($sub_subelement_id) { + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { + switch ($sub_subelement['id']) { + case EBML_ID_PIXELWIDTH: case EBML_ID_PIXELHEIGHT: - case EBML_ID_STEREOMODE: case EBML_ID_PIXELCROPBOTTOM: case EBML_ID_PIXELCROPTOP: case EBML_ID_PIXELCROPLEFT: @@ -427,1009 +691,626 @@ class getid3_matroska case EBML_ID_DISPLAYHEIGHT: case EBML_ID_DISPLAYUNIT: case EBML_ID_ASPECTRATIOTYPE: - $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length)); + case EBML_ID_STEREOMODE: + case EBML_ID_OLDSTEREOMODE: + $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); break; - case EBML_ID_FLAGINTERLACED: - $track_entry[$sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length)); - break; - case EBML_ID_GAMMAVALUE: - $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length)); - break; - case EBML_ID_COLOURSPACE: - $track_entry[$sub_subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), "\x00"); - break; - default: - $this->warnings[] = 'Unhandled track.video element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset; - break; - } - $offset = $sub_subelement_end; - } - if (isset($track_entry[$this->EBMLidName(EBML_ID_CODECID)]) && ($track_entry[$this->EBMLidName(EBML_ID_CODECID)] == 'V_MS/VFW/FOURCC') && isset($track_entry[$this->EBMLidName(EBML_ID_CODECPRIVATE)])) { - if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, false)) { - $track_entry['codec_private_parsed'] = getid3_riff::ParseBITMAPINFOHEADER($track_entry[$this->EBMLidName(EBML_ID_CODECPRIVATE)]); - } else { - $this->warnings[] = 'Unable to parse codec private data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio-video.riff.php"'; + case EBML_ID_FLAGINTERLACED: + $track_entry[$sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_subelement['data']); + break; + + case EBML_ID_GAMMAVALUE: + $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']); + break; + + case EBML_ID_COLOURSPACE: + $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); + break; + + default: + $this->unhandledElement('track.video', __LINE__, $sub_subelement); + break; } } break; case EBML_ID_AUDIO: - while ($offset < $subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_offset = $offset; - $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_idname = $this->EBMLidName($sub_subelement_id); - $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_end = $offset + $sub_subelement_length; - switch ($sub_subelement_id) { + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { + switch ($sub_subelement['id']) { + case EBML_ID_CHANNELS: case EBML_ID_BITDEPTH: - $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length)); + $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); break; + case EBML_ID_SAMPLINGFREQUENCY: case EBML_ID_OUTPUTSAMPLINGFREQUENCY: - $track_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length)); + $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']); break; + case EBML_ID_CHANNELPOSITIONS: - $track_entry[$sub_subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), "\x00"); + $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); break; + default: - $this->warnings[] = 'Unhandled track.video element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset; + $this->unhandledElement('track.audio', __LINE__, $sub_subelement); break; } - $offset = $sub_subelement_end; } break; case EBML_ID_CONTENTENCODINGS: - while ($offset < $subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_offset = $offset; - $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_idname = $this->EBMLidName($sub_subelement_id); - $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_end = $offset + $sub_subelement_length; - switch ($sub_subelement_id) { + + while ($this->getEBMLelement($sub_subelement, $subelement['end'])) { + switch ($sub_subelement['id']) { + case EBML_ID_CONTENTENCODING: - while ($offset < $sub_subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_offset = $offset; - $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id); - $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_end = $offset + $sub_sub_subelement_length; - switch ($sub_sub_subelement_id) { + + while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], array(EBML_ID_CONTENTCOMPRESSION, EBML_ID_CONTENTENCRYPTION))) { + switch ($sub_sub_subelement['id']) { + case EBML_ID_CONTENTENCODINGORDER: case EBML_ID_CONTENTENCODINGSCOPE: case EBML_ID_CONTENTENCODINGTYPE: - $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length)); + $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); break; + case EBML_ID_CONTENTCOMPRESSION: - while ($offset < $sub_sub_subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_sub_subelement_offset = $offset; - $sub_sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id); - $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_sub_subelement_end = $offset + $sub_sub_sub_subelement_length; - switch ($sub_sub_sub_subelement_id) { + + while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { + switch ($sub_sub_sub_subelement['id']) { + case EBML_ID_CONTENTCOMPALGO: - $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length)); + $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); break; + case EBML_ID_CONTENTCOMPSETTINGS: - $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length); + $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; break; + default: - $this->warnings[] = 'Unhandled track.contentencodings.contentencoding.contentcompression element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset; + $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement); break; } - $offset = $sub_sub_sub_subelement_end; } break; case EBML_ID_CONTENTENCRYPTION: - while ($offset < $sub_sub_subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_sub_subelement_offset = $offset; - $sub_sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id); - $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_sub_subelement_end = $offset + $sub_sub_sub_subelement_length; - switch ($sub_sub_sub_subelement_id) { + + while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { + switch ($sub_sub_sub_subelement['id']) { + case EBML_ID_CONTENTENCALGO: case EBML_ID_CONTENTSIGALGO: case EBML_ID_CONTENTSIGHASHALGO: - $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length)); + $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); break; + case EBML_ID_CONTENTENCKEYID: case EBML_ID_CONTENTSIGNATURE: case EBML_ID_CONTENTSIGKEYID: - $track_entry[$sub_subelement_idname][$sub_sub_subelement_idname][$sub_sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length); + $track_entry[$sub_subelement['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; break; + default: - $this->warnings[] = 'Unhandled track.contentencodings.contentencoding.contentcompression element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset; + $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement); break; } - $offset = $sub_sub_sub_subelement_end; } break; default: - $this->warnings[] = 'Unhandled track.contentencodings.contentencoding element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset; + $this->unhandledElement('track.contentencodings.contentencoding', __LINE__, $sub_sub_subelement); break; } - $offset = $sub_sub_subelement_end; } break; + default: - $this->warnings[] = 'Unhandled track.contentencodings element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset; + $this->unhandledElement('track.contentencodings', __LINE__, $sub_subelement); break; } - $offset = $sub_subelement_end; } break; default: - $this->warnings[] = 'Unhandled track element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset; + $this->unhandledElement('track', __LINE__, $subelement); break; } - $offset = $subelement_end; } + + $info['matroska']['tracks']['tracks'][] = $track_entry; break; + default: - $this->warnings[] = 'Unhandled track element ['.basename(__FILE__).':'.__LINE__.'] ('.$track_entry['id'].'::'.$track_entry['id_name'].') at '.$track_entry['offset']; - $offset = $track_entry_endoffset; + $this->unhandledElement('tracks', __LINE__, $track_entry); break; } - $ThisFileInfo['matroska']['tracks']['tracks'][] = $track_entry; } break; - case EBML_ID_INFO: // Contains the position of other level 1 elements + case EBML_ID_INFO: // Contains miscellaneous general information and statistics on the file. $info_entry = array(); - while ($offset < $element_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $subelement_offset = $offset; - $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $subelement_idname = $this->EBMLidName($subelement_id); - $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $subelement_end = $offset + $subelement_length; - switch ($subelement_id) { - case EBML_ID_CHAPTERTRANSLATEEDITIONUID: - case EBML_ID_CHAPTERTRANSLATECODEC: + + while ($this->getEBMLelement($subelement, $element_data['end'], true)) { + switch ($subelement['id']) { + case EBML_ID_TIMECODESCALE: - $info_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length)); + $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); break; + case EBML_ID_DURATION: - $info_entry[$subelement_idname] = getid3_lib::BigEndian2Float(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length)); + $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']); break; + case EBML_ID_DATEUTC: - $info_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length)); - $info_entry[$subelement_idname.'_unix'] = $this->EBMLdate2unix($info_entry[$subelement_idname]); + $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); + $info_entry[$subelement['id_name'].'_unix'] = self::EBMLdate2unix($info_entry[$subelement['id_name']]); break; + case EBML_ID_SEGMENTUID: case EBML_ID_PREVUID: case EBML_ID_NEXTUID: - case EBML_ID_SEGMENTFAMILY: - case EBML_ID_CHAPTERTRANSLATEID: - $info_entry[$subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "\x00"); + $info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); break; + + case EBML_ID_SEGMENTFAMILY: + $info_entry[$subelement['id_name']][] = getid3_lib::trimNullByte($subelement['data']); + break; + case EBML_ID_SEGMENTFILENAME: case EBML_ID_PREVFILENAME: case EBML_ID_NEXTFILENAME: case EBML_ID_TITLE: case EBML_ID_MUXINGAPP: case EBML_ID_WRITINGAPP: - $info_entry[$subelement_idname] = trim(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length), "\x00"); + $info_entry[$subelement['id_name']] = getid3_lib::trimNullByte($subelement['data']); + $info['matroska']['comments'][strtolower($subelement['id_name'])][] = $info_entry[$subelement['id_name']]; break; + + case EBML_ID_CHAPTERTRANSLATE: + $chaptertranslate_entry = array(); + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { + switch ($sub_subelement['id']) { + + case EBML_ID_CHAPTERTRANSLATEEDITIONUID: + $chaptertranslate_entry[$sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_subelement['data']); + break; + + case EBML_ID_CHAPTERTRANSLATECODEC: + $chaptertranslate_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); + break; + + case EBML_ID_CHAPTERTRANSLATEID: + $chaptertranslate_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); + break; + + default: + $this->unhandledElement('info.chaptertranslate', __LINE__, $sub_subelement); + break; + } + } + $info_entry[$subelement['id_name']] = $chaptertranslate_entry; + break; + default: - $this->warnings[] = 'Unhandled info element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset; + $this->unhandledElement('info', __LINE__, $subelement); break; } - $offset = $subelement_end; } - $ThisFileInfo['matroska']['info'][] = $info_entry; + $info['matroska']['info'][] = $info_entry; break; - case EBML_ID_CUES: + case EBML_ID_CUES: // A top-level element to speed seeking access. All entries are local to the segment. Should be mandatory for non "live" streams. + if ($this->hide_clusters) { // do not parse cues if hide clusters is "ON" till they point to clusters anyway + $this->current_offset = $element_data['end']; + break; + } $cues_entry = array(); - while ($offset < $element_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $subelement_offset = $offset; - $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $subelement_idname = $this->EBMLidName($subelement_id); - $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $subelement_end = $offset + $subelement_length; - switch ($subelement_id) { + + while ($this->getEBMLelement($subelement, $element_data['end'])) { + switch ($subelement['id']) { + case EBML_ID_CUEPOINT: $cuepoint_entry = array(); - while ($offset < $subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_offset = $offset; - $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_idname = $this->EBMLidName($sub_subelement_id); - $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_end = $offset + $sub_subelement_length; - switch ($sub_subelement_id) { + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CUETRACKPOSITIONS))) { + switch ($sub_subelement['id']) { + case EBML_ID_CUETRACKPOSITIONS: - while ($offset < $sub_subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_offset = $offset; - $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id); - $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_end = $offset + $sub_sub_subelement_length; - switch ($sub_sub_subelement_id) { + $cuetrackpositions_entry = array(); + + while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) { + switch ($sub_sub_subelement['id']) { + case EBML_ID_CUETRACK: - $cuepoint_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length)); + case EBML_ID_CUECLUSTERPOSITION: + case EBML_ID_CUEBLOCKNUMBER: + case EBML_ID_CUECODECSTATE: + $cuetrackpositions_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); break; + default: - $this->warnings[] = 'Unhandled cues.cuepoint.cuetrackpositions element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset; + $this->unhandledElement('cues.cuepoint.cuetrackpositions', __LINE__, $sub_sub_subelement); break; } - $offset = $sub_subelement_end; } + $cuepoint_entry[$sub_subelement['id_name']][] = $cuetrackpositions_entry; break; + case EBML_ID_CUETIME: - $cuepoint_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length)); + $cuepoint_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); break; + default: - $this->warnings[] = 'Unhandled cues.cuepoint element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset; + $this->unhandledElement('cues.cuepoint', __LINE__, $sub_subelement); break; } - $offset = $sub_subelement_end; } $cues_entry[] = $cuepoint_entry; - $offset = $sub_subelement_end; break; + default: - $this->warnings[] = 'Unhandled cues element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset; + $this->unhandledElement('cues', __LINE__, $subelement); break; } - $offset = $subelement_end; } - $ThisFileInfo['matroska']['cues'] = $cues_entry; + $info['matroska']['cues'] = $cues_entry; break; - case EBML_ID_TAGS: + case EBML_ID_TAGS: // Element containing elements specific to Tracks/Chapters. $tags_entry = array(); - while ($offset < $element_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $subelement_offset = $offset; - $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $subelement_idname = $this->EBMLidName($subelement_id); - $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $subelement_end = $offset + $subelement_length; - switch ($subelement_id) { - case EBML_ID_WRITINGAPP: - $tags_entry[$subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length); - break; + + while ($this->getEBMLelement($subelement, $element_data['end'], false)) { + switch ($subelement['id']) { + case EBML_ID_TAG: $tag_entry = array(); - while ($offset < $subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_offset = $offset; - $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_idname = $this->EBMLidName($sub_subelement_id); - $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_end = $offset + $sub_subelement_length; - switch ($sub_subelement_id) { + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], false)) { + switch ($sub_subelement['id']) { + case EBML_ID_TARGETS: $targets_entry = array(); - while ($offset < $sub_subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_offset = $offset; - $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id); - $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_end = $offset + $sub_sub_subelement_length; - switch ($sub_sub_subelement_id) { + + while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) { + switch ($sub_sub_subelement['id']) { + case EBML_ID_TARGETTYPEVALUE: - case EBML_ID_EDITIONUID: - case EBML_ID_CHAPTERUID: - case EBML_ID_ATTACHMENTUID: + $targets_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); + $targets_entry[strtolower($sub_sub_subelement['id_name']).'_long'] = self::TargetTypeValue($targets_entry[$sub_sub_subelement['id_name']]); + break; + + case EBML_ID_TARGETTYPE: + $targets_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data']; + break; + case EBML_ID_TAGTRACKUID: + case EBML_ID_TAGEDITIONUID: case EBML_ID_TAGCHAPTERUID: - $targets_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length)); + case EBML_ID_TAGATTACHMENTUID: + $targets_entry[$sub_sub_subelement['id_name']][] = getid3_lib::PrintHexBytes($sub_sub_subelement['data'], true, false); break; + default: - $this->warnings[] = 'Unhandled tag.targets element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset; + $this->unhandledElement('tags.tag.targets', __LINE__, $sub_sub_subelement); break; } - $offset = $sub_sub_subelement_end; } - $tag_entry[$sub_subelement_idname][] = $targets_entry; + $tag_entry[$sub_subelement['id_name']] = $targets_entry; break; + case EBML_ID_SIMPLETAG: - $simpletag_entry = array(); - while ($offset < $sub_subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_offset = $offset; - $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id); - $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_end = $offset + $sub_sub_subelement_length; - switch ($sub_sub_subelement_id) { - case EBML_ID_TAGNAME: - case EBML_ID_TAGLANGUAGE: - case EBML_ID_TAGSTRING: - case EBML_ID_TAGBINARY: - $simpletag_entry[$sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length); - break; - case EBML_ID_TAGDEFAULT: - $simpletag_entry[$sub_sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length)); - break; - default: - $this->warnings[] = 'Unhandled tag.simpletag element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset; - break; - } - $offset = $sub_sub_subelement_end; - } - $tag_entry[$sub_subelement_idname][] = $simpletag_entry; - break; - case EBML_ID_TARGETTYPE: - $tag_entry[$sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length); - break; - case EBML_ID_TRACKUID: - $tag_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length)); + $tag_entry[$sub_subelement['id_name']][] = $this->HandleEMBLSimpleTag($sub_subelement['end']); break; + default: - $this->warnings[] = 'Unhandled tags.tag element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset; + $this->unhandledElement('tags.tag', __LINE__, $sub_subelement); break; } - $offset = $sub_subelement_end; } - $tags_entry['tags'][] = $tag_entry; - $offset = $sub_subelement_end; + $tags_entry[] = $tag_entry; break; + default: - $this->warnings[] = 'Unhandled tags element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset; + $this->unhandledElement('tags', __LINE__, $subelement); break; } - $offset = $subelement_end; } - $ThisFileInfo['matroska']['tags'] = $tags_entry; + $info['matroska']['tags'] = $tags_entry; break; + case EBML_ID_ATTACHMENTS: // Contain attached files. + + while ($this->getEBMLelement($subelement, $element_data['end'])) { + switch ($subelement['id']) { - case EBML_ID_ATTACHMENTS: - while ($offset < $element_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $subelement_offset = $offset; - $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $subelement_idname = $this->EBMLidName($subelement_id); - $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $subelement_end = $offset + $subelement_length; - switch ($subelement_id) { case EBML_ID_ATTACHEDFILE: $attachedfile_entry = array(); - while ($offset < $subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_offset = $offset; - $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_idname = $this->EBMLidName($sub_subelement_id); - $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_end = $offset + $sub_subelement_length; - switch ($sub_subelement_id) { + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_FILEDATA))) { + switch ($sub_subelement['id']) { + case EBML_ID_FILEDESCRIPTION: case EBML_ID_FILENAME: case EBML_ID_FILEMIMETYPE: - $attachedfile_entry[$sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length); + $attachedfile_entry[$sub_subelement['id_name']] = $sub_subelement['data']; break; case EBML_ID_FILEDATA: - $attachedfile_entry['data_offset'] = $offset; - $attachedfile_entry['data_length'] = $sub_subelement_length; - if ($sub_subelement_length < 1024) { - $attachedfile_entry[$sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length); - } + $attachedfile_entry['data_offset'] = $this->current_offset; + $attachedfile_entry['data_length'] = $sub_subelement['length']; + + $attachedfile_entry[$sub_subelement['id_name']] = $this->saveAttachment( + $attachedfile_entry['FileName'], + $attachedfile_entry['data_offset'], + $attachedfile_entry['data_length']); + + $this->current_offset = $sub_subelement['end']; break; case EBML_ID_FILEUID: - $attachedfile_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length)); + $attachedfile_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); break; default: - $this->warnings[] = 'Unhandled attachment.attachedfile element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset; + $this->unhandledElement('attachments.attachedfile', __LINE__, $sub_subelement); break; } - $offset = $sub_subelement_end; } - $ThisFileInfo['matroska']['attachments'][] = $attachedfile_entry; - $offset = $sub_subelement_end; + $info['matroska']['attachments'][] = $attachedfile_entry; break; + default: - $this->warnings[] = 'Unhandled tags element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset; + $this->unhandledElement('attachments', __LINE__, $subelement); break; } - $offset = $subelement_end; } break; + case EBML_ID_CHAPTERS: + + while ($this->getEBMLelement($subelement, $element_data['end'])) { + switch ($subelement['id']) { - case EBML_ID_CHAPTERS: // not important to us, contains mostly actual audio/video data, ignore - while ($offset < $element_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $subelement_offset = $offset; - $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $subelement_idname = $this->EBMLidName($subelement_id); - $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $subelement_end = $offset + $subelement_length; - switch ($subelement_id) { case EBML_ID_EDITIONENTRY: $editionentry_entry = array(); - while ($offset < $subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_offset = $offset; - $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_idname = $this->EBMLidName($sub_subelement_id); - $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_end = $offset + $sub_subelement_length; - switch ($sub_subelement_id) { + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CHAPTERATOM))) { + switch ($sub_subelement['id']) { + case EBML_ID_EDITIONUID: - $editionentry_entry[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length)); + $editionentry_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); break; + case EBML_ID_EDITIONFLAGHIDDEN: case EBML_ID_EDITIONFLAGDEFAULT: case EBML_ID_EDITIONFLAGORDERED: - $editionentry_entry[$sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length)); + $editionentry_entry[$sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_subelement['data']); break; + case EBML_ID_CHAPTERATOM: $chapteratom_entry = array(); - while ($offset < $sub_subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_offset = $offset; - $sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id); - $sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_subelement_end = $offset + $sub_sub_subelement_length; - switch ($sub_sub_subelement_id) { + + while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], array(EBML_ID_CHAPTERTRACK, EBML_ID_CHAPTERDISPLAY))) { + switch ($sub_sub_subelement['id']) { + case EBML_ID_CHAPTERSEGMENTUID: case EBML_ID_CHAPTERSEGMENTEDITIONUID: - $chapteratom_entry[$sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length); + $chapteratom_entry[$sub_sub_subelement['id_name']] = $sub_sub_subelement['data']; break; + case EBML_ID_CHAPTERFLAGENABLED: case EBML_ID_CHAPTERFLAGHIDDEN: - $chapteratom_entry[$sub_sub_subelement_idname] = (bool) getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length)); + $chapteratom_entry[$sub_sub_subelement['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_sub_subelement['data']); break; + case EBML_ID_CHAPTERUID: case EBML_ID_CHAPTERTIMESTART: case EBML_ID_CHAPTERTIMEEND: - $chapteratom_entry[$sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_subelement_length)); + $chapteratom_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']); break; + case EBML_ID_CHAPTERTRACK: $chaptertrack_entry = array(); - while ($offset < $sub_sub_subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_sub_subelement_offset = $offset; - $sub_sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_subelement_id); - $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_sub_subelement_end = $offset + $sub_sub_sub_subelement_length; - switch ($sub_sub_sub_subelement_id) { + + while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { + switch ($sub_sub_sub_subelement['id']) { + case EBML_ID_CHAPTERTRACKNUMBER: - $chaptertrack_entry[$sub_sub_sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length)); + $chaptertrack_entry[$sub_sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']); break; + default: - $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom.chaptertrack element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_sub_sub_subelement_id.'::'.$sub_sub_sub_subelement_idname.') at '.$sub_sub_sub_subelement_offset; + $this->unhandledElement('chapters.editionentry.chapteratom.chaptertrack', __LINE__, $sub_sub_sub_subelement); break; } - $offset = $sub_sub_sub_subelement_end; } - $chapteratom_entry[$sub_sub_subelement_idname][] = $chaptertrack_entry; + $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chaptertrack_entry; break; + case EBML_ID_CHAPTERDISPLAY: $chapterdisplay_entry = array(); - while ($offset < $sub_sub_subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_sub_subelement_offset = $offset; - $sub_sub_sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_sub_subelement_idname = $this->EBMLidName($sub_sub_sub_subelement_id); - $sub_sub_sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_sub_sub_subelement_end = $offset + $sub_sub_sub_subelement_length; - switch ($sub_sub_sub_subelement_id) { + + while ($this->getEBMLelement($sub_sub_sub_subelement, $sub_sub_subelement['end'], true)) { + switch ($sub_sub_sub_subelement['id']) { + case EBML_ID_CHAPSTRING: case EBML_ID_CHAPLANGUAGE: case EBML_ID_CHAPCOUNTRY: - $chapterdisplay_entry[$sub_sub_sub_subelement_idname] = substr($EBMLdata, $offset - $EBMLdata_offset, $sub_sub_sub_subelement_length); + $chapterdisplay_entry[$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data']; break; + default: - $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom.chapterdisplay element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_sub_sub_subelement_id.'::'.$sub_sub_sub_subelement_idname.') at '.$sub_sub_sub_subelement_offset; + $this->unhandledElement('chapters.editionentry.chapteratom.chapterdisplay', __LINE__, $sub_sub_sub_subelement); break; } - $offset = $sub_sub_sub_subelement_end; } - $chapteratom_entry[$sub_sub_subelement_idname][] = $chapterdisplay_entry; + $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chapterdisplay_entry; break; + default: - $this->warnings[] = 'Unhandled chapters.editionentry.chapteratom element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_sub_subelement_id.'::'.$sub_sub_subelement_idname.') at '.$sub_sub_subelement_offset; + $this->unhandledElement('chapters.editionentry.chapteratom', __LINE__, $sub_sub_subelement); break; } - $offset = $sub_sub_subelement_end; } - $editionentry_entry[$sub_subelement_idname][] = $chapteratom_entry; + $editionentry_entry[$sub_subelement['id_name']][] = $chapteratom_entry; break; + default: - $this->warnings[] = 'Unhandled chapters.editionentry element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset; + $this->unhandledElement('chapters.editionentry', __LINE__, $sub_subelement); break; } - $offset = $sub_subelement_end; } - $ThisFileInfo['matroska']['chapters'][] = $editionentry_entry; - $offset = $sub_subelement_end; + $info['matroska']['chapters'][] = $editionentry_entry; break; + default: - $this->warnings[] = 'Unhandled chapters element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset; + $this->unhandledElement('chapters', __LINE__, $subelement); break; } - $offset = $subelement_end; } break; - - case EBML_ID_VOID: // padding, ignore - $void_entry = array(); - $void_entry['offset'] = $offset; - $ThisFileInfo['matroska']['void'][] = $void_entry; - break; - - case EBML_ID_CLUSTER: // not important to us, contains mostly actual audio/video data, ignore + case EBML_ID_CLUSTER: // The lower level element containing the (monolithic) Block structure. $cluster_entry = array(); - while ($offset < $element_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $subelement_offset = $offset; - $subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $subelement_idname = $this->EBMLidName($subelement_id); - $subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $subelement_end = $offset + $subelement_length; - switch ($subelement_id) { + + while ($this->getEBMLelement($subelement, $element_data['end'], array(EBML_ID_CLUSTERSILENTTRACKS, EBML_ID_CLUSTERBLOCKGROUP, EBML_ID_CLUSTERSIMPLEBLOCK))) { + switch ($subelement['id']) { + case EBML_ID_CLUSTERTIMECODE: case EBML_ID_CLUSTERPOSITION: case EBML_ID_CLUSTERPREVSIZE: - $cluster_entry[$subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $subelement_length)); + $cluster_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']); break; case EBML_ID_CLUSTERSILENTTRACKS: $cluster_silent_tracks = array(); - while ($offset < $subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_offset = $offset; - $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_idname = $this->EBMLidName($sub_subelement_id); - $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_end = $offset + $sub_subelement_length; - switch ($sub_subelement_id) { + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) { + switch ($sub_subelement['id']) { + case EBML_ID_CLUSTERSILENTTRACKNUMBER: - $cluster_silent_tracks[] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length)); + $cluster_silent_tracks[] = getid3_lib::BigEndian2Int($sub_subelement['data']); break; + default: - $this->warnings[] = 'Unhandled clusters.silenttracks element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset; + $this->unhandledElement('cluster.silenttracks', __LINE__, $sub_subelement); break; } - $offset = $sub_subelement_end; } - $cluster_entry[$subelement_idname][] = $cluster_silent_tracks; - $offset = $sub_subelement_end; + $cluster_entry[$subelement['id_name']][] = $cluster_silent_tracks; break; case EBML_ID_CLUSTERBLOCKGROUP: - $cluster_block_group = array('offset'=>$offset); - while ($offset < $subelement_end) { - $this->EnsureBufferHasEnoughData($fd, $EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_offset = $offset; - $sub_subelement_id = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_idname = $this->EBMLidName($sub_subelement_id); - $sub_subelement_length = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $sub_subelement_end = $offset + $sub_subelement_length; - switch ($sub_subelement_id) { + $cluster_block_group = array('offset' => $this->current_offset); + + while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CLUSTERBLOCK))) { + switch ($sub_subelement['id']) { + case EBML_ID_CLUSTERBLOCK: - $cluster_block_data = array(); - $cluster_block_data['tracknumber'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $cluster_block_data['timecode'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 2)); - $offset += 2; - // unsure whether this is 1 octect or 2 octets? (http://matroska.org/technical/specs/index.html#block_structure) - $cluster_block_data['flags_raw'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1)); - $offset += 1; - //$cluster_block_data['flags']['reserved1'] = (($cluster_block_data['flags_raw'] & 0xF0) >> 4); - $cluster_block_data['flags']['invisible'] = (bool) (($cluster_block_data['flags_raw'] & 0x08) >> 3); - $cluster_block_data['flags']['lacing'] = (($cluster_block_data['flags_raw'] & 0x06) >> 1); - //$cluster_block_data['flags']['reserved2'] = (($cluster_block_data['flags_raw'] & 0x01) >> 0); - $cluster_block_data['flags']['lacing_type'] = $this->MatroskaBlockLacingType($cluster_block_data['flags']['lacing']); - if ($cluster_block_data['flags']['lacing'] != 0) { - $cluster_block_data['lace_frames'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1)); // Number of frames in the lace-1 (uint8) - $offset += 1; - if ($cluster_block_data['flags']['lacing'] != 2) { - $cluster_block_data['lace_frames'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1)); // Lace-coded size of each frame of the lace, except for the last one (multiple uint8). *This is not used with Fixed-size lacing as it is calculated automatically from (total size of lace) / (number of frames in lace). - $offset += 1; - } - } - if (!isset($ThisFileInfo['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']])) { - $ThisFileInfo['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']] = $offset; - } - $cluster_block_group[$sub_subelement_idname] = $cluster_block_data; + $cluster_block_group[$sub_subelement['id_name']] = $this->HandleEMBLClusterBlock($sub_subelement, EBML_ID_CLUSTERBLOCK, $info); break; case EBML_ID_CLUSTERREFERENCEPRIORITY: // unsigned-int case EBML_ID_CLUSTERBLOCKDURATION: // unsigned-int - $cluster_block_group[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length)); + $cluster_block_group[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']); break; case EBML_ID_CLUSTERREFERENCEBLOCK: // signed-int - $cluster_block_group[$sub_subelement_idname] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset - $EBMLdata_offset, $sub_subelement_length), false, true); + $cluster_block_group[$sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_subelement['data'], false, true); + break; + + case EBML_ID_CLUSTERCODECSTATE: + $cluster_block_group[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']); break; default: - $this->warnings[] = 'Unhandled clusters.blockgroup element ['.basename(__FILE__).':'.__LINE__.'] ('.$sub_subelement_id.'::'.$sub_subelement_idname.') at '.$sub_subelement_offset; + $this->unhandledElement('clusters.blockgroup', __LINE__, $sub_subelement); break; } - $offset = $sub_subelement_end; } - $cluster_entry[$subelement_idname][] = $cluster_block_group; - $offset = $sub_subelement_end; + $cluster_entry[$subelement['id_name']][] = $cluster_block_group; break; case EBML_ID_CLUSTERSIMPLEBLOCK: - // http://www.matroska.org/technical/specs/index.html#simpleblock_structure - $cluster_block_data = array(); - $cluster_block_data['tracknumber'] = $this->readEBMLint($EBMLdata, $offset, $EBMLdata_offset); - $cluster_block_data['timecode'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 2)); - $offset += 2; - $cluster_block_data['flags_raw'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1)); - $offset += 1; - $cluster_block_data['flags']['keyframe'] = (($cluster_block_data['flags_raw'] & 0x80) >> 7); - $cluster_block_data['flags']['reserved1'] = (($cluster_block_data['flags_raw'] & 0x70) >> 4); - $cluster_block_data['flags']['invisible'] = (($cluster_block_data['flags_raw'] & 0x08) >> 3); - $cluster_block_data['flags']['lacing'] = (($cluster_block_data['flags_raw'] & 0x06) >> 1); // 00=no lacing; 01=Xiph lacing; 11=EBML lacing; 10=fixed-size lacing - $cluster_block_data['flags']['discardable'] = (($cluster_block_data['flags_raw'] & 0x01)); - - if ($cluster_block_data['flags']['lacing'] > 0) { - $cluster_block_data['lace_frames'] = 1 + getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1)); - $offset += 1; - if ($cluster_block_data['flags']['lacing'] != 0x02) { - // *This is not used with Fixed-size lacing as it is calculated automatically from (total size of lace) / (number of frames in lace). - $cluster_block_data['lace_frame_size'] = getid3_lib::BigEndian2Int(substr($EBMLdata, $offset, 1)); - $offset += 1; - } - } - - if (!isset($ThisFileInfo['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']])) { - $ThisFileInfo['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']] = $offset; - } - $cluster_block_group[$sub_subelement_idname] = $cluster_block_data; + $cluster_entry[$subelement['id_name']][] = $this->HandleEMBLClusterBlock($subelement, EBML_ID_CLUSTERSIMPLEBLOCK, $info); break; default: - $this->warnings[] = 'Unhandled cluster element ['.basename(__FILE__).':'.__LINE__.'] ('.$subelement_id.'::'.$subelement_idname.' ['.$subelement_length.' bytes]) at '.$subelement_offset; + $this->unhandledElement('cluster', __LINE__, $subelement); break; } - $offset = $subelement_end; + $this->current_offset = $subelement['end']; + } + if (!$this->hide_clusters) { + $info['matroska']['cluster'][] = $cluster_entry; } - $ThisFileInfo['matroska']['cluster'][] = $cluster_entry; // check to see if all the data we need exists already, if so, break out of the loop - if (isset($ThisFileInfo['matroska']['info']) && is_array($ThisFileInfo['matroska']['info'])) { - if (isset($ThisFileInfo['matroska']['tracks']['tracks']) && is_array($ThisFileInfo['matroska']['tracks']['tracks'])) { - break 2; + if (!$this->parse_whole_file) { + if (isset($info['matroska']['info']) && is_array($info['matroska']['info'])) { + if (isset($info['matroska']['tracks']['tracks']) && is_array($info['matroska']['tracks']['tracks'])) { + if (count($info['matroska']['track_data_offsets']) == count($info['matroska']['tracks']['tracks'])) { + return; + } + } } } break; default: - if ($element_data['id_name'] == dechex($element_data['id'])) { - $ThisFileInfo['error'][] = 'Unhandled segment ['.basename(__FILE__).':'.__LINE__.'] ('.$element_data['id'].') at '.$element_data_offset; - } else { - $this->warnings[] = 'Unhandled segment ['.basename(__FILE__).':'.__LINE__.'] ('.$element_data['id'].'::'.$element_data['id_name'].') at '.$element_data['offset']; - } + $this->unhandledElement('segment', __LINE__, $element_data); break; } - $offset = $element_end; } break; - default: - $ThisFileInfo['error'][] = 'Unhandled chunk ['.basename(__FILE__).':'.__LINE__.'] ('.$top_element_id.') at '.$offset; + $this->unhandledElement('root', __LINE__, $top_element); break; } - $offset = $top_element_endoffset; } - - - - if (isset($ThisFileInfo['matroska']['info']) && is_array($ThisFileInfo['matroska']['info'])) { - foreach ($ThisFileInfo['matroska']['info'] as $key => $infoarray) { - if (isset($infoarray['Duration'])) { - // TimecodeScale is how many nanoseconds each Duration unit is - $ThisFileInfo['playtime_seconds'] = $infoarray['Duration'] * ((isset($infoarray['TimecodeScale']) ? $infoarray['TimecodeScale'] : 1000000) / 1000000000); - break; - } - } - } - if (isset($ThisFileInfo['matroska']['tracks']['tracks']) && is_array($ThisFileInfo['matroska']['tracks']['tracks'])) { - foreach ($ThisFileInfo['matroska']['tracks']['tracks'] as $key => $trackarray) { - $track_info = array(); - switch (isset($trackarray['TrackType']) ? $trackarray['TrackType'] : '') { - case 1: // Video - if (!empty($trackarray['PixelWidth'])) { $track_info['resolution_x'] = $trackarray['PixelWidth']; } - if (!empty($trackarray['PixelHeight'])) { $track_info['resolution_y'] = $trackarray['PixelHeight']; } - if (!empty($trackarray['DisplayWidth'])) { $track_info['display_x'] = $trackarray['DisplayWidth']; } - if (!empty($trackarray['DisplayHeight'])) { $track_info['display_y'] = $trackarray['DisplayHeight']; } - if (!empty($trackarray['DefaultDuration'])) { $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3); } - if (!empty($trackarray['CodecID'])) { $track_info['dataformat'] = $this->MatroskaCodecIDtoCommonName($trackarray['CodecID']); } - if (!empty($trackarray['codec_private_parsed']['fourcc'])) { $track_info['fourcc'] = $trackarray['codec_private_parsed']['fourcc']; } - $ThisFileInfo['video']['streams'][] = $track_info; - if (isset($track_info['resolution_x']) && empty($ThisFileInfo['video']['resolution_x'])) { - foreach ($track_info as $key => $value) { - $ThisFileInfo['video'][$key] = $value; - } - } - break; - case 2: // Audio - if (!empty($trackarray['CodecID'])) { $track_info['dataformat'] = $this->MatroskaCodecIDtoCommonName($trackarray['CodecID']); } - if (!empty($trackarray['SamplingFrequency'])) { $track_info['sample_rate'] = $trackarray['SamplingFrequency']; } - if (!empty($trackarray['Channels'])) { $track_info['channels'] = $trackarray['Channels']; } - if (!empty($trackarray['BitDepth'])) { $track_info['bits_per_sample'] = $trackarray['BitDepth']; } - if (!empty($trackarray['Language'])) { $track_info['language'] = $trackarray['Language']; } - switch (isset($trackarray[$this->EBMLidName(EBML_ID_CODECID)]) ? $trackarray[$this->EBMLidName(EBML_ID_CODECID)] : '') { - case 'A_PCM/INT/LIT': - case 'A_PCM/INT/BIG': - $track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth']; - break; - - case 'A_AC3': - if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, false)) { - if (isset($ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']])) { - $ac3_thisfileinfo = array('avdataoffset'=>$ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']]); - $getid3_ac3 = new getid3_ac3($fd, $ac3_thisfileinfo); - $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $ac3_thisfileinfo; - if (!empty($ac3_thisfileinfo['error'])) { - foreach ($ac3_thisfileinfo['error'] as $newerror) { - $this->warnings[] = 'getid3_ac3() says: ['.$newerror.']'; - } - } - if (!empty($ac3_thisfileinfo['warning'])) { - foreach ($ac3_thisfileinfo['warning'] as $newerror) { - $this->warnings[] = 'getid3_ac3() says: ['.$newerror.']'; - } - } - if (isset($ac3_thisfileinfo['audio']) && is_array($ac3_thisfileinfo['audio'])) { - foreach ($ac3_thisfileinfo['audio'] as $key => $value) { - $track_info[$key] = $value; - } - } - unset($ac3_thisfileinfo); - unset($getid3_ac3); - } else { - $this->warnings[] = 'Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because $ThisFileInfo[matroska][track_data_offsets]['.$trackarray['TrackNumber'].'] not set'; - } - } else { - $this->warnings[] = 'Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.ac3.php"'; - } - break; - - case 'A_DTS': - $dts_offset = $ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']]; - // this is a NASTY hack, but sometimes audio data is off by a byte or two and not sure why, email info@getid3.org if you can explain better - fseek($fd, $dts_offset, SEEK_SET); - $magic_test = fread($fd, 8); - for ($i = 0; $i < 4; $i++) { - // look to see if DTS "magic" is here, if so adjust offset by that many bytes - if (substr($magic_test, $i, 4) == "\x7F\xFE\x80\x01") { - $dts_offset += $i; - break; - } - } - if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.dts.php', __FILE__, false)) { - $dts_thisfileinfo = array('avdataoffset'=>$dts_offset); - $getid3_dts = new getid3_dts($fd, $dts_thisfileinfo); - $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $dts_thisfileinfo; - if (!empty($dts_thisfileinfo['error'])) { - foreach ($dts_thisfileinfo['error'] as $newerror) { - $this->warnings[] = 'getid3_dts() says: ['.$newerror.']'; - } - } - if (!empty($dts_thisfileinfo['warning'])) { - foreach ($dts_thisfileinfo['warning'] as $newerror) { - $this->warnings[] = 'getid3_dts() says: ['.$newerror.']'; - } - } - if (isset($dts_thisfileinfo['audio']) && is_array($dts_thisfileinfo['audio'])) { - foreach ($dts_thisfileinfo['audio'] as $key => $value) { - $track_info[$key] = $value; - } - } - unset($dts_thisfileinfo); - unset($getid3_dts); - } else { - $this->warnings[] = 'Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.dts.php"'; - } - break; - - case 'A_AAC': -$this->warnings[] = 'This version of getID3() [v'.GETID3_VERSION.'] has problems parsing AAC audio in Matroska containers ['.basename(__FILE__).':'.__LINE__.']'; - if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.aac.php', __FILE__, false)) { - // $aac_thisfileinfo = array('avdataoffset'=>$ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']]); - // $getid3_aac = new getid3_aac($fd, $aac_thisfileinfo); - // $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $aac_thisfileinfo; - // if (isset($aac_thisfileinfo['audio']) && is_array($aac_thisfileinfo['audio'])) { - // foreach ($aac_thisfileinfo['audio'] as $key => $value) { - // $track_info[$key] = $value; - // } - // } - // unset($aac_thisfileinfo); - // unset($getid3_aac); - } else { - $this->warnings[] = 'Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.aac.php"'; - } - break; - - case 'A_MPEG/L3': - if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, false)) { - $mp3_thisfileinfo = array( - 'avdataoffset' => $ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']], - 'avdataend' => $ThisFileInfo['matroska']['track_data_offsets'][$trackarray['TrackNumber']] + 1024, - ); - $getid3_mp3 = new getid3_mp3($fd, $mp3_thisfileinfo); - $getid3_mp3->allow_bruteforce = true; - //getid3_mp3::getOnlyMPEGaudioInfo($fd, $mp3_thisfileinfo, $offset, false); - $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $mp3_thisfileinfo; - if (!empty($mp3_thisfileinfo['error'])) { - foreach ($mp3_thisfileinfo['error'] as $newerror) { - $this->warnings[] = 'getid3_mp3() says: ['.$newerror.']'; - } - } - if (!empty($mp3_thisfileinfo['warning'])) { - foreach ($mp3_thisfileinfo['warning'] as $newerror) { - $this->warnings[] = 'getid3_mp3() says: ['.$newerror.']'; - } - } - if (isset($mp3_thisfileinfo['audio']) && is_array($mp3_thisfileinfo['audio'])) { - foreach ($mp3_thisfileinfo['audio'] as $key => $value) { - $track_info[$key] = $value; - } - } - unset($mp3_thisfileinfo); - unset($getid3_mp3); - } else { - $this->warnings[] = 'Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.mp3.php"'; - } - break; - - case 'A_VORBIS': - if (isset($trackarray['CodecPrivate'])) { - // this is a NASTY hack, email info@getid3.org if you have a better idea how to get this info out - $found_vorbis = false; - for ($vorbis_offset = 1; $vorbis_offset < 16; $vorbis_offset++) { - if (substr($trackarray['CodecPrivate'], $vorbis_offset, 6) == 'vorbis') { - $vorbis_offset--; - $found_vorbis = true; - break; - } - } - if ($found_vorbis) { - if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, false)) { - $vorbis_fileinfo = array(); - $oggpageinfo['page_seqno'] = 0; - getid3_ogg::ParseVorbisPageHeader($trackarray['CodecPrivate'], $vorbis_offset, $vorbis_fileinfo, $oggpageinfo); - $ThisFileInfo['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $vorbis_fileinfo; - if (!empty($vorbis_fileinfo['error'])) { - foreach ($vorbis_fileinfo['error'] as $newerror) { - $this->warnings[] = 'getid3_ogg() says: ['.$newerror.']'; - } - } - if (!empty($vorbis_fileinfo['warning'])) { - foreach ($vorbis_fileinfo['warning'] as $newerror) { - $this->warnings[] = 'getid3_ogg() says: ['.$newerror.']'; - } - } - if (isset($vorbis_fileinfo['audio']) && is_array($vorbis_fileinfo['audio'])) { - foreach ($vorbis_fileinfo['audio'] as $key => $value) { - $track_info[$key] = $value; - } - } - if (!empty($vorbis_fileinfo['ogg']['bitrate_average'])) { - $track_info['bitrate'] = $vorbis_fileinfo['ogg']['bitrate_average']; - } elseif (!empty($vorbis_fileinfo['ogg']['bitrate_nominal'])) { - $track_info['bitrate'] = $vorbis_fileinfo['ogg']['bitrate_nominal']; - } - unset($vorbis_fileinfo); - unset($oggpageinfo); - } else { - $this->warnings[] = 'Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.ogg.php"'; - } - } else { - } - } else { - } - break; - - default: - $this->warnings[] = 'Unhandled audio type "'.(isset($trackarray[$this->EBMLidName(EBML_ID_CODECID)]) ? $trackarray[$this->EBMLidName(EBML_ID_CODECID)] : '').'"'; - break; - } - - - $ThisFileInfo['audio']['streams'][] = $track_info; - if (isset($track_info['dataformat']) && empty($ThisFileInfo['audio']['dataformat'])) { - foreach ($track_info as $key => $value) { - $ThisFileInfo['audio'][$key] = $value; - } - } - break; - default: - // ignore, do nothing - break; - } - } - } - - if ($this->hide_clusters) { - // too much data returned that is usually not useful - if (isset($ThisFileInfo['matroska']['segments']) && is_array($ThisFileInfo['matroska']['segments'])) { - foreach ($ThisFileInfo['matroska']['segments'] as $key => $segmentsarray) { - if ($segmentsarray['id'] == EBML_ID_CLUSTER) { - unset($ThisFileInfo['matroska']['segments'][$key]); - } - } - } - if (isset($ThisFileInfo['matroska']['seek']) && is_array($ThisFileInfo['matroska']['seek'])) { - foreach ($ThisFileInfo['matroska']['seek'] as $key => $seekarray) { - if ($seekarray['target_id'] == EBML_ID_CLUSTER) { - unset($ThisFileInfo['matroska']['seek'][$key]); - } - } - } - //unset($ThisFileInfo['matroska']['cluster']); - //unset($ThisFileInfo['matroska']['track_data_offsets']); - } - - if (!empty($ThisFileInfo['video']['streams'])) { - $ThisFileInfo['mime_type'] = 'video/x-matroska'; - } elseif (!empty($ThisFileInfo['audio']['streams'])) { - $ThisFileInfo['mime_type'] = 'audio/x-matroska'; - } elseif (isset($ThisFileInfo['mime_type'])) { - unset($ThisFileInfo['mime_type']); - } - - foreach ($this->warnings as $key => $value) { - $ThisFileInfo['warning'][] = $value; - } - - return true; } + /** + * @param int $min_data + * + * @return bool + */ + private function EnsureBufferHasEnoughData($min_data=1024) { + if (($this->current_offset - $this->EBMLbuffer_offset) >= ($this->EBMLbuffer_length - $min_data)) { + $read_bytes = max($min_data, $this->getid3->fread_buffer_size()); -/////////////////////////////////////// + try { + $this->fseek($this->current_offset); + $this->EBMLbuffer_offset = $this->current_offset; + $this->EBMLbuffer = $this->fread($read_bytes); + $this->EBMLbuffer_length = strlen($this->EBMLbuffer); + } catch (getid3_exception $e) { + $this->warning('EBML parser: '.$e->getMessage()); + return false; + } - - function EnsureBufferHasEnoughData(&$fd, &$EBMLdata, &$offset, &$EBMLdata_offset) { - $min_data = 1024; - if (!getid3_lib::intValueSupported($offset + $this->read_buffer_size)) { - $offset = pow(2, 63); - return false; - } elseif (($offset - $EBMLdata_offset) >= (strlen($EBMLdata) - $min_data)) { - fseek($fd, $offset, SEEK_SET); - $EBMLdata_offset = ftell($fd); - $EBMLdata = fread($fd, $this->read_buffer_size); + if ($this->EBMLbuffer_length == 0 && $this->feof()) { + return $this->error('EBML parser: ran out of file at offset '.$this->current_offset); + } } return true; } - function readEBMLint(&$string, &$offset, $dataoffset=0) { - $actual_offset = $offset - $dataoffset; - if (!getid3_lib::intValueSupported($offset + $this->read_buffer_size)) { - $this->warnings[] = 'aborting readEBMLint() because $offset larger than '.round(PHP_INT_MAX / 1073741824).'GB'; - return false; - } elseif ($actual_offset >= strlen($string)) { - $this->warnings[] = '$actual_offset > $string in readEBMLint($string['.strlen($string).'], '.$offset.', '.$dataoffset.')'; - return false; - } elseif ($actual_offset < 0) { - $this->warnings[] = '$actual_offset < 0 in readEBMLint($string['.strlen($string).'], '.$offset.', '.$dataoffset.')'; - return false; - } - $first_byte_int = ord($string{$actual_offset}); - if (0x80 & $first_byte_int) { + /** + * @return int|float|false + */ + private function readEBMLint() { + $actual_offset = $this->current_offset - $this->EBMLbuffer_offset; + + // get length of integer + $first_byte_int = ord($this->EBMLbuffer[$actual_offset]); + if (0x80 & $first_byte_int) { $length = 1; } elseif (0x40 & $first_byte_int) { $length = 2; @@ -1446,16 +1327,222 @@ $this->warnings[] = 'This version of getID3() [v'.GETID3_VERSION.'] has problems } elseif (0x01 & $first_byte_int) { $length = 8; } else { - $offset = pow(2, 63); // abort processing, skip to end of file - $this->warnings[] = 'invalid EBML integer (leading 0x00) at '.$offset; - return false; + throw new Exception('invalid EBML integer (leading 0x00) at '.$this->current_offset); } - $int_value = $this->EBML2Int(substr($string, $actual_offset, $length)); - $offset += $length; + + // read + $int_value = self::EBML2Int(substr($this->EBMLbuffer, $actual_offset, $length)); + $this->current_offset += $length; + return $int_value; } - function EBML2Int($EBMLstring) { + /** + * @param int $length + * @param bool $check_buffer + * + * @return string|false + */ + private function readEBMLelementData($length, $check_buffer=false) { + if ($check_buffer && !$this->EnsureBufferHasEnoughData($length)) { + return false; + } + $data = substr($this->EBMLbuffer, $this->current_offset - $this->EBMLbuffer_offset, $length); + $this->current_offset += $length; + return $data; + } + + /** + * @param array $element + * @param int $parent_end + * @param array|bool $get_data + * + * @return bool + */ + private function getEBMLelement(&$element, $parent_end, $get_data=false) { + if ($this->current_offset >= $parent_end) { + return false; + } + + if (!$this->EnsureBufferHasEnoughData()) { + $this->current_offset = PHP_INT_MAX; // do not exit parser right now, allow to finish current loop to gather maximum information + return false; + } + + $element = array(); + + // set offset + $element['offset'] = $this->current_offset; + + // get ID + $element['id'] = $this->readEBMLint(); + + // get name + $element['id_name'] = self::EBMLidName($element['id']); + + // get length + $element['length'] = $this->readEBMLint(); + + // get end offset + $element['end'] = $this->current_offset + $element['length']; + + // get raw data + $dont_parse = (in_array($element['id'], $this->unuseful_elements) || $element['id_name'] == dechex($element['id'])); + if (($get_data === true || (is_array($get_data) && !in_array($element['id'], $get_data))) && !$dont_parse) { + $element['data'] = $this->readEBMLelementData($element['length'], $element); + } + + return true; + } + + /** + * @param string $type + * @param int $line + * @param array $element + */ + private function unhandledElement($type, $line, $element) { + // warn only about unknown and missed elements, not about unuseful + if (!in_array($element['id'], $this->unuseful_elements)) { + $this->warning('Unhandled '.$type.' element ['.basename(__FILE__).':'.$line.'] ('.$element['id'].'::'.$element['id_name'].' ['.$element['length'].' bytes]) at '.$element['offset']); + } + + // increase offset for unparsed elements + if (!isset($element['data'])) { + $this->current_offset = $element['end']; + } + } + + /** + * @param array $SimpleTagArray + * + * @return bool + */ + private function ExtractCommentsSimpleTag($SimpleTagArray) { + if (!empty($SimpleTagArray['SimpleTag'])) { + foreach ($SimpleTagArray['SimpleTag'] as $SimpleTagKey => $SimpleTagData) { + if (!empty($SimpleTagData['TagName']) && !empty($SimpleTagData['TagString'])) { + $this->getid3->info['matroska']['comments'][strtolower($SimpleTagData['TagName'])][] = $SimpleTagData['TagString']; + } + if (!empty($SimpleTagData['SimpleTag'])) { + $this->ExtractCommentsSimpleTag($SimpleTagData); + } + } + } + + return true; + } + + /** + * @param int $parent_end + * + * @return array + */ + private function HandleEMBLSimpleTag($parent_end) { + $simpletag_entry = array(); + + while ($this->getEBMLelement($element, $parent_end, array(EBML_ID_SIMPLETAG))) { + switch ($element['id']) { + + case EBML_ID_TAGNAME: + case EBML_ID_TAGLANGUAGE: + case EBML_ID_TAGSTRING: + case EBML_ID_TAGBINARY: + $simpletag_entry[$element['id_name']] = $element['data']; + break; + + case EBML_ID_SIMPLETAG: + $simpletag_entry[$element['id_name']][] = $this->HandleEMBLSimpleTag($element['end']); + break; + + case EBML_ID_TAGDEFAULT: + $simpletag_entry[$element['id_name']] = (bool)getid3_lib::BigEndian2Int($element['data']); + break; + + default: + $this->unhandledElement('tag.simpletag', __LINE__, $element); + break; + } + } + + return $simpletag_entry; + } + + /** + * @param array $element + * @param int $block_type + * @param array $info + * + * @return array + */ + private function HandleEMBLClusterBlock($element, $block_type, &$info) { + // http://www.matroska.org/technical/specs/index.html#block_structure + // http://www.matroska.org/technical/specs/index.html#simpleblock_structure + + $block_data = array(); + $block_data['tracknumber'] = $this->readEBMLint(); + $block_data['timecode'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(2), false, true); + $block_data['flags_raw'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)); + + if ($block_type == EBML_ID_CLUSTERSIMPLEBLOCK) { + $block_data['flags']['keyframe'] = (($block_data['flags_raw'] & 0x80) >> 7); + //$block_data['flags']['reserved1'] = (($block_data['flags_raw'] & 0x70) >> 4); + } + else { + //$block_data['flags']['reserved1'] = (($block_data['flags_raw'] & 0xF0) >> 4); + } + $block_data['flags']['invisible'] = (bool)(($block_data['flags_raw'] & 0x08) >> 3); + $block_data['flags']['lacing'] = (($block_data['flags_raw'] & 0x06) >> 1); // 00=no lacing; 01=Xiph lacing; 11=EBML lacing; 10=fixed-size lacing + if ($block_type == EBML_ID_CLUSTERSIMPLEBLOCK) { + $block_data['flags']['discardable'] = (($block_data['flags_raw'] & 0x01)); + } + else { + //$block_data['flags']['reserved2'] = (($block_data['flags_raw'] & 0x01) >> 0); + } + $block_data['flags']['lacing_type'] = self::BlockLacingType($block_data['flags']['lacing']); + + // Lace (when lacing bit is set) + if ($block_data['flags']['lacing'] > 0) { + $block_data['lace_frames'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)) + 1; // Number of frames in the lace-1 (uint8) + if ($block_data['flags']['lacing'] != 0x02) { + for ($i = 1; $i < $block_data['lace_frames']; $i ++) { // Lace-coded size of each frame of the lace, except for the last one (multiple uint8). *This is not used with Fixed-size lacing as it is calculated automatically from (total size of lace) / (number of frames in lace). + if ($block_data['flags']['lacing'] == 0x03) { // EBML lacing + $block_data['lace_frames_size'][$i] = $this->readEBMLint(); // TODO: read size correctly, calc size for the last frame. For now offsets are deteminded OK with readEBMLint() and that's the most important thing. + } + else { // Xiph lacing + $block_data['lace_frames_size'][$i] = 0; + do { + $size = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)); + $block_data['lace_frames_size'][$i] += $size; + } + while ($size == 255); + } + } + if ($block_data['flags']['lacing'] == 0x01) { // calc size of the last frame only for Xiph lacing, till EBML sizes are now anyway determined incorrectly + $block_data['lace_frames_size'][] = $element['end'] - $this->current_offset - array_sum($block_data['lace_frames_size']); + } + } + } + + if (!isset($info['matroska']['track_data_offsets'][$block_data['tracknumber']])) { + $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['offset'] = $this->current_offset; + $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['length'] = $element['end'] - $this->current_offset; + //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['total_length'] = 0; + } + //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['total_length'] += $info['matroska']['track_data_offsets'][$block_data['tracknumber']]['length']; + //$info['matroska']['track_data_offsets'][$block_data['tracknumber']]['duration'] = $block_data['timecode'] * ((isset($info['matroska']['info'][0]['TimecodeScale']) ? $info['matroska']['info'][0]['TimecodeScale'] : 1000000) / 1000000000); + + // set offset manually + $this->current_offset = $element['end']; + + return $block_data; + } + + /** + * @param string $EBMLstring + * + * @return int|float|false + */ + private static function EBML2Int($EBMLstring) { // http://matroska.org/specs/ // Element ID coded with an UTF-8 like system: @@ -1475,89 +1562,129 @@ $this->warnings[] = 'This version of getID3() [v'.GETID3_VERSION.'] has problems // 0000 001x xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^49-2 // 0000 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^56-2 - $first_byte_int = ord($EBMLstring{0}); + $first_byte_int = ord($EBMLstring[0]); if (0x80 & $first_byte_int) { - $EBMLstring{0} = chr($first_byte_int & 0x7F); + $EBMLstring[0] = chr($first_byte_int & 0x7F); } elseif (0x40 & $first_byte_int) { - $EBMLstring{0} = chr($first_byte_int & 0x3F); + $EBMLstring[0] = chr($first_byte_int & 0x3F); } elseif (0x20 & $first_byte_int) { - $EBMLstring{0} = chr($first_byte_int & 0x1F); + $EBMLstring[0] = chr($first_byte_int & 0x1F); } elseif (0x10 & $first_byte_int) { - $EBMLstring{0} = chr($first_byte_int & 0x0F); + $EBMLstring[0] = chr($first_byte_int & 0x0F); } elseif (0x08 & $first_byte_int) { - $EBMLstring{0} = chr($first_byte_int & 0x07); + $EBMLstring[0] = chr($first_byte_int & 0x07); } elseif (0x04 & $first_byte_int) { - $EBMLstring{0} = chr($first_byte_int & 0x03); + $EBMLstring[0] = chr($first_byte_int & 0x03); } elseif (0x02 & $first_byte_int) { - $EBMLstring{0} = chr($first_byte_int & 0x01); + $EBMLstring[0] = chr($first_byte_int & 0x01); } elseif (0x01 & $first_byte_int) { - $EBMLstring{0} = chr($first_byte_int & 0x00); - } else { - return false; + $EBMLstring[0] = chr($first_byte_int & 0x00); } + return getid3_lib::BigEndian2Int($EBMLstring); } - - function EBMLdate2unix($EBMLdatestamp) { + /** + * @param int $EBMLdatestamp + * + * @return float + */ + private static function EBMLdate2unix($EBMLdatestamp) { // Date - signed 8 octets integer in nanoseconds with 0 indicating the precise beginning of the millennium (at 2001-01-01T00:00:00,000000000 UTC) // 978307200 == mktime(0, 0, 0, 1, 1, 2001) == January 1, 2001 12:00:00am UTC return round(($EBMLdatestamp / 1000000000) + 978307200); } + /** + * @param int $target_type + * + * @return string|int + */ + public static function TargetTypeValue($target_type) { + // http://www.matroska.org/technical/specs/tagging/index.html + static $TargetTypeValue = array(); + if (empty($TargetTypeValue)) { + $TargetTypeValue[10] = 'A: ~ V:shot'; // the lowest hierarchy found in music or movies + $TargetTypeValue[20] = 'A:subtrack/part/movement ~ V:scene'; // corresponds to parts of a track for audio (like a movement) + $TargetTypeValue[30] = 'A:track/song ~ V:chapter'; // the common parts of an album or a movie + $TargetTypeValue[40] = 'A:part/session ~ V:part/session'; // when an album or episode has different logical parts + $TargetTypeValue[50] = 'A:album/opera/concert ~ V:movie/episode/concert'; // the most common grouping level of music and video (equals to an episode for TV series) + $TargetTypeValue[60] = 'A:edition/issue/volume/opus ~ V:season/sequel/volume'; // a list of lower levels grouped together + $TargetTypeValue[70] = 'A:collection ~ V:collection'; // the high hierarchy consisting of many different lower items + } + return (isset($TargetTypeValue[$target_type]) ? $TargetTypeValue[$target_type] : $target_type); + } - function MatroskaBlockLacingType($lacingtype) { + /** + * @param int $lacingtype + * + * @return string|int + */ + public static function BlockLacingType($lacingtype) { // http://matroska.org/technical/specs/index.html#block_structure - static $MatroskaBlockLacingType = array(); - if (empty($MatroskaBlockLacingType)) { - $MatroskaBlockLacingType[0x00] = 'no lacing'; - $MatroskaBlockLacingType[0x01] = 'Xiph lacing'; - $MatroskaBlockLacingType[0x02] = 'fixed-size lacing'; - $MatroskaBlockLacingType[0x03] = 'EBML lacing'; + static $BlockLacingType = array(); + if (empty($BlockLacingType)) { + $BlockLacingType[0x00] = 'no lacing'; + $BlockLacingType[0x01] = 'Xiph lacing'; + $BlockLacingType[0x02] = 'fixed-size lacing'; + $BlockLacingType[0x03] = 'EBML lacing'; } - return (isset($MatroskaBlockLacingType[$lacingtype]) ? $MatroskaBlockLacingType[$lacingtype] : $lacingtype); + return (isset($BlockLacingType[$lacingtype]) ? $BlockLacingType[$lacingtype] : $lacingtype); } - function MatroskaCodecIDtoCommonName($codecid) { + /** + * @param string $codecid + * + * @return string + */ + public static function CodecIDtoCommonName($codecid) { // http://www.matroska.org/technical/specs/codecid/index.html - static $MatroskaCodecIDlist = array(); - if (empty($MatroskaCodecIDlist)) { - $MatroskaCodecIDlist['A_AAC'] = 'aac'; - $MatroskaCodecIDlist['A_AAC/MPEG2/LC'] = 'aac'; - $MatroskaCodecIDlist['A_AC3'] = 'ac3'; - $MatroskaCodecIDlist['A_DTS'] = 'dts'; - $MatroskaCodecIDlist['A_FLAC'] = 'flac'; - $MatroskaCodecIDlist['A_MPEG/L1'] = 'mp1'; - $MatroskaCodecIDlist['A_MPEG/L2'] = 'mp2'; - $MatroskaCodecIDlist['A_MPEG/L3'] = 'mp3'; - $MatroskaCodecIDlist['A_PCM/INT/LIT'] = 'pcm'; // PCM Integer Little Endian - $MatroskaCodecIDlist['A_PCM/INT/BIG'] = 'pcm'; // PCM Integer Big Endian - $MatroskaCodecIDlist['A_QUICKTIME/QDMC'] = 'quicktime'; // Quicktime: QDesign Music - $MatroskaCodecIDlist['A_QUICKTIME/QDM2'] = 'quicktime'; // Quicktime: QDesign Music v2 - $MatroskaCodecIDlist['A_VORBIS'] = 'vorbis'; - $MatroskaCodecIDlist['V_MPEG1'] = 'mpeg'; - $MatroskaCodecIDlist['V_THEORA'] = 'theora'; - $MatroskaCodecIDlist['V_REAL/RV40'] = 'real'; - $MatroskaCodecIDlist['V_REAL/RV10'] = 'real'; - $MatroskaCodecIDlist['V_REAL/RV20'] = 'real'; - $MatroskaCodecIDlist['V_REAL/RV30'] = 'real'; - $MatroskaCodecIDlist['V_QUICKTIME'] = 'quicktime'; // Quicktime - $MatroskaCodecIDlist['V_MPEG4/ISO/AP'] = 'mpeg4'; - $MatroskaCodecIDlist['V_MPEG4/ISO/ASP'] = 'mpeg4'; - $MatroskaCodecIDlist['V_MPEG4/ISO/AVC'] = 'h264'; - $MatroskaCodecIDlist['V_MPEG4/ISO/SP'] = 'mpeg4'; + static $CodecIDlist = array(); + if (empty($CodecIDlist)) { + $CodecIDlist['A_AAC'] = 'aac'; + $CodecIDlist['A_AAC/MPEG2/LC'] = 'aac'; + $CodecIDlist['A_AC3'] = 'ac3'; + $CodecIDlist['A_EAC3'] = 'eac3'; + $CodecIDlist['A_DTS'] = 'dts'; + $CodecIDlist['A_FLAC'] = 'flac'; + $CodecIDlist['A_MPEG/L1'] = 'mp1'; + $CodecIDlist['A_MPEG/L2'] = 'mp2'; + $CodecIDlist['A_MPEG/L3'] = 'mp3'; + $CodecIDlist['A_PCM/INT/LIT'] = 'pcm'; // PCM Integer Little Endian + $CodecIDlist['A_PCM/INT/BIG'] = 'pcm'; // PCM Integer Big Endian + $CodecIDlist['A_QUICKTIME/QDMC'] = 'quicktime'; // Quicktime: QDesign Music + $CodecIDlist['A_QUICKTIME/QDM2'] = 'quicktime'; // Quicktime: QDesign Music v2 + $CodecIDlist['A_VORBIS'] = 'vorbis'; + $CodecIDlist['V_MPEG1'] = 'mpeg'; + $CodecIDlist['V_THEORA'] = 'theora'; + $CodecIDlist['V_REAL/RV40'] = 'real'; + $CodecIDlist['V_REAL/RV10'] = 'real'; + $CodecIDlist['V_REAL/RV20'] = 'real'; + $CodecIDlist['V_REAL/RV30'] = 'real'; + $CodecIDlist['V_QUICKTIME'] = 'quicktime'; // Quicktime + $CodecIDlist['V_MPEG4/ISO/AP'] = 'mpeg4'; + $CodecIDlist['V_MPEG4/ISO/ASP'] = 'mpeg4'; + $CodecIDlist['V_MPEG4/ISO/AVC'] = 'h264'; + $CodecIDlist['V_MPEG4/ISO/SP'] = 'mpeg4'; + $CodecIDlist['V_VP8'] = 'vp8'; + $CodecIDlist['V_MS/VFW/FOURCC'] = 'vcm'; // Microsoft (TM) Video Codec Manager (VCM) + $CodecIDlist['A_MS/ACM'] = 'acm'; // Microsoft (TM) Audio Codec Manager (ACM) } - return (isset($MatroskaCodecIDlist[$codecid]) ? $MatroskaCodecIDlist[$codecid] : $codecid); + return (isset($CodecIDlist[$codecid]) ? $CodecIDlist[$codecid] : $codecid); } - function EBMLidName($value) { + /** + * @param int $value + * + * @return string + */ + private static function EBMLidName($value) { static $EBMLidList = array(); if (empty($EBMLidList)) { $EBMLidList[EBML_ID_ASPECTRATIOTYPE] = 'AspectRatioType'; $EBMLidList[EBML_ID_ATTACHEDFILE] = 'AttachedFile'; $EBMLidList[EBML_ID_ATTACHMENTLINK] = 'AttachmentLink'; $EBMLidList[EBML_ID_ATTACHMENTS] = 'Attachments'; - $EBMLidList[EBML_ID_ATTACHMENTUID] = 'AttachmentUID'; $EBMLidList[EBML_ID_AUDIO] = 'Audio'; $EBMLidList[EBML_ID_BITDEPTH] = 'BitDepth'; $EBMLidList[EBML_ID_CHANNELPOSITIONS] = 'ChannelPositions'; @@ -1660,6 +1787,7 @@ $this->warnings[] = 'This version of getID3() [v'.GETID3_VERSION.'] has problems $EBMLidList[EBML_ID_DOCTYPEREADVERSION] = 'DocTypeReadVersion'; $EBMLidList[EBML_ID_DOCTYPEVERSION] = 'DocTypeVersion'; $EBMLidList[EBML_ID_DURATION] = 'Duration'; + $EBMLidList[EBML_ID_EBML] = 'EBML'; $EBMLidList[EBML_ID_EBMLMAXIDLENGTH] = 'EBMLMaxIDLength'; $EBMLidList[EBML_ID_EBMLMAXSIZELENGTH] = 'EBMLMaxSizeLength'; $EBMLidList[EBML_ID_EBMLREADVERSION] = 'EBMLReadVersion'; @@ -1704,13 +1832,16 @@ $this->warnings[] = 'This version of getID3() [v'.GETID3_VERSION.'] has problems $EBMLidList[EBML_ID_SEEKHEAD] = 'SeekHead'; $EBMLidList[EBML_ID_SEEKID] = 'SeekID'; $EBMLidList[EBML_ID_SEEKPOSITION] = 'SeekPosition'; + $EBMLidList[EBML_ID_SEGMENT] = 'Segment'; $EBMLidList[EBML_ID_SEGMENTFAMILY] = 'SegmentFamily'; $EBMLidList[EBML_ID_SEGMENTFILENAME] = 'SegmentFilename'; $EBMLidList[EBML_ID_SEGMENTUID] = 'SegmentUID'; $EBMLidList[EBML_ID_SIMPLETAG] = 'SimpleTag'; $EBMLidList[EBML_ID_CLUSTERSLICES] = 'ClusterSlices'; $EBMLidList[EBML_ID_STEREOMODE] = 'StereoMode'; + $EBMLidList[EBML_ID_OLDSTEREOMODE] = 'OldStereoMode'; $EBMLidList[EBML_ID_TAG] = 'Tag'; + $EBMLidList[EBML_ID_TAGATTACHMENTUID] = 'TagAttachmentUID'; $EBMLidList[EBML_ID_TAGBINARY] = 'TagBinary'; $EBMLidList[EBML_ID_TAGCHAPTERUID] = 'TagChapterUID'; $EBMLidList[EBML_ID_TAGDEFAULT] = 'TagDefault'; @@ -1741,9 +1872,51 @@ $this->warnings[] = 'This version of getID3() [v'.GETID3_VERSION.'] has problems $EBMLidList[EBML_ID_VOID] = 'Void'; $EBMLidList[EBML_ID_WRITINGAPP] = 'WritingApp'; } + return (isset($EBMLidList[$value]) ? $EBMLidList[$value] : dechex($value)); } -} + /** + * @param int $value + * + * @return string + */ + public static function displayUnit($value) { + // http://www.matroska.org/technical/specs/index.html#DisplayUnit + static $units = array( + 0 => 'pixels', + 1 => 'centimeters', + 2 => 'inches', + 3 => 'Display Aspect Ratio'); -?> \ No newline at end of file + return (isset($units[$value]) ? $units[$value] : 'unknown'); + } + + /** + * @param array $streams + * + * @return array + */ + private static function getDefaultStreamInfo($streams) + { + $stream = array(); + foreach (array_reverse($streams) as $stream) { + if ($stream['default']) { + break; + } + } + + $unset = array('default', 'name'); + foreach ($unset as $u) { + if (isset($stream[$u])) { + unset($stream[$u]); + } + } + + $info = $stream; + $info['streams'] = $streams; + + return $info; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.mpeg.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.mpeg.php new file mode 100644 index 00000000..6d6b1cc5 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.mpeg.php @@ -0,0 +1,683 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio-video.mpeg.php // +// module for analyzing MPEG files // +// dependencies: module.audio.mp3.php // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); + +class getid3_mpeg extends getid3_handler +{ + + const START_CODE_BASE = "\x00\x00\x01"; + const VIDEO_PICTURE_START = "\x00\x00\x01\x00"; + const VIDEO_USER_DATA_START = "\x00\x00\x01\xB2"; + const VIDEO_SEQUENCE_HEADER = "\x00\x00\x01\xB3"; + const VIDEO_SEQUENCE_ERROR = "\x00\x00\x01\xB4"; + const VIDEO_EXTENSION_START = "\x00\x00\x01\xB5"; + const VIDEO_SEQUENCE_END = "\x00\x00\x01\xB7"; + const VIDEO_GROUP_START = "\x00\x00\x01\xB8"; + const AUDIO_START = "\x00\x00\x01\xC0"; + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'mpeg'; + $this->fseek($info['avdataoffset']); + + $MPEGstreamData = $this->fread($this->getid3->option_fread_buffer_size); + $MPEGstreamBaseOffset = 0; // how far are we from the beginning of the file data ($info['avdataoffset']) + $MPEGstreamDataOffset = 0; // how far are we from the beginning of the buffer data (~32kB) + + $StartCodeValue = false; + $prevStartCodeValue = false; + + $GOPcounter = -1; + $FramesByGOP = array(); + $ParsedAVchannels = array(); + + do { +//echo $MPEGstreamDataOffset.' vs '.(strlen($MPEGstreamData) - 1024).'
    '; + if ($MPEGstreamDataOffset > (strlen($MPEGstreamData) - 16384)) { + // buffer running low, get more data +//echo 'reading more data
    '; + $MPEGstreamData .= $this->fread($this->getid3->option_fread_buffer_size); + if (strlen($MPEGstreamData) > $this->getid3->option_fread_buffer_size) { + $MPEGstreamData = substr($MPEGstreamData, $MPEGstreamDataOffset); + $MPEGstreamBaseOffset += $MPEGstreamDataOffset; + $MPEGstreamDataOffset = 0; + } + } + if (($StartCodeOffset = strpos($MPEGstreamData, self::START_CODE_BASE, $MPEGstreamDataOffset)) === false) { +//echo 'no more start codes found.
    '; + break; + } else { + $MPEGstreamDataOffset = $StartCodeOffset; + $prevStartCodeValue = $StartCodeValue; + $StartCodeValue = ord(substr($MPEGstreamData, $StartCodeOffset + 3, 1)); +//echo 'Found "'.strtoupper(dechex($StartCodeValue)).'" at offset '.($MPEGstreamBaseOffset + $StartCodeOffset).' ($MPEGstreamDataOffset = '.$MPEGstreamDataOffset.')
    '; + } + $MPEGstreamDataOffset += 4; + switch ($StartCodeValue) { + + case 0x00: // picture_start_code + if (!empty($info['mpeg']['video']['bitrate_mode']) && ($info['mpeg']['video']['bitrate_mode'] == 'vbr')) { + $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 4)); + $bitstreamoffset = 0; + + $PictureHeader = array(); + + $PictureHeader['temporal_reference'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 10); // 10-bit unsigned integer associated with each input picture. It is incremented by one, modulo 1024, for each input frame. When a frame is coded as two fields the temporal reference in the picture header of both fields is the same. Following a group start header the temporal reference of the earliest picture (in display order) shall be reset to zero. + $PictureHeader['picture_coding_type'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for picture_coding_type + $PictureHeader['vbv_delay'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 16); // 16 bits for vbv_delay + //... etc + + $FramesByGOP[$GOPcounter][] = $PictureHeader; + } + break; + + case 0xB3: // sequence_header_code + // Note: purposely doing the less-pretty (and probably a bit slower) method of using string of bits rather than bitwise operations. + // Mostly because PHP 32-bit doesn't handle unsigned integers well for bitwise operation. + // Also the MPEG stream is designed as a bitstream and often doesn't align nicely with byte boundaries. + $info['video']['codec'] = 'MPEG-1'; // will be updated if extension_start_code found + + $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 8)); + $bitstreamoffset = 0; + + $info['mpeg']['video']['raw']['horizontal_size_value'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 12); // 12 bits for horizontal frame size. Note: horizontal_size_extension, if present, will add 2 most-significant bits to this value + $info['mpeg']['video']['raw']['vertical_size_value'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 12); // 12 bits for vertical frame size. Note: vertical_size_extension, if present, will add 2 most-significant bits to this value + $info['mpeg']['video']['raw']['aspect_ratio_information'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for aspect_ratio_information + $info['mpeg']['video']['raw']['frame_rate_code'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for Frame Rate id code + $info['mpeg']['video']['raw']['bitrate'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 18); // 18 bits for bit_rate_value (18 set bits = VBR, otherwise bitrate = this value * 400) + $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. + $info['mpeg']['video']['raw']['vbv_buffer_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 10); // 10 bits vbv_buffer_size_value + $info['mpeg']['video']['raw']['constrained_param_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: constrained_param_flag + $info['mpeg']['video']['raw']['load_intra_quantiser_matrix'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: load_intra_quantiser_matrix + + if ($info['mpeg']['video']['raw']['load_intra_quantiser_matrix']) { + $bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 12, 64)); + for ($i = 0; $i < 64; $i++) { + $info['mpeg']['video']['raw']['intra_quantiser_matrix'][$i] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); + } + } + $info['mpeg']['video']['raw']['load_non_intra_quantiser_matrix'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); + + if ($info['mpeg']['video']['raw']['load_non_intra_quantiser_matrix']) { + $bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 12 + ($info['mpeg']['video']['raw']['load_intra_quantiser_matrix'] ? 64 : 0), 64)); + for ($i = 0; $i < 64; $i++) { + $info['mpeg']['video']['raw']['non_intra_quantiser_matrix'][$i] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); + } + } + + $info['mpeg']['video']['pixel_aspect_ratio'] = self::videoAspectRatioLookup($info['mpeg']['video']['raw']['aspect_ratio_information']); // may be overridden later if file turns out to be MPEG-2 + $info['mpeg']['video']['pixel_aspect_ratio_text'] = self::videoAspectRatioTextLookup($info['mpeg']['video']['raw']['aspect_ratio_information']); // may be overridden later if file turns out to be MPEG-2 + $info['mpeg']['video']['frame_rate'] = self::videoFramerateLookup($info['mpeg']['video']['raw']['frame_rate_code']); + if ($info['mpeg']['video']['raw']['bitrate'] == 0x3FFFF) { // 18 set bits = VBR + //$this->warning('This version of getID3() ['.$this->getid3->version().'] cannot determine average bitrate of VBR MPEG video files'); + $info['mpeg']['video']['bitrate_mode'] = 'vbr'; + } else { + $info['mpeg']['video']['bitrate'] = $info['mpeg']['video']['raw']['bitrate'] * 400; + $info['mpeg']['video']['bitrate_mode'] = 'cbr'; + $info['video']['bitrate'] = $info['mpeg']['video']['bitrate']; + } + $info['video']['resolution_x'] = $info['mpeg']['video']['raw']['horizontal_size_value']; + $info['video']['resolution_y'] = $info['mpeg']['video']['raw']['vertical_size_value']; + $info['video']['frame_rate'] = $info['mpeg']['video']['frame_rate']; + $info['video']['bitrate_mode'] = $info['mpeg']['video']['bitrate_mode']; + $info['video']['pixel_aspect_ratio'] = $info['mpeg']['video']['pixel_aspect_ratio']; + $info['video']['lossless'] = false; + $info['video']['bits_per_sample'] = 24; + break; + + case 0xB5: // extension_start_code + $info['video']['codec'] = 'MPEG-2'; + + $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 8)); // 48 bits for Sequence Extension ID; 61 bits for Sequence Display Extension ID; 59 bits for Sequence Scalable Extension ID + $bitstreamoffset = 0; + + $info['mpeg']['video']['raw']['extension_start_code_identifier'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for extension_start_code_identifier +//echo $info['mpeg']['video']['raw']['extension_start_code_identifier'].'
    '; + switch ($info['mpeg']['video']['raw']['extension_start_code_identifier']) { + case 1: // 0001 Sequence Extension ID + $info['mpeg']['video']['raw']['profile_and_level_indication'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for profile_and_level_indication + $info['mpeg']['video']['raw']['progressive_sequence'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: progressive_sequence + $info['mpeg']['video']['raw']['chroma_format'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for chroma_format + $info['mpeg']['video']['raw']['horizontal_size_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for horizontal_size_extension + $info['mpeg']['video']['raw']['vertical_size_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for vertical_size_extension + $info['mpeg']['video']['raw']['bit_rate_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 12); // 12 bits for bit_rate_extension + $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. + $info['mpeg']['video']['raw']['vbv_buffer_size_extension'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for vbv_buffer_size_extension + $info['mpeg']['video']['raw']['low_delay'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: low_delay + $info['mpeg']['video']['raw']['frame_rate_extension_n'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for frame_rate_extension_n + $info['mpeg']['video']['raw']['frame_rate_extension_d'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for frame_rate_extension_d + + $info['video']['resolution_x'] = ($info['mpeg']['video']['raw']['horizontal_size_extension'] << 12) | $info['mpeg']['video']['raw']['horizontal_size_value']; + $info['video']['resolution_y'] = ($info['mpeg']['video']['raw']['vertical_size_extension'] << 12) | $info['mpeg']['video']['raw']['vertical_size_value']; + $info['video']['interlaced'] = !$info['mpeg']['video']['raw']['progressive_sequence']; + $info['mpeg']['video']['interlaced'] = !$info['mpeg']['video']['raw']['progressive_sequence']; + $info['mpeg']['video']['chroma_format'] = self::chromaFormatTextLookup($info['mpeg']['video']['raw']['chroma_format']); + + if (isset($info['mpeg']['video']['raw']['aspect_ratio_information'])) { + // MPEG-2 defines the aspect ratio flag differently from MPEG-1, but the MPEG-2 extension start code may occur after we've already looked up the aspect ratio assuming it was MPEG-1, so re-lookup assuming MPEG-2 + // This must be done after the extended size is known, so the display aspect ratios can be converted to pixel aspect ratios. + $info['mpeg']['video']['pixel_aspect_ratio'] = self::videoAspectRatioLookup($info['mpeg']['video']['raw']['aspect_ratio_information'], 2, $info['video']['resolution_x'], $info['video']['resolution_y']); + $info['mpeg']['video']['pixel_aspect_ratio_text'] = self::videoAspectRatioTextLookup($info['mpeg']['video']['raw']['aspect_ratio_information'], 2); + $info['video']['pixel_aspect_ratio'] = $info['mpeg']['video']['pixel_aspect_ratio']; + $info['video']['pixel_aspect_ratio_text'] = $info['mpeg']['video']['pixel_aspect_ratio_text']; + } + + break; + + case 2: // 0010 Sequence Display Extension ID + $info['mpeg']['video']['raw']['video_format'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for video_format + $info['mpeg']['video']['raw']['colour_description'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: colour_description + if ($info['mpeg']['video']['raw']['colour_description']) { + $info['mpeg']['video']['raw']['colour_primaries'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for colour_primaries + $info['mpeg']['video']['raw']['transfer_characteristics'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for transfer_characteristics + $info['mpeg']['video']['raw']['matrix_coefficients'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for matrix_coefficients + } + $info['mpeg']['video']['raw']['display_horizontal_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for display_horizontal_size + $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. + $info['mpeg']['video']['raw']['display_vertical_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for display_vertical_size + + $info['mpeg']['video']['video_format'] = self::videoFormatTextLookup($info['mpeg']['video']['raw']['video_format']); + break; + + case 3: // 0011 Quant Matrix Extension ID + break; + + case 5: // 0101 Sequence Scalable Extension ID + $info['mpeg']['video']['raw']['scalable_mode'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for scalable_mode + $info['mpeg']['video']['raw']['layer_id'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for layer_id + if ($info['mpeg']['video']['raw']['scalable_mode'] == 1) { // "spatial scalability" + $info['mpeg']['video']['raw']['lower_layer_prediction_horizontal_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for lower_layer_prediction_horizontal_size + $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. + $info['mpeg']['video']['raw']['lower_layer_prediction_vertical_size'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 14); // 14 bits for lower_layer_prediction_vertical_size + $info['mpeg']['video']['raw']['horizontal_subsampling_factor_m'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for horizontal_subsampling_factor_m + $info['mpeg']['video']['raw']['horizontal_subsampling_factor_n'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for horizontal_subsampling_factor_n + $info['mpeg']['video']['raw']['vertical_subsampling_factor_m'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for vertical_subsampling_factor_m + $info['mpeg']['video']['raw']['vertical_subsampling_factor_n'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for vertical_subsampling_factor_n + } elseif ($info['mpeg']['video']['raw']['scalable_mode'] == 3) { // "temporal scalability" + $info['mpeg']['video']['raw']['picture_mux_enable'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: picture_mux_enable + if ($info['mpeg']['video']['raw']['picture_mux_enable']) { + $info['mpeg']['video']['raw']['mux_to_progressive_sequence'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: mux_to_progressive_sequence + } + $info['mpeg']['video']['raw']['picture_mux_order'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for picture_mux_order + $info['mpeg']['video']['raw']['picture_mux_factor'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for picture_mux_factor + } + + $info['mpeg']['video']['scalable_mode'] = self::scalableModeTextLookup($info['mpeg']['video']['raw']['scalable_mode']); + break; + + case 7: // 0111 Picture Display Extension ID + break; + + case 8: // 1000 Picture Coding Extension ID + $info['mpeg']['video']['raw']['f_code_00'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[0][0] (forward horizontal) + $info['mpeg']['video']['raw']['f_code_01'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[0][1] (forward vertical) + $info['mpeg']['video']['raw']['f_code_10'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[1][0] (backward horizontal) + $info['mpeg']['video']['raw']['f_code_11'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 4); // 4 bits for f_code[1][1] (backward vertical) + $info['mpeg']['video']['raw']['intra_dc_precision'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for intra_dc_precision + $info['mpeg']['video']['raw']['picture_structure'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for picture_structure + $info['mpeg']['video']['raw']['top_field_first'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: top_field_first + $info['mpeg']['video']['raw']['frame_pred_frame_dct'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: frame_pred_frame_dct + $info['mpeg']['video']['raw']['concealment_motion_vectors'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: concealment_motion_vectors + $info['mpeg']['video']['raw']['q_scale_type'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: q_scale_type + $info['mpeg']['video']['raw']['intra_vlc_format'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: intra_vlc_format + $info['mpeg']['video']['raw']['alternate_scan'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: alternate_scan + $info['mpeg']['video']['raw']['repeat_first_field'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: repeat_first_field + $info['mpeg']['video']['raw']['chroma_420_type'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: chroma_420_type + $info['mpeg']['video']['raw']['progressive_frame'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: progressive_frame + $info['mpeg']['video']['raw']['composite_display_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: composite_display_flag + if ($info['mpeg']['video']['raw']['composite_display_flag']) { + $info['mpeg']['video']['raw']['v_axis'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: v_axis + $info['mpeg']['video']['raw']['field_sequence'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 3); // 3 bits for field_sequence + $info['mpeg']['video']['raw']['sub_carrier'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: sub_carrier + $info['mpeg']['video']['raw']['burst_amplitude'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 7); // 7 bits for burst_amplitude + $info['mpeg']['video']['raw']['sub_carrier_phase'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 8 bits for sub_carrier_phase + } + + $info['mpeg']['video']['intra_dc_precision_bits'] = $info['mpeg']['video']['raw']['intra_dc_precision'] + 8; + $info['mpeg']['video']['picture_structure'] = self::pictureStructureTextLookup($info['mpeg']['video']['raw']['picture_structure']); + break; + + case 9: // 1001 Picture Spatial Scalable Extension ID + break; + case 10: // 1010 Picture Temporal Scalable Extension ID + break; + + default: + $this->warning('Unexpected $info[mpeg][video][raw][extension_start_code_identifier] value of '.$info['mpeg']['video']['raw']['extension_start_code_identifier']); + break; + } + break; + + + case 0xB8: // group_of_pictures_header + $GOPcounter++; + if (!empty($info['mpeg']['video']['bitrate_mode']) && ($info['mpeg']['video']['bitrate_mode'] == 'vbr')) { + $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 4, 4)); // 27 bits needed for group_of_pictures_header + $bitstreamoffset = 0; + + $GOPheader = array(); + + $GOPheader['byte_offset'] = $MPEGstreamBaseOffset + $StartCodeOffset; + $GOPheader['drop_frame_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: drop_frame_flag + $GOPheader['time_code_hours'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 5); // 5 bits for time_code_hours + $GOPheader['time_code_minutes'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 6); // 6 bits for time_code_minutes + $marker_bit = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // The term "marker_bit" indicates a one bit field in which the value zero is forbidden. These marker bits are introduced at several points in the syntax to avoid start code emulation. + $GOPheader['time_code_seconds'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 6); // 6 bits for time_code_seconds + $GOPheader['time_code_pictures'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 6); // 6 bits for time_code_pictures + $GOPheader['closed_gop'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: closed_gop + $GOPheader['broken_link'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: broken_link + + $time_code_separator = ($GOPheader['drop_frame_flag'] ? ';' : ':'); // While non-drop time code is displayed with colons separating the digit pairs "HH:MM:SS:FF" drop frame is usually represented with a semi-colon (;) or period (.) as the divider between all the digit pairs "HH;MM;SS;FF", "HH.MM.SS.FF" + $GOPheader['time_code'] = sprintf('%02d'.$time_code_separator.'%02d'.$time_code_separator.'%02d'.$time_code_separator.'%02d', $GOPheader['time_code_hours'], $GOPheader['time_code_minutes'], $GOPheader['time_code_seconds'], $GOPheader['time_code_pictures']); + + $info['mpeg']['group_of_pictures'][] = $GOPheader; + } + break; + + case 0xC0: // audio stream + case 0xC1: // audio stream + case 0xC2: // audio stream + case 0xC3: // audio stream + case 0xC4: // audio stream + case 0xC5: // audio stream + case 0xC6: // audio stream + case 0xC7: // audio stream + case 0xC8: // audio stream + case 0xC9: // audio stream + case 0xCA: // audio stream + case 0xCB: // audio stream + case 0xCC: // audio stream + case 0xCD: // audio stream + case 0xCE: // audio stream + case 0xCF: // audio stream + case 0xD0: // audio stream + case 0xD1: // audio stream + case 0xD2: // audio stream + case 0xD3: // audio stream + case 0xD4: // audio stream + case 0xD5: // audio stream + case 0xD6: // audio stream + case 0xD7: // audio stream + case 0xD8: // audio stream + case 0xD9: // audio stream + case 0xDA: // audio stream + case 0xDB: // audio stream + case 0xDC: // audio stream + case 0xDD: // audio stream + case 0xDE: // audio stream + case 0xDF: // audio stream + //case 0xE0: // video stream + //case 0xE1: // video stream + //case 0xE2: // video stream + //case 0xE3: // video stream + //case 0xE4: // video stream + //case 0xE5: // video stream + //case 0xE6: // video stream + //case 0xE7: // video stream + //case 0xE8: // video stream + //case 0xE9: // video stream + //case 0xEA: // video stream + //case 0xEB: // video stream + //case 0xEC: // video stream + //case 0xED: // video stream + //case 0xEE: // video stream + //case 0xEF: // video stream + if (isset($ParsedAVchannels[$StartCodeValue])) { + break; + } + $ParsedAVchannels[$StartCodeValue] = $StartCodeValue; + // http://en.wikipedia.org/wiki/Packetized_elementary_stream + // http://dvd.sourceforge.net/dvdinfo/pes-hdr.html +/* + $PackedElementaryStream = array(); + if ($StartCodeValue >= 0xE0) { + $PackedElementaryStream['stream_type'] = 'video'; + $PackedElementaryStream['stream_id'] = $StartCodeValue - 0xE0; + } else { + $PackedElementaryStream['stream_type'] = 'audio'; + $PackedElementaryStream['stream_id'] = $StartCodeValue - 0xC0; + } + $PackedElementaryStream['packet_length'] = getid3_lib::BigEndian2Int(substr($MPEGstreamData, $StartCodeOffset + 4, 2)); + + $bitstream = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 6, 3)); // more may be needed below + $bitstreamoffset = 0; + + $PackedElementaryStream['marker_bits'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for marker_bits -- should be "10" = 2 +echo 'marker_bits = '.$PackedElementaryStream['marker_bits'].'
    '; + $PackedElementaryStream['scrambling_control'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 2); // 2 bits for scrambling_control -- 00 implies not scrambled + $PackedElementaryStream['priority'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: priority + $PackedElementaryStream['data_alignment_indicator'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: data_alignment_indicator -- 1 indicates that the PES packet header is immediately followed by the video start code or audio syncword + $PackedElementaryStream['copyright'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: copyright -- 1 implies copyrighted + $PackedElementaryStream['original_or_copy'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: original_or_copy -- 1 implies original + $PackedElementaryStream['pts_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: pts_flag -- Presentation Time Stamp + $PackedElementaryStream['dts_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: dts_flag -- Decode Time Stamp + $PackedElementaryStream['escr_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: escr_flag -- Elementary Stream Clock Reference + $PackedElementaryStream['es_rate_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: es_rate_flag -- Elementary Stream [data] Rate + $PackedElementaryStream['dsm_trick_mode_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: dsm_trick_mode_flag -- DSM trick mode - not used by DVD + $PackedElementaryStream['additional_copy_info_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: additional_copy_info_flag + $PackedElementaryStream['crc_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: crc_flag + $PackedElementaryStream['extension_flag'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 1); // 1 bit flag: extension_flag + $PackedElementaryStream['pes_remain_header_length'] = self::readBitsFromStream($bitstream, $bitstreamoffset, 8); // 1 bit flag: priority + + $additional_header_bytes = 0; + $additional_header_bytes += ($PackedElementaryStream['pts_flag'] ? 5 : 0); + $additional_header_bytes += ($PackedElementaryStream['dts_flag'] ? 5 : 0); + $additional_header_bytes += ($PackedElementaryStream['escr_flag'] ? 6 : 0); + $additional_header_bytes += ($PackedElementaryStream['es_rate_flag'] ? 3 : 0); + $additional_header_bytes += ($PackedElementaryStream['additional_copy_info_flag'] ? 1 : 0); + $additional_header_bytes += ($PackedElementaryStream['crc_flag'] ? 2 : 0); + $additional_header_bytes += ($PackedElementaryStream['extension_flag'] ? 1 : 0); +$PackedElementaryStream['additional_header_bytes'] = $additional_header_bytes; + $bitstream .= getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $StartCodeOffset + 9, $additional_header_bytes)); + + $info['mpeg']['packed_elementary_streams'][$PackedElementaryStream['stream_type']][$PackedElementaryStream['stream_id']][] = $PackedElementaryStream; +*/ + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_temp->info = $info; + $getid3_mp3 = new getid3_mp3($getid3_temp); + for ($i = 0; $i <= 7; $i++) { + // some files have the MPEG-audio header 8 bytes after the end of the $00 $00 $01 $C0 signature, some have it up to 13 bytes (or more?) after + // I have no idea why or what the difference is, so this is a stupid hack. + // If anybody has any better idea of what's going on, please let me know - info@getid3.org + $getid3_temp->info = $info; // only overwrite real data if valid header found +//echo 'audio at? '.($MPEGstreamBaseOffset + $StartCodeOffset + 4 + 8 + $i).'
    '; + if ($getid3_mp3->decodeMPEGaudioHeader($MPEGstreamBaseOffset + $StartCodeOffset + 4 + 8 + $i, $getid3_temp->info, false)) { +//echo 'yes!
    '; + $info = $getid3_temp->info; + $info['audio']['bitrate_mode'] = 'cbr'; + $info['audio']['lossless'] = false; + break; + } + } + unset($getid3_temp, $getid3_mp3); + break; + + case 0xBC: // Program Stream Map + case 0xBD: // Private stream 1 (non MPEG audio, subpictures) + case 0xBE: // Padding stream + case 0xBF: // Private stream 2 (navigation data) + case 0xF0: // ECM stream + case 0xF1: // EMM stream + case 0xF2: // DSM-CC stream + case 0xF3: // ISO/IEC_13522_stream + case 0xF4: // ITU-I Rec. H.222.1 type A + case 0xF5: // ITU-I Rec. H.222.1 type B + case 0xF6: // ITU-I Rec. H.222.1 type C + case 0xF7: // ITU-I Rec. H.222.1 type D + case 0xF8: // ITU-I Rec. H.222.1 type E + case 0xF9: // ancilliary stream + case 0xFA: // ISO/IEC 14496-1 SL-packtized stream + case 0xFB: // ISO/IEC 14496-1 FlexMux stream + case 0xFC: // metadata stream + case 0xFD: // extended stream ID + case 0xFE: // reserved data stream + case 0xFF: // program stream directory + // ignore + break; + + default: + // ignore + break; + } + } while (true); + + + +// // Temporary hack to account for interleaving overhead: +// if (!empty($info['video']['bitrate']) && !empty($info['audio']['bitrate'])) { +// $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / ($info['video']['bitrate'] + $info['audio']['bitrate']); +// +// // Interleaved MPEG audio/video files have a certain amount of overhead that varies +// // by both video and audio bitrates, and not in any sensible, linear/logarithmic pattern +// // Use interpolated lookup tables to approximately guess how much is overhead, because +// // playtime is calculated as filesize / total-bitrate +// $info['playtime_seconds'] *= self::systemNonOverheadPercentage($info['video']['bitrate'], $info['audio']['bitrate']); +// +// //switch ($info['video']['bitrate']) { +// // case('5000000'): +// // $multiplier = 0.93292642112380355828048824319889; +// // break; +// // case('5500000'): +// // $multiplier = 0.93582895375200989965359777343219; +// // break; +// // case('6000000'): +// // $multiplier = 0.93796247714820932532911373859139; +// // break; +// // case('7000000'): +// // $multiplier = 0.9413264083635103463010117778776; +// // break; +// // default: +// // $multiplier = 1; +// // break; +// //} +// //$info['playtime_seconds'] *= $multiplier; +// //$this->warning('Interleaved MPEG audio/video playtime may be inaccurate. With current hack should be within a few seconds of accurate. Report to info@getid3.org if off by more than 10 seconds.'); +// if ($info['video']['bitrate'] < 50000) { +// $this->warning('Interleaved MPEG audio/video playtime may be slightly inaccurate for video bitrates below 100kbps. Except in extreme low-bitrate situations, error should be less than 1%. Report to info@getid3.org if greater than this.'); +// } +// } +// +/* +$time_prev = 0; +$byte_prev = 0; +$vbr_bitrates = array(); +foreach ($info['mpeg']['group_of_pictures'] as $gopkey => $gopdata) { + $time_this = ($gopdata['time_code_hours'] * 3600) + ($gopdata['time_code_minutes'] * 60) + $gopdata['time_code_seconds'] + ($gopdata['time_code_seconds'] / 30); + $byte_this = $gopdata['byte_offset']; + if ($gopkey > 0) { + if ($time_this > $time_prev) { + $bytedelta = $byte_this - $byte_prev; + $timedelta = $time_this - $time_prev; + $this_bitrate = ($bytedelta * 8) / $timedelta; +echo $gopkey.': ('.number_format($time_prev, 2).'-'.number_format($time_this, 2).') '.number_format($bytedelta).' bytes over '.number_format($timedelta, 3).' seconds = '.number_format($this_bitrate / 1000, 2).'kbps
    '; + $time_prev = $time_this; + $byte_prev = $byte_this; + $vbr_bitrates[] = $this_bitrate; + } + } +} +echo 'average_File_bitrate = '.number_format(array_sum($vbr_bitrates) / count($vbr_bitrates), 1).'
    '; +*/ +//echo '
    '.print_r($FramesByGOP, true).'
    '; + if (!empty($info['mpeg']['video']['bitrate_mode']) && ($info['mpeg']['video']['bitrate_mode'] == 'vbr')) { + $last_GOP_id = max(array_keys($FramesByGOP)); + $frames_in_last_GOP = count($FramesByGOP[$last_GOP_id]); + $gopdata = &$info['mpeg']['group_of_pictures'][$last_GOP_id]; + $info['playtime_seconds'] = ($gopdata['time_code_hours'] * 3600) + ($gopdata['time_code_minutes'] * 60) + $gopdata['time_code_seconds'] + (($gopdata['time_code_pictures'] + $frames_in_last_GOP + 1) / $info['mpeg']['video']['frame_rate']); + if (!isset($info['video']['bitrate'])) { + $overall_bitrate = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['playtime_seconds']; + $info['video']['bitrate'] = $overall_bitrate - (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0); + } + unset($info['mpeg']['group_of_pictures']); + } + + return true; + } + + /** + * @param string $bitstream + * @param int $bitstreamoffset + * @param int $bits_to_read + * @param bool $return_singlebit_as_boolean + * + * @return bool|int + */ + private function readBitsFromStream(&$bitstream, &$bitstreamoffset, $bits_to_read, $return_singlebit_as_boolean=true) { + $return = bindec(substr($bitstream, $bitstreamoffset, $bits_to_read)); + $bitstreamoffset += $bits_to_read; + if (($bits_to_read == 1) && $return_singlebit_as_boolean) { + $return = (bool) $return; + } + return $return; + } + + /** + * @param int $VideoBitrate + * @param int $AudioBitrate + * + * @return float|int + */ + public static function systemNonOverheadPercentage($VideoBitrate, $AudioBitrate) { + $OverheadPercentage = 0; + + $AudioBitrate = max(min($AudioBitrate / 1000, 384), 32); // limit to range of 32kbps - 384kbps (should be only legal bitrates, but maybe VBR?) + $VideoBitrate = max(min($VideoBitrate / 1000, 10000), 10); // limit to range of 10kbps - 10Mbps (beyond that curves flatten anyways, no big loss) + + + $OverheadMultiplierByBitrate = array(); + //OMBB[audiobitrate] = array(video-10kbps, video-100kbps, video-1000kbps, video-10000kbps) + $OverheadMultiplierByBitrate[32] = array(0, 0.9676287944368530, 0.9802276264360310, 0.9844916183244460, 0.9852821845179940); + $OverheadMultiplierByBitrate[48] = array(0, 0.9779100089209830, 0.9787770035359320, 0.9846738664076130, 0.9852683013799960); + $OverheadMultiplierByBitrate[56] = array(0, 0.9731249855367600, 0.9776624308938040, 0.9832606361852130, 0.9843922606633340); + $OverheadMultiplierByBitrate[64] = array(0, 0.9755642683275760, 0.9795256705493390, 0.9836573009193170, 0.9851122539404470); + $OverheadMultiplierByBitrate[96] = array(0, 0.9788025247497290, 0.9798553314148700, 0.9822956869792560, 0.9834815119124690); + $OverheadMultiplierByBitrate[128] = array(0, 0.9816940050925480, 0.9821675936072120, 0.9829756927470870, 0.9839763420152050); + $OverheadMultiplierByBitrate[160] = array(0, 0.9825894094561180, 0.9820913399073960, 0.9823907143253970, 0.9832821783651570); + $OverheadMultiplierByBitrate[192] = array(0, 0.9832038474336260, 0.9825731694317960, 0.9821028622712400, 0.9828262076447620); + $OverheadMultiplierByBitrate[224] = array(0, 0.9836516298538770, 0.9824718601823890, 0.9818302180625380, 0.9823735101626480); + $OverheadMultiplierByBitrate[256] = array(0, 0.9845863022094920, 0.9837229411967540, 0.9824521662210830, 0.9828645172100790); + $OverheadMultiplierByBitrate[320] = array(0, 0.9849565280263180, 0.9837683142805110, 0.9822885275960400, 0.9824424382727190); + $OverheadMultiplierByBitrate[384] = array(0, 0.9856094774357600, 0.9844573394432720, 0.9825970399837330, 0.9824673808303890); + + $BitrateToUseMin = 32; + $BitrateToUseMax = 32; + $previousBitrate = 32; + foreach ($OverheadMultiplierByBitrate as $key => $value) { + if ($AudioBitrate >= $previousBitrate) { + $BitrateToUseMin = $previousBitrate; + } + if ($AudioBitrate < $key) { + $BitrateToUseMax = $key; + break; + } + $previousBitrate = $key; + } + $FactorA = ($BitrateToUseMax - $AudioBitrate) / ($BitrateToUseMax - $BitrateToUseMin); + + $VideoBitrateLog10 = log10($VideoBitrate); + $VideoFactorMin1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][floor($VideoBitrateLog10)]; + $VideoFactorMin2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][floor($VideoBitrateLog10)]; + $VideoFactorMax1 = $OverheadMultiplierByBitrate[$BitrateToUseMin][ceil($VideoBitrateLog10)]; + $VideoFactorMax2 = $OverheadMultiplierByBitrate[$BitrateToUseMax][ceil($VideoBitrateLog10)]; + $FactorV = $VideoBitrateLog10 - floor($VideoBitrateLog10); + + $OverheadPercentage = $VideoFactorMin1 * $FactorA * $FactorV; + $OverheadPercentage += $VideoFactorMin2 * (1 - $FactorA) * $FactorV; + $OverheadPercentage += $VideoFactorMax1 * $FactorA * (1 - $FactorV); + $OverheadPercentage += $VideoFactorMax2 * (1 - $FactorA) * (1 - $FactorV); + + return $OverheadPercentage; + } + + /** + * @param int $rawframerate + * + * @return float + */ + public static function videoFramerateLookup($rawframerate) { + $lookup = array(0, 23.976, 24, 25, 29.97, 30, 50, 59.94, 60); + return (float) (isset($lookup[$rawframerate]) ? $lookup[$rawframerate] : 0); + } + + /** + * @param int $rawaspectratio + * @param int $mpeg_version + * @param int $width + * @param int $height + * + * @return float + */ + public static function videoAspectRatioLookup($rawaspectratio, $mpeg_version=1, $width=0, $height=0) { + $lookup = array( + 1 => array(0, 1, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, 0.8935, 0.9157, 0.9815, 1.0255, 1.0695, 1.0950, 1.1575, 1.2015, 0), + 2 => array(0, 1, 1.3333, 1.7778, 2.2100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), + ); + $ratio = (float) (isset($lookup[$mpeg_version][$rawaspectratio]) ? $lookup[$mpeg_version][$rawaspectratio] : 0); + if ($mpeg_version == 2 && $ratio != 1 && $width != 0) { + // Calculate pixel aspect ratio from MPEG-2 display aspect ratio + $ratio = $ratio * $height / $width; + } + return $ratio; + } + + /** + * @param int $rawaspectratio + * @param int $mpeg_version + * + * @return string + */ + public static function videoAspectRatioTextLookup($rawaspectratio, $mpeg_version=1) { + $lookup = array( + 1 => array('forbidden', 'square pixels', '0.6735', '16:9, 625 line, PAL', '0.7615', '0.8055', '16:9, 525 line, NTSC', '0.8935', '4:3, 625 line, PAL, CCIR601', '0.9815', '1.0255', '1.0695', '4:3, 525 line, NTSC, CCIR601', '1.1575', '1.2015', 'reserved'), + 2 => array('forbidden', 'square pixels', '4:3', '16:9', '2.21:1', 'reserved', 'reserved', 'reserved', 'reserved', 'reserved', 'reserved', 'reserved', 'reserved', 'reserved', 'reserved', 'reserved'), // http://dvd.sourceforge.net/dvdinfo/mpeghdrs.html + ); + return (isset($lookup[$mpeg_version][$rawaspectratio]) ? $lookup[$mpeg_version][$rawaspectratio] : ''); + } + + /** + * @param int $video_format + * + * @return string + */ + public static function videoFormatTextLookup($video_format) { + // ISO/IEC 13818-2, section 6.3.6, Table 6-6. Meaning of video_format + $lookup = array('component', 'PAL', 'NTSC', 'SECAM', 'MAC', 'Unspecified video format', 'reserved(6)', 'reserved(7)'); + return (isset($lookup[$video_format]) ? $lookup[$video_format] : ''); + } + + /** + * @param int $scalable_mode + * + * @return string + */ + public static function scalableModeTextLookup($scalable_mode) { + // ISO/IEC 13818-2, section 6.3.8, Table 6-10. Definition of scalable_mode + $lookup = array('data partitioning', 'spatial scalability', 'SNR scalability', 'temporal scalability'); + return (isset($lookup[$scalable_mode]) ? $lookup[$scalable_mode] : ''); + } + + /** + * @param int $picture_structure + * + * @return string + */ + public static function pictureStructureTextLookup($picture_structure) { + // ISO/IEC 13818-2, section 6.3.11, Table 6-14 Meaning of picture_structure + $lookup = array('reserved', 'Top Field', 'Bottom Field', 'Frame picture'); + return (isset($lookup[$picture_structure]) ? $lookup[$picture_structure] : ''); + } + + /** + * @param int $chroma_format + * + * @return string + */ + public static function chromaFormatTextLookup($chroma_format) { + // ISO/IEC 13818-2, section 6.3.11, Table 6-14 Meaning of picture_structure + $lookup = array('reserved', '4:2:0', '4:2:2', '4:4:4'); + return (isset($lookup[$chroma_format]) ? $lookup[$chroma_format] : ''); + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.nsv.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.nsv.php new file mode 100644 index 00000000..043cdfc6 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.nsv.php @@ -0,0 +1,243 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.nsv.php // +// module for analyzing Nullsoft NSV files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_nsv extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + $NSVheader = $this->fread(4); + + switch ($NSVheader) { + case 'NSVs': + if ($this->getNSVsHeaderFilepointer(0)) { + $info['fileformat'] = 'nsv'; + $info['audio']['dataformat'] = 'nsv'; + $info['video']['dataformat'] = 'nsv'; + $info['audio']['lossless'] = false; + $info['video']['lossless'] = false; + } + break; + + case 'NSVf': + if ($this->getNSVfHeaderFilepointer(0)) { + $info['fileformat'] = 'nsv'; + $info['audio']['dataformat'] = 'nsv'; + $info['video']['dataformat'] = 'nsv'; + $info['audio']['lossless'] = false; + $info['video']['lossless'] = false; + $this->getNSVsHeaderFilepointer($info['nsv']['NSVf']['header_length']); + } + break; + + default: + $this->error('Expecting "NSVs" or "NSVf" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($NSVheader).'"'); + return false; + } + + if (!isset($info['nsv']['NSVf'])) { + $this->warning('NSVf header not present - cannot calculate playtime or bitrate'); + } + + return true; + } + + /** + * @param int $fileoffset + * + * @return bool + */ + public function getNSVsHeaderFilepointer($fileoffset) { + $info = &$this->getid3->info; + $this->fseek($fileoffset); + $NSVsheader = $this->fread(28); + $offset = 0; + + $info['nsv']['NSVs']['identifier'] = substr($NSVsheader, $offset, 4); + $offset += 4; + + if ($info['nsv']['NSVs']['identifier'] != 'NSVs') { + $this->error('expected "NSVs" at offset ('.$fileoffset.'), found "'.$info['nsv']['NSVs']['identifier'].'" instead'); + unset($info['nsv']['NSVs']); + return false; + } + + $info['nsv']['NSVs']['offset'] = $fileoffset; + + $info['nsv']['NSVs']['video_codec'] = substr($NSVsheader, $offset, 4); + $offset += 4; + $info['nsv']['NSVs']['audio_codec'] = substr($NSVsheader, $offset, 4); + $offset += 4; + $info['nsv']['NSVs']['resolution_x'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2)); + $offset += 2; + $info['nsv']['NSVs']['resolution_y'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2)); + $offset += 2; + + $info['nsv']['NSVs']['framerate_index'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + //$info['nsv']['NSVs']['unknown1b'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + //$info['nsv']['NSVs']['unknown1c'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + //$info['nsv']['NSVs']['unknown1d'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + //$info['nsv']['NSVs']['unknown2a'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + //$info['nsv']['NSVs']['unknown2b'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + //$info['nsv']['NSVs']['unknown2c'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + //$info['nsv']['NSVs']['unknown2d'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + + switch ($info['nsv']['NSVs']['audio_codec']) { + case 'PCM ': + $info['nsv']['NSVs']['bits_channel'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + $info['nsv']['NSVs']['channels'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1)); + $offset += 1; + $info['nsv']['NSVs']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2)); + $offset += 2; + + $info['audio']['sample_rate'] = $info['nsv']['NSVs']['sample_rate']; + break; + + case 'MP3 ': + case 'NONE': + default: + //$info['nsv']['NSVs']['unknown3'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 4)); + $offset += 4; + break; + } + + $info['video']['resolution_x'] = $info['nsv']['NSVs']['resolution_x']; + $info['video']['resolution_y'] = $info['nsv']['NSVs']['resolution_y']; + $info['nsv']['NSVs']['frame_rate'] = $this->NSVframerateLookup($info['nsv']['NSVs']['framerate_index']); + $info['video']['frame_rate'] = $info['nsv']['NSVs']['frame_rate']; + $info['video']['bits_per_sample'] = 24; + $info['video']['pixel_aspect_ratio'] = (float) 1; + + return true; + } + + /** + * @param int $fileoffset + * @param bool $getTOCoffsets + * + * @return bool + */ + public function getNSVfHeaderFilepointer($fileoffset, $getTOCoffsets=false) { + $info = &$this->getid3->info; + $this->fseek($fileoffset); + $NSVfheader = $this->fread(28); + $offset = 0; + + $info['nsv']['NSVf']['identifier'] = substr($NSVfheader, $offset, 4); + $offset += 4; + + if ($info['nsv']['NSVf']['identifier'] != 'NSVf') { + $this->error('expected "NSVf" at offset ('.$fileoffset.'), found "'.$info['nsv']['NSVf']['identifier'].'" instead'); + unset($info['nsv']['NSVf']); + return false; + } + + $info['nsv']['NSVs']['offset'] = $fileoffset; + + $info['nsv']['NSVf']['header_length'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); + $offset += 4; + $info['nsv']['NSVf']['file_size'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); + $offset += 4; + + if ($info['nsv']['NSVf']['file_size'] > $info['avdataend']) { + $this->warning('truncated file - NSVf header indicates '.$info['nsv']['NSVf']['file_size'].' bytes, file actually '.$info['avdataend'].' bytes'); + } + + $info['nsv']['NSVf']['playtime_ms'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); + $offset += 4; + $info['nsv']['NSVf']['meta_size'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); + $offset += 4; + $info['nsv']['NSVf']['TOC_entries_1'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); + $offset += 4; + $info['nsv']['NSVf']['TOC_entries_2'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); + $offset += 4; + + if ($info['nsv']['NSVf']['playtime_ms'] == 0) { + $this->error('Corrupt NSV file: NSVf.playtime_ms == zero'); + return false; + } + + $NSVfheader .= $this->fread($info['nsv']['NSVf']['meta_size'] + (4 * $info['nsv']['NSVf']['TOC_entries_1']) + (4 * $info['nsv']['NSVf']['TOC_entries_2'])); + $NSVfheaderlength = strlen($NSVfheader); + $info['nsv']['NSVf']['metadata'] = substr($NSVfheader, $offset, $info['nsv']['NSVf']['meta_size']); + $offset += $info['nsv']['NSVf']['meta_size']; + + if ($getTOCoffsets) { + $TOCcounter = 0; + while ($TOCcounter < $info['nsv']['NSVf']['TOC_entries_1']) { + if ($TOCcounter < $info['nsv']['NSVf']['TOC_entries_1']) { + $info['nsv']['NSVf']['TOC_1'][$TOCcounter] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4)); + $offset += 4; + $TOCcounter++; + } + } + } + + if (trim($info['nsv']['NSVf']['metadata']) != '') { + $info['nsv']['NSVf']['metadata'] = str_replace('`', "\x01", $info['nsv']['NSVf']['metadata']); + $CommentPairArray = explode("\x01".' ', $info['nsv']['NSVf']['metadata']); + foreach ($CommentPairArray as $CommentPair) { + if (strstr($CommentPair, '='."\x01")) { + list($key, $value) = explode('='."\x01", $CommentPair, 2); + $info['nsv']['comments'][strtolower($key)][] = trim(str_replace("\x01", '', $value)); + } + } + } + + $info['playtime_seconds'] = $info['nsv']['NSVf']['playtime_ms'] / 1000; + $info['bitrate'] = ($info['nsv']['NSVf']['file_size'] * 8) / $info['playtime_seconds']; + + return true; + } + + /** + * @param int $framerateindex + * + * @return float|false + */ + public static function NSVframerateLookup($framerateindex) { + if ($framerateindex <= 127) { + return (float) $framerateindex; + } + static $NSVframerateLookup = array(); + if (empty($NSVframerateLookup)) { + $NSVframerateLookup[129] = 29.970; + $NSVframerateLookup[131] = 23.976; + $NSVframerateLookup[133] = 14.985; + $NSVframerateLookup[197] = 59.940; + $NSVframerateLookup[199] = 47.952; + } + return (isset($NSVframerateLookup[$framerateindex]) ? $NSVframerateLookup[$framerateindex] : false); + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.quicktime.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.quicktime.php new file mode 100644 index 00000000..a769f9c1 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.quicktime.php @@ -0,0 +1,3025 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio-video.quicktime.php // +// module for analyzing Quicktime and MP3-in-MP4 files // +// dependencies: module.audio.mp3.php // +// dependencies: module.tag.id3v2.php // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); // needed for ISO 639-2 language code lookup + +class getid3_quicktime extends getid3_handler +{ + + /** audio-video.quicktime + * return all parsed data from all atoms if true, otherwise just returned parsed metadata + * + * @var bool + */ + public $ReturnAtomData = false; + + /** audio-video.quicktime + * return all parsed data from all atoms if true, otherwise just returned parsed metadata + * + * @var bool + */ + public $ParseAllPossibleAtoms = false; + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'quicktime'; + $info['quicktime']['hinting'] = false; + $info['quicktime']['controller'] = 'standard'; // may be overridden if 'ctyp' atom is present + + $this->fseek($info['avdataoffset']); + + $offset = 0; + $atomcounter = 0; + $atom_data_read_buffer_size = $info['php_memory_limit'] ? round($info['php_memory_limit'] / 4) : $this->getid3->option_fread_buffer_size * 1024; // set read buffer to 25% of PHP memory limit (if one is specified), otherwise use option_fread_buffer_size [default: 32MB] + while ($offset < $info['avdataend']) { + if (!getid3_lib::intValueSupported($offset)) { + $this->error('Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions'); + break; + } + $this->fseek($offset); + $AtomHeader = $this->fread(8); + + // https://github.com/JamesHeinrich/getID3/issues/382 + // Atom sizes are stored as 32-bit number in most cases, but sometimes (notably for "mdat") + // a 64-bit value is required, in which case the normal 32-bit size field is set to 0x00000001 + // and the 64-bit "real" size value is the next 8 bytes. + $atom_size_extended_bytes = 0; + $atomsize = getid3_lib::BigEndian2Int(substr($AtomHeader, 0, 4)); + $atomname = substr($AtomHeader, 4, 4); + if ($atomsize == 1) { + $atom_size_extended_bytes = 8; + $atomsize = getid3_lib::BigEndian2Int($this->fread($atom_size_extended_bytes)); + } + + if (($offset + $atomsize) > $info['avdataend']) { + $info['quicktime'][$atomname]['name'] = $atomname; + $info['quicktime'][$atomname]['size'] = $atomsize; + $info['quicktime'][$atomname]['offset'] = $offset; + $this->error('Atom at offset '.$offset.' claims to go beyond end-of-file (length: '.$atomsize.' bytes)'); + return false; + } + if ($atomsize == 0) { + // Furthermore, for historical reasons the list of atoms is optionally + // terminated by a 32-bit integer set to 0. If you are writing a program + // to read user data atoms, you should allow for the terminating 0. + $info['quicktime'][$atomname]['name'] = $atomname; + $info['quicktime'][$atomname]['size'] = $atomsize; + $info['quicktime'][$atomname]['offset'] = $offset; + break; + } + $atomHierarchy = array(); + $parsedAtomData = $this->QuicktimeParseAtom($atomname, $atomsize, $this->fread(min($atomsize - $atom_size_extended_bytes, $atom_data_read_buffer_size)), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms); + $parsedAtomData['name'] = $atomname; + $parsedAtomData['size'] = $atomsize; + $parsedAtomData['offset'] = $offset; + if ($atom_size_extended_bytes) { + $parsedAtomData['xsize_bytes'] = $atom_size_extended_bytes; + } + if (in_array($atomname, array('uuid'))) { + @$info['quicktime'][$atomname][] = $parsedAtomData; + } else { + $info['quicktime'][$atomname] = $parsedAtomData; + } + + $offset += $atomsize; + $atomcounter++; + } + + if (!empty($info['avdataend_tmp'])) { + // this value is assigned to a temp value and then erased because + // otherwise any atoms beyond the 'mdat' atom would not get parsed + $info['avdataend'] = $info['avdataend_tmp']; + unset($info['avdataend_tmp']); + } + + if (isset($info['quicktime']['comments']['chapters']) && is_array($info['quicktime']['comments']['chapters']) && (count($info['quicktime']['comments']['chapters']) > 0)) { + $durations = $this->quicktime_time_to_sample_table($info); + for ($i = 0; $i < count($info['quicktime']['comments']['chapters']); $i++) { + $bookmark = array(); + $bookmark['title'] = $info['quicktime']['comments']['chapters'][$i]; + if (isset($durations[$i])) { + $bookmark['duration_sample'] = $durations[$i]['sample_duration']; + if ($i > 0) { + $bookmark['start_sample'] = $info['quicktime']['bookmarks'][($i - 1)]['start_sample'] + $info['quicktime']['bookmarks'][($i - 1)]['duration_sample']; + } else { + $bookmark['start_sample'] = 0; + } + if ($time_scale = $this->quicktime_bookmark_time_scale($info)) { + $bookmark['duration_seconds'] = $bookmark['duration_sample'] / $time_scale; + $bookmark['start_seconds'] = $bookmark['start_sample'] / $time_scale; + } + } + $info['quicktime']['bookmarks'][] = $bookmark; + } + } + + if (isset($info['quicktime']['temp_meta_key_names'])) { + unset($info['quicktime']['temp_meta_key_names']); + } + + if (!empty($info['quicktime']['comments']['location.ISO6709'])) { + // https://en.wikipedia.org/wiki/ISO_6709 + foreach ($info['quicktime']['comments']['location.ISO6709'] as $ISO6709string) { + $ISO6709parsed = array('latitude'=>false, 'longitude'=>false, 'altitude'=>false); + if (preg_match('#^([\\+\\-])([0-9]{2}|[0-9]{4}|[0-9]{6})(\\.[0-9]+)?([\\+\\-])([0-9]{3}|[0-9]{5}|[0-9]{7})(\\.[0-9]+)?(([\\+\\-])([0-9]{3}|[0-9]{5}|[0-9]{7})(\\.[0-9]+)?)?/$#', $ISO6709string, $matches)) { + @list($dummy, $lat_sign, $lat_deg, $lat_deg_dec, $lon_sign, $lon_deg, $lon_deg_dec, $dummy, $alt_sign, $alt_deg, $alt_deg_dec) = $matches; + + if (strlen($lat_deg) == 2) { // [+-]DD.D + $ISO6709parsed['latitude'] = (($lat_sign == '-') ? -1 : 1) * floatval(ltrim($lat_deg, '0').$lat_deg_dec); + } elseif (strlen($lat_deg) == 4) { // [+-]DDMM.M + $ISO6709parsed['latitude'] = (($lat_sign == '-') ? -1 : 1) * floatval(ltrim(substr($lat_deg, 0, 2), '0')) + floatval(ltrim(substr($lat_deg, 2, 2), '0').$lat_deg_dec / 60); + } elseif (strlen($lat_deg) == 6) { // [+-]DDMMSS.S + $ISO6709parsed['latitude'] = (($lat_sign == '-') ? -1 : 1) * floatval(ltrim(substr($lat_deg, 0, 2), '0')) + floatval(ltrim(substr($lat_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($lat_deg, 4, 2), '0').$lat_deg_dec / 3600); + } + + if (strlen($lon_deg) == 3) { // [+-]DDD.D + $ISO6709parsed['longitude'] = (($lon_sign == '-') ? -1 : 1) * floatval(ltrim($lon_deg, '0').$lon_deg_dec); + } elseif (strlen($lon_deg) == 5) { // [+-]DDDMM.M + $ISO6709parsed['longitude'] = (($lon_sign == '-') ? -1 : 1) * floatval(ltrim(substr($lon_deg, 0, 2), '0')) + floatval(ltrim(substr($lon_deg, 2, 2), '0').$lon_deg_dec / 60); + } elseif (strlen($lon_deg) == 7) { // [+-]DDDMMSS.S + $ISO6709parsed['longitude'] = (($lon_sign == '-') ? -1 : 1) * floatval(ltrim(substr($lon_deg, 0, 2), '0')) + floatval(ltrim(substr($lon_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($lon_deg, 4, 2), '0').$lon_deg_dec / 3600); + } + + if (strlen($alt_deg) == 3) { // [+-]DDD.D + $ISO6709parsed['altitude'] = (($alt_sign == '-') ? -1 : 1) * floatval(ltrim($alt_deg, '0').$alt_deg_dec); + } elseif (strlen($alt_deg) == 5) { // [+-]DDDMM.M + $ISO6709parsed['altitude'] = (($alt_sign == '-') ? -1 : 1) * floatval(ltrim(substr($alt_deg, 0, 2), '0')) + floatval(ltrim(substr($alt_deg, 2, 2), '0').$alt_deg_dec / 60); + } elseif (strlen($alt_deg) == 7) { // [+-]DDDMMSS.S + $ISO6709parsed['altitude'] = (($alt_sign == '-') ? -1 : 1) * floatval(ltrim(substr($alt_deg, 0, 2), '0')) + floatval(ltrim(substr($alt_deg, 2, 2), '0') / 60) + floatval(ltrim(substr($alt_deg, 4, 2), '0').$alt_deg_dec / 3600); + } + + foreach (array('latitude', 'longitude', 'altitude') as $key) { + if ($ISO6709parsed[$key] !== false) { + $value = (($lat_sign == '-') ? -1 : 1) * floatval($ISO6709parsed[$key]); + if (!isset($info['quicktime']['comments']['gps_'.$key]) || !in_array($value, $info['quicktime']['comments']['gps_'.$key])) { + @$info['quicktime']['comments']['gps_'.$key][] = (($lat_sign == '-') ? -1 : 1) * floatval($ISO6709parsed[$key]); + } + } + } + } + if ($ISO6709parsed['latitude'] === false) { + $this->warning('location.ISO6709 string not parsed correctly: "'.$ISO6709string.'", please submit as a bug'); + } + break; + } + } + + if (!isset($info['bitrate']) && !empty($info['playtime_seconds'])) { + $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + } + if (isset($info['bitrate']) && !isset($info['audio']['bitrate']) && !isset($info['quicktime']['video'])) { + $info['audio']['bitrate'] = $info['bitrate']; + } + if (!empty($info['bitrate']) && !empty($info['audio']['bitrate']) && empty($info['video']['bitrate']) && !empty($info['video']['frame_rate']) && !empty($info['video']['resolution_x']) && ($info['bitrate'] > $info['audio']['bitrate'])) { + $info['video']['bitrate'] = $info['bitrate'] - $info['audio']['bitrate']; + } + if (!empty($info['playtime_seconds']) && !isset($info['video']['frame_rate']) && !empty($info['quicktime']['stts_framecount'])) { + foreach ($info['quicktime']['stts_framecount'] as $key => $samples_count) { + $samples_per_second = $samples_count / $info['playtime_seconds']; + if ($samples_per_second > 240) { + // has to be audio samples + } else { + $info['video']['frame_rate'] = $samples_per_second; + break; + } + } + } + if ($info['audio']['dataformat'] == 'mp4') { + $info['fileformat'] = 'mp4'; + if (empty($info['video']['resolution_x'])) { + $info['mime_type'] = 'audio/mp4'; + unset($info['video']['dataformat']); + } else { + $info['mime_type'] = 'video/mp4'; + } + } + + if (!$this->ReturnAtomData) { + unset($info['quicktime']['moov']); + } + + if (empty($info['audio']['dataformat']) && !empty($info['quicktime']['audio'])) { + $info['audio']['dataformat'] = 'quicktime'; + } + if (empty($info['video']['dataformat']) && !empty($info['quicktime']['video'])) { + $info['video']['dataformat'] = 'quicktime'; + } + if (isset($info['video']) && ($info['mime_type'] == 'audio/mp4') && empty($info['video']['resolution_x']) && empty($info['video']['resolution_y'])) { + unset($info['video']); + } + + return true; + } + + /** + * @param string $atomname + * @param int $atomsize + * @param string $atom_data + * @param int $baseoffset + * @param array $atomHierarchy + * @param bool $ParseAllPossibleAtoms + * + * @return array|false + */ + public function QuicktimeParseAtom($atomname, $atomsize, $atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) { + // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm + // https://code.google.com/p/mp4v2/wiki/iTunesMetadata + + $info = &$this->getid3->info; + + $atom_parent = end($atomHierarchy); // not array_pop($atomHierarchy); see https://www.getid3.org/phpBB3/viewtopic.php?t=1717 + array_push($atomHierarchy, $atomname); + $atom_structure = array(); + $atom_structure['hierarchy'] = implode(' ', $atomHierarchy); + $atom_structure['name'] = $atomname; + $atom_structure['size'] = $atomsize; + $atom_structure['offset'] = $baseoffset; + if (substr($atomname, 0, 3) == "\x00\x00\x00") { + // https://github.com/JamesHeinrich/getID3/issues/139 + $atomname = getid3_lib::BigEndian2Int($atomname); + $atom_structure['name'] = $atomname; + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); + } else { + switch ($atomname) { + case 'moov': // MOVie container atom + case 'moof': // MOvie Fragment box + case 'trak': // TRAcK container atom + case 'traf': // TRAck Fragment box + case 'clip': // CLIPping container atom + case 'matt': // track MATTe container atom + case 'edts': // EDiTS container atom + case 'tref': // Track REFerence container atom + case 'mdia': // MeDIA container atom + case 'minf': // Media INFormation container atom + case 'dinf': // Data INFormation container atom + case 'nmhd': // Null Media HeaDer container atom + case 'udta': // User DaTA container atom + case 'cmov': // Compressed MOVie container atom + case 'rmra': // Reference Movie Record Atom + case 'rmda': // Reference Movie Descriptor Atom + case 'gmhd': // Generic Media info HeaDer atom (seen on QTVR) + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); + break; + + case 'ilst': // Item LiST container atom + if ($atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms)) { + // some "ilst" atoms contain data atoms that have a numeric name, and the data is far more accessible if the returned array is compacted + $allnumericnames = true; + foreach ($atom_structure['subatoms'] as $subatomarray) { + if (!is_integer($subatomarray['name']) || (count($subatomarray['subatoms']) != 1)) { + $allnumericnames = false; + break; + } + } + if ($allnumericnames) { + $newData = array(); + foreach ($atom_structure['subatoms'] as $subatomarray) { + foreach ($subatomarray['subatoms'] as $newData_subatomarray) { + unset($newData_subatomarray['hierarchy'], $newData_subatomarray['name']); + $newData[$subatomarray['name']] = $newData_subatomarray; + break; + } + } + $atom_structure['data'] = $newData; + unset($atom_structure['subatoms']); + } + } + break; + + case 'stbl': // Sample TaBLe container atom + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); + $isVideo = false; + $framerate = 0; + $framecount = 0; + foreach ($atom_structure['subatoms'] as $key => $value_array) { + if (isset($value_array['sample_description_table'])) { + foreach ($value_array['sample_description_table'] as $key2 => $value_array2) { + if (isset($value_array2['data_format'])) { + switch ($value_array2['data_format']) { + case 'avc1': + case 'mp4v': + // video data + $isVideo = true; + break; + case 'mp4a': + // audio data + break; + } + } + } + } elseif (isset($value_array['time_to_sample_table'])) { + foreach ($value_array['time_to_sample_table'] as $key2 => $value_array2) { + if (isset($value_array2['sample_count']) && isset($value_array2['sample_duration']) && ($value_array2['sample_duration'] > 0)) { + $framerate = round($info['quicktime']['time_scale'] / $value_array2['sample_duration'], 3); + $framecount = $value_array2['sample_count']; + } + } + } + } + if ($isVideo && $framerate) { + $info['quicktime']['video']['frame_rate'] = $framerate; + $info['video']['frame_rate'] = $info['quicktime']['video']['frame_rate']; + } + if ($isVideo && $framecount) { + $info['quicktime']['video']['frame_count'] = $framecount; + } + break; + + + case "\xA9".'alb': // ALBum + case "\xA9".'ART': // + case "\xA9".'art': // ARTist + case "\xA9".'aut': // + case "\xA9".'cmt': // CoMmenT + case "\xA9".'com': // COMposer + case "\xA9".'cpy': // + case "\xA9".'day': // content created year + case "\xA9".'dir': // + case "\xA9".'ed1': // + case "\xA9".'ed2': // + case "\xA9".'ed3': // + case "\xA9".'ed4': // + case "\xA9".'ed5': // + case "\xA9".'ed6': // + case "\xA9".'ed7': // + case "\xA9".'ed8': // + case "\xA9".'ed9': // + case "\xA9".'enc': // + case "\xA9".'fmt': // + case "\xA9".'gen': // GENre + case "\xA9".'grp': // GRouPing + case "\xA9".'hst': // + case "\xA9".'inf': // + case "\xA9".'lyr': // LYRics + case "\xA9".'mak': // + case "\xA9".'mod': // + case "\xA9".'nam': // full NAMe + case "\xA9".'ope': // + case "\xA9".'PRD': // + case "\xA9".'prf': // + case "\xA9".'req': // + case "\xA9".'src': // + case "\xA9".'swr': // + case "\xA9".'too': // encoder + case "\xA9".'trk': // TRacK + case "\xA9".'url': // + case "\xA9".'wrn': // + case "\xA9".'wrt': // WRiTer + case '----': // itunes specific + case 'aART': // Album ARTist + case 'akID': // iTunes store account type + case 'apID': // Purchase Account + case 'atID': // + case 'catg': // CaTeGory + case 'cmID': // + case 'cnID': // + case 'covr': // COVeR artwork + case 'cpil': // ComPILation + case 'cprt': // CoPyRighT + case 'desc': // DESCription + case 'disk': // DISK number + case 'egid': // Episode Global ID + case 'geID': // + case 'gnre': // GeNRE + case 'hdvd': // HD ViDeo + case 'keyw': // KEYWord + case 'ldes': // Long DEScription + case 'pcst': // PodCaST + case 'pgap': // GAPless Playback + case 'plID': // + case 'purd': // PURchase Date + case 'purl': // Podcast URL + case 'rati': // + case 'rndu': // + case 'rpdu': // + case 'rtng': // RaTiNG + case 'sfID': // iTunes store country + case 'soaa': // SOrt Album Artist + case 'soal': // SOrt ALbum + case 'soar': // SOrt ARtist + case 'soco': // SOrt COmposer + case 'sonm': // SOrt NaMe + case 'sosn': // SOrt Show Name + case 'stik': // + case 'tmpo': // TeMPO (BPM) + case 'trkn': // TRacK Number + case 'tven': // tvEpisodeID + case 'tves': // TV EpiSode + case 'tvnn': // TV Network Name + case 'tvsh': // TV SHow Name + case 'tvsn': // TV SeasoN + if ($atom_parent == 'udta') { + // User data atom handler + $atom_structure['data_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); + $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); + $atom_structure['data'] = substr($atom_data, 4); + + $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); + if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) { + $info['comments']['language'][] = $atom_structure['language']; + } + } else { + // Apple item list box atom handler + $atomoffset = 0; + if (substr($atom_data, 2, 2) == "\x10\xB5") { + // not sure what it means, but observed on iPhone4 data. + // Each $atom_data has 2 bytes of datasize, plus 0x10B5, then data + while ($atomoffset < strlen($atom_data)) { + $boxsmallsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 2)); + $boxsmalltype = substr($atom_data, $atomoffset + 2, 2); + $boxsmalldata = substr($atom_data, $atomoffset + 4, $boxsmallsize); + if ($boxsmallsize <= 1) { + $this->warning('Invalid QuickTime atom smallbox size "'.$boxsmallsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset)); + $atom_structure['data'] = null; + $atomoffset = strlen($atom_data); + break; + } + switch ($boxsmalltype) { + case "\x10\xB5": + $atom_structure['data'] = $boxsmalldata; + break; + default: + $this->warning('Unknown QuickTime smallbox type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxsmalltype).'" ('.trim(getid3_lib::PrintHexBytes($boxsmalltype)).') at offset '.$baseoffset); + $atom_structure['data'] = $atom_data; + break; + } + $atomoffset += (4 + $boxsmallsize); + } + } else { + while ($atomoffset < strlen($atom_data)) { + $boxsize = getid3_lib::BigEndian2Int(substr($atom_data, $atomoffset, 4)); + $boxtype = substr($atom_data, $atomoffset + 4, 4); + $boxdata = substr($atom_data, $atomoffset + 8, $boxsize - 8); + if ($boxsize <= 1) { + $this->warning('Invalid QuickTime atom box size "'.$boxsize.'" in atom "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" at offset: '.($atom_structure['offset'] + $atomoffset)); + $atom_structure['data'] = null; + $atomoffset = strlen($atom_data); + break; + } + $atomoffset += $boxsize; + + switch ($boxtype) { + case 'mean': + case 'name': + $atom_structure[$boxtype] = substr($boxdata, 4); + break; + + case 'data': + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($boxdata, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($boxdata, 1, 3)); + switch ($atom_structure['flags_raw']) { + case 0: // data flag + case 21: // tmpo/cpil flag + switch ($atomname) { + case 'cpil': + case 'hdvd': + case 'pcst': + case 'pgap': + // 8-bit integer (boolean) + $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); + break; + + case 'tmpo': + // 16-bit integer + $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 2)); + break; + + case 'disk': + case 'trkn': + // binary + $num = getid3_lib::BigEndian2Int(substr($boxdata, 10, 2)); + $num_total = getid3_lib::BigEndian2Int(substr($boxdata, 12, 2)); + $atom_structure['data'] = empty($num) ? '' : $num; + $atom_structure['data'] .= empty($num_total) ? '' : '/'.$num_total; + break; + + case 'gnre': + // enum + $GenreID = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); + $atom_structure['data'] = getid3_id3v1::LookupGenreName($GenreID - 1); + break; + + case 'rtng': + // 8-bit integer + $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); + $atom_structure['data'] = $this->QuicktimeContentRatingLookup($atom_structure[$atomname]); + break; + + case 'stik': + // 8-bit integer (enum) + $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 1)); + $atom_structure['data'] = $this->QuicktimeSTIKLookup($atom_structure[$atomname]); + break; + + case 'sfID': + // 32-bit integer + $atom_structure[$atomname] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); + $atom_structure['data'] = $this->QuicktimeStoreFrontCodeLookup($atom_structure[$atomname]); + break; + + case 'egid': + case 'purl': + $atom_structure['data'] = substr($boxdata, 8); + break; + + case 'plID': + // 64-bit integer + $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 8)); + break; + + case 'covr': + $atom_structure['data'] = substr($boxdata, 8); + // not a foolproof check, but better than nothing + if (preg_match('#^\\xFF\\xD8\\xFF#', $atom_structure['data'])) { + $atom_structure['image_mime'] = 'image/jpeg'; + } elseif (preg_match('#^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A#', $atom_structure['data'])) { + $atom_structure['image_mime'] = 'image/png'; + } elseif (preg_match('#^GIF#', $atom_structure['data'])) { + $atom_structure['image_mime'] = 'image/gif'; + } + $info['quicktime']['comments']['picture'][] = array('image_mime'=>$atom_structure['image_mime'], 'data'=>$atom_structure['data'], 'description'=>'cover'); + break; + + case 'atID': + case 'cnID': + case 'geID': + case 'tves': + case 'tvsn': + default: + // 32-bit integer + $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($boxdata, 8, 4)); + } + break; + + case 1: // text flag + case 13: // image flag + default: + $atom_structure['data'] = substr($boxdata, 8); + if ($atomname == 'covr') { + if (!empty($atom_structure['data'])) { + $atom_structure['image_mime'] = 'image/unknown'; // provide default MIME type to ensure array keys exist + if (function_exists('getimagesizefromstring') && ($getimagesize = getimagesizefromstring($atom_structure['data'])) && !empty($getimagesize['mime'])) { + $atom_structure['image_mime'] = $getimagesize['mime']; + } else { + // if getimagesizefromstring is not available, or fails for some reason, fall back to simple detection of common image formats + $ImageFormatSignatures = array( + 'image/jpeg' => "\xFF\xD8\xFF", + 'image/png' => "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", + 'image/gif' => 'GIF', + ); + foreach ($ImageFormatSignatures as $mime => $image_format_signature) { + if (substr($atom_structure['data'], 0, strlen($image_format_signature)) == $image_format_signature) { + $atom_structure['image_mime'] = $mime; + break; + } + } + } + $info['quicktime']['comments']['picture'][] = array('image_mime'=>$atom_structure['image_mime'], 'data'=>$atom_structure['data'], 'description'=>'cover'); + } else { + $this->warning('Unknown empty "covr" image at offset '.$baseoffset); + } + } + break; + + } + break; + + default: + $this->warning('Unknown QuickTime box type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $boxtype).'" ('.trim(getid3_lib::PrintHexBytes($boxtype)).') at offset '.$baseoffset); + $atom_structure['data'] = $atom_data; + + } + } + } + } + $this->CopyToAppropriateCommentsSection($atomname, $atom_structure['data'], $atom_structure['name']); + break; + + + case 'play': // auto-PLAY atom + $atom_structure['autoplay'] = (bool) getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + + $info['quicktime']['autoplay'] = $atom_structure['autoplay']; + break; + + + case 'WLOC': // Window LOCation atom + $atom_structure['location_x'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); + $atom_structure['location_y'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); + break; + + + case 'LOOP': // LOOPing atom + case 'SelO': // play SELection Only atom + case 'AllF': // play ALL Frames atom + $atom_structure['data'] = getid3_lib::BigEndian2Int($atom_data); + break; + + + case 'name': // + case 'MCPS': // Media Cleaner PRo + case '@PRM': // adobe PReMiere version + case '@PRQ': // adobe PRemiere Quicktime version + $atom_structure['data'] = $atom_data; + break; + + + case 'cmvd': // Compressed MooV Data atom + // Code by ubergeekØubergeek*tv based on information from + // http://developer.apple.com/quicktime/icefloe/dispatch012.html + $atom_structure['unCompressedSize'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); + + $CompressedFileData = substr($atom_data, 4); + if ($UncompressedHeader = @gzuncompress($CompressedFileData)) { + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($UncompressedHeader, 0, $atomHierarchy, $ParseAllPossibleAtoms); + } else { + $this->warning('Error decompressing compressed MOV atom at offset '.$atom_structure['offset']); + } + break; + + + case 'dcom': // Data COMpression atom + $atom_structure['compression_id'] = $atom_data; + $atom_structure['compression_text'] = $this->QuicktimeDCOMLookup($atom_data); + break; + + + case 'rdrf': // Reference movie Data ReFerence atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); + $atom_structure['flags']['internal_data'] = (bool) ($atom_structure['flags_raw'] & 0x000001); + + $atom_structure['reference_type_name'] = substr($atom_data, 4, 4); + $atom_structure['reference_length'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); + switch ($atom_structure['reference_type_name']) { + case 'url ': + $atom_structure['url'] = $this->NoNullString(substr($atom_data, 12)); + break; + + case 'alis': + $atom_structure['file_alias'] = substr($atom_data, 12); + break; + + case 'rsrc': + $atom_structure['resource_alias'] = substr($atom_data, 12); + break; + + default: + $atom_structure['data'] = substr($atom_data, 12); + break; + } + break; + + + case 'rmqu': // Reference Movie QUality atom + $atom_structure['movie_quality'] = getid3_lib::BigEndian2Int($atom_data); + break; + + + case 'rmcs': // Reference Movie Cpu Speed atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['cpu_speed_rating'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); + break; + + + case 'rmvc': // Reference Movie Version Check atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['gestalt_selector'] = substr($atom_data, 4, 4); + $atom_structure['gestalt_value_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); + $atom_structure['gestalt_value'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); + $atom_structure['gestalt_check_type'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2)); + break; + + + case 'rmcd': // Reference Movie Component check atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['component_type'] = substr($atom_data, 4, 4); + $atom_structure['component_subtype'] = substr($atom_data, 8, 4); + $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4); + $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); + $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); + $atom_structure['component_min_version'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 4)); + break; + + + case 'rmdr': // Reference Movie Data Rate atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['data_rate'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + + $atom_structure['data_rate_bps'] = $atom_structure['data_rate'] * 10; + break; + + + case 'rmla': // Reference Movie Language Atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); + + $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); + if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) { + $info['comments']['language'][] = $atom_structure['language']; + } + break; + + + case 'ptv ': // Print To Video - defines a movie's full screen mode + // http://developer.apple.com/documentation/QuickTime/APIREF/SOURCESIV/at_ptv-_pg.htm + $atom_structure['display_size_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); + $atom_structure['reserved_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 2)); // hardcoded: 0x0000 + $atom_structure['reserved_2'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x0000 + $atom_structure['slide_show_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 1)); + $atom_structure['play_on_open_flag'] = getid3_lib::BigEndian2Int(substr($atom_data, 7, 1)); + + $atom_structure['flags']['play_on_open'] = (bool) $atom_structure['play_on_open_flag']; + $atom_structure['flags']['slide_show'] = (bool) $atom_structure['slide_show_flag']; + + $ptv_lookup = array( + 0 => 'normal', + 1 => 'double', + 2 => 'half', + 3 => 'full', + 4 => 'current' + ); + if (isset($ptv_lookup[$atom_structure['display_size_raw']])) { + $atom_structure['display_size'] = $ptv_lookup[$atom_structure['display_size_raw']]; + } else { + $this->warning('unknown "ptv " display constant ('.$atom_structure['display_size_raw'].')'); + } + break; + + + case 'stsd': // Sample Table Sample Description atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + + // see: https://github.com/JamesHeinrich/getID3/issues/111 + // Some corrupt files have been known to have high bits set in the number_entries field + // This field shouldn't really need to be 32-bits, values stores are likely in the range 1-100000 + // Workaround: mask off the upper byte and throw a warning if it's nonzero + if ($atom_structure['number_entries'] > 0x000FFFFF) { + if ($atom_structure['number_entries'] > 0x00FFFFFF) { + $this->warning('"stsd" atom contains improbably large number_entries (0x'.getid3_lib::PrintHexBytes(substr($atom_data, 4, 4), true, false).' = '.$atom_structure['number_entries'].'), probably in error. Ignoring upper byte and interpreting this as 0x'.getid3_lib::PrintHexBytes(substr($atom_data, 5, 3), true, false).' = '.($atom_structure['number_entries'] & 0x00FFFFFF)); + $atom_structure['number_entries'] = ($atom_structure['number_entries'] & 0x00FFFFFF); + } else { + $this->warning('"stsd" atom contains improbably large number_entries (0x'.getid3_lib::PrintHexBytes(substr($atom_data, 4, 4), true, false).' = '.$atom_structure['number_entries'].'), probably in error. Please report this to info@getid3.org referencing bug report #111'); + } + } + + $stsdEntriesDataOffset = 8; + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['sample_description_table'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 4)); + $stsdEntriesDataOffset += 4; + $atom_structure['sample_description_table'][$i]['data_format'] = substr($atom_data, $stsdEntriesDataOffset, 4); + $stsdEntriesDataOffset += 4; + $atom_structure['sample_description_table'][$i]['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 6)); + $stsdEntriesDataOffset += 6; + $atom_structure['sample_description_table'][$i]['reference_index'] = getid3_lib::BigEndian2Int(substr($atom_data, $stsdEntriesDataOffset, 2)); + $stsdEntriesDataOffset += 2; + $atom_structure['sample_description_table'][$i]['data'] = substr($atom_data, $stsdEntriesDataOffset, ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2)); + $stsdEntriesDataOffset += ($atom_structure['sample_description_table'][$i]['size'] - 4 - 4 - 6 - 2); + + if (substr($atom_structure['sample_description_table'][$i]['data'], 1, 54) == 'application/octet-stream;type=com.parrot.videometadata') { + // special handling for apparently-malformed (TextMetaDataSampleEntry?) data for some version of Parrot drones + $atom_structure['sample_description_table'][$i]['parrot_frame_metadata']['mime_type'] = substr($atom_structure['sample_description_table'][$i]['data'], 1, 55); + $atom_structure['sample_description_table'][$i]['parrot_frame_metadata']['metadata_version'] = (int) substr($atom_structure['sample_description_table'][$i]['data'], 55, 1); + unset($atom_structure['sample_description_table'][$i]['data']); +$this->warning('incomplete/incorrect handling of "stsd" with Parrot metadata in this version of getID3() ['.$this->getid3->version().']'); + continue; + } + + $atom_structure['sample_description_table'][$i]['encoder_version'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 0, 2)); + $atom_structure['sample_description_table'][$i]['encoder_revision'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 2, 2)); + $atom_structure['sample_description_table'][$i]['encoder_vendor'] = substr($atom_structure['sample_description_table'][$i]['data'], 4, 4); + + switch ($atom_structure['sample_description_table'][$i]['encoder_vendor']) { + + case "\x00\x00\x00\x00": + // audio tracks + $atom_structure['sample_description_table'][$i]['audio_channels'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 2)); + $atom_structure['sample_description_table'][$i]['audio_bit_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 10, 2)); + $atom_structure['sample_description_table'][$i]['audio_compression_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 2)); + $atom_structure['sample_description_table'][$i]['audio_packet_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 14, 2)); + $atom_structure['sample_description_table'][$i]['audio_sample_rate'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 16, 4)); + + // video tracks + // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap3/qtff3.html + $atom_structure['sample_description_table'][$i]['temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4)); + $atom_structure['sample_description_table'][$i]['spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4)); + $atom_structure['sample_description_table'][$i]['width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2)); + $atom_structure['sample_description_table'][$i]['height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2)); + $atom_structure['sample_description_table'][$i]['resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4)); + $atom_structure['sample_description_table'][$i]['resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4)); + $atom_structure['sample_description_table'][$i]['data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 4)); + $atom_structure['sample_description_table'][$i]['frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 36, 2)); + $atom_structure['sample_description_table'][$i]['compressor_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 38, 4); + $atom_structure['sample_description_table'][$i]['pixel_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 42, 2)); + $atom_structure['sample_description_table'][$i]['color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 44, 2)); + + switch ($atom_structure['sample_description_table'][$i]['data_format']) { + case '2vuY': + case 'avc1': + case 'cvid': + case 'dvc ': + case 'dvcp': + case 'gif ': + case 'h263': + case 'hvc1': + case 'jpeg': + case 'kpcd': + case 'mjpa': + case 'mjpb': + case 'mp4v': + case 'png ': + case 'raw ': + case 'rle ': + case 'rpza': + case 'smc ': + case 'SVQ1': + case 'SVQ3': + case 'tiff': + case 'v210': + case 'v216': + case 'v308': + case 'v408': + case 'v410': + case 'yuv2': + $info['fileformat'] = 'mp4'; + $info['video']['fourcc'] = $atom_structure['sample_description_table'][$i]['data_format']; + if ($this->QuicktimeVideoCodecLookup($info['video']['fourcc'])) { + $info['video']['fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($info['video']['fourcc']); + } + + // https://www.getid3.org/phpBB3/viewtopic.php?t=1550 + //if ((!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['width'])) && (empty($info['video']['resolution_x']) || empty($info['video']['resolution_y']) || (number_format($info['video']['resolution_x'], 6) != number_format(round($info['video']['resolution_x']), 6)) || (number_format($info['video']['resolution_y'], 6) != number_format(round($info['video']['resolution_y']), 6)))) { // ugly check for floating point numbers + if (!empty($atom_structure['sample_description_table'][$i]['width']) && !empty($atom_structure['sample_description_table'][$i]['height'])) { + // assume that values stored here are more important than values stored in [tkhd] atom + $info['video']['resolution_x'] = $atom_structure['sample_description_table'][$i]['width']; + $info['video']['resolution_y'] = $atom_structure['sample_description_table'][$i]['height']; + $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x']; + $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y']; + } + break; + + case 'qtvr': + $info['video']['dataformat'] = 'quicktimevr'; + break; + + case 'mp4a': + default: + $info['quicktime']['audio']['codec'] = $this->QuicktimeAudioCodecLookup($atom_structure['sample_description_table'][$i]['data_format']); + $info['quicktime']['audio']['sample_rate'] = $atom_structure['sample_description_table'][$i]['audio_sample_rate']; + $info['quicktime']['audio']['channels'] = $atom_structure['sample_description_table'][$i]['audio_channels']; + $info['quicktime']['audio']['bit_depth'] = $atom_structure['sample_description_table'][$i]['audio_bit_depth']; + $info['audio']['codec'] = $info['quicktime']['audio']['codec']; + $info['audio']['sample_rate'] = $info['quicktime']['audio']['sample_rate']; + $info['audio']['channels'] = $info['quicktime']['audio']['channels']; + $info['audio']['bits_per_sample'] = $info['quicktime']['audio']['bit_depth']; + switch ($atom_structure['sample_description_table'][$i]['data_format']) { + case 'raw ': // PCM + case 'alac': // Apple Lossless Audio Codec + case 'sowt': // signed/two's complement (Little Endian) + case 'twos': // signed/two's complement (Big Endian) + case 'in24': // 24-bit Integer + case 'in32': // 32-bit Integer + case 'fl32': // 32-bit Floating Point + case 'fl64': // 64-bit Floating Point + $info['audio']['lossless'] = $info['quicktime']['audio']['lossless'] = true; + $info['audio']['bitrate'] = $info['quicktime']['audio']['bitrate'] = $info['audio']['channels'] * $info['audio']['bits_per_sample'] * $info['audio']['sample_rate']; + break; + default: + $info['audio']['lossless'] = false; + break; + } + break; + } + break; + + default: + switch ($atom_structure['sample_description_table'][$i]['data_format']) { + case 'mp4s': + $info['fileformat'] = 'mp4'; + break; + + default: + // video atom + $atom_structure['sample_description_table'][$i]['video_temporal_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 8, 4)); + $atom_structure['sample_description_table'][$i]['video_spatial_quality'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 12, 4)); + $atom_structure['sample_description_table'][$i]['video_frame_width'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 16, 2)); + $atom_structure['sample_description_table'][$i]['video_frame_height'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 18, 2)); + $atom_structure['sample_description_table'][$i]['video_resolution_x'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 20, 4)); + $atom_structure['sample_description_table'][$i]['video_resolution_y'] = getid3_lib::FixedPoint16_16(substr($atom_structure['sample_description_table'][$i]['data'], 24, 4)); + $atom_structure['sample_description_table'][$i]['video_data_size'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 28, 4)); + $atom_structure['sample_description_table'][$i]['video_frame_count'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 32, 2)); + $atom_structure['sample_description_table'][$i]['video_encoder_name_len'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 34, 1)); + $atom_structure['sample_description_table'][$i]['video_encoder_name'] = substr($atom_structure['sample_description_table'][$i]['data'], 35, $atom_structure['sample_description_table'][$i]['video_encoder_name_len']); + $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 66, 2)); + $atom_structure['sample_description_table'][$i]['video_color_table_id'] = getid3_lib::BigEndian2Int(substr($atom_structure['sample_description_table'][$i]['data'], 68, 2)); + + $atom_structure['sample_description_table'][$i]['video_pixel_color_type'] = (((int) $atom_structure['sample_description_table'][$i]['video_pixel_color_depth'] > 32) ? 'grayscale' : 'color'); + $atom_structure['sample_description_table'][$i]['video_pixel_color_name'] = $this->QuicktimeColorNameLookup($atom_structure['sample_description_table'][$i]['video_pixel_color_depth']); + + if ($atom_structure['sample_description_table'][$i]['video_pixel_color_name'] != 'invalid') { + $info['quicktime']['video']['codec_fourcc'] = $atom_structure['sample_description_table'][$i]['data_format']; + $info['quicktime']['video']['codec_fourcc_lookup'] = $this->QuicktimeVideoCodecLookup($atom_structure['sample_description_table'][$i]['data_format']); + $info['quicktime']['video']['codec'] = (((int) $atom_structure['sample_description_table'][$i]['video_encoder_name_len'] > 0) ? $atom_structure['sample_description_table'][$i]['video_encoder_name'] : $atom_structure['sample_description_table'][$i]['data_format']); + $info['quicktime']['video']['color_depth'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_depth']; + $info['quicktime']['video']['color_depth_name'] = $atom_structure['sample_description_table'][$i]['video_pixel_color_name']; + + $info['video']['codec'] = $info['quicktime']['video']['codec']; + $info['video']['bits_per_sample'] = $info['quicktime']['video']['color_depth']; + } + $info['video']['lossless'] = false; + $info['video']['pixel_aspect_ratio'] = (float) 1; + break; + } + break; + } + switch (strtolower($atom_structure['sample_description_table'][$i]['data_format'])) { + case 'mp4a': + $info['audio']['dataformat'] = 'mp4'; + $info['quicktime']['audio']['codec'] = 'mp4'; + break; + + case '3ivx': + case '3iv1': + case '3iv2': + $info['video']['dataformat'] = '3ivx'; + break; + + case 'xvid': + $info['video']['dataformat'] = 'xvid'; + break; + + case 'mp4v': + $info['video']['dataformat'] = 'mpeg4'; + break; + + case 'divx': + case 'div1': + case 'div2': + case 'div3': + case 'div4': + case 'div5': + case 'div6': + $info['video']['dataformat'] = 'divx'; + break; + + default: + // do nothing + break; + } + unset($atom_structure['sample_description_table'][$i]['data']); + } + break; + + + case 'stts': // Sample Table Time-to-Sample atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $sttsEntriesDataOffset = 8; + //$FrameRateCalculatorArray = array(); + $frames_count = 0; + + $max_stts_entries_to_scan = ($info['php_memory_limit'] ? min(floor($this->getid3->memory_limit / 10000), $atom_structure['number_entries']) : $atom_structure['number_entries']); + if ($max_stts_entries_to_scan < $atom_structure['number_entries']) { + $this->warning('QuickTime atom "stts" has '.$atom_structure['number_entries'].' but only scanning the first '.$max_stts_entries_to_scan.' entries due to limited PHP memory available ('.floor($this->getid3->memory_limit / 1048576).'MB).'); + } + for ($i = 0; $i < $max_stts_entries_to_scan; $i++) { + $atom_structure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4)); + $sttsEntriesDataOffset += 4; + $atom_structure['time_to_sample_table'][$i]['sample_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4)); + $sttsEntriesDataOffset += 4; + + $frames_count += $atom_structure['time_to_sample_table'][$i]['sample_count']; + + // THIS SECTION REPLACED WITH CODE IN "stbl" ATOM + //if (!empty($info['quicktime']['time_scale']) && ($atom_structure['time_to_sample_table'][$i]['sample_duration'] > 0)) { + // $stts_new_framerate = $info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration']; + // if ($stts_new_framerate <= 60) { + // // some atoms have durations of "1" giving a very large framerate, which probably is not right + // $info['video']['frame_rate'] = max($info['video']['frame_rate'], $stts_new_framerate); + // } + //} + // + //$FrameRateCalculatorArray[($info['quicktime']['time_scale'] / $atom_structure['time_to_sample_table'][$i]['sample_duration'])] += $atom_structure['time_to_sample_table'][$i]['sample_count']; + } + $info['quicktime']['stts_framecount'][] = $frames_count; + //$sttsFramesTotal = 0; + //$sttsSecondsTotal = 0; + //foreach ($FrameRateCalculatorArray as $frames_per_second => $frame_count) { + // if (($frames_per_second > 60) || ($frames_per_second < 1)) { + // // not video FPS information, probably audio information + // $sttsFramesTotal = 0; + // $sttsSecondsTotal = 0; + // break; + // } + // $sttsFramesTotal += $frame_count; + // $sttsSecondsTotal += $frame_count / $frames_per_second; + //} + //if (($sttsFramesTotal > 0) && ($sttsSecondsTotal > 0)) { + // if (($sttsFramesTotal / $sttsSecondsTotal) > $info['video']['frame_rate']) { + // $info['video']['frame_rate'] = $sttsFramesTotal / $sttsSecondsTotal; + // } + //} + break; + + + case 'stss': // Sample Table Sync Sample (key frames) atom + if ($ParseAllPossibleAtoms) { + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $stssEntriesDataOffset = 8; + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['time_to_sample_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stssEntriesDataOffset, 4)); + $stssEntriesDataOffset += 4; + } + } + break; + + + case 'stsc': // Sample Table Sample-to-Chunk atom + if ($ParseAllPossibleAtoms) { + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $stscEntriesDataOffset = 8; + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['sample_to_chunk_table'][$i]['first_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); + $stscEntriesDataOffset += 4; + $atom_structure['sample_to_chunk_table'][$i]['samples_per_chunk'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); + $stscEntriesDataOffset += 4; + $atom_structure['sample_to_chunk_table'][$i]['sample_description'] = getid3_lib::BigEndian2Int(substr($atom_data, $stscEntriesDataOffset, 4)); + $stscEntriesDataOffset += 4; + } + } + break; + + + case 'stsz': // Sample Table SiZe atom + if ($ParseAllPossibleAtoms) { + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['sample_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); + $stszEntriesDataOffset = 12; + if ($atom_structure['sample_size'] == 0) { + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['sample_size_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stszEntriesDataOffset, 4)); + $stszEntriesDataOffset += 4; + } + } + } + break; + + + case 'stco': // Sample Table Chunk Offset atom +// if (true) { + if ($ParseAllPossibleAtoms) { + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $stcoEntriesDataOffset = 8; + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 4)); + $stcoEntriesDataOffset += 4; + } + } + break; + + + case 'co64': // Chunk Offset 64-bit (version of "stco" that supports > 2GB files) + if ($ParseAllPossibleAtoms) { + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $stcoEntriesDataOffset = 8; + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['chunk_offset_table'][$i] = getid3_lib::BigEndian2Int(substr($atom_data, $stcoEntriesDataOffset, 8)); + $stcoEntriesDataOffset += 8; + } + } + break; + + + case 'dref': // Data REFerence atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $drefDataOffset = 8; + for ($i = 0; $i < $atom_structure['number_entries']; $i++) { + $atom_structure['data_references'][$i]['size'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 4)); + $drefDataOffset += 4; + $atom_structure['data_references'][$i]['type'] = substr($atom_data, $drefDataOffset, 4); + $drefDataOffset += 4; + $atom_structure['data_references'][$i]['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 1)); + $drefDataOffset += 1; + $atom_structure['data_references'][$i]['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $drefDataOffset, 3)); // hardcoded: 0x0000 + $drefDataOffset += 3; + $atom_structure['data_references'][$i]['data'] = substr($atom_data, $drefDataOffset, ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3)); + $drefDataOffset += ($atom_structure['data_references'][$i]['size'] - 4 - 4 - 1 - 3); + + $atom_structure['data_references'][$i]['flags']['self_reference'] = (bool) ($atom_structure['data_references'][$i]['flags_raw'] & 0x001); + } + break; + + + case 'gmin': // base Media INformation atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); + $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); + $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2)); + $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); + $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 2)); + $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 14, 2)); + break; + + + case 'smhd': // Sound Media information HeaDer atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['balance'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); + $atom_structure['reserved'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); + break; + + + case 'vmhd': // Video Media information HeaDer atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); + $atom_structure['graphics_mode'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); + $atom_structure['opcolor_red'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)); + $atom_structure['opcolor_green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 2)); + $atom_structure['opcolor_blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); + + $atom_structure['flags']['no_lean_ahead'] = (bool) ($atom_structure['flags_raw'] & 0x001); + break; + + + case 'hdlr': // HanDLeR reference atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['component_type'] = substr($atom_data, 4, 4); + $atom_structure['component_subtype'] = substr($atom_data, 8, 4); + $atom_structure['component_manufacturer'] = substr($atom_data, 12, 4); + $atom_structure['component_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); + $atom_structure['component_flags_mask'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); + $atom_structure['component_name'] = $this->MaybePascal2String(substr($atom_data, 24)); + + if (($atom_structure['component_subtype'] == 'STpn') && ($atom_structure['component_manufacturer'] == 'zzzz')) { + $info['video']['dataformat'] = 'quicktimevr'; + } + break; + + + case 'mdhd': // MeDia HeaDer atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); + $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); + $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); + $atom_structure['language_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 2)); + $atom_structure['quality'] = getid3_lib::BigEndian2Int(substr($atom_data, 22, 2)); + + if ($atom_structure['time_scale'] == 0) { + $this->error('Corrupt Quicktime file: mdhd.time_scale == zero'); + return false; + } + $info['quicktime']['time_scale'] = ((isset($info['quicktime']['time_scale']) && ($info['quicktime']['time_scale'] < 1000)) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']); + + $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); + $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); + $atom_structure['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale']; + $atom_structure['language'] = $this->QuicktimeLanguageLookup($atom_structure['language_id']); + if (empty($info['comments']['language']) || (!in_array($atom_structure['language'], $info['comments']['language']))) { + $info['comments']['language'][] = $atom_structure['language']; + } + $info['quicktime']['timestamps_unix']['create'][$atom_structure['hierarchy']] = $atom_structure['creation_time_unix']; + $info['quicktime']['timestamps_unix']['modify'][$atom_structure['hierarchy']] = $atom_structure['modify_time_unix']; + break; + + + case 'pnot': // Preview atom + $atom_structure['modification_date'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // "standard Macintosh format" + $atom_structure['version_number'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x00 + $atom_structure['atom_type'] = substr($atom_data, 6, 4); // usually: 'PICT' + $atom_structure['atom_index'] = getid3_lib::BigEndian2Int(substr($atom_data, 10, 2)); // usually: 0x01 + + $atom_structure['modification_date_unix'] = getid3_lib::DateMac2Unix($atom_structure['modification_date']); + $info['quicktime']['timestamps_unix']['modify'][$atom_structure['hierarchy']] = $atom_structure['modification_date_unix']; + break; + + + case 'crgn': // Clipping ReGioN atom + $atom_structure['region_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 2)); // The Region size, Region boundary box, + $atom_structure['boundary_box'] = getid3_lib::BigEndian2Int(substr($atom_data, 2, 8)); // and Clipping region data fields + $atom_structure['clipping_data'] = substr($atom_data, 10); // constitute a QuickDraw region. + break; + + + case 'load': // track LOAD settings atom + $atom_structure['preload_start_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); + $atom_structure['preload_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $atom_structure['preload_flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); + $atom_structure['default_hints_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); + + $atom_structure['default_hints']['double_buffer'] = (bool) ($atom_structure['default_hints_raw'] & 0x0020); + $atom_structure['default_hints']['high_quality'] = (bool) ($atom_structure['default_hints_raw'] & 0x0100); + break; + + + case 'tmcd': // TiMe CoDe atom + case 'chap': // CHAPter list atom + case 'sync': // SYNChronization atom + case 'scpt': // tranSCriPT atom + case 'ssrc': // non-primary SouRCe atom + for ($i = 0; $i < strlen($atom_data); $i += 4) { + @$atom_structure['track_id'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4)); + } + break; + + + case 'elst': // Edit LiST atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['number_entries'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + for ($i = 0; $i < $atom_structure['number_entries']; $i++ ) { + $atom_structure['edit_list'][$i]['track_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 0, 4)); + $atom_structure['edit_list'][$i]['media_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($i * 12) + 4, 4)); + $atom_structure['edit_list'][$i]['media_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 8 + ($i * 12) + 8, 4)); + } + break; + + + case 'kmat': // compressed MATte atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); // hardcoded: 0x0000 + $atom_structure['matte_data_raw'] = substr($atom_data, 4); + break; + + + case 'ctab': // Color TABle atom + $atom_structure['color_table_seed'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); // hardcoded: 0x00000000 + $atom_structure['color_table_flags'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 2)); // hardcoded: 0x8000 + $atom_structure['color_table_size'] = getid3_lib::BigEndian2Int(substr($atom_data, 6, 2)) + 1; + for ($colortableentry = 0; $colortableentry < $atom_structure['color_table_size']; $colortableentry++) { + $atom_structure['color_table'][$colortableentry]['alpha'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 0, 2)); + $atom_structure['color_table'][$colortableentry]['red'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 2, 2)); + $atom_structure['color_table'][$colortableentry]['green'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 4, 2)); + $atom_structure['color_table'][$colortableentry]['blue'] = getid3_lib::BigEndian2Int(substr($atom_data, 8 + ($colortableentry * 8) + 6, 2)); + } + break; + + + case 'mvhd': // MoVie HeaDer atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); + $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); + $atom_structure['time_scale'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); + $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); + $atom_structure['preferred_rate'] = getid3_lib::FixedPoint16_16(substr($atom_data, 20, 4)); + $atom_structure['preferred_volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 24, 2)); + $atom_structure['reserved'] = substr($atom_data, 26, 10); + $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 36, 4)); + $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4)); + $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 44, 4)); + $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 48, 4)); + $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4)); + $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 56, 4)); + $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 60, 4)); + $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4)); + $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 68, 4)); + $atom_structure['preview_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 72, 4)); + $atom_structure['preview_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 76, 4)); + $atom_structure['poster_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 80, 4)); + $atom_structure['selection_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 84, 4)); + $atom_structure['selection_duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 88, 4)); + $atom_structure['current_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 92, 4)); + $atom_structure['next_track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, 96, 4)); + + if ($atom_structure['time_scale'] == 0) { + $this->error('Corrupt Quicktime file: mvhd.time_scale == zero'); + return false; + } + $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); + $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); + $info['quicktime']['timestamps_unix']['create'][$atom_structure['hierarchy']] = $atom_structure['creation_time_unix']; + $info['quicktime']['timestamps_unix']['modify'][$atom_structure['hierarchy']] = $atom_structure['modify_time_unix']; + $info['quicktime']['time_scale'] = ((isset($info['quicktime']['time_scale']) && ($info['quicktime']['time_scale'] < 1000)) ? max($info['quicktime']['time_scale'], $atom_structure['time_scale']) : $atom_structure['time_scale']); + $info['quicktime']['display_scale'] = $atom_structure['matrix_a']; + $info['playtime_seconds'] = $atom_structure['duration'] / $atom_structure['time_scale']; + break; + + + case 'tkhd': // TracK HeaDer atom + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); + $atom_structure['creation_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $atom_structure['modify_time'] = getid3_lib::BigEndian2Int(substr($atom_data, 8, 4)); + $atom_structure['trackid'] = getid3_lib::BigEndian2Int(substr($atom_data, 12, 4)); + $atom_structure['reserved1'] = getid3_lib::BigEndian2Int(substr($atom_data, 16, 4)); + $atom_structure['duration'] = getid3_lib::BigEndian2Int(substr($atom_data, 20, 4)); + $atom_structure['reserved2'] = getid3_lib::BigEndian2Int(substr($atom_data, 24, 8)); + $atom_structure['layer'] = getid3_lib::BigEndian2Int(substr($atom_data, 32, 2)); + $atom_structure['alternate_group'] = getid3_lib::BigEndian2Int(substr($atom_data, 34, 2)); + $atom_structure['volume'] = getid3_lib::FixedPoint8_8(substr($atom_data, 36, 2)); + $atom_structure['reserved3'] = getid3_lib::BigEndian2Int(substr($atom_data, 38, 2)); + // http://developer.apple.com/library/mac/#documentation/QuickTime/RM/MovieBasics/MTEditing/K-Chapter/11MatrixFunctions.html + // http://developer.apple.com/library/mac/#documentation/QuickTime/qtff/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-18737 + $atom_structure['matrix_a'] = getid3_lib::FixedPoint16_16(substr($atom_data, 40, 4)); + $atom_structure['matrix_b'] = getid3_lib::FixedPoint16_16(substr($atom_data, 44, 4)); + $atom_structure['matrix_u'] = getid3_lib::FixedPoint2_30(substr($atom_data, 48, 4)); + $atom_structure['matrix_c'] = getid3_lib::FixedPoint16_16(substr($atom_data, 52, 4)); + $atom_structure['matrix_d'] = getid3_lib::FixedPoint16_16(substr($atom_data, 56, 4)); + $atom_structure['matrix_v'] = getid3_lib::FixedPoint2_30(substr($atom_data, 60, 4)); + $atom_structure['matrix_x'] = getid3_lib::FixedPoint16_16(substr($atom_data, 64, 4)); + $atom_structure['matrix_y'] = getid3_lib::FixedPoint16_16(substr($atom_data, 68, 4)); + $atom_structure['matrix_w'] = getid3_lib::FixedPoint2_30(substr($atom_data, 72, 4)); + $atom_structure['width'] = getid3_lib::FixedPoint16_16(substr($atom_data, 76, 4)); + $atom_structure['height'] = getid3_lib::FixedPoint16_16(substr($atom_data, 80, 4)); + $atom_structure['flags']['enabled'] = (bool) ($atom_structure['flags_raw'] & 0x0001); + $atom_structure['flags']['in_movie'] = (bool) ($atom_structure['flags_raw'] & 0x0002); + $atom_structure['flags']['in_preview'] = (bool) ($atom_structure['flags_raw'] & 0x0004); + $atom_structure['flags']['in_poster'] = (bool) ($atom_structure['flags_raw'] & 0x0008); + $atom_structure['creation_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['creation_time']); + $atom_structure['modify_time_unix'] = getid3_lib::DateMac2Unix($atom_structure['modify_time']); + $info['quicktime']['timestamps_unix']['create'][$atom_structure['hierarchy']] = $atom_structure['creation_time_unix']; + $info['quicktime']['timestamps_unix']['modify'][$atom_structure['hierarchy']] = $atom_structure['modify_time_unix']; + + // https://www.getid3.org/phpBB3/viewtopic.php?t=1908 + // attempt to compute rotation from matrix values + // 2017-Dec-28: uncertain if 90/270 are correctly oriented; values returned by FixedPoint16_16 should perhaps be -1 instead of 65535(?) + $matrixRotation = 0; + switch ($atom_structure['matrix_a'].':'.$atom_structure['matrix_b'].':'.$atom_structure['matrix_c'].':'.$atom_structure['matrix_d']) { + case '1:0:0:1': $matrixRotation = 0; break; + case '0:1:65535:0': $matrixRotation = 90; break; + case '65535:0:0:65535': $matrixRotation = 180; break; + case '0:65535:1:0': $matrixRotation = 270; break; + default: break; + } + + // https://www.getid3.org/phpBB3/viewtopic.php?t=2468 + // The rotation matrix can appear in the Quicktime file multiple times, at least once for each track, + // and it's possible that only the video track (or, in theory, one of the video tracks) is flagged as + // rotated while the other tracks (e.g. audio) is tagged as rotation=0 (behavior noted on iPhone 8 Plus) + // The correct solution would be to check if the TrackID associated with the rotation matrix is indeed + // a video track (or the main video track) and only set the rotation then, but since information about + // what track is what is not trivially there to be examined, the lazy solution is to set the rotation + // if it is found to be nonzero, on the assumption that tracks that don't need it will have rotation set + // to zero (and be effectively ignored) and the video track will have rotation set correctly, which will + // either be zero and automatically correct, or nonzero and be set correctly. + if (!isset($info['video']['rotate']) || (($info['video']['rotate'] == 0) && ($matrixRotation > 0))) { + $info['quicktime']['video']['rotate'] = $info['video']['rotate'] = $matrixRotation; + } + + if ($atom_structure['flags']['enabled'] == 1) { + if (!isset($info['video']['resolution_x']) || !isset($info['video']['resolution_y'])) { + $info['video']['resolution_x'] = $atom_structure['width']; + $info['video']['resolution_y'] = $atom_structure['height']; + } + $info['video']['resolution_x'] = max($info['video']['resolution_x'], $atom_structure['width']); + $info['video']['resolution_y'] = max($info['video']['resolution_y'], $atom_structure['height']); + $info['quicktime']['video']['resolution_x'] = $info['video']['resolution_x']; + $info['quicktime']['video']['resolution_y'] = $info['video']['resolution_y']; + } else { + // see: https://www.getid3.org/phpBB3/viewtopic.php?t=1295 + //if (isset($info['video']['resolution_x'])) { unset($info['video']['resolution_x']); } + //if (isset($info['video']['resolution_y'])) { unset($info['video']['resolution_y']); } + //if (isset($info['quicktime']['video'])) { unset($info['quicktime']['video']); } + } + break; + + + case 'iods': // Initial Object DeScriptor atom + // http://www.koders.com/c/fid1FAB3E762903DC482D8A246D4A4BF9F28E049594.aspx?s=windows.h + // http://libquicktime.sourcearchive.com/documentation/1.0.2plus-pdebian/iods_8c-source.html + $offset = 0; + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 3)); + $offset += 3; + $atom_structure['mp4_iod_tag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + $atom_structure['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset); + //$offset already adjusted by quicktime_read_mp4_descr_length() + $atom_structure['object_descriptor_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 2)); + $offset += 2; + $atom_structure['od_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + $atom_structure['scene_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + $atom_structure['audio_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + $atom_structure['video_profile_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + $atom_structure['graphics_profile_level'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + + $atom_structure['num_iods_tracks'] = ($atom_structure['length'] - 7) / 6; // 6 bytes would only be right if all tracks use 1-byte length fields + for ($i = 0; $i < $atom_structure['num_iods_tracks']; $i++) { + $atom_structure['track'][$i]['ES_ID_IncTag'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 1)); + $offset += 1; + $atom_structure['track'][$i]['length'] = $this->quicktime_read_mp4_descr_length($atom_data, $offset); + //$offset already adjusted by quicktime_read_mp4_descr_length() + $atom_structure['track'][$i]['track_id'] = getid3_lib::BigEndian2Int(substr($atom_data, $offset, 4)); + $offset += 4; + } + + $atom_structure['audio_profile_name'] = $this->QuicktimeIODSaudioProfileName($atom_structure['audio_profile_id']); + $atom_structure['video_profile_name'] = $this->QuicktimeIODSvideoProfileName($atom_structure['video_profile_id']); + break; + + case 'ftyp': // FileTYPe (?) atom (for MP4 it seems) + $atom_structure['signature'] = substr($atom_data, 0, 4); + $atom_structure['unknown_1'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $atom_structure['fourcc'] = substr($atom_data, 8, 4); + break; + + case 'mdat': // Media DATa atom + // 'mdat' contains the actual data for the audio/video, possibly also subtitles + + /* due to lack of known documentation, this is a kludge implementation. If you know of documentation on how mdat is properly structed, please send it to info@getid3.org */ + + // first, skip any 'wide' padding, and second 'mdat' header (with specified size of zero?) + $mdat_offset = 0; + while (true) { + if (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x08".'wide') { + $mdat_offset += 8; + } elseif (substr($atom_data, $mdat_offset, 8) == "\x00\x00\x00\x00".'mdat') { + $mdat_offset += 8; + } else { + break; + } + } + if (substr($atom_data, $mdat_offset, 4) == 'GPRO') { + $GOPRO_chunk_length = getid3_lib::LittleEndian2Int(substr($atom_data, $mdat_offset + 4, 4)); + $GOPRO_offset = 8; + $atom_structure['GPRO']['raw'] = substr($atom_data, $mdat_offset + 8, $GOPRO_chunk_length - 8); + $atom_structure['GPRO']['firmware'] = substr($atom_structure['GPRO']['raw'], 0, 15); + $atom_structure['GPRO']['unknown1'] = substr($atom_structure['GPRO']['raw'], 15, 16); + $atom_structure['GPRO']['unknown2'] = substr($atom_structure['GPRO']['raw'], 31, 32); + $atom_structure['GPRO']['unknown3'] = substr($atom_structure['GPRO']['raw'], 63, 16); + $atom_structure['GPRO']['camera'] = substr($atom_structure['GPRO']['raw'], 79, 32); + $info['quicktime']['camera']['model'] = rtrim($atom_structure['GPRO']['camera'], "\x00"); + } + + // check to see if it looks like chapter titles, in the form of unterminated strings with a leading 16-bit size field + while (($mdat_offset < (strlen($atom_data) - 8)) + && ($chapter_string_length = getid3_lib::BigEndian2Int(substr($atom_data, $mdat_offset, 2))) + && ($chapter_string_length < 1000) + && ($chapter_string_length <= (strlen($atom_data) - $mdat_offset - 2)) + && preg_match('#^([\x00-\xFF]{2})([\x20-\xFF]+)$#', substr($atom_data, $mdat_offset, $chapter_string_length + 2), $chapter_matches)) { + list($dummy, $chapter_string_length_hex, $chapter_string) = $chapter_matches; + $mdat_offset += (2 + $chapter_string_length); + @$info['quicktime']['comments']['chapters'][] = $chapter_string; + + // "encd" atom specifies encoding. In theory could be anything, almost always UTF-8, but may be UTF-16 with BOM (not currently handled) + if (substr($atom_data, $mdat_offset, 12) == "\x00\x00\x00\x0C\x65\x6E\x63\x64\x00\x00\x01\x00") { // UTF-8 + $mdat_offset += 12; + } + } + + if (($atomsize > 8) && (!isset($info['avdataend_tmp']) || ($info['quicktime'][$atomname]['size'] > ($info['avdataend_tmp'] - $info['avdataoffset'])))) { + + $info['avdataoffset'] = $atom_structure['offset'] + 8; // $info['quicktime'][$atomname]['offset'] + 8; + $OldAVDataEnd = $info['avdataend']; + $info['avdataend'] = $atom_structure['offset'] + $atom_structure['size']; // $info['quicktime'][$atomname]['offset'] + $info['quicktime'][$atomname]['size']; + + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; + $getid3_temp->info['avdataend'] = $info['avdataend']; + $getid3_mp3 = new getid3_mp3($getid3_temp); + if ($getid3_mp3->MPEGaudioHeaderValid($getid3_mp3->MPEGaudioHeaderDecode($this->fread(4)))) { + $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false); + if (!empty($getid3_temp->info['warning'])) { + foreach ($getid3_temp->info['warning'] as $value) { + $this->warning($value); + } + } + if (!empty($getid3_temp->info['mpeg'])) { + $info['mpeg'] = $getid3_temp->info['mpeg']; + if (isset($info['mpeg']['audio'])) { + $info['audio']['dataformat'] = 'mp3'; + $info['audio']['codec'] = (!empty($info['mpeg']['audio']['encoder']) ? $info['mpeg']['audio']['encoder'] : (!empty($info['mpeg']['audio']['codec']) ? $info['mpeg']['audio']['codec'] : (!empty($info['mpeg']['audio']['LAME']) ? 'LAME' :'mp3'))); + $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; + $info['audio']['channels'] = $info['mpeg']['audio']['channels']; + $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; + $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); + $info['bitrate'] = $info['audio']['bitrate']; + } + } + } + unset($getid3_mp3, $getid3_temp); + $info['avdataend'] = $OldAVDataEnd; + unset($OldAVDataEnd); + + } + + unset($mdat_offset, $chapter_string_length, $chapter_matches); + break; + + case 'ID32': // ID3v2 + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); + + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_id3v2 = new getid3_id3v2($getid3_temp); + $getid3_id3v2->StartingOffset = $atom_structure['offset'] + 14; // framelength(4)+framename(4)+flags(4)+??(2) + if ($atom_structure['valid'] = $getid3_id3v2->Analyze()) { + $atom_structure['id3v2'] = $getid3_temp->info['id3v2']; + } else { + $this->warning('ID32 frame at offset '.$atom_structure['offset'].' did not parse'); + } + unset($getid3_temp, $getid3_id3v2); + break; + + case 'free': // FREE space atom + case 'skip': // SKIP atom + case 'wide': // 64-bit expansion placeholder atom + // 'free', 'skip' and 'wide' are just padding, contains no useful data at all + + // When writing QuickTime files, it is sometimes necessary to update an atom's size. + // It is impossible to update a 32-bit atom to a 64-bit atom since the 32-bit atom + // is only 8 bytes in size, and the 64-bit atom requires 16 bytes. Therefore, QuickTime + // puts an 8-byte placeholder atom before any atoms it may have to update the size of. + // In this way, if the atom needs to be converted from a 32-bit to a 64-bit atom, the + // placeholder atom can be overwritten to obtain the necessary 8 extra bytes. + // The placeholder atom has a type of kWideAtomPlaceholderType ( 'wide' ). + break; + + + case 'nsav': // NoSAVe atom + // http://developer.apple.com/technotes/tn/tn2038.html + $atom_structure['data'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); + break; + + case 'ctyp': // Controller TYPe atom (seen on QTVR) + // http://homepages.slingshot.co.nz/~helmboy/quicktime/formats/qtm-layout.txt + // some controller names are: + // 0x00 + 'std' for linear movie + // 'none' for no controls + $atom_structure['ctyp'] = substr($atom_data, 0, 4); + $info['quicktime']['controller'] = $atom_structure['ctyp']; + switch ($atom_structure['ctyp']) { + case 'qtvr': + $info['video']['dataformat'] = 'quicktimevr'; + break; + } + break; + + case 'pano': // PANOrama track (seen on QTVR) + $atom_structure['pano'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 4)); + break; + + case 'hint': // HINT track + case 'hinf': // + case 'hinv': // + case 'hnti': // + $info['quicktime']['hinting'] = true; + break; + + case 'imgt': // IMaGe Track reference (kQTVRImageTrackRefType) (seen on QTVR) + for ($i = 0; $i < ($atom_structure['size'] - 8); $i += 4) { + $atom_structure['imgt'][] = getid3_lib::BigEndian2Int(substr($atom_data, $i, 4)); + } + break; + + + // Observed-but-not-handled atom types are just listed here to prevent warnings being generated + case 'FXTC': // Something to do with Adobe After Effects (?) + case 'PrmA': + case 'code': + case 'FIEL': // this is NOT "fiel" (Field Ordering) as describe here: http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html + case 'tapt': // TrackApertureModeDimensionsAID - http://developer.apple.com/documentation/QuickTime/Reference/QT7-1_Update_Reference/Constants/Constants.html + // tapt seems to be used to compute the video size [https://www.getid3.org/phpBB3/viewtopic.php?t=838] + // * http://lists.apple.com/archives/quicktime-api/2006/Aug/msg00014.html + // * http://handbrake.fr/irclogs/handbrake-dev/handbrake-dev20080128_pg2.html + case 'ctts':// STCompositionOffsetAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html + case 'cslg':// STCompositionShiftLeastGreatestAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html + case 'sdtp':// STSampleDependencyAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html + case 'stps':// STPartialSyncSampleAID - http://developer.apple.com/documentation/QuickTime/Reference/QTRef_Constants/Reference/reference.html + //$atom_structure['data'] = $atom_data; + break; + + case "\xA9".'xyz': // GPS latitude+longitude+altitude + $atom_structure['data'] = $atom_data; + if (preg_match('#([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)([\\+\\-][0-9\\.]+)?/$#i', $atom_data, $matches)) { + @list($all, $latitude, $longitude, $altitude) = $matches; + $info['quicktime']['comments']['gps_latitude'][] = floatval($latitude); + $info['quicktime']['comments']['gps_longitude'][] = floatval($longitude); + if (!empty($altitude)) { + $info['quicktime']['comments']['gps_altitude'][] = floatval($altitude); + } + } else { + $this->warning('QuickTime atom "©xyz" data does not match expected data pattern at offset '.$baseoffset.'. Please report as getID3() bug.'); + } + break; + + case 'NCDT': + // https://exiftool.org/TagNames/Nikon.html + // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100 + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms); + break; + case 'NCTH': // Nikon Camera THumbnail image + case 'NCVW': // Nikon Camera preVieW image + case 'NCM1': // Nikon Camera preview iMage 1 + case 'NCM2': // Nikon Camera preview iMage 2 + // https://exiftool.org/TagNames/Nikon.html + if (preg_match('/^\xFF\xD8\xFF/', $atom_data)) { + $descriptions = array( + 'NCTH' => 'Nikon Camera Thumbnail Image', + 'NCVW' => 'Nikon Camera Preview Image', + 'NCM1' => 'Nikon Camera Preview Image 1', + 'NCM2' => 'Nikon Camera Preview Image 2', + ); + $atom_structure['data'] = $atom_data; + $atom_structure['image_mime'] = 'image/jpeg'; + $atom_structure['description'] = isset($descriptions[$atomname]) ? $descriptions[$atomname] : 'Nikon preview image'; + $info['quicktime']['comments']['picture'][] = array( + 'image_mime' => $atom_structure['image_mime'], + 'data' => $atom_data, + 'description' => $atom_structure['description'] + ); + } + break; + case 'NCTG': // Nikon - https://exiftool.org/TagNames/Nikon.html#NCTG + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.nikon-nctg.php', __FILE__, true); + $nikonNCTG = new getid3_tag_nikon_nctg($this->getid3); + + $atom_structure['data'] = $nikonNCTG->parse($atom_data); + break; + case 'NCHD': // Nikon:MakerNoteVersion - https://exiftool.org/TagNames/Nikon.html + $makerNoteVersion = ''; + for ($i = 0, $iMax = strlen($atom_data); $i < $iMax; ++$i) { + if (ord($atom_data[$i]) >= 0x00 && ord($atom_data[$i]) <= 0x1F) { + $makerNoteVersion .= ' '.ord($atom_data[$i]); + } else { + $makerNoteVersion .= $atom_data[$i]; + } + } + $makerNoteVersion = rtrim($makerNoteVersion, "\x00"); + $atom_structure['data'] = array( + 'MakerNoteVersion' => $makerNoteVersion + ); + break; + case 'NCDB': // Nikon - https://exiftool.org/TagNames/Nikon.html + case 'CNCV': // Canon:CompressorVersion - https://exiftool.org/TagNames/Canon.html + $atom_structure['data'] = $atom_data; + break; + + case "\x00\x00\x00\x00": + // some kind of metacontainer, may contain a big data dump such as: + // mdta keys \005 mdtacom.apple.quicktime.make (mdtacom.apple.quicktime.creationdate ,mdtacom.apple.quicktime.location.ISO6709 $mdtacom.apple.quicktime.software !mdtacom.apple.quicktime.model ilst \01D \001 \015data \001DE\010Apple 0 \002 (data \001DE\0102011-05-11T17:54:04+0200 2 \003 *data \001DE\010+52.4936+013.3897+040.247/ \01D \004 \015data \001DE\0104.3.1 \005 \018data \001DE\010iPhone 4 + // https://xhelmboyx.tripod.com/formats/qti-layout.txt + + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom(substr($atom_data, 4), $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); + //$atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); + break; + + case 'meta': // METAdata atom + // https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/Metadata/Metadata.html + + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 8, $atomHierarchy, $ParseAllPossibleAtoms); + break; + + case 'data': // metaDATA atom + static $metaDATAkey = 1; // real ugly, but so is the QuickTime structure that stores keys and values in different multinested locations that are hard to relate to each other + // seems to be 2 bytes language code (ASCII), 2 bytes unknown (set to 0x10B5 in sample I have), remainder is useful data + $atom_structure['language'] = substr($atom_data, 4 + 0, 2); + $atom_structure['unknown'] = getid3_lib::BigEndian2Int(substr($atom_data, 4 + 2, 2)); + $atom_structure['data'] = substr($atom_data, 4 + 4); + $atom_structure['key_name'] = (isset($info['quicktime']['temp_meta_key_names'][$metaDATAkey]) ? $info['quicktime']['temp_meta_key_names'][$metaDATAkey] : ''); + $metaDATAkey++; + + if ($atom_structure['key_name'] && $atom_structure['data']) { + @$info['quicktime']['comments'][str_replace('com.apple.quicktime.', '', $atom_structure['key_name'])][] = $atom_structure['data']; + } + break; + + case 'keys': // KEYS that may be present in the metadata atom. + // https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW21 + // The metadata item keys atom holds a list of the metadata keys that may be present in the metadata atom. + // This list is indexed starting with 1; 0 is a reserved index value. The metadata item keys atom is a full atom with an atom type of "keys". + $atom_structure['version'] = getid3_lib::BigEndian2Int(substr($atom_data, 0, 1)); + $atom_structure['flags_raw'] = getid3_lib::BigEndian2Int(substr($atom_data, 1, 3)); + $atom_structure['entry_count'] = getid3_lib::BigEndian2Int(substr($atom_data, 4, 4)); + $keys_atom_offset = 8; + for ($i = 1; $i <= $atom_structure['entry_count']; $i++) { + $atom_structure['keys'][$i]['key_size'] = getid3_lib::BigEndian2Int(substr($atom_data, $keys_atom_offset + 0, 4)); + $atom_structure['keys'][$i]['key_namespace'] = substr($atom_data, $keys_atom_offset + 4, 4); + $atom_structure['keys'][$i]['key_value'] = substr($atom_data, $keys_atom_offset + 8, $atom_structure['keys'][$i]['key_size'] - 8); + $keys_atom_offset += $atom_structure['keys'][$i]['key_size']; // key_size includes the 4+4 bytes for key_size and key_namespace + + $info['quicktime']['temp_meta_key_names'][$i] = $atom_structure['keys'][$i]['key_value']; + } + break; + + case 'uuid': // user-defined atom often seen containing XML data, also used for potentially many other purposes, only a few specifically handled by getID3 (e.g. 360fly spatial data) + //Get the UUID ID in first 16 bytes + $uuid_bytes_read = unpack('H8time_low/H4time_mid/H4time_hi/H4clock_seq_hi/H12clock_seq_low', substr($atom_data, 0, 16)); + $atom_structure['uuid_field_id'] = implode('-', $uuid_bytes_read); + + switch ($atom_structure['uuid_field_id']) { // http://fileformats.archiveteam.org/wiki/Boxes/atoms_format#UUID_boxes + + case '0537cdab-9d0c-4431-a72a-fa561f2a113e': // Exif - http://fileformats.archiveteam.org/wiki/Exif + case '2c4c0100-8504-40b9-a03e-562148d6dfeb': // Photoshop Image Resources - http://fileformats.archiveteam.org/wiki/Photoshop_Image_Resources + case '33c7a4d2-b81d-4723-a0ba-f1a3e097ad38': // IPTC-IIM - http://fileformats.archiveteam.org/wiki/IPTC-IIM + case '8974dbce-7be7-4c51-84f9-7148f9882554': // PIFF Track Encryption Box - http://fileformats.archiveteam.org/wiki/Protected_Interoperable_File_Format + case '96a9f1f1-dc98-402d-a7ae-d68e34451809': // GeoJP2 World File Box - http://fileformats.archiveteam.org/wiki/GeoJP2 + case 'a2394f52-5a9b-4f14-a244-6c427c648df4': // PIFF Sample Encryption Box - http://fileformats.archiveteam.org/wiki/Protected_Interoperable_File_Format + case 'b14bf8bd-083d-4b43-a5ae-8cd7d5a6ce03': // GeoJP2 GeoTIFF Box - http://fileformats.archiveteam.org/wiki/GeoJP2 + case 'd08a4f18-10f3-4a82-b6c8-32d8aba183d3': // PIFF Protection System Specific Header Box - http://fileformats.archiveteam.org/wiki/Protected_Interoperable_File_Format + $this->warning('Unhandled (but recognized) "uuid" atom identified by "'.$atom_structure['uuid_field_id'].'" at offset '.$atom_structure['offset'].' ('.strlen($atom_data).' bytes)'); + break; + + case 'be7acfcb-97a9-42e8-9c71-999491e3afac': // XMP data (in XML format) + $atom_structure['xml'] = substr($atom_data, 16, strlen($atom_data) - 16 - 8); // 16 bytes for UUID, 8 bytes header(?) + break; + + case 'efe1589a-bb77-49ef-8095-27759eb1dc6f': // 360fly data + /* 360fly code in this block by Paul Lewis 2019-Oct-31 */ + /* Sensor Timestamps need to be calculated using the recordings base time at ['quicktime']['moov']['subatoms'][0]['creation_time_unix']. */ + $atom_structure['title'] = '360Fly Sensor Data'; + + //Get the UUID HEADER data + $uuid_bytes_read = unpack('vheader_size/vheader_version/vtimescale/vhardware_version/x/x/x/x/x/x/x/x/x/x/x/x/x/x/x/x/', substr($atom_data, 16, 32)); + $atom_structure['uuid_header'] = $uuid_bytes_read; + + $start_byte = 48; + $atom_SENSOR_data = substr($atom_data, $start_byte); + $atom_structure['sensor_data']['data_type'] = array( + 'fusion_count' => 0, // ID 250 + 'fusion_data' => array(), + 'accel_count' => 0, // ID 1 + 'accel_data' => array(), + 'gyro_count' => 0, // ID 2 + 'gyro_data' => array(), + 'magno_count' => 0, // ID 3 + 'magno_data' => array(), + 'gps_count' => 0, // ID 5 + 'gps_data' => array(), + 'rotation_count' => 0, // ID 6 + 'rotation_data' => array(), + 'unknown_count' => 0, // ID ?? + 'unknown_data' => array(), + 'debug_list' => '', // Used to debug variables stored as comma delimited strings + ); + $debug_structure = array(); + $debug_structure['debug_items'] = array(); + // Can start loop here to decode all sensor data in 32 Byte chunks: + foreach (str_split($atom_SENSOR_data, 32) as $sensor_key => $sensor_data) { + // This gets me a data_type code to work out what data is in the next 31 bytes. + $sensor_data_type = substr($sensor_data, 0, 1); + $sensor_data_content = substr($sensor_data, 1); + $uuid_bytes_read = unpack('C*', $sensor_data_type); + $sensor_data_array = array(); + switch ($uuid_bytes_read[1]) { + case 250: + $atom_structure['sensor_data']['data_type']['fusion_count']++; + $uuid_bytes_read = unpack('cmode/Jtimestamp/Gyaw/Gpitch/Groll/x*', $sensor_data_content); + $sensor_data_array['mode'] = $uuid_bytes_read['mode']; + $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; + $sensor_data_array['yaw'] = $uuid_bytes_read['yaw']; + $sensor_data_array['pitch'] = $uuid_bytes_read['pitch']; + $sensor_data_array['roll'] = $uuid_bytes_read['roll']; + array_push($atom_structure['sensor_data']['data_type']['fusion_data'], $sensor_data_array); + break; + case 1: + $atom_structure['sensor_data']['data_type']['accel_count']++; + $uuid_bytes_read = unpack('cmode/Jtimestamp/Gyaw/Gpitch/Groll/x*', $sensor_data_content); + $sensor_data_array['mode'] = $uuid_bytes_read['mode']; + $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; + $sensor_data_array['yaw'] = $uuid_bytes_read['yaw']; + $sensor_data_array['pitch'] = $uuid_bytes_read['pitch']; + $sensor_data_array['roll'] = $uuid_bytes_read['roll']; + array_push($atom_structure['sensor_data']['data_type']['accel_data'], $sensor_data_array); + break; + case 2: + $atom_structure['sensor_data']['data_type']['gyro_count']++; + $uuid_bytes_read = unpack('cmode/Jtimestamp/Gyaw/Gpitch/Groll/x*', $sensor_data_content); + $sensor_data_array['mode'] = $uuid_bytes_read['mode']; + $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; + $sensor_data_array['yaw'] = $uuid_bytes_read['yaw']; + $sensor_data_array['pitch'] = $uuid_bytes_read['pitch']; + $sensor_data_array['roll'] = $uuid_bytes_read['roll']; + array_push($atom_structure['sensor_data']['data_type']['gyro_data'], $sensor_data_array); + break; + case 3: + $atom_structure['sensor_data']['data_type']['magno_count']++; + $uuid_bytes_read = unpack('cmode/Jtimestamp/Gmagx/Gmagy/Gmagz/x*', $sensor_data_content); + $sensor_data_array['mode'] = $uuid_bytes_read['mode']; + $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; + $sensor_data_array['magx'] = $uuid_bytes_read['magx']; + $sensor_data_array['magy'] = $uuid_bytes_read['magy']; + $sensor_data_array['magz'] = $uuid_bytes_read['magz']; + array_push($atom_structure['sensor_data']['data_type']['magno_data'], $sensor_data_array); + break; + case 5: + $atom_structure['sensor_data']['data_type']['gps_count']++; + $uuid_bytes_read = unpack('cmode/Jtimestamp/Glat/Glon/Galt/Gspeed/nbearing/nacc/x*', $sensor_data_content); + $sensor_data_array['mode'] = $uuid_bytes_read['mode']; + $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; + $sensor_data_array['lat'] = $uuid_bytes_read['lat']; + $sensor_data_array['lon'] = $uuid_bytes_read['lon']; + $sensor_data_array['alt'] = $uuid_bytes_read['alt']; + $sensor_data_array['speed'] = $uuid_bytes_read['speed']; + $sensor_data_array['bearing'] = $uuid_bytes_read['bearing']; + $sensor_data_array['acc'] = $uuid_bytes_read['acc']; + array_push($atom_structure['sensor_data']['data_type']['gps_data'], $sensor_data_array); + //array_push($debug_structure['debug_items'], $uuid_bytes_read['timestamp']); + break; + case 6: + $atom_structure['sensor_data']['data_type']['rotation_count']++; + $uuid_bytes_read = unpack('cmode/Jtimestamp/Grotx/Groty/Grotz/x*', $sensor_data_content); + $sensor_data_array['mode'] = $uuid_bytes_read['mode']; + $sensor_data_array['timestamp'] = $uuid_bytes_read['timestamp']; + $sensor_data_array['rotx'] = $uuid_bytes_read['rotx']; + $sensor_data_array['roty'] = $uuid_bytes_read['roty']; + $sensor_data_array['rotz'] = $uuid_bytes_read['rotz']; + array_push($atom_structure['sensor_data']['data_type']['rotation_data'], $sensor_data_array); + break; + default: + $atom_structure['sensor_data']['data_type']['unknown_count']++; + break; + } + } + //if (isset($debug_structure['debug_items']) && count($debug_structure['debug_items']) > 0) { + // $atom_structure['sensor_data']['data_type']['debug_list'] = implode(',', $debug_structure['debug_items']); + //} else { + $atom_structure['sensor_data']['data_type']['debug_list'] = 'No debug items in list!'; + //} + break; + + default: + $this->warning('Unhandled "uuid" atom identified by "'.$atom_structure['uuid_field_id'].'" at offset '.$atom_structure['offset'].' ('.strlen($atom_data).' bytes)'); + } + break; + + case 'gps ': + // https://dashcamtalk.com/forum/threads/script-to-extract-gps-data-from-novatek-mp4.20808/page-2#post-291730 + // The 'gps ' contains simple look up table made up of 8byte rows, that point to the 'free' atoms that contains the actual GPS data. + // The first row is version/metadata/notsure, I skip that. + // The following rows consist of 4byte address (absolute) and 4byte size (0x1000), these point to the GPS data in the file. + + $GPS_rowsize = 8; // 4 bytes for offset, 4 bytes for size + if (strlen($atom_data) > 0) { + if ((strlen($atom_data) % $GPS_rowsize) == 0) { + $atom_structure['gps_toc'] = array(); + foreach (str_split($atom_data, $GPS_rowsize) as $counter => $datapair) { + $atom_structure['gps_toc'][] = unpack('Noffset/Nsize', substr($atom_data, $counter * $GPS_rowsize, $GPS_rowsize)); + } + + $atom_structure['gps_entries'] = array(); + $previous_offset = $this->ftell(); + foreach ($atom_structure['gps_toc'] as $key => $gps_pointer) { + if ($key == 0) { + // "The first row is version/metadata/notsure, I skip that." + continue; + } + $this->fseek($gps_pointer['offset']); + $GPS_free_data = $this->fread($gps_pointer['size']); + + /* + // 2017-05-10: I see some of the data, notably the Hour-Minute-Second, but cannot reconcile the rest of the data. However, the NMEA "GPRMC" line is there and relatively easy to parse, so I'm using that instead + + // https://dashcamtalk.com/forum/threads/script-to-extract-gps-data-from-novatek-mp4.20808/page-2#post-291730 + // The structure of the GPS data atom (the 'free' atoms mentioned above) is following: + // hour,minute,second,year,month,day,active,latitude_b,longitude_b,unknown2,latitude,longitude,speed = struct.unpack_from(' 90) ? 1900 : 2000); // complete lack of foresight: datestamps are stored with 2-digit years, take best guess + $GPS_this_GPRMC['timestamp'] = $year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second.$ms; + + $GPS_this_GPRMC['active'] = ($GPS_this_GPRMC['raw']['status'] == 'A'); // A=Active,V=Void + + foreach (array('latitude','longitude') as $latlon) { + preg_match('#^([0-9]{1,3})([0-9]{2}\\.[0-9]+)$#', $GPS_this_GPRMC['raw'][$latlon], $matches); + list($dummy, $deg, $min) = $matches; + $GPS_this_GPRMC[$latlon] = $deg + ($min / 60); + } + $GPS_this_GPRMC['latitude'] *= (($GPS_this_GPRMC['raw']['latitude_direction'] == 'S') ? -1 : 1); + $GPS_this_GPRMC['longitude'] *= (($GPS_this_GPRMC['raw']['longitude_direction'] == 'W') ? -1 : 1); + + $GPS_this_GPRMC['heading'] = $GPS_this_GPRMC['raw']['angle']; + $GPS_this_GPRMC['speed_knot'] = $GPS_this_GPRMC['raw']['knots']; + $GPS_this_GPRMC['speed_kmh'] = $GPS_this_GPRMC['raw']['knots'] * 1.852; + if ($GPS_this_GPRMC['raw']['variation']) { + $GPS_this_GPRMC['variation'] = $GPS_this_GPRMC['raw']['variation']; + $GPS_this_GPRMC['variation'] *= (($GPS_this_GPRMC['raw']['variation_direction'] == 'W') ? -1 : 1); + } + + $atom_structure['gps_entries'][$key] = $GPS_this_GPRMC; + + @$info['quicktime']['gps_track'][$GPS_this_GPRMC['timestamp']] = array( + 'latitude' => (float) $GPS_this_GPRMC['latitude'], + 'longitude' => (float) $GPS_this_GPRMC['longitude'], + 'speed_kmh' => (float) $GPS_this_GPRMC['speed_kmh'], + 'heading' => (float) $GPS_this_GPRMC['heading'], + ); + + } else { + $this->warning('Unhandled GPS format in "free" atom at offset '.$gps_pointer['offset']); + } + } + $this->fseek($previous_offset); + + } else { + $this->warning('QuickTime atom "'.$atomname.'" is not mod-8 bytes long ('.$atomsize.' bytes) at offset '.$baseoffset); + } + } else { + $this->warning('QuickTime atom "'.$atomname.'" is zero bytes long at offset '.$baseoffset); + } + break; + + case 'loci':// 3GP location (El Loco) + $loffset = 0; + $info['quicktime']['comments']['gps_flags'] = array( getid3_lib::BigEndian2Int(substr($atom_data, 0, 4))); + $info['quicktime']['comments']['gps_lang'] = array( getid3_lib::BigEndian2Int(substr($atom_data, 4, 2))); + $info['quicktime']['comments']['gps_location'] = array( $this->LociString(substr($atom_data, 6), $loffset)); + $loci_data = substr($atom_data, 6 + $loffset); + $info['quicktime']['comments']['gps_role'] = array( getid3_lib::BigEndian2Int(substr($loci_data, 0, 1))); + $info['quicktime']['comments']['gps_longitude'] = array(getid3_lib::FixedPoint16_16(substr($loci_data, 1, 4))); + $info['quicktime']['comments']['gps_latitude'] = array(getid3_lib::FixedPoint16_16(substr($loci_data, 5, 4))); + $info['quicktime']['comments']['gps_altitude'] = array(getid3_lib::FixedPoint16_16(substr($loci_data, 9, 4))); + $info['quicktime']['comments']['gps_body'] = array( $this->LociString(substr($loci_data, 13 ), $loffset)); + $info['quicktime']['comments']['gps_notes'] = array( $this->LociString(substr($loci_data, 13 + $loffset), $loffset)); + break; + + case 'chpl': // CHaPter List + // https://www.adobe.com/content/dam/Adobe/en/devnet/flv/pdfs/video_file_format_spec_v10.pdf + $chpl_version = getid3_lib::BigEndian2Int(substr($atom_data, 4, 1)); // Expected to be 0 + $chpl_flags = getid3_lib::BigEndian2Int(substr($atom_data, 5, 3)); // Reserved, set to 0 + $chpl_count = getid3_lib::BigEndian2Int(substr($atom_data, 8, 1)); + $chpl_offset = 9; + for ($i = 0; $i < $chpl_count; $i++) { + if (($chpl_offset + 9) >= strlen($atom_data)) { + $this->warning('QuickTime chapter '.$i.' extends beyond end of "chpl" atom'); + break; + } + $info['quicktime']['chapters'][$i]['timestamp'] = getid3_lib::BigEndian2Int(substr($atom_data, $chpl_offset, 8)) / 10000000; // timestamps are stored as 100-nanosecond units + $chpl_offset += 8; + $chpl_title_size = getid3_lib::BigEndian2Int(substr($atom_data, $chpl_offset, 1)); + $chpl_offset += 1; + $info['quicktime']['chapters'][$i]['title'] = substr($atom_data, $chpl_offset, $chpl_title_size); + $chpl_offset += $chpl_title_size; + } + break; + + case 'FIRM': // FIRMware version(?), seen on GoPro Hero4 + $info['quicktime']['camera']['firmware'] = $atom_data; + break; + + case 'CAME': // FIRMware version(?), seen on GoPro Hero4 + $info['quicktime']['camera']['serial_hash'] = unpack('H*', $atom_data); + break; + + case 'dscp': + case 'rcif': + // https://www.getid3.org/phpBB3/viewtopic.php?t=1908 + if (substr($atom_data, 0, 7) == "\x00\x00\x00\x00\x55\xC4".'{') { + if ($json_decoded = @json_decode(rtrim(substr($atom_data, 6), "\x00"), true)) { + $info['quicktime']['camera'][$atomname] = $json_decoded; + if (($atomname == 'rcif') && isset($info['quicktime']['camera']['rcif']['wxcamera']['rotate'])) { + $info['video']['rotate'] = $info['quicktime']['video']['rotate'] = $info['quicktime']['camera']['rcif']['wxcamera']['rotate']; + } + } else { + $this->warning('Failed to JSON decode atom "'.$atomname.'"'); + $atom_structure['data'] = $atom_data; + } + unset($json_decoded); + } else { + $this->warning('Expecting 55 C4 7B at start of atom "'.$atomname.'", found '.getid3_lib::PrintHexBytes(substr($atom_data, 4, 3)).' instead'); + $atom_structure['data'] = $atom_data; + } + break; + + case 'frea': + // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea + // may contain "scra" (PreviewImage) and/or "thma" (ThumbnailImage) + $atom_structure['subatoms'] = $this->QuicktimeParseContainerAtom($atom_data, $baseoffset + 4, $atomHierarchy, $ParseAllPossibleAtoms); + break; + case 'tima': // subatom to "frea" + // no idea what this does, the one sample file I've seen has a value of 0x00000027 + $atom_structure['data'] = $atom_data; + break; + case 'ver ': // subatom to "frea" + // some kind of version number, the one sample file I've seen has a value of "3.00.073" + $atom_structure['data'] = $atom_data; + break; + case 'thma': // subatom to "frea" -- "ThumbnailImage" + // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea + if (strlen($atom_data) > 0) { + $info['quicktime']['comments']['picture'][] = array('data'=>$atom_data, 'image_mime'=>'image/jpeg', 'description'=>'ThumbnailImage'); + } + break; + case 'scra': // subatom to "frea" -- "PreviewImage" + // https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Kodak.html#frea + // but the only sample file I've seen has no useful data here + if (strlen($atom_data) > 0) { + $info['quicktime']['comments']['picture'][] = array('data'=>$atom_data, 'image_mime'=>'image/jpeg', 'description'=>'PreviewImage'); + } + break; + + case 'cdsc': // timed metadata reference + // A QuickTime movie can contain none, one, or several timed metadata tracks. Timed metadata tracks can refer to multiple tracks. + // Metadata tracks are linked to the tracks they describe using a track-reference of type 'cdsc'. The metadata track holds the 'cdsc' track reference. + $atom_structure['track_number'] = getid3_lib::BigEndian2Int($atom_data); + break; + + +// AVIF-related - https://docs.rs/avif-parse/0.13.2/src/avif_parse/boxes.rs.html + case 'pitm': // Primary ITeM + case 'iloc': // Item LOCation + case 'iinf': // Item INFo + case 'iref': // Image REFerence + case 'iprp': // Image PRoPerties +$this->error('AVIF files not currently supported'); + $atom_structure['data'] = $atom_data; + break; + + case 'tfdt': // Track Fragment base media Decode Time box + case 'tfhd': // Track Fragment HeaDer box + case 'mfhd': // Movie Fragment HeaDer box + case 'trun': // Track fragment RUN box +$this->error('fragmented mp4 files not currently supported'); + $atom_structure['data'] = $atom_data; + break; + + case 'mvex': // MoVie EXtends box + case 'pssh': // Protection System Specific Header box + case 'sidx': // Segment InDeX box + default: + $this->warning('Unknown QuickTime atom type: "'.preg_replace('#[^a-zA-Z0-9 _\\-]#', '?', $atomname).'" ('.trim(getid3_lib::PrintHexBytes($atomname)).'), '.$atomsize.' bytes at offset '.$baseoffset); + $atom_structure['data'] = $atom_data; + break; + } + } + array_pop($atomHierarchy); + return $atom_structure; + } + + /** + * @param string $atom_data + * @param int $baseoffset + * @param array $atomHierarchy + * @param bool $ParseAllPossibleAtoms + * + * @return array|false + */ + public function QuicktimeParseContainerAtom($atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) { + $atom_structure = array(); + $subatomoffset = 0; + $subatomcounter = 0; + if ((strlen($atom_data) == 4) && (getid3_lib::BigEndian2Int($atom_data) == 0x00000000)) { + return false; + } + while ($subatomoffset < strlen($atom_data)) { + $subatomsize = getid3_lib::BigEndian2Int(substr($atom_data, $subatomoffset + 0, 4)); + $subatomname = substr($atom_data, $subatomoffset + 4, 4); + $subatomdata = substr($atom_data, $subatomoffset + 8, $subatomsize - 8); + if ($subatomsize == 0) { + // Furthermore, for historical reasons the list of atoms is optionally + // terminated by a 32-bit integer set to 0. If you are writing a program + // to read user data atoms, you should allow for the terminating 0. + if (strlen($atom_data) > 12) { + $subatomoffset += 4; + continue; + } + break; + } + if (strlen($subatomdata) < ($subatomsize - 8)) { + // we don't have enough data to decode the subatom. + // this may be because we are refusing to parse large subatoms, or it may be because this atom had its size set too large + // so we passed in the start of a following atom incorrectly? + break; + } + $atom_structure[$subatomcounter++] = $this->QuicktimeParseAtom($subatomname, $subatomsize, $subatomdata, $baseoffset + $subatomoffset, $atomHierarchy, $ParseAllPossibleAtoms); + $subatomoffset += $subatomsize; + } + + if (empty($atom_structure)) { + return false; + } + + return $atom_structure; + } + + /** + * @param string $data + * @param int $offset + * + * @return int + */ + public function quicktime_read_mp4_descr_length($data, &$offset) { + // http://libquicktime.sourcearchive.com/documentation/2:1.0.2plus-pdebian-2build1/esds_8c-source.html + $num_bytes = 0; + $length = 0; + do { + $b = ord(substr($data, $offset++, 1)); + $length = ($length << 7) | ($b & 0x7F); + } while (($b & 0x80) && ($num_bytes++ < 4)); + return $length; + } + + /** + * @param int $languageid + * + * @return string + */ + public function QuicktimeLanguageLookup($languageid) { + // http://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap4/qtff4.html#//apple_ref/doc/uid/TP40000939-CH206-34353 + static $QuicktimeLanguageLookup = array(); + if (empty($QuicktimeLanguageLookup)) { + $QuicktimeLanguageLookup[0] = 'English'; + $QuicktimeLanguageLookup[1] = 'French'; + $QuicktimeLanguageLookup[2] = 'German'; + $QuicktimeLanguageLookup[3] = 'Italian'; + $QuicktimeLanguageLookup[4] = 'Dutch'; + $QuicktimeLanguageLookup[5] = 'Swedish'; + $QuicktimeLanguageLookup[6] = 'Spanish'; + $QuicktimeLanguageLookup[7] = 'Danish'; + $QuicktimeLanguageLookup[8] = 'Portuguese'; + $QuicktimeLanguageLookup[9] = 'Norwegian'; + $QuicktimeLanguageLookup[10] = 'Hebrew'; + $QuicktimeLanguageLookup[11] = 'Japanese'; + $QuicktimeLanguageLookup[12] = 'Arabic'; + $QuicktimeLanguageLookup[13] = 'Finnish'; + $QuicktimeLanguageLookup[14] = 'Greek'; + $QuicktimeLanguageLookup[15] = 'Icelandic'; + $QuicktimeLanguageLookup[16] = 'Maltese'; + $QuicktimeLanguageLookup[17] = 'Turkish'; + $QuicktimeLanguageLookup[18] = 'Croatian'; + $QuicktimeLanguageLookup[19] = 'Chinese (Traditional)'; + $QuicktimeLanguageLookup[20] = 'Urdu'; + $QuicktimeLanguageLookup[21] = 'Hindi'; + $QuicktimeLanguageLookup[22] = 'Thai'; + $QuicktimeLanguageLookup[23] = 'Korean'; + $QuicktimeLanguageLookup[24] = 'Lithuanian'; + $QuicktimeLanguageLookup[25] = 'Polish'; + $QuicktimeLanguageLookup[26] = 'Hungarian'; + $QuicktimeLanguageLookup[27] = 'Estonian'; + $QuicktimeLanguageLookup[28] = 'Lettish'; + $QuicktimeLanguageLookup[28] = 'Latvian'; + $QuicktimeLanguageLookup[29] = 'Saamisk'; + $QuicktimeLanguageLookup[29] = 'Lappish'; + $QuicktimeLanguageLookup[30] = 'Faeroese'; + $QuicktimeLanguageLookup[31] = 'Farsi'; + $QuicktimeLanguageLookup[31] = 'Persian'; + $QuicktimeLanguageLookup[32] = 'Russian'; + $QuicktimeLanguageLookup[33] = 'Chinese (Simplified)'; + $QuicktimeLanguageLookup[34] = 'Flemish'; + $QuicktimeLanguageLookup[35] = 'Irish'; + $QuicktimeLanguageLookup[36] = 'Albanian'; + $QuicktimeLanguageLookup[37] = 'Romanian'; + $QuicktimeLanguageLookup[38] = 'Czech'; + $QuicktimeLanguageLookup[39] = 'Slovak'; + $QuicktimeLanguageLookup[40] = 'Slovenian'; + $QuicktimeLanguageLookup[41] = 'Yiddish'; + $QuicktimeLanguageLookup[42] = 'Serbian'; + $QuicktimeLanguageLookup[43] = 'Macedonian'; + $QuicktimeLanguageLookup[44] = 'Bulgarian'; + $QuicktimeLanguageLookup[45] = 'Ukrainian'; + $QuicktimeLanguageLookup[46] = 'Byelorussian'; + $QuicktimeLanguageLookup[47] = 'Uzbek'; + $QuicktimeLanguageLookup[48] = 'Kazakh'; + $QuicktimeLanguageLookup[49] = 'Azerbaijani'; + $QuicktimeLanguageLookup[50] = 'AzerbaijanAr'; + $QuicktimeLanguageLookup[51] = 'Armenian'; + $QuicktimeLanguageLookup[52] = 'Georgian'; + $QuicktimeLanguageLookup[53] = 'Moldavian'; + $QuicktimeLanguageLookup[54] = 'Kirghiz'; + $QuicktimeLanguageLookup[55] = 'Tajiki'; + $QuicktimeLanguageLookup[56] = 'Turkmen'; + $QuicktimeLanguageLookup[57] = 'Mongolian'; + $QuicktimeLanguageLookup[58] = 'MongolianCyr'; + $QuicktimeLanguageLookup[59] = 'Pashto'; + $QuicktimeLanguageLookup[60] = 'Kurdish'; + $QuicktimeLanguageLookup[61] = 'Kashmiri'; + $QuicktimeLanguageLookup[62] = 'Sindhi'; + $QuicktimeLanguageLookup[63] = 'Tibetan'; + $QuicktimeLanguageLookup[64] = 'Nepali'; + $QuicktimeLanguageLookup[65] = 'Sanskrit'; + $QuicktimeLanguageLookup[66] = 'Marathi'; + $QuicktimeLanguageLookup[67] = 'Bengali'; + $QuicktimeLanguageLookup[68] = 'Assamese'; + $QuicktimeLanguageLookup[69] = 'Gujarati'; + $QuicktimeLanguageLookup[70] = 'Punjabi'; + $QuicktimeLanguageLookup[71] = 'Oriya'; + $QuicktimeLanguageLookup[72] = 'Malayalam'; + $QuicktimeLanguageLookup[73] = 'Kannada'; + $QuicktimeLanguageLookup[74] = 'Tamil'; + $QuicktimeLanguageLookup[75] = 'Telugu'; + $QuicktimeLanguageLookup[76] = 'Sinhalese'; + $QuicktimeLanguageLookup[77] = 'Burmese'; + $QuicktimeLanguageLookup[78] = 'Khmer'; + $QuicktimeLanguageLookup[79] = 'Lao'; + $QuicktimeLanguageLookup[80] = 'Vietnamese'; + $QuicktimeLanguageLookup[81] = 'Indonesian'; + $QuicktimeLanguageLookup[82] = 'Tagalog'; + $QuicktimeLanguageLookup[83] = 'MalayRoman'; + $QuicktimeLanguageLookup[84] = 'MalayArabic'; + $QuicktimeLanguageLookup[85] = 'Amharic'; + $QuicktimeLanguageLookup[86] = 'Tigrinya'; + $QuicktimeLanguageLookup[87] = 'Galla'; + $QuicktimeLanguageLookup[87] = 'Oromo'; + $QuicktimeLanguageLookup[88] = 'Somali'; + $QuicktimeLanguageLookup[89] = 'Swahili'; + $QuicktimeLanguageLookup[90] = 'Ruanda'; + $QuicktimeLanguageLookup[91] = 'Rundi'; + $QuicktimeLanguageLookup[92] = 'Chewa'; + $QuicktimeLanguageLookup[93] = 'Malagasy'; + $QuicktimeLanguageLookup[94] = 'Esperanto'; + $QuicktimeLanguageLookup[128] = 'Welsh'; + $QuicktimeLanguageLookup[129] = 'Basque'; + $QuicktimeLanguageLookup[130] = 'Catalan'; + $QuicktimeLanguageLookup[131] = 'Latin'; + $QuicktimeLanguageLookup[132] = 'Quechua'; + $QuicktimeLanguageLookup[133] = 'Guarani'; + $QuicktimeLanguageLookup[134] = 'Aymara'; + $QuicktimeLanguageLookup[135] = 'Tatar'; + $QuicktimeLanguageLookup[136] = 'Uighur'; + $QuicktimeLanguageLookup[137] = 'Dzongkha'; + $QuicktimeLanguageLookup[138] = 'JavaneseRom'; + $QuicktimeLanguageLookup[32767] = 'Unspecified'; + } + if (($languageid > 138) && ($languageid < 32767)) { + /* + ISO Language Codes - http://www.loc.gov/standards/iso639-2/php/code_list.php + Because the language codes specified by ISO 639-2/T are three characters long, they must be packed to fit into a 16-bit field. + The packing algorithm must map each of the three characters, which are always lowercase, into a 5-bit integer and then concatenate + these integers into the least significant 15 bits of a 16-bit integer, leaving the 16-bit integer's most significant bit set to zero. + + One algorithm for performing this packing is to treat each ISO character as a 16-bit integer. Subtract 0x60 from the first character + and multiply by 2^10 (0x400), subtract 0x60 from the second character and multiply by 2^5 (0x20), subtract 0x60 from the third character, + and add the three 16-bit values. This will result in a single 16-bit value with the three codes correctly packed into the 15 least + significant bits and the most significant bit set to zero. + */ + $iso_language_id = ''; + $iso_language_id .= chr((($languageid & 0x7C00) >> 10) + 0x60); + $iso_language_id .= chr((($languageid & 0x03E0) >> 5) + 0x60); + $iso_language_id .= chr((($languageid & 0x001F) >> 0) + 0x60); + $QuicktimeLanguageLookup[$languageid] = getid3_id3v2::LanguageLookup($iso_language_id); + } + return (isset($QuicktimeLanguageLookup[$languageid]) ? $QuicktimeLanguageLookup[$languageid] : 'invalid'); + } + + /** + * @param string $codecid + * + * @return string + */ + public function QuicktimeVideoCodecLookup($codecid) { + static $QuicktimeVideoCodecLookup = array(); + if (empty($QuicktimeVideoCodecLookup)) { + $QuicktimeVideoCodecLookup['.SGI'] = 'SGI'; + $QuicktimeVideoCodecLookup['3IV1'] = '3ivx MPEG-4 v1'; + $QuicktimeVideoCodecLookup['3IV2'] = '3ivx MPEG-4 v2'; + $QuicktimeVideoCodecLookup['3IVX'] = '3ivx MPEG-4'; + $QuicktimeVideoCodecLookup['8BPS'] = 'Planar RGB'; + $QuicktimeVideoCodecLookup['avc1'] = 'H.264/MPEG-4 AVC'; + $QuicktimeVideoCodecLookup['avr '] = 'AVR-JPEG'; + $QuicktimeVideoCodecLookup['b16g'] = '16Gray'; + $QuicktimeVideoCodecLookup['b32a'] = '32AlphaGray'; + $QuicktimeVideoCodecLookup['b48r'] = '48RGB'; + $QuicktimeVideoCodecLookup['b64a'] = '64ARGB'; + $QuicktimeVideoCodecLookup['base'] = 'Base'; + $QuicktimeVideoCodecLookup['clou'] = 'Cloud'; + $QuicktimeVideoCodecLookup['cmyk'] = 'CMYK'; + $QuicktimeVideoCodecLookup['cvid'] = 'Cinepak'; + $QuicktimeVideoCodecLookup['dmb1'] = 'OpenDML JPEG'; + $QuicktimeVideoCodecLookup['dvc '] = 'DVC-NTSC'; + $QuicktimeVideoCodecLookup['dvcp'] = 'DVC-PAL'; + $QuicktimeVideoCodecLookup['dvpn'] = 'DVCPro-NTSC'; + $QuicktimeVideoCodecLookup['dvpp'] = 'DVCPro-PAL'; + $QuicktimeVideoCodecLookup['fire'] = 'Fire'; + $QuicktimeVideoCodecLookup['flic'] = 'FLC'; + $QuicktimeVideoCodecLookup['gif '] = 'GIF'; + $QuicktimeVideoCodecLookup['h261'] = 'H261'; + $QuicktimeVideoCodecLookup['h263'] = 'H263'; + $QuicktimeVideoCodecLookup['hvc1'] = 'H.265/HEVC'; + $QuicktimeVideoCodecLookup['IV41'] = 'Indeo4'; + $QuicktimeVideoCodecLookup['jpeg'] = 'JPEG'; + $QuicktimeVideoCodecLookup['kpcd'] = 'PhotoCD'; + $QuicktimeVideoCodecLookup['mjpa'] = 'Motion JPEG-A'; + $QuicktimeVideoCodecLookup['mjpb'] = 'Motion JPEG-B'; + $QuicktimeVideoCodecLookup['msvc'] = 'Microsoft Video1'; + $QuicktimeVideoCodecLookup['myuv'] = 'MPEG YUV420'; + $QuicktimeVideoCodecLookup['path'] = 'Vector'; + $QuicktimeVideoCodecLookup['png '] = 'PNG'; + $QuicktimeVideoCodecLookup['PNTG'] = 'MacPaint'; + $QuicktimeVideoCodecLookup['qdgx'] = 'QuickDrawGX'; + $QuicktimeVideoCodecLookup['qdrw'] = 'QuickDraw'; + $QuicktimeVideoCodecLookup['raw '] = 'RAW'; + $QuicktimeVideoCodecLookup['ripl'] = 'WaterRipple'; + $QuicktimeVideoCodecLookup['rpza'] = 'Video'; + $QuicktimeVideoCodecLookup['smc '] = 'Graphics'; + $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 1'; + $QuicktimeVideoCodecLookup['SVQ1'] = 'Sorenson Video 3'; + $QuicktimeVideoCodecLookup['syv9'] = 'Sorenson YUV9'; + $QuicktimeVideoCodecLookup['tga '] = 'Targa'; + $QuicktimeVideoCodecLookup['tiff'] = 'TIFF'; + $QuicktimeVideoCodecLookup['WRAW'] = 'Windows RAW'; + $QuicktimeVideoCodecLookup['WRLE'] = 'BMP'; + $QuicktimeVideoCodecLookup['y420'] = 'YUV420'; + $QuicktimeVideoCodecLookup['yuv2'] = 'ComponentVideo'; + $QuicktimeVideoCodecLookup['yuvs'] = 'ComponentVideoUnsigned'; + $QuicktimeVideoCodecLookup['yuvu'] = 'ComponentVideoSigned'; + } + return (isset($QuicktimeVideoCodecLookup[$codecid]) ? $QuicktimeVideoCodecLookup[$codecid] : ''); + } + + /** + * @param string $codecid + * + * @return mixed|string + */ + public function QuicktimeAudioCodecLookup($codecid) { + static $QuicktimeAudioCodecLookup = array(); + if (empty($QuicktimeAudioCodecLookup)) { + $QuicktimeAudioCodecLookup['.mp3'] = 'Fraunhofer MPEG Layer-III alias'; + $QuicktimeAudioCodecLookup['aac '] = 'ISO/IEC 14496-3 AAC'; + $QuicktimeAudioCodecLookup['agsm'] = 'Apple GSM 10:1'; + $QuicktimeAudioCodecLookup['alac'] = 'Apple Lossless Audio Codec'; + $QuicktimeAudioCodecLookup['alaw'] = 'A-law 2:1'; + $QuicktimeAudioCodecLookup['conv'] = 'Sample Format'; + $QuicktimeAudioCodecLookup['dvca'] = 'DV'; + $QuicktimeAudioCodecLookup['dvi '] = 'DV 4:1'; + $QuicktimeAudioCodecLookup['eqal'] = 'Frequency Equalizer'; + $QuicktimeAudioCodecLookup['fl32'] = '32-bit Floating Point'; + $QuicktimeAudioCodecLookup['fl64'] = '64-bit Floating Point'; + $QuicktimeAudioCodecLookup['ima4'] = 'Interactive Multimedia Association 4:1'; + $QuicktimeAudioCodecLookup['in24'] = '24-bit Integer'; + $QuicktimeAudioCodecLookup['in32'] = '32-bit Integer'; + $QuicktimeAudioCodecLookup['lpc '] = 'LPC 23:1'; + $QuicktimeAudioCodecLookup['MAC3'] = 'Macintosh Audio Compression/Expansion (MACE) 3:1'; + $QuicktimeAudioCodecLookup['MAC6'] = 'Macintosh Audio Compression/Expansion (MACE) 6:1'; + $QuicktimeAudioCodecLookup['mixb'] = '8-bit Mixer'; + $QuicktimeAudioCodecLookup['mixw'] = '16-bit Mixer'; + $QuicktimeAudioCodecLookup['mp4a'] = 'ISO/IEC 14496-3 AAC'; + $QuicktimeAudioCodecLookup['MS'."\x00\x02"] = 'Microsoft ADPCM'; + $QuicktimeAudioCodecLookup['MS'."\x00\x11"] = 'DV IMA'; + $QuicktimeAudioCodecLookup['MS'."\x00\x55"] = 'Fraunhofer MPEG Layer III'; + $QuicktimeAudioCodecLookup['NONE'] = 'No Encoding'; + $QuicktimeAudioCodecLookup['Qclp'] = 'Qualcomm PureVoice'; + $QuicktimeAudioCodecLookup['QDM2'] = 'QDesign Music 2'; + $QuicktimeAudioCodecLookup['QDMC'] = 'QDesign Music 1'; + $QuicktimeAudioCodecLookup['ratb'] = '8-bit Rate'; + $QuicktimeAudioCodecLookup['ratw'] = '16-bit Rate'; + $QuicktimeAudioCodecLookup['raw '] = 'raw PCM'; + $QuicktimeAudioCodecLookup['sour'] = 'Sound Source'; + $QuicktimeAudioCodecLookup['sowt'] = 'signed/two\'s complement (Little Endian)'; + $QuicktimeAudioCodecLookup['str1'] = 'Iomega MPEG layer II'; + $QuicktimeAudioCodecLookup['str2'] = 'Iomega MPEG *layer II'; + $QuicktimeAudioCodecLookup['str3'] = 'Iomega MPEG **layer II'; + $QuicktimeAudioCodecLookup['str4'] = 'Iomega MPEG ***layer II'; + $QuicktimeAudioCodecLookup['twos'] = 'signed/two\'s complement (Big Endian)'; + $QuicktimeAudioCodecLookup['ulaw'] = 'mu-law 2:1'; + } + return (isset($QuicktimeAudioCodecLookup[$codecid]) ? $QuicktimeAudioCodecLookup[$codecid] : ''); + } + + /** + * @param string $compressionid + * + * @return string + */ + public function QuicktimeDCOMLookup($compressionid) { + static $QuicktimeDCOMLookup = array(); + if (empty($QuicktimeDCOMLookup)) { + $QuicktimeDCOMLookup['zlib'] = 'ZLib Deflate'; + $QuicktimeDCOMLookup['adec'] = 'Apple Compression'; + } + return (isset($QuicktimeDCOMLookup[$compressionid]) ? $QuicktimeDCOMLookup[$compressionid] : ''); + } + + /** + * @param int $colordepthid + * + * @return string + */ + public function QuicktimeColorNameLookup($colordepthid) { + static $QuicktimeColorNameLookup = array(); + if (empty($QuicktimeColorNameLookup)) { + $QuicktimeColorNameLookup[1] = '2-color (monochrome)'; + $QuicktimeColorNameLookup[2] = '4-color'; + $QuicktimeColorNameLookup[4] = '16-color'; + $QuicktimeColorNameLookup[8] = '256-color'; + $QuicktimeColorNameLookup[16] = 'thousands (16-bit color)'; + $QuicktimeColorNameLookup[24] = 'millions (24-bit color)'; + $QuicktimeColorNameLookup[32] = 'millions+ (32-bit color)'; + $QuicktimeColorNameLookup[33] = 'black & white'; + $QuicktimeColorNameLookup[34] = '4-gray'; + $QuicktimeColorNameLookup[36] = '16-gray'; + $QuicktimeColorNameLookup[40] = '256-gray'; + } + return (isset($QuicktimeColorNameLookup[$colordepthid]) ? $QuicktimeColorNameLookup[$colordepthid] : 'invalid'); + } + + /** + * @param int $stik + * + * @return string + */ + public function QuicktimeSTIKLookup($stik) { + static $QuicktimeSTIKLookup = array(); + if (empty($QuicktimeSTIKLookup)) { + $QuicktimeSTIKLookup[0] = 'Movie'; + $QuicktimeSTIKLookup[1] = 'Normal'; + $QuicktimeSTIKLookup[2] = 'Audiobook'; + $QuicktimeSTIKLookup[5] = 'Whacked Bookmark'; + $QuicktimeSTIKLookup[6] = 'Music Video'; + $QuicktimeSTIKLookup[9] = 'Short Film'; + $QuicktimeSTIKLookup[10] = 'TV Show'; + $QuicktimeSTIKLookup[11] = 'Booklet'; + $QuicktimeSTIKLookup[14] = 'Ringtone'; + $QuicktimeSTIKLookup[21] = 'Podcast'; + } + return (isset($QuicktimeSTIKLookup[$stik]) ? $QuicktimeSTIKLookup[$stik] : 'invalid'); + } + + /** + * @param int $audio_profile_id + * + * @return string + */ + public function QuicktimeIODSaudioProfileName($audio_profile_id) { + static $QuicktimeIODSaudioProfileNameLookup = array(); + if (empty($QuicktimeIODSaudioProfileNameLookup)) { + $QuicktimeIODSaudioProfileNameLookup = array( + 0x00 => 'ISO Reserved (0x00)', + 0x01 => 'Main Audio Profile @ Level 1', + 0x02 => 'Main Audio Profile @ Level 2', + 0x03 => 'Main Audio Profile @ Level 3', + 0x04 => 'Main Audio Profile @ Level 4', + 0x05 => 'Scalable Audio Profile @ Level 1', + 0x06 => 'Scalable Audio Profile @ Level 2', + 0x07 => 'Scalable Audio Profile @ Level 3', + 0x08 => 'Scalable Audio Profile @ Level 4', + 0x09 => 'Speech Audio Profile @ Level 1', + 0x0A => 'Speech Audio Profile @ Level 2', + 0x0B => 'Synthetic Audio Profile @ Level 1', + 0x0C => 'Synthetic Audio Profile @ Level 2', + 0x0D => 'Synthetic Audio Profile @ Level 3', + 0x0E => 'High Quality Audio Profile @ Level 1', + 0x0F => 'High Quality Audio Profile @ Level 2', + 0x10 => 'High Quality Audio Profile @ Level 3', + 0x11 => 'High Quality Audio Profile @ Level 4', + 0x12 => 'High Quality Audio Profile @ Level 5', + 0x13 => 'High Quality Audio Profile @ Level 6', + 0x14 => 'High Quality Audio Profile @ Level 7', + 0x15 => 'High Quality Audio Profile @ Level 8', + 0x16 => 'Low Delay Audio Profile @ Level 1', + 0x17 => 'Low Delay Audio Profile @ Level 2', + 0x18 => 'Low Delay Audio Profile @ Level 3', + 0x19 => 'Low Delay Audio Profile @ Level 4', + 0x1A => 'Low Delay Audio Profile @ Level 5', + 0x1B => 'Low Delay Audio Profile @ Level 6', + 0x1C => 'Low Delay Audio Profile @ Level 7', + 0x1D => 'Low Delay Audio Profile @ Level 8', + 0x1E => 'Natural Audio Profile @ Level 1', + 0x1F => 'Natural Audio Profile @ Level 2', + 0x20 => 'Natural Audio Profile @ Level 3', + 0x21 => 'Natural Audio Profile @ Level 4', + 0x22 => 'Mobile Audio Internetworking Profile @ Level 1', + 0x23 => 'Mobile Audio Internetworking Profile @ Level 2', + 0x24 => 'Mobile Audio Internetworking Profile @ Level 3', + 0x25 => 'Mobile Audio Internetworking Profile @ Level 4', + 0x26 => 'Mobile Audio Internetworking Profile @ Level 5', + 0x27 => 'Mobile Audio Internetworking Profile @ Level 6', + 0x28 => 'AAC Profile @ Level 1', + 0x29 => 'AAC Profile @ Level 2', + 0x2A => 'AAC Profile @ Level 4', + 0x2B => 'AAC Profile @ Level 5', + 0x2C => 'High Efficiency AAC Profile @ Level 2', + 0x2D => 'High Efficiency AAC Profile @ Level 3', + 0x2E => 'High Efficiency AAC Profile @ Level 4', + 0x2F => 'High Efficiency AAC Profile @ Level 5', + 0xFE => 'Not part of MPEG-4 audio profiles', + 0xFF => 'No audio capability required', + ); + } + return (isset($QuicktimeIODSaudioProfileNameLookup[$audio_profile_id]) ? $QuicktimeIODSaudioProfileNameLookup[$audio_profile_id] : 'ISO Reserved / User Private'); + } + + /** + * @param int $video_profile_id + * + * @return string + */ + public function QuicktimeIODSvideoProfileName($video_profile_id) { + static $QuicktimeIODSvideoProfileNameLookup = array(); + if (empty($QuicktimeIODSvideoProfileNameLookup)) { + $QuicktimeIODSvideoProfileNameLookup = array( + 0x00 => 'Reserved (0x00) Profile', + 0x01 => 'Simple Profile @ Level 1', + 0x02 => 'Simple Profile @ Level 2', + 0x03 => 'Simple Profile @ Level 3', + 0x08 => 'Simple Profile @ Level 0', + 0x10 => 'Simple Scalable Profile @ Level 0', + 0x11 => 'Simple Scalable Profile @ Level 1', + 0x12 => 'Simple Scalable Profile @ Level 2', + 0x15 => 'AVC/H264 Profile', + 0x21 => 'Core Profile @ Level 1', + 0x22 => 'Core Profile @ Level 2', + 0x32 => 'Main Profile @ Level 2', + 0x33 => 'Main Profile @ Level 3', + 0x34 => 'Main Profile @ Level 4', + 0x42 => 'N-bit Profile @ Level 2', + 0x51 => 'Scalable Texture Profile @ Level 1', + 0x61 => 'Simple Face Animation Profile @ Level 1', + 0x62 => 'Simple Face Animation Profile @ Level 2', + 0x63 => 'Simple FBA Profile @ Level 1', + 0x64 => 'Simple FBA Profile @ Level 2', + 0x71 => 'Basic Animated Texture Profile @ Level 1', + 0x72 => 'Basic Animated Texture Profile @ Level 2', + 0x81 => 'Hybrid Profile @ Level 1', + 0x82 => 'Hybrid Profile @ Level 2', + 0x91 => 'Advanced Real Time Simple Profile @ Level 1', + 0x92 => 'Advanced Real Time Simple Profile @ Level 2', + 0x93 => 'Advanced Real Time Simple Profile @ Level 3', + 0x94 => 'Advanced Real Time Simple Profile @ Level 4', + 0xA1 => 'Core Scalable Profile @ Level1', + 0xA2 => 'Core Scalable Profile @ Level2', + 0xA3 => 'Core Scalable Profile @ Level3', + 0xB1 => 'Advanced Coding Efficiency Profile @ Level 1', + 0xB2 => 'Advanced Coding Efficiency Profile @ Level 2', + 0xB3 => 'Advanced Coding Efficiency Profile @ Level 3', + 0xB4 => 'Advanced Coding Efficiency Profile @ Level 4', + 0xC1 => 'Advanced Core Profile @ Level 1', + 0xC2 => 'Advanced Core Profile @ Level 2', + 0xD1 => 'Advanced Scalable Texture @ Level1', + 0xD2 => 'Advanced Scalable Texture @ Level2', + 0xE1 => 'Simple Studio Profile @ Level 1', + 0xE2 => 'Simple Studio Profile @ Level 2', + 0xE3 => 'Simple Studio Profile @ Level 3', + 0xE4 => 'Simple Studio Profile @ Level 4', + 0xE5 => 'Core Studio Profile @ Level 1', + 0xE6 => 'Core Studio Profile @ Level 2', + 0xE7 => 'Core Studio Profile @ Level 3', + 0xE8 => 'Core Studio Profile @ Level 4', + 0xF0 => 'Advanced Simple Profile @ Level 0', + 0xF1 => 'Advanced Simple Profile @ Level 1', + 0xF2 => 'Advanced Simple Profile @ Level 2', + 0xF3 => 'Advanced Simple Profile @ Level 3', + 0xF4 => 'Advanced Simple Profile @ Level 4', + 0xF5 => 'Advanced Simple Profile @ Level 5', + 0xF7 => 'Advanced Simple Profile @ Level 3b', + 0xF8 => 'Fine Granularity Scalable Profile @ Level 0', + 0xF9 => 'Fine Granularity Scalable Profile @ Level 1', + 0xFA => 'Fine Granularity Scalable Profile @ Level 2', + 0xFB => 'Fine Granularity Scalable Profile @ Level 3', + 0xFC => 'Fine Granularity Scalable Profile @ Level 4', + 0xFD => 'Fine Granularity Scalable Profile @ Level 5', + 0xFE => 'Not part of MPEG-4 Visual profiles', + 0xFF => 'No visual capability required', + ); + } + return (isset($QuicktimeIODSvideoProfileNameLookup[$video_profile_id]) ? $QuicktimeIODSvideoProfileNameLookup[$video_profile_id] : 'ISO Reserved Profile'); + } + + /** + * @param int $rtng + * + * @return string + */ + public function QuicktimeContentRatingLookup($rtng) { + static $QuicktimeContentRatingLookup = array(); + if (empty($QuicktimeContentRatingLookup)) { + $QuicktimeContentRatingLookup[0] = 'None'; + $QuicktimeContentRatingLookup[1] = 'Explicit'; + $QuicktimeContentRatingLookup[2] = 'Clean'; + $QuicktimeContentRatingLookup[4] = 'Explicit (old)'; + } + return (isset($QuicktimeContentRatingLookup[$rtng]) ? $QuicktimeContentRatingLookup[$rtng] : 'invalid'); + } + + /** + * @param int $akid + * + * @return string + */ + public function QuicktimeStoreAccountTypeLookup($akid) { + static $QuicktimeStoreAccountTypeLookup = array(); + if (empty($QuicktimeStoreAccountTypeLookup)) { + $QuicktimeStoreAccountTypeLookup[0] = 'iTunes'; + $QuicktimeStoreAccountTypeLookup[1] = 'AOL'; + } + return (isset($QuicktimeStoreAccountTypeLookup[$akid]) ? $QuicktimeStoreAccountTypeLookup[$akid] : 'invalid'); + } + + /** + * @param int $sfid + * + * @return string + */ + public function QuicktimeStoreFrontCodeLookup($sfid) { + static $QuicktimeStoreFrontCodeLookup = array(); + if (empty($QuicktimeStoreFrontCodeLookup)) { + $QuicktimeStoreFrontCodeLookup[143460] = 'Australia'; + $QuicktimeStoreFrontCodeLookup[143445] = 'Austria'; + $QuicktimeStoreFrontCodeLookup[143446] = 'Belgium'; + $QuicktimeStoreFrontCodeLookup[143455] = 'Canada'; + $QuicktimeStoreFrontCodeLookup[143458] = 'Denmark'; + $QuicktimeStoreFrontCodeLookup[143447] = 'Finland'; + $QuicktimeStoreFrontCodeLookup[143442] = 'France'; + $QuicktimeStoreFrontCodeLookup[143443] = 'Germany'; + $QuicktimeStoreFrontCodeLookup[143448] = 'Greece'; + $QuicktimeStoreFrontCodeLookup[143449] = 'Ireland'; + $QuicktimeStoreFrontCodeLookup[143450] = 'Italy'; + $QuicktimeStoreFrontCodeLookup[143462] = 'Japan'; + $QuicktimeStoreFrontCodeLookup[143451] = 'Luxembourg'; + $QuicktimeStoreFrontCodeLookup[143452] = 'Netherlands'; + $QuicktimeStoreFrontCodeLookup[143461] = 'New Zealand'; + $QuicktimeStoreFrontCodeLookup[143457] = 'Norway'; + $QuicktimeStoreFrontCodeLookup[143453] = 'Portugal'; + $QuicktimeStoreFrontCodeLookup[143454] = 'Spain'; + $QuicktimeStoreFrontCodeLookup[143456] = 'Sweden'; + $QuicktimeStoreFrontCodeLookup[143459] = 'Switzerland'; + $QuicktimeStoreFrontCodeLookup[143444] = 'United Kingdom'; + $QuicktimeStoreFrontCodeLookup[143441] = 'United States'; + } + return (isset($QuicktimeStoreFrontCodeLookup[$sfid]) ? $QuicktimeStoreFrontCodeLookup[$sfid] : 'invalid'); + } + + /** + * @param string $keyname + * @param string|array $data + * @param string $boxname + * + * @return bool + */ + public function CopyToAppropriateCommentsSection($keyname, $data, $boxname='') { + static $handyatomtranslatorarray = array(); + if (empty($handyatomtranslatorarray)) { + // http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt + // http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt + // http://atomicparsley.sourceforge.net/mpeg-4files.html + // https://code.google.com/p/mp4v2/wiki/iTunesMetadata + $handyatomtranslatorarray["\xA9".'alb'] = 'album'; // iTunes 4.0 + $handyatomtranslatorarray["\xA9".'ART'] = 'artist'; + $handyatomtranslatorarray["\xA9".'art'] = 'artist'; // iTunes 4.0 + $handyatomtranslatorarray["\xA9".'aut'] = 'author'; + $handyatomtranslatorarray["\xA9".'cmt'] = 'comment'; // iTunes 4.0 + $handyatomtranslatorarray["\xA9".'com'] = 'comment'; + $handyatomtranslatorarray["\xA9".'cpy'] = 'copyright'; + $handyatomtranslatorarray["\xA9".'day'] = 'creation_date'; // iTunes 4.0 + $handyatomtranslatorarray["\xA9".'dir'] = 'director'; + $handyatomtranslatorarray["\xA9".'ed1'] = 'edit1'; + $handyatomtranslatorarray["\xA9".'ed2'] = 'edit2'; + $handyatomtranslatorarray["\xA9".'ed3'] = 'edit3'; + $handyatomtranslatorarray["\xA9".'ed4'] = 'edit4'; + $handyatomtranslatorarray["\xA9".'ed5'] = 'edit5'; + $handyatomtranslatorarray["\xA9".'ed6'] = 'edit6'; + $handyatomtranslatorarray["\xA9".'ed7'] = 'edit7'; + $handyatomtranslatorarray["\xA9".'ed8'] = 'edit8'; + $handyatomtranslatorarray["\xA9".'ed9'] = 'edit9'; + $handyatomtranslatorarray["\xA9".'enc'] = 'encoded_by'; + $handyatomtranslatorarray["\xA9".'fmt'] = 'format'; + $handyatomtranslatorarray["\xA9".'gen'] = 'genre'; // iTunes 4.0 + $handyatomtranslatorarray["\xA9".'grp'] = 'grouping'; // iTunes 4.2 + $handyatomtranslatorarray["\xA9".'hst'] = 'host_computer'; + $handyatomtranslatorarray["\xA9".'inf'] = 'information'; + $handyatomtranslatorarray["\xA9".'lyr'] = 'lyrics'; // iTunes 5.0 + $handyatomtranslatorarray["\xA9".'mak'] = 'make'; + $handyatomtranslatorarray["\xA9".'mod'] = 'model'; + $handyatomtranslatorarray["\xA9".'nam'] = 'title'; // iTunes 4.0 + $handyatomtranslatorarray["\xA9".'ope'] = 'composer'; + $handyatomtranslatorarray["\xA9".'prd'] = 'producer'; + $handyatomtranslatorarray["\xA9".'PRD'] = 'product'; + $handyatomtranslatorarray["\xA9".'prf'] = 'performers'; + $handyatomtranslatorarray["\xA9".'req'] = 'system_requirements'; + $handyatomtranslatorarray["\xA9".'src'] = 'source_credit'; + $handyatomtranslatorarray["\xA9".'swr'] = 'software'; + $handyatomtranslatorarray["\xA9".'too'] = 'encoding_tool'; // iTunes 4.0 + $handyatomtranslatorarray["\xA9".'trk'] = 'track_number'; + $handyatomtranslatorarray["\xA9".'url'] = 'url'; + $handyatomtranslatorarray["\xA9".'wrn'] = 'warning'; + $handyatomtranslatorarray["\xA9".'wrt'] = 'composer'; + $handyatomtranslatorarray['aART'] = 'album_artist'; + $handyatomtranslatorarray['apID'] = 'purchase_account'; + $handyatomtranslatorarray['catg'] = 'category'; // iTunes 4.9 + $handyatomtranslatorarray['covr'] = 'picture'; // iTunes 4.0 + $handyatomtranslatorarray['cpil'] = 'compilation'; // iTunes 4.0 + $handyatomtranslatorarray['cprt'] = 'copyright'; // iTunes 4.0? + $handyatomtranslatorarray['desc'] = 'description'; // iTunes 5.0 + $handyatomtranslatorarray['disk'] = 'disc_number'; // iTunes 4.0 + $handyatomtranslatorarray['egid'] = 'episode_guid'; // iTunes 4.9 + $handyatomtranslatorarray['gnre'] = 'genre'; // iTunes 4.0 + $handyatomtranslatorarray['hdvd'] = 'hd_video'; // iTunes 4.0 + $handyatomtranslatorarray['ldes'] = 'description_long'; // + $handyatomtranslatorarray['keyw'] = 'keyword'; // iTunes 4.9 + $handyatomtranslatorarray['pcst'] = 'podcast'; // iTunes 4.9 + $handyatomtranslatorarray['pgap'] = 'gapless_playback'; // iTunes 7.0 + $handyatomtranslatorarray['purd'] = 'purchase_date'; // iTunes 6.0.2 + $handyatomtranslatorarray['purl'] = 'podcast_url'; // iTunes 4.9 + $handyatomtranslatorarray['rtng'] = 'rating'; // iTunes 4.0 + $handyatomtranslatorarray['soaa'] = 'sort_album_artist'; // + $handyatomtranslatorarray['soal'] = 'sort_album'; // + $handyatomtranslatorarray['soar'] = 'sort_artist'; // + $handyatomtranslatorarray['soco'] = 'sort_composer'; // + $handyatomtranslatorarray['sonm'] = 'sort_title'; // + $handyatomtranslatorarray['sosn'] = 'sort_show'; // + $handyatomtranslatorarray['stik'] = 'stik'; // iTunes 4.9 + $handyatomtranslatorarray['tmpo'] = 'bpm'; // iTunes 4.0 + $handyatomtranslatorarray['trkn'] = 'track_number'; // iTunes 4.0 + $handyatomtranslatorarray['tven'] = 'tv_episode_id'; // + $handyatomtranslatorarray['tves'] = 'tv_episode'; // iTunes 6.0 + $handyatomtranslatorarray['tvnn'] = 'tv_network_name'; // iTunes 6.0 + $handyatomtranslatorarray['tvsh'] = 'tv_show_name'; // iTunes 6.0 + $handyatomtranslatorarray['tvsn'] = 'tv_season'; // iTunes 6.0 + + // boxnames: + /* + $handyatomtranslatorarray['iTunSMPB'] = 'iTunSMPB'; + $handyatomtranslatorarray['iTunNORM'] = 'iTunNORM'; + $handyatomtranslatorarray['Encoding Params'] = 'Encoding Params'; + $handyatomtranslatorarray['replaygain_track_gain'] = 'replaygain_track_gain'; + $handyatomtranslatorarray['replaygain_track_peak'] = 'replaygain_track_peak'; + $handyatomtranslatorarray['replaygain_track_minmax'] = 'replaygain_track_minmax'; + $handyatomtranslatorarray['MusicIP PUID'] = 'MusicIP PUID'; + $handyatomtranslatorarray['MusicBrainz Artist Id'] = 'MusicBrainz Artist Id'; + $handyatomtranslatorarray['MusicBrainz Album Id'] = 'MusicBrainz Album Id'; + $handyatomtranslatorarray['MusicBrainz Album Artist Id'] = 'MusicBrainz Album Artist Id'; + $handyatomtranslatorarray['MusicBrainz Track Id'] = 'MusicBrainz Track Id'; + $handyatomtranslatorarray['MusicBrainz Disc Id'] = 'MusicBrainz Disc Id'; + + // http://age.hobba.nl/audio/tag_frame_reference.html + $handyatomtranslatorarray['PLAY_COUNTER'] = 'play_counter'; // Foobar2000 - https://www.getid3.org/phpBB3/viewtopic.php?t=1355 + $handyatomtranslatorarray['MEDIATYPE'] = 'mediatype'; // Foobar2000 - https://www.getid3.org/phpBB3/viewtopic.php?t=1355 + */ + } + $info = &$this->getid3->info; + $comment_key = ''; + if ($boxname && ($boxname != $keyname)) { + $comment_key = (isset($handyatomtranslatorarray[$boxname]) ? $handyatomtranslatorarray[$boxname] : $boxname); + } elseif (isset($handyatomtranslatorarray[$keyname])) { + $comment_key = $handyatomtranslatorarray[$keyname]; + } + if ($comment_key) { + if ($comment_key == 'picture') { + // already copied directly into [comments][picture] elsewhere, do not re-copy here + return true; + } + $gooddata = array($data); + if ($comment_key == 'genre') { + // some other taggers separate multiple genres with semicolon, e.g. "Heavy Metal;Thrash Metal;Metal" + $gooddata = explode(';', $data); + } + foreach ($gooddata as $data) { + if (!empty($info['quicktime']['comments'][$comment_key]) && in_array($data, $info['quicktime']['comments'][$comment_key], true)) { + // avoid duplicate copies of identical data + continue; + } + $info['quicktime']['comments'][$comment_key][] = $data; + } + } + return true; + } + + /** + * @param string $lstring + * @param int $count + * + * @return string + */ + public function LociString($lstring, &$count) { + // Loci strings are UTF-8 or UTF-16 and null (x00/x0000) terminated. UTF-16 has a BOM + // Also need to return the number of bytes the string occupied so additional fields can be extracted + $len = strlen($lstring); + if ($len == 0) { + $count = 0; + return ''; + } + if ($lstring[0] == "\x00") { + $count = 1; + return ''; + } + // check for BOM + if (($len > 2) && ((($lstring[0] == "\xFE") && ($lstring[1] == "\xFF")) || (($lstring[0] == "\xFF") && ($lstring[1] == "\xFE")))) { + // UTF-16 + if (preg_match('/(.*)\x00/', $lstring, $lmatches)) { + $count = strlen($lmatches[1]) * 2 + 2; //account for 2 byte characters and trailing \x0000 + return getid3_lib::iconv_fallback_utf16_utf8($lmatches[1]); + } else { + return ''; + } + } + // UTF-8 + if (preg_match('/(.*)\x00/', $lstring, $lmatches)) { + $count = strlen($lmatches[1]) + 1; //account for trailing \x00 + return $lmatches[1]; + } + return ''; + } + + /** + * @param string $nullterminatedstring + * + * @return string + */ + public function NoNullString($nullterminatedstring) { + // remove the single null terminator on null terminated strings + if (substr($nullterminatedstring, strlen($nullterminatedstring) - 1, 1) === "\x00") { + return substr($nullterminatedstring, 0, strlen($nullterminatedstring) - 1); + } + return $nullterminatedstring; + } + + /** + * @param string $pascalstring + * + * @return string + */ + public function Pascal2String($pascalstring) { + // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string + return substr($pascalstring, 1); + } + + /** + * @param string $pascalstring + * + * @return string + */ + public function MaybePascal2String($pascalstring) { + // Pascal strings have 1 unsigned byte at the beginning saying how many chars (1-255) are in the string + // Check if string actually is in this format or written incorrectly, straight string, or null-terminated string + if (ord(substr($pascalstring, 0, 1)) == (strlen($pascalstring) - 1)) { + return substr($pascalstring, 1); + } elseif (substr($pascalstring, -1, 1) == "\x00") { + // appears to be null-terminated instead of Pascal-style + return substr($pascalstring, 0, -1); + } + return $pascalstring; + } + + + /** + * Helper functions for m4b audiobook chapters + * code by Steffen Hartmann 2015-Nov-08. + * + * @param array $info + * @param string $tag + * @param string $history + * @param array $result + */ + public function search_tag_by_key($info, $tag, $history, &$result) { + foreach ($info as $key => $value) { + $key_history = $history.'/'.$key; + if ($key === $tag) { + $result[] = array($key_history, $info); + } else { + if (is_array($value)) { + $this->search_tag_by_key($value, $tag, $key_history, $result); + } + } + } + } + + /** + * @param array $info + * @param string $k + * @param string $v + * @param string $history + * @param array $result + */ + public function search_tag_by_pair($info, $k, $v, $history, &$result) { + foreach ($info as $key => $value) { + $key_history = $history.'/'.$key; + if (($key === $k) && ($value === $v)) { + $result[] = array($key_history, $info); + } else { + if (is_array($value)) { + $this->search_tag_by_pair($value, $k, $v, $key_history, $result); + } + } + } + } + + /** + * @param array $info + * + * @return array + */ + public function quicktime_time_to_sample_table($info) { + $res = array(); + $this->search_tag_by_pair($info['quicktime']['moov'], 'name', 'stbl', 'quicktime/moov', $res); + foreach ($res as $value) { + $stbl_res = array(); + $this->search_tag_by_pair($value[1], 'data_format', 'text', $value[0], $stbl_res); + if (count($stbl_res) > 0) { + $stts_res = array(); + $this->search_tag_by_key($value[1], 'time_to_sample_table', $value[0], $stts_res); + if (count($stts_res) > 0) { + return $stts_res[0][1]['time_to_sample_table']; + } + } + } + return array(); + } + + /** + * @param array $info + * + * @return int + */ + public function quicktime_bookmark_time_scale($info) { + $time_scale = ''; + $ts_prefix_len = 0; + $res = array(); + $this->search_tag_by_pair($info['quicktime']['moov'], 'name', 'stbl', 'quicktime/moov', $res); + foreach ($res as $value) { + $stbl_res = array(); + $this->search_tag_by_pair($value[1], 'data_format', 'text', $value[0], $stbl_res); + if (count($stbl_res) > 0) { + $ts_res = array(); + $this->search_tag_by_key($info['quicktime']['moov'], 'time_scale', 'quicktime/moov', $ts_res); + foreach ($ts_res as $sub_value) { + $prefix = substr($sub_value[0], 0, -12); + if ((substr($stbl_res[0][0], 0, strlen($prefix)) === $prefix) && ($ts_prefix_len < strlen($prefix))) { + $time_scale = $sub_value[1]['time_scale']; + $ts_prefix_len = strlen($prefix); + } + } + } + } + return $time_scale; + } + /* + // END helper functions for m4b audiobook chapters + */ + + +} diff --git a/serendipity_event_podcast/player/getid3/module.audio-video.real.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.real.php similarity index 78% rename from serendipity_event_podcast/player/getid3/module.audio-video.real.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.real.php index b2c90e74..9b6762d7 100644 --- a/serendipity_event_podcast/player/getid3/module.audio-video.real.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.real.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.audio-video.real.php // @@ -13,69 +14,76 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); -class getid3_real +class getid3_real extends getid3_handler { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_real(&$fd, &$ThisFileInfo) { - $ThisFileInfo['fileformat'] = 'real'; - $ThisFileInfo['bitrate'] = 0; - $ThisFileInfo['playtime_seconds'] = 0; + $info['fileformat'] = 'real'; + $info['bitrate'] = 0; + $info['playtime_seconds'] = 0; - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); + $this->fseek($info['avdataoffset']); $ChunkCounter = 0; - while (ftell($fd) < $ThisFileInfo['avdataend']) { - $ChunkData = fread($fd, 8); + while ($this->ftell() < $info['avdataend']) { + $ChunkData = $this->fread(8); $ChunkName = substr($ChunkData, 0, 4); $ChunkSize = getid3_lib::BigEndian2Int(substr($ChunkData, 4, 4)); if ($ChunkName == '.ra'."\xFD") { - $ChunkData .= fread($fd, $ChunkSize - 8); - if ($this->ParseOldRAheader(substr($ChunkData, 0, 128), $ThisFileInfo['real']['old_ra_header'])) { - $ThisFileInfo['audio']['dataformat'] = 'real'; - $ThisFileInfo['audio']['lossless'] = false; - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['real']['old_ra_header']['sample_rate']; - $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['real']['old_ra_header']['bits_per_sample']; - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['real']['old_ra_header']['channels']; + $ChunkData .= $this->fread($ChunkSize - 8); + if ($this->ParseOldRAheader(substr($ChunkData, 0, 128), $info['real']['old_ra_header'])) { + $info['audio']['dataformat'] = 'real'; + $info['audio']['lossless'] = false; + $info['audio']['sample_rate'] = $info['real']['old_ra_header']['sample_rate']; + $info['audio']['bits_per_sample'] = $info['real']['old_ra_header']['bits_per_sample']; + $info['audio']['channels'] = $info['real']['old_ra_header']['channels']; - $ThisFileInfo['playtime_seconds'] = 60 * ($ThisFileInfo['real']['old_ra_header']['audio_bytes'] / $ThisFileInfo['real']['old_ra_header']['bytes_per_minute']); - $ThisFileInfo['audio']['bitrate'] = 8 * ($ThisFileInfo['real']['old_ra_header']['audio_bytes'] / $ThisFileInfo['playtime_seconds']); - $ThisFileInfo['audio']['codec'] = $this->RealAudioCodecFourCClookup($ThisFileInfo['real']['old_ra_header']['fourcc'], $ThisFileInfo['audio']['bitrate']); + $info['playtime_seconds'] = 60 * ($info['real']['old_ra_header']['audio_bytes'] / $info['real']['old_ra_header']['bytes_per_minute']); + $info['audio']['bitrate'] = 8 * ($info['real']['old_ra_header']['audio_bytes'] / $info['playtime_seconds']); + $info['audio']['codec'] = $this->RealAudioCodecFourCClookup($info['real']['old_ra_header']['fourcc'], $info['audio']['bitrate']); - foreach ($ThisFileInfo['real']['old_ra_header']['comments'] as $key => $valuearray) { + foreach ($info['real']['old_ra_header']['comments'] as $key => $valuearray) { if (strlen(trim($valuearray[0])) > 0) { - $ThisFileInfo['real']['comments'][$key][] = trim($valuearray[0]); + $info['real']['comments'][$key][] = trim($valuearray[0]); } } return true; } - $ThisFileInfo['error'][] = 'There was a problem parsing this RealAudio file. Please submit it for analysis to info@getid3.org'; - unset($ThisFileInfo['bitrate']); - unset($ThisFileInfo['playtime_seconds']); + $this->error('There was a problem parsing this RealAudio file. Please submit it for analysis to info@getid3.org'); + unset($info['bitrate']); + unset($info['playtime_seconds']); return false; } // shortcut - $ThisFileInfo['real']['chunks'][$ChunkCounter] = array(); - $thisfile_real_chunks_currentchunk = &$ThisFileInfo['real']['chunks'][$ChunkCounter]; + $info['real']['chunks'][$ChunkCounter] = array(); + $thisfile_real_chunks_currentchunk = &$info['real']['chunks'][$ChunkCounter]; $thisfile_real_chunks_currentchunk['name'] = $ChunkName; - $thisfile_real_chunks_currentchunk['offset'] = ftell($fd) - 8; + $thisfile_real_chunks_currentchunk['offset'] = $this->ftell() - 8; $thisfile_real_chunks_currentchunk['length'] = $ChunkSize; - if (($thisfile_real_chunks_currentchunk['offset'] + $thisfile_real_chunks_currentchunk['length']) > $ThisFileInfo['avdataend']) { - $ThisFileInfo['warning'][] = 'Chunk "'.$thisfile_real_chunks_currentchunk['name'].'" at offset '.$thisfile_real_chunks_currentchunk['offset'].' claims to be '.$thisfile_real_chunks_currentchunk['length'].' bytes long, which is beyond end of file'; + if (($thisfile_real_chunks_currentchunk['offset'] + $thisfile_real_chunks_currentchunk['length']) > $info['avdataend']) { + $this->warning('Chunk "'.$thisfile_real_chunks_currentchunk['name'].'" at offset '.$thisfile_real_chunks_currentchunk['offset'].' claims to be '.$thisfile_real_chunks_currentchunk['length'].' bytes long, which is beyond end of file'); return false; } - if ($ChunkSize > (GETID3_FREAD_BUFFER_SIZE + 8)) { + if ($ChunkSize > ($this->getid3->fread_buffer_size() + 8)) { - $ChunkData .= fread($fd, GETID3_FREAD_BUFFER_SIZE - 8); - fseek($fd, $thisfile_real_chunks_currentchunk['offset'] + $ChunkSize, SEEK_SET); + $ChunkData .= $this->fread($this->getid3->fread_buffer_size() - 8); + $this->fseek($thisfile_real_chunks_currentchunk['offset'] + $ChunkSize); } elseif(($ChunkSize - 8) > 0) { - $ChunkData .= fread($fd, $ChunkSize - 8); + $ChunkData .= $this->fread($ChunkSize - 8); } $offset = 8; @@ -95,7 +103,7 @@ class getid3_real break; default: - //$ThisFileInfo['warning'][] = 'Expected .RMF-object_version to be "0", actual value is "'.$thisfile_real_chunks_currentchunk['object_version'].'" (should not be a problem)'; + //$this->warning('Expected .RMF-object_version to be "0", actual value is "'.$thisfile_real_chunks_currentchunk['object_version'].'" (should not be a problem)'); break; } @@ -128,9 +136,9 @@ class getid3_real $offset += 2; $thisfile_real_chunks_currentchunk['flags_raw'] = getid3_lib::BigEndian2Int(substr($ChunkData, $offset, 2)); $offset += 2; - $ThisFileInfo['playtime_seconds'] = $thisfile_real_chunks_currentchunk['duration'] / 1000; + $info['playtime_seconds'] = $thisfile_real_chunks_currentchunk['duration'] / 1000; if ($thisfile_real_chunks_currentchunk['duration'] > 0) { - $ThisFileInfo['bitrate'] += $thisfile_real_chunks_currentchunk['avg_bit_rate']; + $info['bitrate'] += $thisfile_real_chunks_currentchunk['avg_bit_rate']; } $thisfile_real_chunks_currentchunk['flags']['save_enabled'] = (bool) ($thisfile_real_chunks_currentchunk['flags_raw'] & 0x0001); $thisfile_real_chunks_currentchunk['flags']['perfect_play'] = (bool) ($thisfile_real_chunks_currentchunk['flags_raw'] & 0x0002); @@ -200,26 +208,27 @@ class getid3_real //$thisfile_real_chunks_currentchunk_videoinfo['unknown8'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 34, 2)); //$thisfile_real_chunks_currentchunk_videoinfo['unknown9'] = getid3_lib::BigEndian2Int(substr($thisfile_real_chunks_currentchunk_typespecificdata, 36, 2)); - $thisfile_real_chunks_currentchunk_videoinfo['codec'] = getid3_riff::RIFFfourccLookup($thisfile_real_chunks_currentchunk_videoinfo['fourcc2']); + $thisfile_real_chunks_currentchunk_videoinfo['codec'] = getid3_riff::fourccLookup($thisfile_real_chunks_currentchunk_videoinfo['fourcc2']); - $ThisFileInfo['video']['resolution_x'] = $thisfile_real_chunks_currentchunk_videoinfo['width']; - $ThisFileInfo['video']['resolution_y'] = $thisfile_real_chunks_currentchunk_videoinfo['height']; - $ThisFileInfo['video']['frame_rate'] = (float) $thisfile_real_chunks_currentchunk_videoinfo['frames_per_second']; - $ThisFileInfo['video']['codec'] = $thisfile_real_chunks_currentchunk_videoinfo['codec']; - $ThisFileInfo['video']['bits_per_sample'] = $thisfile_real_chunks_currentchunk_videoinfo['bits_per_sample']; + $info['video']['resolution_x'] = $thisfile_real_chunks_currentchunk_videoinfo['width']; + $info['video']['resolution_y'] = $thisfile_real_chunks_currentchunk_videoinfo['height']; + $info['video']['frame_rate'] = (float) $thisfile_real_chunks_currentchunk_videoinfo['frames_per_second']; + $info['video']['codec'] = $thisfile_real_chunks_currentchunk_videoinfo['codec']; + $info['video']['bits_per_sample'] = $thisfile_real_chunks_currentchunk_videoinfo['bits_per_sample']; break; case 'audio/x-pn-realaudio': case 'audio/x-pn-multirate-realaudio': - $this->ParseOldRAheader($thisfile_real_chunks_currentchunk_typespecificdata, $thisfile_real_chunks_currentchunk['parsed_audio_data']); + $this->ParseOldRAheader($thisfile_real_chunks_currentchunk_typespecificdata, $parsedAudioData); + $thisfile_real_chunks_currentchunk['parsed_audio_data'] = &$parsedAudioData; - $ThisFileInfo['audio']['sample_rate'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['sample_rate']; - $ThisFileInfo['audio']['bits_per_sample'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['bits_per_sample']; - $ThisFileInfo['audio']['channels'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['channels']; - if (!empty($ThisFileInfo['audio']['dataformat'])) { - foreach ($ThisFileInfo['audio'] as $key => $value) { + $info['audio']['sample_rate'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['sample_rate']; + $info['audio']['bits_per_sample'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['bits_per_sample']; + $info['audio']['channels'] = $thisfile_real_chunks_currentchunk['parsed_audio_data']['channels']; + if (!empty($info['audio']['dataformat'])) { + foreach ($info['audio'] as $key => $value) { if ($key != 'streams') { - $ThisFileInfo['audio']['streams'][$thisfile_real_chunks_currentchunk['stream_number']][$key] = $value; + $info['audio']['streams'][$thisfile_real_chunks_currentchunk['stream_number']][$key] = $value; } } } @@ -255,36 +264,36 @@ class getid3_real } - if (empty($ThisFileInfo['playtime_seconds'])) { - $ThisFileInfo['playtime_seconds'] = max($ThisFileInfo['playtime_seconds'], ($thisfile_real_chunks_currentchunk['duration'] + $thisfile_real_chunks_currentchunk['start_time']) / 1000); + if (empty($info['playtime_seconds'])) { + $info['playtime_seconds'] = max($info['playtime_seconds'], ($thisfile_real_chunks_currentchunk['duration'] + $thisfile_real_chunks_currentchunk['start_time']) / 1000); } if ($thisfile_real_chunks_currentchunk['duration'] > 0) { switch ($thisfile_real_chunks_currentchunk['mime_type']) { case 'audio/x-pn-realaudio': case 'audio/x-pn-multirate-realaudio': - $ThisFileInfo['audio']['bitrate'] = (isset($ThisFileInfo['audio']['bitrate']) ? $ThisFileInfo['audio']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate']; - $ThisFileInfo['audio']['codec'] = $this->RealAudioCodecFourCClookup($thisfile_real_chunks_currentchunk['parsed_audio_data']['fourcc'], $ThisFileInfo['audio']['bitrate']); - $ThisFileInfo['audio']['dataformat'] = 'real'; - $ThisFileInfo['audio']['lossless'] = false; + $info['audio']['bitrate'] = (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate']; + $info['audio']['codec'] = $this->RealAudioCodecFourCClookup($thisfile_real_chunks_currentchunk['parsed_audio_data']['fourcc'], $info['audio']['bitrate']); + $info['audio']['dataformat'] = 'real'; + $info['audio']['lossless'] = false; break; case 'video/x-pn-realvideo': case 'video/x-pn-multirate-realvideo': - $ThisFileInfo['video']['bitrate'] = (isset($ThisFileInfo['video']['bitrate']) ? $ThisFileInfo['video']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate']; - $ThisFileInfo['video']['bitrate_mode'] = 'cbr'; - $ThisFileInfo['video']['dataformat'] = 'real'; - $ThisFileInfo['video']['lossless'] = false; - $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1; + $info['video']['bitrate'] = (isset($info['video']['bitrate']) ? $info['video']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate']; + $info['video']['bitrate_mode'] = 'cbr'; + $info['video']['dataformat'] = 'real'; + $info['video']['lossless'] = false; + $info['video']['pixel_aspect_ratio'] = (float) 1; break; case 'audio/x-ralf-mpeg4-generic': - $ThisFileInfo['audio']['bitrate'] = (isset($ThisFileInfo['audio']['bitrate']) ? $ThisFileInfo['audio']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate']; - $ThisFileInfo['audio']['codec'] = 'RealAudio Lossless'; - $ThisFileInfo['audio']['dataformat'] = 'real'; - $ThisFileInfo['audio']['lossless'] = true; + $info['audio']['bitrate'] = (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0) + $thisfile_real_chunks_currentchunk['avg_bit_rate']; + $info['audio']['codec'] = 'RealAudio Lossless'; + $info['audio']['dataformat'] = 'real'; + $info['audio']['lossless'] = true; break; } - $ThisFileInfo['bitrate'] = (isset($ThisFileInfo['video']['bitrate']) ? $ThisFileInfo['video']['bitrate'] : 0) + (isset($ThisFileInfo['audio']['bitrate']) ? $ThisFileInfo['audio']['bitrate'] : 0); + $info['bitrate'] = (isset($info['video']['bitrate']) ? $info['video']['bitrate'] : 0) + (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0); } } break; @@ -317,7 +326,7 @@ class getid3_real $commentkeystocopy = array('title'=>'title', 'artist'=>'artist', 'copyright'=>'copyright', 'comment'=>'comment'); foreach ($commentkeystocopy as $key => $val) { if ($thisfile_real_chunks_currentchunk[$key]) { - $ThisFileInfo['real']['comments'][$val][] = trim($thisfile_real_chunks_currentchunk[$key]); + $info['real']['comments'][$val][] = trim($thisfile_real_chunks_currentchunk[$key]); } } @@ -345,30 +354,35 @@ class getid3_real break 2; } else { // non-last index chunk, seek to next index chunk (skipping actual index data) - fseek($fd, $thisfile_real_chunks_currentchunk['next_index_header'], SEEK_SET); + $this->fseek($thisfile_real_chunks_currentchunk['next_index_header']); } } break; default: - $ThisFileInfo['warning'][] = 'Unhandled RealMedia chunk "'.$ChunkName.'" at offset '.$thisfile_real_chunks_currentchunk['offset']; + $this->warning('Unhandled RealMedia chunk "'.$ChunkName.'" at offset '.$thisfile_real_chunks_currentchunk['offset']); break; } $ChunkCounter++; } - if (!empty($ThisFileInfo['audio']['streams'])) { - $ThisFileInfo['audio']['bitrate'] = 0; - foreach ($ThisFileInfo['audio']['streams'] as $key => $valuearray) { - $ThisFileInfo['audio']['bitrate'] += $valuearray['bitrate']; + if (!empty($info['audio']['streams'])) { + $info['audio']['bitrate'] = 0; + foreach ($info['audio']['streams'] as $key => $valuearray) { + $info['audio']['bitrate'] += $valuearray['bitrate']; } } return true; } - - function ParseOldRAheader($OldRAheaderData, &$ParsedArray) { + /** + * @param string $OldRAheaderData + * @param array $ParsedArray + * + * @return bool + */ + public function ParseOldRAheader($OldRAheaderData, &$ParsedArray) { // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html $ParsedArray = array(); @@ -473,8 +487,9 @@ class getid3_real $ParsedArray['fourcc'] = $ParsedArray['fourcc3']; } + /** @var string[]|false[] $value */ foreach ($ParsedArray['comments'] as $key => $value) { - if ($ParsedArray['comments'][$key][0] === false) { + if ($value[0] === false) { $ParsedArray['comments'][$key][0] = ''; } } @@ -482,7 +497,13 @@ class getid3_real return true; } - function RealAudioCodecFourCClookup($fourcc, $bitrate) { + /** + * @param string $fourcc + * @param int $bitrate + * + * @return string + */ + public function RealAudioCodecFourCClookup($fourcc, $bitrate) { static $RealAudioCodecFourCClookup = array(); if (empty($RealAudioCodecFourCClookup)) { // http://www.its.msstate.edu/net/real/reports/config/tags.stats @@ -523,6 +544,3 @@ class getid3_real } } - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.riff.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.riff.php new file mode 100644 index 00000000..e745ec65 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.riff.php @@ -0,0 +1,2868 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio-video.riff.php // +// module for analyzing RIFF files // +// multiple formats supported by this module: // +// Wave, AVI, AIFF/AIFC, (MP3,AC3)/RIFF, Wavpack v3, 8SVX // +// dependencies: module.audio.mp3.php // +// module.audio.ac3.php // +// module.audio.dts.php // +// /// +///////////////////////////////////////////////////////////////// + +/** +* @todo Parse AC-3/DTS audio inside WAVE correctly +* @todo Rewrite RIFF parser totally +*/ + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ac3.php', __FILE__, true); +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.dts.php', __FILE__, true); + +class getid3_riff extends getid3_handler +{ + protected $container = 'riff'; // default + + /** + * @return bool + * + * @throws getid3_exception + */ + public function Analyze() { + $info = &$this->getid3->info; + + // initialize these values to an empty array, otherwise they default to NULL + // and you can't append array values to a NULL value + $info['riff'] = array('raw'=>array()); + + // Shortcuts + $thisfile_riff = &$info['riff']; + $thisfile_riff_raw = &$thisfile_riff['raw']; + $thisfile_audio = &$info['audio']; + $thisfile_video = &$info['video']; + $thisfile_audio_dataformat = &$thisfile_audio['dataformat']; + $thisfile_riff_audio = &$thisfile_riff['audio']; + $thisfile_riff_video = &$thisfile_riff['video']; + $thisfile_riff_WAVE = array(); + + $Original = array(); + $Original['avdataoffset'] = $info['avdataoffset']; + $Original['avdataend'] = $info['avdataend']; + + $this->fseek($info['avdataoffset']); + $RIFFheader = $this->fread(12); + $offset = $this->ftell(); + $RIFFtype = substr($RIFFheader, 0, 4); + $RIFFsize = substr($RIFFheader, 4, 4); + $RIFFsubtype = substr($RIFFheader, 8, 4); + + switch ($RIFFtype) { + + case 'FORM': // AIFF, AIFC + //$info['fileformat'] = 'aiff'; + $this->container = 'aiff'; + $thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize); + $thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4)); + break; + + case 'RIFF': // AVI, WAV, etc + case 'SDSS': // SDSS is identical to RIFF, just renamed. Used by SmartSound QuickTracks (www.smartsound.com) + case 'RMP3': // RMP3 is identical to RIFF, just renamed. Used by [unknown program] when creating RIFF-MP3s + //$info['fileformat'] = 'riff'; + $this->container = 'riff'; + $thisfile_riff['header_size'] = $this->EitherEndian2Int($RIFFsize); + if ($RIFFsubtype == 'RMP3') { + // RMP3 is identical to WAVE, just renamed. Used by [unknown program] when creating RIFF-MP3s + $RIFFsubtype = 'WAVE'; + } + if ($RIFFsubtype != 'AMV ') { + // AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size + // Handled separately in ParseRIFFAMV() + $thisfile_riff[$RIFFsubtype] = $this->ParseRIFF($offset, ($offset + $thisfile_riff['header_size'] - 4)); + } + if (($info['avdataend'] - $info['filesize']) == 1) { + // LiteWave appears to incorrectly *not* pad actual output file + // to nearest WORD boundary so may appear to be short by one + // byte, in which case - skip warning + $info['avdataend'] = $info['filesize']; + } + + $nextRIFFoffset = $Original['avdataoffset'] + 8 + $thisfile_riff['header_size']; // 8 = "RIFF" + 32-bit offset + while ($nextRIFFoffset < min($info['filesize'], $info['avdataend'])) { + try { + $this->fseek($nextRIFFoffset); + } catch (getid3_exception $e) { + if ($e->getCode() == 10) { + //$this->warning('RIFF parser: '.$e->getMessage()); + $this->error('AVI extends beyond '.round(PHP_INT_MAX / 1073741824).'GB and PHP filesystem functions cannot read that far, playtime may be wrong'); + $this->warning('[avdataend] value may be incorrect, multiple AVIX chunks may be present'); + break; + } else { + throw $e; + } + } + $nextRIFFheader = $this->fread(12); + if ($nextRIFFoffset == ($info['avdataend'] - 1)) { + if (substr($nextRIFFheader, 0, 1) == "\x00") { + // RIFF padded to WORD boundary, we're actually already at the end + break; + } + } + $nextRIFFheaderID = substr($nextRIFFheader, 0, 4); + $nextRIFFsize = $this->EitherEndian2Int(substr($nextRIFFheader, 4, 4)); + $nextRIFFtype = substr($nextRIFFheader, 8, 4); + $chunkdata = array(); + $chunkdata['offset'] = $nextRIFFoffset + 8; + $chunkdata['size'] = $nextRIFFsize; + $nextRIFFoffset = $chunkdata['offset'] + $chunkdata['size']; + + switch ($nextRIFFheaderID) { + case 'RIFF': + $chunkdata['chunks'] = $this->ParseRIFF($chunkdata['offset'] + 4, $nextRIFFoffset); + if (!isset($thisfile_riff[$nextRIFFtype])) { + $thisfile_riff[$nextRIFFtype] = array(); + } + $thisfile_riff[$nextRIFFtype][] = $chunkdata; + break; + + case 'AMV ': + unset($info['riff']); + $info['amv'] = $this->ParseRIFFAMV($chunkdata['offset'] + 4, $nextRIFFoffset); + break; + + case 'JUNK': + // ignore + $thisfile_riff[$nextRIFFheaderID][] = $chunkdata; + break; + + case 'IDVX': + $info['divxtag']['comments'] = self::ParseDIVXTAG($this->fread($chunkdata['size'])); + break; + + default: + if ($info['filesize'] == ($chunkdata['offset'] - 8 + 128)) { + $DIVXTAG = $nextRIFFheader.$this->fread(128 - 12); + if (substr($DIVXTAG, -7) == 'DIVXTAG') { + // DIVXTAG is supposed to be inside an IDVX chunk in a LIST chunk, but some bad encoders just slap it on the end of a file + $this->warning('Found wrongly-structured DIVXTAG at offset '.($this->ftell() - 128).', parsing anyway'); + $info['divxtag']['comments'] = self::ParseDIVXTAG($DIVXTAG); + break 2; + } + } + $this->warning('Expecting "RIFF|JUNK|IDVX" at '.$nextRIFFoffset.', found "'.$nextRIFFheaderID.'" ('.getid3_lib::PrintHexBytes($nextRIFFheaderID).') - skipping rest of file'); + break 2; + + } + + } + if ($RIFFsubtype == 'WAVE') { + $thisfile_riff_WAVE = &$thisfile_riff['WAVE']; + } + break; + + default: + $this->error('Cannot parse RIFF (this is maybe not a RIFF / WAV / AVI file?) - expecting "FORM|RIFF|SDSS|RMP3" found "'.$RIFFsubtype.'" instead'); + //unset($info['fileformat']); + return false; + } + + $streamindex = 0; + switch ($RIFFsubtype) { + + // http://en.wikipedia.org/wiki/Wav + case 'WAVE': + $info['fileformat'] = 'wav'; + + if (empty($thisfile_audio['bitrate_mode'])) { + $thisfile_audio['bitrate_mode'] = 'cbr'; + } + if (empty($thisfile_audio_dataformat)) { + $thisfile_audio_dataformat = 'wav'; + } + + if (isset($thisfile_riff_WAVE['data'][0]['offset'])) { + $info['avdataoffset'] = $thisfile_riff_WAVE['data'][0]['offset'] + 8; + $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff_WAVE['data'][0]['size']; + } + if (isset($thisfile_riff_WAVE['fmt '][0]['data'])) { + + $thisfile_riff_audio[$streamindex] = self::parseWAVEFORMATex($thisfile_riff_WAVE['fmt '][0]['data']); + $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag']; + if (!isset($thisfile_riff_audio[$streamindex]['bitrate']) || ($thisfile_riff_audio[$streamindex]['bitrate'] == 0)) { + $this->error('Corrupt RIFF file: bitrate_audio == zero'); + return false; + } + $thisfile_riff_raw['fmt '] = $thisfile_riff_audio[$streamindex]['raw']; + unset($thisfile_riff_audio[$streamindex]['raw']); + $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex]; + + $thisfile_audio = (array) getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]); + if (substr($thisfile_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') { + $this->warning('Audio codec = '.$thisfile_audio['codec']); + } + $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate']; + + if (empty($info['playtime_seconds'])) { // may already be set (e.g. DTS-WAV) + $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']); + } + + $thisfile_audio['lossless'] = false; + if (isset($thisfile_riff_WAVE['data'][0]['offset']) && isset($thisfile_riff_raw['fmt ']['wFormatTag'])) { + switch ($thisfile_riff_raw['fmt ']['wFormatTag']) { + + case 0x0001: // PCM + $thisfile_audio['lossless'] = true; + break; + + case 0x2000: // AC-3 + $thisfile_audio_dataformat = 'ac3'; + break; + + default: + // do nothing + break; + + } + } + $thisfile_audio['streams'][$streamindex]['wformattag'] = $thisfile_audio['wformattag']; + $thisfile_audio['streams'][$streamindex]['bitrate_mode'] = $thisfile_audio['bitrate_mode']; + $thisfile_audio['streams'][$streamindex]['lossless'] = $thisfile_audio['lossless']; + $thisfile_audio['streams'][$streamindex]['dataformat'] = $thisfile_audio_dataformat; + } + + if (isset($thisfile_riff_WAVE['rgad'][0]['data'])) { + + // shortcuts + $rgadData = &$thisfile_riff_WAVE['rgad'][0]['data']; + $thisfile_riff_raw['rgad'] = array('track'=>array(), 'album'=>array()); + $thisfile_riff_raw_rgad = &$thisfile_riff_raw['rgad']; + $thisfile_riff_raw_rgad_track = &$thisfile_riff_raw_rgad['track']; + $thisfile_riff_raw_rgad_album = &$thisfile_riff_raw_rgad['album']; + + $thisfile_riff_raw_rgad['fPeakAmplitude'] = getid3_lib::LittleEndian2Float(substr($rgadData, 0, 4)); + $thisfile_riff_raw_rgad['nRadioRgAdjust'] = $this->EitherEndian2Int(substr($rgadData, 4, 2)); + $thisfile_riff_raw_rgad['nAudiophileRgAdjust'] = $this->EitherEndian2Int(substr($rgadData, 6, 2)); + + $nRadioRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nRadioRgAdjust']), 16, '0', STR_PAD_LEFT); + $nAudiophileRgAdjustBitstring = str_pad(getid3_lib::Dec2Bin($thisfile_riff_raw_rgad['nAudiophileRgAdjust']), 16, '0', STR_PAD_LEFT); + $thisfile_riff_raw_rgad_track['name'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 0, 3)); + $thisfile_riff_raw_rgad_track['originator'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 3, 3)); + $thisfile_riff_raw_rgad_track['signbit'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 6, 1)); + $thisfile_riff_raw_rgad_track['adjustment'] = getid3_lib::Bin2Dec(substr($nRadioRgAdjustBitstring, 7, 9)); + $thisfile_riff_raw_rgad_album['name'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 0, 3)); + $thisfile_riff_raw_rgad_album['originator'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 3, 3)); + $thisfile_riff_raw_rgad_album['signbit'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 6, 1)); + $thisfile_riff_raw_rgad_album['adjustment'] = getid3_lib::Bin2Dec(substr($nAudiophileRgAdjustBitstring, 7, 9)); + + $thisfile_riff['rgad']['peakamplitude'] = $thisfile_riff_raw_rgad['fPeakAmplitude']; + if (($thisfile_riff_raw_rgad_track['name'] != 0) && ($thisfile_riff_raw_rgad_track['originator'] != 0)) { + $thisfile_riff['rgad']['track']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_track['name']); + $thisfile_riff['rgad']['track']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_track['originator']); + $thisfile_riff['rgad']['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_track['adjustment'], $thisfile_riff_raw_rgad_track['signbit']); + } + if (($thisfile_riff_raw_rgad_album['name'] != 0) && ($thisfile_riff_raw_rgad_album['originator'] != 0)) { + $thisfile_riff['rgad']['album']['name'] = getid3_lib::RGADnameLookup($thisfile_riff_raw_rgad_album['name']); + $thisfile_riff['rgad']['album']['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_riff_raw_rgad_album['originator']); + $thisfile_riff['rgad']['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($thisfile_riff_raw_rgad_album['adjustment'], $thisfile_riff_raw_rgad_album['signbit']); + } + } + + if (isset($thisfile_riff_WAVE['fact'][0]['data'])) { + $thisfile_riff_raw['fact']['NumberOfSamples'] = $this->EitherEndian2Int(substr($thisfile_riff_WAVE['fact'][0]['data'], 0, 4)); + + // This should be a good way of calculating exact playtime, + // but some sample files have had incorrect number of samples, + // so cannot use this method + + // if (!empty($thisfile_riff_raw['fmt ']['nSamplesPerSec'])) { + // $info['playtime_seconds'] = (float) $thisfile_riff_raw['fact']['NumberOfSamples'] / $thisfile_riff_raw['fmt ']['nSamplesPerSec']; + // } + } + if (!empty($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'])) { + $thisfile_audio['bitrate'] = getid3_lib::CastAsInt($thisfile_riff_raw['fmt ']['nAvgBytesPerSec'] * 8); + } + + if (isset($thisfile_riff_WAVE['bext'][0]['data'])) { + // shortcut + $thisfile_riff_WAVE_bext_0 = &$thisfile_riff_WAVE['bext'][0]; + + $thisfile_riff_WAVE_bext_0['title'] = substr($thisfile_riff_WAVE_bext_0['data'], 0, 256); + $thisfile_riff_WAVE_bext_0['author'] = substr($thisfile_riff_WAVE_bext_0['data'], 256, 32); + $thisfile_riff_WAVE_bext_0['reference'] = substr($thisfile_riff_WAVE_bext_0['data'], 288, 32); + foreach (array('title','author','reference') as $bext_key) { + // Some software (notably Logic Pro) may not blank existing data before writing a null-terminated string to the offsets + // assigned for text fields, resulting in a null-terminated string (or possibly just a single null) followed by garbage + // Keep only string as far as first null byte, discard rest of fixed-width data + // https://github.com/JamesHeinrich/getID3/issues/263 + $null_terminator_offset = strpos($thisfile_riff_WAVE_bext_0[$bext_key], "\x00"); + $thisfile_riff_WAVE_bext_0[$bext_key] = substr($thisfile_riff_WAVE_bext_0[$bext_key], 0, $null_terminator_offset); + } + + $thisfile_riff_WAVE_bext_0['origin_date'] = substr($thisfile_riff_WAVE_bext_0['data'], 320, 10); + $thisfile_riff_WAVE_bext_0['origin_time'] = substr($thisfile_riff_WAVE_bext_0['data'], 330, 8); + $thisfile_riff_WAVE_bext_0['time_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 338, 8)); + $thisfile_riff_WAVE_bext_0['bwf_version'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_bext_0['data'], 346, 1)); + $thisfile_riff_WAVE_bext_0['reserved'] = substr($thisfile_riff_WAVE_bext_0['data'], 347, 254); + $thisfile_riff_WAVE_bext_0['coding_history'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_bext_0['data'], 601))); + if (preg_match('#^([0-9]{4}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_date'], $matches_bext_date)) { + if (preg_match('#^([0-9]{2}).([0-9]{2}).([0-9]{2})$#', $thisfile_riff_WAVE_bext_0['origin_time'], $matches_bext_time)) { + $bext_timestamp = array(); + list($dummy, $bext_timestamp['year'], $bext_timestamp['month'], $bext_timestamp['day']) = $matches_bext_date; + list($dummy, $bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second']) = $matches_bext_time; + $thisfile_riff_WAVE_bext_0['origin_date_unix'] = gmmktime($bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second'], $bext_timestamp['month'], $bext_timestamp['day'], $bext_timestamp['year']); + } else { + $this->warning('RIFF.WAVE.BEXT.origin_time is invalid'); + } + } else { + $this->warning('RIFF.WAVE.BEXT.origin_date is invalid'); + } + $thisfile_riff['comments']['author'][] = $thisfile_riff_WAVE_bext_0['author']; + $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_bext_0['title']; + } + + if (isset($thisfile_riff_WAVE['MEXT'][0]['data'])) { + // shortcut + $thisfile_riff_WAVE_MEXT_0 = &$thisfile_riff_WAVE['MEXT'][0]; + + $thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 0, 2)); + $thisfile_riff_WAVE_MEXT_0['flags']['homogenous'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0001); + if ($thisfile_riff_WAVE_MEXT_0['flags']['homogenous']) { + $thisfile_riff_WAVE_MEXT_0['flags']['padding'] = ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0002) ? false : true; + $thisfile_riff_WAVE_MEXT_0['flags']['22_or_44'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0004); + $thisfile_riff_WAVE_MEXT_0['flags']['free_format'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['sound_information'] & 0x0008); + + $thisfile_riff_WAVE_MEXT_0['nominal_frame_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 2, 2)); + } + $thisfile_riff_WAVE_MEXT_0['anciliary_data_length'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 6, 2)); + $thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_MEXT_0['data'], 8, 2)); + $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_left'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0001); + $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_free'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0002); + $thisfile_riff_WAVE_MEXT_0['flags']['anciliary_data_right'] = (bool) ($thisfile_riff_WAVE_MEXT_0['raw']['anciliary_data_def'] & 0x0004); + } + + if (isset($thisfile_riff_WAVE['cart'][0]['data'])) { + // shortcut + $thisfile_riff_WAVE_cart_0 = &$thisfile_riff_WAVE['cart'][0]; + + $thisfile_riff_WAVE_cart_0['version'] = substr($thisfile_riff_WAVE_cart_0['data'], 0, 4); + $thisfile_riff_WAVE_cart_0['title'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 4, 64)); + $thisfile_riff_WAVE_cart_0['artist'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 68, 64)); + $thisfile_riff_WAVE_cart_0['cut_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 132, 64)); + $thisfile_riff_WAVE_cart_0['client_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 196, 64)); + $thisfile_riff_WAVE_cart_0['category'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 260, 64)); + $thisfile_riff_WAVE_cart_0['classification'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 324, 64)); + $thisfile_riff_WAVE_cart_0['out_cue'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 388, 64)); + $thisfile_riff_WAVE_cart_0['start_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 452, 10)); + $thisfile_riff_WAVE_cart_0['start_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 462, 8)); + $thisfile_riff_WAVE_cart_0['end_date'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 470, 10)); + $thisfile_riff_WAVE_cart_0['end_time'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 480, 8)); + $thisfile_riff_WAVE_cart_0['producer_app_id'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 488, 64)); + $thisfile_riff_WAVE_cart_0['producer_app_version'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 552, 64)); + $thisfile_riff_WAVE_cart_0['user_defined_text'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 616, 64)); + $thisfile_riff_WAVE_cart_0['zero_db_reference'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 680, 4), true); + for ($i = 0; $i < 8; $i++) { + $thisfile_riff_WAVE_cart_0['post_time'][$i]['usage_fourcc'] = substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8), 4); + $thisfile_riff_WAVE_cart_0['post_time'][$i]['timer_value'] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE_cart_0['data'], 684 + ($i * 8) + 4, 4)); + } + $thisfile_riff_WAVE_cart_0['url'] = trim(substr($thisfile_riff_WAVE_cart_0['data'], 748, 1024)); + $thisfile_riff_WAVE_cart_0['tag_text'] = explode("\r\n", trim(substr($thisfile_riff_WAVE_cart_0['data'], 1772))); + $thisfile_riff['comments']['tag_text'][] = substr($thisfile_riff_WAVE_cart_0['data'], 1772); + + $thisfile_riff['comments']['artist'][] = $thisfile_riff_WAVE_cart_0['artist']; + $thisfile_riff['comments']['title'][] = $thisfile_riff_WAVE_cart_0['title']; + } + + if (isset($thisfile_riff_WAVE['SNDM'][0]['data'])) { + // SoundMiner metadata + + // shortcuts + $thisfile_riff_WAVE_SNDM_0 = &$thisfile_riff_WAVE['SNDM'][0]; + $thisfile_riff_WAVE_SNDM_0_data = &$thisfile_riff_WAVE_SNDM_0['data']; + $SNDM_startoffset = 0; + $SNDM_endoffset = $thisfile_riff_WAVE_SNDM_0['size']; + + while ($SNDM_startoffset < $SNDM_endoffset) { + $SNDM_thisTagOffset = 0; + $SNDM_thisTagSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4)); + $SNDM_thisTagOffset += 4; + $SNDM_thisTagKey = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 4); + $SNDM_thisTagOffset += 4; + $SNDM_thisTagDataSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2)); + $SNDM_thisTagOffset += 2; + $SNDM_thisTagDataFlags = getid3_lib::BigEndian2Int(substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, 2)); + $SNDM_thisTagOffset += 2; + $SNDM_thisTagDataText = substr($thisfile_riff_WAVE_SNDM_0_data, $SNDM_startoffset + $SNDM_thisTagOffset, $SNDM_thisTagDataSize); + $SNDM_thisTagOffset += $SNDM_thisTagDataSize; + + if ($SNDM_thisTagSize != (4 + 4 + 2 + 2 + $SNDM_thisTagDataSize)) { + $this->warning('RIFF.WAVE.SNDM.data contains tag not expected length (expected: '.$SNDM_thisTagSize.', found: '.(4 + 4 + 2 + 2 + $SNDM_thisTagDataSize).') at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')'); + break; + } elseif ($SNDM_thisTagSize <= 0) { + $this->warning('RIFF.WAVE.SNDM.data contains zero-size tag at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')'); + break; + } + $SNDM_startoffset += $SNDM_thisTagSize; + + $thisfile_riff_WAVE_SNDM_0['parsed_raw'][$SNDM_thisTagKey] = $SNDM_thisTagDataText; + if ($parsedkey = self::waveSNDMtagLookup($SNDM_thisTagKey)) { + $thisfile_riff_WAVE_SNDM_0['parsed'][$parsedkey] = $SNDM_thisTagDataText; + } else { + $this->warning('RIFF.WAVE.SNDM contains unknown tag "'.$SNDM_thisTagKey.'" at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')'); + } + } + + $tagmapping = array( + 'tracktitle'=>'title', + 'category' =>'genre', + 'cdtitle' =>'album', + ); + foreach ($tagmapping as $fromkey => $tokey) { + if (isset($thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey])) { + $thisfile_riff['comments'][$tokey][] = $thisfile_riff_WAVE_SNDM_0['parsed'][$fromkey]; + } + } + } + + if (isset($thisfile_riff_WAVE['iXML'][0]['data'])) { + // requires functions simplexml_load_string and get_object_vars + if ($parsedXML = getid3_lib::XML2array($thisfile_riff_WAVE['iXML'][0]['data'])) { + $thisfile_riff_WAVE['iXML'][0]['parsed'] = $parsedXML; + if (isset($parsedXML['SPEED']['MASTER_SPEED'])) { + @list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['MASTER_SPEED']); + $thisfile_riff_WAVE['iXML'][0]['master_speed'] = $numerator / ($denominator ? $denominator : 1000); + } + if (isset($parsedXML['SPEED']['TIMECODE_RATE'])) { + @list($numerator, $denominator) = explode('/', $parsedXML['SPEED']['TIMECODE_RATE']); + $thisfile_riff_WAVE['iXML'][0]['timecode_rate'] = $numerator / ($denominator ? $denominator : 1000); + } + if (isset($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO']) && !empty($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) && !empty($thisfile_riff_WAVE['iXML'][0]['timecode_rate'])) { + $samples_since_midnight = floatval(ltrim($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_HI'].$parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO'], '0')); + $timestamp_sample_rate = (is_array($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) ? max($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) : $parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']); // XML could possibly contain more than one TIMESTAMP_SAMPLE_RATE tag, returning as array instead of integer [why? does it make sense? perhaps doesn't matter but getID3 needs to deal with it] - see https://github.com/JamesHeinrich/getID3/issues/105 + $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] = $samples_since_midnight / $timestamp_sample_rate; + $h = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] / 3600); + $m = floor(($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600)) / 60); + $s = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60)); + $f = ($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600) - ($m * 60) - $s) * $thisfile_riff_WAVE['iXML'][0]['timecode_rate']; + $thisfile_riff_WAVE['iXML'][0]['timecode_string'] = sprintf('%02d:%02d:%02d:%05.2f', $h, $m, $s, $f); + $thisfile_riff_WAVE['iXML'][0]['timecode_string_round'] = sprintf('%02d:%02d:%02d:%02d', $h, $m, $s, round($f)); + unset($samples_since_midnight, $timestamp_sample_rate, $h, $m, $s, $f); + } + unset($parsedXML); + } + } + + if (isset($thisfile_riff_WAVE['guan'][0]['data'])) { + // shortcut + $thisfile_riff_WAVE_guan_0 = &$thisfile_riff_WAVE['guan'][0]; + if (!empty($thisfile_riff_WAVE_guan_0['data']) && (substr($thisfile_riff_WAVE_guan_0['data'], 0, 14) == 'GUANO|Version:')) { + $thisfile_riff['guano'] = array(); + foreach (explode("\n", $thisfile_riff_WAVE_guan_0['data']) as $line) { + if ($line) { + @list($key, $value) = explode(':', $line, 2); + if (substr($value, 0, 3) == '[{"') { + if ($decoded = @json_decode($value, true)) { + if (!empty($decoded) && (count($decoded) == 1)) { + $value = $decoded[0]; + } else { + $value = $decoded; + } + } + } + $thisfile_riff['guano'] = array_merge_recursive($thisfile_riff['guano'], getid3_lib::CreateDeepArray($key, '|', $value)); + } + } + + // https://www.wildlifeacoustics.com/SCHEMA/GUANO.html + foreach ($thisfile_riff['guano'] as $key => $value) { + switch ($key) { + case 'Loc Position': + if (preg_match('#^([\\+\\-]?[0-9]+\\.[0-9]+) ([\\+\\-]?[0-9]+\\.[0-9]+)$#', $value, $matches)) { + list($dummy, $latitude, $longitude) = $matches; + $thisfile_riff['comments']['gps_latitude'][0] = floatval($latitude); + $thisfile_riff['comments']['gps_longitude'][0] = floatval($longitude); + $thisfile_riff['guano'][$key] = floatval($latitude).' '.floatval($longitude); + } + break; + case 'Loc Elevation': // Elevation/altitude above mean sea level in meters + $thisfile_riff['comments']['gps_altitude'][0] = floatval($value); + $thisfile_riff['guano'][$key] = (float) $value; + break; + case 'Filter HP': // High-pass filter frequency in kHz + case 'Filter LP': // Low-pass filter frequency in kHz + case 'Humidity': // Relative humidity as a percentage + case 'Length': // Recording length in seconds + case 'Loc Accuracy': // Estimated Position Error in meters + case 'Temperature Ext': // External temperature in degrees Celsius outside the recorder's housing + case 'Temperature Int': // Internal temperature in degrees Celsius inside the recorder's housing + $thisfile_riff['guano'][$key] = (float) $value; + break; + case 'Samplerate': // Recording sample rate, Hz + case 'TE': // Time-expansion factor. If not specified, then 1 (no time-expansion a.k.a. direct-recording) is assumed. + $thisfile_riff['guano'][$key] = (int) $value; + break; + } + } + + } else { + $this->warning('RIFF.guan data not in expected format'); + } + } + + if (!isset($thisfile_audio['bitrate']) && isset($thisfile_riff_audio[$streamindex]['bitrate'])) { + $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate']; + $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $thisfile_audio['bitrate']); + } + + if (!empty($info['wavpack'])) { + $thisfile_audio_dataformat = 'wavpack'; + $thisfile_audio['bitrate_mode'] = 'vbr'; + $thisfile_audio['encoder'] = 'WavPack v'.$info['wavpack']['version']; + + // Reset to the way it was - RIFF parsing will have messed this up + $info['avdataend'] = $Original['avdataend']; + $thisfile_audio['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + + $this->fseek($info['avdataoffset'] - 44); + $RIFFdata = $this->fread(44); + $OrignalRIFFheaderSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8; + $OrignalRIFFdataSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44; + + if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) { + $info['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize); + $this->fseek($info['avdataend']); + $RIFFdata .= $this->fread($OrignalRIFFheaderSize - $OrignalRIFFdataSize); + } + + // move the data chunk after all other chunks (if any) + // so that the RIFF parser doesn't see EOF when trying + // to skip over the data chunk + $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8); + $getid3_riff = new getid3_riff($this->getid3); + $getid3_riff->ParseRIFFdata($RIFFdata); + unset($getid3_riff); + } + + if (isset($thisfile_riff_raw['fmt ']['wFormatTag'])) { + switch ($thisfile_riff_raw['fmt ']['wFormatTag']) { + case 0x0001: // PCM + if (!empty($info['ac3'])) { + // Dolby Digital WAV files masquerade as PCM-WAV, but they're not + $thisfile_audio['wformattag'] = 0x2000; + $thisfile_audio['codec'] = self::wFormatTagLookup($thisfile_audio['wformattag']); + $thisfile_audio['lossless'] = false; + $thisfile_audio['bitrate'] = $info['ac3']['bitrate']; + $thisfile_audio['sample_rate'] = $info['ac3']['sample_rate']; + } + if (!empty($info['dts'])) { + // Dolby DTS files masquerade as PCM-WAV, but they're not + $thisfile_audio['wformattag'] = 0x2001; + $thisfile_audio['codec'] = self::wFormatTagLookup($thisfile_audio['wformattag']); + $thisfile_audio['lossless'] = false; + $thisfile_audio['bitrate'] = $info['dts']['bitrate']; + $thisfile_audio['sample_rate'] = $info['dts']['sample_rate']; + } + break; + case 0x08AE: // ClearJump LiteWave + $thisfile_audio['bitrate_mode'] = 'vbr'; + $thisfile_audio_dataformat = 'litewave'; + + //typedef struct tagSLwFormat { + // WORD m_wCompFormat; // low byte defines compression method, high byte is compression flags + // DWORD m_dwScale; // scale factor for lossy compression + // DWORD m_dwBlockSize; // number of samples in encoded blocks + // WORD m_wQuality; // alias for the scale factor + // WORD m_wMarkDistance; // distance between marks in bytes + // WORD m_wReserved; + // + // //following paramters are ignored if CF_FILESRC is not set + // DWORD m_dwOrgSize; // original file size in bytes + // WORD m_bFactExists; // indicates if 'fact' chunk exists in the original file + // DWORD m_dwRiffChunkSize; // riff chunk size in the original file + // + // PCMWAVEFORMAT m_OrgWf; // original wave format + // }SLwFormat, *PSLwFormat; + + // shortcut + $thisfile_riff['litewave']['raw'] = array(); + $riff_litewave = &$thisfile_riff['litewave']; + $riff_litewave_raw = &$riff_litewave['raw']; + + $flags = array( + 'compression_method' => 1, + 'compression_flags' => 1, + 'm_dwScale' => 4, + 'm_dwBlockSize' => 4, + 'm_wQuality' => 2, + 'm_wMarkDistance' => 2, + 'm_wReserved' => 2, + 'm_dwOrgSize' => 4, + 'm_bFactExists' => 2, + 'm_dwRiffChunkSize' => 4, + ); + $litewave_offset = 18; + foreach ($flags as $flag => $length) { + $riff_litewave_raw[$flag] = getid3_lib::LittleEndian2Int(substr($thisfile_riff_WAVE['fmt '][0]['data'], $litewave_offset, $length)); + $litewave_offset += $length; + } + + //$riff_litewave['quality_factor'] = intval(round((2000 - $riff_litewave_raw['m_dwScale']) / 20)); + $riff_litewave['quality_factor'] = $riff_litewave_raw['m_wQuality']; + + $riff_litewave['flags']['raw_source'] = ($riff_litewave_raw['compression_flags'] & 0x01) ? false : true; + $riff_litewave['flags']['vbr_blocksize'] = ($riff_litewave_raw['compression_flags'] & 0x02) ? false : true; + $riff_litewave['flags']['seekpoints'] = (bool) ($riff_litewave_raw['compression_flags'] & 0x04); + + $thisfile_audio['lossless'] = (($riff_litewave_raw['m_wQuality'] == 100) ? true : false); + $thisfile_audio['encoder_options'] = '-q'.$riff_litewave['quality_factor']; + break; + + default: + break; + } + } + if ($info['avdataend'] > $info['filesize']) { + switch (!empty($thisfile_audio_dataformat) ? $thisfile_audio_dataformat : '') { + case 'wavpack': // WavPack + case 'lpac': // LPAC + case 'ofr': // OptimFROG + case 'ofs': // OptimFROG DualStream + // lossless compressed audio formats that keep original RIFF headers - skip warning + break; + + case 'litewave': + if (($info['avdataend'] - $info['filesize']) == 1) { + // LiteWave appears to incorrectly *not* pad actual output file + // to nearest WORD boundary so may appear to be short by one + // byte, in which case - skip warning + } else { + // Short by more than one byte, throw warning + $this->warning('Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)'); + $info['avdataend'] = $info['filesize']; + } + break; + + default: + if ((($info['avdataend'] - $info['filesize']) == 1) && (($thisfile_riff[$RIFFsubtype]['data'][0]['size'] % 2) == 0) && ((($info['filesize'] - $info['avdataoffset']) % 2) == 1)) { + // output file appears to be incorrectly *not* padded to nearest WORD boundary + // Output less severe warning + $this->warning('File should probably be padded to nearest WORD boundary, but it is not (expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' therefore short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)'); + $info['avdataend'] = $info['filesize']; + } else { + // Short by more than one byte, throw warning + $this->warning('Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)'); + $info['avdataend'] = $info['filesize']; + } + break; + } + } + if (!empty($info['mpeg']['audio']['LAME']['audio_bytes'])) { + if ((($info['avdataend'] - $info['avdataoffset']) - $info['mpeg']['audio']['LAME']['audio_bytes']) == 1) { + $info['avdataend']--; + $this->warning('Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored'); + } + } + if (isset($thisfile_audio_dataformat) && ($thisfile_audio_dataformat == 'ac3')) { + unset($thisfile_audio['bits_per_sample']); + if (!empty($info['ac3']['bitrate']) && ($info['ac3']['bitrate'] != $thisfile_audio['bitrate'])) { + $thisfile_audio['bitrate'] = $info['ac3']['bitrate']; + } + } + break; + + // http://en.wikipedia.org/wiki/Audio_Video_Interleave + case 'AVI ': + $info['fileformat'] = 'avi'; + $info['mime_type'] = 'video/avi'; + + $thisfile_video['bitrate_mode'] = 'vbr'; // maybe not, but probably + $thisfile_video['dataformat'] = 'avi'; + + $thisfile_riff_video_current = array(); + + if (isset($thisfile_riff[$RIFFsubtype]['movi']['offset'])) { + $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['movi']['offset'] + 8; + if (isset($thisfile_riff['AVIX'])) { + $info['avdataend'] = $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['offset'] + $thisfile_riff['AVIX'][(count($thisfile_riff['AVIX']) - 1)]['chunks']['movi']['size']; + } else { + $info['avdataend'] = $thisfile_riff['AVI ']['movi']['offset'] + $thisfile_riff['AVI ']['movi']['size']; + } + if ($info['avdataend'] > $info['filesize']) { + $this->warning('Probably truncated file - expecting '.($info['avdataend'] - $info['avdataoffset']).' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($info['avdataend'] - $info['filesize']).' bytes)'); + $info['avdataend'] = $info['filesize']; + } + } + + if (isset($thisfile_riff['AVI ']['hdrl']['strl']['indx'])) { + //$bIndexType = array( + // 0x00 => 'AVI_INDEX_OF_INDEXES', + // 0x01 => 'AVI_INDEX_OF_CHUNKS', + // 0x80 => 'AVI_INDEX_IS_DATA', + //); + //$bIndexSubtype = array( + // 0x01 => array( + // 0x01 => 'AVI_INDEX_2FIELD', + // ), + //); + foreach ($thisfile_riff['AVI ']['hdrl']['strl']['indx'] as $streamnumber => $steamdataarray) { + $ahsisd = &$thisfile_riff['AVI ']['hdrl']['strl']['indx'][$streamnumber]['data']; + + $thisfile_riff_raw['indx'][$streamnumber]['wLongsPerEntry'] = $this->EitherEndian2Int(substr($ahsisd, 0, 2)); + $thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType'] = $this->EitherEndian2Int(substr($ahsisd, 2, 1)); + $thisfile_riff_raw['indx'][$streamnumber]['bIndexType'] = $this->EitherEndian2Int(substr($ahsisd, 3, 1)); + $thisfile_riff_raw['indx'][$streamnumber]['nEntriesInUse'] = $this->EitherEndian2Int(substr($ahsisd, 4, 4)); + $thisfile_riff_raw['indx'][$streamnumber]['dwChunkId'] = substr($ahsisd, 8, 4); + $thisfile_riff_raw['indx'][$streamnumber]['dwReserved'] = $this->EitherEndian2Int(substr($ahsisd, 12, 4)); + + //$thisfile_riff_raw['indx'][$streamnumber]['bIndexType_name'] = $bIndexType[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']]; + //$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType_name'] = $bIndexSubtype[$thisfile_riff_raw['indx'][$streamnumber]['bIndexType']][$thisfile_riff_raw['indx'][$streamnumber]['bIndexSubType']]; + + unset($ahsisd); + } + } + if (isset($thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data'])) { + $avihData = $thisfile_riff['AVI ']['hdrl']['avih'][$streamindex]['data']; + + // shortcut + $thisfile_riff_raw['avih'] = array(); + $thisfile_riff_raw_avih = &$thisfile_riff_raw['avih']; + + $thisfile_riff_raw_avih['dwMicroSecPerFrame'] = $this->EitherEndian2Int(substr($avihData, 0, 4)); // frame display rate (or 0L) + if ($thisfile_riff_raw_avih['dwMicroSecPerFrame'] == 0) { + $this->error('Corrupt RIFF file: avih.dwMicroSecPerFrame == zero'); + return false; + } + + $flags = array( + 'dwMaxBytesPerSec', // max. transfer rate + 'dwPaddingGranularity', // pad to multiples of this size; normally 2K. + 'dwFlags', // the ever-present flags + 'dwTotalFrames', // # frames in file + 'dwInitialFrames', // + 'dwStreams', // + 'dwSuggestedBufferSize', // + 'dwWidth', // + 'dwHeight', // + 'dwScale', // + 'dwRate', // + 'dwStart', // + 'dwLength', // + ); + $avih_offset = 4; + foreach ($flags as $flag) { + $thisfile_riff_raw_avih[$flag] = $this->EitherEndian2Int(substr($avihData, $avih_offset, 4)); + $avih_offset += 4; + } + + $flags = array( + 'hasindex' => 0x00000010, + 'mustuseindex' => 0x00000020, + 'interleaved' => 0x00000100, + 'trustcktype' => 0x00000800, + 'capturedfile' => 0x00010000, + 'copyrighted' => 0x00020010, + ); + foreach ($flags as $flag => $value) { + $thisfile_riff_raw_avih['flags'][$flag] = (bool) ($thisfile_riff_raw_avih['dwFlags'] & $value); + } + + // shortcut + $thisfile_riff_video[$streamindex] = array(); + /** @var array $thisfile_riff_video_current */ + $thisfile_riff_video_current = &$thisfile_riff_video[$streamindex]; + + if ($thisfile_riff_raw_avih['dwWidth'] > 0) { + $thisfile_riff_video_current['frame_width'] = $thisfile_riff_raw_avih['dwWidth']; + $thisfile_video['resolution_x'] = $thisfile_riff_video_current['frame_width']; + } + if ($thisfile_riff_raw_avih['dwHeight'] > 0) { + $thisfile_riff_video_current['frame_height'] = $thisfile_riff_raw_avih['dwHeight']; + $thisfile_video['resolution_y'] = $thisfile_riff_video_current['frame_height']; + } + if ($thisfile_riff_raw_avih['dwTotalFrames'] > 0) { + $thisfile_riff_video_current['total_frames'] = $thisfile_riff_raw_avih['dwTotalFrames']; + $thisfile_video['total_frames'] = $thisfile_riff_video_current['total_frames']; + } + + $thisfile_riff_video_current['frame_rate'] = round(1000000 / $thisfile_riff_raw_avih['dwMicroSecPerFrame'], 3); + $thisfile_video['frame_rate'] = $thisfile_riff_video_current['frame_rate']; + } + if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][0]['data'])) { + if (is_array($thisfile_riff['AVI ']['hdrl']['strl']['strh'])) { + $thisfile_riff_raw_strf_strhfccType_streamindex = null; + for ($i = 0; $i < count($thisfile_riff['AVI ']['hdrl']['strl']['strh']); $i++) { + if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data'])) { + $strhData = $thisfile_riff['AVI ']['hdrl']['strl']['strh'][$i]['data']; + $strhfccType = substr($strhData, 0, 4); + + if (isset($thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data'])) { + $strfData = $thisfile_riff['AVI ']['hdrl']['strl']['strf'][$i]['data']; + + if (!isset($thisfile_riff_raw['strf'][$strhfccType][$streamindex])) { + $thisfile_riff_raw['strf'][$strhfccType][$streamindex] = null; + } + // shortcut + $thisfile_riff_raw_strf_strhfccType_streamindex = &$thisfile_riff_raw['strf'][$strhfccType][$streamindex]; + + switch ($strhfccType) { + case 'auds': + $thisfile_audio['bitrate_mode'] = 'cbr'; + $thisfile_audio_dataformat = 'wav'; + if (isset($thisfile_riff_audio) && is_array($thisfile_riff_audio)) { + $streamindex = count($thisfile_riff_audio); + } + + $thisfile_riff_audio[$streamindex] = self::parseWAVEFORMATex($strfData); + $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag']; + + // shortcut + $thisfile_audio['streams'][$streamindex] = $thisfile_riff_audio[$streamindex]; + $thisfile_audio_streams_currentstream = &$thisfile_audio['streams'][$streamindex]; + + if ($thisfile_audio_streams_currentstream['bits_per_sample'] == 0) { + unset($thisfile_audio_streams_currentstream['bits_per_sample']); + } + $thisfile_audio_streams_currentstream['wformattag'] = $thisfile_audio_streams_currentstream['raw']['wFormatTag']; + unset($thisfile_audio_streams_currentstream['raw']); + + // shortcut + $thisfile_riff_raw['strf'][$strhfccType][$streamindex] = $thisfile_riff_audio[$streamindex]['raw']; + + unset($thisfile_riff_audio[$streamindex]['raw']); + $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]); + + $thisfile_audio['lossless'] = false; + switch ($thisfile_riff_raw_strf_strhfccType_streamindex['wFormatTag']) { + case 0x0001: // PCM + $thisfile_audio_dataformat = 'wav'; + $thisfile_audio['lossless'] = true; + break; + + case 0x0050: // MPEG Layer 2 or Layer 1 + $thisfile_audio_dataformat = 'mp2'; // Assume Layer-2 + break; + + case 0x0055: // MPEG Layer 3 + $thisfile_audio_dataformat = 'mp3'; + break; + + case 0x00FF: // AAC + $thisfile_audio_dataformat = 'aac'; + break; + + case 0x0161: // Windows Media v7 / v8 / v9 + case 0x0162: // Windows Media Professional v9 + case 0x0163: // Windows Media Lossess v9 + $thisfile_audio_dataformat = 'wma'; + break; + + case 0x2000: // AC-3 + $thisfile_audio_dataformat = 'ac3'; + break; + + case 0x2001: // DTS + $thisfile_audio_dataformat = 'dts'; + break; + + default: + $thisfile_audio_dataformat = 'wav'; + break; + } + $thisfile_audio_streams_currentstream['dataformat'] = $thisfile_audio_dataformat; + $thisfile_audio_streams_currentstream['lossless'] = $thisfile_audio['lossless']; + $thisfile_audio_streams_currentstream['bitrate_mode'] = $thisfile_audio['bitrate_mode']; + break; + + + case 'iavs': + case 'vids': + // shortcut + $thisfile_riff_raw['strh'][$i] = array(); + $thisfile_riff_raw_strh_current = &$thisfile_riff_raw['strh'][$i]; + + $thisfile_riff_raw_strh_current['fccType'] = substr($strhData, 0, 4); // same as $strhfccType; + $thisfile_riff_raw_strh_current['fccHandler'] = substr($strhData, 4, 4); + $thisfile_riff_raw_strh_current['dwFlags'] = $this->EitherEndian2Int(substr($strhData, 8, 4)); // Contains AVITF_* flags + $thisfile_riff_raw_strh_current['wPriority'] = $this->EitherEndian2Int(substr($strhData, 12, 2)); + $thisfile_riff_raw_strh_current['wLanguage'] = $this->EitherEndian2Int(substr($strhData, 14, 2)); + $thisfile_riff_raw_strh_current['dwInitialFrames'] = $this->EitherEndian2Int(substr($strhData, 16, 4)); + $thisfile_riff_raw_strh_current['dwScale'] = $this->EitherEndian2Int(substr($strhData, 20, 4)); + $thisfile_riff_raw_strh_current['dwRate'] = $this->EitherEndian2Int(substr($strhData, 24, 4)); + $thisfile_riff_raw_strh_current['dwStart'] = $this->EitherEndian2Int(substr($strhData, 28, 4)); + $thisfile_riff_raw_strh_current['dwLength'] = $this->EitherEndian2Int(substr($strhData, 32, 4)); + $thisfile_riff_raw_strh_current['dwSuggestedBufferSize'] = $this->EitherEndian2Int(substr($strhData, 36, 4)); + $thisfile_riff_raw_strh_current['dwQuality'] = $this->EitherEndian2Int(substr($strhData, 40, 4)); + $thisfile_riff_raw_strh_current['dwSampleSize'] = $this->EitherEndian2Int(substr($strhData, 44, 4)); + $thisfile_riff_raw_strh_current['rcFrame'] = $this->EitherEndian2Int(substr($strhData, 48, 4)); + + $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_riff_raw_strh_current['fccHandler']); + $thisfile_video['fourcc'] = $thisfile_riff_raw_strh_current['fccHandler']; + if (!$thisfile_riff_video_current['codec'] && isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) && self::fourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) { + $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']); + $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']; + } + $thisfile_video['codec'] = $thisfile_riff_video_current['codec']; + $thisfile_video['pixel_aspect_ratio'] = (float) 1; + switch ($thisfile_riff_raw_strh_current['fccHandler']) { + case 'HFYU': // Huffman Lossless Codec + case 'IRAW': // Intel YUV Uncompressed + case 'YUY2': // Uncompressed YUV 4:2:2 + $thisfile_video['lossless'] = true; + break; + + default: + $thisfile_video['lossless'] = false; + break; + } + + switch ($strhfccType) { + case 'vids': + $thisfile_riff_raw_strf_strhfccType_streamindex = self::ParseBITMAPINFOHEADER(substr($strfData, 0, 40), ($this->container == 'riff')); + $thisfile_video['bits_per_sample'] = $thisfile_riff_raw_strf_strhfccType_streamindex['biBitCount']; + + if ($thisfile_riff_video_current['codec'] == 'DV') { + $thisfile_riff_video_current['dv_type'] = 2; + } + break; + + case 'iavs': + $thisfile_riff_video_current['dv_type'] = 1; + break; + } + break; + + default: + $this->warning('Unhandled fccType for stream ('.$i.'): "'.$strhfccType.'"'); + break; + + } + } + } + + if (isset($thisfile_riff_raw_strf_strhfccType_streamindex) && isset($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc'])) { + + $thisfile_video['fourcc'] = $thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']; + if (self::fourccLookup($thisfile_video['fourcc'])) { + $thisfile_riff_video_current['codec'] = self::fourccLookup($thisfile_video['fourcc']); + $thisfile_video['codec'] = $thisfile_riff_video_current['codec']; + } + + switch ($thisfile_riff_raw_strf_strhfccType_streamindex['fourcc']) { + case 'HFYU': // Huffman Lossless Codec + case 'IRAW': // Intel YUV Uncompressed + case 'YUY2': // Uncompressed YUV 4:2:2 + $thisfile_video['lossless'] = true; + //$thisfile_video['bits_per_sample'] = 24; + break; + + default: + $thisfile_video['lossless'] = false; + //$thisfile_video['bits_per_sample'] = 24; + break; + } + + } + } + } + } + break; + + + case 'AMV ': + $info['fileformat'] = 'amv'; + $info['mime_type'] = 'video/amv'; + + $thisfile_video['bitrate_mode'] = 'vbr'; // it's MJPEG, presumably contant-quality encoding, thereby VBR + $thisfile_video['dataformat'] = 'mjpeg'; + $thisfile_video['codec'] = 'mjpeg'; + $thisfile_video['lossless'] = false; + $thisfile_video['bits_per_sample'] = 24; + + $thisfile_audio['dataformat'] = 'adpcm'; + $thisfile_audio['lossless'] = false; + break; + + + // http://en.wikipedia.org/wiki/CD-DA + case 'CDDA': + $info['fileformat'] = 'cda'; + unset($info['mime_type']); + + $thisfile_audio_dataformat = 'cda'; + + $info['avdataoffset'] = 44; + + if (isset($thisfile_riff['CDDA']['fmt '][0]['data'])) { + // shortcut + $thisfile_riff_CDDA_fmt_0 = &$thisfile_riff['CDDA']['fmt '][0]; + + $thisfile_riff_CDDA_fmt_0['unknown1'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 0, 2)); + $thisfile_riff_CDDA_fmt_0['track_num'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 2, 2)); + $thisfile_riff_CDDA_fmt_0['disc_id'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 4, 4)); + $thisfile_riff_CDDA_fmt_0['start_offset_frame'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 8, 4)); + $thisfile_riff_CDDA_fmt_0['playtime_frames'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 12, 4)); + $thisfile_riff_CDDA_fmt_0['unknown6'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 16, 4)); + $thisfile_riff_CDDA_fmt_0['unknown7'] = $this->EitherEndian2Int(substr($thisfile_riff_CDDA_fmt_0['data'], 20, 4)); + + $thisfile_riff_CDDA_fmt_0['start_offset_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['start_offset_frame'] / 75; + $thisfile_riff_CDDA_fmt_0['playtime_seconds'] = (float) $thisfile_riff_CDDA_fmt_0['playtime_frames'] / 75; + $info['comments']['track_number'] = $thisfile_riff_CDDA_fmt_0['track_num']; + $info['playtime_seconds'] = $thisfile_riff_CDDA_fmt_0['playtime_seconds']; + + // hardcoded data for CD-audio + $thisfile_audio['lossless'] = true; + $thisfile_audio['sample_rate'] = 44100; + $thisfile_audio['channels'] = 2; + $thisfile_audio['bits_per_sample'] = 16; + $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $thisfile_audio['channels'] * $thisfile_audio['bits_per_sample']; + $thisfile_audio['bitrate_mode'] = 'cbr'; + } + break; + + // http://en.wikipedia.org/wiki/AIFF + case 'AIFF': + case 'AIFC': + $info['fileformat'] = 'aiff'; + $info['mime_type'] = 'audio/x-aiff'; + + $thisfile_audio['bitrate_mode'] = 'cbr'; + $thisfile_audio_dataformat = 'aiff'; + $thisfile_audio['lossless'] = true; + + if (isset($thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'])) { + $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['SSND'][0]['offset'] + 8; + $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['SSND'][0]['size']; + if ($info['avdataend'] > $info['filesize']) { + if (($info['avdataend'] == ($info['filesize'] + 1)) && (($info['filesize'] % 2) == 1)) { + // structures rounded to 2-byte boundary, but dumb encoders + // forget to pad end of file to make this actually work + } else { + $this->warning('Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['SSND'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found'); + } + $info['avdataend'] = $info['filesize']; + } + } + + if (isset($thisfile_riff[$RIFFsubtype]['COMM'][0]['data'])) { + + // shortcut + $thisfile_riff_RIFFsubtype_COMM_0_data = &$thisfile_riff[$RIFFsubtype]['COMM'][0]['data']; + + $thisfile_riff_audio['channels'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 0, 2), true); + $thisfile_riff_audio['total_samples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 2, 4), false); + $thisfile_riff_audio['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 6, 2), true); + $thisfile_riff_audio['sample_rate'] = (int) getid3_lib::BigEndian2Float(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 8, 10)); + + if ($thisfile_riff[$RIFFsubtype]['COMM'][0]['size'] > 18) { + $thisfile_riff_audio['codec_fourcc'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 18, 4); + $CodecNameSize = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_COMM_0_data, 22, 1), false); + $thisfile_riff_audio['codec_name'] = substr($thisfile_riff_RIFFsubtype_COMM_0_data, 23, $CodecNameSize); + switch ($thisfile_riff_audio['codec_name']) { + case 'NONE': + $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)'; + $thisfile_audio['lossless'] = true; + break; + + case '': + switch ($thisfile_riff_audio['codec_fourcc']) { + // http://developer.apple.com/qa/snd/snd07.html + case 'sowt': + $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Little-Endian PCM'; + $thisfile_audio['lossless'] = true; + break; + + case 'twos': + $thisfile_riff_audio['codec_name'] = 'Two\'s Compliment Big-Endian PCM'; + $thisfile_audio['lossless'] = true; + break; + + default: + break; + } + break; + + default: + $thisfile_audio['codec'] = $thisfile_riff_audio['codec_name']; + $thisfile_audio['lossless'] = false; + break; + } + } + + $thisfile_audio['channels'] = $thisfile_riff_audio['channels']; + if ($thisfile_riff_audio['bits_per_sample'] > 0) { + $thisfile_audio['bits_per_sample'] = $thisfile_riff_audio['bits_per_sample']; + } + $thisfile_audio['sample_rate'] = $thisfile_riff_audio['sample_rate']; + if ($thisfile_audio['sample_rate'] == 0) { + $this->error('Corrupted AIFF file: sample_rate == zero'); + return false; + } + $info['playtime_seconds'] = $thisfile_riff_audio['total_samples'] / $thisfile_audio['sample_rate']; + } + + if (isset($thisfile_riff[$RIFFsubtype]['COMT'])) { + $offset = 0; + $CommentCount = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false); + $offset += 2; + for ($i = 0; $i < $CommentCount; $i++) { + $info['comments_raw'][$i]['timestamp'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 4), false); + $offset += 4; + $info['comments_raw'][$i]['marker_id'] = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), true); + $offset += 2; + $CommentLength = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, 2), false); + $offset += 2; + $info['comments_raw'][$i]['comment'] = substr($thisfile_riff[$RIFFsubtype]['COMT'][0]['data'], $offset, $CommentLength); + $offset += $CommentLength; + + $info['comments_raw'][$i]['timestamp_unix'] = getid3_lib::DateMac2Unix($info['comments_raw'][$i]['timestamp']); + $thisfile_riff['comments']['comment'][] = $info['comments_raw'][$i]['comment']; + } + } + + $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment'); + foreach ($CommentsChunkNames as $key => $value) { + if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) { + $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data']; + } + } +/* + if (isset($thisfile_riff[$RIFFsubtype]['ID3 '])) { + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_id3v2 = new getid3_id3v2($getid3_temp); + $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['ID3 '][0]['offset'] + 8; + if ($thisfile_riff[$RIFFsubtype]['ID3 '][0]['valid'] = $getid3_id3v2->Analyze()) { + $info['id3v2'] = $getid3_temp->info['id3v2']; + } + unset($getid3_temp, $getid3_id3v2); + } +*/ + break; + + // http://en.wikipedia.org/wiki/8SVX + case '8SVX': + $info['fileformat'] = '8svx'; + $info['mime_type'] = 'audio/8svx'; + + $thisfile_audio['bitrate_mode'] = 'cbr'; + $thisfile_audio_dataformat = '8svx'; + $thisfile_audio['bits_per_sample'] = 8; + $thisfile_audio['channels'] = 1; // overridden below, if need be + $ActualBitsPerSample = 0; + + if (isset($thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'])) { + $info['avdataoffset'] = $thisfile_riff[$RIFFsubtype]['BODY'][0]['offset'] + 8; + $info['avdataend'] = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['BODY'][0]['size']; + if ($info['avdataend'] > $info['filesize']) { + $this->warning('Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['BODY'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found'); + } + } + + if (isset($thisfile_riff[$RIFFsubtype]['VHDR'][0]['offset'])) { + // shortcut + $thisfile_riff_RIFFsubtype_VHDR_0 = &$thisfile_riff[$RIFFsubtype]['VHDR'][0]; + + $thisfile_riff_RIFFsubtype_VHDR_0['oneShotHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 0, 4)); + $thisfile_riff_RIFFsubtype_VHDR_0['repeatHiSamples'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 4, 4)); + $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerHiCycle'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 8, 4)); + $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 12, 2)); + $thisfile_riff_RIFFsubtype_VHDR_0['ctOctave'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 14, 1)); + $thisfile_riff_RIFFsubtype_VHDR_0['sCompression'] = getid3_lib::BigEndian2Int(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 15, 1)); + $thisfile_riff_RIFFsubtype_VHDR_0['Volume'] = getid3_lib::FixedPoint16_16(substr($thisfile_riff_RIFFsubtype_VHDR_0['data'], 16, 4)); + + $thisfile_audio['sample_rate'] = $thisfile_riff_RIFFsubtype_VHDR_0['samplesPerSec']; + + switch ($thisfile_riff_RIFFsubtype_VHDR_0['sCompression']) { + case 0: + $thisfile_audio['codec'] = 'Pulse Code Modulation (PCM)'; + $thisfile_audio['lossless'] = true; + $ActualBitsPerSample = 8; + break; + + case 1: + $thisfile_audio['codec'] = 'Fibonacci-delta encoding'; + $thisfile_audio['lossless'] = false; + $ActualBitsPerSample = 4; + break; + + default: + $this->warning('Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "'.$thisfile_riff_RIFFsubtype_VHDR_0['sCompression'].'"'); + break; + } + } + + if (isset($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'])) { + $ChannelsIndex = getid3_lib::BigEndian2Int(substr($thisfile_riff[$RIFFsubtype]['CHAN'][0]['data'], 0, 4)); + switch ($ChannelsIndex) { + case 6: // Stereo + $thisfile_audio['channels'] = 2; + break; + + case 2: // Left channel only + case 4: // Right channel only + $thisfile_audio['channels'] = 1; + break; + + default: + $this->warning('Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "'.$ChannelsIndex.'"'); + break; + } + + } + + $CommentsChunkNames = array('NAME'=>'title', 'author'=>'artist', '(c) '=>'copyright', 'ANNO'=>'comment'); + foreach ($CommentsChunkNames as $key => $value) { + if (isset($thisfile_riff[$RIFFsubtype][$key][0]['data'])) { + $thisfile_riff['comments'][$value][] = $thisfile_riff[$RIFFsubtype][$key][0]['data']; + } + } + + $thisfile_audio['bitrate'] = $thisfile_audio['sample_rate'] * $ActualBitsPerSample * $thisfile_audio['channels']; + if (!empty($thisfile_audio['bitrate'])) { + $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($thisfile_audio['bitrate'] / 8); + } + break; + + case 'CDXA': + $info['fileformat'] = 'vcd'; // Asume Video CD + $info['mime_type'] = 'video/mpeg'; + + if (!empty($thisfile_riff['CDXA']['data'][0]['size'])) { + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.mpeg.php', __FILE__, true); + + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_mpeg = new getid3_mpeg($getid3_temp); + $getid3_mpeg->Analyze(); + if (empty($getid3_temp->info['error'])) { + $info['audio'] = $getid3_temp->info['audio']; + $info['video'] = $getid3_temp->info['video']; + $info['mpeg'] = $getid3_temp->info['mpeg']; + $info['warning'] = $getid3_temp->info['warning']; + } + unset($getid3_temp, $getid3_mpeg); + } + break; + + case 'WEBP': + // https://developers.google.com/speed/webp/docs/riff_container + // https://tools.ietf.org/html/rfc6386 + // https://chromium.googlesource.com/webm/libwebp/+/master/doc/webp-lossless-bitstream-spec.txt + $info['fileformat'] = 'webp'; + $info['mime_type'] = 'image/webp'; + + if (!empty($thisfile_riff['WEBP']['VP8 '][0]['size'])) { + $old_offset = $this->ftell(); + $this->fseek($thisfile_riff['WEBP']['VP8 '][0]['offset'] + 8); // 4 bytes "VP8 " + 4 bytes chunk size + $WEBP_VP8_header = $this->fread(10); + $this->fseek($old_offset); + if (substr($WEBP_VP8_header, 3, 3) == "\x9D\x01\x2A") { + $thisfile_riff['WEBP']['VP8 '][0]['keyframe'] = !(getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 0, 3)) & 0x800000); + $thisfile_riff['WEBP']['VP8 '][0]['version'] = (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 0, 3)) & 0x700000) >> 20; + $thisfile_riff['WEBP']['VP8 '][0]['show_frame'] = (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 0, 3)) & 0x080000); + $thisfile_riff['WEBP']['VP8 '][0]['data_bytes'] = (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 0, 3)) & 0x07FFFF) >> 0; + + $thisfile_riff['WEBP']['VP8 '][0]['scale_x'] = (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 6, 2)) & 0xC000) >> 14; + $thisfile_riff['WEBP']['VP8 '][0]['width'] = (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 6, 2)) & 0x3FFF); + $thisfile_riff['WEBP']['VP8 '][0]['scale_y'] = (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 8, 2)) & 0xC000) >> 14; + $thisfile_riff['WEBP']['VP8 '][0]['height'] = (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 8, 2)) & 0x3FFF); + + $info['video']['resolution_x'] = $thisfile_riff['WEBP']['VP8 '][0]['width']; + $info['video']['resolution_y'] = $thisfile_riff['WEBP']['VP8 '][0]['height']; + } else { + $this->error('Expecting 9D 01 2A at offset '.($thisfile_riff['WEBP']['VP8 '][0]['offset'] + 8 + 3).', found "'.getid3_lib::PrintHexBytes(substr($WEBP_VP8_header, 3, 3)).'"'); + } + + } + if (!empty($thisfile_riff['WEBP']['VP8L'][0]['size'])) { + $old_offset = $this->ftell(); + $this->fseek($thisfile_riff['WEBP']['VP8L'][0]['offset'] + 8); // 4 bytes "VP8L" + 4 bytes chunk size + $WEBP_VP8L_header = $this->fread(10); + $this->fseek($old_offset); + if (substr($WEBP_VP8L_header, 0, 1) == "\x2F") { + $width_height_flags = getid3_lib::LittleEndian2Bin(substr($WEBP_VP8L_header, 1, 4)); + $thisfile_riff['WEBP']['VP8L'][0]['width'] = bindec(substr($width_height_flags, 18, 14)) + 1; + $thisfile_riff['WEBP']['VP8L'][0]['height'] = bindec(substr($width_height_flags, 4, 14)) + 1; + $thisfile_riff['WEBP']['VP8L'][0]['alpha_is_used'] = (bool) bindec(substr($width_height_flags, 3, 1)); + $thisfile_riff['WEBP']['VP8L'][0]['version'] = bindec(substr($width_height_flags, 0, 3)); + + $info['video']['resolution_x'] = $thisfile_riff['WEBP']['VP8L'][0]['width']; + $info['video']['resolution_y'] = $thisfile_riff['WEBP']['VP8L'][0]['height']; + } else { + $this->error('Expecting 2F at offset '.($thisfile_riff['WEBP']['VP8L'][0]['offset'] + 8).', found "'.getid3_lib::PrintHexBytes(substr($WEBP_VP8L_header, 0, 1)).'"'); + } + + } + break; + + default: + $this->error('Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA|WEBP), found "'.$RIFFsubtype.'" instead'); + //unset($info['fileformat']); + } + + switch ($RIFFsubtype) { + case 'WAVE': + case 'AIFF': + case 'AIFC': + $ID3v2_key_good = 'id3 '; + $ID3v2_keys_bad = array('ID3 ', 'tag '); + foreach ($ID3v2_keys_bad as $ID3v2_key_bad) { + if (isset($thisfile_riff[$RIFFsubtype][$ID3v2_key_bad]) && !array_key_exists($ID3v2_key_good, $thisfile_riff[$RIFFsubtype])) { + $thisfile_riff[$RIFFsubtype][$ID3v2_key_good] = $thisfile_riff[$RIFFsubtype][$ID3v2_key_bad]; + $this->warning('mapping "'.$ID3v2_key_bad.'" chunk to "'.$ID3v2_key_good.'"'); + } + } + + if (isset($thisfile_riff[$RIFFsubtype]['id3 '])) { + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); + + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_id3v2 = new getid3_id3v2($getid3_temp); + $getid3_id3v2->StartingOffset = $thisfile_riff[$RIFFsubtype]['id3 '][0]['offset'] + 8; + if ($thisfile_riff[$RIFFsubtype]['id3 '][0]['valid'] = $getid3_id3v2->Analyze()) { + $info['id3v2'] = $getid3_temp->info['id3v2']; + } + unset($getid3_temp, $getid3_id3v2); + } + break; + } + + if (isset($thisfile_riff_WAVE['DISP']) && is_array($thisfile_riff_WAVE['DISP'])) { + $thisfile_riff['comments']['title'][] = trim(substr($thisfile_riff_WAVE['DISP'][count($thisfile_riff_WAVE['DISP']) - 1]['data'], 4)); + } + if (isset($thisfile_riff_WAVE['INFO']) && is_array($thisfile_riff_WAVE['INFO'])) { + self::parseComments($thisfile_riff_WAVE['INFO'], $thisfile_riff['comments']); + } + if (isset($thisfile_riff['AVI ']['INFO']) && is_array($thisfile_riff['AVI ']['INFO'])) { + self::parseComments($thisfile_riff['AVI ']['INFO'], $thisfile_riff['comments']); + } + + if (empty($thisfile_audio['encoder']) && !empty($info['mpeg']['audio']['LAME']['short_version'])) { + $thisfile_audio['encoder'] = $info['mpeg']['audio']['LAME']['short_version']; + } + + if (!isset($info['playtime_seconds'])) { + $info['playtime_seconds'] = 0; + } + if (isset($thisfile_riff_raw['strh'][0]['dwLength']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) { // @phpstan-ignore-line + // needed for >2GB AVIs where 'avih' chunk only lists number of frames in that chunk, not entire movie + $info['playtime_seconds'] = $thisfile_riff_raw['strh'][0]['dwLength'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000); + } elseif (isset($thisfile_riff_raw['avih']['dwTotalFrames']) && isset($thisfile_riff_raw['avih']['dwMicroSecPerFrame'])) { // @phpstan-ignore-line + $info['playtime_seconds'] = $thisfile_riff_raw['avih']['dwTotalFrames'] * ($thisfile_riff_raw['avih']['dwMicroSecPerFrame'] / 1000000); + } + + if ($info['playtime_seconds'] > 0) { + if (isset($thisfile_riff_audio) && isset($thisfile_riff_video)) { + + if (!isset($info['bitrate'])) { + $info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8); + } + + } elseif (isset($thisfile_riff_audio) && !isset($thisfile_riff_video)) { + + if (!isset($thisfile_audio['bitrate'])) { + $thisfile_audio['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8); + } + + } elseif (!isset($thisfile_riff_audio) && isset($thisfile_riff_video)) { + + if (!isset($thisfile_video['bitrate'])) { + $thisfile_video['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8); + } + + } + } + + + if (isset($thisfile_riff_video) && isset($thisfile_audio['bitrate']) && ($thisfile_audio['bitrate'] > 0) && ($info['playtime_seconds'] > 0)) { + + $info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8); + $thisfile_audio['bitrate'] = 0; + $thisfile_video['bitrate'] = $info['bitrate']; + foreach ($thisfile_riff_audio as $channelnumber => $audioinfoarray) { + $thisfile_video['bitrate'] -= $audioinfoarray['bitrate']; + $thisfile_audio['bitrate'] += $audioinfoarray['bitrate']; + } + if ($thisfile_video['bitrate'] <= 0) { + unset($thisfile_video['bitrate']); + } + if ($thisfile_audio['bitrate'] <= 0) { + unset($thisfile_audio['bitrate']); + } + } + + if (isset($info['mpeg']['audio'])) { + $thisfile_audio_dataformat = 'mp'.$info['mpeg']['audio']['layer']; + $thisfile_audio['sample_rate'] = $info['mpeg']['audio']['sample_rate']; + $thisfile_audio['channels'] = $info['mpeg']['audio']['channels']; + $thisfile_audio['bitrate'] = $info['mpeg']['audio']['bitrate']; + $thisfile_audio['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); + if (!empty($info['mpeg']['audio']['codec'])) { + $thisfile_audio['codec'] = $info['mpeg']['audio']['codec'].' '.$thisfile_audio['codec']; + } + if (!empty($thisfile_audio['streams'])) { + foreach ($thisfile_audio['streams'] as $streamnumber => $streamdata) { + if ($streamdata['dataformat'] == $thisfile_audio_dataformat) { + $thisfile_audio['streams'][$streamnumber]['sample_rate'] = $thisfile_audio['sample_rate']; + $thisfile_audio['streams'][$streamnumber]['channels'] = $thisfile_audio['channels']; + $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate']; + $thisfile_audio['streams'][$streamnumber]['bitrate_mode'] = $thisfile_audio['bitrate_mode']; + $thisfile_audio['streams'][$streamnumber]['codec'] = $thisfile_audio['codec']; + } + } + } + $getid3_mp3 = new getid3_mp3($this->getid3); + $thisfile_audio['encoder_options'] = $getid3_mp3->GuessEncoderOptions(); + unset($getid3_mp3); + } + + + if (!empty($thisfile_riff_raw['fmt ']['wBitsPerSample']) && ($thisfile_riff_raw['fmt ']['wBitsPerSample'] > 0)) { + switch ($thisfile_audio_dataformat) { + case 'ac3': + // ignore bits_per_sample + break; + + default: + $thisfile_audio['bits_per_sample'] = $thisfile_riff_raw['fmt ']['wBitsPerSample']; + break; + } + } + + + if (empty($thisfile_riff_raw)) { + unset($thisfile_riff['raw']); + } + if (empty($thisfile_riff_audio)) { + unset($thisfile_riff['audio']); + } + if (empty($thisfile_riff_video)) { + unset($thisfile_riff['video']); + } + + return true; + } + + /** + * @param int $startoffset + * @param int $maxoffset + * + * @return array|false + * + * @throws Exception + * @throws getid3_exception + */ + public function ParseRIFFAMV($startoffset, $maxoffset) { + // AMV files are RIFF-AVI files with parts of the spec deliberately broken, such as chunk size fields hardcoded to zero (because players known in hardware that these fields are always a certain size + + // https://code.google.com/p/amv-codec-tools/wiki/AmvDocumentation + //typedef struct _amvmainheader { + //FOURCC fcc; // 'amvh' + //DWORD cb; + //DWORD dwMicroSecPerFrame; + //BYTE reserve[28]; + //DWORD dwWidth; + //DWORD dwHeight; + //DWORD dwSpeed; + //DWORD reserve0; + //DWORD reserve1; + //BYTE bTimeSec; + //BYTE bTimeMin; + //WORD wTimeHour; + //} AMVMAINHEADER; + + $info = &$this->getid3->info; + $RIFFchunk = false; + + try { + + $this->fseek($startoffset); + $maxoffset = min($maxoffset, $info['avdataend']); + $AMVheader = $this->fread(284); + if (substr($AMVheader, 0, 8) != 'hdrlamvh') { + throw new Exception('expecting "hdrlamv" at offset '.($startoffset + 0).', found "'.substr($AMVheader, 0, 8).'"'); + } + if (substr($AMVheader, 8, 4) != "\x38\x00\x00\x00") { // "amvh" chunk size, hardcoded to 0x38 = 56 bytes + throw new Exception('expecting "0x38000000" at offset '.($startoffset + 8).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 8, 4)).'"'); + } + $RIFFchunk = array(); + $RIFFchunk['amvh']['us_per_frame'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 12, 4)); + $RIFFchunk['amvh']['reserved28'] = substr($AMVheader, 16, 28); // null? reserved? + $RIFFchunk['amvh']['resolution_x'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 44, 4)); + $RIFFchunk['amvh']['resolution_y'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 48, 4)); + $RIFFchunk['amvh']['frame_rate_int'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 52, 4)); + $RIFFchunk['amvh']['reserved0'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 56, 4)); // 1? reserved? + $RIFFchunk['amvh']['reserved1'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 60, 4)); // 0? reserved? + $RIFFchunk['amvh']['runtime_sec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 64, 1)); + $RIFFchunk['amvh']['runtime_min'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 65, 1)); + $RIFFchunk['amvh']['runtime_hrs'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 66, 2)); + + $info['video']['frame_rate'] = 1000000 / $RIFFchunk['amvh']['us_per_frame']; + $info['video']['resolution_x'] = $RIFFchunk['amvh']['resolution_x']; + $info['video']['resolution_y'] = $RIFFchunk['amvh']['resolution_y']; + $info['playtime_seconds'] = ($RIFFchunk['amvh']['runtime_hrs'] * 3600) + ($RIFFchunk['amvh']['runtime_min'] * 60) + $RIFFchunk['amvh']['runtime_sec']; + + // the rest is all hardcoded(?) and does not appear to be useful until you get to audio info at offset 256, even then everything is probably hardcoded + + if (substr($AMVheader, 68, 20) != 'LIST'."\x00\x00\x00\x00".'strlstrh'."\x38\x00\x00\x00") { + throw new Exception('expecting "LIST<0x00000000>strlstrh<0x38000000>" at offset '.($startoffset + 68).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 68, 20)).'"'); + } + // followed by 56 bytes of null: substr($AMVheader, 88, 56) -> 144 + if (substr($AMVheader, 144, 8) != 'strf'."\x24\x00\x00\x00") { + throw new Exception('expecting "strf<0x24000000>" at offset '.($startoffset + 144).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 144, 8)).'"'); + } + // followed by 36 bytes of null: substr($AMVheader, 144, 36) -> 180 + + if (substr($AMVheader, 188, 20) != 'LIST'."\x00\x00\x00\x00".'strlstrh'."\x30\x00\x00\x00") { + throw new Exception('expecting "LIST<0x00000000>strlstrh<0x30000000>" at offset '.($startoffset + 188).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 188, 20)).'"'); + } + // followed by 48 bytes of null: substr($AMVheader, 208, 48) -> 256 + if (substr($AMVheader, 256, 8) != 'strf'."\x14\x00\x00\x00") { + throw new Exception('expecting "strf<0x14000000>" at offset '.($startoffset + 256).', found "'.getid3_lib::PrintHexBytes(substr($AMVheader, 256, 8)).'"'); + } + // followed by 20 bytes of a modified WAVEFORMATEX: + // typedef struct { + // WORD wFormatTag; //(Fixme: this is equal to PCM's 0x01 format code) + // WORD nChannels; //(Fixme: this is always 1) + // DWORD nSamplesPerSec; //(Fixme: for all known sample files this is equal to 22050) + // DWORD nAvgBytesPerSec; //(Fixme: for all known sample files this is equal to 44100) + // WORD nBlockAlign; //(Fixme: this seems to be 2 in AMV files, is this correct ?) + // WORD wBitsPerSample; //(Fixme: this seems to be 16 in AMV files instead of the expected 4) + // WORD cbSize; //(Fixme: this seems to be 0 in AMV files) + // WORD reserved; + // } WAVEFORMATEX; + $RIFFchunk['strf']['wformattag'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 264, 2)); + $RIFFchunk['strf']['nchannels'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 266, 2)); + $RIFFchunk['strf']['nsamplespersec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 268, 4)); + $RIFFchunk['strf']['navgbytespersec'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 272, 4)); + $RIFFchunk['strf']['nblockalign'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 276, 2)); + $RIFFchunk['strf']['wbitspersample'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 278, 2)); + $RIFFchunk['strf']['cbsize'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 280, 2)); + $RIFFchunk['strf']['reserved'] = getid3_lib::LittleEndian2Int(substr($AMVheader, 282, 2)); + + + $info['audio']['lossless'] = false; + $info['audio']['sample_rate'] = $RIFFchunk['strf']['nsamplespersec']; + $info['audio']['channels'] = $RIFFchunk['strf']['nchannels']; + $info['audio']['bits_per_sample'] = $RIFFchunk['strf']['wbitspersample']; + $info['audio']['bitrate'] = $info['audio']['sample_rate'] * $info['audio']['channels'] * $info['audio']['bits_per_sample']; + $info['audio']['bitrate_mode'] = 'cbr'; + + + } catch (getid3_exception $e) { + if ($e->getCode() == 10) { + $this->warning('RIFFAMV parser: '.$e->getMessage()); + } else { + throw $e; + } + } + + return $RIFFchunk; + } + + /** + * @param int $startoffset + * @param int $maxoffset + * + * @return array|false + * @throws getid3_exception + */ + public function ParseRIFF($startoffset, $maxoffset) { + $info = &$this->getid3->info; + + $RIFFchunk = array(); + $FoundAllChunksWeNeed = false; + $LISTchunkParent = null; + $LISTchunkMaxOffset = null; + $AC3syncwordBytes = pack('n', getid3_ac3::syncword); // 0x0B77 -> "\x0B\x77" + + try { + $this->fseek($startoffset); + $maxoffset = min($maxoffset, $info['avdataend']); + while ($this->ftell() < $maxoffset) { + $chunknamesize = $this->fread(8); + //$chunkname = substr($chunknamesize, 0, 4); + $chunkname = str_replace("\x00", '_', substr($chunknamesize, 0, 4)); // note: chunk names of 4 null bytes do appear to be legal (has been observed inside INFO and PRMI chunks, for example), but makes traversing array keys more difficult + $chunksize = $this->EitherEndian2Int(substr($chunknamesize, 4, 4)); + //if (strlen(trim($chunkname, "\x00")) < 4) { + if (strlen($chunkname) < 4) { + $this->error('Expecting chunk name at offset '.($this->ftell() - 8).' but found nothing. Aborting RIFF parsing.'); + break; + } + if (($chunksize == 0) && ($chunkname != 'JUNK')) { + $this->warning('Chunk ('.$chunkname.') size at offset '.($this->ftell() - 4).' is zero. Aborting RIFF parsing.'); + break; + } + if (($chunksize % 2) != 0) { + // all structures are packed on word boundaries + $chunksize++; + } + + switch ($chunkname) { + case 'LIST': + $listname = $this->fread(4); + if (preg_match('#^(movi|rec )$#i', $listname)) { + $RIFFchunk[$listname]['offset'] = $this->ftell() - 4; + $RIFFchunk[$listname]['size'] = $chunksize; + + if (!$FoundAllChunksWeNeed) { + $WhereWeWere = $this->ftell(); + $AudioChunkHeader = $this->fread(12); + $AudioChunkStreamNum = substr($AudioChunkHeader, 0, 2); + $AudioChunkStreamType = substr($AudioChunkHeader, 2, 2); + $AudioChunkSize = getid3_lib::LittleEndian2Int(substr($AudioChunkHeader, 4, 4)); + + if ($AudioChunkStreamType == 'wb') { + $FirstFourBytes = substr($AudioChunkHeader, 8, 4); + if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', $FirstFourBytes)) { + // MP3 + if (getid3_mp3::MPEGaudioHeaderBytesValid($FirstFourBytes)) { + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_temp->info['avdataoffset'] = $this->ftell() - 4; + $getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize; + $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__); + $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false); + if (isset($getid3_temp->info['mpeg']['audio'])) { + $info['mpeg']['audio'] = $getid3_temp->info['mpeg']['audio']; + $info['audio'] = $getid3_temp->info['audio']; + $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer']; + $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; + $info['audio']['channels'] = $info['mpeg']['audio']['channels']; + $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; + $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); + //$info['bitrate'] = $info['audio']['bitrate']; + } + unset($getid3_temp, $getid3_mp3); + } + + } elseif (strpos($FirstFourBytes, $AC3syncwordBytes) === 0) { + // AC3 + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_temp->info['avdataoffset'] = $this->ftell() - 4; + $getid3_temp->info['avdataend'] = $this->ftell() + $AudioChunkSize; + $getid3_ac3 = new getid3_ac3($getid3_temp); + $getid3_ac3->Analyze(); + if (empty($getid3_temp->info['error'])) { + $info['audio'] = $getid3_temp->info['audio']; + $info['ac3'] = $getid3_temp->info['ac3']; + if (!empty($getid3_temp->info['warning'])) { + foreach ($getid3_temp->info['warning'] as $key => $value) { + $this->warning($value); + } + } + } + unset($getid3_temp, $getid3_ac3); + } + } + $FoundAllChunksWeNeed = true; + $this->fseek($WhereWeWere); + } + $this->fseek($chunksize - 4, SEEK_CUR); + + } else { + + if (!isset($RIFFchunk[$listname])) { + $RIFFchunk[$listname] = array(); + } + $LISTchunkParent = $listname; + $LISTchunkMaxOffset = $this->ftell() - 4 + $chunksize; + if ($parsedChunk = $this->ParseRIFF($this->ftell(), $LISTchunkMaxOffset)) { + $RIFFchunk[$listname] = array_merge_recursive($RIFFchunk[$listname], $parsedChunk); + } + + } + break; + + default: + if (preg_match('#^[0-9]{2}(wb|pc|dc|db)$#', $chunkname)) { + $this->fseek($chunksize, SEEK_CUR); + break; + } + $thisindex = 0; + if (isset($RIFFchunk[$chunkname]) && is_array($RIFFchunk[$chunkname])) { + $thisindex = count($RIFFchunk[$chunkname]); + } + $RIFFchunk[$chunkname][$thisindex]['offset'] = $this->ftell() - 8; + $RIFFchunk[$chunkname][$thisindex]['size'] = $chunksize; + switch ($chunkname) { + case 'data': + $info['avdataoffset'] = $this->ftell(); + $info['avdataend'] = $info['avdataoffset'] + $chunksize; + + $testData = $this->fread(36); + if ($testData === '') { + break; + } + if (preg_match('/^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]/s', substr($testData, 0, 4))) { + + // Probably is MP3 data + if (getid3_mp3::MPEGaudioHeaderBytesValid(substr($testData, 0, 4))) { + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; + $getid3_temp->info['avdataend'] = $info['avdataend']; + $getid3_mp3 = new getid3_mp3($getid3_temp, __CLASS__); + $getid3_mp3->getOnlyMPEGaudioInfo($info['avdataoffset'], false); + if (empty($getid3_temp->info['error'])) { + $info['audio'] = $getid3_temp->info['audio']; + $info['mpeg'] = $getid3_temp->info['mpeg']; + } + unset($getid3_temp, $getid3_mp3); + } + + } elseif (($isRegularAC3 = (substr($testData, 0, 2) == $AC3syncwordBytes)) || substr($testData, 8, 2) == strrev($AC3syncwordBytes)) { + + // This is probably AC-3 data + $getid3_temp = new getID3(); + if ($isRegularAC3) { + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; + $getid3_temp->info['avdataend'] = $info['avdataend']; + } + $getid3_ac3 = new getid3_ac3($getid3_temp); + if ($isRegularAC3) { + $getid3_ac3->Analyze(); + } else { + // Dolby Digital WAV + // AC-3 content, but not encoded in same format as normal AC-3 file + // For one thing, byte order is swapped + $ac3_data = ''; + for ($i = 0; $i < 28; $i += 2) { + $ac3_data .= substr($testData, 8 + $i + 1, 1); + $ac3_data .= substr($testData, 8 + $i + 0, 1); + } + $getid3_ac3->getid3->info['avdataoffset'] = 0; + $getid3_ac3->getid3->info['avdataend'] = strlen($ac3_data); + $getid3_ac3->AnalyzeString($ac3_data); + } + + if (empty($getid3_temp->info['error'])) { + $info['audio'] = $getid3_temp->info['audio']; + $info['ac3'] = $getid3_temp->info['ac3']; + if (!empty($getid3_temp->info['warning'])) { + foreach ($getid3_temp->info['warning'] as $newerror) { + $this->warning('getid3_ac3() says: ['.$newerror.']'); + } + } + } + unset($getid3_temp, $getid3_ac3); + + } elseif (preg_match('/^('.implode('|', array_map('preg_quote', getid3_dts::$syncwords)).')/', $testData)) { + + // This is probably DTS data + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; + $getid3_dts = new getid3_dts($getid3_temp); + $getid3_dts->Analyze(); + if (empty($getid3_temp->info['error'])) { + $info['audio'] = $getid3_temp->info['audio']; + $info['dts'] = $getid3_temp->info['dts']; + $info['playtime_seconds'] = $getid3_temp->info['playtime_seconds']; // may not match RIFF calculations since DTS-WAV often used 14/16 bit-word packing + if (!empty($getid3_temp->info['warning'])) { + foreach ($getid3_temp->info['warning'] as $newerror) { + $this->warning('getid3_dts() says: ['.$newerror.']'); + } + } + } + + unset($getid3_temp, $getid3_dts); + + } elseif (substr($testData, 0, 4) == 'wvpk') { + + // This is WavPack data + $info['wavpack']['offset'] = $info['avdataoffset']; + $info['wavpack']['size'] = getid3_lib::LittleEndian2Int(substr($testData, 4, 4)); + $this->parseWavPackHeader(substr($testData, 8, 28)); + + } else { + // This is some other kind of data (quite possibly just PCM) + // do nothing special, just skip it + } + $nextoffset = $info['avdataend']; + $this->fseek($nextoffset); + break; + + case 'iXML': + case 'bext': + case 'cart': + case 'fmt ': + case 'strh': + case 'strf': + case 'indx': + case 'MEXT': + case 'DISP': + case 'wamd': + case 'guan': + // always read data in + case 'JUNK': + // should be: never read data in + // but some programs write their version strings in a JUNK chunk (e.g. VirtualDub, AVIdemux, etc) + if ($chunksize < 1048576) { + if ($chunksize > 0) { + $RIFFchunk[$chunkname][$thisindex]['data'] = $this->fread($chunksize); + if ($chunkname == 'JUNK') { + if (preg_match('#^([\\x20-\\x7F]+)#', $RIFFchunk[$chunkname][$thisindex]['data'], $matches)) { + // only keep text characters [chr(32)-chr(127)] + $info['riff']['comments']['junk'][] = trim($matches[1]); + } + // but if nothing there, ignore + // remove the key in either case + unset($RIFFchunk[$chunkname][$thisindex]['data']); + } + } + } else { + $this->warning('Chunk "'.$chunkname.'" at offset '.$this->ftell().' is unexpectedly larger than 1MB (claims to be '.number_format($chunksize).' bytes), skipping data'); + $this->fseek($chunksize, SEEK_CUR); + } + break; + + //case 'IDVX': + // $info['divxtag']['comments'] = self::ParseDIVXTAG($this->fread($chunksize)); + // break; + + case 'scot': + // https://cmsdk.com/node-js/adding-scot-chunk-to-wav-file.html + $RIFFchunk[$chunkname][$thisindex]['data'] = $this->fread($chunksize); + $RIFFchunk[$chunkname][$thisindex]['parsed']['alter'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 0, 1); + $RIFFchunk[$chunkname][$thisindex]['parsed']['attrib'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 1, 1); + $RIFFchunk[$chunkname][$thisindex]['parsed']['artnum'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 2, 2)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['title'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 4, 43); // "name" in other documentation + $RIFFchunk[$chunkname][$thisindex]['parsed']['copy'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 47, 4); + $RIFFchunk[$chunkname][$thisindex]['parsed']['padd'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 51, 1); + $RIFFchunk[$chunkname][$thisindex]['parsed']['asclen'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 52, 5); + $RIFFchunk[$chunkname][$thisindex]['parsed']['startseconds'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 57, 2)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['starthundredths'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 59, 2)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['endseconds'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 61, 2)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['endhundreths'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 63, 2)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['sdate'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 65, 6); + $RIFFchunk[$chunkname][$thisindex]['parsed']['kdate'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 71, 6); + $RIFFchunk[$chunkname][$thisindex]['parsed']['start_hr'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 77, 1); + $RIFFchunk[$chunkname][$thisindex]['parsed']['kill_hr'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 78, 1); + $RIFFchunk[$chunkname][$thisindex]['parsed']['digital'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 79, 1); + $RIFFchunk[$chunkname][$thisindex]['parsed']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 80, 2)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['stereo'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 82, 1); + $RIFFchunk[$chunkname][$thisindex]['parsed']['compress'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 83, 1); + $RIFFchunk[$chunkname][$thisindex]['parsed']['eomstrt'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 84, 4)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['eomlen'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 88, 2)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['attrib2'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 90, 4)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['future1'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 94, 12); + $RIFFchunk[$chunkname][$thisindex]['parsed']['catfontcolor'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 106, 4)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['catcolor'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 110, 4)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['segeompos'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 114, 4)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['vt_startsecs'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 118, 2)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['vt_starthunds'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 120, 2)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['priorcat'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 122, 3); + $RIFFchunk[$chunkname][$thisindex]['parsed']['priorcopy'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 125, 4); + $RIFFchunk[$chunkname][$thisindex]['parsed']['priorpadd'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 129, 1); + $RIFFchunk[$chunkname][$thisindex]['parsed']['postcat'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 130, 3); + $RIFFchunk[$chunkname][$thisindex]['parsed']['postcopy'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 133, 4); + $RIFFchunk[$chunkname][$thisindex]['parsed']['postpadd'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 137, 1); + $RIFFchunk[$chunkname][$thisindex]['parsed']['hrcanplay'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 138, 21); + $RIFFchunk[$chunkname][$thisindex]['parsed']['future2'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 159, 108); + $RIFFchunk[$chunkname][$thisindex]['parsed']['artist'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 267, 34); + $RIFFchunk[$chunkname][$thisindex]['parsed']['comment'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 301, 34); // "trivia" in other documentation + $RIFFchunk[$chunkname][$thisindex]['parsed']['intro'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 335, 2); + $RIFFchunk[$chunkname][$thisindex]['parsed']['end'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 337, 1); + $RIFFchunk[$chunkname][$thisindex]['parsed']['year'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 338, 4); + $RIFFchunk[$chunkname][$thisindex]['parsed']['obsolete2'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 342, 1); + $RIFFchunk[$chunkname][$thisindex]['parsed']['rec_hr'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 343, 1); + $RIFFchunk[$chunkname][$thisindex]['parsed']['rdate'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 344, 6); + $RIFFchunk[$chunkname][$thisindex]['parsed']['mpeg_bitrate'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 350, 2)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['pitch'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 352, 2)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['playlevel'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 354, 2)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['lenvalid'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 356, 1); + $RIFFchunk[$chunkname][$thisindex]['parsed']['filelength'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 357, 4)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['newplaylevel'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 361, 2)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['chopsize'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 363, 4)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['vteomovr'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 367, 4)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['desiredlen'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 371, 4)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['triggers'] = getid3_lib::LittleEndian2Int(substr($RIFFchunk[$chunkname][$thisindex]['data'], 375, 4)); + $RIFFchunk[$chunkname][$thisindex]['parsed']['fillout'] = substr($RIFFchunk[$chunkname][$thisindex]['data'], 379, 33); + + foreach (array('title', 'artist', 'comment') as $key) { + if (trim($RIFFchunk[$chunkname][$thisindex]['parsed'][$key])) { + $info['riff']['comments'][$key] = array($RIFFchunk[$chunkname][$thisindex]['parsed'][$key]); + } + } + if ($RIFFchunk[$chunkname][$thisindex]['parsed']['filelength'] && !empty($info['filesize']) && ($RIFFchunk[$chunkname][$thisindex]['parsed']['filelength'] != $info['filesize'])) { + $this->warning('RIFF.WAVE.scot.filelength ('.$RIFFchunk[$chunkname][$thisindex]['parsed']['filelength'].') different from actual filesize ('.$info['filesize'].')'); + } + break; + + default: + if (!empty($LISTchunkParent) && isset($LISTchunkMaxOffset) && (($RIFFchunk[$chunkname][$thisindex]['offset'] + $RIFFchunk[$chunkname][$thisindex]['size']) <= $LISTchunkMaxOffset)) { + $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['offset'] = $RIFFchunk[$chunkname][$thisindex]['offset']; + $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['size'] = $RIFFchunk[$chunkname][$thisindex]['size']; + unset($RIFFchunk[$chunkname][$thisindex]['offset']); + unset($RIFFchunk[$chunkname][$thisindex]['size']); + if (isset($RIFFchunk[$chunkname][$thisindex]) && empty($RIFFchunk[$chunkname][$thisindex])) { + unset($RIFFchunk[$chunkname][$thisindex]); + } + if (isset($RIFFchunk[$chunkname]) && empty($RIFFchunk[$chunkname])) { + unset($RIFFchunk[$chunkname]); + } + $RIFFchunk[$LISTchunkParent][$chunkname][$thisindex]['data'] = $this->fread($chunksize); + } elseif ($chunksize < 2048) { + // only read data in if smaller than 2kB + $RIFFchunk[$chunkname][$thisindex]['data'] = $this->fread($chunksize); + } else { + $this->fseek($chunksize, SEEK_CUR); + } + break; + } + break; + } + } + + } catch (getid3_exception $e) { + if ($e->getCode() == 10) { + $this->warning('RIFF parser: '.$e->getMessage()); + } else { + throw $e; + } + } + + return !empty($RIFFchunk) ? $RIFFchunk : false; + } + + /** + * @param string $RIFFdata + * + * @return bool + */ + public function ParseRIFFdata(&$RIFFdata) { + $info = &$this->getid3->info; + if ($RIFFdata) { + $tempfile = tempnam(GETID3_TEMP_DIR, 'getID3'); + $fp_temp = fopen($tempfile, 'wb'); + $RIFFdataLength = strlen($RIFFdata); + $NewLengthString = getid3_lib::LittleEndian2String($RIFFdataLength, 4); + for ($i = 0; $i < 4; $i++) { + $RIFFdata[($i + 4)] = $NewLengthString[$i]; + } + fwrite($fp_temp, $RIFFdata); + fclose($fp_temp); + + $getid3_temp = new getID3(); + $getid3_temp->openfile($tempfile); + $getid3_temp->info['filesize'] = $RIFFdataLength; + $getid3_temp->info['filenamepath'] = $info['filenamepath']; + $getid3_temp->info['tags'] = $info['tags']; + $getid3_temp->info['warning'] = $info['warning']; + $getid3_temp->info['error'] = $info['error']; + $getid3_temp->info['comments'] = $info['comments']; + $getid3_temp->info['audio'] = (isset($info['audio']) ? $info['audio'] : array()); + $getid3_temp->info['video'] = (isset($info['video']) ? $info['video'] : array()); + $getid3_riff = new getid3_riff($getid3_temp); + $getid3_riff->Analyze(); + + $info['riff'] = $getid3_temp->info['riff']; + $info['warning'] = $getid3_temp->info['warning']; + $info['error'] = $getid3_temp->info['error']; + $info['tags'] = $getid3_temp->info['tags']; + $info['comments'] = $getid3_temp->info['comments']; + unset($getid3_riff, $getid3_temp); + unlink($tempfile); + } + return false; + } + + /** + * @param array $RIFFinfoArray + * @param array $CommentsTargetArray + * + * @return bool + */ + public static function parseComments(&$RIFFinfoArray, &$CommentsTargetArray) { + $RIFFinfoKeyLookup = array( + 'IARL'=>'archivallocation', + 'IART'=>'artist', + 'ICDS'=>'costumedesigner', + 'ICMS'=>'commissionedby', + 'ICMT'=>'comment', + 'ICNT'=>'country', + 'ICOP'=>'copyright', + 'ICRD'=>'creationdate', + 'IDIM'=>'dimensions', + 'IDIT'=>'digitizationdate', + 'IDPI'=>'resolution', + 'IDST'=>'distributor', + 'IEDT'=>'editor', + 'IENG'=>'engineers', + 'IFRM'=>'accountofparts', + 'IGNR'=>'genre', + 'IKEY'=>'keywords', + 'ILGT'=>'lightness', + 'ILNG'=>'language', + 'IMED'=>'orignalmedium', + 'IMUS'=>'composer', + 'INAM'=>'title', + 'IPDS'=>'productiondesigner', + 'IPLT'=>'palette', + 'IPRD'=>'product', + 'IPRO'=>'producer', + 'IPRT'=>'part', + 'IRTD'=>'rating', + 'ISBJ'=>'subject', + 'ISFT'=>'software', + 'ISGN'=>'secondarygenre', + 'ISHP'=>'sharpness', + 'ISRC'=>'sourcesupplier', + 'ISRF'=>'digitizationsource', + 'ISTD'=>'productionstudio', + 'ISTR'=>'starring', + 'ITCH'=>'encoded_by', + 'IWEB'=>'url', + 'IWRI'=>'writer', + '____'=>'comment', + ); + foreach ($RIFFinfoKeyLookup as $key => $value) { + if (isset($RIFFinfoArray[$key])) { + foreach ($RIFFinfoArray[$key] as $commentid => $commentdata) { + if (trim($commentdata['data']) != '') { + if (isset($CommentsTargetArray[$value])) { + $CommentsTargetArray[$value][] = trim($commentdata['data']); + } else { + $CommentsTargetArray[$value] = array(trim($commentdata['data'])); + } + } + } + } + } + return true; + } + + /** + * @param string $WaveFormatExData + * + * @return array + */ + public static function parseWAVEFORMATex($WaveFormatExData) { + // shortcut + $WaveFormatEx = array(); + $WaveFormatEx['raw'] = array(); + $WaveFormatEx_raw = &$WaveFormatEx['raw']; + + $WaveFormatEx_raw['wFormatTag'] = substr($WaveFormatExData, 0, 2); + $WaveFormatEx_raw['nChannels'] = substr($WaveFormatExData, 2, 2); + $WaveFormatEx_raw['nSamplesPerSec'] = substr($WaveFormatExData, 4, 4); + $WaveFormatEx_raw['nAvgBytesPerSec'] = substr($WaveFormatExData, 8, 4); + $WaveFormatEx_raw['nBlockAlign'] = substr($WaveFormatExData, 12, 2); + $WaveFormatEx_raw['wBitsPerSample'] = substr($WaveFormatExData, 14, 2); + if (strlen($WaveFormatExData) > 16) { + $WaveFormatEx_raw['cbSize'] = substr($WaveFormatExData, 16, 2); + } + $WaveFormatEx_raw = array_map('getid3_lib::LittleEndian2Int', $WaveFormatEx_raw); + + $WaveFormatEx['codec'] = self::wFormatTagLookup($WaveFormatEx_raw['wFormatTag']); + $WaveFormatEx['channels'] = $WaveFormatEx_raw['nChannels']; + $WaveFormatEx['sample_rate'] = $WaveFormatEx_raw['nSamplesPerSec']; + $WaveFormatEx['bitrate'] = $WaveFormatEx_raw['nAvgBytesPerSec'] * 8; + $WaveFormatEx['bits_per_sample'] = $WaveFormatEx_raw['wBitsPerSample']; + + return $WaveFormatEx; + } + + /** + * @param string $WavPackChunkData + * + * @return bool + */ + public function parseWavPackHeader($WavPackChunkData) { + // typedef struct { + // char ckID [4]; + // long ckSize; + // short version; + // short bits; // added for version 2.00 + // short flags, shift; // added for version 3.00 + // long total_samples, crc, crc2; + // char extension [4], extra_bc, extras [3]; + // } WavpackHeader; + + // shortcut + $info = &$this->getid3->info; + $info['wavpack'] = array(); + $thisfile_wavpack = &$info['wavpack']; + + $thisfile_wavpack['version'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 0, 2)); + if ($thisfile_wavpack['version'] >= 2) { + $thisfile_wavpack['bits'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 2, 2)); + } + if ($thisfile_wavpack['version'] >= 3) { + $thisfile_wavpack['flags_raw'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 4, 2)); + $thisfile_wavpack['shift'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 6, 2)); + $thisfile_wavpack['total_samples'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 8, 4)); + $thisfile_wavpack['crc1'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 12, 4)); + $thisfile_wavpack['crc2'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 16, 4)); + $thisfile_wavpack['extension'] = substr($WavPackChunkData, 20, 4); + $thisfile_wavpack['extra_bc'] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 24, 1)); + for ($i = 0; $i <= 2; $i++) { + $thisfile_wavpack['extras'][] = getid3_lib::LittleEndian2Int(substr($WavPackChunkData, 25 + $i, 1)); + } + + // shortcut + $thisfile_wavpack['flags'] = array(); + $thisfile_wavpack_flags = &$thisfile_wavpack['flags']; + + $thisfile_wavpack_flags['mono'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000001); + $thisfile_wavpack_flags['fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000002); + $thisfile_wavpack_flags['raw_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000004); + $thisfile_wavpack_flags['calc_noise'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000008); + $thisfile_wavpack_flags['high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000010); + $thisfile_wavpack_flags['3_byte_samples'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000020); + $thisfile_wavpack_flags['over_20_bits'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000040); + $thisfile_wavpack_flags['use_wvc'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000080); + $thisfile_wavpack_flags['noiseshaping'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000100); + $thisfile_wavpack_flags['very_fast_mode'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000200); + $thisfile_wavpack_flags['new_high_quality'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000400); + $thisfile_wavpack_flags['cancel_extreme'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x000800); + $thisfile_wavpack_flags['cross_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x001000); + $thisfile_wavpack_flags['new_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x002000); + $thisfile_wavpack_flags['joint_stereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x004000); + $thisfile_wavpack_flags['extra_decorrelation'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x008000); + $thisfile_wavpack_flags['override_noiseshape'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x010000); + $thisfile_wavpack_flags['override_jointstereo'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x020000); + $thisfile_wavpack_flags['copy_source_filetime'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x040000); + $thisfile_wavpack_flags['create_exe'] = (bool) ($thisfile_wavpack['flags_raw'] & 0x080000); + } + + return true; + } + + /** + * @param string $BITMAPINFOHEADER + * @param bool $littleEndian + * + * @return array + */ + public static function ParseBITMAPINFOHEADER($BITMAPINFOHEADER, $littleEndian=true) { + + $parsed = array(); + $parsed['biSize'] = substr($BITMAPINFOHEADER, 0, 4); // number of bytes required by the BITMAPINFOHEADER structure + $parsed['biWidth'] = substr($BITMAPINFOHEADER, 4, 4); // width of the bitmap in pixels + $parsed['biHeight'] = substr($BITMAPINFOHEADER, 8, 4); // height of the bitmap in pixels. If biHeight is positive, the bitmap is a 'bottom-up' DIB and its origin is the lower left corner. If biHeight is negative, the bitmap is a 'top-down' DIB and its origin is the upper left corner + $parsed['biPlanes'] = substr($BITMAPINFOHEADER, 12, 2); // number of color planes on the target device. In most cases this value must be set to 1 + $parsed['biBitCount'] = substr($BITMAPINFOHEADER, 14, 2); // Specifies the number of bits per pixels + $parsed['biSizeImage'] = substr($BITMAPINFOHEADER, 20, 4); // size of the bitmap data section of the image (the actual pixel data, excluding BITMAPINFOHEADER and RGBQUAD structures) + $parsed['biXPelsPerMeter'] = substr($BITMAPINFOHEADER, 24, 4); // horizontal resolution, in pixels per metre, of the target device + $parsed['biYPelsPerMeter'] = substr($BITMAPINFOHEADER, 28, 4); // vertical resolution, in pixels per metre, of the target device + $parsed['biClrUsed'] = substr($BITMAPINFOHEADER, 32, 4); // actual number of color indices in the color table used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression + $parsed['biClrImportant'] = substr($BITMAPINFOHEADER, 36, 4); // number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important + $parsed = array_map('getid3_lib::'.($littleEndian ? 'Little' : 'Big').'Endian2Int', $parsed); + + $parsed['fourcc'] = substr($BITMAPINFOHEADER, 16, 4); // compression identifier + + return $parsed; + } + + /** + * @param string $DIVXTAG + * @param bool $raw + * + * @return array + */ + public static function ParseDIVXTAG($DIVXTAG, $raw=false) { + // structure from "IDivX" source, Form1.frm, by "Greg Frazier of Daemonic Software Group", email: gfrazier@icestorm.net, web: http://dsg.cjb.net/ + // source available at http://files.divx-digest.com/download/c663efe7ef8ad2e90bf4af4d3ea6188a/on0SWN2r/edit/IDivX.zip + // 'Byte Layout: '1111111111111111 + // '32 for Movie - 1 '1111111111111111 + // '28 for Author - 6 '6666666666666666 + // '4 for year - 2 '6666666666662222 + // '3 for genre - 3 '7777777777777777 + // '48 for Comments - 7 '7777777777777777 + // '1 for Rating - 4 '7777777777777777 + // '5 for Future Additions - 0 '333400000DIVXTAG + // '128 bytes total + + static $DIVXTAGgenre = array( + 0 => 'Action', + 1 => 'Action/Adventure', + 2 => 'Adventure', + 3 => 'Adult', + 4 => 'Anime', + 5 => 'Cartoon', + 6 => 'Claymation', + 7 => 'Comedy', + 8 => 'Commercial', + 9 => 'Documentary', + 10 => 'Drama', + 11 => 'Home Video', + 12 => 'Horror', + 13 => 'Infomercial', + 14 => 'Interactive', + 15 => 'Mystery', + 16 => 'Music Video', + 17 => 'Other', + 18 => 'Religion', + 19 => 'Sci Fi', + 20 => 'Thriller', + 21 => 'Western', + ), + $DIVXTAGrating = array( + 0 => 'Unrated', + 1 => 'G', + 2 => 'PG', + 3 => 'PG-13', + 4 => 'R', + 5 => 'NC-17', + ); + + $parsed = array(); + $parsed['title'] = trim(substr($DIVXTAG, 0, 32)); + $parsed['artist'] = trim(substr($DIVXTAG, 32, 28)); + $parsed['year'] = intval(trim(substr($DIVXTAG, 60, 4))); + $parsed['comment'] = trim(substr($DIVXTAG, 64, 48)); + $parsed['genre_id'] = intval(trim(substr($DIVXTAG, 112, 3))); + $parsed['rating_id'] = ord(substr($DIVXTAG, 115, 1)); + //$parsed['padding'] = substr($DIVXTAG, 116, 5); // 5-byte null + //$parsed['magic'] = substr($DIVXTAG, 121, 7); // "DIVXTAG" + + $parsed['genre'] = (isset($DIVXTAGgenre[$parsed['genre_id']]) ? $DIVXTAGgenre[$parsed['genre_id']] : $parsed['genre_id']); + $parsed['rating'] = (isset($DIVXTAGrating[$parsed['rating_id']]) ? $DIVXTAGrating[$parsed['rating_id']] : $parsed['rating_id']); + + if (!$raw) { + unset($parsed['genre_id'], $parsed['rating_id']); + foreach ($parsed as $key => $value) { + if (empty($value)) { + unset($parsed[$key]); + } + } + } + + foreach ($parsed as $tag => $value) { + $parsed[$tag] = array($value); + } + + return $parsed; + } + + /** + * @param string $tagshortname + * + * @return string + */ + public static function waveSNDMtagLookup($tagshortname) { + $begin = __LINE__; + + /** This is not a comment! + + ©kwd keywords + ©BPM bpm + ©trt tracktitle + ©des description + ©gen category + ©fin featuredinstrument + ©LID longid + ©bex bwdescription + ©pub publisher + ©cdt cdtitle + ©alb library + ©com composer + + */ + + return getid3_lib::EmbeddedLookup($tagshortname, $begin, __LINE__, __FILE__, 'riff-sndm'); + } + + /** + * @param int $wFormatTag + * + * @return string + */ + public static function wFormatTagLookup($wFormatTag) { + + $begin = __LINE__; + + /** This is not a comment! + + 0x0000 Microsoft Unknown Wave Format + 0x0001 Pulse Code Modulation (PCM) + 0x0002 Microsoft ADPCM + 0x0003 IEEE Float + 0x0004 Compaq Computer VSELP + 0x0005 IBM CVSD + 0x0006 Microsoft A-Law + 0x0007 Microsoft mu-Law + 0x0008 Microsoft DTS + 0x0010 OKI ADPCM + 0x0011 Intel DVI/IMA ADPCM + 0x0012 Videologic MediaSpace ADPCM + 0x0013 Sierra Semiconductor ADPCM + 0x0014 Antex Electronics G.723 ADPCM + 0x0015 DSP Solutions DigiSTD + 0x0016 DSP Solutions DigiFIX + 0x0017 Dialogic OKI ADPCM + 0x0018 MediaVision ADPCM + 0x0019 Hewlett-Packard CU + 0x0020 Yamaha ADPCM + 0x0021 Speech Compression Sonarc + 0x0022 DSP Group TrueSpeech + 0x0023 Echo Speech EchoSC1 + 0x0024 Audiofile AF36 + 0x0025 Audio Processing Technology APTX + 0x0026 AudioFile AF10 + 0x0027 Prosody 1612 + 0x0028 LRC + 0x0030 Dolby AC2 + 0x0031 Microsoft GSM 6.10 + 0x0032 MSNAudio + 0x0033 Antex Electronics ADPCME + 0x0034 Control Resources VQLPC + 0x0035 DSP Solutions DigiREAL + 0x0036 DSP Solutions DigiADPCM + 0x0037 Control Resources CR10 + 0x0038 Natural MicroSystems VBXADPCM + 0x0039 Crystal Semiconductor IMA ADPCM + 0x003A EchoSC3 + 0x003B Rockwell ADPCM + 0x003C Rockwell Digit LK + 0x003D Xebec + 0x0040 Antex Electronics G.721 ADPCM + 0x0041 G.728 CELP + 0x0042 MSG723 + 0x0050 MPEG Layer-2 or Layer-1 + 0x0052 RT24 + 0x0053 PAC + 0x0055 MPEG Layer-3 + 0x0059 Lucent G.723 + 0x0060 Cirrus + 0x0061 ESPCM + 0x0062 Voxware + 0x0063 Canopus Atrac + 0x0064 G.726 ADPCM + 0x0065 G.722 ADPCM + 0x0066 DSAT + 0x0067 DSAT Display + 0x0069 Voxware Byte Aligned + 0x0070 Voxware AC8 + 0x0071 Voxware AC10 + 0x0072 Voxware AC16 + 0x0073 Voxware AC20 + 0x0074 Voxware MetaVoice + 0x0075 Voxware MetaSound + 0x0076 Voxware RT29HW + 0x0077 Voxware VR12 + 0x0078 Voxware VR18 + 0x0079 Voxware TQ40 + 0x0080 Softsound + 0x0081 Voxware TQ60 + 0x0082 MSRT24 + 0x0083 G.729A + 0x0084 MVI MV12 + 0x0085 DF G.726 + 0x0086 DF GSM610 + 0x0088 ISIAudio + 0x0089 Onlive + 0x0091 SBC24 + 0x0092 Dolby AC3 SPDIF + 0x0093 MediaSonic G.723 + 0x0094 Aculab PLC Prosody 8kbps + 0x0097 ZyXEL ADPCM + 0x0098 Philips LPCBB + 0x0099 Packed + 0x00FF AAC + 0x0100 Rhetorex ADPCM + 0x0101 IBM mu-law + 0x0102 IBM A-law + 0x0103 IBM AVC Adaptive Differential Pulse Code Modulation (ADPCM) + 0x0111 Vivo G.723 + 0x0112 Vivo Siren + 0x0123 Digital G.723 + 0x0125 Sanyo LD ADPCM + 0x0130 Sipro Lab Telecom ACELP NET + 0x0131 Sipro Lab Telecom ACELP 4800 + 0x0132 Sipro Lab Telecom ACELP 8V3 + 0x0133 Sipro Lab Telecom G.729 + 0x0134 Sipro Lab Telecom G.729A + 0x0135 Sipro Lab Telecom Kelvin + 0x0140 Windows Media Video V8 + 0x0150 Qualcomm PureVoice + 0x0151 Qualcomm HalfRate + 0x0155 Ring Zero Systems TUB GSM + 0x0160 Microsoft Audio 1 + 0x0161 Windows Media Audio V7 / V8 / V9 + 0x0162 Windows Media Audio Professional V9 + 0x0163 Windows Media Audio Lossless V9 + 0x0200 Creative Labs ADPCM + 0x0202 Creative Labs Fastspeech8 + 0x0203 Creative Labs Fastspeech10 + 0x0210 UHER Informatic GmbH ADPCM + 0x0220 Quarterdeck + 0x0230 I-link Worldwide VC + 0x0240 Aureal RAW Sport + 0x0250 Interactive Products HSX + 0x0251 Interactive Products RPELP + 0x0260 Consistent Software CS2 + 0x0270 Sony SCX + 0x0300 Fujitsu FM Towns Snd + 0x0400 BTV Digital + 0x0401 Intel Music Coder + 0x0450 QDesign Music + 0x0680 VME VMPCM + 0x0681 AT&T Labs TPC + 0x08AE ClearJump LiteWave + 0x1000 Olivetti GSM + 0x1001 Olivetti ADPCM + 0x1002 Olivetti CELP + 0x1003 Olivetti SBC + 0x1004 Olivetti OPR + 0x1100 Lernout & Hauspie Codec (0x1100) + 0x1101 Lernout & Hauspie CELP Codec (0x1101) + 0x1102 Lernout & Hauspie SBC Codec (0x1102) + 0x1103 Lernout & Hauspie SBC Codec (0x1103) + 0x1104 Lernout & Hauspie SBC Codec (0x1104) + 0x1400 Norris + 0x1401 AT&T ISIAudio + 0x1500 Soundspace Music Compression + 0x181C VoxWare RT24 Speech + 0x1FC4 NCT Soft ALF2CD (www.nctsoft.com) + 0x2000 Dolby AC3 + 0x2001 Dolby DTS + 0x2002 WAVE_FORMAT_14_4 + 0x2003 WAVE_FORMAT_28_8 + 0x2004 WAVE_FORMAT_COOK + 0x2005 WAVE_FORMAT_DNET + 0x674F Ogg Vorbis 1 + 0x6750 Ogg Vorbis 2 + 0x6751 Ogg Vorbis 3 + 0x676F Ogg Vorbis 1+ + 0x6770 Ogg Vorbis 2+ + 0x6771 Ogg Vorbis 3+ + 0x7A21 GSM-AMR (CBR, no SID) + 0x7A22 GSM-AMR (VBR, including SID) + 0xFFFE WAVE_FORMAT_EXTENSIBLE + 0xFFFF WAVE_FORMAT_DEVELOPMENT + + */ + + return getid3_lib::EmbeddedLookup('0x'.str_pad(strtoupper(dechex($wFormatTag)), 4, '0', STR_PAD_LEFT), $begin, __LINE__, __FILE__, 'riff-wFormatTag'); + } + + /** + * @param string $fourcc + * + * @return string + */ + public static function fourccLookup($fourcc) { + + $begin = __LINE__; + + /** This is not a comment! + + swot http://developer.apple.com/qa/snd/snd07.html + ____ No Codec (____) + _BIT BI_BITFIELDS (Raw RGB) + _JPG JPEG compressed + _PNG PNG compressed W3C/ISO/IEC (RFC-2083) + _RAW Full Frames (Uncompressed) + _RGB Raw RGB Bitmap + _RL4 RLE 4bpp RGB + _RL8 RLE 8bpp RGB + 3IV1 3ivx MPEG-4 v1 + 3IV2 3ivx MPEG-4 v2 + 3IVX 3ivx MPEG-4 + AASC Autodesk Animator + ABYR Kensington ?ABYR? + AEMI Array Microsystems VideoONE MPEG1-I Capture + AFLC Autodesk Animator FLC + AFLI Autodesk Animator FLI + AMPG Array Microsystems VideoONE MPEG + ANIM Intel RDX (ANIM) + AP41 AngelPotion Definitive + ASV1 Asus Video v1 + ASV2 Asus Video v2 + ASVX Asus Video 2.0 (audio) + AUR2 AuraVision Aura 2 Codec - YUV 4:2:2 + AURA AuraVision Aura 1 Codec - YUV 4:1:1 + AVDJ Independent JPEG Group\'s codec (AVDJ) + AVRN Independent JPEG Group\'s codec (AVRN) + AYUV 4:4:4 YUV (AYUV) + AZPR Quicktime Apple Video (AZPR) + BGR Raw RGB32 + BLZ0 Blizzard DivX MPEG-4 + BTVC Conexant Composite Video + BINK RAD Game Tools Bink Video + BT20 Conexant Prosumer Video + BTCV Conexant Composite Video Codec + BW10 Data Translation Broadway MPEG Capture + CC12 Intel YUV12 + CDVC Canopus DV + CFCC Digital Processing Systems DPS Perception + CGDI Microsoft Office 97 Camcorder Video + CHAM Winnov Caviara Champagne + CJPG Creative WebCam JPEG + CLJR Cirrus Logic YUV 4:1:1 + CMYK Common Data Format in Printing (Colorgraph) + CPLA Weitek 4:2:0 YUV Planar + CRAM Microsoft Video 1 (CRAM) + cvid Radius Cinepak + CVID Radius Cinepak + CWLT Microsoft Color WLT DIB + CYUV Creative Labs YUV + CYUY ATI YUV + D261 H.261 + D263 H.263 + DIB Device Independent Bitmap + DIV1 FFmpeg OpenDivX + DIV2 Microsoft MPEG-4 v1/v2 + DIV3 DivX ;-) MPEG-4 v3.x Low-Motion + DIV4 DivX ;-) MPEG-4 v3.x Fast-Motion + DIV5 DivX MPEG-4 v5.x + DIV6 DivX ;-) (MS MPEG-4 v3.x) + DIVX DivX MPEG-4 v4 (OpenDivX / Project Mayo) + divx DivX MPEG-4 + DMB1 Matrox Rainbow Runner hardware MJPEG + DMB2 Paradigm MJPEG + DSVD ?DSVD? + DUCK Duck TrueMotion 1.0 + DPS0 DPS/Leitch Reality Motion JPEG + DPSC DPS/Leitch PAR Motion JPEG + DV25 Matrox DVCPRO codec + DV50 Matrox DVCPRO50 codec + DVC IEC 61834 and SMPTE 314M (DVC/DV Video) + DVCP IEC 61834 and SMPTE 314M (DVC/DV Video) + DVHD IEC Standard DV 1125 lines @ 30fps / 1250 lines @ 25fps + DVMA Darim Vision DVMPEG (dummy for MPEG compressor) (www.darvision.com) + DVSL IEC Standard DV compressed in SD (SDL) + DVAN ?DVAN? + DVE2 InSoft DVE-2 Videoconferencing + dvsd IEC 61834 and SMPTE 314M DVC/DV Video + DVSD IEC 61834 and SMPTE 314M DVC/DV Video + DVX1 Lucent DVX1000SP Video Decoder + DVX2 Lucent DVX2000S Video Decoder + DVX3 Lucent DVX3000S Video Decoder + DX50 DivX v5 + DXT1 Microsoft DirectX Compressed Texture (DXT1) + DXT2 Microsoft DirectX Compressed Texture (DXT2) + DXT3 Microsoft DirectX Compressed Texture (DXT3) + DXT4 Microsoft DirectX Compressed Texture (DXT4) + DXT5 Microsoft DirectX Compressed Texture (DXT5) + DXTC Microsoft DirectX Compressed Texture (DXTC) + DXTn Microsoft DirectX Compressed Texture (DXTn) + EM2V Etymonix MPEG-2 I-frame (www.etymonix.com) + EKQ0 Elsa ?EKQ0? + ELK0 Elsa ?ELK0? + ESCP Eidos Escape + ETV1 eTreppid Video ETV1 + ETV2 eTreppid Video ETV2 + ETVC eTreppid Video ETVC + FLIC Autodesk FLI/FLC Animation + FLV1 Sorenson Spark + FLV4 On2 TrueMotion VP6 + FRWT Darim Vision Forward Motion JPEG (www.darvision.com) + FRWU Darim Vision Forward Uncompressed (www.darvision.com) + FLJP D-Vision Field Encoded Motion JPEG + FPS1 FRAPS v1 + FRWA SoftLab-Nsk Forward Motion JPEG w/ alpha channel + FRWD SoftLab-Nsk Forward Motion JPEG + FVF1 Iterated Systems Fractal Video Frame + GLZW Motion LZW (gabest@freemail.hu) + GPEG Motion JPEG (gabest@freemail.hu) + GWLT Microsoft Greyscale WLT DIB + H260 Intel ITU H.260 Videoconferencing + H261 Intel ITU H.261 Videoconferencing + H262 Intel ITU H.262 Videoconferencing + H263 Intel ITU H.263 Videoconferencing + H264 Intel ITU H.264 Videoconferencing + H265 Intel ITU H.265 Videoconferencing + H266 Intel ITU H.266 Videoconferencing + H267 Intel ITU H.267 Videoconferencing + H268 Intel ITU H.268 Videoconferencing + H269 Intel ITU H.269 Videoconferencing + HFYU Huffman Lossless Codec + HMCR Rendition Motion Compensation Format (HMCR) + HMRR Rendition Motion Compensation Format (HMRR) + I263 FFmpeg I263 decoder + IF09 Indeo YVU9 ("YVU9 with additional delta-frame info after the U plane") + IUYV Interlaced version of UYVY (www.leadtools.com) + IY41 Interlaced version of Y41P (www.leadtools.com) + IYU1 12 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard + IYU2 24 bit format used in mode 2 of the IEEE 1394 Digital Camera 1.04 spec IEEE standard + IYUV Planar YUV format (8-bpp Y plane, followed by 8-bpp 2×2 U and V planes) + i263 Intel ITU H.263 Videoconferencing (i263) + I420 Intel Indeo 4 + IAN Intel Indeo 4 (RDX) + ICLB InSoft CellB Videoconferencing + IGOR Power DVD + IJPG Intergraph JPEG + ILVC Intel Layered Video + ILVR ITU-T H.263+ + IPDV I-O Data Device Giga AVI DV Codec + IR21 Intel Indeo 2.1 + IRAW Intel YUV Uncompressed + IV30 Intel Indeo 3.0 + IV31 Intel Indeo 3.1 + IV32 Ligos Indeo 3.2 + IV33 Ligos Indeo 3.3 + IV34 Ligos Indeo 3.4 + IV35 Ligos Indeo 3.5 + IV36 Ligos Indeo 3.6 + IV37 Ligos Indeo 3.7 + IV38 Ligos Indeo 3.8 + IV39 Ligos Indeo 3.9 + IV40 Ligos Indeo Interactive 4.0 + IV41 Ligos Indeo Interactive 4.1 + IV42 Ligos Indeo Interactive 4.2 + IV43 Ligos Indeo Interactive 4.3 + IV44 Ligos Indeo Interactive 4.4 + IV45 Ligos Indeo Interactive 4.5 + IV46 Ligos Indeo Interactive 4.6 + IV47 Ligos Indeo Interactive 4.7 + IV48 Ligos Indeo Interactive 4.8 + IV49 Ligos Indeo Interactive 4.9 + IV50 Ligos Indeo Interactive 5.0 + JBYR Kensington ?JBYR? + JPEG Still Image JPEG DIB + JPGL Pegasus Lossless Motion JPEG + KMVC Team17 Software Karl Morton\'s Video Codec + LSVM Vianet Lighting Strike Vmail (Streaming) (www.vianet.com) + LEAD LEAD Video Codec + Ljpg LEAD MJPEG Codec + MDVD Alex MicroDVD Video (hacked MS MPEG-4) (www.tiasoft.de) + MJPA Morgan Motion JPEG (MJPA) (www.morgan-multimedia.com) + MJPB Morgan Motion JPEG (MJPB) (www.morgan-multimedia.com) + MMES Matrox MPEG-2 I-frame + MP2v Microsoft S-Mpeg 4 version 1 (MP2v) + MP42 Microsoft S-Mpeg 4 version 2 (MP42) + MP43 Microsoft S-Mpeg 4 version 3 (MP43) + MP4S Microsoft S-Mpeg 4 version 3 (MP4S) + MP4V FFmpeg MPEG-4 + MPG1 FFmpeg MPEG 1/2 + MPG2 FFmpeg MPEG 1/2 + MPG3 FFmpeg DivX ;-) (MS MPEG-4 v3) + MPG4 Microsoft MPEG-4 + MPGI Sigma Designs MPEG + MPNG PNG images decoder + MSS1 Microsoft Windows Screen Video + MSZH LCL (Lossless Codec Library) (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm) + M261 Microsoft H.261 + M263 Microsoft H.263 + M4S2 Microsoft Fully Compliant MPEG-4 v2 simple profile (M4S2) + m4s2 Microsoft Fully Compliant MPEG-4 v2 simple profile (m4s2) + MC12 ATI Motion Compensation Format (MC12) + MCAM ATI Motion Compensation Format (MCAM) + MJ2C Morgan Multimedia Motion JPEG2000 + mJPG IBM Motion JPEG w/ Huffman Tables + MJPG Microsoft Motion JPEG DIB + MP42 Microsoft MPEG-4 (low-motion) + MP43 Microsoft MPEG-4 (fast-motion) + MP4S Microsoft MPEG-4 (MP4S) + mp4s Microsoft MPEG-4 (mp4s) + MPEG Chromatic Research MPEG-1 Video I-Frame + MPG4 Microsoft MPEG-4 Video High Speed Compressor + MPGI Sigma Designs MPEG + MRCA FAST Multimedia Martin Regen Codec + MRLE Microsoft Run Length Encoding + MSVC Microsoft Video 1 + MTX1 Matrox ?MTX1? + MTX2 Matrox ?MTX2? + MTX3 Matrox ?MTX3? + MTX4 Matrox ?MTX4? + MTX5 Matrox ?MTX5? + MTX6 Matrox ?MTX6? + MTX7 Matrox ?MTX7? + MTX8 Matrox ?MTX8? + MTX9 Matrox ?MTX9? + MV12 Motion Pixels Codec (old) + MWV1 Aware Motion Wavelets + nAVI SMR Codec (hack of Microsoft MPEG-4) (IRC #shadowrealm) + NT00 NewTek LightWave HDTV YUV w/ Alpha (www.newtek.com) + NUV1 NuppelVideo + NTN1 Nogatech Video Compression 1 + NVS0 nVidia GeForce Texture (NVS0) + NVS1 nVidia GeForce Texture (NVS1) + NVS2 nVidia GeForce Texture (NVS2) + NVS3 nVidia GeForce Texture (NVS3) + NVS4 nVidia GeForce Texture (NVS4) + NVS5 nVidia GeForce Texture (NVS5) + NVT0 nVidia GeForce Texture (NVT0) + NVT1 nVidia GeForce Texture (NVT1) + NVT2 nVidia GeForce Texture (NVT2) + NVT3 nVidia GeForce Texture (NVT3) + NVT4 nVidia GeForce Texture (NVT4) + NVT5 nVidia GeForce Texture (NVT5) + PIXL MiroXL, Pinnacle PCTV + PDVC I-O Data Device Digital Video Capture DV codec + PGVV Radius Video Vision + PHMO IBM Photomotion + PIM1 MPEG Realtime (Pinnacle Cards) + PIM2 Pegasus Imaging ?PIM2? + PIMJ Pegasus Imaging Lossless JPEG + PVEZ Horizons Technology PowerEZ + PVMM PacketVideo Corporation MPEG-4 + PVW2 Pegasus Imaging Wavelet Compression + Q1.0 Q-Team\'s QPEG 1.0 (www.q-team.de) + Q1.1 Q-Team\'s QPEG 1.1 (www.q-team.de) + QPEG Q-Team QPEG 1.0 + qpeq Q-Team QPEG 1.1 + RGB Raw BGR32 + RGBA Raw RGB w/ Alpha + RMP4 REALmagic MPEG-4 (unauthorized XVID copy) (www.sigmadesigns.com) + ROQV Id RoQ File Video Decoder + RPZA Quicktime Apple Video (RPZA) + RUD0 Rududu video codec (http://rududu.ifrance.com/rududu/) + RV10 RealVideo 1.0 (aka RealVideo 5.0) + RV13 RealVideo 1.0 (RV13) + RV20 RealVideo G2 + RV30 RealVideo 8 + RV40 RealVideo 9 + RGBT Raw RGB w/ Transparency + RLE Microsoft Run Length Encoder + RLE4 Run Length Encoded (4bpp, 16-color) + RLE8 Run Length Encoded (8bpp, 256-color) + RT21 Intel Indeo RealTime Video 2.1 + rv20 RealVideo G2 + rv30 RealVideo 8 + RVX Intel RDX (RVX ) + SMC Apple Graphics (SMC ) + SP54 Logitech Sunplus Sp54 Codec for Mustek GSmart Mini 2 + SPIG Radius Spigot + SVQ3 Sorenson Video 3 (Apple Quicktime 5) + s422 Tekram VideoCap C210 YUV 4:2:2 + SDCC Sun Communication Digital Camera Codec + SFMC CrystalNet Surface Fitting Method + SMSC Radius SMSC + SMSD Radius SMSD + smsv WorldConnect Wavelet Video + SPIG Radius Spigot + SPLC Splash Studios ACM Audio Codec (www.splashstudios.net) + SQZ2 Microsoft VXTreme Video Codec V2 + STVA ST Microelectronics CMOS Imager Data (Bayer) + STVB ST Microelectronics CMOS Imager Data (Nudged Bayer) + STVC ST Microelectronics CMOS Imager Data (Bunched) + STVX ST Microelectronics CMOS Imager Data (Extended CODEC Data Format) + STVY ST Microelectronics CMOS Imager Data (Extended CODEC Data Format with Correction Data) + SV10 Sorenson Video R1 + SVQ1 Sorenson Video + T420 Toshiba YUV 4:2:0 + TM2A Duck TrueMotion Archiver 2.0 (www.duck.com) + TVJP Pinnacle/Truevision Targa 2000 board (TVJP) + TVMJ Pinnacle/Truevision Targa 2000 board (TVMJ) + TY0N Tecomac Low-Bit Rate Codec (www.tecomac.com) + TY2C Trident Decompression Driver + TLMS TeraLogic Motion Intraframe Codec (TLMS) + TLST TeraLogic Motion Intraframe Codec (TLST) + TM20 Duck TrueMotion 2.0 + TM2X Duck TrueMotion 2X + TMIC TeraLogic Motion Intraframe Codec (TMIC) + TMOT Horizons Technology TrueMotion S + tmot Horizons TrueMotion Video Compression + TR20 Duck TrueMotion RealTime 2.0 + TSCC TechSmith Screen Capture Codec + TV10 Tecomac Low-Bit Rate Codec + TY2N Trident ?TY2N? + U263 UB Video H.263/H.263+/H.263++ Decoder + UMP4 UB Video MPEG 4 (www.ubvideo.com) + UYNV Nvidia UYVY packed 4:2:2 + UYVP Evans & Sutherland YCbCr 4:2:2 extended precision + UCOD eMajix.com ClearVideo + ULTI IBM Ultimotion + UYVY UYVY packed 4:2:2 + V261 Lucent VX2000S + VIFP VFAPI Reader Codec (www.yks.ne.jp/~hori/) + VIV1 FFmpeg H263+ decoder + VIV2 Vivo H.263 + VQC2 Vector-quantised codec 2 (research) http://eprints.ecs.soton.ac.uk/archive/00001310/01/VTC97-js.pdf) + VTLP Alaris VideoGramPiX + VYU9 ATI YUV (VYU9) + VYUY ATI YUV (VYUY) + V261 Lucent VX2000S + V422 Vitec Multimedia 24-bit YUV 4:2:2 Format + V655 Vitec Multimedia 16-bit YUV 4:2:2 Format + VCR1 ATI Video Codec 1 + VCR2 ATI Video Codec 2 + VCR3 ATI VCR 3.0 + VCR4 ATI VCR 4.0 + VCR5 ATI VCR 5.0 + VCR6 ATI VCR 6.0 + VCR7 ATI VCR 7.0 + VCR8 ATI VCR 8.0 + VCR9 ATI VCR 9.0 + VDCT Vitec Multimedia Video Maker Pro DIB + VDOM VDOnet VDOWave + VDOW VDOnet VDOLive (H.263) + VDTZ Darim Vison VideoTizer YUV + VGPX Alaris VideoGramPiX + VIDS Vitec Multimedia YUV 4:2:2 CCIR 601 for V422 + VIVO Vivo H.263 v2.00 + vivo Vivo H.263 + VIXL Miro/Pinnacle Video XL + VLV1 VideoLogic/PURE Digital Videologic Capture + VP30 On2 VP3.0 + VP31 On2 VP3.1 + VP6F On2 TrueMotion VP6 + VX1K Lucent VX1000S Video Codec + VX2K Lucent VX2000S Video Codec + VXSP Lucent VX1000SP Video Codec + WBVC Winbond W9960 + WHAM Microsoft Video 1 (WHAM) + WINX Winnov Software Compression + WJPG AverMedia Winbond JPEG + WMV1 Windows Media Video V7 + WMV2 Windows Media Video V8 + WMV3 Windows Media Video V9 + WNV1 Winnov Hardware Compression + XYZP Extended PAL format XYZ palette (www.riff.org) + x263 Xirlink H.263 + XLV0 NetXL Video Decoder + XMPG Xing MPEG (I-Frame only) + XVID XviD MPEG-4 (www.xvid.org) + XXAN ?XXAN? + YU92 Intel YUV (YU92) + YUNV Nvidia Uncompressed YUV 4:2:2 + YUVP Extended PAL format YUV palette (www.riff.org) + Y211 YUV 2:1:1 Packed + Y411 YUV 4:1:1 Packed + Y41B Weitek YUV 4:1:1 Planar + Y41P Brooktree PC1 YUV 4:1:1 Packed + Y41T Brooktree PC1 YUV 4:1:1 with transparency + Y42B Weitek YUV 4:2:2 Planar + Y42T Brooktree UYUV 4:2:2 with transparency + Y422 ADS Technologies Copy of UYVY used in Pyro WebCam firewire camera + Y800 Simple, single Y plane for monochrome images + Y8 Grayscale video + YC12 Intel YUV 12 codec + YUV8 Winnov Caviar YUV8 + YUV9 Intel YUV9 + YUY2 Uncompressed YUV 4:2:2 + YUYV Canopus YUV + YV12 YVU12 Planar + YVU9 Intel YVU9 Planar (8-bpp Y plane, followed by 8-bpp 4x4 U and V planes) + YVYU YVYU 4:2:2 Packed + ZLIB Lossless Codec Library zlib compression (www.geocities.co.jp/Playtown-Denei/2837/LRC.htm) + ZPEG Metheus Video Zipper + + */ + + return getid3_lib::EmbeddedLookup($fourcc, $begin, __LINE__, __FILE__, 'riff-fourcc'); + } + + /** + * @param string $byteword + * @param bool $signed + * + * @return int|float|false + */ + private function EitherEndian2Int($byteword, $signed=false) { + if ($this->container == 'riff') { + return getid3_lib::LittleEndian2Int($byteword, $signed); + } + return getid3_lib::BigEndian2Int($byteword, false, $signed); + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.swf.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.swf.php new file mode 100644 index 00000000..a9b2c1a6 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.swf.php @@ -0,0 +1,150 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio-video.swf.php // +// module for analyzing Shockwave Flash files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_swf extends getid3_handler +{ + /** + * return all parsed tags if true, otherwise do not return tags not parsed by getID3 + * + * @var bool + */ + public $ReturnAllTagData = false; + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'swf'; + $info['video']['dataformat'] = 'swf'; + + // http://www.openswf.org/spec/SWFfileformat.html + + $this->fseek($info['avdataoffset']); + + $SWFfileData = $this->fread($info['avdataend'] - $info['avdataoffset']); // 8 + 2 + 2 + max(9) bytes NOT including Frame_Size RECT data + + $info['swf']['header']['signature'] = substr($SWFfileData, 0, 3); + switch ($info['swf']['header']['signature']) { + case 'FWS': + $info['swf']['header']['compressed'] = false; + break; + + case 'CWS': + $info['swf']['header']['compressed'] = true; + break; + + default: + $this->error('Expecting "FWS" or "CWS" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['swf']['header']['signature']).'"'); + unset($info['swf']); + unset($info['fileformat']); + return false; + } + $info['swf']['header']['version'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 3, 1)); + $info['swf']['header']['length'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 4, 4)); + + if ($info['swf']['header']['compressed']) { + $SWFHead = substr($SWFfileData, 0, 8); + $SWFfileData = substr($SWFfileData, 8); + if ($decompressed = @gzuncompress($SWFfileData)) { + $SWFfileData = $SWFHead.$decompressed; + } else { + $this->error('Error decompressing compressed SWF data ('.strlen($SWFfileData).' bytes compressed, should be '.($info['swf']['header']['length'] - 8).' bytes uncompressed)'); + return false; + } + } + + $FrameSizeBitsPerValue = (ord(substr($SWFfileData, 8, 1)) & 0xF8) >> 3; + $FrameSizeDataLength = ceil((5 + (4 * $FrameSizeBitsPerValue)) / 8); + $FrameSizeDataString = str_pad(decbin(ord(substr($SWFfileData, 8, 1)) & 0x07), 3, '0', STR_PAD_LEFT); + for ($i = 1; $i < $FrameSizeDataLength; $i++) { + $FrameSizeDataString .= str_pad(decbin(ord(substr($SWFfileData, 8 + $i, 1))), 8, '0', STR_PAD_LEFT); + } + list($X1, $X2, $Y1, $Y2) = explode("\n", wordwrap($FrameSizeDataString, $FrameSizeBitsPerValue, "\n", 1)); + $info['swf']['header']['frame_width'] = getid3_lib::Bin2Dec($X2); + $info['swf']['header']['frame_height'] = getid3_lib::Bin2Dec($Y2); + + // http://www-lehre.informatik.uni-osnabrueck.de/~fbstark/diplom/docs/swf/Flash_Uncovered.htm + // Next in the header is the frame rate, which is kind of weird. + // It is supposed to be stored as a 16bit integer, but the first byte + // (or last depending on how you look at it) is completely ignored. + // Example: 0x000C -> 0x0C -> 12 So the frame rate is 12 fps. + + // Byte at (8 + $FrameSizeDataLength) is always zero and ignored + $info['swf']['header']['frame_rate'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 9 + $FrameSizeDataLength, 1)); + $info['swf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($SWFfileData, 10 + $FrameSizeDataLength, 2)); + + $info['video']['frame_rate'] = $info['swf']['header']['frame_rate']; + $info['video']['resolution_x'] = intval(round($info['swf']['header']['frame_width'] / 20)); + $info['video']['resolution_y'] = intval(round($info['swf']['header']['frame_height'] / 20)); + $info['video']['pixel_aspect_ratio'] = (float) 1; + + if (($info['swf']['header']['frame_count'] > 0) && ($info['swf']['header']['frame_rate'] > 0)) { + $info['playtime_seconds'] = $info['swf']['header']['frame_count'] / $info['swf']['header']['frame_rate']; + } +//echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'
    '; + + + // SWF tags + + $CurrentOffset = 12 + $FrameSizeDataLength; + $SWFdataLength = strlen($SWFfileData); + + while ($CurrentOffset < $SWFdataLength) { +//echo __LINE__.'='.number_format(microtime(true) - $start_time, 3).'
    '; + + $TagIDTagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 2)); + $TagID = ($TagIDTagLength & 0xFFFC) >> 6; + $TagLength = ($TagIDTagLength & 0x003F); + $CurrentOffset += 2; + if ($TagLength == 0x3F) { + $TagLength = getid3_lib::LittleEndian2Int(substr($SWFfileData, $CurrentOffset, 4)); + $CurrentOffset += 4; + } + + $TagData = array(); + $TagData['offset'] = $CurrentOffset; + $TagData['size'] = $TagLength; + $TagData['id'] = $TagID; + $TagData['data'] = substr($SWFfileData, $CurrentOffset, $TagLength); + switch ($TagID) { + case 0: // end of movie + break 2; + + case 9: // Set background color + //$info['swf']['tags'][] = $TagData; + $info['swf']['bgcolor'] = strtoupper(str_pad(dechex(getid3_lib::BigEndian2Int($TagData['data'])), 6, '0', STR_PAD_LEFT)); + break; + + default: + if ($this->ReturnAllTagData) { + $info['swf']['tags'][] = $TagData; + } + break; + } + + $CurrentOffset += $TagLength; + } + + return true; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.ts.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.ts.php new file mode 100644 index 00000000..474503a2 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.ts.php @@ -0,0 +1,88 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio-video.ts.php // +// module for analyzing MPEG Transport Stream (.ts) files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_ts extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + $TSheader = $this->fread(19); + $magic = "\x47"; + if (substr($TSheader, 0, 1) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at '.$info['avdataoffset'].', found '.getid3_lib::PrintHexBytes(substr($TSheader, 0, 1)).' instead.'); + return false; + } + $info['fileformat'] = 'ts'; + + // http://en.wikipedia.org/wiki/.ts + + $offset = 0; + $info['ts']['packet']['sync'] = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 1)); $offset += 1; + $pid_flags_raw = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 2)); $offset += 2; + $SAC_raw = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 1)); $offset += 1; + $info['ts']['packet']['flags']['transport_error_indicator'] = (bool) ($pid_flags_raw & 0x8000); // Set by demodulator if can't correct errors in the stream, to tell the demultiplexer that the packet has an uncorrectable error + $info['ts']['packet']['flags']['payload_unit_start_indicator'] = (bool) ($pid_flags_raw & 0x4000); // 1 means start of PES data or PSI otherwise zero only. + $info['ts']['packet']['flags']['transport_high_priority'] = (bool) ($pid_flags_raw & 0x2000); // 1 means higher priority than other packets with the same PID. + $info['ts']['packet']['packet_id'] = ($pid_flags_raw & 0x1FFF) >> 0; + + $info['ts']['packet']['raw']['scrambling_control'] = ($SAC_raw & 0xC0) >> 6; + $info['ts']['packet']['flags']['adaption_field_exists'] = (bool) ($SAC_raw & 0x20); + $info['ts']['packet']['flags']['payload_exists'] = (bool) ($SAC_raw & 0x10); + $info['ts']['packet']['continuity_counter'] = ($SAC_raw & 0x0F) >> 0; // Incremented only when a payload is present + $info['ts']['packet']['scrambling_control'] = $this->TSscramblingControlLookup($info['ts']['packet']['raw']['scrambling_control']); + + if ($info['ts']['packet']['flags']['adaption_field_exists']) { + $AdaptionField_raw = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 2)); $offset += 2; + $info['ts']['packet']['adaption']['field_length'] = ($AdaptionField_raw & 0xFF00) >> 8; // Number of bytes in the adaptation field immediately following this byte + $info['ts']['packet']['adaption']['flags']['discontinuity'] = (bool) ($AdaptionField_raw & 0x0080); // Set to 1 if current TS packet is in a discontinuity state with respect to either the continuity counter or the program clock reference + $info['ts']['packet']['adaption']['flags']['random_access'] = (bool) ($AdaptionField_raw & 0x0040); // Set to 1 if the PES packet in this TS packet starts a video/audio sequence + $info['ts']['packet']['adaption']['flags']['high_priority'] = (bool) ($AdaptionField_raw & 0x0020); // 1 = higher priority + $info['ts']['packet']['adaption']['flags']['pcr'] = (bool) ($AdaptionField_raw & 0x0010); // 1 means adaptation field does contain a PCR field + $info['ts']['packet']['adaption']['flags']['opcr'] = (bool) ($AdaptionField_raw & 0x0008); // 1 means adaptation field does contain an OPCR field + $info['ts']['packet']['adaption']['flags']['splice_point'] = (bool) ($AdaptionField_raw & 0x0004); // 1 means presence of splice countdown field in adaptation field + $info['ts']['packet']['adaption']['flags']['private_data'] = (bool) ($AdaptionField_raw & 0x0002); // 1 means presence of private data bytes in adaptation field + $info['ts']['packet']['adaption']['flags']['extension'] = (bool) ($AdaptionField_raw & 0x0001); // 1 means presence of adaptation field extension + if ($info['ts']['packet']['adaption']['flags']['pcr']) { + $info['ts']['packet']['adaption']['raw']['pcr'] = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 6)); $offset += 6; + } + if ($info['ts']['packet']['adaption']['flags']['opcr']) { + $info['ts']['packet']['adaption']['raw']['opcr'] = getid3_lib::BigEndian2Int(substr($TSheader, $offset, 6)); $offset += 6; + } + } + + $this->error('MPEG Transport Stream (.ts) parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + return false; + + } + + /** + * @param int $raw + * + * @return string + */ + public function TSscramblingControlLookup($raw) { + $TSscramblingControlLookup = array(0x00=>'not scrambled', 0x01=>'reserved', 0x02=>'scrambled, even key', 0x03=>'scrambled, odd key'); + return (isset($TSscramblingControlLookup[$raw]) ? $TSscramblingControlLookup[$raw] : 'invalid'); + } +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.wtv.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.wtv.php new file mode 100644 index 00000000..ed37abe3 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio-video.wtv.php @@ -0,0 +1,37 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.wtv.php // +// module for analyzing WTV (Windows Recorded TV Show) // +// audio-video files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_wtv extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'wtv'; + $info['video']['dataformat'] = 'wtv'; + + $this->error('WTV (Windows Recorded TV Show) files not properly processed by this version of getID3() ['.$this->getid3->version().']'); + + return true; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.aa.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.aa.php new file mode 100644 index 00000000..171e72d1 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.aa.php @@ -0,0 +1,64 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.aa.php // +// module for analyzing Audible Audiobook files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_aa extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + $AAheader = $this->fread(8); + + $magic = "\x57\x90\x75\x36"; + if (substr($AAheader, 4, 4) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($AAheader, 4, 4)).'"'); + return false; + } + + // shortcut + $info['aa'] = array(); + $thisfile_aa = &$info['aa']; + + $info['fileformat'] = 'aa'; + $info['audio']['dataformat'] = 'aa'; + $this->error('Audible Audiobook (.aa) parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + return false; + $info['audio']['bitrate_mode'] = 'cbr'; // is it? + $thisfile_aa['encoding'] = 'ISO-8859-1'; + + $thisfile_aa['filesize'] = getid3_lib::BigEndian2Int(substr($AAheader, 0, 4)); + if ($thisfile_aa['filesize'] > ($info['avdataend'] - $info['avdataoffset'])) { + $this->warning('Possible truncated file - expecting "'.$thisfile_aa['filesize'].'" bytes of data, only found '.($info['avdataend'] - $info['avdataoffset']).' bytes"'); + } + + $info['audio']['bits_per_sample'] = 16; // is it? + $info['audio']['sample_rate'] = $thisfile_aa['sample_rate']; + $info['audio']['channels'] = $thisfile_aa['channels']; + + //$info['playtime_seconds'] = 0; + //$info['audio']['bitrate'] = 0; + + return true; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.aac.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.aac.php new file mode 100644 index 00000000..5b8448d2 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.aac.php @@ -0,0 +1,541 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.aac.php // +// module for analyzing AAC Audio files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_aac extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + if ($this->fread(4) == 'ADIF') { + $this->getAACADIFheaderFilepointer(); + } else { + $this->getAACADTSheaderFilepointer(); + } + return true; + } + + /** + * @return bool + */ + public function getAACADIFheaderFilepointer() { + $info = &$this->getid3->info; + $info['fileformat'] = 'aac'; + $info['audio']['dataformat'] = 'aac'; + $info['audio']['lossless'] = false; + + $this->fseek($info['avdataoffset']); + $AACheader = $this->fread(1024); + $offset = 0; + + if (substr($AACheader, 0, 4) == 'ADIF') { + + // http://faac.sourceforge.net/wiki/index.php?page=ADIF + + // http://libmpeg.org/mpeg4/doc/w2203tfs.pdf + // adif_header() { + // adif_id 32 + // copyright_id_present 1 + // if( copyright_id_present ) + // copyright_id 72 + // original_copy 1 + // home 1 + // bitstream_type 1 + // bitrate 23 + // num_program_config_elements 4 + // for (i = 0; i < num_program_config_elements + 1; i++ ) { + // if( bitstream_type == '0' ) + // adif_buffer_fullness 20 + // program_config_element() + // } + // } + + $AACheaderBitstream = getid3_lib::BigEndian2Bin($AACheader); + $bitoffset = 0; + + $info['aac']['header_type'] = 'ADIF'; + $bitoffset += 32; + $info['aac']['header']['mpeg_version'] = 4; + + $info['aac']['header']['copyright'] = substr($AACheaderBitstream, $bitoffset, 1) == '1'; + $bitoffset += 1; + if ($info['aac']['header']['copyright']) { + $info['aac']['header']['copyright_id'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 72)); + $bitoffset += 72; + } + $info['aac']['header']['original_copy'] = substr($AACheaderBitstream, $bitoffset, 1) == '1'; + $bitoffset += 1; + $info['aac']['header']['home'] = substr($AACheaderBitstream, $bitoffset, 1) == '1'; + $bitoffset += 1; + $info['aac']['header']['is_vbr'] = substr($AACheaderBitstream, $bitoffset, 1) == '1'; + $bitoffset += 1; + if ($info['aac']['header']['is_vbr']) { + $info['audio']['bitrate_mode'] = 'vbr'; + $info['aac']['header']['bitrate_max'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23)); + $bitoffset += 23; + } else { + $info['audio']['bitrate_mode'] = 'cbr'; + $info['aac']['header']['bitrate'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23)); + $bitoffset += 23; + $info['audio']['bitrate'] = $info['aac']['header']['bitrate']; + } + if ($info['audio']['bitrate'] == 0) { + $this->error('Corrupt AAC file: bitrate_audio == zero'); + return false; + } + $info['aac']['header']['num_program_configs'] = 1 + getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + + for ($i = 0; $i < $info['aac']['header']['num_program_configs']; $i++) { + // http://www.audiocoding.com/wiki/index.php?page=program_config_element + + // buffer_fullness 20 + + // element_instance_tag 4 + // object_type 2 + // sampling_frequency_index 4 + // num_front_channel_elements 4 + // num_side_channel_elements 4 + // num_back_channel_elements 4 + // num_lfe_channel_elements 2 + // num_assoc_data_elements 3 + // num_valid_cc_elements 4 + // mono_mixdown_present 1 + // mono_mixdown_element_number 4 if mono_mixdown_present == 1 + // stereo_mixdown_present 1 + // stereo_mixdown_element_number 4 if stereo_mixdown_present == 1 + // matrix_mixdown_idx_present 1 + // matrix_mixdown_idx 2 if matrix_mixdown_idx_present == 1 + // pseudo_surround_enable 1 if matrix_mixdown_idx_present == 1 + // for (i = 0; i < num_front_channel_elements; i++) { + // front_element_is_cpe[i] 1 + // front_element_tag_select[i] 4 + // } + // for (i = 0; i < num_side_channel_elements; i++) { + // side_element_is_cpe[i] 1 + // side_element_tag_select[i] 4 + // } + // for (i = 0; i < num_back_channel_elements; i++) { + // back_element_is_cpe[i] 1 + // back_element_tag_select[i] 4 + // } + // for (i = 0; i < num_lfe_channel_elements; i++) { + // lfe_element_tag_select[i] 4 + // } + // for (i = 0; i < num_assoc_data_elements; i++) { + // assoc_data_element_tag_select[i] 4 + // } + // for (i = 0; i < num_valid_cc_elements; i++) { + // cc_element_is_ind_sw[i] 1 + // valid_cc_element_tag_select[i] 4 + // } + // byte_alignment() VAR + // comment_field_bytes 8 + // for (i = 0; i < comment_field_bytes; i++) { + // comment_field_data[i] 8 + // } + + if (!$info['aac']['header']['is_vbr']) { + $info['aac']['program_configs'][$i]['buffer_fullness'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 20)); + $bitoffset += 20; + } + $info['aac']['program_configs'][$i]['element_instance_tag'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + $info['aac']['program_configs'][$i]['object_type'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); + $bitoffset += 2; + $info['aac']['program_configs'][$i]['sampling_frequency_index'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + $info['aac']['program_configs'][$i]['num_front_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + $info['aac']['program_configs'][$i]['num_side_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + $info['aac']['program_configs'][$i]['num_back_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + $info['aac']['program_configs'][$i]['num_lfe_channel_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); + $bitoffset += 2; + $info['aac']['program_configs'][$i]['num_assoc_data_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 3)); + $bitoffset += 3; + $info['aac']['program_configs'][$i]['num_valid_cc_elements'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + $info['aac']['program_configs'][$i]['mono_mixdown_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + if ($info['aac']['program_configs'][$i]['mono_mixdown_present']) { + $info['aac']['program_configs'][$i]['mono_mixdown_element_number'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + $info['aac']['program_configs'][$i]['stereo_mixdown_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + if ($info['aac']['program_configs'][$i]['stereo_mixdown_present']) { + $info['aac']['program_configs'][$i]['stereo_mixdown_element_number'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + $info['aac']['program_configs'][$i]['matrix_mixdown_idx_present'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + if ($info['aac']['program_configs'][$i]['matrix_mixdown_idx_present']) { + $info['aac']['program_configs'][$i]['matrix_mixdown_idx'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2)); + $bitoffset += 2; + $info['aac']['program_configs'][$i]['pseudo_surround_enable'] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + } + for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_front_channel_elements']; $j++) { + $info['aac']['program_configs'][$i]['front_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + $info['aac']['program_configs'][$i]['front_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_side_channel_elements']; $j++) { + $info['aac']['program_configs'][$i]['side_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + $info['aac']['program_configs'][$i]['side_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_back_channel_elements']; $j++) { + $info['aac']['program_configs'][$i]['back_element_is_cpe'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + $info['aac']['program_configs'][$i]['back_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_lfe_channel_elements']; $j++) { + $info['aac']['program_configs'][$i]['lfe_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_assoc_data_elements']; $j++) { + $info['aac']['program_configs'][$i]['assoc_data_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + for ($j = 0; $j < $info['aac']['program_configs'][$i]['num_valid_cc_elements']; $j++) { + $info['aac']['program_configs'][$i]['cc_element_is_ind_sw'][$j] = (bool) getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1)); + $bitoffset += 1; + $info['aac']['program_configs'][$i]['valid_cc_element_tag_select'][$j] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4)); + $bitoffset += 4; + } + + $bitoffset = ceil($bitoffset / 8) * 8; + + $info['aac']['program_configs'][$i]['comment_field_bytes'] = getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 8)); + $bitoffset += 8; + $info['aac']['program_configs'][$i]['comment_field'] = getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 8 * $info['aac']['program_configs'][$i]['comment_field_bytes'])); + $bitoffset += 8 * $info['aac']['program_configs'][$i]['comment_field_bytes']; + + + $info['aac']['header']['profile'] = self::AACprofileLookup($info['aac']['program_configs'][$i]['object_type'], $info['aac']['header']['mpeg_version']); + $info['aac']['program_configs'][$i]['sampling_frequency'] = self::AACsampleRateLookup($info['aac']['program_configs'][$i]['sampling_frequency_index']); + $info['audio']['sample_rate'] = $info['aac']['program_configs'][$i]['sampling_frequency']; + $info['audio']['channels'] = self::AACchannelCountCalculate($info['aac']['program_configs'][$i]); + if ($info['aac']['program_configs'][$i]['comment_field']) { + $info['aac']['comments'][] = $info['aac']['program_configs'][$i]['comment_field']; + } + } + $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['audio']['bitrate']; + + $info['audio']['encoder_options'] = $info['aac']['header_type'].' '.$info['aac']['header']['profile']; + + + + return true; + + } else { + + unset($info['fileformat']); + unset($info['aac']); + $this->error('AAC-ADIF synch not found at offset '.$info['avdataoffset'].' (expected "ADIF", found "'.substr($AACheader, 0, 4).'" instead)'); + return false; + + } + + } + + /** + * @param int $MaxFramesToScan + * @param bool $ReturnExtendedInfo + * + * @return bool + */ + public function getAACADTSheaderFilepointer($MaxFramesToScan=1000000, $ReturnExtendedInfo=false) { + $info = &$this->getid3->info; + + // based loosely on code from AACfile by Jurgen Faul + // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html + + + // http://faac.sourceforge.net/wiki/index.php?page=ADTS // dead link + // http://wiki.multimedia.cx/index.php?title=ADTS + + // * ADTS Fixed Header: these don't change from frame to frame + // syncword 12 always: '111111111111' + // ID 1 0: MPEG-4, 1: MPEG-2 + // MPEG layer 2 If you send AAC in MPEG-TS, set to 0 + // protection_absent 1 0: CRC present; 1: no CRC + // profile 2 0: AAC Main; 1: AAC LC (Low Complexity); 2: AAC SSR (Scalable Sample Rate); 3: AAC LTP (Long Term Prediction) + // sampling_frequency_index 4 15 not allowed + // private_bit 1 usually 0 + // channel_configuration 3 + // original/copy 1 0: original; 1: copy + // home 1 usually 0 + // emphasis 2 only if ID == 0 (ie MPEG-4) // not present in some documentation? + + // * ADTS Variable Header: these can change from frame to frame + // copyright_identification_bit 1 + // copyright_identification_start 1 + // aac_frame_length 13 length of the frame including header (in bytes) + // adts_buffer_fullness 11 0x7FF indicates VBR + // no_raw_data_blocks_in_frame 2 + + // * ADTS Error check + // crc_check 16 only if protection_absent == 0 + + $byteoffset = $info['avdataoffset']; + $framenumber = 0; + + // Init bit pattern array + static $decbin = array(); + + // Populate $bindec + for ($i = 0; $i < 256; $i++) { + $decbin[chr($i)] = str_pad(decbin($i), 8, '0', STR_PAD_LEFT); + } + + // used to calculate bitrate below + $BitrateCache = array(); + + + while (true) { + // breaks out when end-of-file encountered, or invalid data found, + // or MaxFramesToScan frames have been scanned + + if (!getid3_lib::intValueSupported($byteoffset)) { + $this->warning('Unable to parse AAC file beyond '.$this->ftell().' (PHP does not support file operations beyond '.round(PHP_INT_MAX / 1073741824).'GB)'); + return false; + } + $this->fseek($byteoffset); + + // First get substring + $substring = $this->fread(9); // header is 7 bytes (or 9 if CRC is present) + $substringlength = strlen($substring); + if ($substringlength != 9) { + $this->error('Failed to read 7 bytes at offset '.($this->ftell() - $substringlength).' (only read '.$substringlength.' bytes)'); + return false; + } + // this would be easier with 64-bit math, but split it up to allow for 32-bit: + $header1 = getid3_lib::BigEndian2Int(substr($substring, 0, 2)); + $header2 = getid3_lib::BigEndian2Int(substr($substring, 2, 4)); + $header3 = getid3_lib::BigEndian2Int(substr($substring, 6, 1)); + + $info['aac']['header']['raw']['syncword'] = ($header1 & 0xFFF0) >> 4; + if ($info['aac']['header']['raw']['syncword'] != 0x0FFF) { + $this->error('Synch pattern (0x0FFF) not found at offset '.($this->ftell() - $substringlength).' (found 0x0'.strtoupper(dechex($info['aac']['header']['raw']['syncword'])).' instead)'); + //if ($info['fileformat'] == 'aac') { + // return true; + //} + unset($info['aac']); + return false; + } + + // Gather info for first frame only - this takes time to do 1000 times! + if ($framenumber == 0) { + $info['aac']['header_type'] = 'ADTS'; + $info['fileformat'] = 'aac'; + $info['audio']['dataformat'] = 'aac'; + + $info['aac']['header']['raw']['mpeg_version'] = ($header1 & 0x0008) >> 3; + $info['aac']['header']['raw']['mpeg_layer'] = ($header1 & 0x0006) >> 1; + $info['aac']['header']['raw']['protection_absent'] = ($header1 & 0x0001) >> 0; + + $info['aac']['header']['raw']['profile_code'] = ($header2 & 0xC0000000) >> 30; + $info['aac']['header']['raw']['sample_rate_code'] = ($header2 & 0x3C000000) >> 26; + $info['aac']['header']['raw']['private_stream'] = ($header2 & 0x02000000) >> 25; + $info['aac']['header']['raw']['channels_code'] = ($header2 & 0x01C00000) >> 22; + $info['aac']['header']['raw']['original'] = ($header2 & 0x00200000) >> 21; + $info['aac']['header']['raw']['home'] = ($header2 & 0x00100000) >> 20; + $info['aac']['header']['raw']['copyright_stream'] = ($header2 & 0x00080000) >> 19; + $info['aac']['header']['raw']['copyright_start'] = ($header2 & 0x00040000) >> 18; + $info['aac']['header']['raw']['frame_length'] = ($header2 & 0x0003FFE0) >> 5; + + $info['aac']['header']['mpeg_version'] = ($info['aac']['header']['raw']['mpeg_version'] ? 2 : 4); + $info['aac']['header']['crc_present'] = ($info['aac']['header']['raw']['protection_absent'] ? false: true); + $info['aac']['header']['profile'] = self::AACprofileLookup($info['aac']['header']['raw']['profile_code'], $info['aac']['header']['mpeg_version']); + $info['aac']['header']['sample_frequency'] = self::AACsampleRateLookup($info['aac']['header']['raw']['sample_rate_code']); + $info['aac']['header']['private'] = (bool) $info['aac']['header']['raw']['private_stream']; + $info['aac']['header']['original'] = (bool) $info['aac']['header']['raw']['original']; + $info['aac']['header']['home'] = (bool) $info['aac']['header']['raw']['home']; + $info['aac']['header']['channels'] = (($info['aac']['header']['raw']['channels_code'] == 7) ? 8 : $info['aac']['header']['raw']['channels_code']); + if ($ReturnExtendedInfo) { + $info['aac'][$framenumber]['copyright_id_bit'] = (bool) $info['aac']['header']['raw']['copyright_stream']; + $info['aac'][$framenumber]['copyright_id_start'] = (bool) $info['aac']['header']['raw']['copyright_start']; + } + + if ($info['aac']['header']['raw']['mpeg_layer'] != 0) { + $this->warning('Layer error - expected "0", found "'.$info['aac']['header']['raw']['mpeg_layer'].'" instead'); + } + if ($info['aac']['header']['sample_frequency'] == 0) { + $this->error('Corrupt AAC file: sample_frequency == zero'); + return false; + } + + $info['audio']['sample_rate'] = $info['aac']['header']['sample_frequency']; + $info['audio']['channels'] = $info['aac']['header']['channels']; + } + + $FrameLength = ($header2 & 0x0003FFE0) >> 5; + + if (!isset($BitrateCache[$FrameLength])) { + $BitrateCache[$FrameLength] = ($info['aac']['header']['sample_frequency'] / 1024) * $FrameLength * 8; + } + getid3_lib::safe_inc($info['aac']['bitrate_distribution'][(string)$BitrateCache[$FrameLength]], 1); + + $info['aac'][$framenumber]['aac_frame_length'] = $FrameLength; + + $info['aac'][$framenumber]['adts_buffer_fullness'] = (($header2 & 0x0000001F) << 6) & (($header3 & 0xFC) >> 2); + if ($info['aac'][$framenumber]['adts_buffer_fullness'] == 0x07FF) { + $info['audio']['bitrate_mode'] = 'vbr'; + } else { + $info['audio']['bitrate_mode'] = 'cbr'; + } + $info['aac'][$framenumber]['num_raw_data_blocks'] = (($header3 & 0x03) >> 0); + + if ($info['aac']['header']['crc_present']) { + //$info['aac'][$framenumber]['crc'] = getid3_lib::BigEndian2Int(substr($substring, 7, 2); + } + + if (!$ReturnExtendedInfo) { + unset($info['aac'][$framenumber]); + } + + /* + $rounded_precision = 5000; + $info['aac']['bitrate_distribution_rounded'] = array(); + foreach ($info['aac']['bitrate_distribution'] as $bitrate => $count) { + $rounded_bitrate = round($bitrate / $rounded_precision) * $rounded_precision; + getid3_lib::safe_inc($info['aac']['bitrate_distribution_rounded'][$rounded_bitrate], $count); + } + ksort($info['aac']['bitrate_distribution_rounded']); + */ + + $byteoffset += $FrameLength; + if ((++$framenumber < $MaxFramesToScan) && (($byteoffset + 10) < $info['avdataend'])) { + + // keep scanning + + } else { + + $info['aac']['frames'] = $framenumber; + $info['playtime_seconds'] = ($info['avdataend'] / $byteoffset) * (($framenumber * 1024) / $info['aac']['header']['sample_frequency']); // (1 / % of file scanned) * (samples / (samples/sec)) = seconds + if ($info['playtime_seconds'] == 0) { + $this->error('Corrupt AAC file: playtime_seconds == zero'); + return false; + } + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + ksort($info['aac']['bitrate_distribution']); + + $info['audio']['encoder_options'] = $info['aac']['header_type'].' '.$info['aac']['header']['profile']; + + return true; + + } + } + // should never get here. + } + + /** + * @param int $samplerateid + * + * @return int|string + */ + public static function AACsampleRateLookup($samplerateid) { + static $AACsampleRateLookup = array(); + if (empty($AACsampleRateLookup)) { + $AACsampleRateLookup[0] = 96000; + $AACsampleRateLookup[1] = 88200; + $AACsampleRateLookup[2] = 64000; + $AACsampleRateLookup[3] = 48000; + $AACsampleRateLookup[4] = 44100; + $AACsampleRateLookup[5] = 32000; + $AACsampleRateLookup[6] = 24000; + $AACsampleRateLookup[7] = 22050; + $AACsampleRateLookup[8] = 16000; + $AACsampleRateLookup[9] = 12000; + $AACsampleRateLookup[10] = 11025; + $AACsampleRateLookup[11] = 8000; + $AACsampleRateLookup[12] = 0; + $AACsampleRateLookup[13] = 0; + $AACsampleRateLookup[14] = 0; + $AACsampleRateLookup[15] = 0; + } + return (isset($AACsampleRateLookup[$samplerateid]) ? $AACsampleRateLookup[$samplerateid] : 'invalid'); + } + + /** + * @param int $profileid + * @param int $mpegversion + * + * @return string + */ + public static function AACprofileLookup($profileid, $mpegversion) { + static $AACprofileLookup = array(); + if (empty($AACprofileLookup)) { + $AACprofileLookup[2][0] = 'Main profile'; + $AACprofileLookup[2][1] = 'Low Complexity profile (LC)'; + $AACprofileLookup[2][2] = 'Scalable Sample Rate profile (SSR)'; + $AACprofileLookup[2][3] = '(reserved)'; + $AACprofileLookup[4][0] = 'AAC_MAIN'; + $AACprofileLookup[4][1] = 'AAC_LC'; + $AACprofileLookup[4][2] = 'AAC_SSR'; + $AACprofileLookup[4][3] = 'AAC_LTP'; + } + return (isset($AACprofileLookup[$mpegversion][$profileid]) ? $AACprofileLookup[$mpegversion][$profileid] : 'invalid'); + } + + /** + * @param array $program_configs + * + * @return int + */ + public static function AACchannelCountCalculate($program_configs) { + $channels = 0; + for ($i = 0; $i < $program_configs['num_front_channel_elements']; $i++) { + $channels++; + if ($program_configs['front_element_is_cpe'][$i]) { + // each front element is channel pair (CPE = Channel Pair Element) + $channels++; + } + } + for ($i = 0; $i < $program_configs['num_side_channel_elements']; $i++) { + $channels++; + if ($program_configs['side_element_is_cpe'][$i]) { + // each side element is channel pair (CPE = Channel Pair Element) + $channels++; + } + } + for ($i = 0; $i < $program_configs['num_back_channel_elements']; $i++) { + $channels++; + if ($program_configs['back_element_is_cpe'][$i]) { + // each back element is channel pair (CPE = Channel Pair Element) + $channels++; + } + } + for ($i = 0; $i < $program_configs['num_lfe_channel_elements']; $i++) { + $channels++; + } + return $channels; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.ac3.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.ac3.php new file mode 100644 index 00000000..636ff8f1 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.ac3.php @@ -0,0 +1,823 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.ac3.php // +// module for analyzing AC-3 (aka Dolby Digital) audio files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_ac3 extends getid3_handler +{ + /** + * @var array + */ + private $AC3header = array(); + + /** + * @var int + */ + private $BSIoffset = 0; + + const syncword = 0x0B77; + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + ///AH + $info['ac3']['raw']['bsi'] = array(); + $thisfile_ac3 = &$info['ac3']; + $thisfile_ac3_raw = &$thisfile_ac3['raw']; + $thisfile_ac3_raw_bsi = &$thisfile_ac3_raw['bsi']; + + + // http://www.atsc.org/standards/a_52a.pdf + + $info['fileformat'] = 'ac3'; + + // An AC-3 serial coded audio bit stream is made up of a sequence of synchronization frames + // Each synchronization frame contains 6 coded audio blocks (AB), each of which represent 256 + // new audio samples per channel. A synchronization information (SI) header at the beginning + // of each frame contains information needed to acquire and maintain synchronization. A + // bit stream information (BSI) header follows SI, and contains parameters describing the coded + // audio service. The coded audio blocks may be followed by an auxiliary data (Aux) field. At the + // end of each frame is an error check field that includes a CRC word for error detection. An + // additional CRC word is located in the SI header, the use of which, by a decoder, is optional. + // + // syncinfo() | bsi() | AB0 | AB1 | AB2 | AB3 | AB4 | AB5 | Aux | CRC + + // syncinfo() { + // syncword 16 + // crc1 16 + // fscod 2 + // frmsizecod 6 + // } /* end of syncinfo */ + + $this->fseek($info['avdataoffset']); + $tempAC3header = $this->fread(100); // should be enough to cover all data, there are some variable-length fields...? + $this->AC3header['syncinfo'] = getid3_lib::BigEndian2Int(substr($tempAC3header, 0, 2)); + $this->AC3header['bsi'] = getid3_lib::BigEndian2Bin(substr($tempAC3header, 2)); + $thisfile_ac3_raw_bsi['bsid'] = (getid3_lib::LittleEndian2Int(substr($tempAC3header, 5, 1)) & 0xF8) >> 3; // AC3 and E-AC3 put the "bsid" version identifier in the same place, but unfortnately the 4 bytes between the syncword and the version identifier are interpreted differently, so grab it here so the following code structure can make sense + unset($tempAC3header); + + if ($this->AC3header['syncinfo'] !== self::syncword) { + if (!$this->isDependencyFor('matroska')) { + unset($info['fileformat'], $info['ac3']); + return $this->error('Expecting "'.dechex(self::syncword).'" at offset '.$info['avdataoffset'].', found "'.dechex($this->AC3header['syncinfo']).'"'); + } + } + + $info['audio']['dataformat'] = 'ac3'; + $info['audio']['bitrate_mode'] = 'cbr'; + $info['audio']['lossless'] = false; + + if ($thisfile_ac3_raw_bsi['bsid'] <= 8) { + + $thisfile_ac3_raw_bsi['crc1'] = getid3_lib::Bin2Dec($this->readHeaderBSI(16)); + $thisfile_ac3_raw_bsi['fscod'] = $this->readHeaderBSI(2); // 5.4.1.3 + $thisfile_ac3_raw_bsi['frmsizecod'] = $this->readHeaderBSI(6); // 5.4.1.4 + if ($thisfile_ac3_raw_bsi['frmsizecod'] > 37) { // binary: 100101 - see Table 5.18 Frame Size Code Table (1 word = 16 bits) + $this->warning('Unexpected ac3.bsi.frmsizecod value: '.$thisfile_ac3_raw_bsi['frmsizecod'].', bitrate not set correctly'); + } + + $thisfile_ac3_raw_bsi['bsid'] = $this->readHeaderBSI(5); // we already know this from pre-parsing the version identifier, but re-read it to let the bitstream flow as intended + $thisfile_ac3_raw_bsi['bsmod'] = $this->readHeaderBSI(3); + $thisfile_ac3_raw_bsi['acmod'] = $this->readHeaderBSI(3); + + if ($thisfile_ac3_raw_bsi['acmod'] & 0x01) { + // If the lsb of acmod is a 1, center channel is in use and cmixlev follows in the bit stream. + $thisfile_ac3_raw_bsi['cmixlev'] = $this->readHeaderBSI(2); + $thisfile_ac3['center_mix_level'] = self::centerMixLevelLookup($thisfile_ac3_raw_bsi['cmixlev']); + } + + if ($thisfile_ac3_raw_bsi['acmod'] & 0x04) { + // If the msb of acmod is a 1, surround channels are in use and surmixlev follows in the bit stream. + $thisfile_ac3_raw_bsi['surmixlev'] = $this->readHeaderBSI(2); + $thisfile_ac3['surround_mix_level'] = self::surroundMixLevelLookup($thisfile_ac3_raw_bsi['surmixlev']); + } + + if ($thisfile_ac3_raw_bsi['acmod'] == 0x02) { + // When operating in the two channel mode, this 2-bit code indicates whether or not the program has been encoded in Dolby Surround. + $thisfile_ac3_raw_bsi['dsurmod'] = $this->readHeaderBSI(2); + $thisfile_ac3['dolby_surround_mode'] = self::dolbySurroundModeLookup($thisfile_ac3_raw_bsi['dsurmod']); + } + + $thisfile_ac3_raw_bsi['flags']['lfeon'] = (bool) $this->readHeaderBSI(1); + + // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1-31. + // The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent. + $thisfile_ac3_raw_bsi['dialnorm'] = $this->readHeaderBSI(5); // 5.4.2.8 dialnorm: Dialogue Normalization, 5 Bits + + $thisfile_ac3_raw_bsi['flags']['compr'] = (bool) $this->readHeaderBSI(1); // 5.4.2.9 compre: Compression Gain Word Exists, 1 Bit + if ($thisfile_ac3_raw_bsi['flags']['compr']) { + $thisfile_ac3_raw_bsi['compr'] = $this->readHeaderBSI(8); // 5.4.2.10 compr: Compression Gain Word, 8 Bits + $thisfile_ac3['heavy_compression'] = self::heavyCompression($thisfile_ac3_raw_bsi['compr']); + } + + $thisfile_ac3_raw_bsi['flags']['langcod'] = (bool) $this->readHeaderBSI(1); // 5.4.2.11 langcode: Language Code Exists, 1 Bit + if ($thisfile_ac3_raw_bsi['flags']['langcod']) { + $thisfile_ac3_raw_bsi['langcod'] = $this->readHeaderBSI(8); // 5.4.2.12 langcod: Language Code, 8 Bits + } + + $thisfile_ac3_raw_bsi['flags']['audprodinfo'] = (bool) $this->readHeaderBSI(1); // 5.4.2.13 audprodie: Audio Production Information Exists, 1 Bit + if ($thisfile_ac3_raw_bsi['flags']['audprodinfo']) { + $thisfile_ac3_raw_bsi['mixlevel'] = $this->readHeaderBSI(5); // 5.4.2.14 mixlevel: Mixing Level, 5 Bits + $thisfile_ac3_raw_bsi['roomtyp'] = $this->readHeaderBSI(2); // 5.4.2.15 roomtyp: Room Type, 2 Bits + + $thisfile_ac3['mixing_level'] = (80 + $thisfile_ac3_raw_bsi['mixlevel']).'dB'; + $thisfile_ac3['room_type'] = self::roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp']); + } + + + $thisfile_ac3_raw_bsi['dialnorm2'] = $this->readHeaderBSI(5); // 5.4.2.16 dialnorm2: Dialogue Normalization, ch2, 5 Bits + $thisfile_ac3['dialogue_normalization2'] = '-'.$thisfile_ac3_raw_bsi['dialnorm2'].'dB'; // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1-31. The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent. + + $thisfile_ac3_raw_bsi['flags']['compr2'] = (bool) $this->readHeaderBSI(1); // 5.4.2.17 compr2e: Compression Gain Word Exists, ch2, 1 Bit + if ($thisfile_ac3_raw_bsi['flags']['compr2']) { + $thisfile_ac3_raw_bsi['compr2'] = $this->readHeaderBSI(8); // 5.4.2.18 compr2: Compression Gain Word, ch2, 8 Bits + $thisfile_ac3['heavy_compression2'] = self::heavyCompression($thisfile_ac3_raw_bsi['compr2']); + } + + $thisfile_ac3_raw_bsi['flags']['langcod2'] = (bool) $this->readHeaderBSI(1); // 5.4.2.19 langcod2e: Language Code Exists, ch2, 1 Bit + if ($thisfile_ac3_raw_bsi['flags']['langcod2']) { + $thisfile_ac3_raw_bsi['langcod2'] = $this->readHeaderBSI(8); // 5.4.2.20 langcod2: Language Code, ch2, 8 Bits + } + + $thisfile_ac3_raw_bsi['flags']['audprodinfo2'] = (bool) $this->readHeaderBSI(1); // 5.4.2.21 audprodi2e: Audio Production Information Exists, ch2, 1 Bit + if ($thisfile_ac3_raw_bsi['flags']['audprodinfo2']) { + $thisfile_ac3_raw_bsi['mixlevel2'] = $this->readHeaderBSI(5); // 5.4.2.22 mixlevel2: Mixing Level, ch2, 5 Bits + $thisfile_ac3_raw_bsi['roomtyp2'] = $this->readHeaderBSI(2); // 5.4.2.23 roomtyp2: Room Type, ch2, 2 Bits + + $thisfile_ac3['mixing_level2'] = (80 + $thisfile_ac3_raw_bsi['mixlevel2']).'dB'; + $thisfile_ac3['room_type2'] = self::roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp2']); + } + + $thisfile_ac3_raw_bsi['copyright'] = (bool) $this->readHeaderBSI(1); // 5.4.2.24 copyrightb: Copyright Bit, 1 Bit + + $thisfile_ac3_raw_bsi['original'] = (bool) $this->readHeaderBSI(1); // 5.4.2.25 origbs: Original Bit Stream, 1 Bit + + $thisfile_ac3_raw_bsi['flags']['timecod1'] = $this->readHeaderBSI(2); // 5.4.2.26 timecod1e, timcode2e: Time Code (first and second) Halves Exist, 2 Bits + if ($thisfile_ac3_raw_bsi['flags']['timecod1'] & 0x01) { + $thisfile_ac3_raw_bsi['timecod1'] = $this->readHeaderBSI(14); // 5.4.2.27 timecod1: Time code first half, 14 bits + $thisfile_ac3['timecode1'] = 0; + $thisfile_ac3['timecode1'] += (($thisfile_ac3_raw_bsi['timecod1'] & 0x3E00) >> 9) * 3600; // The first 5 bits of this 14-bit field represent the time in hours, with valid values of 0�23 + $thisfile_ac3['timecode1'] += (($thisfile_ac3_raw_bsi['timecod1'] & 0x01F8) >> 3) * 60; // The next 6 bits represent the time in minutes, with valid values of 0�59 + $thisfile_ac3['timecode1'] += (($thisfile_ac3_raw_bsi['timecod1'] & 0x0003) >> 0) * 8; // The final 3 bits represents the time in 8 second increments, with valid values of 0�7 (representing 0, 8, 16, ... 56 seconds) + } + if ($thisfile_ac3_raw_bsi['flags']['timecod1'] & 0x02) { + $thisfile_ac3_raw_bsi['timecod2'] = $this->readHeaderBSI(14); // 5.4.2.28 timecod2: Time code second half, 14 bits + $thisfile_ac3['timecode2'] = 0; + $thisfile_ac3['timecode2'] += (($thisfile_ac3_raw_bsi['timecod2'] & 0x3800) >> 11) * 1; // The first 3 bits of this 14-bit field represent the time in seconds, with valid values from 0�7 (representing 0-7 seconds) + $thisfile_ac3['timecode2'] += (($thisfile_ac3_raw_bsi['timecod2'] & 0x07C0) >> 6) * (1 / 30); // The next 5 bits represents the time in frames, with valid values from 0�29 (one frame = 1/30th of a second) + $thisfile_ac3['timecode2'] += (($thisfile_ac3_raw_bsi['timecod2'] & 0x003F) >> 0) * ((1 / 30) / 60); // The final 6 bits represents fractions of 1/64 of a frame, with valid values from 0�63 + } + + $thisfile_ac3_raw_bsi['flags']['addbsi'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['addbsi']) { + $thisfile_ac3_raw_bsi['addbsi_length'] = $this->readHeaderBSI(6) + 1; // This 6-bit code, which exists only if addbside is a 1, indicates the length in bytes of additional bit stream information. The valid range of addbsil is 0�63, indicating 1�64 additional bytes, respectively. + + $this->AC3header['bsi'] .= getid3_lib::BigEndian2Bin($this->fread($thisfile_ac3_raw_bsi['addbsi_length'])); + + $thisfile_ac3_raw_bsi['addbsi_data'] = substr($this->AC3header['bsi'], $this->BSIoffset, $thisfile_ac3_raw_bsi['addbsi_length'] * 8); + $this->BSIoffset += $thisfile_ac3_raw_bsi['addbsi_length'] * 8; + } + + + } elseif ($thisfile_ac3_raw_bsi['bsid'] <= 16) { // E-AC3 + + + $this->error('E-AC3 parsing is incomplete and experimental in this version of getID3 ('.$this->getid3->version().'). Notably the bitrate calculations are wrong -- value might (or not) be correct, but it is not calculated correctly. Email info@getid3.org if you know how to calculate EAC3 bitrate correctly.'); + $info['audio']['dataformat'] = 'eac3'; + + $thisfile_ac3_raw_bsi['strmtyp'] = $this->readHeaderBSI(2); + $thisfile_ac3_raw_bsi['substreamid'] = $this->readHeaderBSI(3); + $thisfile_ac3_raw_bsi['frmsiz'] = $this->readHeaderBSI(11); + $thisfile_ac3_raw_bsi['fscod'] = $this->readHeaderBSI(2); + if ($thisfile_ac3_raw_bsi['fscod'] == 3) { + $thisfile_ac3_raw_bsi['fscod2'] = $this->readHeaderBSI(2); + $thisfile_ac3_raw_bsi['numblkscod'] = 3; // six blocks per syncframe + } else { + $thisfile_ac3_raw_bsi['numblkscod'] = $this->readHeaderBSI(2); + } + $thisfile_ac3['bsi']['blocks_per_sync_frame'] = self::blocksPerSyncFrame($thisfile_ac3_raw_bsi['numblkscod']); + $thisfile_ac3_raw_bsi['acmod'] = $this->readHeaderBSI(3); + $thisfile_ac3_raw_bsi['flags']['lfeon'] = (bool) $this->readHeaderBSI(1); + $thisfile_ac3_raw_bsi['bsid'] = $this->readHeaderBSI(5); // we already know this from pre-parsing the version identifier, but re-read it to let the bitstream flow as intended + $thisfile_ac3_raw_bsi['dialnorm'] = $this->readHeaderBSI(5); + $thisfile_ac3_raw_bsi['flags']['compr'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['compr']) { + $thisfile_ac3_raw_bsi['compr'] = $this->readHeaderBSI(8); + } + if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value) + $thisfile_ac3_raw_bsi['dialnorm2'] = $this->readHeaderBSI(5); + $thisfile_ac3_raw_bsi['flags']['compr2'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['compr2']) { + $thisfile_ac3_raw_bsi['compr2'] = $this->readHeaderBSI(8); + } + } + if ($thisfile_ac3_raw_bsi['strmtyp'] == 1) { // if dependent stream + $thisfile_ac3_raw_bsi['flags']['chanmap'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['chanmap']) { + $thisfile_ac3_raw_bsi['chanmap'] = $this->readHeaderBSI(8); + } + } + $thisfile_ac3_raw_bsi['flags']['mixmdat'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['mixmdat']) { // Mixing metadata + if ($thisfile_ac3_raw_bsi['acmod'] > 2) { // if more than 2 channels + $thisfile_ac3_raw_bsi['dmixmod'] = $this->readHeaderBSI(2); + } + if (($thisfile_ac3_raw_bsi['acmod'] & 0x01) && ($thisfile_ac3_raw_bsi['acmod'] > 2)) { // if three front channels exist + $thisfile_ac3_raw_bsi['ltrtcmixlev'] = $this->readHeaderBSI(3); + $thisfile_ac3_raw_bsi['lorocmixlev'] = $this->readHeaderBSI(3); + } + if ($thisfile_ac3_raw_bsi['acmod'] & 0x04) { // if a surround channel exists + $thisfile_ac3_raw_bsi['ltrtsurmixlev'] = $this->readHeaderBSI(3); + $thisfile_ac3_raw_bsi['lorosurmixlev'] = $this->readHeaderBSI(3); + } + if ($thisfile_ac3_raw_bsi['flags']['lfeon']) { // if the LFE channel exists + $thisfile_ac3_raw_bsi['flags']['lfemixlevcod'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['lfemixlevcod']) { + $thisfile_ac3_raw_bsi['lfemixlevcod'] = $this->readHeaderBSI(5); + } + } + if ($thisfile_ac3_raw_bsi['strmtyp'] == 0) { // if independent stream + $thisfile_ac3_raw_bsi['flags']['pgmscl'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['pgmscl']) { + $thisfile_ac3_raw_bsi['pgmscl'] = $this->readHeaderBSI(6); + } + if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value) + $thisfile_ac3_raw_bsi['flags']['pgmscl2'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['pgmscl2']) { + $thisfile_ac3_raw_bsi['pgmscl2'] = $this->readHeaderBSI(6); + } + } + $thisfile_ac3_raw_bsi['flags']['extpgmscl'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['extpgmscl']) { + $thisfile_ac3_raw_bsi['extpgmscl'] = $this->readHeaderBSI(6); + } + $thisfile_ac3_raw_bsi['mixdef'] = $this->readHeaderBSI(2); + if ($thisfile_ac3_raw_bsi['mixdef'] == 1) { // mixing option 2 + $thisfile_ac3_raw_bsi['premixcmpsel'] = (bool) $this->readHeaderBSI(1); + $thisfile_ac3_raw_bsi['drcsrc'] = (bool) $this->readHeaderBSI(1); + $thisfile_ac3_raw_bsi['premixcmpscl'] = $this->readHeaderBSI(3); + } elseif ($thisfile_ac3_raw_bsi['mixdef'] == 2) { // mixing option 3 + $thisfile_ac3_raw_bsi['mixdata'] = $this->readHeaderBSI(12); + } elseif ($thisfile_ac3_raw_bsi['mixdef'] == 3) { // mixing option 4 + $mixdefbitsread = 0; + $thisfile_ac3_raw_bsi['mixdeflen'] = $this->readHeaderBSI(5); $mixdefbitsread += 5; + $thisfile_ac3_raw_bsi['flags']['mixdata2'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['mixdata2']) { + $thisfile_ac3_raw_bsi['premixcmpsel'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + $thisfile_ac3_raw_bsi['drcsrc'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + $thisfile_ac3_raw_bsi['premixcmpscl'] = $this->readHeaderBSI(3); $mixdefbitsread += 3; + $thisfile_ac3_raw_bsi['flags']['extpgmlscl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmlscl']) { + $thisfile_ac3_raw_bsi['extpgmlscl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; + } + $thisfile_ac3_raw_bsi['flags']['extpgmcscl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmcscl']) { + $thisfile_ac3_raw_bsi['extpgmcscl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; + } + $thisfile_ac3_raw_bsi['flags']['extpgmrscl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmrscl']) { + $thisfile_ac3_raw_bsi['extpgmrscl'] = $this->readHeaderBSI(4); + } + $thisfile_ac3_raw_bsi['flags']['extpgmlsscl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmlsscl']) { + $thisfile_ac3_raw_bsi['extpgmlsscl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; + } + $thisfile_ac3_raw_bsi['flags']['extpgmrsscl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmrsscl']) { + $thisfile_ac3_raw_bsi['extpgmrsscl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; + } + $thisfile_ac3_raw_bsi['flags']['extpgmlfescl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmlfescl']) { + $thisfile_ac3_raw_bsi['extpgmlfescl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; + } + $thisfile_ac3_raw_bsi['flags']['dmixscl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['dmixscl']) { + $thisfile_ac3_raw_bsi['dmixscl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; + } + $thisfile_ac3_raw_bsi['flags']['addch'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['addch']) { + $thisfile_ac3_raw_bsi['flags']['extpgmaux1scl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmaux1scl']) { + $thisfile_ac3_raw_bsi['extpgmaux1scl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; + } + $thisfile_ac3_raw_bsi['flags']['extpgmaux2scl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['extpgmaux2scl']) { + $thisfile_ac3_raw_bsi['extpgmaux2scl'] = $this->readHeaderBSI(4); $mixdefbitsread += 4; + } + } + } + $thisfile_ac3_raw_bsi['flags']['mixdata3'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['mixdata3']) { + $thisfile_ac3_raw_bsi['spchdat'] = $this->readHeaderBSI(5); $mixdefbitsread += 5; + $thisfile_ac3_raw_bsi['flags']['addspchdat'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['addspchdat']) { + $thisfile_ac3_raw_bsi['spchdat1'] = $this->readHeaderBSI(5); $mixdefbitsread += 5; + $thisfile_ac3_raw_bsi['spchan1att'] = $this->readHeaderBSI(2); $mixdefbitsread += 2; + $thisfile_ac3_raw_bsi['flags']['addspchdat1'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1; + if ($thisfile_ac3_raw_bsi['flags']['addspchdat1']) { + $thisfile_ac3_raw_bsi['spchdat2'] = $this->readHeaderBSI(5); $mixdefbitsread += 5; + $thisfile_ac3_raw_bsi['spchan2att'] = $this->readHeaderBSI(3); $mixdefbitsread += 3; + } + } + } + $mixdata_bits = (8 * ($thisfile_ac3_raw_bsi['mixdeflen'] + 2)) - $mixdefbitsread; + $mixdata_fill = (($mixdata_bits % 8) ? 8 - ($mixdata_bits % 8) : 0); + $thisfile_ac3_raw_bsi['mixdata'] = $this->readHeaderBSI($mixdata_bits); + $thisfile_ac3_raw_bsi['mixdatafill'] = $this->readHeaderBSI($mixdata_fill); + unset($mixdefbitsread, $mixdata_bits, $mixdata_fill); + } + if ($thisfile_ac3_raw_bsi['acmod'] < 2) { // if mono or dual mono source + $thisfile_ac3_raw_bsi['flags']['paninfo'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['paninfo']) { + $thisfile_ac3_raw_bsi['panmean'] = $this->readHeaderBSI(8); + $thisfile_ac3_raw_bsi['paninfo'] = $this->readHeaderBSI(6); + } + if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value) + $thisfile_ac3_raw_bsi['flags']['paninfo2'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['paninfo2']) { + $thisfile_ac3_raw_bsi['panmean2'] = $this->readHeaderBSI(8); + $thisfile_ac3_raw_bsi['paninfo2'] = $this->readHeaderBSI(6); + } + } + } + $thisfile_ac3_raw_bsi['flags']['frmmixcfginfo'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['frmmixcfginfo']) { // mixing configuration information + if ($thisfile_ac3_raw_bsi['numblkscod'] == 0) { + $thisfile_ac3_raw_bsi['blkmixcfginfo'][0] = $this->readHeaderBSI(5); + } else { + for ($blk = 0; $blk < $thisfile_ac3_raw_bsi['numblkscod']; $blk++) { + $thisfile_ac3_raw_bsi['flags']['blkmixcfginfo'.$blk] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['blkmixcfginfo'.$blk]) { // mixing configuration information + $thisfile_ac3_raw_bsi['blkmixcfginfo'][$blk] = $this->readHeaderBSI(5); + } + } + } + } + } + } + $thisfile_ac3_raw_bsi['flags']['infomdat'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['infomdat']) { // Informational metadata + $thisfile_ac3_raw_bsi['bsmod'] = $this->readHeaderBSI(3); + $thisfile_ac3_raw_bsi['flags']['copyrightb'] = (bool) $this->readHeaderBSI(1); + $thisfile_ac3_raw_bsi['flags']['origbs'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['acmod'] == 2) { // if in 2/0 mode + $thisfile_ac3_raw_bsi['dsurmod'] = $this->readHeaderBSI(2); + $thisfile_ac3_raw_bsi['dheadphonmod'] = $this->readHeaderBSI(2); + } + if ($thisfile_ac3_raw_bsi['acmod'] >= 6) { // if both surround channels exist + $thisfile_ac3_raw_bsi['dsurexmod'] = $this->readHeaderBSI(2); + } + $thisfile_ac3_raw_bsi['flags']['audprodi'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['audprodi']) { + $thisfile_ac3_raw_bsi['mixlevel'] = $this->readHeaderBSI(5); + $thisfile_ac3_raw_bsi['roomtyp'] = $this->readHeaderBSI(2); + $thisfile_ac3_raw_bsi['flags']['adconvtyp'] = (bool) $this->readHeaderBSI(1); + } + if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value) + $thisfile_ac3_raw_bsi['flags']['audprodi2'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['audprodi2']) { + $thisfile_ac3_raw_bsi['mixlevel2'] = $this->readHeaderBSI(5); + $thisfile_ac3_raw_bsi['roomtyp2'] = $this->readHeaderBSI(2); + $thisfile_ac3_raw_bsi['flags']['adconvtyp2'] = (bool) $this->readHeaderBSI(1); + } + } + if ($thisfile_ac3_raw_bsi['fscod'] < 3) { // if not half sample rate + $thisfile_ac3_raw_bsi['flags']['sourcefscod'] = (bool) $this->readHeaderBSI(1); + } + } + if (($thisfile_ac3_raw_bsi['strmtyp'] == 0) && ($thisfile_ac3_raw_bsi['numblkscod'] != 3)) { // if both surround channels exist + $thisfile_ac3_raw_bsi['flags']['convsync'] = (bool) $this->readHeaderBSI(1); + } + if ($thisfile_ac3_raw_bsi['strmtyp'] == 2) { // if bit stream converted from AC-3 + if ($thisfile_ac3_raw_bsi['numblkscod'] != 3) { // 6 blocks per syncframe + $thisfile_ac3_raw_bsi['flags']['blkid'] = 1; + } else { + $thisfile_ac3_raw_bsi['flags']['blkid'] = (bool) $this->readHeaderBSI(1); + } + if ($thisfile_ac3_raw_bsi['flags']['blkid']) { + $thisfile_ac3_raw_bsi['frmsizecod'] = $this->readHeaderBSI(6); + } + } + $thisfile_ac3_raw_bsi['flags']['addbsi'] = (bool) $this->readHeaderBSI(1); + if ($thisfile_ac3_raw_bsi['flags']['addbsi']) { + $thisfile_ac3_raw_bsi['addbsil'] = $this->readHeaderBSI(6); + $thisfile_ac3_raw_bsi['addbsi'] = $this->readHeaderBSI(($thisfile_ac3_raw_bsi['addbsil'] + 1) * 8); + } + + } else { + + $this->error('Bit stream identification is version '.$thisfile_ac3_raw_bsi['bsid'].', but getID3() only understands up to version 16. Please submit a support ticket with a sample file.'); + unset($info['ac3']); + return false; + + } + + if (isset($thisfile_ac3_raw_bsi['fscod2'])) { + $thisfile_ac3['sample_rate'] = self::sampleRateCodeLookup2($thisfile_ac3_raw_bsi['fscod2']); + } else { + $thisfile_ac3['sample_rate'] = self::sampleRateCodeLookup($thisfile_ac3_raw_bsi['fscod']); + } + if ($thisfile_ac3_raw_bsi['fscod'] <= 3) { + $info['audio']['sample_rate'] = $thisfile_ac3['sample_rate']; + } else { + $this->warning('Unexpected ac3.bsi.fscod value: '.$thisfile_ac3_raw_bsi['fscod']); + } + if (isset($thisfile_ac3_raw_bsi['frmsizecod'])) { + $thisfile_ac3['frame_length'] = self::frameSizeLookup($thisfile_ac3_raw_bsi['frmsizecod'], $thisfile_ac3_raw_bsi['fscod']); + $thisfile_ac3['bitrate'] = self::bitrateLookup($thisfile_ac3_raw_bsi['frmsizecod']); + } elseif (!empty($thisfile_ac3_raw_bsi['frmsiz'])) { + // this isn't right, but it's (usually) close, roughly 5% less than it should be. + // but WHERE is the actual bitrate value stored in EAC3?? email info@getid3.org if you know! + $thisfile_ac3['bitrate'] = ($thisfile_ac3_raw_bsi['frmsiz'] + 1) * 16 * 30; // The frmsiz field shall contain a value one less than the overall size of the coded syncframe in 16-bit words. That is, this field may assume a value ranging from 0 to 2047, and these values correspond to syncframe sizes ranging from 1 to 2048. + // kludge-fix to make it approximately the expected value, still not "right": + $thisfile_ac3['bitrate'] = round(($thisfile_ac3['bitrate'] * 1.05) / 16000) * 16000; + } + $info['audio']['bitrate'] = $thisfile_ac3['bitrate']; + + if (isset($thisfile_ac3_raw_bsi['bsmod']) && isset($thisfile_ac3_raw_bsi['acmod'])) { + $thisfile_ac3['service_type'] = self::serviceTypeLookup($thisfile_ac3_raw_bsi['bsmod'], $thisfile_ac3_raw_bsi['acmod']); + } + $ac3_coding_mode = self::audioCodingModeLookup($thisfile_ac3_raw_bsi['acmod']); + foreach($ac3_coding_mode as $key => $value) { + $thisfile_ac3[$key] = $value; + } + switch ($thisfile_ac3_raw_bsi['acmod']) { + case 0: + case 1: + $info['audio']['channelmode'] = 'mono'; + break; + case 3: + case 4: + $info['audio']['channelmode'] = 'stereo'; + break; + default: + $info['audio']['channelmode'] = 'surround'; + break; + } + $info['audio']['channels'] = $thisfile_ac3['num_channels']; + + $thisfile_ac3['lfe_enabled'] = $thisfile_ac3_raw_bsi['flags']['lfeon']; + if ($thisfile_ac3_raw_bsi['flags']['lfeon']) { + $info['audio']['channels'] .= '.1'; + } + + $thisfile_ac3['channels_enabled'] = self::channelsEnabledLookup($thisfile_ac3_raw_bsi['acmod'], $thisfile_ac3_raw_bsi['flags']['lfeon']); + $thisfile_ac3['dialogue_normalization'] = '-'.$thisfile_ac3_raw_bsi['dialnorm'].'dB'; + + return true; + } + + /** + * @param int $length + * + * @return int + */ + private function readHeaderBSI($length) { + $data = substr($this->AC3header['bsi'], $this->BSIoffset, $length); + $this->BSIoffset += $length; + + return bindec($data); + } + + /** + * @param int $fscod + * + * @return int|string|false + */ + public static function sampleRateCodeLookup($fscod) { + static $sampleRateCodeLookup = array( + 0 => 48000, + 1 => 44100, + 2 => 32000, + 3 => 'reserved' // If the reserved code is indicated, the decoder should not attempt to decode audio and should mute. + ); + return (isset($sampleRateCodeLookup[$fscod]) ? $sampleRateCodeLookup[$fscod] : false); + } + + /** + * @param int $fscod2 + * + * @return int|string|false + */ + public static function sampleRateCodeLookup2($fscod2) { + static $sampleRateCodeLookup2 = array( + 0 => 24000, + 1 => 22050, + 2 => 16000, + 3 => 'reserved' // If the reserved code is indicated, the decoder should not attempt to decode audio and should mute. + ); + return (isset($sampleRateCodeLookup2[$fscod2]) ? $sampleRateCodeLookup2[$fscod2] : false); + } + + /** + * @param int $bsmod + * @param int $acmod + * + * @return string|false + */ + public static function serviceTypeLookup($bsmod, $acmod) { + static $serviceTypeLookup = array(); + if (empty($serviceTypeLookup)) { + for ($i = 0; $i <= 7; $i++) { + $serviceTypeLookup[0][$i] = 'main audio service: complete main (CM)'; + $serviceTypeLookup[1][$i] = 'main audio service: music and effects (ME)'; + $serviceTypeLookup[2][$i] = 'associated service: visually impaired (VI)'; + $serviceTypeLookup[3][$i] = 'associated service: hearing impaired (HI)'; + $serviceTypeLookup[4][$i] = 'associated service: dialogue (D)'; + $serviceTypeLookup[5][$i] = 'associated service: commentary (C)'; + $serviceTypeLookup[6][$i] = 'associated service: emergency (E)'; + } + + $serviceTypeLookup[7][1] = 'associated service: voice over (VO)'; + for ($i = 2; $i <= 7; $i++) { + $serviceTypeLookup[7][$i] = 'main audio service: karaoke'; + } + } + return (isset($serviceTypeLookup[$bsmod][$acmod]) ? $serviceTypeLookup[$bsmod][$acmod] : false); + } + + /** + * @param int $acmod + * + * @return array|false + */ + public static function audioCodingModeLookup($acmod) { + // array(channel configuration, # channels (not incl LFE), channel order) + static $audioCodingModeLookup = array ( + 0 => array('channel_config'=>'1+1', 'num_channels'=>2, 'channel_order'=>'Ch1,Ch2'), + 1 => array('channel_config'=>'1/0', 'num_channels'=>1, 'channel_order'=>'C'), + 2 => array('channel_config'=>'2/0', 'num_channels'=>2, 'channel_order'=>'L,R'), + 3 => array('channel_config'=>'3/0', 'num_channels'=>3, 'channel_order'=>'L,C,R'), + 4 => array('channel_config'=>'2/1', 'num_channels'=>3, 'channel_order'=>'L,R,S'), + 5 => array('channel_config'=>'3/1', 'num_channels'=>4, 'channel_order'=>'L,C,R,S'), + 6 => array('channel_config'=>'2/2', 'num_channels'=>4, 'channel_order'=>'L,R,SL,SR'), + 7 => array('channel_config'=>'3/2', 'num_channels'=>5, 'channel_order'=>'L,C,R,SL,SR'), + ); + return (isset($audioCodingModeLookup[$acmod]) ? $audioCodingModeLookup[$acmod] : false); + } + + /** + * @param int $cmixlev + * + * @return int|float|string|false + */ + public static function centerMixLevelLookup($cmixlev) { + static $centerMixLevelLookup; + if (empty($centerMixLevelLookup)) { + $centerMixLevelLookup = array( + 0 => pow(2, -3.0 / 6), // 0.707 (-3.0 dB) + 1 => pow(2, -4.5 / 6), // 0.595 (-4.5 dB) + 2 => pow(2, -6.0 / 6), // 0.500 (-6.0 dB) + 3 => 'reserved' + ); + } + return (isset($centerMixLevelLookup[$cmixlev]) ? $centerMixLevelLookup[$cmixlev] : false); + } + + /** + * @param int $surmixlev + * + * @return int|float|string|false + */ + public static function surroundMixLevelLookup($surmixlev) { + static $surroundMixLevelLookup; + if (empty($surroundMixLevelLookup)) { + $surroundMixLevelLookup = array( + 0 => pow(2, -3.0 / 6), + 1 => pow(2, -6.0 / 6), + 2 => 0, + 3 => 'reserved' + ); + } + return (isset($surroundMixLevelLookup[$surmixlev]) ? $surroundMixLevelLookup[$surmixlev] : false); + } + + /** + * @param int $dsurmod + * + * @return string|false + */ + public static function dolbySurroundModeLookup($dsurmod) { + static $dolbySurroundModeLookup = array( + 0 => 'not indicated', + 1 => 'Not Dolby Surround encoded', + 2 => 'Dolby Surround encoded', + 3 => 'reserved' + ); + return (isset($dolbySurroundModeLookup[$dsurmod]) ? $dolbySurroundModeLookup[$dsurmod] : false); + } + + /** + * @param int $acmod + * @param bool $lfeon + * + * @return array + */ + public static function channelsEnabledLookup($acmod, $lfeon) { + $lookup = array( + 'ch1'=>($acmod == 0), + 'ch2'=>($acmod == 0), + 'left'=>($acmod > 1), + 'right'=>($acmod > 1), + 'center'=>(bool) ($acmod & 0x01), + 'surround_mono'=>false, + 'surround_left'=>false, + 'surround_right'=>false, + 'lfe'=>$lfeon); + switch ($acmod) { + case 4: + case 5: + $lookup['surround_mono'] = true; + break; + case 6: + case 7: + $lookup['surround_left'] = true; + $lookup['surround_right'] = true; + break; + } + return $lookup; + } + + /** + * @param int $compre + * + * @return float|int + */ + public static function heavyCompression($compre) { + // The first four bits indicate gain changes in 6.02dB increments which can be + // implemented with an arithmetic shift operation. The following four bits + // indicate linear gain changes, and require a 5-bit multiply. + // We will represent the two 4-bit fields of compr as follows: + // X0 X1 X2 X3 . Y4 Y5 Y6 Y7 + // The meaning of the X values is most simply described by considering X to represent a 4-bit + // signed integer with values from -8 to +7. The gain indicated by X is then (X + 1) * 6.02 dB. The + // following table shows this in detail. + + // Meaning of 4 msb of compr + // 7 +48.16 dB + // 6 +42.14 dB + // 5 +36.12 dB + // 4 +30.10 dB + // 3 +24.08 dB + // 2 +18.06 dB + // 1 +12.04 dB + // 0 +6.02 dB + // -1 0 dB + // -2 -6.02 dB + // -3 -12.04 dB + // -4 -18.06 dB + // -5 -24.08 dB + // -6 -30.10 dB + // -7 -36.12 dB + // -8 -42.14 dB + + $fourbit = str_pad(decbin(($compre & 0xF0) >> 4), 4, '0', STR_PAD_LEFT); + if ($fourbit[0] == '1') { + $log_gain = -8 + bindec(substr($fourbit, 1)); + } else { + $log_gain = bindec(substr($fourbit, 1)); + } + $log_gain = ($log_gain + 1) * getid3_lib::RGADamplitude2dB(2); + + // The value of Y is a linear representation of a gain change of up to -6 dB. Y is considered to + // be an unsigned fractional integer, with a leading value of 1, or: 0.1 Y4 Y5 Y6 Y7 (base 2). Y can + // represent values between 0.111112 (or 31/32) and 0.100002 (or 1/2). Thus, Y can represent gain + // changes from -0.28 dB to -6.02 dB. + + $lin_gain = (16 + ($compre & 0x0F)) / 32; + + // The combination of X and Y values allows compr to indicate gain changes from + // 48.16 - 0.28 = +47.89 dB, to + // -42.14 - 6.02 = -48.16 dB. + + return $log_gain - $lin_gain; + } + + /** + * @param int $roomtyp + * + * @return string|false + */ + public static function roomTypeLookup($roomtyp) { + static $roomTypeLookup = array( + 0 => 'not indicated', + 1 => 'large room, X curve monitor', + 2 => 'small room, flat monitor', + 3 => 'reserved' + ); + return (isset($roomTypeLookup[$roomtyp]) ? $roomTypeLookup[$roomtyp] : false); + } + + /** + * @param int $frmsizecod + * @param int $fscod + * + * @return int|false + */ + public static function frameSizeLookup($frmsizecod, $fscod) { + // LSB is whether padding is used or not + $padding = (bool) ($frmsizecod & 0x01); + $framesizeid = ($frmsizecod & 0x3E) >> 1; + + static $frameSizeLookup = array(); + if (empty($frameSizeLookup)) { + $frameSizeLookup = array ( + 0 => array( 128, 138, 192), // 32 kbps + 1 => array( 160, 174, 240), // 40 kbps + 2 => array( 192, 208, 288), // 48 kbps + 3 => array( 224, 242, 336), // 56 kbps + 4 => array( 256, 278, 384), // 64 kbps + 5 => array( 320, 348, 480), // 80 kbps + 6 => array( 384, 416, 576), // 96 kbps + 7 => array( 448, 486, 672), // 112 kbps + 8 => array( 512, 556, 768), // 128 kbps + 9 => array( 640, 696, 960), // 160 kbps + 10 => array( 768, 834, 1152), // 192 kbps + 11 => array( 896, 974, 1344), // 224 kbps + 12 => array(1024, 1114, 1536), // 256 kbps + 13 => array(1280, 1392, 1920), // 320 kbps + 14 => array(1536, 1670, 2304), // 384 kbps + 15 => array(1792, 1950, 2688), // 448 kbps + 16 => array(2048, 2228, 3072), // 512 kbps + 17 => array(2304, 2506, 3456), // 576 kbps + 18 => array(2560, 2786, 3840) // 640 kbps + ); + } + $paddingBytes = 0; + if (($fscod == 1) && $padding) { + // frame lengths are padded by 1 word (16 bits) at 44100 + // (fscode==1) means 44100Hz (see sampleRateCodeLookup) + $paddingBytes = 2; + } + return (isset($frameSizeLookup[$framesizeid][$fscod]) ? $frameSizeLookup[$framesizeid][$fscod] + $paddingBytes : false); + } + + /** + * @param int $frmsizecod + * + * @return int|false + */ + public static function bitrateLookup($frmsizecod) { + // LSB is whether padding is used or not + $padding = (bool) ($frmsizecod & 0x01); + $framesizeid = ($frmsizecod & 0x3E) >> 1; + + static $bitrateLookup = array( + 0 => 32000, + 1 => 40000, + 2 => 48000, + 3 => 56000, + 4 => 64000, + 5 => 80000, + 6 => 96000, + 7 => 112000, + 8 => 128000, + 9 => 160000, + 10 => 192000, + 11 => 224000, + 12 => 256000, + 13 => 320000, + 14 => 384000, + 15 => 448000, + 16 => 512000, + 17 => 576000, + 18 => 640000, + ); + return (isset($bitrateLookup[$framesizeid]) ? $bitrateLookup[$framesizeid] : false); + } + + /** + * @param int $numblkscod + * + * @return int|false + */ + public static function blocksPerSyncFrame($numblkscod) { + static $blocksPerSyncFrameLookup = array( + 0 => 1, + 1 => 2, + 2 => 3, + 3 => 6, + ); + return (isset($blocksPerSyncFrameLookup[$numblkscod]) ? $blocksPerSyncFrameLookup[$numblkscod] : false); + } + + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.amr.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.amr.php new file mode 100644 index 00000000..e2e45316 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.amr.php @@ -0,0 +1,110 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.aa.php // +// module for analyzing Audible Audiobook files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_amr extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + $AMRheader = $this->fread(6); + + $magic = '#!AMR'."\x0A"; + if (substr($AMRheader, 0, 6) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($AMRheader, 0, 6)).'"'); + return false; + } + + // shortcut + $info['amr'] = array(); + $thisfile_amr = &$info['amr']; + + $info['fileformat'] = 'amr'; + $info['audio']['dataformat'] = 'amr'; + $info['audio']['bitrate_mode'] = 'vbr'; // within a small predefined range: 4.75kbps to 12.2kbps + $info['audio']['bits_per_sample'] = 13; // http://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec: "Sampling frequency 8 kHz/13-bit (160 samples for 20 ms frames), filtered to 200–3400 Hz" + $info['audio']['sample_rate'] = 8000; // http://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec: "Sampling frequency 8 kHz/13-bit (160 samples for 20 ms frames), filtered to 200–3400 Hz" + $info['audio']['channels'] = 1; + $thisfile_amr['frame_mode_count'] = array(0=>0, 1=>0, 2=>0, 3=>0, 4=>0, 5=>0, 6=>0, 7=>0); + + $buffer = ''; + do { + if ((strlen($buffer) < $this->getid3->fread_buffer_size()) && !feof($this->getid3->fp)) { + $buffer .= $this->fread($this->getid3->fread_buffer_size() * 2); + } + $AMR_frame_header = ord(substr($buffer, 0, 1)); + $codec_mode_request = ($AMR_frame_header & 0x78) >> 3; // The 2nd bit through 5th bit (counting the most significant bit as the first bit) comprise the CMR (Codec Mode Request), values 0-7 being valid for AMR. The top bit of the CMR can actually be ignored, though it is used when AMR forms RTP payloads. The lower 3-bits of the header are reserved and are not used. Viewing the header from most significant bit to least significant bit, the encoding is XCCCCXXX, where Xs are reserved (typically 0) and the Cs are the CMR. + if ($codec_mode_request > 7) { + break; + } + $thisfile_amr['frame_mode_count'][$codec_mode_request]++; + $buffer = substr($buffer, $this->amr_mode_bytes_per_frame($codec_mode_request)); + } while (strlen($buffer) > 0); + + $info['playtime_seconds'] = array_sum($thisfile_amr['frame_mode_count']) * 0.020; // each frame contain 160 samples and is 20 milliseconds long + $info['audio']['bitrate'] = (8 * ($info['avdataend'] - $info['avdataoffset'])) / $info['playtime_seconds']; // bitrate could be calculated from average bitrate by distributation of frame types. That would give effective audio bitrate, this gives overall file bitrate which will be a little bit higher since every frame will waste 8 bits for header, plus a few bits for octet padding + $info['bitrate'] = $info['audio']['bitrate']; + + return true; + } + + /** + * @param int $key + * + * @return int|false + */ + public function amr_mode_bitrate($key) { + static $amr_mode_bitrate = array( + 0 => 4750, + 1 => 5150, + 2 => 5900, + 3 => 6700, + 4 => 7400, + 5 => 7950, + 6 => 10200, + 7 => 12200, + ); + return (isset($amr_mode_bitrate[$key]) ? $amr_mode_bitrate[$key] : false); + } + + /** + * @param int $key + * + * @return int|false + */ + public function amr_mode_bytes_per_frame($key) { + static $amr_mode_bitrate = array( + 0 => 13, // 1-byte frame header + 95 bits [padded to: 12 bytes] audio data + 1 => 14, // 1-byte frame header + 103 bits [padded to: 13 bytes] audio data + 2 => 16, // 1-byte frame header + 118 bits [padded to: 15 bytes] audio data + 3 => 18, // 1-byte frame header + 134 bits [padded to: 17 bytes] audio data + 4 => 20, // 1-byte frame header + 148 bits [padded to: 19 bytes] audio data + 5 => 21, // 1-byte frame header + 159 bits [padded to: 20 bytes] audio data + 6 => 27, // 1-byte frame header + 204 bits [padded to: 26 bytes] audio data + 7 => 32, // 1-byte frame header + 244 bits [padded to: 31 bytes] audio data + ); + return (isset($amr_mode_bitrate[$key]) ? $amr_mode_bitrate[$key] : false); + } + + +} diff --git a/serendipity_event_podcast/player/getid3/module.audio.au.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.au.php similarity index 61% rename from serendipity_event_podcast/player/getid3/module.audio.au.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.au.php index afbc75d6..73df1031 100644 --- a/serendipity_event_podcast/player/getid3/module.audio.au.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.au.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.audio.au.php // @@ -13,32 +14,39 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_au +class getid3_au extends getid3_handler { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_au(&$fd, &$ThisFileInfo) { + $this->fseek($info['avdataoffset']); + $AUheader = $this->fread(8); - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $AUheader = fread($fd, 8); - - if (substr($AUheader, 0, 4) != '.snd') { - $ThisFileInfo['error'][] = 'Expecting ".snd" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($AUheader, 0, 4).'"'; + $magic = '.snd'; + if (substr($AUheader, 0, 4) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" (".snd") at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($AUheader, 0, 4)).'"'); return false; } // shortcut - $ThisFileInfo['au'] = array(); - $thisfile_au = &$ThisFileInfo['au']; + $info['au'] = array(); + $thisfile_au = &$info['au']; - $ThisFileInfo['fileformat'] = 'au'; - $ThisFileInfo['audio']['dataformat'] = 'au'; - $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; + $info['fileformat'] = 'au'; + $info['audio']['dataformat'] = 'au'; + $info['audio']['bitrate_mode'] = 'cbr'; $thisfile_au['encoding'] = 'ISO-8859-1'; $thisfile_au['header_length'] = getid3_lib::BigEndian2Int(substr($AUheader, 4, 4)); - $AUheader .= fread($fd, $thisfile_au['header_length'] - 8); - $ThisFileInfo['avdataoffset'] += $thisfile_au['header_length']; + $AUheader .= $this->fread($thisfile_au['header_length'] - 8); + $info['avdataoffset'] += $thisfile_au['header_length']; $thisfile_au['data_size'] = getid3_lib::BigEndian2Int(substr($AUheader, 8, 4)); $thisfile_au['data_format_id'] = getid3_lib::BigEndian2Int(substr($AUheader, 12, 4)); @@ -49,25 +57,30 @@ class getid3_au $thisfile_au['data_format'] = $this->AUdataFormatNameLookup($thisfile_au['data_format_id']); $thisfile_au['used_bits_per_sample'] = $this->AUdataFormatUsedBitsPerSampleLookup($thisfile_au['data_format_id']); if ($thisfile_au['bits_per_sample'] = $this->AUdataFormatBitsPerSampleLookup($thisfile_au['data_format_id'])) { - $ThisFileInfo['audio']['bits_per_sample'] = $thisfile_au['bits_per_sample']; + $info['audio']['bits_per_sample'] = $thisfile_au['bits_per_sample']; } else { unset($thisfile_au['bits_per_sample']); } - $ThisFileInfo['audio']['sample_rate'] = $thisfile_au['sample_rate']; - $ThisFileInfo['audio']['channels'] = $thisfile_au['channels']; + $info['audio']['sample_rate'] = $thisfile_au['sample_rate']; + $info['audio']['channels'] = $thisfile_au['channels']; - if (($ThisFileInfo['avdataoffset'] + $thisfile_au['data_size']) > $ThisFileInfo['avdataend']) { - $ThisFileInfo['warning'][] = 'Possible truncated file - expecting "'.$thisfile_au['data_size'].'" bytes of audio data, only found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' bytes"'; + if (($info['avdataoffset'] + $thisfile_au['data_size']) > $info['avdataend']) { + $this->warning('Possible truncated file - expecting "'.$thisfile_au['data_size'].'" bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' bytes"'); } - $ThisFileInfo['playtime_seconds'] = $thisfile_au['data_size'] / ($thisfile_au['sample_rate'] * $thisfile_au['channels'] * ($thisfile_au['used_bits_per_sample'] / 8)); - $ThisFileInfo['audio']['bitrate'] = ($thisfile_au['data_size'] * 8) / $ThisFileInfo['playtime_seconds']; + $info['playtime_seconds'] = $thisfile_au['data_size'] / ($thisfile_au['sample_rate'] * $thisfile_au['channels'] * ($thisfile_au['used_bits_per_sample'] / 8)); + $info['audio']['bitrate'] = ($thisfile_au['data_size'] * 8) / $info['playtime_seconds']; return true; } - function AUdataFormatNameLookup($id) { + /** + * @param int $id + * + * @return string|false + */ + public function AUdataFormatNameLookup($id) { static $AUdataFormatNameLookup = array( 0 => 'unspecified format', 1 => '8-bit mu-law', @@ -101,7 +114,12 @@ class getid3_au return (isset($AUdataFormatNameLookup[$id]) ? $AUdataFormatNameLookup[$id] : false); } - function AUdataFormatBitsPerSampleLookup($id) { + /** + * @param int $id + * + * @return int|false + */ + public function AUdataFormatBitsPerSampleLookup($id) { static $AUdataFormatBitsPerSampleLookup = array( 1 => 8, 2 => 8, @@ -129,7 +147,12 @@ class getid3_au return (isset($AUdataFormatBitsPerSampleLookup[$id]) ? $AUdataFormatBitsPerSampleLookup[$id] : false); } - function AUdataFormatUsedBitsPerSampleLookup($id) { + /** + * @param int $id + * + * @return int|false + */ + public function AUdataFormatUsedBitsPerSampleLookup($id) { static $AUdataFormatUsedBitsPerSampleLookup = array( 1 => 8, 2 => 8, @@ -158,6 +181,3 @@ class getid3_au } } - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.avr.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.avr.php new file mode 100644 index 00000000..69a26056 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.avr.php @@ -0,0 +1,130 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.avr.php // +// module for analyzing AVR Audio files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_avr extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + // http://cui.unige.ch/OSG/info/AudioFormats/ap11.html + // http://www.btinternet.com/~AnthonyJ/Atari/programming/avr_format.html + // offset type length name comments + // --------------------------------------------------------------------- + // 0 char 4 ID format ID == "2BIT" + // 4 char 8 name sample name (unused space filled with 0) + // 12 short 1 mono/stereo 0=mono, -1 (0xFFFF)=stereo + // With stereo, samples are alternated, + // the first voice is the left : + // (LRLRLRLRLRLRLRLRLR...) + // 14 short 1 resolution 8, 12 or 16 (bits) + // 16 short 1 signed or not 0=unsigned, -1 (0xFFFF)=signed + // 18 short 1 loop or not 0=no loop, -1 (0xFFFF)=loop on + // 20 short 1 MIDI note 0xFFnn, where 0 <= nn <= 127 + // 0xFFFF means "no MIDI note defined" + // 22 byte 1 Replay speed Frequence in the Replay software + // 0=5.485 Khz, 1=8.084 Khz, 2=10.971 Khz, + // 3=16.168 Khz, 4=21.942 Khz, 5=32.336 Khz + // 6=43.885 Khz, 7=47.261 Khz + // -1 (0xFF)=no defined Frequence + // 23 byte 3 sample rate in Hertz + // 26 long 1 size in bytes (2 * bytes in stereo) + // 30 long 1 loop begin 0 for no loop + // 34 long 1 loop size equal to 'size' for no loop + // 38 short 2 Reserved, MIDI keyboard split */ + // 40 short 2 Reserved, sample compression */ + // 42 short 2 Reserved */ + // 44 char 20; Additional filename space, used if (name[7] != 0) + // 64 byte 64 user data + // 128 bytes ? sample data (12 bits samples are coded on 16 bits: + // 0000 xxxx xxxx xxxx) + // --------------------------------------------------------------------- + + // Note that all values are in motorola (big-endian) format, and that long is + // assumed to be 4 bytes, and short 2 bytes. + // When reading the samples, you should handle both signed and unsigned data, + // and be prepared to convert 16->8 bit, or mono->stereo if needed. To convert + // 8-bit data between signed/unsigned just add 127 to the sample values. + // Simularly for 16-bit data you should add 32769 + + $info['fileformat'] = 'avr'; + + $this->fseek($info['avdataoffset']); + $AVRheader = $this->fread(128); + + $info['avr']['raw']['magic'] = substr($AVRheader, 0, 4); + $magic = '2BIT'; + if ($info['avr']['raw']['magic'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['avr']['raw']['magic']).'"'); + unset($info['fileformat']); + unset($info['avr']); + return false; + } + $info['avdataoffset'] += 128; + + $info['avr']['sample_name'] = rtrim(substr($AVRheader, 4, 8)); + $info['avr']['raw']['mono'] = getid3_lib::BigEndian2Int(substr($AVRheader, 12, 2)); + $info['avr']['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($AVRheader, 14, 2)); + $info['avr']['raw']['signed'] = getid3_lib::BigEndian2Int(substr($AVRheader, 16, 2)); + $info['avr']['raw']['loop'] = getid3_lib::BigEndian2Int(substr($AVRheader, 18, 2)); + $info['avr']['raw']['midi'] = getid3_lib::BigEndian2Int(substr($AVRheader, 20, 2)); + $info['avr']['raw']['replay_freq'] = getid3_lib::BigEndian2Int(substr($AVRheader, 22, 1)); + $info['avr']['sample_rate'] = getid3_lib::BigEndian2Int(substr($AVRheader, 23, 3)); + $info['avr']['sample_length'] = getid3_lib::BigEndian2Int(substr($AVRheader, 26, 4)); + $info['avr']['loop_start'] = getid3_lib::BigEndian2Int(substr($AVRheader, 30, 4)); + $info['avr']['loop_end'] = getid3_lib::BigEndian2Int(substr($AVRheader, 34, 4)); + $info['avr']['midi_split'] = getid3_lib::BigEndian2Int(substr($AVRheader, 38, 2)); + $info['avr']['sample_compression'] = getid3_lib::BigEndian2Int(substr($AVRheader, 40, 2)); + $info['avr']['reserved'] = getid3_lib::BigEndian2Int(substr($AVRheader, 42, 2)); + $info['avr']['sample_name_extra'] = rtrim(substr($AVRheader, 44, 20)); + $info['avr']['comment'] = rtrim(substr($AVRheader, 64, 64)); + + $info['avr']['flags']['stereo'] = (($info['avr']['raw']['mono'] == 0) ? false : true); + $info['avr']['flags']['signed'] = (($info['avr']['raw']['signed'] == 0) ? false : true); + $info['avr']['flags']['loop'] = (($info['avr']['raw']['loop'] == 0) ? false : true); + + $info['avr']['midi_notes'] = array(); + if (($info['avr']['raw']['midi'] & 0xFF00) != 0xFF00) { + $info['avr']['midi_notes'][] = ($info['avr']['raw']['midi'] & 0xFF00) >> 8; + } + if (($info['avr']['raw']['midi'] & 0x00FF) != 0x00FF) { + $info['avr']['midi_notes'][] = ($info['avr']['raw']['midi'] & 0x00FF); + } + + if (($info['avdataend'] - $info['avdataoffset']) != ($info['avr']['sample_length'] * (($info['avr']['bits_per_sample'] == 8) ? 1 : 2))) { + $this->warning('Probable truncated file: expecting '.($info['avr']['sample_length'] * (($info['avr']['bits_per_sample'] == 8) ? 1 : 2)).' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset'])); + } + + $info['audio']['dataformat'] = 'avr'; + $info['audio']['lossless'] = true; + $info['audio']['bitrate_mode'] = 'cbr'; + $info['audio']['bits_per_sample'] = $info['avr']['bits_per_sample']; + $info['audio']['sample_rate'] = $info['avr']['sample_rate']; + $info['audio']['channels'] = ($info['avr']['flags']['stereo'] ? 2 : 1); + $info['playtime_seconds'] = ($info['avr']['sample_length'] / $info['audio']['channels']) / $info['avr']['sample_rate']; + $info['audio']['bitrate'] = ($info['avr']['sample_length'] * (($info['avr']['bits_per_sample'] == 8) ? 8 : 16)) / $info['playtime_seconds']; + + + return true; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.bonk.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.bonk.php new file mode 100644 index 00000000..c6cf9ac7 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.bonk.php @@ -0,0 +1,243 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.la.php // +// module for analyzing BONK audio files // +// dependencies: module.tag.id3v2.php (optional) // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_bonk extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + // shortcut + $info['bonk'] = array(); + $thisfile_bonk = &$info['bonk']; + + $thisfile_bonk['dataoffset'] = $info['avdataoffset']; + $thisfile_bonk['dataend'] = $info['avdataend']; + + if (!getid3_lib::intValueSupported($thisfile_bonk['dataend'])) { + + $this->warning('Unable to parse BONK file from end (v0.6+ preferred method) because PHP filesystem functions only support up to '.round(PHP_INT_MAX / 1073741824).'GB'); + + } else { + + // scan-from-end method, for v0.6 and higher + $this->fseek($thisfile_bonk['dataend'] - 8); + $PossibleBonkTag = $this->fread(8); + while ($this->BonkIsValidTagName(substr($PossibleBonkTag, 4, 4), true)) { + $BonkTagSize = getid3_lib::LittleEndian2Int(substr($PossibleBonkTag, 0, 4)); + $this->fseek(0 - $BonkTagSize, SEEK_CUR); + $BonkTagOffset = $this->ftell(); + $TagHeaderTest = $this->fread(5); + if (($TagHeaderTest[0] != "\x00") || (substr($PossibleBonkTag, 4, 4) != strtolower(substr($PossibleBonkTag, 4, 4)))) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes("\x00".strtoupper(substr($PossibleBonkTag, 4, 4))).'" at offset '.$BonkTagOffset.', found "'.getid3_lib::PrintHexBytes($TagHeaderTest).'"'); + return false; + } + $BonkTagName = substr($TagHeaderTest, 1, 4); + + $thisfile_bonk[$BonkTagName]['size'] = $BonkTagSize; + $thisfile_bonk[$BonkTagName]['offset'] = $BonkTagOffset; + $this->HandleBonkTags($BonkTagName); + $NextTagEndOffset = $BonkTagOffset - 8; + if ($NextTagEndOffset < $thisfile_bonk['dataoffset']) { + if (empty($info['audio']['encoder'])) { + $info['audio']['encoder'] = 'Extended BONK v0.9+'; + } + return true; + } + $this->fseek($NextTagEndOffset); + $PossibleBonkTag = $this->fread(8); + } + + } + + // seek-from-beginning method for v0.4 and v0.5 + if (empty($thisfile_bonk['BONK'])) { + $this->fseek($thisfile_bonk['dataoffset']); + do { + $TagHeaderTest = $this->fread(5); + switch ($TagHeaderTest) { + case "\x00".'BONK': + if (empty($info['audio']['encoder'])) { + $info['audio']['encoder'] = 'BONK v0.4'; + } + break; + + case "\x00".'INFO': + $info['audio']['encoder'] = 'Extended BONK v0.5'; + break; + + default: + break 2; + } + $BonkTagName = substr($TagHeaderTest, 1, 4); + $thisfile_bonk[$BonkTagName]['size'] = $thisfile_bonk['dataend'] - $thisfile_bonk['dataoffset']; + $thisfile_bonk[$BonkTagName]['offset'] = $thisfile_bonk['dataoffset']; + $this->HandleBonkTags($BonkTagName); + + } while (true); + } + + // parse META block for v0.6 - v0.8 + if (empty($thisfile_bonk['INFO']) && isset($thisfile_bonk['META']['tags']['info'])) { + $this->fseek($thisfile_bonk['META']['tags']['info']); + $TagHeaderTest = $this->fread(5); + if ($TagHeaderTest == "\x00".'INFO') { + $info['audio']['encoder'] = 'Extended BONK v0.6 - v0.8'; + + $BonkTagName = substr($TagHeaderTest, 1, 4); + $thisfile_bonk[$BonkTagName]['size'] = $thisfile_bonk['dataend'] - $thisfile_bonk['dataoffset']; + $thisfile_bonk[$BonkTagName]['offset'] = $thisfile_bonk['dataoffset']; + $this->HandleBonkTags($BonkTagName); + } + } + + if (empty($info['audio']['encoder'])) { + $info['audio']['encoder'] = 'Extended BONK v0.9+'; + } + if (empty($thisfile_bonk['BONK'])) { + unset($info['bonk']); + } + return true; + + } + + /** + * @param string $BonkTagName + */ + public function HandleBonkTags($BonkTagName) { + $info = &$this->getid3->info; + switch ($BonkTagName) { + case 'BONK': + // shortcut + $thisfile_bonk_BONK = &$info['bonk']['BONK']; + + $BonkData = "\x00".'BONK'.$this->fread(17); + $thisfile_bonk_BONK['version'] = getid3_lib::LittleEndian2Int(substr($BonkData, 5, 1)); + $thisfile_bonk_BONK['number_samples'] = getid3_lib::LittleEndian2Int(substr($BonkData, 6, 4)); + $thisfile_bonk_BONK['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BonkData, 10, 4)); + + $thisfile_bonk_BONK['channels'] = getid3_lib::LittleEndian2Int(substr($BonkData, 14, 1)); + $thisfile_bonk_BONK['lossless'] = (bool) getid3_lib::LittleEndian2Int(substr($BonkData, 15, 1)); + $thisfile_bonk_BONK['joint_stereo'] = (bool) getid3_lib::LittleEndian2Int(substr($BonkData, 16, 1)); + $thisfile_bonk_BONK['number_taps'] = getid3_lib::LittleEndian2Int(substr($BonkData, 17, 2)); + $thisfile_bonk_BONK['downsampling_ratio'] = getid3_lib::LittleEndian2Int(substr($BonkData, 19, 1)); + $thisfile_bonk_BONK['samples_per_packet'] = getid3_lib::LittleEndian2Int(substr($BonkData, 20, 2)); + + $info['avdataoffset'] = $thisfile_bonk_BONK['offset'] + 5 + 17; + $info['avdataend'] = $thisfile_bonk_BONK['offset'] + $thisfile_bonk_BONK['size']; + + $info['fileformat'] = 'bonk'; + $info['audio']['dataformat'] = 'bonk'; + $info['audio']['bitrate_mode'] = 'vbr'; // assumed + $info['audio']['channels'] = $thisfile_bonk_BONK['channels']; + $info['audio']['sample_rate'] = $thisfile_bonk_BONK['sample_rate']; + $info['audio']['channelmode'] = ($thisfile_bonk_BONK['joint_stereo'] ? 'joint stereo' : 'stereo'); + $info['audio']['lossless'] = $thisfile_bonk_BONK['lossless']; + $info['audio']['codec'] = 'bonk'; + + $info['playtime_seconds'] = $thisfile_bonk_BONK['number_samples'] / ($thisfile_bonk_BONK['sample_rate'] * $thisfile_bonk_BONK['channels']); + if ($info['playtime_seconds'] > 0) { + $info['audio']['bitrate'] = (($info['bonk']['dataend'] - $info['bonk']['dataoffset']) * 8) / $info['playtime_seconds']; + } + break; + + case 'INFO': + // shortcut + $thisfile_bonk_INFO = &$info['bonk']['INFO']; + + $thisfile_bonk_INFO['version'] = getid3_lib::LittleEndian2Int($this->fread(1)); + $thisfile_bonk_INFO['entries_count'] = 0; + $NextInfoDataPair = $this->fread(5); + if (!$this->BonkIsValidTagName(substr($NextInfoDataPair, 1, 4))) { + while (!feof($this->getid3->fp)) { + //$CurrentSeekInfo['offset'] = getid3_lib::LittleEndian2Int(substr($NextInfoDataPair, 0, 4)); + //$CurrentSeekInfo['nextbit'] = getid3_lib::LittleEndian2Int(substr($NextInfoDataPair, 4, 1)); + //$thisfile_bonk_INFO[] = $CurrentSeekInfo; + + $NextInfoDataPair = $this->fread(5); + if ($this->BonkIsValidTagName(substr($NextInfoDataPair, 1, 4))) { + $this->fseek(-5, SEEK_CUR); + break; + } + $thisfile_bonk_INFO['entries_count']++; + } + } + break; + + case 'META': + $BonkData = "\x00".'META'.$this->fread($info['bonk']['META']['size'] - 5); + $info['bonk']['META']['version'] = getid3_lib::LittleEndian2Int(substr($BonkData, 5, 1)); + + $MetaTagEntries = floor(((strlen($BonkData) - 8) - 6) / 8); // BonkData - xxxxmeta - ØMETA + $offset = 6; + for ($i = 0; $i < $MetaTagEntries; $i++) { + $MetaEntryTagName = substr($BonkData, $offset, 4); + $offset += 4; + $MetaEntryTagOffset = getid3_lib::LittleEndian2Int(substr($BonkData, $offset, 4)); + $offset += 4; + $info['bonk']['META']['tags'][$MetaEntryTagName] = $MetaEntryTagOffset; + } + break; + + case ' ID3': + $info['audio']['encoder'] = 'Extended BONK v0.9+'; + + // ID3v2 checking is optional + if (class_exists('getid3_id3v2')) { + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_id3v2 = new getid3_id3v2($getid3_temp); + $getid3_id3v2->StartingOffset = $info['bonk'][' ID3']['offset'] + 2; + $info['bonk'][' ID3']['valid'] = $getid3_id3v2->Analyze(); + if ($info['bonk'][' ID3']['valid']) { + $info['id3v2'] = $getid3_temp->info['id3v2']; + } + unset($getid3_temp, $getid3_id3v2); + } + break; + + default: + $this->warning('Unexpected Bonk tag "'.$BonkTagName.'" at offset '.$info['bonk'][$BonkTagName]['offset']); + break; + + } + } + + /** + * @param string $PossibleBonkTag + * @param bool $ignorecase + * + * @return bool + */ + public static function BonkIsValidTagName($PossibleBonkTag, $ignorecase=false) { + static $BonkIsValidTagName = array('BONK', 'INFO', ' ID3', 'META'); + foreach ($BonkIsValidTagName as $validtagname) { + if ($validtagname == $PossibleBonkTag) { + return true; + } elseif ($ignorecase && (strtolower($validtagname) == strtolower($PossibleBonkTag))) { + return true; + } + } + return false; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.dsdiff.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.dsdiff.php new file mode 100644 index 00000000..20fb0d9a --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.dsdiff.php @@ -0,0 +1,311 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.dsdiff.php // +// module for analyzing Direct Stream Digital Interchange // +// File Format (DSDIFF) files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_dsdiff extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + $DSDIFFheader = $this->fread(4); + + // https://dsd-guide.com/sites/default/files/white-papers/DSDIFF_1.5_Spec.pdf + if (substr($DSDIFFheader, 0, 4) != 'FRM8') { + $this->error('Expecting "FRM8" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($DSDIFFheader, 0, 4)).'"'); + return false; + } + unset($DSDIFFheader); + $this->fseek($info['avdataoffset']); + + $info['encoding'] = 'ISO-8859-1'; // not certain, but assumed + $info['fileformat'] = 'dsdiff'; + $info['mime_type'] = 'audio/dsd'; + $info['audio']['dataformat'] = 'dsdiff'; + $info['audio']['bitrate_mode'] = 'cbr'; + $info['audio']['bits_per_sample'] = 1; + + $info['dsdiff'] = array(); + $thisChunk = null; + while (!$this->feof() && ($ChunkHeader = $this->fread(12))) { + if (strlen($ChunkHeader) < 12) { + $this->error('Expecting chunk header at offset '.(isset($thisChunk['offset']) ? $thisChunk['offset'] : 'N/A').', found insufficient data in file, aborting parsing'); + break; + } + $thisChunk = array(); + $thisChunk['offset'] = $this->ftell() - 12; + $thisChunk['name'] = substr($ChunkHeader, 0, 4); + if (!preg_match('#^[\\x21-\\x7E]+ *$#', $thisChunk['name'])) { + // "a concatenation of four printable ASCII characters in the range ' ' (space, 0x20) through '~'(0x7E). Space (0x20) cannot precede printing characters; trailing spaces are allowed." + $this->error('Invalid chunk name "'.$thisChunk['name'].'" ('.getid3_lib::PrintHexBytes($thisChunk['name']).') at offset '.$thisChunk['offset'].', aborting parsing'); + } + $thisChunk['size'] = getid3_lib::BigEndian2Int(substr($ChunkHeader, 4, 8)); + $datasize = $thisChunk['size'] + ($thisChunk['size'] % 2); // "If the data is an odd number of bytes in length, a pad byte must be added at the end. The pad byte is not included in ckDataSize." + + switch ($thisChunk['name']) { + case 'FRM8': + $thisChunk['form_type'] = $this->fread(4); + if ($thisChunk['form_type'] != 'DSD ') { + $this->error('Expecting "DSD " at offset '.($this->ftell() - 4).', found "'.getid3_lib::PrintHexBytes($thisChunk['form_type']).'", aborting parsing'); + break 2; + } + // do nothing further, prevent skipping subchunks + break; + case 'PROP': // PROPerty chunk + $thisChunk['prop_type'] = $this->fread(4); + if ($thisChunk['prop_type'] != 'SND ') { + $this->error('Expecting "SND " at offset '.($this->ftell() - 4).', found "'.getid3_lib::PrintHexBytes($thisChunk['prop_type']).'", aborting parsing'); + break 2; + } + // do nothing further, prevent skipping subchunks + break; + case 'DIIN': // eDIted master INformation chunk + // do nothing, just prevent skipping subchunks + break; + + case 'FVER': // Format VERsion chunk + if ($thisChunk['size'] == 4) { + $FVER = $this->fread(4); + $info['dsdiff']['format_version'] = ord($FVER[0]).'.'.ord($FVER[1]).'.'.ord($FVER[2]).'.'.ord($FVER[3]); + unset($FVER); + } else { + $this->warning('Expecting "FVER" chunk to be 4 bytes, found '.$thisChunk['size'].' bytes, skipping chunk'); + $this->fseek($datasize, SEEK_CUR); + } + break; + case 'FS ': // sample rate chunk + if ($thisChunk['size'] == 4) { + $info['dsdiff']['sample_rate'] = getid3_lib::BigEndian2Int($this->fread(4)); + $info['audio']['sample_rate'] = $info['dsdiff']['sample_rate']; + } else { + $this->warning('Expecting "FVER" chunk to be 4 bytes, found '.$thisChunk['size'].' bytes, skipping chunk'); + $this->fseek($datasize, SEEK_CUR); + } + break; + case 'CHNL': // CHaNneLs chunk + $thisChunk['num_channels'] = getid3_lib::BigEndian2Int($this->fread(2)); + if ($thisChunk['num_channels'] == 0) { + $this->warning('channel count should be greater than zero, skipping chunk'); + $this->fseek($datasize - 2, SEEK_CUR); + } + for ($i = 0; $i < $thisChunk['num_channels']; $i++) { + $thisChunk['channels'][$i] = $this->fread(4); + } + $info['audio']['channels'] = $thisChunk['num_channels']; + break; + case 'CMPR': // CoMPRession type chunk + $thisChunk['compression_type'] = $this->fread(4); + $info['audio']['dataformat'] = trim($thisChunk['compression_type']); + $humanReadableByteLength = getid3_lib::BigEndian2Int($this->fread(1)); + $thisChunk['compression_name'] = $this->fread($humanReadableByteLength); + if (($humanReadableByteLength % 2) == 0) { + // need to seek to multiple of 2 bytes, human-readable string length is only one byte long so if the string is an even number of bytes we need to seek past a padding byte after the string + $this->fseek(1, SEEK_CUR); + } + unset($humanReadableByteLength); + break; + case 'ABSS': // ABSolute Start time chunk + $ABSS = $this->fread(8); + $info['dsdiff']['absolute_start_time']['hours'] = getid3_lib::BigEndian2Int(substr($ABSS, 0, 2)); + $info['dsdiff']['absolute_start_time']['minutes'] = getid3_lib::BigEndian2Int(substr($ABSS, 2, 1)); + $info['dsdiff']['absolute_start_time']['seconds'] = getid3_lib::BigEndian2Int(substr($ABSS, 3, 1)); + $info['dsdiff']['absolute_start_time']['samples'] = getid3_lib::BigEndian2Int(substr($ABSS, 4, 4)); + unset($ABSS); + break; + case 'LSCO': // LoudSpeaker COnfiguration chunk + // 0 = 2-channel stereo set-up + // 3 = 5-channel set-up according to ITU-R BS.775-1 [ITU] + // 4 = 6-channel set-up, 5-channel set-up according to ITU-R BS.775-1 [ITU], plus additional Low Frequency Enhancement (LFE) loudspeaker. Also known as "5.1 configuration" + // 65535 = Undefined channel set-up + $thisChunk['loundspeaker_config_id'] = getid3_lib::BigEndian2Int($this->fread(2)); + break; + case 'COMT': // COMmenTs chunk + $thisChunk['num_comments'] = getid3_lib::BigEndian2Int($this->fread(2)); + for ($i = 0; $i < $thisChunk['num_comments']; $i++) { + $thisComment = array(); + $COMT = $this->fread(14); + $thisComment['creation_year'] = getid3_lib::BigEndian2Int(substr($COMT, 0, 2)); + $thisComment['creation_month'] = getid3_lib::BigEndian2Int(substr($COMT, 2, 1)); + $thisComment['creation_day'] = getid3_lib::BigEndian2Int(substr($COMT, 3, 1)); + $thisComment['creation_hour'] = getid3_lib::BigEndian2Int(substr($COMT, 4, 1)); + $thisComment['creation_minute'] = getid3_lib::BigEndian2Int(substr($COMT, 5, 1)); + $thisComment['comment_type_id'] = getid3_lib::BigEndian2Int(substr($COMT, 6, 2)); + $thisComment['comment_ref_id'] = getid3_lib::BigEndian2Int(substr($COMT, 8, 2)); + $thisComment['string_length'] = getid3_lib::BigEndian2Int(substr($COMT, 10, 4)); + $thisComment['comment_text'] = $this->fread($thisComment['string_length']); + if ($thisComment['string_length'] % 2) { + // commentText[] is the description of the Comment. This text must be padded with a byte at the end, if needed, to make it an even number of bytes long. This pad byte, if present, is not included in count. + $this->fseek(1, SEEK_CUR); + } + $thisComment['comment_type'] = $this->DSDIFFcmtType($thisComment['comment_type_id']); + $thisComment['comment_reference'] = $this->DSDIFFcmtRef($thisComment['comment_type_id'], $thisComment['comment_ref_id']); + $thisComment['creation_unix'] = mktime($thisComment['creation_hour'], $thisComment['creation_minute'], 0, $thisComment['creation_month'], $thisComment['creation_day'], $thisComment['creation_year']); + $thisChunk['comments'][$i] = $thisComment; + + $commentkey = ($thisComment['comment_reference'] ?: 'comment'); + $info['dsdiff']['comments'][$commentkey][] = $thisComment['comment_text']; + unset($thisComment); + } + break; + case 'MARK': // MARKer chunk + $MARK = $this->fread(22); + $thisChunk['marker_hours'] = getid3_lib::BigEndian2Int(substr($MARK, 0, 2)); + $thisChunk['marker_minutes'] = getid3_lib::BigEndian2Int(substr($MARK, 2, 1)); + $thisChunk['marker_seconds'] = getid3_lib::BigEndian2Int(substr($MARK, 3, 1)); + $thisChunk['marker_samples'] = getid3_lib::BigEndian2Int(substr($MARK, 4, 4)); + $thisChunk['marker_offset'] = getid3_lib::BigEndian2Int(substr($MARK, 8, 4)); + $thisChunk['marker_type_id'] = getid3_lib::BigEndian2Int(substr($MARK, 12, 2)); + $thisChunk['marker_channel'] = getid3_lib::BigEndian2Int(substr($MARK, 14, 2)); + $thisChunk['marker_flagraw'] = getid3_lib::BigEndian2Int(substr($MARK, 16, 2)); + $thisChunk['string_length'] = getid3_lib::BigEndian2Int(substr($MARK, 18, 4)); + $thisChunk['description'] = ($thisChunk['string_length'] ? $this->fread($thisChunk['string_length']) : ''); + if ($thisChunk['string_length'] % 2) { + // markerText[] is the description of the marker. This text must be padded with a byte at the end, if needed, to make it an even number of bytes long. This pad byte, if present, is not included in count. + $this->fseek(1, SEEK_CUR); + } + $thisChunk['marker_type'] = $this->DSDIFFmarkType($thisChunk['marker_type_id']); + unset($MARK); + break; + case 'DIAR': // artist chunk + case 'DITI': // title chunk + $thisChunk['string_length'] = getid3_lib::BigEndian2Int($this->fread(4)); + $thisChunk['description'] = ($thisChunk['string_length'] ? $this->fread($thisChunk['string_length']) : ''); + if ($thisChunk['string_length'] % 2) { + // This text must be padded with a byte at the end, if needed, to make it an even number of bytes long. This pad byte, if present, is not included in count. + $this->fseek(1, SEEK_CUR); + } + + if ($commentkey = (($thisChunk['name'] == 'DIAR') ? 'artist' : (($thisChunk['name'] == 'DITI') ? 'title' : ''))) { + @$info['dsdiff']['comments'][$commentkey][] = $thisChunk['description']; + } + break; + case 'EMID': // Edited Master ID chunk + if ($thisChunk['size']) { + $thisChunk['identifier'] = $this->fread($thisChunk['size']); + } + break; + + case 'ID3 ': + $endOfID3v2 = $this->ftell() + $datasize; // we will need to reset the filepointer after parsing ID3v2 + + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_id3v2 = new getid3_id3v2($getid3_temp); + $getid3_id3v2->StartingOffset = $this->ftell(); + if ($thisChunk['valid'] = $getid3_id3v2->Analyze()) { + $info['id3v2'] = $getid3_temp->info['id3v2']; + } + unset($getid3_temp, $getid3_id3v2); + + $this->fseek($endOfID3v2); + break; + + case 'DSD ': // DSD sound data chunk + case 'DST ': // DST sound data chunk + // actual audio data, we're not interested, skip + $this->fseek($datasize, SEEK_CUR); + break; + default: + $this->warning('Unhandled chunk "'.$thisChunk['name'].'"'); + $this->fseek($datasize, SEEK_CUR); + break; + } + + @$info['dsdiff']['chunks'][] = $thisChunk; + //break; + } + if (empty($info['audio']['bitrate']) && !empty($info['audio']['channels']) && !empty($info['audio']['sample_rate']) && !empty($info['audio']['bits_per_sample'])) { + $info['audio']['bitrate'] = $info['audio']['bits_per_sample'] * $info['audio']['sample_rate'] * $info['audio']['channels']; + } + + return true; + } + + /** + * @param int $cmtType + * + * @return string + */ + public static function DSDIFFcmtType($cmtType) { + static $DSDIFFcmtType = array( + 0 => 'General (album) Comment', + 1 => 'Channel Comment', + 2 => 'Sound Source', + 3 => 'File History', + ); + return (isset($DSDIFFcmtType[$cmtType]) ? $DSDIFFcmtType[$cmtType] : 'reserved'); + } + + /** + * @param int $cmtType + * @param int $cmtRef + * + * @return string + */ + public static function DSDIFFcmtRef($cmtType, $cmtRef) { + static $DSDIFFcmtRef = array( + 2 => array( // Sound Source + 0 => 'DSD recording', + 1 => 'Analogue recording', + 2 => 'PCM recording', + ), + 3 => array( // File History + 0 => 'comment', // General Remark + 1 => 'encodeby', // Name of the operator + 2 => 'encoder', // Name or type of the creating machine + 3 => 'timezone', // Time zone information + 4 => 'revision', // Revision of the file + ), + ); + switch ($cmtType) { + case 0: + // If the comment type is General Comment the comment reference must be 0 + return ''; + case 1: + // If the comment type is Channel Comment, the comment reference defines the channel number to which the comment belongs + return ($cmtRef ? 'channel '.$cmtRef : 'all channels'); + case 2: + case 3: + return (isset($DSDIFFcmtRef[$cmtType][$cmtRef]) ? $DSDIFFcmtRef[$cmtType][$cmtRef] : 'reserved'); + } + return 'unsupported $cmtType='.$cmtType; + } + + /** + * @param int $markType + * + * @return string + */ + public static function DSDIFFmarkType($markType) { + static $DSDIFFmarkType = array( + 0 => 'TrackStart', // Entry point for a Track start + 1 => 'TrackStop', // Entry point for ending a Track + 2 => 'ProgramStart', // Start point of 2-channel or multi-channel area + 3 => 'Obsolete', // + 4 => 'Index', // Entry point of an Index + ); + return (isset($DSDIFFmarkType[$markType]) ? $DSDIFFmarkType[$markType] : 'reserved'); + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.dsf.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.dsf.php new file mode 100644 index 00000000..cd059c92 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.dsf.php @@ -0,0 +1,142 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.dsf.php // +// module for analyzing dsf/DSF Audio files // +// dependencies: module.tag.id3v2.php // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); + +class getid3_dsf extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'dsf'; + $info['audio']['dataformat'] = 'dsf'; + $info['audio']['lossless'] = true; + $info['audio']['bitrate_mode'] = 'cbr'; + + $this->fseek($info['avdataoffset']); + $dsfheader = $this->fread(28 + 12); + + $headeroffset = 0; + $info['dsf']['dsd']['magic'] = substr($dsfheader, $headeroffset, 4); + $headeroffset += 4; + $magic = 'DSD '; + if ($info['dsf']['dsd']['magic'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['dsf']['dsd']['magic']).'"'); + unset($info['fileformat']); + unset($info['audio']); + unset($info['dsf']); + return false; + } + $info['dsf']['dsd']['dsd_chunk_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); // should be 28 + $headeroffset += 8; + $info['dsf']['dsd']['dsf_file_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); + $headeroffset += 8; + $info['dsf']['dsd']['meta_chunk_offset'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); + $headeroffset += 8; + + + $info['dsf']['fmt']['magic'] = substr($dsfheader, $headeroffset, 4); + $headeroffset += 4; + $magic = 'fmt '; + if ($info['dsf']['fmt']['magic'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$headeroffset.', found "'.getid3_lib::PrintHexBytes($info['dsf']['fmt']['magic']).'"'); + return false; + } + $info['dsf']['fmt']['fmt_chunk_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); // usually 52 bytes + $headeroffset += 8; + $dsfheader .= $this->fread($info['dsf']['fmt']['fmt_chunk_size'] - 12 + 12); // we have already read the entire DSD chunk, plus 12 bytes of FMT. We now want to read the size of FMT, plus 12 bytes into the next chunk to get magic and size. + if (strlen($dsfheader) != ($info['dsf']['dsd']['dsd_chunk_size'] + $info['dsf']['fmt']['fmt_chunk_size'] + 12)) { + $this->error('Expecting '.($info['dsf']['dsd']['dsd_chunk_size'] + $info['dsf']['fmt']['fmt_chunk_size']).' bytes header, found '.strlen($dsfheader).' bytes'); + return false; + } + $info['dsf']['fmt']['format_version'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); // usually "1" + $headeroffset += 4; + $info['dsf']['fmt']['format_id'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); // usually "0" = "DSD Raw" + $headeroffset += 4; + $info['dsf']['fmt']['channel_type_id'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); + $headeroffset += 4; + $info['dsf']['fmt']['channels'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); + $headeroffset += 4; + $info['dsf']['fmt']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); + $headeroffset += 4; + $info['dsf']['fmt']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); + $headeroffset += 4; + $info['dsf']['fmt']['sample_count'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); + $headeroffset += 8; + $info['dsf']['fmt']['channel_block_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); + $headeroffset += 4; + $info['dsf']['fmt']['reserved'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4)); // zero-filled + $headeroffset += 4; + + + $info['dsf']['data']['magic'] = substr($dsfheader, $headeroffset, 4); + $headeroffset += 4; + $magic = 'data'; + if ($info['dsf']['data']['magic'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$headeroffset.', found "'.getid3_lib::PrintHexBytes($info['dsf']['data']['magic']).'"'); + return false; + } + $info['dsf']['data']['data_chunk_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8)); + $headeroffset += 8; + $info['avdataoffset'] = $headeroffset; + $info['avdataend'] = $info['avdataoffset'] + $info['dsf']['data']['data_chunk_size']; + + + if ($info['dsf']['dsd']['meta_chunk_offset'] > 0) { + $getid3_id3v2 = new getid3_id3v2($this->getid3); + $getid3_id3v2->StartingOffset = $info['dsf']['dsd']['meta_chunk_offset']; + $getid3_id3v2->Analyze(); + unset($getid3_id3v2); + } + + + $info['dsf']['fmt']['channel_type'] = $this->DSFchannelTypeLookup($info['dsf']['fmt']['channel_type_id']); + $info['audio']['channelmode'] = $info['dsf']['fmt']['channel_type']; + $info['audio']['bits_per_sample'] = $info['dsf']['fmt']['bits_per_sample']; + $info['audio']['sample_rate'] = $info['dsf']['fmt']['sample_rate']; + $info['audio']['channels'] = $info['dsf']['fmt']['channels']; + $info['audio']['bitrate'] = $info['audio']['bits_per_sample'] * $info['audio']['sample_rate'] * $info['audio']['channels']; + $info['playtime_seconds'] = ($info['dsf']['data']['data_chunk_size'] * 8) / $info['audio']['bitrate']; + + return true; + } + + /** + * @param int $channel_type_id + * + * @return string + */ + public static function DSFchannelTypeLookup($channel_type_id) { + static $DSFchannelTypeLookup = array( + // interleaving order: + 1 => 'mono', // 1: Mono + 2 => 'stereo', // 1: Front-Left; 2: Front-Right + 3 => '3-channel', // 1: Front-Left; 2: Front-Right; 3: Center + 4 => 'quad', // 1: Front-Left; 2: Front-Right; 3: Back-Left; 4: Back-Right + 5 => '4-channel', // 1: Front-Left; 2: Front-Right; 3: Center; 4: Low-Frequency + 6 => '5-channel', // 1: Front-Left; 2: Front-Right; 3: Center; 4: Back-Left 5: Back-Right + 7 => '5.1', // 1: Front-Left; 2: Front-Right; 3: Center; 4: Low-Frequency; 5: Back-Left; 6: Back-Right + ); + return (isset($DSFchannelTypeLookup[$channel_type_id]) ? $DSFchannelTypeLookup[$channel_type_id] : ''); + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.dss.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.dss.php new file mode 100644 index 00000000..dd2a56b1 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.dss.php @@ -0,0 +1,114 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.dss.php // +// module for analyzing Digital Speech Standard (DSS) files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_dss extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + $DSSheader = $this->fread(1540); + + if (!preg_match('#^[\\x02-\\x08]ds[s2]#', $DSSheader)) { + $this->error('Expecting "[02-08] 64 73 [73|32]" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($DSSheader, 0, 4)).'"'); + return false; + } + + // some structure information taken from http://cpansearch.perl.org/src/RGIBSON/Audio-DSS-0.02/lib/Audio/DSS.pm + $info['encoding'] = 'ISO-8859-1'; // not certain, but assumed + $info['dss'] = array(); + + $info['fileformat'] = 'dss'; + $info['mime_type'] = 'audio/x-'.substr($DSSheader, 1, 3); // "audio/x-dss" or "audio/x-ds2" + $info['audio']['dataformat'] = substr($DSSheader, 1, 3); // "dss" or "ds2" + $info['audio']['bitrate_mode'] = 'cbr'; + + $info['dss']['version'] = ord(substr($DSSheader, 0, 1)); + $info['dss']['hardware'] = trim(substr($DSSheader, 12, 16)); // identification string for hardware used to create the file, e.g. "DPM 9600", "DS2400" + $info['dss']['unknown1'] = getid3_lib::LittleEndian2Int(substr($DSSheader, 28, 4)); + // 32-37 = "FE FF FE FF F7 FF" in all the sample files I've seen + $info['dss']['date_create_unix'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 38, 12)); + $info['dss']['date_complete_unix'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 50, 12)); + $info['dss']['playtime_sec'] = ((int) substr($DSSheader, 62, 2) * 3600) + ((int) substr($DSSheader, 64, 2) * 60) + (int) substr($DSSheader, 66, 2); // approximate file playtime in HHMMSS + if ($info['dss']['version'] <= 3) { + $info['dss']['playtime_ms'] = getid3_lib::LittleEndian2Int(substr($DSSheader, 512, 4)); // exact file playtime in milliseconds. Has also been observed at offset 530 in one sample file, with something else (unknown) at offset 512 + $info['dss']['priority'] = ord(substr($DSSheader, 793, 1)); + $info['dss']['comments'] = trim(substr($DSSheader, 798, 100)); + $info['dss']['sample_rate_index'] = ord(substr($DSSheader, 1538, 1)); // this isn't certain, this may or may not be where the sample rate info is stored, but it seems consistent on my small selection of sample files + $info['audio']['sample_rate'] = $this->DSSsampleRateLookup($info['dss']['sample_rate_index']); + } else { + $this->getid3->warning('DSS above version 3 not fully supported in this version of getID3. Any additional documentation or format specifications would be welcome. This file is version '.$info['dss']['version']); + } + + $info['audio']['bits_per_sample'] = 16; // maybe, maybe not -- most compressed audio formats don't have a fixed bits-per-sample value, but this is a reasonable approximation + $info['audio']['channels'] = 1; + + if (!empty($info['dss']['playtime_ms']) && (floor($info['dss']['playtime_ms'] / 1000) == $info['dss']['playtime_sec'])) { // *should* just be playtime_ms / 1000 but at least one sample file has playtime_ms at offset 530 instead of offset 512, so safety check + $info['playtime_seconds'] = $info['dss']['playtime_ms'] / 1000; + } else { + $info['playtime_seconds'] = $info['dss']['playtime_sec']; + if (!empty($info['dss']['playtime_ms'])) { + $this->getid3->warning('playtime_ms ('.number_format($info['dss']['playtime_ms'] / 1000, 3).') does not match playtime_sec ('.number_format($info['dss']['playtime_sec']).') - using playtime_sec value'); + } + } + $info['audio']['bitrate'] = ($info['filesize'] * 8) / $info['playtime_seconds']; + + return true; + } + + /** + * @param string $datestring + * + * @return int|false + */ + public function DSSdateStringToUnixDate($datestring) { + $y = (int) substr($datestring, 0, 2); + $m = substr($datestring, 2, 2); + $d = substr($datestring, 4, 2); + $h = substr($datestring, 6, 2); + $i = substr($datestring, 8, 2); + $s = substr($datestring, 10, 2); + $y += (($y < 95) ? 2000 : 1900); + return mktime($h, $i, $s, $m, $d, $y); + } + + /** + * @param int $sample_rate_index + * + * @return int|false + */ + public function DSSsampleRateLookup($sample_rate_index) { + static $dssSampleRateLookup = array( + 0x0A => 16000, + 0x0C => 11025, + 0x0D => 12000, + 0x15 => 8000, + ); + if (!array_key_exists($sample_rate_index, $dssSampleRateLookup)) { + $this->getid3->warning('unknown sample_rate_index: 0x'.strtoupper(dechex($sample_rate_index))); + return false; + } + return $dssSampleRateLookup[$sample_rate_index]; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.dts.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.dts.php new file mode 100644 index 00000000..ff1a88fc --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.dts.php @@ -0,0 +1,327 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.dts.php // +// module for analyzing DTS Audio files // +// dependencies: NONE // +// // +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +/** +* @tutorial http://wiki.multimedia.cx/index.php?title=DTS +*/ +class getid3_dts extends getid3_handler +{ + /** + * Default DTS syncword used in native .cpt or .dts formats. + */ + const syncword = "\x7F\xFE\x80\x01"; + + /** + * @var int + */ + private $readBinDataOffset = 0; + + /** + * Possible syncwords indicating bitstream encoding. + */ + public static $syncwords = array( + 0 => "\x7F\xFE\x80\x01", // raw big-endian + 1 => "\xFE\x7F\x01\x80", // raw little-endian + 2 => "\x1F\xFF\xE8\x00", // 14-bit big-endian + 3 => "\xFF\x1F\x00\xE8"); // 14-bit little-endian + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + $info['fileformat'] = 'dts'; + + $this->fseek($info['avdataoffset']); + $DTSheader = $this->fread(20); // we only need 2 words magic + 6 words frame header, but these words may be normal 16-bit words OR 14-bit words with 2 highest bits set to zero, so 8 words can be either 8*16/8 = 16 bytes OR 8*16*(16/14)/8 = 18.3 bytes + + // check syncword + $sync = substr($DTSheader, 0, 4); + if (($encoding = array_search($sync, self::$syncwords)) !== false) { + + $info['dts']['raw']['magic'] = $sync; + $this->readBinDataOffset = 32; + + } elseif ($this->isDependencyFor('matroska')) { + + // Matroska contains DTS without syncword encoded as raw big-endian format + $encoding = 0; + $this->readBinDataOffset = 0; + + } else { + + unset($info['fileformat']); + return $this->error('Expecting "'.implode('| ', array_map('getid3_lib::PrintHexBytes', self::$syncwords)).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($sync).'"'); + + } + + // decode header + $fhBS = ''; + for ($word_offset = 0; $word_offset <= strlen($DTSheader); $word_offset += 2) { + switch ($encoding) { + case 0: // raw big-endian + $fhBS .= getid3_lib::BigEndian2Bin( substr($DTSheader, $word_offset, 2) ); + break; + case 1: // raw little-endian + $fhBS .= getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2))); + break; + case 2: // 14-bit big-endian + $fhBS .= substr(getid3_lib::BigEndian2Bin( substr($DTSheader, $word_offset, 2) ), 2, 14); + break; + case 3: // 14-bit little-endian + $fhBS .= substr(getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2))), 2, 14); + break; + } + } + + $info['dts']['raw']['frame_type'] = $this->readBinData($fhBS, 1); + $info['dts']['raw']['deficit_samples'] = $this->readBinData($fhBS, 5); + $info['dts']['flags']['crc_present'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['raw']['pcm_sample_blocks'] = $this->readBinData($fhBS, 7); + $info['dts']['raw']['frame_byte_size'] = $this->readBinData($fhBS, 14); + $info['dts']['raw']['channel_arrangement'] = $this->readBinData($fhBS, 6); + $info['dts']['raw']['sample_frequency'] = $this->readBinData($fhBS, 4); + $info['dts']['raw']['bitrate'] = $this->readBinData($fhBS, 5); + $info['dts']['flags']['embedded_downmix'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['flags']['dynamicrange'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['flags']['timestamp'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['flags']['auxdata'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['flags']['hdcd'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['raw']['extension_audio'] = $this->readBinData($fhBS, 3); + $info['dts']['flags']['extended_coding'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['flags']['audio_sync_insertion'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['raw']['lfe_effects'] = $this->readBinData($fhBS, 2); + $info['dts']['flags']['predictor_history'] = (bool) $this->readBinData($fhBS, 1); + if ($info['dts']['flags']['crc_present']) { + $info['dts']['raw']['crc16'] = $this->readBinData($fhBS, 16); + } + $info['dts']['flags']['mri_perfect_reconst'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['raw']['encoder_soft_version'] = $this->readBinData($fhBS, 4); + $info['dts']['raw']['copy_history'] = $this->readBinData($fhBS, 2); + $info['dts']['raw']['bits_per_sample'] = $this->readBinData($fhBS, 2); + $info['dts']['flags']['surround_es'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['flags']['front_sum_diff'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['flags']['surround_sum_diff'] = (bool) $this->readBinData($fhBS, 1); + $info['dts']['raw']['dialog_normalization'] = $this->readBinData($fhBS, 4); + + + $info['dts']['bitrate'] = self::bitrateLookup($info['dts']['raw']['bitrate']); + $info['dts']['bits_per_sample'] = self::bitPerSampleLookup($info['dts']['raw']['bits_per_sample']); + $info['dts']['sample_rate'] = self::sampleRateLookup($info['dts']['raw']['sample_frequency']); + $info['dts']['dialog_normalization'] = self::dialogNormalization($info['dts']['raw']['dialog_normalization'], $info['dts']['raw']['encoder_soft_version']); + $info['dts']['flags']['lossless'] = (($info['dts']['raw']['bitrate'] == 31) ? true : false); + $info['dts']['bitrate_mode'] = (($info['dts']['raw']['bitrate'] == 30) ? 'vbr' : 'cbr'); + $info['dts']['channels'] = self::numChannelsLookup($info['dts']['raw']['channel_arrangement']); + $info['dts']['channel_arrangement'] = self::channelArrangementLookup($info['dts']['raw']['channel_arrangement']); + + $info['audio']['dataformat'] = 'dts'; + $info['audio']['lossless'] = $info['dts']['flags']['lossless']; + $info['audio']['bitrate_mode'] = $info['dts']['bitrate_mode']; + $info['audio']['bits_per_sample'] = $info['dts']['bits_per_sample']; + $info['audio']['sample_rate'] = $info['dts']['sample_rate']; + $info['audio']['channels'] = $info['dts']['channels']; + $info['audio']['bitrate'] = $info['dts']['bitrate']; + if (isset($info['avdataend']) && !empty($info['dts']['bitrate']) && is_numeric($info['dts']['bitrate'])) { + $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($info['dts']['bitrate'] / 8); + if (($encoding == 2) || ($encoding == 3)) { + // 14-bit data packed into 16-bit words, so the playtime is wrong because only (14/16) of the bytes in the data portion of the file are used at the specified bitrate + $info['playtime_seconds'] *= (14 / 16); + } + } + return true; + } + + /** + * @param string $bin + * @param int $length + * + * @return int + */ + private function readBinData($bin, $length) { + $data = substr($bin, $this->readBinDataOffset, $length); + $this->readBinDataOffset += $length; + + return bindec($data); + } + + /** + * @param int $index + * + * @return int|string|false + */ + public static function bitrateLookup($index) { + static $lookup = array( + 0 => 32000, + 1 => 56000, + 2 => 64000, + 3 => 96000, + 4 => 112000, + 5 => 128000, + 6 => 192000, + 7 => 224000, + 8 => 256000, + 9 => 320000, + 10 => 384000, + 11 => 448000, + 12 => 512000, + 13 => 576000, + 14 => 640000, + 15 => 768000, + 16 => 960000, + 17 => 1024000, + 18 => 1152000, + 19 => 1280000, + 20 => 1344000, + 21 => 1408000, + 22 => 1411200, + 23 => 1472000, + 24 => 1536000, + 25 => 1920000, + 26 => 2048000, + 27 => 3072000, + 28 => 3840000, + 29 => 'open', + 30 => 'variable', + 31 => 'lossless', + ); + return (isset($lookup[$index]) ? $lookup[$index] : false); + } + + /** + * @param int $index + * + * @return int|string|false + */ + public static function sampleRateLookup($index) { + static $lookup = array( + 0 => 'invalid', + 1 => 8000, + 2 => 16000, + 3 => 32000, + 4 => 'invalid', + 5 => 'invalid', + 6 => 11025, + 7 => 22050, + 8 => 44100, + 9 => 'invalid', + 10 => 'invalid', + 11 => 12000, + 12 => 24000, + 13 => 48000, + 14 => 'invalid', + 15 => 'invalid', + ); + return (isset($lookup[$index]) ? $lookup[$index] : false); + } + + /** + * @param int $index + * + * @return int|false + */ + public static function bitPerSampleLookup($index) { + static $lookup = array( + 0 => 16, + 1 => 20, + 2 => 24, + 3 => 24, + ); + return (isset($lookup[$index]) ? $lookup[$index] : false); + } + + /** + * @param int $index + * + * @return int|false + */ + public static function numChannelsLookup($index) { + switch ($index) { + case 0: + return 1; + case 1: + case 2: + case 3: + case 4: + return 2; + case 5: + case 6: + return 3; + case 7: + case 8: + return 4; + case 9: + return 5; + case 10: + case 11: + case 12: + return 6; + case 13: + return 7; + case 14: + case 15: + return 8; + } + return false; + } + + /** + * @param int $index + * + * @return string + */ + public static function channelArrangementLookup($index) { + static $lookup = array( + 0 => 'A', + 1 => 'A + B (dual mono)', + 2 => 'L + R (stereo)', + 3 => '(L+R) + (L-R) (sum-difference)', + 4 => 'LT + RT (left and right total)', + 5 => 'C + L + R', + 6 => 'L + R + S', + 7 => 'C + L + R + S', + 8 => 'L + R + SL + SR', + 9 => 'C + L + R + SL + SR', + 10 => 'CL + CR + L + R + SL + SR', + 11 => 'C + L + R+ LR + RR + OV', + 12 => 'CF + CR + LF + RF + LR + RR', + 13 => 'CL + C + CR + L + R + SL + SR', + 14 => 'CL + CR + L + R + SL1 + SL2 + SR1 + SR2', + 15 => 'CL + C+ CR + L + R + SL + S + SR', + ); + return (isset($lookup[$index]) ? $lookup[$index] : 'user-defined'); + } + + /** + * @param int $index + * @param int $version + * + * @return int|false + */ + public static function dialogNormalization($index, $version) { + switch ($version) { + case 7: + return 0 - $index; + case 6: + return 0 - 16 - $index; + } + return false; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.flac.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.flac.php new file mode 100644 index 00000000..014061da --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.flac.php @@ -0,0 +1,519 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.flac.php // +// module for analyzing FLAC and OggFLAC audio files // +// dependencies: module.audio.ogg.php // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, true); + +/** +* @tutorial http://flac.sourceforge.net/format.html +*/ +class getid3_flac extends getid3_handler +{ + const syncword = 'fLaC'; + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + $StreamMarker = $this->fread(4); + if ($StreamMarker != self::syncword) { + return $this->error('Expecting "'.getid3_lib::PrintHexBytes(self::syncword).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($StreamMarker).'"'); + } + $info['fileformat'] = 'flac'; + $info['audio']['dataformat'] = 'flac'; + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['lossless'] = true; + + // parse flac container + return $this->parseMETAdata(); + } + + /** + * @return bool + */ + public function parseMETAdata() { + $info = &$this->getid3->info; + do { + $BlockOffset = $this->ftell(); + $BlockHeader = $this->fread(4); + $LBFBT = getid3_lib::BigEndian2Int(substr($BlockHeader, 0, 1)); // LBFBT = LastBlockFlag + BlockType + $LastBlockFlag = (bool) ($LBFBT & 0x80); + $BlockType = ($LBFBT & 0x7F); + $BlockLength = getid3_lib::BigEndian2Int(substr($BlockHeader, 1, 3)); + $BlockTypeText = self::metaBlockTypeLookup($BlockType); + + if (($BlockOffset + 4 + $BlockLength) > $info['avdataend']) { + $this->warning('METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockTypeText.') at offset '.$BlockOffset.' extends beyond end of file'); + break; + } + if ($BlockLength < 1) { + if ($BlockTypeText != 'reserved') { + // probably supposed to be zero-length + $this->warning('METADATA_BLOCK_HEADER.BLOCK_LENGTH ('.$BlockTypeText.') at offset '.$BlockOffset.' is zero bytes'); + continue; + } + $this->error('METADATA_BLOCK_HEADER.BLOCK_LENGTH ('.$BlockLength.') at offset '.$BlockOffset.' is invalid'); + break; + } + + $info['flac'][$BlockTypeText]['raw'] = array(); + $BlockTypeText_raw = &$info['flac'][$BlockTypeText]['raw']; + + $BlockTypeText_raw['offset'] = $BlockOffset; + $BlockTypeText_raw['last_meta_block'] = $LastBlockFlag; + $BlockTypeText_raw['block_type'] = $BlockType; + $BlockTypeText_raw['block_type_text'] = $BlockTypeText; + $BlockTypeText_raw['block_length'] = $BlockLength; + if ($BlockTypeText_raw['block_type'] != 0x06) { // do not read attachment data automatically + $BlockTypeText_raw['block_data'] = $this->fread($BlockLength); + } + + switch ($BlockTypeText) { + case 'STREAMINFO': // 0x00 + if (!$this->parseSTREAMINFO($BlockTypeText_raw['block_data'])) { + return false; + } + break; + + case 'PADDING': // 0x01 + unset($info['flac']['PADDING']); // ignore + break; + + case 'APPLICATION': // 0x02 + if (!$this->parseAPPLICATION($BlockTypeText_raw['block_data'])) { + return false; + } + break; + + case 'SEEKTABLE': // 0x03 + if (!$this->parseSEEKTABLE($BlockTypeText_raw['block_data'])) { + return false; + } + break; + + case 'VORBIS_COMMENT': // 0x04 + if (!$this->parseVORBIS_COMMENT($BlockTypeText_raw['block_data'])) { + return false; + } + break; + + case 'CUESHEET': // 0x05 + if (!$this->parseCUESHEET($BlockTypeText_raw['block_data'])) { + return false; + } + break; + + case 'PICTURE': // 0x06 + if (!$this->parsePICTURE()) { + return false; + } + break; + + default: + $this->warning('Unhandled METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockType.') at offset '.$BlockOffset); + } + + unset($info['flac'][$BlockTypeText]['raw']); + $info['avdataoffset'] = $this->ftell(); + } + while ($LastBlockFlag === false); + + // handle tags + if (!empty($info['flac']['VORBIS_COMMENT']['comments'])) { + $info['flac']['comments'] = $info['flac']['VORBIS_COMMENT']['comments']; + } + if (!empty($info['flac']['VORBIS_COMMENT']['vendor'])) { + $info['audio']['encoder'] = str_replace('reference ', '', $info['flac']['VORBIS_COMMENT']['vendor']); + } + + // copy attachments to 'comments' array if nesesary + if (isset($info['flac']['PICTURE']) && ($this->getid3->option_save_attachments !== getID3::ATTACHMENTS_NONE)) { + foreach ($info['flac']['PICTURE'] as $entry) { + if (!empty($entry['data'])) { + if (!isset($info['flac']['comments']['picture'])) { + $info['flac']['comments']['picture'] = array(); + } + $comments_picture_data = array(); + foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) { + if (isset($entry[$picture_key])) { + $comments_picture_data[$picture_key] = $entry[$picture_key]; + } + } + $info['flac']['comments']['picture'][] = $comments_picture_data; + unset($comments_picture_data); + } + } + } + + if (isset($info['flac']['STREAMINFO'])) { + if (!$this->isDependencyFor('matroska')) { + $info['flac']['compressed_audio_bytes'] = $info['avdataend'] - $info['avdataoffset']; + } + $info['flac']['uncompressed_audio_bytes'] = $info['flac']['STREAMINFO']['samples_stream'] * $info['flac']['STREAMINFO']['channels'] * ($info['flac']['STREAMINFO']['bits_per_sample'] / 8); + if ($info['flac']['uncompressed_audio_bytes'] == 0) { + return $this->error('Corrupt FLAC file: uncompressed_audio_bytes == zero'); + } + if (!empty($info['flac']['compressed_audio_bytes'])) { + $info['flac']['compression_ratio'] = $info['flac']['compressed_audio_bytes'] / $info['flac']['uncompressed_audio_bytes']; + } + } + + // set md5_data_source - built into flac 0.5+ + if (isset($info['flac']['STREAMINFO']['audio_signature'])) { + + if ($info['flac']['STREAMINFO']['audio_signature'] === str_repeat("\x00", 16)) { + $this->warning('FLAC STREAMINFO.audio_signature is null (known issue with libOggFLAC)'); + } + else { + $info['md5_data_source'] = ''; + $md5 = $info['flac']['STREAMINFO']['audio_signature']; + for ($i = 0; $i < strlen($md5); $i++) { + $info['md5_data_source'] .= str_pad(dechex(ord($md5[$i])), 2, '00', STR_PAD_LEFT); + } + if (!preg_match('/^[0-9a-f]{32}$/', $info['md5_data_source'])) { + unset($info['md5_data_source']); + } + } + } + + if (isset($info['flac']['STREAMINFO']['bits_per_sample'])) { + $info['audio']['bits_per_sample'] = $info['flac']['STREAMINFO']['bits_per_sample']; + if ($info['audio']['bits_per_sample'] == 8) { + // special case + // must invert sign bit on all data bytes before MD5'ing to match FLAC's calculated value + // MD5sum calculates on unsigned bytes, but FLAC calculated MD5 on 8-bit audio data as signed + $this->warning('FLAC calculates MD5 data strangely on 8-bit audio, so the stored md5_data_source value will not match the decoded WAV file'); + } + } + + return true; + } + + + /** + * @param string $BlockData + * + * @return array + */ + public static function parseSTREAMINFOdata($BlockData) { + $streaminfo = array(); + $streaminfo['min_block_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 0, 2)); + $streaminfo['max_block_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 2, 2)); + $streaminfo['min_frame_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 4, 3)); + $streaminfo['max_frame_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 7, 3)); + + $SRCSBSS = getid3_lib::BigEndian2Bin(substr($BlockData, 10, 8)); + $streaminfo['sample_rate'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 0, 20)); + $streaminfo['channels'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 20, 3)) + 1; + $streaminfo['bits_per_sample'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 23, 5)) + 1; + $streaminfo['samples_stream'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 28, 36)); + + $streaminfo['audio_signature'] = substr($BlockData, 18, 16); + + return $streaminfo; + } + + /** + * @param string $BlockData + * + * @return bool + */ + private function parseSTREAMINFO($BlockData) { + $info = &$this->getid3->info; + + $info['flac']['STREAMINFO'] = self::parseSTREAMINFOdata($BlockData); + + if (!empty($info['flac']['STREAMINFO']['sample_rate'])) { + + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['sample_rate'] = $info['flac']['STREAMINFO']['sample_rate']; + $info['audio']['channels'] = $info['flac']['STREAMINFO']['channels']; + $info['audio']['bits_per_sample'] = $info['flac']['STREAMINFO']['bits_per_sample']; + $info['playtime_seconds'] = $info['flac']['STREAMINFO']['samples_stream'] / $info['flac']['STREAMINFO']['sample_rate']; + if ($info['playtime_seconds'] > 0) { + if (!$this->isDependencyFor('matroska')) { + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + } + else { + $this->warning('Cannot determine audio bitrate because total stream size is unknown'); + } + } + + } else { + return $this->error('Corrupt METAdata block: STREAMINFO'); + } + + return true; + } + + /** + * @param string $BlockData + * + * @return bool + */ + private function parseAPPLICATION($BlockData) { + $info = &$this->getid3->info; + + $ApplicationID = getid3_lib::BigEndian2Int(substr($BlockData, 0, 4)); + $info['flac']['APPLICATION'][$ApplicationID]['name'] = self::applicationIDLookup($ApplicationID); + $info['flac']['APPLICATION'][$ApplicationID]['data'] = substr($BlockData, 4); + + return true; + } + + /** + * @param string $BlockData + * + * @return bool + */ + private function parseSEEKTABLE($BlockData) { + $info = &$this->getid3->info; + + $offset = 0; + $BlockLength = strlen($BlockData); + $placeholderpattern = str_repeat("\xFF", 8); + while ($offset < $BlockLength) { + $SampleNumberString = substr($BlockData, $offset, 8); + $offset += 8; + if ($SampleNumberString == $placeholderpattern) { + + // placeholder point + getid3_lib::safe_inc($info['flac']['SEEKTABLE']['placeholders'], 1); + $offset += 10; + + } else { + + $SampleNumber = getid3_lib::BigEndian2Int($SampleNumberString); + $info['flac']['SEEKTABLE'][$SampleNumber]['offset'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8)); + $offset += 8; + $info['flac']['SEEKTABLE'][$SampleNumber]['samples'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 2)); + $offset += 2; + + } + } + + return true; + } + + /** + * @param string $BlockData + * + * @return bool + */ + private function parseVORBIS_COMMENT($BlockData) { + $info = &$this->getid3->info; + + $getid3_ogg = new getid3_ogg($this->getid3); + if ($this->isDependencyFor('matroska')) { + $getid3_ogg->setStringMode($this->data_string); + } + $getid3_ogg->ParseVorbisComments(); + if (isset($info['ogg'])) { + unset($info['ogg']['comments_raw']); + $info['flac']['VORBIS_COMMENT'] = $info['ogg']; + unset($info['ogg']); + } + + unset($getid3_ogg); + + return true; + } + + /** + * @param string $BlockData + * + * @return bool + */ + private function parseCUESHEET($BlockData) { + $info = &$this->getid3->info; + $offset = 0; + $info['flac']['CUESHEET']['media_catalog_number'] = trim(substr($BlockData, $offset, 128), "\0"); + $offset += 128; + $info['flac']['CUESHEET']['lead_in_samples'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8)); + $offset += 8; + $info['flac']['CUESHEET']['flags']['is_cd'] = (bool) (getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)) & 0x80); + $offset += 1; + + $offset += 258; // reserved + + $info['flac']['CUESHEET']['number_tracks'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); + $offset += 1; + + for ($track = 0; $track < $info['flac']['CUESHEET']['number_tracks']; $track++) { + $TrackSampleOffset = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8)); + $offset += 8; + $TrackNumber = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); + $offset += 1; + + $info['flac']['CUESHEET']['tracks'][$TrackNumber]['sample_offset'] = $TrackSampleOffset; + + $info['flac']['CUESHEET']['tracks'][$TrackNumber]['isrc'] = substr($BlockData, $offset, 12); + $offset += 12; + + $TrackFlagsRaw = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); + $offset += 1; + $info['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['is_audio'] = (bool) ($TrackFlagsRaw & 0x80); + $info['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['pre_emphasis'] = (bool) ($TrackFlagsRaw & 0x40); + + $offset += 13; // reserved + + $info['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); + $offset += 1; + + for ($index = 0; $index < $info['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points']; $index++) { + $IndexSampleOffset = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8)); + $offset += 8; + $IndexNumber = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)); + $offset += 1; + + $offset += 3; // reserved + + $info['flac']['CUESHEET']['tracks'][$TrackNumber]['indexes'][$IndexNumber] = $IndexSampleOffset; + } + } + + return true; + } + + /** + * Parse METADATA_BLOCK_PICTURE flac structure and extract attachment + * External usage: audio.ogg + * + * @return bool + */ + public function parsePICTURE() { + $info = &$this->getid3->info; + + $picture = array(); + $picture['typeid'] = getid3_lib::BigEndian2Int($this->fread(4)); + $picture['picturetype'] = self::pictureTypeLookup($picture['typeid']); + $picture['image_mime'] = $this->fread(getid3_lib::BigEndian2Int($this->fread(4))); + $descr_length = getid3_lib::BigEndian2Int($this->fread(4)); + if ($descr_length) { + $picture['description'] = $this->fread($descr_length); + } + $picture['image_width'] = getid3_lib::BigEndian2Int($this->fread(4)); + $picture['image_height'] = getid3_lib::BigEndian2Int($this->fread(4)); + $picture['color_depth'] = getid3_lib::BigEndian2Int($this->fread(4)); + $picture['colors_indexed'] = getid3_lib::BigEndian2Int($this->fread(4)); + $picture['datalength'] = getid3_lib::BigEndian2Int($this->fread(4)); + + if ($picture['image_mime'] == '-->') { + $picture['data'] = $this->fread($picture['datalength']); + } else { + $picture['data'] = $this->saveAttachment( + str_replace('/', '_', $picture['picturetype']).'_'.$this->ftell(), + $this->ftell(), + $picture['datalength'], + $picture['image_mime']); + } + + $info['flac']['PICTURE'][] = $picture; + + return true; + } + + /** + * @param int $blocktype + * + * @return string + */ + public static function metaBlockTypeLookup($blocktype) { + static $lookup = array( + 0 => 'STREAMINFO', + 1 => 'PADDING', + 2 => 'APPLICATION', + 3 => 'SEEKTABLE', + 4 => 'VORBIS_COMMENT', + 5 => 'CUESHEET', + 6 => 'PICTURE', + ); + return (isset($lookup[$blocktype]) ? $lookup[$blocktype] : 'reserved'); + } + + /** + * @param int $applicationid + * + * @return string + */ + public static function applicationIDLookup($applicationid) { + // http://flac.sourceforge.net/id.html + static $lookup = array( + 0x41544348 => 'FlacFile', // "ATCH" + 0x42534F4C => 'beSolo', // "BSOL" + 0x42554753 => 'Bugs Player', // "BUGS" + 0x43756573 => 'GoldWave cue points (specification)', // "Cues" + 0x46696361 => 'CUE Splitter', // "Fica" + 0x46746F6C => 'flac-tools', // "Ftol" + 0x4D4F5442 => 'MOTB MetaCzar', // "MOTB" + 0x4D505345 => 'MP3 Stream Editor', // "MPSE" + 0x4D754D4C => 'MusicML: Music Metadata Language', // "MuML" + 0x52494646 => 'Sound Devices RIFF chunk storage', // "RIFF" + 0x5346464C => 'Sound Font FLAC', // "SFFL" + 0x534F4E59 => 'Sony Creative Software', // "SONY" + 0x5351455A => 'flacsqueeze', // "SQEZ" + 0x54745776 => 'TwistedWave', // "TtWv" + 0x55495453 => 'UITS Embedding tools', // "UITS" + 0x61696666 => 'FLAC AIFF chunk storage', // "aiff" + 0x696D6167 => 'flac-image application for storing arbitrary files in APPLICATION metadata blocks', // "imag" + 0x7065656D => 'Parseable Embedded Extensible Metadata (specification)', // "peem" + 0x71667374 => 'QFLAC Studio', // "qfst" + 0x72696666 => 'FLAC RIFF chunk storage', // "riff" + 0x74756E65 => 'TagTuner', // "tune" + 0x78626174 => 'XBAT', // "xbat" + 0x786D6364 => 'xmcd', // "xmcd" + ); + return (isset($lookup[$applicationid]) ? $lookup[$applicationid] : 'reserved'); + } + + /** + * @param int $type_id + * + * @return string + */ + public static function pictureTypeLookup($type_id) { + static $lookup = array ( + 0 => 'Other', + 1 => '32x32 pixels \'file icon\' (PNG only)', + 2 => 'Other file icon', + 3 => 'Cover (front)', + 4 => 'Cover (back)', + 5 => 'Leaflet page', + 6 => 'Media (e.g. label side of CD)', + 7 => 'Lead artist/lead performer/soloist', + 8 => 'Artist/performer', + 9 => 'Conductor', + 10 => 'Band/Orchestra', + 11 => 'Composer', + 12 => 'Lyricist/text writer', + 13 => 'Recording Location', + 14 => 'During recording', + 15 => 'During performance', + 16 => 'Movie/video screen capture', + 17 => 'A bright coloured fish', + 18 => 'Illustration', + 19 => 'Band/artist logotype', + 20 => 'Publisher/Studio logotype', + ); + return (isset($lookup[$type_id]) ? $lookup[$type_id] : 'reserved'); + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.la.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.la.php new file mode 100644 index 00000000..27a46793 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.la.php @@ -0,0 +1,230 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.la.php // +// module for analyzing LA (LosslessAudio) audio files // +// dependencies: module.audio.riff.php // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); + +class getid3_la extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $offset = 0; + $this->fseek($info['avdataoffset']); + $rawdata = $this->fread($this->getid3->fread_buffer_size()); + + switch (substr($rawdata, $offset, 4)) { + case 'LA02': + case 'LA03': + case 'LA04': + $info['fileformat'] = 'la'; + $info['audio']['dataformat'] = 'la'; + $info['audio']['lossless'] = true; + + $info['la']['version_major'] = (int) substr($rawdata, $offset + 2, 1); + $info['la']['version_minor'] = (int) substr($rawdata, $offset + 3, 1); + $info['la']['version'] = (float) $info['la']['version_major'] + ($info['la']['version_minor'] / 10); + $offset += 4; + + $info['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; + if ($info['la']['uncompressed_size'] == 0) { + $this->error('Corrupt LA file: uncompressed_size == zero'); + return false; + } + + $WAVEchunk = substr($rawdata, $offset, 4); + if ($WAVEchunk !== 'WAVE') { + $this->error('Expected "WAVE" ('.getid3_lib::PrintHexBytes('WAVE').') at offset '.$offset.', found "'.$WAVEchunk.'" ('.getid3_lib::PrintHexBytes($WAVEchunk).') instead.'); + return false; + } + $offset += 4; + + $info['la']['fmt_size'] = 24; + if ($info['la']['version'] >= 0.3) { + + $info['la']['fmt_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $info['la']['header_size'] = 49 + $info['la']['fmt_size'] - 24; + $offset += 4; + + } else { + + // version 0.2 didn't support additional data blocks + $info['la']['header_size'] = 41; + + } + + $fmt_chunk = substr($rawdata, $offset, 4); + if ($fmt_chunk !== 'fmt ') { + $this->error('Expected "fmt " ('.getid3_lib::PrintHexBytes('fmt ').') at offset '.$offset.', found "'.$fmt_chunk.'" ('.getid3_lib::PrintHexBytes($fmt_chunk).') instead.'); + return false; + } + $offset += 4; + $fmt_size = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; + + $info['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); + $offset += 2; + + $info['la']['channels'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); + $offset += 2; + if ($info['la']['channels'] == 0) { + $this->error('Corrupt LA file: channels == zero'); + return false; + } + + $info['la']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; + if ($info['la']['sample_rate'] == 0) { + $this->error('Corrupt LA file: sample_rate == zero'); + return false; + } + + $info['la']['bytes_per_second'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; + $info['la']['bytes_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); + $offset += 2; + $info['la']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2)); + $offset += 2; + + $info['la']['samples'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; + + $info['la']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 1)); + $offset += 1; + $info['la']['flags']['seekable'] = (bool) ($info['la']['raw']['flags'] & 0x01); + if ($info['la']['version'] >= 0.4) { + $info['la']['flags']['high_compression'] = (bool) ($info['la']['raw']['flags'] & 0x02); + } + + $info['la']['original_crc'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; + + // mikeØbevin*de + // Basically, the blocksize/seekevery are 61440/19 in La0.4 and 73728/16 + // in earlier versions. A seekpoint is added every blocksize * seekevery + // samples, so 4 * int(totalSamples / (blockSize * seekEvery)) should + // give the number of bytes used for the seekpoints. Of course, if seeking + // is disabled, there are no seekpoints stored. + if ($info['la']['version'] >= 0.4) { + $info['la']['blocksize'] = 61440; + $info['la']['seekevery'] = 19; + } else { + $info['la']['blocksize'] = 73728; + $info['la']['seekevery'] = 16; + } + + $info['la']['seekpoint_count'] = 0; + if ($info['la']['flags']['seekable']) { + $info['la']['seekpoint_count'] = floor($info['la']['samples'] / ($info['la']['blocksize'] * $info['la']['seekevery'])); + + for ($i = 0; $i < $info['la']['seekpoint_count']; $i++) { + $info['la']['seekpoints'][] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; + } + } + + if ($info['la']['version'] >= 0.3) { + + // Following the main header information, the program outputs all of the + // seekpoints. Following these is what I called the 'footer start', + // i.e. the position immediately after the La audio data is finished. + $info['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4)); + $offset += 4; + + if ($info['la']['footerstart'] > $info['filesize']) { + $this->warning('FooterStart value points to offset '.$info['la']['footerstart'].' which is beyond end-of-file ('.$info['filesize'].')'); + $info['la']['footerstart'] = $info['filesize']; + } + + } else { + + // La v0.2 didn't have FooterStart value + $info['la']['footerstart'] = $info['avdataend']; + + } + + if ($info['la']['footerstart'] < $info['avdataend']) { + if ($RIFFtempfilename = tempnam(GETID3_TEMP_DIR, 'id3')) { + if ($RIFF_fp = fopen($RIFFtempfilename, 'w+b')) { + $RIFFdata = 'WAVE'; + if ($info['la']['version'] == 0.2) { + $RIFFdata .= substr($rawdata, 12, 24); + } else { + $RIFFdata .= substr($rawdata, 16, 24); + } + if ($info['la']['footerstart'] < $info['avdataend']) { + $this->fseek($info['la']['footerstart']); + $RIFFdata .= $this->fread($info['avdataend'] - $info['la']['footerstart']); + } + $RIFFdata = 'RIFF'.getid3_lib::LittleEndian2String(strlen($RIFFdata), 4, false).$RIFFdata; + fwrite($RIFF_fp, $RIFFdata, strlen($RIFFdata)); + fclose($RIFF_fp); + + $getid3_temp = new getID3(); + $getid3_temp->openfile($RIFFtempfilename); + $getid3_riff = new getid3_riff($getid3_temp); + $getid3_riff->Analyze(); + + if (empty($getid3_temp->info['error'])) { + $info['riff'] = $getid3_temp->info['riff']; + } else { + $this->warning('Error parsing RIFF portion of La file: '.implode($getid3_temp->info['error'])); + } + unset($getid3_temp, $getid3_riff); + } + unlink($RIFFtempfilename); + } + } + + // $info['avdataoffset'] should be zero to begin with, but just in case it's not, include the addition anyway + $info['avdataend'] = $info['avdataoffset'] + $info['la']['footerstart']; + $info['avdataoffset'] = $info['avdataoffset'] + $offset; + + $info['la']['compression_ratio'] = (float) (($info['avdataend'] - $info['avdataoffset']) / $info['la']['uncompressed_size']); + $info['playtime_seconds'] = (float) ($info['la']['samples'] / $info['la']['sample_rate']) / $info['la']['channels']; + if ($info['playtime_seconds'] == 0) { + $this->error('Corrupt LA file: playtime_seconds == zero'); + return false; + } + + $info['audio']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['playtime_seconds']; + //$info['audio']['codec'] = $info['la']['codec']; + $info['audio']['bits_per_sample'] = $info['la']['bits_per_sample']; + break; + + default: + if (substr($rawdata, $offset, 2) == 'LA') { + $this->error('This version of getID3() ['.$this->getid3->version().'] does not support LA version '.substr($rawdata, $offset + 2, 1).'.'.substr($rawdata, $offset + 3, 1).' which this appears to be - check http://getid3.sourceforge.net for updates.'); + } else { + $this->error('Not a LA (Lossless-Audio) file'); + } + return false; + } + + $info['audio']['channels'] = $info['la']['channels']; + $info['audio']['sample_rate'] = (int) $info['la']['sample_rate']; + $info['audio']['encoder'] = 'LA v'.$info['la']['version']; + + return true; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.lpac.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.lpac.php new file mode 100644 index 00000000..6656a141 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.lpac.php @@ -0,0 +1,135 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.lpac.php // +// module for analyzing LPAC Audio files // +// dependencies: module.audio-video.riff.php // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); + +class getid3_lpac extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + $LPACheader = $this->fread(14); + $StreamMarker = substr($LPACheader, 0, 4); + if ($StreamMarker != 'LPAC') { + $this->error('Expected "LPAC" at offset '.$info['avdataoffset'].', found "'.$StreamMarker.'"'); + return false; + } + $flags = array(); + $info['avdataoffset'] += 14; + + $info['fileformat'] = 'lpac'; + $info['audio']['dataformat'] = 'lpac'; + $info['audio']['lossless'] = true; + $info['audio']['bitrate_mode'] = 'vbr'; + + $info['lpac']['file_version'] = getid3_lib::BigEndian2Int(substr($LPACheader, 4, 1)); + $flags['audio_type'] = getid3_lib::BigEndian2Int(substr($LPACheader, 5, 1)); + $info['lpac']['total_samples']= getid3_lib::BigEndian2Int(substr($LPACheader, 6, 4)); + $flags['parameters'] = getid3_lib::BigEndian2Int(substr($LPACheader, 10, 4)); + + $info['lpac']['flags']['is_wave'] = (bool) ($flags['audio_type'] & 0x40); + $info['lpac']['flags']['stereo'] = (bool) ($flags['audio_type'] & 0x04); + $info['lpac']['flags']['24_bit'] = (bool) ($flags['audio_type'] & 0x02); + $info['lpac']['flags']['16_bit'] = (bool) ($flags['audio_type'] & 0x01); + + if ($info['lpac']['flags']['24_bit'] && $info['lpac']['flags']['16_bit']) { + $this->warning('24-bit and 16-bit flags cannot both be set'); + } + + $info['lpac']['flags']['fast_compress'] = (bool) ($flags['parameters'] & 0x40000000); + $info['lpac']['flags']['random_access'] = (bool) ($flags['parameters'] & 0x08000000); + $info['lpac']['block_length'] = pow(2, (($flags['parameters'] & 0x07000000) >> 24)) * 256; + $info['lpac']['flags']['adaptive_prediction_order'] = (bool) ($flags['parameters'] & 0x00800000); + $info['lpac']['flags']['adaptive_quantization'] = (bool) ($flags['parameters'] & 0x00400000); + $info['lpac']['flags']['joint_stereo'] = (bool) ($flags['parameters'] & 0x00040000); + $info['lpac']['quantization'] = ($flags['parameters'] & 0x00001F00) >> 8; + $info['lpac']['max_prediction_order'] = ($flags['parameters'] & 0x0000003F); + + if ($info['lpac']['flags']['fast_compress'] && ($info['lpac']['max_prediction_order'] != 3)) { + $this->warning('max_prediction_order expected to be "3" if fast_compress is true, actual value is "'.$info['lpac']['max_prediction_order'].'"'); + } + switch ($info['lpac']['file_version']) { + case 6: + if ($info['lpac']['flags']['adaptive_quantization']) { + $this->warning('adaptive_quantization expected to be false in LPAC file stucture v6, actually true'); + } + if ($info['lpac']['quantization'] != 20) { + $this->warning('Quantization expected to be 20 in LPAC file stucture v6, actually '.$info['lpac']['flags']['Q']); + } + break; + + default: + //$this->warning('This version of getID3() ['.$this->getid3->version().'] only supports LPAC file format version 6, this file is version '.$info['lpac']['file_version'].' - please report to info@getid3.org'); + break; + } + + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_temp->info = $info; + $getid3_riff = new getid3_riff($getid3_temp); + $getid3_riff->Analyze(); + $info['avdataoffset'] = $getid3_temp->info['avdataoffset']; + $info['riff'] = $getid3_temp->info['riff']; + $info['error'] = $getid3_temp->info['error']; + $info['warning'] = $getid3_temp->info['warning']; + $info['lpac']['comments']['comment'] = $getid3_temp->info['comments']; + $info['audio']['sample_rate'] = $getid3_temp->info['audio']['sample_rate']; + unset($getid3_temp, $getid3_riff); + + $info['audio']['channels'] = ($info['lpac']['flags']['stereo'] ? 2 : 1); + + if ($info['lpac']['flags']['24_bit']) { + $info['audio']['bits_per_sample'] = $info['riff']['audio'][0]['bits_per_sample']; + } elseif ($info['lpac']['flags']['16_bit']) { + $info['audio']['bits_per_sample'] = 16; + } else { + $info['audio']['bits_per_sample'] = 8; + } + + if ($info['lpac']['flags']['fast_compress']) { + // fast + $info['audio']['encoder_options'] = '-1'; + } else { + switch ($info['lpac']['max_prediction_order']) { + case 20: // simple + $info['audio']['encoder_options'] = '-2'; + break; + case 30: // medium + $info['audio']['encoder_options'] = '-3'; + break; + case 40: // high + $info['audio']['encoder_options'] = '-4'; + break; + case 60: // extrahigh + $info['audio']['encoder_options'] = '-5'; + break; + } + } + + $info['playtime_seconds'] = $info['lpac']['total_samples'] / $info['audio']['sample_rate']; + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + + return true; + } + +} diff --git a/serendipity_event_podcast/player/getid3/module.audio.midi.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.midi.php similarity index 80% rename from serendipity_event_podcast/player/getid3/module.audio.midi.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.midi.php index a36a9f8d..d5fe81a2 100644 --- a/serendipity_event_podcast/player/getid3/module.audio.midi.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.midi.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.audio.midi.php // @@ -13,27 +14,43 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_midi +define('GETID3_MIDI_MAGIC_MTHD', 'MThd'); // MIDI file header magic +define('GETID3_MIDI_MAGIC_MTRK', 'MTrk'); // MIDI track header magic + +class getid3_midi extends getid3_handler { + /** + * if false only parse most basic information, much faster for some files but may be inaccurate + * + * @var bool + */ + public $scanwholefile = true; - function getid3_midi(&$fd, &$ThisFileInfo, $scanwholefile=true) { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; // shortcut - $ThisFileInfo['midi']['raw'] = array(); - $thisfile_midi = &$ThisFileInfo['midi']; + $info['midi']['raw'] = array(); + $thisfile_midi = &$info['midi']; $thisfile_midi_raw = &$thisfile_midi['raw']; - $ThisFileInfo['fileformat'] = 'midi'; - $ThisFileInfo['audio']['dataformat'] = 'midi'; + $info['fileformat'] = 'midi'; + $info['audio']['dataformat'] = 'midi'; - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $MIDIdata = fread($fd, GETID3_FREAD_BUFFER_SIZE); + $this->fseek($info['avdataoffset']); + $MIDIdata = $this->fread($this->getid3->fread_buffer_size()); $offset = 0; $MIDIheaderID = substr($MIDIdata, $offset, 4); // 'MThd' - if ($MIDIheaderID != 'MThd') { - $ThisFileInfo['error'][] = 'Expecting "MThd" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$MIDIheaderID.'"'; - unset($ThisFileInfo['fileformat']); + if ($MIDIheaderID != GETID3_MIDI_MAGIC_MTHD) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes(GETID3_MIDI_MAGIC_MTHD).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($MIDIheaderID).'"'); + unset($info['fileformat']); return false; } $offset += 4; @@ -46,37 +63,45 @@ class getid3_midi $thisfile_midi_raw['ticksperqnote'] = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 2)); $offset += 2; + $trackdataarray = array(); for ($i = 0; $i < $thisfile_midi_raw['tracks']; $i++) { - if ((strlen($MIDIdata) - $offset) < 8) { - $MIDIdata .= fread($fd, GETID3_FREAD_BUFFER_SIZE); + while ((strlen($MIDIdata) - $offset) < 8) { + if ($buffer = $this->fread($this->getid3->fread_buffer_size())) { + $MIDIdata .= $buffer; + } else { + $this->warning('only processed '.($i - 1).' of '.$thisfile_midi_raw['tracks'].' tracks'); + $this->error('Unabled to read more file data at '.$this->ftell().' (trying to seek to : '.$offset.'), was expecting at least 8 more bytes'); + return false; + } } $trackID = substr($MIDIdata, $offset, 4); $offset += 4; - if ($trackID == 'MTrk') { + if ($trackID == GETID3_MIDI_MAGIC_MTRK) { $tracksize = getid3_lib::BigEndian2Int(substr($MIDIdata, $offset, 4)); $offset += 4; - // $thisfile_midi['tracks'][$i]['size'] = $tracksize; + //$thisfile_midi['tracks'][$i]['size'] = $tracksize; $trackdataarray[$i] = substr($MIDIdata, $offset, $tracksize); $offset += $tracksize; } else { - $ThisFileInfo['error'][] = 'Expecting "MTrk" at '.$offset.', found '.$trackID.' instead'; + $this->error('Expecting "'.getid3_lib::PrintHexBytes(GETID3_MIDI_MAGIC_MTRK).'" at '.($offset - 4).', found "'.getid3_lib::PrintHexBytes($trackID).'" instead'); return false; } } - if (!isset($trackdataarray) || !is_array($trackdataarray)) { - $ThisFileInfo['error'][] = 'Cannot find MIDI track information'; + if (!is_array($trackdataarray) || count($trackdataarray) === 0) { + $this->error('Cannot find MIDI track information'); unset($thisfile_midi); - unset($ThisFileInfo['fileformat']); + unset($info['fileformat']); return false; } - if ($scanwholefile) { // this can take quite a long time, so have the option to bypass it if speed is very important + if ($this->scanwholefile) { // this can take quite a long time, so have the option to bypass it if speed is very important $thisfile_midi['totalticks'] = 0; - $ThisFileInfo['playtime_seconds'] = 0; + $info['playtime_seconds'] = 0; $CurrentMicroSecondsPerBeat = 500000; // 120 beats per minute; 60,000,000 microseconds per minute -> 500,000 microseconds per beat $CurrentBeatsPerMinute = 120; // 120 beats per minute; 60,000,000 microseconds per minute -> 500,000 microseconds per beat $MicroSecondsPerQuarterNoteAfter = array (); + $MIDIevents = array(); foreach ($trackdataarray as $tracknumber => $trackdata) { @@ -215,7 +240,7 @@ class getid3_midi case 0x51: // Tempo: microseconds / quarter note $CurrentMicroSecondsPerBeat = getid3_lib::BigEndian2Int(substr($METAeventData, 0, $METAeventLength)); if ($CurrentMicroSecondsPerBeat == 0) { - $ThisFileInfo['error'][] = 'Corrupt MIDI file: CurrentMicroSecondsPerBeat == zero'; + $this->error('Corrupt MIDI file: CurrentMicroSecondsPerBeat == zero'); return false; } $thisfile_midi_raw['events'][$tracknumber][$CumulativeDeltaTime]['us_qnote'] = $CurrentMicroSecondsPerBeat; @@ -225,9 +250,9 @@ class getid3_midi break; case 0x58: // Time signature - $timesig_numerator = getid3_lib::BigEndian2Int($METAeventData{0}); - $timesig_denominator = pow(2, getid3_lib::BigEndian2Int($METAeventData{1})); // $02 -> x/4, $03 -> x/8, etc - $timesig_32inqnote = getid3_lib::BigEndian2Int($METAeventData{2}); // number of 32nd notes to the quarter note + $timesig_numerator = getid3_lib::BigEndian2Int($METAeventData[0]); + $timesig_denominator = pow(2, getid3_lib::BigEndian2Int($METAeventData[1])); // $02 -> x/4, $03 -> x/8, etc + $timesig_32inqnote = getid3_lib::BigEndian2Int($METAeventData[2]); // number of 32nd notes to the quarter note //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_32inqnote'] = $timesig_32inqnote; //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_numerator'] = $timesig_numerator; //$thisfile_midi_raw['events'][$tracknumber][$eventid]['timesig_denominator'] = $timesig_denominator; @@ -236,13 +261,13 @@ class getid3_midi break; case 0x59: // Keysignature - $keysig_sharpsflats = getid3_lib::BigEndian2Int($METAeventData{0}); + $keysig_sharpsflats = getid3_lib::BigEndian2Int($METAeventData[0]); if ($keysig_sharpsflats & 0x80) { // (-7 -> 7 flats, 0 ->key of C, 7 -> 7 sharps) $keysig_sharpsflats -= 256; } - $keysig_majorminor = getid3_lib::BigEndian2Int($METAeventData{1}); // 0 -> major, 1 -> minor + $keysig_majorminor = getid3_lib::BigEndian2Int($METAeventData[1]); // 0 -> major, 1 -> minor $keysigs = array(-7=>'Cb', -6=>'Gb', -5=>'Db', -4=>'Ab', -3=>'Eb', -2=>'Bb', -1=>'F', 0=>'C', 1=>'G', 2=>'D', 3=>'A', 4=>'E', 5=>'B', 6=>'F#', 7=>'C#'); //$thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_sharps'] = (($keysig_sharpsflats > 0) ? abs($keysig_sharpsflats) : 0); //$thisfile_midi_raw['events'][$tracknumber][$eventid]['keysig_flats'] = (($keysig_sharpsflats < 0) ? abs($keysig_sharpsflats) : 0); @@ -258,13 +283,13 @@ class getid3_midi break; default: - $ThisFileInfo['warning'][] = 'Unhandled META Event Command: '.$METAeventCommand; + $this->warning('Unhandled META Event Command: '.$METAeventCommand); break; } } else { - $ThisFileInfo['warning'][] = 'Unhandled MIDI Event ID: '.$MIDIevents[$tracknumber][$eventid]['eventid'].' + Channel ID: '.$MIDIevents[$tracknumber][$eventid]['channel']; + $this->warning('Unhandled MIDI Event ID: '.$MIDIevents[$tracknumber][$eventid]['eventid'].' + Channel ID: '.$MIDIevents[$tracknumber][$eventid]['channel']); } } @@ -272,7 +297,8 @@ class getid3_midi $thisfile_midi['totalticks'] = max($thisfile_midi['totalticks'], $CumulativeDeltaTime); } } - $previoustickoffset = null; + $previoustickoffset = null; + $prevmicrosecondsperbeat = null; ksort($MicroSecondsPerQuarterNoteAfter); foreach ($MicroSecondsPerQuarterNoteAfter as $tickoffset => $microsecondsperbeat) { @@ -284,11 +310,11 @@ class getid3_midi if ($thisfile_midi['totalticks'] > $tickoffset) { if ($thisfile_midi_raw['ticksperqnote'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt MIDI file: ticksperqnote == zero'; + $this->error('Corrupt MIDI file: ticksperqnote == zero'); return false; } - $ThisFileInfo['playtime_seconds'] += (($tickoffset - $previoustickoffset) / $thisfile_midi_raw['ticksperqnote']) * ($prevmicrosecondsperbeat / 1000000); + $info['playtime_seconds'] += (($tickoffset - $previoustickoffset) / $thisfile_midi_raw['ticksperqnote']) * ($prevmicrosecondsperbeat / 1000000); $prevmicrosecondsperbeat = $microsecondsperbeat; $previoustickoffset = $tickoffset; @@ -297,18 +323,18 @@ class getid3_midi if ($thisfile_midi['totalticks'] > $previoustickoffset) { if ($thisfile_midi_raw['ticksperqnote'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt MIDI file: ticksperqnote == zero'; + $this->error('Corrupt MIDI file: ticksperqnote == zero'); return false; } - $ThisFileInfo['playtime_seconds'] += (($thisfile_midi['totalticks'] - $previoustickoffset) / $thisfile_midi_raw['ticksperqnote']) * ($microsecondsperbeat / 1000000); + $info['playtime_seconds'] += (($thisfile_midi['totalticks'] - $previoustickoffset) / $thisfile_midi_raw['ticksperqnote']) * ($prevmicrosecondsperbeat / 1000000); } } - if (!empty($ThisFileInfo['playtime_seconds'])) { - $ThisFileInfo['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; + if (!empty($info['playtime_seconds'])) { + $info['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; } if (!empty($thisfile_midi['lyrics'])) { @@ -318,7 +344,12 @@ class getid3_midi return true; } - function GeneralMIDIinstrumentLookup($instrumentid) { + /** + * @param int $instrumentid + * + * @return string + */ + public function GeneralMIDIinstrumentLookup($instrumentid) { $begin = __LINE__; @@ -458,7 +489,12 @@ class getid3_midi return getid3_lib::EmbeddedLookup($instrumentid, $begin, __LINE__, __FILE__, 'GeneralMIDIinstrument'); } - function GeneralMIDIpercussionLookup($instrumentid) { + /** + * @param int $instrumentid + * + * @return string + */ + public function GeneralMIDIpercussionLookup($instrumentid) { $begin = __LINE__; @@ -517,6 +553,3 @@ class getid3_midi } } - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.mod.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.mod.php new file mode 100644 index 00000000..4841c640 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.mod.php @@ -0,0 +1,154 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.mod.php // +// module for analyzing MOD Audio files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_mod extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $fileheader = $this->fread(1088); + if (preg_match('#^IMPM#', $fileheader)) { + return $this->getITheaderFilepointer(); + } elseif (preg_match('#^Extended Module#', $fileheader)) { + return $this->getXMheaderFilepointer(); + } elseif (preg_match('#^.{44}SCRM#s', $fileheader)) { + return $this->getS3MheaderFilepointer(); + //} elseif (preg_match('#^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)#s', $fileheader)) { + } elseif (preg_match('#^.{1080}(M\\.K\\.)#s', $fileheader)) { + /* + The four letters "M.K." - This is something Mahoney & Kaktus inserted when they + increased the number of samples from 15 to 31. If it's not there, the module/song + uses 15 samples or the text has been removed to make the module harder to rip. + Startrekker puts "FLT4" or "FLT8" there instead. + If there are more than 64 patterns, PT2.3 will insert M!K! here. + */ + return $this->getMODheaderFilepointer(); + } + $this->error('This is not a known type of MOD file'); + return false; + } + + /** + * @return bool + */ + public function getMODheaderFilepointer() { + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $filedata = $this->fread(1084); + //if (!preg_match('#^(M.K.|[5-9]CHN|[1-3][0-9]CH)$#', $FormatID)) { + if (substr($filedata, 1080, 4) == 'M.K.') { + + // + 0 song/module working title + // + 20 15 sample headers (see below) + // + 470 song length (number of steps in pattern table) + // + 471 song speed in beats per minute (see below) + // + 472 pattern step table + $offset = 0; + $info['mod']['title'] = rtrim(substr($filedata, $offset, 20), "\x00"); $offset += 20; + + $info['tags']['mod']['title'] = array($info['mod']['title']); + + for ($samplenumber = 0; $samplenumber <= 30; $samplenumber++) { + $sampledata = array(); + $sampledata['name'] = substr($filedata, $offset, 22); $offset += 22; + $sampledata['length'] = getid3_lib::BigEndian2Int(substr($filedata, $offset, 2)); $offset += 2; + $sampledata['volume'] = getid3_lib::BigEndian2Int(substr($filedata, $offset, 2)); $offset += 2; + $sampledata['repeat_offset'] = getid3_lib::BigEndian2Int(substr($filedata, $offset, 2)); $offset += 2; + $sampledata['repeat_length'] = getid3_lib::BigEndian2Int(substr($filedata, $offset, 2)); $offset += 2; + $info['mod']['samples'][$samplenumber] = $sampledata; + } + + $info['mod']['song_length'] = getid3_lib::BigEndian2Int(substr($filedata, $offset++, 1));// Songlength. Range is 1-128. + $info['mod']['bpm'] = getid3_lib::BigEndian2Int(substr($filedata, $offset++, 1));// This byte is set to 127, so that old trackers will search through all patterns when loading. Noisetracker uses this byte for restart, ProTracker doesn't. + + for ($songposition = 0; $songposition <= 127; $songposition++) { + // Song positions 0-127. Each hold a number from 0-63 (or 0-127) + // that tells the tracker what pattern to play at that position. + $info['mod']['song_positions'][$songposition] = getid3_lib::BigEndian2Int(substr($filedata, $offset++, 1)); + } + + } else { + $this->error('unknown MOD ID at offset 1080: '.getid3_lib::PrintHexBytes(substr($filedata, 1080, 4))); + return false; + } + $info['fileformat'] = 'mod'; + +$this->warning('MOD (SoundTracker) parsing incomplete in this version of getID3() ['.$this->getid3->version().']'); + return true; + } + + /** + * @return bool + */ + public function getXMheaderFilepointer() { + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $FormatID = $this->fread(15); + if (!preg_match('#^Extended Module$#', $FormatID)) { + $this->error('This is not a known type of XM-MOD file'); + return false; + } + + $info['fileformat'] = 'xm'; + + $this->error('XM-MOD parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + return false; + } + + /** + * @return bool + */ + public function getS3MheaderFilepointer() { + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset'] + 44); + $FormatID = $this->fread(4); + if (!preg_match('#^SCRM$#', $FormatID)) { + $this->error('This is not a ScreamTracker MOD file'); + return false; + } + + $info['fileformat'] = 's3m'; + + $this->error('ScreamTracker parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + return false; + } + + /** + * @return bool + */ + public function getITheaderFilepointer() { + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $FormatID = $this->fread(4); + if (!preg_match('#^IMPM$#', $FormatID)) { + $this->error('This is not an ImpulseTracker MOD file'); + return false; + } + + $info['fileformat'] = 'it'; + + $this->error('ImpulseTracker parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + return false; + } + +} diff --git a/serendipity_event_podcast/player/getid3/module.audio.monkey.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.monkey.php similarity index 73% rename from serendipity_event_podcast/player/getid3/module.audio.monkey.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.monkey.php index 42382ad1..beaca8c1 100644 --- a/serendipity_event_podcast/player/getid3/module.audio.monkey.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.monkey.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.audio.monkey.php // @@ -13,30 +14,38 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_monkey +class getid3_monkey extends getid3_handler { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_monkey(&$fd, &$ThisFileInfo) { - // based loosely on code from TMonkey by Jurgen Faul + // based loosely on code from TMonkey by Jurgen Faul // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html - $ThisFileInfo['fileformat'] = 'mac'; - $ThisFileInfo['audio']['dataformat'] = 'mac'; - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; - $ThisFileInfo['audio']['lossless'] = true; + $info['fileformat'] = 'mac'; + $info['audio']['dataformat'] = 'mac'; + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['lossless'] = true; - $ThisFileInfo['monkeys_audio']['raw'] = array(); - $thisfile_monkeysaudio = &$ThisFileInfo['monkeys_audio']; + $info['monkeys_audio']['raw'] = array(); + $thisfile_monkeysaudio = &$info['monkeys_audio']; $thisfile_monkeysaudio_raw = &$thisfile_monkeysaudio['raw']; - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $MACheaderData = fread($fd, 74); + $this->fseek($info['avdataoffset']); + $MACheaderData = $this->fread(74); $thisfile_monkeysaudio_raw['magic'] = substr($MACheaderData, 0, 4); - if ($thisfile_monkeysaudio_raw['magic'] != 'MAC ') { - $ThisFileInfo['error'][] = 'Expecting "MAC" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$thisfile_monkeysaudio_raw['magic'].'"'; - unset($ThisFileInfo['fileformat']); + $magic = 'MAC '; + if ($thisfile_monkeysaudio_raw['magic'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($thisfile_monkeysaudio_raw['magic']).'"'); + unset($info['fileformat']); return false; } $thisfile_monkeysaudio_raw['nVersion'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 4, 2)); // appears to be uint32 in 3.98+ @@ -105,13 +114,13 @@ class getid3_monkey } $thisfile_monkeysaudio['bits_per_sample'] = ($thisfile_monkeysaudio['flags']['24-bit'] ? 24 : ($thisfile_monkeysaudio['flags']['8-bit'] ? 8 : 16)); $thisfile_monkeysaudio['channels'] = $thisfile_monkeysaudio_raw['nChannels']; - $ThisFileInfo['audio']['channels'] = $thisfile_monkeysaudio['channels']; + $info['audio']['channels'] = $thisfile_monkeysaudio['channels']; $thisfile_monkeysaudio['sample_rate'] = $thisfile_monkeysaudio_raw['nSampleRate']; if ($thisfile_monkeysaudio['sample_rate'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt MAC file: frequency == zero'; + $this->error('Corrupt MAC file: frequency == zero'); return false; } - $ThisFileInfo['audio']['sample_rate'] = $thisfile_monkeysaudio['sample_rate']; + $info['audio']['sample_rate'] = $thisfile_monkeysaudio['sample_rate']; if ($thisfile_monkeysaudio['flags']['peak_level']) { $thisfile_monkeysaudio['peak_level'] = $thisfile_monkeysaudio_raw['nPeakLevel']; $thisfile_monkeysaudio['peak_ratio'] = $thisfile_monkeysaudio['peak_level'] / pow(2, $thisfile_monkeysaudio['bits_per_sample'] - 1); @@ -123,57 +132,62 @@ class getid3_monkey } $thisfile_monkeysaudio['playtime'] = $thisfile_monkeysaudio['samples'] / $thisfile_monkeysaudio['sample_rate']; if ($thisfile_monkeysaudio['playtime'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt MAC file: playtime == zero'; + $this->error('Corrupt MAC file: playtime == zero'); return false; } - $ThisFileInfo['playtime_seconds'] = $thisfile_monkeysaudio['playtime']; - $thisfile_monkeysaudio['compressed_size'] = $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']; + $info['playtime_seconds'] = $thisfile_monkeysaudio['playtime']; + $thisfile_monkeysaudio['compressed_size'] = $info['avdataend'] - $info['avdataoffset']; $thisfile_monkeysaudio['uncompressed_size'] = $thisfile_monkeysaudio['samples'] * $thisfile_monkeysaudio['channels'] * ($thisfile_monkeysaudio['bits_per_sample'] / 8); if ($thisfile_monkeysaudio['uncompressed_size'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt MAC file: uncompressed_size == zero'; + $this->error('Corrupt MAC file: uncompressed_size == zero'); return false; } $thisfile_monkeysaudio['compression_ratio'] = $thisfile_monkeysaudio['compressed_size'] / ($thisfile_monkeysaudio['uncompressed_size'] + $thisfile_monkeysaudio_raw['nHeaderDataBytes']); $thisfile_monkeysaudio['bitrate'] = (($thisfile_monkeysaudio['samples'] * $thisfile_monkeysaudio['channels'] * $thisfile_monkeysaudio['bits_per_sample']) / $thisfile_monkeysaudio['playtime']) * $thisfile_monkeysaudio['compression_ratio']; - $ThisFileInfo['audio']['bitrate'] = $thisfile_monkeysaudio['bitrate']; + $info['audio']['bitrate'] = $thisfile_monkeysaudio['bitrate']; // add size of MAC header to avdataoffset if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) { - $ThisFileInfo['avdataoffset'] += $thisfile_monkeysaudio_raw['nDescriptorBytes']; - $ThisFileInfo['avdataoffset'] += $thisfile_monkeysaudio_raw['nHeaderBytes']; - $ThisFileInfo['avdataoffset'] += $thisfile_monkeysaudio_raw['nSeekTableBytes']; - $ThisFileInfo['avdataoffset'] += $thisfile_monkeysaudio_raw['nHeaderDataBytes']; + $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nDescriptorBytes']; + $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nHeaderBytes']; + $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nSeekTableBytes']; + $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nHeaderDataBytes']; - $ThisFileInfo['avdataend'] -= $thisfile_monkeysaudio_raw['nTerminatingDataBytes']; + $info['avdataend'] -= $thisfile_monkeysaudio_raw['nTerminatingDataBytes']; } else { - $ThisFileInfo['avdataoffset'] += $offset; + $info['avdataoffset'] += $offset; } if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) { if ($thisfile_monkeysaudio_raw['cFileMD5'] === str_repeat("\x00", 16)) { - //$ThisFileInfo['warning'][] = 'cFileMD5 is null'; + //$this->warning('cFileMD5 is null'); } else { - $ThisFileInfo['md5_data_source'] = ''; + $info['md5_data_source'] = ''; $md5 = $thisfile_monkeysaudio_raw['cFileMD5']; for ($i = 0; $i < strlen($md5); $i++) { - $ThisFileInfo['md5_data_source'] .= str_pad(dechex(ord($md5{$i})), 2, '00', STR_PAD_LEFT); + $info['md5_data_source'] .= str_pad(dechex(ord($md5[$i])), 2, '00', STR_PAD_LEFT); } - if (!preg_match('/^[0-9a-f]{32}$/', $ThisFileInfo['md5_data_source'])) { - unset($ThisFileInfo['md5_data_source']); + if (!preg_match('/^[0-9a-f]{32}$/', $info['md5_data_source'])) { + unset($info['md5_data_source']); } } } - $ThisFileInfo['audio']['bits_per_sample'] = $thisfile_monkeysaudio['bits_per_sample']; - $ThisFileInfo['audio']['encoder'] = 'MAC v'.number_format($thisfile_monkeysaudio['version'], 2); - $ThisFileInfo['audio']['encoder_options'] = ucfirst($thisfile_monkeysaudio['compression']).' compression'; + $info['audio']['bits_per_sample'] = $thisfile_monkeysaudio['bits_per_sample']; + $info['audio']['encoder'] = 'MAC v'.number_format($thisfile_monkeysaudio['version'], 2); + $info['audio']['encoder_options'] = ucfirst($thisfile_monkeysaudio['compression']).' compression'; return true; } - function MonkeyCompressionLevelNameLookup($compressionlevel) { + /** + * @param int $compressionlevel + * + * @return string + */ + public function MonkeyCompressionLevelNameLookup($compressionlevel) { static $MonkeyCompressionLevelNameLookup = array( 0 => 'unknown', 1000 => 'fast', @@ -185,7 +199,13 @@ class getid3_monkey return (isset($MonkeyCompressionLevelNameLookup[$compressionlevel]) ? $MonkeyCompressionLevelNameLookup[$compressionlevel] : 'invalid'); } - function MonkeySamplesPerFrame($versionid, $compressionlevel) { + /** + * @param int $versionid + * @param int $compressionlevel + * + * @return int + */ + public function MonkeySamplesPerFrame($versionid, $compressionlevel) { if ($versionid >= 3950) { return 73728 * 4; } elseif ($versionid >= 3900) { @@ -198,5 +218,3 @@ class getid3_monkey } } - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.mp3.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.mp3.php similarity index 52% rename from serendipity_event_podcast/player/getid3/module.audio.mp3.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.mp3.php index b97a7041..3d8a9442 100644 --- a/serendipity_event_podcast/player/getid3/module.audio.mp3.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.mp3.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.audio.mp3.php // @@ -13,73 +14,93 @@ // /// ///////////////////////////////////////////////////////////////// - -// number of frames to scan to determine if MPEG-audio sequence is valid -// Lower this number to 5-20 for faster scanning -// Increase this number to 50+ for most accurate detection of valid VBR/CBR -// mpeg-audio streams -define('GETID3_MP3_VALID_CHECK_FRAMES', 35); +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_mp3 +class getid3_mp3 extends getid3_handler { + /** + * Forces getID3() to scan the file byte-by-byte and log all the valid audio frame headers - extremely slow, + * unrecommended, but may provide data from otherwise-unusable files. + * + * @var bool + */ + public $allow_bruteforce = false; - var $allow_bruteforce = false; // forces getID3() to scan the file byte-by-byte and log all the valid audio frame headers - extremely slow, unrecommended, but may provide data from otherwise-unusuable files + /** + * number of frames to scan to determine if MPEG-audio sequence is valid + * Lower this number to 5-20 for faster scanning + * Increase this number to 50+ for most accurate detection of valid VBR/CBR mpeg-audio streams + * + * @var int + */ + public $mp3_valid_check_frames = 50; - function getid3_mp3(&$fd, &$ThisFileInfo) { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - if (!$this->getOnlyMPEGaudioInfo($fd, $ThisFileInfo, $ThisFileInfo['avdataoffset'])) { + $initialOffset = $info['avdataoffset']; + + if (!$this->getOnlyMPEGaudioInfo($info['avdataoffset'])) { if ($this->allow_bruteforce) { - $ThisFileInfo['error'][] = 'Rescanning file in BruteForce mode'; - $this->getOnlyMPEGaudioInfoBruteForce($fd, $ThisFileInfo); + $this->error('Rescanning file in BruteForce mode'); + $this->getOnlyMPEGaudioInfoBruteForce(); } } - if (isset($ThisFileInfo['mpeg']['audio']['bitrate_mode'])) { - $ThisFileInfo['audio']['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitrate_mode']); + if (isset($info['mpeg']['audio']['bitrate_mode'])) { + $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']); } - if (((isset($ThisFileInfo['id3v2']['headerlength']) && ($ThisFileInfo['avdataoffset'] > $ThisFileInfo['id3v2']['headerlength'])) || (!isset($ThisFileInfo['id3v2']) && ($ThisFileInfo['avdataoffset'] > 0)))) { + $CurrentDataLAMEversionString = null; + if (((isset($info['id3v2']['headerlength']) && ($info['avdataoffset'] > $info['id3v2']['headerlength'])) || (!isset($info['id3v2']) && ($info['avdataoffset'] > 0) && ($info['avdataoffset'] != $initialOffset)))) { $synchoffsetwarning = 'Unknown data before synch '; - if (isset($ThisFileInfo['id3v2']['headerlength'])) { - $synchoffsetwarning .= '(ID3v2 header ends at '.$ThisFileInfo['id3v2']['headerlength'].', then '.($ThisFileInfo['avdataoffset'] - $ThisFileInfo['id3v2']['headerlength']).' bytes garbage, '; + if (isset($info['id3v2']['headerlength'])) { + $synchoffsetwarning .= '(ID3v2 header ends at '.$info['id3v2']['headerlength'].', then '.($info['avdataoffset'] - $info['id3v2']['headerlength']).' bytes garbage, '; + } elseif ($initialOffset > 0) { + $synchoffsetwarning .= '(should be at '.$initialOffset.', '; } else { $synchoffsetwarning .= '(should be at beginning of file, '; } - $synchoffsetwarning .= 'synch detected at '.$ThisFileInfo['avdataoffset'].')'; - if (isset($ThisFileInfo['audio']['bitrate_mode']) && ($ThisFileInfo['audio']['bitrate_mode'] == 'cbr')) { + $synchoffsetwarning .= 'synch detected at '.$info['avdataoffset'].')'; + if (isset($info['audio']['bitrate_mode']) && ($info['audio']['bitrate_mode'] == 'cbr')) { - if (!empty($ThisFileInfo['id3v2']['headerlength']) && (($ThisFileInfo['avdataoffset'] - $ThisFileInfo['id3v2']['headerlength']) == $ThisFileInfo['mpeg']['audio']['framelength'])) { + if (!empty($info['id3v2']['headerlength']) && (($info['avdataoffset'] - $info['id3v2']['headerlength']) == $info['mpeg']['audio']['framelength'])) { $synchoffsetwarning .= '. This is a known problem with some versions of LAME (3.90-3.92) DLL in CBR mode.'; - $ThisFileInfo['audio']['codec'] = 'LAME'; + $info['audio']['codec'] = 'LAME'; $CurrentDataLAMEversionString = 'LAME3.'; - } elseif (empty($ThisFileInfo['id3v2']['headerlength']) && ($ThisFileInfo['avdataoffset'] == $ThisFileInfo['mpeg']['audio']['framelength'])) { + } elseif (empty($info['id3v2']['headerlength']) && ($info['avdataoffset'] == $info['mpeg']['audio']['framelength'])) { $synchoffsetwarning .= '. This is a known problem with some versions of LAME (3.90 - 3.92) DLL in CBR mode.'; - $ThisFileInfo['audio']['codec'] = 'LAME'; + $info['audio']['codec'] = 'LAME'; $CurrentDataLAMEversionString = 'LAME3.'; } } - $ThisFileInfo['warning'][] = $synchoffsetwarning; + $this->warning($synchoffsetwarning); } - if (isset($ThisFileInfo['mpeg']['audio']['LAME'])) { - $ThisFileInfo['audio']['codec'] = 'LAME'; - if (!empty($ThisFileInfo['mpeg']['audio']['LAME']['long_version'])) { - $ThisFileInfo['audio']['encoder'] = rtrim($ThisFileInfo['mpeg']['audio']['LAME']['long_version'], "\x00"); - } elseif (!empty($ThisFileInfo['mpeg']['audio']['LAME']['short_version'])) { - $ThisFileInfo['audio']['encoder'] = rtrim($ThisFileInfo['mpeg']['audio']['LAME']['short_version'], "\x00"); + if (isset($info['mpeg']['audio']['LAME'])) { + $info['audio']['codec'] = 'LAME'; + if (!empty($info['mpeg']['audio']['LAME']['long_version'])) { + $info['audio']['encoder'] = rtrim($info['mpeg']['audio']['LAME']['long_version'], "\x00"); + } elseif (!empty($info['mpeg']['audio']['LAME']['short_version'])) { + $info['audio']['encoder'] = rtrim($info['mpeg']['audio']['LAME']['short_version'], "\x00"); } } - $CurrentDataLAMEversionString = (!empty($CurrentDataLAMEversionString) ? $CurrentDataLAMEversionString : (isset($ThisFileInfo['audio']['encoder']) ? $ThisFileInfo['audio']['encoder'] : '')); + $CurrentDataLAMEversionString = (!empty($CurrentDataLAMEversionString) ? $CurrentDataLAMEversionString : (isset($info['audio']['encoder']) ? $info['audio']['encoder'] : '')); if (!empty($CurrentDataLAMEversionString) && (substr($CurrentDataLAMEversionString, 0, 6) == 'LAME3.') && !preg_match('[0-9\)]', substr($CurrentDataLAMEversionString, -1))) { // a version number of LAME that does not end with a number like "LAME3.92" // or with a closing parenthesis like "LAME3.88 (alpha)" @@ -89,9 +110,9 @@ class getid3_mp3 $PossiblyLongerLAMEversion_FrameLength = 1441; // Not sure what version of LAME this is - look in padding of last frame for longer version string - $PossibleLAMEversionStringOffset = $ThisFileInfo['avdataend'] - $PossiblyLongerLAMEversion_FrameLength; - fseek($fd, $PossibleLAMEversionStringOffset); - $PossiblyLongerLAMEversion_Data = fread($fd, $PossiblyLongerLAMEversion_FrameLength); + $PossibleLAMEversionStringOffset = $info['avdataend'] - $PossiblyLongerLAMEversion_FrameLength; + $this->fseek($PossibleLAMEversionStringOffset); + $PossiblyLongerLAMEversion_Data = $this->fread($PossiblyLongerLAMEversion_FrameLength); switch (substr($CurrentDataLAMEversionString, -1)) { case 'a': case 'b': @@ -103,62 +124,77 @@ class getid3_mp3 if (($PossiblyLongerLAMEversion_String = strstr($PossiblyLongerLAMEversion_Data, $CurrentDataLAMEversionString)) !== false) { if (substr($PossiblyLongerLAMEversion_String, 0, strlen($CurrentDataLAMEversionString)) == $CurrentDataLAMEversionString) { $PossiblyLongerLAMEversion_NewString = substr($PossiblyLongerLAMEversion_String, 0, strspn($PossiblyLongerLAMEversion_String, 'LAME0123456789., (abcdefghijklmnopqrstuvwxyzJFSOND)')); //"LAME3.90.3" "LAME3.87 (beta 1, Sep 27 2000)" "LAME3.88 (beta)" - if (empty($ThisFileInfo['audio']['encoder']) || (strlen($PossiblyLongerLAMEversion_NewString) > strlen($ThisFileInfo['audio']['encoder']))) { - $ThisFileInfo['audio']['encoder'] = $PossiblyLongerLAMEversion_NewString; + if (empty($info['audio']['encoder']) || (strlen($PossiblyLongerLAMEversion_NewString) > strlen($info['audio']['encoder']))) { + if (!empty($info['audio']['encoder']) && !empty($info['mpeg']['audio']['LAME']['short_version']) && ($info['audio']['encoder'] == $info['mpeg']['audio']['LAME']['short_version'])) { + if (preg_match('#^LAME[0-9\\.]+#', $PossiblyLongerLAMEversion_NewString, $matches)) { + // "LAME3.100" -> "LAME3.100.1", but avoid including "(alpha)" and similar + $info['mpeg']['audio']['LAME']['short_version'] = $matches[0]; + } + } + $info['audio']['encoder'] = $PossiblyLongerLAMEversion_NewString; } } } } - if (!empty($ThisFileInfo['audio']['encoder'])) { - $ThisFileInfo['audio']['encoder'] = rtrim($ThisFileInfo['audio']['encoder'], "\x00 "); + if (!empty($info['audio']['encoder'])) { + $info['audio']['encoder'] = rtrim($info['audio']['encoder'], "\x00 "); } - switch (isset($ThisFileInfo['mpeg']['audio']['layer']) ? $ThisFileInfo['mpeg']['audio']['layer'] : '') { + switch (isset($info['mpeg']['audio']['layer']) ? $info['mpeg']['audio']['layer'] : '') { case 1: case 2: - $ThisFileInfo['audio']['dataformat'] = 'mp'.$ThisFileInfo['mpeg']['audio']['layer']; + $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer']; break; } - if (isset($ThisFileInfo['fileformat']) && ($ThisFileInfo['fileformat'] == 'mp3')) { - switch ($ThisFileInfo['audio']['dataformat']) { + if (isset($info['fileformat']) && ($info['fileformat'] == 'mp3')) { + switch ($info['audio']['dataformat']) { case 'mp1': case 'mp2': case 'mp3': - $ThisFileInfo['fileformat'] = $ThisFileInfo['audio']['dataformat']; + $info['fileformat'] = $info['audio']['dataformat']; break; default: - $ThisFileInfo['warning'][] = 'Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$ThisFileInfo['audio']['dataformat'].'"'; + $this->warning('Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$info['audio']['dataformat'].'"'); break; } } - if (empty($ThisFileInfo['fileformat'])) { - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['audio']['bitrate_mode']); - unset($ThisFileInfo['avdataoffset']); - unset($ThisFileInfo['avdataend']); + if (empty($info['fileformat'])) { + unset($info['fileformat']); + unset($info['audio']['bitrate_mode']); + unset($info['avdataoffset']); + unset($info['avdataend']); return false; } - $ThisFileInfo['mime_type'] = 'audio/mpeg'; - $ThisFileInfo['audio']['lossless'] = false; + $info['mime_type'] = 'audio/mpeg'; + $info['audio']['lossless'] = false; // Calculate playtime - if (!isset($ThisFileInfo['playtime_seconds']) && isset($ThisFileInfo['audio']['bitrate']) && ($ThisFileInfo['audio']['bitrate'] > 0)) { - $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate']; + if (!isset($info['playtime_seconds']) && isset($info['audio']['bitrate']) && ($info['audio']['bitrate'] > 0)) { + // https://github.com/JamesHeinrich/getID3/issues/161 + // VBR header frame contains ~0.026s of silent audio data, but is not actually part of the original encoding and should be ignored + $xingVBRheaderFrameLength = ((isset($info['mpeg']['audio']['VBR_frames']) && isset($info['mpeg']['audio']['framelength'])) ? $info['mpeg']['audio']['framelength'] : 0); + + $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset'] - $xingVBRheaderFrameLength) * 8 / $info['audio']['bitrate']; } - $ThisFileInfo['audio']['encoder_options'] = $this->GuessEncoderOptions($ThisFileInfo); + $info['audio']['encoder_options'] = $this->GuessEncoderOptions(); return true; } - - static function GuessEncoderOptions(&$ThisFileInfo) { + /** + * @return string + */ + public function GuessEncoderOptions() { // shortcuts - if (!empty($ThisFileInfo['mpeg']['audio'])) { - $thisfile_mpeg_audio = &$ThisFileInfo['mpeg']['audio']; + $info = &$this->getid3->info; + $thisfile_mpeg_audio = array(); + $thisfile_mpeg_audio_lame = array(); + if (!empty($info['mpeg']['audio'])) { + $thisfile_mpeg_audio = &$info['mpeg']['audio']; if (!empty($thisfile_mpeg_audio['LAME'])) { $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME']; } @@ -171,7 +207,7 @@ class getid3_mp3 $encoder_options = 'VBR q'.$thisfile_mpeg_audio['VBR_quality']; - } elseif (!empty($thisfile_mpeg_audio_lame['preset_used']) && (!in_array($thisfile_mpeg_audio_lame['preset_used_id'], $NamedPresetBitrates))) { + } elseif (!empty($thisfile_mpeg_audio_lame['preset_used']) && isset($thisfile_mpeg_audio_lame['preset_used_id']) && (!in_array($thisfile_mpeg_audio_lame['preset_used_id'], $NamedPresetBitrates))) { $encoder_options = $thisfile_mpeg_audio_lame['preset_used']; @@ -242,7 +278,7 @@ class getid3_mp3 $encoder_options = $KnownEncoderValues['**'][$thisfile_mpeg_audio_lame['vbr_quality']][$thisfile_mpeg_audio_lame['raw']['vbr_method']][$thisfile_mpeg_audio_lame['raw']['noise_shaping']][$thisfile_mpeg_audio_lame['raw']['stereo_mode']][$thisfile_mpeg_audio_lame['ath_type']][$thisfile_mpeg_audio_lame['lowpass_frequency']]; - } elseif ($ThisFileInfo['audio']['bitrate_mode'] == 'vbr') { + } elseif ($info['audio']['bitrate_mode'] == 'vbr') { // http://gabriel.mp3-tech.org/mp3infotag.html // int Quality = (100 - 10 * gfp->VBR_q - gfp->quality)h @@ -252,13 +288,13 @@ class getid3_mp3 $LAME_q_value = 100 - $thisfile_mpeg_audio_lame['vbr_quality'] - ($LAME_V_value * 10); $encoder_options = '-V'.$LAME_V_value.' -q'.$LAME_q_value; - } elseif ($ThisFileInfo['audio']['bitrate_mode'] == 'cbr') { + } elseif ($info['audio']['bitrate_mode'] == 'cbr') { - $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']).ceil($ThisFileInfo['audio']['bitrate'] / 1000); + $encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000); } else { - $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']); + $encoder_options = strtoupper($info['audio']['bitrate_mode']); } @@ -266,12 +302,12 @@ class getid3_mp3 $encoder_options = 'ABR'.$thisfile_mpeg_audio_lame['bitrate_abr']; - } elseif (!empty($ThisFileInfo['audio']['bitrate'])) { + } elseif (!empty($info['audio']['bitrate'])) { - if ($ThisFileInfo['audio']['bitrate_mode'] == 'cbr') { - $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']).ceil($ThisFileInfo['audio']['bitrate'] / 1000); + if ($info['audio']['bitrate_mode'] == 'cbr') { + $encoder_options = strtoupper($info['audio']['bitrate_mode']).round($info['audio']['bitrate'] / 1000); } else { - $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']); + $encoder_options = strtoupper($info['audio']['bitrate_mode']); } } @@ -279,6 +315,10 @@ class getid3_mp3 $encoder_options .= ' -b'.$thisfile_mpeg_audio_lame['bitrate_min']; } + if (isset($thisfile_mpeg_audio['bitrate']) && $thisfile_mpeg_audio['bitrate'] === 'free') { + $encoder_options .= ' --freeformat'; + } + if (!empty($thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev']) || !empty($thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'])) { $encoder_options .= ' --nogap'; } @@ -389,17 +429,24 @@ class getid3_mp3 } } } - if (empty($encoder_options) && !empty($ThisFileInfo['audio']['bitrate']) && !empty($ThisFileInfo['audio']['bitrate_mode'])) { - //$encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']).ceil($ThisFileInfo['audio']['bitrate'] / 1000); - $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']); + if (empty($encoder_options) && !empty($info['audio']['bitrate']) && !empty($info['audio']['bitrate_mode'])) { + //$encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000); + $encoder_options = strtoupper($info['audio']['bitrate_mode']); } return $encoder_options; } - - static function decodeMPEGaudioHeader($fd, $offset, &$ThisFileInfo, $recursivesearch=true, $ScanAsCBR=false, $FastMPEGheaderScan=false) { - + /** + * @param int $offset + * @param array $info + * @param bool $recursivesearch + * @param bool $ScanAsCBR + * @param bool $FastMPEGheaderScan + * + * @return bool + */ + public function decodeMPEGaudioHeader($offset, &$info, $recursivesearch=true, $ScanAsCBR=false, $FastMPEGheaderScan=false) { static $MPEGaudioVersionLookup; static $MPEGaudioLayerLookup; static $MPEGaudioBitrateLookup; @@ -408,22 +455,21 @@ class getid3_mp3 static $MPEGaudioModeExtensionLookup; static $MPEGaudioEmphasisLookup; if (empty($MPEGaudioVersionLookup)) { - $MPEGaudioVersionLookup = getid3_mp3::MPEGaudioVersionArray(); - $MPEGaudioLayerLookup = getid3_mp3::MPEGaudioLayerArray(); - $MPEGaudioBitrateLookup = getid3_mp3::MPEGaudioBitrateArray(); - $MPEGaudioFrequencyLookup = getid3_mp3::MPEGaudioFrequencyArray(); - $MPEGaudioChannelModeLookup = getid3_mp3::MPEGaudioChannelModeArray(); - $MPEGaudioModeExtensionLookup = getid3_mp3::MPEGaudioModeExtensionArray(); - $MPEGaudioEmphasisLookup = getid3_mp3::MPEGaudioEmphasisArray(); + $MPEGaudioVersionLookup = self::MPEGaudioVersionArray(); + $MPEGaudioLayerLookup = self::MPEGaudioLayerArray(); + $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray(); + $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray(); + $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray(); + $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray(); + $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray(); } - if ($offset >= $ThisFileInfo['avdataend']) { - $ThisFileInfo['error'][] = 'end of file encounter looking for MPEG synch'; + if ($this->fseek($offset) != 0) { + $this->error('decodeMPEGaudioHeader() failed to seek to next offset at '.$offset); return false; } - fseek($fd, $offset, SEEK_SET); - //$headerstring = fread($fd, 1441); // worst-case max length = 32kHz @ 320kbps layer 3 = 1441 bytes/frame - $headerstring = fread($fd, 226); // LAME header at offset 36 + 190 bytes of Xing/LAME data + //$headerstring = $this->fread(1441); // worst-case max length = 32kHz @ 320kbps layer 3 = 1441 bytes/frame + $headerstring = $this->fread(226); // LAME header at offset 36 + 190 bytes of Xing/LAME data // MP3 audio frame structure: // $aa $aa $aa $aa [$bb $bb] $cc... @@ -432,39 +478,35 @@ class getid3_mp3 // and $cc... is the audio data $head4 = substr($headerstring, 0, 4); - + $head4_key = getid3_lib::PrintHexBytes($head4, true, false, false); static $MPEGaudioHeaderDecodeCache = array(); - if (isset($MPEGaudioHeaderDecodeCache[$head4])) { - $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4]; + if (isset($MPEGaudioHeaderDecodeCache[$head4_key])) { + $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4_key]; } else { - $MPEGheaderRawArray = getid3_mp3::MPEGaudioHeaderDecode($head4); - $MPEGaudioHeaderDecodeCache[$head4] = $MPEGheaderRawArray; + $MPEGheaderRawArray = self::MPEGaudioHeaderDecode($head4); + $MPEGaudioHeaderDecodeCache[$head4_key] = $MPEGheaderRawArray; } static $MPEGaudioHeaderValidCache = array(); - - // Not in cache - if (!isset($MPEGaudioHeaderValidCache[$head4])) { - //$MPEGaudioHeaderValidCache[$head4] = getid3_mp3::MPEGaudioHeaderValid($MPEGheaderRawArray, false, true); // allow badly-formatted freeformat (from LAME 3.90 - 3.93.1) - $MPEGaudioHeaderValidCache[$head4] = getid3_mp3::MPEGaudioHeaderValid($MPEGheaderRawArray, false, false); + if (!isset($MPEGaudioHeaderValidCache[$head4_key])) { // Not in cache + //$MPEGaudioHeaderValidCache[$head4_key] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, true); // allow badly-formatted freeformat (from LAME 3.90 - 3.93.1) + $MPEGaudioHeaderValidCache[$head4_key] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, false); } // shortcut - if (!isset($ThisFileInfo['mpeg']['audio'])) { - $ThisFileInfo['mpeg']['audio'] = array(); + if (!isset($info['mpeg']['audio'])) { + $info['mpeg']['audio'] = array(); } - $thisfile_mpeg_audio = &$ThisFileInfo['mpeg']['audio']; + $thisfile_mpeg_audio = &$info['mpeg']['audio']; - - if ($MPEGaudioHeaderValidCache[$head4]) { + if ($MPEGaudioHeaderValidCache[$head4_key]) { $thisfile_mpeg_audio['raw'] = $MPEGheaderRawArray; } else { - $ThisFileInfo['error'][] = 'Invalid MPEG audio header at offset '.$offset; + $this->warning('Invalid MPEG audio header ('.getid3_lib::PrintHexBytes($head4).') at offset '.$offset); return false; } if (!$FastMPEGheaderScan) { - $thisfile_mpeg_audio['version'] = $MPEGaudioVersionLookup[$thisfile_mpeg_audio['raw']['version']]; $thisfile_mpeg_audio['layer'] = $MPEGaudioLayerLookup[$thisfile_mpeg_audio['raw']['layer']]; @@ -478,24 +520,23 @@ class getid3_mp3 $thisfile_mpeg_audio['original'] = (bool) $thisfile_mpeg_audio['raw']['original']; $thisfile_mpeg_audio['emphasis'] = $MPEGaudioEmphasisLookup[$thisfile_mpeg_audio['raw']['emphasis']]; - $ThisFileInfo['audio']['channels'] = $thisfile_mpeg_audio['channels']; - $ThisFileInfo['audio']['sample_rate'] = $thisfile_mpeg_audio['sample_rate']; + $info['audio']['channels'] = $thisfile_mpeg_audio['channels']; + $info['audio']['sample_rate'] = $thisfile_mpeg_audio['sample_rate']; if ($thisfile_mpeg_audio['protection']) { $thisfile_mpeg_audio['crc'] = getid3_lib::BigEndian2Int(substr($headerstring, 4, 2)); } - } if ($thisfile_mpeg_audio['raw']['bitrate'] == 15) { // http://www.hydrogenaudio.org/?act=ST&f=16&t=9682&st=0 - $ThisFileInfo['warning'][] = 'Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1'; + $this->warning('Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1'); $thisfile_mpeg_audio['raw']['bitrate'] = 0; } $thisfile_mpeg_audio['padding'] = (bool) $thisfile_mpeg_audio['raw']['padding']; $thisfile_mpeg_audio['bitrate'] = $MPEGaudioBitrateLookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['bitrate']]; - if (($thisfile_mpeg_audio['bitrate'] == 'free') && ($offset == $ThisFileInfo['avdataoffset'])) { + if (($thisfile_mpeg_audio['bitrate'] == 'free') && ($offset == $info['avdataoffset'])) { // only skip multiple frame check if free-format bitstream found at beginning of file // otherwise is quite possibly simply corrupted data $recursivesearch = false; @@ -504,14 +545,14 @@ class getid3_mp3 // For Layer 2 there are some combinations of bitrate and mode which are not allowed. if (!$FastMPEGheaderScan && ($thisfile_mpeg_audio['layer'] == '2')) { - $ThisFileInfo['audio']['dataformat'] = 'mp2'; + $info['audio']['dataformat'] = 'mp2'; switch ($thisfile_mpeg_audio['channelmode']) { case 'mono': if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] <= 192000)) { // these are ok } else { - $ThisFileInfo['error'][] = $thisfile_mpeg_audio['bitrate'].'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.'; + $this->error($thisfile_mpeg_audio['bitrate'].'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.'); return false; } break; @@ -522,7 +563,7 @@ class getid3_mp3 if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] == 64000) || ($thisfile_mpeg_audio['bitrate'] >= 96000)) { // these are ok } else { - $ThisFileInfo['error'][] = intval(round($thisfile_mpeg_audio['bitrate'] / 1000)).'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.'; + $this->error(intval(round($thisfile_mpeg_audio['bitrate'] / 1000)).'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.'); return false; } break; @@ -532,19 +573,19 @@ class getid3_mp3 } - if ($ThisFileInfo['audio']['sample_rate'] > 0) { - $thisfile_mpeg_audio['framelength'] = getid3_mp3::MPEGaudioFrameLength($thisfile_mpeg_audio['bitrate'], $thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['layer'], (int) $thisfile_mpeg_audio['padding'], $ThisFileInfo['audio']['sample_rate']); + if ($info['audio']['sample_rate'] > 0) { + $thisfile_mpeg_audio['framelength'] = self::MPEGaudioFrameLength($thisfile_mpeg_audio['bitrate'], $thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['layer'], (int) $thisfile_mpeg_audio['padding'], $info['audio']['sample_rate']); } $nextframetestoffset = $offset + 1; if ($thisfile_mpeg_audio['bitrate'] != 'free') { - $ThisFileInfo['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate']; + $info['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate']; if (isset($thisfile_mpeg_audio['framelength'])) { $nextframetestoffset = $offset + $thisfile_mpeg_audio['framelength']; } else { - $ThisFileInfo['error'][] = 'Frame at offset('.$offset.') is has an invalid frame length.'; + $this->error('Frame at offset('.$offset.') is has an invalid frame length.'); return false; } @@ -561,7 +602,7 @@ class getid3_mp3 $thisfile_mpeg_audio['bitrate_mode'] = 'vbr'; $thisfile_mpeg_audio['VBR_method'] = 'Fraunhofer'; - $ThisFileInfo['audio']['codec'] = 'Fraunhofer'; + $info['audio']['codec'] = 'Fraunhofer'; $SideInfoData = substr($headerstring, 4 + 2, 32); @@ -594,7 +635,7 @@ class getid3_mp3 // Xing VBR header is hardcoded 'Xing' at a offset 0x0D (13), 0x15 (21) or 0x24 (36) // depending on MPEG layer and number of channels - $VBRidOffset = getid3_mp3::XingVBRidOffset($thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['channelmode']); + $VBRidOffset = self::XingVBRidOffset($thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['channelmode']); $SideInfoData = substr($headerstring, 4 + 2, $VBRidOffset - 4); if ((substr($headerstring, $VBRidOffset, strlen('Xing')) == 'Xing') || (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Info')) { @@ -647,18 +688,29 @@ class getid3_mp3 } //if (($thisfile_mpeg_audio['bitrate'] == 'free') && !empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) { - if (!empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) { + //if (!empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) { + if (!empty($thisfile_mpeg_audio['VBR_frames'])) { + $used_filesize = 0; + if (!empty($thisfile_mpeg_audio['VBR_bytes'])) { + $used_filesize = $thisfile_mpeg_audio['VBR_bytes']; + } elseif (!empty($info['filesize'])) { + $used_filesize = $info['filesize']; + $used_filesize -= (isset($info['id3v2']['headerlength']) ? intval($info['id3v2']['headerlength']) : 0); + $used_filesize -= (isset($info['id3v1']) ? 128 : 0); + $used_filesize -= (isset($info['tag_offset_end']) ? $info['tag_offset_end'] - $info['tag_offset_start'] : 0); + $this->warning('MP3.Xing header missing VBR_bytes, assuming MPEG audio portion of file is '.number_format($used_filesize).' bytes'); + } - $framelengthfloat = $thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames']; + $framelengthfloat = $used_filesize / $thisfile_mpeg_audio['VBR_frames']; if ($thisfile_mpeg_audio['layer'] == '1') { // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12 - //$ThisFileInfo['audio']['bitrate'] = ((($framelengthfloat / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12; - $ThisFileInfo['audio']['bitrate'] = ($framelengthfloat / 4) * $thisfile_mpeg_audio['sample_rate'] * (2 / $ThisFileInfo['audio']['channels']) / 12; + //$info['audio']['bitrate'] = ((($framelengthfloat / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12; + $info['audio']['bitrate'] = ($framelengthfloat / 4) * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 12; } else { // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144 - //$ThisFileInfo['audio']['bitrate'] = (($framelengthfloat - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144; - $ThisFileInfo['audio']['bitrate'] = $framelengthfloat * $thisfile_mpeg_audio['sample_rate'] * (2 / $ThisFileInfo['audio']['channels']) / 144; + //$info['audio']['bitrate'] = (($framelengthfloat - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144; + $info['audio']['bitrate'] = $framelengthfloat * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 144; } $thisfile_mpeg_audio['framelength'] = floor($framelengthfloat); } @@ -666,7 +718,7 @@ class getid3_mp3 if ($thisfile_mpeg_audio['xing_flags']['toc']) { $LAMEtocData = substr($headerstring, $VBRidOffset + 16, 100); for ($i = 0; $i < 100; $i++) { - $thisfile_mpeg_audio['toc'][$i] = ord($LAMEtocData{$i}); + $thisfile_mpeg_audio['toc'][$i] = ord($LAMEtocData[$i]); } } if ($thisfile_mpeg_audio['xing_flags']['vbr_scale']) { @@ -685,187 +737,200 @@ class getid3_mp3 $thisfile_mpeg_audio_lame['long_version'] = substr($headerstring, $VBRidOffset + 120, 20); $thisfile_mpeg_audio_lame['short_version'] = substr($thisfile_mpeg_audio_lame['long_version'], 0, 9); - if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.90') { - - // extra 11 chars are not part of version string when LAMEtag present - unset($thisfile_mpeg_audio_lame['long_version']); - - // It the LAME tag was only introduced in LAME v3.90 - // http://www.hydrogenaudio.org/?act=ST&f=15&t=9933 - - // Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html - // are assuming a 'Xing' identifier offset of 0x24, which is the case for - // MPEG-1 non-mono, but not for other combinations - $LAMEtagOffsetContant = $VBRidOffset - 0x24; - - // shortcuts - $thisfile_mpeg_audio_lame['RGAD'] = array('track'=>array(), 'album'=>array()); - $thisfile_mpeg_audio_lame_RGAD = &$thisfile_mpeg_audio_lame['RGAD']; - $thisfile_mpeg_audio_lame_RGAD_track = &$thisfile_mpeg_audio_lame_RGAD['track']; - $thisfile_mpeg_audio_lame_RGAD_album = &$thisfile_mpeg_audio_lame_RGAD['album']; - $thisfile_mpeg_audio_lame['raw'] = array(); - $thisfile_mpeg_audio_lame_raw = &$thisfile_mpeg_audio_lame['raw']; - - // byte $9B VBR Quality - // This field is there to indicate a quality level, although the scale was not precised in the original Xing specifications. - // Actually overwrites original Xing bytes - unset($thisfile_mpeg_audio['VBR_scale']); - $thisfile_mpeg_audio_lame['vbr_quality'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0x9B, 1)); - - // bytes $9C-$A4 Encoder short VersionString - $thisfile_mpeg_audio_lame['short_version'] = substr($headerstring, $LAMEtagOffsetContant + 0x9C, 9); - - // byte $A5 Info Tag revision + VBR method - $LAMEtagRevisionVBRmethod = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA5, 1)); - - $thisfile_mpeg_audio_lame['tag_revision'] = ($LAMEtagRevisionVBRmethod & 0xF0) >> 4; - $thisfile_mpeg_audio_lame_raw['vbr_method'] = $LAMEtagRevisionVBRmethod & 0x0F; - $thisfile_mpeg_audio_lame['vbr_method'] = getid3_mp3::LAMEvbrMethodLookup($thisfile_mpeg_audio_lame_raw['vbr_method']); - $thisfile_mpeg_audio['bitrate_mode'] = substr($thisfile_mpeg_audio_lame['vbr_method'], 0, 3); // usually either 'cbr' or 'vbr', but truncates 'vbr-old / vbr-rh' to 'vbr' - - // byte $A6 Lowpass filter value - $thisfile_mpeg_audio_lame['lowpass_frequency'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100; - - // bytes $A7-$AE Replay Gain - // http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html - // bytes $A7-$AA : 32 bit floating point "Peak signal amplitude" - if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.94b') { - // LAME 3.94a16 and later - 9.23 fixed point - // ie 0x0059E2EE / (2^23) = 5890798 / 8388608 = 0.7022378444671630859375 - $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = (float) ((getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4))) / 8388608); - } else { - // LAME 3.94a15 and earlier - 32-bit floating point - // Actually 3.94a16 will fall in here too and be WRONG, but is hard to detect 3.94a16 vs 3.94a15 - $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = getid3_lib::LittleEndian2Float(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4)); - } - if ($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] == 0) { - unset($thisfile_mpeg_audio_lame_RGAD['peak_amplitude']); - } else { - $thisfile_mpeg_audio_lame_RGAD['peak_db'] = getid3_lib::RGADamplitude2dB($thisfile_mpeg_audio_lame_RGAD['peak_amplitude']); + //$thisfile_mpeg_audio_lame['numeric_version'] = str_replace('LAME', '', $thisfile_mpeg_audio_lame['short_version']); + $thisfile_mpeg_audio_lame['numeric_version'] = ''; + if (preg_match('#^LAME([0-9\\.a-z]*)#', $thisfile_mpeg_audio_lame['long_version'], $matches)) { + $thisfile_mpeg_audio_lame['short_version'] = $matches[0]; + $thisfile_mpeg_audio_lame['numeric_version'] = $matches[1]; + } + if (strlen($thisfile_mpeg_audio_lame['numeric_version']) > 0) { + foreach (explode('.', $thisfile_mpeg_audio_lame['numeric_version']) as $key => $number) { + $thisfile_mpeg_audio_lame['integer_version'][$key] = intval($number); } + //if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.90') { + if ((($thisfile_mpeg_audio_lame['integer_version'][0] * 1000) + $thisfile_mpeg_audio_lame['integer_version'][1]) >= 3090) { // cannot use string version compare, may have "LAME3.90" or "LAME3.100" -- see https://github.com/JamesHeinrich/getID3/issues/207 - $thisfile_mpeg_audio_lame_raw['RGAD_track'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAB, 2)); - $thisfile_mpeg_audio_lame_raw['RGAD_album'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAD, 2)); + // extra 11 chars are not part of version string when LAMEtag present + unset($thisfile_mpeg_audio_lame['long_version']); + // It the LAME tag was only introduced in LAME v3.90 + // https://wiki.hydrogenaud.io/index.php/LAME#VBR_header_and_LAME_tag + // https://hydrogenaud.io/index.php?topic=9933 - if ($thisfile_mpeg_audio_lame_raw['RGAD_track'] != 0) { + // Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html + // are assuming a 'Xing' identifier offset of 0x24, which is the case for + // MPEG-1 non-mono, but not for other combinations + $LAMEtagOffsetContant = $VBRidOffset - 0x24; - $thisfile_mpeg_audio_lame_RGAD_track['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0xE000) >> 13; - $thisfile_mpeg_audio_lame_RGAD_track['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x1C00) >> 10; - $thisfile_mpeg_audio_lame_RGAD_track['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x0200) >> 9; - $thisfile_mpeg_audio_lame_RGAD_track['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x01FF; - $thisfile_mpeg_audio_lame_RGAD_track['name'] = getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['name']); - $thisfile_mpeg_audio_lame_RGAD_track['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['originator']); - $thisfile_mpeg_audio_lame_RGAD_track['gain_db'] = getid3_lib::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_RGAD_track['raw']['sign_bit']); + // shortcuts + $thisfile_mpeg_audio_lame['RGAD'] = array('track'=>array(), 'album'=>array()); + $thisfile_mpeg_audio_lame_RGAD = &$thisfile_mpeg_audio_lame['RGAD']; + $thisfile_mpeg_audio_lame_RGAD_track = &$thisfile_mpeg_audio_lame_RGAD['track']; + $thisfile_mpeg_audio_lame_RGAD_album = &$thisfile_mpeg_audio_lame_RGAD['album']; + $thisfile_mpeg_audio_lame['raw'] = array(); + $thisfile_mpeg_audio_lame_raw = &$thisfile_mpeg_audio_lame['raw']; - if (!empty($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'])) { - $ThisFileInfo['replay_gain']['track']['peak'] = $thisfile_mpeg_audio_lame_RGAD['peak_amplitude']; + // byte $9B VBR Quality + // This field is there to indicate a quality level, although the scale was not precised in the original Xing specifications. + // Actually overwrites original Xing bytes + unset($thisfile_mpeg_audio['VBR_scale']); + $thisfile_mpeg_audio_lame['vbr_quality'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0x9B, 1)); + + // bytes $9C-$A4 Encoder short VersionString + $thisfile_mpeg_audio_lame['short_version'] = substr($headerstring, $LAMEtagOffsetContant + 0x9C, 9); + + // byte $A5 Info Tag revision + VBR method + $LAMEtagRevisionVBRmethod = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA5, 1)); + + $thisfile_mpeg_audio_lame['tag_revision'] = ($LAMEtagRevisionVBRmethod & 0xF0) >> 4; + $thisfile_mpeg_audio_lame_raw['vbr_method'] = $LAMEtagRevisionVBRmethod & 0x0F; + $thisfile_mpeg_audio_lame['vbr_method'] = self::LAMEvbrMethodLookup($thisfile_mpeg_audio_lame_raw['vbr_method']); + $thisfile_mpeg_audio['bitrate_mode'] = substr($thisfile_mpeg_audio_lame['vbr_method'], 0, 3); // usually either 'cbr' or 'vbr', but truncates 'vbr-old / vbr-rh' to 'vbr' + + // byte $A6 Lowpass filter value + $thisfile_mpeg_audio_lame['lowpass_frequency'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100; + + // bytes $A7-$AE Replay Gain + // https://web.archive.org/web/20021015212753/http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html + // bytes $A7-$AA : 32 bit floating point "Peak signal amplitude" + if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.94b') { + // LAME 3.94a16 and later - 9.23 fixed point + // ie 0x0059E2EE / (2^23) = 5890798 / 8388608 = 0.7022378444671630859375 + $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = (float) ((getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4))) / 8388608); + } else { + // LAME 3.94a15 and earlier - 32-bit floating point + // Actually 3.94a16 will fall in here too and be WRONG, but is hard to detect 3.94a16 vs 3.94a15 + $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = getid3_lib::LittleEndian2Float(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4)); } - $ThisFileInfo['replay_gain']['track']['originator'] = $thisfile_mpeg_audio_lame_RGAD_track['originator']; - $ThisFileInfo['replay_gain']['track']['adjustment'] = $thisfile_mpeg_audio_lame_RGAD_track['gain_db']; - } else { - unset($thisfile_mpeg_audio_lame_RGAD['track']); - } - if ($thisfile_mpeg_audio_lame_raw['RGAD_album'] != 0) { - - $thisfile_mpeg_audio_lame_RGAD_album['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0xE000) >> 13; - $thisfile_mpeg_audio_lame_RGAD_album['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x1C00) >> 10; - $thisfile_mpeg_audio_lame_RGAD_album['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x0200) >> 9; - $thisfile_mpeg_audio_lame_RGAD_album['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x01FF; - $thisfile_mpeg_audio_lame_RGAD_album['name'] = getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['name']); - $thisfile_mpeg_audio_lame_RGAD_album['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['originator']); - $thisfile_mpeg_audio_lame_RGAD_album['gain_db'] = getid3_lib::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_RGAD_album['raw']['sign_bit']); - - if (!empty($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'])) { - $ThisFileInfo['replay_gain']['album']['peak'] = $thisfile_mpeg_audio_lame_RGAD['peak_amplitude']; + if ($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] == 0) { + unset($thisfile_mpeg_audio_lame_RGAD['peak_amplitude']); + } else { + $thisfile_mpeg_audio_lame_RGAD['peak_db'] = getid3_lib::RGADamplitude2dB($thisfile_mpeg_audio_lame_RGAD['peak_amplitude']); } - $ThisFileInfo['replay_gain']['album']['originator'] = $thisfile_mpeg_audio_lame_RGAD_album['originator']; - $ThisFileInfo['replay_gain']['album']['adjustment'] = $thisfile_mpeg_audio_lame_RGAD_album['gain_db']; - } else { - unset($thisfile_mpeg_audio_lame_RGAD['album']); - } - if (empty($thisfile_mpeg_audio_lame_RGAD)) { - unset($thisfile_mpeg_audio_lame['RGAD']); - } + + $thisfile_mpeg_audio_lame_raw['RGAD_track'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAB, 2)); + $thisfile_mpeg_audio_lame_raw['RGAD_album'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAD, 2)); - // byte $AF Encoding flags + ATH Type - $EncodingFlagsATHtype = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAF, 1)); - $thisfile_mpeg_audio_lame['encoding_flags']['nspsytune'] = (bool) ($EncodingFlagsATHtype & 0x10); - $thisfile_mpeg_audio_lame['encoding_flags']['nssafejoint'] = (bool) ($EncodingFlagsATHtype & 0x20); - $thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'] = (bool) ($EncodingFlagsATHtype & 0x40); - $thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev'] = (bool) ($EncodingFlagsATHtype & 0x80); - $thisfile_mpeg_audio_lame['ath_type'] = $EncodingFlagsATHtype & 0x0F; + if ($thisfile_mpeg_audio_lame_raw['RGAD_track'] != 0) { - // byte $B0 if ABR {specified bitrate} else {minimal bitrate} - $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB0, 1)); - if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 2) { // Average BitRate (ABR) - $thisfile_mpeg_audio_lame['bitrate_abr'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']; - } elseif ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) { // Constant BitRate (CBR) - // ignore - } elseif ($thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] > 0) { // Variable BitRate (VBR) - minimum bitrate - $thisfile_mpeg_audio_lame['bitrate_min'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']; - } + $thisfile_mpeg_audio_lame_RGAD_track['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0xE000) >> 13; + $thisfile_mpeg_audio_lame_RGAD_track['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x1C00) >> 10; + $thisfile_mpeg_audio_lame_RGAD_track['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x0200) >> 9; + $thisfile_mpeg_audio_lame_RGAD_track['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x01FF; + $thisfile_mpeg_audio_lame_RGAD_track['name'] = getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['name']); + $thisfile_mpeg_audio_lame_RGAD_track['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['originator']); + $thisfile_mpeg_audio_lame_RGAD_track['gain_db'] = getid3_lib::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_track['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_RGAD_track['raw']['sign_bit']); - // bytes $B1-$B3 Encoder delays - $EncoderDelays = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB1, 3)); - $thisfile_mpeg_audio_lame['encoder_delay'] = ($EncoderDelays & 0xFFF000) >> 12; - $thisfile_mpeg_audio_lame['end_padding'] = $EncoderDelays & 0x000FFF; + if (!empty($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'])) { + $info['replay_gain']['track']['peak'] = $thisfile_mpeg_audio_lame_RGAD['peak_amplitude']; + } + $info['replay_gain']['track']['originator'] = $thisfile_mpeg_audio_lame_RGAD_track['originator']; + $info['replay_gain']['track']['adjustment'] = $thisfile_mpeg_audio_lame_RGAD_track['gain_db']; + } else { + unset($thisfile_mpeg_audio_lame_RGAD['track']); + } + if ($thisfile_mpeg_audio_lame_raw['RGAD_album'] != 0) { - // byte $B4 Misc - $MiscByte = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB4, 1)); - $thisfile_mpeg_audio_lame_raw['noise_shaping'] = ($MiscByte & 0x03); - $thisfile_mpeg_audio_lame_raw['stereo_mode'] = ($MiscByte & 0x1C) >> 2; - $thisfile_mpeg_audio_lame_raw['not_optimal_quality'] = ($MiscByte & 0x20) >> 5; - $thisfile_mpeg_audio_lame_raw['source_sample_freq'] = ($MiscByte & 0xC0) >> 6; - $thisfile_mpeg_audio_lame['noise_shaping'] = $thisfile_mpeg_audio_lame_raw['noise_shaping']; - $thisfile_mpeg_audio_lame['stereo_mode'] = getid3_mp3::LAMEmiscStereoModeLookup($thisfile_mpeg_audio_lame_raw['stereo_mode']); - $thisfile_mpeg_audio_lame['not_optimal_quality'] = (bool) $thisfile_mpeg_audio_lame_raw['not_optimal_quality']; - $thisfile_mpeg_audio_lame['source_sample_freq'] = getid3_mp3::LAMEmiscSourceSampleFrequencyLookup($thisfile_mpeg_audio_lame_raw['source_sample_freq']); + $thisfile_mpeg_audio_lame_RGAD_album['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0xE000) >> 13; + $thisfile_mpeg_audio_lame_RGAD_album['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x1C00) >> 10; + $thisfile_mpeg_audio_lame_RGAD_album['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x0200) >> 9; + $thisfile_mpeg_audio_lame_RGAD_album['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x01FF; + $thisfile_mpeg_audio_lame_RGAD_album['name'] = getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['name']); + $thisfile_mpeg_audio_lame_RGAD_album['originator'] = getid3_lib::RGADoriginatorLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['originator']); + $thisfile_mpeg_audio_lame_RGAD_album['gain_db'] = getid3_lib::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_album['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_RGAD_album['raw']['sign_bit']); - // byte $B5 MP3 Gain - $thisfile_mpeg_audio_lame_raw['mp3_gain'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB5, 1), false, true); - $thisfile_mpeg_audio_lame['mp3_gain_db'] = (getid3_lib::RGADamplitude2dB(2) / 4) * $thisfile_mpeg_audio_lame_raw['mp3_gain']; - $thisfile_mpeg_audio_lame['mp3_gain_factor'] = pow(2, ($thisfile_mpeg_audio_lame['mp3_gain_db'] / 6)); - - // bytes $B6-$B7 Preset and surround info - $PresetSurroundBytes = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB6, 2)); - // Reserved = ($PresetSurroundBytes & 0xC000); - $thisfile_mpeg_audio_lame_raw['surround_info'] = ($PresetSurroundBytes & 0x3800); - $thisfile_mpeg_audio_lame['surround_info'] = getid3_mp3::LAMEsurroundInfoLookup($thisfile_mpeg_audio_lame_raw['surround_info']); - $thisfile_mpeg_audio_lame['preset_used_id'] = ($PresetSurroundBytes & 0x07FF); - $thisfile_mpeg_audio_lame['preset_used'] = getid3_mp3::LAMEpresetUsedLookup($thisfile_mpeg_audio_lame); - if (!empty($thisfile_mpeg_audio_lame['preset_used_id']) && empty($thisfile_mpeg_audio_lame['preset_used'])) { - $ThisFileInfo['warning'][] = 'Unknown LAME preset used ('.$thisfile_mpeg_audio_lame['preset_used_id'].') - please report to info@getid3.org'; - } - if (($thisfile_mpeg_audio_lame['short_version'] == 'LAME3.90.') && !empty($thisfile_mpeg_audio_lame['preset_used_id'])) { - // this may change if 3.90.4 ever comes out - $thisfile_mpeg_audio_lame['short_version'] = 'LAME3.90.3'; - } - - // bytes $B8-$BB MusicLength - $thisfile_mpeg_audio_lame['audio_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB8, 4)); - $ExpectedNumberOfAudioBytes = (($thisfile_mpeg_audio_lame['audio_bytes'] > 0) ? $thisfile_mpeg_audio_lame['audio_bytes'] : $thisfile_mpeg_audio['VBR_bytes']); - - // bytes $BC-$BD MusicCRC - $thisfile_mpeg_audio_lame['music_crc'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBC, 2)); - - // bytes $BE-$BF CRC-16 of Info Tag - $thisfile_mpeg_audio_lame['lame_tag_crc'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBE, 2)); + if (!empty($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'])) { + $info['replay_gain']['album']['peak'] = $thisfile_mpeg_audio_lame_RGAD['peak_amplitude']; + } + $info['replay_gain']['album']['originator'] = $thisfile_mpeg_audio_lame_RGAD_album['originator']; + $info['replay_gain']['album']['adjustment'] = $thisfile_mpeg_audio_lame_RGAD_album['gain_db']; + } else { + unset($thisfile_mpeg_audio_lame_RGAD['album']); + } + if (empty($thisfile_mpeg_audio_lame_RGAD)) { + unset($thisfile_mpeg_audio_lame['RGAD']); + } - // LAME CBR - if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) { + // byte $AF Encoding flags + ATH Type + $EncodingFlagsATHtype = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAF, 1)); + $thisfile_mpeg_audio_lame['encoding_flags']['nspsytune'] = (bool) ($EncodingFlagsATHtype & 0x10); + $thisfile_mpeg_audio_lame['encoding_flags']['nssafejoint'] = (bool) ($EncodingFlagsATHtype & 0x20); + $thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'] = (bool) ($EncodingFlagsATHtype & 0x40); + $thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev'] = (bool) ($EncodingFlagsATHtype & 0x80); + $thisfile_mpeg_audio_lame['ath_type'] = $EncodingFlagsATHtype & 0x0F; - $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; - $thisfile_mpeg_audio['bitrate'] = getid3_mp3::ClosestStandardMP3Bitrate($thisfile_mpeg_audio['bitrate']); - $ThisFileInfo['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate']; - //if (empty($thisfile_mpeg_audio['bitrate']) || (!empty($thisfile_mpeg_audio_lame['bitrate_min']) && ($thisfile_mpeg_audio_lame['bitrate_min'] != 255))) { - // $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio_lame['bitrate_min']; - //} + // byte $B0 if ABR {specified bitrate} else {minimal bitrate} + $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB0, 1)); + if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 2) { // Average BitRate (ABR) + $thisfile_mpeg_audio_lame['bitrate_abr'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']; + } elseif ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) { // Constant BitRate (CBR) + // ignore + } elseif ($thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] > 0) { // Variable BitRate (VBR) - minimum bitrate + $thisfile_mpeg_audio_lame['bitrate_min'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate']; + } + + // bytes $B1-$B3 Encoder delays + $EncoderDelays = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB1, 3)); + $thisfile_mpeg_audio_lame['encoder_delay'] = ($EncoderDelays & 0xFFF000) >> 12; + $thisfile_mpeg_audio_lame['end_padding'] = $EncoderDelays & 0x000FFF; + + // byte $B4 Misc + $MiscByte = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB4, 1)); + $thisfile_mpeg_audio_lame_raw['noise_shaping'] = ($MiscByte & 0x03); + $thisfile_mpeg_audio_lame_raw['stereo_mode'] = ($MiscByte & 0x1C) >> 2; + $thisfile_mpeg_audio_lame_raw['not_optimal_quality'] = ($MiscByte & 0x20) >> 5; + $thisfile_mpeg_audio_lame_raw['source_sample_freq'] = ($MiscByte & 0xC0) >> 6; + $thisfile_mpeg_audio_lame['noise_shaping'] = $thisfile_mpeg_audio_lame_raw['noise_shaping']; + $thisfile_mpeg_audio_lame['stereo_mode'] = self::LAMEmiscStereoModeLookup($thisfile_mpeg_audio_lame_raw['stereo_mode']); + $thisfile_mpeg_audio_lame['not_optimal_quality'] = (bool) $thisfile_mpeg_audio_lame_raw['not_optimal_quality']; + $thisfile_mpeg_audio_lame['source_sample_freq'] = self::LAMEmiscSourceSampleFrequencyLookup($thisfile_mpeg_audio_lame_raw['source_sample_freq']); + + // byte $B5 MP3 Gain + $thisfile_mpeg_audio_lame_raw['mp3_gain'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB5, 1), false, true); + $thisfile_mpeg_audio_lame['mp3_gain_db'] = (getid3_lib::RGADamplitude2dB(2) / 4) * $thisfile_mpeg_audio_lame_raw['mp3_gain']; + $thisfile_mpeg_audio_lame['mp3_gain_factor'] = pow(2, ($thisfile_mpeg_audio_lame['mp3_gain_db'] / 6)); + + // bytes $B6-$B7 Preset and surround info + $PresetSurroundBytes = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB6, 2)); + // Reserved = ($PresetSurroundBytes & 0xC000); + $thisfile_mpeg_audio_lame_raw['surround_info'] = ($PresetSurroundBytes & 0x3800); + $thisfile_mpeg_audio_lame['surround_info'] = self::LAMEsurroundInfoLookup($thisfile_mpeg_audio_lame_raw['surround_info']); + $thisfile_mpeg_audio_lame['preset_used_id'] = ($PresetSurroundBytes & 0x07FF); + $thisfile_mpeg_audio_lame['preset_used'] = self::LAMEpresetUsedLookup($thisfile_mpeg_audio_lame); + if (!empty($thisfile_mpeg_audio_lame['preset_used_id']) && empty($thisfile_mpeg_audio_lame['preset_used'])) { + $this->warning('Unknown LAME preset used ('.$thisfile_mpeg_audio_lame['preset_used_id'].') - please report to info@getid3.org'); + } + if (($thisfile_mpeg_audio_lame['short_version'] == 'LAME3.90.') && !empty($thisfile_mpeg_audio_lame['preset_used_id'])) { + // this may change if 3.90.4 ever comes out + $thisfile_mpeg_audio_lame['short_version'] = 'LAME3.90.3'; + } + + // bytes $B8-$BB MusicLength + $thisfile_mpeg_audio_lame['audio_bytes'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB8, 4)); + $ExpectedNumberOfAudioBytes = (($thisfile_mpeg_audio_lame['audio_bytes'] > 0) ? $thisfile_mpeg_audio_lame['audio_bytes'] : $thisfile_mpeg_audio['VBR_bytes']); + + // bytes $BC-$BD MusicCRC + $thisfile_mpeg_audio_lame['music_crc'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBC, 2)); + + // bytes $BE-$BF CRC-16 of Info Tag + $thisfile_mpeg_audio_lame['lame_tag_crc'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBE, 2)); + + + // LAME CBR + if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1 && $thisfile_mpeg_audio['bitrate'] !== 'free') { + + $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; + $thisfile_mpeg_audio['bitrate'] = self::ClosestStandardMP3Bitrate($thisfile_mpeg_audio['bitrate']); + $info['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate']; + //if (empty($thisfile_mpeg_audio['bitrate']) || (!empty($thisfile_mpeg_audio_lame['bitrate_min']) && ($thisfile_mpeg_audio_lame['bitrate_min'] != 255))) { + // $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio_lame['bitrate_min']; + //} + + } } - } } @@ -875,12 +940,12 @@ class getid3_mp3 $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; if ($recursivesearch) { $thisfile_mpeg_audio['bitrate_mode'] = 'vbr'; - if (getid3_mp3::RecursiveFrameScanning($fd, $ThisFileInfo, $offset, $nextframetestoffset, true)) { + if ($this->RecursiveFrameScanning($offset, $nextframetestoffset, true)) { $recursivesearch = false; $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; } if ($thisfile_mpeg_audio['bitrate_mode'] == 'vbr') { - $ThisFileInfo['warning'][] = 'VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.'; + $this->warning('VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.'); } } @@ -888,47 +953,49 @@ class getid3_mp3 } - if (($ExpectedNumberOfAudioBytes > 0) && ($ExpectedNumberOfAudioBytes != ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']))) { - if ($ExpectedNumberOfAudioBytes > ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'])) { - if (isset($ThisFileInfo['fileformat']) && ($ThisFileInfo['fileformat'] == 'riff')) { + if (($ExpectedNumberOfAudioBytes > 0) && ($ExpectedNumberOfAudioBytes != ($info['avdataend'] - $info['avdataoffset']))) { + if ($ExpectedNumberOfAudioBytes > ($info['avdataend'] - $info['avdataoffset'])) { + if ($this->isDependencyFor('matroska') || $this->isDependencyFor('riff')) { // ignore, audio data is broken into chunks so will always be data "missing" - } elseif (($ExpectedNumberOfAudioBytes - ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'])) == 1) { - $ThisFileInfo['warning'][] = 'Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)'; - } else { - $ThisFileInfo['warning'][] = 'Probable truncated file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, only found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' (short by '.($ExpectedNumberOfAudioBytes - ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'])).' bytes)'; + } + elseif (($ExpectedNumberOfAudioBytes - ($info['avdataend'] - $info['avdataoffset'])) == 1) { + $this->warning('Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)'); + } + else { + $this->warning('Probable truncated file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' (short by '.($ExpectedNumberOfAudioBytes - ($info['avdataend'] - $info['avdataoffset'])).' bytes)'); } } else { - if ((($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) - $ExpectedNumberOfAudioBytes) == 1) { - // $prenullbytefileoffset = ftell($fd); - // fseek($fd, $ThisFileInfo['avdataend'], SEEK_SET); - // $PossibleNullByte = fread($fd, 1); - // fseek($fd, $prenullbytefileoffset, SEEK_SET); + if ((($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes) == 1) { + // $prenullbytefileoffset = $this->ftell(); + // $this->fseek($info['avdataend']); + // $PossibleNullByte = $this->fread(1); + // $this->fseek($prenullbytefileoffset); // if ($PossibleNullByte === "\x00") { - $ThisFileInfo['avdataend']--; - // $ThisFileInfo['warning'][] = 'Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored'; + $info['avdataend']--; + // $this->warning('Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored'); // } else { - // $ThisFileInfo['warning'][] = 'Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' ('.(($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)'; + // $this->warning('Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)'); // } } else { - $ThisFileInfo['warning'][] = 'Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']).' ('.(($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)'; + $this->warning('Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)'); } } } - if (($thisfile_mpeg_audio['bitrate'] == 'free') && empty($ThisFileInfo['audio']['bitrate'])) { - if (($offset == $ThisFileInfo['avdataoffset']) && empty($thisfile_mpeg_audio['VBR_frames'])) { - $framebytelength = getid3_mp3::FreeFormatFrameLength($fd, $offset, $ThisFileInfo, true); + if (($thisfile_mpeg_audio['bitrate'] == 'free') && empty($info['audio']['bitrate'])) { + if (($offset == $info['avdataoffset']) && empty($thisfile_mpeg_audio['VBR_frames'])) { + $framebytelength = $this->FreeFormatFrameLength($offset, true); if ($framebytelength > 0) { $thisfile_mpeg_audio['framelength'] = $framebytelength; if ($thisfile_mpeg_audio['layer'] == '1') { // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12 - $ThisFileInfo['audio']['bitrate'] = ((($framebytelength / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12; + $info['audio']['bitrate'] = ((($framebytelength / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12; } else { // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144 - $ThisFileInfo['audio']['bitrate'] = (($framebytelength - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144; + $info['audio']['bitrate'] = (($framebytelength - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144; } } else { - $ThisFileInfo['error'][] = 'Error calculating frame length of free-format MP3 without Xing/LAME header'; + $this->error('Error calculating frame length of free-format MP3 without Xing/LAME header'); } } } @@ -943,9 +1010,9 @@ class getid3_mp3 } elseif ((($thisfile_mpeg_audio['version'] == '2') || ($thisfile_mpeg_audio['version'] == '2.5')) && ($thisfile_mpeg_audio['layer'] == 3)) { $bytes_per_frame = 576; } - $thisfile_mpeg_audio['VBR_bitrate'] = (isset($thisfile_mpeg_audio['VBR_bytes']) ? (($thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames']) * 8) * ($ThisFileInfo['audio']['sample_rate'] / $bytes_per_frame) : 0); + $thisfile_mpeg_audio['VBR_bitrate'] = (isset($thisfile_mpeg_audio['VBR_bytes']) ? (($thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames']) * 8) * ($info['audio']['sample_rate'] / $bytes_per_frame) : 0); if ($thisfile_mpeg_audio['VBR_bitrate'] > 0) { - $ThisFileInfo['audio']['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; + $info['audio']['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; // to avoid confusion } break; @@ -957,9 +1024,25 @@ class getid3_mp3 if ($recursivesearch) { - if (!getid3_mp3::RecursiveFrameScanning($fd, $ThisFileInfo, $offset, $nextframetestoffset, $ScanAsCBR)) { + if (!$this->RecursiveFrameScanning($offset, $nextframetestoffset, $ScanAsCBR)) { return false; } + if (!empty($this->getid3->info['mp3_validity_check_bitrates']) && !empty($thisfile_mpeg_audio['bitrate_mode']) && ($thisfile_mpeg_audio['bitrate_mode'] == 'vbr') && !empty($thisfile_mpeg_audio['VBR_bitrate'])) { + // https://github.com/JamesHeinrich/getID3/issues/287 + if (count(array_keys($this->getid3->info['mp3_validity_check_bitrates'])) == 1) { + list($cbr_bitrate_in_short_scan) = array_keys($this->getid3->info['mp3_validity_check_bitrates']); + $deviation_cbr_from_header_bitrate = abs($thisfile_mpeg_audio['VBR_bitrate'] - $cbr_bitrate_in_short_scan) / $cbr_bitrate_in_short_scan; + if ($deviation_cbr_from_header_bitrate < 0.01) { + // VBR header bitrate may differ slightly from true bitrate of frames, perhaps accounting for overhead of VBR header frame itself? + // If measured CBR bitrate is within 1% of specified bitrate in VBR header then assume that file is truly CBR + $thisfile_mpeg_audio['bitrate_mode'] = 'cbr'; + //$this->warning('VBR header ignored, assuming CBR '.round($cbr_bitrate_in_short_scan / 1000).'kbps based on scan of '.$this->mp3_valid_check_frames.' frames'); + } + } + } + if (isset($this->getid3->info['mp3_validity_check_bitrates'])) { + unset($this->getid3->info['mp3_validity_check_bitrates']); + } } @@ -997,7 +1080,7 @@ class getid3_mp3 // } // // if ($thisfile_mpeg_audio['version'] == '1') { - // for ($channel = 0; $channel < $ThisFileInfo['audio']['channels']; $channel++) { + // for ($channel = 0; $channel < $info['audio']['channels']; $channel++) { // for ($scfsi_band = 0; $scfsi_band < 4; $scfsi_band++) { // $thisfile_mpeg_audio['scfsi'][$channel][$scfsi_band] = substr($SideInfoBitstream, $SideInfoOffset, 1); // $SideInfoOffset += 2; @@ -1005,7 +1088,7 @@ class getid3_mp3 // } // } // for ($granule = 0; $granule < (($thisfile_mpeg_audio['version'] == '1') ? 2 : 1); $granule++) { - // for ($channel = 0; $channel < $ThisFileInfo['audio']['channels']; $channel++) { + // for ($channel = 0; $channel < $info['audio']['channels']; $channel++) { // $thisfile_mpeg_audio['part2_3_length'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 12); // $SideInfoOffset += 12; // $thisfile_mpeg_audio['big_values'][$granule][$channel] = substr($SideInfoBitstream, $SideInfoOffset, 9); @@ -1069,20 +1152,33 @@ class getid3_mp3 return true; } - static function RecursiveFrameScanning(&$fd, &$ThisFileInfo, &$offset, &$nextframetestoffset, $ScanAsCBR) { - for ($i = 0; $i < GETID3_MP3_VALID_CHECK_FRAMES; $i++) { - // check next GETID3_MP3_VALID_CHECK_FRAMES frames for validity, to make sure we haven't run across a false synch - if (($nextframetestoffset + 4) >= $ThisFileInfo['avdataend']) { + /** + * @param int $offset + * @param int $nextframetestoffset + * @param bool $ScanAsCBR + * + * @return bool + */ + public function RecursiveFrameScanning(&$offset, &$nextframetestoffset, $ScanAsCBR) { + $info = &$this->getid3->info; + $firstframetestarray = array('error' => array(), 'warning'=> array(), 'avdataend' => $info['avdataend'], 'avdataoffset' => $info['avdataoffset']); + $this->decodeMPEGaudioHeader($offset, $firstframetestarray, false); + + $info['mp3_validity_check_bitrates'] = array(); + for ($i = 0; $i < $this->mp3_valid_check_frames; $i++) { + // check next (default: 50) frames for validity, to make sure we haven't run across a false synch + if (($nextframetestoffset + 4) >= $info['avdataend']) { // end of file return true; } - $nextframetestarray = array('error'=>'', 'warning'=>'', 'avdataend'=>$ThisFileInfo['avdataend'], 'avdataoffset'=>$ThisFileInfo['avdataoffset']); - if (getid3_mp3::decodeMPEGaudioHeader($fd, $nextframetestoffset, $nextframetestarray, false)) { + $nextframetestarray = array('error' => array(), 'warning' => array(), 'avdataend' => $info['avdataend'], 'avdataoffset'=>$info['avdataoffset']); + if ($this->decodeMPEGaudioHeader($nextframetestoffset, $nextframetestarray, false)) { + /** @phpstan-ignore-next-line */ + getid3_lib::safe_inc($info['mp3_validity_check_bitrates'][$nextframetestarray['mpeg']['audio']['bitrate']]); if ($ScanAsCBR) { - // force CBR mode, used for trying to pick out invalid audio streams with - // valid(?) VBR headers, or VBR streams with no VBR header - if (!isset($nextframetestarray['mpeg']['audio']['bitrate']) || !isset($ThisFileInfo['mpeg']['audio']['bitrate']) || ($nextframetestarray['mpeg']['audio']['bitrate'] != $ThisFileInfo['mpeg']['audio']['bitrate'])) { + // force CBR mode, used for trying to pick out invalid audio streams with valid(?) VBR headers, or VBR streams with no VBR header + if (!isset($nextframetestarray['mpeg']['audio']['bitrate']) || !isset($firstframetestarray['mpeg']['audio']['bitrate']) || ($nextframetestarray['mpeg']['audio']['bitrate'] != $firstframetestarray['mpeg']['audio']['bitrate'])) { return false; } } @@ -1092,14 +1188,19 @@ class getid3_mp3 if (isset($nextframetestarray['mpeg']['audio']['framelength']) && ($nextframetestarray['mpeg']['audio']['framelength'] > 0)) { $nextframetestoffset += $nextframetestarray['mpeg']['audio']['framelength']; } else { - $ThisFileInfo['error'][] = 'Frame at offset ('.$offset.') is has an invalid frame length.'; + $this->error('Frame at offset ('.$offset.') is has an invalid frame length.'); return false; } + } elseif (!empty($firstframetestarray['mpeg']['audio']['framelength']) && (($nextframetestoffset + $firstframetestarray['mpeg']['audio']['framelength']) > $info['avdataend'])) { + + // it's not the end of the file, but there's not enough data left for another frame, so assume it's garbage/padding and return OK + return true; + } else { // next frame is not valid, note the error and fail, so scanning can contiue for a valid frame sequence - $ThisFileInfo['error'][] = 'Frame at offset ('.$offset.') is valid, but the next one at ('.$nextframetestoffset.') is not.'; + $this->warning('Frame at offset ('.$offset.') is valid, but the next one at ('.$nextframetestoffset.') is not.'); return false; } @@ -1107,15 +1208,23 @@ class getid3_mp3 return true; } - static function FreeFormatFrameLength($fd, $offset, &$ThisFileInfo, $deepscan=false) { - fseek($fd, $offset, SEEK_SET); - $MPEGaudioData = fread($fd, 32768); + /** + * @param int $offset + * @param bool $deepscan + * + * @return int|false + */ + public function FreeFormatFrameLength($offset, $deepscan=false) { + $info = &$this->getid3->info; + + $this->fseek($offset); + $MPEGaudioData = $this->fread(32768); $SyncPattern1 = substr($MPEGaudioData, 0, 4); // may be different pattern due to padding - $SyncPattern2 = $SyncPattern1{0}.$SyncPattern1{1}.chr(ord($SyncPattern1{2}) | 0x02).$SyncPattern1{3}; + $SyncPattern2 = $SyncPattern1[0].$SyncPattern1[1].chr(ord($SyncPattern1[2]) | 0x02).$SyncPattern1[3]; if ($SyncPattern2 === $SyncPattern1) { - $SyncPattern2 = $SyncPattern1{0}.$SyncPattern1{1}.chr(ord($SyncPattern1{2}) & 0xFD).$SyncPattern1{3}; + $SyncPattern2 = $SyncPattern1[0].$SyncPattern1[1].chr(ord($SyncPattern1[2]) & 0xFD).$SyncPattern1[3]; } $framelength = false; @@ -1140,12 +1249,12 @@ class getid3_mp3 $framelength = $framelength2; } if (!$framelength) { - $ThisFileInfo['error'][] = 'Cannot find next free-format synch pattern ('.getid3_lib::PrintHexBytes($SyncPattern1).' or '.getid3_lib::PrintHexBytes($SyncPattern2).') after offset '.$offset; + $this->error('Cannot find next free-format synch pattern ('.getid3_lib::PrintHexBytes($SyncPattern1).' or '.getid3_lib::PrintHexBytes($SyncPattern2).') after offset '.$offset); return false; } else { - $ThisFileInfo['warning'][] = 'ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)'; - $ThisFileInfo['audio']['codec'] = 'LAME'; - $ThisFileInfo['audio']['encoder'] = 'LAME3.88'; + $this->warning('ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)'); + $info['audio']['codec'] = 'LAME'; + $info['audio']['encoder'] = 'LAME3.88'; $SyncPattern1 = substr($SyncPattern1, 0, 3); $SyncPattern2 = substr($SyncPattern2, 0, 3); } @@ -1155,9 +1264,9 @@ class getid3_mp3 $ActualFrameLengthValues = array(); $nextoffset = $offset + $framelength; - while ($nextoffset < ($ThisFileInfo['avdataend'] - 6)) { - fseek($fd, $nextoffset - 1, SEEK_SET); - $NextSyncPattern = fread($fd, 6); + while ($nextoffset < ($info['avdataend'] - 6)) { + $this->fseek($nextoffset - 1); + $NextSyncPattern = $this->fread(6); if ((substr($NextSyncPattern, 1, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 1, strlen($SyncPattern2)) == $SyncPattern2)) { // good - found where expected $ActualFrameLengthValues[] = $framelength; @@ -1170,7 +1279,7 @@ class getid3_mp3 $ActualFrameLengthValues[] = ($framelength + 1); $nextoffset++; } else { - $ThisFileInfo['error'][] = 'Did not find expected free-format sync pattern at offset '.$nextoffset; + $this->error('Did not find expected free-format sync pattern at offset '.$nextoffset); return false; } $nextoffset += $framelength; @@ -1182,56 +1291,59 @@ class getid3_mp3 return $framelength; } - function getOnlyMPEGaudioInfoBruteForce($fd, &$ThisFileInfo) { + /** + * @return bool + */ + public function getOnlyMPEGaudioInfoBruteForce() { + $MPEGaudioHeaderDecodeCache = array(); + $MPEGaudioHeaderValidCache = array(); + $MPEGaudioHeaderLengthCache = array(); + $MPEGaudioVersionLookup = self::MPEGaudioVersionArray(); + $MPEGaudioLayerLookup = self::MPEGaudioLayerArray(); + $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray(); + $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray(); + $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray(); + $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray(); + $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray(); + $LongMPEGversionLookup = array(); + $LongMPEGlayerLookup = array(); + $LongMPEGbitrateLookup = array(); + $LongMPEGpaddingLookup = array(); + $LongMPEGfrequencyLookup = array(); + $Distribution = array(); + $Distribution['bitrate'] = array(); + $Distribution['frequency'] = array(); + $Distribution['layer'] = array(); + $Distribution['version'] = array(); + $Distribution['padding'] = array(); - $MPEGaudioHeaderDecodeCache = array(); - $MPEGaudioHeaderValidCache = array(); - $MPEGaudioHeaderLengthCache = array(); - $MPEGaudioVersionLookup = getid3_mp3::MPEGaudioVersionArray(); - $MPEGaudioLayerLookup = getid3_mp3::MPEGaudioLayerArray(); - $MPEGaudioBitrateLookup = getid3_mp3::MPEGaudioBitrateArray(); - $MPEGaudioFrequencyLookup = getid3_mp3::MPEGaudioFrequencyArray(); - $MPEGaudioChannelModeLookup = getid3_mp3::MPEGaudioChannelModeArray(); - $MPEGaudioModeExtensionLookup = getid3_mp3::MPEGaudioModeExtensionArray(); - $MPEGaudioEmphasisLookup = getid3_mp3::MPEGaudioEmphasisArray(); - $LongMPEGversionLookup = array(); - $LongMPEGlayerLookup = array(); - $LongMPEGbitrateLookup = array(); - $LongMPEGpaddingLookup = array(); - $LongMPEGfrequencyLookup = array(); - - $Distribution['bitrate'] = array(); - $Distribution['frequency'] = array(); - $Distribution['layer'] = array(); - $Distribution['version'] = array(); - $Distribution['padding'] = array(); - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); $max_frames_scan = 5000; $frames_scanned = 0; - $previousvalidframe = $ThisFileInfo['avdataoffset']; - while (ftell($fd) < $ThisFileInfo['avdataend']) { + $previousvalidframe = $info['avdataoffset']; + while ($this->ftell() < $info['avdataend']) { set_time_limit(30); - $head4 = fread($fd, 4); + $head4 = $this->fread(4); if (strlen($head4) < 4) { break; } - if ($head4{0} != "\xFF") { + if ($head4[0] != "\xFF") { for ($i = 1; $i < 4; $i++) { - if ($head4{$i} == "\xFF") { - fseek($fd, $i - 4, SEEK_CUR); + if ($head4[$i] == "\xFF") { + $this->fseek($i - 4, SEEK_CUR); continue 2; } } continue; } if (!isset($MPEGaudioHeaderDecodeCache[$head4])) { - $MPEGaudioHeaderDecodeCache[$head4] = getid3_mp3::MPEGaudioHeaderDecode($head4); + $MPEGaudioHeaderDecodeCache[$head4] = self::MPEGaudioHeaderDecode($head4); } if (!isset($MPEGaudioHeaderValidCache[$head4])) { - $MPEGaudioHeaderValidCache[$head4] = getid3_mp3::MPEGaudioHeaderValid($MPEGaudioHeaderDecodeCache[$head4], false, false); + $MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGaudioHeaderDecodeCache[$head4], false, false); } if ($MPEGaudioHeaderValidCache[$head4]) { @@ -1241,7 +1353,7 @@ class getid3_mp3 $LongMPEGbitrateLookup[$head4] = $MPEGaudioBitrateLookup[$LongMPEGversionLookup[$head4]][$LongMPEGlayerLookup[$head4]][$MPEGaudioHeaderDecodeCache[$head4]['bitrate']]; $LongMPEGpaddingLookup[$head4] = (bool) $MPEGaudioHeaderDecodeCache[$head4]['padding']; $LongMPEGfrequencyLookup[$head4] = $MPEGaudioFrequencyLookup[$LongMPEGversionLookup[$head4]][$MPEGaudioHeaderDecodeCache[$head4]['sample_rate']]; - $MPEGaudioHeaderLengthCache[$head4] = getid3_mp3::MPEGaudioFrameLength( + $MPEGaudioHeaderLengthCache[$head4] = self::MPEGaudioFrameLength( $LongMPEGbitrateLookup[$head4], $LongMPEGversionLookup[$head4], $LongMPEGlayerLookup[$head4], @@ -1249,27 +1361,27 @@ class getid3_mp3 $LongMPEGfrequencyLookup[$head4]); } if ($MPEGaudioHeaderLengthCache[$head4] > 4) { - $WhereWeWere = ftell($fd); - fseek($fd, $MPEGaudioHeaderLengthCache[$head4] - 4, SEEK_CUR); - $next4 = fread($fd, 4); - if ($next4{0} == "\xFF") { + $WhereWeWere = $this->ftell(); + $this->fseek($MPEGaudioHeaderLengthCache[$head4] - 4, SEEK_CUR); + $next4 = $this->fread(4); + if ($next4[0] == "\xFF") { if (!isset($MPEGaudioHeaderDecodeCache[$next4])) { - $MPEGaudioHeaderDecodeCache[$next4] = getid3_mp3::MPEGaudioHeaderDecode($next4); + $MPEGaudioHeaderDecodeCache[$next4] = self::MPEGaudioHeaderDecode($next4); } if (!isset($MPEGaudioHeaderValidCache[$next4])) { - $MPEGaudioHeaderValidCache[$next4] = getid3_mp3::MPEGaudioHeaderValid($MPEGaudioHeaderDecodeCache[$next4], false, false); + $MPEGaudioHeaderValidCache[$next4] = self::MPEGaudioHeaderValid($MPEGaudioHeaderDecodeCache[$next4], false, false); } if ($MPEGaudioHeaderValidCache[$next4]) { - fseek($fd, -4, SEEK_CUR); + $this->fseek(-4, SEEK_CUR); - getid3_lib::safe_inc($Distribution['bitrate'][$LongMPEGbitrateLookup[$head4]]); - getid3_lib::safe_inc($Distribution['layer'][$LongMPEGlayerLookup[$head4]]); - getid3_lib::safe_inc($Distribution['version'][$LongMPEGversionLookup[$head4]]); - getid3_lib::safe_inc($Distribution['padding'][intval($LongMPEGpaddingLookup[$head4])]); - getid3_lib::safe_inc($Distribution['frequency'][$LongMPEGfrequencyLookup[$head4]]); - if ($max_frames_scan && (++$frames_scanned >= $max_frames_scan)) { - $pct_data_scanned = (ftell($fd) - $ThisFileInfo['avdataoffset']) / ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']); - $ThisFileInfo['warning'][] = 'too many MPEG audio frames to scan, only scanned first '.$max_frames_scan.' frames ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.'; + $Distribution['bitrate'][$LongMPEGbitrateLookup[$head4]] = isset($Distribution['bitrate'][$LongMPEGbitrateLookup[$head4]]) ? ++$Distribution['bitrate'][$LongMPEGbitrateLookup[$head4]] : 1; + $Distribution['layer'][$LongMPEGlayerLookup[$head4]] = isset($Distribution['layer'][$LongMPEGlayerLookup[$head4]]) ? ++$Distribution['layer'][$LongMPEGlayerLookup[$head4]] : 1; + $Distribution['version'][$LongMPEGversionLookup[$head4]] = isset($Distribution['version'][$LongMPEGversionLookup[$head4]]) ? ++$Distribution['version'][$LongMPEGversionLookup[$head4]] : 1; + $Distribution['padding'][intval($LongMPEGpaddingLookup[$head4])] = isset($Distribution['padding'][intval($LongMPEGpaddingLookup[$head4])]) ? ++$Distribution['padding'][intval($LongMPEGpaddingLookup[$head4])] : 1; + $Distribution['frequency'][$LongMPEGfrequencyLookup[$head4]] = isset($Distribution['frequency'][$LongMPEGfrequencyLookup[$head4]]) ? ++$Distribution['frequency'][$LongMPEGfrequencyLookup[$head4]] : 1; + if (++$frames_scanned >= $max_frames_scan) { + $pct_data_scanned = ($this->ftell() - $info['avdataoffset']) / ($info['avdataend'] - $info['avdataoffset']); + $this->warning('too many MPEG audio frames to scan, only scanned first '.$max_frames_scan.' frames ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.'); foreach ($Distribution as $key1 => $value1) { foreach ($value1 as $key2 => $value2) { $Distribution[$key1][$key2] = round($value2 / $pct_data_scanned); @@ -1281,7 +1393,7 @@ class getid3_mp3 } } unset($next4); - fseek($fd, $WhereWeWere - 3, SEEK_SET); + $this->fseek($WhereWeWere - 3); } } @@ -1290,19 +1402,19 @@ class getid3_mp3 ksort($Distribution[$key], SORT_NUMERIC); } ksort($Distribution['version'], SORT_STRING); - $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = $Distribution['bitrate']; - $ThisFileInfo['mpeg']['audio']['frequency_distribution'] = $Distribution['frequency']; - $ThisFileInfo['mpeg']['audio']['layer_distribution'] = $Distribution['layer']; - $ThisFileInfo['mpeg']['audio']['version_distribution'] = $Distribution['version']; - $ThisFileInfo['mpeg']['audio']['padding_distribution'] = $Distribution['padding']; + $info['mpeg']['audio']['bitrate_distribution'] = $Distribution['bitrate']; + $info['mpeg']['audio']['frequency_distribution'] = $Distribution['frequency']; + $info['mpeg']['audio']['layer_distribution'] = $Distribution['layer']; + $info['mpeg']['audio']['version_distribution'] = $Distribution['version']; + $info['mpeg']['audio']['padding_distribution'] = $Distribution['padding']; if (count($Distribution['version']) > 1) { - $ThisFileInfo['error'][] = 'Corrupt file - more than one MPEG version detected'; + $this->error('Corrupt file - more than one MPEG version detected'); } if (count($Distribution['layer']) > 1) { - $ThisFileInfo['error'][] = 'Corrupt file - more than one MPEG layer detected'; + $this->error('Corrupt file - more than one MPEG layer detected'); } if (count($Distribution['frequency']) > 1) { - $ThisFileInfo['error'][] = 'Corrupt file - more than one MPEG sample rate detected'; + $this->error('Corrupt file - more than one MPEG sample rate detected'); } @@ -1312,164 +1424,184 @@ class getid3_mp3 $bittotal += ($bitratevalue * $bitratecount); } } - $ThisFileInfo['mpeg']['audio']['frame_count'] = array_sum($Distribution['bitrate']); - if ($ThisFileInfo['mpeg']['audio']['frame_count'] == 0) { - $ThisFileInfo['error'][] = 'no MPEG audio frames found'; + $info['mpeg']['audio']['frame_count'] = array_sum($Distribution['bitrate']); + if ($info['mpeg']['audio']['frame_count'] == 0) { + $this->error('no MPEG audio frames found'); return false; } - $ThisFileInfo['mpeg']['audio']['bitrate'] = ($bittotal / $ThisFileInfo['mpeg']['audio']['frame_count']); - $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = ((count($Distribution['bitrate']) > 0) ? 'vbr' : 'cbr'); - $ThisFileInfo['mpeg']['audio']['sample_rate'] = getid3_lib::array_max($Distribution['frequency'], true); + $info['mpeg']['audio']['bitrate'] = ($bittotal / $info['mpeg']['audio']['frame_count']); + $info['mpeg']['audio']['bitrate_mode'] = ((count($Distribution['bitrate']) > 0) ? 'vbr' : 'cbr'); + $info['mpeg']['audio']['sample_rate'] = getid3_lib::array_max($Distribution['frequency'], true); - $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate']; - $ThisFileInfo['audio']['bitrate_mode'] = $ThisFileInfo['mpeg']['audio']['bitrate_mode']; - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate']; - $ThisFileInfo['audio']['dataformat'] = 'mp'.getid3_lib::array_max($Distribution['layer'], true); - $ThisFileInfo['fileformat'] = $ThisFileInfo['audio']['dataformat']; + $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; + $info['audio']['bitrate_mode'] = $info['mpeg']['audio']['bitrate_mode']; + $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; + $info['audio']['dataformat'] = 'mp'.getid3_lib::array_max($Distribution['layer'], true); + $info['fileformat'] = $info['audio']['dataformat']; return true; } - - static function getOnlyMPEGaudioInfo($fd, &$ThisFileInfo, $avdataoffset, $BitrateHistogram=false) { - + /** + * @param int $avdataoffset + * @param bool $BitrateHistogram + * + * @return bool + */ + public function getOnlyMPEGaudioInfo($avdataoffset, $BitrateHistogram=false) { // looks for synch, decodes MPEG audio header + $info = &$this->getid3->info; + static $MPEGaudioVersionLookup; static $MPEGaudioLayerLookup; static $MPEGaudioBitrateLookup; if (empty($MPEGaudioVersionLookup)) { - $MPEGaudioVersionLookup = getid3_mp3::MPEGaudioVersionArray(); - $MPEGaudioLayerLookup = getid3_mp3::MPEGaudioLayerArray(); - $MPEGaudioBitrateLookup = getid3_mp3::MPEGaudioBitrateArray(); - + $MPEGaudioVersionLookup = self::MPEGaudioVersionArray(); + $MPEGaudioLayerLookup = self::MPEGaudioLayerArray(); + $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray(); } - fseek($fd, $avdataoffset, SEEK_SET); - $sync_seek_buffer_size = min(128 * 1024, $ThisFileInfo['avdataend'] - $avdataoffset); + $this->fseek($avdataoffset); + $sync_seek_buffer_size = min(128 * 1024, $info['avdataend'] - $avdataoffset); if ($sync_seek_buffer_size <= 0) { - $ThisFileInfo['error'][] = 'Invalid $sync_seek_buffer_size at offset '.$avdataoffset; + $this->error('Invalid $sync_seek_buffer_size at offset '.$avdataoffset); return false; } - $header = fread($fd, $sync_seek_buffer_size); + $header = $this->fread($sync_seek_buffer_size); $sync_seek_buffer_size = strlen($header); $SynchSeekOffset = 0; + $SyncSeekAttempts = 0; + $SyncSeekAttemptsMax = 1000; + $FirstFrameThisfileInfo = null; while ($SynchSeekOffset < $sync_seek_buffer_size) { - - if ((($avdataoffset + $SynchSeekOffset) < $ThisFileInfo['avdataend']) && !feof($fd)) { + if ((($avdataoffset + $SynchSeekOffset) < $info['avdataend']) && !feof($this->getid3->fp)) { if ($SynchSeekOffset > $sync_seek_buffer_size) { // if a synch's not found within the first 128k bytes, then give up - $ThisFileInfo['error'][] = 'Could not find valid MPEG audio synch within the first '.round($sync_seek_buffer_size / 1024).'kB'; - if (isset($ThisFileInfo['audio']['bitrate'])) { - unset($ThisFileInfo['audio']['bitrate']); + $this->error('Could not find valid MPEG audio synch within the first '.round($sync_seek_buffer_size / 1024).'kB'); + if (isset($info['audio']['bitrate'])) { + unset($info['audio']['bitrate']); } - if (isset($ThisFileInfo['mpeg']['audio'])) { - unset($ThisFileInfo['mpeg']['audio']); + if (isset($info['mpeg']['audio'])) { + unset($info['mpeg']['audio']); } - if (empty($ThisFileInfo['mpeg'])) { - unset($ThisFileInfo['mpeg']); + if (empty($info['mpeg'])) { + unset($info['mpeg']); } return false; - } elseif (feof($fd)) { + } elseif (feof($this->getid3->fp)) { - $ThisFileInfo['error'][] = 'Could not find valid MPEG audio synch before end of file'; - if (isset($ThisFileInfo['audio']['bitrate'])) { - unset($ThisFileInfo['audio']['bitrate']); + $this->error('Could not find valid MPEG audio synch before end of file'); + if (isset($info['audio']['bitrate'])) { + unset($info['audio']['bitrate']); } - if (isset($ThisFileInfo['mpeg']['audio'])) { - unset($ThisFileInfo['mpeg']['audio']); + if (isset($info['mpeg']['audio'])) { + unset($info['mpeg']['audio']); } - if (isset($ThisFileInfo['mpeg']) && (!is_array($ThisFileInfo['mpeg']) || (count($ThisFileInfo['mpeg']) == 0))) { - unset($ThisFileInfo['mpeg']); + if (isset($info['mpeg']) && (!is_array($info['mpeg']) || (count($info['mpeg']) == 0))) { + unset($info['mpeg']); } return false; } } if (($SynchSeekOffset + 1) >= strlen($header)) { - $ThisFileInfo['error'][] = 'Could not find valid MPEG synch before end of file'; + $this->error('Could not find valid MPEG synch before end of file'); return false; } - if (($header{$SynchSeekOffset} == "\xFF") && ($header{($SynchSeekOffset + 1)} > "\xE0")) { // synch detected - - if (!isset($FirstFrameThisfileInfo) && !isset($ThisFileInfo['mpeg']['audio'])) { - $FirstFrameThisfileInfo = $ThisFileInfo; + if (($header[$SynchSeekOffset] == "\xFF") && ($header[($SynchSeekOffset + 1)] > "\xE0")) { // possible synch detected + if (++$SyncSeekAttempts >= $SyncSeekAttemptsMax) { + // https://github.com/JamesHeinrich/getID3/issues/286 + // corrupt files claiming to be MP3, with a large number of 0xFF bytes near the beginning, can cause this loop to take a very long time + // should have escape condition to avoid spending too much time scanning a corrupt file + // if a synch's not found within the first 128k bytes, then give up + $this->error('Could not find valid MPEG audio synch after scanning '.$SyncSeekAttempts.' candidate offsets'); + if (isset($info['audio']['bitrate'])) { + unset($info['audio']['bitrate']); + } + if (isset($info['mpeg']['audio'])) { + unset($info['mpeg']['audio']); + } + if (empty($info['mpeg'])) { + unset($info['mpeg']); + } + return false; + } + $FirstFrameAVDataOffset = null; + if (!isset($FirstFrameThisfileInfo) && !isset($info['mpeg']['audio'])) { + $FirstFrameThisfileInfo = $info; $FirstFrameAVDataOffset = $avdataoffset + $SynchSeekOffset; - if (!getid3_mp3::decodeMPEGaudioHeader($fd, $avdataoffset + $SynchSeekOffset, $FirstFrameThisfileInfo, false)) { + if (!$this->decodeMPEGaudioHeader($FirstFrameAVDataOffset, $FirstFrameThisfileInfo, false)) { // if this is the first valid MPEG-audio frame, save it in case it's a VBR header frame and there's // garbage between this frame and a valid sequence of MPEG-audio frames, to be restored below unset($FirstFrameThisfileInfo); } } - $dummy = $ThisFileInfo; // only overwrite real data if valid header found - if (getid3_mp3::decodeMPEGaudioHeader($fd, $avdataoffset + $SynchSeekOffset, $dummy, true)) { - $ThisFileInfo = $dummy; - $ThisFileInfo['avdataoffset'] = $avdataoffset + $SynchSeekOffset; - switch (isset($ThisFileInfo['fileformat']) ? $ThisFileInfo['fileformat'] : '') { + $dummy = $info; // only overwrite real data if valid header found + if ($this->decodeMPEGaudioHeader($avdataoffset + $SynchSeekOffset, $dummy, true)) { + $info = $dummy; + $info['avdataoffset'] = $avdataoffset + $SynchSeekOffset; + switch (isset($info['fileformat']) ? $info['fileformat'] : '') { case '': case 'id3': case 'ape': case 'mp3': - $ThisFileInfo['fileformat'] = 'mp3'; - $ThisFileInfo['audio']['dataformat'] = 'mp3'; + $info['fileformat'] = 'mp3'; + $info['audio']['dataformat'] = 'mp3'; break; } - if (isset($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode']) && ($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr')) { - if (!(abs($ThisFileInfo['audio']['bitrate'] - $FirstFrameThisfileInfo['audio']['bitrate']) <= 1)) { + if (isset($FirstFrameThisfileInfo) && isset($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode']) && ($FirstFrameThisfileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr')) { + if (!(abs($info['audio']['bitrate'] - $FirstFrameThisfileInfo['audio']['bitrate']) <= 1)) { // If there is garbage data between a valid VBR header frame and a sequence // of valid MPEG-audio frames the VBR data is no longer discarded. - $ThisFileInfo = $FirstFrameThisfileInfo; - $ThisFileInfo['avdataoffset'] = $FirstFrameAVDataOffset; - $ThisFileInfo['fileformat'] = 'mp3'; - $ThisFileInfo['audio']['dataformat'] = 'mp3'; - $dummy = $ThisFileInfo; + $info = $FirstFrameThisfileInfo; + $info['avdataoffset'] = $FirstFrameAVDataOffset; + $info['fileformat'] = 'mp3'; + $info['audio']['dataformat'] = 'mp3'; + $dummy = $info; unset($dummy['mpeg']['audio']); $GarbageOffsetStart = $FirstFrameAVDataOffset + $FirstFrameThisfileInfo['mpeg']['audio']['framelength']; $GarbageOffsetEnd = $avdataoffset + $SynchSeekOffset; - if (getid3_mp3::decodeMPEGaudioHeader($fd, $GarbageOffsetEnd, $dummy, true, true)) { - - $ThisFileInfo = $dummy; - $ThisFileInfo['avdataoffset'] = $GarbageOffsetEnd; - $ThisFileInfo['warning'][] = 'apparently-valid VBR header not used because could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.'), but did find valid CBR stream starting at '.$GarbageOffsetEnd; - + if ($this->decodeMPEGaudioHeader($GarbageOffsetEnd, $dummy, true, true)) { + $info = $dummy; + $info['avdataoffset'] = $GarbageOffsetEnd; + $this->warning('apparently-valid VBR header not used because could not find '.$this->mp3_valid_check_frames.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.'), but did find valid CBR stream starting at '.$GarbageOffsetEnd); } else { - - $ThisFileInfo['warning'][] = 'using data from VBR header even though could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.')'; - + $this->warning('using data from VBR header even though could not find '.$this->mp3_valid_check_frames.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.')'); } } } - if (isset($ThisFileInfo['mpeg']['audio']['bitrate_mode']) && ($ThisFileInfo['mpeg']['audio']['bitrate_mode'] == 'vbr') && !isset($ThisFileInfo['mpeg']['audio']['VBR_method'])) { + if (isset($info['mpeg']['audio']['bitrate_mode']) && ($info['mpeg']['audio']['bitrate_mode'] == 'vbr') && !isset($info['mpeg']['audio']['VBR_method'])) { // VBR file with no VBR header $BitrateHistogram = true; } if ($BitrateHistogram) { - $ThisFileInfo['mpeg']['audio']['stereo_distribution'] = array('stereo'=>0, 'joint stereo'=>0, 'dual channel'=>0, 'mono'=>0); - $ThisFileInfo['mpeg']['audio']['version_distribution'] = array('1'=>0, '2'=>0, '2.5'=>0); + $info['mpeg']['audio']['stereo_distribution'] = array('stereo'=>0, 'joint stereo'=>0, 'dual channel'=>0, 'mono'=>0); + $info['mpeg']['audio']['version_distribution'] = array('1'=>0, '2'=>0, '2.5'=>0); - if ($ThisFileInfo['mpeg']['audio']['version'] == '1') { - if ($ThisFileInfo['mpeg']['audio']['layer'] == 3) { - $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 40000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 320000=>0); - } elseif ($ThisFileInfo['mpeg']['audio']['layer'] == 2) { - $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 320000=>0, 384000=>0); - } elseif ($ThisFileInfo['mpeg']['audio']['layer'] == 1) { - $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 64000=>0, 96000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 288000=>0, 320000=>0, 352000=>0, 384000=>0, 416000=>0, 448000=>0); + if ($info['mpeg']['audio']['version'] == '1') { + if ($info['mpeg']['audio']['layer'] == 3) { + $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 40000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 320000=>0); + } elseif ($info['mpeg']['audio']['layer'] == 2) { + $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 320000=>0, 384000=>0); + } elseif ($info['mpeg']['audio']['layer'] == 1) { + $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 64000=>0, 96000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 288000=>0, 320000=>0, 352000=>0, 384000=>0, 416000=>0, 448000=>0); } - } elseif ($ThisFileInfo['mpeg']['audio']['layer'] == 1) { - $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 144000=>0, 160000=>0, 176000=>0, 192000=>0, 224000=>0, 256000=>0); + } elseif ($info['mpeg']['audio']['layer'] == 1) { + $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 32000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 144000=>0, 160000=>0, 176000=>0, 192000=>0, 224000=>0, 256000=>0); } else { - $ThisFileInfo['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 8000=>0, 16000=>0, 24000=>0, 32000=>0, 40000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 144000=>0, 160000=>0); + $info['mpeg']['audio']['bitrate_distribution'] = array('free'=>0, 8000=>0, 16000=>0, 24000=>0, 32000=>0, 40000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 144000=>0, 160000=>0); } - $dummy = array('error'=>$ThisFileInfo['error'], 'warning'=>$ThisFileInfo['warning'], 'avdataend'=>$ThisFileInfo['avdataend'], 'avdataoffset'=>$ThisFileInfo['avdataoffset']); - $synchstartoffset = $ThisFileInfo['avdataoffset']; - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); + $dummy = array('error'=>$info['error'], 'warning'=>$info['warning'], 'avdataend'=>$info['avdataend'], 'avdataoffset'=>$info['avdataoffset']); + $synchstartoffset = $info['avdataoffset']; + $this->fseek($info['avdataoffset']); // you can play with these numbers: $max_frames_scan = 50000; @@ -1484,18 +1616,19 @@ class getid3_mp3 $pct_data_scanned = 0; for ($current_segment = 0; $current_segment < $max_scan_segments; $current_segment++) { $frames_scanned_this_segment = 0; - if (ftell($fd) >= $ThisFileInfo['avdataend']) { + $scan_start_offset = array(); + if ($this->ftell() >= $info['avdataend']) { break; } - $scan_start_offset[$current_segment] = max(ftell($fd), $ThisFileInfo['avdataoffset'] + round($current_segment * (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $max_scan_segments))); + $scan_start_offset[$current_segment] = max($this->ftell(), $info['avdataoffset'] + round($current_segment * (($info['avdataend'] - $info['avdataoffset']) / $max_scan_segments))); if ($current_segment > 0) { - fseek($fd, $scan_start_offset[$current_segment], SEEK_SET); - $buffer_4k = fread($fd, 4096); + $this->fseek($scan_start_offset[$current_segment]); + $buffer_4k = $this->fread(4096); for ($j = 0; $j < (strlen($buffer_4k) - 4); $j++) { - if (($buffer_4k{$j} == "\xFF") && ($buffer_4k{($j + 1)} > "\xE0")) { // synch detected - if (getid3_mp3::decodeMPEGaudioHeader($fd, $scan_start_offset[$current_segment] + $j, $dummy, false, false, $FastMode)) { + if (($buffer_4k[$j] == "\xFF") && ($buffer_4k[($j + 1)] > "\xE0")) { // synch detected + if ($this->decodeMPEGaudioHeader($scan_start_offset[$current_segment] + $j, $dummy, false, false, $FastMode)) { $calculated_next_offset = $scan_start_offset[$current_segment] + $j + $dummy['mpeg']['audio']['framelength']; - if (getid3_mp3::decodeMPEGaudioHeader($fd, $calculated_next_offset, $dummy, false, false, $FastMode)) { + if ($this->decodeMPEGaudioHeader($calculated_next_offset, $dummy, false, false, $FastMode)) { $scan_start_offset[$current_segment] += $j; break; } @@ -1504,7 +1637,7 @@ class getid3_mp3 } } $synchstartoffset = $scan_start_offset[$current_segment]; - while (getid3_mp3::decodeMPEGaudioHeader($fd, $synchstartoffset, $dummy, false, false, $FastMode)) { + while (($synchstartoffset < $info['avdataend']) && $this->decodeMPEGaudioHeader($synchstartoffset, $dummy, false, false, $FastMode)) { $FastMode = true; $thisframebitrate = $MPEGaudioBitrateLookup[$MPEGaudioVersionLookup[$dummy['mpeg']['audio']['raw']['version']]][$MPEGaudioLayerLookup[$dummy['mpeg']['audio']['raw']['layer']]][$dummy['mpeg']['audio']['raw']['bitrate']]; @@ -1512,14 +1645,14 @@ class getid3_mp3 $SynchErrorsFound++; $synchstartoffset++; } else { - getid3_lib::safe_inc($ThisFileInfo['mpeg']['audio']['bitrate_distribution'][$thisframebitrate]); - getid3_lib::safe_inc($ThisFileInfo['mpeg']['audio']['stereo_distribution'][$dummy['mpeg']['audio']['channelmode']]); - getid3_lib::safe_inc($ThisFileInfo['mpeg']['audio']['version_distribution'][$dummy['mpeg']['audio']['version']]); + getid3_lib::safe_inc($info['mpeg']['audio']['bitrate_distribution'][$thisframebitrate]); + getid3_lib::safe_inc($info['mpeg']['audio']['stereo_distribution'][$dummy['mpeg']['audio']['channelmode']]); + getid3_lib::safe_inc($info['mpeg']['audio']['version_distribution'][$dummy['mpeg']['audio']['version']]); $synchstartoffset += $dummy['mpeg']['audio']['framelength']; } $frames_scanned++; if ($frames_scan_per_segment && (++$frames_scanned_this_segment >= $frames_scan_per_segment)) { - $this_pct_scanned = (ftell($fd) - $scan_start_offset[$current_segment]) / ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']); + $this_pct_scanned = ($this->ftell() - $scan_start_offset[$current_segment]) / ($info['avdataend'] - $info['avdataoffset']); if (($current_segment == 0) && (($this_pct_scanned * $max_scan_segments) >= 1)) { // file likely contains < $max_frames_scan, just scan as one segment $max_scan_segments = 1; @@ -1532,53 +1665,53 @@ class getid3_mp3 } } if ($pct_data_scanned > 0) { - $ThisFileInfo['warning'][] = 'too many MPEG audio frames to scan, only scanned '.$frames_scanned.' frames in '.$max_scan_segments.' segments ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.'; - foreach ($ThisFileInfo['mpeg']['audio'] as $key1 => $value1) { + $this->warning('too many MPEG audio frames to scan, only scanned '.$frames_scanned.' frames in '.$max_scan_segments.' segments ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.'); + foreach ($info['mpeg']['audio'] as $key1 => $value1) { if (!preg_match('#_distribution$#i', $key1)) { continue; } foreach ($value1 as $key2 => $value2) { - $ThisFileInfo['mpeg']['audio'][$key1][$key2] = round($value2 / $pct_data_scanned); + $info['mpeg']['audio'][$key1][$key2] = round($value2 / $pct_data_scanned); } } } if ($SynchErrorsFound > 0) { - $ThisFileInfo['warning'][] = 'Found '.$SynchErrorsFound.' synch errors in histogram analysis'; + $this->warning('Found '.$SynchErrorsFound.' synch errors in histogram analysis'); //return false; } $bittotal = 0; $framecounter = 0; - foreach ($ThisFileInfo['mpeg']['audio']['bitrate_distribution'] as $bitratevalue => $bitratecount) { + foreach ($info['mpeg']['audio']['bitrate_distribution'] as $bitratevalue => $bitratecount) { $framecounter += $bitratecount; if ($bitratevalue != 'free') { $bittotal += ($bitratevalue * $bitratecount); } } if ($framecounter == 0) { - $ThisFileInfo['error'][] = 'Corrupt MP3 file: framecounter == zero'; + $this->error('Corrupt MP3 file: framecounter == zero'); return false; } - $ThisFileInfo['mpeg']['audio']['frame_count'] = getid3_lib::CastAsInt($framecounter); - $ThisFileInfo['mpeg']['audio']['bitrate'] = ($bittotal / $framecounter); + $info['mpeg']['audio']['frame_count'] = getid3_lib::CastAsInt($framecounter); + $info['mpeg']['audio']['bitrate'] = ($bittotal / $framecounter); - $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['mpeg']['audio']['bitrate']; + $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate']; // Definitively set VBR vs CBR, even if the Xing/LAME/VBRI header says differently $distinct_bitrates = 0; - foreach ($ThisFileInfo['mpeg']['audio']['bitrate_distribution'] as $bitrate_value => $bitrate_count) { + foreach ($info['mpeg']['audio']['bitrate_distribution'] as $bitrate_value => $bitrate_count) { if ($bitrate_count > 0) { $distinct_bitrates++; } } if ($distinct_bitrates > 1) { - $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'vbr'; + $info['mpeg']['audio']['bitrate_mode'] = 'vbr'; } else { - $ThisFileInfo['mpeg']['audio']['bitrate_mode'] = 'cbr'; + $info['mpeg']['audio']['bitrate_mode'] = 'cbr'; } - $ThisFileInfo['audio']['bitrate_mode'] = $ThisFileInfo['mpeg']['audio']['bitrate_mode']; + $info['audio']['bitrate_mode'] = $info['mpeg']['audio']['bitrate_mode']; } @@ -1587,20 +1720,20 @@ class getid3_mp3 } $SynchSeekOffset++; - if (($avdataoffset + $SynchSeekOffset) >= $ThisFileInfo['avdataend']) { + if (($avdataoffset + $SynchSeekOffset) >= $info['avdataend']) { // end of file/data - if (empty($ThisFileInfo['mpeg']['audio'])) { + if (empty($info['mpeg']['audio'])) { - $ThisFileInfo['error'][] = 'could not find valid MPEG synch before end of file'; - if (isset($ThisFileInfo['audio']['bitrate'])) { - unset($ThisFileInfo['audio']['bitrate']); + $this->error('could not find valid MPEG synch before end of file'); + if (isset($info['audio']['bitrate'])) { + unset($info['audio']['bitrate']); } - if (isset($ThisFileInfo['mpeg']['audio'])) { - unset($ThisFileInfo['mpeg']['audio']); + if (isset($info['mpeg']['audio'])) { + unset($info['mpeg']['audio']); } - if (isset($ThisFileInfo['mpeg']) && (!is_array($ThisFileInfo['mpeg']) || empty($ThisFileInfo['mpeg']))) { - unset($ThisFileInfo['mpeg']); + if (isset($info['mpeg']) && (!is_array($info['mpeg']) || empty($info['mpeg']))) { + unset($info['mpeg']); } return false; @@ -1609,24 +1742,32 @@ class getid3_mp3 } } - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['mpeg']['audio']['channels']; - $ThisFileInfo['audio']['channelmode'] = $ThisFileInfo['mpeg']['audio']['channelmode']; - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['mpeg']['audio']['sample_rate']; + $info['audio']['channels'] = $info['mpeg']['audio']['channels']; + $info['audio']['channelmode'] = $info['mpeg']['audio']['channelmode']; + $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate']; return true; } - - static function MPEGaudioVersionArray() { + /** + * @return array + */ + public static function MPEGaudioVersionArray() { static $MPEGaudioVersion = array('2.5', false, '2', '1'); return $MPEGaudioVersion; } - static function MPEGaudioLayerArray() { + /** + * @return array + */ + public static function MPEGaudioLayerArray() { static $MPEGaudioLayer = array(false, 3, 2, 1); return $MPEGaudioLayer; } - static function MPEGaudioBitrateArray() { + /** + * @return array + */ + public static function MPEGaudioBitrateArray() { static $MPEGaudioBitrate; if (empty($MPEGaudioBitrate)) { $MPEGaudioBitrate = array ( @@ -1645,7 +1786,10 @@ class getid3_mp3 return $MPEGaudioBitrate; } - static function MPEGaudioFrequencyArray() { + /** + * @return array + */ + public static function MPEGaudioFrequencyArray() { static $MPEGaudioFrequency; if (empty($MPEGaudioFrequency)) { $MPEGaudioFrequency = array ( @@ -1657,12 +1801,18 @@ class getid3_mp3 return $MPEGaudioFrequency; } - static function MPEGaudioChannelModeArray() { + /** + * @return array + */ + public static function MPEGaudioChannelModeArray() { static $MPEGaudioChannelMode = array('stereo', 'joint stereo', 'dual channel', 'mono'); return $MPEGaudioChannelMode; } - static function MPEGaudioModeExtensionArray() { + /** + * @return array + */ + public static function MPEGaudioModeExtensionArray() { static $MPEGaudioModeExtension; if (empty($MPEGaudioModeExtension)) { $MPEGaudioModeExtension = array ( @@ -1674,17 +1824,33 @@ class getid3_mp3 return $MPEGaudioModeExtension; } - static function MPEGaudioEmphasisArray() { + /** + * @return array + */ + public static function MPEGaudioEmphasisArray() { static $MPEGaudioEmphasis = array('none', '50/15ms', false, 'CCIT J.17'); return $MPEGaudioEmphasis; } - static function MPEGaudioHeaderBytesValid($head4, $allowBitrate15=false) { - return getid3_mp3::MPEGaudioHeaderValid(getid3_mp3::MPEGaudioHeaderDecode($head4), false, $allowBitrate15); + /** + * @param string $head4 + * @param bool $allowBitrate15 + * + * @return bool + */ + public static function MPEGaudioHeaderBytesValid($head4, $allowBitrate15=false) { + return self::MPEGaudioHeaderValid(self::MPEGaudioHeaderDecode($head4), false, $allowBitrate15); } - static function MPEGaudioHeaderValid($rawarray, $echoerrors=false, $allowBitrate15=false) { - if (($rawarray['synch'] & 0x0FFE) != 0x0FFE) { + /** + * @param array $rawarray + * @param bool $echoerrors + * @param bool $allowBitrate15 + * + * @return bool + */ + public static function MPEGaudioHeaderValid($rawarray, $echoerrors=false, $allowBitrate15=false) { + if (!isset($rawarray['synch']) || ($rawarray['synch'] & 0x0FFE) != 0x0FFE) { return false; } @@ -1696,13 +1862,13 @@ class getid3_mp3 static $MPEGaudioModeExtensionLookup; static $MPEGaudioEmphasisLookup; if (empty($MPEGaudioVersionLookup)) { - $MPEGaudioVersionLookup = getid3_mp3::MPEGaudioVersionArray(); - $MPEGaudioLayerLookup = getid3_mp3::MPEGaudioLayerArray(); - $MPEGaudioBitrateLookup = getid3_mp3::MPEGaudioBitrateArray(); - $MPEGaudioFrequencyLookup = getid3_mp3::MPEGaudioFrequencyArray(); - $MPEGaudioChannelModeLookup = getid3_mp3::MPEGaudioChannelModeArray(); - $MPEGaudioModeExtensionLookup = getid3_mp3::MPEGaudioModeExtensionArray(); - $MPEGaudioEmphasisLookup = getid3_mp3::MPEGaudioEmphasisArray(); + $MPEGaudioVersionLookup = self::MPEGaudioVersionArray(); + $MPEGaudioLayerLookup = self::MPEGaudioLayerArray(); + $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray(); + $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray(); + $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray(); + $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray(); + $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray(); } if (isset($MPEGaudioVersionLookup[$rawarray['version']])) { @@ -1755,7 +1921,12 @@ class getid3_mp3 return true; } - static function MPEGaudioHeaderDecode($Header4Bytes) { + /** + * @param string $Header4Bytes + * + * @return array|false + */ + public static function MPEGaudioHeaderDecode($Header4Bytes) { // AAAA AAAA AAAB BCCD EEEE FFGH IIJJ KLMM // A - Frame sync (all bits set) // B - MPEG Audio version ID @@ -1775,24 +1946,34 @@ class getid3_mp3 return false; } + $MPEGrawHeader = array(); $MPEGrawHeader['synch'] = (getid3_lib::BigEndian2Int(substr($Header4Bytes, 0, 2)) & 0xFFE0) >> 4; - $MPEGrawHeader['version'] = (ord($Header4Bytes{1}) & 0x18) >> 3; // BB - $MPEGrawHeader['layer'] = (ord($Header4Bytes{1}) & 0x06) >> 1; // CC - $MPEGrawHeader['protection'] = (ord($Header4Bytes{1}) & 0x01); // D - $MPEGrawHeader['bitrate'] = (ord($Header4Bytes{2}) & 0xF0) >> 4; // EEEE - $MPEGrawHeader['sample_rate'] = (ord($Header4Bytes{2}) & 0x0C) >> 2; // FF - $MPEGrawHeader['padding'] = (ord($Header4Bytes{2}) & 0x02) >> 1; // G - $MPEGrawHeader['private'] = (ord($Header4Bytes{2}) & 0x01); // H - $MPEGrawHeader['channelmode'] = (ord($Header4Bytes{3}) & 0xC0) >> 6; // II - $MPEGrawHeader['modeextension'] = (ord($Header4Bytes{3}) & 0x30) >> 4; // JJ - $MPEGrawHeader['copyright'] = (ord($Header4Bytes{3}) & 0x08) >> 3; // K - $MPEGrawHeader['original'] = (ord($Header4Bytes{3}) & 0x04) >> 2; // L - $MPEGrawHeader['emphasis'] = (ord($Header4Bytes{3}) & 0x03); // MM + $MPEGrawHeader['version'] = (ord($Header4Bytes[1]) & 0x18) >> 3; // BB + $MPEGrawHeader['layer'] = (ord($Header4Bytes[1]) & 0x06) >> 1; // CC + $MPEGrawHeader['protection'] = (ord($Header4Bytes[1]) & 0x01); // D + $MPEGrawHeader['bitrate'] = (ord($Header4Bytes[2]) & 0xF0) >> 4; // EEEE + $MPEGrawHeader['sample_rate'] = (ord($Header4Bytes[2]) & 0x0C) >> 2; // FF + $MPEGrawHeader['padding'] = (ord($Header4Bytes[2]) & 0x02) >> 1; // G + $MPEGrawHeader['private'] = (ord($Header4Bytes[2]) & 0x01); // H + $MPEGrawHeader['channelmode'] = (ord($Header4Bytes[3]) & 0xC0) >> 6; // II + $MPEGrawHeader['modeextension'] = (ord($Header4Bytes[3]) & 0x30) >> 4; // JJ + $MPEGrawHeader['copyright'] = (ord($Header4Bytes[3]) & 0x08) >> 3; // K + $MPEGrawHeader['original'] = (ord($Header4Bytes[3]) & 0x04) >> 2; // L + $MPEGrawHeader['emphasis'] = (ord($Header4Bytes[3]) & 0x03); // MM return $MPEGrawHeader; } - static function MPEGaudioFrameLength(&$bitrate, &$version, &$layer, $padding, &$samplerate) { + /** + * @param int|string $bitrate + * @param string $version + * @param string $layer + * @param bool $padding + * @param int $samplerate + * + * @return int|false + */ + public static function MPEGaudioFrameLength(&$bitrate, &$version, &$layer, $padding, &$samplerate) { static $AudioFrameLengthCache = array(); if (!isset($AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate])) { @@ -1853,7 +2034,12 @@ class getid3_mp3 return $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate]; } - static function ClosestStandardMP3Bitrate($bit_rate) { + /** + * @param float|int $bit_rate + * + * @return int|float|string + */ + public static function ClosestStandardMP3Bitrate($bit_rate) { static $standard_bit_rates = array (320000, 256000, 224000, 192000, 160000, 128000, 112000, 96000, 80000, 64000, 56000, 48000, 40000, 32000, 24000, 16000, 8000); static $bit_rate_table = array (0=>'-'); $round_bit_rate = intval(round($bit_rate, -3)); @@ -1873,10 +2059,16 @@ class getid3_mp3 return $bit_rate_table[$round_bit_rate]; } - static function XingVBRidOffset($version, $channelmode) { + /** + * @param string $version + * @param string $channelmode + * + * @return int + */ + public static function XingVBRidOffset($version, $channelmode) { static $XingVBRidOffsetCache = array(); - if (empty($XingVBRidOffset)) { - $XingVBRidOffset = array ( + if (empty($XingVBRidOffsetCache)) { + $XingVBRidOffsetCache = array ( '1' => array ('mono' => 0x15, // 4 + 17 = 21 'stereo' => 0x24, // 4 + 32 = 36 'joint stereo' => 0x24, @@ -1896,10 +2088,15 @@ class getid3_mp3 ) ); } - return $XingVBRidOffset[$version][$channelmode]; + return $XingVBRidOffsetCache[$version][$channelmode]; } - static function LAMEvbrMethodLookup($VBRmethodID) { + /** + * @param int $VBRmethodID + * + * @return string + */ + public static function LAMEvbrMethodLookup($VBRmethodID) { static $LAMEvbrMethodLookup = array( 0x00 => 'unknown', 0x01 => 'cbr', @@ -1915,7 +2112,12 @@ class getid3_mp3 return (isset($LAMEvbrMethodLookup[$VBRmethodID]) ? $LAMEvbrMethodLookup[$VBRmethodID] : ''); } - static function LAMEmiscStereoModeLookup($StereoModeID) { + /** + * @param int $StereoModeID + * + * @return string + */ + public static function LAMEmiscStereoModeLookup($StereoModeID) { static $LAMEmiscStereoModeLookup = array( 0 => 'mono', 1 => 'stereo', @@ -1929,7 +2131,12 @@ class getid3_mp3 return (isset($LAMEmiscStereoModeLookup[$StereoModeID]) ? $LAMEmiscStereoModeLookup[$StereoModeID] : ''); } - static function LAMEmiscSourceSampleFrequencyLookup($SourceSampleFrequencyID) { + /** + * @param int $SourceSampleFrequencyID + * + * @return string + */ + public static function LAMEmiscSourceSampleFrequencyLookup($SourceSampleFrequencyID) { static $LAMEmiscSourceSampleFrequencyLookup = array( 0 => '<= 32 kHz', 1 => '44.1 kHz', @@ -1939,7 +2146,12 @@ class getid3_mp3 return (isset($LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID]) ? $LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID] : ''); } - static function LAMEsurroundInfoLookup($SurroundInfoID) { + /** + * @param int $SurroundInfoID + * + * @return string + */ + public static function LAMEsurroundInfoLookup($SurroundInfoID) { static $LAMEsurroundInfoLookup = array( 0 => 'no surround info', 1 => 'DPL encoding', @@ -1949,7 +2161,12 @@ class getid3_mp3 return (isset($LAMEsurroundInfoLookup[$SurroundInfoID]) ? $LAMEsurroundInfoLookup[$SurroundInfoID] : 'reserved'); } - static function LAMEpresetUsedLookup($LAMEtag) { + /** + * @param array $LAMEtag + * + * @return string + */ + public static function LAMEpresetUsedLookup($LAMEtag) { if ($LAMEtag['preset_used_id'] == 0) { // no preset used (LAME >=3.93) @@ -2003,5 +2220,3 @@ class getid3_mp3 } } - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.audio.mpc.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.mpc.php similarity index 69% rename from serendipity_event_podcast/player/getid3/module.audio.mpc.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.mpc.php index 41f039cd..e869e29f 100644 --- a/serendipity_event_podcast/player/getid3/module.audio.mpc.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.mpc.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.audio.mpc.php // @@ -13,79 +14,88 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_mpc +class getid3_mpc extends getid3_handler { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_mpc(&$fd, &$ThisFileInfo) { - $ThisFileInfo['mpc']['header'] = array(); - $thisfile_mpc_header = &$ThisFileInfo['mpc']['header']; + $info['mpc']['header'] = array(); + $thisfile_mpc_header = &$info['mpc']['header']; - $ThisFileInfo['fileformat'] = 'mpc'; - $ThisFileInfo['audio']['dataformat'] = 'mpc'; - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; - $ThisFileInfo['audio']['channels'] = 2; // up to SV7 the format appears to have been hardcoded for stereo only - $ThisFileInfo['audio']['lossless'] = false; + $info['fileformat'] = 'mpc'; + $info['audio']['dataformat'] = 'mpc'; + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['channels'] = 2; // up to SV7 the format appears to have been hardcoded for stereo only + $info['audio']['lossless'] = false; - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $MPCheaderData = fread($fd, 4); - $ThisFileInfo['mpc']['header']['preamble'] = substr($MPCheaderData, 0, 4); // should be 'MPCK' (SV8) or 'MP+' (SV7), otherwise possible stream data (SV4-SV6) - if (preg_match('#^MPCK#', $ThisFileInfo['mpc']['header']['preamble'])) { + $this->fseek($info['avdataoffset']); + $MPCheaderData = $this->fread(4); + $info['mpc']['header']['preamble'] = substr($MPCheaderData, 0, 4); // should be 'MPCK' (SV8) or 'MP+' (SV7), otherwise possible stream data (SV4-SV6) + if (preg_match('#^MPCK#', $info['mpc']['header']['preamble'])) { // this is SV8 - return $this->ParseMPCsv8($fd, $ThisFileInfo); + return $this->ParseMPCsv8(); - } elseif (preg_match('#^MP\+#', $ThisFileInfo['mpc']['header']['preamble'])) { + } elseif (preg_match('#^MP\+#', $info['mpc']['header']['preamble'])) { // this is SV7 - return $this->ParseMPCsv7($fd, $ThisFileInfo); + return $this->ParseMPCsv7(); - } elseif (preg_match('/^[\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0]/s', $MPCheaderData)) { + } elseif (preg_match('#^[\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0]#s', $MPCheaderData)) { // this is SV4 - SV6, handle seperately - return $this->ParseMPCsv6($fd, $ThisFileInfo); + return $this->ParseMPCsv6(); } else { - $ThisFileInfo['error'][] = 'Expecting "MP+" or "MPCK" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($MPCheaderData, 0, 4).'"'; - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['mpc']); + $this->error('Expecting "MP+" or "MPCK" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($MPCheaderData, 0, 4)).'"'); + unset($info['fileformat']); + unset($info['mpc']); return false; } - return false; } - - function ParseMPCsv8(&$fd, &$ThisFileInfo) { + /** + * @return bool + */ + public function ParseMPCsv8() { // this is SV8 // http://trac.musepack.net/trac/wiki/SV8Specification - $thisfile_mpc_header = &$ThisFileInfo['mpc']['header']; + $info = &$this->getid3->info; + $thisfile_mpc_header = &$info['mpc']['header']; $keyNameSize = 2; $maxHandledPacketLength = 9; // specs say: "n*8; 0 < n < 10" - $offset = ftell($fd); - while ($offset < $ThisFileInfo['avdataend']) { + $offset = $this->ftell(); + while ($offset < $info['avdataend']) { $thisPacket = array(); $thisPacket['offset'] = $offset; $packet_offset = 0; // Size is a variable-size field, could be 1-4 bytes (possibly more?) // read enough data in and figure out the exact size later - $MPCheaderData = fread($fd, $keyNameSize + $maxHandledPacketLength); + $MPCheaderData = $this->fread($keyNameSize + $maxHandledPacketLength); $packet_offset += $keyNameSize; $thisPacket['key'] = substr($MPCheaderData, 0, $keyNameSize); $thisPacket['key_name'] = $this->MPCsv8PacketName($thisPacket['key']); if ($thisPacket['key'] == $thisPacket['key_name']) { - $ThisFileInfo['error'][] = 'Found unexpected key value "'.$thisPacket['key'].'" at offset '.$thisPacket['offset']; + $this->error('Found unexpected key value "'.$thisPacket['key'].'" at offset '.$thisPacket['offset']); return false; } $packetLength = 0; $thisPacket['packet_size'] = $this->SV8variableLengthInteger(substr($MPCheaderData, $keyNameSize), $packetLength); // includes keyname and packet_size field if ($thisPacket['packet_size'] === false) { - $ThisFileInfo['error'][] = 'Did not find expected packet length within '.$maxHandledPacketLength.' bytes at offset '.($thisPacket['offset'] + $keyNameSize); + $this->error('Did not find expected packet length within '.$maxHandledPacketLength.' bytes at offset '.($thisPacket['offset'] + $keyNameSize)); return false; } $packet_offset += $packetLength; @@ -95,7 +105,7 @@ class getid3_mpc case 'SH': // Stream Header $moreBytesToRead = $thisPacket['packet_size'] - $keyNameSize - $maxHandledPacketLength; if ($moreBytesToRead > 0) { - $MPCheaderData .= fread($fd, $moreBytesToRead); + $MPCheaderData .= $this->fread($moreBytesToRead); } $thisPacket['crc'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 4)); $packet_offset += 4; @@ -124,16 +134,16 @@ class getid3_mpc $thisfile_mpc_header['samples'] = $thisPacket['sample_count']; $thisfile_mpc_header['stream_version_major'] = $thisPacket['stream_version']; - $ThisFileInfo['audio']['channels'] = $thisPacket['channels']; - $ThisFileInfo['audio']['sample_rate'] = $thisPacket['sample_frequency']; - $ThisFileInfo['playtime_seconds'] = $thisPacket['sample_count'] / $thisPacket['sample_frequency']; - $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; + $info['audio']['channels'] = $thisPacket['channels']; + $info['audio']['sample_rate'] = $thisPacket['sample_frequency']; + $info['playtime_seconds'] = $thisPacket['sample_count'] / $thisPacket['sample_frequency']; + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; break; case 'RG': // Replay Gain $moreBytesToRead = $thisPacket['packet_size'] - $keyNameSize - $maxHandledPacketLength; if ($moreBytesToRead > 0) { - $MPCheaderData .= fread($fd, $moreBytesToRead); + $MPCheaderData .= $this->fread($moreBytesToRead); } $thisPacket['replaygain_version'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1)); $packet_offset += 1; @@ -146,16 +156,16 @@ class getid3_mpc $thisPacket['replaygain_album_peak'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2)); $packet_offset += 2; - if ($thisPacket['replaygain_title_gain']) { $ThisFileInfo['replay_gain']['title']['gain'] = $thisPacket['replaygain_title_gain']; } - if ($thisPacket['replaygain_title_peak']) { $ThisFileInfo['replay_gain']['title']['peak'] = $thisPacket['replaygain_title_peak']; } - if ($thisPacket['replaygain_album_gain']) { $ThisFileInfo['replay_gain']['album']['gain'] = $thisPacket['replaygain_album_gain']; } - if ($thisPacket['replaygain_album_peak']) { $ThisFileInfo['replay_gain']['album']['peak'] = $thisPacket['replaygain_album_peak']; } + if ($thisPacket['replaygain_title_gain']) { $info['replay_gain']['title']['gain'] = $thisPacket['replaygain_title_gain']; } + if ($thisPacket['replaygain_title_peak']) { $info['replay_gain']['title']['peak'] = $thisPacket['replaygain_title_peak']; } + if ($thisPacket['replaygain_album_gain']) { $info['replay_gain']['album']['gain'] = $thisPacket['replaygain_album_gain']; } + if ($thisPacket['replaygain_album_peak']) { $info['replay_gain']['album']['peak'] = $thisPacket['replaygain_album_peak']; } break; case 'EI': // Encoder Info $moreBytesToRead = $thisPacket['packet_size'] - $keyNameSize - $maxHandledPacketLength; if ($moreBytesToRead > 0) { - $MPCheaderData .= fread($fd, $moreBytesToRead); + $MPCheaderData .= $this->fread($moreBytesToRead); } $profile_pns = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1)); $packet_offset += 1; @@ -171,8 +181,8 @@ class getid3_mpc $packet_offset += 1; $thisPacket['version'] = $thisPacket['version_major'].'.'.$thisPacket['version_minor'].'.'.$thisPacket['version_build']; - $ThisFileInfo['audio']['encoder'] = 'MPC v'.$thisPacket['version'].' ('.(($thisPacket['version_minor'] % 2) ? 'unstable' : 'stable').')'; - $thisfile_mpc_header['encoder_version'] = $ThisFileInfo['audio']['encoder']; + $info['audio']['encoder'] = 'MPC v'.$thisPacket['version'].' ('.(($thisPacket['version_minor'] % 2) ? 'unstable' : 'stable').')'; + $thisfile_mpc_header['encoder_version'] = $info['audio']['encoder']; //$thisfile_mpc_header['quality'] = (float) ($thisPacket['quality'] / 1.5875); // values can range from 0.000 to 15.875, mapped to qualities of 0.0 to 10.0 $thisfile_mpc_header['quality'] = (float) ($thisPacket['quality'] - 5); // values can range from 0.000 to 15.875, of which 0..4 are "reserved/experimental", and 5..15 are mapped to qualities of 0.0 to 10.0 break; @@ -191,28 +201,32 @@ class getid3_mpc break; default: - $ThisFileInfo['error'][] = 'Found unhandled key type "'.$thisPacket['key'].'" at offset '.$thisPacket['offset']; + $this->error('Found unhandled key type "'.$thisPacket['key'].'" at offset '.$thisPacket['offset']); return false; - break; } if (!empty($thisPacket)) { - $ThisFileInfo['mpc']['packets'][] = $thisPacket; + $info['mpc']['packets'][] = $thisPacket; } - fseek($fd, $offset); + $this->fseek($offset); } $thisfile_mpc_header['size'] = $offset; return true; } - function ParseMPCsv7(&$fd, &$ThisFileInfo) { + /** + * @return bool + */ + public function ParseMPCsv7() { // this is SV7 // http://www.uni-jena.de/~pfk/mpp/sv8/header.html - $thisfile_mpc_header = &$ThisFileInfo['mpc']['header']; + + $info = &$this->getid3->info; + $thisfile_mpc_header = &$info['mpc']['header']; $offset = 0; $thisfile_mpc_header['size'] = 28; - $MPCheaderData = $ThisFileInfo['mpc']['header']['preamble']; - $MPCheaderData .= fread($fd, $thisfile_mpc_header['size'] - strlen($ThisFileInfo['mpc']['header']['preamble'])); + $MPCheaderData = $info['mpc']['header']['preamble']; + $MPCheaderData .= $this->fread($thisfile_mpc_header['size'] - strlen($info['mpc']['header']['preamble'])); $offset = strlen('MP+'); $StreamVersionByte = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 1)); @@ -223,7 +237,7 @@ class getid3_mpc $offset += 4; if ($thisfile_mpc_header['stream_version_major'] != 7) { - $ThisFileInfo['error'][] = 'Only Musepack SV7 supported (this file claims to be v'.$thisfile_mpc_header['stream_version_major'].')'; + $this->error('Only Musepack SV7 supported (this file claims to be v'.$thisfile_mpc_header['stream_version_major'].')'); return false; } @@ -262,22 +276,22 @@ class getid3_mpc $thisfile_mpc_header['profile'] = $this->MPCprofileNameLookup($thisfile_mpc_header['raw']['profile']); $thisfile_mpc_header['sample_rate'] = $this->MPCfrequencyLookup($thisfile_mpc_header['raw']['sample_rate']); if ($thisfile_mpc_header['sample_rate'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt MPC file: frequency == zero'; + $this->error('Corrupt MPC file: frequency == zero'); return false; } - $ThisFileInfo['audio']['sample_rate'] = $thisfile_mpc_header['sample_rate']; - $thisfile_mpc_header['samples'] = ((($thisfile_mpc_header['frame_count'] - 1) * 1152) + $thisfile_mpc_header['last_frame_length']) * $ThisFileInfo['audio']['channels']; + $info['audio']['sample_rate'] = $thisfile_mpc_header['sample_rate']; + $thisfile_mpc_header['samples'] = ((($thisfile_mpc_header['frame_count'] - 1) * 1152) + $thisfile_mpc_header['last_frame_length']) * $info['audio']['channels']; - $ThisFileInfo['playtime_seconds'] = ($thisfile_mpc_header['samples'] / $ThisFileInfo['audio']['channels']) / $ThisFileInfo['audio']['sample_rate']; - if ($ThisFileInfo['playtime_seconds'] == 0) { - $ThisFileInfo['error'][] = 'Corrupt MPC file: playtime_seconds == zero'; + $info['playtime_seconds'] = ($thisfile_mpc_header['samples'] / $info['audio']['channels']) / $info['audio']['sample_rate']; + if ($info['playtime_seconds'] == 0) { + $this->error('Corrupt MPC file: playtime_seconds == zero'); return false; } // add size of file header to avdataoffset - calc bitrate correctly + MD5 data - $ThisFileInfo['avdataoffset'] += $thisfile_mpc_header['size']; + $info['avdataoffset'] += $thisfile_mpc_header['size']; - $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; $thisfile_mpc_header['title_peak'] = $thisfile_mpc_header['raw']['title_peak']; $thisfile_mpc_header['title_peak_db'] = $this->MPCpeakDBLookup($thisfile_mpc_header['title_peak']); @@ -296,39 +310,45 @@ class getid3_mpc } $thisfile_mpc_header['encoder_version'] = $this->MPCencoderVersionLookup($thisfile_mpc_header['raw']['encoder_version']); - $ThisFileInfo['replay_gain']['track']['adjustment'] = $thisfile_mpc_header['title_gain_db']; - $ThisFileInfo['replay_gain']['album']['adjustment'] = $thisfile_mpc_header['album_gain_db']; + $info['replay_gain']['track']['adjustment'] = $thisfile_mpc_header['title_gain_db']; + $info['replay_gain']['album']['adjustment'] = $thisfile_mpc_header['album_gain_db']; if ($thisfile_mpc_header['title_peak'] > 0) { - $ThisFileInfo['replay_gain']['track']['peak'] = $thisfile_mpc_header['title_peak']; + $info['replay_gain']['track']['peak'] = $thisfile_mpc_header['title_peak']; } elseif (round($thisfile_mpc_header['max_level'] * 1.18) > 0) { - $ThisFileInfo['replay_gain']['track']['peak'] = getid3_lib::CastAsInt(round($thisfile_mpc_header['max_level'] * 1.18)); // why? I don't know - see mppdec.c + $info['replay_gain']['track']['peak'] = getid3_lib::CastAsInt(round($thisfile_mpc_header['max_level'] * 1.18)); // why? I don't know - see mppdec.c } if ($thisfile_mpc_header['album_peak'] > 0) { - $ThisFileInfo['replay_gain']['album']['peak'] = $thisfile_mpc_header['album_peak']; + $info['replay_gain']['album']['peak'] = $thisfile_mpc_header['album_peak']; } - //$ThisFileInfo['audio']['encoder'] = 'SV'.$thisfile_mpc_header['stream_version_major'].'.'.$thisfile_mpc_header['stream_version_minor'].', '.$thisfile_mpc_header['encoder_version']; - $ThisFileInfo['audio']['encoder'] = $thisfile_mpc_header['encoder_version']; - $ThisFileInfo['audio']['encoder_options'] = $thisfile_mpc_header['profile']; + //$info['audio']['encoder'] = 'SV'.$thisfile_mpc_header['stream_version_major'].'.'.$thisfile_mpc_header['stream_version_minor'].', '.$thisfile_mpc_header['encoder_version']; + $info['audio']['encoder'] = $thisfile_mpc_header['encoder_version']; + $info['audio']['encoder_options'] = $thisfile_mpc_header['profile']; $thisfile_mpc_header['quality'] = (float) ($thisfile_mpc_header['raw']['profile'] - 5); // values can range from 0 to 15, of which 0..4 are "reserved/experimental", and 5..15 are mapped to qualities of 0.0 to 10.0 return true; } - function ParseMPCsv6(&$fd, &$ThisFileInfo) { + /** + * @return bool + */ + public function ParseMPCsv6() { // this is SV4 - SV6 - $thisfile_mpc_header = &$ThisFileInfo['mpc']['header']; + + $info = &$this->getid3->info; + $thisfile_mpc_header = &$info['mpc']['header']; $offset = 0; $thisfile_mpc_header['size'] = 8; - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $MPCheaderData = fread($fd, $thisfile_mpc_header['size']); + $this->fseek($info['avdataoffset']); + $MPCheaderData = $this->fread($thisfile_mpc_header['size']); // add size of file header to avdataoffset - calc bitrate correctly + MD5 data - $ThisFileInfo['avdataoffset'] += $thisfile_mpc_header['size']; + $info['avdataoffset'] += $thisfile_mpc_header['size']; // Most of this code adapted from Jurgen Faul's MPEGplus source code - thanks Jurgen! :) + $HeaderDWORD = array(); $HeaderDWORD[0] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, 0, 4)); $HeaderDWORD[1] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, 4, 4)); @@ -362,35 +382,38 @@ class getid3_mpc break; default: - $ThisFileInfo['error'] = 'Expecting 4, 5 or 6 in version field, found '.$thisfile_mpc_header['stream_version_major'].' instead'; - unset($ThisFileInfo['mpc']); + $info['error'] = 'Expecting 4, 5 or 6 in version field, found '.$thisfile_mpc_header['stream_version_major'].' instead'; + unset($info['mpc']); return false; - break; } if (($thisfile_mpc_header['stream_version_major'] > 4) && ($thisfile_mpc_header['block_size'] != 1)) { - $ThisFileInfo['warning'][] = 'Block size expected to be 1, actual value found: '.$thisfile_mpc_header['block_size']; + $this->warning('Block size expected to be 1, actual value found: '.$thisfile_mpc_header['block_size']); } $thisfile_mpc_header['sample_rate'] = 44100; // AB: used by all files up to SV7 - $ThisFileInfo['audio']['sample_rate'] = $thisfile_mpc_header['sample_rate']; - $thisfile_mpc_header['samples'] = $thisfile_mpc_header['frame_count'] * 1152 * $ThisFileInfo['audio']['channels']; + $info['audio']['sample_rate'] = $thisfile_mpc_header['sample_rate']; + $thisfile_mpc_header['samples'] = $thisfile_mpc_header['frame_count'] * 1152 * $info['audio']['channels']; if ($thisfile_mpc_header['target_bitrate'] == 0) { - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['bitrate_mode'] = 'vbr'; } else { - $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; + $info['audio']['bitrate_mode'] = 'cbr'; } - $ThisFileInfo['mpc']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 * 44100 / $thisfile_mpc_header['frame_count'] / 1152; - $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['mpc']['bitrate']; - $ThisFileInfo['audio']['encoder'] = 'SV'.$thisfile_mpc_header['stream_version_major']; + $info['mpc']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * 8 * 44100 / $thisfile_mpc_header['frame_count'] / 1152; + $info['audio']['bitrate'] = $info['mpc']['bitrate']; + $info['audio']['encoder'] = 'SV'.$thisfile_mpc_header['stream_version_major']; return true; } - - function MPCprofileNameLookup($profileid) { + /** + * @param int $profileid + * + * @return string + */ + public function MPCprofileNameLookup($profileid) { static $MPCprofileNameLookup = array( 0 => 'no profile', 1 => 'Experimental', @@ -412,7 +435,12 @@ class getid3_mpc return (isset($MPCprofileNameLookup[$profileid]) ? $MPCprofileNameLookup[$profileid] : 'invalid'); } - function MPCfrequencyLookup($frequencyid) { + /** + * @param int $frequencyid + * + * @return int|string + */ + public function MPCfrequencyLookup($frequencyid) { static $MPCfrequencyLookup = array( 0 => 44100, 1 => 48000, @@ -422,14 +450,24 @@ class getid3_mpc return (isset($MPCfrequencyLookup[$frequencyid]) ? $MPCfrequencyLookup[$frequencyid] : 'invalid'); } - function MPCpeakDBLookup($intvalue) { + /** + * @param int $intvalue + * + * @return float|false + */ + public function MPCpeakDBLookup($intvalue) { if ($intvalue > 0) { return ((log10($intvalue) / log10(2)) - 15) * 6; } return false; } - function MPCencoderVersionLookup($encoderversion) { + /** + * @param int $encoderversion + * + * @return string + */ + public function MPCencoderVersionLookup($encoderversion) { //Encoder version * 100 (106 = 1.06) //EncoderVersion % 10 == 0 Release (1.0) //EncoderVersion % 2 == 0 Beta (1.06) @@ -456,7 +494,14 @@ class getid3_mpc return number_format($encoderversion / 100, 2).' alpha'; } - function SV8variableLengthInteger($data, &$packetLength, $maxHandledPacketLength=9) { + /** + * @param string $data + * @param int $packetLength + * @param int $maxHandledPacketLength + * + * @return int|false + */ + public function SV8variableLengthInteger($data, &$packetLength, $maxHandledPacketLength=9) { $packet_size = 0; for ($packetLength = 1; $packetLength <= $maxHandledPacketLength; $packetLength++) { // variable-length size field: @@ -480,7 +525,12 @@ class getid3_mpc return $packet_size; } - function MPCsv8PacketName($packetKey) { + /** + * @param string $packetKey + * + * @return string + */ + public function MPCsv8PacketName($packetKey) { static $MPCsv8PacketName = array(); if (empty($MPCsv8PacketName)) { $MPCsv8PacketName = array( @@ -497,6 +547,3 @@ class getid3_mpc return (isset($MPCsv8PacketName[$packetKey]) ? $MPCsv8PacketName[$packetKey] : $packetKey); } } - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.ogg.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.ogg.php new file mode 100644 index 00000000..0cbea61e --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.ogg.php @@ -0,0 +1,925 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.ogg.php // +// module for analyzing Ogg Vorbis, OggFLAC and Speex files // +// dependencies: module.audio.flac.php // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.flac.php', __FILE__, true); + +class getid3_ogg extends getid3_handler +{ + /** + * @link http://xiph.org/vorbis/doc/Vorbis_I_spec.html + * + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'ogg'; + + // Warn about illegal tags - only vorbiscomments are allowed + if (isset($info['id3v2'])) { + $this->warning('Illegal ID3v2 tag present.'); + } + if (isset($info['id3v1'])) { + $this->warning('Illegal ID3v1 tag present.'); + } + if (isset($info['ape'])) { + $this->warning('Illegal APE tag present.'); + } + + + // Page 1 - Stream Header + + $this->fseek($info['avdataoffset']); + + $oggpageinfo = $this->ParseOggPageHeader(); + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; + + if ($this->ftell() >= $this->getid3->fread_buffer_size()) { + $this->error('Could not find start of Ogg page in the first '.$this->getid3->fread_buffer_size().' bytes (this might not be an Ogg-Vorbis file?)'); + unset($info['fileformat']); + unset($info['ogg']); + return false; + } + + $filedata = $this->fread($oggpageinfo['page_length']); + $filedataoffset = 0; + + if (substr($filedata, 0, 4) == 'fLaC') { + + $info['audio']['dataformat'] = 'flac'; + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['lossless'] = true; + + } elseif (substr($filedata, 1, 6) == 'vorbis') { + + $this->ParseVorbisPageHeader($filedata, $filedataoffset, $oggpageinfo); + + } elseif (substr($filedata, 0, 8) == 'OpusHead') { + + if ($this->ParseOpusPageHeader($filedata, $filedataoffset, $oggpageinfo) === false) { + return false; + } + + } elseif (substr($filedata, 0, 8) == 'Speex ') { + + // http://www.speex.org/manual/node10.html + + $info['audio']['dataformat'] = 'speex'; + $info['mime_type'] = 'audio/speex'; + $info['audio']['bitrate_mode'] = 'abr'; + $info['audio']['lossless'] = false; + + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_string'] = substr($filedata, $filedataoffset, 8); // hard-coded to 'Speex ' + $filedataoffset += 8; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version'] = substr($filedata, $filedataoffset, 20); + $filedataoffset += 20; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version_id'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['header_size'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['rate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode_bitstream_version'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['nb_channels'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['bitrate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['framesize'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['vbr'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['frames_per_packet'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['extra_headers'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['reserved1'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['reserved2'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + + $info['speex']['speex_version'] = trim($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['speex_version']); + $info['speex']['sample_rate'] = $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['rate']; + $info['speex']['channels'] = $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['nb_channels']; + $info['speex']['vbr'] = (bool) $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['vbr']; + $info['speex']['band_type'] = $this->SpeexBandModeLookup($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['mode']); + + $info['audio']['sample_rate'] = $info['speex']['sample_rate']; + $info['audio']['channels'] = $info['speex']['channels']; + if ($info['speex']['vbr']) { + $info['audio']['bitrate_mode'] = 'vbr'; + } + + } elseif (substr($filedata, 0, 7) == "\x80".'theora') { + + // http://www.theora.org/doc/Theora.pdf (section 6.2) + + $info['ogg']['pageheader']['theora']['theora_magic'] = substr($filedata, $filedataoffset, 7); // hard-coded to "\x80.'theora' + $filedataoffset += 7; + $info['ogg']['pageheader']['theora']['version_major'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['pageheader']['theora']['version_minor'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['pageheader']['theora']['version_revision'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['pageheader']['theora']['frame_width_macroblocks'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2)); + $filedataoffset += 2; + $info['ogg']['pageheader']['theora']['frame_height_macroblocks'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2)); + $filedataoffset += 2; + $info['ogg']['pageheader']['theora']['resolution_x'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); + $filedataoffset += 3; + $info['ogg']['pageheader']['theora']['resolution_y'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); + $filedataoffset += 3; + $info['ogg']['pageheader']['theora']['picture_offset_x'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['pageheader']['theora']['picture_offset_y'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['pageheader']['theora']['frame_rate_numerator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader']['theora']['frame_rate_denominator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); + $filedataoffset += 3; + $info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); + $filedataoffset += 3; + $info['ogg']['pageheader']['theora']['color_space_id'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['pageheader']['theora']['nominal_bitrate'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 3)); + $filedataoffset += 3; + $info['ogg']['pageheader']['theora']['flags'] = getid3_lib::BigEndian2Int(substr($filedata, $filedataoffset, 2)); + $filedataoffset += 2; + + $info['ogg']['pageheader']['theora']['quality'] = ($info['ogg']['pageheader']['theora']['flags'] & 0xFC00) >> 10; + $info['ogg']['pageheader']['theora']['kfg_shift'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x03E0) >> 5; + $info['ogg']['pageheader']['theora']['pixel_format_id'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x0018) >> 3; + $info['ogg']['pageheader']['theora']['reserved'] = ($info['ogg']['pageheader']['theora']['flags'] & 0x0007) >> 0; // should be 0 + $info['ogg']['pageheader']['theora']['color_space'] = self::TheoraColorSpace($info['ogg']['pageheader']['theora']['color_space_id']); + $info['ogg']['pageheader']['theora']['pixel_format'] = self::TheoraPixelFormat($info['ogg']['pageheader']['theora']['pixel_format_id']); + + $info['video']['dataformat'] = 'theora'; + $info['mime_type'] = 'video/ogg'; + //$info['audio']['bitrate_mode'] = 'abr'; + //$info['audio']['lossless'] = false; + $info['video']['resolution_x'] = $info['ogg']['pageheader']['theora']['resolution_x']; + $info['video']['resolution_y'] = $info['ogg']['pageheader']['theora']['resolution_y']; + if ($info['ogg']['pageheader']['theora']['frame_rate_denominator'] > 0) { + $info['video']['frame_rate'] = (float) $info['ogg']['pageheader']['theora']['frame_rate_numerator'] / $info['ogg']['pageheader']['theora']['frame_rate_denominator']; + } + if ($info['ogg']['pageheader']['theora']['pixel_aspect_denominator'] > 0) { + $info['video']['pixel_aspect_ratio'] = (float) $info['ogg']['pageheader']['theora']['pixel_aspect_numerator'] / $info['ogg']['pageheader']['theora']['pixel_aspect_denominator']; + } +$this->warning('Ogg Theora (v3) not fully supported in this version of getID3 ['.$this->getid3->version().'] -- bitrate, playtime and all audio data are currently unavailable'); + + + } elseif (substr($filedata, 0, 8) == "fishead\x00") { + + // Ogg Skeleton version 3.0 Format Specification + // http://xiph.org/ogg/doc/skeleton.html + $filedataoffset += 8; + $info['ogg']['skeleton']['fishead']['raw']['version_major'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2)); + $filedataoffset += 2; + $info['ogg']['skeleton']['fishead']['raw']['version_minor'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2)); + $filedataoffset += 2; + $info['ogg']['skeleton']['fishead']['raw']['presentationtime_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $info['ogg']['skeleton']['fishead']['raw']['presentationtime_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $info['ogg']['skeleton']['fishead']['raw']['basetime_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $info['ogg']['skeleton']['fishead']['raw']['basetime_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $info['ogg']['skeleton']['fishead']['raw']['utc'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 20)); + $filedataoffset += 20; + + $info['ogg']['skeleton']['fishead']['version'] = $info['ogg']['skeleton']['fishead']['raw']['version_major'].'.'.$info['ogg']['skeleton']['fishead']['raw']['version_minor']; + $info['ogg']['skeleton']['fishead']['presentationtime'] = $info['ogg']['skeleton']['fishead']['raw']['presentationtime_numerator'] / $info['ogg']['skeleton']['fishead']['raw']['presentationtime_denominator']; + $info['ogg']['skeleton']['fishead']['basetime'] = $info['ogg']['skeleton']['fishead']['raw']['basetime_numerator'] / $info['ogg']['skeleton']['fishead']['raw']['basetime_denominator']; + $info['ogg']['skeleton']['fishead']['utc'] = $info['ogg']['skeleton']['fishead']['raw']['utc']; + + + $counter = 0; + do { + $oggpageinfo = $this->ParseOggPageHeader(); + $info['ogg']['pageheader'][$oggpageinfo['page_seqno'].'.'.$counter++] = $oggpageinfo; + $filedata = $this->fread($oggpageinfo['page_length']); + $this->fseek($oggpageinfo['page_end_offset']); + + if (substr($filedata, 0, 8) == "fisbone\x00") { + + $filedataoffset = 8; + $info['ogg']['skeleton']['fisbone']['raw']['message_header_offset'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['skeleton']['fisbone']['raw']['serial_number'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['skeleton']['fisbone']['raw']['number_header_packets'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['skeleton']['fisbone']['raw']['granulerate_numerator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $info['ogg']['skeleton']['fisbone']['raw']['granulerate_denominator'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $info['ogg']['skeleton']['fisbone']['raw']['basegranule'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $info['ogg']['skeleton']['fisbone']['raw']['preroll'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['skeleton']['fisbone']['raw']['granuleshift'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['skeleton']['fisbone']['raw']['padding'] = substr($filedata, $filedataoffset, 3); + $filedataoffset += 3; + + } elseif (substr($filedata, 1, 6) == 'theora') { + + $info['video']['dataformat'] = 'theora1'; + $this->error('Ogg Theora (v1) not correctly handled in this version of getID3 ['.$this->getid3->version().']'); + //break; + + } elseif (substr($filedata, 1, 6) == 'vorbis') { + + $this->ParseVorbisPageHeader($filedata, $filedataoffset, $oggpageinfo); + + } else { + $this->error('unexpected'); + //break; + } + //} while ($oggpageinfo['page_seqno'] == 0); + } while (($oggpageinfo['page_seqno'] == 0) && (substr($filedata, 0, 8) != "fisbone\x00")); + + $this->fseek($oggpageinfo['page_start_offset']); + + $this->error('Ogg Skeleton not correctly handled in this version of getID3 ['.$this->getid3->version().']'); + //return false; + + } elseif (substr($filedata, 0, 5) == "\x7F".'FLAC') { + // https://xiph.org/flac/ogg_mapping.html + + $info['audio']['dataformat'] = 'flac'; + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['lossless'] = true; + + $info['ogg']['flac']['header']['version_major'] = ord(substr($filedata, 5, 1)); + $info['ogg']['flac']['header']['version_minor'] = ord(substr($filedata, 6, 1)); + $info['ogg']['flac']['header']['header_packets'] = getid3_lib::BigEndian2Int(substr($filedata, 7, 2)) + 1; // "A two-byte, big-endian binary number signifying the number of header (non-audio) packets, not including this one. This number may be zero (0x0000) to signify 'unknown' but be aware that some decoders may not be able to handle such streams." + $info['ogg']['flac']['header']['magic'] = substr($filedata, 9, 4); + if ($info['ogg']['flac']['header']['magic'] != 'fLaC') { + $this->error('Ogg-FLAC expecting "fLaC", found "'.$info['ogg']['flac']['header']['magic'].'" ('.trim(getid3_lib::PrintHexBytes($info['ogg']['flac']['header']['magic'])).')'); + return false; + } + $info['ogg']['flac']['header']['STREAMINFO_bytes'] = getid3_lib::BigEndian2Int(substr($filedata, 13, 4)); + $info['flac']['STREAMINFO'] = getid3_flac::parseSTREAMINFOdata(substr($filedata, 17, 34)); + if (!empty($info['flac']['STREAMINFO']['sample_rate'])) { + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['sample_rate'] = $info['flac']['STREAMINFO']['sample_rate']; + $info['audio']['channels'] = $info['flac']['STREAMINFO']['channels']; + $info['audio']['bits_per_sample'] = $info['flac']['STREAMINFO']['bits_per_sample']; + $info['playtime_seconds'] = $info['flac']['STREAMINFO']['samples_stream'] / $info['flac']['STREAMINFO']['sample_rate']; + } + + } else { + + $this->error('Expecting one of "vorbis", "Speex", "OpusHead", "vorbis", "fishhead", "theora", "fLaC" identifier strings, found "'.substr($filedata, 0, 8).'"'); + unset($info['ogg']); + unset($info['mime_type']); + return false; + + } + + // Page 2 - Comment Header + $oggpageinfo = $this->ParseOggPageHeader(); + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; + + switch ($info['audio']['dataformat']) { + case 'vorbis': + $filedata = $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int(substr($filedata, 0, 1)); + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, 1, 6); // hard-coded to 'vorbis' + + $this->ParseVorbisComments(); + break; + + case 'flac': + $flac = new getid3_flac($this->getid3); + if (!$flac->parseMETAdata()) { + $this->error('Failed to parse FLAC headers'); + return false; + } + unset($flac); + break; + + case 'speex': + $this->fseek($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length'], SEEK_CUR); + $this->ParseVorbisComments(); + break; + + case 'opus': + $filedata = $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, 0, 8); // hard-coded to 'OpusTags' + if(substr($filedata, 0, 8) != 'OpusTags') { + $this->error('Expected "OpusTags" as header but got "'.substr($filedata, 0, 8).'"'); + return false; + } + + $this->ParseVorbisComments(); + break; + + } + + // Last Page - Number of Samples + if (!getid3_lib::intValueSupported($info['avdataend'])) { + + $this->warning('Unable to parse Ogg end chunk file (PHP does not support file operations beyond '.round(PHP_INT_MAX / 1073741824).'GB)'); + + } else { + + $this->fseek(max($info['avdataend'] - $this->getid3->fread_buffer_size(), 0)); + $LastChunkOfOgg = strrev($this->fread($this->getid3->fread_buffer_size())); + if ($LastOggSpostion = strpos($LastChunkOfOgg, 'SggO')) { + $this->fseek($info['avdataend'] - ($LastOggSpostion + strlen('SggO'))); + $info['avdataend'] = $this->ftell(); + $info['ogg']['pageheader']['eos'] = $this->ParseOggPageHeader(); + $info['ogg']['samples'] = $info['ogg']['pageheader']['eos']['pcm_abs_position']; + if ($info['ogg']['samples'] == 0) { + $this->error('Corrupt Ogg file: eos.number of samples == zero'); + return false; + } + if (!empty($info['audio']['sample_rate'])) { + $info['ogg']['bitrate_average'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / ($info['ogg']['samples'] / $info['audio']['sample_rate']); + } + } + + } + + if (!empty($info['ogg']['bitrate_average'])) { + $info['audio']['bitrate'] = $info['ogg']['bitrate_average']; + } elseif (!empty($info['ogg']['bitrate_nominal'])) { + $info['audio']['bitrate'] = $info['ogg']['bitrate_nominal']; + } elseif (!empty($info['ogg']['bitrate_min']) && !empty($info['ogg']['bitrate_max'])) { + $info['audio']['bitrate'] = ($info['ogg']['bitrate_min'] + $info['ogg']['bitrate_max']) / 2; + } + if (isset($info['audio']['bitrate']) && !isset($info['playtime_seconds'])) { + if ($info['audio']['bitrate'] == 0) { + $this->error('Corrupt Ogg file: bitrate_audio == zero'); + return false; + } + $info['playtime_seconds'] = (float) ((($info['avdataend'] - $info['avdataoffset']) * 8) / $info['audio']['bitrate']); + } + + if (isset($info['ogg']['vendor'])) { + $info['audio']['encoder'] = preg_replace('/^Encoded with /', '', $info['ogg']['vendor']); + + // Vorbis only + if ($info['audio']['dataformat'] == 'vorbis') { + + // Vorbis 1.0 starts with Xiph.Org + if (preg_match('/^Xiph.Org/', $info['audio']['encoder'])) { + + if ($info['audio']['bitrate_mode'] == 'abr') { + + // Set -b 128 on abr files + $info['audio']['encoder_options'] = '-b '.round($info['ogg']['bitrate_nominal'] / 1000); + + } elseif (($info['audio']['bitrate_mode'] == 'vbr') && ($info['audio']['channels'] == 2) && ($info['audio']['sample_rate'] >= 44100) && ($info['audio']['sample_rate'] <= 48000)) { + // Set -q N on vbr files + $info['audio']['encoder_options'] = '-q '.$this->get_quality_from_nominal_bitrate($info['ogg']['bitrate_nominal']); + + } + } + + if (empty($info['audio']['encoder_options']) && !empty($info['ogg']['bitrate_nominal'])) { + $info['audio']['encoder_options'] = 'Nominal bitrate: '.intval(round($info['ogg']['bitrate_nominal'] / 1000)).'kbps'; + } + } + } + + return true; + } + + /** + * @param string $filedata + * @param int $filedataoffset + * @param array $oggpageinfo + * + * @return bool + */ + public function ParseVorbisPageHeader(&$filedata, &$filedataoffset, &$oggpageinfo) { + $info = &$this->getid3->info; + $info['audio']['dataformat'] = 'vorbis'; + $info['audio']['lossless'] = false; + + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['packet_type'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['stream_type'] = substr($filedata, $filedataoffset, 6); // hard-coded to 'vorbis' + $filedataoffset += 6; + $info['ogg']['bitstreamversion'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['numberofchannels'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $info['audio']['channels'] = $info['ogg']['numberofchannels']; + $info['ogg']['samplerate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + if ($info['ogg']['samplerate'] == 0) { + $this->error('Corrupt Ogg file: sample rate == zero'); + return false; + } + $info['audio']['sample_rate'] = $info['ogg']['samplerate']; + $info['ogg']['samples'] = 0; // filled in later + $info['ogg']['bitrate_average'] = 0; // filled in later + $info['ogg']['bitrate_max'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['bitrate_nominal'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['bitrate_min'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $info['ogg']['blocksize_small'] = pow(2, getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)) & 0x0F); + $info['ogg']['blocksize_large'] = pow(2, (getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)) & 0xF0) >> 4); + $info['ogg']['stop_bit'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); // must be 1, marks end of packet + + $info['audio']['bitrate_mode'] = 'vbr'; // overridden if actually abr + if ($info['ogg']['bitrate_max'] == 0xFFFFFFFF) { + unset($info['ogg']['bitrate_max']); + $info['audio']['bitrate_mode'] = 'abr'; + } + if ($info['ogg']['bitrate_nominal'] == 0xFFFFFFFF) { + unset($info['ogg']['bitrate_nominal']); + } + if ($info['ogg']['bitrate_min'] == 0xFFFFFFFF) { + unset($info['ogg']['bitrate_min']); + $info['audio']['bitrate_mode'] = 'abr'; + } + return true; + } + + /** + * @link http://tools.ietf.org/html/draft-ietf-codec-oggopus-03 + * + * @param string $filedata + * @param int $filedataoffset + * @param array $oggpageinfo + * + * @return bool + */ + public function ParseOpusPageHeader(&$filedata, &$filedataoffset, &$oggpageinfo) { + $info = &$this->getid3->info; + $info['audio']['dataformat'] = 'opus'; + $info['mime_type'] = 'audio/ogg; codecs=opus'; + + /** @todo find a usable way to detect abr (vbr that is padded to be abr) */ + $info['audio']['bitrate_mode'] = 'vbr'; + + $info['audio']['lossless'] = false; + + $info['ogg']['pageheader']['opus']['opus_magic'] = substr($filedata, $filedataoffset, 8); // hard-coded to 'OpusHead' + $filedataoffset += 8; + $info['ogg']['pageheader']['opus']['version'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + + if ($info['ogg']['pageheader']['opus']['version'] < 1 || $info['ogg']['pageheader']['opus']['version'] > 15) { + $this->error('Unknown opus version number (only accepting 1-15)'); + return false; + } + + $info['ogg']['pageheader']['opus']['out_channel_count'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + + if ($info['ogg']['pageheader']['opus']['out_channel_count'] == 0) { + $this->error('Invalid channel count in opus header (must not be zero)'); + return false; + } + + $info['ogg']['pageheader']['opus']['pre_skip'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2)); + $filedataoffset += 2; + + $info['ogg']['pageheader']['opus']['input_sample_rate'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + + //$info['ogg']['pageheader']['opus']['output_gain'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 2)); + //$filedataoffset += 2; + + //$info['ogg']['pageheader']['opus']['channel_mapping_family'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + //$filedataoffset += 1; + + $info['opus']['opus_version'] = $info['ogg']['pageheader']['opus']['version']; + $info['opus']['sample_rate_input'] = $info['ogg']['pageheader']['opus']['input_sample_rate']; + $info['opus']['out_channel_count'] = $info['ogg']['pageheader']['opus']['out_channel_count']; + + $info['audio']['channels'] = $info['opus']['out_channel_count']; + $info['audio']['sample_rate_input'] = $info['opus']['sample_rate_input']; + $info['audio']['sample_rate'] = 48000; // "All Opus audio is coded at 48 kHz, and should also be decoded at 48 kHz for playback (unless the target hardware does not support this sampling rate). However, this field may be used to resample the audio back to the original sampling rate, for example, when saving the output to a file." -- https://mf4.xiph.org/jenkins/view/opus/job/opusfile-unix/ws/doc/html/structOpusHead.html + return true; + } + + /** + * @return array|false + */ + public function ParseOggPageHeader() { + // http://xiph.org/ogg/vorbis/doc/framing.html + $oggheader = array(); + $oggheader['page_start_offset'] = $this->ftell(); // where we started from in the file + + $filedata = $this->fread($this->getid3->fread_buffer_size()); + $filedataoffset = 0; + while ((substr($filedata, $filedataoffset++, 4) != 'OggS')) { + if (($this->ftell() - $oggheader['page_start_offset']) >= $this->getid3->fread_buffer_size()) { + // should be found before here + return false; + } + if ((($filedataoffset + 28) > strlen($filedata)) || (strlen($filedata) < 28)) { + if ($this->feof() || (($filedata .= $this->fread($this->getid3->fread_buffer_size())) === '')) { + // get some more data, unless eof, in which case fail + return false; + } + } + } + $filedataoffset += strlen('OggS') - 1; // page, delimited by 'OggS' + + $oggheader['stream_structver'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $oggheader['flags_raw'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $oggheader['flags']['fresh'] = (bool) ($oggheader['flags_raw'] & 0x01); // fresh packet + $oggheader['flags']['bos'] = (bool) ($oggheader['flags_raw'] & 0x02); // first page of logical bitstream (bos) + $oggheader['flags']['eos'] = (bool) ($oggheader['flags_raw'] & 0x04); // last page of logical bitstream (eos) + + $oggheader['pcm_abs_position'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 8)); + $filedataoffset += 8; + $oggheader['stream_serialno'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $oggheader['page_seqno'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $oggheader['page_checksum'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 4)); + $filedataoffset += 4; + $oggheader['page_segments'] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $oggheader['page_length'] = 0; + for ($i = 0; $i < $oggheader['page_segments']; $i++) { + $oggheader['segment_table'][$i] = getid3_lib::LittleEndian2Int(substr($filedata, $filedataoffset, 1)); + $filedataoffset += 1; + $oggheader['page_length'] += $oggheader['segment_table'][$i]; + } + $oggheader['header_end_offset'] = $oggheader['page_start_offset'] + $filedataoffset; + $oggheader['page_end_offset'] = $oggheader['header_end_offset'] + $oggheader['page_length']; + $this->fseek($oggheader['header_end_offset']); + + return $oggheader; + } + + /** + * @link http://xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-810005 + * + * @return bool + */ + public function ParseVorbisComments() { + $info = &$this->getid3->info; + + $OriginalOffset = $this->ftell(); + $commentdata = null; + $commentdataoffset = 0; + $VorbisCommentPage = 1; + $CommentStartOffset = 0; + + switch ($info['audio']['dataformat']) { + case 'vorbis': + case 'speex': + case 'opus': + $CommentStartOffset = $info['ogg']['pageheader'][$VorbisCommentPage]['page_start_offset']; // Second Ogg page, after header block + $this->fseek($CommentStartOffset); + $commentdataoffset = 27 + $info['ogg']['pageheader'][$VorbisCommentPage]['page_segments']; + $commentdata = $this->fread(self::OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1) + $commentdataoffset); + + if ($info['audio']['dataformat'] == 'vorbis') { + $commentdataoffset += (strlen('vorbis') + 1); + } + else if ($info['audio']['dataformat'] == 'opus') { + $commentdataoffset += strlen('OpusTags'); + } + + break; + + case 'flac': + $CommentStartOffset = $info['flac']['VORBIS_COMMENT']['raw']['offset'] + 4; + $this->fseek($CommentStartOffset); + $commentdata = $this->fread($info['flac']['VORBIS_COMMENT']['raw']['block_length']); + break; + + default: + return false; + } + + $VendorSize = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4)); + $commentdataoffset += 4; + + $info['ogg']['vendor'] = substr($commentdata, $commentdataoffset, $VendorSize); + $commentdataoffset += $VendorSize; + + $CommentsCount = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4)); + $commentdataoffset += 4; + $info['avdataoffset'] = $CommentStartOffset + $commentdataoffset; + + $basicfields = array('TITLE', 'ARTIST', 'ALBUM', 'TRACKNUMBER', 'GENRE', 'DATE', 'DESCRIPTION', 'COMMENT'); + $ThisFileInfo_ogg_comments_raw = &$info['ogg']['comments_raw']; + for ($i = 0; $i < $CommentsCount; $i++) { + + if ($i >= 10000) { + // https://github.com/owncloud/music/issues/212#issuecomment-43082336 + $this->warning('Unexpectedly large number ('.$CommentsCount.') of Ogg comments - breaking after reading '.$i.' comments'); + break; + } + + $ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] = $CommentStartOffset + $commentdataoffset; + + if ($this->ftell() < ($ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] + 4)) { + if ($oggpageinfo = $this->ParseOggPageHeader()) { + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; + + $VorbisCommentPage++; + + // First, save what we haven't read yet + $AsYetUnusedData = substr($commentdata, $commentdataoffset); + + // Then take that data off the end + $commentdata = substr($commentdata, 0, $commentdataoffset); + + // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct + $commentdata .= str_repeat("\x00", 27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); + $commentdataoffset += (27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); + + // Finally, stick the unused data back on the end + $commentdata .= $AsYetUnusedData; + + //$commentdata .= $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); + $commentdata .= $this->fread($this->OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1)); + } + + } + $ThisFileInfo_ogg_comments_raw[$i]['size'] = getid3_lib::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4)); + + // replace avdataoffset with position just after the last vorbiscomment + $info['avdataoffset'] = $ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] + $ThisFileInfo_ogg_comments_raw[$i]['size'] + 4; + + $commentdataoffset += 4; + while ((strlen($commentdata) - $commentdataoffset) < $ThisFileInfo_ogg_comments_raw[$i]['size']) { + if (($ThisFileInfo_ogg_comments_raw[$i]['size'] > $info['avdataend']) || ($ThisFileInfo_ogg_comments_raw[$i]['size'] < 0)) { + $this->warning('Invalid Ogg comment size (comment #'.$i.', claims to be '.number_format($ThisFileInfo_ogg_comments_raw[$i]['size']).' bytes) - aborting reading comments'); + break 2; + } + + $VorbisCommentPage++; + + if ($oggpageinfo = $this->ParseOggPageHeader()) { + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo; + + // First, save what we haven't read yet + $AsYetUnusedData = substr($commentdata, $commentdataoffset); + + // Then take that data off the end + $commentdata = substr($commentdata, 0, $commentdataoffset); + + // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct + $commentdata .= str_repeat("\x00", 27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); + $commentdataoffset += (27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']); + + // Finally, stick the unused data back on the end + $commentdata .= $AsYetUnusedData; + + //$commentdata .= $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']); + if (!isset($info['ogg']['pageheader'][$VorbisCommentPage])) { + $this->warning('undefined Vorbis Comment page "'.$VorbisCommentPage.'" at offset '.$this->ftell()); + break; + } + $readlength = self::OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1); + if ($readlength <= 0) { + $this->warning('invalid length Vorbis Comment page "'.$VorbisCommentPage.'" at offset '.$this->ftell()); + break; + } + $commentdata .= $this->fread($readlength); + + //$filebaseoffset += $oggpageinfo['header_end_offset'] - $oggpageinfo['page_start_offset']; + } else { + $this->warning('failed to ParseOggPageHeader() at offset '.$this->ftell()); + break; + } + } + $ThisFileInfo_ogg_comments_raw[$i]['offset'] = $commentdataoffset; + $commentstring = substr($commentdata, $commentdataoffset, $ThisFileInfo_ogg_comments_raw[$i]['size']); + $commentdataoffset += $ThisFileInfo_ogg_comments_raw[$i]['size']; + + if (!$commentstring) { + + // no comment? + $this->warning('Blank Ogg comment ['.$i.']'); + + } elseif (strstr($commentstring, '=')) { + + $commentexploded = explode('=', $commentstring, 2); + $ThisFileInfo_ogg_comments_raw[$i]['key'] = strtoupper($commentexploded[0]); + $ThisFileInfo_ogg_comments_raw[$i]['value'] = (isset($commentexploded[1]) ? $commentexploded[1] : ''); + + if ($ThisFileInfo_ogg_comments_raw[$i]['key'] == 'METADATA_BLOCK_PICTURE') { + + // http://wiki.xiph.org/VorbisComment#METADATA_BLOCK_PICTURE + // The unencoded format is that of the FLAC picture block. The fields are stored in big endian order as in FLAC, picture data is stored according to the relevant standard. + // http://flac.sourceforge.net/format.html#metadata_block_picture + $flac = new getid3_flac($this->getid3); + $flac->setStringMode(base64_decode($ThisFileInfo_ogg_comments_raw[$i]['value'])); + $flac->parsePICTURE(); + $info['ogg']['comments']['picture'][] = $flac->getid3->info['flac']['PICTURE'][0]; + unset($flac); + + } elseif ($ThisFileInfo_ogg_comments_raw[$i]['key'] == 'COVERART') { + + $data = base64_decode($ThisFileInfo_ogg_comments_raw[$i]['value']); + $this->notice('Found deprecated COVERART tag, it should be replaced in honor of METADATA_BLOCK_PICTURE structure'); + /** @todo use 'coverartmime' where available */ + $imageinfo = getid3_lib::GetDataImageSize($data); + if ($imageinfo === false || !isset($imageinfo['mime'])) { + $this->warning('COVERART vorbiscomment tag contains invalid image'); + continue; + } + + $ogg = new self($this->getid3); + $ogg->setStringMode($data); + $info['ogg']['comments']['picture'][] = array( + 'image_mime' => $imageinfo['mime'], + 'datalength' => strlen($data), + 'picturetype' => 'cover art', + 'image_height' => $imageinfo['height'], + 'image_width' => $imageinfo['width'], + 'data' => $ogg->saveAttachment('coverart', 0, strlen($data), $imageinfo['mime']), + ); + unset($ogg); + + } else { + + $info['ogg']['comments'][strtolower($ThisFileInfo_ogg_comments_raw[$i]['key'])][] = $ThisFileInfo_ogg_comments_raw[$i]['value']; + + } + + } else { + + $this->warning('[known problem with CDex >= v1.40, < v1.50b7] Invalid Ogg comment name/value pair ['.$i.']: '.$commentstring); + + } + unset($ThisFileInfo_ogg_comments_raw[$i]); + } + unset($ThisFileInfo_ogg_comments_raw); + + + // Replay Gain Adjustment + // http://privatewww.essex.ac.uk/~djmrob/replaygain/ + if (isset($info['ogg']['comments']) && is_array($info['ogg']['comments'])) { + foreach ($info['ogg']['comments'] as $index => $commentvalue) { + switch ($index) { + case 'rg_audiophile': + case 'replaygain_album_gain': + $info['replay_gain']['album']['adjustment'] = (double) $commentvalue[0]; + unset($info['ogg']['comments'][$index]); + break; + + case 'rg_radio': + case 'replaygain_track_gain': + $info['replay_gain']['track']['adjustment'] = (double) $commentvalue[0]; + unset($info['ogg']['comments'][$index]); + break; + + case 'replaygain_album_peak': + $info['replay_gain']['album']['peak'] = (double) $commentvalue[0]; + unset($info['ogg']['comments'][$index]); + break; + + case 'rg_peak': + case 'replaygain_track_peak': + $info['replay_gain']['track']['peak'] = (double) $commentvalue[0]; + unset($info['ogg']['comments'][$index]); + break; + + case 'replaygain_reference_loudness': + $info['replay_gain']['reference_volume'] = (double) $commentvalue[0]; + unset($info['ogg']['comments'][$index]); + break; + + default: + // do nothing + break; + } + } + } + + $this->fseek($OriginalOffset); + + return true; + } + + /** + * @param int $mode + * + * @return string|null + */ + public static function SpeexBandModeLookup($mode) { + static $SpeexBandModeLookup = array(); + if (empty($SpeexBandModeLookup)) { + $SpeexBandModeLookup[0] = 'narrow'; + $SpeexBandModeLookup[1] = 'wide'; + $SpeexBandModeLookup[2] = 'ultra-wide'; + } + return (isset($SpeexBandModeLookup[$mode]) ? $SpeexBandModeLookup[$mode] : null); + } + + /** + * @param array $OggInfoArray + * @param int $SegmentNumber + * + * @return int + */ + public static function OggPageSegmentLength($OggInfoArray, $SegmentNumber=1) { + $segmentlength = 0; + for ($i = 0; $i < $SegmentNumber; $i++) { + $segmentlength = 0; + foreach ($OggInfoArray['segment_table'] as $key => $value) { + $segmentlength += $value; + if ($value < 255) { + break; + } + } + } + return $segmentlength; + } + + /** + * @param int $nominal_bitrate + * + * @return float + */ + public static function get_quality_from_nominal_bitrate($nominal_bitrate) { + + // decrease precision + $nominal_bitrate = $nominal_bitrate / 1000; + + if ($nominal_bitrate < 128) { + // q-1 to q4 + $qval = ($nominal_bitrate - 64) / 16; + } elseif ($nominal_bitrate < 256) { + // q4 to q8 + $qval = $nominal_bitrate / 32; + } elseif ($nominal_bitrate < 320) { + // q8 to q9 + $qval = ($nominal_bitrate + 256) / 64; + } else { + // q9 to q10 + $qval = ($nominal_bitrate + 1300) / 180; + } + //return $qval; // 5.031324 + //return intval($qval); // 5 + return round($qval, 1); // 5 or 4.9 + } + + /** + * @param int $colorspace_id + * + * @return string|null + */ + public static function TheoraColorSpace($colorspace_id) { + // http://www.theora.org/doc/Theora.pdf (table 6.3) + static $TheoraColorSpaceLookup = array(); + if (empty($TheoraColorSpaceLookup)) { + $TheoraColorSpaceLookup[0] = 'Undefined'; + $TheoraColorSpaceLookup[1] = 'Rec. 470M'; + $TheoraColorSpaceLookup[2] = 'Rec. 470BG'; + $TheoraColorSpaceLookup[3] = 'Reserved'; + } + return (isset($TheoraColorSpaceLookup[$colorspace_id]) ? $TheoraColorSpaceLookup[$colorspace_id] : null); + } + + /** + * @param int $pixelformat_id + * + * @return string|null + */ + public static function TheoraPixelFormat($pixelformat_id) { + // http://www.theora.org/doc/Theora.pdf (table 6.4) + static $TheoraPixelFormatLookup = array(); + if (empty($TheoraPixelFormatLookup)) { + $TheoraPixelFormatLookup[0] = '4:2:0'; + $TheoraPixelFormatLookup[1] = 'Reserved'; + $TheoraPixelFormatLookup[2] = '4:2:2'; + $TheoraPixelFormatLookup[3] = '4:4:4'; + } + return (isset($TheoraPixelFormatLookup[$pixelformat_id]) ? $TheoraPixelFormatLookup[$pixelformat_id] : null); + } + +} diff --git a/serendipity_event_podcast/player/getid3/module.audio.optimfrog.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.optimfrog.php similarity index 61% rename from serendipity_event_podcast/player/getid3/module.audio.optimfrog.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.optimfrog.php index 3c2dfb0b..d84c2c48 100644 --- a/serendipity_event_podcast/player/getid3/module.audio.optimfrog.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.optimfrog.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.audio.optimfrog.php // @@ -13,41 +14,51 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); -class getid3_optimfrog +class getid3_optimfrog extends getid3_handler { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_optimfrog(&$fd, &$ThisFileInfo) { - $ThisFileInfo['fileformat'] = 'ofr'; - $ThisFileInfo['audio']['dataformat'] = 'ofr'; - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; - $ThisFileInfo['audio']['lossless'] = true; + $info['fileformat'] = 'ofr'; + $info['audio']['dataformat'] = 'ofr'; + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['lossless'] = true; - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $OFRheader = fread($fd, 8); + $this->fseek($info['avdataoffset']); + $OFRheader = $this->fread(8); if (substr($OFRheader, 0, 5) == '*RIFF') { - return $this->ParseOptimFROGheader42($fd, $ThisFileInfo); + return $this->ParseOptimFROGheader42(); } elseif (substr($OFRheader, 0, 3) == 'OFR') { - return $this->ParseOptimFROGheader45($fd, $ThisFileInfo); + return $this->ParseOptimFROGheader45(); } - $ThisFileInfo['error'][] = 'Expecting "*RIFF" or "OFR " at offset '.$ThisFileInfo['avdataoffset'].', found "'.$OFRheader.'"'; - unset($ThisFileInfo['fileformat']); + $this->error('Expecting "*RIFF" or "OFR " at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($OFRheader).'"'); + unset($info['fileformat']); return false; } - - function ParseOptimFROGheader42(&$fd, &$ThisFileInfo) { + /** + * @return bool + */ + public function ParseOptimFROGheader42() { // for fileformat of v4.21 and older - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $OptimFROGheaderData = fread($fd, 45); - $ThisFileInfo['avdataoffset'] = 45; + $info = &$this->getid3->info; + $this->fseek($info['avdataoffset']); + $OptimFROGheaderData = $this->fread(45); + $info['avdataoffset'] = 45; $OptimFROGencoderVersion_raw = getid3_lib::LittleEndian2Int(substr($OptimFROGheaderData, 0, 1)); $OptimFROGencoderVersion_major = floor($OptimFROGencoderVersion_raw / 10); @@ -57,36 +68,48 @@ class getid3_optimfrog $OrignalRIFFdataSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44; if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) { - $ThisFileInfo['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize); - fseek($fd, $ThisFileInfo['avdataend'], SEEK_SET); - $RIFFdata .= fread($fd, $OrignalRIFFheaderSize - $OrignalRIFFdataSize); + $info['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize); + $this->fseek($info['avdataend']); + $RIFFdata .= $this->fread($OrignalRIFFheaderSize - $OrignalRIFFdataSize); } // move the data chunk after all other chunks (if any) // so that the RIFF parser doesn't see EOF when trying // to skip over the data chunk $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8); - getid3_riff::ParseRIFFdata($RIFFdata, $ThisFileInfo); - $ThisFileInfo['audio']['encoder'] = 'OptimFROG '.$OptimFROGencoderVersion_major.'.'.$OptimFROGencoderVersion_minor; - $ThisFileInfo['audio']['channels'] = $ThisFileInfo['riff']['audio'][0]['channels']; - $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['riff']['audio'][0]['sample_rate']; - $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['riff']['audio'][0]['bits_per_sample']; - $ThisFileInfo['playtime_seconds'] = $OrignalRIFFdataSize / ($ThisFileInfo['audio']['channels'] * $ThisFileInfo['audio']['sample_rate'] * ($ThisFileInfo['audio']['bits_per_sample'] / 8)); - $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; + $getid3_temp->info['avdataend'] = $info['avdataend']; + $getid3_riff = new getid3_riff($getid3_temp); + $getid3_riff->ParseRIFFdata($RIFFdata); + $info['riff'] = $getid3_temp->info['riff']; + + $info['audio']['encoder'] = 'OptimFROG '.$OptimFROGencoderVersion_major.'.'.$OptimFROGencoderVersion_minor; + $info['audio']['channels'] = $info['riff']['audio'][0]['channels']; + $info['audio']['sample_rate'] = $info['riff']['audio'][0]['sample_rate']; + $info['audio']['bits_per_sample'] = $info['riff']['audio'][0]['bits_per_sample']; + $info['playtime_seconds'] = $OrignalRIFFdataSize / ($info['audio']['channels'] * $info['audio']['sample_rate'] * ($info['audio']['bits_per_sample'] / 8)); + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + + unset($getid3_riff, $getid3_temp, $RIFFdata); return true; } - - function ParseOptimFROGheader45(&$fd, &$ThisFileInfo) { + /** + * @return bool + */ + public function ParseOptimFROGheader45() { // for fileformat of v4.50a and higher + $info = &$this->getid3->info; $RIFFdata = ''; - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - while (!feof($fd) && (ftell($fd) < $ThisFileInfo['avdataend'])) { - $BlockOffset = ftell($fd); - $BlockData = fread($fd, 8); + $this->fseek($info['avdataoffset']); + while (!feof($this->getid3->fp) && ($this->ftell() < $info['avdataend'])) { + $BlockOffset = $this->ftell(); + $BlockData = $this->fread(8); $offset = 8; $BlockName = substr($BlockData, 0, 4); $BlockSize = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 4)); @@ -94,10 +117,10 @@ class getid3_optimfrog if ($BlockName == 'OFRX') { $BlockName = 'OFR '; } - if (!isset($ThisFileInfo['ofr'][$BlockName])) { - $ThisFileInfo['ofr'][$BlockName] = array(); + if (!isset($info['ofr'][$BlockName])) { + $info['ofr'][$BlockName] = array(); } - $thisfile_ofr_thisblock = &$ThisFileInfo['ofr'][$BlockName]; + $thisfile_ofr_thisblock = &$info['ofr'][$BlockName]; switch ($BlockName) { case 'OFR ': @@ -106,7 +129,7 @@ class getid3_optimfrog $thisfile_ofr_thisblock['offset'] = $BlockOffset; $thisfile_ofr_thisblock['size'] = $BlockSize; - $ThisFileInfo['audio']['encoder'] = 'OptimFROG 4.50 alpha'; + $info['audio']['encoder'] = 'OptimFROG 4.50 alpha'; switch ($BlockSize) { case 12: case 15: @@ -114,10 +137,10 @@ class getid3_optimfrog break; default: - $ThisFileInfo['warning'][] = '"'.$BlockName.'" contains more data than expected (expected 12 or 15 bytes, found '.$BlockSize.' bytes)'; + $this->warning('"'.$BlockName.'" contains more data than expected (expected 12 or 15 bytes, found '.$BlockSize.' bytes)'); break; } - $BlockData .= fread($fd, $BlockSize); + $BlockData .= $this->fread($BlockSize); $thisfile_ofr_thisblock['total_samples'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 6)); $offset += 6; @@ -142,39 +165,40 @@ class getid3_optimfrog $thisfile_ofr_thisblock['speedup'] = $this->OptimFROGspeedupLookup($thisfile_ofr_thisblock['raw']['compression']); $offset += 1; - $ThisFileInfo['audio']['encoder'] = 'OptimFROG '.$thisfile_ofr_thisblock['encoder']; - $ThisFileInfo['audio']['encoder_options'] = '--mode '.$thisfile_ofr_thisblock['compression']; + $info['audio']['encoder'] = 'OptimFROG '.$thisfile_ofr_thisblock['encoder']; + $info['audio']['encoder_options'] = '--mode '.$thisfile_ofr_thisblock['compression']; if ((($thisfile_ofr_thisblock['raw']['encoder_id'] & 0xF0) >> 4) == 7) { // v4.507 - if (strtolower(getid3_lib::fileextension($ThisFileInfo['filename'])) == 'ofs') { + if (strtolower(getid3_lib::fileextension($info['filename'])) == 'ofs') { // OptimFROG DualStream format is lossy, but as of v4.507 there is no way to tell the difference // between lossless and lossy other than the file extension. - $ThisFileInfo['audio']['dataformat'] = 'ofs'; - $ThisFileInfo['audio']['lossless'] = true; + $info['audio']['dataformat'] = 'ofs'; + $info['audio']['lossless'] = true; } } } - $ThisFileInfo['audio']['channels'] = $thisfile_ofr_thisblock['channels']; - $ThisFileInfo['audio']['sample_rate'] = $thisfile_ofr_thisblock['sample_rate']; - $ThisFileInfo['audio']['bits_per_sample'] = $this->OptimFROGbitsPerSampleTypeLookup($thisfile_ofr_thisblock['raw']['sample_type']); + $info['audio']['channels'] = $thisfile_ofr_thisblock['channels']; + $info['audio']['sample_rate'] = $thisfile_ofr_thisblock['sample_rate']; + $info['audio']['bits_per_sample'] = $this->OptimFROGbitsPerSampleTypeLookup($thisfile_ofr_thisblock['raw']['sample_type']); break; case 'COMP': // unlike other block types, there CAN be multiple COMP blocks + $COMPdata = array(); $COMPdata['offset'] = $BlockOffset; $COMPdata['size'] = $BlockSize; - if ($ThisFileInfo['avdataoffset'] == 0) { - $ThisFileInfo['avdataoffset'] = $BlockOffset; + if ($info['avdataoffset'] == 0) { + $info['avdataoffset'] = $BlockOffset; } // Only interested in first 14 bytes (only first 12 needed for v4.50 alpha), not actual audio data - $BlockData .= fread($fd, 14); - fseek($fd, $BlockSize - 14, SEEK_CUR); + $BlockData .= $this->fread(14); + $this->fseek($BlockSize - 14, SEEK_CUR); $COMPdata['crc_32'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4)); $offset += 4; @@ -190,7 +214,7 @@ class getid3_optimfrog //$COMPdata['algorithm'] = OptimFROGalgorithmNameLookup($COMPdata['raw']['algorithm_id']); $offset += 2; - if ($ThisFileInfo['ofr']['OFR ']['size'] > 12) { + if ($info['ofr']['OFR ']['size'] > 12) { // OFR 4.504b or higher $COMPdata['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2)); @@ -211,7 +235,7 @@ class getid3_optimfrog $thisfile_ofr_thisblock['offset'] = $BlockOffset; $thisfile_ofr_thisblock['size'] = $BlockSize; - $RIFFdata .= fread($fd, $BlockSize); + $RIFFdata .= $this->fread($BlockSize); break; case 'TAIL': @@ -219,7 +243,7 @@ class getid3_optimfrog $thisfile_ofr_thisblock['size'] = $BlockSize; if ($BlockSize > 0) { - $RIFFdata .= fread($fd, $BlockSize); + $RIFFdata .= $this->fread($BlockSize); } break; @@ -229,7 +253,7 @@ class getid3_optimfrog $thisfile_ofr_thisblock['offset'] = $BlockOffset; $thisfile_ofr_thisblock['size'] = $BlockSize; - fseek($fd, $BlockSize, SEEK_CUR); + $this->fseek($BlockSize, SEEK_CUR); break; @@ -238,9 +262,9 @@ class getid3_optimfrog $thisfile_ofr_thisblock['offset'] = $BlockOffset; $thisfile_ofr_thisblock['size'] = $BlockSize; - $ThisFileInfo['warning'][] = 'APEtag processing inside OptimFROG not supported in this version ('.GETID3_VERSION.') of getID3()'; + $this->warning('APEtag processing inside OptimFROG not supported in this version ('.$this->getid3->version().') of getID3()'); - fseek($fd, $BlockSize, SEEK_CUR); + $this->fseek($BlockSize, SEEK_CUR); break; @@ -252,14 +276,14 @@ class getid3_optimfrog if ($BlockSize == 16) { - $thisfile_ofr_thisblock['md5_binary'] = fread($fd, $BlockSize); + $thisfile_ofr_thisblock['md5_binary'] = $this->fread($BlockSize); $thisfile_ofr_thisblock['md5_string'] = getid3_lib::PrintHexBytes($thisfile_ofr_thisblock['md5_binary'], true, false, false); - $ThisFileInfo['md5_data_source'] = $thisfile_ofr_thisblock['md5_string']; + $info['md5_data_source'] = $thisfile_ofr_thisblock['md5_string']; } else { - $ThisFileInfo['warning'][] = 'Expecting block size of 16 in "MD5 " chunk, found '.$BlockSize.' instead'; - fseek($fd, $BlockSize, SEEK_CUR); + $this->warning('Expecting block size of 16 in "MD5 " chunk, found '.$BlockSize.' instead'); + $this->fseek($BlockSize, SEEK_CUR); } break; @@ -269,29 +293,42 @@ class getid3_optimfrog $thisfile_ofr_thisblock['offset'] = $BlockOffset; $thisfile_ofr_thisblock['size'] = $BlockSize; - $ThisFileInfo['warning'][] = 'Unhandled OptimFROG block type "'.$BlockName.'" at offset '.$thisfile_ofr_thisblock['offset']; - fseek($fd, $BlockSize, SEEK_CUR); + $this->warning('Unhandled OptimFROG block type "'.$BlockName.'" at offset '.$thisfile_ofr_thisblock['offset']); + $this->fseek($BlockSize, SEEK_CUR); break; } } - if (isset($ThisFileInfo['ofr']['TAIL']['offset'])) { - $ThisFileInfo['avdataend'] = $ThisFileInfo['ofr']['TAIL']['offset']; + if (isset($info['ofr']['TAIL']['offset'])) { + $info['avdataend'] = $info['ofr']['TAIL']['offset']; } - $ThisFileInfo['playtime_seconds'] = (float) $ThisFileInfo['ofr']['OFR ']['total_samples'] / ($ThisFileInfo['audio']['channels'] * $ThisFileInfo['audio']['sample_rate']); - $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; + $info['playtime_seconds'] = (float) $info['ofr']['OFR ']['total_samples'] / ($info['audio']['channels'] * $info['audio']['sample_rate']); + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; // move the data chunk after all other chunks (if any) // so that the RIFF parser doesn't see EOF when trying // to skip over the data chunk $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8); - getid3_riff::ParseRIFFdata($RIFFdata, $ThisFileInfo); + + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_temp->info['avdataoffset'] = $info['avdataoffset']; + $getid3_temp->info['avdataend'] = $info['avdataend']; + $getid3_riff = new getid3_riff($getid3_temp); + $getid3_riff->ParseRIFFdata($RIFFdata); + $info['riff'] = $getid3_temp->info['riff']; + + unset($getid3_riff, $getid3_temp, $RIFFdata); return true; } - - function OptimFROGsampleTypeLookup($SampleType) { + /** + * @param int $SampleType + * + * @return string|false + */ + public static function OptimFROGsampleTypeLookup($SampleType) { static $OptimFROGsampleTypeLookup = array( 0 => 'unsigned int (8-bit)', 1 => 'signed int (8-bit)', @@ -308,7 +345,12 @@ class getid3_optimfrog return (isset($OptimFROGsampleTypeLookup[$SampleType]) ? $OptimFROGsampleTypeLookup[$SampleType] : false); } - function OptimFROGbitsPerSampleTypeLookup($SampleType) { + /** + * @param int $SampleType + * + * @return int|false + */ + public static function OptimFROGbitsPerSampleTypeLookup($SampleType) { static $OptimFROGbitsPerSampleTypeLookup = array( 0 => 8, 1 => 8, @@ -325,7 +367,12 @@ class getid3_optimfrog return (isset($OptimFROGbitsPerSampleTypeLookup[$SampleType]) ? $OptimFROGbitsPerSampleTypeLookup[$SampleType] : false); } - function OptimFROGchannelConfigurationLookup($ChannelConfiguration) { + /** + * @param int $ChannelConfiguration + * + * @return string|false + */ + public static function OptimFROGchannelConfigurationLookup($ChannelConfiguration) { static $OptimFROGchannelConfigurationLookup = array( 0 => 'mono', 1 => 'stereo' @@ -333,7 +380,12 @@ class getid3_optimfrog return (isset($OptimFROGchannelConfigurationLookup[$ChannelConfiguration]) ? $OptimFROGchannelConfigurationLookup[$ChannelConfiguration] : false); } - function OptimFROGchannelConfigNumChannelsLookup($ChannelConfiguration) { + /** + * @param int $ChannelConfiguration + * + * @return int|false + */ + public static function OptimFROGchannelConfigNumChannelsLookup($ChannelConfiguration) { static $OptimFROGchannelConfigNumChannelsLookup = array( 0 => 1, 1 => 2 @@ -342,14 +394,18 @@ class getid3_optimfrog } - - // function OptimFROGalgorithmNameLookup($AlgorithID) { + // static function OptimFROGalgorithmNameLookup($AlgorithID) { // static $OptimFROGalgorithmNameLookup = array(); // return (isset($OptimFROGalgorithmNameLookup[$AlgorithID]) ? $OptimFROGalgorithmNameLookup[$AlgorithID] : false); // } - function OptimFROGencoderNameLookup($EncoderID) { + /** + * @param int $EncoderID + * + * @return string + */ + public static function OptimFROGencoderNameLookup($EncoderID) { // version = (encoderID >> 4) + 4500 // system = encoderID & 0xF @@ -364,7 +420,12 @@ class getid3_optimfrog return $EncoderVersion.' ('.(isset($OptimFROGencoderSystemLookup[$EncoderSystemID]) ? $OptimFROGencoderSystemLookup[$EncoderSystemID] : 'undefined encoder type (0x'.dechex($EncoderSystemID).')').')'; } - function OptimFROGcompressionLookup($CompressionID) { + /** + * @param int $CompressionID + * + * @return string + */ + public static function OptimFROGcompressionLookup($CompressionID) { // mode = compression >> 3 // speedup = compression & 0x07 @@ -386,7 +447,12 @@ class getid3_optimfrog return (isset($OptimFROGencoderModeLookup[$CompressionModeID]) ? $OptimFROGencoderModeLookup[$CompressionModeID] : 'undefined mode (0x'.str_pad(dechex($CompressionModeID), 2, '0', STR_PAD_LEFT).')'); } - function OptimFROGspeedupLookup($CompressionID) { + /** + * @param int $CompressionID + * + * @return string + */ + public static function OptimFROGspeedupLookup($CompressionID) { // mode = compression >> 3 // speedup = compression & 0x07 @@ -398,11 +464,7 @@ class getid3_optimfrog 0x01 => '2x', 0x02 => '4x' ); - return (isset($OptimFROGencoderSpeedupLookup[$CompressionSpeedupID]) ? $OptimFROGencoderSpeedupLookup[$CompressionSpeedupID] : 'undefined mode (0x'.dechex($CompressionSpeedupID)); } } - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.rkau.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.rkau.php new file mode 100644 index 00000000..8bbacd43 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.rkau.php @@ -0,0 +1,102 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.shorten.php // +// module for analyzing Shorten Audio files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_rkau extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + $RKAUHeader = $this->fread(20); + $magic = 'RKA'; + if (substr($RKAUHeader, 0, 3) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($RKAUHeader, 0, 3)).'"'); + return false; + } + + $info['fileformat'] = 'rkau'; + $info['audio']['dataformat'] = 'rkau'; + $info['audio']['bitrate_mode'] = 'vbr'; + + $info['rkau']['raw']['version'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 3, 1)); + $info['rkau']['version'] = '1.'.str_pad($info['rkau']['raw']['version'] & 0x0F, 2, '0', STR_PAD_LEFT); + if (($info['rkau']['version'] > 1.07) || ($info['rkau']['version'] < 1.06)) { + $this->error('This version of getID3() ['.$this->getid3->version().'] can only parse RKAU files v1.06 and 1.07 (this file is v'.$info['rkau']['version'].')'); + unset($info['rkau']); + return false; + } + + $info['rkau']['source_bytes'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 4, 4)); + $info['rkau']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 8, 4)); + $info['rkau']['channels'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 12, 1)); + $info['rkau']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 13, 1)); + + $info['rkau']['raw']['quality'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 14, 1)); + $this->RKAUqualityLookup($info['rkau']); + + $info['rkau']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 15, 1)); + $info['rkau']['flags']['joint_stereo'] = !($info['rkau']['raw']['flags'] & 0x01); + $info['rkau']['flags']['streaming'] = (bool) ($info['rkau']['raw']['flags'] & 0x02); + $info['rkau']['flags']['vrq_lossy_mode'] = (bool) ($info['rkau']['raw']['flags'] & 0x04); + + if ($info['rkau']['flags']['streaming']) { + $info['avdataoffset'] += 20; + $info['rkau']['compressed_bytes'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 16, 4)); + } else { + $info['avdataoffset'] += 16; + $info['rkau']['compressed_bytes'] = $info['avdataend'] - $info['avdataoffset'] - 1; + } + // Note: compressed_bytes does not always equal what appears to be the actual number of compressed bytes, + // sometimes it's more, sometimes less. No idea why(?) + + $info['audio']['lossless'] = $info['rkau']['lossless']; + $info['audio']['channels'] = $info['rkau']['channels']; + $info['audio']['bits_per_sample'] = $info['rkau']['bits_per_sample']; + $info['audio']['sample_rate'] = $info['rkau']['sample_rate']; + + $info['playtime_seconds'] = $info['rkau']['source_bytes'] / ($info['rkau']['sample_rate'] * $info['rkau']['channels'] * ($info['rkau']['bits_per_sample'] / 8)); + $info['audio']['bitrate'] = ($info['rkau']['compressed_bytes'] * 8) / $info['playtime_seconds']; + + return true; + + } + + /** + * @param array $RKAUdata + * + * @return bool + */ + public function RKAUqualityLookup(&$RKAUdata) { + $level = ($RKAUdata['raw']['quality'] & 0xF0) >> 4; + $quality = $RKAUdata['raw']['quality'] & 0x0F; + + $RKAUdata['lossless'] = (($quality == 0) ? true : false); + $RKAUdata['compression_level'] = $level + 1; + if (!$RKAUdata['lossless']) { + $RKAUdata['quality_setting'] = $quality; + } + + return true; + } + +} diff --git a/serendipity_event_podcast/player/getid3/module.audio.shorten.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.shorten.php similarity index 54% rename from serendipity_event_podcast/player/getid3/module.audio.shorten.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.shorten.php index bd80c59b..673a4858 100644 --- a/serendipity_event_podcast/player/getid3/module.audio.shorten.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.shorten.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.audio.shorten.php // @@ -13,37 +14,45 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_shorten +class getid3_shorten extends getid3_handler { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_shorten(&$fd, &$ThisFileInfo) { + $this->fseek($info['avdataoffset']); - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - - $ShortenHeader = fread($fd, 8); - if (substr($ShortenHeader, 0, 4) != 'ajkg') { - $ThisFileInfo['error'][] = 'Expecting "ajkg" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($ShortenHeader, 0, 4).'"'; + $ShortenHeader = $this->fread(8); + $magic = 'ajkg'; + if (substr($ShortenHeader, 0, 4) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($ShortenHeader, 0, 4)).'"'); return false; } - $ThisFileInfo['fileformat'] = 'shn'; - $ThisFileInfo['audio']['dataformat'] = 'shn'; - $ThisFileInfo['audio']['lossless'] = true; - $ThisFileInfo['audio']['bitrate_mode'] = 'vbr'; + $info['fileformat'] = 'shn'; + $info['audio']['dataformat'] = 'shn'; + $info['audio']['lossless'] = true; + $info['audio']['bitrate_mode'] = 'vbr'; - $ThisFileInfo['shn']['version'] = getid3_lib::LittleEndian2Int(substr($ShortenHeader, 4, 1)); + $info['shn']['version'] = getid3_lib::LittleEndian2Int(substr($ShortenHeader, 4, 1)); - fseek($fd, $ThisFileInfo['avdataend'] - 12, SEEK_SET); - $SeekTableSignatureTest = fread($fd, 12); - $ThisFileInfo['shn']['seektable']['present'] = (bool) (substr($SeekTableSignatureTest, 4, 8) == 'SHNAMPSK'); - if ($ThisFileInfo['shn']['seektable']['present']) { - $ThisFileInfo['shn']['seektable']['length'] = getid3_lib::LittleEndian2Int(substr($SeekTableSignatureTest, 0, 4)); - $ThisFileInfo['shn']['seektable']['offset'] = $ThisFileInfo['avdataend'] - $ThisFileInfo['shn']['seektable']['length']; - fseek($fd, $ThisFileInfo['shn']['seektable']['offset'], SEEK_SET); - $SeekTableMagic = fread($fd, 4); - if ($SeekTableMagic != 'SEEK') { + $this->fseek($info['avdataend'] - 12); + $SeekTableSignatureTest = $this->fread(12); + $info['shn']['seektable']['present'] = substr($SeekTableSignatureTest, 4, 8) == 'SHNAMPSK'; + if ($info['shn']['seektable']['present']) { + $info['shn']['seektable']['length'] = getid3_lib::LittleEndian2Int(substr($SeekTableSignatureTest, 0, 4)); + $info['shn']['seektable']['offset'] = $info['avdataend'] - $info['shn']['seektable']['length']; + $this->fseek($info['shn']['seektable']['offset']); + $SeekTableMagic = $this->fread(4); + $magic = 'SEEK'; + if ($SeekTableMagic != $magic) { - $ThisFileInfo['error'][] = 'Expecting "SEEK" at offset '.$ThisFileInfo['shn']['seektable']['offset'].', found "'.$SeekTableMagic.'"'; + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['shn']['seektable']['offset'].', found "'.getid3_lib::PrintHexBytes($SeekTableMagic).'"'); return false; } else { @@ -64,11 +73,11 @@ class getid3_shorten // long Offset1[4]; // }TSeekEntry; - $SeekTableData = fread($fd, $ThisFileInfo['shn']['seektable']['length'] - 16); - $ThisFileInfo['shn']['seektable']['entry_count'] = floor(strlen($SeekTableData) / 80); - //$ThisFileInfo['shn']['seektable']['entries'] = array(); + $SeekTableData = $this->fread($info['shn']['seektable']['length'] - 16); + $info['shn']['seektable']['entry_count'] = floor(strlen($SeekTableData) / 80); + //$info['shn']['seektable']['entries'] = array(); //$SeekTableOffset = 0; - //for ($i = 0; $i < $ThisFileInfo['shn']['seektable']['entry_count']; $i++) { + //for ($i = 0; $i < $info['shn']['seektable']['entry_count']; $i++) { // $SeekTableEntry['sample_number'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); // $SeekTableOffset += 4; // $SeekTableEntry['shn_file_byte_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4)); @@ -102,7 +111,7 @@ class getid3_shorten // $SeekTableOffset += 4; // } // - // $ThisFileInfo['shn']['seektable']['entries'][] = $SeekTableEntry; + // $info['shn']['seektable']['entries'][] = $SeekTableEntry; //} } @@ -110,7 +119,7 @@ class getid3_shorten } if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { - $ThisFileInfo['error'][] = 'PHP running in Safe Mode - backtick operator not available, cannot run shntool to analyze Shorten files'; + $this->error('PHP running in Safe Mode - backtick operator not available, cannot run shntool to analyze Shorten files'); return false; } @@ -119,11 +128,11 @@ class getid3_shorten $RequiredFiles = array('shorten.exe', 'cygwin1.dll', 'head.exe'); foreach ($RequiredFiles as $required_file) { if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) { - $ThisFileInfo['error'][] = GETID3_HELPERAPPSDIR.$required_file.' does not exist'; + $this->error(GETID3_HELPERAPPSDIR.$required_file.' does not exist'); return false; } } - $commandline = GETID3_HELPERAPPSDIR.'shorten.exe -x "'.$ThisFileInfo['filenamepath'].'" - | '.GETID3_HELPERAPPSDIR.'head.exe -c 64'; + $commandline = GETID3_HELPERAPPSDIR.'shorten.exe -x "'.$info['filenamepath'].'" - | '.GETID3_HELPERAPPSDIR.'head.exe -c 64'; $commandline = str_replace('/', '\\', $commandline); } else { @@ -133,10 +142,10 @@ class getid3_shorten $shorten_present = file_exists('/usr/local/bin/shorten') || `which shorten`; } if (!$shorten_present) { - $ThisFileInfo['error'][] = 'shorten binary was not found in path or /usr/local/bin'; + $this->error('shorten binary was not found in path or /usr/local/bin'); return false; } - $commandline = (file_exists('/usr/local/bin/shorten') ? '/usr/local/bin/' : '' ) . 'shorten -x '.escapeshellarg($ThisFileInfo['filenamepath']).' - | head -c 64'; + $commandline = (file_exists('/usr/local/bin/shorten') ? '/usr/local/bin/' : '' ) . 'shorten -x '.escapeshellarg($info['filenamepath']).' - | head -c 64'; } @@ -144,30 +153,33 @@ class getid3_shorten if (!empty($output) && (substr($output, 12, 4) == 'fmt ')) { + if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; + } getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); $fmt_size = getid3_lib::LittleEndian2Int(substr($output, 16, 4)); - $DecodedWAVFORMATEX = getid3_riff::RIFFparseWAVEFORMATex(substr($output, 20, $fmt_size)); - $ThisFileInfo['audio']['channels'] = $DecodedWAVFORMATEX['channels']; - $ThisFileInfo['audio']['bits_per_sample'] = $DecodedWAVFORMATEX['bits_per_sample']; - $ThisFileInfo['audio']['sample_rate'] = $DecodedWAVFORMATEX['sample_rate']; + $DecodedWAVFORMATEX = getid3_riff::parseWAVEFORMATex(substr($output, 20, $fmt_size)); + $info['audio']['channels'] = $DecodedWAVFORMATEX['channels']; + $info['audio']['bits_per_sample'] = $DecodedWAVFORMATEX['bits_per_sample']; + $info['audio']['sample_rate'] = $DecodedWAVFORMATEX['sample_rate']; if (substr($output, 20 + $fmt_size, 4) == 'data') { - $ThisFileInfo['playtime_seconds'] = getid3_lib::LittleEndian2Int(substr($output, 20 + 4 + $fmt_size, 4)) / $DecodedWAVFORMATEX['raw']['nAvgBytesPerSec']; + $info['playtime_seconds'] = getid3_lib::LittleEndian2Int(substr($output, 20 + 4 + $fmt_size, 4)) / $DecodedWAVFORMATEX['raw']['nAvgBytesPerSec']; } else { - $ThisFileInfo['error'][] = 'shorten failed to decode DATA chunk to expected location, cannot determine playtime'; + $this->error('shorten failed to decode DATA chunk to expected location, cannot determine playtime'); return false; } - $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds']) * 8; + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8; } else { - $ThisFileInfo['error'][] = 'shorten failed to decode file to WAV for parsing'; + $this->error('shorten failed to decode file to WAV for parsing'); return false; } @@ -176,5 +188,3 @@ class getid3_shorten } } - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.tak.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.tak.php new file mode 100644 index 00000000..0391d05b --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.tak.php @@ -0,0 +1,216 @@ + // +// available at http://getid3.sourceforge.net // +// or https://www.getid3.org // +// also https://github.com/JamesHeinrich/getID3 // +///////////////////////////////////////////////////////////////// +// See readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.tak.php // +// module for analyzing Tom's lossless Audio Kompressor // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_tak extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'tak'; + $info['audio']['dataformat'] = 'tak'; + $info['audio']['bitrate_mode'] = 'vbr'; + $info['audio']['lossless'] = true; + + $info['tak_audio']['raw'] = array(); + $thisfile_takaudio = &$info['tak_audio']; + $thisfile_takaudio_raw = &$thisfile_takaudio['raw']; + + $this->fseek($info['avdataoffset']); + $TAKMetaData = $this->fread(4); + + $thisfile_takaudio_raw['magic'] = $TAKMetaData; + $magic = 'tBaK'; + if ($thisfile_takaudio_raw['magic'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($thisfile_takaudio_raw['magic']).'"'); + unset($info['fileformat']); + return false; + } + $offset = 4; //skip magic + $this->fseek($offset); + $TAKMetaData = $this->fread(4); //read Metadata Block Header + $objtype = getid3_lib::BigEndian2Int(substr($TAKMetaData, 0, 1)); //Metadata Block Object Type + $objlength = getid3_lib::LittleEndian2Int(substr($TAKMetaData, 1, 3)); //Metadata Block Object Lenght excluding header + if ($objtype == 1) { //The First Metadata Block Object must be of Type 1 (STREAMINFO) + $offset += 4; //skip to Metadata Block contents + $this->fseek($offset); + $TAKMetaData = $this->fread($objlength); // Get the raw Metadata Block Data + $thisfile_takaudio_raw['STREAMINFO'] = getid3_lib::LittleEndian2Bin(substr($TAKMetaData, 0, $objlength - 3)); + $offset += $objlength; // Move to the next Metadata Block Object + $thisfile_takaudio['channels'] = getid3_lib::Bin2Dec(substr($thisfile_takaudio_raw['STREAMINFO'], 1, 4)) + 1; + $thisfile_takaudio['bits_per_sample'] = getid3_lib::Bin2Dec(substr($thisfile_takaudio_raw['STREAMINFO'], 5, 5)) + 8; + $thisfile_takaudio['sample_rate'] = getid3_lib::Bin2Dec(substr($thisfile_takaudio_raw['STREAMINFO'], 10, 18)) + 6000; + $thisfile_takaudio['samples'] = getid3_lib::Bin2Dec(substr($thisfile_takaudio_raw['STREAMINFO'], 31, 35)); + $thisfile_takaudio['framesize'] = self::TAKFramesizeLookup(getid3_lib::Bin2Dec(substr($thisfile_takaudio_raw['STREAMINFO'], 66, 4))); + $thisfile_takaudio['codectype'] = self::TAKCodecTypeLookup(getid3_lib::Bin2Dec(substr($thisfile_takaudio_raw['STREAMINFO'], 74, 6))); + } else { + $this->error('Expecting Type 1 (STREAMINFO) Metadata Object header, but found Type "'.$objtype.'" Object instead'); + unset($info['fileformat']); + return false; + } + $this->fseek($offset); + $TAKMetaData = $this->fread(4); + $objtype = getid3_lib::BigEndian2Int(substr($TAKMetaData, 0, 1)); + $objlength = getid3_lib::LittleEndian2Int(substr($TAKMetaData, 1, 3)); + while ($objtype != 0) { + switch ($objtype) { + case 4 : + // ENCODERINFO Metadata Block + $offset += 4; + $this->fseek($offset); + $TAKMetaData = $this->fread($objlength); + $ver = getid3_lib::LittleEndian2Int(substr($TAKMetaData, 0, 3)); + $major = ($ver & 0xff0000) >> 16; + $minor = ($ver & 0x00ff00) >> 8; + $revision= $ver & 0x0000ff; + $thisfile_takaudio['version'] = 'TAK V '.$major.'.'.$minor.'.'.$revision; + $thisfile_takaudio['profile'] = self::TAKProfileLookup(getid3_lib::BigEndian2Int(substr($TAKMetaData, 3, 1))); + $offset += $objlength; + break; + case 6 : + // MD5 Checksum Metadata Block + $offset += 4; + $this->fseek($offset); + $TAKMetaData = $this->fread($objlength); + $thisfile_takaudio_raw['MD5Data'] = substr($TAKMetaData, 0, 16); + $offset += $objlength; + break; + case 7 : + // LASTFRAME Metadata Block + $offset += 4; + $this->fseek($offset); + $TAKMetaData = $this->fread($objlength); + $thisfile_takaudio['lastframe_pos'] = getid3_lib::LittleEndian2Int(substr($TAKMetaData, 0, 5)); + $thisfile_takaudio['last_frame_size'] = getid3_lib::LittleEndian2Int(substr($TAKMetaData, 5, 3)); + $offset += $objlength; + break; + case 3 : + // ORIGINALFILEDATA Metadata Block + $offset += 4; + $this->fseek($offset); + $TAKMetaData = $this->fread($objlength); + $headersize = getid3_lib::LittleEndian2Int(substr($TAKMetaData, 0, 3)); + $footersize = getid3_lib::LittleEndian2Int(substr($TAKMetaData, 3, 3)); + if ($headersize) $thisfile_takaudio_raw['header_data'] = substr($TAKMetaData, 6, $headersize); + if ($footersize) $thisfile_takaudio_raw['footer_data'] = substr($TAKMetaData, $headersize, $footersize); + $offset += $objlength; + break; + default : + // PADDING or SEEKTABLE Metadata Block. Just skip it + $offset += 4; + $this->fseek($offset); + $TAKMetaData = $this->fread($objlength); + $offset += $objlength; + break; + } + $this->fseek($offset); + $TAKMetaData = $this->fread(4); + $objtype = getid3_lib::BigEndian2Int(substr($TAKMetaData, 0, 1)); + $objlength = getid3_lib::LittleEndian2Int(substr($TAKMetaData, 1, 3)); + } + // Finished all Metadata Blocks. So update $info['avdataoffset'] because next block is the first Audio data block + $info['avdataoffset'] = $offset; + + $info['audio']['channels'] = $thisfile_takaudio['channels']; + if ($thisfile_takaudio['sample_rate'] == 0) { + $this->error('Corrupt TAK file: samplerate == zero'); + return false; + } + $info['audio']['sample_rate'] = $thisfile_takaudio['sample_rate']; + $thisfile_takaudio['playtime'] = $thisfile_takaudio['samples'] / $thisfile_takaudio['sample_rate']; + if ($thisfile_takaudio['playtime'] == 0) { + $this->error('Corrupt TAK file: playtime == zero'); + return false; + } + $info['playtime_seconds'] = $thisfile_takaudio['playtime']; + $thisfile_takaudio['compressed_size'] = $info['avdataend'] - $info['avdataoffset']; + $thisfile_takaudio['uncompressed_size'] = $thisfile_takaudio['samples'] * $thisfile_takaudio['channels'] * ($thisfile_takaudio['bits_per_sample'] / 8); + if ($thisfile_takaudio['uncompressed_size'] == 0) { + $this->error('Corrupt TAK file: uncompressed_size == zero'); + return false; + } + $thisfile_takaudio['compression_ratio'] = $thisfile_takaudio['compressed_size'] / ($thisfile_takaudio['uncompressed_size'] + $offset); + $thisfile_takaudio['bitrate'] = (($thisfile_takaudio['samples'] * $thisfile_takaudio['channels'] * $thisfile_takaudio['bits_per_sample']) / $thisfile_takaudio['playtime']) * $thisfile_takaudio['compression_ratio']; + $info['audio']['bitrate'] = $thisfile_takaudio['bitrate']; + + if (empty($thisfile_takaudio_raw['MD5Data'])) { + //$this->warning('MD5Data is not set'); + } elseif ($thisfile_takaudio_raw['MD5Data'] === str_repeat("\x00", 16)) { + //$this->warning('MD5Data is null'); + } else { + $info['md5_data_source'] = ''; + $md5 = $thisfile_takaudio_raw['MD5Data']; + for ($i = 0; $i < strlen($md5); $i++) { + $info['md5_data_source'] .= str_pad(dechex(ord($md5[$i])), 2, '00', STR_PAD_LEFT); + } + if (!preg_match('/^[0-9a-f]{32}$/', $info['md5_data_source'])) { + unset($info['md5_data_source']); + } + } + + foreach (array('bits_per_sample', 'version', 'profile') as $key) { + if (!empty($thisfile_takaudio[$key])) { + $info['audio'][$key] = $thisfile_takaudio[$key]; + } + } + + return true; + } + + public function TAKFramesizeLookup($framesize) { + static $TAKFramesizeLookup = array( + 0 => '94 ms', + 1 => '125 ms', + 2 => '188 ms', + 3 => '250 ms', + 4 => '4096 samples', + 5 => '8192 samples', + 6 => '16384 samples', + 7 => '512 samples', + 8 => '1024 samples', + 9 => '2048 samples' + ); + return (isset($TAKFramesizeLookup[$framesize]) ? $TAKFramesizeLookup[$framesize] : 'invalid'); + } + public function TAKCodecTypeLookup($code) { + static $TAKCodecTypeLookup = array( + 0 => 'Integer 24 bit (TAK 1.0)', + 1 => 'Experimental!', + 2 => 'Integer 24 bit (TAK 2.0)', + 3 => 'LossyWav (TAK 2.1)', + 4 => 'Integer 24 bit MC (TAK 2.2)' + ); + return (isset($TAKCodecTypeLookup[$code]) ? $TAKCodecTypeLookup[$code] : 'invalid'); + } + public function TAKProfileLookup($code) { + $out ='-p'; + $evaluation = ($code & 0xf0) >> 4; + $compresion = $code & 0x0f; + static $TAKEvaluationLookup = array( + 0 => '', + 1 => 'e', + 2 => 'm' + ); + return (isset($TAKEvaluationLookup[$evaluation]) ? $out .= $compresion . $TAKEvaluationLookup[$evaluation] : 'invalid'); + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.tta.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.tta.php new file mode 100644 index 00000000..700cd05a --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.tta.php @@ -0,0 +1,111 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.tta.php // +// module for analyzing TTA Audio files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_tta extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'tta'; + $info['audio']['dataformat'] = 'tta'; + $info['audio']['lossless'] = true; + $info['audio']['bitrate_mode'] = 'vbr'; + + $this->fseek($info['avdataoffset']); + $ttaheader = $this->fread(26); + + $info['tta']['magic'] = substr($ttaheader, 0, 3); + $magic = 'TTA'; + if ($info['tta']['magic'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['tta']['magic']).'"'); + unset($info['fileformat']); + unset($info['audio']); + unset($info['tta']); + return false; + } + + switch ($ttaheader[3]) { + case "\x01": // TTA v1.x + case "\x02": // TTA v1.x + case "\x03": // TTA v1.x + // "It was the demo-version of the TTA encoder. There is no released format with such header. TTA encoder v1 is not supported about a year." + $info['tta']['major_version'] = 1; + $info['avdataoffset'] += 16; + + $info['tta']['compression_level'] = ord($ttaheader[3]); + $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); + $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2)); + $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 4)); + $info['tta']['samples_per_channel'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12, 4)); + + $info['audio']['encoder_options'] = '-e'.$info['tta']['compression_level']; + $info['playtime_seconds'] = $info['tta']['samples_per_channel'] / $info['tta']['sample_rate']; + break; + + case '2': // TTA v2.x + // "I have hurried to release the TTA 2.0 encoder. Format documentation is removed from our site. This format still in development. Please wait the TTA2 format, encoder v4." + $info['tta']['major_version'] = 2; + $info['avdataoffset'] += 20; + + $info['tta']['compression_level'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); + $info['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2)); + $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 2)); + $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 10, 2)); + $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12, 4)); + $info['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 16, 4)); + + $info['audio']['encoder_options'] = '-e'.$info['tta']['compression_level']; + $info['playtime_seconds'] = $info['tta']['data_length'] / $info['tta']['sample_rate']; + break; + + case '1': // TTA v3.x + // "This is a first stable release of the TTA format. It will be supported by the encoders v3 or higher." + $info['tta']['major_version'] = 3; + $info['avdataoffset'] += 26; + + $info['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); // getid3_riff::wFormatTagLookup() + $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2)); + $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 2)); + $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 10, 4)); + $info['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 14, 4)); + $info['tta']['crc32_footer'] = substr($ttaheader, 18, 4); + $info['tta']['seek_point'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 22, 4)); + + $info['playtime_seconds'] = $info['tta']['data_length'] / $info['tta']['sample_rate']; + break; + + default: + $this->error('This version of getID3() ['.$this->getid3->version().'] only knows how to handle TTA v1 and v2 - it may not work correctly with this file which appears to be TTA v'.$ttaheader[3]); + return false; + } + + $info['audio']['encoder'] = 'TTA v'.$info['tta']['major_version']; + $info['audio']['bits_per_sample'] = $info['tta']['bits_per_sample']; + $info['audio']['sample_rate'] = $info['tta']['sample_rate']; + $info['audio']['channels'] = $info['tta']['channels']; + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + + return true; + } + +} diff --git a/serendipity_event_podcast/player/getid3/module.audio.voc.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.voc.php similarity index 69% rename from serendipity_event_podcast/player/getid3/module.audio.voc.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.voc.php index a538a4ae..6bed1318 100644 --- a/serendipity_event_podcast/player/getid3/module.audio.voc.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.voc.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.audio.voc.php // @@ -13,27 +14,34 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_voc +class getid3_voc extends getid3_handler { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_voc(&$fd, &$ThisFileInfo) { + $OriginalAVdataOffset = $info['avdataoffset']; + $this->fseek($info['avdataoffset']); + $VOCheader = $this->fread(26); - $OriginalAVdataOffset = $ThisFileInfo['avdataoffset']; - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $VOCheader = fread($fd, 26); - - if (substr($VOCheader, 0, 19) != 'Creative Voice File') { - $ThisFileInfo['error'][] = 'Expecting "Creative Voice File" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($VOCheader, 0, 19).'"'; + $magic = 'Creative Voice File'; + if (substr($VOCheader, 0, 19) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($VOCheader, 0, 19)).'"'); return false; } // shortcuts - $thisfile_audio = &$ThisFileInfo['audio']; - $ThisFileInfo['voc'] = array(); - $thisfile_voc = &$ThisFileInfo['voc']; + $thisfile_audio = &$info['audio']; + $info['voc'] = array(); + $thisfile_voc = &$info['voc']; - $ThisFileInfo['fileformat'] = 'voc'; + $info['fileformat'] = 'voc'; $thisfile_audio['dataformat'] = 'voc'; $thisfile_audio['bitrate_mode'] = 'cbr'; $thisfile_audio['lossless'] = true; @@ -51,15 +59,17 @@ class getid3_voc $thisfile_voc['header']['datablock_offset'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 20, 2)); $thisfile_voc['header']['minor_version'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 22, 1)); $thisfile_voc['header']['major_version'] = getid3_lib::LittleEndian2Int(substr($VOCheader, 23, 1)); + $thisfile_voc['blocktypes'] = array(); do { - $BlockOffset = ftell($fd); - $BlockData = fread($fd, 4); - $BlockType = ord($BlockData{0}); + $BlockOffset = $this->ftell(); + $BlockData = $this->fread(4); + $BlockType = ord($BlockData[0]); $BlockSize = getid3_lib::LittleEndian2Int(substr($BlockData, 1, 3)); $ThisBlock = array(); + /** @phpstan-ignore-next-line */ getid3_lib::safe_inc($thisfile_voc['blocktypes'][$BlockType], 1); switch ($BlockType) { case 0: // Terminator @@ -67,11 +77,11 @@ class getid3_voc break; case 1: // Sound data - $BlockData .= fread($fd, 2); - if ($ThisFileInfo['avdataoffset'] <= $OriginalAVdataOffset) { - $ThisFileInfo['avdataoffset'] = ftell($fd); + $BlockData .= $this->fread(2); + if ($info['avdataoffset'] <= $OriginalAVdataOffset) { + $info['avdataoffset'] = $this->ftell(); } - fseek($fd, $BlockSize - 2, SEEK_CUR); + $this->fseek($BlockSize - 2, SEEK_CUR); $ThisBlock['sample_rate_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 1)); $ThisBlock['compression_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, 5, 1)); @@ -94,11 +104,11 @@ class getid3_voc case 6: // Repeat case 7: // End repeat // nothing useful, just skip - fseek($fd, $BlockSize, SEEK_CUR); + $this->fseek($BlockSize, SEEK_CUR); break; case 8: // Extended - $BlockData .= fread($fd, 4); + $BlockData .= $this->fread(4); //00-01 Time Constant: // Mono: 65536 - (256000000 / sample_rate) @@ -112,11 +122,11 @@ class getid3_voc break; case 9: // data block that supersedes blocks 1 and 8. Used for stereo, 16 bit - $BlockData .= fread($fd, 12); - if ($ThisFileInfo['avdataoffset'] <= $OriginalAVdataOffset) { - $ThisFileInfo['avdataoffset'] = ftell($fd); + $BlockData .= $this->fread(12); + if ($info['avdataoffset'] <= $OriginalAVdataOffset) { + $info['avdataoffset'] = $this->ftell(); } - fseek($fd, $BlockSize - 12, SEEK_CUR); + $this->fseek($BlockSize - 12, SEEK_CUR); $ThisBlock['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 4)); $ThisBlock['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($BlockData, 8, 1)); @@ -134,8 +144,8 @@ class getid3_voc break; default: - $ThisFileInfo['warning'][] = 'Unhandled block type "'.$BlockType.'" at offset '.$BlockOffset; - fseek($fd, $BlockSize, SEEK_CUR); + $this->warning('Unhandled block type "'.$BlockType.'" at offset '.$BlockOffset); + $this->fseek($BlockSize, SEEK_CUR); break; } @@ -146,22 +156,27 @@ class getid3_voc $thisfile_voc['blocks'][] = $ThisBlock; } - } while (!feof($fd) && ($BlockType != 0)); + } while (!feof($this->getid3->fp) && ($BlockType != 0)); // Terminator block doesn't have size field, so seek back 3 spaces - fseek($fd, -3, SEEK_CUR); + $this->fseek(-3, SEEK_CUR); ksort($thisfile_voc['blocktypes']); if (!empty($thisfile_voc['compressed_bits_per_sample'])) { - $ThisFileInfo['playtime_seconds'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / ($thisfile_voc['compressed_bits_per_sample'] * $thisfile_audio['channels'] * $thisfile_audio['sample_rate']); - $thisfile_audio['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds']; + $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / ($thisfile_voc['compressed_bits_per_sample'] * $thisfile_audio['channels'] * $thisfile_audio['sample_rate']); + $thisfile_audio['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; } return true; } - function VOCcompressionTypeLookup($index) { + /** + * @param int $index + * + * @return string + */ + public function VOCcompressionTypeLookup($index) { static $VOCcompressionTypeLookup = array( 0 => '8-bit', 1 => '4-bit', @@ -171,7 +186,12 @@ class getid3_voc return (isset($VOCcompressionTypeLookup[$index]) ? $VOCcompressionTypeLookup[$index] : 'Multi DAC ('.($index - 3).') channels'); } - function VOCwFormatLookup($index) { + /** + * @param int $index + * + * @return string|false + */ + public function VOCwFormatLookup($index) { static $VOCwFormatLookup = array( 0x0000 => '8-bit unsigned PCM', 0x0001 => 'Creative 8-bit to 4-bit ADPCM', @@ -185,21 +205,23 @@ class getid3_voc return (isset($VOCwFormatLookup[$index]) ? $VOCwFormatLookup[$index] : false); } - function VOCwFormatActualBitsPerSampleLookup($index) { + /** + * @param int $index + * + * @return int|false + */ + public function VOCwFormatActualBitsPerSampleLookup($index) { static $VOCwFormatLookup = array( - 0x0000 => 8, - 0x0001 => 4, - 0x0002 => 3, - 0x0003 => 2, + 0x0000 => 8, + 0x0001 => 4, + 0x0002 => 3, + 0x0003 => 2, 0x0004 => 16, - 0x0006 => 8, - 0x0007 => 8, - 0x2000 => 4 + 0x0006 => 8, + 0x0007 => 8, + 0x2000 => 4 ); return (isset($VOCwFormatLookup[$index]) ? $VOCwFormatLookup[$index] : false); } } - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.vqf.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.vqf.php new file mode 100644 index 00000000..55c7881d --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.vqf.php @@ -0,0 +1,176 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.vqf.php // +// module for analyzing VQF audio files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_vqf extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + // based loosely on code from TTwinVQ by Jurgen Faul + // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html + + $info['fileformat'] = 'vqf'; + $info['audio']['dataformat'] = 'vqf'; + $info['audio']['bitrate_mode'] = 'cbr'; + $info['audio']['lossless'] = false; + + // shortcut + $info['vqf']['raw'] = array(); + $thisfile_vqf = &$info['vqf']; + $thisfile_vqf_raw = &$thisfile_vqf['raw']; + + $this->fseek($info['avdataoffset']); + $VQFheaderData = $this->fread(16); + + $offset = 0; + $thisfile_vqf_raw['header_tag'] = substr($VQFheaderData, $offset, 4); + $magic = 'TWIN'; + if ($thisfile_vqf_raw['header_tag'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($thisfile_vqf_raw['header_tag']).'"'); + unset($info['vqf']); + unset($info['fileformat']); + return false; + } + $offset += 4; + $thisfile_vqf_raw['version'] = substr($VQFheaderData, $offset, 8); + $offset += 8; + $thisfile_vqf_raw['size'] = getid3_lib::BigEndian2Int(substr($VQFheaderData, $offset, 4)); + $offset += 4; + + while ($this->ftell() < $info['avdataend']) { + + $ChunkBaseOffset = $this->ftell(); + $chunkoffset = 0; + $ChunkData = $this->fread(8); + $ChunkName = substr($ChunkData, $chunkoffset, 4); + if ($ChunkName == 'DATA') { + $info['avdataoffset'] = $ChunkBaseOffset; + break; + } + $chunkoffset += 4; + $ChunkSize = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); + $chunkoffset += 4; + if ($ChunkSize > ($info['avdataend'] - $this->ftell())) { + $this->error('Invalid chunk size ('.$ChunkSize.') for chunk "'.$ChunkName.'" at offset '.$ChunkBaseOffset); + break; + } + if ($ChunkSize > 0) { + $ChunkData .= $this->fread($ChunkSize); + } + + switch ($ChunkName) { + case 'COMM': + // shortcut + $thisfile_vqf['COMM'] = array(); + $thisfile_vqf_COMM = &$thisfile_vqf['COMM']; + + $thisfile_vqf_COMM['channel_mode'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); + $chunkoffset += 4; + $thisfile_vqf_COMM['bitrate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); + $chunkoffset += 4; + $thisfile_vqf_COMM['sample_rate'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); + $chunkoffset += 4; + $thisfile_vqf_COMM['security_level'] = getid3_lib::BigEndian2Int(substr($ChunkData, $chunkoffset, 4)); + $chunkoffset += 4; + + $info['audio']['channels'] = $thisfile_vqf_COMM['channel_mode'] + 1; + $info['audio']['sample_rate'] = $this->VQFchannelFrequencyLookup($thisfile_vqf_COMM['sample_rate']); + $info['audio']['bitrate'] = $thisfile_vqf_COMM['bitrate'] * 1000; + $info['audio']['encoder_options'] = 'CBR' . ceil($info['audio']['bitrate']/1000); + + if ($info['audio']['bitrate'] == 0) { + $this->error('Corrupt VQF file: bitrate_audio == zero'); + return false; + } + break; + + case 'NAME': + case 'AUTH': + case '(c) ': + case 'FILE': + case 'COMT': + case 'ALBM': + $thisfile_vqf['comments'][$this->VQFcommentNiceNameLookup($ChunkName)][] = trim(substr($ChunkData, 8)); + break; + + case 'DSIZ': + $thisfile_vqf['DSIZ'] = getid3_lib::BigEndian2Int(substr($ChunkData, 8, 4)); + break; + + default: + $this->warning('Unhandled chunk type "'.$ChunkName.'" at offset '.$ChunkBaseOffset); + break; + } + } + + $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['audio']['bitrate']; + + if (isset($thisfile_vqf['DSIZ']) && (($thisfile_vqf['DSIZ'] != ($info['avdataend'] - $info['avdataoffset'] - strlen('DATA'))))) { + switch ($thisfile_vqf['DSIZ']) { + case 0: + case 1: + $this->warning('Invalid DSIZ value "'.$thisfile_vqf['DSIZ'].'". This is known to happen with VQF files encoded by Ahead Nero, and seems to be its way of saying this is TwinVQF v'.($thisfile_vqf['DSIZ'] + 1).'.0'); + $info['audio']['encoder'] = 'Ahead Nero'; + break; + + default: + $this->warning('Probable corrupted file - should be '.$thisfile_vqf['DSIZ'].' bytes, actually '.($info['avdataend'] - $info['avdataoffset'] - strlen('DATA'))); + break; + } + } + + return true; + } + + /** + * @param int $frequencyid + * + * @return int + */ + public function VQFchannelFrequencyLookup($frequencyid) { + static $VQFchannelFrequencyLookup = array( + 11 => 11025, + 22 => 22050, + 44 => 44100 + ); + return (isset($VQFchannelFrequencyLookup[$frequencyid]) ? $VQFchannelFrequencyLookup[$frequencyid] : $frequencyid * 1000); + } + + /** + * @param string $shortname + * + * @return string + */ + public function VQFcommentNiceNameLookup($shortname) { + static $VQFcommentNiceNameLookup = array( + 'NAME' => 'title', + 'AUTH' => 'artist', + '(c) ' => 'copyright', + 'FILE' => 'filename', + 'COMT' => 'comment', + 'ALBM' => 'album' + ); + return (isset($VQFcommentNiceNameLookup[$shortname]) ? $VQFcommentNiceNameLookup[$shortname] : $shortname); + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.wavpack.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.wavpack.php new file mode 100644 index 00000000..dfeb85d4 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.audio.wavpack.php @@ -0,0 +1,424 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.audio.wavpack.php // +// module for analyzing WavPack v4.0+ Audio files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} +class getid3_wavpack extends getid3_handler +{ + /** + * Avoid scanning all frames (break after finding ID_RIFF_HEADER and ID_CONFIG_BLOCK, + * significantly faster for very large files but other data may be missed + * + * @var bool + */ + public $quick_parsing = false; + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + + $found_blocks = array(); + while (true) { + + $wavpackheader = $this->fread(32); + + if ($this->ftell() >= $info['avdataend']) { + break; + } elseif (feof($this->getid3->fp)) { + break; + } elseif ( + isset($info['wavpack']['blockheader']['total_samples']) && + isset($info['wavpack']['blockheader']['block_samples']) && + ($info['wavpack']['blockheader']['total_samples'] > 0) && + ($info['wavpack']['blockheader']['block_samples'] > 0) && + (!isset($info['wavpack']['riff_trailer_size']) || ($info['wavpack']['riff_trailer_size'] <= 0)) && + ((isset($info['wavpack']['config_flags']['md5_checksum']) && ($info['wavpack']['config_flags']['md5_checksum'] === false)) || !empty($info['md5_data_source']))) { + break; + } + + $blockheader_offset = $this->ftell() - 32; + $blockheader_magic = substr($wavpackheader, 0, 4); + $blockheader_size = getid3_lib::LittleEndian2Int(substr($wavpackheader, 4, 4)); + + $magic = 'wvpk'; + if ($blockheader_magic != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$blockheader_offset.', found "'.getid3_lib::PrintHexBytes($blockheader_magic).'"'); + switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') { + case 'wavpack': + case 'wvc': + break; + default: + unset($info['fileformat']); + unset($info['audio']); + unset($info['wavpack']); + break; + } + return false; + } + + if (empty($info['wavpack']['blockheader']['block_samples']) || + empty($info['wavpack']['blockheader']['total_samples']) || + ($info['wavpack']['blockheader']['block_samples'] <= 0) || + ($info['wavpack']['blockheader']['total_samples'] <= 0)) { + // Also, it is possible that the first block might not have + // any samples (block_samples == 0) and in this case you should skip blocks + // until you find one with samples because the other information (like + // total_samples) are not guaranteed to be correct until (block_samples > 0) + + // Finally, I have defined a format for files in which the length is not known + // (for example when raw files are created using pipes). In these cases + // total_samples will be -1 and you must seek to the final block to determine + // the total number of samples. + + + $info['audio']['dataformat'] = 'wavpack'; + $info['fileformat'] = 'wavpack'; + $info['audio']['lossless'] = true; + $info['audio']['bitrate_mode'] = 'vbr'; + + $info['wavpack']['blockheader']['offset'] = $blockheader_offset; + $info['wavpack']['blockheader']['magic'] = $blockheader_magic; + $info['wavpack']['blockheader']['size'] = $blockheader_size; + + if ($info['wavpack']['blockheader']['size'] >= 0x100000) { + $this->error('Expecting WavPack block size less than "0x100000", found "'.$info['wavpack']['blockheader']['size'].'" at offset '.$info['wavpack']['blockheader']['offset']); + switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') { + case 'wavpack': + case 'wvc': + break; + default: + unset($info['fileformat']); + unset($info['audio']); + unset($info['wavpack']); + break; + } + return false; + } + + $info['wavpack']['blockheader']['minor_version'] = ord($wavpackheader[8]); + $info['wavpack']['blockheader']['major_version'] = ord($wavpackheader[9]); + + if (($info['wavpack']['blockheader']['major_version'] != 4) || + (($info['wavpack']['blockheader']['minor_version'] < 4) && + ($info['wavpack']['blockheader']['minor_version'] > 16))) { + $this->error('Expecting WavPack version between "4.2" and "4.16", found version "'.$info['wavpack']['blockheader']['major_version'].'.'.$info['wavpack']['blockheader']['minor_version'].'" at offset '.$info['wavpack']['blockheader']['offset']); + switch (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '') { + case 'wavpack': + case 'wvc': + break; + default: + unset($info['fileformat']); + unset($info['audio']); + unset($info['wavpack']); + break; + } + return false; + } + + $info['wavpack']['blockheader']['track_number'] = ord($wavpackheader[10]); // unused + $info['wavpack']['blockheader']['index_number'] = ord($wavpackheader[11]); // unused + $info['wavpack']['blockheader']['total_samples'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 12, 4)); + $info['wavpack']['blockheader']['block_index'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 16, 4)); + $info['wavpack']['blockheader']['block_samples'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 20, 4)); + $info['wavpack']['blockheader']['flags_raw'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 24, 4)); + $info['wavpack']['blockheader']['crc'] = getid3_lib::LittleEndian2Int(substr($wavpackheader, 28, 4)); + + $info['wavpack']['blockheader']['flags']['bytes_per_sample'] = 1 + ($info['wavpack']['blockheader']['flags_raw'] & 0x00000003); + $info['wavpack']['blockheader']['flags']['mono'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000004); + $info['wavpack']['blockheader']['flags']['hybrid'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000008); + $info['wavpack']['blockheader']['flags']['joint_stereo'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000010); + $info['wavpack']['blockheader']['flags']['cross_decorrelation'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000020); + $info['wavpack']['blockheader']['flags']['hybrid_noiseshape'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000040); + $info['wavpack']['blockheader']['flags']['ieee_32bit_float'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000080); + $info['wavpack']['blockheader']['flags']['int_32bit'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000100); + $info['wavpack']['blockheader']['flags']['hybrid_bitrate_noise'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000200); + $info['wavpack']['blockheader']['flags']['hybrid_balance_noise'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000400); + $info['wavpack']['blockheader']['flags']['multichannel_initial'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00000800); + $info['wavpack']['blockheader']['flags']['multichannel_final'] = (bool) ($info['wavpack']['blockheader']['flags_raw'] & 0x00001000); + + $info['audio']['lossless'] = !$info['wavpack']['blockheader']['flags']['hybrid']; + } + + while (!feof($this->getid3->fp) && ($this->ftell() < ($blockheader_offset + $blockheader_size + 8))) { + + $metablock = array('offset'=>$this->ftell()); + $metablockheader = $this->fread(2); + if (feof($this->getid3->fp)) { + break; + } + $metablock['id'] = ord($metablockheader[0]); + $metablock['function_id'] = ($metablock['id'] & 0x3F); + $metablock['function_name'] = $this->WavPackMetablockNameLookup($metablock['function_id']); + $found_blocks[$metablock['function_name']] = (isset($found_blocks[$metablock['function_name']]) ? $found_blocks[$metablock['function_name']] : 0) + 1; // cannot use getid3_lib::safe_inc without warnings(?) + + // The 0x20 bit in the id of the meta subblocks (which is defined as + // ID_OPTIONAL_DATA) is a permanent part of the id. The idea is that + // if a decoder encounters an id that it does not know about, it uses + // that "ID_OPTIONAL_DATA" flag to determine what to do. If it is set + // then the decoder simply ignores the metadata, but if it is zero + // then the decoder should quit because it means that an understanding + // of the metadata is required to correctly decode the audio. + $metablock['non_decoder'] = (bool) ($metablock['id'] & 0x20); + + $metablock['padded_data'] = (bool) ($metablock['id'] & 0x40); + $metablock['large_block'] = (bool) ($metablock['id'] & 0x80); + if ($metablock['large_block']) { + $metablockheader .= $this->fread(2); + } + $metablock['size'] = getid3_lib::LittleEndian2Int(substr($metablockheader, 1)) * 2; // size is stored in words + $metablock['data'] = null; + $metablock['comments'] = array(); + + if ($metablock['size'] > 0) { + + switch ($metablock['function_id']) { + case 0x21: // ID_RIFF_HEADER + case 0x22: // ID_RIFF_TRAILER + case 0x23: // ID_REPLAY_GAIN + case 0x24: // ID_CUESHEET + case 0x25: // ID_CONFIG_BLOCK + case 0x26: // ID_MD5_CHECKSUM + $metablock['data'] = $this->fread($metablock['size']); + + if ($metablock['padded_data']) { + // padded to the nearest even byte + $metablock['size']--; + $metablock['data'] = substr($metablock['data'], 0, -1); + } + break; + + case 0x00: // ID_DUMMY + case 0x01: // ID_ENCODER_INFO + case 0x02: // ID_DECORR_TERMS + case 0x03: // ID_DECORR_WEIGHTS + case 0x04: // ID_DECORR_SAMPLES + case 0x05: // ID_ENTROPY_VARS + case 0x06: // ID_HYBRID_PROFILE + case 0x07: // ID_SHAPING_WEIGHTS + case 0x08: // ID_FLOAT_INFO + case 0x09: // ID_INT32_INFO + case 0x0A: // ID_WV_BITSTREAM + case 0x0B: // ID_WVC_BITSTREAM + case 0x0C: // ID_WVX_BITSTREAM + case 0x0D: // ID_CHANNEL_INFO + $this->fseek($metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size']); + break; + + default: + $this->warning('Unexpected metablock type "0x'.str_pad(dechex($metablock['function_id']), 2, '0', STR_PAD_LEFT).'" at offset '.$metablock['offset']); + $this->fseek($metablock['offset'] + ($metablock['large_block'] ? 4 : 2) + $metablock['size']); + break; + } + + switch ($metablock['function_id']) { + case 0x21: // ID_RIFF_HEADER + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); + $original_wav_filesize = getid3_lib::LittleEndian2Int(substr($metablock['data'], 4, 4)); + + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_riff = new getid3_riff($getid3_temp); + $getid3_riff->ParseRIFFdata($metablock['data']); + $metablock['riff'] = $getid3_temp->info['riff']; + $info['audio']['sample_rate'] = $getid3_temp->info['riff']['raw']['fmt ']['nSamplesPerSec']; + unset($getid3_riff, $getid3_temp); + + $metablock['riff']['original_filesize'] = $original_wav_filesize; + $info['wavpack']['riff_trailer_size'] = $original_wav_filesize - $metablock['riff']['WAVE']['data'][0]['size'] - $metablock['riff']['header_size']; + $info['playtime_seconds'] = $info['wavpack']['blockheader']['total_samples'] / $info['audio']['sample_rate']; + + // Safe RIFF header in case there's a RIFF footer later + $metablockRIFFheader = $metablock['data']; + if ($this->quick_parsing && !empty($found_blocks['RIFF header']) && !empty($found_blocks['Config Block'])) { + $this->warning('WavPack quick-parsing enabled (faster at parsing large fules, but may miss some data)'); + break 2; + } + break; + + + case 0x22: // ID_RIFF_TRAILER + $metablockRIFFfooter = isset($metablockRIFFheader) ? $metablockRIFFheader : ''.$metablock['data']; + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true); + + $startoffset = $metablock['offset'] + ($metablock['large_block'] ? 4 : 2); + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_temp->info['avdataend'] = $info['avdataend']; + //$getid3_temp->info['fileformat'] = 'riff'; + $getid3_riff = new getid3_riff($getid3_temp); + $metablock['riff'] = $getid3_riff->ParseRIFF($startoffset, $startoffset + $metablock['size']); + + if (!empty($metablock['riff']['INFO'])) { + getid3_riff::parseComments($metablock['riff']['INFO'], $metablock['comments']); + $info['tags']['riff'] = $metablock['comments']; + } + unset($getid3_temp, $getid3_riff); + break; + + + case 0x23: // ID_REPLAY_GAIN + $this->warning('WavPack "Replay Gain" contents not yet handled by getID3() in metablock at offset '.$metablock['offset']); + break; + + + case 0x24: // ID_CUESHEET + $this->warning('WavPack "Cuesheet" contents not yet handled by getID3() in metablock at offset '.$metablock['offset']); + break; + + + case 0x25: // ID_CONFIG_BLOCK + $metablock['flags_raw'] = getid3_lib::LittleEndian2Int(substr($metablock['data'], 0, 3)); + + $metablock['flags']['adobe_mode'] = (bool) ($metablock['flags_raw'] & 0x000001); // "adobe" mode for 32-bit floats + $metablock['flags']['fast_flag'] = (bool) ($metablock['flags_raw'] & 0x000002); // fast mode + $metablock['flags']['very_fast_flag'] = (bool) ($metablock['flags_raw'] & 0x000004); // double fast + $metablock['flags']['high_flag'] = (bool) ($metablock['flags_raw'] & 0x000008); // high quality mode + $metablock['flags']['very_high_flag'] = (bool) ($metablock['flags_raw'] & 0x000010); // double high (not used yet) + $metablock['flags']['bitrate_kbps'] = (bool) ($metablock['flags_raw'] & 0x000020); // bitrate is kbps, not bits / sample + $metablock['flags']['auto_shaping'] = (bool) ($metablock['flags_raw'] & 0x000040); // automatic noise shaping + $metablock['flags']['shape_override'] = (bool) ($metablock['flags_raw'] & 0x000080); // shaping mode specified + $metablock['flags']['joint_override'] = (bool) ($metablock['flags_raw'] & 0x000100); // joint-stereo mode specified + $metablock['flags']['copy_time'] = (bool) ($metablock['flags_raw'] & 0x000200); // copy file-time from source + $metablock['flags']['create_exe'] = (bool) ($metablock['flags_raw'] & 0x000400); // create executable + $metablock['flags']['create_wvc'] = (bool) ($metablock['flags_raw'] & 0x000800); // create correction file + $metablock['flags']['optimize_wvc'] = (bool) ($metablock['flags_raw'] & 0x001000); // maximize bybrid compression + $metablock['flags']['quality_mode'] = (bool) ($metablock['flags_raw'] & 0x002000); // psychoacoustic quality mode + $metablock['flags']['raw_flag'] = (bool) ($metablock['flags_raw'] & 0x004000); // raw mode (not implemented yet) + $metablock['flags']['calc_noise'] = (bool) ($metablock['flags_raw'] & 0x008000); // calc noise in hybrid mode + $metablock['flags']['lossy_mode'] = (bool) ($metablock['flags_raw'] & 0x010000); // obsolete (for information) + $metablock['flags']['extra_mode'] = (bool) ($metablock['flags_raw'] & 0x020000); // extra processing mode + $metablock['flags']['skip_wvx'] = (bool) ($metablock['flags_raw'] & 0x040000); // no wvx stream w/ floats & big ints + $metablock['flags']['md5_checksum'] = (bool) ($metablock['flags_raw'] & 0x080000); // compute & store MD5 signature + $metablock['flags']['quiet_mode'] = (bool) ($metablock['flags_raw'] & 0x100000); // don't report progress % + + $info['wavpack']['config_flags'] = $metablock['flags']; + + + $info['audio']['encoder_options'] = ''; + if ($info['wavpack']['blockheader']['flags']['hybrid']) { + $info['audio']['encoder_options'] .= ' -b???'; + } + $info['audio']['encoder_options'] .= ($metablock['flags']['adobe_mode'] ? ' -a' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['optimize_wvc'] ? ' -cc' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['create_exe'] ? ' -e' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['fast_flag'] ? ' -f' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['joint_override'] ? ' -j?' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['high_flag'] ? ' -h' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['md5_checksum'] ? ' -m' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['calc_noise'] ? ' -n' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['shape_override'] ? ' -s?' : ''); + $info['audio']['encoder_options'] .= ($metablock['flags']['extra_mode'] ? ' -x?' : ''); + if (!empty($info['audio']['encoder_options'])) { + $info['audio']['encoder_options'] = trim($info['audio']['encoder_options']); + } elseif (isset($info['audio']['encoder_options'])) { + unset($info['audio']['encoder_options']); + } + if ($this->quick_parsing && !empty($found_blocks['RIFF header']) && !empty($found_blocks['Config Block'])) { + $this->warning('WavPack quick-parsing enabled (faster at parsing large fules, but may miss some data)'); + break 2; + } + break; + + + case 0x26: // ID_MD5_CHECKSUM + if (strlen($metablock['data']) == 16) { + $info['md5_data_source'] = strtolower(getid3_lib::PrintHexBytes($metablock['data'], true, false, false)); + } else { + $this->warning('Expecting 16 bytes of WavPack "MD5 Checksum" in metablock at offset '.$metablock['offset'].', but found '.strlen($metablock['data']).' bytes'); + } + break; + + + case 0x00: // ID_DUMMY + case 0x01: // ID_ENCODER_INFO + case 0x02: // ID_DECORR_TERMS + case 0x03: // ID_DECORR_WEIGHTS + case 0x04: // ID_DECORR_SAMPLES + case 0x05: // ID_ENTROPY_VARS + case 0x06: // ID_HYBRID_PROFILE + case 0x07: // ID_SHAPING_WEIGHTS + case 0x08: // ID_FLOAT_INFO + case 0x09: // ID_INT32_INFO + case 0x0A: // ID_WV_BITSTREAM + case 0x0B: // ID_WVC_BITSTREAM + case 0x0C: // ID_WVX_BITSTREAM + case 0x0D: // ID_CHANNEL_INFO + unset($metablock); + break; + } + + } + if (!empty($metablock)) { + $info['wavpack']['metablocks'][] = $metablock; + } + + } + + } + + $info['audio']['encoder'] = 'WavPack v'.$info['wavpack']['blockheader']['major_version'].'.'.str_pad($info['wavpack']['blockheader']['minor_version'], 2, '0', STR_PAD_LEFT); + $info['audio']['bits_per_sample'] = $info['wavpack']['blockheader']['flags']['bytes_per_sample'] * 8; + $info['audio']['channels'] = ($info['wavpack']['blockheader']['flags']['mono'] ? 1 : 2); + + if (!empty($info['playtime_seconds'])) { + + $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds']; + + } else { + + $info['audio']['dataformat'] = 'wvc'; + + } + return true; + } + + /** + * @param int $id + * + * @return string + */ + public function WavPackMetablockNameLookup(&$id) { + static $WavPackMetablockNameLookup = array( + 0x00 => 'Dummy', + 0x01 => 'Encoder Info', + 0x02 => 'Decorrelation Terms', + 0x03 => 'Decorrelation Weights', + 0x04 => 'Decorrelation Samples', + 0x05 => 'Entropy Variables', + 0x06 => 'Hybrid Profile', + 0x07 => 'Shaping Weights', + 0x08 => 'Float Info', + 0x09 => 'Int32 Info', + 0x0A => 'WV Bitstream', + 0x0B => 'WVC Bitstream', + 0x0C => 'WVX Bitstream', + 0x0D => 'Channel Info', + 0x21 => 'RIFF header', + 0x22 => 'RIFF trailer', + 0x23 => 'Replay Gain', + 0x24 => 'Cuesheet', + 0x25 => 'Config Block', + 0x26 => 'MD5 Checksum', + ); + return (isset($WavPackMetablockNameLookup[$id]) ? $WavPackMetablockNameLookup[$id] : ''); + } + +} diff --git a/serendipity_event_podcast/player/getid3/module.graphic.bmp.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.bmp.php similarity index 85% rename from serendipity_event_podcast/player/getid3/module.graphic.bmp.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.bmp.php index d3f17da3..84565701 100644 --- a/serendipity_event_podcast/player/getid3/module.graphic.bmp.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.bmp.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.graphic.bmp.php // @@ -13,15 +14,35 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_bmp +class getid3_bmp extends getid3_handler { + /** + * return BMP palette + * + * @var bool + */ + public $ExtractPalette = false; - function getid3_bmp(&$fd, &$ThisFileInfo, $ExtractPalette=false, $ExtractData=false) { + /** + * return image data + * + * @var bool + */ + public $ExtractData = false; + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; // shortcuts - $ThisFileInfo['bmp']['header']['raw'] = array(); - $thisfile_bmp = &$ThisFileInfo['bmp']; + $info['bmp']['header']['raw'] = array(); + $thisfile_bmp = &$info['bmp']; $thisfile_bmp_header = &$thisfile_bmp['header']; $thisfile_bmp_header_raw = &$thisfile_bmp_header['raw']; @@ -33,17 +54,18 @@ class getid3_bmp // WORD bfReserved2; // DWORD bfOffBits; - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); + $this->fseek($info['avdataoffset']); $offset = 0; - $BMPheader = fread($fd, 14 + 40); + $BMPheader = $this->fread(14 + 40); $thisfile_bmp_header_raw['identifier'] = substr($BMPheader, $offset, 2); $offset += 2; - if ($thisfile_bmp_header_raw['identifier'] != 'BM') { - $ThisFileInfo['error'][] = 'Expecting "BM" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$thisfile_bmp_header_raw['identifier'].'"'; - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['bmp']); + $magic = 'BM'; + if ($thisfile_bmp_header_raw['identifier'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($thisfile_bmp_header_raw['identifier']).'"'); + unset($info['fileformat']); + unset($info['bmp']); return false; } @@ -81,16 +103,16 @@ class getid3_bmp $thisfile_bmp['type_os'] = 'Windows'; $thisfile_bmp['type_version'] = 5; } else { - $ThisFileInfo['error'][] = 'Unknown BMP subtype (or not a BMP file)'; - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['bmp']); + $this->error('Unknown BMP subtype (or not a BMP file)'); + unset($info['fileformat']); + unset($info['bmp']); return false; } - $ThisFileInfo['fileformat'] = 'bmp'; - $ThisFileInfo['video']['dataformat'] = 'bmp'; - $ThisFileInfo['video']['lossless'] = true; - $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1; + $info['fileformat'] = 'bmp'; + $info['video']['dataformat'] = 'bmp'; + $info['video']['lossless'] = true; + $info['video']['pixel_aspect_ratio'] = (float) 1; if ($thisfile_bmp['type_os'] == 'OS/2') { @@ -112,10 +134,10 @@ class getid3_bmp $thisfile_bmp_header_raw['bits_per_pixel'] = getid3_lib::LittleEndian2Int(substr($BMPheader, $offset, 2)); $offset += 2; - $ThisFileInfo['video']['resolution_x'] = $thisfile_bmp_header_raw['width']; - $ThisFileInfo['video']['resolution_y'] = $thisfile_bmp_header_raw['height']; - $ThisFileInfo['video']['codec'] = 'BI_RGB '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit'; - $ThisFileInfo['video']['bits_per_sample'] = $thisfile_bmp_header_raw['bits_per_pixel']; + $info['video']['resolution_x'] = $thisfile_bmp_header_raw['width']; + $info['video']['resolution_y'] = $thisfile_bmp_header_raw['height']; + $info['video']['codec'] = 'BI_RGB '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit'; + $info['video']['bits_per_sample'] = $thisfile_bmp_header_raw['bits_per_pixel']; if ($thisfile_bmp['type_version'] >= 2) { // DWORD Compression; /* Bitmap compression scheme */ @@ -164,7 +186,7 @@ class getid3_bmp $thisfile_bmp_header['compression'] = $this->BMPcompressionOS2Lookup($thisfile_bmp_header_raw['compression']); - $ThisFileInfo['video']['codec'] = $thisfile_bmp_header['compression'].' '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit'; + $info['video']['codec'] = $thisfile_bmp_header['compression'].' '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit'; } } elseif ($thisfile_bmp['type_os'] == 'Windows') { @@ -209,14 +231,14 @@ class getid3_bmp $offset += 4; $thisfile_bmp_header['compression'] = $this->BMPcompressionWindowsLookup($thisfile_bmp_header_raw['compression']); - $ThisFileInfo['video']['resolution_x'] = $thisfile_bmp_header_raw['width']; - $ThisFileInfo['video']['resolution_y'] = $thisfile_bmp_header_raw['height']; - $ThisFileInfo['video']['codec'] = $thisfile_bmp_header['compression'].' '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit'; - $ThisFileInfo['video']['bits_per_sample'] = $thisfile_bmp_header_raw['bits_per_pixel']; + $info['video']['resolution_x'] = $thisfile_bmp_header_raw['width']; + $info['video']['resolution_y'] = $thisfile_bmp_header_raw['height']; + $info['video']['codec'] = $thisfile_bmp_header['compression'].' '.$thisfile_bmp_header_raw['bits_per_pixel'].'-bit'; + $info['video']['bits_per_sample'] = $thisfile_bmp_header_raw['bits_per_pixel']; if (($thisfile_bmp['type_version'] >= 4) || ($thisfile_bmp_header_raw['compression'] == 3)) { // should only be v4+, but BMPs with type_version==1 and BI_BITFIELDS compression have been seen - $BMPheader .= fread($fd, 44); + $BMPheader .= $this->fread(44); // BITMAPV4HEADER - [44 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_2k1e.asp // Win95+, WinNT4.0+ @@ -258,7 +280,7 @@ class getid3_bmp } if ($thisfile_bmp['type_version'] >= 5) { - $BMPheader .= fread($fd, 16); + $BMPheader .= $this->fread(16); // BITMAPV5HEADER - [16 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_7c36.asp // Win98+, Win2000+ @@ -278,13 +300,13 @@ class getid3_bmp } else { - $ThisFileInfo['error'][] = 'Unknown BMP format in header.'; + $this->error('Unknown BMP format in header.'); return false; } - if ($ExtractPalette || $ExtractData) { + if ($this->ExtractPalette || $this->ExtractData) { $PaletteEntries = 0; if ($thisfile_bmp_header_raw['bits_per_pixel'] < 16) { $PaletteEntries = pow(2, $thisfile_bmp_header_raw['bits_per_pixel']); @@ -292,7 +314,7 @@ class getid3_bmp $PaletteEntries = $thisfile_bmp_header_raw['colors_used']; } if ($PaletteEntries > 0) { - $BMPpalette = fread($fd, 4 * $PaletteEntries); + $BMPpalette = $this->fread(4 * $PaletteEntries); $paletteoffset = 0; for ($i = 0; $i < $PaletteEntries; $i++) { // RGBQUAD - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_5f8y.asp @@ -313,10 +335,10 @@ class getid3_bmp } } - if ($ExtractData) { - fseek($fd, $thisfile_bmp_header_raw['data_offset'], SEEK_SET); + if ($this->ExtractData) { + $this->fseek($thisfile_bmp_header_raw['data_offset']); $RowByteLength = ceil(($thisfile_bmp_header_raw['width'] * ($thisfile_bmp_header_raw['bits_per_pixel'] / 8)) / 4) * 4; // round up to nearest DWORD boundry - $BMPpixelData = fread($fd, $thisfile_bmp_header_raw['height'] * $RowByteLength); + $BMPpixelData = $this->fread($thisfile_bmp_header_raw['height'] * $RowByteLength); $pixeldataoffset = 0; $thisfile_bmp_header_raw['compression'] = (isset($thisfile_bmp_header_raw['compression']) ? $thisfile_bmp_header_raw['compression'] : ''); switch ($thisfile_bmp_header_raw['compression']) { @@ -326,7 +348,7 @@ class getid3_bmp case 1: for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col = $col) { - $paletteindexbyte = ord($BMPpixelData{$pixeldataoffset++}); + $paletteindexbyte = ord($BMPpixelData[$pixeldataoffset++]); for ($i = 7; $i >= 0; $i--) { $paletteindex = ($paletteindexbyte & (0x01 << $i)) >> $i; $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; @@ -343,7 +365,7 @@ class getid3_bmp case 4: for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col = $col) { - $paletteindexbyte = ord($BMPpixelData{$pixeldataoffset++}); + $paletteindexbyte = ord($BMPpixelData[$pixeldataoffset++]); for ($i = 1; $i >= 0; $i--) { $paletteindex = ($paletteindexbyte & (0x0F << (4 * $i))) >> (4 * $i); $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; @@ -360,7 +382,7 @@ class getid3_bmp case 8: for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) { - $paletteindex = ord($BMPpixelData{$pixeldataoffset++}); + $paletteindex = ord($BMPpixelData[$pixeldataoffset++]); $thisfile_bmp['data'][$row][$col] = $thisfile_bmp['palette'][$paletteindex]; } while (($pixeldataoffset % 4) != 0) { @@ -373,7 +395,7 @@ class getid3_bmp case 24: for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) { - $thisfile_bmp['data'][$row][$col] = (ord($BMPpixelData{$pixeldataoffset+2}) << 16) | (ord($BMPpixelData{$pixeldataoffset+1}) << 8) | ord($BMPpixelData{$pixeldataoffset}); + $thisfile_bmp['data'][$row][$col] = (ord($BMPpixelData[$pixeldataoffset+2]) << 16) | (ord($BMPpixelData[$pixeldataoffset+1]) << 8) | ord($BMPpixelData[$pixeldataoffset]); $pixeldataoffset += 3; } while (($pixeldataoffset % 4) != 0) { @@ -386,7 +408,7 @@ class getid3_bmp case 32: for ($row = ($thisfile_bmp_header_raw['height'] - 1); $row >= 0; $row--) { for ($col = 0; $col < $thisfile_bmp_header_raw['width']; $col++) { - $thisfile_bmp['data'][$row][$col] = (ord($BMPpixelData{$pixeldataoffset+3}) << 24) | (ord($BMPpixelData{$pixeldataoffset+2}) << 16) | (ord($BMPpixelData{$pixeldataoffset+1}) << 8) | ord($BMPpixelData{$pixeldataoffset}); + $thisfile_bmp['data'][$row][$col] = (ord($BMPpixelData[$pixeldataoffset+3]) << 24) | (ord($BMPpixelData[$pixeldataoffset+2]) << 16) | (ord($BMPpixelData[$pixeldataoffset+1]) << 8) | ord($BMPpixelData[$pixeldataoffset]); $pixeldataoffset += 4; } while (($pixeldataoffset % 4) != 0) { @@ -401,7 +423,7 @@ class getid3_bmp break; default: - $ThisFileInfo['error'][] = 'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'; + $this->error('Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'); break; } break; @@ -476,7 +498,7 @@ class getid3_bmp break; default: - $ThisFileInfo['error'][] = 'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'; + $this->error('Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'); break; } break; @@ -487,6 +509,7 @@ class getid3_bmp switch ($thisfile_bmp_header_raw['bits_per_pixel']) { case 4: $pixelcounter = 0; + $paletteindexes = array(); while ($pixeldataoffset < strlen($BMPpixelData)) { $firstbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); $secondbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); @@ -522,7 +545,7 @@ class getid3_bmp // of color indexes that follow. Subsequent bytes contain color indexes in their // high- and low-order 4 bits, one color index for each pixel. In absolute mode, // each run must be aligned on a word boundary. - unset($paletteindexes); + $paletteindexes = array(); for ($i = 0; $i < ceil($secondbyte / 2); $i++) { $paletteindexbyte = getid3_lib::LittleEndian2Int(substr($BMPpixelData, $pixeldataoffset++, 1)); $paletteindexes[] = ($paletteindexbyte & 0xF0) >> 4; @@ -565,7 +588,7 @@ class getid3_bmp break; default: - $ThisFileInfo['error'][] = 'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'; + $this->error('Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'); break; } break; @@ -605,14 +628,14 @@ class getid3_bmp break; default: - $ThisFileInfo['error'][] = 'Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'; + $this->error('Unknown bits-per-pixel value ('.$thisfile_bmp_header_raw['bits_per_pixel'].') - cannot read pixel data'); break; } break; default: // unhandled compression type - $ThisFileInfo['error'][] = 'Unknown/unhandled compression type value ('.$thisfile_bmp_header_raw['compression'].') - cannot decompress pixel data'; + $this->error('Unknown/unhandled compression type value ('.$thisfile_bmp_header_raw['compression'].') - cannot decompress pixel data'); break; } } @@ -620,23 +643,27 @@ class getid3_bmp return true; } - - function PlotBMP(&$BMPinfo) { + /** + * @param array $BMPinfo + * + * @return bool + */ + public function PlotBMP(&$BMPinfo) { $starttime = time(); if (!isset($BMPinfo['bmp']['data']) || !is_array($BMPinfo['bmp']['data'])) { echo 'ERROR: no pixel data
    '; return false; } set_time_limit(intval(round($BMPinfo['resolution_x'] * $BMPinfo['resolution_y'] / 10000))); - if ($im = ImageCreateTrueColor($BMPinfo['resolution_x'], $BMPinfo['resolution_y'])) { + if ($im = imagecreatetruecolor($BMPinfo['resolution_x'], $BMPinfo['resolution_y'])) { for ($row = 0; $row < $BMPinfo['resolution_y']; $row++) { for ($col = 0; $col < $BMPinfo['resolution_x']; $col++) { if (isset($BMPinfo['bmp']['data'][$row][$col])) { $red = ($BMPinfo['bmp']['data'][$row][$col] & 0x00FF0000) >> 16; $green = ($BMPinfo['bmp']['data'][$row][$col] & 0x0000FF00) >> 8; $blue = ($BMPinfo['bmp']['data'][$row][$col] & 0x000000FF); - $pixelcolor = ImageColorAllocate($im, $red, $green, $blue); - ImageSetPixel($im, $col, $row, $pixelcolor); + $pixelcolor = imagecolorallocate($im, $red, $green, $blue); + imagesetpixel($im, $col, $row, $pixelcolor); } else { //echo 'ERROR: no data for pixel '.$row.' x '.$col.'
    '; //return false; @@ -645,19 +672,24 @@ class getid3_bmp } if (headers_sent()) { echo 'plotted '.($BMPinfo['resolution_x'] * $BMPinfo['resolution_y']).' pixels in '.(time() - $starttime).' seconds
    '; - ImageDestroy($im); + imagedestroy($im); exit; } else { header('Content-type: image/png'); - ImagePNG($im); - ImageDestroy($im); + imagepng($im); + imagedestroy($im); return true; } } return false; } - function BMPcompressionWindowsLookup($compressionid) { + /** + * @param int $compressionid + * + * @return string + */ + public function BMPcompressionWindowsLookup($compressionid) { static $BMPcompressionWindowsLookup = array( 0 => 'BI_RGB', 1 => 'BI_RLE8', @@ -669,7 +701,12 @@ class getid3_bmp return (isset($BMPcompressionWindowsLookup[$compressionid]) ? $BMPcompressionWindowsLookup[$compressionid] : 'invalid'); } - function BMPcompressionOS2Lookup($compressionid) { + /** + * @param int $compressionid + * + * @return string + */ + public function BMPcompressionOS2Lookup($compressionid) { static $BMPcompressionOS2Lookup = array( 0 => 'BI_RGB', 1 => 'BI_RLE8', @@ -681,6 +718,3 @@ class getid3_bmp } } - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.efax.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.efax.php new file mode 100644 index 00000000..82ea3544 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.efax.php @@ -0,0 +1,54 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.archive.efax.php // +// module for analyzing eFax files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_efax extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + $efaxheader = $this->fread(1024); + + $info['efax']['header']['magic'] = substr($efaxheader, 0, 2); + if ($info['efax']['header']['magic'] != "\xDC\xFE") { + $this->error('Invalid eFax byte order identifier (expecting DC FE, found '.getid3_lib::PrintHexBytes($info['efax']['header']['magic']).') at offset '.$info['avdataoffset']); + return false; + } + $info['fileformat'] = 'efax'; + + $info['efax']['header']['filesize'] = getid3_lib::LittleEndian2Int(substr($efaxheader, 2, 4)); + if ($info['efax']['header']['filesize'] != $info['filesize']) { + $this->error('Probable '.(($info['efax']['header']['filesize'] > $info['filesize']) ? 'truncated' : 'corrupt').' file, expecting '.$info['efax']['header']['filesize'].' bytes, found '.$info['filesize'].' bytes'); + } + $info['efax']['header']['software1'] = rtrim(substr($efaxheader, 26, 32), "\x00"); + $info['efax']['header']['software2'] = rtrim(substr($efaxheader, 58, 32), "\x00"); + $info['efax']['header']['software3'] = rtrim(substr($efaxheader, 90, 32), "\x00"); + + $info['efax']['header']['pages'] = getid3_lib::LittleEndian2Int(substr($efaxheader, 198, 2)); + $info['efax']['header']['data_bytes'] = getid3_lib::LittleEndian2Int(substr($efaxheader, 202, 4)); + + $this->error('eFax parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + return false; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.gif.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.gif.php new file mode 100644 index 00000000..f9719137 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.gif.php @@ -0,0 +1,235 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.graphic.gif.php // +// module for analyzing GIF Image files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +/** + * @link https://www.w3.org/Graphics/GIF/spec-gif89a.txt + * @link http://www.matthewflickinger.com/lab/whatsinagif/bits_and_bytes.asp + * @link http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension + */ + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_gif extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'gif'; + $info['video']['dataformat'] = 'gif'; + $info['video']['lossless'] = true; + $info['video']['pixel_aspect_ratio'] = (float) 1; + + $this->fseek($info['avdataoffset']); + $GIFheader = $this->fread(13); + $offset = 0; + + $info['gif']['header']['raw']['identifier'] = substr($GIFheader, $offset, 3); + $offset += 3; + + $magic = 'GIF'; + if ($info['gif']['header']['raw']['identifier'] != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['gif']['header']['raw']['identifier']).'"'); + unset($info['fileformat']); + unset($info['gif']); + return false; + } + + //if (!$this->getid3->option_extra_info) { + // $this->warning('GIF Extensions and Global Color Table not returned due to !getid3->option_extra_info'); + //} + + $info['gif']['header']['raw']['version'] = substr($GIFheader, $offset, 3); + $offset += 3; + $info['gif']['header']['raw']['width'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 2)); + $offset += 2; + $info['gif']['header']['raw']['height'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 2)); + $offset += 2; + $info['gif']['header']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1)); + $offset += 1; + $info['gif']['header']['raw']['bg_color_index'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1)); + $offset += 1; + $info['gif']['header']['raw']['aspect_ratio'] = getid3_lib::LittleEndian2Int(substr($GIFheader, $offset, 1)); + $offset += 1; + + $info['video']['resolution_x'] = $info['gif']['header']['raw']['width']; + $info['video']['resolution_y'] = $info['gif']['header']['raw']['height']; + $info['gif']['version'] = $info['gif']['header']['raw']['version']; + $info['gif']['header']['flags']['global_color_table'] = (bool) ($info['gif']['header']['raw']['flags'] & 0x80); + if ($info['gif']['header']['raw']['flags'] & 0x80) { + // Number of bits per primary color available to the original image, minus 1 + $info['gif']['header']['bits_per_pixel'] = 3 * ((($info['gif']['header']['raw']['flags'] & 0x70) >> 4) + 1); + } else { + $info['gif']['header']['bits_per_pixel'] = 0; + } + $info['gif']['header']['flags']['global_color_sorted'] = (bool) ($info['gif']['header']['raw']['flags'] & 0x40); + if ($info['gif']['header']['flags']['global_color_table']) { + // the number of bytes contained in the Global Color Table. To determine that + // actual size of the color table, raise 2 to [the value of the field + 1] + $info['gif']['header']['global_color_size'] = pow(2, ($info['gif']['header']['raw']['flags'] & 0x07) + 1); + $info['video']['bits_per_sample'] = ($info['gif']['header']['raw']['flags'] & 0x07) + 1; + } else { + $info['gif']['header']['global_color_size'] = 0; + } + if ($info['gif']['header']['raw']['aspect_ratio'] != 0) { + // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64 + $info['gif']['header']['aspect_ratio'] = ($info['gif']['header']['raw']['aspect_ratio'] + 15) / 64; + } + + if ($info['gif']['header']['flags']['global_color_table']) { + $GIFcolorTable = $this->fread(3 * $info['gif']['header']['global_color_size']); + if ($this->getid3->option_extra_info) { + $offset = 0; + for ($i = 0; $i < $info['gif']['header']['global_color_size']; $i++) { + $red = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1)); + $green = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1)); + $blue = getid3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1)); + $info['gif']['global_color_table'][$i] = (($red << 16) | ($green << 8) | ($blue)); + $info['gif']['global_color_table_rgb'][$i] = sprintf('%02X%02X%02X', $red, $green, $blue); + } + } + } + + // Image Descriptor + $info['gif']['animation']['animated'] = false; + while (!feof($this->getid3->fp)) { + $NextBlockTest = $this->fread(1); + switch ($NextBlockTest) { + +/* + case ',': // ',' - Image separator character + $ImageDescriptorData = $NextBlockTest.$this->fread(9); + $ImageDescriptor = array(); + $ImageDescriptor['image_left'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 1, 2)); + $ImageDescriptor['image_top'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 3, 2)); + $ImageDescriptor['image_width'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 5, 2)); + $ImageDescriptor['image_height'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 7, 2)); + $ImageDescriptor['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ImageDescriptorData, 9, 1)); + $ImageDescriptor['flags']['use_local_color_map'] = (bool) ($ImageDescriptor['flags_raw'] & 0x80); + $ImageDescriptor['flags']['image_interlaced'] = (bool) ($ImageDescriptor['flags_raw'] & 0x40); + $info['gif']['image_descriptor'][] = $ImageDescriptor; + + if ($ImageDescriptor['flags']['use_local_color_map']) { + + $this->warning('This version of getID3() cannot parse local color maps for GIFs'); + return true; + + } + $RasterData = array(); + $RasterData['code_size'] = getid3_lib::LittleEndian2Int($this->fread(1)); + $RasterData['block_byte_count'] = getid3_lib::LittleEndian2Int($this->fread(1)); + $info['gif']['raster_data'][count($info['gif']['image_descriptor']) - 1] = $RasterData; + + $CurrentCodeSize = $RasterData['code_size'] + 1; + for ($i = 0; $i < pow(2, $RasterData['code_size']); $i++) { + $DefaultDataLookupTable[$i] = chr($i); + } + $DefaultDataLookupTable[pow(2, $RasterData['code_size']) + 0] = ''; // Clear Code + $DefaultDataLookupTable[pow(2, $RasterData['code_size']) + 1] = ''; // End Of Image Code + + $NextValue = $this->GetLSBits($CurrentCodeSize); + echo 'Clear Code: '.$NextValue.'
    '; + + $NextValue = $this->GetLSBits($CurrentCodeSize); + echo 'First Color: '.$NextValue.'
    '; + + $Prefix = $NextValue; + $i = 0; + while ($i++ < 20) { + $NextValue = $this->GetLSBits($CurrentCodeSize); + echo $NextValue.'
    '; + } + echo 'escaping
    '; + return true; + break; +*/ + + case '!': + // GIF Extension Block + $ExtensionBlockData = $NextBlockTest.$this->fread(2); + $ExtensionBlock = array(); + $ExtensionBlock['function_code'] = getid3_lib::LittleEndian2Int(substr($ExtensionBlockData, 1, 1)); + $ExtensionBlock['byte_length'] = getid3_lib::LittleEndian2Int(substr($ExtensionBlockData, 2, 1)); + $ExtensionBlock['data'] = (($ExtensionBlock['byte_length'] > 0) ? $this->fread($ExtensionBlock['byte_length']) : null); + + switch ($ExtensionBlock['function_code']) { + case 0xFF: + // Application Extension + if ($ExtensionBlock['byte_length'] != 11) { + $this->warning('Expected block size of the Application Extension is 11 bytes, found '.$ExtensionBlock['byte_length'].' at offset '.$this->ftell()); + break; + } + + if (substr($ExtensionBlock['data'], 0, 11) !== 'NETSCAPE2.0' + && substr($ExtensionBlock['data'], 0, 11) !== 'ANIMEXTS1.0' + ) { + $this->warning('Ignoring unsupported Application Extension '.substr($ExtensionBlock['data'], 0, 11)); + break; + } + + // Netscape Application Block (NAB) + $ExtensionBlock['data'] .= $this->fread(4); + if (substr($ExtensionBlock['data'], 11, 2) == "\x03\x01") { + $info['gif']['animation']['animated'] = true; + $info['gif']['animation']['loop_count'] = getid3_lib::LittleEndian2Int(substr($ExtensionBlock['data'], 13, 2)); + } else { + $this->warning('Expecting 03 01 at offset '.($this->ftell() - 4).', found "'.getid3_lib::PrintHexBytes(substr($ExtensionBlock['data'], 11, 2)).'"'); + } + + break; + } + + if ($this->getid3->option_extra_info) { + $info['gif']['extension_blocks'][] = $ExtensionBlock; + } + break; + + case ';': + $info['gif']['terminator_offset'] = $this->ftell() - 1; + // GIF Terminator + break; + + default: + break; + + + } + } + + return true; + } + + /** + * @param int $bits + * + * @return float|int + */ + public function GetLSBits($bits) { + static $bitbuffer = ''; + while (strlen($bitbuffer) < $bits) { + $bitbuffer = str_pad(decbin(ord($this->fread(1))), 8, '0', STR_PAD_LEFT).$bitbuffer; + } + $value = bindec(substr($bitbuffer, 0 - $bits)); + $bitbuffer = substr($bitbuffer, 0, 0 - $bits); + + return $value; + } + +} diff --git a/serendipity_event_podcast/player/getid3/module.graphic.jpg.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.jpg.php similarity index 56% rename from serendipity_event_podcast/player/getid3/module.graphic.jpg.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.jpg.php index d74507f7..c6ffad7e 100644 --- a/serendipity_event_podcast/player/getid3/module.graphic.jpg.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.jpg.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.graphic.jpg.php // @@ -14,22 +15,28 @@ // /// ///////////////////////////////////////////////////////////////// - -class getid3_jpg +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} +class getid3_jpg extends getid3_handler { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + $info['fileformat'] = 'jpg'; + $info['video']['dataformat'] = 'jpg'; + $info['video']['lossless'] = false; + $info['video']['bits_per_sample'] = 24; + $info['video']['pixel_aspect_ratio'] = (float) 1; - function getid3_jpg(&$fd, &$ThisFileInfo) { - $ThisFileInfo['fileformat'] = 'jpg'; - $ThisFileInfo['video']['dataformat'] = 'jpg'; - $ThisFileInfo['video']['lossless'] = false; - $ThisFileInfo['video']['bits_per_sample'] = 24; - $ThisFileInfo['video']['pixel_aspect_ratio'] = (float) 1; - - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); + $this->fseek($info['avdataoffset']); $imageinfo = array(); - list($width, $height, $type) = getid3_lib::GetDataImageSize(fread($fd, $ThisFileInfo['filesize']), $imageinfo); + //list($width, $height, $type) = getid3_lib::GetDataImageSize($this->fread($info['filesize']), $imageinfo); + list($width, $height, $type) = getimagesize($info['filenamepath'], $imageinfo); // https://www.getid3.org/phpBB3/viewtopic.php?t=1474 if (isset($imageinfo['APP13'])) { @@ -43,10 +50,10 @@ class getid3_jpg foreach ($iptc_values as $key => $value) { $IPTCrecordName = $this->IPTCrecordName($iptc_record); $IPTCrecordTagName = $this->IPTCrecordTagName($iptc_record, $iptc_tagkey); - if (isset($ThisFileInfo['iptc'][$IPTCrecordName][$IPTCrecordTagName])) { - $ThisFileInfo['iptc'][$IPTCrecordName][$IPTCrecordTagName][] = $value; + if (isset($info['iptc']['comments'][$IPTCrecordName][$IPTCrecordTagName])) { + $info['iptc']['comments'][$IPTCrecordName][$IPTCrecordTagName][] = $value; } else { - $ThisFileInfo['iptc'][$IPTCrecordName][$IPTCrecordTagName] = array($value); + $info['iptc']['comments'][$IPTCrecordName][$IPTCrecordTagName] = array($value); } } } @@ -55,26 +62,29 @@ class getid3_jpg $returnOK = false; switch ($type) { - case IMG_JPG: - $ThisFileInfo['video']['resolution_x'] = $width; - $ThisFileInfo['video']['resolution_y'] = $height; + case IMAGETYPE_JPEG: + $info['video']['resolution_x'] = $width; + $info['video']['resolution_y'] = $height; if (isset($imageinfo['APP1'])) { if (function_exists('exif_read_data')) { if (substr($imageinfo['APP1'], 0, 4) == 'Exif') { - ob_start(); - $ThisFileInfo['jpg']['exif'] = exif_read_data($ThisFileInfo['filenamepath'], '', true, false); - $errors = ob_get_contents(); - if ($errors) { - $ThisFileInfo['warning'][] = strip_tags($errors); - //unset($ThisFileInfo['jpg']['exif']); - } - ob_end_clean(); + //$this->warning('known issue: https://bugs.php.net/bug.php?id=62523'); + //return false; + set_error_handler(function($errno, $errstr, $errfile, $errline) { // https://github.com/JamesHeinrich/getID3/issues/275 + if (!(error_reporting() & $errno)) { + // error is not specified in the error_reporting setting, so we ignore it + return false; + } + $this->warning('Error parsing EXIF data ('.$errstr.')'); + }); + $info['jpg']['exif'] = exif_read_data($info['filenamepath'], null, true, false); + restore_error_handler(); } else { - $ThisFileInfo['warning'][] = 'exif_read_data() cannot parse non-EXIF data in APP1 (expected "Exif", found "'.substr($imageinfo['APP1'], 0, 4).'")'; + $this->warning('exif_read_data() cannot parse non-EXIF data in APP1 (expected "Exif", found "'.substr($imageinfo['APP1'], 0, 4).'")'); } } else { - $ThisFileInfo['warning'][] = 'EXIF parsing only available when '.(GETID3_OS_ISWINDOWS ? 'php_exif.dll enabled' : 'compiled with --enable-exif'); + $this->warning('EXIF parsing only available when '.(GETID3_OS_ISWINDOWS ? 'php_exif.dll enabled' : 'compiled with --enable-exif')); } } $returnOK = true; @@ -87,88 +97,94 @@ class getid3_jpg $cast_as_appropriate_keys = array('EXIF', 'IFD0', 'THUMBNAIL'); foreach ($cast_as_appropriate_keys as $exif_key) { - if (isset($ThisFileInfo['jpg']['exif'][$exif_key])) { - foreach ($ThisFileInfo['jpg']['exif'][$exif_key] as $key => $value) { - $ThisFileInfo['jpg']['exif'][$exif_key][$key] = $this->CastAsAppropriate($value); + if (isset($info['jpg']['exif'][$exif_key])) { + foreach ($info['jpg']['exif'][$exif_key] as $key => $value) { + $info['jpg']['exif'][$exif_key][$key] = $this->CastAsAppropriate($value); } } } - if (isset($ThisFileInfo['jpg']['exif']['GPS'])) { + if (isset($info['jpg']['exif']['GPS'])) { - if (isset($ThisFileInfo['jpg']['exif']['GPS']['GPSVersion'])) { + if (isset($info['jpg']['exif']['GPS']['GPSVersion'])) { + $version_subparts = array(); for ($i = 0; $i < 4; $i++) { - $version_subparts[$i] = ord(substr($ThisFileInfo['jpg']['exif']['GPS']['GPSVersion'], $i, 1)); + $version_subparts[$i] = ord(substr($info['jpg']['exif']['GPS']['GPSVersion'], $i, 1)); } - $ThisFileInfo['jpg']['exif']['GPS']['computed']['version'] = 'v'.implode('.', $version_subparts); + $info['jpg']['exif']['GPS']['computed']['version'] = 'v'.implode('.', $version_subparts); } - if (isset($ThisFileInfo['jpg']['exif']['GPS']['GPSDateStamp'])) { - $explodedGPSDateStamp = explode(':', $ThisFileInfo['jpg']['exif']['GPS']['GPSDateStamp']); + if (isset($info['jpg']['exif']['GPS']['GPSDateStamp'])) { + $explodedGPSDateStamp = explode(':', $info['jpg']['exif']['GPS']['GPSDateStamp']); $computed_time[5] = (isset($explodedGPSDateStamp[0]) ? $explodedGPSDateStamp[0] : ''); $computed_time[3] = (isset($explodedGPSDateStamp[1]) ? $explodedGPSDateStamp[1] : ''); $computed_time[4] = (isset($explodedGPSDateStamp[2]) ? $explodedGPSDateStamp[2] : ''); - if (function_exists('date_default_timezone_set')) { - date_default_timezone_set('UTC'); - } else { - ini_set('date.timezone', 'UTC'); - } - $computed_time = array(0=>0, 1=>0, 2=>0, 3=>0, 4=>0, 5=>0); - if (isset($ThisFileInfo['jpg']['exif']['GPS']['GPSTimeStamp']) && is_array($ThisFileInfo['jpg']['exif']['GPS']['GPSTimeStamp'])) { - foreach ($ThisFileInfo['jpg']['exif']['GPS']['GPSTimeStamp'] as $key => $value) { + if (isset($info['jpg']['exif']['GPS']['GPSTimeStamp']) && is_array($info['jpg']['exif']['GPS']['GPSTimeStamp'])) { + foreach ($info['jpg']['exif']['GPS']['GPSTimeStamp'] as $key => $value) { $computed_time[$key] = getid3_lib::DecimalizeFraction($value); } } - $ThisFileInfo['jpg']['exif']['GPS']['computed']['timestamp'] = mktime($computed_time[0], $computed_time[1], $computed_time[2], $computed_time[3], $computed_time[4], $computed_time[5]); + $info['jpg']['exif']['GPS']['computed']['timestamp'] = gmmktime($computed_time[0], $computed_time[1], $computed_time[2], $computed_time[3], $computed_time[4], $computed_time[5]); } - if (isset($ThisFileInfo['jpg']['exif']['GPS']['GPSLatitude']) && is_array($ThisFileInfo['jpg']['exif']['GPS']['GPSLatitude'])) { - $direction_multiplier = ((isset($ThisFileInfo['jpg']['exif']['GPS']['GPSLatitudeRef']) && ($ThisFileInfo['jpg']['exif']['GPS']['GPSLatitudeRef'] == 'S')) ? -1 : 1); - foreach ($ThisFileInfo['jpg']['exif']['GPS']['GPSLatitude'] as $key => $value) { + if (isset($info['jpg']['exif']['GPS']['GPSLatitude']) && is_array($info['jpg']['exif']['GPS']['GPSLatitude'])) { + $direction_multiplier = ((isset($info['jpg']['exif']['GPS']['GPSLatitudeRef']) && ($info['jpg']['exif']['GPS']['GPSLatitudeRef'] == 'S')) ? -1 : 1); + $computed_latitude = array(); + foreach ($info['jpg']['exif']['GPS']['GPSLatitude'] as $key => $value) { $computed_latitude[$key] = getid3_lib::DecimalizeFraction($value); } - $ThisFileInfo['jpg']['exif']['GPS']['computed']['latitude'] = $direction_multiplier * ($computed_latitude[0] + ($computed_latitude[1] / 60) + ($computed_latitude[2] / 3600)); + $info['jpg']['exif']['GPS']['computed']['latitude'] = $direction_multiplier * ($computed_latitude[0] + ($computed_latitude[1] / 60) + ($computed_latitude[2] / 3600)); } - if (isset($ThisFileInfo['jpg']['exif']['GPS']['GPSLongitude']) && is_array($ThisFileInfo['jpg']['exif']['GPS']['GPSLongitude'])) { - $direction_multiplier = ((isset($ThisFileInfo['jpg']['exif']['GPS']['GPSLongitudeRef']) && ($ThisFileInfo['jpg']['exif']['GPS']['GPSLongitudeRef'] == 'W')) ? -1 : 1); - foreach ($ThisFileInfo['jpg']['exif']['GPS']['GPSLongitude'] as $key => $value) { + if (isset($info['jpg']['exif']['GPS']['GPSLongitude']) && is_array($info['jpg']['exif']['GPS']['GPSLongitude'])) { + $direction_multiplier = ((isset($info['jpg']['exif']['GPS']['GPSLongitudeRef']) && ($info['jpg']['exif']['GPS']['GPSLongitudeRef'] == 'W')) ? -1 : 1); + $computed_longitude = array(); + foreach ($info['jpg']['exif']['GPS']['GPSLongitude'] as $key => $value) { $computed_longitude[$key] = getid3_lib::DecimalizeFraction($value); } - $ThisFileInfo['jpg']['exif']['GPS']['computed']['longitude'] = $direction_multiplier * ($computed_longitude[0] + ($computed_longitude[1] / 60) + ($computed_longitude[2] / 3600)); + $info['jpg']['exif']['GPS']['computed']['longitude'] = $direction_multiplier * ($computed_longitude[0] + ($computed_longitude[1] / 60) + ($computed_longitude[2] / 3600)); } - - if (isset($ThisFileInfo['jpg']['exif']['GPS']['GPSAltitude'])) { - $direction_multiplier = ((isset($ThisFileInfo['jpg']['exif']['GPS']['GPSAltitudeRef']) && ($ThisFileInfo['jpg']['exif']['GPS']['GPSAltitudeRef'] === chr(1))) ? -1 : 1); - $ThisFileInfo['jpg']['exif']['GPS']['computed']['altitude'] = $direction_multiplier * getid3_lib::DecimalizeFraction($ThisFileInfo['jpg']['exif']['GPS']['GPSAltitude']); + if (isset($info['jpg']['exif']['GPS']['GPSAltitudeRef'])) { + $info['jpg']['exif']['GPS']['GPSAltitudeRef'] = ord($info['jpg']['exif']['GPS']['GPSAltitudeRef']); // 0 = above sea level; 1 = below sea level + } + if (isset($info['jpg']['exif']['GPS']['GPSAltitude'])) { + $direction_multiplier = (!empty($info['jpg']['exif']['GPS']['GPSAltitudeRef']) ? -1 : 1); // 0 = above sea level; 1 = below sea level + $info['jpg']['exif']['GPS']['computed']['altitude'] = $direction_multiplier * getid3_lib::DecimalizeFraction($info['jpg']['exif']['GPS']['GPSAltitude']); } } - if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.xmp.php', __FILE__, false)) { - if (isset($ThisFileInfo['filenamepath'])) { - $image_xmp = new Image_XMP($ThisFileInfo['filenamepath']); - $xmp_raw = $image_xmp->getAllTags(); - foreach ($xmp_raw as $key => $value) { + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.xmp.php', __FILE__, true); + if (isset($info['filenamepath'])) { + $image_xmp = new Image_XMP($info['filenamepath']); + $xmp_raw = $image_xmp->getAllTags(); + foreach ($xmp_raw as $key => $value) { + if (strpos($key, ':')) { list($subsection, $tagname) = explode(':', $key); - $ThisFileInfo['xmp'][$subsection][$tagname] = $this->CastAsAppropriate($value); + $info['xmp'][$subsection][$tagname] = $this->CastAsAppropriate($value); + } else { + $this->warning('XMP: expecting ":", found "'.$key.'"'); } } } if (!$returnOK) { - unset($ThisFileInfo['fileformat']); + unset($info['fileformat']); return false; } return true; } - - function CastAsAppropriate($value) { + /** + * @param mixed $value + * + * @return mixed + */ + public function CastAsAppropriate($value) { if (is_array($value)) { return $value; } elseif (preg_match('#^[0-9]+/[0-9]+$#', $value)) { @@ -181,8 +197,12 @@ class getid3_jpg return $value; } - - function IPTCrecordName($iptc_record) { + /** + * @param int $iptc_record + * + * @return string + */ + public function IPTCrecordName($iptc_record) { // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html static $IPTCrecordName = array(); if (empty($IPTCrecordName)) { @@ -198,8 +218,13 @@ class getid3_jpg return (isset($IPTCrecordName[$iptc_record]) ? $IPTCrecordName[$iptc_record] : ''); } - - function IPTCrecordTagName($iptc_record, $iptc_tagkey) { + /** + * @param int $iptc_record + * @param int $iptc_tagkey + * + * @return string + */ + public function IPTCrecordTagName($iptc_record, $iptc_tagkey) { // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html static $IPTCrecordTagName = array(); if (empty($IPTCrecordTagName)) { @@ -338,6 +363,3 @@ class getid3_jpg } } - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.graphic.pcd.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.pcd.php similarity index 54% rename from serendipity_event_podcast/player/getid3/module.graphic.pcd.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.pcd.php index 60efabdf..6f2aaac6 100644 --- a/serendipity_event_podcast/player/getid3/module.graphic.pcd.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.pcd.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.graphic.pcd.php // @@ -13,36 +14,47 @@ // /// ///////////////////////////////////////////////////////////////// - -class getid3_pcd +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} +class getid3_pcd extends getid3_handler { - function getid3_pcd(&$fd, &$ThisFileInfo, $ExtractData=0) { - $ThisFileInfo['fileformat'] = 'pcd'; - $ThisFileInfo['video']['dataformat'] = 'pcd'; - $ThisFileInfo['video']['lossless'] = false; + public $ExtractData = 0; + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'pcd'; + $info['video']['dataformat'] = 'pcd'; + $info['video']['lossless'] = false; - fseek($fd, $ThisFileInfo['avdataoffset'] + 72, SEEK_SET); + $this->fseek($info['avdataoffset'] + 72); - $PCDflags = fread($fd, 1); + $PCDflags = $this->fread(1); $PCDisVertical = ((ord($PCDflags) & 0x01) ? true : false); if ($PCDisVertical) { - $ThisFileInfo['video']['resolution_x'] = 3072; - $ThisFileInfo['video']['resolution_y'] = 2048; + $info['video']['resolution_x'] = 3072; + $info['video']['resolution_y'] = 2048; } else { - $ThisFileInfo['video']['resolution_x'] = 2048; - $ThisFileInfo['video']['resolution_y'] = 3072; + $info['video']['resolution_x'] = 2048; + $info['video']['resolution_y'] = 3072; } - if ($ExtractData > 3) { + if ($this->ExtractData > 3) { - $ThisFileInfo['error'][] = 'Cannot extract PSD image data for detail levels above BASE (3)'; + $this->error('Cannot extract PSD image data for detail levels above BASE (level-3) because encrypted with Kodak-proprietary compression/encryption.'); + return false; - } elseif ($ExtractData > 0) { + } elseif ($this->ExtractData > 0) { + $PCD_levels = array(); $PCD_levels[1] = array( 192, 128, 0x02000); // BASE/16 $PCD_levels[2] = array( 384, 256, 0x0B800); // BASE/4 $PCD_levels[3] = array( 768, 512, 0x30000); // BASE @@ -52,27 +64,27 @@ class getid3_pcd list($PCD_width, $PCD_height, $PCD_dataOffset) = $PCD_levels[3]; - fseek($fd, $ThisFileInfo['avdataoffset'] + $PCD_dataOffset, SEEK_SET); + $this->fseek($info['avdataoffset'] + $PCD_dataOffset); for ($y = 0; $y < $PCD_height; $y += 2) { // The image-data of these subtypes start at the respective offsets of 02000h, 0b800h and 30000h. // To decode the YcbYr to the more usual RGB-code, three lines of data have to be read, each - // consisting of ‘w’ bytes, where ‘w’ is the width of the image-subtype. The first ‘w’ bytes and - // the first half of the third ‘w’ bytes contain data for the first RGB-line, the second ‘w’ bytes - // and the second half of the third ‘w’ bytes contain data for a second RGB-line. + // consisting of ‘wÂ’ bytes, where ‘wÂ’ is the width of the image-subtype. The first ‘wÂ’ bytes and + // the first half of the third ‘wÂ’ bytes contain data for the first RGB-line, the second ‘wÂ’ bytes + // and the second half of the third ‘wÂ’ bytes contain data for a second RGB-line. - $PCD_data_Y1 = fread($fd, $PCD_width); - $PCD_data_Y2 = fread($fd, $PCD_width); - $PCD_data_Cb = fread($fd, intval(round($PCD_width / 2))); - $PCD_data_Cr = fread($fd, intval(round($PCD_width / 2))); + $PCD_data_Y1 = $this->fread($PCD_width); + $PCD_data_Y2 = $this->fread($PCD_width); + $PCD_data_Cb = $this->fread(intval(round($PCD_width / 2))); + $PCD_data_Cr = $this->fread(intval(round($PCD_width / 2))); for ($x = 0; $x < $PCD_width; $x++) { if ($PCDisVertical) { - $ThisFileInfo['pcd']['data'][$PCD_width - $x][$y] = $this->YCbCr2RGB(ord($PCD_data_Y1{$x}), ord($PCD_data_Cb{floor($x / 2)}), ord($PCD_data_Cr{floor($x / 2)})); - $ThisFileInfo['pcd']['data'][$PCD_width - $x][$y + 1] = $this->YCbCr2RGB(ord($PCD_data_Y2{$x}), ord($PCD_data_Cb{floor($x / 2)}), ord($PCD_data_Cr{floor($x / 2)})); + $info['pcd']['data'][$PCD_width - $x][$y] = $this->YCbCr2RGB(ord($PCD_data_Y1[$x]), ord($PCD_data_Cb[(int) floor($x / 2)]), ord($PCD_data_Cr[(int) floor($x / 2)])); + $info['pcd']['data'][$PCD_width - $x][$y + 1] = $this->YCbCr2RGB(ord($PCD_data_Y2[$x]), ord($PCD_data_Cb[(int) floor($x / 2)]), ord($PCD_data_Cr[(int) floor($x / 2)])); } else { - $ThisFileInfo['pcd']['data'][$y][$x] = $this->YCbCr2RGB(ord($PCD_data_Y1{$x}), ord($PCD_data_Cb{floor($x / 2)}), ord($PCD_data_Cr{floor($x / 2)})); - $ThisFileInfo['pcd']['data'][$y + 1][$x] = $this->YCbCr2RGB(ord($PCD_data_Y2{$x}), ord($PCD_data_Cb{floor($x / 2)}), ord($PCD_data_Cr{floor($x / 2)})); + $info['pcd']['data'][$y][$x] = $this->YCbCr2RGB(ord($PCD_data_Y1[$x]), ord($PCD_data_Cb[(int) floor($x / 2)]), ord($PCD_data_Cr[(int) floor($x / 2)])); + $info['pcd']['data'][$y + 1][$x] = $this->YCbCr2RGB(ord($PCD_data_Y2[$x]), ord($PCD_data_Cb[(int) floor($x / 2)]), ord($PCD_data_Cr[(int) floor($x / 2)])); } } } @@ -86,15 +98,23 @@ class getid3_pcd // $BMPinfo['resolution_x'] = $PCD_width; // $BMPinfo['resolution_y'] = $PCD_height; //} - //$BMPinfo['bmp']['data'] = $ThisFileInfo['pcd']['data']; + //$BMPinfo['bmp']['data'] = $info['pcd']['data']; //getid3_bmp::PlotBMP($BMPinfo); //exit; } + return false; } - function YCbCr2RGB($Y, $Cb, $Cr) { + /** + * @param int $Y + * @param int $Cb + * @param int $Cr + * + * @return int + */ + public function YCbCr2RGB($Y, $Cb, $Cr) { static $YCbCr_constants = array(); if (empty($YCbCr_constants)) { $YCbCr_constants['red']['Y'] = 0.0054980 * 256; @@ -126,5 +146,3 @@ class getid3_pcd } } - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.graphic.png.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.png.php similarity index 76% rename from serendipity_event_podcast/player/getid3/module.graphic.png.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.png.php index c9873cc4..e29eeb79 100644 --- a/serendipity_event_podcast/player/getid3/module.graphic.png.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.png.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.graphic.png.php // @@ -13,43 +14,75 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_png +class getid3_png extends getid3_handler { + /** + * If data chunk is larger than this do not read it completely (getID3 only needs the first + * few dozen bytes for parsing). + * + * @var int + */ + public $max_data_bytes = 10000000; - function getid3_png(&$fd, &$ThisFileInfo) { + /** + * @return bool + */ + public function Analyze() { + + $info = &$this->getid3->info; // shortcut - $ThisFileInfo['png'] = array(); - $thisfile_png = &$ThisFileInfo['png']; + $info['png'] = array(); + $thisfile_png = &$info['png']; - $ThisFileInfo['fileformat'] = 'png'; - $ThisFileInfo['video']['dataformat'] = 'png'; - $ThisFileInfo['video']['lossless'] = false; + $info['fileformat'] = 'png'; + $info['video']['dataformat'] = 'png'; + $info['video']['lossless'] = false; - fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); - $PNGfiledata = fread($fd, GETID3_FREAD_BUFFER_SIZE); + $this->fseek($info['avdataoffset']); + $PNGfiledata = $this->fread($this->getid3->fread_buffer_size()); $offset = 0; $PNGidentifier = substr($PNGfiledata, $offset, 8); // $89 $50 $4E $47 $0D $0A $1A $0A $offset += 8; if ($PNGidentifier != "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") { - $ThisFileInfo['error'][] = 'First 8 bytes of file ('.getid3_lib::PrintHexBytes($PNGidentifier).') did not match expected PNG identifier'; - unset($ThisFileInfo['fileformat']); + $this->error('First 8 bytes of file ('.getid3_lib::PrintHexBytes($PNGidentifier).') did not match expected PNG identifier'); + unset($info['fileformat']); return false; } - while (((ftell($fd) - (strlen($PNGfiledata) - $offset)) < $ThisFileInfo['filesize'])) { + while ((($this->ftell() - (strlen($PNGfiledata) - $offset)) < $info['filesize'])) { + $chunk = array(); $chunk['data_length'] = getid3_lib::BigEndian2Int(substr($PNGfiledata, $offset, 4)); - $offset += 4; - while (((strlen($PNGfiledata) - $offset) < ($chunk['data_length'] + 4)) && (ftell($fd) < $ThisFileInfo['filesize'])) { - $PNGfiledata .= fread($fd, GETID3_FREAD_BUFFER_SIZE); + if ($chunk['data_length'] === false) { + $this->error('Failed to read data_length at offset '.$offset); + return false; } - $chunk['type_text'] = substr($PNGfiledata, $offset, 4); + $offset += 4; + $truncated_data = false; + while (((strlen($PNGfiledata) - $offset) < ($chunk['data_length'] + 4)) && ($this->ftell() < $info['filesize'])) { + if (strlen($PNGfiledata) < $this->max_data_bytes) { + $str = $this->fread($this->getid3->fread_buffer_size()); + if (strlen($str) > 0) { + $PNGfiledata .= $str; + } else { + $this->warning('At offset '.$offset.' chunk "'.substr($PNGfiledata, $offset, 4).'" no more data to read, data chunk will be truncated at '.(strlen($PNGfiledata) - 8).' bytes'); + break; + } + } else { + $this->warning('At offset '.$offset.' chunk "'.substr($PNGfiledata, $offset, 4).'" exceeded max_data_bytes value of '.$this->max_data_bytes.', data chunk will be truncated at '.(strlen($PNGfiledata) - 8).' bytes'); + break; + } + } + $chunk['type_text'] = substr($PNGfiledata, $offset, 4); $offset += 4; $chunk['type_raw'] = getid3_lib::BigEndian2Int($chunk['type_text']); - $chunk['data'] = substr($PNGfiledata, $offset, $chunk['data_length']); + $chunk['data'] = substr($PNGfiledata, $offset, $chunk['data_length']); $offset += $chunk['data_length']; $chunk['crc'] = getid3_lib::BigEndian2Int(substr($PNGfiledata, $offset, 4)); $offset += 4; @@ -80,10 +113,10 @@ class getid3_png $thisfile_png_chunk_type_text['color_type']['true_color'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x02); $thisfile_png_chunk_type_text['color_type']['alpha'] = (bool) ($thisfile_png_chunk_type_text['raw']['color_type'] & 0x04); - $ThisFileInfo['video']['resolution_x'] = $thisfile_png_chunk_type_text['width']; - $ThisFileInfo['video']['resolution_y'] = $thisfile_png_chunk_type_text['height']; + $info['video']['resolution_x'] = $thisfile_png_chunk_type_text['width']; + $info['video']['resolution_y'] = $thisfile_png_chunk_type_text['height']; - $ThisFileInfo['video']['bits_per_sample'] = $this->IHDRcalculateBitsPerSample($thisfile_png_chunk_type_text['raw']['color_type'], $thisfile_png_chunk_type_text['raw']['bit_depth']); + $info['video']['bits_per_sample'] = $this->IHDRcalculateBitsPerSample($thisfile_png_chunk_type_text['raw']['color_type'], $thisfile_png_chunk_type_text['raw']['bit_depth']); break; @@ -123,10 +156,11 @@ class getid3_png case 4: case 6: - $ThisFileInfo['error'][] = 'Invalid color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']; + $this->error('Invalid color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']); + break; default: - $ThisFileInfo['warning'][] = 'Unhandled color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']; + $this->warning('Unhandled color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']); break; } break; @@ -160,7 +194,7 @@ class getid3_png case 'iCCP': // Embedded ICC Profile $thisfile_png_chunk_type_text['header'] = $chunk; - list($profilename, $compressiondata) = explode("\x00", $chunk['data'], 2); + list($profilename, $compressiondata) = explode("\x00", $chunk['data'], 2); $thisfile_png_chunk_type_text['profile_name'] = $profilename; $thisfile_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int(substr($compressiondata, 0, 1)); $thisfile_png_chunk_type_text['compression_profile'] = substr($compressiondata, 1); @@ -171,7 +205,7 @@ class getid3_png case 'tEXt': // Textual Data $thisfile_png_chunk_type_text['header'] = $chunk; - list($keyword, $text) = explode("\x00", $chunk['data'], 2); + list($keyword, $text) = explode("\x00", $chunk['data'], 2); $thisfile_png_chunk_type_text['keyword'] = $keyword; $thisfile_png_chunk_type_text['text'] = $text; @@ -181,7 +215,7 @@ class getid3_png case 'zTXt': // Compressed Textual Data $thisfile_png_chunk_type_text['header'] = $chunk; - list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2); + list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2); $thisfile_png_chunk_type_text['keyword'] = $keyword; $thisfile_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int(substr($otherdata, 0, 1)); $thisfile_png_chunk_type_text['compressed_text'] = substr($otherdata, 1); @@ -204,7 +238,7 @@ class getid3_png case 'iTXt': // International Textual Data $thisfile_png_chunk_type_text['header'] = $chunk; - list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2); + list($keyword, $otherdata) = explode("\x00", $chunk['data'], 2); $thisfile_png_chunk_type_text['keyword'] = $keyword; $thisfile_png_chunk_type_text['compression'] = (bool) getid3_lib::BigEndian2Int(substr($otherdata, 0, 1)); $thisfile_png_chunk_type_text['compression_method'] = getid3_lib::BigEndian2Int(substr($otherdata, 1, 1)); @@ -305,7 +339,7 @@ class getid3_png case 'sPLT': // Suggested Palette $thisfile_png_chunk_type_text['header'] = $chunk; - list($palettename, $otherdata) = explode("\x00", $chunk['data'], 2); + list($palettename, $otherdata) = explode("\x00", $chunk['data'], 2); $thisfile_png_chunk_type_text['palette_name'] = $palettename; $sPLToffset = 0; $thisfile_png_chunk_type_text['sample_depth_bits'] = getid3_lib::BigEndian2Int(substr($otherdata, $sPLToffset, 1)); @@ -420,24 +454,70 @@ class getid3_png $thisfile_png_chunk_type_text[$idatinformationfieldindex]['header'] = $chunk; break; - case 'IEND': // Image Trailer $thisfile_png_chunk_type_text['header'] = $chunk; break; + case 'acTL': // Animation Control chunk + // https://wiki.mozilla.org/APNG_Specification#.60acTL.60:_The_Animation_Control_Chunk + $thisfile_png['animation']['num_frames'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4)); // Number of frames + $thisfile_png['animation']['num_plays'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4)); // Number of times to loop this APNG. 0 indicates infinite looping. + + unset($chunk['data']); + $thisfile_png_chunk_type_text['header'] = $chunk; + break; + + case 'fcTL': // Frame Control chunk + // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk + $fcTL = array(); + $fcTL['sequence_number'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 0, 4)); // Sequence number of the animation chunk, starting from 0 + $fcTL['width'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 4, 4)); // Width of the following frame + $fcTL['height'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 8, 4)); // Height of the following frame + $fcTL['x_offset'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 12, 4)); // X position at which to render the following frame + $fcTL['y_offset'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 16, 4)); // Y position at which to render the following frame + $fcTL['delay_num'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 20, 2)); // Frame delay fraction numerator + $fcTL['delay_den'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 22, 2)); // Frame delay fraction numerator + $fcTL['dispose_op'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 23, 1)); // Type of frame area disposal to be done after rendering this frame + $fcTL['blend_op'] = getid3_lib::BigEndian2Int(substr($chunk['data'], 23, 1)); // Type of frame area rendering for this frame + if ($fcTL['delay_den']) { + $fcTL['delay'] = $fcTL['delay_num'] / $fcTL['delay_den']; + } + $thisfile_png['animation']['fcTL'][$fcTL['sequence_number']] = $fcTL; + + unset($chunk['data']); + $thisfile_png_chunk_type_text['header'] = $chunk; + break; + + case 'fdAT': // Frame Data chunk + // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk + // "The `fdAT` chunk has the same purpose as an `IDAT` chunk. It has the same structure as an `IDAT` chunk, except preceded by a sequence number." + unset($chunk['data']); + $thisfile_png_chunk_type_text['header'] = $chunk; + break; default: //unset($chunk['data']); $thisfile_png_chunk_type_text['header'] = $chunk; - $ThisFileInfo['warning'][] = 'Unhandled chunk type: '.$chunk['type_text']; + $this->warning('Unhandled chunk type: '.$chunk['type_text']); break; } } - + if (!empty($thisfile_png['animation']['num_frames']) && !empty($thisfile_png['animation']['fcTL'])) { + $info['video']['dataformat'] = 'apng'; + $info['playtime_seconds'] = 0; + foreach ($thisfile_png['animation']['fcTL'] as $seqno => $fcTL) { + $info['playtime_seconds'] += $fcTL['delay']; + } + } return true; } - function PNGsRGBintentLookup($sRGB) { + /** + * @param int $sRGB + * + * @return string + */ + public function PNGsRGBintentLookup($sRGB) { static $PNGsRGBintentLookup = array( 0 => 'Perceptual', 1 => 'Relative colorimetric', @@ -447,14 +527,24 @@ class getid3_png return (isset($PNGsRGBintentLookup[$sRGB]) ? $PNGsRGBintentLookup[$sRGB] : 'invalid'); } - function PNGcompressionMethodLookup($compressionmethod) { + /** + * @param int $compressionmethod + * + * @return string + */ + public function PNGcompressionMethodLookup($compressionmethod) { static $PNGcompressionMethodLookup = array( 0 => 'deflate/inflate' ); return (isset($PNGcompressionMethodLookup[$compressionmethod]) ? $PNGcompressionMethodLookup[$compressionmethod] : 'invalid'); } - function PNGpHYsUnitLookup($unitid) { + /** + * @param int $unitid + * + * @return string + */ + public function PNGpHYsUnitLookup($unitid) { static $PNGpHYsUnitLookup = array( 0 => 'unknown', 1 => 'meter' @@ -462,7 +552,12 @@ class getid3_png return (isset($PNGpHYsUnitLookup[$unitid]) ? $PNGpHYsUnitLookup[$unitid] : 'invalid'); } - function PNGoFFsUnitLookup($unitid) { + /** + * @param int $unitid + * + * @return string + */ + public function PNGoFFsUnitLookup($unitid) { static $PNGoFFsUnitLookup = array( 0 => 'pixel', 1 => 'micrometer' @@ -470,7 +565,12 @@ class getid3_png return (isset($PNGoFFsUnitLookup[$unitid]) ? $PNGoFFsUnitLookup[$unitid] : 'invalid'); } - function PNGpCALequationTypeLookup($equationtype) { + /** + * @param int $equationtype + * + * @return string + */ + public function PNGpCALequationTypeLookup($equationtype) { static $PNGpCALequationTypeLookup = array( 0 => 'Linear mapping', 1 => 'Base-e exponential mapping', @@ -480,7 +580,12 @@ class getid3_png return (isset($PNGpCALequationTypeLookup[$equationtype]) ? $PNGpCALequationTypeLookup[$equationtype] : 'invalid'); } - function PNGsCALUnitLookup($unitid) { + /** + * @param int $unitid + * + * @return string + */ + public function PNGsCALUnitLookup($unitid) { static $PNGsCALUnitLookup = array( 0 => 'meter', 1 => 'radian' @@ -488,32 +593,30 @@ class getid3_png return (isset($PNGsCALUnitLookup[$unitid]) ? $PNGsCALUnitLookup[$unitid] : 'invalid'); } - function IHDRcalculateBitsPerSample($color_type, $bit_depth) { + /** + * @param int $color_type + * @param int $bit_depth + * + * @return int|false + */ + public function IHDRcalculateBitsPerSample($color_type, $bit_depth) { switch ($color_type) { case 0: // Each pixel is a grayscale sample. return $bit_depth; - break; case 2: // Each pixel is an R,G,B triple return 3 * $bit_depth; - break; case 3: // Each pixel is a palette index; a PLTE chunk must appear. return $bit_depth; - break; case 4: // Each pixel is a grayscale sample, followed by an alpha sample. return 2 * $bit_depth; - break; case 6: // Each pixel is an R,G,B triple, followed by an alpha sample. return 4 * $bit_depth; - break; } return false; } } - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.svg.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.svg.php new file mode 100644 index 00000000..8bb577b9 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.svg.php @@ -0,0 +1,106 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.graphic.svg.php // +// module for analyzing SVG Image files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_svg extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + + $SVGheader = $this->fread(4096); + if (preg_match('#\<\?xml([^\>]+)\?\>#i', $SVGheader, $matches)) { + $info['svg']['xml']['raw'] = $matches; + } + if (preg_match('#\<\!DOCTYPE([^\>]+)\>#i', $SVGheader, $matches)) { + $info['svg']['doctype']['raw'] = $matches; + } + if (preg_match('#\]+)\>#i', $SVGheader, $matches)) { + $info['svg']['svg']['raw'] = $matches; + } + if (isset($info['svg']['svg']['raw'])) { + + $sections_to_fix = array('xml', 'doctype', 'svg'); + foreach ($sections_to_fix as $section_to_fix) { + if (!isset($info['svg'][$section_to_fix])) { + continue; + } + $section_data = array(); + while (preg_match('/ "([^"]+)"/', $info['svg'][$section_to_fix]['raw'][1], $matches)) { + $section_data[] = $matches[1]; + $info['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $info['svg'][$section_to_fix]['raw'][1]); + } + while (preg_match('/([^\s]+)="([^"]+)"/', $info['svg'][$section_to_fix]['raw'][1], $matches)) { + $section_data[] = $matches[0]; + $info['svg'][$section_to_fix]['raw'][1] = str_replace($matches[0], '', $info['svg'][$section_to_fix]['raw'][1]); + } + $section_data = array_merge($section_data, preg_split('/[\s,]+/', $info['svg'][$section_to_fix]['raw'][1])); + foreach ($section_data as $keyvaluepair) { + $keyvaluepair = trim($keyvaluepair); + if ($keyvaluepair) { + $keyvalueexploded = explode('=', $keyvaluepair); + $key = (isset($keyvalueexploded[0]) ? $keyvalueexploded[0] : ''); + $value = (isset($keyvalueexploded[1]) ? $keyvalueexploded[1] : ''); + $info['svg'][$section_to_fix]['sections'][$key] = trim($value, '"'); + } + } + } + + $info['fileformat'] = 'svg'; + $info['video']['dataformat'] = 'svg'; + $info['video']['lossless'] = true; + //$info['video']['bits_per_sample'] = 24; + $info['video']['pixel_aspect_ratio'] = (float) 1; + + if (!empty($info['svg']['svg']['sections']['width'])) { + $info['svg']['width'] = intval($info['svg']['svg']['sections']['width']); + } + if (!empty($info['svg']['svg']['sections']['height'])) { + $info['svg']['height'] = intval($info['svg']['svg']['sections']['height']); + } + if (!empty($info['svg']['svg']['sections']['version'])) { + $info['svg']['version'] = $info['svg']['svg']['sections']['version']; + } + if (!isset($info['svg']['version']) && isset($info['svg']['doctype']['sections'])) { + foreach ($info['svg']['doctype']['sections'] as $key => $value) { + if (preg_match('#//W3C//DTD SVG ([0-9\.]+)//#i', $key, $matches)) { + $info['svg']['version'] = $matches[1]; + break; + } + } + } + + if (!empty($info['svg']['width'])) { + $info['video']['resolution_x'] = $info['svg']['width']; + } + if (!empty($info['svg']['height'])) { + $info['video']['resolution_y'] = $info['svg']['height']; + } + + return true; + } + $this->error('Did not find expected tag'); + return false; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.tiff.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.tiff.php new file mode 100644 index 00000000..e4f3cf7b --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.graphic.tiff.php @@ -0,0 +1,520 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.archive.tiff.php // +// module for analyzing TIFF files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_tiff extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + $TIFFheader = $this->fread(4); + + switch (substr($TIFFheader, 0, 2)) { + case 'II': + $info['tiff']['byte_order'] = 'Intel'; + break; + case 'MM': + $info['tiff']['byte_order'] = 'Motorola'; + break; + default: + $this->error('Invalid TIFF byte order identifier ('.substr($TIFFheader, 0, 2).') at offset '.$info['avdataoffset']); + return false; + } + + $info['fileformat'] = 'tiff'; + $info['video']['dataformat'] = 'tiff'; + $info['video']['lossless'] = true; + $info['tiff']['ifd'] = array(); + $CurrentIFD = array(); + + $FieldTypeByteLength = array(1=>1, 2=>1, 3=>2, 4=>4, 5=>8); + + $nextIFDoffset = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']); + + while ($nextIFDoffset > 0) { + + $CurrentIFD['offset'] = $nextIFDoffset; + + $this->fseek($info['avdataoffset'] + $nextIFDoffset); + $CurrentIFD['fieldcount'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']); + + for ($i = 0; $i < $CurrentIFD['fieldcount']; $i++) { + $CurrentIFD['fields'][$i]['raw']['tag'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']); + $CurrentIFD['fields'][$i]['raw']['type'] = $this->TIFFendian2Int($this->fread(2), $info['tiff']['byte_order']); + $CurrentIFD['fields'][$i]['raw']['length'] = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']); + $CurrentIFD['fields'][$i]['raw']['valoff'] = $this->fread(4); // To save time and space the Value Offset contains the Value instead of pointing to the Value if and only if the Value fits into 4 bytes. If the Value is shorter than 4 bytes, it is left-justified within the 4-byte Value Offset, i.e., stored in the lowernumbered bytes. Whether the Value fits within 4 bytes is determined by the Type and Count of the field. + $CurrentIFD['fields'][$i]['raw']['tag_name'] = $this->TIFFcommentName($CurrentIFD['fields'][$i]['raw']['tag']); + + switch ($CurrentIFD['fields'][$i]['raw']['type']) { + case 1: // BYTE An 8-bit unsigned integer. + if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) { + $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['valoff'], 0, 1), $info['tiff']['byte_order']); + } else { + $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['valoff'], $info['tiff']['byte_order']); + } + break; + + case 2: // ASCII 8-bit bytes that store ASCII codes; the last byte must be null. + if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) { + $CurrentIFD['fields'][$i]['value'] = substr($CurrentIFD['fields'][$i]['raw']['valoff'], 3); + } else { + $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['valoff'], $info['tiff']['byte_order']); + } + break; + + case 3: // SHORT A 16-bit (2-byte) unsigned integer. + if ($CurrentIFD['fields'][$i]['raw']['length'] <= 2) { + $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int(substr($CurrentIFD['fields'][$i]['raw']['valoff'], 0, 2), $info['tiff']['byte_order']); + } else { + $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['valoff'], $info['tiff']['byte_order']); + } + break; + + case 4: // LONG A 32-bit (4-byte) unsigned integer. + if ($CurrentIFD['fields'][$i]['raw']['length'] <= 4) { + $CurrentIFD['fields'][$i]['value'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['valoff'], $info['tiff']['byte_order']); + } else { + $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['valoff'], $info['tiff']['byte_order']); + } + break; + + case 5: // RATIONAL Two LONG_s: the first represents the numerator of a fraction, the second the denominator. + case 7: // UNDEFINED An 8-bit byte that may contain anything, depending on the definition of the field. + $CurrentIFD['fields'][$i]['offset'] = $this->TIFFendian2Int($CurrentIFD['fields'][$i]['raw']['valoff'], $info['tiff']['byte_order']); + break; + + // Warning: It is possible that other TIFF field types will be added in the future. Readers should skip over fields containing an unexpected field type. + // In TIFF 6.0, some new field types have been defined: + // These new field types are also governed by the byte order (II or MM) in the TIFF header. + case 6: // SBYTE An 8-bit signed (twos-complement) integer. + case 8: // SSHORT A 16-bit (2-byte) signed (twos-complement) integer. + case 9: // SLONG A 32-bit (4-byte) signed (twos-complement) integer. + case 10: // SRATIONAL Two SLONGs: the first represents the numerator of a fraction, the second the denominator. + case 11: // FLOAT Single precision (4-byte) IEEE format + case 12: // DOUBLE Double precision (8-byte) IEEE format + default: + $this->warning('unhandled IFD field type '.$CurrentIFD['fields'][$i]['raw']['type'].' for IFD entry '.$i); + break; + } + } + + $info['tiff']['ifd'][] = $CurrentIFD; + $CurrentIFD = array(); + $nextIFDoffset = $this->TIFFendian2Int($this->fread(4), $info['tiff']['byte_order']); + + } + + foreach ($info['tiff']['ifd'] as $IFDid => $IFDarray) { + if(!isset($IFDarray['fields'])) { + continue; + } + + foreach ($IFDarray['fields'] as $key => $fieldarray) { + switch ($fieldarray['raw']['tag']) { + case 256: // ImageWidth + case 257: // ImageLength + case 258: // BitsPerSample + case 259: // Compression + if (!isset($fieldarray['value'])) { + $this->fseek($fieldarray['offset']); + $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $this->fread($fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]); + + } + break; + + case 270: // ImageDescription + case 271: // Make + case 272: // Model + case 305: // Software + case 306: // DateTime + case 315: // Artist + case 316: // HostComputer + if (isset($fieldarray['value'])) { + $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $fieldarray['value']; + } else { + $this->fseek($fieldarray['offset']); + $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'] = $this->fread($fieldarray['raw']['length'] * $FieldTypeByteLength[$fieldarray['raw']['type']]); + + } + break; + case 700: + $XMPmagic = 'fseek($fieldarray['offset']); + $xmpkey = (isset($info['tiff']['XMP']) ? count($info['tiff']['XMP']) : 0); + $info['tiff']['XMP'][$xmpkey]['raw'] = $this->fread($fieldarray['raw']['length']); + if (substr($info['tiff']['XMP'][$xmpkey]['raw'], 0, strlen($XMPmagic)) != $XMPmagic) { + $this->warning('did not find expected XMP data at offset '.$fieldarray['offset']); + unset($info['tiff']['XMP'][$xmpkey]['raw']); + } + break; + } + switch ($fieldarray['raw']['tag']) { + case 256: // ImageWidth + $info['video']['resolution_x'] = $fieldarray['value']; + break; + + case 257: // ImageLength + $info['video']['resolution_y'] = $fieldarray['value']; + break; + + case 258: // BitsPerSample + if (isset($fieldarray['value'])) { + $info['video']['bits_per_sample'] = $fieldarray['value']; + } else { + $info['video']['bits_per_sample'] = 0; + for ($i = 0; $i < $fieldarray['raw']['length']; $i++) { + $info['video']['bits_per_sample'] += $this->TIFFendian2Int(substr($info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data'], $i * $FieldTypeByteLength[$fieldarray['raw']['type']], $FieldTypeByteLength[$fieldarray['raw']['type']]), $info['tiff']['byte_order']); + } + } + break; + + case 259: // Compression + $info['video']['codec'] = $this->TIFFcompressionMethod($fieldarray['value']); + break; + + case 270: // ImageDescription + case 271: // Make + case 272: // Model + case 305: // Software + case 306: // DateTime + case 315: // Artist + case 316: // HostComputer + $TIFFcommentName = strtolower($fieldarray['raw']['tag_name']); + if (isset($info['tiff']['comments'][$TIFFcommentName])) { + $info['tiff']['comments'][$TIFFcommentName][] = $info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data']; + } else { + $info['tiff']['comments'][$TIFFcommentName] = array($info['tiff']['ifd'][$IFDid]['fields'][$key]['raw']['data']); + } + break; + + default: + break; + } + } + } + + return true; + } + + /** + * @param string $bytestring + * @param string $byteorder + * + * @return int|float|false + */ + public function TIFFendian2Int($bytestring, $byteorder) { + if ($byteorder == 'Intel') { + return getid3_lib::LittleEndian2Int($bytestring); + } elseif ($byteorder == 'Motorola') { + return getid3_lib::BigEndian2Int($bytestring); + } + return false; + } + + /** + * @param int $id + * + * @return string + */ + public function TIFFcompressionMethod($id) { + // https://en.wikipedia.org/wiki/TIFF#TIFF_Compression_Tag + static $TIFFcompressionMethod = array(); + if (empty($TIFFcompressionMethod)) { + $TIFFcompressionMethod = array( + 0x0001 => 'Uncompressed', + 0x0002 => 'Huffman', + 0x0003 => 'CCITT T.4', + 0x0004 => 'CCITT T.6', + 0x0005 => 'LZW', + 0x0006 => 'JPEG-old', + 0x0007 => 'JPEG', + 0x0008 => 'deflate', + 0x0009 => 'JBIG ITU-T T.85', + 0x000A => 'JBIG ITU-T T.43', + 0x7FFE => 'NeXT RLE 2-bit', + 0x8005 => 'PackBits', + 0x8029 => 'ThunderScan RLE 4-bit', + 0x807F => 'RasterPadding', + 0x8080 => 'RLE-LW', + 0x8081 => 'RLE-CT', + 0x8082 => 'RLE-BL', + 0x80B2 => 'deflate-PK', + 0x80B3 => 'Kodak-DCS', + 0x8765 => 'JBIG', + 0x8798 => 'JPEG2000', + 0x8799 => 'Nikon NEF', + 0x879B => 'JBIG2', + ); + } + return (isset($TIFFcompressionMethod[$id]) ? $TIFFcompressionMethod[$id] : 'unknown/invalid ('.$id.')'); + } + + /** + * @param int $id + * + * @return string + */ + public function TIFFcommentName($id) { + // https://www.awaresystems.be/imaging/tiff/tifftags.html + static $TIFFcommentName = array(); + if (empty($TIFFcommentName)) { + $TIFFcommentName = array( + 254 => 'NewSubfileType', + 255 => 'SubfileType', + 256 => 'ImageWidth', + 257 => 'ImageLength', + 258 => 'BitsPerSample', + 259 => 'Compression', + 262 => 'PhotometricInterpretation', + 263 => 'Threshholding', + 264 => 'CellWidth', + 265 => 'CellLength', + 266 => 'FillOrder', + 269 => 'DocumentName', + 270 => 'ImageDescription', + 271 => 'Make', + 272 => 'Model', + 273 => 'StripOffsets', + 274 => 'Orientation', + 277 => 'SamplesPerPixel', + 278 => 'RowsPerStrip', + 279 => 'StripByteCounts', + 280 => 'MinSampleValue', + 281 => 'MaxSampleValue', + 282 => 'XResolution', + 283 => 'YResolution', + 284 => 'PlanarConfiguration', + 285 => 'PageName', + 286 => 'XPosition', + 287 => 'YPosition', + 288 => 'FreeOffsets', + 289 => 'FreeByteCounts', + 290 => 'GrayResponseUnit', + 291 => 'GrayResponseCurve', + 292 => 'T4Options', + 293 => 'T6Options', + 296 => 'ResolutionUnit', + 297 => 'PageNumber', + 301 => 'TransferFunction', + 305 => 'Software', + 306 => 'DateTime', + 315 => 'Artist', + 316 => 'HostComputer', + 317 => 'Predictor', + 318 => 'WhitePoint', + 319 => 'PrimaryChromaticities', + 320 => 'ColorMap', + 321 => 'HalftoneHints', + 322 => 'TileWidth', + 323 => 'TileLength', + 324 => 'TileOffsets', + 325 => 'TileByteCounts', + 326 => 'BadFaxLines', + 327 => 'CleanFaxData', + 328 => 'ConsecutiveBadFaxLines', + 330 => 'SubIFDs', + 332 => 'InkSet', + 333 => 'InkNames', + 334 => 'NumberOfInks', + 336 => 'DotRange', + 337 => 'TargetPrinter', + 338 => 'ExtraSamples', + 339 => 'SampleFormat', + 340 => 'SMinSampleValue', + 341 => 'SMaxSampleValue', + 342 => 'TransferRange', + 343 => 'ClipPath', + 344 => 'XClipPathUnits', + 345 => 'YClipPathUnits', + 346 => 'Indexed', + 347 => 'JPEGTables', + 351 => 'OPIProxy', + 400 => 'GlobalParametersIFD', + 401 => 'ProfileType', + 402 => 'FaxProfile', + 403 => 'CodingMethods', + 404 => 'VersionYear', + 405 => 'ModeNumber', + 433 => 'Decode', + 434 => 'DefaultImageColor', + 512 => 'JPEGProc', + 513 => 'JPEGInterchangeFormat', + 514 => 'JPEGInterchangeFormatLngth', + 515 => 'JPEGRestartInterval', + 517 => 'JPEGLosslessPredictors', + 518 => 'JPEGPointTransforms', + 519 => 'JPEGQTables', + 520 => 'JPEGDCTables', + 521 => 'JPEGACTables', + 529 => 'YCbCrCoefficients', + 530 => 'YCbCrSubSampling', + 531 => 'YCbCrPositioning', + 532 => 'ReferenceBlackWhite', + 559 => 'StripRowCounts', + 700 => 'XMP', + + 32781 => 'ImageID', + 33432 => 'Copyright', + 34732 => 'ImageLayer', + + // Private Tags - https://www.awaresystems.be/imaging/tiff/tifftags/private.html + 32932 => 'Wang Annotation', // Annotation data, as used in 'Imaging for Windows'. + 33445 => 'MD FileTag', // Specifies the pixel data format encoding in the Molecular Dynamics GEL file format. + 33446 => 'MD ScalePixel', // Specifies a scale factor in the Molecular Dynamics GEL file format. + 33447 => 'MD ColorTable', // Used to specify the conversion from 16bit to 8bit in the Molecular Dynamics GEL file format. + 33448 => 'MD LabName', // Name of the lab that scanned this file, as used in the Molecular Dynamics GEL file format. + 33449 => 'MD SampleInfo', // Information about the sample, as used in the Molecular Dynamics GEL file format. + 33450 => 'MD PrepDate', // Date the sample was prepared, as used in the Molecular Dynamics GEL file format. + 33451 => 'MD PrepTime', // Time the sample was prepared, as used in the Molecular Dynamics GEL file format. + 33452 => 'MD FileUnits', // Units for data in this file, as used in the Molecular Dynamics GEL file format. + 33550 => 'ModelPixelScaleTag', // Used in interchangeable GeoTIFF files. + 33723 => 'IPTC', // IPTC (International Press Telecommunications Council) metadata. + 33918 => 'INGR Packet Data Tag', // Intergraph Application specific storage. + 33919 => 'INGR Flag Registers', // Intergraph Application specific flags. + 33920 => 'IrasB Transformation Matrix', // Originally part of Intergraph's GeoTIFF tags, but likely understood by IrasB only. + 33922 => 'ModelTiepointTag', // Originally part of Intergraph's GeoTIFF tags, but now used in interchangeable GeoTIFF files. + 34264 => 'ModelTransformationTag', // Used in interchangeable GeoTIFF files. + 34377 => 'Photoshop', // Collection of Photoshop 'Image Resource Blocks'. + 34665 => 'Exif IFD', // A pointer to the Exif IFD. + 34675 => 'ICC Profile', // ICC profile data. + 34735 => 'GeoKeyDirectoryTag', // Used in interchangeable GeoTIFF files. + 34736 => 'GeoDoubleParamsTag', // Used in interchangeable GeoTIFF files. + 34737 => 'GeoAsciiParamsTag', // Used in interchangeable GeoTIFF files. + 34853 => 'GPS IFD', // A pointer to the Exif-related GPS Info IFD. + 34908 => 'HylaFAX FaxRecvParams', // Used by HylaFAX. + 34909 => 'HylaFAX FaxSubAddress', // Used by HylaFAX. + 34910 => 'HylaFAX FaxRecvTime', // Used by HylaFAX. + 37724 => 'ImageSourceData', // Used by Adobe Photoshop. + 40965 => 'Interoperability IFD', // A pointer to the Exif-related Interoperability IFD. + 42112 => 'GDAL_METADATA', // Used by the GDAL library, holds an XML list of name=value 'metadata' values about the image as a whole, and about specific samples. + 42113 => 'GDAL_NODATA', // Used by the GDAL library, contains an ASCII encoded nodata or background pixel value. + 50215 => 'Oce Scanjob Description', // Used in the Oce scanning process. + 50216 => 'Oce Application Selector', // Used in the Oce scanning process. + 50217 => 'Oce Identification Number', // Used in the Oce scanning process. + 50218 => 'Oce ImageLogic Characteristics', // Used in the Oce scanning process. + 50706 => 'DNGVersion', // Used in IFD 0 of DNG files. + 50707 => 'DNGBackwardVersion', // Used in IFD 0 of DNG files. + 50708 => 'UniqueCameraModel', // Used in IFD 0 of DNG files. + 50709 => 'LocalizedCameraModel', // Used in IFD 0 of DNG files. + 50710 => 'CFAPlaneColor', // Used in Raw IFD of DNG files. + 50711 => 'CFALayout', // Used in Raw IFD of DNG files. + 50712 => 'LinearizationTable', // Used in Raw IFD of DNG files. + 50713 => 'BlackLevelRepeatDim', // Used in Raw IFD of DNG files. + 50714 => 'BlackLevel', // Used in Raw IFD of DNG files. + 50715 => 'BlackLevelDeltaH', // Used in Raw IFD of DNG files. + 50716 => 'BlackLevelDeltaV', // Used in Raw IFD of DNG files. + 50717 => 'WhiteLevel', // Used in Raw IFD of DNG files. + 50718 => 'DefaultScale', // Used in Raw IFD of DNG files. + 50719 => 'DefaultCropOrigin', // Used in Raw IFD of DNG files. + 50720 => 'DefaultCropSize', // Used in Raw IFD of DNG files. + 50721 => 'ColorMatrix1', // Used in IFD 0 of DNG files. + 50722 => 'ColorMatrix2', // Used in IFD 0 of DNG files. + 50723 => 'CameraCalibration1', // Used in IFD 0 of DNG files. + 50724 => 'CameraCalibration2', // Used in IFD 0 of DNG files. + 50725 => 'ReductionMatrix1', // Used in IFD 0 of DNG files. + 50726 => 'ReductionMatrix2', // Used in IFD 0 of DNG files. + 50727 => 'AnalogBalance', // Used in IFD 0 of DNG files. + 50728 => 'AsShotNeutral', // Used in IFD 0 of DNG files. + 50729 => 'AsShotWhiteXY', // Used in IFD 0 of DNG files. + 50730 => 'BaselineExposure', // Used in IFD 0 of DNG files. + 50731 => 'BaselineNoise', // Used in IFD 0 of DNG files. + 50732 => 'BaselineSharpness', // Used in IFD 0 of DNG files. + 50733 => 'BayerGreenSplit', // Used in Raw IFD of DNG files. + 50734 => 'LinearResponseLimit', // Used in IFD 0 of DNG files. + 50735 => 'CameraSerialNumber', // Used in IFD 0 of DNG files. + 50736 => 'LensInfo', // Used in IFD 0 of DNG files. + 50737 => 'ChromaBlurRadius', // Used in Raw IFD of DNG files. + 50738 => 'AntiAliasStrength', // Used in Raw IFD of DNG files. + 50740 => 'DNGPrivateData', // Used in IFD 0 of DNG files. + 50741 => 'MakerNoteSafety', // Used in IFD 0 of DNG files. + 50778 => 'CalibrationIlluminant1', // Used in IFD 0 of DNG files. + 50779 => 'CalibrationIlluminant2', // Used in IFD 0 of DNG files. + 50780 => 'BestQualityScale', // Used in Raw IFD of DNG files. + 50784 => 'Alias Layer Metadata', // Alias Sketchbook Pro layer usage description. + 50908 => 'TIFF_RSID', // This private tag is used in a GEOTIFF standard by DGIWG. + 50909 => 'GEO_METADATA', // This private tag is used in a GEOTIFF standard by DGIWG. + + // EXIF tags - https://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif.html + 33434 => 'ExposureTime', // Exposure time, given in seconds. + 33437 => 'FNumber', // The F number. + 34850 => 'ExposureProgram', // The class of the program used by the camera to set exposure when the picture is taken. + 34852 => 'SpectralSensitivity', // Indicates the spectral sensitivity of each channel of the camera used. + 34855 => 'ISOSpeedRatings', // Indicates the ISO Speed and ISO Latitude of the camera or input device as specified in ISO 12232. + 34856 => 'OECF', // Indicates the Opto-Electric Conversion Function (OECF) specified in ISO 14524. + 36864 => 'ExifVersion', // The version of the supported Exif standard. + 36867 => 'DateTimeOriginal', // The date and time when the original image data was generated. + 36868 => 'DateTimeDigitized', // The date and time when the image was stored as digital data. + 37121 => 'ComponentsConfiguration', // Specific to compressed data; specifies the channels and complements PhotometricInterpretation + 37122 => 'CompressedBitsPerPixel', // Specific to compressed data; states the compressed bits per pixel. + 37377 => 'ShutterSpeedValue', // Shutter speed. + 37378 => 'ApertureValue', // The lens aperture. + 37379 => 'BrightnessValue', // The value of brightness. + 37380 => 'ExposureBiasValue', // The exposure bias. + 37381 => 'MaxApertureValue', // The smallest F number of the lens. + 37382 => 'SubjectDistance', // The distance to the subject, given in meters. + 37383 => 'MeteringMode', // The metering mode. + 37384 => 'LightSource', // The kind of light source. + 37385 => 'Flash', // Indicates the status of flash when the image was shot. + 37386 => 'FocalLength', // The actual focal length of the lens, in mm. + 37396 => 'SubjectArea', // Indicates the location and area of the main subject in the overall scene. + 37500 => 'MakerNote', // Manufacturer specific information. + 37510 => 'UserComment', // Keywords or comments on the image; complements ImageDescription. + 37520 => 'SubsecTime', // A tag used to record fractions of seconds for the DateTime tag. + 37521 => 'SubsecTimeOriginal', // A tag used to record fractions of seconds for the DateTimeOriginal tag. + 37522 => 'SubsecTimeDigitized', // A tag used to record fractions of seconds for the DateTimeDigitized tag. + 40960 => 'FlashpixVersion', // The Flashpix format version supported by a FPXR file. + 40961 => 'ColorSpace', // The color space information tag is always recorded as the color space specifier. + 40962 => 'PixelXDimension', // Specific to compressed data; the valid width of the meaningful image. + 40963 => 'PixelYDimension', // Specific to compressed data; the valid height of the meaningful image. + 40964 => 'RelatedSoundFile', // Used to record the name of an audio file related to the image data. + 41483 => 'FlashEnergy', // Indicates the strobe energy at the time the image is captured, as measured in Beam Candle Power Seconds + 41484 => 'SpatialFrequencyResponse', // Records the camera or input device spatial frequency table and SFR values in the direction of image width, image height, and diagonal direction, as specified in ISO 12233. + 41486 => 'FocalPlaneXResolution', // Indicates the number of pixels in the image width (X) direction per FocalPlaneResolutionUnit on the camera focal plane. + 41487 => 'FocalPlaneYResolution', // Indicates the number of pixels in the image height (Y) direction per FocalPlaneResolutionUnit on the camera focal plane. + 41488 => 'FocalPlaneResolutionUnit', // Indicates the unit for measuring FocalPlaneXResolution and FocalPlaneYResolution. + 41492 => 'SubjectLocation', // Indicates the location of the main subject in the scene. + 41493 => 'ExposureIndex', // Indicates the exposure index selected on the camera or input device at the time the image is captured. + 41495 => 'SensingMethod', // Indicates the image sensor type on the camera or input device. + 41728 => 'FileSource', // Indicates the image source. + 41729 => 'SceneType', // Indicates the type of scene. + 41730 => 'CFAPattern', // Indicates the color filter array (CFA) geometric pattern of the image sensor when a one-chip color area sensor is used. + 41985 => 'CustomRendered', // Indicates the use of special processing on image data, such as rendering geared to output. + 41986 => 'ExposureMode', // Indicates the exposure mode set when the image was shot. + 41987 => 'WhiteBalance', // Indicates the white balance mode set when the image was shot. + 41988 => 'DigitalZoomRatio', // Indicates the digital zoom ratio when the image was shot. + 41989 => 'FocalLengthIn35mmFilm', // Indicates the equivalent focal length assuming a 35mm film camera, in mm. + 41990 => 'SceneCaptureType', // Indicates the type of scene that was shot. + 41991 => 'GainControl', // Indicates the degree of overall image gain adjustment. + 41992 => 'Contrast', // Indicates the direction of contrast processing applied by the camera when the image was shot. + 41993 => 'Saturation', // Indicates the direction of saturation processing applied by the camera when the image was shot. + 41994 => 'Sharpness', // Indicates the direction of sharpness processing applied by the camera when the image was shot. + 41995 => 'DeviceSettingDescription', // This tag indicates information on the picture-taking conditions of a particular camera model. + 41996 => 'SubjectDistanceRange', // Indicates the distance to the subject. + 42016 => 'ImageUniqueID', // Indicates an identifier assigned uniquely to each image. + ); + } + return (isset($TIFFcommentName[$id]) ? $TIFFcommentName[$id] : 'unknown/invalid ('.$id.')'); + } + + +} diff --git a/serendipity_event_podcast/player/getid3/module.misc.cue.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.cue.php similarity index 64% rename from serendipity_event_podcast/player/getid3/module.misc.cue.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.cue.php index 351915f9..b358f8ac 100644 --- a/serendipity_event_podcast/player/getid3/module.misc.cue.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.cue.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.misc.cue.php // @@ -14,7 +15,7 @@ ///////////////////////////////////////////////////////////////// // // // Module originally written [2009-Mar-25] by // -// Nigel Barnes // +// Nigel Barnes // // Minor reformatting and similar small changes to integrate // // into getID3 by James Heinrich // // /// @@ -30,33 +31,49 @@ * A CueSheet class used to open and parse cuesheets. * */ -class getid3_cue -{ - var $cuesheet = array(); - function getid3_cue(&$fd, &$ThisFileInfo) { - $ThisFileInfo['fileformat'] = 'cue'; - $this->readCueSheetFilename($ThisFileInfo['filenamepath']); - $ThisFileInfo['cue'] = $this->cuesheet; +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_cue extends getid3_handler +{ + public $cuesheet = array(); + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $info['fileformat'] = 'cue'; + $this->readCueSheetFilename($info['filenamepath']); + $info['cue'] = $this->cuesheet; return true; } - - - function readCueSheetFilename($filename) + /** + * @param string $filename + * + * @return array + */ + public function readCueSheetFilename($filename) { $filedata = file_get_contents($filename); return $this->readCueSheet($filedata); } + /** - * Parses a cue sheet file. - * - * @param string $filename - The filename for the cue sheet to open. - */ - function readCueSheet(&$filedata) + * Parses a cue sheet file. + * + * @param string $filedata + * + * @return array + */ + public function readCueSheet(&$filedata) { $cue_lines = array(); - foreach (explode("\n", str_replace("\r", null, $filedata)) as $line) + foreach (explode("\n", str_replace("\r", '', $filedata)) as $line) { if ( (strlen($line) > 0) && ($line[0] != '#')) { @@ -69,18 +86,18 @@ class getid3_cue } /** - * Parses the cue sheet array. - * - * @param array $file - The cuesheet as an array of each line. - */ - function parseCueSheet($file) + * Parses the cue sheet array. + * + * @param array $file - The cuesheet as an array of each line. + */ + public function parseCueSheet($file) { //-1 means still global, all others are track specific $track_on = -1; + $currentFile = null; - for ($i=0; $i < count($file); $i++) - { - list($key) = explode(' ', strtolower($file[$i]), 2); + foreach ($file as $line) { + list($key) = explode(' ', strtolower($line), 2); switch ($key) { case 'catalog': @@ -89,25 +106,25 @@ class getid3_cue case 'performer': case 'songwriter': case 'title': - $this->parseString($file[$i], $track_on); + $this->parseString($line, $track_on); break; case 'file': - $currentFile = $this->parseFile($file[$i]); + $currentFile = $this->parseFile($line); break; case 'flags': - $this->parseFlags($file[$i], $track_on); + $this->parseFlags($line, $track_on); break; case 'index': case 'postgap': case 'pregap': - $this->parseIndex($file[$i], $track_on); + $this->parseIndex($line, $track_on); break; case 'rem': - $this->parseComment($file[$i], $track_on); + $this->parseComment($line, $track_on); break; case 'track': $track_on++; - $this->parseTrack($file[$i], $track_on); + $this->parseTrack($line, $track_on); if (isset($currentFile)) // if there's a file { $this->cuesheet['tracks'][$track_on]['datafile'] = $currentFile; @@ -115,19 +132,19 @@ class getid3_cue break; default: //save discarded junk and place string[] with track it was found in - $this->parseGarbage($file[$i], $track_on); + $this->parseGarbage($line, $track_on); break; } } } /** - * Parses the REM command. - * - * @param string $line - The line in the cue file that contains the TRACK command. - * @param integer $track_on - The track currently processing. - */ - function parseComment($line, $track_on) + * Parses the REM command. + * + * @param string $line - The line in the cue file that contains the TRACK command. + * @param integer $track_on - The track currently processing. + */ + public function parseComment($line, $track_on) { $explodedline = explode(' ', $line, 3); $comment_REM = (isset($explodedline[0]) ? $explodedline[0] : ''); @@ -145,12 +162,13 @@ class getid3_cue } /** - * Parses the FILE command. - * - * @param string $line - The line in the cue file that contains the FILE command. - * @return array - Array of FILENAME and TYPE of file.. - */ - function parseFile($line) + * Parses the FILE command. + * + * @param string $line - The line in the cue file that contains the FILE command. + * + * @return array - Array of FILENAME and TYPE of file.. + */ + public function parseFile($line) { $line = substr($line, strpos($line, ' ') + 1); $type = strtolower(substr($line, strrpos($line, ' '))); @@ -165,12 +183,12 @@ class getid3_cue } /** - * Parses the FLAG command. - * - * @param string $line - The line in the cue file that contains the TRACK command. - * @param integer $track_on - The track currently processing. - */ - function parseFlags($line, $track_on) + * Parses the FLAG command. + * + * @param string $line - The line in the cue file that contains the TRACK command. + * @param integer $track_on - The track currently processing. + */ + public function parseFlags($line, $track_on) { if ($track_on != -1) { @@ -203,12 +221,12 @@ class getid3_cue } /** - * Collect any unidentified data. - * - * @param string $line - The line in the cue file that contains the TRACK command. - * @param integer $track_on - The track currently processing. - */ - function parseGarbage($line, $track_on) + * Collect any unidentified data. + * + * @param string $line - The line in the cue file that contains the TRACK command. + * @param integer $track_on - The track currently processing. + */ + public function parseGarbage($line, $track_on) { if ( strlen($line) > 0 ) { @@ -224,15 +242,16 @@ class getid3_cue } /** - * Parses the INDEX command of a TRACK. - * - * @param string $line - The line in the cue file that contains the TRACK command. - * @param integer $track_on - The track currently processing. - */ - function parseIndex($line, $track_on) + * Parses the INDEX command of a TRACK. + * + * @param string $line - The line in the cue file that contains the TRACK command. + * @param integer $track_on - The track currently processing. + */ + public function parseIndex($line, $track_on) { $type = strtolower(substr($line, 0, strpos($line, ' '))); $line = substr($line, strpos($line, ' ') + 1); + $number = 0; if ($type == 'index') { @@ -258,7 +277,11 @@ class getid3_cue } } - function parseString($line, $track_on) + /** + * @param string $line + * @param int $track_on + */ + public function parseString($line, $track_on) { $category = strtolower(substr($line, 0, strpos($line, ' '))); $line = substr($line, strpos($line, ' ') + 1); @@ -289,12 +312,12 @@ class getid3_cue } /** - * Parses the TRACK command. - * - * @param string $line - The line in the cue file that contains the TRACK command. - * @param integer $track_on - The track currently processing. - */ - function parseTrack($line, $track_on) + * Parses the TRACK command. + * + * @param string $line - The line in the cue file that contains the TRACK command. + * @param integer $track_on - The track currently processing. + */ + public function parseTrack($line, $track_on) { $line = substr($line, strpos($line, ' ') + 1); $track = ltrim(substr($line, 0, strpos($line, ' ')), '0'); @@ -307,4 +330,3 @@ class getid3_cue } -?> diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.exe.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.exe.php new file mode 100644 index 00000000..9064fed8 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.exe.php @@ -0,0 +1,64 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.misc.exe.php // +// module for analyzing EXE files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_exe extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + $EXEheader = $this->fread(28); + + $magic = 'MZ'; + if (substr($EXEheader, 0, 2) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($EXEheader, 0, 2)).'"'); + return false; + } + + $info['fileformat'] = 'exe'; + $info['exe']['mz']['magic'] = 'MZ'; + + $info['exe']['mz']['raw']['last_page_size'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 2, 2)); + $info['exe']['mz']['raw']['page_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 4, 2)); + $info['exe']['mz']['raw']['relocation_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 6, 2)); + $info['exe']['mz']['raw']['header_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 8, 2)); + $info['exe']['mz']['raw']['min_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 10, 2)); + $info['exe']['mz']['raw']['max_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 12, 2)); + $info['exe']['mz']['raw']['initial_ss'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 14, 2)); + $info['exe']['mz']['raw']['initial_sp'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 16, 2)); + $info['exe']['mz']['raw']['checksum'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 18, 2)); + $info['exe']['mz']['raw']['cs_ip'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 20, 4)); + $info['exe']['mz']['raw']['relocation_table_offset'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 24, 2)); + $info['exe']['mz']['raw']['overlay_number'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 26, 2)); + + $info['exe']['mz']['byte_size'] = (($info['exe']['mz']['raw']['page_count'] - 1)) * 512 + $info['exe']['mz']['raw']['last_page_size']; + $info['exe']['mz']['header_size'] = $info['exe']['mz']['raw']['header_paragraphs'] * 16; + $info['exe']['mz']['memory_minimum'] = $info['exe']['mz']['raw']['min_memory_paragraphs'] * 16; + $info['exe']['mz']['memory_recommended'] = $info['exe']['mz']['raw']['max_memory_paragraphs'] * 16; + + $this->error('EXE parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + return false; + + } + +} diff --git a/serendipity_event_podcast/player/getid3/module.misc.iso.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.iso.php similarity index 75% rename from serendipity_event_podcast/player/getid3/module.misc.iso.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.iso.php index 94df9294..939bd631 100644 --- a/serendipity_event_podcast/player/getid3/module.misc.iso.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.iso.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.misc.iso.php // @@ -13,26 +14,33 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_iso +class getid3_iso extends getid3_handler { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_iso($fd, &$ThisFileInfo) { - $ThisFileInfo['fileformat'] = 'iso'; + $info['fileformat'] = 'iso'; for ($i = 16; $i <= 19; $i++) { - fseek($fd, 2048 * $i, SEEK_SET); - $ISOheader = fread($fd, 2048); + $this->fseek(2048 * $i); + $ISOheader = $this->fread(2048); if (substr($ISOheader, 1, 5) == 'CD001') { - switch (ord($ISOheader{0})) { + switch (ord($ISOheader[0])) { case 1: - $ThisFileInfo['iso']['primary_volume_descriptor']['offset'] = 2048 * $i; - $this->ParsePrimaryVolumeDescriptor($ISOheader, $ThisFileInfo); + $info['iso']['primary_volume_descriptor']['offset'] = 2048 * $i; + $this->ParsePrimaryVolumeDescriptor($ISOheader); break; case 2: - $ThisFileInfo['iso']['supplementary_volume_descriptor']['offset'] = 2048 * $i; - $this->ParseSupplementaryVolumeDescriptor($ISOheader, $ThisFileInfo); + $info['iso']['supplementary_volume_descriptor']['offset'] = 2048 * $i; + $this->ParseSupplementaryVolumeDescriptor($ISOheader); break; default: @@ -42,35 +50,39 @@ class getid3_iso } } - $this->ParsePathTable($fd, $ThisFileInfo); - - $ThisFileInfo['iso']['files'] = array(); - foreach ($ThisFileInfo['iso']['path_table']['directories'] as $directorynum => $directorydata) { - - $ThisFileInfo['iso']['directories'][$directorynum] = $this->ParseDirectoryRecord($fd, $directorydata, $ThisFileInfo); + $this->ParsePathTable(); + $info['iso']['files'] = array(); + if (!empty($info['iso']['path_table']['directories'])) { + foreach ($info['iso']['path_table']['directories'] as $directorynum => $directorydata) { + $info['iso']['directories'][$directorynum] = $this->ParseDirectoryRecord($directorydata); + } } return true; - } - - function ParsePrimaryVolumeDescriptor(&$ISOheader, &$ThisFileInfo) { + /** + * @param string $ISOheader + * + * @return bool + */ + public function ParsePrimaryVolumeDescriptor(&$ISOheader) { // ISO integer values are stored *BOTH* Little-Endian AND Big-Endian format!! // ie 12345 == 0x3039 is stored as $39 $30 $30 $39 in a 4-byte field // shortcuts - $ThisFileInfo['iso']['primary_volume_descriptor']['raw'] = array(); - $thisfile_iso_primaryVD = &$ThisFileInfo['iso']['primary_volume_descriptor']; + $info = &$this->getid3->info; + $info['iso']['primary_volume_descriptor']['raw'] = array(); + $thisfile_iso_primaryVD = &$info['iso']['primary_volume_descriptor']; $thisfile_iso_primaryVD_raw = &$thisfile_iso_primaryVD['raw']; $thisfile_iso_primaryVD_raw['volume_descriptor_type'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 0, 1)); $thisfile_iso_primaryVD_raw['standard_identifier'] = substr($ISOheader, 1, 5); if ($thisfile_iso_primaryVD_raw['standard_identifier'] != 'CD001') { - $ThisFileInfo['error'][] = 'Expected "CD001" at offset ('.($thisfile_iso_primaryVD['offset'] + 1).'), found "'.$thisfile_iso_primaryVD_raw['standard_identifier'].'" instead'; - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['iso']); + $this->error('Expected "CD001" at offset ('.($thisfile_iso_primaryVD['offset'] + 1).'), found "'.$thisfile_iso_primaryVD_raw['standard_identifier'].'" instead'); + unset($info['fileformat']); + unset($info['iso']); return false; } @@ -121,29 +133,34 @@ class getid3_iso $thisfile_iso_primaryVD['volume_expiration_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_expiration_date_time']); $thisfile_iso_primaryVD['volume_effective_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_effective_date_time']); - if (($thisfile_iso_primaryVD_raw['volume_space_size'] * 2048) > $ThisFileInfo['filesize']) { - $ThisFileInfo['error'][] = 'Volume Space Size ('.($thisfile_iso_primaryVD_raw['volume_space_size'] * 2048).' bytes) is larger than the file size ('.$ThisFileInfo['filesize'].' bytes) (truncated file?)'; + if (($thisfile_iso_primaryVD_raw['volume_space_size'] * 2048) > $info['filesize']) { + $this->error('Volume Space Size ('.($thisfile_iso_primaryVD_raw['volume_space_size'] * 2048).' bytes) is larger than the file size ('.$info['filesize'].' bytes) (truncated file?)'); } return true; } - - function ParseSupplementaryVolumeDescriptor(&$ISOheader, &$ThisFileInfo) { + /** + * @param string $ISOheader + * + * @return bool + */ + public function ParseSupplementaryVolumeDescriptor(&$ISOheader) { // ISO integer values are stored Both-Endian format!! // ie 12345 == 0x3039 is stored as $39 $30 $30 $39 in a 4-byte field // shortcuts - $ThisFileInfo['iso']['supplementary_volume_descriptor']['raw'] = array(); - $thisfile_iso_supplementaryVD = &$ThisFileInfo['iso']['supplementary_volume_descriptor']; + $info = &$this->getid3->info; + $info['iso']['supplementary_volume_descriptor']['raw'] = array(); + $thisfile_iso_supplementaryVD = &$info['iso']['supplementary_volume_descriptor']; $thisfile_iso_supplementaryVD_raw = &$thisfile_iso_supplementaryVD['raw']; $thisfile_iso_supplementaryVD_raw['volume_descriptor_type'] = getid3_lib::LittleEndian2Int(substr($ISOheader, 0, 1)); $thisfile_iso_supplementaryVD_raw['standard_identifier'] = substr($ISOheader, 1, 5); if ($thisfile_iso_supplementaryVD_raw['standard_identifier'] != 'CD001') { - $ThisFileInfo['error'][] = 'Expected "CD001" at offset ('.($thisfile_iso_supplementaryVD['offset'] + 1).'), found "'.$thisfile_iso_supplementaryVD_raw['standard_identifier'].'" instead'; - unset($ThisFileInfo['fileformat']); - unset($ThisFileInfo['iso']); + $this->error('Expected "CD001" at offset ('.($thisfile_iso_supplementaryVD['offset'] + 1).'), found "'.$thisfile_iso_supplementaryVD_raw['standard_identifier'].'" instead'); + unset($info['fileformat']); + unset($info['iso']); return false; } @@ -199,62 +216,66 @@ class getid3_iso $thisfile_iso_supplementaryVD['volume_expiration_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_expiration_date_time']); $thisfile_iso_supplementaryVD['volume_effective_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_effective_date_time']); - if (($thisfile_iso_supplementaryVD_raw['volume_space_size'] * $thisfile_iso_supplementaryVD_raw['logical_block_size']) > $ThisFileInfo['filesize']) { - $ThisFileInfo['error'][] = 'Volume Space Size ('.($thisfile_iso_supplementaryVD_raw['volume_space_size'] * $thisfile_iso_supplementaryVD_raw['logical_block_size']).' bytes) is larger than the file size ('.$ThisFileInfo['filesize'].' bytes) (truncated file?)'; + if (($thisfile_iso_supplementaryVD_raw['volume_space_size'] * $thisfile_iso_supplementaryVD_raw['logical_block_size']) > $info['filesize']) { + $this->error('Volume Space Size ('.($thisfile_iso_supplementaryVD_raw['volume_space_size'] * $thisfile_iso_supplementaryVD_raw['logical_block_size']).' bytes) is larger than the file size ('.$info['filesize'].' bytes) (truncated file?)'); } return true; } - - function ParsePathTable($fd, &$ThisFileInfo) { - if (!isset($ThisFileInfo['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']) && !isset($ThisFileInfo['iso']['primary_volume_descriptor']['raw']['path_table_l_location'])) { + /** + * @return bool + */ + public function ParsePathTable() { + $info = &$this->getid3->info; + if (!isset($info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']) && !isset($info['iso']['primary_volume_descriptor']['raw']['path_table_l_location'])) { return false; } - if (isset($ThisFileInfo['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location'])) { - $PathTableLocation = $ThisFileInfo['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']; - $PathTableSize = $ThisFileInfo['iso']['supplementary_volume_descriptor']['raw']['path_table_size']; + if (isset($info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location'])) { + $PathTableLocation = $info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']; + $PathTableSize = $info['iso']['supplementary_volume_descriptor']['raw']['path_table_size']; $TextEncoding = 'UTF-16BE'; // Big-Endian Unicode } else { - $PathTableLocation = $ThisFileInfo['iso']['primary_volume_descriptor']['raw']['path_table_l_location']; - $PathTableSize = $ThisFileInfo['iso']['primary_volume_descriptor']['raw']['path_table_size']; + $PathTableLocation = $info['iso']['primary_volume_descriptor']['raw']['path_table_l_location']; + $PathTableSize = $info['iso']['primary_volume_descriptor']['raw']['path_table_size']; $TextEncoding = 'ISO-8859-1'; // Latin-1 } - if (($PathTableLocation * 2048) > $ThisFileInfo['filesize']) { - $ThisFileInfo['error'][] = 'Path Table Location specifies an offset ('.($PathTableLocation * 2048).') beyond the end-of-file ('.$ThisFileInfo['filesize'].')'; + if (($PathTableLocation * 2048) > $info['filesize']) { + $this->error('Path Table Location specifies an offset ('.($PathTableLocation * 2048).') beyond the end-of-file ('.$info['filesize'].')'); return false; } - $ThisFileInfo['iso']['path_table']['offset'] = $PathTableLocation * 2048; - fseek($fd, $ThisFileInfo['iso']['path_table']['offset'], SEEK_SET); - $ThisFileInfo['iso']['path_table']['raw'] = fread($fd, $PathTableSize); + $info['iso']['path_table']['offset'] = $PathTableLocation * 2048; + $this->fseek($info['iso']['path_table']['offset']); + $info['iso']['path_table']['raw'] = $this->fread($PathTableSize); $offset = 0; $pathcounter = 1; + $FullPathArray = array(); while ($offset < $PathTableSize) { // shortcut - $ThisFileInfo['iso']['path_table']['directories'][$pathcounter] = array(); - $thisfile_iso_pathtable_directories_current = &$ThisFileInfo['iso']['path_table']['directories'][$pathcounter]; + $info['iso']['path_table']['directories'][$pathcounter] = array(); + $thisfile_iso_pathtable_directories_current = &$info['iso']['path_table']['directories'][$pathcounter]; - $thisfile_iso_pathtable_directories_current['length'] = getid3_lib::LittleEndian2Int(substr($ThisFileInfo['iso']['path_table']['raw'], $offset, 1)); + $thisfile_iso_pathtable_directories_current['length'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 1)); $offset += 1; - $thisfile_iso_pathtable_directories_current['extended_length'] = getid3_lib::LittleEndian2Int(substr($ThisFileInfo['iso']['path_table']['raw'], $offset, 1)); + $thisfile_iso_pathtable_directories_current['extended_length'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 1)); $offset += 1; - $thisfile_iso_pathtable_directories_current['location_logical'] = getid3_lib::LittleEndian2Int(substr($ThisFileInfo['iso']['path_table']['raw'], $offset, 4)); + $thisfile_iso_pathtable_directories_current['location_logical'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 4)); $offset += 4; - $thisfile_iso_pathtable_directories_current['parent_directory'] = getid3_lib::LittleEndian2Int(substr($ThisFileInfo['iso']['path_table']['raw'], $offset, 2)); + $thisfile_iso_pathtable_directories_current['parent_directory'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 2)); $offset += 2; - $thisfile_iso_pathtable_directories_current['name'] = substr($ThisFileInfo['iso']['path_table']['raw'], $offset, $thisfile_iso_pathtable_directories_current['length']); + $thisfile_iso_pathtable_directories_current['name'] = substr($info['iso']['path_table']['raw'], $offset, $thisfile_iso_pathtable_directories_current['length']); $offset += $thisfile_iso_pathtable_directories_current['length'] + ($thisfile_iso_pathtable_directories_current['length'] % 2); - $thisfile_iso_pathtable_directories_current['name_ascii'] = getid3_lib::iconv_fallback($TextEncoding, $ThisFileInfo['encoding'], $thisfile_iso_pathtable_directories_current['name']); + $thisfile_iso_pathtable_directories_current['name_ascii'] = getid3_lib::iconv_fallback($TextEncoding, $info['encoding'], $thisfile_iso_pathtable_directories_current['name']); $thisfile_iso_pathtable_directories_current['location_bytes'] = $thisfile_iso_pathtable_directories_current['location_logical'] * 2048; if ($pathcounter == 1) { $thisfile_iso_pathtable_directories_current['full_path'] = '/'; } else { - $thisfile_iso_pathtable_directories_current['full_path'] = $ThisFileInfo['iso']['path_table']['directories'][$thisfile_iso_pathtable_directories_current['parent_directory']]['full_path'].$thisfile_iso_pathtable_directories_current['name_ascii'].'/'; + $thisfile_iso_pathtable_directories_current['full_path'] = $info['iso']['path_table']['directories'][$thisfile_iso_pathtable_directories_current['parent_directory']]['full_path'].$thisfile_iso_pathtable_directories_current['name_ascii'].'/'; } $FullPathArray[] = $thisfile_iso_pathtable_directories_current['full_path']; @@ -264,20 +285,28 @@ class getid3_iso return true; } - - function ParseDirectoryRecord(&$fd, $directorydata, &$ThisFileInfo) { - if (isset($ThisFileInfo['iso']['supplementary_volume_descriptor'])) { + /** + * @param array $directorydata + * + * @return array + */ + public function ParseDirectoryRecord($directorydata) { + $info = &$this->getid3->info; + if (isset($info['iso']['supplementary_volume_descriptor'])) { $TextEncoding = 'UTF-16BE'; // Big-Endian Unicode } else { $TextEncoding = 'ISO-8859-1'; // Latin-1 } - fseek($fd, $directorydata['location_bytes'], SEEK_SET); - $DirectoryRecordData = fread($fd, 1); + $this->fseek($directorydata['location_bytes']); + $DirectoryRecordData = $this->fread(1); + $DirectoryRecord = array(); - while (ord($DirectoryRecordData{0}) > 33) { + while (ord($DirectoryRecordData[0]) > 33) { - $DirectoryRecordData .= fread($fd, ord($DirectoryRecordData{0}) - 1); + $DirectoryRecordData .= $this->fread(ord($DirectoryRecordData[0]) - 1); + + $ThisDirectoryRecord = array(); $ThisDirectoryRecord['raw']['length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 0, 1)); $ThisDirectoryRecord['raw']['extended_attribute_length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 1, 1)); @@ -291,7 +320,7 @@ class getid3_iso $ThisDirectoryRecord['raw']['file_identifier_length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 32, 1)); $ThisDirectoryRecord['raw']['file_identifier'] = substr($DirectoryRecordData, 33, $ThisDirectoryRecord['raw']['file_identifier_length']); - $ThisDirectoryRecord['file_identifier_ascii'] = getid3_lib::iconv_fallback($TextEncoding, $ThisFileInfo['encoding'], $ThisDirectoryRecord['raw']['file_identifier']); + $ThisDirectoryRecord['file_identifier_ascii'] = getid3_lib::iconv_fallback($TextEncoding, $info['encoding'], $ThisDirectoryRecord['raw']['file_identifier']); $ThisDirectoryRecord['filesize'] = $ThisDirectoryRecord['raw']['filesize']; $ThisDirectoryRecord['offset_bytes'] = $ThisDirectoryRecord['raw']['offset_logical'] * 2048; @@ -307,17 +336,22 @@ class getid3_iso $ThisDirectoryRecord['filename'] = $directorydata['full_path']; } else { $ThisDirectoryRecord['filename'] = $directorydata['full_path'].$this->ISOstripFilenameVersion($ThisDirectoryRecord['file_identifier_ascii']); - $ThisFileInfo['iso']['files'] = getid3_lib::array_merge_clobber($ThisFileInfo['iso']['files'], getid3_lib::CreateDeepArray($ThisDirectoryRecord['filename'], '/', $ThisDirectoryRecord['filesize'])); + $info['iso']['files'] = getid3_lib::array_merge_clobber($info['iso']['files'], getid3_lib::CreateDeepArray($ThisDirectoryRecord['filename'], '/', $ThisDirectoryRecord['filesize'])); } $DirectoryRecord[] = $ThisDirectoryRecord; - $DirectoryRecordData = fread($fd, 1); + $DirectoryRecordData = $this->fread(1); } return $DirectoryRecord; } - function ISOstripFilenameVersion($ISOfilename) { + /** + * @param string $ISOfilename + * + * @return string + */ + public function ISOstripFilenameVersion($ISOfilename) { // convert 'filename.ext;1' to 'filename.ext' if (!strstr($ISOfilename, ';')) { return $ISOfilename; @@ -326,7 +360,12 @@ class getid3_iso } } - function ISOtimeText2UNIXtime($ISOtime) { + /** + * @param string $ISOtime + * + * @return int|false + */ + public function ISOtimeText2UNIXtime($ISOtime) { $UNIXyear = (int) substr($ISOtime, 0, 4); $UNIXmonth = (int) substr($ISOtime, 4, 2); @@ -341,7 +380,12 @@ class getid3_iso return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear); } - function ISOtime2UNIXtime($ISOtime) { + /** + * @param string $ISOtime + * + * @return int + */ + public function ISOtime2UNIXtime($ISOtime) { // Represented by seven bytes: // 1: Number of years since 1900 // 2: Month of the year from 1 to 12 @@ -351,18 +395,23 @@ class getid3_iso // 6: second of the minute from 0 to 59 // 7: Offset from Greenwich Mean Time in number of 15 minute intervals from -48 (West) to +52 (East) - $UNIXyear = ord($ISOtime{0}) + 1900; - $UNIXmonth = ord($ISOtime{1}); - $UNIXday = ord($ISOtime{2}); - $UNIXhour = ord($ISOtime{3}); - $UNIXminute = ord($ISOtime{4}); - $UNIXsecond = ord($ISOtime{5}); - $GMToffset = $this->TwosCompliment2Decimal(ord($ISOtime{5})); + $UNIXyear = ord($ISOtime[0]) + 1900; + $UNIXmonth = ord($ISOtime[1]); + $UNIXday = ord($ISOtime[2]); + $UNIXhour = ord($ISOtime[3]); + $UNIXminute = ord($ISOtime[4]); + $UNIXsecond = ord($ISOtime[5]); + $GMToffset = $this->TwosCompliment2Decimal(ord($ISOtime[5])); return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear); } - function TwosCompliment2Decimal($BinaryValue) { + /** + * @param int $BinaryValue + * + * @return int + */ + public function TwosCompliment2Decimal($BinaryValue) { // http://sandbox.mc.edu/~bennet/cs110/tc/tctod.html // First check if the number is negative or positive by looking at the sign bit. // If it is positive, simply convert it to decimal. @@ -382,5 +431,3 @@ class getid3_iso } - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.msoffice.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.msoffice.php new file mode 100644 index 00000000..56d07f0e --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.msoffice.php @@ -0,0 +1,43 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.misc.msoffice.php // +// module for analyzing MS Office (.doc, .xls, etc) files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_msoffice extends getid3_handler +{ + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + $this->fseek($info['avdataoffset']); + $DOCFILEheader = $this->fread(8); + $magic = "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"; + if (substr($DOCFILEheader, 0, 8) != $magic) { + $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at '.$info['avdataoffset'].', found '.getid3_lib::PrintHexBytes(substr($DOCFILEheader, 0, 8)).' instead.'); + return false; + } + $info['fileformat'] = 'msoffice'; + + $this->error('MS Office (.doc, .xls, etc) parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); + return false; + + } + +} diff --git a/serendipity_event_podcast/player/getid3/module.misc.par2.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.par2.php similarity index 50% rename from serendipity_event_podcast/player/getid3/module.misc.par2.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.par2.php index 9f0e2218..b6c493ba 100644 --- a/serendipity_event_podcast/player/getid3/module.misc.par2.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.par2.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.misc.par2.php // @@ -13,20 +14,23 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_par2 +class getid3_par2 extends getid3_handler { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_par2(&$fd, &$ThisFileInfo) { + $info['fileformat'] = 'par2'; - $ThisFileInfo['fileformat'] = 'par2'; - - $ThisFileInfo['error'][] = 'PAR2 parsing not enabled in this version of getID3()'; + $this->error('PAR2 parsing not enabled in this version of getID3()'); return false; } } - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.pdf.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.pdf.php new file mode 100644 index 00000000..fd4ae728 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.pdf.php @@ -0,0 +1,158 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.misc.pdf.php // +// module for analyzing PDF files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_pdf extends getid3_handler +{ + /** misc.pdf + * return full details of PDF Cross-Reference Table (XREF) + * + * @var bool + */ + public $returnXREF = false; + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + $this->fseek(0); + if (preg_match('#^%PDF-([0-9\\.]+)$#', rtrim($this->fgets()), $matches)) { + $info['pdf']['header']['version'] = floatval($matches[1]); + $info['fileformat'] = 'pdf'; + + // the PDF Cross-Reference Table (XREF) is located near the end of the file + // the starting offset is specified in the penultimate section, on the two lines just before "%%EOF" + // the first line is "startxref", the second line is the byte offset of the XREF. + // We know the length of "%%EOF" and "startxref", but the offset could be 2-10 bytes, + // and we're not sure if the line ends are one or two bytes, so we might find "startxref" as little as 18(?) bytes + // from EOF, but it could 30 bytes, so we start 40 bytes back just to be safe and do a search for the data we want. + $this->fseek(-40, SEEK_END); + if (preg_match('#[\r\n]startxref[ \r\n]+([0-9]+)[ \r\n]+#', $this->fread(40), $matches)) { + $info['pdf']['trailer']['startxref'] = intval($matches[1]); + $this->parseXREF($info['pdf']['trailer']['startxref']); + if (!empty($info['pdf']['xref']['offset'])) { + while (!$this->feof() && (max(array_keys($info['pdf']['xref']['offset'])) > $info['pdf']['xref']['count'])) { + // suspect that there may be another XREF entry somewhere in the file, brute-force scan for it + /* + // starting at last known entry of main XREF table + $this->fseek(max($info['pdf']['xref']['offset'])); + */ + // starting at the beginning of the file + $this->fseek(0); + while (!$this->feof()) { + $XREFoffset = $this->ftell(); + if (rtrim($this->fgets()) == 'xref') { + if (empty($info['pdf']['xref']['xref_offsets']) || !in_array($XREFoffset, $info['pdf']['xref']['xref_offsets'])) { + $this->parseXREF($XREFoffset); + break; + } + } + } + } + + asort($info['pdf']['xref']['offset']); + $maxObjLengths = array(); + $prevOffset = 0; + $prevObjNum = 0; + foreach ($info['pdf']['xref']['offset'] as $objectNumber => $offset) { + // walk through all listed offsets to calculate the maximum possible length for each known object + if ($prevObjNum) { + $maxObjLengths[$prevObjNum] = $offset - $prevOffset; + } + $prevOffset = $offset; + $prevObjNum = $objectNumber; + } + ksort($maxObjLengths); + foreach ($info['pdf']['xref']['offset'] as $objectNumber => $offset) { + if ($info['pdf']['xref']['entry'][$objectNumber] == 'f') { + // "free" object means "deleted", ignore + continue; + } + if (!empty($maxObjLengths[$objectNumber]) && ($maxObjLengths[$objectNumber] < $this->getid3->option_fread_buffer_size)) { + // ignore object that are zero-size or >32kB, they are unlikely to contain information we're interested in + $this->fseek($offset); + $objBlob = $this->fread($maxObjLengths[$objectNumber]); + if (preg_match('#^'.$objectNumber.'[\\x00 \\r\\n\\t]*([0-9]+)[\\x00 \\r\\n\\t]*obj[\\x00 \\r\\n\\t]*(.*)(endobj)?[\\x00 \\r\\n\\t]*$#s', $objBlob, $matches)) { + list($dummy, $generation, $objectData) = $matches; + if (preg_match('#^<<[\r\n\s]*(/Type|/Pages|/Parent [0-9]+ [0-9]+ [A-Z]|/Count [0-9]+|/Kids *\\[[0-9A-Z ]+\\]|[\r\n\s])+[\r\n\s]*>>#', $objectData, $matches)) { + if (preg_match('#/Count ([0-9]+)#', $objectData, $matches)) { + $info['pdf']['pages'] = (int) $matches[1]; + break; // for now this is the only data we're looking for in the PDF not need to loop through every object in the file (and a large PDF may contain MANY objects). And it MAY be possible that there are other objects elsewhere in the file that define additional (or removed?) pages + } + } + } else { + $this->error('Unexpected structure "'.substr($objBlob, 0, 100).'" at offset '.$offset); + break; + } + } + } + if (!$this->returnXREF) { + unset($info['pdf']['xref']['offset'], $info['pdf']['xref']['generation'], $info['pdf']['xref']['entry'], $info['pdf']['xref']['xref_offsets']); + } + + } else { + $this->error('Did not find "xref" at offset '.$info['pdf']['trailer']['startxref']); + } + } else { + $this->error('Did not find "startxref" in the last 40 bytes of the PDF'); + } + + $this->warning('PDF parsing incomplete in this version of getID3() ['.$this->getid3->version().']'); + return true; + } + $this->error('Did not find "%PDF" at the beginning of the PDF'); + return false; + + } + + /** + * @return bool + */ + private function parseXREF($XREFoffset) { + $info = &$this->getid3->info; + + $this->fseek($XREFoffset); + if (rtrim($this->fgets()) == 'xref') { + + $info['pdf']['xref']['xref_offsets'][$XREFoffset] = $XREFoffset; + list($firstObjectNumber, $XREFcount) = explode(' ', rtrim($this->fgets())); + $firstObjectNumber = (int) $firstObjectNumber; + $XREFcount = (int) $XREFcount; + $info['pdf']['xref']['count'] = $XREFcount + (!empty($info['pdf']['xref']['count']) ? $info['pdf']['xref']['count'] : 0); + for ($i = 0; $i < $XREFcount; $i++) { + $line = rtrim($this->fgets()); + if (preg_match('#^([0-9]+) ([0-9]+) ([nf])$#', $line, $matches)) { + $info['pdf']['xref']['offset'][($firstObjectNumber + $i)] = (int) $matches[1]; + $info['pdf']['xref']['generation'][($firstObjectNumber + $i)] = (int) $matches[2]; + $info['pdf']['xref']['entry'][($firstObjectNumber + $i)] = $matches[3]; + } else { + $this->error('failed to parse XREF entry #'.$i.' in XREF table at offset '.$XREFoffset); + return false; + } + } + sort($info['pdf']['xref']['xref_offsets']); + return true; + + } + $this->warning('failed to find expected XREF structure at offset '.$XREFoffset); + return false; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.torrent.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.torrent.php new file mode 100644 index 00000000..1e25f95f --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.misc.torrent.php @@ -0,0 +1,247 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.misc.torrent.php // +// module for analyzing .torrent files // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_torrent extends getid3_handler +{ + /** + * Assume all .torrent files are less than 1MB and just read entire thing into memory for easy processing. + * Override this value if you need to process files larger than 1MB + * + * @var int + */ + public $max_torrent_filesize = 1048576; + + /** + * calculated InfoHash (SHA1 of the entire "info" Dictionary) + * + * @var string + */ + private $infohash = ''; + + const PIECE_HASHLENGTH = 20; // number of bytes the SHA1 hash is for each piece + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + $filesize = $info['avdataend'] - $info['avdataoffset']; + if ($filesize > $this->max_torrent_filesize) { // + $this->error('File larger ('.number_format($filesize).' bytes) than $max_torrent_filesize ('.number_format($this->max_torrent_filesize).' bytes), increase getid3_torrent->max_torrent_filesize if needed'); + return false; + } + $this->fseek($info['avdataoffset']); + $TORRENT = $this->fread($filesize); + $offset = 0; + if (!preg_match('#^(d8\\:announce|d7\\:comment)#', $TORRENT)) { + $this->error('Expecting "d8:announce" or "d7:comment" at '.$info['avdataoffset'].', found "'.substr($TORRENT, $offset, 12).'" instead.'); + return false; + } + $info['fileformat'] = 'torrent'; + + $info['torrent'] = $this->NextEntity($TORRENT, $offset); + if ($this->infohash) { + $info['torrent']['infohash'] = $this->infohash; + } + + if (empty($info['torrent']['info']['length']) && !empty($info['torrent']['info']['files'][0]['length'])) { + $info['torrent']['info']['length'] = 0; + foreach ($info['torrent']['info']['files'] as $key => $filedetails) { + $info['torrent']['info']['length'] += $filedetails['length']; + } + } + if (!empty($info['torrent']['info']['length']) && !empty($info['torrent']['info']['piece length']) && !empty($info['torrent']['info']['pieces'])) { + $num_pieces_size = ceil($info['torrent']['info']['length'] / $info['torrent']['info']['piece length']); + $num_pieces_hash = strlen($info['torrent']['info']['pieces']) / getid3_torrent::PIECE_HASHLENGTH; // should be concatenated 20-byte SHA1 hashes + if ($num_pieces_hash == $num_pieces_size) { + $info['torrent']['info']['piece_hash'] = array(); + for ($i = 0; $i < $num_pieces_size; $i++) { + $info['torrent']['info']['piece_hash'][$i] = ''; + for ($j = 0; $j < getid3_torrent::PIECE_HASHLENGTH; $j++) { + $info['torrent']['info']['piece_hash'][$i] .= sprintf('%02x', ord($info['torrent']['info']['pieces'][(($i * getid3_torrent::PIECE_HASHLENGTH) + $j)])); + } + } + unset($info['torrent']['info']['pieces']); + } else { + $this->warning('found '.$num_pieces_size.' pieces based on file/chunk size; found '.$num_pieces_hash.' pieces in hash table'); + } + } + if (!empty($info['torrent']['info']['name']) && !empty($info['torrent']['info']['length']) && !isset($info['torrent']['info']['files'])) { + // single-file torrent + $info['torrent']['files'] = array($info['torrent']['info']['name'] => $info['torrent']['info']['length']); + } elseif (!empty($info['torrent']['info']['files'])) { + // multi-file torrent + $info['torrent']['files'] = array(); + foreach ($info['torrent']['info']['files'] as $key => $filedetails) { + $info['torrent']['files'][implode('/', $filedetails['path'])] = $filedetails['length']; + } + } else { + $this->warning('no files found'); + } + + return true; + } + + /** + * @return string|array|int|bool + */ + public function NextEntity(&$TORRENT, &$offset) { + // https://fileformats.fandom.com/wiki/Torrent_file + // https://en.wikipedia.org/wiki/Torrent_file + // https://en.wikipedia.org/wiki/Bencode + + if ($offset >= strlen($TORRENT)) { + $this->error('cannot read beyond end of file '.$offset); + return false; + } + $type = $TORRENT[$offset++]; + if ($type == 'i') { + + // Integers are stored as ie: + // i90e + $value = $this->ReadSequentialDigits($TORRENT, $offset, true); + if ($TORRENT[$offset++] == 'e') { +//echo '
  • int: '.$value.'
  • '; + return (int) $value; + } + $this->error('unexpected('.__LINE__.') input "'.$value.'" at offset '.($offset - 1)); + return false; + + } elseif ($type == 'd') { + + // Dictionaries are stored as d[key1][value1][key2][value2][...]e. Keys and values appear alternately. + // Keys must be strings and must be ordered alphabetically. + // For example, {apple-red, lemon-yellow, violet-blue, banana-yellow} is stored as: + // d5:apple3:red6:banana6:yellow5:lemon6:yellow6:violet4:bluee + $values = array(); +//echo 'DICTIONARY @ '.$offset.'
      '; + $info_dictionary_start = null; // dummy declaration to prevent "Variable might not be defined" warnings + while (true) { + if ($TORRENT[$offset] === 'e') { + break; + } + $thisentry = array(); + $key = $this->NextEntity($TORRENT, $offset); + if ($key == 'info') { + $info_dictionary_start = $offset; + } + if ($key === false) { + $this->error('unexpected('.__LINE__.') input at offset '.$offset); + return false; + } + $value = $this->NextEntity($TORRENT, $offset); + if ($key == 'info') { + $info_dictionary_end = $offset; + $this->infohash = sha1(substr($TORRENT, $info_dictionary_start, $info_dictionary_end - $info_dictionary_start)); + } + if ($value === false) { + $this->error('unexpected('.__LINE__.') input at offset '.$offset); + return false; + } + $values[$key] = $value; + } + if ($TORRENT[$offset++] == 'e') { +//echo '
    '; + return $values; + } + $this->error('unexpected('.__LINE__.') input "'.$TORRENT[($offset - 1)].'" at offset '.($offset - 1)); + return false; + + } elseif ($type == 'l') { + +//echo 'LIST @ '.$offset.'
      '; + // Lists are stored as l[value 1][value2][value3][...]e. For example, {spam, eggs, cheeseburger} is stored as: + // l4:spam4:eggs12:cheeseburgere + $values = array(); + while (true) { + if ($TORRENT[$offset] === 'e') { + break; + } + $NextEntity = $this->NextEntity($TORRENT, $offset); + if ($NextEntity === false) { + $this->error('unexpected('.__LINE__.') input at offset '.($offset - 1)); + return false; + } + $values[] = $NextEntity; + } + if ($TORRENT[$offset++] == 'e') { +//echo '
    '; + return $values; + } + $this->error('unexpected('.__LINE__.') input "'.$TORRENT[($offset - 1)].'" at offset '.($offset - 1)); + return false; + + } elseif (ctype_digit($type)) { + + // Strings are stored as :: + // 4:wiki + $length = $type; + while (true) { + $char = $TORRENT[$offset++]; + if ($char == ':') { + break; + } elseif (!ctype_digit($char)) { + $this->error('unexpected('.__LINE__.') input "'.$char.'" at offset '.($offset - 1)); + return false; + } + $length .= $char; + } + if (($offset + $length) > strlen($TORRENT)) { + $this->error('string at offset '.$offset.' claims to be '.$length.' bytes long but only '.(strlen($TORRENT) - $offset).' bytes of data left in file'); + return false; + } + $string = substr($TORRENT, $offset, $length); + $offset += $length; +//echo '
  • string: '.$string.'
  • '; + return (string) $string; + + } else { + + $this->error('unexpected('.__LINE__.') input "'.$type.'" at offset '.($offset - 1)); + return false; + + } + } + + /** + * @return string + */ + public function ReadSequentialDigits(&$TORRENT, &$offset, $allow_negative=false) { + $start_offset = $offset; + $value = ''; + while (true) { + $char = $TORRENT[$offset++]; + if (!ctype_digit($char)) { + if ($allow_negative && ($char == '-') && (strlen($value) == 0)) { + // allow negative-sign if first character and $allow_negative enabled + } else { + $offset--; + break; + } + } + $value .= $char; + } + if (($value[0] === '0') && ($value !== '0')) { + $this->warning('illegal zero-padded number "'.$value.'" at offset '.$start_offset); + } + return $value; + } + +} diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.apetag.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.apetag.php new file mode 100644 index 00000000..c5502133 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.apetag.php @@ -0,0 +1,454 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.tag.apetag.php // +// module for analyzing APE tags // +// dependencies: NONE // +// /// +///////////////////////////////////////////////////////////////// + +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} + +class getid3_apetag extends getid3_handler +{ + /** + * true: return full data for all attachments; + * false: return no data for all attachments; + * integer: return data for attachments <= than this; + * string: save as file to this directory. + * + * @var int|bool|string + */ + public $inline_attachments = true; + + public $overrideendoffset = 0; + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; + + if (!getid3_lib::intValueSupported($info['filesize'])) { + $this->warning('Unable to check for APEtags because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'); + return false; + } + + $id3v1tagsize = 128; + $apetagheadersize = 32; + $lyrics3tagsize = 10; + + if ($this->overrideendoffset == 0) { + + $this->fseek(0 - $id3v1tagsize - $apetagheadersize - $lyrics3tagsize, SEEK_END); + $APEfooterID3v1 = $this->fread($id3v1tagsize + $apetagheadersize + $lyrics3tagsize); + + //if (preg_match('/APETAGEX.{24}TAG.{125}$/i', $APEfooterID3v1)) { + if (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $id3v1tagsize - $apetagheadersize, 8) == 'APETAGEX') { + + // APE tag found before ID3v1 + $info['ape']['tag_offset_end'] = $info['filesize'] - $id3v1tagsize; + + //} elseif (preg_match('/APETAGEX.{24}$/i', $APEfooterID3v1)) { + } elseif (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $apetagheadersize, 8) == 'APETAGEX') { + + // APE tag found, no ID3v1 + $info['ape']['tag_offset_end'] = $info['filesize']; + + } + + } else { + + $this->fseek($this->overrideendoffset - $apetagheadersize); + if ($this->fread(8) == 'APETAGEX') { + $info['ape']['tag_offset_end'] = $this->overrideendoffset; + } + + } + if (!isset($info['ape']['tag_offset_end'])) { + + // APE tag not found + unset($info['ape']); + return false; + + } + + // shortcut + $thisfile_ape = &$info['ape']; + + $this->fseek($thisfile_ape['tag_offset_end'] - $apetagheadersize); + $APEfooterData = $this->fread(32); + if (!($thisfile_ape['footer'] = $this->parseAPEheaderFooter($APEfooterData))) { + $this->error('Error parsing APE footer at offset '.$thisfile_ape['tag_offset_end']); + return false; + } + + if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) { + $this->fseek($thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'] - $apetagheadersize); + $thisfile_ape['tag_offset_start'] = $this->ftell(); + $APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize'] + $apetagheadersize); + } else { + $thisfile_ape['tag_offset_start'] = $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize']; + $this->fseek($thisfile_ape['tag_offset_start']); + $APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize']); + } + $info['avdataend'] = $thisfile_ape['tag_offset_start']; + + if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] < $thisfile_ape['tag_offset_end'])) { + $this->warning('ID3v1 tag information ignored since it appears to be a false synch in APEtag data'); + unset($info['id3v1']); + foreach ($info['warning'] as $key => $value) { + if ($value == 'Some ID3v1 fields do not use NULL characters for padding') { + unset($info['warning'][$key]); + sort($info['warning']); + break; + } + } + } + + $offset = 0; + if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) { + if ($thisfile_ape['header'] = $this->parseAPEheaderFooter(substr($APEtagData, 0, $apetagheadersize))) { + $offset += $apetagheadersize; + } else { + $this->error('Error parsing APE header at offset '.$thisfile_ape['tag_offset_start']); + return false; + } + } + + // shortcut + $info['replay_gain'] = array(); + $thisfile_replaygain = &$info['replay_gain']; + + for ($i = 0; $i < $thisfile_ape['footer']['raw']['tag_items']; $i++) { + $value_size = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4)); + $offset += 4; + $item_flags = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4)); + $offset += 4; + if (strstr(substr($APEtagData, $offset), "\x00") === false) { + $this->error('Cannot find null-byte (0x00) separator between ItemKey #'.$i.' and value. ItemKey starts '.$offset.' bytes into the APE tag, at file offset '.($thisfile_ape['tag_offset_start'] + $offset)); + return false; + } + $ItemKeyLength = strpos($APEtagData, "\x00", $offset) - $offset; + $item_key = strtolower(substr($APEtagData, $offset, $ItemKeyLength)); + + // shortcut + $thisfile_ape['items'][$item_key] = array(); + $thisfile_ape_items_current = &$thisfile_ape['items'][$item_key]; + + $thisfile_ape_items_current['offset'] = $thisfile_ape['tag_offset_start'] + $offset; + + $offset += ($ItemKeyLength + 1); // skip 0x00 terminator + $thisfile_ape_items_current['data'] = substr($APEtagData, $offset, $value_size); + $offset += $value_size; + + $thisfile_ape_items_current['flags'] = $this->parseAPEtagFlags($item_flags); + switch ($thisfile_ape_items_current['flags']['item_contents_raw']) { + case 0: // UTF-8 + case 2: // Locator (URL, filename, etc), UTF-8 encoded + $thisfile_ape_items_current['data'] = explode("\x00", $thisfile_ape_items_current['data']); + break; + + case 1: // binary data + default: + break; + } + + switch (strtolower($item_key)) { + // http://wiki.hydrogenaud.io/index.php?title=ReplayGain#MP3Gain + case 'replaygain_track_gain': + if (preg_match('#^([\\-\\+][0-9\\.,]{8})( dB)?$#', $thisfile_ape_items_current['data'][0], $matches)) { + $thisfile_replaygain['track']['adjustment'] = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero! + $thisfile_replaygain['track']['originator'] = 'unspecified'; + } else { + $this->warning('MP3gainTrackGain value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); + } + break; + + case 'replaygain_track_peak': + if (preg_match('#^([0-9\\.,]{8})$#', $thisfile_ape_items_current['data'][0], $matches)) { + $thisfile_replaygain['track']['peak'] = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero! + $thisfile_replaygain['track']['originator'] = 'unspecified'; + if ($thisfile_replaygain['track']['peak'] <= 0) { + $this->warning('ReplayGain Track peak from APEtag appears invalid: '.$thisfile_replaygain['track']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")'); + } + } else { + $this->warning('MP3gainTrackPeak value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); + } + break; + + case 'replaygain_album_gain': + if (preg_match('#^([\\-\\+][0-9\\.,]{8})( dB)?$#', $thisfile_ape_items_current['data'][0], $matches)) { + $thisfile_replaygain['album']['adjustment'] = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero! + $thisfile_replaygain['album']['originator'] = 'unspecified'; + } else { + $this->warning('MP3gainAlbumGain value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); + } + break; + + case 'replaygain_album_peak': + if (preg_match('#^([0-9\\.,]{8})$#', $thisfile_ape_items_current['data'][0], $matches)) { + $thisfile_replaygain['album']['peak'] = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero! + $thisfile_replaygain['album']['originator'] = 'unspecified'; + if ($thisfile_replaygain['album']['peak'] <= 0) { + $this->warning('ReplayGain Album peak from APEtag appears invalid: '.$thisfile_replaygain['album']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")'); + } + } else { + $this->warning('MP3gainAlbumPeak value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); + } + break; + + case 'mp3gain_undo': + if (preg_match('#^[\\-\\+][0-9]{3},[\\-\\+][0-9]{3},[NW]$#', $thisfile_ape_items_current['data'][0])) { + list($mp3gain_undo_left, $mp3gain_undo_right, $mp3gain_undo_wrap) = explode(',', $thisfile_ape_items_current['data'][0]); + $thisfile_replaygain['mp3gain']['undo_left'] = intval($mp3gain_undo_left); + $thisfile_replaygain['mp3gain']['undo_right'] = intval($mp3gain_undo_right); + $thisfile_replaygain['mp3gain']['undo_wrap'] = (($mp3gain_undo_wrap == 'Y') ? true : false); + } else { + $this->warning('MP3gainUndo value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); + } + break; + + case 'mp3gain_minmax': + if (preg_match('#^[0-9]{3},[0-9]{3}$#', $thisfile_ape_items_current['data'][0])) { + list($mp3gain_globalgain_min, $mp3gain_globalgain_max) = explode(',', $thisfile_ape_items_current['data'][0]); + $thisfile_replaygain['mp3gain']['globalgain_track_min'] = intval($mp3gain_globalgain_min); + $thisfile_replaygain['mp3gain']['globalgain_track_max'] = intval($mp3gain_globalgain_max); + } else { + $this->warning('MP3gainMinMax value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); + } + break; + + case 'mp3gain_album_minmax': + if (preg_match('#^[0-9]{3},[0-9]{3}$#', $thisfile_ape_items_current['data'][0])) { + list($mp3gain_globalgain_album_min, $mp3gain_globalgain_album_max) = explode(',', $thisfile_ape_items_current['data'][0]); + $thisfile_replaygain['mp3gain']['globalgain_album_min'] = intval($mp3gain_globalgain_album_min); + $thisfile_replaygain['mp3gain']['globalgain_album_max'] = intval($mp3gain_globalgain_album_max); + } else { + $this->warning('MP3gainAlbumMinMax value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"'); + } + break; + + case 'tracknumber': + if (is_array($thisfile_ape_items_current['data'])) { + foreach ($thisfile_ape_items_current['data'] as $comment) { + $thisfile_ape['comments']['track_number'][] = $comment; + } + } + break; + + case 'cover art (artist)': + case 'cover art (back)': + case 'cover art (band logo)': + case 'cover art (band)': + case 'cover art (colored fish)': + case 'cover art (composer)': + case 'cover art (conductor)': + case 'cover art (front)': + case 'cover art (icon)': + case 'cover art (illustration)': + case 'cover art (lead)': + case 'cover art (leaflet)': + case 'cover art (lyricist)': + case 'cover art (media)': + case 'cover art (movie scene)': + case 'cover art (other icon)': + case 'cover art (other)': + case 'cover art (performance)': + case 'cover art (publisher logo)': + case 'cover art (recording)': + case 'cover art (studio)': + // list of possible cover arts from http://taglib-sharp.sourcearchive.com/documentation/2.0.3.0-2/Ape_2Tag_8cs-source.html + if (is_array($thisfile_ape_items_current['data'])) { + $this->warning('APEtag "'.$item_key.'" should be flagged as Binary data, but was incorrectly flagged as UTF-8'); + $thisfile_ape_items_current['data'] = implode("\x00", $thisfile_ape_items_current['data']); + } + list($thisfile_ape_items_current['filename'], $thisfile_ape_items_current['data']) = explode("\x00", $thisfile_ape_items_current['data'], 2); + $thisfile_ape_items_current['data_offset'] = $thisfile_ape_items_current['offset'] + strlen($thisfile_ape_items_current['filename']."\x00"); + $thisfile_ape_items_current['data_length'] = strlen($thisfile_ape_items_current['data']); + + do { + $thisfile_ape_items_current['image_mime'] = ''; + $imageinfo = array(); + $imagechunkcheck = getid3_lib::GetDataImageSize($thisfile_ape_items_current['data'], $imageinfo); + if (($imagechunkcheck === false) || !isset($imagechunkcheck[2])) { + $this->warning('APEtag "'.$item_key.'" contains invalid image data'); + break; + } + $thisfile_ape_items_current['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]); + + if ($this->inline_attachments === false) { + // skip entirely + unset($thisfile_ape_items_current['data']); + break; + } + if ($this->inline_attachments === true) { + // great + } elseif (is_int($this->inline_attachments)) { + if ($this->inline_attachments < $thisfile_ape_items_current['data_length']) { + // too big, skip + $this->warning('attachment at '.$thisfile_ape_items_current['offset'].' is too large to process inline ('.number_format($thisfile_ape_items_current['data_length']).' bytes)'); + unset($thisfile_ape_items_current['data']); + break; + } + } elseif (is_string($this->inline_attachments)) { + $this->inline_attachments = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->inline_attachments), DIRECTORY_SEPARATOR); + if (!is_dir($this->inline_attachments) || !getID3::is_writable($this->inline_attachments)) { + // cannot write, skip + $this->warning('attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$this->inline_attachments.'" (not writable)'); + unset($thisfile_ape_items_current['data']); + break; + } + } + // if we get this far, must be OK + if (is_string($this->inline_attachments)) { + $destination_filename = $this->inline_attachments.DIRECTORY_SEPARATOR.md5($info['filenamepath']).'_'.$thisfile_ape_items_current['data_offset']; + if (!file_exists($destination_filename) || getID3::is_writable($destination_filename)) { + file_put_contents($destination_filename, $thisfile_ape_items_current['data']); + } else { + $this->warning('attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$destination_filename.'" (not writable)'); + } + $thisfile_ape_items_current['data_filename'] = $destination_filename; + unset($thisfile_ape_items_current['data']); + } else { + if (!isset($info['ape']['comments']['picture'])) { + $info['ape']['comments']['picture'] = array(); + } + $comments_picture_data = array(); + foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) { + if (isset($thisfile_ape_items_current[$picture_key])) { + $comments_picture_data[$picture_key] = $thisfile_ape_items_current[$picture_key]; + } + } + $info['ape']['comments']['picture'][] = $comments_picture_data; + unset($comments_picture_data); + } + } while (false); + break; + + default: + if (is_array($thisfile_ape_items_current['data'])) { + foreach ($thisfile_ape_items_current['data'] as $comment) { + $thisfile_ape['comments'][strtolower($item_key)][] = $comment; + } + } + break; + } + + } + if (empty($thisfile_replaygain)) { + unset($info['replay_gain']); + } + return true; + } + + /** + * @param string $APEheaderFooterData + * + * @return array|false + */ + public function parseAPEheaderFooter($APEheaderFooterData) { + // http://www.uni-jena.de/~pfk/mpp/sv8/apeheader.html + + // shortcut + $headerfooterinfo = array(); + $headerfooterinfo['raw'] = array(); + $headerfooterinfo_raw = &$headerfooterinfo['raw']; + + $headerfooterinfo_raw['footer_tag'] = substr($APEheaderFooterData, 0, 8); + if ($headerfooterinfo_raw['footer_tag'] != 'APETAGEX') { + return false; + } + $headerfooterinfo_raw['version'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 8, 4)); + $headerfooterinfo_raw['tagsize'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 12, 4)); + $headerfooterinfo_raw['tag_items'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 16, 4)); + $headerfooterinfo_raw['global_flags'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 20, 4)); + $headerfooterinfo_raw['reserved'] = substr($APEheaderFooterData, 24, 8); + + $headerfooterinfo['tag_version'] = $headerfooterinfo_raw['version'] / 1000; + if ($headerfooterinfo['tag_version'] >= 2) { + $headerfooterinfo['flags'] = $this->parseAPEtagFlags($headerfooterinfo_raw['global_flags']); + } + return $headerfooterinfo; + } + + /** + * @param int $rawflagint + * + * @return array + */ + public function parseAPEtagFlags($rawflagint) { + // "Note: APE Tags 1.0 do not use any of the APE Tag flags. + // All are set to zero on creation and ignored on reading." + // http://wiki.hydrogenaud.io/index.php?title=Ape_Tags_Flags + $flags = array(); + $flags['header'] = (bool) ($rawflagint & 0x80000000); + $flags['footer'] = (bool) ($rawflagint & 0x40000000); + $flags['this_is_header'] = (bool) ($rawflagint & 0x20000000); + $flags['item_contents_raw'] = ($rawflagint & 0x00000006) >> 1; + $flags['read_only'] = (bool) ($rawflagint & 0x00000001); + + $flags['item_contents'] = $this->APEcontentTypeFlagLookup($flags['item_contents_raw']); + + return $flags; + } + + /** + * @param int $contenttypeid + * + * @return string + */ + public function APEcontentTypeFlagLookup($contenttypeid) { + static $APEcontentTypeFlagLookup = array( + 0 => 'utf-8', + 1 => 'binary', + 2 => 'external', + 3 => 'reserved' + ); + return (isset($APEcontentTypeFlagLookup[$contenttypeid]) ? $APEcontentTypeFlagLookup[$contenttypeid] : 'invalid'); + } + + /** + * @param string $itemkey + * + * @return bool + */ + public function APEtagItemIsUTF8Lookup($itemkey) { + static $APEtagItemIsUTF8Lookup = array( + 'title', + 'subtitle', + 'artist', + 'album', + 'debut album', + 'publisher', + 'conductor', + 'track', + 'composer', + 'comment', + 'copyright', + 'publicationright', + 'file', + 'year', + 'record date', + 'record location', + 'genre', + 'media', + 'related', + 'isrc', + 'abstract', + 'language', + 'bibliography' + ); + return in_array(strtolower($itemkey), $APEtagItemIsUTF8Lookup); + } + +} diff --git a/serendipity_event_podcast/player/getid3/module.tag.id3v1.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.id3v1.php similarity index 63% rename from serendipity_event_podcast/player/getid3/module.tag.id3v1.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.id3v1.php index 30a40b72..b1de2578 100644 --- a/serendipity_event_podcast/player/getid3/module.tag.id3v1.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.id3v1.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.tag.id3v1.php // @@ -13,25 +14,39 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} -class getid3_id3v1 +class getid3_id3v1 extends getid3_handler { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_id3v1(&$fd, &$ThisFileInfo) { - - if (!getid3_lib::intValueSupported($ThisFileInfo['filesize'])) { - $ThisFileInfo['warning'][] = 'Unable to check for ID3v1 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; + if (!getid3_lib::intValueSupported($info['filesize'])) { + $this->warning('Unable to check for ID3v1 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'); return false; } - fseek($fd, -256, SEEK_END); - $preid3v1 = fread($fd, 128); - $id3v1tag = fread($fd, 128); + if($info['filesize'] < 256) { + $this->fseek(-128, SEEK_END); + $preid3v1 = ''; + $id3v1tag = $this->fread(128); + } else { + $this->fseek(-256, SEEK_END); + $preid3v1 = $this->fread(128); + $id3v1tag = $this->fread(128); + } + if (substr($id3v1tag, 0, 3) == 'TAG') { - $ThisFileInfo['avdataend'] = $ThisFileInfo['filesize'] - 128; + $info['avdataend'] = $info['filesize'] - 128; + $ParsedID3v1 = array(); $ParsedID3v1['title'] = $this->cutfield(substr($id3v1tag, 3, 30)); $ParsedID3v1['artist'] = $this->cutfield(substr($id3v1tag, 33, 30)); $ParsedID3v1['album'] = $this->cutfield(substr($id3v1tag, 63, 30)); @@ -41,9 +56,9 @@ class getid3_id3v1 // If second-last byte of comment field is null and last byte of comment field is non-null // then this is ID3v1.1 and the comment field is 28 bytes long and the 30th byte is the track number - if (($id3v1tag{125} === "\x00") && ($id3v1tag{126} !== "\x00")) { - $ParsedID3v1['track'] = ord(substr($ParsedID3v1['comment'], 29, 1)); - $ParsedID3v1['comment'] = substr($ParsedID3v1['comment'], 0, 28); + if (($id3v1tag[125] === "\x00") && ($id3v1tag[126] !== "\x00")) { + $ParsedID3v1['track_number'] = ord(substr($ParsedID3v1['comment'], 29, 1)); + $ParsedID3v1['comment'] = substr($ParsedID3v1['comment'], 0, 28); } $ParsedID3v1['comment'] = $this->cutfield($ParsedID3v1['comment']); @@ -58,6 +73,30 @@ class getid3_id3v1 foreach ($ParsedID3v1 as $key => $value) { $ParsedID3v1['comments'][$key][0] = $value; } + $ID3v1encoding = $this->getid3->encoding_id3v1; + if ($this->getid3->encoding_id3v1_autodetect) { + // ID3v1 encoding detection hack START + // ID3v1 is defined as always using ISO-8859-1 encoding, but it is not uncommon to find files tagged with ID3v1 using Windows-1251 or other character sets + // Since ID3v1 has no concept of character sets there is no certain way to know we have the correct non-ISO-8859-1 character set, but we can guess + foreach ($ParsedID3v1['comments'] as $tag_key => $valuearray) { + foreach ($valuearray as $key => $value) { + if (preg_match('#^[\\x00-\\x40\\x80-\\xFF]+$#', $value) && !ctype_digit((string) $value)) { // check for strings with only characters above chr(128) and punctuation/numbers, but not just numeric strings (e.g. track numbers or years) + foreach (array('Windows-1251', 'KOI8-R') as $id3v1_bad_encoding) { + if (function_exists('mb_convert_encoding') && @mb_convert_encoding($value, $id3v1_bad_encoding, $id3v1_bad_encoding) === $value) { + $ID3v1encoding = $id3v1_bad_encoding; + $this->warning('ID3v1 detected as '.$id3v1_bad_encoding.' text encoding in '.$tag_key); + break 3; + } elseif (function_exists('iconv') && @iconv($id3v1_bad_encoding, $id3v1_bad_encoding, $value) === $value) { + $ID3v1encoding = $id3v1_bad_encoding; + $this->warning('ID3v1 detected as '.$id3v1_bad_encoding.' text encoding in '.$tag_key); + break 3; + } + } + } + } + } + // ID3v1 encoding detection hack END + } // ID3v1 data is supposed to be padded with NULL characters, but some taggers pad with spaces $GoodFormatID3v1tag = $this->GenerateID3v1Tag( @@ -67,17 +106,18 @@ class getid3_id3v1 $ParsedID3v1['year'], (isset($ParsedID3v1['genre']) ? $this->LookupGenreID($ParsedID3v1['genre']) : false), $ParsedID3v1['comment'], - (!empty($ParsedID3v1['track']) ? $ParsedID3v1['track'] : '')); + (!empty($ParsedID3v1['track_number']) ? $ParsedID3v1['track_number'] : '')); $ParsedID3v1['padding_valid'] = true; if ($id3v1tag !== $GoodFormatID3v1tag) { $ParsedID3v1['padding_valid'] = false; - $ThisFileInfo['warning'][] = 'Some ID3v1 fields do not use NULL characters for padding'; + $this->warning('Some ID3v1 fields do not use NULL characters for padding'); } - $ParsedID3v1['tag_offset_end'] = $ThisFileInfo['filesize']; + $ParsedID3v1['tag_offset_end'] = $info['filesize']; $ParsedID3v1['tag_offset_start'] = $ParsedID3v1['tag_offset_end'] - 128; - $ThisFileInfo['id3v1'] = $ParsedID3v1; + $info['id3v1'] = $ParsedID3v1; + $info['id3v1']['encoding'] = $ID3v1encoding; } if (substr($preid3v1, 0, 3) == 'TAG') { @@ -93,19 +133,29 @@ class getid3_id3v1 // a Lyrics3 tag footer was found before the last ID3v1, assume false "TAG" synch } else { // APE and Lyrics3 footers not found - assume double ID3v1 - $ThisFileInfo['warning'][] = 'Duplicate ID3v1 tag detected - this has been known to happen with iTunes'; - $ThisFileInfo['avdataend'] -= 128; + $this->warning('Duplicate ID3v1 tag detected - this has been known to happen with iTunes'); + $info['avdataend'] -= 128; } } return true; } - static function cutfield($str) { + /** + * @param string $str + * + * @return string + */ + public static function cutfield($str) { return trim(substr($str, 0, strcspn($str, "\x00"))); } - static function ArrayOfGenres($allowSCMPXextended=false) { + /** + * @param bool $allowSCMPXextended + * + * @return string[] + */ + public static function ArrayOfGenres($allowSCMPXextended=false) { static $GenreLookup = array( 0 => 'Blues', 1 => 'Classic Rock', @@ -251,10 +301,54 @@ class getid3_id3v1 141 => 'Christian Rock', 142 => 'Merengue', 143 => 'Salsa', - 144 => 'Trash Metal', + 144 => 'Thrash Metal', 145 => 'Anime', 146 => 'JPop', 147 => 'Synthpop', + 148 => 'Abstract', + 149 => 'Art Rock', + 150 => 'Baroque', + 151 => 'Bhangra', + 152 => 'Big Beat', + 153 => 'Breakbeat', + 154 => 'Chillout', + 155 => 'Downtempo', + 156 => 'Dub', + 157 => 'EBM', + 158 => 'Eclectic', + 159 => 'Electro', + 160 => 'Electroclash', + 161 => 'Emo', + 162 => 'Experimental', + 163 => 'Garage', + 164 => 'Global', + 165 => 'IDM', + 166 => 'Illbient', + 167 => 'Industro-Goth', + 168 => 'Jam Band', + 169 => 'Krautrock', + 170 => 'Leftfield', + 171 => 'Lounge', + 172 => 'Math Rock', + 173 => 'New Romantic', + 174 => 'Nu-Breakz', + 175 => 'Post-Punk', + 176 => 'Post-Rock', + 177 => 'Psytrance', + 178 => 'Shoegaze', + 179 => 'Space Rock', + 180 => 'Trop Rock', + 181 => 'World Music', + 182 => 'Neoclassical', + 183 => 'Audiobook', + 184 => 'Audio Theatre', + 185 => 'Neue Deutsche Welle', + 186 => 'Podcast', + 187 => 'Indie-Rock', + 188 => 'G-Funk', + 189 => 'Dubstep', + 190 => 'Garage Rock', + 191 => 'Psybient', 255 => 'Unknown', @@ -289,7 +383,13 @@ class getid3_id3v1 return ($allowSCMPXextended ? $GenreLookupSCMPX : $GenreLookup); } - static function LookupGenreName($genreid, $allowSCMPXextended=true) { + /** + * @param string $genreid + * @param bool $allowSCMPXextended + * + * @return string|false + */ + public static function LookupGenreName($genreid, $allowSCMPXextended=true) { switch ($genreid) { case 'RX': case 'CR': @@ -301,12 +401,18 @@ class getid3_id3v1 $genreid = intval($genreid); // to handle 3 or '3' or '03' break; } - $GenreLookup = getid3_id3v1::ArrayOfGenres($allowSCMPXextended); + $GenreLookup = self::ArrayOfGenres($allowSCMPXextended); return (isset($GenreLookup[$genreid]) ? $GenreLookup[$genreid] : false); } - static function LookupGenreID($genre, $allowSCMPXextended=false) { - $GenreLookup = getid3_id3v1::ArrayOfGenres($allowSCMPXextended); + /** + * @param string $genre + * @param bool $allowSCMPXextended + * + * @return string|false + */ + public static function LookupGenreID($genre, $allowSCMPXextended=false) { + $GenreLookup = self::ArrayOfGenres($allowSCMPXextended); $LowerCaseNoSpaceSearchTerm = strtolower(str_replace(' ', '', $genre)); foreach ($GenreLookup as $key => $value) { if (strtolower(str_replace(' ', '', $value)) == $LowerCaseNoSpaceSearchTerm) { @@ -316,14 +422,30 @@ class getid3_id3v1 return false; } - static function StandardiseID3v1GenreName($OriginalGenre) { - if (($GenreID = getid3_id3v1::LookupGenreID($OriginalGenre)) !== false) { - return getid3_id3v1::LookupGenreName($GenreID); + /** + * @param string $OriginalGenre + * + * @return string|false + */ + public static function StandardiseID3v1GenreName($OriginalGenre) { + if (($GenreID = self::LookupGenreID($OriginalGenre)) !== false) { + return self::LookupGenreName($GenreID); } return $OriginalGenre; } - static function GenerateID3v1Tag($title, $artist, $album, $year, $genreid, $comment, $track='') { + /** + * @param string $title + * @param string $artist + * @param string $album + * @param string $year + * @param int $genreid + * @param string $comment + * @param int|string $track + * + * @return string + */ + public static function GenerateID3v1Tag($title, $artist, $album, $year, $genreid, $comment, $track='') { $ID3v1Tag = 'TAG'; $ID3v1Tag .= str_pad(trim(substr($title, 0, 30)), 30, "\x00", STR_PAD_RIGHT); $ID3v1Tag .= str_pad(trim(substr($artist, 0, 30)), 30, "\x00", STR_PAD_RIGHT); @@ -356,6 +478,3 @@ class getid3_id3v1 } } - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/module.tag.id3v2.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.id3v2.php similarity index 65% rename from serendipity_event_podcast/player/getid3/module.tag.id3v2.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.id3v2.php index 9641bc5a..9e7b4eb1 100644 --- a/serendipity_event_podcast/player/getid3/module.tag.id3v2.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.id3v2.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// /// // // module.tag.id3v2.php // @@ -13,12 +14,21 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true); -class getid3_id3v2 +class getid3_id3v2 extends getid3_handler { + public $StartingOffset = 0; + + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_id3v2(&$fd, &$ThisFileInfo, $StartingOffset=0) { // Overall tag structure: // +-----------------------------+ // | Header (10 bytes) | @@ -42,37 +52,37 @@ class getid3_id3v2 // shortcuts - $ThisFileInfo['id3v2']['header'] = true; - $thisfile_id3v2 = &$ThisFileInfo['id3v2']; + $info['id3v2']['header'] = true; + $thisfile_id3v2 = &$info['id3v2']; $thisfile_id3v2['flags'] = array(); $thisfile_id3v2_flags = &$thisfile_id3v2['flags']; - fseek($fd, $StartingOffset, SEEK_SET); - $header = fread($fd, 10); + $this->fseek($this->StartingOffset); + $header = $this->fread(10); if (substr($header, 0, 3) == 'ID3' && strlen($header) == 10) { - $thisfile_id3v2['majorversion'] = ord($header{3}); - $thisfile_id3v2['minorversion'] = ord($header{4}); + $thisfile_id3v2['majorversion'] = ord($header[3]); + $thisfile_id3v2['minorversion'] = ord($header[4]); // shortcut $id3v2_majorversion = &$thisfile_id3v2['majorversion']; } else { - unset($ThisFileInfo['id3v2']); + unset($info['id3v2']); return false; } if ($id3v2_majorversion > 4) { // this script probably won't correctly parse ID3v2.5.x and above (if it ever exists) - $ThisFileInfo['error'][] = 'this script only parses up to ID3v2.4.x - this tag is ID3v2.'.$id3v2_majorversion.'.'.$thisfile_id3v2['minorversion']; + $this->error('this script only parses up to ID3v2.4.x - this tag is ID3v2.'.$id3v2_majorversion.'.'.$thisfile_id3v2['minorversion']); return false; } - $id3_flags = ord($header{5}); + $id3_flags = ord($header[5]); switch ($id3v2_majorversion) { case 2: // %ab000000 in v2.2 @@ -98,7 +108,7 @@ class getid3_id3v2 $thisfile_id3v2['headerlength'] = getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length - $thisfile_id3v2['tag_offset_start'] = $StartingOffset; + $thisfile_id3v2['tag_offset_start'] = $this->StartingOffset; $thisfile_id3v2['tag_offset_end'] = $thisfile_id3v2['tag_offset_start'] + $thisfile_id3v2['headerlength']; @@ -128,7 +138,7 @@ class getid3_id3v2 } if ($sizeofframes > 0) { - $framedata = fread($fd, $sizeofframes); // read all frames from file into $framedata variable + $framedata = $this->fread($sizeofframes); // read all frames from file into $framedata variable // if entire frame data is unsynched, de-unsynch it now (ID3v2.3.x) if (!empty($thisfile_id3v2_flags['unsynch']) && ($id3v2_majorversion <= 3)) { @@ -191,33 +201,56 @@ class getid3_id3v2 // d - Tag restrictions // Flag data length $01 - $thisfile_id3v2['exthead']['length'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4), 1); + $thisfile_id3v2['exthead']['length'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 4), true); $extended_header_offset += 4; - $thisfile_id3v2['exthead']['flag_bytes'] = 1; + $thisfile_id3v2['exthead']['flag_bytes'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should always be 1 + $extended_header_offset += 1; + $thisfile_id3v2['exthead']['flag_raw'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, $thisfile_id3v2['exthead']['flag_bytes'])); $extended_header_offset += $thisfile_id3v2['exthead']['flag_bytes']; - $thisfile_id3v2['exthead']['flags']['update'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x4000); - $thisfile_id3v2['exthead']['flags']['crc'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x2000); - $thisfile_id3v2['exthead']['flags']['restrictions'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x1000); + $thisfile_id3v2['exthead']['flags']['update'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x40); + $thisfile_id3v2['exthead']['flags']['crc'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x20); + $thisfile_id3v2['exthead']['flags']['restrictions'] = (bool) ($thisfile_id3v2['exthead']['flag_raw'] & 0x10); + + if ($thisfile_id3v2['exthead']['flags']['update']) { + $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 0 + $extended_header_offset += 1; + } if ($thisfile_id3v2['exthead']['flags']['crc']) { - $thisfile_id3v2['exthead']['flag_data']['crc'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 5), 1); - $extended_header_offset += 5; + $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 5 + $extended_header_offset += 1; + $thisfile_id3v2['exthead']['flag_data']['crc'] = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, $ext_header_chunk_length), true, false); + $extended_header_offset += $ext_header_chunk_length; } + if ($thisfile_id3v2['exthead']['flags']['restrictions']) { + $ext_header_chunk_length = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); // should be 1 + $extended_header_offset += 1; + // %ppqrrstt $restrictions_raw = getid3_lib::BigEndian2Int(substr($framedata, $extended_header_offset, 1)); $extended_header_offset += 1; - $thisfile_id3v2['exthead']['flags']['restrictions']['tagsize'] = ($restrictions_raw && 0xC0) >> 6; // p - Tag size restrictions - $thisfile_id3v2['exthead']['flags']['restrictions']['textenc'] = ($restrictions_raw && 0x20) >> 5; // q - Text encoding restrictions - $thisfile_id3v2['exthead']['flags']['restrictions']['textsize'] = ($restrictions_raw && 0x18) >> 3; // r - Text fields size restrictions - $thisfile_id3v2['exthead']['flags']['restrictions']['imgenc'] = ($restrictions_raw && 0x04) >> 2; // s - Image encoding restrictions - $thisfile_id3v2['exthead']['flags']['restrictions']['imgsize'] = ($restrictions_raw && 0x03) >> 0; // t - Image size restrictions + $thisfile_id3v2['exthead']['flags']['restrictions']['tagsize'] = ($restrictions_raw & 0xC0) >> 6; // p - Tag size restrictions + $thisfile_id3v2['exthead']['flags']['restrictions']['textenc'] = ($restrictions_raw & 0x20) >> 5; // q - Text encoding restrictions + $thisfile_id3v2['exthead']['flags']['restrictions']['textsize'] = ($restrictions_raw & 0x18) >> 3; // r - Text fields size restrictions + $thisfile_id3v2['exthead']['flags']['restrictions']['imgenc'] = ($restrictions_raw & 0x04) >> 2; // s - Image encoding restrictions + $thisfile_id3v2['exthead']['flags']['restrictions']['imgsize'] = ($restrictions_raw & 0x03) >> 0; // t - Image size restrictions + + $thisfile_id3v2['exthead']['flags']['restrictions_text']['tagsize'] = $this->LookupExtendedHeaderRestrictionsTagSizeLimits($thisfile_id3v2['exthead']['flags']['restrictions']['tagsize']); + $thisfile_id3v2['exthead']['flags']['restrictions_text']['textenc'] = $this->LookupExtendedHeaderRestrictionsTextEncodings($thisfile_id3v2['exthead']['flags']['restrictions']['textenc']); + $thisfile_id3v2['exthead']['flags']['restrictions_text']['textsize'] = $this->LookupExtendedHeaderRestrictionsTextFieldSize($thisfile_id3v2['exthead']['flags']['restrictions']['textsize']); + $thisfile_id3v2['exthead']['flags']['restrictions_text']['imgenc'] = $this->LookupExtendedHeaderRestrictionsImageEncoding($thisfile_id3v2['exthead']['flags']['restrictions']['imgenc']); + $thisfile_id3v2['exthead']['flags']['restrictions_text']['imgsize'] = $this->LookupExtendedHeaderRestrictionsImageSizeSize($thisfile_id3v2['exthead']['flags']['restrictions']['imgsize']); } + if ($thisfile_id3v2['exthead']['length'] != $extended_header_offset) { + $this->warning('ID3v2.4 extended header length mismatch (expecting '.intval($thisfile_id3v2['exthead']['length']).', found '.intval($extended_header_offset).')'); + } } + $framedataoffset += $extended_header_offset; $framedata = substr($framedata, $extended_header_offset); } // end extended header @@ -230,15 +263,19 @@ class getid3_id3v2 $thisfile_id3v2['padding']['length'] = strlen($framedata); $thisfile_id3v2['padding']['valid'] = true; for ($i = 0; $i < $thisfile_id3v2['padding']['length']; $i++) { - if ($framedata{$i} != "\x00") { + if ($framedata[$i] != "\x00") { $thisfile_id3v2['padding']['valid'] = false; $thisfile_id3v2['padding']['errorpos'] = $thisfile_id3v2['padding']['start'] + $i; - $ThisFileInfo['warning'][] = 'Invalid ID3v2 padding found at offset '.$thisfile_id3v2['padding']['errorpos'].' (the remaining '.($thisfile_id3v2['padding']['length'] - $i).' bytes are considered invalid)'; + $this->warning('Invalid ID3v2 padding found at offset '.$thisfile_id3v2['padding']['errorpos'].' (the remaining '.($thisfile_id3v2['padding']['length'] - $i).' bytes are considered invalid)'); break; } } break; // skip rest of ID3v2 header } + $frame_header = null; + $frame_name = null; + $frame_size = null; + $frame_flags = null; if ($id3v2_majorversion == 2) { // Frame ID $xx xx xx (three characters) // Size $xx xx xx (24-bit integer) @@ -273,7 +310,7 @@ class getid3_id3v2 } elseif (($frame_name == "\x00".'MP3') || ($frame_name == "\x00\x00".'MP') || ($frame_name == ' MP3') || ($frame_name == 'MP3e')) { // MP3ext known broken frames - "ok" for the purposes of this test } elseif (($id3v2_majorversion == 4) && ($this->IsValidID3v2FrameName(substr($framedata, getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 0), 4), 3))) { - $ThisFileInfo['warning'][] = 'ID3v2 tag written as ID3v2.4, but with non-synchsafe integers (ID3v2.3 style). Older versions of (Helium2; iTunes) are known culprits of this. Tag has been parsed as ID3v2.3'; + $this->warning('ID3v2 tag written as ID3v2.4, but with non-synchsafe integers (ID3v2.3 style). Older versions of (Helium2; iTunes) are known culprits of this. Tag has been parsed as ID3v2.3'); $id3v2_majorversion = 3; $frame_size = getid3_lib::BigEndian2Int(substr($frame_header, 4, 4), 0); // 32-bit integer } @@ -292,30 +329,30 @@ class getid3_id3v2 $len = strlen($framedata); for ($i = 0; $i < $len; $i++) { - if ($framedata{$i} != "\x00") { + if ($framedata[$i] != "\x00") { $thisfile_id3v2['padding']['valid'] = false; $thisfile_id3v2['padding']['errorpos'] = $thisfile_id3v2['padding']['start'] + $i; - $ThisFileInfo['warning'][] = 'Invalid ID3v2 padding found at offset '.$thisfile_id3v2['padding']['errorpos'].' (the remaining '.($thisfile_id3v2['padding']['length'] - $i).' bytes are considered invalid)'; + $this->warning('Invalid ID3v2 padding found at offset '.$thisfile_id3v2['padding']['errorpos'].' (the remaining '.($thisfile_id3v2['padding']['length'] - $i).' bytes are considered invalid)'); break; } } break; // skip rest of ID3v2 header } - if ($frame_name == 'COM ') { - $ThisFileInfo['warning'][] = 'error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))). [Note: this particular error has been known to happen with tags edited by iTunes (versions "X v2.0.3", "v3.0.1" are known-guilty, probably others too)]'; - $frame_name = 'COMM'; + if ($iTunesBrokenFrameNameFixed = self::ID3v22iTunesBrokenFrameName($frame_name)) { + $this->warning('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))). [Note: this particular error has been known to happen with tags edited by iTunes (versions "X v2.0.3", "v3.0.1", "v7.0.0.70" are known-guilty, probably others too)]. Translated frame name from "'.str_replace("\x00", ' ', $frame_name).'" to "'.$iTunesBrokenFrameNameFixed.'" for parsing.'); + $frame_name = $iTunesBrokenFrameNameFixed; } if (($frame_size <= strlen($framedata)) && ($this->IsValidID3v2FrameName($frame_name, $id3v2_majorversion))) { - unset($parsedFrame); + $parsedFrame = array(); $parsedFrame['frame_name'] = $frame_name; $parsedFrame['frame_flags_raw'] = $frame_flags; $parsedFrame['data'] = substr($framedata, 0, $frame_size); $parsedFrame['datalength'] = getid3_lib::CastAsInt($frame_size); $parsedFrame['dataoffset'] = $framedataoffset; - $this->ParseID3v2Frame($parsedFrame, $ThisFileInfo); + $this->ParseID3v2Frame($parsedFrame); $thisfile_id3v2[$frame_name][] = $parsedFrame; $framedata = substr($framedata, $frame_size); @@ -328,28 +365,28 @@ class getid3_id3v2 // next frame is valid, just skip the current frame $framedata = substr($framedata, $frame_size); - $ThisFileInfo['warning'][] = 'Next ID3v2 frame is valid, skipping current frame.'; + $this->warning('Next ID3v2 frame is valid, skipping current frame.'); } else { // next frame is invalid too, abort processing //unset($framedata); $framedata = null; - $ThisFileInfo['error'][] = 'Next ID3v2 frame is also invalid, aborting processing.'; + $this->error('Next ID3v2 frame is also invalid, aborting processing.'); } } elseif ($frame_size == strlen($framedata)) { // this is the last frame, just skip - $ThisFileInfo['warning'][] = 'This was the last ID3v2 frame.'; + $this->warning('This was the last ID3v2 frame.'); } else { // next frame is invalid too, abort processing //unset($framedata); $framedata = null; - $ThisFileInfo['warning'][] = 'Invalid ID3v2 frame size, aborting.'; + $this->warning('Invalid ID3v2 frame size, aborting.'); } if (!$this->IsValidID3v2FrameName($frame_name, $id3v2_majorversion)) { @@ -362,21 +399,21 @@ class getid3_id3v2 case "\x00".'MP': case ' MP': case 'MP3': - $ThisFileInfo['warning'][] = 'error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: !IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))). [Note: this particular error has been known to happen with tags edited by "MP3ext (www.mutschler.de/mp3ext/)"]'; + $this->warning('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: !IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))). [Note: this particular error has been known to happen with tags edited by "MP3ext (www.mutschler.de/mp3ext/)"]'); break; default: - $ThisFileInfo['warning'][] = 'error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: !IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))).'; + $this->warning('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: !IsValidID3v2FrameName("'.str_replace("\x00", ' ', $frame_name).'", '.$id3v2_majorversion.'))).'); break; } } elseif (!isset($framedata) || ($frame_size > strlen($framedata))) { - $ThisFileInfo['error'][] = 'error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: $frame_size ('.$frame_size.') > strlen($framedata) ('.(isset($framedata) ? strlen($framedata) : 'null').')).'; + $this->error('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag). (ERROR: $frame_size ('.$frame_size.') > strlen($framedata) ('.(isset($framedata) ? strlen($framedata) : 'null').')).'); } else { - $ThisFileInfo['error'][] = 'error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag).'; + $this->error('error parsing "'.$frame_name.'" ('.$framedataoffset.' bytes into the ID3v2.'.$id3v2_majorversion.' tag).'); } @@ -397,14 +434,14 @@ class getid3_id3v2 // ID3v2 size 4 * %0xxxxxxx if (isset($thisfile_id3v2_flags['isfooter']) && $thisfile_id3v2_flags['isfooter']) { - $footer = fread($fd, 10); + $footer = $this->fread(10); if (substr($footer, 0, 3) == '3DI') { $thisfile_id3v2['footer'] = true; - $thisfile_id3v2['majorversion_footer'] = ord($footer{3}); - $thisfile_id3v2['minorversion_footer'] = ord($footer{4}); + $thisfile_id3v2['majorversion_footer'] = ord($footer[3]); + $thisfile_id3v2['minorversion_footer'] = ord($footer[4]); } if ($thisfile_id3v2['majorversion_footer'] <= 4) { - $id3_flags = ord(substr($footer{5})); + $id3_flags = ord($footer[5]); $thisfile_id3v2_flags['unsynch_footer'] = (bool) ($id3_flags & 0x80); $thisfile_id3v2_flags['extfoot_footer'] = (bool) ($id3_flags & 0x40); $thisfile_id3v2_flags['experim_footer'] = (bool) ($id3_flags & 0x20); @@ -415,16 +452,20 @@ class getid3_id3v2 } // end footer if (isset($thisfile_id3v2['comments']['genre'])) { + $genres = array(); foreach ($thisfile_id3v2['comments']['genre'] as $key => $value) { - unset($thisfile_id3v2['comments']['genre'][$key]); - $thisfile_id3v2['comments'] = getid3_lib::array_merge_noclobber($thisfile_id3v2['comments'], array('genre'=>$this->ParseID3v2GenreString($value))); + foreach ($this->ParseID3v2GenreString($value) as $genre) { + $genres[] = $genre; + } } + $thisfile_id3v2['comments']['genre'] = array_unique($genres); + unset($key, $value, $genres, $genre); } - if (isset($thisfile_id3v2['comments']['track'])) { - foreach ($thisfile_id3v2['comments']['track'] as $key => $value) { + if (isset($thisfile_id3v2['comments']['track_number'])) { + foreach ($thisfile_id3v2['comments']['track_number'] as $key => $value) { if (strstr($value, '/')) { - list($thisfile_id3v2['comments']['tracknum'][$key], $thisfile_id3v2['comments']['totaltracks'][$key]) = explode('/', $thisfile_id3v2['comments']['track'][$key]); + list($thisfile_id3v2['comments']['track_number'][$key], $thisfile_id3v2['comments']['totaltracks'][$key]) = explode('/', $thisfile_id3v2['comments']['track_number'][$key]); } } } @@ -434,29 +475,83 @@ class getid3_id3v2 } + if (!empty($thisfile_id3v2['TXXX'])) { + // MediaMonkey does this, maybe others: write a blank RGAD frame, but put replay-gain adjustment values in TXXX frames + foreach ($thisfile_id3v2['TXXX'] as $txxx_array) { + switch ($txxx_array['description']) { + case 'replaygain_track_gain': + if (empty($info['replay_gain']['track']['adjustment']) && !empty($txxx_array['data'])) { + $info['replay_gain']['track']['adjustment'] = floatval(trim(str_replace('dB', '', $txxx_array['data']))); + } + break; + case 'replaygain_track_peak': + if (empty($info['replay_gain']['track']['peak']) && !empty($txxx_array['data'])) { + $info['replay_gain']['track']['peak'] = floatval($txxx_array['data']); + } + break; + case 'replaygain_album_gain': + if (empty($info['replay_gain']['album']['adjustment']) && !empty($txxx_array['data'])) { + $info['replay_gain']['album']['adjustment'] = floatval(trim(str_replace('dB', '', $txxx_array['data']))); + } + break; + } + } + } + + // Set avdataoffset - $ThisFileInfo['avdataoffset'] = $thisfile_id3v2['headerlength']; + $info['avdataoffset'] = $thisfile_id3v2['headerlength']; if (isset($thisfile_id3v2['footer'])) { - $ThisFileInfo['avdataoffset'] += 10; + $info['avdataoffset'] += 10; } return true; } - - function ParseID3v2GenreString($genrestring) { + /** + * @param string $genrestring + * + * @return array + */ + public function ParseID3v2GenreString($genrestring) { // Parse genres into arrays of genreName and genreID // ID3v2.2.x, ID3v2.3.x: '(21)' or '(4)Eurodisco' or '(51)(39)' or '(55)((I think...)' // ID3v2.4.x: '21' $00 'Eurodisco' $00 $clean_genres = array(); + + // hack-fixes for some badly-written ID3v2.3 taggers, while trying not to break correctly-written tags + if (($this->getid3->info['id3v2']['majorversion'] == 3) && !preg_match('#[\x00]#', $genrestring)) { + // note: MusicBrainz Picard incorrectly stores plaintext genres separated by "/" when writing in ID3v2.3 mode, hack-fix here: + // replace / with NULL, then replace back the two ID3v1 genres that legitimately have "/" as part of the single genre name + if (strpos($genrestring, '/') !== false) { + $LegitimateSlashedGenreList = array( // https://github.com/JamesHeinrich/getID3/issues/223 + 'Pop/Funk', // ID3v1 genre #62 - https://en.wikipedia.org/wiki/ID3#standard + 'Cut-up/DJ', // Discogs - https://www.discogs.com/style/cut-up/dj + 'RnB/Swing', // Discogs - https://www.discogs.com/style/rnb/swing + 'Funk / Soul', // Discogs (note spaces) - https://www.discogs.com/genre/funk+%2F+soul + ); + $genrestring = str_replace('/', "\x00", $genrestring); + foreach ($LegitimateSlashedGenreList as $SlashedGenre) { + $genrestring = str_ireplace(str_replace('/', "\x00", $SlashedGenre), $SlashedGenre, $genrestring); + } + } + + // some other taggers separate multiple genres with semicolon, e.g. "Heavy Metal;Thrash Metal;Metal" + if (strpos($genrestring, ';') !== false) { + $genrestring = str_replace(';', "\x00", $genrestring); + } + } + + if (strpos($genrestring, "\x00") === false) { $genrestring = preg_replace('#\(([0-9]{1,3})\)#', '$1'."\x00", $genrestring); } + $genre_elements = explode("\x00", $genrestring); foreach ($genre_elements as $element) { $element = trim($element); if ($element) { - if (preg_match('#^[0-9]{1,3}#', $element)) { + if (preg_match('#^[0-9]{1,3}$#', $element)) { $clean_genres[] = getid3_id3v1::LookupGenreName($element); } else { $clean_genres[] = str_replace('((', '(', $element); @@ -466,11 +561,16 @@ class getid3_id3v2 return $clean_genres; } - - function ParseID3v2Frame(&$parsedFrame, &$ThisFileInfo) { + /** + * @param array $parsedFrame + * + * @return bool + */ + public function ParseID3v2Frame(&$parsedFrame) { // shortcuts - $id3v2_majorversion = $ThisFileInfo['id3v2']['majorversion']; + $info = &$this->getid3->info; + $id3v2_majorversion = $info['id3v2']['majorversion']; $parsedFrame['framenamelong'] = $this->FrameNameLongLookup($parsedFrame['frame_name']); if (empty($parsedFrame['framenamelong'])) { @@ -512,9 +612,6 @@ class getid3_id3v2 if ($parsedFrame['flags']['DataLengthIndicator']) { $parsedFrame['data_length_indicator'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 4), 1); $parsedFrame['data'] = substr($parsedFrame['data'], 4); - if ($parsedFrame['data_length_indicator'] != strlen($parsedFrame['data'])) { - $ThisFileInfo['warning'][] = 'ID3v2 frame "'.$parsedFrame['frame_name'].'" should be '.$parsedFrame['data_length_indicator'].' bytes long according to DataLengthIndicator, but found '.strlen($parsedFrame['data']).' bytes of data'; - } } } @@ -522,21 +619,25 @@ class getid3_id3v2 if ($parsedFrame['flags']['compression']) { $parsedFrame['decompressed_size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 0, 4)); if (!function_exists('gzuncompress')) { - $ThisFileInfo['warning'][] = 'gzuncompress() support required to decompress ID3v2 frame "'.$parsedFrame['frame_name'].'"'; + $this->warning('gzuncompress() support required to decompress ID3v2 frame "'.$parsedFrame['frame_name'].'"'); } else { - ob_start(); - if ($decompresseddata = gzuncompress(substr($parsedFrame['data'], 4))) { - ob_end_clean(); + if ($decompresseddata = @gzuncompress(substr($parsedFrame['data'], 4))) { + //if ($decompresseddata = @gzuncompress($parsedFrame['data'])) { $parsedFrame['data'] = $decompresseddata; + unset($decompresseddata); } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - $ThisFileInfo['warning'][] = 'gzuncompress() failed on compressed contents of ID3v2 frame "'.$parsedFrame['frame_name'].'"'; + $this->warning('gzuncompress() failed on compressed contents of ID3v2 frame "'.$parsedFrame['frame_name'].'"'); } } } } + if (!empty($parsedFrame['flags']['DataLengthIndicator'])) { + if ($parsedFrame['data_length_indicator'] != strlen($parsedFrame['data'])) { + $this->warning('ID3v2 frame "'.$parsedFrame['frame_name'].'" should be '.$parsedFrame['data_length_indicator'].' bytes long according to DataLengthIndicator, but found '.strlen($parsedFrame['data']).' bytes of data'); + } + } + if (isset($parsedFrame['datalength']) && ($parsedFrame['datalength'] == 0)) { $warning = 'Frame "'.$parsedFrame['frame_name'].'" at offset '.$parsedFrame['dataoffset'].' has no data portion'; @@ -548,7 +649,7 @@ class getid3_id3v2 default: break; } - $ThisFileInfo['warning'][] = $warning; + $this->warning($warning); } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'UFID')) || // 4.1 UFID Unique file identifier (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'UFI'))) { // 4.1 UFI Unique file identifier @@ -560,7 +661,6 @@ class getid3_id3v2 $exploded = explode("\x00", $parsedFrame['data'], 2); $parsedFrame['ownerid'] = (isset($exploded[0]) ? $exploded[0] : ''); $parsedFrame['data'] = (isset($exploded[1]) ? $exploded[1] : ''); - unset($parsedFrame['data']); } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'TXXX')) || // 4.2.2 TXXX User defined text information frame (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'TXX'))) { // 4.2.2 TXX User defined text information frame @@ -573,30 +673,35 @@ class getid3_id3v2 $frame_offset = 0; $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $ThisFileInfo['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; } - $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) { + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 } - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_description) === 0) { - $frame_description = ''; - } + $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); $parsedFrame['encodingid'] = $frame_textencoding; $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - $parsedFrame['description'] = $frame_description; - $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding))); + $parsedFrame['description'] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['description'])); + $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); + $parsedFrame['data'] = $this->RemoveStringTerminator($parsedFrame['data'], $frame_textencoding_terminator); if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - $ThisFileInfo['id3v2']['comments'][$parsedFrame['framenameshort']][] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $ThisFileInfo['id3v2']['encoding'], $parsedFrame['data'])); + $commentkey = ($parsedFrame['description'] ? $parsedFrame['description'] : (isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) ? count($info['id3v2']['comments'][$parsedFrame['framenameshort']]) : 0)); + if (!isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) || !array_key_exists($commentkey, $info['id3v2']['comments'][$parsedFrame['framenameshort']])) { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][$commentkey] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data'])); + } else { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = trim(getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data'])); + } } - unset($parsedFrame['data']); + //unset($parsedFrame['data']); do not unset, may be needed elsewhere, e.g. for replaygain - } elseif ($parsedFrame['frame_name']{0} == 'T') { // 4.2. T??[?] Text information frame + } elseif ($parsedFrame['frame_name'][0] == 'T') { // 4.2. T??[?] Text information frame // There may only be one text information frame of its kind in an tag. //
    @@ -606,23 +711,47 @@ class getid3_id3v2 $frame_offset = 0; $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $ThisFileInfo['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); } $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); + $parsedFrame['data'] = $this->RemoveStringTerminator($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding)); $parsedFrame['encodingid'] = $frame_textencoding; $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - - // remove possible terminating \x00 (put by encoding id or software bug) - $string = getid3_lib::iconv_fallback($parsedFrame['encoding'], $ThisFileInfo['id3v2']['encoding'], $parsedFrame['data']); - if ($string[strlen($string) - 1] == "\x00") { - $string = substr($string, 0, strlen($string) - 1); + // ID3v2.3 specs say that TPE1 (and others) can contain multiple artist values separated with / + // This of course breaks when an artist name contains slash character, e.g. "AC/DC" + // MP3tag (maybe others) implement alternative system where multiple artists are null-separated, which makes more sense + // getID3 will split null-separated artists into multiple artists and leave slash-separated ones to the user + switch ($parsedFrame['encoding']) { + case 'UTF-16': + case 'UTF-16BE': + case 'UTF-16LE': + $wordsize = 2; + break; + case 'ISO-8859-1': + case 'UTF-8': + default: + $wordsize = 1; + break; } - $ThisFileInfo['id3v2']['comments'][$parsedFrame['framenameshort']][] = $string; - unset($string); + $Txxx_elements = array(); + $Txxx_elements_start_offset = 0; + for ($i = 0; $i < strlen($parsedFrame['data']); $i += $wordsize) { + if (substr($parsedFrame['data'], $i, $wordsize) == str_repeat("\x00", $wordsize)) { + $Txxx_elements[] = substr($parsedFrame['data'], $Txxx_elements_start_offset, $i - $Txxx_elements_start_offset); + $Txxx_elements_start_offset = $i + $wordsize; + } + } + $Txxx_elements[] = substr($parsedFrame['data'], $Txxx_elements_start_offset, $i - $Txxx_elements_start_offset); + foreach ($Txxx_elements as $Txxx_element) { + $string = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $Txxx_element); + if (!empty($string)) { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $string; + } + } + unset($string, $wordsize, $i, $Txxx_elements, $Txxx_element, $Txxx_elements_start_offset); } } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'WXXX')) || // 4.3.2 WXXX User defined URL link frame @@ -636,60 +765,45 @@ class getid3_id3v2 $frame_offset = 0; $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $ThisFileInfo['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; } - $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) { + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 } - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - - if (ord($frame_description) === 0) { - $frame_description = ''; - } - $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding))); - - $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding)); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) { - $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 - } - if ($frame_terminatorpos) { - // there are null bytes after the data - this is not according to spec - // only use data up to first null byte - $frame_urldata = (string) substr($parsedFrame['data'], 0, $frame_terminatorpos); - } else { - // no null bytes following data, just use all data - $frame_urldata = (string) $parsedFrame['data']; - } - $parsedFrame['encodingid'] = $frame_textencoding; $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); + $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); // according to the frame text encoding + $parsedFrame['url'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); // always ISO-8859-1 + $parsedFrame['description'] = $this->RemoveStringTerminator($parsedFrame['description'], $frame_textencoding_terminator); + $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); - $parsedFrame['url'] = $frame_urldata; - $parsedFrame['description'] = $frame_description; if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { - $ThisFileInfo['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $ThisFileInfo['id3v2']['encoding'], $parsedFrame['url']); + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback('ISO-8859-1', $info['id3v2']['encoding'], $parsedFrame['url']); } unset($parsedFrame['data']); - } elseif ($parsedFrame['frame_name']{0} == 'W') { // 4.3. W??? URL link frames + } elseif ($parsedFrame['frame_name'][0] == 'W') { // 4.3. W??? URL link frames // There may only be one URL link frame of its kind in a tag, // except when stated otherwise in the frame description //
    // URL - $parsedFrame['url'] = trim($parsedFrame['data']); + $parsedFrame['url'] = trim($parsedFrame['data']); // always ISO-8859-1 if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { - $ThisFileInfo['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['url']; + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback('ISO-8859-1', $info['id3v2']['encoding'], $parsedFrame['url']); } unset($parsedFrame['data']); } elseif ((($id3v2_majorversion == 3) && ($parsedFrame['frame_name'] == 'IPLS')) || // 4.4 IPLS Involved people list (ID3v2.3 only) (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'IPL'))) { // 4.4 IPL Involved people list (ID3v2.2 only) + // http://id3.org/id3v2.3.0#sec4.4 // There may only be one 'IPL' frame in each tag //
    // Text encoding $xx @@ -698,14 +812,72 @@ class getid3_id3v2 $frame_offset = 0; $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $ThisFileInfo['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); } $parsedFrame['encodingid'] = $frame_textencoding; $parsedFrame['encoding'] = $this->TextEncodingNameLookup($parsedFrame['encodingid']); + $parsedFrame['data_raw'] = (string) substr($parsedFrame['data'], $frame_offset); + + // https://www.getid3.org/phpBB3/viewtopic.php?t=1369 + // "this tag typically contains null terminated strings, which are associated in pairs" + // "there are users that use the tag incorrectly" + $IPLS_parts = array(); + if (strpos($parsedFrame['data_raw'], "\x00") !== false) { + $IPLS_parts_unsorted = array(); + if (((strlen($parsedFrame['data_raw']) % 2) == 0) && ((substr($parsedFrame['data_raw'], 0, 2) == "\xFF\xFE") || (substr($parsedFrame['data_raw'], 0, 2) == "\xFE\xFF"))) { + // UTF-16, be careful looking for null bytes since most 2-byte characters may contain one; you need to find twin null bytes, and on even padding + $thisILPS = ''; + for ($i = 0; $i < strlen($parsedFrame['data_raw']); $i += 2) { + $twobytes = substr($parsedFrame['data_raw'], $i, 2); + if ($twobytes === "\x00\x00") { + $IPLS_parts_unsorted[] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $thisILPS); + $thisILPS = ''; + } else { + $thisILPS .= $twobytes; + } + } + if (strlen($thisILPS) > 2) { // 2-byte BOM + $IPLS_parts_unsorted[] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $thisILPS); + } + } else { + // ISO-8859-1 or UTF-8 or other single-byte-null character set + $IPLS_parts_unsorted = explode("\x00", $parsedFrame['data_raw']); + } + if (count($IPLS_parts_unsorted) == 1) { + // just a list of names, e.g. "Dino Baptiste, Jimmy Copley, John Gordon, Bernie Marsden, Sharon Watson" + foreach ($IPLS_parts_unsorted as $key => $value) { + $IPLS_parts_sorted = preg_split('#[;,\\r\\n\\t]#', $value); + $position = ''; + foreach ($IPLS_parts_sorted as $person) { + $IPLS_parts[] = array('position'=>$position, 'person'=>$person); + } + } + } elseif ((count($IPLS_parts_unsorted) % 2) == 0) { + $position = ''; + $person = ''; + foreach ($IPLS_parts_unsorted as $key => $value) { + if (($key % 2) == 0) { + $position = $value; + } else { + $person = $value; + $IPLS_parts[] = array('position'=>$position, 'person'=>$person); + $position = ''; + $person = ''; + } + } + } else { + foreach ($IPLS_parts_unsorted as $key => $value) { + $IPLS_parts[] = array($value); + } + } + + } else { + $IPLS_parts = preg_split('#[;,\\r\\n\\t]#', $parsedFrame['data_raw']); + } + $parsedFrame['data'] = $IPLS_parts; - $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - $ThisFileInfo['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $ThisFileInfo['id3v2']['encoding'], $parsedFrame['data']); + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['data']; } @@ -716,7 +888,7 @@ class getid3_id3v2 // CD TOC if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - $ThisFileInfo['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['data']; + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['data']; } @@ -766,6 +938,7 @@ class getid3_id3v2 $parsedFrame['bitsforbytesdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 8, 1)); $parsedFrame['bitsformsdeviation'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], 9, 1)); $parsedFrame['data'] = substr($parsedFrame['data'], 10); + $deviationbitstream = ''; while ($frame_offset < strlen($parsedFrame['data'])) { $deviationbitstream .= getid3_lib::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1)); } @@ -805,7 +978,7 @@ class getid3_id3v2 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'USLT')) || // 4.8 USLT Unsynchronised lyric/text transcription - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'ULT'))) { // 4.9 ULT Unsynchronised lyric/text transcription + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'ULT'))) { // 4.9 ULT Unsynchronised lyric/text transcription // There may be more than one 'Unsynchronised lyrics/text transcription' frame // in each tag, but only one with the same language and content descriptor. //
    @@ -816,30 +989,33 @@ class getid3_id3v2 $frame_offset = 0; $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $ThisFileInfo['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; } - $frame_language = substr($parsedFrame['data'], $frame_offset, 3); - $frame_offset += 3; - $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) { - $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 - } - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_description) === 0) { - $frame_description = ''; - } - $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding))); + if (strlen($parsedFrame['data']) >= (4 + strlen($frame_textencoding_terminator))) { // shouldn't be an issue but badly-written files have been spotted in the wild with not only no contents but also missing the required language field, see https://github.com/JamesHeinrich/getID3/issues/315 + $frame_language = substr($parsedFrame['data'], $frame_offset, 3); + $frame_offset += 3; + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { + $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 + } + $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); + $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); + $parsedFrame['data'] = $this->RemoveStringTerminator($parsedFrame['data'], $frame_textencoding_terminator); - $parsedFrame['encodingid'] = $frame_textencoding; - $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); + $parsedFrame['encodingid'] = $frame_textencoding; + $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - $parsedFrame['data'] = $parsedFrame['data']; - $parsedFrame['language'] = $frame_language; - $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); - $parsedFrame['description'] = $frame_description; - if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - $ThisFileInfo['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $ThisFileInfo['id3v2']['encoding'], $parsedFrame['data']); + $parsedFrame['language'] = $frame_language; + $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); + if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); + } + } else { + $this->warning('Invalid data in frame "'.$parsedFrame['frame_name'].'" at offset '.$parsedFrame['dataoffset']); } unset($parsedFrame['data']); @@ -862,8 +1038,10 @@ class getid3_id3v2 $frame_offset = 0; $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $ThisFileInfo['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; } $frame_language = substr($parsedFrame['data'], $frame_offset, 3); $frame_offset += 3; @@ -880,17 +1058,17 @@ class getid3_id3v2 $frame_remainingdata = substr($parsedFrame['data'], $frame_offset); while (strlen($frame_remainingdata)) { $frame_offset = 0; - $frame_terminatorpos = strpos($frame_remainingdata, $this->TextEncodingTerminatorLookup($frame_textencoding)); + $frame_terminatorpos = strpos($frame_remainingdata, $frame_textencoding_terminator); if ($frame_terminatorpos === false) { $frame_remainingdata = ''; } else { - if (ord(substr($frame_remainingdata, $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) { + if (ord(substr($frame_remainingdata, $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 } $parsedFrame['lyrics'][$timestampindex]['data'] = substr($frame_remainingdata, $frame_offset, $frame_terminatorpos - $frame_offset); - $frame_remainingdata = substr($frame_remainingdata, $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding))); - if (($timestampindex == 0) && (ord($frame_remainingdata{0}) != 0)) { + $frame_remainingdata = substr($frame_remainingdata, $frame_terminatorpos + strlen($frame_textencoding_terminator)); + if (($timestampindex == 0) && (ord($frame_remainingdata[0]) != 0)) { // timestamp probably omitted for first data item } else { $parsedFrame['lyrics'][$timestampindex]['timestamp'] = getid3_lib::BigEndian2Int(substr($frame_remainingdata, 0, 4)); @@ -914,36 +1092,41 @@ class getid3_id3v2 if (strlen($parsedFrame['data']) < 5) { - $ThisFileInfo['warning'][] = 'Invalid data (too short) for "'.$parsedFrame['frame_name'].'" frame at offset '.$parsedFrame['dataoffset']; + $this->warning('Invalid data (too short) for "'.$parsedFrame['frame_name'].'" frame at offset '.$parsedFrame['dataoffset']); } else { $frame_offset = 0; $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $ThisFileInfo['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; } $frame_language = substr($parsedFrame['data'], $frame_offset, 3); $frame_offset += 3; - $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) { + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 } - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_description) === 0) { - $frame_description = ''; - } - $frame_text = (string) substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding))); + $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); + $frame_text = (string) substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); + $frame_text = $this->RemoveStringTerminator($frame_text, $frame_textencoding_terminator); $parsedFrame['encodingid'] = $frame_textencoding; $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); $parsedFrame['language'] = $frame_language; $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false); - $parsedFrame['description'] = $frame_description; $parsedFrame['data'] = $frame_text; if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - $ThisFileInfo['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $ThisFileInfo['id3v2']['encoding'], $parsedFrame['data']); + $commentkey = ($parsedFrame['description'] ? $parsedFrame['description'] : (!empty($info['id3v2']['comments'][$parsedFrame['framenameshort']]) ? count($info['id3v2']['comments'][$parsedFrame['framenameshort']]) : 0)); + if (!isset($info['id3v2']['comments'][$parsedFrame['framenameshort']]) || !array_key_exists($commentkey, $info['id3v2']['comments'][$parsedFrame['framenameshort']])) { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][$commentkey] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); + } else { + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); + } } } @@ -978,7 +1161,7 @@ class getid3_id3v2 $frame_offset += 2; $parsedFrame[$RVA2channelcounter]['bitspeakvolume'] = ord(substr($frame_remainingdata, $frame_offset++, 1)); if (($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] < 1) || ($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] > 4)) { - $ThisFileInfo['warning'][] = 'ID3v2::RVA2 frame['.$RVA2channelcounter.'] contains invalid '.$parsedFrame[$RVA2channelcounter]['bitspeakvolume'].'-byte bits-representing-peak value'; + $this->warning('ID3v2::RVA2 frame['.$RVA2channelcounter.'] contains invalid '.$parsedFrame[$RVA2channelcounter]['bitspeakvolume'].'-byte bits-representing-peak value'); break; } $frame_bytespeakvolume = ceil($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] / 8); @@ -1185,15 +1368,19 @@ class getid3_id3v2 $frame_offset = 0; $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $ThisFileInfo['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; } + $frame_imagetype = null; + $frame_mimetype = null; if ($id3v2_majorversion == 2 && strlen($parsedFrame['data']) > $frame_offset) { $frame_imagetype = substr($parsedFrame['data'], $frame_offset, 3); if (strtolower($frame_imagetype) == 'ima') { // complete hack for mp3Rage (www.chaoticsoftware.com) that puts ID3v2.3-formatted - // MIME type instead of 3-char ID3v2.2-format image type (thanks xbhoffØpacbell*net) + // MIME type instead of 3-char ID3v2.2-format image type (thanks xbhoffØpacbell*net) $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); if (ord($frame_mimetype) === 0) { @@ -1219,46 +1406,95 @@ class getid3_id3v2 $frame_picturetype = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) { - $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 - } - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_description) === 0) { - $frame_description = ''; - } - $parsedFrame['encodingid'] = $frame_textencoding; - $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - - if ($id3v2_majorversion == 2) { - $parsedFrame['imagetype'] = $frame_imagetype; + if ($frame_offset >= $parsedFrame['datalength']) { + $this->warning('data portion of APIC frame is missing at offset '.($parsedFrame['dataoffset'] + 8 + $frame_offset)); } else { - $parsedFrame['mime'] = $frame_mimetype; - } - $parsedFrame['picturetypeid'] = $frame_picturetype; - $parsedFrame['picturetype'] = $this->APICPictureTypeLookup($frame_picturetype); - $parsedFrame['description'] = $frame_description; - $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding))); + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { + $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 + } + $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); + $parsedFrame['encodingid'] = $frame_textencoding; + $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - $parsedFrame['image_mime'] = ''; - $imageinfo = array(); - $imagechunkcheck = getid3_lib::GetDataImageSize($parsedFrame['data'], $imageinfo); - if (($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) { - $parsedFrame['image_mime'] = 'image/'.getid3_lib::ImageTypesLookup($imagechunkcheck[2]); - if ($imagechunkcheck[0]) { - $parsedFrame['image_width'] = $imagechunkcheck[0]; + if ($id3v2_majorversion == 2) { + $parsedFrame['imagetype'] = isset($frame_imagetype) ? $frame_imagetype : null; + } else { + $parsedFrame['mime'] = isset($frame_mimetype) ? $frame_mimetype : null; } - if ($imagechunkcheck[1]) { - $parsedFrame['image_height'] = $imagechunkcheck[1]; - } - $parsedFrame['image_bytes'] = strlen($parsedFrame['data']); - } + $parsedFrame['picturetypeid'] = $frame_picturetype; + $parsedFrame['picturetype'] = $this->APICPictureTypeLookup($frame_picturetype); + $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator)); + $parsedFrame['datalength'] = strlen($parsedFrame['data']); - if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - if (!isset($ThisFileInfo['id3v2']['comments']['picture'])) { - $ThisFileInfo['id3v2']['comments']['picture'] = array(); + $parsedFrame['image_mime'] = ''; + $imageinfo = array(); + if ($imagechunkcheck = getid3_lib::GetDataImageSize($parsedFrame['data'], $imageinfo)) { + if (($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) { + $parsedFrame['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]); + if ($imagechunkcheck[0]) { + $parsedFrame['image_width'] = $imagechunkcheck[0]; + } + if ($imagechunkcheck[1]) { + $parsedFrame['image_height'] = $imagechunkcheck[1]; + } + } } - $ThisFileInfo['id3v2']['comments']['picture'][] = array('data'=>$parsedFrame['data'], 'image_mime'=>$parsedFrame['image_mime']); + + do { + if ($this->getid3->option_save_attachments === false) { + // skip entirely + unset($parsedFrame['data']); + break; + } + $dir = ''; + if ($this->getid3->option_save_attachments === true) { + // great +/* + } elseif (is_int($this->getid3->option_save_attachments)) { + if ($this->getid3->option_save_attachments < $parsedFrame['data_length']) { + // too big, skip + $this->warning('attachment at '.$frame_offset.' is too large to process inline ('.number_format($parsedFrame['data_length']).' bytes)'); + unset($parsedFrame['data']); + break; + } +*/ + } elseif (is_string($this->getid3->option_save_attachments)) { + $dir = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->getid3->option_save_attachments), DIRECTORY_SEPARATOR); + if (!is_dir($dir) || !getID3::is_writable($dir)) { + // cannot write, skip + $this->warning('attachment at '.$frame_offset.' cannot be saved to "'.$dir.'" (not writable)'); + unset($parsedFrame['data']); + break; + } + } + // if we get this far, must be OK + if (is_string($this->getid3->option_save_attachments)) { + $destination_filename = $dir.DIRECTORY_SEPARATOR.md5($info['filenamepath']).'_'.$frame_offset; + if (!file_exists($destination_filename) || getID3::is_writable($destination_filename)) { + file_put_contents($destination_filename, $parsedFrame['data']); + } else { + $this->warning('attachment at '.$frame_offset.' cannot be saved to "'.$destination_filename.'" (not writable)'); + } + $parsedFrame['data_filename'] = $destination_filename; + unset($parsedFrame['data']); + } else { + if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { + if (!isset($info['id3v2']['comments']['picture'])) { + $info['id3v2']['comments']['picture'] = array(); + } + $comments_picture_data = array(); + foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) { + if (isset($parsedFrame[$picture_key])) { + $comments_picture_data[$picture_key] = $parsedFrame[$picture_key]; + } + } + $info['id3v2']['comments']['picture'][] = $comments_picture_data; + unset($comments_picture_data); + } + } + } while (false); } } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'GEOB')) || // 4.15 GEOB General encapsulated object @@ -1274,8 +1510,10 @@ class getid3_id3v2 $frame_offset = 0; $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $ThisFileInfo['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; } $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); @@ -1284,25 +1522,23 @@ class getid3_id3v2 } $frame_offset = $frame_terminatorpos + strlen("\x00"); - $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) { + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 } $frame_filename = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); if (ord($frame_filename) === 0) { $frame_filename = ''; } - $frame_offset = $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)); + $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); - $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) { + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 } - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_description) === 0) { - $frame_description = ''; - } - $frame_offset = $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)); + $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); + $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); $parsedFrame['objectdata'] = (string) substr($parsedFrame['data'], $frame_offset); $parsedFrame['encodingid'] = $frame_textencoding; @@ -1310,7 +1546,6 @@ class getid3_id3v2 $parsedFrame['mime'] = $frame_mimetype; $parsedFrame['filename'] = $frame_filename; - $parsedFrame['description'] = $frame_description; unset($parsedFrame['data']); @@ -1326,7 +1561,7 @@ class getid3_id3v2 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'POPM')) || // 4.17 POPM Popularimeter - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'POP'))) { // 4.18 POP Popularimeter + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'POP'))) { // 4.18 POP Popularimeter // There may be more than one 'POPM' frame in each tag, // but only one with the same email address //
    @@ -1342,9 +1577,9 @@ class getid3_id3v2 } $frame_offset = $frame_terminatorpos + strlen("\x00"); $frame_rating = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $parsedFrame['data'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset)); - $parsedFrame['email'] = $frame_emailaddress; - $parsedFrame['rating'] = $frame_rating; + $parsedFrame['counter'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset)); + $parsedFrame['email'] = $frame_emailaddress; + $parsedFrame['rating'] = $frame_rating; unset($parsedFrame['data']); @@ -1380,15 +1615,12 @@ class getid3_id3v2 $frame_offset = $frame_terminatorpos + strlen("\x00"); $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_description) === 0) { - $frame_description = ''; - } + $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); $frame_offset = $frame_terminatorpos + strlen("\x00"); $parsedFrame['ownerid'] = $frame_ownerid; $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); - $parsedFrame['description'] = $frame_description; unset($parsedFrame['data']); @@ -1406,7 +1638,7 @@ class getid3_id3v2 $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); if (ord($frame_ownerid) === 0) { - $frame_ownerid == ''; + $frame_ownerid = ''; } $frame_offset = $frame_terminatorpos + strlen("\x00"); $parsedFrame['ownerid'] = $frame_ownerid; @@ -1419,7 +1651,7 @@ class getid3_id3v2 } elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'LINK')) || // 4.20 LINK Linked information - (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'LNK'))) { // 4.22 LNK Linked information + (($id3v2_majorversion == 2) && ($parsedFrame['frame_name'] == 'LNK'))) { // 4.22 LNK Linked information // There may be more than one 'LINK' frame in a tag, // but only one with the same contents //
    @@ -1447,7 +1679,7 @@ class getid3_id3v2 $parsedFrame['additionaldata'] = (string) substr($parsedFrame['data'], $frame_offset); if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) { - $ThisFileInfo['id3v2']['comments'][$parsedFrame['framenameshort']][] = utf8_encode($parsedFrame['url']); + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback_iso88591_utf8($parsedFrame['url']); } unset($parsedFrame['data']); @@ -1475,7 +1707,7 @@ class getid3_id3v2 $frame_offset = 0; $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $ThisFileInfo['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); } $frame_language = substr($parsedFrame['data'], $frame_offset, 3); $frame_offset += 3; @@ -1484,9 +1716,10 @@ class getid3_id3v2 $parsedFrame['encodingid'] = $frame_textencoding; $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); - $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); + $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset); + $parsedFrame['data'] = $this->RemoveStringTerminator($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding)); if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) { - $ThisFileInfo['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $ThisFileInfo['id3v2']['encoding'], $parsedFrame['data']); + $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = getid3_lib::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']); } unset($parsedFrame['data']); @@ -1502,7 +1735,7 @@ class getid3_id3v2 $frame_offset = 0; $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $ThisFileInfo['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); } $parsedFrame['encodingid'] = $frame_textencoding; $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding); @@ -1516,12 +1749,13 @@ class getid3_id3v2 $parsedFrame['pricepaid']['value'] = substr($frame_pricepaid, 3); $parsedFrame['purchasedate'] = substr($parsedFrame['data'], $frame_offset, 8); - if (!$this->IsValidDateStampString($parsedFrame['purchasedate'])) { + if ($this->IsValidDateStampString($parsedFrame['purchasedate'])) { $parsedFrame['purchasedateunix'] = mktime (0, 0, 0, substr($parsedFrame['purchasedate'], 4, 2), substr($parsedFrame['purchasedate'], 6, 2), substr($parsedFrame['purchasedate'], 0, 4)); } $frame_offset += 8; $parsedFrame['seller'] = (string) substr($parsedFrame['data'], $frame_offset); + $parsedFrame['seller'] = $this->RemoveStringTerminator($parsedFrame['seller'], $this->TextEncodingTerminatorLookup($frame_textencoding)); unset($parsedFrame['data']); @@ -1541,8 +1775,10 @@ class getid3_id3v2 $frame_offset = 0; $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1)); + $frame_textencoding_terminator = $this->TextEncodingTerminatorLookup($frame_textencoding); if ((($id3v2_majorversion <= 3) && ($frame_textencoding > 1)) || (($id3v2_majorversion == 4) && ($frame_textencoding > 3))) { - $ThisFileInfo['warning'][] = 'Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'; + $this->warning('Invalid text encoding byte ('.$frame_textencoding.') in frame "'.$parsedFrame['frame_name'].'" - defaulting to ISO-8859-1 encoding'); + $frame_textencoding_terminator = "\x00"; } $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); @@ -1564,25 +1800,23 @@ class getid3_id3v2 $frame_receivedasid = ord(substr($parsedFrame['data'], $frame_offset++, 1)); - $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) { + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 } $frame_sellername = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); if (ord($frame_sellername) === 0) { $frame_sellername = ''; } - $frame_offset = $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)); + $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); - $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset); - if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) { + $frame_terminatorpos = strpos($parsedFrame['data'], $frame_textencoding_terminator, $frame_offset); + if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($frame_textencoding_terminator), 1)) === 0) { $frame_terminatorpos++; // strpos() fooled because 2nd byte of Unicode chars are often 0x00 } - $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); - if (ord($frame_description) === 0) { - $frame_description = ''; - } - $frame_offset = $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)); + $parsedFrame['description'] = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); + $parsedFrame['description'] = $this->MakeUTF16emptyStringEmpty($parsedFrame['description']); + $frame_offset = $frame_terminatorpos + strlen($frame_textencoding_terminator); $frame_terminatorpos = strpos($parsedFrame['data'], "\x00", $frame_offset); $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset); @@ -1598,7 +1832,6 @@ class getid3_id3v2 $parsedFrame['receivedasid'] = $frame_receivedasid; $parsedFrame['receivedas'] = $this->COMRReceivedAsLookup($frame_receivedasid); $parsedFrame['sellername'] = $frame_sellername; - $parsedFrame['description'] = $frame_description; $parsedFrame['mime'] = $frame_mimetype; $parsedFrame['logo'] = $frame_sellerlogo; unset($parsedFrame['data']); @@ -1708,7 +1941,7 @@ class getid3_id3v2 $frame_offset += 2; $parsedFrame['bitsperpoint'] = ord(substr($parsedFrame['data'], $frame_offset++, 1)); $frame_bytesperpoint = ceil($parsedFrame['bitsperpoint'] / 8); - for ($i = 0; $i < $frame_indexpoints; $i++) { + for ($i = 0; $i < $parsedFrame['indexpoints']; $i++) { $parsedFrame['indexes'][$i] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesperpoint)); $frame_offset += $frame_bytesperpoint; } @@ -1729,18 +1962,14 @@ class getid3_id3v2 $frame_offset = 0; $parsedFrame['peakamplitude'] = getid3_lib::BigEndian2Float(substr($parsedFrame['data'], $frame_offset, 4)); $frame_offset += 4; - $rg_track_adjustment = getid3_lib::Dec2Bin(substr($parsedFrame['data'], $frame_offset, 2)); - $frame_offset += 2; - $rg_album_adjustment = getid3_lib::Dec2Bin(substr($parsedFrame['data'], $frame_offset, 2)); - $frame_offset += 2; - $parsedFrame['raw']['track']['name'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 0, 3)); - $parsedFrame['raw']['track']['originator'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 3, 3)); - $parsedFrame['raw']['track']['signbit'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 6, 1)); - $parsedFrame['raw']['track']['adjustment'] = getid3_lib::Bin2Dec(substr($rg_track_adjustment, 7, 9)); - $parsedFrame['raw']['album']['name'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 0, 3)); - $parsedFrame['raw']['album']['originator'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 3, 3)); - $parsedFrame['raw']['album']['signbit'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 6, 1)); - $parsedFrame['raw']['album']['adjustment'] = getid3_lib::Bin2Dec(substr($rg_album_adjustment, 7, 9)); + foreach (array('track','album') as $rgad_entry_type) { + $rg_adjustment_word = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); + $frame_offset += 2; + $parsedFrame['raw'][$rgad_entry_type]['name'] = ($rg_adjustment_word & 0xE000) >> 13; + $parsedFrame['raw'][$rgad_entry_type]['originator'] = ($rg_adjustment_word & 0x1C00) >> 10; + $parsedFrame['raw'][$rgad_entry_type]['signbit'] = ($rg_adjustment_word & 0x0200) >> 9; + $parsedFrame['raw'][$rgad_entry_type]['adjustment'] = ($rg_adjustment_word & 0x0100); + } $parsedFrame['track']['name'] = getid3_lib::RGADnameLookup($parsedFrame['raw']['track']['name']); $parsedFrame['track']['originator'] = getid3_lib::RGADoriginatorLookup($parsedFrame['raw']['track']['originator']); $parsedFrame['track']['adjustment'] = getid3_lib::RGADadjustmentLookup($parsedFrame['raw']['track']['adjustment'], $parsedFrame['raw']['track']['signbit']); @@ -1748,25 +1977,314 @@ class getid3_id3v2 $parsedFrame['album']['originator'] = getid3_lib::RGADoriginatorLookup($parsedFrame['raw']['album']['originator']); $parsedFrame['album']['adjustment'] = getid3_lib::RGADadjustmentLookup($parsedFrame['raw']['album']['adjustment'], $parsedFrame['raw']['album']['signbit']); - $ThisFileInfo['replay_gain']['track']['peak'] = $parsedFrame['peakamplitude']; - $ThisFileInfo['replay_gain']['track']['originator'] = $parsedFrame['track']['originator']; - $ThisFileInfo['replay_gain']['track']['adjustment'] = $parsedFrame['track']['adjustment']; - $ThisFileInfo['replay_gain']['album']['originator'] = $parsedFrame['album']['originator']; - $ThisFileInfo['replay_gain']['album']['adjustment'] = $parsedFrame['album']['adjustment']; + $info['replay_gain']['track']['peak'] = $parsedFrame['peakamplitude']; + $info['replay_gain']['track']['originator'] = $parsedFrame['track']['originator']; + $info['replay_gain']['track']['adjustment'] = $parsedFrame['track']['adjustment']; + $info['replay_gain']['album']['originator'] = $parsedFrame['album']['originator']; + $info['replay_gain']['album']['adjustment'] = $parsedFrame['album']['adjustment']; unset($parsedFrame['data']); + } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'CHAP')) { // CHAP Chapters frame (ID3v2.3+ only) + // http://id3.org/id3v2-chapters-1.0 + // (10 bytes) + // Element ID $00 + // Start time $xx xx xx xx + // End time $xx xx xx xx + // Start offset $xx xx xx xx + // End offset $xx xx xx xx + // + + $frame_offset = 0; + @list($parsedFrame['element_id']) = explode("\x00", $parsedFrame['data'], 2); + $frame_offset += strlen($parsedFrame['element_id']."\x00"); + $parsedFrame['time_begin'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + $frame_offset += 4; + $parsedFrame['time_end'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + $frame_offset += 4; + if (substr($parsedFrame['data'], $frame_offset, 4) != "\xFF\xFF\xFF\xFF") { + // "If these bytes are all set to 0xFF then the value should be ignored and the start time value should be utilized." + $parsedFrame['offset_begin'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + } + $frame_offset += 4; + if (substr($parsedFrame['data'], $frame_offset, 4) != "\xFF\xFF\xFF\xFF") { + // "If these bytes are all set to 0xFF then the value should be ignored and the start time value should be utilized." + $parsedFrame['offset_end'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + } + $frame_offset += 4; + + if ($frame_offset < strlen($parsedFrame['data'])) { + $parsedFrame['subframes'] = array(); + while ($frame_offset < strlen($parsedFrame['data'])) { + // + $subframe = array(); + $subframe['name'] = substr($parsedFrame['data'], $frame_offset, 4); + $frame_offset += 4; + $subframe['size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + $frame_offset += 4; + $subframe['flags_raw'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); + $frame_offset += 2; + if ($subframe['size'] > (strlen($parsedFrame['data']) - $frame_offset)) { + $this->warning('CHAP subframe "'.$subframe['name'].'" at frame offset '.$frame_offset.' claims to be "'.$subframe['size'].'" bytes, which is more than the available data ('.(strlen($parsedFrame['data']) - $frame_offset).' bytes)'); + break; + } + $subframe_rawdata = substr($parsedFrame['data'], $frame_offset, $subframe['size']); + $frame_offset += $subframe['size']; + + $subframe['encodingid'] = ord(substr($subframe_rawdata, 0, 1)); + $subframe['text'] = substr($subframe_rawdata, 1); + $subframe['encoding'] = $this->TextEncodingNameLookup($subframe['encodingid']); + $encoding_converted_text = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe['text'])); + switch (substr($encoding_converted_text, 0, 2)) { + case "\xFF\xFE": + case "\xFE\xFF": + switch (strtoupper($info['id3v2']['encoding'])) { + case 'ISO-8859-1': + case 'UTF-8': + $encoding_converted_text = substr($encoding_converted_text, 2); + // remove unwanted byte-order-marks + break; + default: + // ignore + break; + } + break; + default: + // do not remove BOM + break; + } + + switch ($subframe['name']) { + case 'TIT2': + $parsedFrame['chapter_name'] = $encoding_converted_text; + $parsedFrame['subframes'][] = $subframe; + break; + case 'TIT3': + $parsedFrame['chapter_description'] = $encoding_converted_text; + $parsedFrame['subframes'][] = $subframe; + break; + case 'WXXX': + @list($subframe['chapter_url_description'], $subframe['chapter_url']) = explode("\x00", $encoding_converted_text, 2); + $parsedFrame['chapter_url'][$subframe['chapter_url_description']] = $subframe['chapter_url']; + $parsedFrame['subframes'][] = $subframe; + break; + case 'APIC': + if (preg_match('#^([^\\x00]+)*\\x00(.)([^\\x00]+)*\\x00(.+)$#s', $subframe['text'], $matches)) { + list($dummy, $subframe_apic_mime, $subframe_apic_picturetype, $subframe_apic_description, $subframe_apic_picturedata) = $matches; + $subframe['image_mime'] = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe_apic_mime)); + $subframe['picture_type'] = $this->APICPictureTypeLookup($subframe_apic_picturetype); + $subframe['description'] = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe_apic_description)); + if (strlen($this->TextEncodingTerminatorLookup($subframe['encoding'])) == 2) { + // the null terminator between "description" and "picture data" could be either 1 byte (ISO-8859-1, UTF-8) or two bytes (UTF-16) + // the above regex assumes one byte, if it's actually two then strip the second one here + $subframe_apic_picturedata = substr($subframe_apic_picturedata, 1); + } + $subframe['data'] = $subframe_apic_picturedata; + unset($dummy, $subframe_apic_mime, $subframe_apic_picturetype, $subframe_apic_description, $subframe_apic_picturedata); + unset($subframe['text'], $parsedFrame['text']); + $parsedFrame['subframes'][] = $subframe; + $parsedFrame['picture_present'] = true; + } else { + $this->warning('ID3v2.CHAP subframe #'.(count($parsedFrame['subframes']) + 1).' "'.$subframe['name'].'" not in expected format'); + } + break; + default: + $this->warning('ID3v2.CHAP subframe "'.$subframe['name'].'" not handled (supported: TIT2, TIT3, WXXX, APIC)'); + break; + } + } + unset($subframe_rawdata, $subframe, $encoding_converted_text); + unset($parsedFrame['data']); // debatable whether this this be here, without it the returned structure may contain a large amount of duplicate data if chapters contain APIC + } + + $id3v2_chapter_entry = array(); + foreach (array('id', 'time_begin', 'time_end', 'offset_begin', 'offset_end', 'chapter_name', 'chapter_description', 'chapter_url', 'picture_present') as $id3v2_chapter_key) { + if (isset($parsedFrame[$id3v2_chapter_key])) { + $id3v2_chapter_entry[$id3v2_chapter_key] = $parsedFrame[$id3v2_chapter_key]; + } + } + if (!isset($info['id3v2']['chapters'])) { + $info['id3v2']['chapters'] = array(); + } + $info['id3v2']['chapters'][] = $id3v2_chapter_entry; + unset($id3v2_chapter_entry, $id3v2_chapter_key); + + + } elseif (($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'CTOC')) { // CTOC Chapters Table Of Contents frame (ID3v2.3+ only) + // http://id3.org/id3v2-chapters-1.0 + // (10 bytes) + // Element ID $00 + // CTOC flags %xx + // Entry count $xx + // Child Element ID $00 /* zero or more child CHAP or CTOC entries */ + // + + $frame_offset = 0; + @list($parsedFrame['element_id']) = explode("\x00", $parsedFrame['data'], 2); + $frame_offset += strlen($parsedFrame['element_id']."\x00"); + $ctoc_flags_raw = ord(substr($parsedFrame['data'], $frame_offset, 1)); + $frame_offset += 1; + $parsedFrame['entry_count'] = ord(substr($parsedFrame['data'], $frame_offset, 1)); + $frame_offset += 1; + + $terminator_position = null; + for ($i = 0; $i < $parsedFrame['entry_count']; $i++) { + $terminator_position = strpos($parsedFrame['data'], "\x00", $frame_offset); + $parsedFrame['child_element_ids'][$i] = substr($parsedFrame['data'], $frame_offset, $terminator_position - $frame_offset); + $frame_offset = $terminator_position + 1; + } + + $parsedFrame['ctoc_flags']['ordered'] = (bool) ($ctoc_flags_raw & 0x01); + $parsedFrame['ctoc_flags']['top_level'] = (bool) ($ctoc_flags_raw & 0x03); + + unset($ctoc_flags_raw, $terminator_position); + + if ($frame_offset < strlen($parsedFrame['data'])) { + $parsedFrame['subframes'] = array(); + while ($frame_offset < strlen($parsedFrame['data'])) { + // + $subframe = array(); + $subframe['name'] = substr($parsedFrame['data'], $frame_offset, 4); + $frame_offset += 4; + $subframe['size'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4)); + $frame_offset += 4; + $subframe['flags_raw'] = getid3_lib::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2)); + $frame_offset += 2; + if ($subframe['size'] > (strlen($parsedFrame['data']) - $frame_offset)) { + $this->warning('CTOS subframe "'.$subframe['name'].'" at frame offset '.$frame_offset.' claims to be "'.$subframe['size'].'" bytes, which is more than the available data ('.(strlen($parsedFrame['data']) - $frame_offset).' bytes)'); + break; + } + $subframe_rawdata = substr($parsedFrame['data'], $frame_offset, $subframe['size']); + $frame_offset += $subframe['size']; + + $subframe['encodingid'] = ord(substr($subframe_rawdata, 0, 1)); + $subframe['text'] = substr($subframe_rawdata, 1); + $subframe['encoding'] = $this->TextEncodingNameLookup($subframe['encodingid']); + $encoding_converted_text = trim(getid3_lib::iconv_fallback($subframe['encoding'], $info['encoding'], $subframe['text']));; + switch (substr($encoding_converted_text, 0, 2)) { + case "\xFF\xFE": + case "\xFE\xFF": + switch (strtoupper($info['id3v2']['encoding'])) { + case 'ISO-8859-1': + case 'UTF-8': + $encoding_converted_text = substr($encoding_converted_text, 2); + // remove unwanted byte-order-marks + break; + default: + // ignore + break; + } + break; + default: + // do not remove BOM + break; + } + + if (($subframe['name'] == 'TIT2') || ($subframe['name'] == 'TIT3')) { + if ($subframe['name'] == 'TIT2') { + $parsedFrame['toc_name'] = $encoding_converted_text; + } elseif ($subframe['name'] == 'TIT3') { + $parsedFrame['toc_description'] = $encoding_converted_text; + } + $parsedFrame['subframes'][] = $subframe; + } else { + $this->warning('ID3v2.CTOC subframe "'.$subframe['name'].'" not handled (only TIT2 and TIT3)'); + } + } + unset($subframe_rawdata, $subframe, $encoding_converted_text); + } + } return true; } - - function DeUnsynchronise($data) { + /** + * @param string $data + * + * @return string + */ + public function DeUnsynchronise($data) { return str_replace("\xFF\x00", "\xFF", $data); } - function LookupCurrencyUnits($currencyid) { + /** + * @param int $index + * + * @return string + */ + public function LookupExtendedHeaderRestrictionsTagSizeLimits($index) { + static $LookupExtendedHeaderRestrictionsTagSizeLimits = array( + 0x00 => 'No more than 128 frames and 1 MB total tag size', + 0x01 => 'No more than 64 frames and 128 KB total tag size', + 0x02 => 'No more than 32 frames and 40 KB total tag size', + 0x03 => 'No more than 32 frames and 4 KB total tag size', + ); + return (isset($LookupExtendedHeaderRestrictionsTagSizeLimits[$index]) ? $LookupExtendedHeaderRestrictionsTagSizeLimits[$index] : ''); + } + + /** + * @param int $index + * + * @return string + */ + public function LookupExtendedHeaderRestrictionsTextEncodings($index) { + static $LookupExtendedHeaderRestrictionsTextEncodings = array( + 0x00 => 'No restrictions', + 0x01 => 'Strings are only encoded with ISO-8859-1 or UTF-8', + ); + return (isset($LookupExtendedHeaderRestrictionsTextEncodings[$index]) ? $LookupExtendedHeaderRestrictionsTextEncodings[$index] : ''); + } + + /** + * @param int $index + * + * @return string + */ + public function LookupExtendedHeaderRestrictionsTextFieldSize($index) { + static $LookupExtendedHeaderRestrictionsTextFieldSize = array( + 0x00 => 'No restrictions', + 0x01 => 'No string is longer than 1024 characters', + 0x02 => 'No string is longer than 128 characters', + 0x03 => 'No string is longer than 30 characters', + ); + return (isset($LookupExtendedHeaderRestrictionsTextFieldSize[$index]) ? $LookupExtendedHeaderRestrictionsTextFieldSize[$index] : ''); + } + + /** + * @param int $index + * + * @return string + */ + public function LookupExtendedHeaderRestrictionsImageEncoding($index) { + static $LookupExtendedHeaderRestrictionsImageEncoding = array( + 0x00 => 'No restrictions', + 0x01 => 'Images are encoded only with PNG or JPEG', + ); + return (isset($LookupExtendedHeaderRestrictionsImageEncoding[$index]) ? $LookupExtendedHeaderRestrictionsImageEncoding[$index] : ''); + } + + /** + * @param int $index + * + * @return string + */ + public function LookupExtendedHeaderRestrictionsImageSizeSize($index) { + static $LookupExtendedHeaderRestrictionsImageSizeSize = array( + 0x00 => 'No restrictions', + 0x01 => 'All images are 256x256 pixels or smaller', + 0x02 => 'All images are 64x64 pixels or smaller', + 0x03 => 'All images are exactly 64x64 pixels, unless required otherwise', + ); + return (isset($LookupExtendedHeaderRestrictionsImageSizeSize[$index]) ? $LookupExtendedHeaderRestrictionsImageSizeSize[$index] : ''); + } + + /** + * @param string $currencyid + * + * @return string + */ + public function LookupCurrencyUnits($currencyid) { $begin = __LINE__; @@ -1928,7 +2446,8 @@ class getid3_id3v2 TMM Manats TND Dinars TOP Pa'anga - TRL Liras + TRL Liras (old) + TRY Liras TTD Dollars TVD Tuvalu Dollars TWD New Dollars @@ -1962,8 +2481,12 @@ class getid3_id3v2 return getid3_lib::EmbeddedLookup($currencyid, $begin, __LINE__, __FILE__, 'id3v2-currency-units'); } - - function LookupCurrencyCountry($currencyid) { + /** + * @param string $currencyid + * + * @return string + */ + public function LookupCurrencyCountry($currencyid) { $begin = __LINE__; @@ -2115,7 +2638,7 @@ class getid3_id3v2 SOS Somalia SPL Seborga SRG Suriname - STD São Tome and Principe + STD São Tome and Principe SVC El Salvador SYP Syria SZL Swaziland @@ -2125,6 +2648,7 @@ class getid3_id3v2 TND Tunisia TOP Tonga TRL Turkey + TRY Turkey TTD Trinidad and Tobago TVD Tuvalu TWD Taiwan @@ -2139,13 +2663,13 @@ class getid3_id3v2 VND Viet Nam VUV Vanuatu WST Samoa - XAF Communauté Financière Africaine + XAF Communauté Financière Africaine XAG Silver XAU Gold XCD East Caribbean XDR International Monetary Fund XPD Palladium - XPF Comptoirs Français du Pacifique + XPF Comptoirs Français du Pacifique XPT Platinum YER Yemen YUM Yugoslavia @@ -2158,9 +2682,13 @@ class getid3_id3v2 return getid3_lib::EmbeddedLookup($currencyid, $begin, __LINE__, __FILE__, 'id3v2-currency-country'); } - - - static function LanguageLookup($languagecode, $casesensitive=false) { + /** + * @param string $languagecode + * @param bool $casesensitive + * + * @return string + */ + public static function LanguageLookup($languagecode, $casesensitive=false) { if (!$casesensitive) { $languagecode = strtolower($languagecode); @@ -2589,7 +3117,7 @@ class getid3_id3v2 vai Vai ven Venda vie Vietnamese - vol Volapük + vol Volapük vot Votic wak Wakashan Languages wal Walamo @@ -2615,8 +3143,12 @@ class getid3_id3v2 return getid3_lib::EmbeddedLookup($languagecode, $begin, __LINE__, __FILE__, 'id3v2-languagecode'); } - - static function ETCOEventLookup($index) { + /** + * @param int $index + * + * @return string + */ + public static function ETCOEventLookup($index) { if (($index >= 0x17) && ($index <= 0xDF)) { return 'reserved for future use'; } @@ -2659,7 +3191,12 @@ class getid3_id3v2 return (isset($EventLookup[$index]) ? $EventLookup[$index] : ''); } - static function SYTLContentTypeLookup($index) { + /** + * @param int $index + * + * @return string + */ + public static function SYTLContentTypeLookup($index) { static $SYTLContentTypeLookup = array( 0x00 => 'other', 0x01 => 'lyrics', @@ -2675,7 +3212,13 @@ class getid3_id3v2 return (isset($SYTLContentTypeLookup[$index]) ? $SYTLContentTypeLookup[$index] : ''); } - static function APICPictureTypeLookup($index, $returnarray=false) { + /** + * @param int $index + * @param bool $returnarray + * + * @return array|string + */ + public static function APICPictureTypeLookup($index, $returnarray=false) { static $APICPictureTypeLookup = array( 0x00 => 'Other', 0x01 => '32x32 pixels \'file icon\' (PNG only)', @@ -2705,7 +3248,12 @@ class getid3_id3v2 return (isset($APICPictureTypeLookup[$index]) ? $APICPictureTypeLookup[$index] : ''); } - static function COMRReceivedAsLookup($index) { + /** + * @param int $index + * + * @return string + */ + public static function COMRReceivedAsLookup($index) { static $COMRReceivedAsLookup = array( 0x00 => 'Other', 0x01 => 'Standard CD album with other songs', @@ -2721,7 +3269,12 @@ class getid3_id3v2 return (isset($COMRReceivedAsLookup[$index]) ? $COMRReceivedAsLookup[$index] : ''); } - static function RVA2ChannelTypeLookup($index) { + /** + * @param int $index + * + * @return string + */ + public static function RVA2ChannelTypeLookup($index) { static $RVA2ChannelTypeLookup = array( 0x00 => 'Other', 0x01 => 'Master volume', @@ -2737,7 +3290,12 @@ class getid3_id3v2 return (isset($RVA2ChannelTypeLookup[$index]) ? $RVA2ChannelTypeLookup[$index] : ''); } - static function FrameNameLongLookup($framename) { + /** + * @param string $framename + * + * @return string + */ + public static function FrameNameLongLookup($framename) { $begin = __LINE__; @@ -2888,7 +3446,7 @@ class getid3_id3v2 TYER Year UFI Unique file identifier UFID Unique file identifier - ULT Unsychronised lyric/text transcription + ULT Unsynchronised lyric/text transcription USER Terms of use USLT Unsynchronised lyric/text transcription WAF Official audio file webpage @@ -2920,8 +3478,12 @@ class getid3_id3v2 // from http://privatewww.essex.ac.uk/~djmrob/replaygain/file_format_id3v2.html } - - static function FrameNameShortLookup($framename) { + /** + * @param string $framename + * + * @return string + */ + public static function FrameNameShortLookup($framename) { $begin = __LINE__; @@ -2932,8 +3494,8 @@ class getid3_id3v2 ASPI audio_seek_point_index BUF recommended_buffer_size CNT play_counter - COM comments - COMM comments + COM comment + COMM comment COMR commercial_frame CRA audio_encryption CRM encrypted_meta_frame @@ -3062,7 +3624,7 @@ class getid3_id3v2 TSSE encoder_settings TSST set_subtitle TST title_sort_order - TT1 description + TT1 content_group_description TT2 title TT3 subtitle TXT lyricist @@ -3072,7 +3634,7 @@ class getid3_id3v2 TYER year UFI unique_file_identifier UFID unique_file_identifier - ULT unsychronised_lyric + ULT unsynchronised_lyric USER terms_of_use USLT unsynchronised_lyric WAF url_file @@ -3100,7 +3662,12 @@ class getid3_id3v2 return getid3_lib::EmbeddedLookup($framename, $begin, __LINE__, __FILE__, 'id3v2-framename_short'); } - static function TextEncodingTerminatorLookup($encoding) { + /** + * @param string $encoding + * + * @return string + */ + public static function TextEncodingTerminatorLookup($encoding) { // http://www.id3.org/id3v2.4.0-structure.txt // Frames that allow different types of text encoding contains a text encoding description byte. Possible encodings: static $TextEncodingTerminatorLookup = array( @@ -3110,10 +3677,15 @@ class getid3_id3v2 3 => "\x00", // $03 UTF-8 encoded Unicode. Terminated with $00. 255 => "\x00\x00" ); - return (isset($TextEncodingTerminatorLookup[$encoding]) ? $TextEncodingTerminatorLookup[$encoding] : ''); + return (isset($TextEncodingTerminatorLookup[$encoding]) ? $TextEncodingTerminatorLookup[$encoding] : "\x00"); } - static function TextEncodingNameLookup($encoding) { + /** + * @param int $encoding + * + * @return string + */ + public static function TextEncodingNameLookup($encoding) { // http://www.id3.org/id3v2.4.0-structure.txt // Frames that allow different types of text encoding contains a text encoding description byte. Possible encodings: static $TextEncodingNameLookup = array( @@ -3126,26 +3698,66 @@ class getid3_id3v2 return (isset($TextEncodingNameLookup[$encoding]) ? $TextEncodingNameLookup[$encoding] : 'ISO-8859-1'); } - static function IsValidID3v2FrameName($framename, $id3v2majorversion) { + /** + * @param string $string + * @param string $terminator + * + * @return string + */ + public static function RemoveStringTerminator($string, $terminator) { + // Null terminator at end of comment string is somewhat ambiguous in the specification, may or may not be implemented by various taggers. Remove terminator only if present. + // https://github.com/JamesHeinrich/getID3/issues/121 + // https://community.mp3tag.de/t/x-trailing-nulls-in-id3v2-comments/19227 + if (substr($string, -strlen($terminator), strlen($terminator)) === $terminator) { + $string = substr($string, 0, -strlen($terminator)); + } + return $string; + } + + /** + * @param string $string + * + * @return string + */ + public static function MakeUTF16emptyStringEmpty($string) { + if (in_array($string, array("\x00", "\x00\x00", "\xFF\xFE", "\xFE\xFF"))) { + // if string only contains a BOM or terminator then make it actually an empty string + $string = ''; + } + return $string; + } + + /** + * @param string $framename + * @param int $id3v2majorversion + * + * @return bool|int + */ + public static function IsValidID3v2FrameName($framename, $id3v2majorversion) { switch ($id3v2majorversion) { case 2: return preg_match('#[A-Z][A-Z0-9]{2}#', $framename); - break; case 3: case 4: return preg_match('#[A-Z][A-Z0-9]{3}#', $framename); - break; } return false; } - static function IsANumber($numberstring, $allowdecimal=false, $allownegative=false) { + /** + * @param string $numberstring + * @param bool $allowdecimal + * @param bool $allownegative + * + * @return bool + */ + public static function IsANumber($numberstring, $allowdecimal=false, $allownegative=false) { for ($i = 0; $i < strlen($numberstring); $i++) { - if ((chr($numberstring{$i}) < chr('0')) || (chr($numberstring{$i}) > chr('9'))) { - if (($numberstring{$i} == '.') && $allowdecimal) { + if ((chr($numberstring[$i]) < chr('0')) || (chr($numberstring[$i]) > chr('9'))) { + if (($numberstring[$i] == '.') && $allowdecimal) { // allowed - } elseif (($numberstring{$i} == '-') && $allownegative && ($i == 0)) { + } elseif (($numberstring[$i] == '-') && $allownegative && ($i == 0)) { // allowed } else { return false; @@ -3155,11 +3767,16 @@ class getid3_id3v2 return true; } - static function IsValidDateStampString($datestamp) { + /** + * @param string $datestamp + * + * @return bool + */ + public static function IsValidDateStampString($datestamp) { if (strlen($datestamp) != 8) { return false; } - if (!$this->IsANumber($datestamp, false)) { + if (!self::IsANumber($datestamp, false)) { return false; } $year = substr($datestamp, 0, 4); @@ -3183,10 +3800,104 @@ class getid3_id3v2 return true; } - static function ID3v2HeaderLength($majorversion) { + /** + * @param int $majorversion + * + * @return int + */ + public static function ID3v2HeaderLength($majorversion) { return (($majorversion == 2) ? 6 : 10); } + /** + * @param string $frame_name + * + * @return string|false + */ + public static function ID3v22iTunesBrokenFrameName($frame_name) { + // iTunes (multiple versions) has been known to write ID3v2.3 style frames + // but use ID3v2.2 frame names, right-padded using either [space] or [null] + // to make them fit in the 4-byte frame name space of the ID3v2.3 frame. + // This function will detect and translate the corrupt frame name into ID3v2.3 standard. + static $ID3v22_iTunes_BrokenFrames = array( + 'BUF' => 'RBUF', // Recommended buffer size + 'CNT' => 'PCNT', // Play counter + 'COM' => 'COMM', // Comments + 'CRA' => 'AENC', // Audio encryption + 'EQU' => 'EQUA', // Equalisation + 'ETC' => 'ETCO', // Event timing codes + 'GEO' => 'GEOB', // General encapsulated object + 'IPL' => 'IPLS', // Involved people list + 'LNK' => 'LINK', // Linked information + 'MCI' => 'MCDI', // Music CD identifier + 'MLL' => 'MLLT', // MPEG location lookup table + 'PIC' => 'APIC', // Attached picture + 'POP' => 'POPM', // Popularimeter + 'REV' => 'RVRB', // Reverb + 'RVA' => 'RVAD', // Relative volume adjustment + 'SLT' => 'SYLT', // Synchronised lyric/text + 'STC' => 'SYTC', // Synchronised tempo codes + 'TAL' => 'TALB', // Album/Movie/Show title + 'TBP' => 'TBPM', // BPM (beats per minute) + 'TCM' => 'TCOM', // Composer + 'TCO' => 'TCON', // Content type + 'TCP' => 'TCMP', // Part of a compilation + 'TCR' => 'TCOP', // Copyright message + 'TDA' => 'TDAT', // Date + 'TDY' => 'TDLY', // Playlist delay + 'TEN' => 'TENC', // Encoded by + 'TFT' => 'TFLT', // File type + 'TIM' => 'TIME', // Time + 'TKE' => 'TKEY', // Initial key + 'TLA' => 'TLAN', // Language(s) + 'TLE' => 'TLEN', // Length + 'TMT' => 'TMED', // Media type + 'TOA' => 'TOPE', // Original artist(s)/performer(s) + 'TOF' => 'TOFN', // Original filename + 'TOL' => 'TOLY', // Original lyricist(s)/text writer(s) + 'TOR' => 'TORY', // Original release year + 'TOT' => 'TOAL', // Original album/movie/show title + 'TP1' => 'TPE1', // Lead performer(s)/Soloist(s) + 'TP2' => 'TPE2', // Band/orchestra/accompaniment + 'TP3' => 'TPE3', // Conductor/performer refinement + 'TP4' => 'TPE4', // Interpreted, remixed, or otherwise modified by + 'TPA' => 'TPOS', // Part of a set + 'TPB' => 'TPUB', // Publisher + 'TRC' => 'TSRC', // ISRC (international standard recording code) + 'TRD' => 'TRDA', // Recording dates + 'TRK' => 'TRCK', // Track number/Position in set + 'TS2' => 'TSO2', // Album-Artist sort order + 'TSA' => 'TSOA', // Album sort order + 'TSC' => 'TSOC', // Composer sort order + 'TSI' => 'TSIZ', // Size + 'TSP' => 'TSOP', // Performer sort order + 'TSS' => 'TSSE', // Software/Hardware and settings used for encoding + 'TST' => 'TSOT', // Title sort order + 'TT1' => 'TIT1', // Content group description + 'TT2' => 'TIT2', // Title/songname/content description + 'TT3' => 'TIT3', // Subtitle/Description refinement + 'TXT' => 'TEXT', // Lyricist/Text writer + 'TXX' => 'TXXX', // User defined text information frame + 'TYE' => 'TYER', // Year + 'UFI' => 'UFID', // Unique file identifier + 'ULT' => 'USLT', // Unsynchronised lyric/text transcription + 'WAF' => 'WOAF', // Official audio file webpage + 'WAR' => 'WOAR', // Official artist/performer webpage + 'WAS' => 'WOAS', // Official audio source webpage + 'WCM' => 'WCOM', // Commercial information + 'WCP' => 'WCOP', // Copyright/Legal information + 'WPB' => 'WPUB', // Publishers official webpage + 'WXX' => 'WXXX', // User defined URL link frame + ); + if (strlen($frame_name) == 4) { + if ((substr($frame_name, 3, 1) == ' ') || (substr($frame_name, 3, 1) == "\x00")) { + if (isset($ID3v22_iTunes_BrokenFrames[substr($frame_name, 0, 3)])) { + return $ID3v22_iTunes_BrokenFrames[substr($frame_name, 0, 3)]; + } + } + } + return false; + } + } -?> diff --git a/serendipity_event_podcast/player/getid3/module.tag.lyrics3.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.lyrics3.php similarity index 55% rename from serendipity_event_podcast/player/getid3/module.tag.lyrics3.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.lyrics3.php index ccd25e55..c8b2cf63 100644 --- a/serendipity_event_podcast/player/getid3/module.tag.lyrics3.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.lyrics3.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// /// // // module.tag.lyrics3.php // @@ -13,21 +14,30 @@ // /// ///////////////////////////////////////////////////////////////// - -class getid3_lyrics3 +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} +class getid3_lyrics3 extends getid3_handler { + /** + * @return bool + */ + public function Analyze() { + $info = &$this->getid3->info; - function getid3_lyrics3(&$fd, &$ThisFileInfo) { // http://www.volweb.cz/str/tags.htm - if (!getid3_lib::intValueSupported($ThisFileInfo['filesize'])) { - $ThisFileInfo['warning'][] = 'Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; + if (!getid3_lib::intValueSupported($info['filesize'])) { + $this->warning('Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'); return false; } - fseek($fd, (0 - 128 - 9 - 6), SEEK_END); // end - ID3v1 - "LYRICSEND" - [Lyrics3size] - $lyrics3_id3v1 = fread($fd, 128 + 9 + 6); - $lyrics3lsz = substr($lyrics3_id3v1, 0, 6); // Lyrics3size + $this->fseek((0 - 128 - 9 - 6), SEEK_END); // end - ID3v1 - "LYRICSEND" - [Lyrics3size] + $lyrics3offset = null; + $lyrics3version = null; + $lyrics3size = null; + $lyrics3_id3v1 = $this->fread(128 + 9 + 6); + $lyrics3lsz = (int) substr($lyrics3_id3v1, 0, 6); // Lyrics3size $lyrics3end = substr($lyrics3_id3v1, 6, 9); // LYRICSEND or LYRICS200 $id3v1tag = substr($lyrics3_id3v1, 15, 128); // ID3v1 @@ -35,7 +45,7 @@ class getid3_lyrics3 // Lyrics3v1, ID3v1, no APE $lyrics3size = 5100; - $lyrics3offset = $ThisFileInfo['filesize'] - 128 - $lyrics3size; + $lyrics3offset = $info['filesize'] - 128 - $lyrics3size; $lyrics3version = 1; } elseif ($lyrics3end == 'LYRICS200') { @@ -43,49 +53,49 @@ class getid3_lyrics3 // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200' $lyrics3size = $lyrics3lsz + 6 + strlen('LYRICS200'); - $lyrics3offset = $ThisFileInfo['filesize'] - 128 - $lyrics3size; + $lyrics3offset = $info['filesize'] - 128 - $lyrics3size; $lyrics3version = 2; } elseif (substr(strrev($lyrics3_id3v1), 0, 9) == strrev('LYRICSEND')) { // Lyrics3v1, no ID3v1, no APE $lyrics3size = 5100; - $lyrics3offset = $ThisFileInfo['filesize'] - $lyrics3size; + $lyrics3offset = $info['filesize'] - $lyrics3size; $lyrics3version = 1; - $lyrics3offset = $ThisFileInfo['filesize'] - $lyrics3size; + $lyrics3offset = $info['filesize'] - $lyrics3size; } elseif (substr(strrev($lyrics3_id3v1), 0, 9) == strrev('LYRICS200')) { // Lyrics3v2, no ID3v1, no APE - $lyrics3size = strrev(substr(strrev($lyrics3_id3v1), 9, 6)) + 6 + strlen('LYRICS200'); // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200' - $lyrics3offset = $ThisFileInfo['filesize'] - $lyrics3size; + $lyrics3size = (int) strrev(substr(strrev($lyrics3_id3v1), 9, 6)) + 6 + strlen('LYRICS200'); // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200' + $lyrics3offset = $info['filesize'] - $lyrics3size; $lyrics3version = 2; } else { - if (isset($ThisFileInfo['ape']['tag_offset_start']) && ($ThisFileInfo['ape']['tag_offset_start'] > 15)) { + if (isset($info['ape']['tag_offset_start']) && ($info['ape']['tag_offset_start'] > 15)) { - fseek($fd, $ThisFileInfo['ape']['tag_offset_start'] - 15, SEEK_SET); - $lyrics3lsz = fread($fd, 6); - $lyrics3end = fread($fd, 9); + $this->fseek($info['ape']['tag_offset_start'] - 15); + $lyrics3lsz = $this->fread(6); + $lyrics3end = $this->fread(9); if ($lyrics3end == 'LYRICSEND') { // Lyrics3v1, APE, maybe ID3v1 $lyrics3size = 5100; - $lyrics3offset = $ThisFileInfo['ape']['tag_offset_start'] - $lyrics3size; - $ThisFileInfo['avdataend'] = $lyrics3offset; + $lyrics3offset = $info['ape']['tag_offset_start'] - $lyrics3size; + $info['avdataend'] = $lyrics3offset; $lyrics3version = 1; - $ThisFileInfo['warning'][] = 'APE tag located after Lyrics3, will probably break Lyrics3 compatability'; + $this->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability'); } elseif ($lyrics3end == 'LYRICS200') { // Lyrics3v2, APE, maybe ID3v1 $lyrics3size = $lyrics3lsz + 6 + strlen('LYRICS200'); // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200' - $lyrics3offset = $ThisFileInfo['ape']['tag_offset_start'] - $lyrics3size; + $lyrics3offset = $info['ape']['tag_offset_start'] - $lyrics3size; $lyrics3version = 2; - $ThisFileInfo['warning'][] = 'APE tag located after Lyrics3, will probably break Lyrics3 compatability'; + $this->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability'); } @@ -93,15 +103,28 @@ class getid3_lyrics3 } - if (isset($lyrics3offset)) { - $ThisFileInfo['avdataend'] = $lyrics3offset; - $this->getLyrics3Data($ThisFileInfo, $fd, $lyrics3offset, $lyrics3version, $lyrics3size); + if (isset($lyrics3offset) && isset($lyrics3version) && isset($lyrics3size)) { + $info['avdataend'] = $lyrics3offset; + $this->getLyrics3Data($lyrics3offset, $lyrics3version, $lyrics3size); - if (!isset($ThisFileInfo['ape'])) { - $GETID3_ERRORARRAY = &$ThisFileInfo['warning']; - if (getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.apetag.php', __FILE__, false)) { - $tag = new getid3_apetag($fd, $ThisFileInfo, $ThisFileInfo['lyrics3']['tag_offset_start']); - unset($tag); + if (!isset($info['ape'])) { + if (isset($info['lyrics3']['tag_offset_start'])) { + $GETID3_ERRORARRAY = &$info['warning']; + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.apetag.php', __FILE__, true); + $getid3_temp = new getID3(); + $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); + $getid3_apetag = new getid3_apetag($getid3_temp); + $getid3_apetag->overrideendoffset = $info['lyrics3']['tag_offset_start']; + $getid3_apetag->Analyze(); + if (!empty($getid3_temp->info['ape'])) { + $info['ape'] = $getid3_temp->info['ape']; + } + if (!empty($getid3_temp->info['replay_gain'])) { + $info['replay_gain'] = $getid3_temp->info['replay_gain']; + } + unset($getid3_temp, $getid3_apetag); + } else { + $this->warning('Lyrics3 and APE tags appear to have become entangled (most likely due to updating the APE tags with a non-Lyrics3-aware tagger)'); } } @@ -110,43 +133,55 @@ class getid3_lyrics3 return true; } - function getLyrics3Data(&$ThisFileInfo, &$fd, $endoffset, $version, $length) { + /** + * @param int $endoffset + * @param int $version + * @param int $length + * + * @return bool + */ + public function getLyrics3Data($endoffset, $version, $length) { // http://www.volweb.cz/str/tags.htm + $info = &$this->getid3->info; + if (!getid3_lib::intValueSupported($endoffset)) { - $ThisFileInfo['warning'][] = 'Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; + $this->warning('Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'); return false; } - fseek($fd, $endoffset, SEEK_SET); + $this->fseek($endoffset); if ($length <= 0) { return false; } - $rawdata = fread($fd, $length); + $rawdata = $this->fread($length); + + $ParsedLyrics3 = array(); + + $ParsedLyrics3['raw']['lyrics3version'] = $version; + $ParsedLyrics3['raw']['lyrics3tagsize'] = $length; + $ParsedLyrics3['tag_offset_start'] = $endoffset; + $ParsedLyrics3['tag_offset_end'] = $endoffset + $length - 1; if (substr($rawdata, 0, 11) != 'LYRICSBEGIN') { if (strpos($rawdata, 'LYRICSBEGIN') !== false) { - $ThisFileInfo['warning'][] = '"LYRICSBEGIN" expected at '.$endoffset.' but actually found at '.($endoffset + strpos($rawdata, 'LYRICSBEGIN')).' - this is invalid for Lyrics3 v'.$version; - $ThisFileInfo['avdataend'] = $endoffset + strpos($rawdata, 'LYRICSBEGIN'); - $ParsedLyrics3['tag_offset_start'] = $ThisFileInfo['avdataend']; + $this->warning('"LYRICSBEGIN" expected at '.$endoffset.' but actually found at '.($endoffset + strpos($rawdata, 'LYRICSBEGIN')).' - this is invalid for Lyrics3 v'.$version); + $info['avdataend'] = $endoffset + strpos($rawdata, 'LYRICSBEGIN'); $rawdata = substr($rawdata, strpos($rawdata, 'LYRICSBEGIN')); $length = strlen($rawdata); + $ParsedLyrics3['tag_offset_start'] = $info['avdataend']; + $ParsedLyrics3['raw']['lyrics3tagsize'] = $length; } else { - $ThisFileInfo['error'][] = '"LYRICSBEGIN" expected at '.$endoffset.' but found "'.substr($rawdata, 0, 11).'" instead'; + $this->error('"LYRICSBEGIN" expected at '.$endoffset.' but found "'.substr($rawdata, 0, 11).'" instead'); return false; } } - $ParsedLyrics3['raw']['lyrics3version'] = $version; - $ParsedLyrics3['raw']['lyrics3tagsize'] = $length; - $ParsedLyrics3['tag_offset_start'] = $endoffset; - $ParsedLyrics3['tag_offset_end'] = $endoffset + $length; - switch ($version) { case 1: @@ -154,7 +189,7 @@ class getid3_lyrics3 $ParsedLyrics3['raw']['LYR'] = trim(substr($rawdata, 11, strlen($rawdata) - 11 - 9)); $this->Lyrics3LyricsTimestampParse($ParsedLyrics3); } else { - $ThisFileInfo['error'][] = '"LYRICSEND" expected at '.(ftell($fd) - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead'; + $this->error('"LYRICSEND" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead'); return false; } break; @@ -202,44 +237,54 @@ class getid3_lyrics3 $this->Lyrics3LyricsTimestampParse($ParsedLyrics3); } } else { - $ThisFileInfo['error'][] = '"LYRICS200" expected at '.(ftell($fd) - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead'; + $this->error('"LYRICS200" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead'); return false; } break; default: - $ThisFileInfo['error'][] = 'Cannot process Lyrics3 version '.$version.' (only v1 and v2)'; + $this->error('Cannot process Lyrics3 version '.$version.' (only v1 and v2)'); return false; - break; } - if (isset($ThisFileInfo['id3v1']['tag_offset_start']) && ($ThisFileInfo['id3v1']['tag_offset_start'] < $ParsedLyrics3['tag_offset_end'])) { - $ThisFileInfo['warning'][] = 'ID3v1 tag information ignored since it appears to be a false synch in Lyrics3 tag data'; - unset($ThisFileInfo['id3v1']); - foreach ($ThisFileInfo['warning'] as $key => $value) { + if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] <= $ParsedLyrics3['tag_offset_end'])) { + $this->warning('ID3v1 tag information ignored since it appears to be a false synch in Lyrics3 tag data'); + unset($info['id3v1']); + foreach ($info['warning'] as $key => $value) { if ($value == 'Some ID3v1 fields do not use NULL characters for padding') { - unset($ThisFileInfo['warning'][$key]); - sort($ThisFileInfo['warning']); + unset($info['warning'][$key]); + sort($info['warning']); break; } } } - $ThisFileInfo['lyrics3'] = $ParsedLyrics3; + $info['lyrics3'] = $ParsedLyrics3; return true; } - function Lyrics3Timestamp2Seconds($rawtimestamp) { + /** + * @param string $rawtimestamp + * + * @return int|false + */ + public function Lyrics3Timestamp2Seconds($rawtimestamp) { if (preg_match('#^\\[([0-9]{2}):([0-9]{2})\\]$#', $rawtimestamp, $regs)) { return (int) (($regs[1] * 60) + $regs[2]); } return false; } - function Lyrics3LyricsTimestampParse(&$Lyrics3data) { + /** + * @param array $Lyrics3data + * + * @return bool + */ + public function Lyrics3LyricsTimestampParse(&$Lyrics3data) { $lyricsarray = explode("\r\n", $Lyrics3data['raw']['LYR']); + $notimestamplyricsarray = array(); foreach ($lyricsarray as $key => $lyricline) { $regs = array(); unset($thislinetimestamps); @@ -268,7 +313,12 @@ class getid3_lyrics3 return true; } - function IntString2Bool($char) { + /** + * @param string $char + * + * @return bool|null + */ + public function IntString2Bool($char) { if ($char == '1') { return true; } elseif ($char == '0') { @@ -277,6 +327,3 @@ class getid3_lyrics3 return null; } } - - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.nikon-nctg.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.nikon-nctg.php new file mode 100644 index 00000000..46e2f21d --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.nikon-nctg.php @@ -0,0 +1,1448 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// module.tag.nikon-nctg.php // +// // +///////////////////////////////////////////////////////////////// + +/** + * Module for analyzing Nikon NCTG metadata in MOV files + * + * @author Pavel Starosek + * @author Phil Harvey + * + * @link https://exiftool.org/TagNames/Nikon.html#NCTG + * @link https://github.com/exiftool/exiftool/blob/master/lib/Image/ExifTool/Nikon.pm + * @link https://leo-van-stee.github.io/ + */ +class getid3_tag_nikon_nctg +{ + const EXIF_TYPE_UINT8 = 0x0001; + const EXIF_TYPE_CHAR = 0x0002; + const EXIF_TYPE_UINT16 = 0x0003; + const EXIF_TYPE_UINT32 = 0x0004; + const EXIF_TYPE_URATIONAL = 0x0005; + const EXIF_TYPE_INT8 = 0x0006; + const EXIF_TYPE_RAW = 0x0007; + const EXIF_TYPE_INT16 = 0x0008; + const EXIF_TYPE_INT32 = 0x0009; + const EXIF_TYPE_RATIONAL = 0x000A; + + protected static $exifTypeSizes = array( + self::EXIF_TYPE_UINT8 => 1, + self::EXIF_TYPE_CHAR => 1, + self::EXIF_TYPE_UINT16 => 2, + self::EXIF_TYPE_UINT32 => 4, + self::EXIF_TYPE_URATIONAL => 8, + self::EXIF_TYPE_INT8 => 1, + self::EXIF_TYPE_RAW => 1, + self::EXIF_TYPE_INT16 => 2, + self::EXIF_TYPE_INT32 => 4, + self::EXIF_TYPE_RATIONAL => 8, + ); + + protected static $exposurePrograms = array( + 0 => 'Not Defined', + 1 => 'Manual', + 2 => 'Program AE', + 3 => 'Aperture-priority AE', + 4 => 'Shutter speed priority AE', + 5 => 'Creative (Slow speed)', + 6 => 'Action (High speed)', + 7 => 'Portrait', + 8 => 'Landscape' + ); + + protected static $meteringModes = array( + 0 => 'Unknown', + 1 => 'Average', + 2 => 'Center-weighted average', + 3 => 'Spot', + 4 => 'Multi-spot', + 5 => 'Multi-segment', + 6 => 'Partial', + 255 => 'Other' + ); + + protected static $cropHiSpeeds = array( + 0 => 'Off', + 1 => '1.3x Crop', + 2 => 'DX Crop', + 3 => '5:4 Crop', + 4 => '3:2 Crop', + 6 => '16:9 Crop', + 8 => '2.7x Crop', + 9 => 'DX Movie Crop', + 10 => '1.3x Movie Crop', + 11 => 'FX Uncropped', + 12 => 'DX Uncropped', + 15 => '1.5x Movie Crop', + 17 => '1:1 Crop' + ); + + protected static $colorSpaces = array( + 1 => 'sRGB', + 2 => 'Adobe RGB' + ); + + protected static $vibrationReductions = array( + 1 => 'On', + 2 => 'Off' + ); + + protected static $VRModes = array( + 0 => 'Normal', + 1 => 'On (1)', + 2 => 'Active', + 3 => 'Sport' + ); + + protected static $activeDLightnings = array( + 0 => 'Off', + 1 => 'Low', + 3 => 'Normal', + 5 => 'High', + 7 => 'Extra High', + 8 => 'Extra High 1', + 9 => 'Extra High 2', + 10 => 'Extra High 3', + 11 => 'Extra High 4', + 65535 => 'Auto' + ); + + protected static $pictureControlDataAdjusts = array( + 0 => 'default', + 1 => 'quick', + 2 => 'full' + ); + + protected static $pictureControlDataFilterEffects = array( + 0x80 => 'off', + 0x81 => 'yellow', + 0x82 => 'orange', + 0x83 => 'red', + 0x84 => 'green', + 0xff => 'n/a' + ); + + protected static $pictureControlDataToningEffects = array( + 0x80 => 'b&w', + 0x81 => 'sepia', + 0x82 => 'cyanotype', + 0x83 => 'red', + 0x84 => 'yellow', + 0x85 => 'green', + 0x86 => 'blue-green', + 0x87 => 'blue', + 0x88 => 'purple-blue', + 0x89 => 'red-purple', + 0xff => 'n/a' + ); + + protected static $isoInfoExpansions = array( + 0x0000 => 'Off', + 0x0101 => 'Hi 0.3', + 0x0102 => 'Hi 0.5', + 0x0103 => 'Hi 0.7', + 0x0104 => 'Hi 1.0', + 0x0105 => 'Hi 1.3', + 0x0106 => 'Hi 1.5', + 0x0107 => 'Hi 1.7', + 0x0108 => 'Hi 2.0', + 0x0109 => 'Hi 2.3', + 0x010a => 'Hi 2.5', + 0x010b => 'Hi 2.7', + 0x010c => 'Hi 3.0', + 0x010d => 'Hi 3.3', + 0x010e => 'Hi 3.5', + 0x010f => 'Hi 3.7', + 0x0110 => 'Hi 4.0', + 0x0111 => 'Hi 4.3', + 0x0112 => 'Hi 4.5', + 0x0113 => 'Hi 4.7', + 0x0114 => 'Hi 5.0', + 0x0201 => 'Lo 0.3', + 0x0202 => 'Lo 0.5', + 0x0203 => 'Lo 0.7', + 0x0204 => 'Lo 1.0', + ); + + protected static $isoInfoExpansions2 = array( + 0x0000 => 'Off', + 0x0101 => 'Hi 0.3', + 0x0102 => 'Hi 0.5', + 0x0103 => 'Hi 0.7', + 0x0104 => 'Hi 1.0', + 0x0105 => 'Hi 1.3', + 0x0106 => 'Hi 1.5', + 0x0107 => 'Hi 1.7', + 0x0108 => 'Hi 2.0', + 0x0201 => 'Lo 0.3', + 0x0202 => 'Lo 0.5', + 0x0203 => 'Lo 0.7', + 0x0204 => 'Lo 1.0', + ); + + protected static $vignetteControls = array( + 0 => 'Off', + 1 => 'Low', + 3 => 'Normal', + 5 => 'High' + ); + + protected static $flashModes = array( + 0 => 'Did Not Fire', + 1 => 'Fired, Manual', + 3 => 'Not Ready', + 7 => 'Fired, External', + 8 => 'Fired, Commander Mode', + 9 => 'Fired, TTL Mode', + 18 => 'LED Light' + ); + + protected static $flashInfoSources = array( + 0 => 'None', + 1 => 'External', + 2 => 'Internal' + ); + + protected static $flashInfoExternalFlashFirmwares = array( + '0 0' => 'n/a', + '1 1' => '1.01 (SB-800 or Metz 58 AF-1)', + '1 3' => '1.03 (SB-800)', + '2 1' => '2.01 (SB-800)', + '2 4' => '2.04 (SB-600)', + '2 5' => '2.05 (SB-600)', + '3 1' => '3.01 (SU-800 Remote Commander)', + '4 1' => '4.01 (SB-400)', + '4 2' => '4.02 (SB-400)', + '4 4' => '4.04 (SB-400)', + '5 1' => '5.01 (SB-900)', + '5 2' => '5.02 (SB-900)', + '6 1' => '6.01 (SB-700)', + '7 1' => '7.01 (SB-910)', + ); + + protected static $flashInfoExternalFlashFlags = array( + 0 => 'Fired', + 2 => 'Bounce Flash', + 4 => 'Wide Flash Adapter', + 5 => 'Dome Diffuser', + ); + + protected static $flashInfoExternalFlashStatuses = array( + 0 => 'Flash Not Attached', + 1 => 'Flash Attached', + ); + + protected static $flashInfoExternalFlashReadyStates = array( + 0 => 'n/a', + 1 => 'Ready', + 6 => 'Not Ready', + ); + + protected static $flashInfoGNDistances = array( + 0 => 0, 19 => '2.8 m', + 1 => '0.1 m', 20 => '3.2 m', + 2 => '0.2 m', 21 => '3.6 m', + 3 => '0.3 m', 22 => '4.0 m', + 4 => '0.4 m', 23 => '4.5 m', + 5 => '0.5 m', 24 => '5.0 m', + 6 => '0.6 m', 25 => '5.6 m', + 7 => '0.7 m', 26 => '6.3 m', + 8 => '0.8 m', 27 => '7.1 m', + 9 => '0.9 m', 28 => '8.0 m', + 10 => '1.0 m', 29 => '9.0 m', + 11 => '1.1 m', 30 => '10.0 m', + 12 => '1.3 m', 31 => '11.0 m', + 13 => '1.4 m', 32 => '13.0 m', + 14 => '1.6 m', 33 => '14.0 m', + 15 => '1.8 m', 34 => '16.0 m', + 16 => '2.0 m', 35 => '18.0 m', + 17 => '2.2 m', 36 => '20.0 m', + 18 => '2.5 m', 255 => 'n/a' + ); + + protected static $flashInfoControlModes = array( + 0x00 => 'Off', + 0x01 => 'iTTL-BL', + 0x02 => 'iTTL', + 0x03 => 'Auto Aperture', + 0x04 => 'Automatic', + 0x05 => 'GN (distance priority)', + 0x06 => 'Manual', + 0x07 => 'Repeating Flash', + ); + + protected static $flashInfoColorFilters = array( + 0 => 'None', + 1 => 'FL-GL1 or SZ-2FL Fluorescent', + 2 => 'FL-GL2', + 9 => 'TN-A1 or SZ-2TN Incandescent', + 10 => 'TN-A2', + 65 => 'Red', + 66 => 'Blue', + 67 => 'Yellow', + 68 => 'Amber', + ); + + protected static $highISONoiseReductions = array( + 0 => 'Off', + 1 => 'Minimal', + 2 => 'Low', + 3 => 'Medium Low', + 4 => 'Normal', + 5 => 'Medium High', + 6 => 'High' + ); + + protected static $AFInfo2ContrastDetectAFChoices = array( + 0 => 'Off', + 1 => 'On', + 2 => 'On (2)' + ); + + protected static $AFInfo2AFAreaModesWithoutContrastDetectAF = array( + 0 => 'Single Area', + 1 => 'Dynamic Area', + 2 => 'Dynamic Area (closest subject)', + 3 => 'Group Dynamic', + 4 => 'Dynamic Area (9 points)', + 5 => 'Dynamic Area (21 points)', + 6 => 'Dynamic Area (51 points)', + 7 => 'Dynamic Area (51 points, 3D-tracking)', + 8 => 'Auto-area', + 9 => 'Dynamic Area (3D-tracking)', + 10 => 'Single Area (wide)', + 11 => 'Dynamic Area (wide)', + 12 => 'Dynamic Area (wide, 3D-tracking)', + 13 => 'Group Area', + 14 => 'Dynamic Area (25 points)', + 15 => 'Dynamic Area (72 points)', + 16 => 'Group Area (HL)', + 17 => 'Group Area (VL)', + 18 => 'Dynamic Area (49 points)', + 128 => 'Single', + 129 => 'Auto (41 points)', + 130 => 'Subject Tracking (41 points)', + 131 => 'Face Priority (41 points)', + 192 => 'Pinpoint', + 193 => 'Single', + 195 => 'Wide (S)', + 196 => 'Wide (L)', + 197 => 'Auto', + ); + + protected static $AFInfo2AFAreaModesWithContrastDetectAF = array( + 0 => 'Contrast-detect', + 1 => 'Contrast-detect (normal area)', + 2 => 'Contrast-detect (wide area)', + 3 => 'Contrast-detect (face priority)', + 4 => 'Contrast-detect (subject tracking)', + 128 => 'Single', + 129 => 'Auto (41 points)', + 130 => 'Subject Tracking (41 points)', + 131 => 'Face Priority (41 points)', + 192 => 'Pinpoint', + 193 => 'Single', + 194 => 'Dynamic', + 195 => 'Wide (S)', + 196 => 'Wide (L)', + 197 => 'Auto', + 198 => 'Auto (People)', + 199 => 'Auto (Animal)', + 200 => 'Normal-area AF', + 201 => 'Wide-area AF', + 202 => 'Face-priority AF', + 203 => 'Subject-tracking AF', + ); + + protected static $AFInfo2PhaseDetectAFChoices = array( + 0 => 'Off', + 1 => 'On (51-point)', + 2 => 'On (11-point)', + 3 => 'On (39-point)', + 4 => 'On (73-point)', + 5 => 'On (5)', + 6 => 'On (105-point)', + 7 => 'On (153-point)', + 8 => 'On (81-point)', + 9 => 'On (105-point)', + ); + + protected static $NikkorZLensIDS = array( + 1 => 'Nikkor Z 24-70mm f/4 S', + 2 => 'Nikkor Z 14-30mm f/4 S', + 4 => 'Nikkor Z 35mm f/1.8 S', + 8 => 'Nikkor Z 58mm f/0.95 S Noct', + 9 => 'Nikkor Z 50mm f/1.8 S', + 11 => 'Nikkor Z DX 16-50mm f/3.5-6.3 VR', + 12 => 'Nikkor Z DX 50-250mm f/4.5-6.3 VR', + 13 => 'Nikkor Z 24-70mm f/2.8 S', + 14 => 'Nikkor Z 85mm f/1.8 S', + 15 => 'Nikkor Z 24mm f/1.8 S', + 16 => 'Nikkor Z 70-200mm f/2.8 VR S', + 17 => 'Nikkor Z 20mm f/1.8 S', + 18 => 'Nikkor Z 24-200mm f/4-6.3 VR', + 21 => 'Nikkor Z 50mm f/1.2 S', + 22 => 'Nikkor Z 24-50mm f/4-6.3', + 23 => 'Nikkor Z 14-24mm f/2.8 S', + ); + + protected static $nikonTextEncodings = array( + 1 => 'UTF-8', + 2 => 'UTF-16' + ); + + /** + * Ref 4 + * + * @var int[][] + */ + protected static $decodeTables = array( + array( + 0xc1,0xbf,0x6d,0x0d,0x59,0xc5,0x13,0x9d,0x83,0x61,0x6b,0x4f,0xc7,0x7f,0x3d,0x3d, + 0x53,0x59,0xe3,0xc7,0xe9,0x2f,0x95,0xa7,0x95,0x1f,0xdf,0x7f,0x2b,0x29,0xc7,0x0d, + 0xdf,0x07,0xef,0x71,0x89,0x3d,0x13,0x3d,0x3b,0x13,0xfb,0x0d,0x89,0xc1,0x65,0x1f, + 0xb3,0x0d,0x6b,0x29,0xe3,0xfb,0xef,0xa3,0x6b,0x47,0x7f,0x95,0x35,0xa7,0x47,0x4f, + 0xc7,0xf1,0x59,0x95,0x35,0x11,0x29,0x61,0xf1,0x3d,0xb3,0x2b,0x0d,0x43,0x89,0xc1, + 0x9d,0x9d,0x89,0x65,0xf1,0xe9,0xdf,0xbf,0x3d,0x7f,0x53,0x97,0xe5,0xe9,0x95,0x17, + 0x1d,0x3d,0x8b,0xfb,0xc7,0xe3,0x67,0xa7,0x07,0xf1,0x71,0xa7,0x53,0xb5,0x29,0x89, + 0xe5,0x2b,0xa7,0x17,0x29,0xe9,0x4f,0xc5,0x65,0x6d,0x6b,0xef,0x0d,0x89,0x49,0x2f, + 0xb3,0x43,0x53,0x65,0x1d,0x49,0xa3,0x13,0x89,0x59,0xef,0x6b,0xef,0x65,0x1d,0x0b, + 0x59,0x13,0xe3,0x4f,0x9d,0xb3,0x29,0x43,0x2b,0x07,0x1d,0x95,0x59,0x59,0x47,0xfb, + 0xe5,0xe9,0x61,0x47,0x2f,0x35,0x7f,0x17,0x7f,0xef,0x7f,0x95,0x95,0x71,0xd3,0xa3, + 0x0b,0x71,0xa3,0xad,0x0b,0x3b,0xb5,0xfb,0xa3,0xbf,0x4f,0x83,0x1d,0xad,0xe9,0x2f, + 0x71,0x65,0xa3,0xe5,0x07,0x35,0x3d,0x0d,0xb5,0xe9,0xe5,0x47,0x3b,0x9d,0xef,0x35, + 0xa3,0xbf,0xb3,0xdf,0x53,0xd3,0x97,0x53,0x49,0x71,0x07,0x35,0x61,0x71,0x2f,0x43, + 0x2f,0x11,0xdf,0x17,0x97,0xfb,0x95,0x3b,0x7f,0x6b,0xd3,0x25,0xbf,0xad,0xc7,0xc5, + 0xc5,0xb5,0x8b,0xef,0x2f,0xd3,0x07,0x6b,0x25,0x49,0x95,0x25,0x49,0x6d,0x71,0xc7 + ), + array( + 0xa7,0xbc,0xc9,0xad,0x91,0xdf,0x85,0xe5,0xd4,0x78,0xd5,0x17,0x46,0x7c,0x29,0x4c, + 0x4d,0x03,0xe9,0x25,0x68,0x11,0x86,0xb3,0xbd,0xf7,0x6f,0x61,0x22,0xa2,0x26,0x34, + 0x2a,0xbe,0x1e,0x46,0x14,0x68,0x9d,0x44,0x18,0xc2,0x40,0xf4,0x7e,0x5f,0x1b,0xad, + 0x0b,0x94,0xb6,0x67,0xb4,0x0b,0xe1,0xea,0x95,0x9c,0x66,0xdc,0xe7,0x5d,0x6c,0x05, + 0xda,0xd5,0xdf,0x7a,0xef,0xf6,0xdb,0x1f,0x82,0x4c,0xc0,0x68,0x47,0xa1,0xbd,0xee, + 0x39,0x50,0x56,0x4a,0xdd,0xdf,0xa5,0xf8,0xc6,0xda,0xca,0x90,0xca,0x01,0x42,0x9d, + 0x8b,0x0c,0x73,0x43,0x75,0x05,0x94,0xde,0x24,0xb3,0x80,0x34,0xe5,0x2c,0xdc,0x9b, + 0x3f,0xca,0x33,0x45,0xd0,0xdb,0x5f,0xf5,0x52,0xc3,0x21,0xda,0xe2,0x22,0x72,0x6b, + 0x3e,0xd0,0x5b,0xa8,0x87,0x8c,0x06,0x5d,0x0f,0xdd,0x09,0x19,0x93,0xd0,0xb9,0xfc, + 0x8b,0x0f,0x84,0x60,0x33,0x1c,0x9b,0x45,0xf1,0xf0,0xa3,0x94,0x3a,0x12,0x77,0x33, + 0x4d,0x44,0x78,0x28,0x3c,0x9e,0xfd,0x65,0x57,0x16,0x94,0x6b,0xfb,0x59,0xd0,0xc8, + 0x22,0x36,0xdb,0xd2,0x63,0x98,0x43,0xa1,0x04,0x87,0x86,0xf7,0xa6,0x26,0xbb,0xd6, + 0x59,0x4d,0xbf,0x6a,0x2e,0xaa,0x2b,0xef,0xe6,0x78,0xb6,0x4e,0xe0,0x2f,0xdc,0x7c, + 0xbe,0x57,0x19,0x32,0x7e,0x2a,0xd0,0xb8,0xba,0x29,0x00,0x3c,0x52,0x7d,0xa8,0x49, + 0x3b,0x2d,0xeb,0x25,0x49,0xfa,0xa3,0xaa,0x39,0xa7,0xc5,0xa7,0x50,0x11,0x36,0xfb, + 0xc6,0x67,0x4a,0xf5,0xa5,0x12,0x65,0x7e,0xb0,0xdf,0xaf,0x4e,0xb3,0x61,0x7f,0x2f + ) + ); + + /** + * @var getID3 + */ + private $getid3; + + public function __construct(getID3 $getid3) + { + $this->getid3 = $getid3; + } + + /** + * Get a copy of all NCTG tags extracted from the video + * + * @param string $atomData + * + * @return array + */ + public function parse($atomData) { + // Nikon-specific QuickTime tags found in the NCDT atom of MOV videos from some Nikon cameras such as the Coolpix S8000 and D5100 + // Data is stored as records of: + // * 4 bytes record type + // * 2 bytes size of data field type: + // 0x0001 = flag / unsigned byte (size field *= 1-byte) + // 0x0002 = char / ascii strings (size field *= 1-byte) + // 0x0003 = DWORD+ / unsigned short (size field *= 2-byte), values are stored CDAB + // 0x0004 = QWORD+ / unsigned long (size field *= 4-byte), values are stored EFGHABCD + // 0x0005 = float / unsigned rational (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together + // 0x0006 = signed byte (size field *= 1-byte) + // 0x0007 = raw bytes (size field *= 1-byte) + // 0x0008 = signed short (size field *= 2-byte), values are stored as CDAB + // 0x0009 = signed long (size field *= 4-byte), values are stored as EFGHABCD + // 0x000A = float / signed rational (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together + // * 2 bytes data size field + // * ? bytes data (string data may be null-padded; datestamp fields are in the format "2011:05:25 20:24:15") + // all integers are stored BigEndian + + $NCTGtagName = array( + 0x00000001 => 'Make', + 0x00000002 => 'Model', + 0x00000003 => 'Software', + 0x00000011 => 'CreateDate', + 0x00000012 => 'DateTimeOriginal', + 0x00000013 => 'FrameCount', + 0x00000016 => 'FrameRate', + 0x00000019 => 'TimeZone', + 0x00000022 => 'FrameWidth', + 0x00000023 => 'FrameHeight', + 0x00000032 => 'AudioChannels', + 0x00000033 => 'AudioBitsPerSample', + 0x00000034 => 'AudioSampleRate', + 0x00001002 => 'NikonDateTime', + 0x00001013 => 'ElectronicVR', + 0x0110829a => 'ExposureTime', + 0x0110829d => 'FNumber', + 0x01108822 => 'ExposureProgram', + 0x01109204 => 'ExposureCompensation', + 0x01109207 => 'MeteringMode', + 0x0110920a => 'FocalLength', // mm + 0x0110a431 => 'SerialNumber', + 0x0110a432 => 'LensInfo', + 0x0110a433 => 'LensMake', + 0x0110a434 => 'LensModel', + 0x0110a435 => 'LensSerialNumber', + 0x01200000 => 'GPSVersionID', + 0x01200001 => 'GPSLatitudeRef', + 0x01200002 => 'GPSLatitude', + 0x01200003 => 'GPSLongitudeRef', + 0x01200004 => 'GPSLongitude', + 0x01200005 => 'GPSAltitudeRef', // 0 = Above Sea Level, 1 = Below Sea Level + 0x01200006 => 'GPSAltitude', + 0x01200007 => 'GPSTimeStamp', + 0x01200008 => 'GPSSatellites', + 0x01200010 => 'GPSImgDirectionRef', // M = Magnetic North, T = True North + 0x01200011 => 'GPSImgDirection', + 0x01200012 => 'GPSMapDatum', + 0x0120001d => 'GPSDateStamp', + 0x02000001 => 'MakerNoteVersion', + 0x02000005 => 'WhiteBalance', + 0x02000007 => 'FocusMode', + 0x0200000b => 'WhiteBalanceFineTune', + 0x0200001b => 'CropHiSpeed', + 0x0200001e => 'ColorSpace', + 0x0200001f => 'VRInfo', + 0x02000022 => 'ActiveDLighting', + 0x02000023 => 'PictureControlData', + 0x02000024 => 'WorldTime', + 0x02000025 => 'ISOInfo', + 0x0200002a => 'VignetteControl', + 0x0200002c => 'UnknownInfo', + 0x02000032 => 'UnknownInfo2', + 0x02000039 => 'LocationInfo', + 0x02000083 => 'LensType', + 0x02000084 => 'Lens', + 0x02000087 => 'FlashMode', + 0x02000098 => 'LensData', + 0x020000a7 => 'ShutterCount', + 0x020000a8 => 'FlashInfo', + 0x020000ab => 'VariProgram', + 0x020000b1 => 'HighISONoiseReduction', + 0x020000b7 => 'AFInfo2', + 0x020000c3 => 'BarometerInfo', + ); + + $firstPassNeededTags = array( + 0x00000002, // Model + 0x0110a431, // SerialNumber + 0x020000a7, // ShutterCount + ); + + $datalength = strlen($atomData); + $parsed = array(); + $model = $serialNumber = $shutterCount = null; + for ($pass = 0; $pass < 2; ++$pass) { + $offset = 0; + $parsed = array(); + $data = null; + while ($offset < $datalength) { + $record_type = getid3_lib::BigEndian2Int(substr($atomData, $offset, 4)); + $offset += 4; + $data_size_type = getid3_lib::BigEndian2Int(substr($atomData, $offset, 2)); + $data_size = static::$exifTypeSizes[$data_size_type]; + $offset += 2; + $data_count = getid3_lib::BigEndian2Int(substr($atomData, $offset, 2)); + $offset += 2; + $data = array(); + + if ($pass === 0 && !in_array($record_type, $firstPassNeededTags, true)) { + $offset += $data_count * $data_size; + continue; + } + + switch ($data_size_type) { + case self::EXIF_TYPE_UINT8: // 0x0001 = flag / unsigned byte (size field *= 1-byte) + for ($i = 0; $i < $data_count; ++$i) { + $data[] = getid3_lib::BigEndian2Int(substr($atomData, $offset + ($i * $data_size), $data_size)); + } + $offset += ($data_count * $data_size); + break; + case self::EXIF_TYPE_CHAR: // 0x0002 = char / ascii strings (size field *= 1-byte) + $data = substr($atomData, $offset, $data_count * $data_size); + $offset += ($data_count * $data_size); + $data = rtrim($data, "\x00"); + break; + case self::EXIF_TYPE_UINT16: // 0x0003 = DWORD+ / unsigned short (size field *= 2-byte), values are stored CDAB + for ($i = 0; $i < $data_count; ++$i) { + $data[] = getid3_lib::BigEndian2Int(substr($atomData, $offset + ($i * $data_size), $data_size)); + } + $offset += ($data_count * $data_size); + break; + case self::EXIF_TYPE_UINT32: // 0x0004 = QWORD+ / unsigned long (size field *= 4-byte), values are stored EFGHABCD + // нужно проверить FrameCount + for ($i = 0; $i < $data_count; ++$i) { + $data[] = getid3_lib::BigEndian2Int(substr($atomData, $offset + ($i * $data_size), $data_size)); + } + $offset += ($data_count * $data_size); + break; + case self::EXIF_TYPE_URATIONAL: // 0x0005 = float / unsigned rational (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together + for ($i = 0; $i < $data_count; ++$i) { + $numerator = getid3_lib::BigEndian2Int(substr($atomData, $offset + ($i * $data_size) + 0, 4)); + $denomninator = getid3_lib::BigEndian2Int(substr($atomData, $offset + ($i * $data_size) + 4, 4)); + if ($denomninator == 0) { + $data[] = false; + } else { + $data[] = (float)$numerator / $denomninator; + } + } + $offset += ($data_size * $data_count); + break; + case self::EXIF_TYPE_INT8: // 0x0006 = bytes / signed byte (size field *= 1-byte) + // NOT TESTED + for ($i = 0; $i < $data_count; ++$i) { + $data[] = getid3_lib::BigEndian2Int(substr($atomData, $offset + ($i * $data_size), $data_size), false, true); + } + $offset += ($data_count * $data_size); + break; + case self::EXIF_TYPE_RAW: // 0x0007 = raw bytes (size field *= 1-byte) + $data = substr($atomData, $offset, $data_count * $data_size); + $offset += ($data_count * $data_size); + break; + case self::EXIF_TYPE_INT16: // 0x0008 = signed short (size field *= 2-byte), values are stored as CDAB + for ($i = 0; $i < $data_count; ++$i) { + $value = getid3_lib::BigEndian2Int(substr($atomData, $offset + ($i * $data_size), $data_size)); + if ($value >= 0x8000) { + $value -= 0x10000; + } + $data[] = $value; + } + $offset += ($data_count * $data_size); + break; + case self::EXIF_TYPE_INT32: // 0x0009 = signed long (size field *= 4-byte), values are stored as EFGHABCD + // NOT TESTED + for ($i = 0; $i < $data_count; ++$i) { + $data = getid3_lib::BigEndian2Int(substr($atomData, $offset + ($i * $data_size), $data_size), false, true); + } + $offset += ($data_count * $data_size); + break; + case self::EXIF_TYPE_RATIONAL: // 0x000A = float / signed rational (size field *= 8-byte), values are stored aaaabbbb where value is aaaa/bbbb; possibly multiple sets of values appended together + // NOT TESTED + for ($i = 0; $i < $data_count; ++$i) { + $numerator = getid3_lib::BigEndian2Int(substr($atomData, $offset + ($i * $data_size) + 0, 4), false, true); + $denomninator = getid3_lib::BigEndian2Int(substr($atomData, $offset + ($i * $data_size) + 4, 4), false, true); + if ($denomninator == 0) { + $data[] = false; + } else { + $data[] = (float)$numerator / $denomninator; + } + } + $offset += ($data_size * $data_count); + if (count($data) == 1) { + $data = $data[0]; + } + break; + default: + $this->getid3->warning('QuicktimeParseNikonNCTG()::unknown $data_size_type: ' . $data_size_type); + break 2; + } + + if (is_array($data) && count($data) === 1) { + $data = $data[0]; + } + + switch ($record_type) { + case 0x00000002: + $model = $data; + break; + case 0x00000013: // FrameCount + if (is_array($data) && count($data) === 2 && $data[1] == 0) { + $data = $data[0]; + } + break; + case 0x00000011: // CreateDate + case 0x00000012: // DateTimeOriginal + case 0x00001002: // NikonDateTime + $data = strtotime($data); + break; + case 0x00001013: // ElectronicVR + $data = (bool) $data; + break; + case 0x0110829a: // ExposureTime + // Print exposure time as a fraction + /** @var float $data */ + if ($data < 0.25001 && $data > 0) { + $data = sprintf("1/%d", intval(0.5 + 1 / $data)); + } + break; + case 0x01109204: // ExposureCompensation + $data = $this->printFraction($data); + break; + case 0x01108822: // ExposureProgram + $data = isset(static::$exposurePrograms[$data]) ? static::$exposurePrograms[$data] : $data; + break; + case 0x01109207: // MeteringMode + $data = isset(static::$meteringModes[$data]) ? static::$meteringModes[$data] : $data; + break; + case 0x0110a431: // SerialNumber + $serialNumber = $this->serialKey($data, $model); + break; + case 0x01200000: // GPSVersionID + $parsed['GPS']['computed']['version'] = 'v'.implode('.', $data); + break; + case 0x01200002: // GPSLatitude + if (is_array($data)) { + $direction_multiplier = ((isset($parsed['GPSLatitudeRef']) && ($parsed['GPSLatitudeRef'] === 'S')) ? -1 : 1); + $parsed['GPS']['computed']['latitude'] = $direction_multiplier * ($data[0] + ($data[1] / 60) + ($data[2] / 3600)); + } + break; + case 0x01200004: // GPSLongitude + if (is_array($data)) { + $direction_multiplier = ((isset($parsed['GPSLongitudeRef']) && ($parsed['GPSLongitudeRef'] === 'W')) ? -1 : 1); + $parsed['GPS']['computed']['longitude'] = $direction_multiplier * ($data[0] + ($data[1] / 60) + ($data[2] / 3600)); + } + break; + case 0x01200006: // GPSAltitude + if (isset($parsed['GPSAltitudeRef'])) { + $direction_multiplier = (!empty($parsed['GPSAltitudeRef']) ? -1 : 1); // 0 = above sea level; 1 = below sea level + $parsed['GPS']['computed']['altitude'] = $direction_multiplier * $data; + } + break; + case 0x0120001d: // GPSDateStamp + if (isset($parsed['GPSTimeStamp']) && is_array($parsed['GPSTimeStamp']) && $data !== '') { + $explodedDate = explode(':', $data); + $parsed['GPS']['computed']['timestamp'] = gmmktime($parsed['GPSTimeStamp'][0], $parsed['GPSTimeStamp'][1], $parsed['GPSTimeStamp'][2], $explodedDate[1], $explodedDate[2], $explodedDate[0]); + } + break; + case 0x02000001: // MakerNoteVersion + $data = ltrim(substr($data, 0, 2) . '.' . substr($data, 2, 2), '0'); + break; + case 0x0200001b: // CropHiSpeed + if (is_array($data) && count($data) === 7) { + $name = isset(static::$cropHiSpeeds[$data[0]]) ? static::$cropHiSpeeds[$data[0]] : sprintf('Unknown (%d)', $data[0]); + $data = array( + 'Name' => $name, + 'OriginalWidth' => $data[1], + 'OriginalHeight' => $data[2], + 'CroppedWidth' => $data[3], + 'CroppedHeight' => $data[4], + 'PixelXPosition' => $data[5], + 'PixelYPosition' => $data[6], + ); + } + break; + case 0x0200001e: // ColorSpace + $data = isset(static::$colorSpaces[$data]) ? static::$colorSpaces[$data] : $data; + break; + case 0x0200001f: // VRInfo + $data = array( + 'VRInfoVersion' => substr($data, 0, 4), + 'VibrationReduction' => isset(static::$vibrationReductions[ord(substr($data, 4, 1))]) + ? static::$vibrationReductions[ord(substr($data, 4, 1))] + : null, + 'VRMode' => static::$VRModes[ord(substr($data, 6, 1))], + ); + break; + case 0x02000022: // ActiveDLighting + $data = isset(static::$activeDLightnings[$data]) ? static::$activeDLightnings[$data] : $data; + break; + case 0x02000023: // PictureControlData + switch (substr($data, 0, 2)) { + case '01': + $data = array( + 'PictureControlVersion' => substr($data, 0, 4), + 'PictureControlName' => rtrim(substr($data, 4, 20), "\x00"), + 'PictureControlBase' => rtrim(substr($data, 24, 20), "\x00"), + //'?' => substr($data, 44, 4), + 'PictureControlAdjust' => static::$pictureControlDataAdjusts[ord(substr($data, 48, 1))], + 'PictureControlQuickAdjust' => $this->printPC(ord(substr($data, 49, 1)) - 0x80), + 'Sharpness' => $this->printPC(ord(substr($data, 50, 1)) - 0x80, 'No Sharpening', '%d'), + 'Contrast' => $this->printPC(ord(substr($data, 51, 1)) - 0x80), + 'Brightness' => $this->printPC(ord(substr($data, 52, 1)) - 0x80), + 'Saturation' => $this->printPC(ord(substr($data, 53, 1)) - 0x80), + 'HueAdjustment' => $this->printPC(ord(substr($data, 54, 1)) - 0x80, 'None'), + 'FilterEffect' => static::$pictureControlDataFilterEffects[ord(substr($data, 55, 1))], + 'ToningEffect' => static::$pictureControlDataToningEffects[ord(substr($data, 56, 1))], + 'ToningSaturation' => $this->printPC(ord(substr($data, 57, 1)) - 0x80), + ); + break; + case '02': + $data = array( + 'PictureControlVersion' => substr($data, 0, 4), + 'PictureControlName' => rtrim(substr($data, 4, 20), "\x00"), + 'PictureControlBase' => rtrim(substr($data, 24, 20), "\x00"), + //'?' => substr($data, 44, 4), + 'PictureControlAdjust' => static::$pictureControlDataAdjusts[ord(substr($data, 48, 1))], + 'PictureControlQuickAdjust' => $this->printPC(ord(substr($data, 49, 1)) - 0x80), + 'Sharpness' => $this->printPC(ord(substr($data, 51, 1)) - 0x80, 'None', '%.2f', 4), + 'Clarity' => $this->printPC(ord(substr($data, 53, 1)) - 0x80, 'None', '%.2f', 4), + 'Contrast' => $this->printPC(ord(substr($data, 55, 1)) - 0x80, 'None', '%.2f', 4), + 'Brightness' => $this->printPC(ord(substr($data, 57, 1)) - 0x80, 'Normal', '%.2f', 4), + 'Saturation' => $this->printPC(ord(substr($data, 59, 1)) - 0x80, 'None', '%.2f', 4), + 'Hue' => $this->printPC(ord(substr($data, 61, 1)) - 0x80, 'None', '%.2f', 4), + 'FilterEffect' => static::$pictureControlDataFilterEffects[ord(substr($data, 63, 1))], + 'ToningEffect' => static::$pictureControlDataToningEffects[ord(substr($data, 64, 1))], + 'ToningSaturation' => $this->printPC(ord(substr($data, 65, 1)) - 0x80, 'None', '%.2f', 4), + ); + break; + case '03': + $data = array( + 'PictureControlVersion' => substr($data, 0, 4), + 'PictureControlName' => rtrim(substr($data, 8, 20), "\x00"), + 'PictureControlBase' => rtrim(substr($data, 28, 20), "\x00"), + 'PictureControlAdjust' => static::$pictureControlDataAdjusts[ord(substr($data, 54, 1))], + 'PictureControlQuickAdjust' => $this->printPC(ord(substr($data, 55, 1)) - 0x80), + 'Sharpness' => $this->printPC(ord(substr($data, 57, 1)) - 0x80, 'None', '%.2f', 4), + 'MidRangeSharpness' => $this->printPC(ord(substr($data, 59, 1)) - 0x80, 'None', '%.2f', 4), + 'Clarity' => $this->printPC(ord(substr($data, 61, 1)) - 0x80, 'None', '%.2f', 4), + 'Contrast' => $this->printPC(ord(substr($data, 63, 1)) - 0x80, 'None', '%.2f', 4), + 'Brightness' => $this->printPC(ord(substr($data, 65, 1)) - 0x80, 'Normal', '%.2f', 4), + 'Saturation' => $this->printPC(ord(substr($data, 67, 1)) - 0x80, 'None', '%.2f', 4), + 'Hue' => $this->printPC(ord(substr($data, 69, 1)) - 0x80, 'None', '%.2f', 4), + 'FilterEffect' => static::$pictureControlDataFilterEffects[ord(substr($data, 71, 1))], + 'ToningEffect' => static::$pictureControlDataToningEffects[ord(substr($data, 72, 1))], + 'ToningSaturation' => $this->printPC(ord(substr($data, 73, 1)) - 0x80, 'None', '%.2f', 4), + ); + break; + default: + $data = array( + 'PictureControlVersion' => substr($data, 0, 4), + ); + break; + } + break; + case 0x02000024: // WorldTime + // https://exiftool.org/TagNames/Nikon.html#WorldTime + // timezone is stored as offset from GMT in minutes + $timezone = getid3_lib::BigEndian2Int(substr($data, 0, 2)); + if ($timezone & 0x8000) { + $timezone = 0 - (0x10000 - $timezone); + } + $hours = (int)abs($timezone / 60); + $minutes = abs($timezone) - $hours * 60; + + $dst = (bool)getid3_lib::BigEndian2Int(substr($data, 2, 1)); + switch (getid3_lib::BigEndian2Int(substr($data, 3, 1))) { + case 2: + $datedisplayformat = 'D/M/Y'; + break; + case 1: + $datedisplayformat = 'M/D/Y'; + break; + case 0: + default: + $datedisplayformat = 'Y/M/D'; + break; + } + + $data = array( + 'timezone' => sprintf('%s%02d:%02d', $timezone >= 0 ? '+' : '-', $hours, $minutes), + 'dst' => $dst, + 'display' => $datedisplayformat + ); + break; + case 0x02000025: // ISOInfo + $data = array( + 'ISO' => (int)ceil(100 * pow(2, ord(substr($data, 0, 1)) / 12 - 5)), + 'ISOExpansion' => static::$isoInfoExpansions[getid3_lib::BigEndian2Int(substr($data, 4, 2))], + 'ISO2' => (int)ceil(100 * pow(2, ord(substr($data, 6, 1)) / 12 - 5)), + 'ISOExpansion2' => static::$isoInfoExpansions2[getid3_lib::BigEndian2Int(substr($data, 10, 2))] + ); + break; + case 0x0200002a: // VignetteControl + $data = isset(static::$vignetteControls[$data]) ? static::$vignetteControls[$data] : $data; + break; + case 0x0200002c: // UnknownInfo + $data = array( + 'UnknownInfoVersion' => substr($data, 0, 4), + ); + break; + case 0x02000032: // UnknownInfo2 + $data = array( + 'UnknownInfo2Version' => substr($data, 0, 4), + ); + break; + case 0x02000039: // LocationInfo + $encoding = isset(static::$nikonTextEncodings[ord(substr($data, 4, 1))]) + ? static::$nikonTextEncodings[ord(substr($data, 4, 1))] + : null; + $data = array( + 'LocationInfoVersion' => substr($data, 0, 4), + 'TextEncoding' => $encoding, + 'CountryCode' => trim(substr($data, 5, 3), "\x00"), + 'POILevel' => ord(substr($data, 8, 1)), + 'Location' => getid3_lib::iconv_fallback($encoding, $this->getid3->info['encoding'], substr($data, 9, 70)), + ); + break; + case 0x02000083: // LensType + if ($data) { + $decodedBits = array( + '1' => (bool) (($data >> 4) & 1), + 'MF' => (bool) (($data >> 0) & 1), + 'D' => (bool) (($data >> 1) & 1), + 'E' => (bool) (($data >> 6) & 1), + 'G' => (bool) (($data >> 2) & 1), + 'VR' => (bool) (($data >> 3) & 1), + '[7]' => (bool) (($data >> 7) & 1), // AF-P? + '[8]' => (bool) (($data >> 5) & 1) // FT-1? + ); + if ($decodedBits['D'] === true && $decodedBits['G'] === true) { + $decodedBits['D'] = false; + } + } else { + $decodedBits = array('AF' => true); + } + $data = $decodedBits; + break; + case 0x0110a432: // LensInfo + case 0x02000084: // Lens + if (count($data) !== 4) { + break; + } + + $value = $data[0]; + if ($data[1] && $data[1] !== $data[0]) { + $value .= '-' . $data[1]; + } + $value .= 'mm f/' . $data[2]; + if ($data[3] && $data[3] !== $data[2]) { + $value .= '-' . $data[3]; + } + $data = $value; + break; + case 0x02000087: // FlashMode + $data = isset(static::$flashModes[$data]) ? static::$flashModes[$data] : $data; + break; + case 0x02000098: // LensData + $version = substr($data, 0, 4); + + switch ($version) { + case '0100': + $data = array( + 'LensDataVersion' => $version, + 'LensIDNumber' => ord(substr($data, 6, 1)), + 'LensFStops' => ord(substr($data, 7, 1)) / 12, + 'MinFocalLength' => 5 * pow(2, ord(substr($data, 8, 1)) / 24), // mm + 'MaxFocalLength' => 5 * pow(2, ord(substr($data, 9, 1)) / 24), // mm + 'MaxApertureAtMinFocal' => pow(2, ord(substr($data, 10, 1)) / 24), + 'MaxApertureAtMaxFocal' => pow(2, ord(substr($data, 11, 1)) / 24), + 'MCUVersion' => ord(substr($data, 12, 1)), + ); + break; + case '0101': + case '0201': + case '0202': + case '0203': + $isEncrypted = $version !== '0101'; + if ($isEncrypted) { + $data = $this->decryptLensInfo($data, $serialNumber, $shutterCount, 4); + } + + $data = array( + 'LensDataVersion' => $version, + 'ExitPupilPosition' => ord(substr($data, 4, 1)) > 0 ? 2048 / ord(substr($data, 4, 1)) : 0, // mm + 'AFAperture' => pow(2, ord(substr($data, 5, 1)) / 24), + 'FocusPosition' => '0x' . str_pad(strtoupper(dechex(ord(substr($data, 8, 1)))), 2, '0', STR_PAD_LEFT), + 'FocusDistance' => 0.01 * pow(10, ord(substr($data, 9, 1)) / 40), // m + 'FocalLength' => 5 * pow(2, ord(substr($data, 10, 1)) / 24), // mm + 'LensIDNumber' => ord(substr($data, 11, 1)), + 'LensFStops' => ord(substr($data, 12, 1)) / 12, + 'MinFocalLength' => 5 * pow(2, ord(substr($data, 13, 1)) / 24), // mm + 'MaxFocalLength' => 5 * pow(2, ord(substr($data, 14, 1)) / 24), // mm + 'MaxApertureAtMinFocal' => pow(2, ord(substr($data, 15, 1)) / 24), + 'MaxApertureAtMaxFocal' => pow(2, ord(substr($data, 16, 1)) / 24), + 'MCUVersion' => ord(substr($data, 17, 1)), + 'EffectiveMaxAperture' => pow(2, ord(substr($data, 18, 1)) / 24), + ); + break; + case '0204': + $data = $this->decryptLensInfo($data, $serialNumber, $shutterCount, 4); + + $data = array( + 'LensDataVersion' => $version, + 'ExitPupilPosition' => ord(substr($data, 4, 1)) > 0 ? 2048 / ord(substr($data, 4, 1)) : 0, // mm + 'AFAperture' => pow(2, ord(substr($data, 5, 1)) / 24), + 'FocusPosition' => '0x' . str_pad(strtoupper(dechex(ord(substr($data, 8, 1)))), 2, '0', STR_PAD_LEFT), + 'FocusDistance' => 0.01 * pow(10, ord(substr($data, 10, 1)) / 40), // m + 'FocalLength' => 5 * pow(2, ord(substr($data, 11, 1)) / 24), // mm + 'LensIDNumber' => ord(substr($data, 12, 1)), + 'LensFStops' => ord(substr($data, 13, 1)) / 12, + 'MinFocalLength' => 5 * pow(2, ord(substr($data, 14, 1)) / 24), // mm + 'MaxFocalLength' => 5 * pow(2, ord(substr($data, 15, 1)) / 24), // mm + 'MaxApertureAtMinFocal' => pow(2, ord(substr($data, 16, 1)) / 24), + 'MaxApertureAtMaxFocal' => pow(2, ord(substr($data, 17, 1)) / 24), + 'MCUVersion' => ord(substr($data, 18, 1)), + 'EffectiveMaxAperture' => pow(2, ord(substr($data, 19, 1)) / 24), + ); + break; + case '0400': + case '0401': + $data = $this->decryptLensInfo($data, $serialNumber, $shutterCount, 4); + + $data = array( + 'LensDataVersion' => $version, + 'LensModel' => substr($data, 394, 64), + ); + break; + case '0402': + $data = $this->decryptLensInfo($data, $serialNumber, $shutterCount, 4); + + $data = array( + 'LensDataVersion' => $version, + 'LensModel' => substr($data, 395, 64), + ); + break; + case '0403': + $data = $this->decryptLensInfo($data, $serialNumber, $shutterCount, 4); + + $data = array( + 'LensDataVersion' => $version, + 'LensModel' => substr($data, 684, 64), + ); + break; + case '0800': + case '0801': + $data = $this->decryptLensInfo($data, $serialNumber, $shutterCount, 4); + + $newData = array( + 'LensDataVersion' => $version, + ); + + if (!preg_match('#^.\0+#s', substr($data, 3, 17))) { + $newData['ExitPupilPosition'] = ord(substr($data, 4, 1)) > 0 ? 2048 / ord(substr($data, 4, 1)) : 0; // mm + $newData['AFAperture'] = pow(2, ord(substr($data, 5, 1)) / 24); + $newData['FocusPosition'] = '0x' . str_pad(strtoupper(dechex(ord(substr($data, 9, 1)))), 2, '0', STR_PAD_LEFT); + $newData['FocusDistance'] = 0.01 * pow(10, ord(substr($data, 11, 1)) / 40); // m + $newData['FocalLength'] = 5 * pow(2, ord(substr($data, 12, 1)) / 24); // mm + $newData['LensIDNumber'] = ord(substr($data, 13, 1)); + $newData['LensFStops'] = ord(substr($data, 14, 1)) / 12; + $newData['MinFocalLength'] = 5 * pow(2, ord(substr($data, 15, 1)) / 24); // mm + $newData['MaxFocalLength'] = 5 * pow(2, ord(substr($data, 16, 1)) / 24); // mm + $newData['MaxApertureAtMinFocal'] = pow(2, ord(substr($data, 17, 1)) / 24); + $newData['MaxApertureAtMaxFocal'] = pow(2, ord(substr($data, 18, 1)) / 24); + $newData['MCUVersion'] = ord(substr($data, 19, 1)); + $newData['EffectiveMaxAperture'] = pow(2, ord(substr($data, 20, 1)) / 24); + } + + if (!preg_match('#^.\0+#s', substr($data, 47, 17))) { + $newData['LensID'] = static::$NikkorZLensIDS[getid3_lib::LittleEndian2Int(substr($data, 48, 2))]; + $newData['MaxAperture'] = pow(2, (getid3_lib::LittleEndian2Int(substr($data, 54, 2)) / 384 - 1)); + $newData['FNumber'] = pow(2, (getid3_lib::LittleEndian2Int(substr($data, 56, 2)) / 384 - 1)); + $newData['FocalLength'] = getid3_lib::LittleEndian2Int(substr($data, 60, 2)); // mm + $newData['FocusDistance'] = 0.01 * pow(10, ord(substr($data, 79, 1)) / 40); // m + } + + $data = $newData; + break; + default: + // $data = $this->decryptLensInfo($data, $serialNumber, $shutterCount, 4); + + $data = array( + 'LensDataVersion' => $version, + ); + break; + } + break; + case 0x020000a7: // ShutterCount + $shutterCount = $data; + break; + case 0x020000a8: // FlashInfo + $version = substr($data, 0, 4); + + switch ($version) { + case '0100': + case '0101': + $data = array( + 'FlashInfoVersion' => substr($data, 0, 4), + 'FlashSource' => static::$flashInfoSources[ord(substr($data, 4, 1))], + 'ExternalFlashFirmware' => $this->flashFirmwareLookup(ord(substr($data, 6, 1)), ord(substr($data, 7, 1))), + 'ExternalFlashFlags' => $this->externalFlashFlagsLookup(ord(substr($data, 8, 1))), + 'FlashCommanderMode' => (bool)(ord(substr($data, 9, 1)) & 0x80), + 'FlashControlMode' => static::$flashInfoControlModes[ord(substr($data, 9, 1)) & 0x7F], + 'FlashOutput' => (ord(substr($data, 9, 1)) & 0x7F) >= 0x06 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 10, 1)) / 6) * 100)) : 0, + 'FlashCompensation' => $this->printFraction(-getid3_lib::BigEndian2Int(substr($data, 10, 1), false, true) / 6), + 'FlashFocalLength' => ord(substr($data, 11, 1)), // mm + 'RepeatingFlashRate' => ord(substr($data, 12, 1)), // Hz + 'RepeatingFlashCount' => ord(substr($data, 13, 1)), + 'FlashGNDistance' => static::$flashInfoGNDistances[ord(substr($data, 14, 1))], + 'FlashGroupAControlMode' => static::$flashInfoControlModes[ord(substr($data, 15, 1)) & 0x0F], + 'FlashGroupBControlMode' => static::$flashInfoControlModes[ord(substr($data, 16, 1)) & 0x0F], + 'FlashGroupAOutput' => (ord(substr($data, 15, 1)) & 0x0F) >= 0x06 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 17, 1)) / 6) * 100)) : 0, + 'FlashGroupACompensation' => sprintf('%+.1f', -getid3_lib::BigEndian2Int(substr($data, 17, 1), false, true) / 6), + 'FlashGroupBOutput' => (ord(substr($data, 16, 1)) & 0xF0) >= 0x06 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 18, 1)) / 6) * 100)) : 0, + 'FlashGroupBCompensation' => sprintf('%+.1f', -getid3_lib::BigEndian2Int(substr($data, 18, 1), false, true) / 6), + ); + break; + case '0102': + $data = array( + 'FlashInfoVersion' => substr($data, 0, 4), + 'FlashSource' => static::$flashInfoSources[ord(substr($data, 4, 1))], + 'ExternalFlashFirmware' => $this->flashFirmwareLookup(ord(substr($data, 6, 1)), ord(substr($data, 7, 1))), + 'ExternalFlashFlags' => $this->externalFlashFlagsLookup(ord(substr($data, 8, 1))), + 'FlashCommanderMode' => (bool)(ord(substr($data, 9, 1)) & 0x80), + 'FlashControlMode' => static::$flashInfoControlModes[ord(substr($data, 9, 1)) & 0x7F], + 'FlashOutput' => (ord(substr($data, 9, 1)) & 0x7F) >= 0x06 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 10, 1)) / 6) * 100)) : 0, + 'FlashCompensation' => $this->printFraction(-getid3_lib::BigEndian2Int(substr($data, 10, 1), false, true) / 6), + 'FlashFocalLength' => ord(substr($data, 12, 1)), // mm + 'RepeatingFlashRate' => ord(substr($data, 13, 1)), // Hz + 'RepeatingFlashCount' => ord(substr($data, 14, 1)), + 'FlashGNDistance' => static::$flashInfoGNDistances[ord(substr($data, 15, 1))], + 'FlashGroupAControlMode' => static::$flashInfoControlModes[ord(substr($data, 16, 1)) & 0x0F], + 'FlashGroupBControlMode' => static::$flashInfoControlModes[ord(substr($data, 17, 1)) & 0xF0], + 'FlashGroupCControlMode' => static::$flashInfoControlModes[ord(substr($data, 17, 1)) & 0x0F], + 'FlashGroupAOutput' => (ord(substr($data, 16, 1)) & 0x0F) >= 0x06 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 18, 1)) / 6) * 100)) : 0, + 'FlashGroupACompensation' => sprintf('%+.1f', -getid3_lib::BigEndian2Int(substr($data, 18, 1), false, true) / 6), + 'FlashGroupBOutput' => (ord(substr($data, 17, 1)) & 0xF0) >= 0x60 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 19, 1)) / 6) * 100)) : 0, + 'FlashGroupBCompensation' => sprintf('%+.1f', -getid3_lib::BigEndian2Int(substr($data, 19, 1), false, true) / 6), + 'FlashGroupCOutput' => (ord(substr($data, 17, 1)) & 0x0F) >= 0x06 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 20, 1)) / 6) * 100)) : 0, + 'FlashGroupCCompensation' => sprintf('%+.1f', -getid3_lib::BigEndian2Int(substr($data, 20, 1), false, true) / 6), + ); + break; + case '0103': + case '0104': + case '0105': + $data = array( + 'FlashInfoVersion' => substr($data, 0, 4), + 'FlashSource' => static::$flashInfoSources[ord(substr($data, 4, 1))], + 'ExternalFlashFirmware' => $this->flashFirmwareLookup(ord(substr($data, 6, 1)), ord(substr($data, 7, 1))), + 'ExternalFlashFlags' => $this->externalFlashFlagsLookup(ord(substr($data, 8, 1))), + 'FlashCommanderMode' => (bool)(ord(substr($data, 9, 1)) & 0x80), + 'FlashControlMode' => static::$flashInfoControlModes[ord(substr($data, 9, 1)) & 0x7F], + 'FlashOutput' => (ord(substr($data, 9, 1)) & 0x7F) >= 0x06 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 10, 1)) / 6) * 100)) : 0, + 'FlashCompensation' => $this->printFraction(-getid3_lib::BigEndian2Int(substr($data, 10, 1), false, true) / 6), + 'FlashFocalLength' => ord(substr($data, 12, 1)), // mm + 'RepeatingFlashRate' => ord(substr($data, 13, 1)), // Hz + 'RepeatingFlashCount' => ord(substr($data, 14, 1)), + 'FlashGNDistance' => static::$flashInfoGNDistances[ord(substr($data, 15, 1))], + 'FlashColorFilter' => static::$flashInfoColorFilters[ord(substr($data, 16, 1))], + 'FlashGroupAControlMode' => static::$flashInfoControlModes[ord(substr($data, 17, 1)) & 0x0F], + 'FlashGroupBControlMode' => static::$flashInfoControlModes[ord(substr($data, 18, 1)) & 0xF0], + 'FlashGroupCControlMode' => static::$flashInfoControlModes[ord(substr($data, 18, 1)) & 0x0F], + 'FlashGroupAOutput' => (ord(substr($data, 17, 1)) & 0x0F) >= 0x06 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 19, 1)) / 6) * 100)) : 0, + 'FlashGroupACompensation' => sprintf('%+.1f', -getid3_lib::BigEndian2Int(substr($data, 19, 1), false, true) / 6), + 'FlashGroupBOutput' => (ord(substr($data, 18, 1)) & 0xF0) >= 0x60 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 20, 1)) / 6) * 100)) : 0, + 'FlashGroupBCompensation' => sprintf('%+.1f', -getid3_lib::BigEndian2Int(substr($data, 20, 1), false, true) / 6), + 'FlashGroupCOutput' => (ord(substr($data, 18, 1)) & 0x0F) >= 0x06 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 21, 1)) / 6) * 100)) : 0, + 'FlashGroupCCompensation' => sprintf('%+.1f', -getid3_lib::BigEndian2Int(substr($data, 21, 1), false, true) / 6), + 'ExternalFlashCompensation' => $this->printFraction(-getid3_lib::BigEndian2Int(substr($data, 27, 1), false, true) / 6), + 'FlashExposureComp3' => $this->printFraction(-getid3_lib::BigEndian2Int(substr($data, 29, 1), false, true) / 6), + 'FlashExposureComp4' => $this->printFraction(-getid3_lib::BigEndian2Int(substr($data, 39, 1), false, true) / 6), + ); + break; + case '0106': + $data = array( + 'FlashInfoVersion' => substr($data, 0, 4), + 'FlashSource' => static::$flashInfoSources[ord(substr($data, 4, 1))], + 'ExternalFlashFirmware' => $this->flashFirmwareLookup(ord(substr($data, 6, 1)), ord(substr($data, 7, 1))), + 'ExternalFlashFlags' => $this->externalFlashFlagsLookup(ord(substr($data, 8, 1))), + 'FlashCommanderMode' => (bool)(ord(substr($data, 9, 1)) & 0x80), + 'FlashControlMode' => static::$flashInfoControlModes[ord(substr($data, 9, 1)) & 0x7F], + 'FlashFocalLength' => ord(substr($data, 12, 1)), // mm + 'RepeatingFlashRate' => ord(substr($data, 13, 1)), // Hz + 'RepeatingFlashCount' => ord(substr($data, 14, 1)), + 'FlashGNDistance' => self::$flashInfoGNDistances[ord(substr($data, 15, 1))], + 'FlashColorFilter' => static::$flashInfoColorFilters[ord(substr($data, 16, 1))], + 'FlashGroupAControlMode' => static::$flashInfoControlModes[ord(substr($data, 17, 1)) & 0x0F], + 'FlashGroupBControlMode' => static::$flashInfoControlModes[ord(substr($data, 18, 1)) & 0xF0], + 'FlashGroupCControlMode' => static::$flashInfoControlModes[ord(substr($data, 18, 1)) & 0x0F], + 'FlashOutput' => (ord(substr($data, 9, 1)) & 0x7F) >= 0x06 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 39, 1)) / 6) * 100)) : 0, + 'FlashCompensation' => $this->printFraction(-getid3_lib::BigEndian2Int(substr($data, 39, 1), false, true) / 6), + 'FlashGroupAOutput' => (ord(substr($data, 17, 1)) & 0x0F) >= 0x06 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 40, 1)) / 6) * 100)) : 0, + 'FlashGroupACompensation' => sprintf('%+.1f', -getid3_lib::BigEndian2Int(substr($data, 40, 1), false, true) / 6), + 'FlashGroupBOutput' => (ord(substr($data, 18, 1)) & 0xF0) >= 0x60 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 41, 1)) / 6) * 100)) : 0, + 'FlashGroupBCompensation' => sprintf('%+.1f', -getid3_lib::BigEndian2Int(substr($data, 41, 1), false, true) / 6), + 'FlashGroupCOutput' => (ord(substr($data, 18, 1)) & 0x0F) >= 0x06 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 42, 1)) / 6) * 100)) : 0, + 'FlashGroupCCompensation' => sprintf('%+.1f', -getid3_lib::BigEndian2Int(substr($data, 42, 1), false, true) / 6), + ); + break; + case '0107': + case '0108': + $data = array( + 'FlashInfoVersion' => substr($data, 0, 4), + 'FlashSource' => static::$flashInfoSources[ord(substr($data, 4, 1))], + 'ExternalFlashFirmware' => $this->flashFirmwareLookup(ord(substr($data, 6, 1)), ord(substr($data, 7, 1))), + 'ExternalFlashZoomOverride' => (bool)(ord(substr($data, 8, 1)) & 0x80), + 'ExternalFlashStatus' => static::$flashInfoExternalFlashStatuses[ord(substr($data, 8, 1)) & 0x01], + 'ExternalFlashReadyState' => static::$flashInfoExternalFlashReadyStates[ord(substr($data, 9, 1)) & 0x07], + 'FlashCompensation' => $this->printFraction(-getid3_lib::BigEndian2Int(substr($data, 10, 1), false, true) / 6), + 'FlashFocalLength' => ord(substr($data, 12, 1)), // mm + 'RepeatingFlashRate' => ord(substr($data, 13, 1)), // Hz + 'RepeatingFlashCount' => ord(substr($data, 14, 1)), + 'FlashGNDistance' => static::$flashInfoGNDistances[ord(substr($data, 15, 1))], + 'FlashGroupAControlMode' => static::$flashInfoControlModes[ord(substr($data, 17, 1)) & 0x0F], + 'FlashGroupBControlMode' => static::$flashInfoControlModes[ord(substr($data, 18, 1)) & 0xF0], + 'FlashGroupCControlMode' => static::$flashInfoControlModes[ord(substr($data, 18, 1)) & 0x0F], + 'FlashGroupAOutput' => (ord(substr($data, 17, 1)) & 0x0F) >= 0x06 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 40, 1)) / 6) * 100)) : 0, + 'FlashGroupACompensation' => sprintf('%+.1f', -getid3_lib::BigEndian2Int(substr($data, 40, 1), false, true) / 6), + 'FlashGroupBOutput' => (ord(substr($data, 18, 1)) & 0xF0) >= 0x60 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 41, 1)) / 6) * 100)) : 0, + 'FlashGroupBCompensation' => sprintf('%+.1f', -getid3_lib::BigEndian2Int(substr($data, 41, 1), false, true) / 6), + 'FlashGroupCOutput' => (ord(substr($data, 18, 1)) & 0x0F) >= 0x06 ? sprintf('%.0f%%', pow(2, (-ord(substr($data, 42, 1)) / 6) * 100)) : 0, + 'FlashGroupCCompensation' => sprintf('%+.1f', -getid3_lib::BigEndian2Int(substr($data, 42, 1), false, true) / 6), + ); + break; + case '0300': + $data = array( + 'FlashInfoVersion' => substr($data, 0, 4), + 'FlashSource' => static::$flashInfoSources[ord(substr($data, 4, 1))], + 'ExternalFlashFirmware' => $this->flashFirmwareLookup(ord(substr($data, 6, 1)), ord(substr($data, 7, 1))), + 'FlashCompensation' => $this->printFraction(-getid3_lib::BigEndian2Int(substr($data, 27, 1), false, true) / 6), + ); + break; + default: + $data = array( + 'FlashInfoVersion' => substr($data, 0, 4), + ); + break; + } + break; + case 0x020000b1: // HighISONoiseReduction + $data = isset(static::$highISONoiseReductions[$data]) ? static::$highISONoiseReductions[$data] : $data; + break; + case 0x020000b7: // AFInfo2 + $avInfo2Version = substr($data, 0, 4); + $contrastDetectAF = ord(substr($data, 4, 1)); + $phaseDetectAF = ord(substr($data, 6, 1)); + $rows = array( + 'AFInfo2Version' => $avInfo2Version, + 'ContrastDetectAF' => static::$AFInfo2ContrastDetectAFChoices[$contrastDetectAF], + 'AFAreaMode' => $contrastDetectAF + ? static::$AFInfo2AFAreaModesWithContrastDetectAF[ord(substr($data, 5, 1))] + : static::$AFInfo2AFAreaModesWithoutContrastDetectAF[ord(substr($data, 5, 1))], + 'PhaseDetectAF' => static::$AFInfo2PhaseDetectAFChoices[$phaseDetectAF], + ); + + if ($avInfo2Version === '0100') { + $rows['AFImageWidth'] = getid3_lib::BigEndian2Int(substr($data, 16, 2)); + $rows['AFImageHeight'] = getid3_lib::BigEndian2Int(substr($data, 18, 2)); + $rows['AFAreaXPosition'] = getid3_lib::BigEndian2Int(substr($data, 20, 2)); + $rows['AFAreaYPosition'] = getid3_lib::BigEndian2Int(substr($data, 22, 2)); + $rows['AFAreaWidth'] = getid3_lib::BigEndian2Int(substr($data, 24, 2)); + $rows['AFAreaHeight'] = getid3_lib::BigEndian2Int(substr($data, 26, 2)); + $rows['ContrastDetectAFInFocus'] = (bool)ord(substr($data, 28, 1)); + } elseif (strpos($avInfo2Version, '03') === 0) { + $rows['AFImageWidth'] = getid3_lib::BigEndian2Int(substr($data, 42, 2)); + $rows['AFImageHeight'] = getid3_lib::BigEndian2Int(substr($data, 44, 2)); + if ($contrastDetectAF === 2 + || ($contrastDetectAF === 1 && $avInfo2Version === '0301') + ) { + $rows['AFAreaXPosition'] = getid3_lib::BigEndian2Int(substr($data, 46, 2)); + $rows['AFAreaYPosition'] = getid3_lib::BigEndian2Int(substr($data, 48, 2)); + } + $rows['AFAreaWidth'] = getid3_lib::BigEndian2Int(substr($data, 50, 2)); + $rows['AFAreaHeight'] = getid3_lib::BigEndian2Int(substr($data, 52, 2)); + } elseif ($contrastDetectAF === 1 && $avInfo2Version === '0101') { + $rows['AFImageWidth'] = getid3_lib::BigEndian2Int(substr($data, 70, 2)); + $rows['AFImageHeight'] = getid3_lib::BigEndian2Int(substr($data, 72, 2)); + $rows['AFAreaXPosition'] = getid3_lib::BigEndian2Int(substr($data, 74, 2)); + $rows['AFAreaYPosition'] = getid3_lib::BigEndian2Int(substr($data, 76, 2)); + $rows['AFAreaWidth'] = getid3_lib::BigEndian2Int(substr($data, 78, 2)); + $rows['AFAreaHeight'] = getid3_lib::BigEndian2Int(substr($data, 80, 2)); + $rows['ContrastDetectAFInFocus'] = (bool) ord(substr($data, 82, 1)); + } + + $data = $rows; + break; + case 0x020000c3: // BarometerInfo + $data = array( + 'BarometerInfoVersion' => substr($data, 0, 4), + 'Altitude' => getid3_lib::BigEndian2Int(substr($data, 6, 4), false, true), // m + ); + break; + } + $tag_name = (isset($NCTGtagName[$record_type]) ? $NCTGtagName[$record_type] : '0x' . str_pad(dechex($record_type), 8, '0', STR_PAD_LEFT)); + + $parsed[$tag_name] = $data; + } + } + + return $parsed; + } + + /** + * @param int $value 0x80 subtracted + * @param string $normalName 'Normal' (0 value) string + * @param string|null $format format string for numbers (default '%+d'), 3) v2 divisor + * @param int|null $div + * + * @return string + */ + protected function printPC($value, $normalName = 'Normal', $format = '%+d', $div = 1) { + switch ($value) { + case 0: + return $normalName; + case 0x7f: + return 'n/a'; + case -0x80: + return 'Auto'; + case -0x7f: + return 'User'; + } + + return sprintf($format, $value / $div); + } + + /** + * @param int|float $value + * + * @return string + */ + protected function printFraction($value) { + if (!$value) { + return '0'; + } elseif ((int) $value /$value > 0.999) { + return sprintf("%+d", (int) $value); + } elseif ((int) ($value * 2) / ($value * 2) > 0.999) { + return sprintf("%+d/2", (int) ($value * 2)); + } elseif ((int) ($value * 3) / ($value * 3) > 0.999) { + return sprintf("%+d/3", (int) ($value * 3)); + } + + return sprintf("%+.3g", $value); + } + + /** + * @param int $firstByte + * @param int $secondByte + * + * @return string + */ + protected function flashFirmwareLookup($firstByte, $secondByte) + { + $indexKey = $firstByte.' '.$secondByte; + if (isset(static::$flashInfoExternalFlashFirmwares[$indexKey])) { + return static::$flashInfoExternalFlashFirmwares[$indexKey]; + } + + return sprintf('%d.%.2d (Unknown model)', $firstByte, $secondByte); + } + + /** + * @param int $flags + * + * @return string[]|string + */ + protected function externalFlashFlagsLookup($flags) + { + $result = array(); + foreach (static::$flashInfoExternalFlashFlags as $bit => $value) { + if (($flags >> $bit) & 1) { + $result[] = $value; + } + } + + return $result; + } + + /** + * @param string $data + * @param mixed|null $serialNumber + * @param mixed|null $shutterCount + * @param int $decryptStart + * + * @return false|string + */ + protected function decryptLensInfo( + $data, + $serialNumber = null, + $shutterCount = null, + $decryptStart = 0 + ) { + if (null === $serialNumber && null === $shutterCount) { + return false; + } + + if (!is_int($serialNumber) || !is_int($shutterCount)) { + if (null !== $serialNumber && null !== $shutterCount) { + $this->getid3->warning('Invalid '.(!is_int($serialNumber) ? 'SerialNumber' : 'ShutterCount')); + } else { + $this->getid3->warning('Cannot decrypt Nikon tags because '.(null === $serialNumber ? 'SerialNumber' : 'ShutterCount').' key is not defined.'); + } + + return false; + } + + $start = $decryptStart; + $length = strlen($data) - $start; + + return $this->decrypt($data, $serialNumber, $shutterCount, $start, $length); + } + + /** + * Decrypt Nikon data block + * + * @param string $data + * @param int $serialNumber + * @param int $count + * @param int $start + * @param int $length + * + * @return string + */ + protected function decrypt($data, $serialNumber, $count, $start = 0, $length = null) + { + $maxLen = strlen($data) - $start; + if (null === $length || $length > $maxLen) { + $length = $maxLen; + } + + if ($length <= 0) { + return $data; + } + + $key = 0; + for ($i = 0; $i < 4; ++$i) { + $key ^= ($count >> ($i * 8)) & 0xFF; + } + $ci = static::$decodeTables[0][$serialNumber & 0xff]; + $cj = static::$decodeTables[1][$key]; + $ck = 0x60; + $unpackedData = array(); + for ($i = $start; $i < $length + $start; ++$i) { + $cj = ($cj + $ci * $ck) & 0xff; + $ck = ($ck + 1) & 0xff; + $unpackedData[] = ord($data[$i]) ^ $cj; + } + + $end = $start + $length; + $pre = $start ? substr($data, 0, $start) : ''; + $post = $end < strlen($data) ? substr($data, $end) : ''; + + return $pre . implode('', array_map('chr', $unpackedData)) . $post; + } + + /** + * Get serial number for use as a decryption key + * + * @param string $serialNumber + * @param string|null $model + * + * @return int|null + */ + protected function serialKey($serialNumber, $model = null) + { + if (empty($serialNumber) || ctype_digit($serialNumber)) { + return (int) $serialNumber; + } + + if (null !== $model && preg_match('#\bD50$#', $model)) { + return 0x22; + } + + return 0x60; + } +} diff --git a/serendipity_event_podcast/player/getid3/module.tag.xmp.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.xmp.php similarity index 84% rename from serendipity_event_podcast/player/getid3/module.tag.xmp.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.xmp.php index 364204af..23c0d1ab 100644 --- a/serendipity_event_podcast/player/getid3/module.tag.xmp.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/module.tag.xmp.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // module.tag.xmp.php // @@ -14,7 +15,7 @@ ///////////////////////////////////////////////////////////////// // // // Module originally written [2009-Mar-26] by // -// Nigel Barnes // +// Nigel Barnes // // Bundled into getID3 with permission // // called by getID3 in module.graphic.jpg.php // // /// @@ -37,21 +38,21 @@ class Image_XMP * The name of the image file that contains the XMP fields to extract and modify. * @see Image_XMP() */ - var $_sFilename = null; + public $_sFilename = null; /** * @var array * The XMP fields that were extracted from the image or updated by this class. * @see getAllTags() */ - var $_aXMP = array(); + public $_aXMP = array(); /** * @var boolean * True if an APP1 segment was found to contain XMP metadata. * @see isValid() */ - var $_bXMPParse = false; + public $_bXMPParse = false; /** * Returns the status of XMP parsing during instantiation @@ -61,7 +62,7 @@ class Image_XMP * @return boolean * Returns true if an APP1 segment was found to contain XMP metadata. */ - function isValid() + public function isValid() { return $this->_bXMPParse; } @@ -71,7 +72,7 @@ class Image_XMP * * @return array - An array of XMP fields as it extracted by the XMPparse() function */ - function getAllTags() + public function getAllTags() { return $this->_aXMP; } @@ -80,10 +81,10 @@ class Image_XMP * Reads all the JPEG header segments from an JPEG image file into an array * * @param string $filename - the filename of the JPEG file to read - * @return array $headerdata - Array of JPEG header segments - * @return boolean FALSE - if headers could not be read + * @return array|false $headerdata - Array of JPEG header segments, + * FALSE - if headers could not be read */ - function _get_jpeg_header_data($filename) + public function _get_jpeg_header_data($filename) { // prevent refresh from aborting file operations and hosing file ignore_user_abort(true); @@ -91,16 +92,9 @@ class Image_XMP // Attempt to open the jpeg file - the at symbol supresses the error message about // not being able to open files. The file_exists would have been used, but it // does not work with files fetched over http or ftp. - ob_start(); - $filehnd = fopen($filename, 'rb'); - $errormessage = ob_get_contents(); - ob_end_clean(); - - // Check if the file opened successfully - if (!$filehnd) - { - // Could't open the file - exit - echo '

    Could not open file '.htmlentities($filename, ENT_COMPAT, LANG_CHARSET).'

    '."\n"; + if (is_readable($filename) && is_file($filename) && ($filehnd = fopen($filename, 'rb'))) { + // great + } else { return false; } @@ -120,7 +114,7 @@ class Image_XMP $data = fread($filehnd, 2); // Check that the third character is 0xFF (Start of first segment header) - if ($data{0} != "\xFF") + if ($data[0] != "\xFF") { // NO FF found - close file and return - JPEG is probably corrupted fclose($filehnd); @@ -130,15 +124,16 @@ class Image_XMP // Flag that we havent yet hit the compressed image data $hit_compressed_image_data = false; + $headerdata = array(); // Cycle through the file until, one of: 1) an EOI (End of image) marker is hit, // 2) we have hit the compressed image data (no more headers are allowed after data) // 3) or end of file is hit - while (($data{1} != "\xD9") && (!$hit_compressed_image_data) && (!feof($filehnd))) + while (($data[1] != "\xD9") && (!$hit_compressed_image_data) && (!feof($filehnd))) { // Found a segment to look at. // Check that the segment marker is not a Restart marker - restart markers don't have size or data after them - if ((ord($data{1}) < 0xD0) || (ord($data{1}) > 0xD7)) + if ((ord($data[1]) < 0xD0) || (ord($data[1]) > 0xD7)) { // Segment isn't a Restart marker // Read the next two bytes (size) @@ -155,15 +150,15 @@ class Image_XMP // Store the segment information in the output array $headerdata[] = array( - 'SegType' => ord($data{1}), - 'SegName' => $GLOBALS['JPEG_Segment_Names'][ord($data{1})], + 'SegType' => ord($data[1]), + 'SegName' => $GLOBALS['JPEG_Segment_Names'][ord($data[1])], 'SegDataStart' => $segdatastart, 'SegData' => $segdata, ); } // If this is a SOS (Start Of Scan) segment, then there is no more header data - the compressed image data follows - if ($data{1} == "\xDA") + if ($data[1] == "\xDA") { // Flag that we have hit the compressed image data - exit loop as no more headers available. $hit_compressed_image_data = true; @@ -174,7 +169,7 @@ class Image_XMP $data = fread($filehnd, 2); // Check that the first byte of the two is 0xFF as it should be for a marker - if ($data{0} != "\xFF") + if ($data[0] != "\xFF") { // NO FF found - close file and return - JPEG is probably corrupted fclose($filehnd); @@ -197,31 +192,34 @@ class Image_XMP * Retrieves XMP information from an APP1 JPEG segment and returns the raw XML text as a string. * * @param string $filename - the filename of the JPEG file to read - * @return string $xmp_data - the string of raw XML text - * @return boolean FALSE - if an APP 1 XMP segment could not be found, or if an error occured + * @return string|false $xmp_data - the string of raw XML text, + * FALSE - if an APP 1 XMP segment could not be found, or if an error occurred */ - function _get_XMP_text($filename) + public function _get_XMP_text($filename) { //Get JPEG header data $jpeg_header_data = $this->_get_jpeg_header_data($filename); //Cycle through the header segments - for ($i = 0; $i < count($jpeg_header_data); $i++) - { - // If we find an APP1 header, - if (strcmp($jpeg_header_data[$i]['SegName'], 'APP1') == 0) - { - // And if it has the Adobe XMP/RDF label (http://ns.adobe.com/xap/1.0/\x00) , - if (strncmp($jpeg_header_data[$i]['SegData'], 'http://ns.adobe.com/xap/1.0/'."\x00", 29) == 0) - { - // Found a XMP/RDF block - // Return the XMP text - $xmp_data = substr($jpeg_header_data[$i]['SegData'], 29); + if (is_array($jpeg_header_data) && count($jpeg_header_data) > 0) { + foreach ($jpeg_header_data as $segment) { + // If we find an APP1 header, + if (strcmp($segment['SegName'], 'APP1') === 0) { + // And if it has the Adobe XMP/RDF label (http://ns.adobe.com/xap/1.0/\x00) , + if (strncmp($segment['SegData'], 'http://ns.adobe.com/xap/1.0/' . "\x00", 29) === 0) { + // Found a XMP/RDF block + // Return the XMP text + $xmp_data = substr($segment['SegData'], 29); - return $xmp_data; + // trim() should not be necessary, but some files found in the wild with null-terminated block + // (known samples from Apple Aperture) causes problems elsewhere + // (see https://www.getid3.org/phpBB3/viewtopic.php?f=4&t=1153) + return trim($xmp_data); + } } } } + return false; } @@ -229,11 +227,11 @@ class Image_XMP * Parses a string containing XMP data (XML), and returns an array * which contains all the XMP (XML) information. * - * @param string $xml_text - a string containing the XMP data (XML) to be parsed - * @return array $xmp_array - an array containing all xmp details retrieved. - * @return boolean FALSE - couldn't parse the XMP data + * @param string $xmltext - a string containing the XMP data (XML) to be parsed + * @return array|false $xmp_array - an array containing all xmp details retrieved, + * FALSE - couldn't parse the XMP data. */ - function read_XMP_array_from_text($xmltext) + public function read_XMP_array_from_text($xmltext) { // Check if there actually is any text to parse if (trim($xmltext) == '') @@ -309,17 +307,20 @@ class Image_XMP foreach (array_keys($xml_elem['attributes']) as $key) { // Check whether we want this details from this attribute - if (in_array($key, $GLOBALS['XMP_tag_captions'])) - { +// if (in_array($key, $GLOBALS['XMP_tag_captions'])) +// if (true) +// { // Attribute wanted $xmp_array[$key] = $xml_elem['attributes'][$key]; - } +// } } } + break; case 'cdata': case 'close': break; } + break; case 'rdf:ID': case 'rdf:nodeID': @@ -333,14 +334,14 @@ class Image_XMP if (array_key_exists('attributes', $xml_elem)) { // If Lang Alt (language alternatives) then ensure we take the default language - if ($xml_elem['attributes']['xml:lang'] != 'x-default') + if (isset($xml_elem['attributes']['xml:lang']) && ($xml_elem['attributes']['xml:lang'] != 'x-default')) { break; } } if ($current_property != '') { - $xmp_array[$current_property][$container_index] = $xml_elem['value']; + $xmp_array[$current_property][$container_index] = (isset($xml_elem['value']) ? $xml_elem['value'] : ''); $container_index += 1; } //else unidentified attribute!! @@ -366,8 +367,9 @@ class Image_XMP default: // Check whether we want the details from this attribute - if (in_array($xml_elem['tag'], $GLOBALS['XMP_tag_captions'])) - { +// if (in_array($xml_elem['tag'], $GLOBALS['XMP_tag_captions'])) +// if (true) +// { switch ($xml_elem['type']) { case 'open': @@ -382,14 +384,14 @@ class Image_XMP case 'complete': // store attribute value - $xmp_array[$xml_elem['tag']] = (isset($xml_elem['value']) ? $xml_elem['value'] : ''); + $xmp_array[$xml_elem['tag']] = (isset($xml_elem['attributes']) ? $xml_elem['attributes'] : (isset($xml_elem['value']) ? $xml_elem['value'] : '')); break; case 'cdata': // ignore break; } - } +// } break; } @@ -401,9 +403,9 @@ class Image_XMP /** * Constructor * - * @param string - Name of the image file to access and extract XMP information from. + * @param string $sFilename - Name of the image file to access and extract XMP information from. */ - function Image_XMP($sFilename) + public function __construct($sFilename) { $this->_sFilename = $sFilename; @@ -413,8 +415,11 @@ class Image_XMP $xmp_data = $this->_get_XMP_text($sFilename); if ($xmp_data) { - $this->_aXMP = $this->read_XMP_array_from_text($xmp_data); - $this->_bXMPParse = true; + $aXMP = $this->read_XMP_array_from_text($xmp_data); + if ($aXMP !== false) { + $this->_aXMP = (array) $aXMP; + $this->_bXMPParse = true; + } } } } @@ -427,6 +432,7 @@ class Image_XMP * The Property names of all known XMP fields. * Note: this is a full list with unrequired properties commented out. */ +/* $GLOBALS['XMP_tag_captions'] = array( // IPTC Core 'Iptc4xmpCore:CiAdrCity', @@ -695,7 +701,7 @@ $GLOBALS['XMP_tag_captions'] = array( 'exif:Rows', 'exif:Settings', ); - +*/ /** * Global Variable: JPEG_Segment_Names @@ -769,5 +775,3 @@ $GLOBALS['JPEG_Segment_Names'] = array( 0xFD => 'JPG13', 0xFE => 'COM', ); - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/write.apetag.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.apetag.php similarity index 72% rename from serendipity_event_podcast/player/getid3/write.apetag.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.apetag.php index 8b157181..a34beed4 100644 --- a/serendipity_event_podcast/player/getid3/write.apetag.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.apetag.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // write.apetag.php // @@ -13,23 +14,51 @@ // /// ///////////////////////////////////////////////////////////////// - +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.apetag.php', __FILE__, true); class getid3_write_apetag { + /** + * @var string + */ + public $filename; - var $filename; - var $tag_data; - var $always_preserve_replaygain = true; // ReplayGain / MP3gain tags will be copied from old tag even if not passed in data - var $warnings = array(); // any non-critical errors will be stored here - var $errors = array(); // any critical errors will be stored here + /** + * @var array + */ + public $tag_data; - function getid3_write_apetag() { - return true; + /** + * ReplayGain / MP3gain tags will be copied from old tag even if not passed in data. + * + * @var bool + */ + public $always_preserve_replaygain = true; + + /** + * Any non-critical errors will be stored here. + * + * @var array + */ + public $warnings = array(); + + /** + * Any critical errors will be stored here. + * + * @var array + */ + public $errors = array(); + + public function __construct() { } - function WriteAPEtag() { + /** + * @return bool + */ + public function WriteAPEtag() { // NOTE: All data passed to this function must be UTF-8 format $getID3 = new getID3; @@ -56,9 +85,7 @@ class getid3_write_apetag } if ($APEtag = $this->GenerateAPEtag()) { - ob_start(); - if ($fp = fopen($this->filename, 'a+b')) { - ob_end_clean(); + if (getID3::is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) { $oldignoreuserabort = ignore_user_abort(true); flock($fp, LOCK_EX); @@ -69,15 +96,15 @@ class getid3_write_apetag if (isset($ThisFileInfo['lyrics3']['tag_offset_start'])) { $PostAPEdataOffset = max($PostAPEdataOffset, $ThisFileInfo['lyrics3']['tag_offset_start']); } - fseek($fp, $PostAPEdataOffset, SEEK_SET); + fseek($fp, $PostAPEdataOffset); $PostAPEdata = ''; if ($ThisFileInfo['filesize'] > $PostAPEdataOffset) { $PostAPEdata = fread($fp, $ThisFileInfo['filesize'] - $PostAPEdataOffset); } - fseek($fp, $PostAPEdataOffset, SEEK_SET); + fseek($fp, $PostAPEdataOffset); if (isset($ThisFileInfo['ape']['tag_offset_start'])) { - fseek($fp, $ThisFileInfo['ape']['tag_offset_start'], SEEK_SET); + fseek($fp, $ThisFileInfo['ape']['tag_offset_start']); } ftruncate($fp, ftell($fp)); fwrite($fp, $APEtag, strlen($APEtag)); @@ -89,32 +116,30 @@ class getid3_write_apetag ignore_user_abort($oldignoreuserabort); return true; } - $errormessage = ob_get_contents(); - ob_end_clean(); - return false; } return false; } - function DeleteAPEtag() { + /** + * @return bool + */ + public function DeleteAPEtag() { $getID3 = new getID3; $ThisFileInfo = $getID3->analyze($this->filename); if (isset($ThisFileInfo['ape']['tag_offset_start']) && isset($ThisFileInfo['ape']['tag_offset_end'])) { - ob_start(); - if ($fp = fopen($this->filename, 'a+b')) { - ob_end_clean(); + if (getID3::is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) { flock($fp, LOCK_EX); $oldignoreuserabort = ignore_user_abort(true); - fseek($fp, $ThisFileInfo['ape']['tag_offset_end'], SEEK_SET); + fseek($fp, $ThisFileInfo['ape']['tag_offset_end']); $DataAfterAPE = ''; if ($ThisFileInfo['filesize'] > $ThisFileInfo['ape']['tag_offset_end']) { $DataAfterAPE = fread($fp, $ThisFileInfo['filesize'] - $ThisFileInfo['ape']['tag_offset_end']); } ftruncate($fp, $ThisFileInfo['ape']['tag_offset_start']); - fseek($fp, $ThisFileInfo['ape']['tag_offset_start'], SEEK_SET); + fseek($fp, $ThisFileInfo['ape']['tag_offset_start']); if (!empty($DataAfterAPE)) { fwrite($fp, $DataAfterAPE, strlen($DataAfterAPE)); @@ -126,15 +151,15 @@ class getid3_write_apetag return true; } - $errormessage = ob_get_contents(); - ob_end_clean(); return false; } return true; } - - function GenerateAPEtag() { + /** + * @return string|false + */ + public function GenerateAPEtag() { // NOTE: All data passed to this function must be UTF-8 format $items = array(); @@ -168,7 +193,13 @@ class getid3_write_apetag return $this->GenerateAPEtagHeaderFooter($items, true).implode('', $items).$this->GenerateAPEtagHeaderFooter($items, false); } - function GenerateAPEtagHeaderFooter(&$items, $isheader=false) { + /** + * @param array $items + * @param bool $isheader + * + * @return string + */ + public function GenerateAPEtagHeaderFooter(&$items, $isheader=false) { $tagdatalength = 0; foreach ($items as $itemdata) { $tagdatalength += strlen($itemdata); @@ -184,7 +215,16 @@ class getid3_write_apetag return $APEheader; } - function GenerateAPEtagFlags($header=true, $footer=true, $isheader=false, $encodingid=0, $readonly=false) { + /** + * @param bool $header + * @param bool $footer + * @param bool $isheader + * @param int $encodingid + * @param bool $readonly + * + * @return string + */ + public function GenerateAPEtagFlags($header=true, $footer=true, $isheader=false, $encodingid=0, $readonly=false) { $APEtagFlags = array_fill(0, 4, 0); if ($header) { $APEtagFlags[0] |= 0x80; // Tag contains a header @@ -197,8 +237,8 @@ class getid3_write_apetag } // 0: Item contains text information coded in UTF-8 - // 1: Item contains binary information °) - // 2: Item is a locator of external stored information °°) + // 1: Item contains binary information °) + // 2: Item is a locator of external stored information °°) // 3: reserved $APEtagFlags[3] |= ($encodingid << 1); @@ -209,7 +249,12 @@ class getid3_write_apetag return chr($APEtagFlags[3]).chr($APEtagFlags[2]).chr($APEtagFlags[1]).chr($APEtagFlags[0]); } - function CleanAPEtagItemKey($itemkey) { + /** + * @param string $itemkey + * + * @return string + */ + public function CleanAPEtagItemKey($itemkey) { $itemkey = preg_replace("#[^\x20-\x7E]#i", '', $itemkey); // http://www.personal.uni-jena.de/~pfk/mpp/sv8/apekey.html @@ -230,5 +275,3 @@ class getid3_write_apetag } } - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/write.id3v1.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.id3v1.php similarity index 62% rename from serendipity_event_podcast/player/getid3/write.id3v1.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.id3v1.php index 28fc1606..22c46779 100644 --- a/serendipity_event_podcast/player/getid3/write.id3v1.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.id3v1.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // write.id3v1.php // @@ -13,56 +14,79 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true); class getid3_write_id3v1 { - var $filename; - var $filesize; - var $tag_data; - var $warnings = array(); // any non-critical errors will be stored here - var $errors = array(); // any critical errors will be stored here + /** + * @var string + */ + public $filename; - function getid3_write_id3v1() { - return true; + /** + * @var int + */ + public $filesize; + + /** + * @var array + */ + public $tag_data; + + /** + * Any non-critical errors will be stored here. + * + * @var array + */ + public $warnings = array(); + + /** + * Any critical errors will be stored here. + * + * @var array + */ + public $errors = array(); + + public function __construct() { } - function WriteID3v1() { + /** + * @return bool + */ + public function WriteID3v1() { // File MUST be writeable - CHMOD(646) at least - if (!empty($this->filename) && is_writeable($this->filename)) { + if (!empty($this->filename) && is_readable($this->filename) && getID3::is_writable($this->filename) && is_file($this->filename)) { $this->setRealFileSize(); if (($this->filesize <= 0) || !getid3_lib::intValueSupported($this->filesize)) { $this->errors[] = 'Unable to WriteID3v1('.$this->filename.') because filesize ('.$this->filesize.') is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; return false; } - ob_start(); if ($fp_source = fopen($this->filename, 'r+b')) { - - ob_end_clean(); fseek($fp_source, -128, SEEK_END); if (fread($fp_source, 3) == 'TAG') { fseek($fp_source, -128, SEEK_END); // overwrite existing ID3v1 tag } else { fseek($fp_source, 0, SEEK_END); // append new ID3v1 tag } - $this->tag_data['track'] = (isset($this->tag_data['track']) ? $this->tag_data['track'] : (isset($this->tag_data['track_number']) ? $this->tag_data['track_number'] : (isset($this->tag_data['tracknumber']) ? $this->tag_data['tracknumber'] : ''))); + $this->tag_data['track_number'] = (isset($this->tag_data['track_number']) ? $this->tag_data['track_number'] : ''); $new_id3v1_tag_data = getid3_id3v1::GenerateID3v1Tag( - (isset($this->tag_data['title'] ) ? $this->tag_data['title'] : ''), - (isset($this->tag_data['artist'] ) ? $this->tag_data['artist'] : ''), - (isset($this->tag_data['album'] ) ? $this->tag_data['album'] : ''), - (isset($this->tag_data['year'] ) ? $this->tag_data['year'] : ''), - (isset($this->tag_data['genreid']) ? $this->tag_data['genreid'] : ''), - (isset($this->tag_data['comment']) ? $this->tag_data['comment'] : ''), - (isset($this->tag_data['track'] ) ? $this->tag_data['track'] : '')); + (isset($this->tag_data['title'] ) ? $this->tag_data['title'] : ''), + (isset($this->tag_data['artist'] ) ? $this->tag_data['artist'] : ''), + (isset($this->tag_data['album'] ) ? $this->tag_data['album'] : ''), + (isset($this->tag_data['year'] ) ? $this->tag_data['year'] : ''), + (isset($this->tag_data['genreid'] ) ? $this->tag_data['genreid'] : ''), + (isset($this->tag_data['comment'] ) ? $this->tag_data['comment'] : ''), + (isset($this->tag_data['track_number']) ? $this->tag_data['track_number'] : '')); fwrite($fp_source, $new_id3v1_tag_data, 128); fclose($fp_source); return true; } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - $this->errors[] = 'Could not open '.$this->filename.' mode "r+b"'; + $this->errors[] = 'Could not fopen('.$this->filename.', "r+b")'; return false; } } @@ -70,7 +94,10 @@ class getid3_write_id3v1 return false; } - function FixID3v1Padding() { + /** + * @return bool + */ + public function FixID3v1Padding() { // ID3v1 data is supposed to be padded with NULL characters, but some taggers incorrectly use spaces // This function rewrites the ID3v1 tag with correct padding @@ -83,6 +110,7 @@ class getid3_write_id3v1 $getID3->option_tag_id3v1 = true; $ThisFileInfo = $getID3->analyze($this->filename); if (isset($ThisFileInfo['tags']['id3v1'])) { + $id3v1data = array(); foreach ($ThisFileInfo['tags']['id3v1'] as $key => $value) { $id3v1data[$key] = implode(',', $value); } @@ -92,18 +120,19 @@ class getid3_write_id3v1 return false; } - function RemoveID3v1() { + /** + * @return bool + */ + public function RemoveID3v1() { // File MUST be writeable - CHMOD(646) at least - if (!empty($this->filename) && is_writeable($this->filename)) { + if (!empty($this->filename) && is_readable($this->filename) && getID3::is_writable($this->filename) && is_file($this->filename)) { $this->setRealFileSize(); if (($this->filesize <= 0) || !getid3_lib::intValueSupported($this->filesize)) { $this->errors[] = 'Unable to RemoveID3v1('.$this->filename.') because filesize ('.$this->filesize.') is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; return false; } - ob_start(); if ($fp_source = fopen($this->filename, 'r+b')) { - ob_end_clean(); fseek($fp_source, -128, SEEK_END); if (fread($fp_source, 3) == 'TAG') { ftruncate($fp_source, $this->filesize - 128); @@ -114,9 +143,7 @@ class getid3_write_id3v1 return true; } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - $this->errors[] = 'Could not open '.$this->filename.' mode "r+b"'; + $this->errors[] = 'Could not fopen('.$this->filename.', "r+b")'; } } else { $this->errors[] = $this->filename.' is not writeable'; @@ -124,7 +151,10 @@ class getid3_write_id3v1 return false; } - function setRealFileSize() { + /** + * @return bool + */ + public function setRealFileSize() { if (PHP_INT_MAX > 2147483647) { $this->filesize = filesize($this->filename); return true; @@ -143,5 +173,3 @@ class getid3_write_id3v1 } } - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/write.id3v2.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.id3v2.php similarity index 82% rename from serendipity_event_podcast/player/getid3/write.id3v2.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.id3v2.php index 9960f1ce..7385a459 100644 --- a/serendipity_event_podcast/player/getid3/write.id3v2.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.id3v2.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// /// // // write.id3v2.php // @@ -13,36 +14,103 @@ // /// ///////////////////////////////////////////////////////////////// +if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers + exit; +} getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); class getid3_write_id3v2 { - var $filename; - var $tag_data; - var $paddedlength = 4096; // minimum length of ID3v2 tag in bytes - var $majorversion = 3; // ID3v2 major version (2, 3 (recommended), 4) - var $minorversion = 0; // ID3v2 minor version - always 0 - var $merge_existing_data = false; // if true, merge new data with existing tags; if false, delete old tag data and only write new tags - var $id3v2_default_encodingid = 0; // default text encoding (ISO-8859-1) if not explicitly passed - var $id3v2_use_unsynchronisation = false; // the specs say it should be TRUE, but most other ID3v2-aware programs are broken if unsynchronization is used, so by default don't use it. - var $warnings = array(); // any non-critical errors will be stored here - var $errors = array(); // any critical errors will be stored here + /** + * @var string + */ + public $filename; - function getid3_write_id3v2() { - return true; + /** + * @var array|null + */ + public $tag_data; + + /** + * Read buffer size in bytes. + * + * @var int + */ + public $fread_buffer_size = 32768; + + /** + * Minimum length of ID3v2 tag in bytes. + * + * @var int + */ + public $paddedlength = 4096; + + /** + * ID3v2 major version (2, 3 (recommended), 4). + * + * @var int + */ + public $majorversion = 3; + + /** + * ID3v2 minor version - always 0. + * + * @var int + */ + public $minorversion = 0; + + /** + * If true, merge new data with existing tags; if false, delete old tag data and only write new tags. + * + * @var bool + */ + public $merge_existing_data = false; + + /** + * Default text encoding (ISO-8859-1) if not explicitly passed. + * + * @var int + */ + public $id3v2_default_encodingid = 0; + + /** + * The specs say it should be TRUE, but most other ID3v2-aware programs are broken if unsynchronization is used, + * so by default don't use it. + * + * @var bool + */ + public $id3v2_use_unsynchronisation = false; + + /** + * Any non-critical errors will be stored here. + * + * @var array + */ + public $warnings = array(); + + /** + * Any critical errors will be stored here. + * + * @var array + */ + public $errors = array(); + + public function __construct() { } - function WriteID3v2() { + /** + * @return bool + */ + public function WriteID3v2() { // File MUST be writeable - CHMOD(646) at least. It's best if the // directory is also writeable, because that method is both faster and less susceptible to errors. - if (!empty($this->filename) && (is_writeable($this->filename) || (!file_exists($this->filename) && is_writeable(dirname($this->filename))))) { + if (!empty($this->filename) && (getID3::is_writable($this->filename) || (!file_exists($this->filename) && getID3::is_writable(dirname($this->filename))))) { // Initialize getID3 engine $getID3 = new getID3; $OldThisFileInfo = $getID3->analyze($this->filename); if (!getid3_lib::intValueSupported($OldThisFileInfo['filesize'])) { $this->errors[] = 'Unable to write ID3v2 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'; - fclose($fp_source); return false; } if ($this->merge_existing_data) { @@ -55,50 +123,45 @@ class getid3_write_id3v2 if ($NewID3v2Tag = $this->GenerateID3v2Tag()) { - if (file_exists($this->filename) && is_writeable($this->filename) && isset($OldThisFileInfo['id3v2']['headerlength']) && ($OldThisFileInfo['id3v2']['headerlength'] == strlen($NewID3v2Tag))) { + if (file_exists($this->filename) && getID3::is_writable($this->filename) && isset($OldThisFileInfo['id3v2']['headerlength']) && ($OldThisFileInfo['id3v2']['headerlength'] == strlen($NewID3v2Tag))) { // best and fastest method - insert-overwrite existing tag (padded to length of old tag if neccesary) if (file_exists($this->filename)) { - ob_start(); - if ($fp = fopen($this->filename, 'r+b')) { + if (is_readable($this->filename) && getID3::is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'r+b'))) { rewind($fp); fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag)); fclose($fp); } else { - $this->errors[] = 'Could not open '.$this->filename.' mode "r+b" - '.strip_tags(ob_get_contents()); + $this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")'; } - ob_end_clean(); } else { - ob_start(); - if ($fp = fopen($this->filename, 'wb')) { + if (getID3::is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'wb'))) { rewind($fp); fwrite($fp, $NewID3v2Tag, strlen($NewID3v2Tag)); fclose($fp); } else { - $this->errors[] = 'Could not open '.$this->filename.' mode "wb" - '.strip_tags(ob_get_contents()); + $this->errors[] = 'Could not fopen("'.$this->filename.'", "wb")'; } - ob_end_clean(); } } else { if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) { - ob_start(); - if ($fp_source = fopen($this->filename, 'rb')) { - if ($fp_temp = fopen($tempfilename, 'wb')) { + if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) { + if (getID3::is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) { fwrite($fp_temp, $NewID3v2Tag, strlen($NewID3v2Tag)); rewind($fp_source); if (!empty($OldThisFileInfo['avdataoffset'])) { - fseek($fp_source, $OldThisFileInfo['avdataoffset'], SEEK_SET); + fseek($fp_source, $OldThisFileInfo['avdataoffset']); } - while ($buffer = fread($fp_source, GETID3_FREAD_BUFFER_SIZE)) { + while ($buffer = fread($fp_source, $this->fread_buffer_size)) { fwrite($fp_temp, $buffer, strlen($buffer)); } @@ -106,22 +169,16 @@ class getid3_write_id3v2 fclose($fp_source); copy($tempfilename, $this->filename); unlink($tempfilename); - ob_end_clean(); return true; } else { - - $this->errors[] = 'Could not open '.$tempfilename.' mode "wb" - '.strip_tags(ob_get_contents()); - + $this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")'; } fclose($fp_source); } else { - - $this->errors[] = 'Could not open '.$this->filename.' mode "rb" - '.strip_tags(ob_get_contents()); - + $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")'; } - ob_end_clean(); } return false; @@ -143,16 +200,18 @@ class getid3_write_id3v2 return false; } - function RemoveID3v2() { + /** + * @return bool + */ + public function RemoveID3v2() { // File MUST be writeable - CHMOD(646) at least. It's best if the // directory is also writeable, because that method is both faster and less susceptible to errors. - if (is_writeable(dirname($this->filename))) { + if (getID3::is_writable(dirname($this->filename))) { // preferred method - only one copying operation, minimal chance of corrupting // original file if script is interrupted, but required directory to be writeable - ob_start(); - if ($fp_source = fopen($this->filename, 'rb')) { - ob_end_clean(); + if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) { + // Initialize getID3 engine $getID3 = new getID3; $OldThisFileInfo = $getID3->analyze($this->filename); @@ -163,38 +222,31 @@ class getid3_write_id3v2 } rewind($fp_source); if ($OldThisFileInfo['avdataoffset'] !== false) { - fseek($fp_source, $OldThisFileInfo['avdataoffset'], SEEK_SET); + fseek($fp_source, $OldThisFileInfo['avdataoffset']); } - ob_start(); - if ($fp_temp = fopen($this->filename.'getid3tmp', 'w+b')) { - ob_end_clean(); - while ($buffer = fread($fp_source, GETID3_FREAD_BUFFER_SIZE)) { + if (getID3::is_writable($this->filename) && is_file($this->filename) && ($fp_temp = fopen($this->filename.'getid3tmp', 'w+b'))) { + while ($buffer = fread($fp_source, $this->fread_buffer_size)) { fwrite($fp_temp, $buffer, strlen($buffer)); } fclose($fp_temp); } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - $this->errors[] = 'Could not open '.$this->filename.'getid3tmp mode "w+b"'; + $this->errors[] = 'Could not fopen("'.$this->filename.'getid3tmp", "w+b")'; } fclose($fp_source); } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - $this->errors[] = 'Could not open '.$this->filename.' mode "rb"'; + $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")'; } if (file_exists($this->filename)) { unlink($this->filename); } rename($this->filename.'getid3tmp', $this->filename); - } elseif (is_writable($this->filename)) { + } elseif (getID3::is_writable($this->filename)) { // less desirable alternate method - double-copies the file, overwrites original file // and could corrupt source file if the script is interrupted or an error occurs. - ob_start(); - if ($fp_source = fopen($this->filename, 'rb')) { - ob_end_clean(); + if (is_readable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'rb'))) { + // Initialize getID3 engine $getID3 = new getID3; $OldThisFileInfo = $getID3->analyze($this->filename); @@ -205,35 +257,29 @@ class getid3_write_id3v2 } rewind($fp_source); if ($OldThisFileInfo['avdataoffset'] !== false) { - fseek($fp_source, $OldThisFileInfo['avdataoffset'], SEEK_SET); + fseek($fp_source, $OldThisFileInfo['avdataoffset']); } if ($fp_temp = tmpfile()) { - while ($buffer = fread($fp_source, GETID3_FREAD_BUFFER_SIZE)) { + while ($buffer = fread($fp_source, $this->fread_buffer_size)) { fwrite($fp_temp, $buffer, strlen($buffer)); } fclose($fp_source); - ob_start(); - if ($fp_source = fopen($this->filename, 'wb')) { - ob_end_clean(); + if (getID3::is_writable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'wb'))) { rewind($fp_temp); - while ($buffer = fread($fp_temp, GETID3_FREAD_BUFFER_SIZE)) { + while ($buffer = fread($fp_temp, $this->fread_buffer_size)) { fwrite($fp_source, $buffer, strlen($buffer)); } fseek($fp_temp, -128, SEEK_END); fclose($fp_source); } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - $this->errors[] = 'Could not open '.$this->filename.' mode "wb"'; + $this->errors[] = 'Could not fopen("'.$this->filename.'", "wb")'; } fclose($fp_temp); } else { $this->errors[] = 'Could not create tmpfile()'; } } else { - $errormessage = ob_get_contents(); - ob_end_clean(); - $this->errors[] = 'Could not open '.$this->filename.' mode "rb"'; + $this->errors[] = 'Could not fopen("'.$this->filename.'", "rb")'; } } else { @@ -248,8 +294,13 @@ class getid3_write_id3v2 return true; } - - function GenerateID3v2TagFlags($flags) { + /** + * @param array $flags + * + * @return string|false + */ + public function GenerateID3v2TagFlags($flags) { + $flag = null; switch ($this->majorversion) { case 4: // %abcd0000 @@ -277,13 +328,25 @@ class getid3_write_id3v2 default: return false; - break; } return chr(bindec($flag)); } - - function GenerateID3v2FrameFlags($TagAlter=false, $FileAlter=false, $ReadOnly=false, $Compression=false, $Encryption=false, $GroupingIdentity=false, $Unsynchronisation=false, $DataLengthIndicator=false) { + /** + * @param bool $TagAlter + * @param bool $FileAlter + * @param bool $ReadOnly + * @param bool $Compression + * @param bool $Encryption + * @param bool $GroupingIdentity + * @param bool $Unsynchronisation + * @param bool $DataLengthIndicator + * + * @return string|false + */ + public function GenerateID3v2FrameFlags($TagAlter=false, $FileAlter=false, $ReadOnly=false, $Compression=false, $Encryption=false, $GroupingIdentity=false, $Unsynchronisation=false, $DataLengthIndicator=false) { + $flag1 = null; + $flag2 = null; switch ($this->majorversion) { case 4: // %0abc0000 %0h00kmnp @@ -317,13 +380,18 @@ class getid3_write_id3v2 default: return false; - break; } return chr(bindec($flag1)).chr(bindec($flag2)); } - function GenerateID3v2FrameData($frame_name, $source_data_array) { + /** + * @param string $frame_name + * @param array $source_data_array + * + * @return string|false + */ + public function GenerateID3v2FrameData($frame_name, $source_data_array) { if (!getid3_id3v2::IsValidID3v2FrameName($frame_name, $this->majorversion)) { return false; } @@ -354,7 +422,7 @@ class getid3_write_id3v2 // Description $00 (00) // Value $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) { + if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; } else { $framedata .= chr($source_data_array['encodingid']); @@ -369,9 +437,9 @@ class getid3_write_id3v2 // Description $00 (00) // URL $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) { + if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; - } elseif (!isset($source_data_array['data']) || !$this->IsValidURL($source_data_array['data'], false, false)) { + } elseif (!isset($source_data_array['data']) || !$this->IsValidURL($source_data_array['data'], false)) { //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; // probably should be an error, need to rewrite IsValidURL() to handle other encodings $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; @@ -387,7 +455,7 @@ class getid3_write_id3v2 // Text encoding $xx // People list strings $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); - if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'], $this->majorversion)) { + if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; } else { $framedata .= chr($source_data_array['encodingid']); @@ -420,13 +488,14 @@ class getid3_write_id3v2 if (!$this->ID3v2IsValidETCOevent($val['typeid'])) { $this->errors[] = 'Invalid Event Type byte in '.$frame_name.' ('.$val['typeid'].')'; } elseif (($key != 'timestampformat') && ($key != 'flags')) { - if (($val['timestamp'] > 0) && ($previousETCOtimestamp >= $val['timestamp'])) { + if (($val['timestamp'] > 0) && isset($previousETCOtimestamp) && ($previousETCOtimestamp >= $val['timestamp'])) { // The 'Time stamp' is set to zero if directly at the beginning of the sound // or after the previous event. All events MUST be sorted in chronological order. $this->errors[] = 'Out-of-order timestamp in '.$frame_name.' ('.$val['timestamp'].') for Event Type ('.$val['typeid'].')'; } else { $framedata .= chr($val['typeid']); $framedata .= getid3_lib::BigEndian2String($val['timestamp'], 4, false); + $previousETCOtimestamp = $val['timestamp']; } } } @@ -476,6 +545,7 @@ class getid3_write_id3v2 } else { $this->errors[] = 'Invalid Bits For Milliseconds Deviation in '.$frame_name.' ('.$source_data_array['bitsformsdeviation'].')'; } + $unwrittenbitstream = ''; foreach ($source_data_array as $key => $val) { if (($key != 'framesbetweenreferences') && ($key != 'bytesbetweenreferences') && ($key != 'msbetweenreferences') && ($key != 'bitsforbytesdeviation') && ($key != 'bitsformsdeviation') && ($key != 'flags')) { $unwrittenbitstream .= str_pad(getid3_lib::Dec2Bin($val['bytedeviation']), $source_data_array['bitsforbytesdeviation'], '0', STR_PAD_LEFT); @@ -640,7 +710,7 @@ class getid3_write_id3v2 if (!$this->IsWithinBitRange($source_data_array['bitsvolume'], 8, false)) { $this->errors[] = 'Invalid Bits For Volume Description byte in '.$frame_name.' ('.$source_data_array['bitsvolume'].') (range = 1 to 255)'; } else { - $incdecflag .= '00'; + $incdecflag = '00'; $incdecflag .= $source_data_array['incdec']['right'] ? '1' : '0'; // a - Relative volume change, right $incdecflag .= $source_data_array['incdec']['left'] ? '1' : '0'; // b - Relative volume change, left $incdecflag .= $source_data_array['incdec']['rightrear'] ? '1' : '0'; // c - Relative volume change, right back @@ -783,9 +853,9 @@ class getid3_write_id3v2 $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].') for ID3v2.'.$this->majorversion; } elseif (!$this->ID3v2IsValidAPICpicturetype($source_data_array['picturetypeid'])) { $this->errors[] = 'Invalid Picture Type byte in '.$frame_name.' ('.$source_data_array['picturetypeid'].') for ID3v2.'.$this->majorversion; - } elseif (($this->majorversion >= 3) && (!$this->ID3v2IsValidAPICimageformat($source_data_array['mime']))) { + } elseif ((!$this->ID3v2IsValidAPICimageformat($source_data_array['mime']))) { $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].') for ID3v2.'.$this->majorversion; - } elseif (($source_data_array['mime'] == '-->') && (!$this->IsValidURL($source_data_array['data'], false, false))) { + } elseif (($source_data_array['mime'] == '-->') && (!$this->IsValidURL($source_data_array['data'], false))) { //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; // probably should be an error, need to rewrite IsValidURL() to handle other encodings $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; @@ -836,10 +906,14 @@ class getid3_write_id3v2 // Email to user $00 // Rating $xx // Counter $xx xx xx xx (xx ...) + if (!$this->IsValidEmail($source_data_array['email'])) { + // https://github.com/JamesHeinrich/getID3/issues/216 + // https://en.wikipedia.org/wiki/ID3#ID3v2_rating_tag_issue + // ID3v2 specs say it should be an email address, but Windows instead uses string like "Windows Media Player 9 Series" + $this->warnings[] = 'Invalid Email in '.$frame_name.' ('.$source_data_array['email'].')'; + } if (!$this->IsWithinBitRange($source_data_array['rating'], 8, false)) { $this->errors[] = 'Invalid Rating byte in '.$frame_name.' ('.$source_data_array['rating'].') (range = 0 to 255)'; - } elseif (!IsValidEmail($source_data_array['email'])) { - $this->errors[] = 'Invalid Email in '.$frame_name.' ('.$source_data_array['email'].')'; } else { $framedata .= str_replace("\x00", '', $source_data_array['email'])."\x00"; $framedata .= chr($source_data_array['rating']); @@ -858,7 +932,7 @@ class getid3_write_id3v2 $this->errors[] = 'Invalid Offset To Next Tag in '.$frame_name; } else { $framedata .= getid3_lib::BigEndian2String($source_data_array['buffersize'], 3, false); - $flag .= '0000000'; + $flag = '0000000'; $flag .= $source_data_array['flags']['embededinfo'] ? '1' : '0'; $framedata .= chr(bindec($flag)); $framedata .= getid3_lib::BigEndian2String($source_data_array['nexttagoffset'], 4, false); @@ -890,7 +964,7 @@ class getid3_write_id3v2 // ID and additional data if (!getid3_id3v2::IsValidID3v2FrameName($source_data_array['frameid'], $this->majorversion)) { $this->errors[] = 'Invalid Frame Identifier in '.$frame_name.' ('.$source_data_array['frameid'].')'; - } elseif (!$this->IsValidURL($source_data_array['data'], true, false)) { + } elseif (!$this->IsValidURL($source_data_array['data'], true)) { //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; // probably should be an error, need to rewrite IsValidURL() to handle other encodings $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; @@ -937,6 +1011,7 @@ class getid3_write_id3v2 } else { $this->errors[] = $source_data_array['frameid'].' is not a valid Frame Identifier in '.$frame_name.' (in ID3v2.'.$this->majorversion.')'; } + break; default: if ((substr($source_data_array['frameid'], 0, 1) == 'T') || (substr($source_data_array['frameid'], 0, 1) == 'W')) { @@ -989,9 +1064,9 @@ class getid3_write_id3v2 $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')'; - } elseif (!$this->IsANumber($source_data_array['pricepaid']['value'], false)) { + } elseif (!getid3_id3v2::IsANumber($source_data_array['pricepaid']['value'], false)) { $this->errors[] = 'Invalid Price Paid in '.$frame_name.' ('.$source_data_array['pricepaid']['value'].')'; - } elseif (!$this->IsValidDateStampString($source_data_array['purchasedate'])) { + } elseif (!getid3_id3v2::IsValidDateStampString($source_data_array['purchasedate'])) { $this->errors[] = 'Invalid Date Of Purchase in '.$frame_name.' ('.$source_data_array['purchasedate'].') (format = YYYYMMDD)'; } else { $framedata .= chr($source_data_array['encodingid']); @@ -1015,9 +1090,9 @@ class getid3_write_id3v2 $source_data_array['encodingid'] = (isset($source_data_array['encodingid']) ? $source_data_array['encodingid'] : $this->id3v2_default_encodingid); if (!$this->ID3v2IsValidTextEncoding($source_data_array['encodingid'])) { $this->errors[] = 'Invalid Text Encoding in '.$frame_name.' ('.$source_data_array['encodingid'].')'; - } elseif (!$this->IsValidDateStampString($source_data_array['pricevaliduntil'])) { + } elseif (!getid3_id3v2::IsValidDateStampString($source_data_array['pricevaliduntil'])) { $this->errors[] = 'Invalid Valid Until date in '.$frame_name.' ('.$source_data_array['pricevaliduntil'].') (format = YYYYMMDD)'; - } elseif (!$this->IsValidURL($source_data_array['contacturl'], false, true)) { + } elseif (!$this->IsValidURL($source_data_array['contacturl'], false)) { $this->errors[] = 'Invalid Contact URL in '.$frame_name.' ('.$source_data_array['contacturl'].') (allowed schemes: http, https, ftp, mailto)'; } elseif (!$this->ID3v2IsValidCOMRreceivedAs($source_data_array['receivedasid'])) { $this->errors[] = 'Invalid Received As byte in '.$frame_name.' ('.$source_data_array['contacturl'].') (range = 0 to 8)'; @@ -1025,7 +1100,7 @@ class getid3_write_id3v2 $this->errors[] = 'Invalid MIME Type in '.$frame_name.' ('.$source_data_array['mime'].')'; } else { $framedata .= chr($source_data_array['encodingid']); - unset($pricestring); + $pricestrings = array(); foreach ($source_data_array['price'] as $key => $val) { if ($this->ID3v2IsValidPriceString($key.$val['value'])) { $pricestrings[] = $key.$val['value']; @@ -1162,9 +1237,9 @@ class getid3_write_id3v2 break; default: - if ((($this->majorversion == 2) && (strlen($frame_name) != 3)) || (($this->majorversion > 2) && (strlen($frame_name) != 4))) { + if (/*(($this->majorversion == 2) && (strlen($frame_name) != 3)) || (($this->majorversion > 2) && (*/strlen($frame_name) != 4/*))*/) { $this->errors[] = 'Invalid frame name "'.$frame_name.'" for ID3v2.'.$this->majorversion; - } elseif ($frame_name{0} == 'T') { + } elseif ($frame_name[0] == 'T') { // 4.2. T??? Text information frames // Text encoding $xx // Information @@ -1175,10 +1250,10 @@ class getid3_write_id3v2 $framedata .= chr($source_data_array['encodingid']); $framedata .= $source_data_array['data']; } - } elseif ($frame_name{0} == 'W') { + } elseif ($frame_name[0] == 'W') { // 4.3. W??? URL link frames // URL - if (!$this->IsValidURL($source_data_array['data'], false, false)) { + if (!$this->IsValidURL($source_data_array['data'], false)) { //$this->errors[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; // probably should be an error, need to rewrite IsValidURL() to handle other encodings $this->warnings[] = 'Invalid URL in '.$frame_name.' ('.$source_data_array['data'].')'; @@ -1197,7 +1272,13 @@ class getid3_write_id3v2 return $framedata; } - function ID3v2FrameIsAllowed($frame_name, $source_data_array) { + /** + * @param string|null $frame_name + * @param array $source_data_array + * + * @return bool + */ + public function ID3v2FrameIsAllowed($frame_name, $source_data_array) { static $PreviousFrames = array(); if ($frame_name === null) { @@ -1206,7 +1287,6 @@ class getid3_write_id3v2 $PreviousFrames = array(); return true; } - if ($this->majorversion == 4) { switch ($frame_name) { case 'UFID': @@ -1326,7 +1406,7 @@ class getid3_write_id3v2 break; default: - if (($frame_name{0} != 'T') && ($frame_name{0} != 'W')) { + if (($frame_name[0] != 'T') && ($frame_name[0] != 'W')) { $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name; } break; @@ -1449,7 +1529,7 @@ class getid3_write_id3v2 break; default: - if (($frame_name{0} != 'T') && ($frame_name{0} != 'W')) { + if (($frame_name[0] != 'T') && ($frame_name[0] != 'W')) { $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name; } break; @@ -1541,7 +1621,7 @@ class getid3_write_id3v2 break; default: - if (($frame_name{0} != 'T') && ($frame_name{0} != 'W')) { + if (($frame_name[0] != 'T') && ($frame_name[0] != 'W')) { $this->errors[] = 'Frame not allowed in ID3v2.'.$this->majorversion.': '.$frame_name; } break; @@ -1554,7 +1634,12 @@ class getid3_write_id3v2 return true; } - function GenerateID3v2Tag($noerrorsonly=true) { + /** + * @param bool $noerrorsonly + * + * @return string|false + */ + public function GenerateID3v2Tag($noerrorsonly=true) { $this->ID3v2FrameIsAllowed(null, ''); // clear static array in case this isn't the first call to $this->GenerateID3v2Tag() $tagstring = ''; @@ -1566,6 +1651,9 @@ class getid3_write_id3v2 unset($frame_flags); $frame_data = false; if ($this->ID3v2FrameIsAllowed($frame_name, $source_data_array)) { + if(array_key_exists('description', $source_data_array) && array_key_exists('encodingid', $source_data_array) && array_key_exists('encoding', $this->tag_data)) { + $source_data_array['description'] = getid3_lib::iconv_fallback($this->tag_data['encoding'], $source_data_array['encoding'], $source_data_array['description']); + } if ($frame_data = $this->GenerateID3v2FrameData($frame_name, $source_data_array)) { $FrameUnsynchronisation = false; if ($this->majorversion >= 4) { @@ -1604,18 +1692,18 @@ class getid3_write_id3v2 if ($noerrorsonly) { return false; } else { - unset($frame_name); + $frame_name = null; } } } else { // ignore any invalid frame names, including 'title', 'header', etc $this->warnings[] = 'Ignoring invalid ID3v2 frame type: "'.$frame_name.'"'; - unset($frame_name); + $frame_name = null; unset($frame_length); unset($frame_flags); unset($frame_data); } - if (isset($frame_name) && isset($frame_length) && isset($frame_flags) && isset($frame_data)) { + if (null !== $frame_name && isset($frame_length) && isset($frame_flags) && isset($frame_data)) { $tagstring .= $frame_name.$frame_length.$frame_flags.$frame_data; } } @@ -1639,7 +1727,7 @@ class getid3_write_id3v2 } $footer = false; // ID3v2 footers not yet supported in getID3() - if (!$footer && ($this->paddedlength > (strlen($tagstring) + getid3_id3v2::ID3v2HeaderLength($this->majorversion)))) { + if (/*!$footer && */($this->paddedlength > (strlen($tagstring) + getid3_id3v2::ID3v2HeaderLength($this->majorversion)))) { // pad up to $paddedlength bytes if unpadded tag is shorter than $paddedlength // "Furthermore it MUST NOT have any padding when a tag footer is added to the tag." if (($this->paddedlength - strlen($tagstring) - getid3_id3v2::ID3v2HeaderLength($this->majorversion)) > 0) { @@ -1665,20 +1753,31 @@ class getid3_write_id3v2 return false; } - function ID3v2IsValidPriceString($pricestring) { + /** + * @param string $pricestring + * + * @return bool + */ + public function ID3v2IsValidPriceString($pricestring) { if (getid3_id3v2::LanguageLookup(substr($pricestring, 0, 3), true) == '') { return false; - } elseif (!$this->IsANumber(substr($pricestring, 3), true)) { + } elseif (!getid3_id3v2::IsANumber(substr($pricestring, 3), true)) { return false; } return true; } - function ID3v2FrameFlagsLookupTagAlter($framename) { + /** + * @param string $framename + * + * @return bool + */ + public function ID3v2FrameFlagsLookupTagAlter($framename) { // unfinished switch ($framename) { case 'RGAD': $allow = true; + break; default: $allow = false; break; @@ -1686,20 +1785,28 @@ class getid3_write_id3v2 return $allow; } - function ID3v2FrameFlagsLookupFileAlter($framename) { + /** + * @param string $framename + * + * @return bool + */ + public function ID3v2FrameFlagsLookupFileAlter($framename) { // unfinished switch ($framename) { case 'RGAD': return false; - break; default: return false; - break; } } - function ID3v2IsValidETCOevent($eventid) { + /** + * @param int $eventid + * + * @return bool + */ + public function ID3v2IsValidETCOevent($eventid) { if (($eventid < 0) || ($eventid > 0xFF)) { // outside range of 1 byte return false; @@ -1719,7 +1826,12 @@ class getid3_write_id3v2 return true; } - function ID3v2IsValidSYLTtype($contenttype) { + /** + * @param int $contenttype + * + * @return bool + */ + public function ID3v2IsValidSYLTtype($contenttype) { if (($contenttype >= 0) && ($contenttype <= 8) && ($this->majorversion == 4)) { return true; } elseif (($contenttype >= 0) && ($contenttype <= 6) && ($this->majorversion == 3)) { @@ -1728,21 +1840,36 @@ class getid3_write_id3v2 return false; } - function ID3v2IsValidRVA2channeltype($channeltype) { + /** + * @param int $channeltype + * + * @return bool + */ + public function ID3v2IsValidRVA2channeltype($channeltype) { if (($channeltype >= 0) && ($channeltype <= 8) && ($this->majorversion == 4)) { return true; } return false; } - function ID3v2IsValidAPICpicturetype($picturetype) { + /** + * @param int $picturetype + * + * @return bool + */ + public function ID3v2IsValidAPICpicturetype($picturetype) { if (($picturetype >= 0) && ($picturetype <= 0x14) && ($this->majorversion >= 2) && ($this->majorversion <= 4)) { return true; } return false; } - function ID3v2IsValidAPICimageformat($imageformat) { + /** + * @param int|string $imageformat + * + * @return bool + */ + public function ID3v2IsValidAPICimageformat($imageformat) { if ($imageformat == '-->') { return true; } elseif ($this->majorversion == 2) { @@ -1757,36 +1884,66 @@ class getid3_write_id3v2 return false; } - function ID3v2IsValidCOMRreceivedAs($receivedas) { + /** + * @param int $receivedas + * + * @return bool + */ + public function ID3v2IsValidCOMRreceivedAs($receivedas) { if (($this->majorversion >= 3) && ($receivedas >= 0) && ($receivedas <= 8)) { return true; } return false; } - function ID3v2IsValidRGADname($RGADname) { + /** + * @param int $RGADname + * + * @return bool + */ + public static function ID3v2IsValidRGADname($RGADname) { if (($RGADname >= 0) && ($RGADname <= 2)) { return true; } return false; } - function ID3v2IsValidRGADoriginator($RGADoriginator) { + /** + * @param int $RGADoriginator + * + * @return bool + */ + public static function ID3v2IsValidRGADoriginator($RGADoriginator) { if (($RGADoriginator >= 0) && ($RGADoriginator <= 3)) { return true; } return false; } - function ID3v2IsValidTextEncoding($textencodingbyte) { + /** + * @param int $textencodingbyte + * + * @return bool + */ + public function ID3v2IsValidTextEncoding($textencodingbyte) { + // 0 = ISO-8859-1 + // 1 = UTF-16 with BOM + // 2 = UTF-16BE without BOM + // 3 = UTF-8 static $ID3v2IsValidTextEncoding_cache = array( - 2 => array(true, true), - 3 => array(true, true), - 4 => array(true, true, true, true)); + 2 => array(true, true), // ID3v2.2 - allow 0=ISO-8859-1, 1=UTF-16 + 3 => array(true, true), // ID3v2.3 - allow 0=ISO-8859-1, 1=UTF-16 + 4 => array(true, true, true, true), // ID3v2.4 - allow 0=ISO-8859-1, 1=UTF-16, 2=UTF-16BE, 3=UTF-8 + ); return isset($ID3v2IsValidTextEncoding_cache[$this->majorversion][$textencodingbyte]); } - function Unsynchronise($data) { + /** + * @param string $data + * + * @return string + */ + public static function Unsynchronise($data) { // Whenever a false synchronisation is found within the tag, one zeroed // byte is inserted after the first false synchronisation byte. The // format of a correct sync that should be altered by ID3 encoders is as @@ -1803,10 +1960,10 @@ class getid3_write_id3v2 $unsyncheddata = ''; $datalength = strlen($data); for ($i = 0; $i < $datalength; $i++) { - $thischar = $data{$i}; + $thischar = $data[$i]; $unsyncheddata .= $thischar; if ($thischar == "\xFF") { - $nextchar = ord($data{$i + 1}); + $nextchar = ord($data[$i + 1]); if (($nextchar & 0xE0) == 0xE0) { // previous byte = 11111111, this byte = 111????? $unsyncheddata .= "\x00"; @@ -1816,14 +1973,19 @@ class getid3_write_id3v2 return $unsyncheddata; } - function is_hash($var) { - // written by dev-nullØchristophe*vg + /** + * @param mixed $var + * + * @return bool + */ + public function is_hash($var) { + // written by dev-nullØchristophe*vg // taken from http://www.php.net/manual/en/function.array-merge-recursive.php if (is_array($var)) { $keys = array_keys($var); $all_num = true; - for ($i = 0; $i < count($keys); $i++) { - if (is_string($keys[$i])) { + foreach ($keys as $key) { + if (is_string($key)) { return true; } } @@ -1831,8 +1993,14 @@ class getid3_write_id3v2 return false; } - function array_join_merge($arr1, $arr2) { - // written by dev-nullØchristophe*vg + /** + * @param mixed $arr1 + * @param mixed $arr2 + * + * @return array + */ + public function array_join_merge($arr1, $arr2) { + // written by dev-nullØchristophe*vg // taken from http://www.php.net/manual/en/function.array-merge-recursive.php if (is_array($arr1) && is_array($arr2)) { // the same -> merge @@ -1855,14 +2023,23 @@ class getid3_write_id3v2 } } - function IsValidMIMEstring($mimestring) { - if ((strlen($mimestring) >= 3) && (strpos($mimestring, '/') > 0) && (strpos($mimestring, '/') < (strlen($mimestring) - 1))) { - return true; - } - return false; + /** + * @param string $mimestring + * + * @return false|int + */ + public static function IsValidMIMEstring($mimestring) { + return preg_match('#^.+/.+$#', $mimestring); } - function IsWithinBitRange($number, $maxbits, $signed=false) { + /** + * @param int $number + * @param int $maxbits + * @param bool $signed + * + * @return bool + */ + public static function IsWithinBitRange($number, $maxbits, $signed=false) { if ($signed) { if (($number > (0 - pow(2, $maxbits - 1))) && ($number <= pow(2, $maxbits - 1))) { return true; @@ -1875,21 +2052,26 @@ class getid3_write_id3v2 return false; } - function safe_parse_url($url) { - ob_start(); - $parts = parse_url($url); - $errormessage = ob_get_contents(); - ob_end_clean(); - $parts['scheme'] = (isset($parts['scheme']) ? $parts['scheme'] : ''); - $parts['host'] = (isset($parts['host']) ? $parts['host'] : ''); - $parts['user'] = (isset($parts['user']) ? $parts['user'] : ''); - $parts['pass'] = (isset($parts['pass']) ? $parts['pass'] : ''); - $parts['path'] = (isset($parts['path']) ? $parts['path'] : ''); - $parts['query'] = (isset($parts['query']) ? $parts['query'] : ''); - return $parts; + /** + * @param string $email + * + * @return false|int|mixed + */ + public static function IsValidEmail($email) { + if (function_exists('filter_var')) { + return filter_var($email, FILTER_VALIDATE_EMAIL); + } + // VERY crude email validation + return preg_match('#^[^ ]+@[a-z\\-\\.]+\\.[a-z]{2,}$#', $email); } - function IsValidURL($url, $allowUserPass=false) { + /** + * @param string $url + * @param bool $allowUserPass + * + * @return bool + */ + public static function IsValidURL($url, $allowUserPass=false) { if ($url == '') { return false; } @@ -1900,173 +2082,243 @@ class getid3_write_id3v2 return false; } } + // 2016-06-08: relax URL checking to avoid falsely rejecting valid URLs, leave URL validation to the user + // https://www.getid3.org/phpBB3/viewtopic.php?t=1926 + return true; + /* if ($parts = $this->safe_parse_url($url)) { if (($parts['scheme'] != 'http') && ($parts['scheme'] != 'https') && ($parts['scheme'] != 'ftp') && ($parts['scheme'] != 'gopher')) { return false; - } elseif (!preg_match("#^[[:alnum:]]([-.]?[0-9a-z])*\.[a-z]{2,3}#i$", $parts['host'], $regs) && !preg_match('#^[0-9]{1,3}(\.[0-9]{1,3}){3}$#', $parts['host'])) { + } elseif (!preg_match('#^[[:alnum:]]([-.]?[0-9a-z])*\\.[a-z]{2,3}$#i', $parts['host'], $regs) && !preg_match('#^[0-9]{1,3}(\\.[0-9]{1,3}){3}$#', $parts['host'])) { return false; - } elseif (!preg_match("#^([[:alnum:]-]|[\_])*$#i", $parts['user'], $regs)) { + } elseif (!preg_match('#^([[:alnum:]-]|[\\_])*$#i', $parts['user'], $regs)) { return false; - } elseif (!preg_match("#^([[:alnum:]-]|[\_])*$#i", $parts['pass'], $regs)) { + } elseif (!preg_match('#^([[:alnum:]-]|[\\_])*$#i', $parts['pass'], $regs)) { return false; - } elseif (!preg_match("#^[[:alnum:]/_\.@~-]*$#i", $parts['path'], $regs)) { + } elseif (!preg_match('#^[[:alnum:]/_\\.@~-]*$#i', $parts['path'], $regs)) { return false; - } elseif (!preg_match("#^[[:alnum:]?&=+:;_()%#/,\.-]*$#i", $parts['query'], $regs)) { + } elseif (!empty($parts['query']) && !preg_match('#^[[:alnum:]?&=+:;_()%\\#/,\\.-]*$#i', $parts['query'], $regs)) { return false; } else { return true; } } return false; + */ } - static function ID3v2ShortFrameNameLookup($majorversion, $long_description) { + /** + * @param string $url + * + * @return array + */ + public static function safe_parse_url($url) { + $parts = @parse_url($url); + $parts['scheme'] = (isset($parts['scheme']) ? $parts['scheme'] : ''); + $parts['host'] = (isset($parts['host']) ? $parts['host'] : ''); + $parts['user'] = (isset($parts['user']) ? $parts['user'] : ''); + $parts['pass'] = (isset($parts['pass']) ? $parts['pass'] : ''); + $parts['path'] = (isset($parts['path']) ? $parts['path'] : ''); + $parts['query'] = (isset($parts['query']) ? $parts['query'] : ''); + return $parts; + } + + /** + * @param int $majorversion + * @param string $long_description + * + * @return string + */ + public static function ID3v2ShortFrameNameLookup($majorversion, $long_description) { $long_description = str_replace(' ', '_', strtolower(trim($long_description))); static $ID3v2ShortFrameNameLookup = array(); if (empty($ID3v2ShortFrameNameLookup)) { // The following are unique to ID3v2.2 - $ID3v2ShortFrameNameLookup[2]['comment'] = 'COM'; - $ID3v2ShortFrameNameLookup[2]['album'] = 'TAL'; - $ID3v2ShortFrameNameLookup[2]['beats_per_minute'] = 'TBP'; - $ID3v2ShortFrameNameLookup[2]['composer'] = 'TCM'; - $ID3v2ShortFrameNameLookup[2]['genre'] = 'TCO'; - $ID3v2ShortFrameNameLookup[2]['itunescompilation'] = 'TCP'; - $ID3v2ShortFrameNameLookup[2]['copyright'] = 'TCR'; - $ID3v2ShortFrameNameLookup[2]['encoded_by'] = 'TEN'; - $ID3v2ShortFrameNameLookup[2]['language'] = 'TLA'; - $ID3v2ShortFrameNameLookup[2]['length'] = 'TLE'; - $ID3v2ShortFrameNameLookup[2]['original_artist'] = 'TOA'; - $ID3v2ShortFrameNameLookup[2]['original_filename'] = 'TOF'; - $ID3v2ShortFrameNameLookup[2]['original_lyricist'] = 'TOL'; - $ID3v2ShortFrameNameLookup[2]['original_album_title'] = 'TOT'; - $ID3v2ShortFrameNameLookup[2]['artist'] = 'TP1'; - $ID3v2ShortFrameNameLookup[2]['band'] = 'TP2'; - $ID3v2ShortFrameNameLookup[2]['conductor'] = 'TP3'; - $ID3v2ShortFrameNameLookup[2]['remixer'] = 'TP4'; - $ID3v2ShortFrameNameLookup[2]['publisher'] = 'TPB'; - $ID3v2ShortFrameNameLookup[2]['isrc'] = 'TRC'; - $ID3v2ShortFrameNameLookup[2]['tracknumber'] = 'TRK'; - $ID3v2ShortFrameNameLookup[2]['size'] = 'TSI'; - $ID3v2ShortFrameNameLookup[2]['encoder_settings'] = 'TSS'; - $ID3v2ShortFrameNameLookup[2]['description'] = 'TT1'; - $ID3v2ShortFrameNameLookup[2]['title'] = 'TT2'; - $ID3v2ShortFrameNameLookup[2]['subtitle'] = 'TT3'; - $ID3v2ShortFrameNameLookup[2]['lyricist'] = 'TXT'; - $ID3v2ShortFrameNameLookup[2]['user_text'] = 'TXX'; - $ID3v2ShortFrameNameLookup[2]['year'] = 'TYE'; - $ID3v2ShortFrameNameLookup[2]['unique_file_identifier'] = 'UFI'; - $ID3v2ShortFrameNameLookup[2]['unsynchronised_lyrics'] = 'ULT'; - $ID3v2ShortFrameNameLookup[2]['url_file'] = 'WAF'; - $ID3v2ShortFrameNameLookup[2]['url_artist'] = 'WAR'; - $ID3v2ShortFrameNameLookup[2]['url_source'] = 'WAS'; - $ID3v2ShortFrameNameLookup[2]['copyright_information'] = 'WCP'; - $ID3v2ShortFrameNameLookup[2]['url_publisher'] = 'WPB'; - $ID3v2ShortFrameNameLookup[2]['url_user'] = 'WXX'; + $ID3v2ShortFrameNameLookup[2]['recommended_buffer_size'] = 'BUF'; + $ID3v2ShortFrameNameLookup[2]['comment'] = 'COM'; + $ID3v2ShortFrameNameLookup[2]['audio_encryption'] = 'CRA'; + $ID3v2ShortFrameNameLookup[2]['encrypted_meta_frame'] = 'CRM'; + $ID3v2ShortFrameNameLookup[2]['equalisation'] = 'EQU'; + $ID3v2ShortFrameNameLookup[2]['event_timing_codes'] = 'ETC'; + $ID3v2ShortFrameNameLookup[2]['general_encapsulated_object'] = 'GEO'; + $ID3v2ShortFrameNameLookup[2]['involved_people_list'] = 'IPL'; + $ID3v2ShortFrameNameLookup[2]['linked_information'] = 'LNK'; + $ID3v2ShortFrameNameLookup[2]['music_cd_identifier'] = 'MCI'; + $ID3v2ShortFrameNameLookup[2]['mpeg_location_lookup_table'] = 'MLL'; + $ID3v2ShortFrameNameLookup[2]['attached_picture'] = 'PIC'; + $ID3v2ShortFrameNameLookup[2]['popularimeter'] = 'POP'; + $ID3v2ShortFrameNameLookup[2]['reverb'] = 'REV'; + $ID3v2ShortFrameNameLookup[2]['relative_volume_adjustment'] = 'RVA'; + $ID3v2ShortFrameNameLookup[2]['synchronised_lyric'] = 'SLT'; + $ID3v2ShortFrameNameLookup[2]['synchronised_tempo_codes'] = 'STC'; + $ID3v2ShortFrameNameLookup[2]['album'] = 'TAL'; + $ID3v2ShortFrameNameLookup[2]['beats_per_minute'] = 'TBP'; + $ID3v2ShortFrameNameLookup[2]['bpm'] = 'TBP'; + $ID3v2ShortFrameNameLookup[2]['composer'] = 'TCM'; + $ID3v2ShortFrameNameLookup[2]['genre'] = 'TCO'; + $ID3v2ShortFrameNameLookup[2]['part_of_a_compilation'] = 'TCP'; + $ID3v2ShortFrameNameLookup[2]['copyright_message'] = 'TCR'; + $ID3v2ShortFrameNameLookup[2]['date'] = 'TDA'; + $ID3v2ShortFrameNameLookup[2]['playlist_delay'] = 'TDY'; + $ID3v2ShortFrameNameLookup[2]['encoded_by'] = 'TEN'; + $ID3v2ShortFrameNameLookup[2]['file_type'] = 'TFT'; + $ID3v2ShortFrameNameLookup[2]['time'] = 'TIM'; + $ID3v2ShortFrameNameLookup[2]['initial_key'] = 'TKE'; + $ID3v2ShortFrameNameLookup[2]['language'] = 'TLA'; + $ID3v2ShortFrameNameLookup[2]['length'] = 'TLE'; + $ID3v2ShortFrameNameLookup[2]['media_type'] = 'TMT'; + $ID3v2ShortFrameNameLookup[2]['original_artist'] = 'TOA'; + $ID3v2ShortFrameNameLookup[2]['original_filename'] = 'TOF'; + $ID3v2ShortFrameNameLookup[2]['original_lyricist'] = 'TOL'; + $ID3v2ShortFrameNameLookup[2]['original_year'] = 'TOR'; + $ID3v2ShortFrameNameLookup[2]['original_album'] = 'TOT'; + $ID3v2ShortFrameNameLookup[2]['artist'] = 'TP1'; + $ID3v2ShortFrameNameLookup[2]['band'] = 'TP2'; + $ID3v2ShortFrameNameLookup[2]['conductor'] = 'TP3'; + $ID3v2ShortFrameNameLookup[2]['remixer'] = 'TP4'; + $ID3v2ShortFrameNameLookup[2]['part_of_a_set'] = 'TPA'; + $ID3v2ShortFrameNameLookup[2]['publisher'] = 'TPB'; + $ID3v2ShortFrameNameLookup[2]['isrc'] = 'TRC'; + $ID3v2ShortFrameNameLookup[2]['recording_dates'] = 'TRD'; + $ID3v2ShortFrameNameLookup[2]['tracknumber'] = 'TRK'; + $ID3v2ShortFrameNameLookup[2]['track_number'] = 'TRK'; + $ID3v2ShortFrameNameLookup[2]['album_artist_sort_order'] = 'TS2'; + $ID3v2ShortFrameNameLookup[2]['album_sort_order'] = 'TSA'; + $ID3v2ShortFrameNameLookup[2]['composer_sort_order'] = 'TSC'; + $ID3v2ShortFrameNameLookup[2]['size'] = 'TSI'; + $ID3v2ShortFrameNameLookup[2]['performer_sort_order'] = 'TSP'; + $ID3v2ShortFrameNameLookup[2]['encoder_settings'] = 'TSS'; + $ID3v2ShortFrameNameLookup[2]['title_sort_order'] = 'TST'; + $ID3v2ShortFrameNameLookup[2]['content_group_description'] = 'TT1'; + $ID3v2ShortFrameNameLookup[2]['title'] = 'TT2'; + $ID3v2ShortFrameNameLookup[2]['subtitle'] = 'TT3'; + $ID3v2ShortFrameNameLookup[2]['lyricist'] = 'TXT'; + $ID3v2ShortFrameNameLookup[2]['text'] = 'TXX'; + $ID3v2ShortFrameNameLookup[2]['year'] = 'TYE'; + $ID3v2ShortFrameNameLookup[2]['unique_file_identifier'] = 'UFI'; + $ID3v2ShortFrameNameLookup[2]['unsynchronised_lyric'] = 'ULT'; + $ID3v2ShortFrameNameLookup[2]['url_file'] = 'WAF'; + $ID3v2ShortFrameNameLookup[2]['url_artist'] = 'WAR'; + $ID3v2ShortFrameNameLookup[2]['url_source'] = 'WAS'; + $ID3v2ShortFrameNameLookup[2]['commercial_information'] = 'WCM'; + $ID3v2ShortFrameNameLookup[2]['copyright'] = 'WCP'; + $ID3v2ShortFrameNameLookup[2]['url_publisher'] = 'WPB'; + $ID3v2ShortFrameNameLookup[2]['url_user'] = 'WXX'; // The following are common to ID3v2.3 and ID3v2.4 - $ID3v2ShortFrameNameLookup[3]['audio_encryption'] = 'AENC'; - $ID3v2ShortFrameNameLookup[3]['attached_picture'] = 'APIC'; - $ID3v2ShortFrameNameLookup[3]['comment'] = 'COMM'; - $ID3v2ShortFrameNameLookup[3]['commercial'] = 'COMR'; - $ID3v2ShortFrameNameLookup[3]['encryption_method_registration'] = 'ENCR'; - $ID3v2ShortFrameNameLookup[3]['event_timing_codes'] = 'ETCO'; - $ID3v2ShortFrameNameLookup[3]['general_encapsulated_object'] = 'GEOB'; - $ID3v2ShortFrameNameLookup[3]['group_identification_registration'] = 'GRID'; - $ID3v2ShortFrameNameLookup[3]['linked_information'] = 'LINK'; - $ID3v2ShortFrameNameLookup[3]['music_cd_identifier'] = 'MCDI'; - $ID3v2ShortFrameNameLookup[3]['mpeg_location_lookup_table'] = 'MLLT'; - $ID3v2ShortFrameNameLookup[3]['ownership'] = 'OWNE'; - $ID3v2ShortFrameNameLookup[3]['play_counter'] = 'PCNT'; - $ID3v2ShortFrameNameLookup[3]['popularimeter'] = 'POPM'; - $ID3v2ShortFrameNameLookup[3]['position_synchronisation'] = 'POSS'; - $ID3v2ShortFrameNameLookup[3]['private'] = 'PRIV'; - $ID3v2ShortFrameNameLookup[3]['recommended_buffer_size'] = 'RBUF'; - $ID3v2ShortFrameNameLookup[3]['reverb'] = 'RVRB'; - $ID3v2ShortFrameNameLookup[3]['synchronised_lyrics'] = 'SYLT'; - $ID3v2ShortFrameNameLookup[3]['synchronised_tempo_codes'] = 'SYTC'; - $ID3v2ShortFrameNameLookup[3]['album'] = 'TALB'; - $ID3v2ShortFrameNameLookup[3]['beats_per_minute'] = 'TBPM'; - $ID3v2ShortFrameNameLookup[3]['itunescompilation'] = 'TCMP'; - $ID3v2ShortFrameNameLookup[3]['composer'] = 'TCOM'; - $ID3v2ShortFrameNameLookup[3]['genre'] = 'TCON'; - $ID3v2ShortFrameNameLookup[3]['copyright'] = 'TCOP'; - $ID3v2ShortFrameNameLookup[3]['playlist_delay'] = 'TDLY'; - $ID3v2ShortFrameNameLookup[3]['encoded_by'] = 'TENC'; - $ID3v2ShortFrameNameLookup[3]['lyricist'] = 'TEXT'; - $ID3v2ShortFrameNameLookup[3]['file_type'] = 'TFLT'; - $ID3v2ShortFrameNameLookup[3]['content_group_description'] = 'TIT1'; - $ID3v2ShortFrameNameLookup[3]['title'] = 'TIT2'; - $ID3v2ShortFrameNameLookup[3]['subtitle'] = 'TIT3'; - $ID3v2ShortFrameNameLookup[3]['initial_key'] = 'TKEY'; - $ID3v2ShortFrameNameLookup[3]['language'] = 'TLAN'; - $ID3v2ShortFrameNameLookup[3]['length'] = 'TLEN'; - $ID3v2ShortFrameNameLookup[3]['media_type'] = 'TMED'; - $ID3v2ShortFrameNameLookup[3]['original_album_title'] = 'TOAL'; - $ID3v2ShortFrameNameLookup[3]['original_filename'] = 'TOFN'; - $ID3v2ShortFrameNameLookup[3]['original_lyricist'] = 'TOLY'; - $ID3v2ShortFrameNameLookup[3]['original_artist'] = 'TOPE'; - $ID3v2ShortFrameNameLookup[3]['file_owner'] = 'TOWN'; - $ID3v2ShortFrameNameLookup[3]['artist'] = 'TPE1'; - $ID3v2ShortFrameNameLookup[3]['band'] = 'TPE2'; - $ID3v2ShortFrameNameLookup[3]['conductor'] = 'TPE3'; - $ID3v2ShortFrameNameLookup[3]['remixer'] = 'TPE4'; - $ID3v2ShortFrameNameLookup[3]['part_of_a_set'] = 'TPOS'; - $ID3v2ShortFrameNameLookup[3]['publisher'] = 'TPUB'; - $ID3v2ShortFrameNameLookup[3]['tracknumber'] = 'TRCK'; - $ID3v2ShortFrameNameLookup[3]['internet_radio_station_name'] = 'TRSN'; - $ID3v2ShortFrameNameLookup[3]['internet_radio_station_owner'] = 'TRSO'; - $ID3v2ShortFrameNameLookup[3]['isrc'] = 'TSRC'; - $ID3v2ShortFrameNameLookup[3]['encoder_settings'] = 'TSSE'; - $ID3v2ShortFrameNameLookup[3]['user_text'] = 'TXXX'; - $ID3v2ShortFrameNameLookup[3]['unique_file_identifier'] = 'UFID'; - $ID3v2ShortFrameNameLookup[3]['terms_of_use'] = 'USER'; - $ID3v2ShortFrameNameLookup[3]['unsynchronised_lyrics'] = 'USLT'; - $ID3v2ShortFrameNameLookup[3]['commercial'] = 'WCOM'; - $ID3v2ShortFrameNameLookup[3]['copyright_information'] = 'WCOP'; - $ID3v2ShortFrameNameLookup[3]['url_file'] = 'WOAF'; - $ID3v2ShortFrameNameLookup[3]['url_artist'] = 'WOAR'; - $ID3v2ShortFrameNameLookup[3]['url_source'] = 'WOAS'; - $ID3v2ShortFrameNameLookup[3]['url_station'] = 'WORS'; - $ID3v2ShortFrameNameLookup[3]['payment'] = 'WPAY'; - $ID3v2ShortFrameNameLookup[3]['url_publisher'] = 'WPUB'; - $ID3v2ShortFrameNameLookup[3]['url_user'] = 'WXXX'; + $ID3v2ShortFrameNameLookup[3]['audio_encryption'] = 'AENC'; + $ID3v2ShortFrameNameLookup[3]['attached_picture'] = 'APIC'; + $ID3v2ShortFrameNameLookup[3]['picture'] = 'APIC'; + $ID3v2ShortFrameNameLookup[3]['comment'] = 'COMM'; + $ID3v2ShortFrameNameLookup[3]['commercial_frame'] = 'COMR'; + $ID3v2ShortFrameNameLookup[3]['encryption_method_registration'] = 'ENCR'; + $ID3v2ShortFrameNameLookup[3]['event_timing_codes'] = 'ETCO'; + $ID3v2ShortFrameNameLookup[3]['general_encapsulated_object'] = 'GEOB'; + $ID3v2ShortFrameNameLookup[3]['group_identification_registration'] = 'GRID'; + $ID3v2ShortFrameNameLookup[3]['linked_information'] = 'LINK'; + $ID3v2ShortFrameNameLookup[3]['music_cd_identifier'] = 'MCDI'; + $ID3v2ShortFrameNameLookup[3]['mpeg_location_lookup_table'] = 'MLLT'; + $ID3v2ShortFrameNameLookup[3]['ownership_frame'] = 'OWNE'; + $ID3v2ShortFrameNameLookup[3]['play_counter'] = 'PCNT'; + $ID3v2ShortFrameNameLookup[3]['popularimeter'] = 'POPM'; + $ID3v2ShortFrameNameLookup[3]['position_synchronisation_frame'] = 'POSS'; + $ID3v2ShortFrameNameLookup[3]['private_frame'] = 'PRIV'; + $ID3v2ShortFrameNameLookup[3]['recommended_buffer_size'] = 'RBUF'; + $ID3v2ShortFrameNameLookup[3]['replay_gain_adjustment'] = 'RGAD'; + $ID3v2ShortFrameNameLookup[3]['reverb'] = 'RVRB'; + $ID3v2ShortFrameNameLookup[3]['synchronised_lyric'] = 'SYLT'; + $ID3v2ShortFrameNameLookup[3]['synchronised_tempo_codes'] = 'SYTC'; + $ID3v2ShortFrameNameLookup[3]['album'] = 'TALB'; + $ID3v2ShortFrameNameLookup[3]['beats_per_minute'] = 'TBPM'; + $ID3v2ShortFrameNameLookup[3]['bpm'] = 'TBPM'; + $ID3v2ShortFrameNameLookup[3]['part_of_a_compilation'] = 'TCMP'; + $ID3v2ShortFrameNameLookup[3]['composer'] = 'TCOM'; + $ID3v2ShortFrameNameLookup[3]['genre'] = 'TCON'; + $ID3v2ShortFrameNameLookup[3]['copyright_message'] = 'TCOP'; + $ID3v2ShortFrameNameLookup[3]['playlist_delay'] = 'TDLY'; + $ID3v2ShortFrameNameLookup[3]['encoded_by'] = 'TENC'; + $ID3v2ShortFrameNameLookup[3]['lyricist'] = 'TEXT'; + $ID3v2ShortFrameNameLookup[3]['file_type'] = 'TFLT'; + $ID3v2ShortFrameNameLookup[3]['content_group_description'] = 'TIT1'; + $ID3v2ShortFrameNameLookup[3]['title'] = 'TIT2'; + $ID3v2ShortFrameNameLookup[3]['subtitle'] = 'TIT3'; + $ID3v2ShortFrameNameLookup[3]['initial_key'] = 'TKEY'; + $ID3v2ShortFrameNameLookup[3]['language'] = 'TLAN'; + $ID3v2ShortFrameNameLookup[3]['length'] = 'TLEN'; + $ID3v2ShortFrameNameLookup[3]['media_type'] = 'TMED'; + $ID3v2ShortFrameNameLookup[3]['original_album'] = 'TOAL'; + $ID3v2ShortFrameNameLookup[3]['original_filename'] = 'TOFN'; + $ID3v2ShortFrameNameLookup[3]['original_lyricist'] = 'TOLY'; + $ID3v2ShortFrameNameLookup[3]['original_artist'] = 'TOPE'; + $ID3v2ShortFrameNameLookup[3]['file_owner'] = 'TOWN'; + $ID3v2ShortFrameNameLookup[3]['artist'] = 'TPE1'; + $ID3v2ShortFrameNameLookup[3]['band'] = 'TPE2'; + $ID3v2ShortFrameNameLookup[3]['conductor'] = 'TPE3'; + $ID3v2ShortFrameNameLookup[3]['remixer'] = 'TPE4'; + $ID3v2ShortFrameNameLookup[3]['part_of_a_set'] = 'TPOS'; + $ID3v2ShortFrameNameLookup[3]['publisher'] = 'TPUB'; + $ID3v2ShortFrameNameLookup[3]['tracknumber'] = 'TRCK'; + $ID3v2ShortFrameNameLookup[3]['track_number'] = 'TRCK'; + $ID3v2ShortFrameNameLookup[3]['internet_radio_station_name'] = 'TRSN'; + $ID3v2ShortFrameNameLookup[3]['internet_radio_station_owner'] = 'TRSO'; + $ID3v2ShortFrameNameLookup[3]['album_artist_sort_order'] = 'TSO2'; + $ID3v2ShortFrameNameLookup[3]['album_sort_order'] = 'TSOA'; + $ID3v2ShortFrameNameLookup[3]['composer_sort_order'] = 'TSOC'; + $ID3v2ShortFrameNameLookup[3]['performer_sort_order'] = 'TSOP'; + $ID3v2ShortFrameNameLookup[3]['title_sort_order'] = 'TSOT'; + $ID3v2ShortFrameNameLookup[3]['isrc'] = 'TSRC'; + $ID3v2ShortFrameNameLookup[3]['encoder_settings'] = 'TSSE'; + $ID3v2ShortFrameNameLookup[3]['text'] = 'TXXX'; + $ID3v2ShortFrameNameLookup[3]['unique_file_identifier'] = 'UFID'; + $ID3v2ShortFrameNameLookup[3]['terms_of_use'] = 'USER'; + $ID3v2ShortFrameNameLookup[3]['unsynchronised_lyric'] = 'USLT'; + $ID3v2ShortFrameNameLookup[3]['commercial_information'] = 'WCOM'; + $ID3v2ShortFrameNameLookup[3]['copyright'] = 'WCOP'; + $ID3v2ShortFrameNameLookup[3]['url_file'] = 'WOAF'; + $ID3v2ShortFrameNameLookup[3]['url_artist'] = 'WOAR'; + $ID3v2ShortFrameNameLookup[3]['url_source'] = 'WOAS'; + $ID3v2ShortFrameNameLookup[3]['url_station'] = 'WORS'; + $ID3v2ShortFrameNameLookup[3]['url_payment'] = 'WPAY'; + $ID3v2ShortFrameNameLookup[3]['url_publisher'] = 'WPUB'; + $ID3v2ShortFrameNameLookup[3]['url_user'] = 'WXXX'; // The above are common to ID3v2.3 and ID3v2.4 // so copy them to ID3v2.4 before adding specifics for 2.3 and 2.4 $ID3v2ShortFrameNameLookup[4] = $ID3v2ShortFrameNameLookup[3]; // The following are unique to ID3v2.3 - $ID3v2ShortFrameNameLookup[3]['equalisation'] = 'EQUA'; - $ID3v2ShortFrameNameLookup[3]['involved_people_list'] = 'IPLS'; - $ID3v2ShortFrameNameLookup[3]['relative_volume_adjustment'] = 'RVAD'; - $ID3v2ShortFrameNameLookup[3]['date'] = 'TDAT'; - $ID3v2ShortFrameNameLookup[3]['time'] = 'TIME'; - $ID3v2ShortFrameNameLookup[3]['original_release_year'] = 'TORY'; - $ID3v2ShortFrameNameLookup[3]['recording_dates'] = 'TRDA'; - $ID3v2ShortFrameNameLookup[3]['size'] = 'TSIZ'; - $ID3v2ShortFrameNameLookup[3]['year'] = 'TYER'; + $ID3v2ShortFrameNameLookup[3]['equalisation'] = 'EQUA'; + $ID3v2ShortFrameNameLookup[3]['involved_people_list'] = 'IPLS'; + $ID3v2ShortFrameNameLookup[3]['relative_volume_adjustment'] = 'RVAD'; + $ID3v2ShortFrameNameLookup[3]['date'] = 'TDAT'; + $ID3v2ShortFrameNameLookup[3]['time'] = 'TIME'; + $ID3v2ShortFrameNameLookup[3]['original_year'] = 'TORY'; + $ID3v2ShortFrameNameLookup[3]['recording_dates'] = 'TRDA'; + $ID3v2ShortFrameNameLookup[3]['size'] = 'TSIZ'; + $ID3v2ShortFrameNameLookup[3]['year'] = 'TYER'; // The following are unique to ID3v2.4 - $ID3v2ShortFrameNameLookup[4]['audio_seek_point_index'] = 'ASPI'; - $ID3v2ShortFrameNameLookup[4]['equalisation'] = 'EQU2'; - $ID3v2ShortFrameNameLookup[4]['relative_volume_adjustment'] = 'RVA2'; - $ID3v2ShortFrameNameLookup[4]['seek'] = 'SEEK'; - $ID3v2ShortFrameNameLookup[4]['signature'] = 'SIGN'; - $ID3v2ShortFrameNameLookup[4]['encoding_time'] = 'TDEN'; - $ID3v2ShortFrameNameLookup[4]['original_release_time'] = 'TDOR'; - $ID3v2ShortFrameNameLookup[4]['recording_time'] = 'TDRC'; - $ID3v2ShortFrameNameLookup[4]['release_time'] = 'TDRL'; - $ID3v2ShortFrameNameLookup[4]['tagging_time'] = 'TDTG'; - $ID3v2ShortFrameNameLookup[4]['involved_people_list'] = 'TIPL'; - $ID3v2ShortFrameNameLookup[4]['musician_credits_list'] = 'TMCL'; - $ID3v2ShortFrameNameLookup[4]['mood'] = 'TMOO'; - $ID3v2ShortFrameNameLookup[4]['produced_notice'] = 'TPRO'; - $ID3v2ShortFrameNameLookup[4]['album_sort_order'] = 'TSOA'; - $ID3v2ShortFrameNameLookup[4]['performer_sort_order'] = 'TSOP'; - $ID3v2ShortFrameNameLookup[4]['title_sort_order'] = 'TSOT'; - $ID3v2ShortFrameNameLookup[4]['set_subtitle'] = 'TSST'; + $ID3v2ShortFrameNameLookup[4]['audio_seek_point_index'] = 'ASPI'; + $ID3v2ShortFrameNameLookup[4]['equalisation'] = 'EQU2'; + $ID3v2ShortFrameNameLookup[4]['relative_volume_adjustment'] = 'RVA2'; + $ID3v2ShortFrameNameLookup[4]['seek_frame'] = 'SEEK'; + $ID3v2ShortFrameNameLookup[4]['signature_frame'] = 'SIGN'; + $ID3v2ShortFrameNameLookup[4]['encoding_time'] = 'TDEN'; + $ID3v2ShortFrameNameLookup[4]['original_release_time'] = 'TDOR'; + $ID3v2ShortFrameNameLookup[4]['recording_time'] = 'TDRC'; + $ID3v2ShortFrameNameLookup[4]['release_time'] = 'TDRL'; + $ID3v2ShortFrameNameLookup[4]['tagging_time'] = 'TDTG'; + $ID3v2ShortFrameNameLookup[4]['involved_people_list'] = 'TIPL'; + $ID3v2ShortFrameNameLookup[4]['musician_credits_list'] = 'TMCL'; + $ID3v2ShortFrameNameLookup[4]['mood'] = 'TMOO'; + $ID3v2ShortFrameNameLookup[4]['produced_notice'] = 'TPRO'; + $ID3v2ShortFrameNameLookup[4]['album_sort_order'] = 'TSOA'; + $ID3v2ShortFrameNameLookup[4]['performer_sort_order'] = 'TSOP'; + $ID3v2ShortFrameNameLookup[4]['title_sort_order'] = 'TSOT'; + $ID3v2ShortFrameNameLookup[4]['set_subtitle'] = 'TSST'; + $ID3v2ShortFrameNameLookup[4]['year'] = 'TDRC'; // subset of ISO 8601: valid timestamps are yyyy, yyyy-MM, yyyy-MM-dd, yyyy-MM-ddTHH, yyyy-MM-ddTHH:mm and yyyy-MM-ddTHH:mm:ss. All time stamps are UTC } return (isset($ID3v2ShortFrameNameLookup[$majorversion][strtolower($long_description)]) ? $ID3v2ShortFrameNameLookup[$majorversion][strtolower($long_description)] : ''); @@ -2074,4 +2326,3 @@ class getid3_write_id3v2 } -?> diff --git a/serendipity_event_podcast/player/getid3/write.lyrics3.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.lyrics3.php similarity index 59% rename from serendipity_event_podcast/player/getid3/write.lyrics3.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.lyrics3.php index feb3face..4c5c8686 100644 --- a/serendipity_event_podcast/player/getid3/write.lyrics3.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.lyrics3.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // write.lyrics3.php // @@ -16,33 +17,56 @@ class getid3_write_lyrics3 { - var $filename; - var $tag_data; - //var $lyrics3_version = 2; // 1 or 2 - var $warnings = array(); // any non-critical errors will be stored here - var $errors = array(); // any critical errors will be stored here + /** + * @var string + */ + public $filename; - function getid3_write_lyrics3() { - return true; + /** + * @var array + */ + public $tag_data; + //public $lyrics3_version = 2; // 1 or 2 + + /** + * Any non-critical errors will be stored here. + * + * @var array + */ + public $warnings = array(); + + /** + * Any critical errors will be stored here. + * + * @var array + */ + public $errors = array(); + + public function __construct() { } - function WriteLyrics3() { + /** + * @return bool + */ + public function WriteLyrics3() { $this->errors[] = 'WriteLyrics3() not yet functional - cannot write Lyrics3'; return false; } - function DeleteLyrics3() { + + /** + * @return bool + */ + public function DeleteLyrics3() { // Initialize getID3 engine $getID3 = new getID3; $ThisFileInfo = $getID3->analyze($this->filename); if (isset($ThisFileInfo['lyrics3']['tag_offset_start']) && isset($ThisFileInfo['lyrics3']['tag_offset_end'])) { - ob_start(); - if ($fp = fopen($this->filename, 'a+b')) { - ob_end_clean(); + if (is_readable($this->filename) && getID3::is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) { flock($fp, LOCK_EX); $oldignoreuserabort = ignore_user_abort(true); - fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_end'], SEEK_SET); + fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_end']); $DataAfterLyrics3 = ''; if ($ThisFileInfo['filesize'] > $ThisFileInfo['lyrics3']['tag_offset_end']) { $DataAfterLyrics3 = fread($fp, $ThisFileInfo['filesize'] - $ThisFileInfo['lyrics3']['tag_offset_end']); @@ -51,7 +75,7 @@ class getid3_write_lyrics3 ftruncate($fp, $ThisFileInfo['lyrics3']['tag_offset_start']); if (!empty($DataAfterLyrics3)) { - fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_start'], SEEK_SET); + fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_start']); fwrite($fp, $DataAfterLyrics3, strlen($DataAfterLyrics3)); } @@ -62,12 +86,8 @@ class getid3_write_lyrics3 return true; } else { - - $errormessage = ob_get_contents(); - ob_end_clean(); - $this->errors[] = 'Cannot open "'.$this->filename.'" in "a+b" mode'; + $this->errors[] = 'Cannot fopen('.$this->filename.', "a+b")'; return false; - } } // no Lyrics3 present @@ -75,5 +95,3 @@ class getid3_write_lyrics3 } } - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/write.metaflac.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.metaflac.php similarity index 52% rename from serendipity_event_podcast/player/getid3/write.metaflac.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.metaflac.php index acf1035e..65cf3c15 100644 --- a/serendipity_event_podcast/player/getid3/write.metaflac.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.metaflac.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // write.metaflac.php // @@ -16,28 +17,74 @@ class getid3_write_metaflac { + /** + * @var string + */ + public $filename; - 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 + /** + * @var array + */ + public $tag_data; - function getid3_write_metaflac() { - return true; + /** + * Any non-critical errors will be stored here. + * + * @var array + */ + public $warnings = array(); + + /** + * Any critical errors will be stored here. + * + * @var array + */ + public $errors = array(); + + private $pictures = array(); + + public function __construct() { } - function WriteMetaFLAC() { + /** + * @return bool + */ + public function WriteMetaFLAC() { if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call metaflac, tags not written'; return false; } + $tempfilenames = array(); + + + if (!empty($this->tag_data['ATTACHED_PICTURE'])) { + foreach ($this->tag_data['ATTACHED_PICTURE'] as $key => $picturedetails) { + $temppicturefilename = tempnam(GETID3_TEMP_DIR, 'getID3'); + $tempfilenames[] = $temppicturefilename; + if (getID3::is_writable($temppicturefilename) && is_file($temppicturefilename) && ($fpcomments = fopen($temppicturefilename, 'wb'))) { + // https://xiph.org/flac/documentation_tools_flac.html#flac_options_picture + // [TYPE]|[MIME-TYPE]|[DESCRIPTION]|[WIDTHxHEIGHTxDEPTH[/COLORS]]|FILE + fwrite($fpcomments, $picturedetails['data']); + fclose($fpcomments); + $picture_typeid = (!empty($picturedetails['picturetypeid']) ? $this->ID3v2toFLACpictureTypes($picturedetails['picturetypeid']) : 3); // default to "3:Cover (front)" + $picture_mimetype = (!empty($picturedetails['mime']) ? $picturedetails['mime'] : ''); // should be auto-detected + $picture_width_height_depth = ''; + $this->pictures[] = $picture_typeid.'|'.$picture_mimetype.'|'.preg_replace('#[^\x20-\x7B\x7D-\x7F]#', '', $picturedetails['description']).'|'.$picture_width_height_depth.'|'.$temppicturefilename; + } else { + $this->errors[] = 'failed to open temporary tags file, tags not written - fopen("'.$temppicturefilename.'", "wb")'; + return false; + } + } + unset($this->tag_data['ATTACHED_PICTURE']); + } + + // Create file with new comments $tempcommentsfilename = tempnam(GETID3_TEMP_DIR, 'getID3'); - ob_start(); - if ($fpcomments = fopen($tempcommentsfilename, 'wb')) { - ob_end_clean(); + $tempfilenames[] = $tempcommentsfilename; + if (getID3::is_writable($tempcommentsfilename) && is_file($tempcommentsfilename) && ($fpcomments = fopen($tempcommentsfilename, 'wb'))) { foreach ($this->tag_data as $key => $value) { foreach ($value as $commentdata) { fwrite($fpcomments, $this->CleanmetaflacName($key).'='.$commentdata."\n"); @@ -46,12 +93,8 @@ class getid3_write_metaflac fclose($fpcomments); } else { - - $errormessage = ob_get_contents(); - ob_end_clean(); - $this->errors[] = 'failed to open temporary tags file "'.$tempcommentsfilename.'", tags not written'; + $this->errors[] = 'failed to open temporary tags file, tags not written - fopen("'.$tempcommentsfilename.'", "wb")'; return false; - } $oldignoreuserabort = ignore_user_abort(true); @@ -67,14 +110,18 @@ class getid3_write_metaflac // 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(); + clearstatcache(true, $this->filename); $timestampbeforewriting = filemtime($this->filename); - $commandline = GETID3_HELPERAPPSDIR.'metaflac.exe --no-utf8-convert --remove-all-tags --import-tags-from='.escapeshellarg($tempcommentsfilename).' '.escapeshellarg($this->filename).' 2>&1'; + $commandline = GETID3_HELPERAPPSDIR.'metaflac.exe --no-utf8-convert --remove-all-tags --import-tags-from='.escapeshellarg($tempcommentsfilename); + foreach ($this->pictures as $picturecommand) { + $commandline .= ' --import-picture-from='.escapeshellarg($picturecommand); + } + $commandline .= ' '.escapeshellarg($this->filename).' 2>&1'; $metaflacError = `$commandline`; if (empty($metaflacError)) { - clearstatcache(); + clearstatcache(true, $this->filename); if ($timestampbeforewriting == filemtime($this->filename)) { $metaflacError = 'File modification timestamp has not changed - it looks like the tags were not written'; } @@ -86,13 +133,19 @@ class getid3_write_metaflac } else { // It's simpler on *nix - $commandline = 'metaflac --no-utf8-convert --remove-all-tags --import-tags-from='.escapeshellarg($tempcommentsfilename).' '.escapeshellarg($this->filename).' 2>&1'; + $commandline = 'metaflac --no-utf8-convert --remove-all-tags --import-tags-from='.escapeshellarg($tempcommentsfilename); + foreach ($this->pictures as $picturecommand) { + $commandline .= ' --import-picture-from='.escapeshellarg($picturecommand); + } + $commandline .= ' '.escapeshellarg($this->filename).' 2>&1'; $metaflacError = `$commandline`; } // Remove temporary comments file - unlink($tempcommentsfilename); + foreach ($tempfilenames as $tempfilename) { + unlink($tempfilename); + } ignore_user_abort($oldignoreuserabort); if (!empty($metaflacError)) { @@ -105,8 +158,10 @@ class getid3_write_metaflac return true; } - - function DeleteMetaFLAC() { + /** + * @return bool + */ + public function DeleteMetaFLAC() { if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call metaflac, tags not deleted'; @@ -118,14 +173,14 @@ class getid3_write_metaflac 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(); + clearstatcache(true, $this->filename); $timestampbeforewriting = filemtime($this->filename); $commandline = GETID3_HELPERAPPSDIR.'metaflac.exe --remove-all-tags "'.$this->filename.'" 2>&1'; $metaflacError = `$commandline`; if (empty($metaflacError)) { - clearstatcache(); + clearstatcache(true, $this->filename); if ($timestampbeforewriting == filemtime($this->filename)) { $metaflacError = 'File modification timestamp has not changed - it looks like the tags were not deleted'; } @@ -151,19 +206,33 @@ class getid3_write_metaflac return true; } + /** + * @param int $id3v2_picture_typeid + * + * @return int + */ + public function ID3v2toFLACpictureTypes($id3v2_picture_typeid) { + // METAFLAC picture type list is identical to ID3v2 picture type list (as least up to 0x14 "Publisher/Studio logotype") + // http://id3.org/id3v2.4.0-frames (section 4.14) + // https://xiph.org/flac/documentation_tools_flac.html#flac_options_picture + //return (isset($ID3v2toFLACpictureTypes[$id3v2_picture_typeid]) ? $ID3v2toFLACpictureTypes[$id3v2_picture_typeid] : 3); // default: "3: Cover (front)" + return (($id3v2_picture_typeid <= 0x14) ? $id3v2_picture_typeid : 3); // default: "3: Cover (front)" + } - function CleanmetaflacName($originalcommentname) { + /** + * @param string $originalcommentname + * + * @return string + */ + public 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 for improving this function + // Thanks Chris Bolt for improving this function // note: *reg_replace() replaces nulls with empty string (not space) return strtoupper(preg_replace('#[^ -<>-}]#', ' ', str_replace("\x00", ' ', $originalcommentname))); - } } - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/getid3/write.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.php similarity index 67% rename from serendipity_event_podcast/player/getid3/write.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.php index e3df4bdb..1167e0f7 100644 --- a/serendipity_event_podcast/player/getid3/write.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.php @@ -1,10 +1,11 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// /// // // write.php // @@ -26,49 +27,114 @@ if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) { throw new Exception('write.php depends on getid3.lib.php, which is missing.'); } - -// NOTES: -// -// You should pass data here with standard field names as follows: -// * TITLE -// * ARTIST -// * ALBUM -// * TRACKNUMBER -// * COMMENT -// * GENRE -// * YEAR -// * ATTACHED_PICTURE (ID3v2 only) -// -// http://www.personal.uni-jena.de/~pfk/mpp/sv8/apekey.html -// The APEv2 Tag Items Keys definition says "TRACK" is correct but foobar2000 uses "TRACKNUMBER" instead -// Pass data here as "TRACKNUMBER" for compatability with all formats - - +/** + * NOTES: + * + * You should pass data here with standard field names as follows: + * * TITLE + * * ARTIST + * * ALBUM + * * TRACKNUMBER + * * COMMENT + * * GENRE + * * YEAR + * * ATTACHED_PICTURE (ID3v2 only) + * The APEv2 Tag Items Keys definition says "TRACK" is correct but foobar2000 uses "TRACKNUMBER" instead + * Pass data here as "TRACKNUMBER" for compatability with all formats + * + * @link http://www.personal.uni-jena.de/~pfk/mpp/sv8/apekey.html + */ class getid3_writetags { - // public - var $filename; // absolute filename of file to write tags to - var $tagformats = array(); // array of tag formats to write ('id3v1', 'id3v2.2', 'id2v2.3', 'id3v2.4', 'ape', 'vorbiscomment', 'metaflac', 'real') - var $tag_data = array(array()); // 2-dimensional array of tag data (ex: $data['ARTIST'][0] = 'Elvis') - var $tag_encoding = 'ISO-8859-1'; // text encoding used for tag data ('ISO-8859-1', 'UTF-8', 'UTF-16', 'UTF-16LE', 'UTF-16BE', ) - var $overwrite_tags = true; // if true will erase existing tag data and write only passed data; if false will merge passed data with existing tag data - var $remove_other_tags = false; // if true will erase remove all existing tags and only write those passed in $tagformats; if false will ignore any tags not mentioned in $tagformats + /** + * Absolute filename of file to write tags to. + * + * @var string + */ + public $filename; - var $id3v2_tag_language = 'eng'; // ISO-639-2 3-character language code needed for some ID3v2 frames (http://www.id3.org/iso639-2.html) - var $id3v2_paddedlength = 4096; // minimum length of ID3v2 tags (will be padded to this length if tag data is shorter) + /** + * Array of tag formats to write ('id3v1', 'id3v2.2', 'id2v2.3', 'id3v2.4', 'ape', 'vorbiscomment', + * 'metaflac', 'real'). + * + * @var array + */ + public $tagformats = array(); - var $warnings = array(); // any non-critical errors will be stored here - var $errors = array(); // any critical errors will be stored here + /** + * 2-dimensional array of tag data (ex: $data['ARTIST'][0] = 'Elvis'). + * + * @var array + */ + public $tag_data = array(array()); - // private - var $ThisFileInfo; // analysis of file before writing + /** + * Text encoding used for tag data ('ISO-8859-1', 'UTF-8', 'UTF-16', 'UTF-16LE', 'UTF-16BE', ). + * + * @var string + */ + public $tag_encoding = 'ISO-8859-1'; - function getid3_writetags() { - return true; + /** + * If true will erase existing tag data and write only passed data; if false will merge passed data + * with existing tag data. + * + * @var bool + */ + public $overwrite_tags = true; + + /** + * If true will erase remove all existing tags and only write those passed in $tagformats; + * If false will ignore any tags not mentioned in $tagformats. + * + * @var bool + */ + public $remove_other_tags = false; + + /** + * ISO-639-2 3-character language code needed for some ID3v2 frames. + * + * @link http://www.id3.org/iso639-2.html + * + * @var string + */ + public $id3v2_tag_language = 'eng'; + + /** + * Minimum length of ID3v2 tags (will be padded to this length if tag data is shorter). + * + * @var int + */ + public $id3v2_paddedlength = 4096; + + /** + * Any non-critical errors will be stored here. + * + * @var array + */ + public $warnings = array(); + + /** + * Any critical errors will be stored here. + * + * @var array + */ + public $errors = array(); + + /** + * Analysis of file before writing. + * + * @var array + */ + private $ThisFileInfo; + + public function __construct() { } - - function WriteTags() { + /** + * @return bool + */ + public function WriteTags() { if (empty($this->filename)) { $this->errors[] = 'filename is undefined in getid3_writetags'; @@ -82,8 +148,23 @@ class getid3_writetags $this->errors[] = 'tagformats must be an array in getid3_writetags'; return false; } + // prevent duplicate tag formats + $this->tagformats = array_unique($this->tagformats); + + // prevent trying to specify more than one version of ID3v2 tag to write simultaneously + $id3typecounter = 0; + foreach ($this->tagformats as $tagformat) { + if (substr(strtolower($tagformat), 0, 6) == 'id3v2.') { + $id3typecounter++; + } + } + if ($id3typecounter > 1) { + $this->errors[] = 'tagformats must not contain more than one version of ID3v2'; + return false; + } $TagFormatsToRemove = array(); + $AllowedTagFormats = array(); if (filesize($this->filename) == 0) { // empty file special case - allow any tag format, don't check existing format @@ -124,14 +205,12 @@ class getid3_writetags //$AllowedTagFormats = array('metaflac'); $this->errors[] = 'metaflac is not (yet) compatible with OggFLAC files'; return false; - break; case 'vorbis': $AllowedTagFormats = array('vorbiscomment'); break; default: $this->errors[] = 'metaflac is not (yet) compatible with Ogg files other than OggVorbis'; return false; - break; } break; @@ -178,9 +257,7 @@ class getid3_writetags switch ($tagformat) { case 'ape': $GETID3_ERRORARRAY = &$this->errors; - if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.apetag.php', __FILE__, false)) { - return false; - } + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.apetag.php', __FILE__, true); break; case 'id3v1': @@ -189,9 +266,7 @@ class getid3_writetags case 'metaflac': case 'real': $GETID3_ERRORARRAY = &$this->errors; - if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.'.$tagformat.'.php', __FILE__, false)) { - return false; - } + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.'.$tagformat.'.php', __FILE__, true); break; case 'id3v2.2': @@ -199,15 +274,12 @@ class getid3_writetags case 'id3v2.4': case 'id3v2': $GETID3_ERRORARRAY = &$this->errors; - if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.id3v2.php', __FILE__, false)) { - return false; - } + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.id3v2.php', __FILE__, true); break; default: $this->errors[] = 'unknown tag format "'.$tagformat.'" in $tagformats in WriteTags()'; return false; - break; } } @@ -236,9 +308,9 @@ class getid3_writetags } } - // Convert "TRACK" to "TRACKNUMBER" (if needed) for compatability with all formats - if (isset($this->tag_data['TRACK']) && !isset($this->tag_data['TRACKNUMBER'])) { - $this->tag_data['TRACKNUMBER'] = $this->tag_data['TRACK']; + // Convert "TRACK" to "TRACK_NUMBER" (if needed) for compatability with all formats + if (isset($this->tag_data['TRACK']) && !isset($this->tag_data['TRACK_NUMBER'])) { + $this->tag_data['TRACK_NUMBER'] = $this->tag_data['TRACK']; unset($this->tag_data['TRACK']); } @@ -253,10 +325,10 @@ class getid3_writetags switch ($tagformat) { case 'ape': $ape_writer = new getid3_write_apetag; - if (($ape_writer->tag_data = $this->FormatDataForAPE()) !== false) { + if ($ape_writer->tag_data = $this->FormatDataForAPE()) { $ape_writer->filename = $this->filename; if (($success = $ape_writer->WriteAPEtag()) === false) { - $this->errors[] = 'WriteAPEtag() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $ape_writer->errors)), ENT_COMPAT, LANG_CHARSET)).'
    '; + $this->errors[] = 'WriteAPEtag() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $ape_writer->errors)))).'
    '; } } else { $this->errors[] = 'FormatDataForAPE() failed'; @@ -265,10 +337,10 @@ class getid3_writetags case 'id3v1': $id3v1_writer = new getid3_write_id3v1; - if (($id3v1_writer->tag_data = $this->FormatDataForID3v1()) !== false) { + if ($id3v1_writer->tag_data = $this->FormatDataForID3v1()) { $id3v1_writer->filename = $this->filename; if (($success = $id3v1_writer->WriteID3v1()) === false) { - $this->errors[] = 'WriteID3v1() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $id3v1_writer->errors)), ENT_COMPAT, LANG_CHARSET)).'
    '; + $this->errors[] = 'WriteID3v1() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $id3v1_writer->errors)))).'
    '; } } else { $this->errors[] = 'FormatDataForID3v1() failed'; @@ -281,10 +353,13 @@ class getid3_writetags $id3v2_writer = new getid3_write_id3v2; $id3v2_writer->majorversion = intval(substr($tagformat, -1)); $id3v2_writer->paddedlength = $this->id3v2_paddedlength; - if (($id3v2_writer->tag_data = $this->FormatDataForID3v2($id3v2_writer->majorversion)) !== false) { + $id3v2_writer_tag_data = $this->FormatDataForID3v2($id3v2_writer->majorversion); + if ($id3v2_writer_tag_data !== false) { + $id3v2_writer->tag_data = $id3v2_writer_tag_data; + unset($id3v2_writer_tag_data); $id3v2_writer->filename = $this->filename; if (($success = $id3v2_writer->WriteID3v2()) === false) { - $this->errors[] = 'WriteID3v2() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $id3v2_writer->errors)), ENT_COMPAT, LANG_CHARSET)).'
    '; + $this->errors[] = 'WriteID3v2() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $id3v2_writer->errors)))).'
    '; } } else { $this->errors[] = 'FormatDataForID3v2() failed'; @@ -293,10 +368,10 @@ class getid3_writetags case 'vorbiscomment': $vorbiscomment_writer = new getid3_write_vorbiscomment; - if (($vorbiscomment_writer->tag_data = $this->FormatDataForVorbisComment()) !== false) { + if ($vorbiscomment_writer->tag_data = $this->FormatDataForVorbisComment()) { $vorbiscomment_writer->filename = $this->filename; if (($success = $vorbiscomment_writer->WriteVorbisComment()) === false) { - $this->errors[] = 'WriteVorbisComment() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $vorbiscomment_writer->errors)), ENT_COMPAT, LANG_CHARSET)).'
    '; + $this->errors[] = 'WriteVorbisComment() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $vorbiscomment_writer->errors)))).'
    '; } } else { $this->errors[] = 'FormatDataForVorbisComment() failed'; @@ -305,10 +380,10 @@ class getid3_writetags case 'metaflac': $metaflac_writer = new getid3_write_metaflac; - if (($metaflac_writer->tag_data = $this->FormatDataForMetaFLAC()) !== false) { + if ($metaflac_writer->tag_data = $this->FormatDataForMetaFLAC()) { $metaflac_writer->filename = $this->filename; if (($success = $metaflac_writer->WriteMetaFLAC()) === false) { - $this->errors[] = 'WriteMetaFLAC() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $metaflac_writer->errors)), ENT_COMPAT, LANG_CHARSET)).'
    '; + $this->errors[] = 'WriteMetaFLAC() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $metaflac_writer->errors)))).'
    '; } } else { $this->errors[] = 'FormatDataForMetaFLAC() failed'; @@ -317,10 +392,10 @@ class getid3_writetags case 'real': $real_writer = new getid3_write_real; - if (($real_writer->tag_data = $this->FormatDataForReal()) !== false) { + if ($real_writer->tag_data = $this->FormatDataForReal()) { $real_writer->filename = $this->filename; if (($success = $real_writer->WriteReal()) === false) { - $this->errors[] = 'WriteReal() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $real_writer->errors)), ENT_COMPAT, LANG_CHARSET)).'
    '; + $this->errors[] = 'WriteReal() failed with message(s):
    • '.str_replace("\n", '
    • ', htmlentities(trim(implode("\n", $real_writer->errors)))).'
    '; } } else { $this->errors[] = 'FormatDataForReal() failed'; @@ -330,7 +405,6 @@ class getid3_writetags default: $this->errors[] = 'Invalid tag format to write: "'.$tagformat.'"'; return false; - break; } if (!$success) { return false; @@ -340,8 +414,12 @@ class getid3_writetags } - - function DeleteTags($TagFormatsToDelete) { + /** + * @param string[] $TagFormatsToDelete + * + * @return bool + */ + public function DeleteTags($TagFormatsToDelete) { foreach ($TagFormatsToDelete as $DeleteTagFormat) { $success = false; // overridden if tag deletion is successful switch ($DeleteTagFormat) { @@ -402,9 +480,8 @@ class getid3_writetags break; default: - $this->errors[] = 'Invalid tag format to delete: "'.$tagformat.'"'; + $this->errors[] = 'Invalid tag format to delete: "'.$DeleteTagFormat.'"'; return false; - break; } if (!$success) { return false; @@ -413,22 +490,31 @@ class getid3_writetags return true; } - - function MergeExistingTagData($TagFormat, &$tag_data) { + /** + * @param string $TagFormat + * @param array $tag_data + * + * @return bool + * @throws Exception + */ + public function MergeExistingTagData($TagFormat, &$tag_data) { // Merge supplied data with existing data, if requested if ($this->overwrite_tags) { // do nothing - ignore previous data } else { -throw new Exception('$this->overwrite_tags=false is known to be buggy in this version of getID3. Will be fixed in the near future, check www.getid3.org for a newer version.'); - if (!isset($this->ThisFileInfo['tags'][$TagFormat])) { - return false; - } - $tag_data = array_merge_recursive($tag_data, $this->ThisFileInfo['tags'][$TagFormat]); + throw new Exception('$this->overwrite_tags=false is known to be buggy in this version of getID3. Check http://github.com/JamesHeinrich/getID3 for a newer version.'); +// if (!isset($this->ThisFileInfo['tags'][$TagFormat])) { +// return false; +// } +// $tag_data = array_merge_recursive($tag_data, $this->ThisFileInfo['tags'][$TagFormat]); } return true; } - function FormatDataForAPE() { + /** + * @return array + */ + public function FormatDataForAPE() { $ape_tag_data = array(); foreach ($this->tag_data as $tag_key => $valuearray) { switch ($tag_key) { @@ -454,8 +540,11 @@ throw new Exception('$this->overwrite_tags=false is known to be buggy in this ve return $ape_tag_data; } - - function FormatDataForID3v1() { + /** + * @return array + */ + public function FormatDataForID3v1() { + $tag_data_id3v1 = array(); $tag_data_id3v1['genreid'] = 255; if (!empty($this->tag_data['GENRE'])) { foreach ($this->tag_data['GENRE'] as $key => $value) { @@ -465,23 +554,29 @@ throw new Exception('$this->overwrite_tags=false is known to be buggy in this ve } } } - $tag_data_id3v1['title'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['TITLE'] ) ? $this->tag_data['TITLE'] : array()))); - $tag_data_id3v1['artist'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['ARTIST'] ) ? $this->tag_data['ARTIST'] : array()))); - $tag_data_id3v1['album'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['ALBUM'] ) ? $this->tag_data['ALBUM'] : array()))); - $tag_data_id3v1['year'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['YEAR'] ) ? $this->tag_data['YEAR'] : array()))); - $tag_data_id3v1['comment'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['COMMENT'] ) ? $this->tag_data['COMMENT'] : array()))); - $tag_data_id3v1['track'] = intval(getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['TRACKNUMBER']) ? $this->tag_data['TRACKNUMBER'] : array())))); - if ($tag_data_id3v1['track'] <= 0) { - $tag_data_id3v1['track'] = ''; + $tag_data_id3v1['title'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['TITLE'] ) ? $this->tag_data['TITLE'] : array()))); + $tag_data_id3v1['artist'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['ARTIST'] ) ? $this->tag_data['ARTIST'] : array()))); + $tag_data_id3v1['album'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['ALBUM'] ) ? $this->tag_data['ALBUM'] : array()))); + $tag_data_id3v1['year'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['YEAR'] ) ? $this->tag_data['YEAR'] : array()))); + $tag_data_id3v1['comment'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['COMMENT'] ) ? $this->tag_data['COMMENT'] : array()))); + $tag_data_id3v1['track_number'] = intval(getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['TRACK_NUMBER']) ? $this->tag_data['TRACK_NUMBER'] : array())))); + if ($tag_data_id3v1['track_number'] <= 0) { + $tag_data_id3v1['track_number'] = ''; } $this->MergeExistingTagData('id3v1', $tag_data_id3v1); return $tag_data_id3v1; } - function FormatDataForID3v2($id3v2_majorversion) { + /** + * @param int $id3v2_majorversion + * + * @return array|false + */ + public function FormatDataForID3v2($id3v2_majorversion) { $tag_data_id3v2 = array(); + $ID3v2_text_encoding_lookup = array(); $ID3v2_text_encoding_lookup[2] = array('ISO-8859-1'=>0, 'UTF-16'=>1); $ID3v2_text_encoding_lookup[3] = array('ISO-8859-1'=>0, 'UTF-16'=>1); $ID3v2_text_encoding_lookup[4] = array('ISO-8859-1'=>0, 'UTF-16'=>1, 'UTF-16BE'=>2, 'UTF-8'=>3); @@ -502,6 +597,51 @@ throw new Exception('$this->overwrite_tags=false is known to be buggy in this ve } break; + case 'POPM': + if (isset($valuearray['email']) && + isset($valuearray['rating']) && + isset($valuearray['data'])) { + $tag_data_id3v2['POPM'][] = $valuearray; + } else { + $this->errors[] = 'ID3v2 POPM data is not properly structured'; + return false; + } + break; + + case 'GRID': + if ( + isset($valuearray['groupsymbol']) && + isset($valuearray['ownerid']) && + isset($valuearray['data']) + ) { + $tag_data_id3v2['GRID'][] = $valuearray; + } else { + $this->errors[] = 'ID3v2 GRID data is not properly structured'; + return false; + } + break; + + case 'UFID': + if (isset($valuearray['ownerid']) && + isset($valuearray['data'])) { + $tag_data_id3v2['UFID'][] = $valuearray; + } else { + $this->errors[] = 'ID3v2 UFID data is not properly structured'; + return false; + } + break; + + case 'TXXX': + foreach ($valuearray as $key => $txxx_data_array) { + if (isset($txxx_data_array['description']) && isset($txxx_data_array['data'])) { + $tag_data_id3v2['TXXX'][] = $txxx_data_array; + } else { + $this->errors[] = 'ID3v2 TXXX data is not properly structured'; + return false; + } + } + break; + case '': $this->errors[] = 'ID3v2: Skipping "'.$tag_key.'" because cannot match it to a known ID3v2 frame type'; // some other data type, don't know how to handle it, ignore it @@ -521,7 +661,7 @@ throw new Exception('$this->overwrite_tags=false is known to be buggy in this ve // note: some software, notably Windows Media Player and iTunes are broken and treat files tagged with UTF-16BE (with BOM) as corrupt // therefore we force data to UTF-16LE and manually prepend the BOM $ID3v2_tag_data_converted = false; - if (!$ID3v2_tag_data_converted && ($this->tag_encoding == 'ISO-8859-1')) { + if (/*!$ID3v2_tag_data_converted && */($this->tag_encoding == 'ISO-8859-1')) { // great, leave data as-is for minimum compatability problems $tag_data_id3v2[$ID3v2_framename][$key]['encodingid'] = 0; $tag_data_id3v2[$ID3v2_framename][$key]['data'] = $value; @@ -530,8 +670,9 @@ throw new Exception('$this->overwrite_tags=false is known to be buggy in this ve if (!$ID3v2_tag_data_converted && ($this->tag_encoding == 'UTF-8')) { do { // if UTF-8 string does not include any characters above chr(127) then it is identical to ISO-8859-1 + $value = (string) $value; // prevent warnings/errors if $value is a non-string (e.g. integer,float) for ($i = 0; $i < strlen($value); $i++) { - if (ord($value{$i}) > 127) { + if (ord($value[$i]) > 127) { break 2; } } @@ -565,28 +706,35 @@ throw new Exception('$this->overwrite_tags=false is known to be buggy in this ve return $tag_data_id3v2; } - function FormatDataForVorbisComment() { + /** + * @return array + */ + public function FormatDataForVorbisComment() { $tag_data_vorbiscomment = $this->tag_data; // check for multi-line comment values - split out to multiple comments if neccesary // and convert data to UTF-8 strings foreach ($tag_data_vorbiscomment as $tag_key => $valuearray) { foreach ($valuearray as $key => $value) { - str_replace("\r", "\n", $value); - if (strstr($value, "\n")) { - unset($tag_data_vorbiscomment[$tag_key][$key]); - $multilineexploded = explode("\n", $value); - foreach ($multilineexploded as $newcomment) { - if (strlen(trim($newcomment)) > 0) { - $tag_data_vorbiscomment[$tag_key][] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $newcomment); - } - } - } elseif (is_string($value) || is_numeric($value)) { - $tag_data_vorbiscomment[$tag_key][$key] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value); + if (($tag_key == 'ATTACHED_PICTURE') && is_array($value)) { + continue; // handled separately in write.metaflac.php } else { - $this->warnings[] = '$data['.$tag_key.']['.$key.'] is not a string value - all of $data['.$tag_key.'] NOT written to VorbisComment tag'; - unset($tag_data_vorbiscomment[$tag_key]); - break; + str_replace("\r", "\n", $value); + if (strstr($value, "\n")) { + unset($tag_data_vorbiscomment[$tag_key][$key]); + $multilineexploded = explode("\n", $value); + foreach ($multilineexploded as $newcomment) { + if (strlen(trim($newcomment)) > 0) { + $tag_data_vorbiscomment[$tag_key][] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $newcomment); + } + } + } elseif (is_string($value) || is_numeric($value)) { + $tag_data_vorbiscomment[$tag_key][$key] = getid3_lib::iconv_fallback($this->tag_encoding, 'UTF-8', $value); + } else { + $this->warnings[] = '$data['.$tag_key.']['.$key.'] is not a string value - all of $data['.$tag_key.'] NOT written to VorbisComment tag'; + unset($tag_data_vorbiscomment[$tag_key]); + break; + } } } } @@ -594,13 +742,20 @@ throw new Exception('$this->overwrite_tags=false is known to be buggy in this ve return $tag_data_vorbiscomment; } - function FormatDataForMetaFLAC() { + /** + * @return array + */ + public function FormatDataForMetaFLAC() { // FLAC & OggFLAC use VorbisComments same as OggVorbis // but require metaflac to do the writing rather than vorbiscomment return $this->FormatDataForVorbisComment(); } - function FormatDataForReal() { + /** + * @return array + */ + public function FormatDataForReal() { + $tag_data_real = array(); $tag_data_real['title'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['TITLE'] ) ? $this->tag_data['TITLE'] : array()))); $tag_data_real['artist'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['ARTIST'] ) ? $this->tag_data['ARTIST'] : array()))); $tag_data_real['copyright'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', implode(' ', (isset($this->tag_data['COPYRIGHT']) ? $this->tag_data['COPYRIGHT'] : array()))); @@ -611,5 +766,3 @@ throw new Exception('$this->overwrite_tags=false is known to be buggy in this ve } } - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.real.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.real.php new file mode 100644 index 00000000..492cc4bb --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.real.php @@ -0,0 +1,328 @@ + // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // +// see readme.txt for more details // +///////////////////////////////////////////////////////////////// +// // +// write.real.php // +// module for writing RealAudio/RealVideo tags // +// dependencies: module.tag.real.php // +// /// +///////////////////////////////////////////////////////////////// + +class getid3_write_real +{ + /** + * @var string + */ + public $filename; + + /** + * @var array + */ + public $tag_data = array(); + + /** + * Read buffer size in bytes. + * + * @var int + */ + public $fread_buffer_size = 32768; + + /** + * Any non-critical errors will be stored here. + * + * @var array + */ + public $warnings = array(); + + /** + * Any critical errors will be stored here. + * + * @var array + */ + public $errors = array(); + + /** + * Minimum length of CONT tag in bytes. + * + * @var int + */ + public $paddedlength = 512; + + public function __construct() { + } + + /** + * @return bool + */ + public function WriteReal() { + // File MUST be writeable - CHMOD(646) at least + if (getID3::is_writable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'r+b'))) { + + // Initialize getID3 engine + $getID3 = new getID3; + $OldThisFileInfo = $getID3->analyze($this->filename); + if (empty($OldThisFileInfo['real']['chunks']) && !empty($OldThisFileInfo['real']['old_ra_header'])) { + $this->errors[] = 'Cannot write Real tags on old-style file format'; + fclose($fp_source); + return false; + } + + if (empty($OldThisFileInfo['real']['chunks'])) { + $this->errors[] = 'Cannot write Real tags because cannot find DATA chunk in file'; + fclose($fp_source); + return false; + } + $oldChunkInfo = array(); + foreach ($OldThisFileInfo['real']['chunks'] as $chunknumber => $chunkarray) { + $oldChunkInfo[$chunkarray['name']] = $chunkarray; + } + if (!empty($oldChunkInfo['CONT']['length'])) { + $this->paddedlength = max($oldChunkInfo['CONT']['length'], $this->paddedlength); + } + + $new_CONT_tag_data = $this->GenerateCONTchunk(); + $new_PROP_tag_data = $this->GeneratePROPchunk($OldThisFileInfo['real']['chunks'], $new_CONT_tag_data); + $new__RMF_tag_data = $this->GenerateRMFchunk($OldThisFileInfo['real']['chunks']); + + if (isset($oldChunkInfo['.RMF']['length']) && ($oldChunkInfo['.RMF']['length'] == strlen($new__RMF_tag_data))) { + fseek($fp_source, $oldChunkInfo['.RMF']['offset']); + fwrite($fp_source, $new__RMF_tag_data); + } else { + $this->errors[] = 'new .RMF tag ('.strlen($new__RMF_tag_data).' bytes) different length than old .RMF tag ('.$oldChunkInfo['.RMF']['length'].' bytes)'; + fclose($fp_source); + return false; + } + + if (isset($oldChunkInfo['PROP']['length']) && ($oldChunkInfo['PROP']['length'] == strlen($new_PROP_tag_data))) { + fseek($fp_source, $oldChunkInfo['PROP']['offset']); + fwrite($fp_source, $new_PROP_tag_data); + } else { + $this->errors[] = 'new PROP tag ('.strlen($new_PROP_tag_data).' bytes) different length than old PROP tag ('.$oldChunkInfo['PROP']['length'].' bytes)'; + fclose($fp_source); + return false; + } + + if (isset($oldChunkInfo['CONT']['length']) && ($oldChunkInfo['CONT']['length'] == strlen($new_CONT_tag_data))) { + + // new data length is same as old data length - just overwrite + fseek($fp_source, $oldChunkInfo['CONT']['offset']); + fwrite($fp_source, $new_CONT_tag_data); + fclose($fp_source); + return true; + + } else { + + if (empty($oldChunkInfo['CONT'])) { + // no existing CONT chunk + $BeforeOffset = $oldChunkInfo['DATA']['offset']; + $AfterOffset = $oldChunkInfo['DATA']['offset']; + } else { + // new data is longer than old data + $BeforeOffset = $oldChunkInfo['CONT']['offset']; + $AfterOffset = $oldChunkInfo['CONT']['offset'] + $oldChunkInfo['CONT']['length']; + } + if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) { + if (getID3::is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) { + + rewind($fp_source); + fwrite($fp_temp, fread($fp_source, $BeforeOffset)); + fwrite($fp_temp, $new_CONT_tag_data); + fseek($fp_source, $AfterOffset); + while ($buffer = fread($fp_source, $this->fread_buffer_size)) { + fwrite($fp_temp, $buffer, strlen($buffer)); + } + fclose($fp_temp); + + if (copy($tempfilename, $this->filename)) { + unlink($tempfilename); + fclose($fp_source); + return true; + } + unlink($tempfilename); + $this->errors[] = 'FAILED: copy('.$tempfilename.', '.$this->filename.')'; + + } else { + $this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")'; + } + } + fclose($fp_source); + return false; + + } + + } + $this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")'; + return false; + } + + /** + * @param array $chunks + * + * @return string + */ + public function GenerateRMFchunk(&$chunks) { + $oldCONTexists = false; + $chunkNameKeys = array(); + foreach ($chunks as $key => $chunk) { + $chunkNameKeys[$chunk['name']] = $key; + if ($chunk['name'] == 'CONT') { + $oldCONTexists = true; + } + } + $newHeadersCount = $chunks[$chunkNameKeys['.RMF']]['headers_count'] + ($oldCONTexists ? 0 : 1); + + $RMFchunk = "\x00\x00"; // object version + $RMFchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['.RMF']]['file_version'], 4); + $RMFchunk .= getid3_lib::BigEndian2String($newHeadersCount, 4); + + $RMFchunk = '.RMF'.getid3_lib::BigEndian2String(strlen($RMFchunk) + 8, 4).$RMFchunk; // .RMF chunk identifier + chunk length + return $RMFchunk; + } + + /** + * @param array $chunks + * @param string $new_CONT_tag_data + * + * @return string + */ + public function GeneratePROPchunk(&$chunks, &$new_CONT_tag_data) { + $old_CONT_length = 0; + $old_DATA_offset = 0; + $old_INDX_offset = 0; + $chunkNameKeys = array(); + foreach ($chunks as $key => $chunk) { + $chunkNameKeys[$chunk['name']] = $key; + if ($chunk['name'] == 'CONT') { + $old_CONT_length = $chunk['length']; + } elseif ($chunk['name'] == 'DATA') { + if (!$old_DATA_offset) { + $old_DATA_offset = $chunk['offset']; + } + } elseif ($chunk['name'] == 'INDX') { + if (!$old_INDX_offset) { + $old_INDX_offset = $chunk['offset']; + } + } + } + $CONTdelta = strlen($new_CONT_tag_data) - $old_CONT_length; + + $PROPchunk = "\x00\x00"; // object version + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['max_bit_rate'], 4); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['avg_bit_rate'], 4); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['max_packet_size'], 4); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['avg_packet_size'], 4); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['num_packets'], 4); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['duration'], 4); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['preroll'], 4); + $PROPchunk .= getid3_lib::BigEndian2String(max(0, $old_INDX_offset + $CONTdelta), 4); + $PROPchunk .= getid3_lib::BigEndian2String(max(0, $old_DATA_offset + $CONTdelta), 4); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['num_streams'], 2); + $PROPchunk .= getid3_lib::BigEndian2String($chunks[$chunkNameKeys['PROP']]['flags_raw'], 2); + + $PROPchunk = 'PROP'.getid3_lib::BigEndian2String(strlen($PROPchunk) + 8, 4).$PROPchunk; // PROP chunk identifier + chunk length + return $PROPchunk; + } + + /** + * @return string + */ + public function GenerateCONTchunk() { + foreach ($this->tag_data as $key => $value) { + // limit each value to 0xFFFF bytes + $this->tag_data[$key] = substr($value, 0, 65535); + } + + $CONTchunk = "\x00\x00"; // object version + + $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['title']) ? strlen($this->tag_data['title']) : 0), 2); + $CONTchunk .= (!empty($this->tag_data['title']) ? strlen($this->tag_data['title']) : ''); + + $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['artist']) ? strlen($this->tag_data['artist']) : 0), 2); + $CONTchunk .= (!empty($this->tag_data['artist']) ? strlen($this->tag_data['artist']) : ''); + + $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['copyright']) ? strlen($this->tag_data['copyright']) : 0), 2); + $CONTchunk .= (!empty($this->tag_data['copyright']) ? strlen($this->tag_data['copyright']) : ''); + + $CONTchunk .= getid3_lib::BigEndian2String((!empty($this->tag_data['comment']) ? strlen($this->tag_data['comment']) : 0), 2); + $CONTchunk .= (!empty($this->tag_data['comment']) ? strlen($this->tag_data['comment']) : ''); + + if ($this->paddedlength > (strlen($CONTchunk) + 8)) { + $CONTchunk .= str_repeat("\x00", $this->paddedlength - strlen($CONTchunk) - 8); + } + + $CONTchunk = 'CONT'.getid3_lib::BigEndian2String(strlen($CONTchunk) + 8, 4).$CONTchunk; // CONT chunk identifier + chunk length + + return $CONTchunk; + } + + /** + * @return bool + */ + public function RemoveReal() { + // File MUST be writeable - CHMOD(646) at least + if (getID3::is_writable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename, 'r+b'))) { + + // Initialize getID3 engine + $getID3 = new getID3; + $OldThisFileInfo = $getID3->analyze($this->filename); + if (empty($OldThisFileInfo['real']['chunks']) && !empty($OldThisFileInfo['real']['old_ra_header'])) { + $this->errors[] = 'Cannot remove Real tags from old-style file format'; + fclose($fp_source); + return false; + } + + if (empty($OldThisFileInfo['real']['chunks'])) { + $this->errors[] = 'Cannot remove Real tags because cannot find DATA chunk in file'; + fclose($fp_source); + return false; + } + $oldChunkInfo = array(); + foreach ($OldThisFileInfo['real']['chunks'] as $chunknumber => $chunkarray) { + $oldChunkInfo[$chunkarray['name']] = $chunkarray; + } + + if (empty($oldChunkInfo['CONT'])) { + // no existing CONT chunk + fclose($fp_source); + return true; + } + + $BeforeOffset = $oldChunkInfo['CONT']['offset']; + $AfterOffset = $oldChunkInfo['CONT']['offset'] + $oldChunkInfo['CONT']['length']; + if ($tempfilename = tempnam(GETID3_TEMP_DIR, 'getID3')) { + if (getID3::is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename, 'wb'))) { + + rewind($fp_source); + fwrite($fp_temp, fread($fp_source, $BeforeOffset)); + fseek($fp_source, $AfterOffset); + while ($buffer = fread($fp_source, $this->fread_buffer_size)) { + fwrite($fp_temp, $buffer, strlen($buffer)); + } + fclose($fp_temp); + + if (copy($tempfilename, $this->filename)) { + unlink($tempfilename); + fclose($fp_source); + return true; + } + unlink($tempfilename); + $this->errors[] = 'FAILED: copy('.$tempfilename.', '.$this->filename.')'; + + } else { + $this->errors[] = 'Could not fopen("'.$tempfilename.'", "wb")'; + } + } + fclose($fp_source); + return false; + } + $this->errors[] = 'Could not fopen("'.$this->filename.'", "r+b")'; + return false; + } + +} diff --git a/serendipity_event_podcast/player/getid3/write.vorbiscomment.php b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.vorbiscomment.php similarity index 76% rename from serendipity_event_podcast/player/getid3/write.vorbiscomment.php rename to serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.vorbiscomment.php index 03349249..31cc5a40 100644 --- a/serendipity_event_podcast/player/getid3/write.vorbiscomment.php +++ b/serendipity_event_podcast/player/james-heinrich/getid3/getid3/write.vorbiscomment.php @@ -1,10 +1,12 @@ // -// available at http://getid3.sourceforge.net // -// or http://www.getid3.org // +// available at https://github.com/JamesHeinrich/getID3 // +// or https://www.getid3.org // +// or http://getid3.sourceforge.net // ///////////////////////////////////////////////////////////////// -// See readme.txt for more details // +// see readme.txt for more details // ///////////////////////////////////////////////////////////////// // // // write.vorbiscomment.php // @@ -16,17 +18,37 @@ class getid3_write_vorbiscomment { + /** + * @var string + */ + public $filename; - 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 + /** + * @var array + */ + public $tag_data; - function getid3_write_vorbiscomment() { - return true; + /** + * Any non-critical errors will be stored here. + * + * @var array + */ + public $warnings = array(); + + /** + * Any critical errors will be stored here. + * + * @var array + */ + public $errors = array(); + + public function __construct() { } - function WriteVorbisComment() { + /** + * @return bool + */ + public function WriteVorbisComment() { if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { $this->errors[] = 'PHP running in Safe Mode (backtick operator not available) - cannot call vorbiscomment, tags not written'; @@ -35,10 +57,8 @@ class getid3_write_vorbiscomment // Create file with new comments $tempcommentsfilename = tempnam(GETID3_TEMP_DIR, 'getID3'); - ob_start(); - if ($fpcomments = fopen($tempcommentsfilename, 'wb')) { + if (getID3::is_writable($tempcommentsfilename) && is_file($tempcommentsfilename) && ($fpcomments = fopen($tempcommentsfilename, 'wb'))) { - ob_end_clean(); foreach ($this->tag_data as $key => $value) { foreach ($value as $commentdata) { fwrite($fpcomments, $this->CleanVorbisCommentName($key).'='.$commentdata."\n"); @@ -47,12 +67,8 @@ class getid3_write_vorbiscomment fclose($fpcomments); } else { - - $errormessage = ob_get_contents(); - ob_end_clean(); $this->errors[] = 'failed to open temporary tags file "'.$tempcommentsfilename.'", tags not written'; return false; - } $oldignoreuserabort = ignore_user_abort(true); @@ -68,14 +84,14 @@ class getid3_write_vorbiscomment // 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(); + clearstatcache(true, $this->filename); $timestampbeforewriting = filemtime($this->filename); $commandline = GETID3_HELPERAPPSDIR.'vorbiscomment.exe -w --raw -c "'.$tempcommentsfilename.'" "'.$this->filename.'" 2>&1'; $VorbiscommentError = `$commandline`; if (empty($VorbiscommentError)) { - clearstatcache(); + clearstatcache(true, $this->filename); if ($timestampbeforewriting == filemtime($this->filename)) { $VorbiscommentError = 'File modification timestamp has not changed - it looks like the tags were not written'; } @@ -105,23 +121,29 @@ class getid3_write_vorbiscomment return true; } - function DeleteVorbisComment() { + /** + * @return bool + */ + public function DeleteVorbisComment() { $this->tag_data = array(array()); return $this->WriteVorbisComment(); } - function CleanVorbisCommentName($originalcommentname) { + /** + * @param string $originalcommentname + * + * @return string + */ + public function CleanVorbisCommentName($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 for improving this function + // Thanks Chris Bolt for improving this function // note: *reg_replace() replaces nulls with empty string (not space) return strtoupper(preg_replace('#[^ -<>-}]#', ' ', str_replace("\x00", ' ', $originalcommentname))); } } - -?> \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/cygwin1.dll b/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/cygwin1.dll new file mode 100644 index 00000000..4f2596ce Binary files /dev/null and b/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/cygwin1.dll differ diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/head.exe b/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/head.exe new file mode 100644 index 00000000..7f5ef876 Binary files /dev/null and b/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/head.exe differ diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/metaflac.exe b/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/metaflac.exe new file mode 100644 index 00000000..fa62c403 Binary files /dev/null and b/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/metaflac.exe differ diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/readme.helperapps.txt b/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/readme.helperapps.txt new file mode 100644 index 00000000..3f71a4af --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/readme.helperapps.txt @@ -0,0 +1,54 @@ +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich // +// available at http://getid3.sourceforge.net // +// or https://www.getid3.org // +// also https://github.com/JamesHeinrich/getID3 // +///////////////////////////////////////////////////////////////// +// // +// /helperapps/readme.txt - part of getID3() // +// List of binary files required under Windows for some // +// features and/or file formats // +// See /readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +This directory should contain binaries of various helper applications +that getID3() depends on to handle some file formats under Windows. + +The location of this directory is configurable in /getid3/getid3.php +as GETID3_HELPERAPPSDIR + +If this directory is empty, or you are missing any files, please +download the latest version of the "getID3()-WindowsSupport" package +from the usual download location (http://getid3.sourceforge.net) + + + +Included files: +===================================================== + +Taken from http://www.cygwin.com/ +* cygwin1.dll + +Taken from http://unxutils.sourceforge.net/ +* head.exe + +Taken from http://www.vorbis.com/download.psp +* vorbiscomment.exe + +Taken from http://flac.sourceforge.net/download.html +* metaflac.exe + +Taken from http://www.etree.org/shncom.html +* shorten.exe + + +///////////////////////////////////////////////////////////////// + +Changelog: + +2003.12.29: + * Initial release + +2019.07.24: + * Remove obsolete md5sum.exe, sha1sum.exe, tail.exe diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/shorten.exe b/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/shorten.exe new file mode 100644 index 00000000..b82d6c35 Binary files /dev/null and b/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/shorten.exe differ diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/vorbiscomment.exe b/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/vorbiscomment.exe new file mode 100644 index 00000000..dadfae44 Binary files /dev/null and b/serendipity_event_podcast/player/james-heinrich/getid3/helperapps/vorbiscomment.exe differ diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/license.txt b/serendipity_event_podcast/player/james-heinrich/getid3/license.txt new file mode 100644 index 00000000..c67873ae --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/license.txt @@ -0,0 +1,29 @@ +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich // +// available at http://getid3.sourceforge.net // +// or https://www.getid3.org // +// also https://github.com/JamesHeinrich/getID3 // +///////////////////////////////////////////////////////////////// + +***************************************************************** +***************************************************************** + + getID3() is released under multiple licenses. You may choose + from the following licenses, and use getID3 according to the + terms of the license most suitable to your project. + +GNU GPL: https://gnu.org/licenses/gpl.html (v3) + https://gnu.org/licenses/old-licenses/gpl-2.0.html (v2) + https://gnu.org/licenses/old-licenses/gpl-1.0.html (v1) + +GNU LGPL: https://gnu.org/licenses/lgpl.html (v3) + +Mozilla MPL: https://www.mozilla.org/MPL/2.0/ (v2) + +getID3 Commercial License: https://www.getid3.org/#gCL (payment required) + +***************************************************************** +***************************************************************** + +Copies of each of the above licenses are included in the 'licenses' +directory of the getID3 distribution. diff --git a/serendipity_event_podcast/player/getid3/license.commercial.txt b/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.commercial.txt similarity index 100% rename from serendipity_event_podcast/player/getid3/license.commercial.txt rename to serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.commercial.txt diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.gpl-10.txt b/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.gpl-10.txt new file mode 100644 index 00000000..8de98afa --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.gpl-10.txt @@ -0,0 +1,251 @@ + + GNU GENERAL PUBLIC LICENSE + Version 1, February 1989 + + Copyright (C) 1989 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The license agreements of most software companies try to keep users +at the mercy of those companies. By contrast, our General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. The +General Public License applies to the Free Software Foundation's +software and to any other program whose authors commit to using it. +You can use it for your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Specifically, the General Public License is designed to make +sure that you have the freedom to give away or sell copies of free +software, that you receive source code or can get it if you want it, +that you can change the software or use pieces of it in new free +programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of a such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must tell them their rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any program or other work which +contains a notice placed by the copyright holder saying it may be +distributed under the terms of this General Public License. The +"Program", below, refers to any such program or work, and a "work based +on the Program" means either the Program or any work containing the +Program or a portion of it, either verbatim or with modifications. Each +licensee is addressed as "you". + + 1. You may copy and distribute verbatim copies of the Program's source +code as you receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice and +disclaimer of warranty; keep intact all the notices that refer to this +General Public License and to the absence of any warranty; and give any +other recipients of the Program a copy of this General Public License +along with the Program. You may charge a fee for the physical act of +transferring a copy. + + 2. You may modify your copy or copies of the Program or any portion of +it, and copy and distribute such modifications under the terms of Paragraph +1 above, provided that you also do the following: + + a) cause the modified files to carry prominent notices stating that + you changed the files and the date of any change; and + + b) cause the whole of any work that you distribute or publish, that + in whole or in part contains the Program or any part thereof, either + with or without modifications, to be licensed at no charge to all + third parties under the terms of this General Public License (except + that you may choose to grant warranty protection to some or all + third parties, at your option). + + c) If the modified program normally reads commands interactively when + run, you must cause it, when started running for such interactive use + in the simplest and most usual way, to print or display an + announcement including an appropriate copyright notice and a notice + that there is no warranty (or else, saying that you provide a + warranty) and that users may redistribute the program under these + conditions, and telling the user how to view a copy of this General + Public License. + + d) You may charge a fee for the physical act of transferring a + copy, and you may at your option offer warranty protection in + exchange for a fee. + +Mere aggregation of another independent work with the Program (or its +derivative) on a volume of a storage or distribution medium does not bring +the other work under the scope of these terms. + + 3. You may copy and distribute the Program (or a portion or derivative of +it, under Paragraph 2) in object code or executable form under the terms of +Paragraphs 1 and 2 above provided that you also do one of the following: + + a) accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of + Paragraphs 1 and 2 above; or, + + b) accompany it with a written offer, valid for at least three + years, to give any third party free (except for a nominal charge + for the cost of distribution) a complete machine-readable copy of the + corresponding source code, to be distributed under the terms of + Paragraphs 1 and 2 above; or, + + c) accompany it with the information you received as to where the + corresponding source code may be obtained. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form alone.) + +Source code for a work means the preferred form of the work for making +modifications to it. For an executable file, complete source code means +all the source code for all modules it contains; but, as a special +exception, it need not include source code for modules which are standard +libraries that accompany the operating system on which the executable +file runs, or for standard header files or definitions files that +accompany that operating system. + + 4. You may not copy, modify, sublicense, distribute or transfer the +Program except as expressly provided under this General Public License. +Any attempt otherwise to copy, modify, sublicense, distribute or transfer +the Program is void, and will automatically terminate your rights to use +the Program under this License. However, parties who have received +copies, or rights to use copies, from you under this General Public +License will not have their licenses terminated so long as such parties +remain in full compliance. + + 5. By copying, distributing or modifying the Program (or any work based +on the Program) you indicate your acceptance of this license to do so, +and all its terms and conditions. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the original +licensor to copy, distribute or modify the Program subject to these +terms and conditions. You may not impose any further restrictions on the +recipients' exercise of the rights granted herein. + + 7. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of the license which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +the license, you may choose any version ever published by the Free Software +Foundation. + + 8. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to humanity, the best way to achieve this is to make it +free software which everyone can redistribute and change under these +terms. + + To do so, attach the following notices to the program. It is safest to +attach them to the start of each source file to most effectively convey +the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 1, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19xx name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the +appropriate parts of the General Public License. Of course, the +commands you use may be called something other than `show w' and `show +c'; they could even be mouse-clicks or menu items--whatever suits your +program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + program `Gnomovision' (a program to direct compilers to make passes + at assemblers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/serendipity_event_podcast/player/getid3/license.txt b/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.gpl-20.txt similarity index 95% rename from serendipity_event_podcast/player/getid3/license.txt rename to serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.gpl-20.txt index 9fec8082..d159169d 100644 --- a/serendipity_event_podcast/player/getid3/license.txt +++ b/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.gpl-20.txt @@ -1,12 +1,12 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - Preamble + Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public @@ -15,7 +15,7 @@ software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to +the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not @@ -55,8 +55,8 @@ patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. - - GNU GENERAL PUBLIC LICENSE + + GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains @@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions: License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) - + These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in @@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. - + 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is @@ -225,7 +225,7 @@ impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. - + 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License @@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. - NO WARRANTY + NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN @@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it @@ -303,10 +303,9 @@ the "copyright" line and a pointer to where the full notice is found. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. @@ -336,5 +335,5 @@ necessary. Here is a sample; alter the names: This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General +library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.gpl-30.txt b/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.gpl-30.txt new file mode 100644 index 00000000..94a9ed02 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.gpl-30.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.lgpl-30.txt b/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.lgpl-30.txt new file mode 100644 index 00000000..65c5ca88 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.lgpl-30.txt @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.mpl-20.txt b/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.mpl-20.txt new file mode 100644 index 00000000..14e2f777 --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/licenses/license.mpl-20.txt @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/serendipity_event_podcast/player/getid3/readme.txt b/serendipity_event_podcast/player/james-heinrich/getid3/readme.txt similarity index 80% rename from serendipity_event_podcast/player/getid3/readme.txt rename to serendipity_event_podcast/player/james-heinrich/getid3/readme.txt index 06095c53..0888bc4d 100644 --- a/serendipity_event_podcast/player/getid3/readme.txt +++ b/serendipity_event_podcast/player/james-heinrich/getid3/readme.txt @@ -1,25 +1,37 @@ ///////////////////////////////////////////////////////////////// /// getID3() by James Heinrich // // available at http://getid3.sourceforge.net // -// or http://www.getid3.org // -///////////////////////////////////////////////////////////////// -// // -// changelog.txt - part of getID3() // -// See readme.txt for more details // -// /// +// or https://www.getid3.org // +// also https://github.com/JamesHeinrich/getID3 // ///////////////////////////////////////////////////////////////// - This code is released under the GNU GPL: - http://www.gnu.org/copyleft/gpl.html +***************************************************************** +***************************************************************** - +---------------------------------------------+ - | If you do use this code somewhere, send me | - | an email and tell me how/where you used it. | - | | - | If you want to donate, there is a link on | - | http://www.getid3.org for PayPal donations. | - +---------------------------------------------+ + getID3() is released under multiple licenses. You may choose + from the following licenses, and use getID3 according to the + terms of the license most suitable to your project. +GNU GPL: https://gnu.org/licenses/gpl.html (v3) + https://gnu.org/licenses/old-licenses/gpl-2.0.html (v2) + https://gnu.org/licenses/old-licenses/gpl-1.0.html (v1) + +GNU LGPL: https://gnu.org/licenses/lgpl.html (v3) + +Mozilla MPL: https://www.mozilla.org/MPL/2.0/ (v2) + +getID3 Commercial License: https://www.getid3.org/#gCL (payment required) + +***************************************************************** +***************************************************************** +Copies of each of the above licenses are included in the 'licenses' +directory of the getID3 distribution. + + + +----------------------------------------------+ + | If you want to donate, there is a link on | + | https://www.getid3.org for PayPal donations. | + +----------------------------------------------+ Quick Start @@ -56,16 +68,17 @@ What does getID3() do? =========================================================================== Reads & parses (to varying degrees): - ¤ tags: + ¤ tags: * APE (v1 and v2) * ID3v1 (& ID3v1.1) * ID3v2 (v2.4, v2.3, v2.2) * Lyrics3 (v1 & v2) - ¤ audio-lossy: + ¤ audio-lossy: * MP3/MP2/MP1 * MPC / Musepack - * Ogg (Vorbis, OggFLAC, Speex) + * Ogg (Vorbis, OggFLAC, Speex, Opus) + * AAC / MP4 * AC3 * DTS * RealAudio @@ -73,7 +86,7 @@ Reads & parses (to varying degrees): * DSS * VQF - ¤ audio-lossless: + ¤ audio-lossless: * AIFF * AU * Bonk @@ -92,17 +105,17 @@ Reads & parses (to varying degrees): * WAV (RIFF) * WavPack - ¤ audio-video: + ¤ audio-video: * ASF: ASF, Windows Media Audio (WMA), Windows Media Video (WMV) * AVI (RIFF) * Flash * Matroska (MKV) * MPEG-1 / MPEG-2 * NSV (Nullsoft Streaming Video) - * Quicktime + * Quicktime (including MP4) * RealVideo - ¤ still image: + ¤ still image: * BMP * GIF * JPEG @@ -111,7 +124,7 @@ Reads & parses (to varying degrees): * SWF (Flash) * PhotoCD - ¤ data: + ¤ data: * ISO-9660 CD-ROM image (directory structure) * SZIP (limited support) * ZIP (directory structure) @@ -132,10 +145,11 @@ Writes: Requirements =========================================================================== -* PHP 4.2.0 (or higher) for getID3() 1.7.x (and earlier) -* PHP 5.3.0 (or higher) for getID3() 1.8.x (and up) -* PHP 5.0.0 (or higher) for getID3() 2.0.x (and up) -* at least 4MB memory for PHP. 8MB is highly recommended. +* PHP 4.2.0 up to 5.2.x for getID3() 1.7.x (and earlier) +* PHP 5.0.5 (or higher) for getID3() 1.8.x (and up) +* PHP 5.3.0 (or higher) for getID3() 1.9.17 (and up) +* PHP 5.3.0 (or higher) for getID3() 2.0.x (and up) +* at least 4MB memory for PHP. 8MB or more is highly recommended. 12MB is required with all modules loaded. @@ -164,24 +178,32 @@ like this: // Copy remote file locally to scan with getID3() $remotefilename = 'http://www.example.com/filename.mp3'; if ($fp_remote = fopen($remotefilename, 'rb')) { - $localtempfilename = tempnam('/tmp', 'getID3'); - if ($fp_local = fopen($localtempfilename, 'wb')) { - while ($buffer = fread($fp_remote, 8192)) { - fwrite($fp_local, $buffer); - } - fclose($fp_local); + $localtempfilename = tempnam('/tmp', 'getID3'); + if ($fp_local = fopen($localtempfilename, 'wb')) { + while ($buffer = fread($fp_remote, 32768)) { + fwrite($fp_local, $buffer); + } + fclose($fp_local); + + $remote_headers = array_change_key_case(get_headers($remotefilename, 1), CASE_LOWER); + $remote_filesize = (isset($remote_headers['content-length']) ? (is_array($remote_headers['content-length']) ? $remote_headers['content-length'][count($remote_headers['content-length']) - 1] : $remote_headers['content-length']) : null); // Initialize getID3 engine $getID3 = new getID3; - $ThisFileInfo = $getID3->analyze($filename); + $ThisFileInfo = $getID3->analyze($localtempfilename, $remote_filesize, basename($remotefilename)); - // Delete temporary file - unlink($localtempfilename); - } - fclose($fp_remote); + // Delete temporary file + unlink($localtempfilename); + } + fclose($fp_remote); } +Note: since v1.9.9-20150212 it is possible a second and third parameter +to $getID3->analyze(), for original filesize and original filename +respectively. This permits you to download only a portion of a large remote +file but get accurate playtime estimates, assuming the format only requires +the beginning of the file for correct format analysis. See /demos/demo.write.php for how to write tags. @@ -279,6 +301,7 @@ could essentially write it today with a one-line function: Future Plans =========================================================================== +https://www.getid3.org/phpBB3/viewforum.php?f=7 * Better support for MP4 container format * Scan for appended ID3v2 tag at end of file per ID3v2.4 specs (Section 5.0) @@ -296,7 +319,7 @@ Future Plans (http://web.inter.nl.net/users/hvdh/lossless/lossless.htm) * Support for RIFF-INFO chunks * http://lotto.st-andrews.ac.uk/~njh/tag_interchange.html - (thanks Nick Humfrey ) + (thanks Nick Humfrey ) * http://abcavi.narod.ru/sof/abcavi/infotags.htm (thanks Kibi) * Better support for Bink video @@ -311,23 +334,23 @@ Future Plans * Support for IFF * Support for ICO * Support for ANI -* Support for EXE (comments, author, etc) (thanks p*quaedackersØplanet*nl) +* Support for EXE (comments, author, etc) (thanks p*quaedackersØplanet*nl) * Support for DVD-IFO (region, subtitles, aspect ratio, etc) - (thanks p*quaedackersØplanet*nl) + (thanks p*quaedackersØplanet*nl) * More complete support for SWF - parsing encapsulated MP3 and/or JPEG content - (thanks n8n8Øyahoo*com) + (thanks n8n8Øyahoo*com) * Support for a2b * Optional scan-through-frames for AVI verification - (thanks rockcohenØmassive-interactive*nl) -* Support for TTF (thanks infoØbutterflyx*com) -* Support for DSS (http://www.getid3.org/phpBB3/viewtopic.php?t=171) + (thanks rockcohenØmassive-interactive*nl) +* Support for TTF (thanks infoØbutterflyx*com) +* Support for DSS (https://www.getid3.org/phpBB3/viewtopic.php?t=171) * Support for SMAF (http://smaf-yamaha.com/what/demo.html) - http://www.getid3.org/phpBB3/viewtopic.php?t=182 -* Support for AMR (http://www.getid3.org/phpBB3/viewtopic.php?t=195) -* Support for 3gpp (http://www.getid3.org/phpBB3/viewtopic.php?t=195) -* Support for ID4 (http://www.wackysoft.cjb.net grizlyY2KØhotmail*com) + https://www.getid3.org/phpBB3/viewtopic.php?t=182 +* Support for AMR (https://www.getid3.org/phpBB3/viewtopic.php?t=195) +* Support for 3gpp (https://www.getid3.org/phpBB3/viewtopic.php?t=195) +* Support for ID4 (http://www.wackysoft.cjb.net grizlyY2KØhotmail*com) * Parse XML data returned in Ogg comments -* Parse XML data from Quicktime SMIL metafiles (klausrathØmac*com) +* Parse XML data from Quicktime SMIL metafiles (klausrathØmac*com) * ID3v2 genre string creator function * More complete parsing of JPG * Support for all old-style ASF packets @@ -360,6 +383,7 @@ Future Plans Known Bugs/Issues in getID3() that may be fixed eventually =========================================================================== +https://www.getid3.org/phpBB3/viewtopic.php?t=25 * Cannot determine bitrate for MPEG video with VBR video data (need documentation) @@ -385,13 +409,16 @@ Known Bugs/Issues in getID3() that may be fixed eventually Known Bugs/Issues in getID3() that cannot be fixed -------------------------------------------------- +https://www.getid3.org/phpBB3/viewtopic.php?t=25 -* Files larger than 2GB cannot always be parsed fully by getID3() - due to limitations in the PHP filesystem functions. +* 32-bit PHP installations only: + Files larger than 2GB cannot always be parsed fully by getID3() + due to limitations in the 32-bit PHP filesystem functions. NOTE: Since v1.7.8b3 there is partial support for larger-than- 2GB files, most of which will parse OK, as long as no critical data is located beyond the 2GB offset. Known will-work: + * all file formats on 64-bit PHP * ZIP (format doesn't support files >2GB) * FLAC (current encoders don't support files >2GB) Known will-not-work: @@ -407,12 +434,20 @@ Known Bugs/Issues in getID3() that cannot be fixed "movi" chunk that fits in the first 2GB, should issue error to show that playtime is incorrect. Other data should be mostly correct, assuming that data is constant throughout the file) - +* PHP <= v5 on Windows cannot read UTF-8 filenames Known Bugs/Issues in other programs ----------------------------------- +https://www.getid3.org/phpBB3/viewtopic.php?t=25 +* MusicBrainz Picard (at least up to v1.3.2) writes multiple + ID3v2.3 genres in non-standard forward-slash separated text + rather than parenthesis-numeric+refinement style per the ID3v2.3 + specs. Tags written in ID3v2.4 mode are written correctly. + (detected and worked around by getID3()) +* PZ TagEditor v4.53.408 has been known to insert ID3v2.3 frames + into an existing ID3v2.2 tag which, of course, breaks things * Windows Media Player (up to v11) and iTunes (up to v10+) do not correctly handle ID3v2.3 tags with UTF-16BE+BOM encoding (they assume the data is UTF-16LE+BOM and either @@ -432,6 +467,11 @@ Known Bugs/Issues in other programs written just "value" (detected by getID3()) * Oggenc 0.9-rc3 flags the encoded file as ABR whether it's actually ABR or VBR. +* iTunes (versions "v7.0.0.70" is known-guilty, probably + other versions are too) writes ID3v2.3 comment tags using an + ID3v2.2 frame name (3-bytes) null-padded to 4 bytes which is + not valid for ID3v2.3+ + (detected by getID3() since 1.9.12-201603221746) * iTunes (versions "X v2.0.3", "v3.0.1" are known-guilty, probably other versions are too) writes ID3v2.3 comment tags using a frame name 'COM ' which is not valid for ID3v2.3+ (it's an @@ -481,6 +521,9 @@ Known Bugs/Issues in other programs * iTunes has been known to append a new ID3v1 tag on the end of an existing ID3v1 tag when ID3v2 tag is also present (detected by getID3()) +* MediaMonkey may write a blank RGAD ID3v2 frame but put actual + replay gain adjustments in a series of user-defined TXXX frames + (detected and handled by getID3() since v1.9.2) @@ -578,4 +621,8 @@ Reference material: * http://pda.etsi.org/pda/queryform.asp * http://cpansearch.perl.org/src/RGIBSON/Audio-DSS-0.02/lib/Audio/DSS.pm * http://trac.musepack.net/trac/wiki/SV8Specification -* http://wyday.com/cuesharp/specification.php \ No newline at end of file +* http://wyday.com/cuesharp/specification.php +* http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html +* http://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header +* http://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf +* https://fileformats.fandom.com/wiki/Torrent_file \ No newline at end of file diff --git a/serendipity_event_podcast/player/james-heinrich/getid3/structure.txt b/serendipity_event_podcast/player/james-heinrich/getid3/structure.txt new file mode 100644 index 00000000..c6d7f7ef --- /dev/null +++ b/serendipity_event_podcast/player/james-heinrich/getid3/structure.txt @@ -0,0 +1,2276 @@ +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich // +// available at http://getid3.sourceforge.net // +// or https://www.getid3.org // +// also https://github.com/JamesHeinrich/getID3 // +///////////////////////////////////////////////////////////////// +// // +// changelog.txt - part of getID3() // +// See readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +What does the returned data structure look like? +================================================ + +Hint: If you take a look at the nicely-formatted output of +/demos/demo.browse.php you can generally see where the data you want +is returned. + +Note that what is described below is only a rough guide to what data +is actually returned by getID3(), since the actual data returned +depends entirely on what data is in your file, what type of file it +is, what kind of data is in the tags, etc. In addition, some formats +(Quicktime for example) use a freeform recursive structure that is +impossible to document completely. + +In the vast majority of cases, all the data you'll need is located +in the root of the array or the special arrays described below in +Section 1 (['audio'], ['video'], ['tags_html'], ['replay_gain']). + +It is suggested that for most applications you should use tag data +from the root ['tags_html'] array, as this is the only location +where data is stored in a consistant format: HTML-compatible +character entities (ie Ӓ) for characters outside the 0x20-0x7F +range (printable ISO-8859-1 characters). This data can be used as-is +for output in HTML, and can be converted to whatever character set +you wish to use if the output is not HTML. + +If you want to merge all available tags (for example, ID3v2 + ID3v1) +into one array, you can call +getid3_lib::CopyTagsToComments($ThisFileInfo) +and you'll then have ['comments'] and ['comments_html'] which are +identical to ['tags'] and ['tags_html'] except the array is one +dimension shorter (no tag type array keys). For example, artist is: +['tags_html']['id3v1']['artist'][0] or ['comments_html']['artist'][0] + + +Some commonly-used information is found in these locations: + +File type: ['fileformat'] // ex 'mp3' +Song length: ['playtime_string'] // ex '3:45' (minutes:seconds) + ['playtime_seconds'] // ex 225.13 (seconds) +Overall bitrate: ['bitrate'] // ex 113485.71 (bits-per-second - divide by 1000 for kbps) +Audio frequency: ['audio']['sample_rate'] // ex 44100 (Hertz) +Artist name: ['comments_html']['artist'][0] // ex 'Elvis' (if CopyTagsToComments() is used - see above) + // more than one artist may be present, you may want to use implode: + // implode(' & ', ['comments_html']['artist']) + + +///////////////////////////////////////////////////////////////// + +array() { + // SECTION 1: Values that are present for most or all file types + + ['getID3version']=>string() // version of getID3() that scanned this file (ex: '1.6.2') + ['error']=>array() // if present, contains one or more fatal error messages + ['warning']=>array() // if present, contains one or more non-fatal warning messages + ['exist']=>boolean() // does this file actually exist? + ['fileformat']=>string() // one of the standard filetype abbreviations ('mp3', 'riff', 'quicktime', etc) + ['filename']=>string() // filename only, no path + ['filenamepath']=>string() // full filename with path + ['filepath']=>string() // path to file, not including filename + ['filesize']=>integer() // filesize in bytes + ['md5_file']=>string() // md5 hash of entire file + ['md5_data']=>string() // md5 hash of portion of file excluding prepended and appeneded metainformation tags (ID3, APE, etc) - may be identical to ['md5_file'] + ['md5_data_source']=>string() // md5 hash of original source file before compression (currently used by FLAC, OptimFROG, WavPack v4+) + ['sha1_file']=>string() // sha1 hash of entire file + ['sha1_data']=>string() // sha1 hash of portion of file excluding prepended and appeneded metainformation tags (ID3, APE, etc) - may be identical to ['md5_file'] + ['avdataoffset']=>integer() // offset in bytes where audio/video data starts and prepended tags end + ['avdataend']=>integer() // offset in bytes where audio/video data ends and appended tags start + ['bitrate']=>double() // average bitrate for entire file (all audio/video streams), in bits per second + ['mime_type']=>string() // if present, MIME type of scanned file + ['playtime_seconds']=>double() // playing time of file, in seconds + ['playtime_string']=>string() // playing time of file, formatted as : + ['tags']=>array() // array of all metainformation tags present in file ('id3v1', 'id3v2', 'ape', 'riff', 'asf', etc) + ['audio']=>array() { + ['bitrate']=>double() // average bitrate for audio portion of file (all audio streams), in bits per second + ['bitrate_mode']=>string() // 'cbr' (Constant Bit Rate) or 'vbr' (Variable Bit Rate) + ['bits_per_sample']=>integer() // + ['channelmode']=>string() // 'mono' or 'stereo' + ['channels']=>integer() // number of audio channels + ['codec']=>string() // name of audio compression codec + ['compression_ratio']=>double() // ratio of compressed byte size of audio to uncompressed size + ['dataformat']=>string() // one of the standard filetype abbreviations ('mp3', 'wma', etc) + ['encoder']=>string() // name and version of encoder used to create file, if known + ['lossless']=>boolean() // true = lossless compression; false = lossy compression + ['sample_rate']=>integer() + } + ['video']=>array() { + ['bitrate']=>integer() // average bitrate for video portion of file (all video streams), in bits per second + ['bitrate_mode']=>string() // 'cbr' (Constant Bit Rate) or 'vbr' (Variable Bit Rate) + ['bits_per_sample']=>integer() // + ['codec']=>string() // name of video compression codec + ['compression_ratio']=>double() // ratio of compressed byte size of video to uncompressed size + ['dataformat']=>string() // one of the standard filetype abbreviations ('avi', 'mpeg', etc) + ['encoder']=>string() // name and version of encoder used to create file, if known + ['frame_rate']=>double() // frames per second + ['lossless']=>boolean() // true = lossless compression; false = lossy compression + ['resolution_x']=>integer() // horizontal dimension of video/image in pixels + ['resolution_y']=>integer() // vertical dimension of video/image in pixels + ['pixel_aspect_ratio']=>double() // pixel display aspect ratio + } + ['tags']=>array() { // array of array of strings containing best data from any available metainformation tag (APE, ID3v2, ID3v1, Lyrics3, Vorbis, ASF, RIFF, Real, etc.) + []=>array() // can be anything, usually 'artist', 'title', etc. Contains array of one or more values (eg: multiple artists are possible) + } + ['tags_html']=>array() { // identical to ['tags'], but with all entries converted to HTML entities as appropriate from various source encodings + []=>array() // + } + ['replay_gain']=>array() { // replay gain information combined from any source that contains this information (LAME, ID3v2, Vorbis, APE, etc) + ['audiophile']=>array() { + ['adjustment']=>double() + ['originator']=>string() + ['peak']=>double() + } + ['radio']=>array() { + ['adjustment']=>double() + ['originator']=>string() + ['peak']=>double() + } + } + + + // SECTION 2: Values that are present for specific file types only + + ['aac']=>array() { // AAC - Advanced Audio Coding / MPEG-4 + ['bitrate_distribution']=>array() // + ['header']=>array() { // + ['channel_configuration']=>integer() // + ['crc_present']=>boolean() // + ['home']=>boolean() // + ['layer']=>integer() // + ['mpeg_version']=>integer() // + ['original']=>boolean() // + ['private']=>boolean() // + ['profile_id']=>integer() // + ['profile_text']=>string() // + ['sample_frequency']=>integer() // + ['sample_frequency_index']=>integer() // + ['synch']=>integer() // + } // + ['header_type']=>string() // + } // + // + ['ape']=>array() // + { // + ['comments']=>array() { // array of array of strings containing best data from any available metainformation tag (APE, ID3v2, ID3v1, Lyrics3, Vorbis, ASF, RIFF, Real, etc.) + []=>array() // can be anything, usually 'artist', 'title', etc. Contains array of one or more values (eg: multiple artists are possible) + } // + ['footer']=>array() // + { // + ['flags']=>array() // + ['raw']=>array() // + ['tag_version']=>integer() // + } // + ['header']=>array() // + { // + ['flags']=>array() // + ['raw']=>array() // + ['tag_version']=>integer() // + } // + ['items']=>array() { // array of array of strings containing metainformation + []=>array() { // can be anything, usually 'artist', 'title', etc. Contains array of one or more values (eg: multiple artists are possible) + ['data']=>array() { // array of one or more Unicode values + ['data_ascii']=>array() { // array of values converted approximately from Unicode to ASCII + ['flags']=>array() // + } // + } // + ['tag_offset_end']=>integer() // + ['tag_offset_start']=>integer() // + } // + + + ['asf']=>array() { // ASF - Advanced Streaming Format (ASF, Windows Media Audio (WMA), Windows Media Video (WMV)) + ['audio_media']=>array() { // + []=>array() { // + ['bitrate']=>integer() // + ['bits_per_sample']=>integer() // + ['channels']=>integer() // + ['codec']=>string() // + ['codec_data']=>string() // + ['codec_data_size']=>integer() // + ['raw']=>array() { // + ['nAvgBytesPerSec']=>integer() // + ['wBitsPerSample']=>integer() // + ['nBlockAlign']=>integer() // + ['nChannels']=>integer() // + ['nSamplesPerSec']=>integer() // + ['wFormatTag']=>integer() // + } // + ['sample_rate']=>integer() // + } // + } // + ['codec_list']=>array() { // + ['codec_entries']=>array() { // + []=>array() { // + ['description']=>string() // + ['description_ascii']=>string() // + ['information']=>string() // + ['name']=>string() // + ['name_ascii']=>string() // + ['type']=>string() // + ['type_raw']=>integer() // + } // + } // + ['codec_entries_count']=>integer() // + ['objectid']=>string() // + ['objectid_guid']=>string() // + ['objectsize']=>integer() // + ['reserved']=>string() // + ['reserved_guid']=>string() // + } // + ['comments']=>array() { // array of comment values, derived from ['content_description'] + ['album']=>string() // + ['artist']=>string() // + ['comment']=>string() // + ['copyright']=>string() // + ['genre']=>string() // + ['title']=>string() // + ['track']=>string() // + ['year']=>string() // + } // + ['content_description']=>array() { // raw values - should use values from ['comments'] instead + ['author']=>string() // + ['author_ascii']=>string() // + ['author_length']=>integer() // + ['copyright']=>string() // + ['copyright_ascii']=>string() // + ['copyright_length']=>integer() // + ['description']=>string() // + ['description_ascii']=>string() // + ['description_length']=>integer() // + ['objectid']=>string() // + ['objectid_guid']=>string() // + ['objectsize']=>integer() // + ['rating']=>string() // + ['rating_ascii']=>string() // + ['rating_length']=>integer() // + ['title']=>string() // + ['title_ascii']=>string() // + ['title_length']=>integer() // + } // + ['data_object']=>array() { // + ['fileid']=>string() // + ['fileid_guid']=>string() // + ['objectid']=>string() // + ['objectid_guid']=>string() // + ['objectsize']=>integer() // + ['reserved']=>integer() // + ['total_data_packets']=>integer() // + } // + ['extended_content_description']=>array() { // + ['content_descriptors']=>array() { // + []=>array() { // + ['name']=>string() // + ['name_ascii']=>string() // + ['name_length']=>integer() // + ['value']=>string() // + ['value_ascii']=>string() // + ['value_length']=>integer() // + ['value_type']=>integer() // + } // + } // + ['content_descriptors_count']=>integer() // + ['objectid']=>string() // + ['objectid_guid']=>string() // + ['objectsize']=>integer() // + } // + ['file_properties_object']=>array() { // + ['creation_date']=>double() // + ['creation_date_unix']=>double() // + ['data_packets']=>integer() // + ['fileid']=>string() // + ['fileid_guid']=>string() // + ['filesize']=>integer() // + ['flags']=>array() { // + ['broadcast']=>boolean() // + ['seekable']=>boolean() // + } // + ['flags_raw']=>integer() // + ['max_bitrate']=>integer() // + ['max_packet_size']=>integer() // + ['min_packet_size']=>integer() // + ['objectid']=>string() // + ['objectid_guid']=>string() // + ['objectsize']=>integer() // + ['play_duration']=>double() // + ['preroll']=>integer() // + ['send_duration']=>double() // + } // + ['header_extension_object']=>array() { // + ['extension_data']=>integer() // + ['extension_data_size']=>integer() // + ['objectid']=>string() // + ['objectid_guid']=>string() // + ['objectsize']=>integer() // + ['reserved_1']=>string() // + ['reserved_1_guid']=>string() // + ['reserved_2']=>integer() // + } // + ['header_object']=>array() { // + ['headerobjects']=>integer() // + ['objectid']=>string() // + ['objectid_guid']=>string() // + ['objectsize']=>integer() // + ['reserved1']=>integer() // + ['reserved2']=>integer() // + } // + ['marker_object']=>array() { // + ['markers_count']=>integer() // + ['objectid']=>string() // + ['objectid_guid']=>string() // + ['objectsize']=>integer() // + ['reserved']=>string() // + ['reserved_2']=>integer() // + ['reserved_guid']=>string() // + } // + ['stream_bitrate_properties']=>array() { // + ['bitrate_records']=>array() { // + []=>array() { // + ['bitrate']=>integer() // + ['flags_raw']=>integer() // + ['flags']=>array() { // + ['stream_number']=>integer() // + } // + } // + } // + ['bitrate_records_count']=>integer() // + ['objectid']=>string() // + ['objectid_guid']=>string() // + ['objectsize']=>integer() // + } // + ['stream_properties_object']=>array() { // + []=>array() { // + ['error_correct_data']=>string() // + ['error_correct_guid']=>string() // + ['error_correct_type']=>string() // + ['error_data_length']=>integer() // + ['flags_raw']=>integer() // + ['flags']=>array() { // + ['encrypted']=>boolean() // + } // + ['objectid']=>string() // + ['objectid_guid']=>string() // + ['objectsize']=>integer() // + ['stream_type']=>string() // + ['stream_type_guid']=>string() // + ['time_offset']=>integer() // + ['type_data_length']=>integer() // + ['type_specific_data']=>string() // + } // + } // + ['video_media']=>array() { // + []=>array() { // + ['flags']=>integer() // + ['format_data']=>array() { // + ['bits_per_pixel']=>integer() // + ['codec']=>string() // + ['codec_data']=>boolean() // + ['codec_fourcc']=>string() // + ['colors_important']=>integer() // + ['colors_used']=>integer() // + ['format_data_size']=>integer() // + ['horizontal_pels']=>integer() // + ['image_height']=>integer() // + ['image_size']=>integer() // + ['image_width']=>integer() // + ['reserved']=>integer() // + ['vertical_pels']=>integer() // + } // + ['format_data_size']=>integer() // + ['image_height']=>integer() // + ['image_width']=>integer() // + } // + } // + } // + + + ['au']=>array() { // AU - Next/Sun AUdio format + ['bits_per_sample']=>integer() // + ['channels']=>integer() // + ['comment']=>string() // + ['data_format']=>string() // + ['data_format_id']=>integer() // + ['data_size']=>integer() // + ['header_length']=>integer() // + ['sample_rate']=>integer() // + ['used_bits_per_sample']=>integer() // + } // + + + ['bmp']=>array() { // BMP - OS/2 or Windows BitMaP + ['header']=>array() { // + ['compression']=>string() // + ['raw']=>array() { // + ['bits_per_pixel']=>integer() // + ['bmp_data_size']=>integer() // + ['colors_important']=>integer() // + ['colors_used']=>integer() // + ['compression']=>integer() // + ['data_offset']=>integer() // + ['filesize']=>integer() // + ['header_size']=>integer() // + ['height']=>integer() // + ['identifier']=>string() // + ['planes']=>integer() // + ['resolution_h']=>integer() // + ['resolution_v']=>integer() // + ['width']=>integer() // + } // + } // + ['type_os']=>string() // + ['type_version']=>integer() // + } // + + + ['bonk']=>array() { // BONK - lossy/lossless audio compression (www.bonkenc.org) + ['BONK']=>array() { // + ['channels']=>integer() // + ['downsampling_ratio']=>integer() // + ['joint_stereo']=>boolean() // + ['lossless']=>boolean() // + ['number_samples']=>integer() // + ['number_taps']=>integer() // + ['offset']=>integer() // + ['sample_rate']=>integer() // + ['samples_per_packet']=>integer() // + ['size']=>integer() // + ['version']=>integer() // + } // + ['INFO']=>array() { // + ['size']=>integer() // + ['offset']=>integer() // + ['version']=>integer() // + []=>array() { // + ['nextbit']=>integer() // + ['offset']=>integer() // + } // + } // + ['dataend']=>integer() // + ['dataoffset']=>integer() // + } // + + + ['flac']=>array() { // FLAC - Free Lossless Audio Compressor + ['SEEKTABLE']=>array() { // + []=>array() { // + ['offset']=>integer() // + ['samples']=>integer() // + } // + ['placeholders']=>integer() // + ['raw']=>array() { // + ['block_data']=>string() // + ['block_length']=>integer() // + ['block_type']=>integer() // + ['block_type_text']=>string() // + ['last_meta_block']=>boolean() // + ['offset']=>integer() // + } // + } // + ['STREAMINFO']=>array() { // + ['audio_signature']=>string() // + ['bits_per_sample']=>integer() // + ['channels']=>integer() // + ['max_block_size']=>integer() // + ['max_frame_size']=>integer() // + ['min_block_size']=>integer() // + ['min_frame_size']=>integer() // + ['raw']=>array() { // + ['block_data']=>string() // + ['block_length']=>integer() // + ['block_type']=>integer() // + ['block_type_text']=>string() // + ['last_meta_block']=>boolean() // + ['offset']=>integer() // + } // + ['sample_rate']=>integer() // + ['samples_stream']=>integer() // + } // + ['VORBIS_COMMENT']=>array() { // + ['raw']=>array() { // + ['block_data']=>string() // + ['block_length']=>integer() // + ['block_type']=>integer() // + ['block_type_text']=>string() // + ['last_meta_block']=>boolean() // + ['offset']=>integer() // + } // + } // + ['compressed_audio_bytes']=>integer() // + ['compression_ratio']=>double() // + ['uncompressed_audio_bytes']=>integer() // + } // + + + ['gif']=>array() { // GIF - Graphics Interchange Format + ['global_color_table']=>array() { // + []=>integer() // + } // + ['header']=>array() { // + ['bits_per_pixel']=>integer() // + ['flags']=>array() { // + ['global_color_sorted']=>boolean() // + ['global_color_table']=>boolean() // + } // + ['global_color_size']=>integer() // + ['raw']=>array() { // + ['aspect_ratio']=>integer() // + ['bg_color_index']=>integer() // + ['flags']=>integer() // + ['height']=>integer() // + ['identifier']=>string() // + ['version']=>string() // + ['width']=>integer() // + } // + } // + ['version']=>string() // + } // + + + ['id3v1']=>array() { // ID3v1 + ['album']=>string() // + ['artist']=>string() // + ['comment']=>string() // + ['genre']=>string() // + ['genreid']=>integer() // + ['title']=>string() // + ['track']=>integer() // + ['year']=>string() // + ['padding_valid']=>boolean() // + ['comments']=>array() // + ['tag_offset_start']=>integer() // + ['tag_offset_end']=>integer() // + } // + + + ['id3v2']=>array() { // ID3v2 - www.id3.org + []=>array() { // can be any of the 4-character (3-character in ID3v2.2) frame names allowed in the ID3v2 spec. Exact contents of returned array data varies with frame type. + []=>array() { // some frames types allow multiple values ('COMM' for example), others do not and do not have this array level + ['asciidata']=>boolean() // + ['asciidescription']=>string() // + ['data']=>boolean() // + ['datalength']=>integer() // + ['dataoffset']=>integer() // + ['description']=>string() // + ['encoding']=>string() // + ['encodingid']=>integer() // + ['flags']=>array() { // + ['Encryption']=>boolean() // + ['FileAlterPreservation']=>boolean() // + ['GroupingIdentity']=>boolean() // + ['ReadOnly']=>boolean() // + ['TagAlterPreservation']=>boolean() // + ['compression']=>boolean() // + } // + ['framenamelong']=>string() // + ['language']=>string() // + ['languagename']=>string() // + } // + } // + ['comments']=>array() { // array of array of strings containing best data from any available metainformation tag (APE, ID3v2, ID3v1, Lyrics3, Vorbis, ASF, RIFF, Real, etc.) + []=>array() // can be anything, usually 'artist', 'title', etc. Contains array of one or more values (eg: multiple artists are possible) + } // + ['flags']=>array() { // + ['experim']=>string() // + ['exthead']=>string() // + ['unsynch']=>string() // + } // + ['header']=>boolean() // + ['headerlength']=>integer() // + ['majorversion']=>integer() // + ['minorversion']=>integer() // + ['padding']=>array() { // + ['length']=>integer() // + ['start']=>integer() // + ['valid']=>boolean() // + } // + ['tag_offset_end']=>integer() // + ['tag_offset_start']=>integer() // + } // + + + ['iso']=>array() { // ISO-9660 - CD-ROM Image + ['directories']=>array() { // + []=>array() { // + []=>array() { // + ['file_flags']=>array() { // + ['associated']=>boolean() // + ['directory']=>boolean() // + ['extended']=>boolean() // + ['hidden']=>boolean() // + ['multiple']=>boolean() // + ['permissions']=>boolean() // + } // + ['file_identifier_ascii']=>string() // + ['filename']=>string() // + ['filesize']=>integer() // + ['offset_bytes']=>integer() // + ['raw']=>array() { // + ['extended_attribute_length']=>integer() // + ['file_flags']=>integer() // + ['file_identifier']=>string() // + ['file_identifier_length']=>integer() // + ['file_unit_size']=>integer() // + ['filesize']=>integer() // + ['interleave_gap_size']=>integer() // + ['length']=>integer() // + ['offset_logical']=>integer() // + ['recording_date_time']=>string() // + ['volume_sequence_number']=>integer() // + } // + ['recording_timestamp']=>integer() // + } // + } // + } // + ['files']=>array() { // multidimensional tree-structure array listing of all files and directories in image + []=>array() // entries of type array are directories (key is directory name), may contain files and/or other subdirectories + []=>integer() // entries of type integer are files (key is file name, value is file size in bytes) + } // + ['path_table']=>array() { // + ['directories']=>array() { // + []=>array() { // + ['extended_length']=>integer() // + ['full_path']=>string() // + ['length']=>integer() // + ['location_bytes']=>integer() // + ['location_logical']=>integer() // + ['name']=>string() // + ['name_ascii']=>string() // + ['parent_directory']=>integer() // + } // + } // + ['offset']=>integer() // + ['raw']=>string() // + } // + ['primary_volume_descriptor']=>array() { // + ['abstract_file_identifier']=>string() // + ['application_identifier']=>string() // + ['bibliographic_file_identifier']=>string() // + ['copyright_file_identifier']=>string() // + ['data_preparer_identifier']=>string() // + ['offset']=>integer() // + ['publisher_identifier']=>string() // + ['raw']=>array() { // + ['abstract_file_identifier']=>string() // + ['application_data']=>string() // + ['application_identifier']=>string() // + ['bibliographic_file_identifier']=>string() // + ['copyright_file_identifier']=>string() // + ['data_preparer_identifier']=>string() // + ['file_structure_version']=>integer() // + ['logical_block_size']=>integer() // + ['path_table_l_location']=>integer() // + ['path_table_l_opt_location']=>integer() // + ['path_table_m_location']=>integer() // + ['path_table_m_opt_location']=>integer() // + ['path_table_size']=>integer() // + ['publisher_identifier']=>string() // + ['root_directory_record']=>string() // + ['standard_identifier']=>string() // + ['system_identifier']=>string() // + ['unused_1']=>string() // + ['unused_2']=>string() // + ['unused_3']=>string() // + ['unused_4']=>integer() // + ['volume_creation_date_time']=>string() // + ['volume_descriptor_type']=>integer() // + ['volume_descriptor_version']=>integer() // + ['volume_effective_date_time']=>string() // + ['volume_expiration_date_time']=>string() // + ['volume_identifier']=>string() // + ['volume_modification_date_time']=>string() // + ['volume_sequence_number']=>integer() // + ['volume_set_identifier']=>string() // + ['volume_set_size']=>integer() // + ['volume_space_size']=>integer() // + } // + ['system_identifier']=>string() // + ['volume_creation_date_time']=>integer() // + ['volume_effective_date_time']=>boolean() // + ['volume_expiration_date_time']=>boolean() // + ['volume_identifier']=>string() // + ['volume_modification_date_time']=>integer() // + ['volume_set_identifier']=>string() // + } // + ['supplementary_volume_descriptor']=>array() { // + ['abstract_file_identifier']=>string() // + ['application_identifier']=>string() // + ['bibliographic_file_identifier']=>string() // + ['copyright_file_identifier']=>string() // + ['data_preparer_identifier']=>string() // + ['offset']=>integer() // + ['publisher_identifier']=>string() // + ['raw']=>array() { // + ['abstract_file_identifier']=>string() // + ['application_data']=>string() // + ['application_identifier']=>string() // + ['bibliographic_file_identifier']=>string() // + ['copyright_file_identifier']=>string() // + ['data_preparer_identifier']=>string() // + ['file_structure_version']=>integer() // + ['logical_block_size']=>integer() // + ['path_table_l_location']=>integer() // + ['path_table_l_opt_location']=>integer() // + ['path_table_m_location']=>integer() // + ['path_table_m_opt_location']=>integer() // + ['path_table_size']=>integer() // + ['publisher_identifier']=>string() // + ['root_directory_record']=>string() // + ['standard_identifier']=>string() // + ['system_identifier']=>string() // + ['unused_1']=>string() // + ['unused_2']=>string() // + ['unused_3']=>string() // + ['unused_4']=>integer() // + ['volume_creation_date_time']=>string() // + ['volume_descriptor_type']=>integer() // + ['volume_descriptor_version']=>integer() // + ['volume_effective_date_time']=>string() // + ['volume_expiration_date_time']=>string() // + ['volume_identifier']=>string() // + ['volume_modification_date_time']=>string() // + ['volume_sequence_number']=>integer() // + ['volume_set_identifier']=>string() // + ['volume_set_size']=>integer() // + ['volume_space_size']=>integer() // + } // + ['system_identifier']=>string() // + ['volume_creation_date_time']=>integer() // + ['volume_effective_date_time']=>boolean() // + ['volume_expiration_date_time']=>boolean() // + ['volume_identifier']=>string() // + ['volume_modification_date_time']=>integer() // + ['volume_set_identifier']=>string() // + } // + } // + + + ['jpg']=>array() { // JPEG - still image + ['exif']=>array() // data returned from PHP's exif_read_data() function + } // + + + ['la']=>array() { // LA - Lossless Audio (www.lossless-audio.com) + ['raw']=>array() { + ['format']=>integer() // + ['flags']=>integer() // + } // + ['flags']=>array() { // + ['seekable']=>boolean() // + ['high_compression']=>boolean() // + } // + ['bits_per_sample']=>integer() // + ['bytes_per_sample']=>integer() // + ['bytes_per_second']=>integer() // + ['channels']=>integer() // + ['compression_ratio']=>double() // + ['format_size']=>integer() // + ['header_size']=>integer() // + ['original_crc']=>double() // + ['sample_rate']=>integer() // + ['samples']=>integer() // + ['uncompressed_size']=>integer() // + ['version']=>double() // + ['version_major']=>integer() // + ['version_minor']=>integer() // + ['footerstart']=>double() // + } + + + ['lpac']=>array() { // LPAC - Lossless Predictive Audio Compressor + ['block_length']=>integer() // + ['file_version']=>integer() // + ['flags']=>array() { // + ['16_bit']=>boolean() // + ['24_bit']=>boolean() // + ['adaptive_prediction_order']=>boolean() // + ['adaptive_quantization']=>boolean() // + ['fast_compress']=>boolean() // + ['is_wave']=>boolean() // + ['joint_stereo']=>boolean() // + ['max_prediction_order']=>integer() // + ['quantization']=>integer() // + ['random_access']=>boolean() // + ['stereo']=>boolean() // + } // + ['raw']=>array() { // + ['audio_type']=>integer() // + ['parameters']=>double() // + } // + ['total_samples']=>integer() // + } // + + + ['lyrics3']=>array() { // Lyrics3 - metainformation tags + ['comments']=>array() { // + ['album']=>string() // + ['artist']=>string() // + ['author']=>string() // + ['comment']=>string() // + ['title']=>string() // + } // + ['flags']=>array() { // + ['lyrics']=>boolean() // + ['timestamps']=>boolean() // + } // + ['images']=>array() { // + []=>array() { // + ['description']=>string() // + ['filename']=>string() // + ['timestamp']=>integer() // + } // + } // + ['raw']=>array() { // + ['offset_start']=>integer() // + ['offset_end']=>integer() // + ['AUT']=>string() // + ['EAL']=>string() // + ['EAR']=>string() // + ['ETT']=>string() // + ['IMG']=>string() // + ['IND']=>string() // + ['INF']=>string() // + ['LYR']=>string() // + ['lyrics3tagsize']=>integer() // + ['lyrics3version']=>integer() // + ['unparsed']=>string() // + } // + ['synchedlyrics']=>array() { // + []=>string() // + } // + ['unsynchedlyrics']=>string() // + } // + + + ['midi']=>array() { // MIDI (Musical Instrument Digital Interface) - sequenced music + ['comments']=>array() { // + ['comment']=>string() // + ['copyright']=>string() // + } // + ['keysignature']=>array() { // + []=>string() // + } // + ['raw']=>array() { // + ['events']=>array() { // + []=>array() { // + []=>array() { // + ['us_qnote']=>integer() // + } // + } // + } // + ['fileformat']=>integer() // + ['headersize']=>integer() // + ['ticksperqnote']=>integer() // + ['track']=>array() { // + []=>array() { // + ['instrument']=>string() // + ['instrumentid']=>integer() // + ['name']=>string() // + } // + } // + ['tracks']=>integer() // + } // + ['timesignature']=>array() { // + []=>string() // + } // + ['totalticks']=>integer() // + } // + + + ['monkeys_audio']=>array() { // Monkey's Audio - lossless audio compression + ['bitrate']=>double() // + ['bits_per_sample']=>integer() // + ['channels']=>integer() // + ['compressed_size']=>integer() // + ['compression']=>string() // + ['compression_ratio']=>double() // + ['flags']=>array() { // + ['24-bit']=>boolean() // + ['8-bit']=>boolean() // + ['crc-32']=>boolean() // + ['no_wav_header']=>boolean() // + ['peak_level']=>boolean() // + ['seek_elements']=>boolean() // + } // + ['frames']=>integer() // + ['peak_level']=>integer() // + ['peak_ratio']=>double() // + ['playtime']=>double() // + ['raw']=>array() { // + ['header_tag']=>string() // + ['nChannels']=>integer() // + ['nCompressionLevel']=>integer() // + ['nFinalFrameSamples']=>integer() // + ['nFormatFlags']=>integer() // + ['nPeakLevel']=>integer() // + ['nSampleRate']=>integer() // + ['nSeekElements']=>integer() // + ['nTotalFrames']=>integer() // + ['nVersion']=>integer() // + ['nWAVHeaderBytes']=>integer() // + ['nWAVTerminatingBytes']=>integer() // + } // + ['sample_rate']=>integer() // + ['samples']=>integer() // + ['samples_per_frame']=>integer() // + ['uncompressed_size']=>integer() // + ['version']=>double() // + } // + + + ['mpc']=>array() { // MPC (Musepack) - lossy audio compression + ['header']=>array() { // + ['album_gain_db']=>integer() // + ['album_peak']=>integer() // + ['album_peak_db']=>boolean() // + ['title_gain_db']=>integer() // + ['title_peak']=>integer() // + ['title_peak_db']=>boolean() // + ['begin_loud']=>boolean() // + ['end_loud']=>boolean() // + ['encoder_version']=>string() // + ['frame_count']=>integer() // + ['intensity_stereo']=>boolean() // + ['last_frame_length']=>integer() // + ['max_level']=>integer() // + ['max_subband']=>integer() // + ['mid_side_stereo']=>boolean() // + ['profile']=>string() // + ['sample_rate']=>integer() // + ['samples']=>integer() // + ['size']=>integer() // + ['stream_major_version']=>integer() // + ['stream_minor_version']=>integer() // + ['true_gapless']=>boolean() // + ['raw']=>array() { // + ['album_gain']=>integer() // + ['album_peak']=>integer() // + ['encoder_version']=>integer() // + ['preamble']=>string() // + ['profile']=>integer() // + ['sample_rate']=>integer() // + ['title_gain']=>integer() // + ['title_peak']=>integer() // + } // + } // + } // + + + ['mpeg']=>array() { // MPEG (Motion Picture Experts Group) - MPEG video and/or MPEG audio (MP3/MP2/MP1) + ['audio']=>array() { // + ['LAME']=>array() { // + ['RGAD']=>array() { // + ['peak_amplitude']=>double() // + } // + ['ath_type']=>integer() // + ['audio_bytes']=>integer() // + ['bitrate_min']=>integer() // + ['encoder_delay']=>integer() // + ['encoding_flags']=>array() { // + ['nogap_next']=>boolean() // + ['nogap_prev']=>boolean() // + ['nspsytune']=>boolean() // + ['nssafejoint']=>boolean() // + } // + ['end_padding']=>integer() // + ['lame_tag_crc']=>integer() // + ['lowpass_frequency']=>integer() // + ['mp3_gain_db']=>double() // + ['mp3_gain_factor']=>double() // + ['mp3_gain_raw']=>integer() // + ['music_crc']=>integer() // + ['noise_shaping']=>integer() // + ['noise_shaping_raw']=>integer() // + ['not_optimal_quality']=>boolean() // + ['not_optimal_quality_raw']=>integer() // + ['preset_used_id']=>integer() // + ['short_version']=>string() // ex: "LAME 3.93" + ['long_version']=>string() // (pre-v3.90 only) ex: "LAME 3.88 (alpha)" + ['source_sample_freq']=>string() // + ['source_sample_freq_raw']=>integer() // + ['stereo_mode']=>string() // + ['stereo_mode_raw']=>integer() // + ['surround_info']=>string() // + ['surround_info_id']=>integer() // + ['tag_revision']=>integer() // + ['vbr_method']=>string() // + ['vbr_method_raw']=>integer() // + } // + ['VBR_bitrate']=>double() // + ['VBR_bytes']=>integer() // + ['VBR_frames']=>integer() // + ['VBR_method']=>string() // + ['VBR_scale']=>integer() // + ['bitrate']=>integer() // + ['bitrate_distribution']=>array() { // + ['free']=>integer() // + ['8']=>integer() // + ['16']=>integer() // + ['24']=>integer() // + ['32']=>integer() // + ['40']=>integer() // + ['48']=>integer() // + ['56']=>integer() // + ['64']=>integer() // + ['80']=>integer() // + ['96']=>integer() // + ['112']=>integer() // + ['128']=>integer() // + ['144']=>integer() // + ['160']=>integer() // + } // + ['bitrate_mode']=>string() // + ['channelmode']=>string() // + ['channels']=>integer() // + ['copyright']=>boolean() // + ['crc']=>integer() // + ['emphasis']=>string() // + ['frame_count']=>integer() // + ['framelength']=>integer() // + ['layer']=>integer() // + ['modeextension']=>string() // + ['original']=>boolean() // + ['padding']=>boolean() // + ['private']=>boolean() // + ['protection']=>boolean() // + ['raw']=>array() { // + ['bitrate']=>integer() // + ['channelmode']=>integer() // + ['copyright']=>integer() // + ['emphasis']=>integer() // + ['layer']=>integer() // + ['modeextension']=>integer() // + ['original']=>integer() // + ['padding']=>integer() // + ['private']=>integer() // + ['protection']=>integer() // + ['sample_rate']=>integer() // + ['synch']=>integer() // + ['version']=>integer() // + } // + ['sample_rate']=>integer() // + ['stereo_distribution']=>array() { // + ['dual channel']=>integer() // + ['joint stereo']=>integer() // + ['mono']=>integer() // + ['stereo']=>integer() // + } // + ['toc']=>array() { // + []=>integer() // + } // + ['version']=>string() // + ['version_distribution']=>array() { // + []=>integer() // + []=>integer() // + ['2.5']=>integer() // + } // + ['xing_flags']=>array() { // + ['bytes']=>boolean() // + ['frames']=>boolean() // + ['toc']=>boolean() // + ['vbr_scale']=>boolean() // + } // + ['xing_flags_raw']=>string() // + } // + ['video']=>array() { // + ['bitrate']=>integer() // + ['bitrate_mode']=>string() // + ['frame_rate']=>double() // + ['framesize_horizontal']=>integer() // + ['framesize_vertical']=>integer() // + ['pixel_aspect_ratio']=>double() // + ['pixel_aspect_ratio_text']=>string() // + ['raw']=>array() { // + ['bitrate']=>integer() // + ['constrained_param_flag']=>integer() // + ['frame_rate']=>integer() // + ['framesize_horizontal']=>integer() // + ['framesize_vertical']=>integer() // + ['intra_quant_flag']=>integer() // + ['marker_bit']=>integer() // + ['pixel_aspect_ratio']=>integer() // + ['vbv_buffer_size']=>integer() // + } // + } // + } // + + + ['nsv']=>array() { // NSV - Nullsoft Streaming Video + ['NSVf']=>array() { // + ['TOC_entries_1']=>integer() // + ['TOC_entries_2']=>integer() // + ['file_size']=>integer() // + ['header_length']=>integer() // + ['identifier']=>string() // + ['meta_size']=>integer() // + ['metadata']=>string() // + ['playtime_ms']=>integer() // + } // + ['NSVs']=>array() { // + ['audio_codec']=>string() // + ['frame_rate']=>double() // + ['framerate_index']=>integer() // + ['identifier']=>string() // + ['offset']=>integer() // + ['resolution_x']=>integer() // + ['resolution_y']=>integer() // + ['unknown1b']=>integer() // + ['unknown1c']=>integer() // + ['unknown1d']=>integer() // + ['unknown2a']=>integer() // + ['unknown2b']=>integer() // + ['unknown2c']=>integer() // + ['unknown2d']=>integer() // + ['unknown3a']=>integer() // + ['unknown3b']=>integer() // + ['unknown3c']=>integer() // + ['unknown3d']=>integer() // + ['video_codec']=>string() // + } // + ['comments']=>array() { // + ['aspect']=>string() // + ['title']=>string() // + } // + } // + + + ['ofr']=>array() { // OFR (OptimFROG) - lossless audio compression + ['COMP']=>array() { // + []=>array() { // + ['channel_configuration']=>string() // + ['crc_32']=>boolean() // + ['encoder']=>string() // + ['offset']=>integer() // + ['raw']=>array() { // + ['algorithm_id']=>integer() // + ['channel_configuration']=>integer() // + ['encoder_id']=>integer() // + ['sample_type']=>integer() // + } // + ['sample_count']=>integer() // + ['sample_type']=>string() // + ['size']=>integer() // + } // + } // + ['HEAD']=>array() { // + ['offset']=>integer() // + ['size']=>integer() // + } // + ['OFR ']=>array() { // + ['channel_config']=>integer() // + ['channels']=>integer() // + ['compression']=>string() // + ['encoder']=>string() // + ['offset']=>integer() // + ['raw']=>array() { // + ['compression']=>integer() // + ['encoder_id']=>integer() // + ['sample_type']=>integer() // + } // + ['sample_rate']=>integer() // + ['sample_type']=>string() // + ['size']=>integer() // + ['total_samples']=>integer() // + } // + ['TAIL']=>array() { // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + + + ['ogg']=>array() { // OGG - container format for Ogg Vorbis, OggFLAC, Speex, etc + ['bitrate_average']=>double() // + ['bitrate_max']=>integer() // + ['bitrate_min']=>integer() // + ['bitrate_nominal']=>integer() // + ['bitstreamversion']=>integer() // + ['blocksize_large']=>integer() // + ['blocksize_small']=>integer() // + ['comments']=>array() { // array of array of strings containing best data from any available metainformation tag (APE, ID3v2, ID3v1, Lyrics3, Vorbis, ASF, RIFF, Real, etc.) + []=>array() // can be anything, usually 'artist', 'title', etc. Contains array of one or more values (eg: multiple artists are possible) + } // + ['comments_raw']=>array() { // + []=>array() { // + ['dataoffset']=>integer() // + ['key']=>string() // + ['size']=>integer() // + ['value']=>string() // + } // + } // + ['numberofchannels']=>integer() // + ['pageheader']=>array() { // + []=>array() { // + ['flags']=>array() { // + ['bos']=>boolean() // + ['eos']=>boolean() // + ['fresh']=>boolean() // + } // + ['flags_raw']=>integer() // + ['header_end_offset']=>integer() // + ['packet_type']=>integer() // + ['page_checksum']=>double() // + ['page_end_offset']=>integer() // + ['page_length']=>integer() // + ['page_segments']=>integer() // + ['page_seqno']=>integer() // + ['page_start_offset']=>integer() // + ['pcm_abs_position']=>integer() // + ['segment_table']=>array() { // + []=>integer() // + } // + ['stream_serialno']=>integer() // + ['stream_structver']=>integer() // + ['stream_type']=>string() // + } // + ['eos']=>array() { // + ['flags']=>array() { // + ['bos']=>boolean() // + ['eos']=>boolean() // + ['fresh']=>boolean() // + } // + ['flags_raw']=>integer() // + ['header_end_offset']=>integer() // + ['page_checksum']=>double() // + ['page_end_offset']=>integer() // + ['page_length']=>integer() // + ['page_segments']=>integer() // + ['page_seqno']=>integer() // + ['page_start_offset']=>integer() // + ['pcm_abs_position']=>integer() // + ['segment_table']=>array() { // + []=>integer() // + } // + ['stream_serialno']=>integer() // + ['stream_structver']=>integer() // + } // + } // + ['samplerate']=>integer() // + ['samples']=>integer() // + ['stop_bit']=>integer() // + ['vendor']=>string() // + } // + + + ['png']=>array() { // PNG (Portable Network Graphics) - still image + ['IDAT']=>array() { // + []=>array() { // + ['header']=>array() { // + ['crc']=>integer() // + ['data_length']=>integer() // + ['flags']=>array() { // + ['ancilliary']=>boolean() // + ['private']=>boolean() // + ['reserved']=>boolean() // + ['safe_to_copy']=>boolean() // + } // + ['type_raw']=>double() // + ['type_text']=>string() // + } // + } // + } // + ['IEND']=>array() { // + ['header']=>array() { // + ['crc']=>double() // + ['data']=>string() // + ['data_length']=>integer() // + ['flags']=>array() { // + ['ancilliary']=>boolean() // + ['private']=>boolean() // + ['reserved']=>boolean() // + ['safe_to_copy']=>boolean() // + } // + ['type_raw']=>double() // + ['type_text']=>string() // + } // + } // + ['IHDR']=>array() { // + ['color_type']=>array() { // + ['alpha']=>boolean() // + ['palette']=>boolean() // + ['true_color']=>boolean() // + } // + ['compression_method_text']=>string() // + ['header']=>array() { // + ['crc']=>double() // + ['data']=>string() // + ['data_length']=>integer() // + ['flags']=>array() { // + ['ancilliary']=>boolean() // + ['private']=>boolean() // + ['reserved']=>boolean() // + ['safe_to_copy']=>boolean() // + } // + ['type_raw']=>double() // + ['type_text']=>string() // + } // + ['height']=>integer() // + ['raw']=>array() { // + ['bit_depth']=>integer() // + ['color_type']=>integer() // + ['compression_method']=>integer() // + ['filter_method']=>integer() // + ['interlace_method']=>integer() // + } // + ['width']=>integer() // + } // + ['PLTE']=>array() { // + ['header']=>array() { // + ['crc']=>double() // + ['data']=>string() // + ['data_length']=>integer() // + ['flags']=>array() { // + ['ancilliary']=>boolean() // + ['private']=>boolean() // + ['reserved']=>boolean() // + ['safe_to_copy']=>boolean() // + } // + ['type_raw']=>double() // + ['type_text']=>string() // + } // + []=>integer() // + } // + ['comments']=>array() { // array of array of strings containing best data from any available metainformation tag (APE, ID3v2, ID3v1, Lyrics3, Vorbis, ASF, RIFF, Real, etc.) + []=>array() // can be anything, usually 'artist', 'title', etc. Contains array of one or more values (eg: multiple artists are possible) + } // + ['gAMA']=>array() { // + ['gamma']=>double() // + ['header']=>array() { // + ['crc']=>integer() // + ['data']=>string() // + ['data_length']=>integer() // + ['flags']=>array() { // + ['ancilliary']=>boolean() // + ['private']=>boolean() // + ['reserved']=>boolean() // + ['safe_to_copy']=>boolean() // + } // + ['type_raw']=>double() // + ['type_text']=>string() // + } // + } // + ['oFFs']=>array() { // + ['header']=>array() { // + ['crc']=>double() // + ['data']=>string() // + ['data_length']=>integer() // + ['flags']=>array() { // + ['ancilliary']=>boolean() // + ['private']=>boolean() // + ['reserved']=>boolean() // + ['safe_to_copy']=>boolean() // + } // + ['type_raw']=>double() // + ['type_text']=>string() // + } // + ['position_x']=>integer() // + ['position_y']=>integer() // + ['unit']=>string() // + ['unit_specifier']=>integer() // + } // + ['pHYs']=>array() { // + ['header']=>array() { // + ['crc']=>integer() // + ['data']=>string() // + ['data_length']=>integer() // + ['flags']=>array() { // + ['ancilliary']=>boolean() // + ['private']=>boolean() // + ['reserved']=>boolean() // + ['safe_to_copy']=>boolean() // + } // + ['type_raw']=>double() // + ['type_text']=>string() // + } // + ['pixels_per_unit_x']=>integer() // + ['pixels_per_unit_y']=>integer() // + ['unit']=>string() // + ['unit_specifier']=>integer() // + } // + ['pcLb']=>array() { // + ['header']=>array() { // + ['crc']=>double() // + ['data']=>string() // + ['data_length']=>integer() // + ['flags']=>array() { // + ['ancilliary']=>boolean() // + ['private']=>boolean() // + ['reserved']=>boolean() // + ['safe_to_copy']=>boolean() // + } // + ['type_raw']=>double() // + ['type_text']=>string() // + } // + } // + ['tEXt']=>array() { // + ['header']=>array() { // + ['crc']=>integer() // + ['data']=>string() // + ['data_length']=>integer() // + ['flags']=>array() { // + ['ancilliary']=>boolean() // + ['private']=>boolean() // + ['reserved']=>boolean() // + ['safe_to_copy']=>boolean() // + } // + ['type_raw']=>double() // + ['type_text']=>string() // + } // + ['keyword']=>string() // + ['text']=>string() // + } // + ['tIME']=>array() { // + ['day']=>integer() // + ['header']=>array() { // + ['crc']=>integer() // + ['data']=>string() // + ['data_length']=>integer() // + ['flags']=>array() { // + ['ancilliary']=>boolean() // + ['private']=>boolean() // + ['reserved']=>boolean() // + ['safe_to_copy']=>boolean() // + } // + ['type_raw']=>double() // + ['type_text']=>string() // + } // + ['hour']=>integer() // + ['minute']=>integer() // + ['month']=>integer() // + ['second']=>integer() // + ['unix']=>integer() // + ['year']=>integer() // + } // + ['tRNS']=>array() { // + ['header']=>array() { // + ['crc']=>double() // + ['data']=>string() // + ['data_length']=>integer() // + ['flags']=>array() { // + ['ancilliary']=>boolean() // + ['private']=>boolean() // + ['reserved']=>boolean() // + ['safe_to_copy']=>boolean() // + } // + ['type_raw']=>double() // + ['type_text']=>string() // + } // + ['transparent_color_blue']=>integer() // + ['transparent_color_green']=>integer() // + ['transparent_color_red']=>integer() // + } // + ['zTXt']=>array() { // + ['compressed_text']=>string() // + ['compression_method']=>integer() // + ['compression_method_text']=>string() // + ['header']=>array() { // + ['crc']=>double() // + ['data']=>string() // + ['data_length']=>integer() // + ['flags']=>array() { // + ['ancilliary']=>boolean() // + ['private']=>boolean() // + ['reserved']=>boolean() // + ['safe_to_copy']=>boolean() // + } // + ['type_raw']=>double() // + ['type_text']=>string() // + } // + ['keyword']=>string() // + ['text']=>string() // + } // + } // + + + ['quicktime']=>array() { // Quicktime - video/audio + ['']=>array() { // + ['name']=>boolean() // + ['offset']=>integer() // + ['size']=>integer() // + } // + ['audio']=>array() { // + ['bit_depth']=>integer() // + ['channels']=>integer() // + ['codec']=>string() // + ['sample_rate']=>double() // + } // + ['free']=>array() { // + ['name']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + ['mdat']=>array() { // + ['name']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + ['moov']=>array() { // + ['hierarchy']=>string() // + ['name']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + ['subatoms']=>array() // This is an undocumentably-complex recursive array, typically containing a huge amount of seemingly disorganized data. Avoid this like the plague. + } // + ['time_scale']=>integer() // + ['display_scale']=>integer() // 1 = normal; 0.5 = half; 2 = double + ['video']=>array() { // + ['codec']=>string() // + ['color_depth']=>integer() // + ['color_depth_name']=>string() // + ['resolution_x']=>double() // + ['resolution_y']=>double() // + } // + ['wide']=>array() { // + ['name']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + + + ['real']=>array() { // Real (RealAudio / RealVideo) - audio/video + ['chunks']=>array() { // + []=>array() { // + ['file_version']=>integer() // + ['headers_count']=>integer() // + ['length']=>integer() // + ['name']=>string() // + ['object_version']=>integer() // + ['offset']=>integer() // + } // + []=>array() { // + ['avg_bit_rate']=>integer() // + ['avg_packet_size']=>integer() // + ['data_offset']=>integer() // + ['duration']=>integer() // + ['flags']=>array() { // + ['live_broadcast']=>boolean() // + ['perfect_play']=>boolean() // + ['save_enabled']=>boolean() // + } // + ['flags_raw']=>integer() // + ['index_offset']=>integer() // + ['length']=>integer() // + ['max_bit_rate']=>integer() // + ['max_packet_size']=>integer() // + ['name']=>string() // + ['num_packets']=>integer() // + ['num_streams']=>integer() // + ['object_version']=>integer() // + ['offset']=>integer() // + ['preroll']=>integer() // + } // + } // + ['comments']=>array() { // + ['artist']=>string() // + ['comment']=>string() // + ['title']=>string() // + } // + } // + + + ['riff']=>array() { // RIFF (Resource Interchange File Format) - audio/video container format (AVI, WAV, CDDA, etc) + ['AIFC']=>array() { // + ['COMM']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['FVER']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['INST']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['MARK']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['SSND']=>array() { // + []=>array() { // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + } // + ['AIFF']=>array() { // + ['(c) ']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['COMM']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['SSND']=>array() { // + []=>array() { // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + } // + ['AVI ']=>array() { // + ['JUNK']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['hdrl']=>array() { // + ['avih']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['odml']=>array() { // + ['dmlh']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + } // + ['strl']=>array() { // + ['JUNK']=>array() { // + []=>array() { // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['strf']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['strh']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['strn']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + } // + } // + ['idx1']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['movi']=>array() { // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['CDDA']=>array() { // + ['fmt ']=>array() { // + []=>array() { // + ['data']=>string() // + ['disc_id']=>integer() // + ['offset']=>integer() // + ['playtime_frames']=>integer() // + ['playtime_seconds']=>double() // + ['size']=>integer() // + ['start_offset_frame']=>integer() // + ['start_offset_seconds']=>double() // + ['track_num']=>integer() // + ['unknown1']=>integer() // + ['unknown6']=>integer() // + ['unknown7']=>integer() // + } // + } // + } // + ['WAVE']=>array() { // + ['DISP']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['INFO']=>array() { // + ['IART']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['ICMT']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['ICOP']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['IENG']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['IGNR']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['IKEY']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['IMED']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['INAM']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['ISBJ']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['ISFT']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['ISRC']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['ISRF']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['ITCH']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + } // + ['MEXT']=>array() { // + []=>array() { // + ['anciliary_data_length']=>integer() // + ['data']=>string() // + ['flags']=>array() { // + ['anciliary_data_free']=>boolean() // + ['anciliary_data_left']=>boolean() // + ['anciliary_data_right']=>boolean() // + ['homogenous']=>boolean() // + } // + ['offset']=>integer() // + ['raw']=>array() { // + ['anciliary_data_def']=>integer() // + ['sound_information']=>integer() // + } // + ['size']=>integer() // + } // + } // + ['bext']=>array() { // + []=>array() { // + ['author']=>string() // + ['bwf_version']=>integer() // + ['coding_history']=>array() { // + []=>string() // + } // + ['data']=>string() // + ['offset']=>integer() // + ['origin_date']=>string() // + ['origin_date_unix']=>integer() // + ['origin_time']=>string() // + ['reference']=>string() // + ['reserved']=>integer() // + ['size']=>integer() // + ['time_reference']=>integer() // + ['title']=>string() // + } // + } // + ['cart']=>array() { // + []=>array() { // + ['artist']=>string() // + ['category']=>string() // + ['classification']=>string() // + ['client_id']=>string() // + ['cut_id']=>string() // + ['data']=>string() // + ['end_date']=>string() // + ['end_time']=>string() // + ['offset']=>integer() // + ['out_cue']=>string() // + ['post_time']=>array() { // + []=>array() { // + ['timer_value']=>integer() // + ['usage_fourcc']=>string() // + } // + } // + ['producer_app_id']=>string() // + ['producer_app_version']=>string() // + ['size']=>integer() // + ['start_date']=>string() // + ['start_time']=>string() // + ['tag_text']=>array() { // + []=>string() // + } // + ['title']=>string() // + ['url']=>string() // + ['user_defined_text']=>string() // + ['version']=>string() // + ['zero_db_reference']=>integer() // + } // + } // + ['data']=>array() { // + []=>array() { // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['fact']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['fmt ']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + ['rgad']=>array() { // + []=>array() { // + ['data']=>string() // + ['offset']=>integer() // + ['size']=>integer() // + } // + } // + } // + ['audio']=>array() { // + []=>array() { // + ['bitrate']=>integer() // + ['bits_per_sample']=>integer() // + ['channels']=>integer() // + ['codec']=>string() // + ['sample_rate']=>integer() // + } // + ['bits_per_sample']=>integer() // + ['channels']=>integer() // + ['codec_fourcc']=>string() // + ['codec_name']=>string() // + ['sample_rate']=>integer() // + ['total_samples']=>integer() // + } // + ['comments']=>array() { // array of array of strings containing best data from any available metainformation tag (APE, ID3v2, ID3v1, Lyrics3, Vorbis, ASF, RIFF, Real, etc.) + []=>array() // can be anything, usually 'artist', 'title', etc. Contains array of one or more values (eg: multiple artists are possible) + } // + ['header_size']=>integer() // + ['raw']=>array() { // + ['avih']=>array() { // + ['dwFlags']=>integer() // + ['dwHeight']=>integer() // + ['dwInitialFrames']=>integer() // + ['dwLength']=>integer() // + ['dwMaxBytesPerSec']=>integer() // + ['dwMicroSecPerFrame']=>integer() // + ['dwPaddingGranularity']=>integer() // + ['dwRate']=>integer() // + ['dwScale']=>integer() // + ['dwStart']=>integer() // + ['dwStreams']=>integer() // + ['dwSuggestedBufferSize']=>integer() // + ['dwTotalFrames']=>integer() // + ['dwWidth']=>integer() // + ['flags']=>array() { // + ['capturedfile']=>boolean() // + ['copyrighted']=>boolean() // + ['hasindex']=>boolean() // + ['interleaved']=>boolean() // + ['mustuseindex']=>boolean() // + ['trustcktype']=>boolean() // + } // + } // + ['fact']=>array() { // + ['NumberOfSamples']=>integer() // + } // + ['fmt ']=>array() { // + ['nAvgBytesPerSec']=>integer() // + ['wBitsPerSample']=>integer() // + ['nBlockAlign']=>integer() // + ['nChannels']=>integer() // + ['nSamplesPerSec']=>integer() // + ['wFormatTag']=>integer() // + } // + ['rgad']=>array() { // + ['audiophile']=>array() { // + ['adjustment']=>integer() // + ['name']=>integer() // + ['originator']=>integer() // + ['signbit']=>integer() // + } // + ['fPeakAmplitude']=>double() // + ['nAudiophileRgAdjust']=>integer() // + ['nRadioRgAdjust']=>integer() // + ['radio']=>array() { // + ['adjustment']=>integer() // + ['name']=>integer() // + ['originator']=>integer() // + ['signbit']=>integer() // + } // + } // + ['strf']=>array() { // + ['auds']=>array() { // + []=>array() { // + ['nAvgBytesPerSec']=>integer() // + ['wBitsPerSample']=>integer() // + ['nBlockAlign']=>integer() // + ['nChannels']=>integer() // + ['nSamplesPerSec']=>integer() // + ['wFormatTag']=>integer() // + } // + } // + ['vids']=>array() { // + []=>array() { // + ['biBitCount']=>integer() // + ['biClrImportant']=>integer() // + ['biClrUsed']=>integer() // + ['biHeight']=>integer() // + ['biPlanes']=>integer() // + ['biSize']=>integer() // + ['biSizeImage']=>integer() // + ['biWidth']=>integer() // + ['biXPelsPerMeter']=>integer() // + ['biYPelsPerMeter']=>integer() // + ['fourcc']=>string() // + } // + } // + } // + ['strh']=>array() { // + []=>array() { // + ['dwFlags']=>integer() // + ['dwInitialFrames']=>integer() // + ['dwLength']=>integer() // + ['dwQuality']=>integer() // + ['dwRate']=>integer() // + ['dwSampleSize']=>integer() // + ['dwScale']=>integer() // + ['dwStart']=>integer() // + ['dwSuggestedBufferSize']=>integer() // + ['fccHandler']=>string() // + ['fccType']=>string() // + ['rcFrame']=>integer() // + ['wLanguage']=>integer() // + ['wPriority']=>integer() // + } // + } // + } // + ['rgad']=>array() { // + ['audiophile']=>array() { // + ['adjustment']=>double() // + ['name']=>string() // + ['originator']=>string() // + } // + ['peakamplitude']=>double() // + ['radio']=>array() { // + ['adjustment']=>double() // + ['name']=>string() // + ['originator']=>string() // + } // + } // + ['video']=>array() { // + []=>array() { // + ['codec']=>string() // + ['frame_height']=>integer() // + ['frame_rate']=>double() // + ['frame_width']=>integer() // + } // + } // + ['litewave']=>array() { // http://www.clearjump.com + ['raw']=>array() { // + ['compression_method']=>integer() // 1=lossy; 2=lossless + ['compression_flags']=>integer() // + ['m_dwScale']=>integer() // scalefactor for lossy compression - related to m_wQuality as: $m_wQuality = round((2000 - $m_dwScale) / 20) + ['m_dwBlockSize']=>integer() // number of samples in encoded blocks + ['m_wQuality']=>integer() // quality factor (0=most compressed lossy; 99=best quality lossy; 100=lossless) + ['m_wMarkDistance']=>integer() // distance between marks in bytes + ['m_wReserved']=>integer() // + ['m_dwOrgSize']=>integer() // original file size in bytes + ['m_bFactExists']=>integer() // indicates if 'fact' chunk exists in the original file + ['m_dwRiffChunkSize']=>integer() // riff chunk size in the original file + } // + ['quality_factor']=>integer() // alias of ['raw']['m_wQuality'] + } // + } // + + + ['shn']=>array() { // Shorten - lossless audio compression + ['seektable']=>array() { // + ['length']=>integer() // + ['offset']=>integer() // + ['present']=>boolean() // + } // + ['version']=>integer() // + } // + + + ['swf']=>array() { // SWF - ShockWave Flash (www.openswf.org) + ['header']=>array() { // + ['frame_count']=>integer() // + ['frame_height']=>integer() // + ['frame_width']=>integer() // + ['length']=>integer() // + ['signature']=>string() // + ['version']=>integer() // + } // + ['bgcolor']=>string() // + ['tags']=>array() // + } // + +['tak_audio']=>array() { // TAK - Tom's lossless Audio Kompressor format + ['raw']=>array() { // + ['magic']=>string() // + ['STREAMINFO']=>string() // + ['MD5Data']=>string() // + ['header_data']=>string() // Original wave header data to enable perfect reconstruction + ['footer_data']=>string() // --||-- + } // + ['channels']=>integer() // + ['bits_per_sample']=>integer() // + ['sample_rate']=>integer() // + ['samples']=>integer() // + ['framesize']=>string() // + ['codectype']=>string() // + ['version']=>string() // + ['profile']=>string() // + ['lastframe_pos']=>integer() // + ['last_frame_size']=>integer() // + ['playtime']=>integer() // + ['compressed_size']=>integer() // + ['uncompressed_size']=>integer() // + ['compression_ratio']=>integer() // + } // + + + ['voc']=>array() { // VOC - SoundBlaster VOC audio format + ['blocks']=>array() { // + []=>array() { // + ['bits_per_sample']=>integer() // + ['block_offset']=>integer() // + ['block_size']=>integer() // + ['block_type_id']=>integer() // + ['channels']=>integer() // + ['compression_name']=>string() // + ['compression_type']=>integer() // + ['pack_method']=>integer() // + ['sample_rate']=>integer() // + ['sample_rate_id']=>integer() // + ['stereo']=>boolean() // + ['time_constant']=>integer() // + ['wFormat']=>integer() // + } // + } // + ['compressed_bits_per_sample']=>integer() // + ['header']=>array() { // + ['datablock_offset']=>integer() // + ['major_version']=>integer() // + ['minor_version']=>integer() // + } // + } // + + + ['vqf']=>array() { // VQF - transform-domain weighted interleave Vector Quantization Format (lossy audio) + ['COMM']=>array() { // + ['bitrate']=>integer() // + ['channel_mode']=>integer() // + ['sample_rate']=>integer() // + ['security_level']=>integer() // + } // + ['DSIZ']=>integer() // + ['comments']=>array() { // array of array of strings containing best data from any available metainformation tag (APE, ID3v2, ID3v1, Lyrics3, Vorbis, ASF, RIFF, Real, etc.) + []=>array() // can be anything, usually 'artist', 'title', etc. Contains array of one or more values (eg: multiple artists are possible) + } // + ['raw']=>array() { // + ['header_tag']=>string() // + ['size']=>integer() // + ['version']=>string() // + } // + } // + + + ['wavpack']=>array() { // WavPack - lossless audio compression + ['bits']=>integer() // + ['crc1']=>double() // + ['crc2']=>integer() // + ['extension']=>string() // + ['extra_bc']=>string() // + ['extras']=>string() // + ['flags_raw']=>integer() // + ['offset']=>integer() // + ['shift']=>integer() // + ['size']=>integer() // + ['total_samples']=>integer() // + ['version']=>integer() // + } // + + + ['zip']=>array() { // ZIP - lossless data compression + ['central_directory']=>array() { // + []=>array() { // + ['compressed_size']=>integer() // + ['compression_method']=>string() // + ['create_version']=>string() // + ['entry_offset']=>integer() // + ['extract_version']=>string() // + ['filename']=>string() // + ['flags']=>array() { // + ['compression_speed']=>string() // + ['data_descriptor_used']=>boolean() // + ['encrypted']=>boolean() // + } // + ['host_os']=>string() // + ['last_modified_timestamp']=>integer() // + ['offset']=>integer() // + ['raw']=>array() { // + ['compressed_size']=>integer() // + ['compression_method']=>integer() // + ['crc_32']=>double() // + ['create_version']=>integer() // + ['disk_number_start']=>integer() // + ['external_file_attrib']=>double() // + ['extra_field_length']=>integer() // + ['extract_version']=>integer() // + ['file_comment_length']=>integer() // + ['filename_length']=>integer() // + ['general_flags']=>integer() // + ['internal_file_attrib']=>integer() // + ['last_mod_file_date']=>integer() // + ['last_mod_file_time']=>integer() // + ['local_header_offset']=>integer() // + ['signature']=>integer() // + ['uncompressed_size']=>integer() // + } // + ['uncompressed_size']=>integer() // + } // + } // + ['comments']=>array() { // + ['comment']=>string() // + } // + ['compressed_size']=>integer() // + ['compression_method']=>string() // + ['compression_speed']=>string() // + ['end_central_directory']=>array() { // + ['comment']=>string() // + ['comment_length']=>integer() // + ['directory_entries_this_disk']=>integer() // + ['directory_entries_total']=>integer() // + ['directory_offset']=>integer() // + ['directory_size']=>integer() // + ['disk_number_current']=>integer() // + ['disk_number_start_directory']=>integer() // + ['offset']=>integer() // + ['signature']=>integer() // + } // + ['entries']=>array() { // + []=>array() { // + ['compressed_size']=>integer() // + ['compression_method']=>string() // + ['extract_version']=>string() // + ['filename']=>string() // + ['flags']=>array() { // + ['compression_speed']=>string() // + ['data_descriptor_used']=>boolean() // + ['encrypted']=>boolean() // + } // + ['host_os']=>string() // + ['last_modified_timestamp']=>integer() // + ['offset']=>integer() // + ['raw']=>array() { // + ['compressed_size']=>integer() // + ['compression_method']=>integer() // + ['crc_32']=>integer() // + ['extra_field_length']=>integer() // + ['extract_version']=>integer() // + ['filename_length']=>integer() // + ['general_flags']=>integer() // + ['last_mod_file_date']=>integer() // + ['last_mod_file_time']=>integer() // + ['signature']=>integer() // + ['uncompressed_size']=>integer() // + } // + ['uncompressed_size']=>integer() // + } // + } // + ['entries_count']=>integer() // + ['files']=>array() { // multidimensional tree-structure array listing of all files and directories in image + []=>array() // entries of type array are directories (key is directory name), may contain files and/or other subdirectories + []=>integer() // entries of type integer are files (key is file name, value is file size in bytes) + } // + ['uncompressed_size']=>integer() // + } // +} // diff --git a/serendipity_event_podcast/serendipity_event_podcast.php b/serendipity_event_podcast/serendipity_event_podcast.php index 7e64f106..fbdc7dbf 100644 --- a/serendipity_event_podcast/serendipity_event_podcast.php +++ b/serendipity_event_podcast/serendipity_event_podcast.php @@ -9,7 +9,7 @@ if (IN_serendipity !== true) { include_once dirname(__FILE__) . '/podcast_player.php'; -@define("SERENDIPITY_EVENT_PODCAST_VERSION", "1.37.6"); +@define("SERENDIPITY_EVENT_PODCAST_VERSION", "1.37.7"); class serendipity_event_podcast extends serendipity_event { /** @@ -409,6 +409,9 @@ class serendipity_event_podcast extends serendipity_event{ } function iTunify(&$eventData) { + if (! array_key_exists('per_entry_display_dat', $eventData)) { + $eventData['per_entry_display_dat'] = ''; + } $eventData['per_entry_display_dat'] .= '' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($eventData['author']) : htmlspecialchars($eventData['author'], ENT_COMPAT, LANG_CHARSET)) . '' . "\n"; $eventData['per_entry_display_dat'] .= '' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($eventData['title']) : htmlspecialchars($eventData['title'], ENT_COMPAT, LANG_CHARSET)) . '' . "\n"; $eventData['per_entry_display_dat'] .= '' . (function_exists('serendipity_specialchars') ? serendipity_specialchars(strip_tags($eventData['feed_body'])) : htmlspecialchars(strip_tags($eventData['feed_body']), ENT_COMPAT, LANG_CHARSET)) . '' . "\n"; @@ -552,7 +555,7 @@ class serendipity_event_podcast extends serendipity_event{ if (!$use_player && preg_match_all($patterns['playerRewritePattern'], $matchSource, $matches)) { for ($i = 0, $maxi = count($matches[1]); $i < $maxi; $i++){ $complete = $matches[0]; - if (!empty($nopodcasting_class) && preg_match($classPattern, $complete)) { + if (!empty($nopodcasting_class) && is_string($complete) && preg_match($classPattern, $complete)) { $this->log("NoPodcasting class found!"); continue; } @@ -1065,9 +1068,9 @@ class serendipity_event_podcast extends serendipity_event{ $fileInfoArray['width'] = 0; $fileInfoArray['height'] = 0; - // Try to find the getid3 library in the bundled-libs first: - if (file_exists(dirname(__FILE__) . '/player/getid3/getid3.lib.php')) { - @define('GETID3_INCLUDEPATH', dirname(__FILE__) . '/player/getid3/'); + // Try to find the getid3 library in the plugins bundled-libs first: + if (file_exists(dirname(__FILE__) . '/player/james-heinrich/getid3/getid3/')) { + @define('GETID3_INCLUDEPATH', dirname(__FILE__) . '/player/james-heinrich/getid3/getid3/'); } elseif (file_exists(S9Y_INCLUDE_PATH . '/bundled-libs/getid3/getid3.lib.php')) { $this->log("GetID3Infos: include path " . S9Y_INCLUDE_PATH . '/bundled-libs/getid3/'); @define('GETID3_INCLUDEPATH', S9Y_INCLUDE_PATH . '/bundled-libs/getid3/');