diff --git a/app/Album.php b/app/Album.php
index 60cd2f05..a6a5673d 100644
--- a/app/Album.php
+++ b/app/Album.php
@@ -1,7 +1,5 @@
';
+ }
+
+ $scripts = self::mergeGlobs(self::getScriptsForArea($area));
+ $retVal = "";
+
+ foreach ($scripts as $script) {
+ $filename = self::replaceExtensionWith($script, ".coffee", ".js");
+ $retVal .= "";
+ }
+
+ return $retVal;
+ }
+
+ public static function styleIncludes($area = 'app')
+ {
+ if (!Config::get("app.debug")) {
+ return '';
+ }
+
+ $styles = self::mergeGlobs(self::getStylesForArea($area));
+ $retVal = "";
+
+ foreach ($styles as $style) {
+ $filename = self::replaceExtensionWith($style, ".less", ".css");
+ $retVal .= "";
+ }
+
+ return $retVal;
+ }
+
+ private static function replaceExtensionWith($filename, $fromExtension, $toExtension)
+ {
+ $fromLength = strlen($fromExtension);
+
+ return substr($filename, -$fromLength) == $fromExtension
+ ? substr($filename, 0, strlen($filename) - $fromLength) . $toExtension
+ : $filename;
+ }
+
+ /** Merges an array of paths that are passed into "glob" into a list of unique filenames.
+ * Note that this method assumes the globs should be relative to the "app" folder of this project */
+ private static function mergeGlobs($globs)
+ {
+ $files = [];
+ $filesFound = [];
+ foreach ($globs as $glob) {
+ foreach (glob("../app/" . $glob, GLOB_BRACE) as $file) {
+ if (isset($filesFound[$file])) {
+ continue;
+ }
+
+ $filesFound[$file] = true;
+ $files[] = substr($file, 7); // chop off ../app/
+ }
+ }
+
+ return $files;
+ }
+
+ private static function getScriptsForArea($area)
+ {
+ if ($area == 'app') {
+ return [
+ "scripts/base/jquery-2.0.2.js",
+ "scripts/base/angular.js",
+ "scripts/base/*.{coffee,js}",
+ "scripts/shared/*.{coffee,js}",
+ "scripts/app/*.{coffee,js}",
+ "scripts/app/services/*.{coffee,js}",
+ "scripts/app/filters/*.{coffee,js}",
+ "scripts/app/directives/*.{coffee,js}",
+ "scripts/app/controllers/*.{coffee,js}",
+ "scripts/**/*.{coffee,js}"
+ ];
+ } else {
+ if ($area == 'embed') {
+ return [
+ "scripts/base/jquery-2.0.2.js",
+ "scripts/base/jquery.viewport.js",
+ "scripts/base/underscore.js",
+ "scripts/base/moment.js",
+ "scripts/base/jquery.timeago.js",
+ "scripts/base/soundmanager2-nodebug.js",
+ "scripts/embed/*.coffee"
+ ];
+ }
+ }
+
+ throw new Exception();
+ }
+
+ private static function getStylesForArea($area)
+ {
+ if ($area == 'app') {
+ return [
+ "styles/base/jquery-ui.css",
+ "styles/base/colorbox.css",
+ "styles/app.less",
+ "styles/profiler.less"
+ ];
+ } else {
+ if ($area == 'embed') {
+ return [
+ "styles/embed.less"
+ ];
+ }
+ }
+
+ throw new Exception();
+ }
+}
\ No newline at end of file
diff --git a/app/Library/AudioCache.php b/app/Library/AudioCache.php
new file mode 100644
index 00000000..fdf8f627
--- /dev/null
+++ b/app/Library/AudioCache.php
@@ -0,0 +1,19 @@
+_lastModified = $lastModified;
+ parent::__construct([], '', '', []);
+ }
+
+ public function load(FilterInterface $additionalFilter = null)
+ {
+ }
+
+ public function getLastModified()
+ {
+ return $this->_lastModified;
+ }
+}
diff --git a/app/Library/External.php b/app/Library/External.php
new file mode 100644
index 00000000..0bd4e642
--- /dev/null
+++ b/app/Library/External.php
@@ -0,0 +1,16 @@
+
+ */
+class File extends \Illuminate\Support\Facades\File
+{
+
+ public static function inline($path, $mime, $name = null)
+ {
+ if (is_null($name)) {
+ $name = basename($path);
+ }
+
+ $response = Response::make(static::get($path));
+
+ $response->header('Content-Type', $mime);
+ $response->header('Content-Disposition', 'inline; filename="' . $name . '"');
+ $response->header('Content-Transfer-Encoding', 'binary');
+ $response->header('Expires', 0);
+ $response->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
+ $response->header('Pragma', 'public');
+ $response->header('Content-Length', filesize($path));
+
+ return $response;
+ }
+
+}
diff --git a/app/Library/Gravatar.php b/app/Library/Gravatar.php
new file mode 100644
index 00000000..67c08de1
--- /dev/null
+++ b/app/Library/Gravatar.php
@@ -0,0 +1,30 @@
+format('c');
+ }
+
+ $title = date('c', strtotime($timestamp));
+ $content = date('F d, o \@ g:i:s a', strtotime($timestamp));
+
+ return '' . $content . '';
+ }
+}
\ No newline at end of file
diff --git a/app/Library/IpsHasher.php b/app/Library/IpsHasher.php
new file mode 100644
index 00000000..e103b2f8
--- /dev/null
+++ b/app/Library/IpsHasher.php
@@ -0,0 +1,35 @@
+ $options['salt']]) === $hashedValue;
+ }
+
+ public function needsRehash($hashedValue, array $options = array())
+ {
+ return false;
+ }
+
+ static public function ips_sanitize($value)
+ {
+ $value = str_replace('&', '&', $value);
+ $value = str_replace('\\', '\', $value);
+ $value = str_replace('!', '!', $value);
+ $value = str_replace('$', '$', $value);
+ $value = str_replace('"', '"', $value);
+ $value = str_replace('<', '<', $value);
+ $value = str_replace('>', '>', $value);
+ $value = str_replace('\'', ''', $value);
+
+ return $value;
+ }
+}
\ No newline at end of file
diff --git a/app/Library/PFMAuth.php b/app/Library/PFMAuth.php
new file mode 100644
index 00000000..5127e4b4
--- /dev/null
+++ b/app/Library/PFMAuth.php
@@ -0,0 +1,26 @@
+getPathname());
+
+ return in_array($file->getAudioCodec(), $parameters);
+ }
+
+
+ /**
+ * Validate the sample rate of the audio file.
+ *
+ * @param string $attribute
+ * @param array $value
+ * @param array $parameters
+ * @return bool
+ */
+ public function validateSampleRate($attribute, $value, $parameters)
+ {
+ // attribute is the file field
+ // value is the file array itself
+ // parameters is a list of sample rates the file can be, verified via ffmpeg
+ $file = AudioCache::get($value->getPathname());
+
+ return in_array($file->getAudioSampleRate(), $parameters);
+ }
+
+
+ /**
+ * Validate the number of channels in the audio file.
+ *
+ * @param string $attribute
+ * @param array $value
+ * @param array $parameters
+ * @return bool
+ */
+ public function validateAudioChannels($attribute, $value, $parameters)
+ {
+ // attribute is the file field
+ // value is the file array itself
+ // parameters is a list of sample rates the file can be, verified via ffmpeg
+ $file = AudioCache::get($value->getPathname());
+
+ return in_array($file->getAudioChannels(), $parameters);
+ }
+
+
+ /**
+ * Validate the bit rate of the audio file.
+ *
+ * @param string $attribute
+ * @param array $value
+ * @param array $parameters
+ * @return bool
+ */
+ public function validateAudioBitrate($attribute, $value, $parameters)
+ {
+ // attribute is the file field
+ // value is the file array itself
+ // parameters is a list of sample rates the file can be, verified via ffmpeg
+ $file = AudioCache::get($value->getPathname());
+
+ return in_array($file->getAudioBitRate(), $parameters);
+ }
+
+
+ /**
+ * Validate the duration of the audio file, in seconds.
+ *
+ * @param string $attribute
+ * @param array $value
+ * @param array $parameters
+ * @return bool
+ */
+ public function validateMinDuration($attribute, $value, $parameters)
+ {
+ // attribute is the file field
+ // value is the file array itself
+ // parameters is an array containing one value: the minimum duration
+ $file = AudioCache::get($value->getPathname());
+
+ return $file->getDuration() >= (float)$parameters[0];
+ }
+
+
+ /**
+ * Require a field when the value of another field matches a certain value.
+ *
+ * @param string $attribute
+ * @param array $value
+ * @param array $parameters
+ * @return bool
+ */
+ /** OLD CODE
+ * public function validate_required_when($attribute, $value, $parameters)
+ * {
+ * if ( Input::get($parameters[0]) === $parameters[1] && static::required($attribute, $value) ){
+ * return true;
+ *
+ * } else {
+ * return false;
+ * }
+ * }
+ **/
+
+ // custom required_when validator
+ public function validateRequiredWhen($attribute, $value, $parameters)
+ {
+ if (Input::get($parameters[0]) == $parameters[1]) {
+ return $this->validate_required($attribute, $value);
+ }
+
+ return true;
+ }
+
+
+ // custom image width validator
+ public function validateMinWidth($attribute, $value, $parameters)
+ {
+ return getimagesize($value->getPathname())[0] >= $parameters[0];
+ }
+
+ // custom image height validator
+ public function validateMinHeight($attribute, $value, $parameters)
+ {
+ return getimagesize($value->getPathname())[1] >= $parameters[0];
+ }
+
+ public function validateTextareaLength($attribute, $value, $parameters)
+ {
+ return strlen(str_replace("\r\n", "\n", $value)) <= $parameters[0];
+ }
+}
\ No newline at end of file
diff --git a/app/Library/Poniverse/Poniverse.php b/app/Library/Poniverse/Poniverse.php
new file mode 100644
index 00000000..3ad250cf
--- /dev/null
+++ b/app/Library/Poniverse/Poniverse.php
@@ -0,0 +1,95 @@
+urls = Config::get('poniverse.urls');
+
+ $this->clientId = $clientId;
+ $this->clientSecret = $clientSecret;
+ $this->accessToken = $accessToken;
+
+ //Setup Dependencies
+ $this->setupOAuth2();
+ $this->setupHttpful();
+ }
+
+ protected function setupOAuth2()
+ {
+ require_once('oauth2/Client.php');
+ require_once('oauth2/GrantType/IGrantType.php');
+ require_once('oauth2/GrantType/AuthorizationCode.php');
+
+ $this->client = new \OAuth2\Client($this->clientId, $this->clientSecret);
+ }
+
+ protected function setupHttpful()
+ {
+ require_once('autoloader.php');
+ $autoloader = new SplClassLoader('Httpful', __DIR__."/httpful/src/");
+ $autoloader->register();
+ }
+
+ public function setAccessToken($accessToken)
+ {
+ $this->accessToken = $accessToken;
+ }
+
+ public function getAuthenticationUrl($state)
+ {
+ return $this->client->getAuthenticationUrl($this->urls['auth'], $this->redirectUri, ['state' => $state]);
+ }
+
+ public function setRedirectUri($redirectUri)
+ {
+ $this->redirectUri = $redirectUri;
+ }
+
+ /**
+ * Gets the OAuth2 Client
+ *
+ * @return \OAuth2\Client
+ */
+ public function getClient()
+ {
+ return $this->client;
+ }
+
+ /**
+ * Gets data about the currently logged in user
+ *
+ * @return array
+ */
+ public function getUser()
+ {
+ $data = \Httpful\Request::get($this->urls['api'] . "users?access_token=" . $this->accessToken );
+
+ $result = $data->addHeader('Accept', 'application/json')->send();
+
+ return json_decode($result, true);
+ }
+}
\ No newline at end of file
diff --git a/app/Library/Poniverse/autoloader.php b/app/Library/Poniverse/autoloader.php
new file mode 100644
index 00000000..54a20935
--- /dev/null
+++ b/app/Library/Poniverse/autoloader.php
@@ -0,0 +1,137 @@
+register();
+ *
+ * @author Jonathan H. Wage
+ * @author Roman S. Borschel
+ * @author Matthew Weier O'Phinney
+ * @author Kris Wallsmith
+ * @author Fabien Potencier
+ */
+class SplClassLoader
+{
+ private $_fileExtension = '.php';
+ private $_namespace;
+ private $_includePath;
+ private $_namespaceSeparator = '\\';
+
+ /**
+ * Creates a new SplClassLoader that loads classes of the
+ * specified namespace.
+ *
+ * @param string $ns The namespace to use.
+ * @param string $includePath
+ */
+ public function __construct($ns = null, $includePath = null)
+ {
+ $this->_namespace = $ns;
+ $this->_includePath = $includePath;
+ }
+
+ /**
+ * Sets the namespace separator used by classes in the namespace of this class loader.
+ *
+ * @param string $sep The separator to use.
+ */
+ public function setNamespaceSeparator($sep)
+ {
+ $this->_namespaceSeparator = $sep;
+ }
+
+ /**
+ * Gets the namespace seperator used by classes in the namespace of this class loader.
+ *
+ * @return string
+ */
+ public function getNamespaceSeparator()
+ {
+ return $this->_namespaceSeparator;
+ }
+
+ /**
+ * Sets the base include path for all class files in the namespace of this class loader.
+ *
+ * @param string $includePath
+ */
+ public function setIncludePath($includePath)
+ {
+ $this->_includePath = $includePath;
+ }
+
+ /**
+ * Gets the base include path for all class files in the namespace of this class loader.
+ *
+ * @return string $includePath
+ */
+ public function getIncludePath()
+ {
+ return $this->_includePath;
+ }
+
+ /**
+ * Sets the file extension of class files in the namespace of this class loader.
+ *
+ * @param string $fileExtension
+ */
+ public function setFileExtension($fileExtension)
+ {
+ $this->_fileExtension = $fileExtension;
+ }
+
+ /**
+ * Gets the file extension of class files in the namespace of this class loader.
+ *
+ * @return string $fileExtension
+ */
+ public function getFileExtension()
+ {
+ return $this->_fileExtension;
+ }
+
+ /**
+ * Installs this class loader on the SPL autoload stack.
+ */
+ public function register()
+ {
+ spl_autoload_register(array($this, 'loadClass'));
+ }
+
+ /**
+ * Uninstalls this class loader from the SPL autoloader stack.
+ */
+ public function unregister()
+ {
+ spl_autoload_unregister(array($this, 'loadClass'));
+ }
+
+ /**
+ * Loads the given class or interface.
+ *
+ * @param string $className The name of the class to load.
+ * @return void
+ */
+ public function loadClass($className)
+ {
+ if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) {
+ $fileName = '';
+ $namespace = '';
+ if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) {
+ $namespace = substr($className, 0, $lastNsPos);
+ $className = substr($className, $lastNsPos + 1);
+ $fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
+ }
+ $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension;
+
+ require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/Library/Poniverse/httpful/.gitignore b/app/Library/Poniverse/httpful/.gitignore
new file mode 100644
index 00000000..d1584ef4
--- /dev/null
+++ b/app/Library/Poniverse/httpful/.gitignore
@@ -0,0 +1,4 @@
+.DS_Store
+composer.lock
+vendor
+downloads
diff --git a/app/Library/Poniverse/httpful/.travis.yml b/app/Library/Poniverse/httpful/.travis.yml
new file mode 100644
index 00000000..ba03761e
--- /dev/null
+++ b/app/Library/Poniverse/httpful/.travis.yml
@@ -0,0 +1,5 @@
+language: php
+before_script: cd tests
+php:
+ - 5.3
+ - 5.4
\ No newline at end of file
diff --git a/app/Library/Poniverse/httpful/LICENSE.txt b/app/Library/Poniverse/httpful/LICENSE.txt
new file mode 100644
index 00000000..90892706
--- /dev/null
+++ b/app/Library/Poniverse/httpful/LICENSE.txt
@@ -0,0 +1,7 @@
+Copyright (c) 2012 Nate Good
+
+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.
\ No newline at end of file
diff --git a/app/Library/Poniverse/httpful/README.md b/app/Library/Poniverse/httpful/README.md
new file mode 100644
index 00000000..f816015a
--- /dev/null
+++ b/app/Library/Poniverse/httpful/README.md
@@ -0,0 +1,150 @@
+# Httpful
+
+[![Build Status](https://secure.travis-ci.org/nategood/httpful.png?branch=master)](http://travis-ci.org/nategood/httpful)
+
+[Httpful](http://phphttpclient.com) is a simple Http Client library for PHP 5.3+. There is an emphasis of readability, simplicity, and flexibility – basically provide the features and flexibility to get the job done and make those features really easy to use.
+
+Features
+
+ - Readable HTTP Method Support (GET, PUT, POST, DELETE, HEAD, PATCH and OPTIONS)
+ - Custom Headers
+ - Automatic "Smart" Parsing
+ - Automatic Payload Serialization
+ - Basic Auth
+ - Client Side Certificate Auth
+ - Request "Templates"
+
+# Sneak Peak
+
+Here's something to whet your appetite. Search the twitter API for tweets containing "#PHP". Include a trivial header for the heck of it. Notice that the library automatically interprets the response as JSON (can override this if desired) and parses it as an array of objects.
+
+ $url = "http://search.twitter.com/search.json?q=" . urlencode('#PHP');
+ $response = Request::get($url)
+ ->withXTrivialHeader('Just as a demo')
+ ->send();
+
+ foreach ($response->body->results as $tweet) {
+ echo "@{$tweet->from_user} tweets \"{$tweet->text}\"\n";
+ }
+
+# Installation
+
+## Phar
+
+A [PHP Archive](http://php.net/manual/en/book.phar.php) (or .phar) file is available for [downloading](http://phphttpclient.com/httpful.phar). Simply [download](http://phphttpclient.com/httpful.phar) the .phar, drop it into your project, and include it like you would any other php file. _This method is ideal smaller projects, one off scripts, and quick API hacking_.
+
+ sendIt();
+ ...
+
+## Composer
+
+Httpful is PSR-0 compliant and can be installed using [composer](http://getcomposer.org/). Simply add `nategood/httpful` to your composer.json file. _Composer is the sane alternative to PEAR. It is excellent for managing dependancies in larger projects_.
+
+ {
+ "require": {
+ "nategood/httpful": "*"
+ }
+ }
+
+## Install from Source
+
+Because Httpful is PSR-0 compliant, you can also just clone the Httpful repository and use a PSR-0 compatible autoloader to load the library, like [Symfony's](http://symfony.com/doc/current/components/class_loader.html). Alternatively you can use the PSR-0 compliant autoloader included with the Httpful (simply `require("bootstrap.php")`).
+
+# Show Me More!
+
+You can checkout the [Httpful Landing Page](http://phphttpclient.com) for more info including many examples and [documentation](http:://phphttpclient.com/docs).
+
+# Contributing
+
+Httpful highly encourages sending in pull requests. When submitting a pull request please:
+
+ - All pull requests should target the `dev` branch (not `master`)
+ - Make sure your code follows the [coding conventions](http://pear.php.net/manual/en/standards.php)
+ - Please use soft tabs (four spaces) instead of hard tabs
+ - Make sure you add appropriate test coverage for your changes
+ - Run all unit tests in the test directory via `phpunit ./tests`
+ - Include commenting where appropriate and add a descriptive pull request message
+
+# Changelog
+
+## 0.2.6
+
+ - FIX [I #85](https://github.com/nategood/httpful/issues/85) Empty Content Length issue resolved
+
+## 0.2.5
+
+ - FEATURE [I #80](https://github.com/nategood/httpful/issues/80) [I #81](https://github.com/nategood/httpful/issues/81) Proxy support added with `useProxy` method.
+
+## 0.2.4
+
+ - FEATURE [I #77](https://github.com/nategood/httpful/issues/77) Convenience method for setting a timeout (seconds) `$req->timeoutIn(10);`
+ - FIX [I #75](https://github.com/nategood/httpful/issues/75) [I #78](https://github.com/nategood/httpful/issues/78) Bug with checking if digest auth is being used.
+
+## 0.2.3
+
+ - FIX Overriding default Mime Handlers
+ - FIX [PR #73](https://github.com/nategood/httpful/pull/73) Parsing http status codes
+
+## 0.2.2
+
+ - FEATURE Add support for parsing JSON responses as associative arrays instead of objects
+ - FEATURE Better support for setting constructor arguments on Mime Handlers
+
+## 0.2.1
+
+ - FEATURE [PR #72](https://github.com/nategood/httpful/pull/72) Allow support for custom Accept header
+
+## 0.2.0
+
+ - REFACTOR [PR #49](https://github.com/nategood/httpful/pull/49) Broke headers out into their own class
+ - REFACTOR [PR #54](https://github.com/nategood/httpful/pull/54) Added more specific Exceptions
+ - FIX [PR #58](https://github.com/nategood/httpful/pull/58) Fixes throwing an error on an empty xml response
+ - FEATURE [PR #57](https://github.com/nategood/httpful/pull/57) Adds support for digest authentication
+
+## 0.1.6
+
+ - Ability to set the number of max redirects via overloading `followRedirects(int max_redirects)`
+ - Standards Compliant fix to `Accepts` header
+ - Bug fix for bootstrap process when installed via Composer
+
+## 0.1.5
+
+ - Use `DIRECTORY_SEPARATOR` constant [PR #33](https://github.com/nategood/httpful/pull/32)
+ - [PR #35](https://github.com/nategood/httpful/pull/35)
+ - Added the raw\_headers property reference to response.
+ - Compose request header and added raw\_header to Request object.
+ - Fixed response has errors and added more comments for clarity.
+ - Fixed header parsing to allow the minimum (status line only) and also cater for the actual CRLF ended headers as per RFC2616.
+ - Added the perfect test Accept: header for all Acceptable scenarios see @b78e9e82cd9614fbe137c01bde9439c4e16ca323 for details.
+ - Added default User-Agent header
+ - `User-Agent: Httpful/0.1.5` + curl version + server software + PHP version
+ - To bypass this "default" operation simply add a User-Agent to the request headers even a blank User-Agent is sufficient and more than simple enough to produce me thinks.
+ - Completed test units for additions.
+ - Added phpunit coverage reporting and helped phpunit auto locate the tests a bit easier.
+
+## 0.1.4
+
+ - Add support for CSV Handling [PR #32](https://github.com/nategood/httpful/pull/32)
+
+## 0.1.3
+
+ - Handle empty responses in JsonParser and XmlParser
+
+## 0.1.2
+
+ - Added support for setting XMLHandler configuration options
+ - Added examples for overriding XmlHandler and registering a custom parser
+ - Removed the httpful.php download (deprecated in favor of httpful.phar)
+
+## 0.1.1
+
+ - Bug fix serialization default case and phpunit tests
+
+## 0.1.0
+
+ - Added Support for Registering Mime Handlers
+ - Created AbstractMimeHandler type that all Mime Handlers must extend
+ - Pulled out the parsing/serializing logic from the Request/Response classes into their own MimeHandler classes
+ - Added ability to register new mime handlers for mime types
diff --git a/app/Library/Poniverse/httpful/bootstrap.php b/app/Library/Poniverse/httpful/bootstrap.php
new file mode 100644
index 00000000..10f2a7cf
--- /dev/null
+++ b/app/Library/Poniverse/httpful/bootstrap.php
@@ -0,0 +1,4 @@
+setStub($stub);
+} catch(Exception $e) {
+ $phar = false;
+}
+exit_unless($phar, "Unable to create a phar. Make certain you have phar.readonly=0 set in your ini file.");
+$phar->buildFromDirectory(dirname($source_dir));
+echo "[ OK ]\n";
+
+
+
+// Add it to git!
+echo "Adding httpful.phar to the repo... ";
+$return_code = 0;
+passthru("git add $phar_path", $return_code);
+exit_unless($return_code === 0, "Unable to add download files to git.");
+echo "[ OK ]\n";
+echo "\nBuild completed successfully.\n\n";
diff --git a/app/Library/Poniverse/httpful/composer.json b/app/Library/Poniverse/httpful/composer.json
new file mode 100644
index 00000000..6d61e6e7
--- /dev/null
+++ b/app/Library/Poniverse/httpful/composer.json
@@ -0,0 +1,27 @@
+{
+ "name": "nategood/httpful",
+ "description": "A Readable, Chainable, REST friendly, PHP HTTP Client",
+ "homepage": "http://github.com/nategood/httpful",
+ "license": "MIT",
+ "keywords": ["http", "curl", "rest", "restful", "api", "requests"],
+ "version": "0.2.6",
+ "authors": [
+ {
+ "name": "Nate Good",
+ "email": "me@nategood.com",
+ "homepage": "http://nategood.com"
+ }
+ ],
+ "require": {
+ "php": ">=5.3",
+ "ext-curl": "*"
+ },
+ "autoload": {
+ "psr-0": {
+ "Httpful": "src/"
+ }
+ },
+ "require-dev": {
+ "phpunit/phpunit": "*"
+ }
+}
diff --git a/app/Library/Poniverse/httpful/examples/freebase.php b/app/Library/Poniverse/httpful/examples/freebase.php
new file mode 100644
index 00000000..bb3b528f
--- /dev/null
+++ b/app/Library/Poniverse/httpful/examples/freebase.php
@@ -0,0 +1,12 @@
+expectsJson()
+ ->sendIt();
+
+echo 'The Dead Weather has ' . count($response->body->result->album) . " albums.\n";
\ No newline at end of file
diff --git a/app/Library/Poniverse/httpful/examples/github.php b/app/Library/Poniverse/httpful/examples/github.php
new file mode 100644
index 00000000..8eb3f3ba
--- /dev/null
+++ b/app/Library/Poniverse/httpful/examples/github.php
@@ -0,0 +1,9 @@
+send();
+
+echo "{$request->body->name} joined GitHub on " . date('M jS', strtotime($request->body->{'created-at'})) ."\n";
\ No newline at end of file
diff --git a/app/Library/Poniverse/httpful/examples/override.php b/app/Library/Poniverse/httpful/examples/override.php
new file mode 100644
index 00000000..2c3bdd5c
--- /dev/null
+++ b/app/Library/Poniverse/httpful/examples/override.php
@@ -0,0 +1,44 @@
+ 'http://example.com');
+\Httpful\Httpful::register(\Httpful\Mime::XML, new \Httpful\Handlers\XmlHandler($conf));
+
+// We can also add the parsers with our own...
+class SimpleCsvHandler extends \Httpful\Handlers\MimeHandlerAdapter
+{
+ /**
+ * Takes a response body, and turns it into
+ * a two dimensional array.
+ *
+ * @param string $body
+ * @return mixed
+ */
+ public function parse($body)
+ {
+ return str_getcsv($body);
+ }
+
+ /**
+ * Takes a two dimensional array and turns it
+ * into a serialized string to include as the
+ * body of a request
+ *
+ * @param mixed $payload
+ * @return string
+ */
+ public function serialize($payload)
+ {
+ $serialized = '';
+ foreach ($payload as $line) {
+ $serialized .= '"' . implode('","', $line) . '"' . "\n";
+ }
+ return $serialized;
+ }
+}
+
+\Httpful\Httpful::register('text/csv', new SimpleCsvHandler());
\ No newline at end of file
diff --git a/app/Library/Poniverse/httpful/examples/showclix.php b/app/Library/Poniverse/httpful/examples/showclix.php
new file mode 100644
index 00000000..9c50bf5f
--- /dev/null
+++ b/app/Library/Poniverse/httpful/examples/showclix.php
@@ -0,0 +1,24 @@
+expectsType('json')
+ ->sendIt();
+
+// Print out the event details
+echo "The event {$response->body->event} will take place on {$response->body->event_start}\n";
+
+// Example overriding the default JSON handler with one that encodes the response as an array
+\Httpful\Httpful::register(\Httpful\Mime::JSON, new \Httpful\Handlers\JsonHandler(array('decode_as_array' => true)));
+
+$response = Request::get($uri)
+ ->expectsType('json')
+ ->sendIt();
+
+// Print out the event details
+echo "The event {$response->body['event']} will take place on {$response->body['event_start']}\n";
\ No newline at end of file
diff --git a/app/Library/Poniverse/httpful/src/Httpful/Bootstrap.php b/app/Library/Poniverse/httpful/src/Httpful/Bootstrap.php
new file mode 100644
index 00000000..3bf62ae6
--- /dev/null
+++ b/app/Library/Poniverse/httpful/src/Httpful/Bootstrap.php
@@ -0,0 +1,97 @@
+
+ */
+class Bootstrap
+{
+
+ const DIR_GLUE = DIRECTORY_SEPARATOR;
+ const NS_GLUE = '\\';
+
+ public static $registered = false;
+
+ /**
+ * Register the autoloader and any other setup needed
+ */
+ public static function init()
+ {
+ spl_autoload_register(array('\Httpful\Bootstrap', 'autoload'));
+ self::registerHandlers();
+ }
+
+ /**
+ * The autoload magic (PSR-0 style)
+ *
+ * @param string $classname
+ */
+ public static function autoload($classname)
+ {
+ self::_autoload(dirname(dirname(__FILE__)), $classname);
+ }
+
+ /**
+ * Register the autoloader and any other setup needed
+ */
+ public static function pharInit()
+ {
+ spl_autoload_register(array('\Httpful\Bootstrap', 'pharAutoload'));
+ self::registerHandlers();
+ }
+
+ /**
+ * Phar specific autoloader
+ *
+ * @param string $classname
+ */
+ public static function pharAutoload($classname)
+ {
+ self::_autoload('phar://httpful.phar', $classname);
+ }
+
+ /**
+ * @param string base
+ * @param string classname
+ */
+ private static function _autoload($base, $classname)
+ {
+ $parts = explode(self::NS_GLUE, $classname);
+ $path = $base . self::DIR_GLUE . implode(self::DIR_GLUE, $parts) . '.php';
+
+ if (file_exists($path)) {
+ require_once($path);
+ }
+ }
+ /**
+ * Register default mime handlers. Is idempotent.
+ */
+ public static function registerHandlers()
+ {
+ if (self::$registered === true) {
+ return;
+ }
+
+ // @todo check a conf file to load from that instead of
+ // hardcoding into the library?
+ $handlers = array(
+ \Httpful\Mime::JSON => new \Httpful\Handlers\JsonHandler(),
+ \Httpful\Mime::XML => new \Httpful\Handlers\XmlHandler(),
+ \Httpful\Mime::FORM => new \Httpful\Handlers\FormHandler(),
+ \Httpful\Mime::CSV => new \Httpful\Handlers\CsvHandler(),
+ );
+
+ foreach ($handlers as $mime => $handler) {
+ // Don't overwrite if the handler has already been registered
+ if (Httpful::hasParserRegistered($mime))
+ continue;
+ Httpful::register($mime, $handler);
+ }
+
+ self::$registered = true;
+ }
+}
diff --git a/app/Library/Poniverse/httpful/src/Httpful/Exception/ConnectionErrorException.php b/app/Library/Poniverse/httpful/src/Httpful/Exception/ConnectionErrorException.php
new file mode 100644
index 00000000..bba73a69
--- /dev/null
+++ b/app/Library/Poniverse/httpful/src/Httpful/Exception/ConnectionErrorException.php
@@ -0,0 +1,7 @@
+
+ */
+
+namespace Httpful\Handlers;
+
+class CsvHandler extends MimeHandlerAdapter
+{
+ /**
+ * @param string $body
+ * @return mixed
+ */
+ public function parse($body)
+ {
+ if (empty($body))
+ return null;
+
+ $parsed = array();
+ $fp = fopen('data://text/plain;base64,' . base64_encode($body), 'r');
+ while (($r = fgetcsv($fp)) !== FALSE) {
+ $parsed[] = $r;
+ }
+
+ if (empty($parsed))
+ throw new \Exception("Unable to parse response as CSV");
+ return $parsed;
+ }
+
+ /**
+ * @param mixed $payload
+ * @return string
+ */
+ public function serialize($payload)
+ {
+ $fp = fopen('php://temp/maxmemory:'. (6*1024*1024), 'r+');
+ $i = 0;
+ foreach ($payload as $fields) {
+ if($i++ == 0) {
+ fputcsv($fp, array_keys($fields));
+ }
+ fputcsv($fp, $fields);
+ }
+ rewind($fp);
+ $data = stream_get_contents($fp);
+ fclose($fp);
+ return $data;
+ }
+}
diff --git a/app/Library/Poniverse/httpful/src/Httpful/Handlers/FormHandler.php b/app/Library/Poniverse/httpful/src/Httpful/Handlers/FormHandler.php
new file mode 100644
index 00000000..fea1c37c
--- /dev/null
+++ b/app/Library/Poniverse/httpful/src/Httpful/Handlers/FormHandler.php
@@ -0,0 +1,30 @@
+
+ */
+
+namespace Httpful\Handlers;
+
+class FormHandler extends MimeHandlerAdapter
+{
+ /**
+ * @param string $body
+ * @return mixed
+ */
+ public function parse($body)
+ {
+ $parsed = array();
+ parse_str($body, $parsed);
+ return $parsed;
+ }
+
+ /**
+ * @param mixed $payload
+ * @return string
+ */
+ public function serialize($payload)
+ {
+ return http_build_query($payload, null, '&');
+ }
+}
\ No newline at end of file
diff --git a/app/Library/Poniverse/httpful/src/Httpful/Handlers/JsonHandler.php b/app/Library/Poniverse/httpful/src/Httpful/Handlers/JsonHandler.php
new file mode 100644
index 00000000..6520d933
--- /dev/null
+++ b/app/Library/Poniverse/httpful/src/Httpful/Handlers/JsonHandler.php
@@ -0,0 +1,40 @@
+
+ */
+
+namespace Httpful\Handlers;
+
+class JsonHandler extends MimeHandlerAdapter
+{
+ private $decode_as_array = false;
+
+ public function init(array $args)
+ {
+ $this->decode_as_array = !!(array_key_exists('decode_as_array', $args) ? $args['decode_as_array'] : false);
+ }
+
+ /**
+ * @param string $body
+ * @return mixed
+ */
+ public function parse($body)
+ {
+ if (empty($body))
+ return null;
+ $parsed = json_decode($body, $this->decode_as_array);
+ if (is_null($parsed))
+ throw new \Exception("Unable to parse response as JSON");
+ return $parsed;
+ }
+
+ /**
+ * @param mixed $payload
+ * @return string
+ */
+ public function serialize($payload)
+ {
+ return json_encode($payload);
+ }
+}
\ No newline at end of file
diff --git a/app/Library/Poniverse/httpful/src/Httpful/Handlers/MimeHandlerAdapter.php b/app/Library/Poniverse/httpful/src/Httpful/Handlers/MimeHandlerAdapter.php
new file mode 100644
index 00000000..dd15c04c
--- /dev/null
+++ b/app/Library/Poniverse/httpful/src/Httpful/Handlers/MimeHandlerAdapter.php
@@ -0,0 +1,43 @@
+init($args);
+ }
+
+ /**
+ * Initial setup of
+ * @param array $args
+ */
+ public function init(array $args)
+ {
+ }
+
+ /**
+ * @param string $body
+ * @return mixed
+ */
+ public function parse($body)
+ {
+ return $body;
+ }
+
+ /**
+ * @param mixed $payload
+ * @return string
+ */
+ function serialize($payload)
+ {
+ return (string) $payload;
+ }
+}
\ No newline at end of file
diff --git a/app/Library/Poniverse/httpful/src/Httpful/Handlers/README.md b/app/Library/Poniverse/httpful/src/Httpful/Handlers/README.md
new file mode 100644
index 00000000..5542d406
--- /dev/null
+++ b/app/Library/Poniverse/httpful/src/Httpful/Handlers/README.md
@@ -0,0 +1,44 @@
+# Handlers
+
+Handlers are simple classes that are used to parse response bodies and serialize request payloads. All Handlers must extend the `MimeHandlerAdapter` class and implement two methods: `serialize($payload)` and `parse($response)`. Let's build a very basic Handler to register for the `text/csv` mime type.
+
+
+ */
+
+namespace Httpful\Handlers;
+
+class XHtmlHandler extends MimeHandlerAdapter
+{
+ // @todo add html specific parsing
+ // see DomDocument::load http://docs.php.net/manual/en/domdocument.loadhtml.php
+}
\ No newline at end of file
diff --git a/app/Library/Poniverse/httpful/src/Httpful/Handlers/XmlHandler.php b/app/Library/Poniverse/httpful/src/Httpful/Handlers/XmlHandler.php
new file mode 100644
index 00000000..4b11659b
--- /dev/null
+++ b/app/Library/Poniverse/httpful/src/Httpful/Handlers/XmlHandler.php
@@ -0,0 +1,120 @@
+
+ * @author Nathan Good
+ */
+
+namespace Httpful\Handlers;
+
+class XmlHandler extends MimeHandlerAdapter
+{
+ /**
+ * @var string $namespace xml namespace to use with simple_load_string
+ */
+ private $namespace;
+
+ /**
+ * @var int $libxml_opts see http://www.php.net/manual/en/libxml.constants.php
+ */
+ private $libxml_opts;
+
+ /**
+ * @param array $conf sets configuration options
+ */
+ public function __construct(array $conf = array())
+ {
+ $this->namespace = isset($conf['namespace']) ? $conf['namespace'] : '';
+ $this->libxml_opts = isset($conf['libxml_opts']) ? $conf['libxml_opts'] : 0;
+ }
+
+ /**
+ * @param string $body
+ * @return mixed
+ * @throws Exception if unable to parse
+ */
+ public function parse($body)
+ {
+ if (empty($body))
+ return null;
+ $parsed = simplexml_load_string($body, null, $this->libxml_opts, $this->namespace);
+ if ($parsed === false)
+ throw new \Exception("Unable to parse response as XML");
+ return $parsed;
+ }
+
+ /**
+ * @param mixed $payload
+ * @return string
+ * @throws Exception if unable to serialize
+ */
+ public function serialize($payload)
+ {
+ list($_, $dom) = $this->_future_serializeAsXml($payload);
+ return $dom->saveXml();
+ }
+
+ /**
+ * @author Zack Douglas
+ */
+ private function _future_serializeAsXml($value, $node = null, $dom = null)
+ {
+ if (!$dom) {
+ $dom = new \DOMDocument;
+ }
+ if (!$node) {
+ if (!is_object($value)) {
+ $node = $dom->createElement('response');
+ $dom->appendChild($node);
+ } else {
+ $node = $dom;
+ }
+ }
+ if (is_object($value)) {
+ $objNode = $dom->createElement(get_class($value));
+ $node->appendChild($objNode);
+ $this->_future_serializeObjectAsXml($value, $objNode, $dom);
+ } else if (is_array($value)) {
+ $arrNode = $dom->createElement('array');
+ $node->appendChild($arrNode);
+ $this->_future_serializeArrayAsXml($value, $arrNode, $dom);
+ } else if (is_bool($value)) {
+ $node->appendChild($dom->createTextNode($value?'TRUE':'FALSE'));
+ } else {
+ $node->appendChild($dom->createTextNode($value));
+ }
+ return array($node, $dom);
+ }
+ /**
+ * @author Zack Douglas
+ */
+ private function _future_serializeArrayAsXml($value, &$parent, &$dom)
+ {
+ foreach ($value as $k => &$v) {
+ $n = $k;
+ if (is_numeric($k)) {
+ $n = "child-{$n}";
+ }
+ $el = $dom->createElement($n);
+ $parent->appendChild($el);
+ $this->_future_serializeAsXml($v, $el, $dom);
+ }
+ return array($parent, $dom);
+ }
+ /**
+ * @author Zack Douglas
+ */
+ private function _future_serializeObjectAsXml($value, &$parent, &$dom)
+ {
+ $refl = new \ReflectionObject($value);
+ foreach ($refl->getProperties() as $pr) {
+ if (!$pr->isPrivate()) {
+ $el = $dom->createElement($pr->getName());
+ $parent->appendChild($el);
+ $this->_future_serializeAsXml($pr->getValue($value), $el, $dom);
+ }
+ }
+ return array($parent, $dom);
+ }
+}
\ No newline at end of file
diff --git a/app/Library/Poniverse/httpful/src/Httpful/Http.php b/app/Library/Poniverse/httpful/src/Httpful/Http.php
new file mode 100644
index 00000000..59374e93
--- /dev/null
+++ b/app/Library/Poniverse/httpful/src/Httpful/Http.php
@@ -0,0 +1,86 @@
+
+ */
+class Http
+{
+ const HEAD = 'HEAD';
+ const GET = 'GET';
+ const POST = 'POST';
+ const PUT = 'PUT';
+ const DELETE = 'DELETE';
+ const PATCH = 'PATCH';
+ const OPTIONS = 'OPTIONS';
+ const TRACE = 'TRACE';
+
+ /**
+ * @return array of HTTP method strings
+ */
+ public static function safeMethods()
+ {
+ return array(self::HEAD, self::GET, self::OPTIONS, self::TRACE);
+ }
+
+ /**
+ * @return bool
+ * @param string HTTP method
+ */
+ public static function isSafeMethod($method)
+ {
+ return in_array($method, self::safeMethods());
+ }
+
+ /**
+ * @return bool
+ * @param string HTTP method
+ */
+ public static function isUnsafeMethod($method)
+ {
+ return !in_array($method, self::safeMethods());
+ }
+
+ /**
+ * @return array list of (always) idempotent HTTP methods
+ */
+ public static function idempotentMethods()
+ {
+ // Though it is possible to be idempotent, POST
+ // is not guarunteed to be, and more often than
+ // not, it is not.
+ return array(self::HEAD, self::GET, self::PUT, self::DELETE, self::OPTIONS, self::TRACE, self::PATCH);
+ }
+
+ /**
+ * @return bool
+ * @param string HTTP method
+ */
+ public static function isIdempotent($method)
+ {
+ return in_array($method, self::safeidempotentMethodsMethods());
+ }
+
+ /**
+ * @return bool
+ * @param string HTTP method
+ */
+ public static function isNotIdempotent($method)
+ {
+ return !in_array($method, self::idempotentMethods());
+ }
+
+ /**
+ * @deprecated Technically anything *can* have a body,
+ * they just don't have semantic meaning. So say's Roy
+ * http://tech.groups.yahoo.com/group/rest-discuss/message/9962
+ *
+ * @return array of HTTP method strings
+ */
+ public static function canHaveBody()
+ {
+ return array(self::POST, self::PUT, self::PATCH, self::OPTIONS);
+ }
+
+}
\ No newline at end of file
diff --git a/app/Library/Poniverse/httpful/src/Httpful/Httpful.php b/app/Library/Poniverse/httpful/src/Httpful/Httpful.php
new file mode 100644
index 00000000..98cd75a9
--- /dev/null
+++ b/app/Library/Poniverse/httpful/src/Httpful/Httpful.php
@@ -0,0 +1,46 @@
+
+ */
+class Mime
+{
+ const JSON = 'application/json';
+ const XML = 'application/xml';
+ const XHTML = 'application/html+xml';
+ const FORM = 'application/x-www-form-urlencoded';
+ const PLAIN = 'text/plain';
+ const JS = 'text/javascript';
+ const HTML = 'text/html';
+ const YAML = 'application/x-yaml';
+ const CSV = 'text/csv';
+
+ /**
+ * Map short name for a mime type
+ * to a full proper mime type
+ */
+ public static $mimes = array(
+ 'json' => self::JSON,
+ 'xml' => self::XML,
+ 'form' => self::FORM,
+ 'plain' => self::PLAIN,
+ 'text' => self::PLAIN,
+ 'html' => self::HTML,
+ 'xhtml' => self::XHTML,
+ 'js' => self::JS,
+ 'javascript'=> self::JS,
+ 'yaml' => self::YAML,
+ 'csv' => self::CSV,
+ );
+
+ /**
+ * Get the full Mime Type name from a "short name".
+ * Returns the short if no mapping was found.
+ * @return string full mime type (e.g. application/json)
+ * @param string common name for mime type (e.g. json)
+ */
+ public static function getFullMime($short_name)
+ {
+ return array_key_exists($short_name, self::$mimes) ? self::$mimes[$short_name] : $short_name;
+ }
+
+ /**
+ * @return bool
+ * @param string $short_name
+ */
+ public static function supportsMimeType($short_name)
+ {
+ return array_key_exists($short_name, self::$mimes);
+ }
+}
diff --git a/app/Library/Poniverse/httpful/src/Httpful/Request.php b/app/Library/Poniverse/httpful/src/Httpful/Request.php
new file mode 100644
index 00000000..63b92ecb
--- /dev/null
+++ b/app/Library/Poniverse/httpful/src/Httpful/Request.php
@@ -0,0 +1,1023 @@
+
+ */
+class Request
+{
+
+ // Option constants
+ const SERIALIZE_PAYLOAD_NEVER = 0;
+ const SERIALIZE_PAYLOAD_ALWAYS = 1;
+ const SERIALIZE_PAYLOAD_SMART = 2;
+
+ const MAX_REDIRECTS_DEFAULT = 25;
+
+ public $uri,
+ $method = Http::GET,
+ $headers = array(),
+ $raw_headers = '',
+ $strict_ssl = false,
+ $content_type,
+ $expected_type,
+ $additional_curl_opts = array(),
+ $auto_parse = true,
+ $serialize_payload_method = self::SERIALIZE_PAYLOAD_SMART,
+ $username,
+ $password,
+ $serialized_payload,
+ $payload,
+ $parse_callback,
+ $error_callback,
+ $follow_redirects = false,
+ $max_redirects = self::MAX_REDIRECTS_DEFAULT,
+ $payload_serializers = array();
+
+ // Options
+ // private $_options = array(
+ // 'serialize_payload_method' => self::SERIALIZE_PAYLOAD_SMART
+ // 'auto_parse' => true
+ // );
+
+ // Curl Handle
+ public $_ch,
+ $_debug;
+
+ // Template Request object
+ private static $_template;
+
+ /**
+ * We made the constructor private to force the factory style. This was
+ * done to keep the syntax cleaner and better the support the idea of
+ * "default templates". Very basic and flexible as it is only intended
+ * for internal use.
+ * @param array $attrs hash of initial attribute values
+ */
+ private function __construct($attrs = null)
+ {
+ if (!is_array($attrs)) return;
+ foreach ($attrs as $attr => $value) {
+ $this->$attr = $value;
+ }
+ }
+
+ // Defaults Management
+
+ /**
+ * Let's you configure default settings for this
+ * class from a template Request object. Simply construct a
+ * Request object as much as you want to and then pass it to
+ * this method. It will then lock in those settings from
+ * that template object.
+ * The most common of which may be default mime
+ * settings or strict ssl settings.
+ * Again some slight memory overhead incurred here but in the grand
+ * scheme of things as it typically only occurs once
+ * @param Request $template
+ */
+ public static function ini(Request $template)
+ {
+ self::$_template = clone $template;
+ }
+
+ /**
+ * Reset the default template back to the
+ * library defaults.
+ */
+ public static function resetIni()
+ {
+ self::_initializeDefaults();
+ }
+
+ /**
+ * Get default for a value based on the template object
+ * @return mixed default value
+ * @param string|null $attr Name of attribute (e.g. mime, headers)
+ * if null just return the whole template object;
+ */
+ public static function d($attr)
+ {
+ return isset($attr) ? self::$_template->$attr : self::$_template;
+ }
+
+ // Accessors
+
+ /**
+ * @return bool does the request have a timeout?
+ */
+ public function hasTimeout()
+ {
+ return isset($this->timeout);
+ }
+
+ /**
+ * @return bool has the internal curl request been initialized?
+ */
+ public function hasBeenInitialized()
+ {
+ return isset($this->_ch);
+ }
+
+ /**
+ * @return bool Is this request setup for basic auth?
+ */
+ public function hasBasicAuth()
+ {
+ return isset($this->password) && isset($this->username);
+ }
+
+ /**
+ * @return bool Is this request setup for digest auth?
+ */
+ public function hasDigestAuth()
+ {
+ return isset($this->password) && isset($this->username) && $this->additional_curl_opts[CURLOPT_HTTPAUTH] == CURLAUTH_DIGEST;
+ }
+
+ /**
+ * Specify a HTTP timeout
+ * @return Request $this
+ * @param |int $timeout seconds to timeout the HTTP call
+ */
+ public function timeout($timeout)
+ {
+ $this->timeout = $timeout;
+ return $this;
+ }
+
+ // alias timeout
+ public function timeoutIn($seconds)
+ {
+ return $this->timeout($seconds);
+ }
+
+ /**
+ * If the response is a 301 or 302 redirect, automatically
+ * send off another request to that location
+ * @return Request $this
+ * @param bool|int $follow follow or not to follow or maximal number of redirects
+ */
+ public function followRedirects($follow = true)
+ {
+ $this->max_redirects = $follow === true ? self::MAX_REDIRECTS_DEFAULT : max(0, $follow);
+ $this->follow_redirects = (bool) $follow;
+ return $this;
+ }
+
+ /**
+ * @return Request $this
+ * @see Request::followRedirects()
+ */
+ public function doNotFollowRedirects()
+ {
+ return $this->followRedirects(false);
+ }
+
+ /**
+ * Actually send off the request, and parse the response
+ * @return string|associative array of parsed results
+ * @throws ConnectionErrorException when unable to parse or communicate w server
+ */
+ public function send()
+ {
+ if (!$this->hasBeenInitialized())
+ $this->_curlPrep();
+
+ $result = curl_exec($this->_ch);
+
+ if ($result === false) {
+ $this->_error(curl_error($this->_ch));
+ throw new ConnectionErrorException('Unable to connect.');
+ }
+
+ $info = curl_getinfo($this->_ch);
+ $response = explode("\r\n\r\n", $result, 2 + $info['redirect_count']);
+
+ $body = array_pop($response);
+ $headers = array_pop($response);
+
+ return new Response($body, $headers, $this);
+ }
+ public function sendIt()
+ {
+ return $this->send();
+ }
+
+ // Setters
+
+ /**
+ * @return Request this
+ * @param string $uri
+ */
+ public function uri($uri)
+ {
+ $this->uri = $uri;
+ return $this;
+ }
+
+ /**
+ * User Basic Auth.
+ * Only use when over SSL/TSL/HTTPS.
+ * @return Request this
+ * @param string $username
+ * @param string $password
+ */
+ public function basicAuth($username, $password)
+ {
+ $this->username = $username;
+ $this->password = $password;
+ return $this;
+ }
+ // @alias of basicAuth
+ public function authenticateWith($username, $password)
+ {
+ return $this->basicAuth($username, $password);
+ }
+ // @alias of basicAuth
+ public function authenticateWithBasic($username, $password)
+ {
+ return $this->basicAuth($username, $password);
+ }
+
+ /**
+ * User Digest Auth.
+ * @return Request this
+ * @param string $username
+ * @param string $password
+ */
+ public function digestAuth($username, $password)
+ {
+ $this->addOnCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
+ return $this->basicAuth($username, $password);
+ }
+
+ // @alias of digestAuth
+ public function authenticateWithDigest($username, $password)
+ {
+ return $this->digestAuth($username, $password);
+ }
+
+ /**
+ * @return is this request setup for client side cert?
+ */
+ public function hasClientSideCert() {
+ return isset($this->client_cert) && isset($this->client_key);
+ }
+
+ /**
+ * Use Client Side Cert Authentication
+ * @return Request $this
+ * @param string $key file path to client key
+ * @param string $cert file path to client cert
+ * @param string $passphrase for client key
+ * @param string $encoding default PEM
+ */
+ public function clientSideCert($cert, $key, $passphrase = null, $encoding = 'PEM')
+ {
+ $this->client_cert = $cert;
+ $this->client_key = $key;
+ $this->client_passphrase = $passphrase;
+ $this->client_encoding = $encoding;
+
+ return $this;
+ }
+ // @alias of basicAuth
+ public function authenticateWithCert($cert, $key, $passphrase = null, $encoding = 'PEM')
+ {
+ return $this->clientSideCert($cert, $key, $passphrase, $encoding);
+ }
+
+ /**
+ * Set the body of the request
+ * @return Request this
+ * @param mixed $payload
+ * @param string $mimeType
+ */
+ public function body($payload, $mimeType = null)
+ {
+ $this->mime($mimeType);
+ $this->payload = $payload;
+ // Iserntentially don't call _serializePayload yet. Wait until
+ // we actually send off the request to convert payload to string.
+ // At that time, the `serialized_payload` is set accordingly.
+ return $this;
+ }
+
+ /**
+ * Helper function to set the Content type and Expected as same in
+ * one swoop
+ * @return Request this
+ * @param string $mime mime type to use for content type and expected return type
+ */
+ public function mime($mime)
+ {
+ if (empty($mime)) return $this;
+ $this->content_type = $this->expected_type = Mime::getFullMime($mime);
+ return $this;
+ }
+ // @alias of mime
+ public function sendsAndExpectsType($mime)
+ {
+ return $this->mime($mime);
+ }
+ // @alias of mime
+ public function sendsAndExpects($mime)
+ {
+ return $this->mime($mime);
+ }
+
+ /**
+ * Set the method. Shouldn't be called often as the preferred syntax
+ * for instantiation is the method specific factory methods.
+ * @return Request this
+ * @param string $method
+ */
+ public function method($method)
+ {
+ if (empty($method)) return $this;
+ $this->method = $method;
+ return $this;
+ }
+
+ /**
+ * @return Request this
+ * @param string $mime
+ */
+ public function expects($mime)
+ {
+ if (empty($mime)) return $this;
+ $this->expected_type = Mime::getFullMime($mime);
+ return $this;
+ }
+ // @alias of expects
+ public function expectsType($mime)
+ {
+ return $this->expects($mime);
+ }
+
+ /**
+ * @return Request this
+ * @param string $mime
+ */
+ public function contentType($mime)
+ {
+ if (empty($mime)) return $this;
+ $this->content_type = Mime::getFullMime($mime);
+ return $this;
+ }
+ // @alias of contentType
+ public function sends($mime)
+ {
+ return $this->contentType($mime);
+ }
+ // @alias of contentType
+ public function sendsType($mime)
+ {
+ return $this->contentType($mime);
+ }
+
+ /**
+ * Do we strictly enforce SSL verification?
+ * @return Request this
+ * @param bool $strict
+ */
+ public function strictSSL($strict)
+ {
+ $this->strict_ssl = $strict;
+ return $this;
+ }
+ public function withoutStrictSSL()
+ {
+ return $this->strictSSL(false);
+ }
+ public function withStrictSSL()
+ {
+ return $this->strictSSL(true);
+ }
+
+ /**
+ * Use proxy configuration
+ * @return Request this
+ * @param string $proxy_host Hostname or address of the proxy
+ * @param number $proxy_port Port of the proxy. Default 80
+ * @param string $auth_type Authentication type or null. Accepted values are CURLAUTH_BASIC, CURLAUTH_NTLM. Default null, no authentication
+ * @param string $auth_username Authentication username. Default null
+ * @param string $auth_password Authentication password. Default null
+ */
+ public function useProxy($proxy_host, $proxy_port = 80, $auth_type = null, $auth_username = null, $auth_password = null){
+ $this->addOnCurlOption(CURLOPT_PROXY, "{$proxy_host}:{$proxy_port}");
+ if(in_array($auth_type, array(CURLAUTH_BASIC,CURLAUTH_NTLM)) ){
+ $this->addOnCurlOption(CURLOPT_PROXYAUTH, $auth_type)
+ ->addOnCurlOption(CURLOPT_PROXYUSERPWD, "{$auth_username}:{$auth_password}");
+ }
+ return $this;
+ }
+
+ /**
+ * @return is this request setup for using proxy?
+ */
+ public function hasProxy(){
+ return is_string($this->additional_curl_opts[CURLOPT_PROXY]);
+ }
+
+ /**
+ * Determine how/if we use the built in serialization by
+ * setting the serialize_payload_method
+ * The default (SERIALIZE_PAYLOAD_SMART) is...
+ * - if payload is not a scalar (object/array)
+ * use the appropriate serialize method according to
+ * the Content-Type of this request.
+ * - if the payload IS a scalar (int, float, string, bool)
+ * than just return it as is.
+ * When this option is set SERIALIZE_PAYLOAD_ALWAYS,
+ * it will always use the appropriate
+ * serialize option regardless of whether payload is scalar or not
+ * When this option is set SERIALIZE_PAYLOAD_NEVER,
+ * it will never use any of the serialization methods.
+ * Really the only use for this is if you want the serialize methods
+ * to handle strings or not (e.g. Blah is not valid JSON, but "Blah"
+ * is). Forcing the serialization helps prevent that kind of error from
+ * happening.
+ * @return Request $this
+ * @param int $mode
+ */
+ public function serializePayload($mode)
+ {
+ $this->serialize_payload_method = $mode;
+ return $this;
+ }
+
+ /**
+ * @see Request::serializePayload()
+ * @return Request
+ */
+ public function neverSerializePayload()
+ {
+ return $this->serializePayload(self::SERIALIZE_PAYLOAD_NEVER);
+ }
+
+ /**
+ * This method is the default behavior
+ * @see Request::serializePayload()
+ * @return Request
+ */
+ public function smartSerializePayload()
+ {
+ return $this->serializePayload(self::SERIALIZE_PAYLOAD_SMART);
+ }
+
+ /**
+ * @see Request::serializePayload()
+ * @return Request
+ */
+ public function alwaysSerializePayload()
+ {
+ return $this->serializePayload(self::SERIALIZE_PAYLOAD_ALWAYS);
+ }
+
+ /**
+ * Add an additional header to the request
+ * Can also use the cleaner syntax of
+ * $Request->withMyHeaderName($my_value);
+ * @see Request::__call()
+ *
+ * @return Request this
+ * @param string $header_name
+ * @param string $value
+ */
+ public function addHeader($header_name, $value)
+ {
+ $this->headers[$header_name] = $value;
+ return $this;
+ }
+
+ /**
+ * Add group of headers all at once. Note: This is
+ * here just as a convenience in very specific cases.
+ * The preferred "readable" way would be to leverage
+ * the support for custom header methods.
+ * @return Response $this
+ * @param array $headers
+ */
+ public function addHeaders(array $headers)
+ {
+ foreach ($headers as $header => $value) {
+ $this->addHeader($header, $value);
+ }
+ return $this;
+ }
+
+ /**
+ * @return Request
+ * @param bool $auto_parse perform automatic "smart"
+ * parsing based on Content-Type or "expectedType"
+ * If not auto parsing, Response->body returns the body
+ * as a string.
+ */
+ public function autoParse($auto_parse = true)
+ {
+ $this->auto_parse = $auto_parse;
+ return $this;
+ }
+
+ /**
+ * @see Request::autoParse()
+ * @return Request
+ */
+ public function withoutAutoParsing()
+ {
+ return $this->autoParse(false);
+ }
+
+ /**
+ * @see Request::autoParse()
+ * @return Request
+ */
+ public function withAutoParsing()
+ {
+ return $this->autoParse(true);
+ }
+
+ /**
+ * Use a custom function to parse the response.
+ * @return Request this
+ * @param \Closure $callback Takes the raw body of
+ * the http response and returns a mixed
+ */
+ public function parseWith(\Closure $callback)
+ {
+ $this->parse_callback = $callback;
+ return $this;
+ }
+
+ /**
+ * @see Request::parseResponsesWith()
+ * @return Request $this
+ * @param \Closure $callback
+ */
+ public function parseResponsesWith(\Closure $callback)
+ {
+ return $this->parseWith($callback);
+ }
+
+ /**
+ * Register a callback that will be used to serialize the payload
+ * for a particular mime type. When using "*" for the mime
+ * type, it will use that parser for all responses regardless of the mime
+ * type. If a custom '*' and 'application/json' exist, the custom
+ * 'application/json' would take precedence over the '*' callback.
+ *
+ * @return Request $this
+ * @param string $mime mime type we're registering
+ * @param Closure $callback takes one argument, $payload,
+ * which is the payload that we'll be
+ */
+ public function registerPayloadSerializer($mime, \Closure $callback)
+ {
+ $this->payload_serializers[Mime::getFullMime($mime)] = $callback;
+ return $this;
+ }
+
+ /**
+ * @see Request::registerPayloadSerializer()
+ * @return Request $this
+ * @param Closure $callback
+ */
+ public function serializePayloadWith(\Closure $callback)
+ {
+ return $this->regregisterPayloadSerializer('*', $callback);
+ }
+
+ /**
+ * Magic method allows for neatly setting other headers in a
+ * similar syntax as the other setters. This method also allows
+ * for the sends* syntax.
+ * @return Request this
+ * @param string $method "missing" method name called
+ * the method name called should be the name of the header that you
+ * are trying to set in camel case without dashes e.g. to set a
+ * header for Content-Type you would use contentType() or more commonly
+ * to add a custom header like X-My-Header, you would use xMyHeader().
+ * To promote readability, you can optionally prefix these methods with
+ * "with" (e.g. withXMyHeader("blah") instead of xMyHeader("blah")).
+ * @param array $args in this case, there should only ever be 1 argument provided
+ * and that argument should be a string value of the header we're setting
+ */
+ public function __call($method, $args)
+ {
+ // This method supports the sends* methods
+ // like sendsJSON, sendsForm
+ //!method_exists($this, $method) &&
+ if (substr($method, 0, 5) === 'sends') {
+ $mime = strtolower(substr($method, 5));
+ if (Mime::supportsMimeType($mime)) {
+ $this->sends(Mime::getFullMime($mime));
+ return $this;
+ }
+ // else {
+ // throw new \Exception("Unsupported Content-Type $mime");
+ // }
+ }
+ if (substr($method, 0, 7) === 'expects') {
+ $mime = strtolower(substr($method, 7));
+ if (Mime::supportsMimeType($mime)) {
+ $this->expects(Mime::getFullMime($mime));
+ return $this;
+ }
+ // else {
+ // throw new \Exception("Unsupported Content-Type $mime");
+ // }
+ }
+
+ // This method also adds the custom header support as described in the
+ // method comments
+ if (count($args) === 0)
+ return;
+
+ // Strip the sugar. If it leads with "with", strip.
+ // This is okay because: No defined HTTP headers begin with with,
+ // and if you are defining a custom header, the standard is to prefix it
+ // with an "X-", so that should take care of any collisions.
+ if (substr($method, 0, 4) === 'with')
+ $method = substr($method, 4);
+
+ // Precede upper case letters with dashes, uppercase the first letter of method
+ $header = ucwords(implode('-', preg_split('/([A-Z][^A-Z]*)/', $method, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)));
+ $this->addHeader($header, $args[0]);
+ return $this;
+ }
+
+ // Internal Functions
+
+ /**
+ * This is the default template to use if no
+ * template has been provided. The template
+ * tells the class which default values to use.
+ * While there is a slight overhead for object
+ * creation once per execution (not once per
+ * Request instantiation), it promotes readability
+ * and flexibility within the class.
+ */
+ private static function _initializeDefaults()
+ {
+ // This is the only place you will
+ // see this constructor syntax. It
+ // is only done here to prevent infinite
+ // recusion. Do not use this syntax elsewhere.
+ // It goes against the whole readability
+ // and transparency idea.
+ self::$_template = new Request(array('method' => Http::GET));
+
+ // This is more like it...
+ self::$_template
+ ->withoutStrictSSL();
+ }
+
+ /**
+ * Set the defaults on a newly instantiated object
+ * Doesn't copy variables prefixed with _
+ * @return Request this
+ */
+ private function _setDefaults()
+ {
+ if (!isset(self::$_template))
+ self::_initializeDefaults();
+ foreach (self::$_template as $k=>$v) {
+ if ($k[0] != '_')
+ $this->$k = $v;
+ }
+ return $this;
+ }
+
+ private function _error($error)
+ {
+ // Default actions write to error log
+ // TODO add in support for various Loggers
+ error_log($error);
+ }
+
+ /**
+ * Factory style constructor works nicer for chaining. This
+ * should also really only be used internally. The Request::get,
+ * Request::post syntax is preferred as it is more readable.
+ * @return Request
+ * @param string $method Http Method
+ * @param string $mime Mime Type to Use
+ */
+ public static function init($method = null, $mime = null)
+ {
+ // Setup our handlers, can call it here as it's idempotent
+ Bootstrap::init();
+
+ // Setup the default template if need be
+ if (!isset(self::$_template))
+ self::_initializeDefaults();
+
+ $request = new Request();
+ return $request
+ ->_setDefaults()
+ ->method($method)
+ ->sendsType($mime)
+ ->expectsType($mime);
+ }
+
+ /**
+ * Does the heavy lifting. Uses de facto HTTP
+ * library cURL to set up the HTTP request.
+ * Note: It does NOT actually send the request
+ * @return Request $this;
+ */
+ public function _curlPrep()
+ {
+ // Check for required stuff
+ if (!isset($this->uri))
+ throw new \Exception('Attempting to send a request before defining a URI endpoint.');
+
+ $ch = curl_init($this->uri);
+
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->method);
+
+ if ($this->hasBasicAuth()) {
+ curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);
+ }
+
+ if ($this->hasClientSideCert()) {
+
+ if (!file_exists($this->client_key))
+ throw new \Exception('Could not read Client Key');
+
+ if (!file_exists($this->client_cert))
+ throw new \Exception('Could not read Client Certificate');
+
+ curl_setopt($ch, CURLOPT_SSLCERTTYPE, $this->client_encoding);
+ curl_setopt($ch, CURLOPT_SSLKEYTYPE, $this->client_encoding);
+ curl_setopt($ch, CURLOPT_SSLCERT, $this->client_cert);
+ curl_setopt($ch, CURLOPT_SSLKEY, $this->client_key);
+ curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $this->client_passphrase);
+ // curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $this->client_cert_passphrase);
+ }
+
+ if ($this->hasTimeout()) {
+ curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
+ }
+
+ if ($this->follow_redirects) {
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+ curl_setopt($ch, CURLOPT_MAXREDIRS, $this->max_redirects);
+ }
+
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->strict_ssl);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+ // https://github.com/nategood/httpful/issues/84
+ // set Content-Length to the size of the payload if present
+ if (isset($this->payload)) {
+ $this->serialized_payload = $this->_serializePayload($this->payload);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $this->serialized_payload);
+ $this->headers['Content-Length'] = strlen($this->serialized_payload);
+ }
+
+ $headers = array();
+ // https://github.com/nategood/httpful/issues/37
+ // Except header removes any HTTP 1.1 Continue from response headers
+ $headers[] = 'Expect:';
+
+ if (!isset($this->headers['User-Agent'])) {
+ $headers[] = $this->buildUserAgent();
+ }
+
+ $headers[] = "Content-Type: {$this->content_type}";
+
+ // allow custom Accept header if set
+ if (!isset($this->headers['Accept'])) {
+ // http://pretty-rfc.herokuapp.com/RFC2616#header.accept
+ $accept = 'Accept: */*; q=0.5, text/plain; q=0.8, text/html;level=3;';
+
+ if (!empty($this->expected_type)) {
+ $accept .= "q=0.9, {$this->expected_type}";
+ }
+
+ $headers[] = $accept;
+ }
+
+ // Solve a bug on squid proxy, NONE/411 when miss content length
+ if (!isset($this->headers['Content-Length'])) {
+ $this->headers['Content-Length'] = 0;
+ }
+
+ foreach ($this->headers as $header => $value) {
+ $headers[] = "$header: $value";
+ }
+
+ $url = \parse_url($this->uri);
+ $path = (isset($url['path']) ? $url['path'] : '/').(isset($url['query']) ? '?'.$url['query'] : '');
+ $this->raw_headers = "{$this->method} $path HTTP/1.1\r\n";
+ $host = (isset($url['host']) ? $url['host'] : 'localhost').(isset($url['port']) ? ':'.$url['port'] : '');
+ $this->raw_headers .= "Host: $host\r\n";
+ $this->raw_headers .= \implode("\r\n", $headers);
+ $this->raw_headers .= "\r\n";
+
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+
+ if ($this->_debug) {
+ curl_setopt($ch, CURLOPT_VERBOSE, true);
+ }
+
+ curl_setopt($ch, CURLOPT_HEADER, 1);
+
+ // If there are some additional curl opts that the user wants
+ // to set, we can tack them in here
+ foreach ($this->additional_curl_opts as $curlopt => $curlval) {
+ curl_setopt($ch, $curlopt, $curlval);
+ }
+
+ $this->_ch = $ch;
+
+ return $this;
+ }
+
+ public function buildUserAgent() {
+ $user_agent = 'User-Agent: Httpful/' . Httpful::VERSION . ' (cURL/';
+ $curl = \curl_version();
+
+ if (isset($curl['version'])) {
+ $user_agent .= $curl['version'];
+ } else {
+ $user_agent .= '?.?.?';
+ }
+
+ $user_agent .= ' PHP/'. PHP_VERSION . ' (' . PHP_OS . ')';
+
+ if (isset($_SERVER['SERVER_SOFTWARE'])) {
+ $user_agent .= ' ' . \preg_replace('~PHP/[\d\.]+~U', '',
+ $_SERVER['SERVER_SOFTWARE']);
+ } else {
+ if (isset($_SERVER['TERM_PROGRAM'])) {
+ $user_agent .= " {$_SERVER['TERM_PROGRAM']}";
+ }
+
+ if (isset($_SERVER['TERM_PROGRAM_VERSION'])) {
+ $user_agent .= "/{$_SERVER['TERM_PROGRAM_VERSION']}";
+ }
+ }
+
+ if (isset($_SERVER['HTTP_USER_AGENT'])) {
+ $user_agent .= " {$_SERVER['HTTP_USER_AGENT']}";
+ }
+
+ $user_agent .= ')';
+
+ return $user_agent;
+ }
+
+ /**
+ * Semi-reluctantly added this as a way to add in curl opts
+ * that are not otherwise accessible from the rest of the API.
+ * @return Request $this
+ * @param string $curlopt
+ * @param mixed $curloptval
+ */
+ public function addOnCurlOption($curlopt, $curloptval)
+ {
+ $this->additional_curl_opts[$curlopt] = $curloptval;
+ return $this;
+ }
+
+ /**
+ * Turn payload from structured data into
+ * a string based on the current Mime type.
+ * This uses the auto_serialize option to determine
+ * it's course of action. See serialize method for more.
+ * Renamed from _detectPayload to _serializePayload as of
+ * 2012-02-15.
+ *
+ * Added in support for custom payload serializers.
+ * The serialize_payload_method stuff still holds true though.
+ * @see Request::registerPayloadSerializer()
+ *
+ * @return string
+ * @param mixed $payload
+ */
+ private function _serializePayload($payload)
+ {
+ if (empty($payload) || $this->serialize_payload_method === self::SERIALIZE_PAYLOAD_NEVER)
+ return $payload;
+
+ // When we are in "smart" mode, don't serialize strings/scalars, assume they are already serialized
+ if ($this->serialize_payload_method === self::SERIALIZE_PAYLOAD_SMART && is_scalar($payload))
+ return $payload;
+
+ // Use a custom serializer if one is registered for this mime type
+ if (isset($this->payload_serializers['*']) || isset($this->payload_serializers[$this->content_type])) {
+ $key = isset($this->payload_serializers[$this->content_type]) ? $this->content_type : '*';
+ return call_user_func($this->payload_serializers[$key], $payload);
+ }
+
+ return Httpful::get($this->content_type)->serialize($payload);
+ }
+
+ /**
+ * HTTP Method Get
+ * @return Request
+ * @param string $uri optional uri to use
+ * @param string $mime expected
+ */
+ public static function get($uri, $mime = null)
+ {
+ return self::init(Http::GET)->uri($uri)->mime($mime);
+ }
+
+
+ /**
+ * Like Request:::get, except that it sends off the request as well
+ * returning a response
+ * @return Response
+ * @param string $uri optional uri to use
+ * @param string $mime expected
+ */
+ public static function getQuick($uri, $mime = null)
+ {
+ return self::get($uri, $mime)->send();
+ }
+
+ /**
+ * HTTP Method Post
+ * @return Request
+ * @param string $uri optional uri to use
+ * @param string $payload data to send in body of request
+ * @param string $mime MIME to use for Content-Type
+ */
+ public static function post($uri, $payload = null, $mime = null)
+ {
+ return self::init(Http::POST)->uri($uri)->body($payload, $mime);
+ }
+
+ /**
+ * HTTP Method Put
+ * @return Request
+ * @param string $uri optional uri to use
+ * @param string $payload data to send in body of request
+ * @param string $mime MIME to use for Content-Type
+ */
+ public static function put($uri, $payload = null, $mime = null)
+ {
+ return self::init(Http::PUT)->uri($uri)->body($payload, $mime);
+ }
+
+ /**
+ * HTTP Method Patch
+ * @return Request
+ * @param string $uri optional uri to use
+ * @param string $payload data to send in body of request
+ * @param string $mime MIME to use for Content-Type
+ */
+ public static function patch($uri, $payload = null, $mime = null)
+ {
+ return self::init(Http::PATCH)->uri($uri)->body($payload, $mime);
+ }
+
+ /**
+ * HTTP Method Delete
+ * @return Request
+ * @param string $uri optional uri to use
+ */
+ public static function delete($uri, $mime = null)
+ {
+ return self::init(Http::DELETE)->uri($uri)->mime($mime);
+ }
+
+ /**
+ * HTTP Method Head
+ * @return Request
+ * @param string $uri optional uri to use
+ */
+ public static function head($uri)
+ {
+ return self::init(Http::HEAD)->uri($uri);
+ }
+
+ /**
+ * HTTP Method Options
+ * @return Request
+ * @param string $uri optional uri to use
+ */
+ public static function options($uri)
+ {
+ return self::init(Http::OPTIONS)->uri($uri);
+ }
+}
diff --git a/app/Library/Poniverse/httpful/src/Httpful/Response.php b/app/Library/Poniverse/httpful/src/Httpful/Response.php
new file mode 100644
index 00000000..c5199d3e
--- /dev/null
+++ b/app/Library/Poniverse/httpful/src/Httpful/Response.php
@@ -0,0 +1,189 @@
+
+ */
+class Response
+{
+
+ public $body,
+ $raw_body,
+ $headers,
+ $raw_headers,
+ $request,
+ $code = 0,
+ $content_type,
+ $parent_type,
+ $charset,
+ $is_mime_vendor_specific = false,
+ $is_mime_personal = false;
+
+ private $parsers;
+ /**
+ * @param string $body
+ * @param string $headers
+ * @param Request $request
+ */
+ public function __construct($body, $headers, Request $request)
+ {
+ $this->request = $request;
+ $this->raw_headers = $headers;
+ $this->raw_body = $body;
+
+ $this->code = $this->_parseCode($headers);
+ $this->headers = Response\Headers::fromString($headers);
+
+ $this->_interpretHeaders();
+
+ $this->body = $this->_parse($body);
+ }
+
+ /**
+ * Status Code Definitions
+ *
+ * Informational 1xx
+ * Successful 2xx
+ * Redirection 3xx
+ * Client Error 4xx
+ * Server Error 5xx
+ *
+ * http://pretty-rfc.herokuapp.com/RFC2616#status.codes
+ *
+ * @return bool Did we receive a 4xx or 5xx?
+ */
+ public function hasErrors()
+ {
+ return $this->code >= 400;
+ }
+
+ /**
+ * @return return bool
+ */
+ public function hasBody()
+ {
+ return !empty($this->body);
+ }
+
+ /**
+ * Parse the response into a clean data structure
+ * (most often an associative array) based on the expected
+ * Mime type.
+ * @return array|string|object the response parse accordingly
+ * @param string Http response body
+ */
+ public function _parse($body)
+ {
+ // If the user decided to forgo the automatic
+ // smart parsing, short circuit.
+ if (!$this->request->auto_parse) {
+ return $body;
+ }
+
+ // If provided, use custom parsing callback
+ if (isset($this->request->parse_callback)) {
+ return call_user_func($this->request->parse_callback, $body);
+ }
+
+ // Decide how to parse the body of the response in the following order
+ // 1. If provided, use the mime type specifically set as part of the `Request`
+ // 2. If a MimeHandler is registered for the content type, use it
+ // 3. If provided, use the "parent type" of the mime type from the response
+ // 4. Default to the content-type provided in the response
+ $parse_with = $this->request->expected_type;
+ if (empty($this->request->expected_type)) {
+ $parse_with = Httpful::hasParserRegistered($this->content_type)
+ ? $this->content_type
+ : $this->parent_type;
+ }
+
+ return Httpful::get($parse_with)->parse($body);
+ }
+
+ /**
+ * Parse text headers from response into
+ * array of key value pairs
+ * @return array parse headers
+ * @param string $headers raw headers
+ */
+ public function _parseHeaders($headers)
+ {
+ $headers = preg_split("/(\r|\n)+/", $headers, -1, \PREG_SPLIT_NO_EMPTY);
+ $parse_headers = array();
+ for ($i = 1; $i < count($headers); $i++) {
+ list($key, $raw_value) = explode(':', $headers[$i], 2);
+ $key = trim($key);
+ $value = trim($raw_value);
+ if (array_key_exists($key, $parse_headers)) {
+ // See HTTP RFC Sec 4.2 Paragraph 5
+ // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
+ // If a header appears more than once, it must also be able to
+ // be represented as a single header with a comma-separated
+ // list of values. We transform accordingly.
+ $parse_headers[$key] .= ',' . $value;
+ } else {
+ $parse_headers[$key] = $value;
+ }
+ }
+ return $parse_headers;
+ }
+
+ public function _parseCode($headers)
+ {
+ $parts = explode(' ', substr($headers, 0, strpos($headers, "\r\n")));
+ if (count($parts) < 2 || !is_numeric($parts[1])) {
+ throw new \Exception("Unable to parse response code from HTTP response due to malformed response");
+ }
+ return intval($parts[1]);
+ }
+
+ /**
+ * After we've parse the headers, let's clean things
+ * up a bit and treat some headers specially
+ */
+ public function _interpretHeaders()
+ {
+ // Parse the Content-Type and charset
+ $content_type = isset($this->headers['Content-Type']) ? $this->headers['Content-Type'] : '';
+ $content_type = explode(';', $content_type);
+
+ $this->content_type = $content_type[0];
+ if (count($content_type) == 2 && strpos($content_type[1], '=') !== false) {
+ list($nill, $this->charset) = explode('=', $content_type[1]);
+ }
+
+ // RFC 2616 states "text/*" Content-Types should have a default
+ // charset of ISO-8859-1. "application/*" and other Content-Types
+ // are assumed to have UTF-8 unless otherwise specified.
+ // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1
+ // http://www.w3.org/International/O-HTTP-charset.en.php
+ if (!isset($this->charset)) {
+ $this->charset = substr($this->content_type, 5) === 'text/' ? 'iso-8859-1' : 'utf-8';
+ }
+
+ // Is vendor type? Is personal type?
+ if (strpos($this->content_type, '/') !== false) {
+ list($type, $sub_type) = explode('/', $this->content_type);
+ $this->is_mime_vendor_specific = substr($sub_type, 0, 4) === 'vnd.';
+ $this->is_mime_personal = substr($sub_type, 0, 4) === 'prs.';
+ }
+
+ // Parent type (e.g. xml for application/vnd.github.message+xml)
+ $this->parent_type = $this->content_type;
+ if (strpos($this->content_type, '+') !== false) {
+ list($vendor, $this->parent_type) = explode('+', $this->content_type, 2);
+ $this->parent_type = Mime::getFullMime($this->parent_type);
+ }
+ }
+
+ /**
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->raw_body;
+ }
+}
diff --git a/app/Library/Poniverse/httpful/src/Httpful/Response/Headers.php b/app/Library/Poniverse/httpful/src/Httpful/Response/Headers.php
new file mode 100644
index 00000000..7abc57dd
--- /dev/null
+++ b/app/Library/Poniverse/httpful/src/Httpful/Response/Headers.php
@@ -0,0 +1,58 @@
+headers = $headers;
+ }
+
+ public static function fromString($string)
+ {
+ $lines = preg_split("/(\r|\n)+/", $string, -1, PREG_SPLIT_NO_EMPTY);
+ array_shift($lines); // HTTP HEADER
+ $headers = array();
+ foreach ($lines as $line) {
+ list($name, $value) = explode(':', $line, 2);
+ $headers[strtolower(trim($name))] = trim($value);
+ }
+ return new self($headers);
+ }
+
+ public function offsetExists($offset)
+ {
+ return isset($this->headers[strtolower($offset)]);
+ }
+
+ public function offsetGet($offset)
+ {
+ if (isset($this->headers[$name = strtolower($offset)])) {
+ return $this->headers[$name];
+ }
+ }
+
+ public function offsetSet($offset, $value)
+ {
+ throw new \Exception("Headers are read-only.");
+ }
+
+ public function offsetUnset($offset)
+ {
+ throw new \Exception("Headers are read-only.");
+ }
+
+ public function count()
+ {
+ return count($this->headers);
+ }
+
+ public function toArray()
+ {
+ return $this->headers;
+ }
+
+}
\ No newline at end of file
diff --git a/app/Library/Poniverse/httpful/tests/Httpful/HttpfulTest.php b/app/Library/Poniverse/httpful/tests/Httpful/HttpfulTest.php
new file mode 100644
index 00000000..ac2ab546
--- /dev/null
+++ b/app/Library/Poniverse/httpful/tests/Httpful/HttpfulTest.php
@@ -0,0 +1,458 @@
+
+ */
+namespace Httpful\Test;
+
+require(dirname(dirname(dirname(__FILE__))) . '/bootstrap.php');
+\Httpful\Bootstrap::init();
+
+use Httpful\Httpful;
+use Httpful\Request;
+use Httpful\Mime;
+use Httpful\Http;
+use Httpful\Response;
+
+class HttpfulTest extends \PHPUnit_Framework_TestCase
+{
+ const TEST_SERVER = '127.0.0.1:8008';
+ const TEST_URL = 'http://127.0.0.1:8008';
+ const TEST_URL_400 = 'http://127.0.0.1:8008/400';
+
+ const SAMPLE_JSON_HEADER =
+"HTTP/1.1 200 OK
+Content-Type: application/json
+Connection: keep-alive
+Transfer-Encoding: chunked\r\n";
+ const SAMPLE_JSON_RESPONSE = '{"key":"value","object":{"key":"value"},"array":[1,2,3,4]}';
+ const SAMPLE_CSV_HEADER =
+"HTTP/1.1 200 OK
+Content-Type: text/csv
+Connection: keep-alive
+Transfer-Encoding: chunked\r\n";
+ const SAMPLE_CSV_RESPONSE =
+"Key1,Key2
+Value1,Value2
+\"40.0\",\"Forty\"";
+ const SAMPLE_XML_RESPONSE = '2a stringTRUE';
+ const SAMPLE_XML_HEADER =
+"HTTP/1.1 200 OK
+Content-Type: application/xml
+Connection: keep-alive
+Transfer-Encoding: chunked\r\n";
+ const SAMPLE_VENDOR_HEADER =
+"HTTP/1.1 200 OK
+Content-Type: application/vnd.nategood.message+xml
+Connection: keep-alive
+Transfer-Encoding: chunked\r\n";
+ const SAMPLE_VENDOR_TYPE = "application/vnd.nategood.message+xml";
+ const SAMPLE_MULTI_HEADER =
+"HTTP/1.1 200 OK
+Content-Type: application/json
+Connection: keep-alive
+Transfer-Encoding: chunked
+X-My-Header:Value1
+X-My-Header:Value2\r\n";
+ function testInit()
+ {
+ $r = Request::init();
+ // Did we get a 'Request' object?
+ $this->assertEquals('Httpful\Request', get_class($r));
+ }
+
+ function testMethods()
+ {
+ $valid_methods = array('get', 'post', 'delete', 'put', 'options', 'head');
+ $url = 'http://example.com/';
+ foreach ($valid_methods as $method) {
+ $r = call_user_func(array('Httpful\Request', $method), $url);
+ $this->assertEquals('Httpful\Request', get_class($r));
+ $this->assertEquals(strtoupper($method), $r->method);
+ }
+ }
+
+ function testDefaults()
+ {
+ // Our current defaults are as follows
+ $r = Request::init();
+ $this->assertEquals(Http::GET, $r->method);
+ $this->assertFalse($r->strict_ssl);
+ }
+
+ function testShortMime()
+ {
+ // Valid short ones
+ $this->assertEquals(Mime::JSON, Mime::getFullMime('json'));
+ $this->assertEquals(Mime::XML, Mime::getFullMime('xml'));
+ $this->assertEquals(Mime::HTML, Mime::getFullMime('html'));
+ $this->assertEquals(Mime::CSV, Mime::getFullMime('csv'));
+
+ // Valid long ones
+ $this->assertEquals(Mime::JSON, Mime::getFullMime(Mime::JSON));
+ $this->assertEquals(Mime::XML, Mime::getFullMime(Mime::XML));
+ $this->assertEquals(Mime::HTML, Mime::getFullMime(Mime::HTML));
+ $this->assertEquals(Mime::CSV, Mime::getFullMime(Mime::CSV));
+
+ // No false positives
+ $this->assertNotEquals(Mime::XML, Mime::getFullMime(Mime::HTML));
+ $this->assertNotEquals(Mime::JSON, Mime::getFullMime(Mime::XML));
+ $this->assertNotEquals(Mime::HTML, Mime::getFullMime(Mime::JSON));
+ $this->assertNotEquals(Mime::XML, Mime::getFullMime(Mime::CSV));
+ }
+
+ function testSettingStrictSsl()
+ {
+ $r = Request::init()
+ ->withStrictSsl();
+
+ $this->assertTrue($r->strict_ssl);
+
+ $r = Request::init()
+ ->withoutStrictSsl();
+
+ $this->assertFalse($r->strict_ssl);
+ }
+
+ function testSendsAndExpectsType()
+ {
+ $r = Request::init()
+ ->sendsAndExpectsType(Mime::JSON);
+ $this->assertEquals(Mime::JSON, $r->expected_type);
+ $this->assertEquals(Mime::JSON, $r->content_type);
+
+ $r = Request::init()
+ ->sendsAndExpectsType('html');
+ $this->assertEquals(Mime::HTML, $r->expected_type);
+ $this->assertEquals(Mime::HTML, $r->content_type);
+
+ $r = Request::init()
+ ->sendsAndExpectsType('form');
+ $this->assertEquals(Mime::FORM, $r->expected_type);
+ $this->assertEquals(Mime::FORM, $r->content_type);
+
+ $r = Request::init()
+ ->sendsAndExpectsType('application/x-www-form-urlencoded');
+ $this->assertEquals(Mime::FORM, $r->expected_type);
+ $this->assertEquals(Mime::FORM, $r->content_type);
+
+ $r = Request::init()
+ ->sendsAndExpectsType(Mime::CSV);
+ $this->assertEquals(Mime::CSV, $r->expected_type);
+ $this->assertEquals(Mime::CSV, $r->content_type);
+ }
+
+ function testIni()
+ {
+ // Test setting defaults/templates
+
+ // Create the template
+ $template = Request::init()
+ ->method(Http::POST)
+ ->withStrictSsl()
+ ->expectsType(Mime::HTML)
+ ->sendsType(Mime::FORM);
+
+ Request::ini($template);
+
+ $r = Request::init();
+
+ $this->assertTrue($r->strict_ssl);
+ $this->assertEquals(Http::POST, $r->method);
+ $this->assertEquals(Mime::HTML, $r->expected_type);
+ $this->assertEquals(Mime::FORM, $r->content_type);
+
+ // Test the default accessor as well
+ $this->assertTrue(Request::d('strict_ssl'));
+ $this->assertEquals(Http::POST, Request::d('method'));
+ $this->assertEquals(Mime::HTML, Request::d('expected_type'));
+ $this->assertEquals(Mime::FORM, Request::d('content_type'));
+
+ Request::resetIni();
+ }
+
+ function testAccept()
+ {
+ $r = Request::get('http://example.com/')
+ ->expectsType(Mime::JSON);
+
+ $this->assertEquals(Mime::JSON, $r->expected_type);
+ $r->_curlPrep();
+ $this->assertContains('application/json', $r->raw_headers);
+ }
+
+ function testCustomAccept()
+ {
+ $accept = 'application/api-1.0+json';
+ $r = Request::get('http://example.com/')
+ ->addHeader('Accept', $accept);
+
+ $r->_curlPrep();
+ $this->assertContains($accept, $r->raw_headers);
+ $this->assertEquals($accept, $r->headers['Accept']);
+ }
+
+ function testUserAgent()
+ {
+ $r = Request::get('http://example.com/')
+ ->withUserAgent('ACME/1.2.3');
+
+ $this->assertArrayHasKey('User-Agent', $r->headers);
+ $r->_curlPrep();
+ $this->assertContains('User-Agent: ACME/1.2.3', $r->raw_headers);
+ $this->assertNotContains('User-Agent: HttpFul/1.0', $r->raw_headers);
+
+ $r = Request::get('http://example.com/')
+ ->withUserAgent('');
+
+ $this->assertArrayHasKey('User-Agent', $r->headers);
+ $r->_curlPrep();
+ $this->assertContains('User-Agent:', $r->raw_headers);
+ $this->assertNotContains('User-Agent: HttpFul/1.0', $r->raw_headers);
+ }
+
+ function testAuthSetup()
+ {
+ $username = 'nathan';
+ $password = 'opensesame';
+
+ $r = Request::get('http://example.com/')
+ ->authenticateWith($username, $password);
+
+ $this->assertEquals($username, $r->username);
+ $this->assertEquals($password, $r->password);
+ $this->assertTrue($r->hasBasicAuth());
+ }
+
+ function testDigestAuthSetup()
+ {
+ $username = 'nathan';
+ $password = 'opensesame';
+
+ $r = Request::get('http://example.com/')
+ ->authenticateWithDigest($username, $password);
+
+ $this->assertEquals($username, $r->username);
+ $this->assertEquals($password, $r->password);
+ $this->assertTrue($r->hasDigestAuth());
+ }
+
+ function testJsonResponseParse()
+ {
+ $req = Request::init()->sendsAndExpects(Mime::JSON);
+ $response = new Response(self::SAMPLE_JSON_RESPONSE, self::SAMPLE_JSON_HEADER, $req);
+
+ $this->assertEquals("value", $response->body->key);
+ $this->assertEquals("value", $response->body->object->key);
+ $this->assertInternalType('array', $response->body->array);
+ $this->assertEquals(1, $response->body->array[0]);
+ }
+
+ function testXMLResponseParse()
+ {
+ $req = Request::init()->sendsAndExpects(Mime::XML);
+ $response = new Response(self::SAMPLE_XML_RESPONSE, self::SAMPLE_XML_HEADER, $req);
+ $sxe = $response->body;
+ $this->assertEquals("object", gettype($sxe));
+ $this->assertEquals("SimpleXMLElement", get_class($sxe));
+ $bools = $sxe->xpath('/stdClass/boolProp');
+ list( , $bool ) = each($bools);
+ $this->assertEquals("TRUE", (string) $bool);
+ $ints = $sxe->xpath('/stdClass/arrayProp/array/k1/myClass/intProp');
+ list( , $int ) = each($ints);
+ $this->assertEquals("2", (string) $int);
+ $strings = $sxe->xpath('/stdClass/stringProp');
+ list( , $string ) = each($strings);
+ $this->assertEquals("a string", (string) $string);
+ }
+
+ function testCsvResponseParse()
+ {
+ $req = Request::init()->sendsAndExpects(Mime::CSV);
+ $response = new Response(self::SAMPLE_CSV_RESPONSE, self::SAMPLE_CSV_HEADER, $req);
+
+ $this->assertEquals("Key1", $response->body[0][0]);
+ $this->assertEquals("Value1", $response->body[1][0]);
+ $this->assertInternalType('string', $response->body[2][0]);
+ $this->assertEquals("40.0", $response->body[2][0]);
+ }
+
+ function testParsingContentTypeCharset()
+ {
+ $req = Request::init()->sendsAndExpects(Mime::JSON);
+ // $response = new Response(SAMPLE_JSON_RESPONSE, "", $req);
+ // // Check default content type of iso-8859-1
+ $response = new Response(self::SAMPLE_JSON_RESPONSE, "HTTP/1.1 200 OK
+Content-Type: text/plain; charset=utf-8\r\n", $req);
+ $this->assertInstanceOf('Httpful\Response\Headers', $response->headers);
+ $this->assertEquals($response->headers['Content-Type'], 'text/plain; charset=utf-8');
+ $this->assertEquals($response->content_type, 'text/plain');
+ $this->assertEquals($response->charset, 'utf-8');
+ }
+
+ function testEmptyResponseParse()
+ {
+ $req = Request::init()->sendsAndExpects(Mime::JSON);
+ $response = new Response("", self::SAMPLE_JSON_HEADER, $req);
+ $this->assertEquals(null, $response->body);
+
+ $reqXml = Request::init()->sendsAndExpects(Mime::XML);
+ $responseXml = new Response("", self::SAMPLE_XML_HEADER, $reqXml);
+ $this->assertEquals(null, $responseXml->body);
+ }
+
+ function testNoAutoParse()
+ {
+ $req = Request::init()->sendsAndExpects(Mime::JSON)->withoutAutoParsing();
+ $response = new Response(self::SAMPLE_JSON_RESPONSE, self::SAMPLE_JSON_HEADER, $req);
+ $this->assertInternalType('string', $response->body);
+ $req = Request::init()->sendsAndExpects(Mime::JSON)->withAutoParsing();
+ $response = new Response(self::SAMPLE_JSON_RESPONSE, self::SAMPLE_JSON_HEADER, $req);
+ $this->assertInternalType('object', $response->body);
+ }
+
+ function testParseHeaders()
+ {
+ $req = Request::init()->sendsAndExpects(Mime::JSON);
+ $response = new Response(self::SAMPLE_JSON_RESPONSE, self::SAMPLE_JSON_HEADER, $req);
+ $this->assertEquals('application/json', $response->headers['Content-Type']);
+ }
+
+ function testRawHeaders()
+ {
+ $req = Request::init()->sendsAndExpects(Mime::JSON);
+ $response = new Response(self::SAMPLE_JSON_RESPONSE, self::SAMPLE_JSON_HEADER, $req);
+ $this->assertContains('Content-Type: application/json', $response->raw_headers);
+ }
+
+ function testHasErrors()
+ {
+ $req = Request::init()->sendsAndExpects(Mime::JSON);
+ $response = new Response('', "HTTP/1.1 100 Continue\r\n", $req);
+ $this->assertFalse($response->hasErrors());
+ $response = new Response('', "HTTP/1.1 200 OK\r\n", $req);
+ $this->assertFalse($response->hasErrors());
+ $response = new Response('', "HTTP/1.1 300 Multiple Choices\r\n", $req);
+ $this->assertFalse($response->hasErrors());
+ $response = new Response('', "HTTP/1.1 400 Bad Request\r\n", $req);
+ $this->assertTrue($response->hasErrors());
+ $response = new Response('', "HTTP/1.1 500 Internal Server Error\r\n", $req);
+ $this->assertTrue($response->hasErrors());
+ }
+
+ function test_parseCode()
+ {
+ $req = Request::init()->sendsAndExpects(Mime::JSON);
+ $response = new Response(self::SAMPLE_JSON_RESPONSE, self::SAMPLE_JSON_HEADER, $req);
+ $code = $response->_parseCode("HTTP/1.1 406 Not Acceptable\r\n");
+ $this->assertEquals(406, $code);
+ }
+
+ function testToString()
+ {
+ $req = Request::init()->sendsAndExpects(Mime::JSON);
+ $response = new Response(self::SAMPLE_JSON_RESPONSE, self::SAMPLE_JSON_HEADER, $req);
+ $this->assertEquals(self::SAMPLE_JSON_RESPONSE, (string)$response);
+ }
+
+ function test_parseHeaders()
+ {
+ $parse_headers = Response\Headers::fromString(self::SAMPLE_JSON_HEADER);
+ $this->assertCount(3, $parse_headers);
+ $this->assertEquals('application/json', $parse_headers['Content-Type']);
+ $this->assertTrue(isset($parse_headers['Connection']));
+ }
+
+ function testMultiHeaders()
+ {
+ $req = Request::init();
+ $response = new Response(self::SAMPLE_JSON_RESPONSE, self::SAMPLE_MULTI_HEADER, $req);
+ $parse_headers = $response->_parseHeaders(self::SAMPLE_MULTI_HEADER);
+ $this->assertEquals('Value1,Value2', $parse_headers['X-My-Header']);
+ }
+
+ function testDetectContentType()
+ {
+ $req = Request::init();
+ $response = new Response(self::SAMPLE_JSON_RESPONSE, self::SAMPLE_JSON_HEADER, $req);
+ $this->assertEquals('application/json', $response->headers['Content-Type']);
+ }
+
+ function testMissingBodyContentType()
+ {
+ $body = 'A string';
+ $request = Request::post(HttpfulTest::TEST_URL, $body)->_curlPrep();
+ $this->assertEquals($body, $request->serialized_payload);
+ }
+
+ function testParentType()
+ {
+ // Parent type
+ $request = Request::init()->sendsAndExpects(Mime::XML);
+ $response = new Response('Nathan', self::SAMPLE_VENDOR_HEADER, $request);
+
+ $this->assertEquals("application/xml", $response->parent_type);
+ $this->assertEquals(self::SAMPLE_VENDOR_TYPE, $response->content_type);
+ $this->assertTrue($response->is_mime_vendor_specific);
+
+ // Make sure we still parsed as if it were plain old XML
+ $this->assertEquals("Nathan", $response->body->name->__toString());
+ }
+
+ function testMissingContentType()
+ {
+ // Parent type
+ $request = Request::init()->sendsAndExpects(Mime::XML);
+ $response = new Response('Nathan',
+"HTTP/1.1 200 OK
+Connection: keep-alive
+Transfer-Encoding: chunked\r\n", $request);
+
+ $this->assertEquals("", $response->content_type);
+ }
+
+ function testCustomMimeRegistering()
+ {
+ // Register new mime type handler for "application/vnd.nategood.message+xml"
+ Httpful::register(self::SAMPLE_VENDOR_TYPE, new DemoMimeHandler());
+
+ $this->assertTrue(Httpful::hasParserRegistered(self::SAMPLE_VENDOR_TYPE));
+
+ $request = Request::init();
+ $response = new Response('Nathan', self::SAMPLE_VENDOR_HEADER, $request);
+
+ $this->assertEquals(self::SAMPLE_VENDOR_TYPE, $response->content_type);
+ $this->assertEquals('custom parse', $response->body);
+ }
+
+ public function testShorthandMimeDefinition()
+ {
+ $r = Request::init()->expects('json');
+ $this->assertEquals(Mime::JSON, $r->expected_type);
+
+ $r = Request::init()->expectsJson();
+ $this->assertEquals(Mime::JSON, $r->expected_type);
+ }
+
+ public function testOverrideXmlHandler()
+ {
+ // Lazy test...
+ $prev = \Httpful\Httpful::get(\Httpful\Mime::XML);
+ $this->assertEquals($prev, new \Httpful\Handlers\XmlHandler());
+ $conf = array('namespace' => 'http://example.com');
+ \Httpful\Httpful::register(\Httpful\Mime::XML, new \Httpful\Handlers\XmlHandler($conf));
+ $new = \Httpful\Httpful::get(\Httpful\Mime::XML);
+ $this->assertNotEquals($prev, $new);
+ }
+}
+
+class DemoMimeHandler extends \Httpful\Handlers\MimeHandlerAdapter {
+ public function parse($body) {
+ return 'custom parse';
+ }
+}
+
diff --git a/app/Library/Poniverse/httpful/tests/phpunit.xml b/app/Library/Poniverse/httpful/tests/phpunit.xml
new file mode 100644
index 00000000..8f62e80a
--- /dev/null
+++ b/app/Library/Poniverse/httpful/tests/phpunit.xml
@@ -0,0 +1,9 @@
+
+
+ .
+
+
+
+
+
+
diff --git a/app/Library/Poniverse/oauth2/Client.php b/app/Library/Poniverse/oauth2/Client.php
new file mode 100644
index 00000000..698739fc
--- /dev/null
+++ b/app/Library/Poniverse/oauth2/Client.php
@@ -0,0 +1,515 @@
+
+ * @author Anis Berejeb
+ * @version 1.2-dev
+ */
+namespace OAuth2;
+
+class Client
+{
+ /**
+ * Different AUTH method
+ */
+ const AUTH_TYPE_URI = 0;
+ const AUTH_TYPE_AUTHORIZATION_BASIC = 1;
+ const AUTH_TYPE_FORM = 2;
+
+ /**
+ * Different Access token type
+ */
+ const ACCESS_TOKEN_URI = 0;
+ const ACCESS_TOKEN_BEARER = 1;
+ const ACCESS_TOKEN_OAUTH = 2;
+ const ACCESS_TOKEN_MAC = 3;
+
+ /**
+ * Different Grant types
+ */
+ const GRANT_TYPE_AUTH_CODE = 'authorization_code';
+ const GRANT_TYPE_PASSWORD = 'password';
+ const GRANT_TYPE_CLIENT_CREDENTIALS = 'client_credentials';
+ const GRANT_TYPE_REFRESH_TOKEN = 'refresh_token';
+
+ /**
+ * HTTP Methods
+ */
+ const HTTP_METHOD_GET = 'GET';
+ const HTTP_METHOD_POST = 'POST';
+ const HTTP_METHOD_PUT = 'PUT';
+ const HTTP_METHOD_DELETE = 'DELETE';
+ const HTTP_METHOD_HEAD = 'HEAD';
+ const HTTP_METHOD_PATCH = 'PATCH';
+
+ /**
+ * HTTP Form content types
+ */
+ const HTTP_FORM_CONTENT_TYPE_APPLICATION = 0;
+ const HTTP_FORM_CONTENT_TYPE_MULTIPART = 1;
+
+ /**
+ * Client ID
+ *
+ * @var string
+ */
+ protected $client_id = null;
+
+ /**
+ * Client Secret
+ *
+ * @var string
+ */
+ protected $client_secret = null;
+
+ /**
+ * Client Authentication method
+ *
+ * @var int
+ */
+ protected $client_auth = self::AUTH_TYPE_URI;
+
+ /**
+ * Access Token
+ *
+ * @var string
+ */
+ protected $access_token = null;
+
+ /**
+ * Access Token Type
+ *
+ * @var int
+ */
+ protected $access_token_type = self::ACCESS_TOKEN_URI;
+
+ /**
+ * Access Token Secret
+ *
+ * @var string
+ */
+ protected $access_token_secret = null;
+
+ /**
+ * Access Token crypt algorithm
+ *
+ * @var string
+ */
+ protected $access_token_algorithm = null;
+
+ /**
+ * Access Token Parameter name
+ *
+ * @var string
+ */
+ protected $access_token_param_name = 'access_token';
+
+ /**
+ * The path to the certificate file to use for https connections
+ *
+ * @var string Defaults to .
+ */
+ protected $certificate_file = null;
+
+ /**
+ * cURL options
+ *
+ * @var array
+ */
+ protected $curl_options = array();
+
+ /**
+ * Construct
+ *
+ * @param string $client_id Client ID
+ * @param string $client_secret Client Secret
+ * @param int $client_auth (AUTH_TYPE_URI, AUTH_TYPE_AUTHORIZATION_BASIC, AUTH_TYPE_FORM)
+ * @param string $certificate_file Indicates if we want to use a certificate file to trust the server. Optional, defaults to null.
+ * @return void
+ */
+ public function __construct($client_id, $client_secret, $client_auth = self::AUTH_TYPE_URI, $certificate_file = null)
+ {
+ if (!extension_loaded('curl')) {
+ throw new Exception('The PHP exention curl must be installed to use this library.', Exception::CURL_NOT_FOUND);
+ }
+
+ $this->client_id = $client_id;
+ $this->client_secret = $client_secret;
+ $this->client_auth = $client_auth;
+ $this->certificate_file = $certificate_file;
+ if (!empty($this->certificate_file) && !is_file($this->certificate_file)) {
+ throw new InvalidArgumentException('The certificate file was not found', InvalidArgumentException::CERTIFICATE_NOT_FOUND);
+ }
+ }
+
+ /**
+ * Get the client Id
+ *
+ * @return string Client ID
+ */
+ public function getClientId()
+ {
+ return $this->client_id;
+ }
+
+ /**
+ * Get the client Secret
+ *
+ * @return string Client Secret
+ */
+ public function getClientSecret()
+ {
+ return $this->client_secret;
+ }
+
+ /**
+ * getAuthenticationUrl
+ *
+ * @param string $auth_endpoint Url of the authentication endpoint
+ * @param string $redirect_uri Redirection URI
+ * @param array $extra_parameters Array of extra parameters like scope or state (Ex: array('scope' => null, 'state' => ''))
+ * @return string URL used for authentication
+ */
+ public function getAuthenticationUrl($auth_endpoint, $redirect_uri, array $extra_parameters = array())
+ {
+ $parameters = array_merge(array(
+ 'response_type' => 'code',
+ 'client_id' => $this->client_id,
+ 'redirect_uri' => $redirect_uri
+ ), $extra_parameters);
+ return $auth_endpoint . '?' . http_build_query($parameters, null, '&');
+ }
+
+ /**
+ * getAccessToken
+ *
+ * @param string $token_endpoint Url of the token endpoint
+ * @param int $grant_type Grant Type ('authorization_code', 'password', 'client_credentials', 'refresh_token', or a custom code (@see GrantType Classes)
+ * @param array $parameters Array sent to the server (depend on which grant type you're using)
+ * @return array Array of parameters required by the grant_type (CF SPEC)
+ */
+ public function getAccessToken($token_endpoint, $grant_type, array $parameters)
+ {
+ if (!$grant_type) {
+ throw new InvalidArgumentException('The grant_type is mandatory.', InvalidArgumentException::INVALID_GRANT_TYPE);
+ }
+ $grantTypeClassName = $this->convertToCamelCase($grant_type);
+ $grantTypeClass = __NAMESPACE__ . '\\GrantType\\' . $grantTypeClassName;
+ if (!class_exists($grantTypeClass)) {
+ throw new InvalidArgumentException('Unknown grant type \'' . $grant_type . '\'', InvalidArgumentException::INVALID_GRANT_TYPE);
+ }
+ $grantTypeObject = new $grantTypeClass();
+ $grantTypeObject->validateParameters($parameters);
+ if (!defined($grantTypeClass . '::GRANT_TYPE')) {
+ throw new Exception('Unknown constant GRANT_TYPE for class ' . $grantTypeClassName, Exception::GRANT_TYPE_ERROR);
+ }
+ $parameters['grant_type'] = $grantTypeClass::GRANT_TYPE;
+ $http_headers = array();
+ switch ($this->client_auth) {
+ case self::AUTH_TYPE_URI:
+ case self::AUTH_TYPE_FORM:
+ $parameters['client_id'] = $this->client_id;
+ $parameters['client_secret'] = $this->client_secret;
+ break;
+ case self::AUTH_TYPE_AUTHORIZATION_BASIC:
+ $parameters['client_id'] = $this->client_id;
+ $http_headers['Authorization'] = 'Basic ' . base64_encode($this->client_id . ':' . $this->client_secret);
+ break;
+ default:
+ throw new Exception('Unknown client auth type.', Exception::INVALID_CLIENT_AUTHENTICATION_TYPE);
+ break;
+ }
+
+ return $this->executeRequest($token_endpoint, $parameters, self::HTTP_METHOD_POST, $http_headers, self::HTTP_FORM_CONTENT_TYPE_APPLICATION);
+ }
+
+ /**
+ * setToken
+ *
+ * @param string $token Set the access token
+ * @return void
+ */
+ public function setAccessToken($token)
+ {
+ $this->access_token = $token;
+ }
+
+ /**
+ * Set the client authentication type
+ *
+ * @param string $client_auth (AUTH_TYPE_URI, AUTH_TYPE_AUTHORIZATION_BASIC, AUTH_TYPE_FORM)
+ * @return void
+ */
+ public function setClientAuthType($client_auth)
+ {
+ $this->client_auth = $client_auth;
+ }
+
+ /**
+ * Set an option for the curl transfer
+ *
+ * @param int $option The CURLOPT_XXX option to set
+ * @param mixed $value The value to be set on option
+ * @return void
+ */
+ public function setCurlOption($option, $value)
+ {
+ $this->curl_options[$option] = $value;
+ }
+
+ /**
+ * Set multiple options for a cURL transfer
+ *
+ * @param array $options An array specifying which options to set and their values
+ * @return void
+ */
+ public function setCurlOptions($options)
+ {
+ $this->curl_options = array_merge($this->curl_options, $options);
+ }
+
+ /**
+ * Set the access token type
+ *
+ * @param int $type Access token type (ACCESS_TOKEN_BEARER, ACCESS_TOKEN_MAC, ACCESS_TOKEN_URI)
+ * @param string $secret The secret key used to encrypt the MAC header
+ * @param string $algorithm Algorithm used to encrypt the signature
+ * @return void
+ */
+ public function setAccessTokenType($type, $secret = null, $algorithm = null)
+ {
+ $this->access_token_type = $type;
+ $this->access_token_secret = $secret;
+ $this->access_token_algorithm = $algorithm;
+ }
+
+ /**
+ * Fetch a protected ressource
+ *
+ * @param string $protected_ressource_url Protected resource URL
+ * @param array $parameters Array of parameters
+ * @param string $http_method HTTP Method to use (POST, PUT, GET, HEAD, DELETE)
+ * @param array $http_headers HTTP headers
+ * @param int $form_content_type HTTP form content type to use
+ * @return array
+ */
+ public function fetch($protected_resource_url, $parameters = array(), $http_method = self::HTTP_METHOD_GET, array $http_headers = array(), $form_content_type = self::HTTP_FORM_CONTENT_TYPE_MULTIPART)
+ {
+ if ($this->access_token) {
+ switch ($this->access_token_type) {
+ case self::ACCESS_TOKEN_URI:
+ if (is_array($parameters)) {
+ $parameters[$this->access_token_param_name] = $this->access_token;
+ } else {
+ throw new InvalidArgumentException(
+ 'You need to give parameters as array if you want to give the token within the URI.',
+ InvalidArgumentException::REQUIRE_PARAMS_AS_ARRAY
+ );
+ }
+ break;
+ case self::ACCESS_TOKEN_BEARER:
+ $http_headers['Authorization'] = 'Bearer ' . $this->access_token;
+ break;
+ case self::ACCESS_TOKEN_OAUTH:
+ $http_headers['Authorization'] = 'OAuth ' . $this->access_token;
+ break;
+ case self::ACCESS_TOKEN_MAC:
+ $http_headers['Authorization'] = 'MAC ' . $this->generateMACSignature($protected_resource_url, $parameters, $http_method);
+ break;
+ default:
+ throw new Exception('Unknown access token type.', Exception::INVALID_ACCESS_TOKEN_TYPE);
+ break;
+ }
+ }
+ return $this->executeRequest($protected_resource_url, $parameters, $http_method, $http_headers, $form_content_type);
+ }
+
+ /**
+ * Generate the MAC signature
+ *
+ * @param string $url Called URL
+ * @param array $parameters Parameters
+ * @param string $http_method Http Method
+ * @return string
+ */
+ private function generateMACSignature($url, $parameters, $http_method)
+ {
+ $timestamp = time();
+ $nonce = uniqid();
+ $parsed_url = parse_url($url);
+ if (!isset($parsed_url['port']))
+ {
+ $parsed_url['port'] = ($parsed_url['scheme'] == 'https') ? 443 : 80;
+ }
+ if ($http_method == self::HTTP_METHOD_GET) {
+ if (is_array($parameters)) {
+ $parsed_url['path'] .= '?' . http_build_query($parameters, null, '&');
+ } elseif ($parameters) {
+ $parsed_url['path'] .= '?' . $parameters;
+ }
+ }
+
+ $signature = base64_encode(hash_hmac($this->access_token_algorithm,
+ $timestamp . "\n"
+ . $nonce . "\n"
+ . $http_method . "\n"
+ . $parsed_url['path'] . "\n"
+ . $parsed_url['host'] . "\n"
+ . $parsed_url['port'] . "\n\n"
+ , $this->access_token_secret, true));
+
+ return 'id="' . $this->access_token . '", ts="' . $timestamp . '", nonce="' . $nonce . '", mac="' . $signature . '"';
+ }
+
+ /**
+ * Execute a request (with curl)
+ *
+ * @param string $url URL
+ * @param mixed $parameters Array of parameters
+ * @param string $http_method HTTP Method
+ * @param array $http_headers HTTP Headers
+ * @param int $form_content_type HTTP form content type to use
+ * @return array
+ */
+ private function executeRequest($url, $parameters = array(), $http_method = self::HTTP_METHOD_GET, array $http_headers = null, $form_content_type = self::HTTP_FORM_CONTENT_TYPE_MULTIPART)
+ {
+ $curl_options = array(
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_SSL_VERIFYPEER => true,
+ CURLOPT_CUSTOMREQUEST => $http_method
+ );
+
+ switch($http_method) {
+ case self::HTTP_METHOD_POST:
+ $curl_options[CURLOPT_POST] = true;
+ /* No break */
+ case self::HTTP_METHOD_PUT:
+ case self::HTTP_METHOD_PATCH:
+
+ /**
+ * Passing an array to CURLOPT_POSTFIELDS will encode the data as multipart/form-data,
+ * while passing a URL-encoded string will encode the data as application/x-www-form-urlencoded.
+ * http://php.net/manual/en/function.curl-setopt.php
+ */
+ if(is_array($parameters) && self::HTTP_FORM_CONTENT_TYPE_APPLICATION === $form_content_type) {
+ $parameters = http_build_query($parameters, null, '&');
+ }
+ $curl_options[CURLOPT_POSTFIELDS] = $parameters;
+ break;
+ case self::HTTP_METHOD_HEAD:
+ $curl_options[CURLOPT_NOBODY] = true;
+ /* No break */
+ case self::HTTP_METHOD_DELETE:
+ case self::HTTP_METHOD_GET:
+ if (is_array($parameters)) {
+ $url .= '?' . http_build_query($parameters, null, '&');
+ } elseif ($parameters) {
+ $url .= '?' . $parameters;
+ }
+ break;
+ default:
+ break;
+ }
+
+ $curl_options[CURLOPT_URL] = $url;
+
+ if (is_array($http_headers)) {
+ $header = array();
+ foreach($http_headers as $key => $parsed_urlvalue) {
+ $header[] = "$key: $parsed_urlvalue";
+ }
+ $curl_options[CURLOPT_HTTPHEADER] = $header;
+ }
+
+ $ch = curl_init();
+ curl_setopt_array($ch, $curl_options);
+ // https handling
+ if (!empty($this->certificate_file)) {
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
+ curl_setopt($ch, CURLOPT_CAINFO, $this->certificate_file);
+ } else {
+ // bypass ssl verification
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
+ }
+ if (!empty($this->curl_options)) {
+ curl_setopt_array($ch, $this->curl_options);
+ }
+ $result = curl_exec($ch);
+ $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
+ if ($curl_error = curl_error($ch)) {
+ throw new Exception($curl_error, Exception::CURL_ERROR);
+ } else {
+ $json_decode = json_decode($result, true);
+ }
+ curl_close($ch);
+
+ return array(
+ 'result' => (null === $json_decode) ? $result : $json_decode,
+ 'code' => $http_code,
+ 'content_type' => $content_type
+ );
+ }
+
+ /**
+ * Set the name of the parameter that carry the access token
+ *
+ * @param string $name Token parameter name
+ * @return void
+ */
+ public function setAccessTokenParamName($name)
+ {
+ $this->access_token_param_name = $name;
+ }
+
+ /**
+ * Converts the class name to camel case
+ *
+ * @param mixed $grant_type the grant type
+ * @return string
+ */
+ private function convertToCamelCase($grant_type)
+ {
+ $parts = explode('_', $grant_type);
+ array_walk($parts, function(&$item) { $item = ucfirst($item);});
+ return implode('', $parts);
+ }
+}
+
+class Exception extends \Exception
+{
+ const CURL_NOT_FOUND = 0x01;
+ const CURL_ERROR = 0x02;
+ const GRANT_TYPE_ERROR = 0x03;
+ const INVALID_CLIENT_AUTHENTICATION_TYPE = 0x04;
+ const INVALID_ACCESS_TOKEN_TYPE = 0x05;
+}
+
+class InvalidArgumentException extends \InvalidArgumentException
+{
+ const INVALID_GRANT_TYPE = 0x01;
+ const CERTIFICATE_NOT_FOUND = 0x02;
+ const REQUIRE_PARAMS_AS_ARRAY = 0x03;
+ const MISSING_PARAMETER = 0x04;
+}
diff --git a/app/Library/Poniverse/oauth2/GrantType/AuthorizationCode.php b/app/Library/Poniverse/oauth2/GrantType/AuthorizationCode.php
new file mode 100644
index 00000000..f3436e4c
--- /dev/null
+++ b/app/Library/Poniverse/oauth2/GrantType/AuthorizationCode.php
@@ -0,0 +1,41 @@
+getAuthenticationUrl(AUTHORIZATION_ENDPOINT, REDIRECT_URI);
+ header('Location: ' . $auth_url);
+ die('Redirect');
+}
+else
+{
+ $params = array('code' => $_GET['code'], 'redirect_uri' => REDIRECT_URI);
+ $response = $client->getAccessToken(TOKEN_ENDPOINT, 'authorization_code', $params);
+ parse_str($response['result'], $info);
+ $client->setAccessToken($info['access_token']);
+ $response = $client->fetch('https://graph.facebook.com/me');
+ var_dump($response, $response['result']);
+}
+
+How can I add a new Grant Type ?
+================================
+Simply write a new class in the namespace OAuth2\GrantType. You can place the class file under GrantType.
+Here is an example :
+
+namespace OAuth2\GrantType;
+
+/**
+ * MyCustomGrantType Grant Type
+ */
+class MyCustomGrantType implements IGrantType
+{
+ /**
+ * Defines the Grant Type
+ *
+ * @var string Defaults to 'my_custom_grant_type'.
+ */
+ const GRANT_TYPE = 'my_custom_grant_type';
+
+ /**
+ * Adds a specific Handling of the parameters
+ *
+ * @return array of Specific parameters to be sent.
+ * @param mixed $parameters the parameters array (passed by reference)
+ */
+ public function validateParameters(&$parameters)
+ {
+ if (!isset($parameters['first_mandatory_parameter']))
+ {
+ throw new \Exception('The \'first_mandatory_parameter\' parameter must be defined for the Password grant type');
+ }
+ elseif (!isset($parameters['second_mandatory_parameter']))
+ {
+ throw new \Exception('The \'seconde_mandatory_parameter\' parameter must be defined for the Password grant type');
+ }
+ }
+}
+
+call the OAuth client getAccessToken with the grantType you defined in the GRANT_TYPE constant, As following :
+$response = $client->getAccessToken(TOKEN_ENDPOINT, 'my_custom_grant_type', $params);
+
diff --git a/app/Library/Poniverse/oauth2/composer.json b/app/Library/Poniverse/oauth2/composer.json
new file mode 100644
index 00000000..2e052a52
--- /dev/null
+++ b/app/Library/Poniverse/oauth2/composer.json
@@ -0,0 +1,19 @@
+{
+ "name": "adoy/oauth2",
+ "description": "Light PHP wrapper for the OAuth 2.0 protocol (based on OAuth 2.0 Authorization Protocol draft-ietf-oauth-v2-15)",
+ "authors": [
+ {
+ "name": "Charron Pierrick",
+ "email": "pierrick@webstart.fr"
+ },
+ {
+ "name": "Berejeb Anis",
+ "email": "anis.berejeb@gmail.com"
+ }
+ ],
+ "autoload": {
+ "classmap": [
+ "../"
+ ]
+ }
+}
diff --git a/app/Library/ZipStream.php b/app/Library/ZipStream.php
new file mode 100644
index 00000000..e627efb8
--- /dev/null
+++ b/app/Library/ZipStream.php
@@ -0,0 +1,573 @@
+
+ * @copyright 2009-2013 A. Grandt
+ * @license GNU LGPL, Attribution required for commercial implementations, requested for everything else.
+ * @link http://www.phpclasses.org/package/6116
+ * @link https://github.com/Grandt/PHPZip
+ * @version 1.37
+ */
+class ZipStream {
+ const VERSION = 1.37;
+
+ const ZIP_LOCAL_FILE_HEADER = "\x50\x4b\x03\x04"; // Local file header signature
+ const ZIP_CENTRAL_FILE_HEADER = "\x50\x4b\x01\x02"; // Central file header signature
+ const ZIP_END_OF_CENTRAL_DIRECTORY = "\x50\x4b\x05\x06\x00\x00\x00\x00"; //end of Central directory record
+
+ const EXT_FILE_ATTR_DIR = "\x10\x00\xFF\x41";
+ const EXT_FILE_ATTR_FILE = "\x00\x00\xFF\x81";
+
+ const ATTR_VERSION_TO_EXTRACT = "\x14\x00"; // Version needed to extract
+ const ATTR_MADE_BY_VERSION = "\x1E\x03"; // Made By Version
+
+ private $zipMemoryThreshold = 1048576; // Autocreate tempfile if the zip data exceeds 1048576 bytes (1 MB)
+
+ private $zipComment = null;
+ private $cdRec = array(); // central directory
+ private $offset = 0;
+ private $isFinalized = FALSE;
+ private $addExtraField = TRUE;
+
+ private $streamChunkSize = 16384; // 65536;
+ private $streamFilePath = null;
+ private $streamTimeStamp = null;
+ private $streamComment = null;
+ private $streamFile = null;
+ private $streamData = null;
+ private $streamFileLength = 0;
+
+ /**
+ * Constructor.
+ *
+ * @param String $archiveName Name to send to the HTTP client.
+ * @param String $contentType Content mime type. Optional, defaults to "application/zip".
+ */
+ function __construct($archiveName = "", $contentType = "application/zip") {
+ if (!function_exists('sys_get_temp_dir')) {
+ die ("ERROR: ZipStream " . self::VERSION . " requires PHP version 5.2.1 or above.");
+ }
+
+ $headerFile = null;
+ $headerLine = null;
+ if (!headers_sent($headerFile, $headerLine) or die("
Error: Unable to send file $archiveName. HTML Headers have already been sent from $headerFile in line $headerLine
")) {
+ if ((ob_get_contents() === FALSE || ob_get_contents() == '') or die("\n
Error: Unable to send file $archiveName.epub. Output buffer contains the following text (typically warnings or errors): " . ob_get_contents() . "
")) {
+ if (ini_get('zlib.output_compression')) {
+ ini_set('zlib.output_compression', 'Off');
+ }
+
+ header('Pragma: public');
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s T"));
+ header("Expires: 0");
+ header("Accept-Ranges: bytes");
+ //header("Connection: Keep-Alive");
+ header("Content-Type: " . $contentType);
+ header('Content-Disposition: attachment; filename="' . $archiveName . '";');
+ header("Content-Transfer-Encoding: binary");
+ flush();
+ }
+ }
+ }
+
+ function __destruct() {
+ $this->isFinalized = TRUE;
+ $this->cdRec = null;
+ exit;
+ }
+
+ /**
+ * Extra fields on the Zip directory records are Unix time codes needed for compatibility on the default Mac zip archive tool.
+ * These are enabled as default, as they do no harm elsewhere and only add 26 bytes per file added.
+ *
+ * @param bool $setExtraField TRUE (default) will enable adding of extra fields, anything else will disable it.
+ */
+ function setExtraField($setExtraField = TRUE) {
+ $this->addExtraField = ($setExtraField === TRUE);
+ }
+
+ /**
+ * Set Zip archive comment.
+ *
+ * @param string $newComment New comment. null to clear.
+ * @return bool $success
+ */
+ public function setComment($newComment = null) {
+ if ($this->isFinalized) {
+ return FALSE;
+ }
+ $this->zipComment = $newComment;
+
+ return TRUE;
+ }
+
+ /**
+ * Add an empty directory entry to the zip archive.
+ * Basically this is only used if an empty directory is added.
+ *
+ * @param string $directoryPath Directory Path and name to be added to the archive.
+ * @param int $timestamp (Optional) Timestamp for the added directory, if omitted or set to 0, the current time will be used.
+ * @param string $fileComment (Optional) Comment to be added to the archive for this directory. To use fileComment, timestamp must be given.
+ * @return bool $success
+ */
+ public function addDirectory($directoryPath, $timestamp = 0, $fileComment = null) {
+ if ($this->isFinalized) {
+ return FALSE;
+ }
+
+ $directoryPath = str_replace("\\", "/", $directoryPath);
+ $directoryPath = rtrim($directoryPath, "/");
+
+ if (strlen($directoryPath) > 0) {
+ $this->buildZipEntry($directoryPath.'/', $fileComment, "\x00\x00", "\x00\x00", $timestamp, "\x00\x00\x00\x00", 0, 0, self::EXT_FILE_ATTR_DIR);
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ /**
+ * Add a file to the archive at the specified location and file name.
+ *
+ * @param string $data File data.
+ * @param string $filePath Filepath and name to be used in the archive.
+ * @param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.
+ * @param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.
+ * @return bool $success
+ */
+ public function addFile($data, $filePath, $timestamp = 0, $fileComment = null) {
+ if ($this->isFinalized) {
+ return FALSE;
+ }
+
+ if (is_resource($data) && get_resource_type($data) == "stream") {
+ $this->addLargeFile($data, $filePath, $timestamp, $fileComment);
+ return FALSE;
+ }
+
+ $gzType = "\x08\x00"; // Compression type 8 = deflate
+ $gpFlags = "\x00\x00"; // General Purpose bit flags for compression type 8 it is: 0=Normal, 1=Maximum, 2=Fast, 3=super fast compression.
+ $dataLength = strlen($data);
+ $fileCRC32 = pack("V", crc32($data));
+
+ $gzData = gzcompress($data);
+ $gzData = substr(substr($gzData, 0, strlen($gzData) - 4), 2); // gzcompress adds a 2 byte header and 4 byte CRC we can't use.
+ // The 2 byte header does contain useful data, though in this case the 2 parameters we'd be interrested in will always be 8 for compression type, and 2 for General purpose flag.
+ $gzLength = strlen($gzData);
+
+ if ($gzLength >= $dataLength) {
+ $gzLength = $dataLength;
+ $gzData = $data;
+ $gzType = "\x00\x00"; // Compression type 0 = stored
+ $gpFlags = "\x00\x00"; // Compression type 0 = stored
+ }
+
+ $this->buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, self::EXT_FILE_ATTR_FILE);
+
+ print ($gzData);
+
+ return TRUE;
+ }
+
+ /**
+ * Add the content to a directory.
+ *
+ * @author Adam Schmalhofer
+ * @author A. Grandt
+ *
+ * @param String $realPath Path on the file system.
+ * @param String $zipPath Filepath and name to be used in the archive.
+ * @param bool $recursive Add content recursively, default is TRUE.
+ * @param bool $followSymlinks Follow and add symbolic links, if they are accessible, default is TRUE.
+ * @param array &$addedFiles Reference to the added files, this is used to prevent duplicates, efault is an empty array.
+ * If you start the function by parsing an array, the array will be populated with the realPath
+ * and zipPath kay/value pairs added to the archive by the function.
+ */
+ public function addDirectoryContent($realPath, $zipPath, $recursive = TRUE, $followSymlinks = TRUE, &$addedFiles = array()) {
+ if (file_exists($realPath) && !isset($addedFiles[realpath($realPath)])) {
+ if (is_dir($realPath)) {
+ $this->addDirectory($zipPath);
+ }
+
+ $addedFiles[realpath($realPath)] = $zipPath;
+
+ $iter = new DirectoryIterator($realPath);
+ foreach ($iter as $file) {
+ if ($file->isDot()) {
+ continue;
+ }
+ $newRealPath = $file->getPathname();
+ $newZipPath = self::pathJoin($zipPath, $file->getFilename());
+
+ if (file_exists($newRealPath) && ($followSymlinks === TRUE || !is_link($newRealPath))) {
+ if ($file->isFile()) {
+ $addedFiles[realpath($newRealPath)] = $newZipPath;
+ $this->addLargeFile($newRealPath, $newZipPath);
+ } else if ($recursive === TRUE) {
+ $this->addDirectoryContent($newRealPath, $newZipPath, $recursive);
+ } else {
+ $this->addDirectory($zipPath);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Add a file to the archive at the specified location and file name.
+ *
+ * @param string $dataFile File name/path.
+ * @param string $filePath Filepath and name to be used in the archive.
+ * @param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.
+ * @param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.
+ * @return bool $success
+ */
+ public function addLargeFile($dataFile, $filePath, $timestamp = 0, $fileComment = null) {
+ if ($this->isFinalized) {
+ return FALSE;
+ }
+
+ if (is_string($dataFile) && is_file($dataFile)) {
+ $this->processFile($dataFile, $filePath, $timestamp, $fileComment);
+ } else if (is_resource($dataFile) && get_resource_type($dataFile) == "stream") {
+ $fh = $dataFile;
+ $this->openStream($filePath, $timestamp, $fileComment);
+
+ while (!feof($fh)) {
+ $this->addStreamData(fread($fh, $this->streamChunkSize));
+ }
+ $this->closeStream($this->addExtraField);
+ }
+ return TRUE;
+ }
+
+ /**
+ * Create a stream to be used for large entries.
+ *
+ * @param string $filePath Filepath and name to be used in the archive.
+ * @param int $timestamp (Optional) Timestamp for the added file, if omitted or set to 0, the current time will be used.
+ * @param string $fileComment (Optional) Comment to be added to the archive for this file. To use fileComment, timestamp must be given.
+ * @return bool $success
+ */
+ public function openStream($filePath, $timestamp = 0, $fileComment = null) {
+ if (!function_exists('sys_get_temp_dir')) {
+ die ("ERROR: Zip " . self::VERSION . " requires PHP version 5.2.1 or above if large files are used.");
+ }
+
+ if ($this->isFinalized) {
+ return FALSE;
+ }
+
+ if (strlen($this->streamFilePath) > 0) {
+ closeStream();
+ }
+
+ $this->streamFile = tempnam(sys_get_temp_dir(), 'ZipStream');
+ $this->streamData = fopen($this->streamFile, "wb");
+ $this->streamFilePath = $filePath;
+ $this->streamTimestamp = $timestamp;
+ $this->streamFileComment = $fileComment;
+ $this->streamFileLength = 0;
+
+ return TRUE;
+ }
+
+ /**
+ * Add data to the open stream.
+ *
+ * @param String $data
+ * @return $length bytes added or FALSE if the archive is finalized or there are no open stream.
+ */
+ public function addStreamData($data) {
+ if ($this->isFinalized || strlen($this->streamFilePath) == 0) {
+ return FALSE;
+ }
+
+ $length = fwrite($this->streamData, $data, strlen($data));
+ if ($length != strlen($data)) {
+ die ("
Length mismatch
\n");
+ }
+ $this->streamFileLength += $length;
+
+ return $length;
+ }
+
+ /**
+ * Close the current stream.
+ *
+ * @return bool $success
+ */
+ public function closeStream() {
+ if ($this->isFinalized || strlen($this->streamFilePath) == 0) {
+ return FALSE;
+ }
+
+ fflush($this->streamData);
+ fclose($this->streamData);
+
+ $this->processFile($this->streamFile, $this->streamFilePath, $this->streamTimestamp, $this->streamFileComment);
+
+ $this->streamData = null;
+ $this->streamFilePath = null;
+ $this->streamTimestamp = null;
+ $this->streamFileComment = null;
+ $this->streamFileLength = 0;
+
+ // Windows is a little slow at times, so a millisecond later, we can unlink this.
+ unlink($this->streamFile);
+
+ $this->streamFile = null;
+
+ return TRUE;
+ }
+
+ private function processFile($dataFile, $filePath, $timestamp = 0, $fileComment = null) {
+ if ($this->isFinalized) {
+ return FALSE;
+ }
+
+ $tempzip = tempnam(sys_get_temp_dir(), 'ZipStream');
+
+ $zip = new ZipArchive;
+ if ($zip->open($tempzip) === TRUE) {
+ $zip->addFile($dataFile, 'file');
+ $zip->close();
+ }
+
+ $file_handle = fopen($tempzip, "rb");
+ $stats = fstat($file_handle);
+ $eof = $stats['size']-72;
+
+ fseek($file_handle, 6);
+
+ $gpFlags = fread($file_handle, 2);
+ $gzType = fread($file_handle, 2);
+ fread($file_handle, 4);
+ $fileCRC32 = fread($file_handle, 4);
+ $v = unpack("Vval", fread($file_handle, 4));
+ $gzLength = $v['val'];
+ $v = unpack("Vval", fread($file_handle, 4));
+ $dataLength = $v['val'];
+
+ $this->buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, self::EXT_FILE_ATTR_FILE);
+
+ fseek($file_handle, 34);
+ $pos = 34;
+
+ while (!feof($file_handle) && $pos < $eof) {
+ $datalen = $this->streamChunkSize;
+ if ($pos + $this->streamChunkSize > $eof) {
+ $datalen = $eof-$pos;
+ }
+ echo fread($file_handle, $datalen);
+ $pos += $datalen;
+ flush();
+ }
+
+ fclose($file_handle);
+ unlink($tempzip);
+ }
+
+ /**
+ * Close the archive.
+ * A closed archive can no longer have new files added to it.
+ * @return bool $success
+ */
+ public function finalize() {
+ if (!$this->isFinalized) {
+ if (strlen($this->streamFilePath) > 0) {
+ $this->closeStream();
+ }
+
+ $cdRecSize = pack("v", sizeof($this->cdRec));
+
+ $cd = implode("", $this->cdRec);
+ print($cd);
+ print(self::ZIP_END_OF_CENTRAL_DIRECTORY);
+ print($cdRecSize.$cdRecSize);
+ print(pack("VV", strlen($cd), $this->offset));
+ if (!empty($this->zipComment)) {
+ print(pack("v", strlen($this->zipComment)));
+ print($this->zipComment);
+ } else {
+ print("\x00\x00");
+ }
+
+ flush();
+
+ $this->isFinalized = TRUE;
+ $cd = null;
+ $this->cdRec = null;
+
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ /**
+ * Calculate the 2 byte dostime used in the zip entries.
+ *
+ * @param int $timestamp
+ * @return 2-byte encoded DOS Date
+ */
+ private function getDosTime($timestamp = 0) {
+ $timestamp = (int)$timestamp;
+ $oldTZ = @date_default_timezone_get();
+ date_default_timezone_set('UTC');
+ $date = ($timestamp == 0 ? getdate() : getdate($timestamp));
+ date_default_timezone_set($oldTZ);
+ if ($date["year"] >= 1980) {
+ return pack("V", (($date["mday"] + ($date["mon"] << 5) + (($date["year"]-1980) << 9)) << 16) |
+ (($date["seconds"] >> 1) + ($date["minutes"] << 5) + ($date["hours"] << 11)));
+ }
+ return "\x00\x00\x00\x00";
+ }
+
+ /**
+ * Build the Zip file structures
+ *
+ * @param String $filePath
+ * @param String $fileComment
+ * @param String $gpFlags
+ * @param String $gzType
+ * @param int $timestamp
+ * @param string $fileCRC32
+ * @param int $gzLength
+ * @param int $dataLength
+ * @param integer $extFileAttr Use self::EXT_FILE_ATTR_FILE for files, self::EXT_FILE_ATTR_DIR for Directories.
+ */
+ private function buildZipEntry($filePath, $fileComment, $gpFlags, $gzType, $timestamp, $fileCRC32, $gzLength, $dataLength, $extFileAttr) {
+ $filePath = str_replace("\\", "/", $filePath);
+ $fileCommentLength = (empty($fileComment) ? 0 : strlen($fileComment));
+ $timestamp = (int)$timestamp;
+ $timestamp = ($timestamp == 0 ? time() : $timestamp);
+
+ $dosTime = $this->getDosTime($timestamp);
+ $tsPack = pack("V", $timestamp);
+
+ $ux = "\x75\x78\x0B\x00\x01\x04\xE8\x03\x00\x00\x04\x00\x00\x00\x00";
+
+ if (!isset($gpFlags) || strlen($gpFlags) != 2) {
+ $gpFlags = "\x00\x00";
+ }
+
+ $isFileUTF8 = mb_check_encoding($filePath, "UTF-8") && !mb_check_encoding($filePath, "ASCII");
+ $isCommentUTF8 = !empty($fileComment) && mb_check_encoding($fileComment, "UTF-8") && !mb_check_encoding($fileComment, "ASCII");
+ if ($isFileUTF8 || $isCommentUTF8) {
+ $flag = 0;
+ $gpFlagsV = unpack("vflags", $gpFlags);
+ if (isset($gpFlagsV['flags'])) {
+ $flag = $gpFlagsV['flags'];
+ }
+ $gpFlags = pack("v", $flag | (1 << 11));
+ }
+
+ $header = $gpFlags . $gzType . $dosTime. $fileCRC32
+ . pack("VVv", $gzLength, $dataLength, strlen($filePath)); // File name length
+
+ $zipEntry = self::ZIP_LOCAL_FILE_HEADER;
+ $zipEntry .= self::ATTR_VERSION_TO_EXTRACT;
+ $zipEntry .= $header;
+ $zipEntry .= $this->addExtraField ? "\x1C\x00" : "\x00\x00"; // Extra field length
+ $zipEntry .= $filePath; // FileName
+ // Extra fields
+ if ($this->addExtraField) {
+ $zipEntry .= "\x55\x54\x09\x00\x03" . $tsPack . $tsPack . $ux;
+ }
+
+ print($zipEntry);
+
+ $cdEntry = self::ZIP_CENTRAL_FILE_HEADER;
+ $cdEntry .= self::ATTR_MADE_BY_VERSION;
+ $cdEntry .= ($dataLength === 0 ? "\x0A\x00" : self::ATTR_VERSION_TO_EXTRACT);
+ $cdEntry .= $header;
+ $cdEntry .= $this->addExtraField ? "\x18\x00" : "\x00\x00"; // Extra field length
+ $cdEntry .= pack("v", $fileCommentLength); // File comment length
+ $cdEntry .= "\x00\x00"; // Disk number start
+ $cdEntry .= "\x00\x00"; // internal file attributes
+ $cdEntry .= $extFileAttr; // External file attributes
+ $cdEntry .= pack("V", $this->offset); // Relative offset of local header
+ $cdEntry .= $filePath; // FileName
+ // Extra fields
+ if ($this->addExtraField) {
+ $cdEntry .= "\x55\x54\x05\x00\x03" . $tsPack . $ux;
+ }
+
+ if (!empty($fileComment)) {
+ $cdEntry .= $fileComment; // Comment
+ }
+
+ $this->cdRec[] = $cdEntry;
+ $this->offset += strlen($zipEntry) + $gzLength;
+ }
+
+ /**
+ * Join $file to $dir path, and clean up any excess slashes.
+ *
+ * @param String $dir
+ * @param String $file
+ */
+ public static function pathJoin($dir, $file) {
+ if (empty($dir) || empty($file)) {
+ return self::getRelativePath($dir . $file);
+ }
+ return self::getRelativePath($dir . '/' . $file);
+ }
+
+ /**
+ * Clean up a path, removing any unnecessary elements such as /./, // or redundant ../ segments.
+ * If the path starts with a "/", it is deemed an absolute path and any /../ in the beginning is stripped off.
+ * The returned path will not end in a "/".
+ *
+ * @param String $path The path to clean up
+ * @return String the clean path
+ */
+ public static function getRelativePath($path) {
+ $path = preg_replace("#/+\.?/+#", "/", str_replace("\\", "/", $path));
+ $dirs = explode("/", rtrim(preg_replace('#^(?:\./)+#', '', $path), '/'));
+
+ $offset = 0;
+ $sub = 0;
+ $subOffset = 0;
+ $root = "";
+
+ if (empty($dirs[0])) {
+ $root = "/";
+ $dirs = array_splice($dirs, 1);
+ } else if (preg_match("#[A-Za-z]:#", $dirs[0])) {
+ $root = strtoupper($dirs[0]) . "/";
+ $dirs = array_splice($dirs, 1);
+ }
+
+ $newDirs = array();
+ foreach ($dirs as $dir) {
+ if ($dir !== "..") {
+ $subOffset--;
+ $newDirs[++$offset] = $dir;
+ } else {
+ $subOffset++;
+ if (--$offset < 0) {
+ $offset = 0;
+ if ($subOffset > $sub) {
+ $sub++;
+ }
+ }
+ }
+ }
+
+ if (empty($root)) {
+ $root = str_repeat("../", $sub);
+ }
+ return $root . implode("/", array_slice($newDirs, 0, $offset));
+ }
+}
+?>
\ No newline at end of file
diff --git a/app/Library/getid3/extension.cache.dbm.php b/app/Library/getid3/extension.cache.dbm.php
new file mode 100644
index 00000000..9a88c22b
--- /dev/null
+++ b/app/Library/getid3/extension.cache.dbm.php
@@ -0,0 +1,211 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// //
+// extension.cache.dbm.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:
+*
+* 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.dbm.php';
+* $getID3 = new getID3_cached('db3', '/tmp/getid3_cache.dbm',
+* '/tmp/getid3_cache.lock');
+* $getID3->encoding = 'UTF-8';
+* $info1 = $getID3->analyze('file1.flac');
+* $info2 = $getID3->analyze('file2.wv');
+*
+*
+* Supported Cache Types
+*
+* SQL Databases: (use extension.cache.mysql)
+*
+* cache_type cache_options
+* -------------------------------------------------------------------
+* mysql host, database, username, password
+*
+*
+* DBM-Style Databases: (this extension)
+*
+* 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_dbm extends getID3
+{
+
+ // public: constructor - see top of this file for cache type and cache_options
+ function getID3_cached_dbm($cache_type, $dbm_filename, $lock_filename) {
+
+ // Check for dba extension
+ if (!extension_loaded('dba')) {
+ throw new Exception('PHP is not compiled with dba support, required to use DBM style cache.');
+ }
+
+ // Check for specific dba driver
+ if (!function_exists('dba_handlers') || !in_array($cache_type, dba_handlers())) {
+ throw new Exception('PHP is not compiled --with '.$cache_type.' support, required to use DBM style cache.');
+ }
+
+ // Create lock file if needed
+ if (!file_exists($lock_filename)) {
+ if (!touch($lock_filename)) {
+ throw new Exception('failed to create lock file: '.$lock_filename);
+ }
+ }
+
+ // Open lock file for writing
+ if (!is_writeable($lock_filename)) {
+ throw new Exception('lock file: '.$lock_filename.' is not writable');
+ }
+ $this->lock = fopen($lock_filename, 'w');
+
+ // Acquire exclusive write lock to lock file
+ flock($this->lock, LOCK_EX);
+
+ // Create dbm-file if needed
+ if (!file_exists($dbm_filename)) {
+ if (!touch($dbm_filename)) {
+ throw new Exception('failed to create dbm file: '.$dbm_filename);
+ }
+ }
+
+ // Try to open dbm file for writing
+ $this->dba = dba_open($dbm_filename, 'w', $cache_type);
+ if (!$this->dba) {
+
+ // Failed - create new dbm file
+ $this->dba = dba_open($dbm_filename, 'n', $cache_type);
+
+ if (!$this->dba) {
+ throw new Exception('failed to create dbm file: '.$dbm_filename);
+ }
+
+ // Insert getID3 version number
+ dba_insert(getID3::VERSION, getID3::VERSION, $this->dba);
+ }
+
+ // Init misc values
+ $this->cache_type = $cache_type;
+ $this->dbm_filename = $dbm_filename;
+
+ // Register destructor
+ register_shutdown_function(array($this, '__destruct'));
+
+ // Check version number and clear cache if changed
+ if (dba_fetch(getID3::VERSION, $this->dba) != getID3::VERSION) {
+ $this->clear_cache();
+ }
+
+ parent::getID3();
+ }
+
+
+
+ // public: destuctor
+ function __destruct() {
+
+ // Close dbm file
+ dba_close($this->dba);
+
+ // Release exclusive lock
+ flock($this->lock, LOCK_UN);
+
+ // Close lock file
+ fclose($this->lock);
+ }
+
+
+
+ // public: clear cache
+ function clear_cache() {
+
+ // Close dbm file
+ dba_close($this->dba);
+
+ // Create new dbm file
+ $this->dba = dba_open($this->dbm_filename, 'n', $this->cache_type);
+
+ if (!$this->dba) {
+ throw new Exception('failed to clear cache/recreate dbm file: '.$this->dbm_filename);
+ }
+
+ // Insert getID3 version number
+ dba_insert(getID3::VERSION, getID3::VERSION, $this->dba);
+
+ // Re-register shutdown function
+ register_shutdown_function(array($this, '__destruct'));
+ }
+
+
+
+ // public: analyze file
+ function analyze($filename) {
+
+ if (file_exists($filename)) {
+
+ // Calc key filename::mod_time::size - should be unique
+ $key = $filename.'::'.filemtime($filename).'::'.filesize($filename);
+
+ // Loopup key
+ $result = dba_fetch($key, $this->dba);
+
+ // Hit
+ if ($result !== false) {
+ return unserialize($result);
+ }
+ }
+
+ // Miss
+ $result = parent::analyze($filename);
+
+ // Save result
+ if (file_exists($filename)) {
+ dba_insert($key, serialize($result), $this->dba);
+ }
+
+ return $result;
+ }
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/app/Library/getid3/extension.cache.mysql.php b/app/Library/getid3/extension.cache.mysql.php
new file mode 100644
index 00000000..1e1f91fa
--- /dev/null
+++ b/app/Library/getid3/extension.cache.mysql.php
@@ -0,0 +1,173 @@
+ //
+// 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 //
+// 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
+{
+
+ // 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, $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 = '';
+ if ($this->cursor = mysql_query("SELECT `value` FROM `".mysql_real_escape_string($this->table)."` 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 `".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);
+ }
+
+
+
+ // public: analyze file
+ function analyze($filename) {
+
+ if (file_exists($filename)) {
+
+ // Short-hands
+ $filetime = filemtime($filename);
+ $filesize = filesize($filename);
+
+ // Lookup file
+ $this->cursor = mysql_query("SELECT `value` FROM `".mysql_real_escape_string($this->table)."` WHERE (`filename` = '".mysql_real_escape_string($filename)."') AND (`filesize` = '".mysql_real_escape_string($filesize)."') AND (`filetime` = '".mysql_real_escape_string($filetime)."')", $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);
+
+ // Save result
+ if (file_exists($filename)) {
+ $this->cursor = mysql_query("INSERT INTO `".mysql_real_escape_string($this->table)."` (`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 $analysis;
+ }
+
+
+
+ // private: (re)create sql table
+ function create_table($drop=false) {
+
+ $this->cursor = mysql_query("CREATE TABLE IF NOT EXISTS `".mysql_real_escape_string($this->table)."` (
+ `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/app/Library/getid3/getid3.lib.php b/app/Library/getid3/getid3.lib.php
new file mode 100644
index 00000000..e736688e
--- /dev/null
+++ b/app/Library/getid3/getid3.lib.php
@@ -0,0 +1,1316 @@
+ //
+// 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, $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;
+ }
+
+ 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); // 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 getid3_lib::BigEndian2Int()');
+ }
+ }
+ 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 ksort_recursive(&$theArray) {
+ ksort($theArray);
+ foreach ($theArray as $key => $value) {
+ if (is_array($value)) {
+ self::ksort_recursive($theArray[$key]);
+ }
+ }
+ return true;
+ }
+
+ 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($seconds) {
+ $sign = (($seconds < 0) ? '-' : '');
+ $seconds = abs($seconds);
+ $H = floor( $seconds / 3600);
+ $M = floor(($seconds - (3600 * $H) ) / 60);
+ $S = 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);
+ }
+
+
+ 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);
+ }
+
+ static function XML2array($XMLstring) {
+ if (function_exists('simplexml_load_string')) {
+ if (function_exists('get_object_vars')) {
+ $XMLobject = simplexml_load_string($XMLstring);
+ return self::SimpleXMLelement2array($XMLobject);
+ }
+ }
+ return false;
+ }
+
+ static function SimpleXMLelement2array($XMLobject) {
+ if (!is_object($XMLobject) && !is_array($XMLobject)) {
+ return $XMLobject;
+ }
+ $XMLarray = (is_object($XMLobject) ? get_object_vars($XMLobject) : $XMLobject);
+ foreach ($XMLarray as $key => $value) {
+ $XMLarray[$key] = self::SimpleXMLelement2array($value);
+ }
+ return $XMLarray;
+ }
+
+
+ // 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) {
+ static $tempdir = '';
+ 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'))) {
+ //throw new Exception('PHP running in Safe Mode - backtick operator not available, using slower non-system-call '.$algorithm.' algorithm');
+ break;
+ }
+ return substr(`$commandline`, 0, $hash_length);
+ }
+
+ if (empty($tempdir)) {
+ // yes this is ugly, feel free to suggest a better way
+ require_once(dirname(__FILE__).'/getid3.php');
+ $getid3_temp = new getID3();
+ $tempdir = $getid3_temp->tempdir;
+ unset($getid3_temp);
+ }
+ // try to create a temporary file in the system temp directory - invalid dirname should force to system temp dir
+ if (($data_filename = tempnam($tempdir, 'gI3')) === false) {
+ // can't find anywhere to create a temp file, just fail
+ return false;
+ }
+
+ // Init
+ $result = false;
+
+ // copy parts of file
+ try {
+ getid3_lib::CopyFileParts($file, $data_filename, $offset, $end - $offset);
+ $result = $hash_function($data_filename);
+ } catch (Exception $e) {
+ throw new Exception('getid3_lib::CopyFileParts() failed in getid_lib::hash_data(): '.$e->getMessage());
+ }
+ unlink($data_filename);
+ return $result;
+ }
+
+ static function CopyFileParts($filename_source, $filename_dest, $offset, $length) {
+ if (!getid3_lib::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, SEEK_SET) == 0) {
+ $byteslefttowrite = $length;
+ while (($byteslefttowrite > 0) && ($buffer = fread($fp_src, min($byteslefttowrite, getID3::FREAD_BUFFER_SIZE)))) {
+ $byteswritten = fwrite($fp_dest, $buffer, $byteslefttowrite);
+ $byteslefttowrite -= $byteswritten;
+ }
+ return true;
+ } else {
+ throw new Exception('failed to seek to offset '.$offset.' in '.$filename_source);
+ }
+ fclose($fp_dest);
+ } else {
+ throw new Exception('failed to create file for writing '.$filename_dest);
+ }
+ fclose($fp_src);
+ } else {
+ throw new Exception('failed to open file for reading '.$filename_source);
+ }
+ return false;
+ }
+
+ 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')) {
+ 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;
+ }
+
+
+ // 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') {
+ $string = (string) $string; // in case trying to pass a numeric (float, int) string, would otherwise return an empty string
+ $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));
+ } 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) {
+ static $tempdir = '';
+ if (empty($tempdir)) {
+ // yes this is ugly, feel free to suggest a better way
+ require_once(dirname(__FILE__).'/getid3.php');
+ $getid3_temp = new getID3();
+ $tempdir = $getid3_temp->tempdir;
+ unset($getid3_temp);
+ }
+ $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);
+ }
+ 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) {
+ 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('', '', getid3_lib::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+
+ 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;
+ }
+
+ public static function trimNullByte($string) {
+ return trim($string, "\x00");
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/app/Library/getid3/getid3.php b/app/Library/getid3/getid3.php
new file mode 100644
index 00000000..e8a3f7e2
--- /dev/null
+++ b/app/Library/getid3/getid3.php
@@ -0,0 +1,1744 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// //
+// Please see readme.txt for more information //
+// ///
+/////////////////////////////////////////////////////////////////
+
+// 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
+ public $encoding = 'UTF-8'; // CASE SENSITIVE! - i.e. (must be supported by iconv()). Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE
+ public $encoding_id3v1 = 'ISO-8859-1'; // Should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'EUC-CN' or 'CP1252'
+
+ // public: Optional tag checks - disable for speed.
+ public $option_tag_id3v1 = true; // Read and process ID3v1 tags
+ public $option_tag_id3v2 = true; // Read and process ID3v2 tags
+ public $option_tag_lyrics3 = true; // Read and process Lyrics3 tags
+ public $option_tag_apetag = true; // Read and process APE tags
+ public $option_tags_process = true; // Copy tags to root key 'tags' and encode to $this->encoding
+ public $option_tags_html = true; // Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities
+
+ // public: Optional tag/comment calucations
+ public $option_extra_info = true; // Calculate additional info such as bitrate, channelmode etc
+
+ // public: Optional handling of embedded attachments (e.g. images)
+ public $option_save_attachments = true; // defaults to true (ATTACHMENTS_INLINE) for backward compatibility
+
+ // public: Optional calculations
+ public $option_md5_data = false; // Get MD5 sum of data part - slow
+ public $option_md5_data_source = false; // Use MD5 of source file if availble - only FLAC and OptimFROG
+ public $option_sha1_data = false; // Get SHA1 sum of data part - slow
+ public $option_max_2gb_check = null; // Check whether file is larger than 2GB and thus not supported by 32-bit PHP (null: auto-detect based on PHP_INT_MAX)
+
+ // public: Read buffer size in bytes
+ public $option_fread_buffer_size = 32768;
+
+ // Public variables
+ public $filename; // Filename of file being analysed.
+ public $fp; // Filepointer to file being analysed.
+ public $info; // Result array.
+
+ // Protected variables
+ protected $startup_error = '';
+ protected $startup_warning = '';
+ protected $memory_limit = 0;
+
+ const VERSION = '1.9.3-20111213';
+ const FREAD_BUFFER_SIZE = 32768;
+ var $tempdir = GETID3_TEMP_DIR;
+
+ const ATTACHMENTS_NONE = false;
+ const ATTACHMENTS_INLINE = true;
+
+ // public: constructor
+ public function __construct() {
+
+ // Check for PHP version
+ $required_php_version = '5.0.5';
+ 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;
+ return false;
+ }
+
+ // Check memory
+ $this->memory_limit = ini_get('memory_limit');
+ if (preg_match('#([0-9]+)M#i', $this->memory_limit, $matches)) {
+ // could be stored as "16M" rather than 16777216 for example
+ $this->memory_limit = $matches[1] * 1048576;
+ } elseif (preg_match('#([0-9]+)G#i', $this->memory_limit, $matches)) { // The 'G' modifier is available since PHP 5.1.0
+ // could be stored as "2G" rather than 2147483648 for example
+ $this->memory_limit = $matches[1] * 1073741824;
+ }
+ 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';
+ } 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';
+ }
+
+ // 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 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_warning .= '"'.$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_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.';
+ }
+ }
+ $path_so_far[] = $value;
+ }
+ $helperappsdir = implode(DIRECTORY_SEPARATOR, $path_so_far);
+ }
+ define('GETID3_HELPERAPPSDIR', $helperappsdir.DIRECTORY_SEPARATOR);
+ }
+
+ return true;
+ }
+
+ public function version() {
+ return self::VERSION;
+ }
+
+ public function fread_buffer_size() {
+ return $this->option_fread_buffer_size;
+ }
+
+
+ // public: setOption
+ 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;
+ }
+
+
+ public function openfile($filename) {
+ try {
+ if (!empty($this->startup_error)) {
+ throw new getid3_exception($this->startup_error);
+ }
+ if (!empty($this->startup_warning)) {
+ $this->warning($this->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;
+
+ // remote files not supported
+ if (preg_match('/^(ht|f)tp:\/\//', $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('#(.+)'.preg_quote(DIRECTORY_SEPARATOR).'{2,}#U', '\1'.DIRECTORY_SEPARATOR, $filename);
+
+ // open local file
+ if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
+ // great
+ } else {
+ throw new getid3_exception('Could not open "'.$filename.'" (does not exist, or is not a file)');
+ }
+
+ $this->info['filesize'] = filesize($filename);
+ // 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'];
+
+
+ // 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 = 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($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, 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
+
+ return true;
+
+ } catch (Exception $e) {
+ $this->error($e->getMessage());
+ }
+ return false;
+ }
+
+ // public: analyze file
+ function analyze($filename) {
+ try {
+ if (!$this->openfile($filename)) {
+ 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, SEEK_SET);
+ $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'], SEEK_SET);
+ $formattest = fread($this->fp, 32774);
+
+ // determine format
+ $determined_format = $this->GetFileFormat($formattest, $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 iconv support
+ // Check encoding/iconv support
+ if (!empty($determined_format['iconv_req']) && !function_exists('iconv') && !in_array($this->encoding, array('ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'))) {
+ $errormessage = '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 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);
+ }
+
+ // 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($this->fp, $this->info, $determined_format['option']);
+ //} else {
+ //$class = new $class_name($this->fp, $this->info);
+ $class = new $class_name($this);
+ //}
+
+ if (!empty($determined_format['set_inline_attachments'])) {
+ $class->inline_attachments = $this->option_save_attachments;
+ }
+ $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 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) {
+ $this->error('Caught exception: '.$e->getMessage());
+ }
+
+ // return info array
+ return $this->info;
+ }
+
+
+ // private: error handling
+ function error($message) {
+ $this->CleanUp();
+ if (!isset($this->info['error'])) {
+ $this->info['error'] = array();
+ }
+ $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']);
+ }
+ }
+
+ // 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
+ 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' => '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',
+ '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',
+ 'set_inline_attachments' => true,
+ ),
+
+ // 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
+ 'set_inline_attachments' => true,
+ ),
+
+ // 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',
+ 'set_inline_attachments' => true,
+ ),
+
+ // 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',
+ ),
+
+
+ // EFAX - still image - eFax (TIFF derivative)
+ 'bmp' => 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,
+ ),
+
+ // 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'),
+ 'matroska' => array('matroska' , 'UTF-8'),
+ );
+ }
+
+ // 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 ($value) {
+ $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value;
+ }
+ }
+ }
+
+ 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('', '', trim(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!
+ }
+
+ }
+
+ // 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;
+ }
+
+
+ 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->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 (!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']);
+ }
+ }
+
+
+ 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'])) {
+ if (!isset($this->info['replay_gain']['reference_volume'])) {
+ $this->info['replay_gain']['reference_volume'] = (double) 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;
+ }
+
+ 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');
+ }
+
+
+ public function saveAttachment(&$ThisFileInfoIndex, $filename, $offset, $length) {
+ try {
+ if (!getid3_lib::intValueSupported($offset + $length)) {
+ throw new Exception('cannot extract attachment, it extends beyond the '.round(PHP_INT_MAX / 1073741824).'GB limit');
+ }
+
+ // do not extract at all
+ if ($this->option_save_attachments === getID3::ATTACHMENTS_NONE) {
+
+ unset($ThisFileInfoIndex); // do not set any
+
+ // extract to return array
+ } elseif ($this->option_save_attachments === getID3::ATTACHMENTS_INLINE) {
+
+ // get whole data in one pass, till it is anyway stored in memory
+ $ThisFileInfoIndex = file_get_contents($this->info['filenamepath'], false, null, $offset, $length);
+ if (($ThisFileInfoIndex === false) || (strlen($ThisFileInfoIndex) != $length)) { // verify
+ throw new Exception('failed to read attachment data');
+ }
+
+ // assume directory path is given
+ } else {
+
+ $dir = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->option_save_attachments), DIRECTORY_SEPARATOR);
+ // check supplied directory
+ if (!is_dir($dir) || !is_writable($dir)) {
+ throw new Exception('getID3::saveAttachment() -- supplied path ('.$dir.') does not exist, or is not writable');
+ }
+
+ // set up destination path
+ $dest = $dir.DIRECTORY_SEPARATOR.$filename;
+
+ // optimize speed if read buffer size is configured to be large enough
+ // here stream_copy_to_stream() may also be used. need to do speed-compare tests
+ if ($length <= $this->fread_buffer_size()) {
+ $data = file_get_contents($this->info['filenamepath'], false, null, $offset, $length);
+ if (($data === false) || (strlen($data) != $length)) { // verify
+ throw new Exception('failed to read attachment data');
+ }
+ if (!file_put_contents($dest, $data)) {
+ throw new Exception('failed to create file '.$dest);
+ }
+ } else {
+ // optimization not available - copy data in loop
+ // here stream_copy_to_stream() shouldn't be used because it's internal read buffer may be larger than ours!
+ getid3_lib::CopyFileParts($this->info['filenamepath'], $dest, $offset, $length);
+ }
+ $ThisFileInfoIndex = $dest;
+ }
+
+ } catch (Exception $e) {
+
+ unset($ThisFileInfoIndex); // do not set any is case of error
+ $this->warning('Failed to extract attachment '.$filename.': '.$e->getMessage());
+ return false;
+
+ }
+ return true;
+ }
+
+
+ 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;
+ }
+
+}
+
+
+abstract class getid3_handler
+{
+ protected $getid3; // pointer
+
+ protected $data_string_flag = false; // analyzing filepointer or string
+ protected $data_string; // string to analyze
+ protected $data_string_position = 0; // seek position in string
+
+
+ public function __construct(getID3 $getid3) {
+ $this->getid3 = $getid3;
+ }
+
+
+ // Analyze from file pointer
+ abstract public function Analyze();
+
+
+ // Analyze from string instead
+ public function AnalyzeString(&$string) {
+ // Enter string mode
+ $this->data_string_flag = true;
+ $this->data_string = $string;
+
+ // Save info
+ $saved_avdataoffset = $this->getid3->info['avdataoffset'];
+ $saved_avdataend = $this->getid3->info['avdataend'];
+ $saved_filesize = $this->getid3->info['filesize'];
+
+ // Reset some info
+ $this->getid3->info['avdataoffset'] = 0;
+ $this->getid3->info['avdataend'] = $this->getid3->info['filesize'] = strlen($string);
+
+ // 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;
+ }
+
+
+ protected function ftell() {
+ if ($this->data_string_flag) {
+ return $this->data_string_position;
+ }
+ return ftell($this->getid3->fp);
+ }
+
+
+ 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);
+ }
+ return fread($this->getid3->fp, $bytes);
+ }
+
+
+ protected function fseek($bytes, $whence = SEEK_SET) {
+ if ($this->data_string_flag) {
+ switch ($whence) {
+ case SEEK_SET:
+ $this->data_string_position = $bytes;
+ return;
+
+ case SEEK_CUR:
+ $this->data_string_position += $bytes;
+ return;
+
+ case SEEK_END:
+ $this->data_string_position = strlen($this->data_string) + $bytes;
+ return;
+ }
+ }
+ return fseek($this->getid3->fp, $bytes, $whence);
+ }
+
+}
+
+
+class getid3_exception extends Exception
+{
+ public $message;
+}
+
+?>
\ No newline at end of file
diff --git a/app/Library/getid3/module.archive.gzip.php b/app/Library/getid3/module.archive.gzip.php
new file mode 100644
index 00000000..c30052ed
--- /dev/null
+++ b/app/Library/getid3/module.archive.gzip.php
@@ -0,0 +1,280 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.archive.gzip.php //
+// module for analyzing GZIP files //
+// dependencies: NONE //
+// ///
+/////////////////////////////////////////////////////////////////
+// //
+// Module originally written by //
+// Mike Mozolin //
+// //
+/////////////////////////////////////////////////////////////////
+
+
+class getid3_gzip extends getid3_handler {
+
+ // 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)
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ $info['fileformat'] = 'gzip';
+
+ $start_length = 10;
+ $unpack_header = 'a1id1/a1id2/a1cmethod/a1flags/a4mtime/a1xflags/a1os';
+ //+---+---+---+---+---+---+---+---+---+---+
+ //|ID1|ID2|CM |FLG| MTIME |XFL|OS |
+ //+---+---+---+---+---+---+---+---+---+---+
+
+ if ($info['filesize'] > $info['php_memory_limit']) {
+ $info['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;
+ }
+ fseek($this->getid3->fp, 0);
+ $buffer = fread($this->getid3->fp, $info['filesize']);
+
+ $arr_members = explode("\x1F\x8B\x08", $buffer);
+ while (true) {
+ $is_wrong_members = false;
+ $num_members = intval(count($arr_members));
+ for ($i = 0; $i < $num_members; $i++) {
+ if (strlen($arr_members[$i]) == 0) {
+ continue;
+ }
+ $buf = "\x1F\x8B\x08".$arr_members[$i];
+
+ $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] = '';
+ $is_wrong_members = true;
+ continue;
+ }
+ }
+ if (!$is_wrong_members) {
+ break;
+ }
+ }
+
+ $info['gzip']['files'] = array();
+
+ $fpointer = 0;
+ $idx = 0;
+ for ($i = 0; $i < $num_members; $i++) {
+ if (strlen($arr_members[$i]) == 0) {
+ continue;
+ }
+ $thisInfo = &$info['gzip']['member_header'][++$idx];
+
+ $buff = "\x1F\x8B\x08".$arr_members[$i];
+
+ $attr = unpack($unpack_header, substr($buff, 0, $start_length));
+ $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']);
+
+ $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);
+
+ $thisInfo['compression'] = $this->get_xflag_type($thisInfo['raw']['xflags']);
+
+ $thisInfo['os'] = $this->get_os_type($thisInfo['raw']['os']);
+ if (!$thisInfo['os']) {
+ $info['error'][] = 'Read error on gzip file';
+ return false;
+ }
+
+ $fpointer = 10;
+ $arr_xsubfield = array();
+ // bit 2 - FLG.FEXTRA
+ //+---+---+=================================+
+ //| XLEN |...XLEN bytes of "extra field"...|
+ //+---+---+=================================+
+ if ($thisInfo['flags']['extra']) {
+ $w_xlen = substr($buff, $fpointer, 2);
+ $xlen = getid3_lib::LittleEndian2Int($w_xlen);
+ $fpointer += 2;
+
+ $thisInfo['raw']['xfield'] = substr($buff, $fpointer, $xlen);
+ // Extra SubFields
+ //+---+---+---+---+==================================+
+ //|SI1|SI2| LEN |... LEN bytes of subfield data ...|
+ //+---+---+---+---+==================================+
+ $idx = 0;
+ while (true) {
+ if ($idx >= $xlen) {
+ break;
+ }
+ $si1 = ord(substr($buff, $fpointer + $idx++, 1));
+ $si2 = ord(substr($buff, $fpointer + $idx++, 1));
+ if (($si1 == 0x41) && ($si2 == 0x70)) {
+ $w_xsublen = substr($buff, $fpointer + $idx, 2);
+ $xsublen = getid3_lib::LittleEndian2Int($w_xsublen);
+ $idx += 2;
+ $arr_xsubfield[] = substr($buff, $fpointer + $idx, $xsublen);
+ $idx += $xsublen;
+ } else {
+ break;
+ }
+ }
+ $fpointer += $xlen;
+ }
+ // bit 3 - FLG.FNAME
+ //+=========================================+
+ //|...original file name, zero-terminated...|
+ //+=========================================+
+ // GZIP files may have only one file, with no filename, so assume original filename is current filename without .gz
+ $thisInfo['filename'] = preg_replace('#\.gz$#i', '', $info['filename']);
+ if ($thisInfo['flags']['filename']) {
+ while (true) {
+ if (ord($buff[$fpointer]) == 0) {
+ $fpointer++;
+ break;
+ }
+ $thisInfo['filename'] .= $buff[$fpointer];
+ $fpointer++;
+ }
+ }
+ // bit 4 - FLG.FCOMMENT
+ //+===================================+
+ //|...file comment, zero-terminated...|
+ //+===================================+
+ if ($thisInfo['flags']['comment']) {
+ while (true) {
+ if (ord($buff[$fpointer]) == 0) {
+ $fpointer++;
+ break;
+ }
+ $thisInfo['comment'] .= $buff[$fpointer];
+ $fpointer++;
+ }
+ }
+ // bit 1 - FLG.FHCRC
+ //+---+---+
+ //| CRC16 |
+ //+---+---+
+ if ($thisInfo['flags']['crc16']) {
+ $w_crc = substr($buff, $fpointer, 2);
+ $thisInfo['crc16'] = getid3_lib::LittleEndian2Int($w_crc);
+ $fpointer += 2;
+ }
+ // bit 0 - FLG.FTEXT
+ //if ($thisInfo['raw']['flags'] & 0x01) {
+ // Ignored...
+ //}
+ // bits 5, 6, 7 - reserved
+
+ $thisInfo['crc32'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 8, 4));
+ $thisInfo['filesize'] = getid3_lib::LittleEndian2Int(substr($buff, strlen($buff) - 4));
+
+ $info['gzip']['files'] = getid3_lib::array_merge_clobber($info['gzip']['files'], getid3_lib::CreateDeepArray($thisInfo['filename'], '/', $thisInfo['filesize']));
+
+ if ($this->option_gzip_parse_contents) {
+ // Try to inflate GZip
+ $csize = 0;
+ $inflated = '';
+ $chkcrc32 = '';
+ if (function_exists('gzinflate')) {
+ $cdata = substr($buff, $fpointer);
+ $cdata = substr($cdata, 0, strlen($cdata) - 8);
+ $csize = strlen($cdata);
+ $inflated = gzinflate($cdata);
+
+ // Calculate CRC32 for inflated content
+ $thisInfo['crc32_valid'] = (bool) (sprintf('%u', crc32($inflated)) == $thisInfo['crc32']);
+
+ // determine format
+ $formattest = substr($inflated, 0, 32774);
+ $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'] : '');
+ switch ($determined_format['module']) {
+ case 'tar':
+ // view TAR-file info
+ 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
+ $info['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);
+ 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 {
+ $info['error'][] = 'Unable to fopen() temp file to parse TAR inside GZIP file';
+ break;
+ }
+ }
+ break;
+
+ case '':
+ default:
+ // unknown or unhandled format
+ break;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ // Converts the OS type
+ function get_os_type($key) {
+ static $os_type = array(
+ '0' => 'FAT filesystem (MS-DOS, OS/2, NT/Win32)',
+ '1' => 'Amiga',
+ '2' => 'VMS (or OpenVMS)',
+ '3' => 'Unix',
+ '4' => 'VM/CMS',
+ '5' => 'Atari TOS',
+ '6' => 'HPFS filesystem (OS/2, NT)',
+ '7' => 'Macintosh',
+ '8' => 'Z-System',
+ '9' => 'CP/M',
+ '10' => 'TOPS-20',
+ '11' => 'NTFS filesystem (NT)',
+ '12' => 'QDOS',
+ '13' => 'Acorn RISCOS',
+ '255' => 'unknown'
+ );
+ return (isset($os_type[$key]) ? $os_type[$key] : '');
+ }
+
+ // Converts the eXtra FLags
+ function get_xflag_type($key) {
+ static $xflag_type = array(
+ '0' => 'unknown',
+ '2' => 'maximum compression',
+ '4' => 'fastest algorithm'
+ );
+ return (isset($xflag_type[$key]) ? $xflag_type[$key] : '');
+ }
+}
+
+?>
diff --git a/app/Library/getid3/module.archive.rar.php b/app/Library/getid3/module.archive.rar.php
new file mode 100644
index 00000000..4f5d46f8
--- /dev/null
+++ b/app/Library/getid3/module.archive.rar.php
@@ -0,0 +1,53 @@
+ //
+// 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 extends getid3_handler
+{
+
+ var $option_use_rar_extension = false;
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ $info['fileformat'] = 'rar';
+
+ if ($this->option_use_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 {
+ $info['error'][] = 'failed to rar_open('.$info['filename'].')';
+ }
+ } else {
+ $info['error'][] = 'RAR support does not appear to be available in this PHP installation';
+ }
+ } else {
+ $info['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/app/Library/getid3/module.archive.szip.php b/app/Library/getid3/module.archive.szip.php
new file mode 100644
index 00000000..3be62532
--- /dev/null
+++ b/app/Library/getid3/module.archive.szip.php
@@ -0,0 +1,96 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.archive.szip.php //
+// module for analyzing SZIP compressed files //
+// dependencies: NONE //
+// ///
+/////////////////////////////////////////////////////////////////
+
+
+class getid3_szip extends getid3_handler
+{
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
+ $SZIPHeader = fread($this->getid3->fp, 6);
+ if (substr($SZIPHeader, 0, 4) != "SZ\x0A\x04") {
+ $info['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));
+
+ while (!feof($this->getid3->fp)) {
+ $NextBlockID = fread($this->getid3->fp, 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($this->getid3->fp, 4, SEEK_CUR);
+ break;
+
+ case 'BH':
+ $BHheaderbytes = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 3));
+ $BHheaderdata = fread($this->getid3->fp, $BHheaderbytes);
+ $BHheaderoffset = 0;
+ while (strpos($BHheaderdata, "\x00", $BHheaderoffset) > 0) {
+ //filename as \0 terminated string (empty string indicates end)
+ //owner as \0 terminated string (empty is same as last file)
+ //group as \0 terminated string (empty is same as last file)
+ //3 byte filelength in this block
+ //2 byte access flags
+ //4 byte creation time (like in unix)
+ //4 byte modification time (like in unix)
+ //4 byte access time (like in unix)
+
+ $BHdataArray['filename'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
+ $BHheaderoffset += (strlen($BHdataArray['filename']) + 1);
+
+ $BHdataArray['owner'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
+ $BHheaderoffset += (strlen($BHdataArray['owner']) + 1);
+
+ $BHdataArray['group'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
+ $BHheaderoffset += (strlen($BHdataArray['group']) + 1);
+
+ $BHdataArray['filelength'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 3));
+ $BHheaderoffset += 3;
+
+ $BHdataArray['access_flags'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 2));
+ $BHheaderoffset += 2;
+
+ $BHdataArray['creation_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
+ $BHheaderoffset += 4;
+
+ $BHdataArray['modification_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
+ $BHheaderoffset += 4;
+
+ $BHdataArray['access_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
+ $BHheaderoffset += 4;
+
+ $info['szip']['BH'][] = $BHdataArray;
+ }
+ break;
+
+ default:
+ break 2;
+ }
+ }
+
+ return true;
+
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/app/Library/getid3/module.archive.tar.php b/app/Library/getid3/module.archive.tar.php
new file mode 100644
index 00000000..94d32039
--- /dev/null
+++ b/app/Library/getid3/module.archive.tar.php
@@ -0,0 +1,178 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.archive.tar.php //
+// module for analyzing TAR files //
+// dependencies: NONE //
+// ///
+/////////////////////////////////////////////////////////////////
+// //
+// Module originally written by //
+// Mike Mozolin //
+// //
+/////////////////////////////////////////////////////////////////
+
+
+class getid3_tar extends getid3_handler
+{
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ $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
+
+ fseek($this->getid3->fp, 0);
+ while (!feof($this->getid3->fp)) {
+ $buffer = fread($this->getid3->fp, 512);
+ if (strlen($buffer) < 512) {
+ break;
+ }
+
+ // check the block
+ $checksum = 0;
+ for ($i = 0; $i < 148; $i++) {
+ $checksum += ord($buffer{$i});
+ }
+ for ($i = 148; $i < 156; $i++) {
+ $checksum += ord(' ');
+ }
+ for ($i = 156; $i < 512; $i++) {
+ $checksum += ord($buffer{$i});
+ }
+ $attr = unpack($unpack_header, $buffer);
+ $name = (isset($attr['fname'] ) ? trim($attr['fname'] ) : '');
+ $mode = octdec(isset($attr['mode'] ) ? trim($attr['mode'] ) : '');
+ $uid = octdec(isset($attr['uid'] ) ? trim($attr['uid'] ) : '');
+ $gid = octdec(isset($attr['gid'] ) ? trim($attr['gid'] ) : '');
+ $size = octdec(isset($attr['size'] ) ? trim($attr['size'] ) : '');
+ $mtime = octdec(isset($attr['mtime'] ) ? trim($attr['mtime'] ) : '');
+ $chksum = octdec(isset($attr['chksum'] ) ? trim($attr['chksum'] ) : '');
+ $typflag = (isset($attr['typflag']) ? trim($attr['typflag']) : '');
+ $lnkname = (isset($attr['lnkname']) ? trim($attr['lnkname']) : '');
+ $magic = (isset($attr['magic'] ) ? trim($attr['magic'] ) : '');
+ $ver = (isset($attr['ver'] ) ? trim($attr['ver'] ) : '');
+ $uname = (isset($attr['uname'] ) ? trim($attr['uname'] ) : '');
+ $gname = (isset($attr['gname'] ) ? trim($attr['gname'] ) : '');
+ $devmaj = octdec(isset($attr['devmaj'] ) ? trim($attr['devmaj'] ) : '');
+ $devmin = octdec(isset($attr['devmin'] ) ? trim($attr['devmin'] ) : '');
+ $prefix = (isset($attr['prefix'] ) ? trim($attr['prefix'] ) : '');
+ if (($checksum == 256) && ($chksum == 0)) {
+ // EOF Found
+ break;
+ }
+ if ($prefix) {
+ $name = $prefix.'/'.$name;
+ }
+ if ((preg_match('#/$#', $name)) && !$name) {
+ $typeflag = 5;
+ }
+ if ($buffer == $null_512k) {
+ // it's the end of the tar-file...
+ break;
+ }
+
+ // Read to the next chunk
+ fseek($this->getid3->fp, $size, SEEK_CUR);
+
+ $diff = $size % 512;
+ if ($diff != 0) {
+ // Padding, throw away
+ fseek($this->getid3->fp, (512 - $diff), SEEK_CUR);
+ }
+ // Protect against tar-files with garbage at the end
+ if ($name == '') {
+ break;
+ }
+ $info['tar']['file_details'][$name] = array (
+ 'name' => $name,
+ 'mode_raw' => $mode,
+ 'mode' => getid3_tar::display_perms($mode),
+ 'uid' => $uid,
+ 'gid' => $gid,
+ 'size' => $size,
+ 'mtime' => $mtime,
+ 'chksum' => $chksum,
+ 'typeflag' => getid3_tar::get_flag_type($typflag),
+ 'linkname' => $lnkname,
+ 'magic' => $magic,
+ 'version' => $ver,
+ 'uname' => $uname,
+ 'gname' => $gname,
+ 'devmajor' => $devmaj,
+ 'devminor' => $devmin
+ );
+ $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) {
+ // Determine Type
+ if ($mode & 0x1000) $type='p'; // FIFO pipe
+ elseif ($mode & 0x2000) $type='c'; // Character special
+ elseif ($mode & 0x4000) $type='d'; // Directory
+ elseif ($mode & 0x6000) $type='b'; // Block special
+ elseif ($mode & 0x8000) $type='-'; // Regular
+ elseif ($mode & 0xA000) $type='l'; // Symbolic Link
+ elseif ($mode & 0xC000) $type='s'; // Socket
+ else $type='u'; // UNKNOWN
+
+ // Determine permissions
+ $owner['read'] = (($mode & 00400) ? 'r' : '-');
+ $owner['write'] = (($mode & 00200) ? 'w' : '-');
+ $owner['execute'] = (($mode & 00100) ? 'x' : '-');
+ $group['read'] = (($mode & 00040) ? 'r' : '-');
+ $group['write'] = (($mode & 00020) ? 'w' : '-');
+ $group['execute'] = (($mode & 00010) ? 'x' : '-');
+ $world['read'] = (($mode & 00004) ? 'r' : '-');
+ $world['write'] = (($mode & 00002) ? 'w' : '-');
+ $world['execute'] = (($mode & 00001) ? 'x' : '-');
+
+ // Adjust for SUID, SGID and sticky bit
+ if ($mode & 0x800) $owner['execute'] = ($owner['execute'] == 'x') ? 's' : 'S';
+ if ($mode & 0x400) $group['execute'] = ($group['execute'] == 'x') ? 's' : 'S';
+ if ($mode & 0x200) $world['execute'] = ($world['execute'] == 'x') ? 't' : 'T';
+
+ $s = sprintf('%1s', $type);
+ $s .= sprintf('%1s%1s%1s', $owner['read'], $owner['write'], $owner['execute']);
+ $s .= sprintf('%1s%1s%1s', $group['read'], $group['write'], $group['execute']);
+ $s .= sprintf('%1s%1s%1s'."\n", $world['read'], $world['write'], $world['execute']);
+ return $s;
+ }
+
+ // Converts the file type
+ function get_flag_type($typflag) {
+ static $flag_types = array(
+ '0' => 'LF_NORMAL',
+ '1' => 'LF_LINK',
+ '2' => 'LF_SYNLINK',
+ '3' => 'LF_CHR',
+ '4' => 'LF_BLK',
+ '5' => 'LF_DIR',
+ '6' => 'LF_FIFO',
+ '7' => 'LF_CONFIG',
+ 'D' => 'LF_DUMPDIR',
+ 'K' => 'LF_LONGLINK',
+ 'L' => 'LF_LONGNAME',
+ 'M' => 'LF_MULTIVOL',
+ 'N' => 'LF_NAMES',
+ 'S' => 'LF_SPARSE',
+ 'V' => 'LF_VOLHDR'
+ );
+ return (isset($flag_types[$typflag]) ? $flag_types[$typflag] : '');
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/app/Library/getid3/module.archive.zip.php b/app/Library/getid3/module.archive.zip.php
new file mode 100644
index 00000000..7db8fd23
--- /dev/null
+++ b/app/Library/getid3/module.archive.zip.php
@@ -0,0 +1,424 @@
+ //
+// 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 extends getid3_handler
+{
+
+ 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'])) {
+ $info['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($this->getid3->fp, -128 * $EOCDsearchCounter, SEEK_END);
+ $EOCDsearchData = fread($this->getid3->fp, 128).$EOCDsearchData;
+
+ if (strstr($EOCDsearchData, 'PK'."\x05\x06")) {
+
+ $EOCDposition = strpos($EOCDsearchData, 'PK'."\x05\x06");
+ fseek($this->getid3->fp, (-128 * $EOCDsearchCounter) + $EOCDposition, SEEK_END);
+ $info['zip']['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory();
+
+ fseek($this->getid3->fp, $info['zip']['end_central_directory']['directory_offset'], SEEK_SET);
+ $info['zip']['entries_count'] = 0;
+ while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($this->getid3->fp)) {
+ $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) {
+ $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) {
+ $info['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';
+ }
+
+ return true;
+
+ }
+ }
+ }
+
+ if ($this->getZIPentriesFilepointer()) {
+
+ // 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)) {
+ $info['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)';
+ }
+ $info['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;
+
+ } else {
+
+ unset($info['zip']);
+ $info['fileformat'] = '';
+ $info['error'][] = 'Cannot find End Of Central Directory (truncated file?)';
+ return false;
+
+ }
+ }
+
+
+ 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) {
+ $info['error'][] = 'No Local File Header entries found';
+ return false;
+ }
+
+ $info['zip']['entries_count'] = 0;
+ while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($this->getid3->fp)) {
+ $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) {
+ $info['error'][] = 'No Central Directory entries found (truncated file?)';
+ return false;
+ }
+
+ if ($EOCD = $this->ZIPparseEndOfCentralDirectory()) {
+ $info['zip']['end_central_directory'] = $EOCD;
+ } else {
+ $info['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;
+ }
+
+
+ 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) {
+ $info['error'][] = 'No Local File Header entries found';
+ return false;
+ }
+
+ return true;
+ }
+
+
+ function ZIPparseLocalFileHeader() {
+ $LocalFileHeader['offset'] = ftell($this->getid3->fp);
+
+ $ZIPlocalFileHeader = fread($this->getid3->fp, 30);
+
+ $LocalFileHeader['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 0, 4));
+ if ($LocalFileHeader['raw']['signature'] != 0x04034B50) {
+ // invalid Local File Header Signature
+ fseek($this->getid3->fp, $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($this->getid3->fp, $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($this->getid3->fp);
+ //$LocalFileHeader['compressed_data'] = fread($this->getid3->fp, $LocalFileHeader['raw']['compressed_size']);
+ fseek($this->getid3->fp, $LocalFileHeader['raw']['compressed_size'], SEEK_CUR);
+
+ if ($LocalFileHeader['flags']['data_descriptor_used']) {
+ $DataDescriptor = fread($this->getid3->fp, 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() {
+ $CentralDirectory['offset'] = ftell($this->getid3->fp);
+
+ $ZIPcentralDirectory = fread($this->getid3->fp, 46);
+
+ $CentralDirectory['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 0, 4));
+ if ($CentralDirectory['raw']['signature'] != 0x02014B50) {
+ // invalid Central Directory Signature
+ fseek($this->getid3->fp, $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($this->getid3->fp, $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() {
+ $EndOfCentralDirectory['offset'] = ftell($this->getid3->fp);
+
+ $ZIPendOfCentralDirectory = fread($this->getid3->fp, 22);
+
+ $EndOfCentralDirectory['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 0, 4));
+ if ($EndOfCentralDirectory['signature'] != 0x06054B50) {
+ // invalid End Of Central Directory Signature
+ fseek($this->getid3->fp, $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($this->getid3->fp, $EndOfCentralDirectory['comment_length']);
+ }
+
+ return $EndOfCentralDirectory;
+ }
+
+
+ static 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;
+ }
+
+
+ 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'
+ );
+
+ return (isset($ZIPversionOSLookup[$index]) ? $ZIPversionOSLookup[$index] : '[unknown]');
+ }
+
+ static 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]');
+ }
+
+ 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);
+ }
+
+}
+
+
+?>
\ No newline at end of file
diff --git a/app/Library/getid3/module.audio-video.asf.php b/app/Library/getid3/module.audio-video.asf.php
new file mode 100644
index 00000000..0bb095f5
--- /dev/null
+++ b/app/Library/getid3/module.audio-video.asf.php
@@ -0,0 +1,2021 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.audio-video.asf.php //
+// module for analyzing ASF, WMA and WMV files //
+// dependencies: module.audio-video.riff.php //
+// ///
+/////////////////////////////////////////////////////////////////
+
+getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
+
+class getid3_asf extends getid3_handler
+{
+
+ 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));
+ }
+ }
+ }
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ // Shortcuts
+ $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();
+ $thisfile_asf_headerobject = &$thisfile_asf['header_object'];
+
+
+ // ASF structure:
+ // * Header Object [required]
+ // * File Properties Object [required] (global file attributes)
+ // * Stream Properties Object [required] (defines media stream & characteristics)
+ // * Header Extension Object [required] (additional functionality)
+ // * Content Description Object (bibliographic information)
+ // * Script Command Object (commands for during playback)
+ // * Marker Object (named jumped points within the file)
+ // * Data Object [required]
+ // * Data Packets
+ // * Index Object
+
+ // Header Object: (mandatory, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for header object - GETID3_ASF_Header_Object
+ // Object Size QWORD 64 // size of header object, including 30 bytes of Header Object header
+ // Number of Header Objects DWORD 32 // number of objects in header object
+ // Reserved1 BYTE 8 // hardcoded: 0x01
+ // Reserved2 BYTE 8 // hardcoded: 0x02
+
+ $info['fileformat'] = 'asf';
+
+ fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
+ $HeaderObjectData = fread($this->getid3->fp, 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) {
+ $info['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($info['fileformat']);
+ unset($info['asf']);
+ return false;
+ break;
+ }
+ $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));
+
+ $NextObjectOffset = ftell($this->getid3->fp);
+ $ASFHeaderData = fread($this->getid3->fp, $thisfile_asf_headerobject['objectsize'] - 30);
+ $offset = 0;
+
+ for ($HeaderObjectsCounter = 0; $HeaderObjectsCounter < $thisfile_asf_headerobject['headerobjects']; $HeaderObjectsCounter++) {
+ $NextObjectGUID = substr($ASFHeaderData, $offset, 16);
+ $offset += 16;
+ $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID);
+ $NextObjectSize = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ switch ($NextObjectGUID) {
+
+ case GETID3_ASF_File_Properties_Object:
+ // File Properties Object: (mandatory, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for file properties object - GETID3_ASF_File_Properties_Object
+ // Object Size QWORD 64 // size of file properties object, including 104 bytes of File Properties Object header
+ // File ID GUID 128 // unique ID - identical to File ID in Data Object
+ // File Size QWORD 64 // entire file in bytes. Invalid if Broadcast Flag == 1
+ // Creation Date QWORD 64 // date & time of file creation. Maybe invalid if Broadcast Flag == 1
+ // Data Packets Count QWORD 64 // number of data packets in Data Object. Invalid if Broadcast Flag == 1
+ // Play Duration QWORD 64 // playtime, in 100-nanosecond units. Invalid if Broadcast Flag == 1
+ // Send Duration QWORD 64 // time needed to send file, in 100-nanosecond units. Players can ignore this value. Invalid if Broadcast Flag == 1
+ // Preroll QWORD 64 // time to buffer data before starting to play file, in 1-millisecond units. If <> 0, PlayDuration and PresentationTime have been offset by this amount
+ // Flags DWORD 32 //
+ // * Broadcast Flag bits 1 (0x01) // file is currently being written, some header values are invalid
+ // * Seekable Flag bits 1 (0x02) // is file seekable
+ // * Reserved bits 30 (0xFFFFFFFC) // reserved - set to zero
+ // Minimum Data Packet Size DWORD 32 // in bytes. should be same as Maximum Data Packet Size. Invalid if Broadcast Flag == 1
+ // Maximum Data Packet Size DWORD 32 // in bytes. should be same as Minimum Data Packet Size. Invalid if Broadcast Flag == 1
+ // Maximum Bitrate DWORD 32 // maximum instantaneous bitrate in bits per second for entire file, including all data streams and ASF overhead
+
+ // shortcut
+ $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;
+ $thisfile_asf_filepropertiesobject['fileid'] = substr($ASFHeaderData, $offset, 16);
+ $offset += 16;
+ $thisfile_asf_filepropertiesobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_filepropertiesobject['fileid']);
+ $thisfile_asf_filepropertiesobject['filesize'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_filepropertiesobject['creation_date'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $thisfile_asf_filepropertiesobject['creation_date_unix'] = $this->FILETIMEtoUNIXtime($thisfile_asf_filepropertiesobject['creation_date']);
+ $offset += 8;
+ $thisfile_asf_filepropertiesobject['data_packets'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_filepropertiesobject['play_duration'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_filepropertiesobject['send_duration'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_filepropertiesobject['preroll'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_filepropertiesobject['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_filepropertiesobject['flags']['broadcast'] = (bool) ($thisfile_asf_filepropertiesobject['flags_raw'] & 0x0001);
+ $thisfile_asf_filepropertiesobject['flags']['seekable'] = (bool) ($thisfile_asf_filepropertiesobject['flags_raw'] & 0x0002);
+
+ $thisfile_asf_filepropertiesobject['min_packet_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_filepropertiesobject['max_packet_size'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_filepropertiesobject['max_bitrate'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+
+ if ($thisfile_asf_filepropertiesobject['flags']['broadcast']) {
+
+ // broadcast flag is set, some values invalid
+ unset($thisfile_asf_filepropertiesobject['filesize']);
+ unset($thisfile_asf_filepropertiesobject['data_packets']);
+ unset($thisfile_asf_filepropertiesobject['play_duration']);
+ unset($thisfile_asf_filepropertiesobject['send_duration']);
+ unset($thisfile_asf_filepropertiesobject['min_packet_size']);
+ unset($thisfile_asf_filepropertiesobject['max_packet_size']);
+
+ } else {
+
+ // broadcast flag NOT set, perform calculations
+ $info['playtime_seconds'] = ($thisfile_asf_filepropertiesobject['play_duration'] / 10000000) - ($thisfile_asf_filepropertiesobject['preroll'] / 1000);
+
+ //$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;
+
+ case GETID3_ASF_Stream_Properties_Object:
+ // Stream Properties Object: (mandatory, one per media stream)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for stream properties object - GETID3_ASF_Stream_Properties_Object
+ // Object Size QWORD 64 // size of stream properties object, including 78 bytes of Stream Properties Object header
+ // Stream Type GUID 128 // GETID3_ASF_Audio_Media, GETID3_ASF_Video_Media or GETID3_ASF_Command_Media
+ // Error Correction Type GUID 128 // GETID3_ASF_Audio_Spread for audio-only streams, GETID3_ASF_No_Error_Correction for other stream types
+ // Time Offset QWORD 64 // 100-nanosecond units. typically zero. added to all timestamps of samples in the stream
+ // Type-Specific Data Length DWORD 32 // number of bytes for Type-Specific Data field
+ // Error Correction Data Length DWORD 32 // number of bytes for Error Correction Data field
+ // Flags WORD 16 //
+ // * Stream Number bits 7 (0x007F) // number of this stream. 1 <= valid <= 127
+ // * Reserved bits 8 (0x7F80) // reserved - set to zero
+ // * Encrypted Content Flag bits 1 (0x8000) // stream contents encrypted if set
+ // Reserved DWORD 32 // reserved - set to zero
+ // Type-Specific Data BYTESTREAM variable // type-specific format data, depending on value of Stream Type
+ // Error Correction Data BYTESTREAM variable // error-correction-specific format data, depending on value of Error Correct Type
+
+ // There is one GETID3_ASF_Stream_Properties_Object for each stream (audio, video) but the
+ // 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;
+ $StreamPropertiesObjectData['stream_type'] = substr($ASFHeaderData, $offset, 16);
+ $offset += 16;
+ $StreamPropertiesObjectData['stream_type_guid'] = $this->BytestringToGUID($StreamPropertiesObjectData['stream_type']);
+ $StreamPropertiesObjectData['error_correct_type'] = substr($ASFHeaderData, $offset, 16);
+ $offset += 16;
+ $StreamPropertiesObjectData['error_correct_guid'] = $this->BytestringToGUID($StreamPropertiesObjectData['error_correct_type']);
+ $StreamPropertiesObjectData['time_offset'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $StreamPropertiesObjectData['type_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $StreamPropertiesObjectData['error_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $StreamPropertiesObjectData['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $StreamPropertiesObjectStreamNumber = $StreamPropertiesObjectData['flags_raw'] & 0x007F;
+ $StreamPropertiesObjectData['flags']['encrypted'] = (bool) ($StreamPropertiesObjectData['flags_raw'] & 0x8000);
+
+ $offset += 4; // reserved - DWORD
+ $StreamPropertiesObjectData['type_specific_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['type_data_length']);
+ $offset += $StreamPropertiesObjectData['type_data_length'];
+ $StreamPropertiesObjectData['error_correct_data'] = substr($ASFHeaderData, $offset, $StreamPropertiesObjectData['error_data_length']);
+ $offset += $StreamPropertiesObjectData['error_data_length'];
+
+ switch ($StreamPropertiesObjectData['stream_type']) {
+
+ case GETID3_ASF_Audio_Media:
+ $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));
+ unset($audiodata['raw']);
+ $thisfile_audio = getid3_lib::array_merge_noclobber($audiodata, $thisfile_audio);
+ break;
+
+ case GETID3_ASF_Video_Media:
+ $thisfile_video['dataformat'] = (!empty($thisfile_video['dataformat']) ? $thisfile_video['dataformat'] : 'asf');
+ $thisfile_video['bitrate_mode'] = (!empty($thisfile_video['bitrate_mode']) ? $thisfile_video['bitrate_mode'] : 'cbr');
+ break;
+
+ case GETID3_ASF_Command_Media:
+ default:
+ // do nothing
+ break;
+
+ }
+
+ $thisfile_asf['stream_properties_object'][$StreamPropertiesObjectStreamNumber] = $StreamPropertiesObjectData;
+ unset($StreamPropertiesObjectData); // clear for next stream, if any
+ break;
+
+ case GETID3_ASF_Header_Extension_Object:
+ // Header Extension Object: (mandatory, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Header Extension object - GETID3_ASF_Header_Extension_Object
+ // Object Size QWORD 64 // size of Header Extension object, including 46 bytes of Header Extension Object header
+ // Reserved Field 1 GUID 128 // hardcoded: GETID3_ASF_Reserved_1
+ // Reserved Field 2 WORD 16 // hardcoded: 0x00000006
+ // Header Extension Data Size DWORD 32 // in bytes. valid: 0, or > 24. equals object size minus 46
+ // Header Extension Data BYTESTREAM variable // array of zero or more extended header objects
+
+ // shortcut
+ $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;
+ $thisfile_asf_headerextensionobject['reserved_1'] = substr($ASFHeaderData, $offset, 16);
+ $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) {
+ $info['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) {
+ $info['warning'][] = 'header_extension_object.reserved_2 ('.getid3_lib::PrintHexBytes($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->ASF_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;
+
+ case GETID3_ASF_Codec_List_Object:
+ // Codec List Object: (optional, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Codec List object - GETID3_ASF_Codec_List_Object
+ // Object Size QWORD 64 // size of Codec List object, including 44 bytes of Codec List Object header
+ // Reserved GUID 128 // hardcoded: 86D15241-311D-11D0-A3A4-00A0C90348F6
+ // Codec Entries Count DWORD 32 // number of entries in Codec Entries array
+ // Codec Entries array of: variable //
+ // * Type WORD 16 // 0x0001 = Video Codec, 0x0002 = Audio Codec, 0xFFFF = Unknown Codec
+ // * Codec Name Length WORD 16 // number of Unicode characters stored in the Codec Name field
+ // * Codec Name WCHAR variable // array of Unicode characters - name of codec used to create the content
+ // * Codec Description Length WORD 16 // number of Unicode characters stored in the Codec Description field
+ // * Codec Description WCHAR variable // array of Unicode characters - description of format used to create the content
+ // * Codec Information Length WORD 16 // number of Unicode characters stored in the Codec Information field
+ // * Codec Information BYTESTREAM variable // opaque array of information bytes about the codec used to create the content
+
+ // shortcut
+ $thisfile_asf['codec_list_object'] = array();
+ $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;
+ $thisfile_asf_codeclistobject['reserved'] = substr($ASFHeaderData, $offset, 16);
+ $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')) {
+ $info['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));
+ $offset += 4;
+ for ($CodecEntryCounter = 0; $CodecEntryCounter < $thisfile_asf_codeclistobject['codec_entries_count']; $CodecEntryCounter++) {
+ // shortcut
+ $thisfile_asf_codeclistobject['codec_entries'][$CodecEntryCounter] = array();
+ $thisfile_asf_codeclistobject_codecentries_current = &$thisfile_asf_codeclistobject['codec_entries'][$CodecEntryCounter];
+
+ $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']);
+
+ $CodecNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
+ $offset += 2;
+ $thisfile_asf_codeclistobject_codecentries_current['name'] = substr($ASFHeaderData, $offset, $CodecNameLength);
+ $offset += $CodecNameLength;
+
+ $CodecDescriptionLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
+ $offset += 2;
+ $thisfile_asf_codeclistobject_codecentries_current['description'] = substr($ASFHeaderData, $offset, $CodecDescriptionLength);
+ $offset += $CodecDescriptionLength;
+
+ $CodecInformationLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_codeclistobject_codecentries_current['information'] = substr($ASFHeaderData, $offset, $CodecInformationLength);
+ $offset += $CodecInformationLength;
+
+ if ($thisfile_asf_codeclistobject_codecentries_current['type_raw'] == 2) { // audio codec
+
+ if (strpos($thisfile_asf_codeclistobject_codecentries_current['description'], ',') === false) {
+ $info['warning'][] = '[asf][codec_list_object][codec_entries]['.$CodecEntryCounter.'][description] expected to contain comma-seperated 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);
+ }
+ //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($info['bitrate'])) {
+ //$thisfile_video['bitrate'] = $thisfile_asf['file_properties_object']['max_bitrate'] - $thisfile_audio['bitrate'];
+ $thisfile_video['bitrate'] = $info['bitrate'] - $thisfile_audio['bitrate'];
+ }
+
+ $AudioCodecFrequency = (int) trim(str_replace('kHz', '', $AudioCodecFrequency));
+ switch ($AudioCodecFrequency) {
+ case 8:
+ case 8000:
+ $thisfile_audio['sample_rate'] = 8000;
+ break;
+
+ case 11:
+ case 11025:
+ $thisfile_audio['sample_rate'] = 11025;
+ break;
+
+ case 12:
+ case 12000:
+ $thisfile_audio['sample_rate'] = 12000;
+ break;
+
+ case 16:
+ case 16000:
+ $thisfile_audio['sample_rate'] = 16000;
+ break;
+
+ case 22:
+ case 22050:
+ $thisfile_audio['sample_rate'] = 22050;
+ break;
+
+ case 24:
+ case 24000:
+ $thisfile_audio['sample_rate'] = 24000;
+ break;
+
+ case 32:
+ case 32000:
+ $thisfile_audio['sample_rate'] = 32000;
+ break;
+
+ case 44:
+ case 441000:
+ $thisfile_audio['sample_rate'] = 44100;
+ break;
+
+ case 48:
+ case 48000:
+ $thisfile_audio['sample_rate'] = 48000;
+ break;
+
+ default:
+ $info['warning'][] = 'unknown frequency: "'.$AudioCodecFrequency.'" ('.$this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['description']).')';
+ break;
+ }
+
+ if (!isset($thisfile_audio['channels'])) {
+ if (strstr($AudioCodecChannels, 'stereo')) {
+ $thisfile_audio['channels'] = 2;
+ } elseif (strstr($AudioCodecChannels, 'mono')) {
+ $thisfile_audio['channels'] = 1;
+ }
+ }
+
+ }
+ }
+ }
+ break;
+
+ case GETID3_ASF_Script_Command_Object:
+ // Script Command Object: (optional, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Script Command object - GETID3_ASF_Script_Command_Object
+ // Object Size QWORD 64 // size of Script Command object, including 44 bytes of Script Command Object header
+ // Reserved GUID 128 // hardcoded: 4B1ACBE3-100B-11D0-A39B-00A0C90348F6
+ // Commands Count WORD 16 // number of Commands structures in the Script Commands Objects
+ // Command Types Count WORD 16 // number of Command Types structures in the Script Commands Objects
+ // Command Types array of: variable //
+ // * Command Type Name Length WORD 16 // number of Unicode characters for Command Type Name
+ // * Command Type Name WCHAR variable // array of Unicode characters - name of a type of command
+ // Commands array of: variable //
+ // * Presentation Time DWORD 32 // presentation time of that command, in milliseconds
+ // * Type Index WORD 16 // type of this command, as a zero-based index into the array of Command Types of this object
+ // * Command Name Length WORD 16 // number of Unicode characters for Command Name
+ // * Command Name WCHAR variable // array of Unicode characters - name of this command
+
+ // shortcut
+ $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;
+ $thisfile_asf_scriptcommandobject['reserved'] = substr($ASFHeaderData, $offset, 16);
+ $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')) {
+ $info['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;
+ }
+ $thisfile_asf_scriptcommandobject['commands_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_scriptcommandobject['command_types_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ for ($CommandTypesCounter = 0; $CommandTypesCounter < $thisfile_asf_scriptcommandobject['command_types_count']; $CommandTypesCounter++) {
+ $CommandTypeNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
+ $offset += 2;
+ $thisfile_asf_scriptcommandobject['command_types'][$CommandTypesCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength);
+ $offset += $CommandTypeNameLength;
+ }
+ for ($CommandsCounter = 0; $CommandsCounter < $thisfile_asf_scriptcommandobject['commands_count']; $CommandsCounter++) {
+ $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['type_index'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+
+ $CommandTypeNameLength = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2)) * 2; // 2 bytes per character
+ $offset += 2;
+ $thisfile_asf_scriptcommandobject['commands'][$CommandsCounter]['name'] = substr($ASFHeaderData, $offset, $CommandTypeNameLength);
+ $offset += $CommandTypeNameLength;
+ }
+ break;
+
+ case GETID3_ASF_Marker_Object:
+ // Marker Object: (optional, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Marker object - GETID3_ASF_Marker_Object
+ // Object Size QWORD 64 // size of Marker object, including 48 bytes of Marker Object header
+ // Reserved GUID 128 // hardcoded: 4CFEDB20-75F6-11CF-9C0F-00A0C90349CB
+ // Markers Count DWORD 32 // number of Marker structures in Marker Object
+ // Reserved WORD 16 // hardcoded: 0x0000
+ // Name Length WORD 16 // number of bytes in the Name field
+ // Name WCHAR variable // name of the Marker Object
+ // Markers array of: variable //
+ // * Offset QWORD 64 // byte offset into Data Object
+ // * Presentation Time QWORD 64 // in 100-nanosecond units
+ // * Entry Length WORD 16 // length in bytes of (Send Time + Flags + Marker Description Length + Marker Description + Padding)
+ // * Send Time DWORD 32 // in milliseconds
+ // * Flags DWORD 32 // hardcoded: 0x00000000
+ // * Marker Description Length DWORD 32 // number of bytes in Marker Description field
+ // * Marker Description WCHAR variable // array of Unicode characters - description of marker entry
+ // * Padding BYTESTREAM variable // optional padding bytes
+
+ // shortcut
+ $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;
+ $thisfile_asf_markerobject['reserved'] = substr($ASFHeaderData, $offset, 16);
+ $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')) {
+ $info['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}';
+ break;
+ }
+ $thisfile_asf_markerobject['markers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_markerobject['reserved_2'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ if ($thisfile_asf_markerobject['reserved_2'] != 0) {
+ $info['warning'][] = 'marker_object.reserved_2 ('.getid3_lib::PrintHexBytes($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));
+ $offset += 2;
+ $thisfile_asf_markerobject['name'] = substr($ASFHeaderData, $offset, $thisfile_asf_markerobject['name_length']);
+ $offset += $thisfile_asf_markerobject['name_length'];
+ for ($MarkersCounter = 0; $MarkersCounter < $thisfile_asf_markerobject['markers_count']; $MarkersCounter++) {
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['offset'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['presentation_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['entry_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['send_time'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['flags'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description'] = substr($ASFHeaderData, $offset, $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length']);
+ $offset += $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'];
+ $PaddingLength = $thisfile_asf_markerobject['markers'][$MarkersCounter]['entry_length'] - 4 - 4 - 4 - $thisfile_asf_markerobject['markers'][$MarkersCounter]['marker_description_length'];
+ if ($PaddingLength > 0) {
+ $thisfile_asf_markerobject['markers'][$MarkersCounter]['padding'] = substr($ASFHeaderData, $offset, $PaddingLength);
+ $offset += $PaddingLength;
+ }
+ }
+ break;
+
+ case GETID3_ASF_Bitrate_Mutual_Exclusion_Object:
+ // Bitrate Mutual Exclusion Object: (optional)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Bitrate Mutual Exclusion object - GETID3_ASF_Bitrate_Mutual_Exclusion_Object
+ // Object Size QWORD 64 // size of Bitrate Mutual Exclusion object, including 42 bytes of Bitrate Mutual Exclusion Object header
+ // Exlusion Type GUID 128 // nature of mutual exclusion relationship. one of: (GETID3_ASF_Mutex_Bitrate, GETID3_ASF_Mutex_Unknown)
+ // Stream Numbers Count WORD 16 // number of video streams
+ // Stream Numbers WORD variable // array of mutually exclusive video stream numbers. 1 <= valid <= 127
+
+ // shortcut
+ $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;
+ $thisfile_asf_bitratemutualexclusionobject['reserved'] = substr($ASFHeaderData, $offset, 16);
+ $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)) {
+ $info['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;
+ }
+ $thisfile_asf_bitratemutualexclusionobject['stream_numbers_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ for ($StreamNumberCounter = 0; $StreamNumberCounter < $thisfile_asf_bitratemutualexclusionobject['stream_numbers_count']; $StreamNumberCounter++) {
+ $thisfile_asf_bitratemutualexclusionobject['stream_numbers'][$StreamNumberCounter] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ }
+ break;
+
+ case GETID3_ASF_Error_Correction_Object:
+ // Error Correction Object: (optional, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Error Correction object - GETID3_ASF_Error_Correction_Object
+ // Object Size QWORD 64 // size of Error Correction object, including 44 bytes of Error Correction Object header
+ // Error Correction Type GUID 128 // type of error correction. one of: (GETID3_ASF_No_Error_Correction, GETID3_ASF_Audio_Spread)
+ // Error Correction Data Length DWORD 32 // number of bytes in Error Correction Data field
+ // Error Correction Data BYTESTREAM variable // structure depends on value of Error Correction Type field
+
+ // shortcut
+ $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;
+ $thisfile_asf_errorcorrectionobject['error_correction_type'] = substr($ASFHeaderData, $offset, 16);
+ $offset += 16;
+ $thisfile_asf_errorcorrectionobject['error_correction_guid'] = $this->BytestringToGUID($thisfile_asf_errorcorrectionobject['error_correction_type']);
+ $thisfile_asf_errorcorrectionobject['error_correction_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ switch ($thisfile_asf_errorcorrectionobject['error_correction_type']) {
+ case GETID3_ASF_No_Error_Correction:
+ // should be no data, but just in case there is, skip to the end of the field
+ $offset += $thisfile_asf_errorcorrectionobject['error_correction_data_length'];
+ break;
+
+ case GETID3_ASF_Audio_Spread:
+ // Field Name Field Type Size (bits)
+ // Span BYTE 8 // number of packets over which audio will be spread.
+ // Virtual Packet Length WORD 16 // size of largest audio payload found in audio stream
+ // Virtual Chunk Length WORD 16 // size of largest audio payload found in audio stream
+ // Silence Data Length WORD 16 // number of bytes in Silence Data field
+ // Silence Data BYTESTREAM variable // hardcoded: 0x00 * (Silence Data Length) bytes
+
+ $thisfile_asf_errorcorrectionobject['span'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 1));
+ $offset += 1;
+ $thisfile_asf_errorcorrectionobject['virtual_packet_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_errorcorrectionobject['virtual_chunk_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_errorcorrectionobject['silence_data_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_errorcorrectionobject['silence_data'] = substr($ASFHeaderData, $offset, $thisfile_asf_errorcorrectionobject['silence_data_length']);
+ $offset += $thisfile_asf_errorcorrectionobject['silence_data_length'];
+ break;
+
+ default:
+ $info['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).'}';
+ //return false;
+ break;
+ }
+
+ break;
+
+ case GETID3_ASF_Content_Description_Object:
+ // Content Description Object: (optional, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Content Description object - GETID3_ASF_Content_Description_Object
+ // Object Size QWORD 64 // size of Content Description object, including 34 bytes of Content Description Object header
+ // Title Length WORD 16 // number of bytes in Title field
+ // Author Length WORD 16 // number of bytes in Author field
+ // Copyright Length WORD 16 // number of bytes in Copyright field
+ // Description Length WORD 16 // number of bytes in Description field
+ // Rating Length WORD 16 // number of bytes in Rating field
+ // Title WCHAR 16 // array of Unicode characters - Title
+ // Author WCHAR 16 // array of Unicode characters - Author
+ // Copyright WCHAR 16 // array of Unicode characters - Copyright
+ // Description WCHAR 16 // array of Unicode characters - Description
+ // Rating WCHAR 16 // array of Unicode characters - Rating
+
+ // shortcut
+ $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;
+ $thisfile_asf_contentdescriptionobject['title_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_contentdescriptionobject['author_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_contentdescriptionobject['copyright_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_contentdescriptionobject['description_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_contentdescriptionobject['rating_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_contentdescriptionobject['title'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['title_length']);
+ $offset += $thisfile_asf_contentdescriptionobject['title_length'];
+ $thisfile_asf_contentdescriptionobject['author'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['author_length']);
+ $offset += $thisfile_asf_contentdescriptionobject['author_length'];
+ $thisfile_asf_contentdescriptionobject['copyright'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['copyright_length']);
+ $offset += $thisfile_asf_contentdescriptionobject['copyright_length'];
+ $thisfile_asf_contentdescriptionobject['description'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['description_length']);
+ $offset += $thisfile_asf_contentdescriptionobject['description_length'];
+ $thisfile_asf_contentdescriptionobject['rating'] = substr($ASFHeaderData, $offset, $thisfile_asf_contentdescriptionobject['rating_length']);
+ $offset += $thisfile_asf_contentdescriptionobject['rating_length'];
+
+ $ASFcommentKeysToCopy = array('title'=>'title', 'author'=>'artist', 'copyright'=>'copyright', 'description'=>'comment', 'rating'=>'rating');
+ foreach ($ASFcommentKeysToCopy as $keytocopyfrom => $keytocopyto) {
+ if (!empty($thisfile_asf_contentdescriptionobject[$keytocopyfrom])) {
+ $thisfile_asf_comments[$keytocopyto][] = $this->TrimTerm($thisfile_asf_contentdescriptionobject[$keytocopyfrom]);
+ }
+ }
+ break;
+
+ case GETID3_ASF_Extended_Content_Description_Object:
+ // Extended Content Description Object: (optional, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Extended Content Description object - GETID3_ASF_Extended_Content_Description_Object
+ // Object Size QWORD 64 // size of ExtendedContent Description object, including 26 bytes of Extended Content Description Object header
+ // Content Descriptors Count WORD 16 // number of entries in Content Descriptors list
+ // Content Descriptors array of: variable //
+ // * Descriptor Name Length WORD 16 // size in bytes of Descriptor Name field
+ // * Descriptor Name WCHAR variable // array of Unicode characters - Descriptor Name
+ // * Descriptor Value Data Type WORD 16 // Lookup array:
+ // 0x0000 = Unicode String (variable length)
+ // 0x0001 = BYTE array (variable length)
+ // 0x0002 = BOOL (DWORD, 32 bits)
+ // 0x0003 = DWORD (DWORD, 32 bits)
+ // 0x0004 = QWORD (QWORD, 64 bits)
+ // 0x0005 = WORD (WORD, 16 bits)
+ // * Descriptor Value Length WORD 16 // number of bytes stored in Descriptor Value field
+ // * Descriptor Value variable variable // value for Content Descriptor
+
+ // shortcut
+ $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;
+ $thisfile_asf_extendedcontentdescriptionobject['content_descriptors_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ 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['base_offset'] = $offset + 30;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name'] = substr($ASFHeaderData, $offset, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length']);
+ $offset += $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name_length'];
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = substr($ASFHeaderData, $offset, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length']);
+ $offset += $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_length'];
+ switch ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type']) {
+ case 0x0000: // Unicode string
+ break;
+
+ case 0x0001: // BYTE array
+ // do nothing
+ break;
+
+ case 0x0002: // BOOL
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = (bool) getid3_lib::LittleEndian2Int($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
+ break;
+
+ case 0x0003: // DWORD
+ case 0x0004: // QWORD
+ case 0x0005: // WORD
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'] = getid3_lib::LittleEndian2Int($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
+ break;
+
+ default:
+ $info['warning'][] = 'extended_content_description.content_descriptors.'.$ExtendedContentDescriptorsCounter.'.value_type is invalid ('.$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type'].')';
+ //return false;
+ break;
+ }
+ switch ($this->TrimConvert(strtolower($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name']))) {
+
+ case 'wm/albumartist':
+ case 'artist':
+ // Note: not 'artist', that comes from 'author' tag
+ $thisfile_asf_comments['albumartist'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ break;
+
+ case 'wm/albumtitle':
+ case 'album':
+ $thisfile_asf_comments['album'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ break;
+
+ case 'wm/genre':
+ case 'genre':
+ $thisfile_asf_comments['genre'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ break;
+
+ case 'wm/partofset':
+ $thisfile_asf_comments['partofset'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ break;
+
+ 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) {
+ if (preg_match('/^[0-9\x00]+$/', $value)) {
+ $thisfile_asf_comments['track'][$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']));
+ }
+ break;
+
+ case 'wm/year':
+ case 'year':
+ case 'date':
+ $thisfile_asf_comments['year'] = array( $this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ break;
+
+ case 'wm/lyrics':
+ case 'lyrics':
+ $thisfile_asf_comments['lyrics'] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ break;
+
+ case 'isvbr':
+ if ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']) {
+ $thisfile_audio['bitrate_mode'] = 'vbr';
+ $thisfile_video['bitrate_mode'] = 'vbr';
+ }
+ 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'=>$info['encoding']);
+ fwrite($tempfilehandle, $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
+ fclose($tempfilehandle);
+
+ $getid3_temp = new getID3();
+ $getid3_temp->openfile($tempfile);
+ $getid3_id3v2 = new getid3_id3v2($getid3_temp);
+ $getid3_id3v2->Analyze();
+ $info['id3v2'] = $getid3_temp->info['id3v2'];
+ unset($getid3_temp, $getid3_id3v2);
+
+ unlink($tempfile);
+ }
+ break;
+
+ case 'wm/encodingtime':
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['encoding_time_unix'] = $this->FILETIMEtoUNIXtime($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
+ $thisfile_asf_comments['encoding_time_unix'] = array($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['encoding_time_unix']);
+ break;
+
+ case '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_size'] = getid3_lib::LittleEndian2Int(substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 4));
+ $wm_picture_offset += 4;
+
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = '';
+ do {
+ $next_byte_pair = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 2);
+ $wm_picture_offset += 2;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] .= $next_byte_pair;
+ } while ($next_byte_pair !== "\x00\x00");
+
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_description'] = '';
+ do {
+ $next_byte_pair = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset, 2);
+ $wm_picture_offset += 2;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_description'] .= $next_byte_pair;
+ } while ($next_byte_pair !== "\x00\x00");
+
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['dataoffset'] = $wm_picture_offset;
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'] = substr($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value'], $wm_picture_offset);
+ unset($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']);
+
+ $imageinfo = array();
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = '';
+ $imagechunkcheck = getid3_lib::GetDataImageSize($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'], $imageinfo);
+ unset($imageinfo);
+ if (!empty($imagechunkcheck)) {
+ $thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]);
+ }
+ if (!isset($thisfile_asf_comments['picture'])) {
+ $thisfile_asf_comments['picture'] = array();
+ }
+ $thisfile_asf_comments['picture'][] = array('data'=>$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['data'], 'image_mime'=>$thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['image_mime']);
+*/
+ break;
+
+ default:
+ switch ($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value_type']) {
+ case 0: // Unicode string
+ if (substr($this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name']), 0, 3) == 'WM/') {
+ $thisfile_asf_comments[str_replace('wm/', '', strtolower($this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['name'])))] = array($this->TrimTerm($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
+ }
+ break;
+
+ case 1:
+ break;
+ }
+ break;
+ }
+
+ }
+ break;
+
+ case GETID3_ASF_Stream_Bitrate_Properties_Object:
+ // Stream Bitrate Properties Object: (optional, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Stream Bitrate Properties object - GETID3_ASF_Stream_Bitrate_Properties_Object
+ // Object Size QWORD 64 // size of Extended Content Description object, including 26 bytes of Stream Bitrate Properties Object header
+ // Bitrate Records Count WORD 16 // number of records in Bitrate Records
+ // Bitrate Records array of: variable //
+ // * Flags WORD 16 //
+ // * * Stream Number bits 7 (0x007F) // number of this stream
+ // * * Reserved bits 9 (0xFF80) // hardcoded: 0
+ // * Average Bitrate DWORD 32 // in bits per second
+
+ // shortcut
+ $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;
+ $thisfile_asf_streambitratepropertiesobject['bitrate_records_count'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitratepropertiesobject['bitrate_records_count']; $BitrateRecordsCounter++) {
+ $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags']['stream_number'] = $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['flags_raw'] & 0x007F;
+ $thisfile_asf_streambitratepropertiesobject['bitrate_records'][$BitrateRecordsCounter]['bitrate'] = getid3_lib::LittleEndian2Int(substr($ASFHeaderData, $offset, 4));
+ $offset += 4;
+ }
+ break;
+
+ case GETID3_ASF_Padding_Object:
+ // Padding Object: (optional)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Padding object - GETID3_ASF_Padding_Object
+ // Object Size QWORD 64 // size of Padding object, including 24 bytes of ASF Padding Object header
+ // Padding Data BYTESTREAM variable // ignore
+
+ // shortcut
+ $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;
+ $thisfile_asf_paddingobject['padding_length'] = $thisfile_asf_paddingobject['objectsize'] - 16 - 8;
+ $thisfile_asf_paddingobject['padding'] = substr($ASFHeaderData, $offset, $thisfile_asf_paddingobject['padding_length']);
+ $offset += ($NextObjectSize - 16 - 8);
+ break;
+
+ case GETID3_ASF_Extended_Content_Encryption_Object:
+ case GETID3_ASF_Content_Encryption_Object:
+ // WMA DRM - just ignore
+ $offset += ($NextObjectSize - 16 - 8);
+ break;
+
+ default:
+ // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
+ if ($this->GUIDname($NextObjectGUIDtext)) {
+ $info['warning'][] = 'unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF header at offset '.($offset - 16 - 8);
+ } else {
+ $info['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'])) {
+ $ASFbitrateAudio = 0;
+ $ASFbitrateVideo = 0;
+ for ($BitrateRecordsCounter = 0; $BitrateRecordsCounter < $thisfile_asf_streambitrateproperties['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'];
+ break;
+
+ case 2:
+ $ASFbitrateAudio += $thisfile_asf_streambitrateproperties['bitrate_records'][$BitrateRecordsCounter]['bitrate'];
+ break;
+
+ default:
+ // do nothing
+ break;
+ }
+ }
+ }
+ if ($ASFbitrateAudio > 0) {
+ $thisfile_audio['bitrate'] = $ASFbitrateAudio;
+ }
+ if ($ASFbitrateVideo > 0) {
+ $thisfile_video['bitrate'] = $ASFbitrateVideo;
+ }
+ }
+ if (isset($thisfile_asf['stream_properties_object']) && is_array($thisfile_asf['stream_properties_object'])) {
+
+ $thisfile_audio['bitrate'] = 0;
+ $thisfile_video['bitrate'] = 0;
+
+ foreach ($thisfile_asf['stream_properties_object'] as $streamnumber => $streamdata) {
+
+ switch ($streamdata['stream_type']) {
+ case GETID3_ASF_Audio_Media:
+ // Field Name Field Type Size (bits)
+ // Codec ID / Format Tag WORD 16 // unique ID of audio codec - defined as wFormatTag field of WAVEFORMATEX structure
+ // Number of Channels WORD 16 // number of channels of audio - defined as nChannels field of WAVEFORMATEX structure
+ // Samples Per Second DWORD 32 // in Hertz - defined as nSamplesPerSec field of WAVEFORMATEX structure
+ // Average number of Bytes/sec DWORD 32 // bytes/sec of audio stream - defined as nAvgBytesPerSec field of WAVEFORMATEX structure
+ // Block Alignment WORD 16 // block size in bytes of audio codec - defined as nBlockAlign field of WAVEFORMATEX structure
+ // Bits per sample WORD 16 // bits per sample of mono data. set to zero for variable bitrate codecs. defined as wBitsPerSample field of WAVEFORMATEX structure
+ // Codec Specific Data Size WORD 16 // size in bytes of Codec Specific Data buffer - defined as cbSize field of WAVEFORMATEX structure
+ // Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes
+
+ // shortcut
+ $thisfile_asf['audio_media'][$streamnumber] = array();
+ $thisfile_asf_audiomedia_currentstream = &$thisfile_asf['audio_media'][$streamnumber];
+
+ $audiomediaoffset = 0;
+
+ $thisfile_asf_audiomedia_currentstream = getid3_riff::RIFFparseWAVEFORMATex(substr($streamdata['type_specific_data'], $audiomediaoffset, 16));
+ $audiomediaoffset += 16;
+
+ $thisfile_audio['lossless'] = false;
+ switch ($thisfile_asf_audiomedia_currentstream['raw']['wFormatTag']) {
+ case 0x0001: // PCM
+ case 0x0163: // WMA9 Lossless
+ $thisfile_audio['lossless'] = true;
+ break;
+ }
+
+ if (!empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) {
+ foreach ($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'] as $dummy => $dataarray) {
+ if (isset($dataarray['flags']['stream_number']) && ($dataarray['flags']['stream_number'] == $streamnumber)) {
+ $thisfile_asf_audiomedia_currentstream['bitrate'] = $dataarray['bitrate'];
+ $thisfile_audio['bitrate'] += $dataarray['bitrate'];
+ break;
+ }
+ }
+ } else {
+ if (!empty($thisfile_asf_audiomedia_currentstream['bytes_sec'])) {
+ $thisfile_audio['bitrate'] += $thisfile_asf_audiomedia_currentstream['bytes_sec'] * 8;
+ } elseif (!empty($thisfile_asf_audiomedia_currentstream['bitrate'])) {
+ $thisfile_audio['bitrate'] += $thisfile_asf_audiomedia_currentstream['bitrate'];
+ }
+ }
+ $thisfile_audio['streams'][$streamnumber] = $thisfile_asf_audiomedia_currentstream;
+ $thisfile_audio['streams'][$streamnumber]['wformattag'] = $thisfile_asf_audiomedia_currentstream['raw']['wFormatTag'];
+ $thisfile_audio['streams'][$streamnumber]['lossless'] = $thisfile_audio['lossless'];
+ $thisfile_audio['streams'][$streamnumber]['bitrate'] = $thisfile_audio['bitrate'];
+ $thisfile_audio['streams'][$streamnumber]['dataformat'] = 'wma';
+ unset($thisfile_audio['streams'][$streamnumber]['raw']);
+
+ $thisfile_asf_audiomedia_currentstream['codec_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $audiomediaoffset, 2));
+ $audiomediaoffset += 2;
+ $thisfile_asf_audiomedia_currentstream['codec_data'] = substr($streamdata['type_specific_data'], $audiomediaoffset, $thisfile_asf_audiomedia_currentstream['codec_data_size']);
+ $audiomediaoffset += $thisfile_asf_audiomedia_currentstream['codec_data_size'];
+
+ break;
+
+ case GETID3_ASF_Video_Media:
+ // Field Name Field Type Size (bits)
+ // Encoded Image Width DWORD 32 // width of image in pixels
+ // Encoded Image Height DWORD 32 // height of image in pixels
+ // Reserved Flags BYTE 8 // hardcoded: 0x02
+ // Format Data Size WORD 16 // size of Format Data field in bytes
+ // Format Data array of: variable //
+ // * Format Data Size DWORD 32 // number of bytes in Format Data field, in bytes - defined as biSize field of BITMAPINFOHEADER structure
+ // * Image Width LONG 32 // width of encoded image in pixels - defined as biWidth field of BITMAPINFOHEADER structure
+ // * Image Height LONG 32 // height of encoded image in pixels - defined as biHeight field of BITMAPINFOHEADER structure
+ // * Reserved WORD 16 // hardcoded: 0x0001 - defined as biPlanes field of BITMAPINFOHEADER structure
+ // * Bits Per Pixel Count WORD 16 // bits per pixel - defined as biBitCount field of BITMAPINFOHEADER structure
+ // * Compression ID FOURCC 32 // fourcc of video codec - defined as biCompression field of BITMAPINFOHEADER structure
+ // * Image Size DWORD 32 // image size in bytes - defined as biSizeImage field of BITMAPINFOHEADER structure
+ // * Horizontal Pixels / Meter DWORD 32 // horizontal resolution of target device in pixels per meter - defined as biXPelsPerMeter field of BITMAPINFOHEADER structure
+ // * Vertical Pixels / Meter DWORD 32 // vertical resolution of target device in pixels per meter - defined as biYPelsPerMeter field of BITMAPINFOHEADER structure
+ // * Colors Used Count DWORD 32 // number of color indexes in the color table that are actually used - defined as biClrUsed field of BITMAPINFOHEADER structure
+ // * Important Colors Count DWORD 32 // number of color index required for displaying bitmap. if zero, all colors are required. defined as biClrImportant field of BITMAPINFOHEADER structure
+ // * Codec Specific Data BYTESTREAM variable // array of codec-specific data bytes
+
+ // shortcut
+ $thisfile_asf['video_media'][$streamnumber] = array();
+ $thisfile_asf_videomedia_currentstream = &$thisfile_asf['video_media'][$streamnumber];
+
+ $videomediaoffset = 0;
+ $thisfile_asf_videomedia_currentstream['image_width'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['image_height'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['flags'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 1));
+ $videomediaoffset += 1;
+ $thisfile_asf_videomedia_currentstream['format_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
+ $videomediaoffset += 2;
+ $thisfile_asf_videomedia_currentstream['format_data']['format_data_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['image_width'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['image_height'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['reserved'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
+ $videomediaoffset += 2;
+ $thisfile_asf_videomedia_currentstream['format_data']['bits_per_pixel'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 2));
+ $videomediaoffset += 2;
+ $thisfile_asf_videomedia_currentstream['format_data']['codec_fourcc'] = substr($streamdata['type_specific_data'], $videomediaoffset, 4);
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['image_size'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['horizontal_pels'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['vertical_pels'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['colors_used'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['colors_important'] = getid3_lib::LittleEndian2Int(substr($streamdata['type_specific_data'], $videomediaoffset, 4));
+ $videomediaoffset += 4;
+ $thisfile_asf_videomedia_currentstream['format_data']['codec_data'] = substr($streamdata['type_specific_data'], $videomediaoffset);
+
+ if (!empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) {
+ foreach ($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'] as $dummy => $dataarray) {
+ if (isset($dataarray['flags']['stream_number']) && ($dataarray['flags']['stream_number'] == $streamnumber)) {
+ $thisfile_asf_videomedia_currentstream['bitrate'] = $dataarray['bitrate'];
+ $thisfile_video['streams'][$streamnumber]['bitrate'] = $dataarray['bitrate'];
+ $thisfile_video['bitrate'] += $dataarray['bitrate'];
+ break;
+ }
+ }
+ }
+
+ $thisfile_asf_videomedia_currentstream['format_data']['codec'] = getid3_riff::RIFFfourccLookup($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'];
+ $thisfile_video['streams'][$streamnumber]['resolution_x'] = $thisfile_asf_videomedia_currentstream['image_width'];
+ $thisfile_video['streams'][$streamnumber]['resolution_y'] = $thisfile_asf_videomedia_currentstream['image_height'];
+ $thisfile_video['streams'][$streamnumber]['bits_per_sample'] = $thisfile_asf_videomedia_currentstream['format_data']['bits_per_pixel'];
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ while (ftell($this->getid3->fp) < $info['avdataend']) {
+ $NextObjectDataHeader = fread($this->getid3->fp, 24);
+ $offset = 0;
+ $NextObjectGUID = substr($NextObjectDataHeader, 0, 16);
+ $offset += 16;
+ $NextObjectGUIDtext = $this->BytestringToGUID($NextObjectGUID);
+ $NextObjectSize = getid3_lib::LittleEndian2Int(substr($NextObjectDataHeader, $offset, 8));
+ $offset += 8;
+
+ switch ($NextObjectGUID) {
+ case GETID3_ASF_Data_Object:
+ // Data Object: (mandatory, one only)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Data object - GETID3_ASF_Data_Object
+ // Object Size QWORD 64 // size of Data object, including 50 bytes of Data Object header. may be 0 if FilePropertiesObject.BroadcastFlag == 1
+ // File ID GUID 128 // unique identifier. identical to File ID field in Header Object
+ // Total Data Packets QWORD 64 // number of Data Packet entries in Data Object. invalid if FilePropertiesObject.BroadcastFlag == 1
+ // Reserved WORD 16 // hardcoded: 0x0101
+
+ // shortcut
+ $thisfile_asf['data_object'] = array();
+ $thisfile_asf_dataobject = &$thisfile_asf['data_object'];
+
+ $DataObjectData = $NextObjectDataHeader.fread($this->getid3->fp, 50 - 24);
+ $offset = 24;
+
+ $thisfile_asf_dataobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_dataobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_dataobject['objectsize'] = $NextObjectSize;
+
+ $thisfile_asf_dataobject['fileid'] = substr($DataObjectData, $offset, 16);
+ $offset += 16;
+ $thisfile_asf_dataobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_dataobject['fileid']);
+ $thisfile_asf_dataobject['total_data_packets'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_dataobject['reserved'] = getid3_lib::LittleEndian2Int(substr($DataObjectData, $offset, 2));
+ $offset += 2;
+ if ($thisfile_asf_dataobject['reserved'] != 0x0101) {
+ $info['warning'][] = 'data_object.reserved ('.getid3_lib::PrintHexBytes($thisfile_asf_dataobject['reserved']).') does not match expected value of "0x0101"';
+ //return false;
+ break;
+ }
+
+ // Data Packets array of: variable //
+ // * Error Correction Flags BYTE 8 //
+ // * * Error Correction Data Length bits 4 // if Error Correction Length Type == 00, size of Error Correction Data in bytes, else hardcoded: 0000
+ // * * Opaque Data Present bits 1 //
+ // * * Error Correction Length Type bits 2 // number of bits for size of the error correction data. hardcoded: 00
+ // * * Error Correction Present bits 1 // If set, use Opaque Data Packet structure, else use Payload structure
+ // * Error Correction Data
+
+ $info['avdataoffset'] = ftell($this->getid3->fp);
+ fseek($this->getid3->fp, ($thisfile_asf_dataobject['objectsize'] - 50), SEEK_CUR); // skip actual audio/video data
+ $info['avdataend'] = ftell($this->getid3->fp);
+ break;
+
+ case GETID3_ASF_Simple_Index_Object:
+ // Simple Index Object: (optional, recommended, one per video stream)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for Simple Index object - GETID3_ASF_Data_Object
+ // Object Size QWORD 64 // size of Simple Index object, including 56 bytes of Simple Index Object header
+ // File ID GUID 128 // unique identifier. may be zero or identical to File ID field in Data Object and Header Object
+ // Index Entry Time Interval QWORD 64 // interval between index entries in 100-nanosecond units
+ // Maximum Packet Count DWORD 32 // maximum packet count for all index entries
+ // Index Entries Count DWORD 32 // number of Index Entries structures
+ // Index Entries array of: variable //
+ // * Packet Number DWORD 32 // number of the Data Packet associated with this index entry
+ // * Packet Count WORD 16 // number of Data Packets to sent at this index entry
+
+ // shortcut
+ $thisfile_asf['simple_index_object'] = array();
+ $thisfile_asf_simpleindexobject = &$thisfile_asf['simple_index_object'];
+
+ $SimpleIndexObjectData = $NextObjectDataHeader.fread($this->getid3->fp, 56 - 24);
+ $offset = 24;
+
+ $thisfile_asf_simpleindexobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_simpleindexobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_simpleindexobject['objectsize'] = $NextObjectSize;
+
+ $thisfile_asf_simpleindexobject['fileid'] = substr($SimpleIndexObjectData, $offset, 16);
+ $offset += 16;
+ $thisfile_asf_simpleindexobject['fileid_guid'] = $this->BytestringToGUID($thisfile_asf_simpleindexobject['fileid']);
+ $thisfile_asf_simpleindexobject['index_entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 8));
+ $offset += 8;
+ $thisfile_asf_simpleindexobject['maximum_packet_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_simpleindexobject['index_entries_count'] = getid3_lib::LittleEndian2Int(substr($SimpleIndexObjectData, $offset, 4));
+ $offset += 4;
+
+ $IndexEntriesData = $SimpleIndexObjectData.fread($this->getid3->fp, 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;
+ $thisfile_asf_simpleindexobject['index_entries'][$IndexEntriesCounter]['packet_count'] = getid3_lib::LittleEndian2Int(substr($IndexEntriesData, $offset, 4));
+ $offset += 2;
+ }
+
+ break;
+
+ case GETID3_ASF_Index_Object:
+ // 6.2 ASF top-level Index Object (optional but recommended when appropriate, 0 or 1)
+ // Field Name Field Type Size (bits)
+ // Object ID GUID 128 // GUID for the Index Object - GETID3_ASF_Index_Object
+ // Object Size QWORD 64 // Specifies the size, in bytes, of the Index Object, including at least 34 bytes of Index Object header
+ // Index Entry Time Interval DWORD 32 // Specifies the time interval between each index entry in ms.
+ // Index Specifiers Count WORD 16 // Specifies the number of Index Specifiers structures in this Index Object.
+ // Index Blocks Count DWORD 32 // Specifies the number of Index Blocks structures in this Index Object.
+
+ // Index Entry Time Interval DWORD 32 // Specifies the time interval between index entries in milliseconds. This value cannot be 0.
+ // 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 Index Type values as follows:
+ // 1 = Nearest Past Data Packet - indexes point to the data packet whose presentation time is closest to the index entry time.
+ // 2 = Nearest Past Media Object - indexes point to the closest data packet containing an entire object or first fragment of an object.
+ // 3 = Nearest Past Cleanpoint. - indexes point to the closest data packet containing an entire object (or first fragment of an object) that has the Cleanpoint Flag set.
+ // Nearest Past Cleanpoint is the most common type of index.
+ // Index Entry Count DWORD 32 // Specifies the number of Index Entries in the block.
+ // * Block Positions QWORD varies // Specifies a list of byte offsets of the beginnings of the blocks relative to the beginning of the first Data Packet (i.e., the beginning of the Data Object + 50 bytes). The number of entries in this list is specified by the value of the Index Specifiers Count field. The order of those byte offsets is tied to the order in which Index Specifiers are listed.
+ // * Index Entries array of: varies //
+ // * * Offsets DWORD varies // An offset value of 0xffffffff indicates an invalid offset value
+
+ // shortcut
+ $thisfile_asf['asf_index_object'] = array();
+ $thisfile_asf_asfindexobject = &$thisfile_asf['asf_index_object'];
+
+ $ASFIndexObjectData = $NextObjectDataHeader.fread($this->getid3->fp, 34 - 24);
+ $offset = 24;
+
+ $thisfile_asf_asfindexobject['objectid'] = $NextObjectGUID;
+ $thisfile_asf_asfindexobject['objectid_guid'] = $NextObjectGUIDtext;
+ $thisfile_asf_asfindexobject['objectsize'] = $NextObjectSize;
+
+ $thisfile_asf_asfindexobject['entry_time_interval'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
+ $offset += 4;
+ $thisfile_asf_asfindexobject['index_specifiers_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_asfindexobject['index_blocks_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
+ $offset += 4;
+
+ $ASFIndexObjectData .= fread($this->getid3->fp, 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;
+ $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['stream_number'] = $IndexSpecifierStreamNumber;
+ $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 2));
+ $offset += 2;
+ $thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type_text'] = $this->ASFIndexObjectIndexTypeLookup($thisfile_asf_asfindexobject['index_specifiers'][$IndexSpecifiersCounter]['index_type']);
+ }
+
+ $ASFIndexObjectData .= fread($this->getid3->fp, 4);
+ $thisfile_asf_asfindexobject['index_entry_count'] = getid3_lib::LittleEndian2Int(substr($ASFIndexObjectData, $offset, 4));
+ $offset += 4;
+
+ $ASFIndexObjectData .= fread($this->getid3->fp, 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($this->getid3->fp, 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));
+ $offset += 4;
+ }
+ }
+ break;
+
+
+ default:
+ // Implementations shall ignore any standard or non-standard object that they do not know how to handle.
+ if ($this->GUIDname($NextObjectGUIDtext)) {
+ $info['warning'][] = 'unhandled GUID "'.$this->GUIDname($NextObjectGUIDtext).'" {'.$NextObjectGUIDtext.'} in ASF body at offset '.($offset - 16 - 8);
+ } else {
+ $info['warning'][] = 'unknown GUID {'.$NextObjectGUIDtext.'} in ASF body at offset '.(ftell($this->getid3->fp) - 16 - 8);
+ }
+ fseek($this->getid3->fp, ($NextObjectSize - 16 - 8), SEEK_CUR);
+ break;
+ }
+ }
+
+ if (isset($thisfile_asf_codeclistobject['codec_entries']) && is_array($thisfile_asf_codeclistobject['codec_entries'])) {
+ foreach ($thisfile_asf_codeclistobject['codec_entries'] as $streamnumber => $streamdata) {
+ switch ($streamdata['information']) {
+ case 'WMV1':
+ case 'WMV2':
+ case 'WMV3':
+ case 'MSS1':
+ case 'MSS2':
+ case 'WMVA':
+ case 'WVC1':
+ case 'WMVP':
+ case 'WVP2':
+ $thisfile_video['dataformat'] = 'wmv';
+ $info['mime_type'] = 'video/x-ms-wmv';
+ break;
+
+ case 'MP42':
+ case 'MP43':
+ case 'MP4S':
+ case 'mp4s':
+ $thisfile_video['dataformat'] = 'asf';
+ $info['mime_type'] = 'video/x-ms-asf';
+ break;
+
+ default:
+ switch ($streamdata['type_raw']) {
+ case 1:
+ if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) {
+ $thisfile_video['dataformat'] = 'wmv';
+ if ($info['mime_type'] == 'video/x-ms-asf') {
+ $info['mime_type'] = 'video/x-ms-wmv';
+ }
+ }
+ break;
+
+ case 2:
+ if (strstr($this->TrimConvert($streamdata['name']), 'Windows Media')) {
+ $thisfile_audio['dataformat'] = 'wma';
+ if ($info['mime_type'] == 'video/x-ms-asf') {
+ $info['mime_type'] = 'audio/x-ms-wma';
+ }
+ }
+ break;
+
+ }
+ break;
+ }
+ }
+ }
+
+ switch (isset($thisfile_audio['codec']) ? $thisfile_audio['codec'] : '') {
+ case 'MPEG Layer-3':
+ $thisfile_audio['dataformat'] = 'mp3';
+ break;
+
+ default:
+ break;
+ }
+
+ if (isset($thisfile_asf_codeclistobject['codec_entries'])) {
+ foreach ($thisfile_asf_codeclistobject['codec_entries'] as $streamnumber => $streamdata) {
+ switch ($streamdata['type_raw']) {
+
+ case 1: // video
+ $thisfile_video['encoder'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][$streamnumber]['name']);
+ break;
+
+ case 2: // audio
+ $thisfile_audio['encoder'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][$streamnumber]['name']);
+
+ // AH 2003-10-01
+ $thisfile_audio['encoder_options'] = $this->TrimConvert($thisfile_asf_codeclistobject['codec_entries'][0]['description']);
+
+ $thisfile_audio['codec'] = $thisfile_audio['encoder'];
+ break;
+
+ default:
+ $info['warning'][] = 'Unknown streamtype: [codec_list_object][codec_entries]['.$streamnumber.'][type_raw] == '.$streamdata['type_raw'];
+ break;
+
+ }
+ }
+ }
+
+ 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');
+ }
+ if (!empty($thisfile_video['dataformat'])) {
+ $thisfile_video['lossless'] = (isset($thisfile_audio['lossless']) ? $thisfile_audio['lossless'] : false);
+ $thisfile_video['pixel_aspect_ratio'] = (isset($thisfile_audio['pixel_aspect_ratio']) ? $thisfile_audio['pixel_aspect_ratio'] : (float) 1);
+ $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;
+ foreach ($thisfile_video['streams'] as $key => $valuearray) {
+ if (($valuearray['resolution_x'] > $thisfile_video['streams']['resolution_x']) || ($valuearray['resolution_y'] > $thisfile_video['streams']['resolution_y'])) {
+ $thisfile_video['resolution_x'] = $valuearray['resolution_x'];
+ $thisfile_video['resolution_y'] = $valuearray['resolution_y'];
+ }
+ }
+ }
+ $info['bitrate'] = (isset($thisfile_audio['bitrate']) ? $thisfile_audio['bitrate'] : 0) + (isset($thisfile_video['bitrate']) ? $thisfile_video['bitrate'] : 0);
+
+ 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';
+ }
+
+ return (isset($ASFCodecListObjectTypeLookup[$CodecListType]) ? $ASFCodecListObjectTypeLookup[$CodecListType] : 'Invalid Codec Type');
+ }
+
+ 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', // http://cpan.uwinnipeg.ca/htdocs/Audio-WMA/Audio/WMA.pm.html
+ 'GETID3_ASF_Compatibility_Object' => '26F18B5D-4584-47EC-9F5F-0E651F0452C9', // http://cpan.uwinnipeg.ca/htdocs/Audio-WMA/Audio/WMA.pm.html
+ );
+ return $GUIDarray;
+ }
+
+ static function GUIDname($GUIDstring) {
+ static $GUIDarray = array();
+ if (empty($GUIDarray)) {
+ $GUIDarray = getid3_asf::KnownGUIDs();
+ }
+ return array_search($GUIDstring, $GUIDarray);
+ }
+
+ static function ASFIndexObjectIndexTypeLookup($id) {
+ static $ASFIndexObjectIndexTypeLookup = array();
+ if (empty($ASFIndexObjectIndexTypeLookup)) {
+ $ASFIndexObjectIndexTypeLookup[1] = 'Nearest Past Data Packet';
+ $ASFIndexObjectIndexTypeLookup[2] = 'Nearest Past Media Object';
+ $ASFIndexObjectIndexTypeLookup[3] = 'Nearest Past Cleanpoint';
+ }
+ return (isset($ASFIndexObjectIndexTypeLookup[$id]) ? $ASFIndexObjectIndexTypeLookup[$id] : 'invalid');
+ }
+
+ 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
+ // 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;
+ }
+
+ 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 .= '-';
+ $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);
+ }
+
+ 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
+ // 116444736000000000 = 10000000 * 60 * 60 * 24 * 365 * 369 + 89 leap days
+ if ($round) {
+ return intval(round(($FILETIME - 116444736000000000) / 10000000));
+ }
+ 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');
+ }
+ return (isset($WMpictureTypeLookup[$WMpictureType]) ? $WMpictureTypeLookup[$WMpictureType] : '');
+ }
+
+ function ASF_HeaderExtensionObjectDataParse(&$asf_header_extension_object_data, &$unhandled_sections) {
+ // http://msdn.microsoft.com/en-us/library/bb643323.aspx
+
+ $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, 4));
+ $offset += 4;
+
+ $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'] = getid3_lib::LittleEndian2Int(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_length'] = getid3_lib::LittleEndian2Int(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_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'] = $this->ASFmetadataLibraryObjectDataTypeLookup($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'] = $this->ASFmetadataLibraryObjectDataTypeLookup($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;
+
+ default:
+ $unhandled_sections++;
+ if ($this->GUIDname($thisObject['guid_text'])) {
+ $this->getid3->info['warning'][] = 'unhandled Header Extension Object GUID "'.$this->GUIDname($thisObject['guid_text']).'" {'.$thisObject['guid_text'].'} at offset '.($offset - 16 - 8);
+ } else {
+ $this->getid3->info['warning'][] = 'unknown Header Extension Object GUID {'.$thisObject['guid_text'].'} in at offset '.($offset - 16 - 8);
+ }
+ break;
+ }
+ $HeaderExtensionObjectParsed[] = $thisObject;
+
+ $objectOffset += $thisObject['size'];
+ }
+ return $HeaderExtensionObjectParsed;
+ }
+
+
+ static function ASFmetadataLibraryObjectDataTypeLookup($id) {
+ static $ASFmetadataLibraryObjectDataTypeLookup = 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($ASFmetadataLibraryObjectDataTypeLookup[$id]) ? $ASFmetadataLibraryObjectDataTypeLookup[$id] : 'invalid');
+ }
+
+ 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'] = $this->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
+ static function TrimConvert($string) {
+ return trim(getid3_lib::iconv_fallback('UTF-16LE', 'ISO-8859-1', getid3_asf::TrimTerm($string)), ' ');
+ }
+
+
+ // Remove terminator 00 00
+ static function TrimTerm($string) {
+ // remove terminator, only if present (it should be, but...)
+ if (substr($string, -2) === "\x00\x00") {
+ $string = substr($string, 0, -2);
+ }
+ return $string;
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/app/Library/getid3/module.audio-video.bink.php b/app/Library/getid3/module.audio-video.bink.php
new file mode 100644
index 00000000..0a321396
--- /dev/null
+++ b/app/Library/getid3/module.audio-video.bink.php
@@ -0,0 +1,73 @@
+ //
+// 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 extends getid3_handler
+{
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+$info['error'][] = 'Bink / Smacker files not properly processed by this version of getID3() ['.$this->getid3->version().']';
+
+ fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
+ $fileTypeID = fread($this->getid3->fp, 3);
+ switch ($fileTypeID) {
+ case 'BIK':
+ return $this->ParseBink();
+ break;
+
+ case 'SMK':
+ return $this->ParseSmacker();
+ break;
+
+ default:
+ $info['error'][] = 'Expecting "BIK" or "SMK" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($fileTypeID).'"';
+ return false;
+ break;
+ }
+
+ return true;
+
+ }
+
+ function ParseBink() {
+ $info = &$this->getid3->info;
+ $info['fileformat'] = 'bink';
+ $info['video']['dataformat'] = 'bink';
+
+ $fileData = 'BIK'.fread($this->getid3->fp, 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)) {
+ $info['error'][] = 'Probably truncated file: expecting '.$info['bink']['data_size'].' bytes, found '.($info['avdataend'] - $info['avdataoffset']);
+ }
+
+ return true;
+ }
+
+ function ParseSmacker() {
+ $info = &$this->getid3->info;
+ $info['fileformat'] = 'smacker';
+ $info['video']['dataformat'] = 'smacker';
+
+ return true;
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/app/Library/getid3/module.audio-video.flv.php b/app/Library/getid3/module.audio-video.flv.php
new file mode 100644
index 00000000..ba3cd908
--- /dev/null
+++ b/app/Library/getid3/module.audio-video.flv.php
@@ -0,0 +1,731 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+// //
+// 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() //
+// //
+/////////////////////////////////////////////////////////////////
+// //
+// 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 extends getid3_handler
+{
+ var $max_frames = 100000; // break out of the loop if too many frames have been scanned; only scan this many if meta frame does not contain useful duration
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
+
+ $FLVdataLength = $info['avdataend'] - $info['avdataoffset'];
+ $FLVheader = fread($this->getid3->fp, 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));
+
+ $magic = 'FLV';
+ if ($info['flv']['header']['signature'] != $magic) {
+ $info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['flv']['header']['signature']).'"';
+ unset($info['flv']);
+ unset($info['fileformat']);
+ return false;
+ }
+
+ $info['flv']['header']['hasAudio'] = (bool) ($TypeFlags & 0x04);
+ $info['flv']['header']['hasVideo'] = (bool) ($TypeFlags & 0x01);
+
+ $FrameSizeDataLength = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 4));
+ $FLVheaderFrameLength = 9;
+ if ($FrameSizeDataLength > $FLVheaderFrameLength) {
+ fseek($this->getid3->fp, $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 (((ftell($this->getid3->fp) + 16) < $info['avdataend']) && (($tagParseCount++ <= $this->max_frames) || !$found_valid_meta_playtime)) {
+ $ThisTagHeader = fread($this->getid3->fp, 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($this->getid3->fp) - 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 = fread($this->getid3->fp, 11);
+
+ 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 = fread($this->getid3->fp, $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));
+ $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 5, 2));
+ $PictureSizeEnc['x'] >>= 7;
+ $PictureSizeEnc['y'] >>= 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));
+ $PictureSizeEnc['y'] = getid3_lib::BigEndian2Int(substr($FLVvideoHeader, 6, 3));
+ $PictureSizeEnc['x'] >>= 7;
+ $PictureSizeEnc['y'] >>= 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;
+
+ }
+ }
+ $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;
+ fseek($this->getid3->fp, -1, SEEK_CUR);
+ $datachunk = fread($this->getid3->fp, $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;
+ }
+ fseek($this->getid3->fp, $NextOffset, SEEK_SET);
+ }
+
+ $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'] = $this->FLVaudioFormat($info['flv']['audio']['audioFormat']);
+ $info['audio']['sample_rate'] = $this->FLVaudioRate($info['flv']['audio']['audioRate']);
+ $info['audio']['bits_per_sample'] = $this->FLVaudioBitDepth($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'] = $this->FLVvideoCodec($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'] = $this->FLVaudioFormat($info['flv']['meta']['onMetaData']['audiocodecid']);
+ }
+ if (isset($info['flv']['meta']['onMetaData']['videocodecid'])) {
+ $info['video']['codec'] = $this->FLVvideoCodec($info['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();
+
+ if ($significantBits > 31) {
+ // something is broken, this is an emergency escape to prevent infinite loops
+ return 0;
+ }
+ }
+ 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/app/Library/getid3/module.audio-video.matroska.php b/app/Library/getid3/module.audio-video.matroska.php
new file mode 100644
index 00000000..b7ab6679
--- /dev/null
+++ b/app/Library/getid3/module.audio-video.matroska.php
@@ -0,0 +1,1706 @@
+ //
+// available at http://getid3.sourceforge.net //
+// or http://www.getid3.org //
+/////////////////////////////////////////////////////////////////
+// See readme.txt for more details //
+/////////////////////////////////////////////////////////////////
+// //
+// module.audio-video.matriska.php //
+// module for analyzing Matroska containers //
+// dependencies: NONE //
+// ///
+/////////////////////////////////////////////////////////////////
+
+
+// from: http://www.matroska.org/technical/specs/index.html
+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 .
+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.
+define('EBML_ID_ATTACHMENTS', 0x0941A469); // [19][41][A4][69] -- Contain attached files.
+define('EBML_ID_EBML', 0x0A45DFA3); // [1A][45][DF][A3] -- Set the EBML characteristics of the data to follow. Each EBML document has to start with this.
+define('EBML_ID_CUES', 0x0C53BB6B); // [1C][53][BB][6B] -- A top-level element to speed seeking access. All entries are local to the segment.
+define('EBML_ID_CLUSTER', 0x0F43B675); // [1F][43][B6][75] -- The lower level element containing the (monolithic) Block structure.
+define('EBML_ID_LANGUAGE', 0x02B59C); // [22][B5][9C] -- Specifies the language of the track in the Matroska languages form.
+define('EBML_ID_TRACKTIMECODESCALE', 0x03314F); // [23][31][4F] -- The scale to apply on this track to work at normal speed in relation with other tracks (mostly used to adjust video speed when the audio length differs).
+define('EBML_ID_DEFAULTDURATION', 0x03E383); // [23][E3][83] -- Number of nanoseconds (i.e. not scaled) per frame.
+define('EBML_ID_CODECNAME', 0x058688); // [25][86][88] -- A human-readable string specifying the codec.
+define('EBML_ID_CODECDOWNLOADURL', 0x06B240); // [26][B2][40] -- A URL to download about the codec used.
+define('EBML_ID_TIMECODESCALE', 0x0AD7B1); // [2A][D7][B1] -- Timecode scale in nanoseconds (1.000.000 means all timecodes in the segment are expressed in milliseconds).
+define('EBML_ID_COLOURSPACE', 0x0EB524); // [2E][B5][24] -- Same value as in AVI (32 bits).
+define('EBML_ID_GAMMAVALUE', 0x0FB523); // [2F][B5][23] -- Gamma Value.
+define('EBML_ID_CODECSETTINGS', 0x1A9697); // [3A][96][97] -- A string describing the encoding setting used.
+define('EBML_ID_CODECINFOURL', 0x1B4040); // [3B][40][40] -- A URL to find information about the codec used.
+define('EBML_ID_PREVFILENAME', 0x1C83AB); // [3C][83][AB] -- An escaped filename corresponding to the previous segment.
+define('EBML_ID_PREVUID', 0x1CB923); // [3C][B9][23] -- A unique ID to identify the previous chained segment (128 bits).
+define('EBML_ID_NEXTFILENAME', 0x1E83BB); // [3E][83][BB] -- An escaped filename corresponding to the next segment.
+define('EBML_ID_NEXTUID', 0x1EB923); // [3E][B9][23] -- A unique ID to identify the next chained segment (128 bits).
+define('EBML_ID_CONTENTCOMPALGO', 0x0254); // [42][54] -- The compression algorithm used. Algorithms that have been specified so far are:
+define('EBML_ID_CONTENTCOMPSETTINGS', 0x0255); // [42][55] -- Settings that might be needed by the decompressor. For Header Stripping (ContentCompAlgo=3), the bytes that were removed from the beggining of each frames of the track.
+define('EBML_ID_DOCTYPE', 0x0282); // [42][82] -- A string that describes the type of document that follows this EBML header ('matroska' in our case).
+define('EBML_ID_DOCTYPEREADVERSION', 0x0285); // [42][85] -- The minimum DocType version an interpreter has to support to read this file.
+define('EBML_ID_EBMLVERSION', 0x0286); // [42][86] -- The version of EBML parser used to create the file.
+define('EBML_ID_DOCTYPEVERSION', 0x0287); // [42][87] -- The version of DocType interpreter used to create the file.
+define('EBML_ID_EBMLMAXIDLENGTH', 0x02F2); // [42][F2] -- The maximum length of the IDs you'll find in this file (4 or less in Matroska).
+define('EBML_ID_EBMLMAXSIZELENGTH', 0x02F3); // [42][F3] -- The maximum length of the sizes you'll find in this file (8 or less in Matroska). This does not override the element size indicated at the beginning of an element. Elements that have an indicated size which is larger than what is allowed by EBMLMaxSizeLength shall be considered invalid.
+define('EBML_ID_EBMLREADVERSION', 0x02F7); // [42][F7] -- The minimum EBML version a parser has to support to read this file.
+define('EBML_ID_CHAPLANGUAGE', 0x037C); // [43][7C] -- The languages corresponding to the string, in the bibliographic ISO-639-2 form.
+define('EBML_ID_CHAPCOUNTRY', 0x037E); // [43][7E] -- The countries corresponding to the string, same 2 octets as in Internet domains.
+define('EBML_ID_SEGMENTFAMILY', 0x0444); // [44][44] -- A randomly generated unique ID that all segments related to each other must use (128 bits).
+define('EBML_ID_DATEUTC', 0x0461); // [44][61] -- Date of the origin of timecode (value 0), i.e. production date.
+define('EBML_ID_TAGLANGUAGE', 0x047A); // [44][7A] -- Specifies the language of the tag specified, in the Matroska languages form.
+define('EBML_ID_TAGDEFAULT', 0x0484); // [44][84] -- Indication to know if this is the default/original language to use for the given tag.
+define('EBML_ID_TAGBINARY', 0x0485); // [44][85] -- The values of the Tag if it is binary. Note that this cannot be used in the same SimpleTag as TagString.
+define('EBML_ID_TAGSTRING', 0x0487); // [44][87] -- The value of the Tag.
+define('EBML_ID_DURATION', 0x0489); // [44][89] -- Duration of the segment (based on TimecodeScale).
+define('EBML_ID_CHAPPROCESSPRIVATE', 0x050D); // [45][0D] -- Some optional data attached to the ChapProcessCodecID information. For ChapProcessCodecID = 1, it is the "DVD level" equivalent.
+define('EBML_ID_CHAPTERFLAGENABLED', 0x0598); // [45][98] -- Specify wether the chapter is enabled. It can be enabled/disabled by a Control Track. When disabled, the movie should skip all the content between the TimeStart and TimeEnd of this chapter.
+define('EBML_ID_TAGNAME', 0x05A3); // [45][A3] -- The name of the Tag that is going to be stored.
+define('EBML_ID_EDITIONENTRY', 0x05B9); // [45][B9] -- Contains all information about a segment edition.
+define('EBML_ID_EDITIONUID', 0x05BC); // [45][BC] -- A unique ID to identify the edition. It's useful for tagging an edition.
+define('EBML_ID_EDITIONFLAGHIDDEN', 0x05BD); // [45][BD] -- If an edition is hidden (1), it should not be available to the user interface (but still to Control Tracks).
+define('EBML_ID_EDITIONFLAGDEFAULT', 0x05DB); // [45][DB] -- If a flag is set (1) the edition should be used as the default one.
+define('EBML_ID_EDITIONFLAGORDERED', 0x05DD); // [45][DD] -- Specify if the chapters can be defined multiple times and the order to play them is enforced.
+define('EBML_ID_FILEDATA', 0x065C); // [46][5C] -- The data of the file.
+define('EBML_ID_FILEMIMETYPE', 0x0660); // [46][60] -- MIME type of the file.
+define('EBML_ID_FILENAME', 0x066E); // [46][6E] -- Filename of the attached file.
+define('EBML_ID_FILEREFERRAL', 0x0675); // [46][75] -- A binary value that a track/codec can refer to when the attachment is needed.
+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_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:
+define('EBML_ID_CONTENTSIGHASHALGO', 0x07E6); // [47][E6] -- The hash algorithm used for the signature. A value of '0' means that the contents have not been signed but only encrypted. Predefined values:
+define('EBML_ID_MUXINGAPP', 0x0D80); // [4D][80] -- Muxing application or library ("libmatroska-0.4.3").
+define('EBML_ID_SEEK', 0x0DBB); // [4D][BB] -- Contains a single seek entry to an EBML element.
+define('EBML_ID_CONTENTENCODINGORDER', 0x1031); // [50][31] -- Tells when this modification was used during encoding/muxing starting with 0 and counting upwards. The decoder/demuxer has to start with the highest order number it finds and work its way down. This value has to be unique over all ContentEncodingOrder elements in the segment.
+define('EBML_ID_CONTENTENCODINGSCOPE', 0x1032); // [50][32] -- A bit field that describes which elements have been modified in this way. Values (big endian) can be OR'ed. Possible values:
+define('EBML_ID_CONTENTENCODINGTYPE', 0x1033); // [50][33] -- A value describing what kind of transformation has been done. Possible values:
+define('EBML_ID_CONTENTCOMPRESSION', 0x1034); // [50][34] -- Settings describing the compression used. Must be present if the value of ContentEncodingType is 0 and absent otherwise. Each block must be decompressable even if no previous block is available in order not to prevent seeking.
+define('EBML_ID_CONTENTENCRYPTION', 0x1035); // [50][35] -- Settings describing the encryption used. Must be present if the value of ContentEncodingType is 1 and absent otherwise.
+define('EBML_ID_CUEREFNUMBER', 0x135F); // [53][5F] -- Number of the referenced Block of Track X in the specified Cluster.
+define('EBML_ID_NAME', 0x136E); // [53][6E] -- A human-readable track name.
+define('EBML_ID_CUEBLOCKNUMBER', 0x1378); // [53][78] -- Number of the Block in the specified Cluster.
+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_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).
+define('EBML_ID_ASPECTRATIOTYPE', 0x14B3); // [54][B3] -- Specify the possible modifications to the aspect ratio (0: free resizing, 1: keep aspect ratio, 2: fixed).
+define('EBML_ID_DISPLAYHEIGHT', 0x14BA); // [54][BA] -- Height of the video frames to display.
+define('EBML_ID_PIXELCROPTOP', 0x14BB); // [54][BB] -- The number of video pixels to remove at the top of the image.
+define('EBML_ID_PIXELCROPLEFT', 0x14CC); // [54][CC] -- The number of video pixels to remove on the left of the image.
+define('EBML_ID_PIXELCROPRIGHT', 0x14DD); // [54][DD] -- The number of video pixels to remove on the right of the image.
+define('EBML_ID_FLAGFORCED', 0x15AA); // [55][AA] -- Set if that track MUST be used during playback. There can be many forced track for a kind (audio, video or subs), the player should select the one which language matches the user preference or the default + forced track. Overlay MAY happen between a forced and non-forced track of the same kind.
+define('EBML_ID_MAXBLOCKADDITIONID', 0x15EE); // [55][EE] -- The maximum value of BlockAddID. A value 0 means there is no BlockAdditions for this track.
+define('EBML_ID_WRITINGAPP', 0x1741); // [57][41] -- Writing application ("mkvmerge-0.3.3").
+define('EBML_ID_CLUSTERSILENTTRACKS', 0x1854); // [58][54] -- The list of tracks that are not used in that part of the stream. It is useful when using overlay tracks on seeking. Then you should decide what track to use.
+define('EBML_ID_CLUSTERSILENTTRACKNUMBER', 0x18D7); // [58][D7] -- One of the track number that are not used from now on in the stream. It could change later if not specified as silent in a further Cluster.
+define('EBML_ID_ATTACHEDFILE', 0x21A7); // [61][A7] -- An attached file.
+define('EBML_ID_CONTENTENCODING', 0x2240); // [62][40] -- Settings for one content encoding like compression or encryption.
+define('EBML_ID_BITDEPTH', 0x2264); // [62][64] -- Bits per sample, mostly used for PCM.
+define('EBML_ID_CODECPRIVATE', 0x23A2); // [63][A2] -- Private data only known to the codec.
+define('EBML_ID_TARGETS', 0x23C0); // [63][C0] -- Contain all UIDs where the specified meta data apply. It is void to describe everything in the segment.
+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_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.
+define('EBML_ID_TRACKTRANSLATETRACKID', 0x26A5); // [66][A5] -- The binary value used to represent this track in the chapter codec data. The format depends on the ChapProcessCodecID used.
+define('EBML_ID_TRACKTRANSLATECODEC', 0x26BF); // [66][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu).
+define('EBML_ID_TRACKTRANSLATEEDITIONUID', 0x26FC); // [66][FC] -- Specify an edition UID on which this translation applies. When not specified, it means for all editions found in the segment.
+define('EBML_ID_SIMPLETAG', 0x27C8); // [67][C8] -- Contains general information about the target.
+define('EBML_ID_TARGETTYPEVALUE', 0x28CA); // [68][CA] -- A number to indicate the logical level of the target (see TargetType).
+define('EBML_ID_CHAPPROCESSCOMMAND', 0x2911); // [69][11] -- Contains all the commands associated to the Atom.
+define('EBML_ID_CHAPPROCESSTIME', 0x2922); // [69][22] -- Defines when the process command should be handled (0: during the whole chapter, 1: before starting playback, 2: after playback of the chapter).
+define('EBML_ID_CHAPTERTRANSLATE', 0x2924); // [69][24] -- A tuple of corresponding ID used by chapter codecs to represent this segment.
+define('EBML_ID_CHAPPROCESSDATA', 0x2933); // [69][33] -- Contains the command information. The data should be interpreted depending on the ChapProcessCodecID value. For ChapProcessCodecID = 1, the data correspond to the binary DVD cell pre/post commands.
+define('EBML_ID_CHAPPROCESS', 0x2944); // [69][44] -- Contains all the commands associated to the Atom.
+define('EBML_ID_CHAPPROCESSCODECID', 0x2955); // [69][55] -- Contains the type of the codec used for the processing. A value of 0 means native Matroska processing (to be defined), a value of 1 means the DVD command set is used. More codec IDs can be added later.
+define('EBML_ID_CHAPTERTRANSLATEID', 0x29A5); // [69][A5] -- The binary value used to represent this segment in the chapter codec data. The format depends on the ChapProcessCodecID used.
+define('EBML_ID_CHAPTERTRANSLATECODEC', 0x29BF); // [69][BF] -- The chapter codec using this ID (0: Matroska Script, 1: DVD-menu).
+define('EBML_ID_CHAPTERTRANSLATEEDITIONUID', 0x29FC); // [69][FC] -- Specify an edition UID on which this correspondance applies. When not specified, it means for all editions found in the segment.
+define('EBML_ID_CONTENTENCODINGS', 0x2D80); // [6D][80] -- Settings for several content encoding mechanisms like compression or encryption.
+define('EBML_ID_MINCACHE', 0x2DE7); // [6D][E7] -- The minimum number of frames a player should be able to cache during playback. If set to 0, the reference pseudo-cache system is not used.
+define('EBML_ID_MAXCACHE', 0x2DF8); // [6D][F8] -- The maximum cache size required to store referenced frames in and the current frame. 0 means no cache is needed.
+define('EBML_ID_CHAPTERSEGMENTUID', 0x2E67); // [6E][67] -- A segment to play in place of this chapter. Edition ChapterSegmentEditionUID should be used for this segment, otherwise no edition is used.
+define('EBML_ID_CHAPTERSEGMENTEDITIONUID', 0x2EBC); // [6E][BC] -- The edition to play from the segment linked in ChapterSegmentUID.
+define('EBML_ID_TRACKOVERLAY', 0x2FAB); // [6F][AB] -- Specify that this track is an overlay track for the Track specified (in the u-integer). That means when this track has a gap (see SilentTracks) the overlay track should be used instead. The order of multiple TrackOverlay matters, the first one is the one that should be used. If not found it should be the second, etc.
+define('EBML_ID_TAG', 0x3373); // [73][73] -- Element containing elements specific to Tracks/Chapters.
+define('EBML_ID_SEGMENTFILENAME', 0x3384); // [73][84] -- A filename corresponding to this segment.
+define('EBML_ID_SEGMENTUID', 0x33A4); // [73][A4] -- A randomly generated unique ID to identify the current segment between many others (128 bits).
+define('EBML_ID_CHAPTERUID', 0x33C4); // [73][C4] -- A unique ID to identify the Chapter.
+define('EBML_ID_TRACKUID', 0x33C5); // [73][C5] -- A unique ID to identify the Track. This should be kept the same when making a direct stream copy of the Track to another file.
+define('EBML_ID_ATTACHMENTLINK', 0x3446); // [74][46] -- The UID of an attachment that is used by this codec.
+define('EBML_ID_CLUSTERBLOCKADDITIONS', 0x35A1); // [75][A1] -- Contain additional blocks to complete the main one. An EBML parser that has no knowledge of the Block structure could still see and use/skip these data.
+define('EBML_ID_CHANNELPOSITIONS', 0x347B); // [7D][7B] -- Table of horizontal angles for each successive channel, see appendix.
+define('EBML_ID_OUTPUTSAMPLINGFREQUENCY', 0x38B5); // [78][B5] -- Real output sampling frequency in Hz (used for SBR techniques).
+define('EBML_ID_TITLE', 0x3BA9); // [7B][A9] -- General name of the segment.
+define('EBML_ID_CHAPTERDISPLAY', 0x00); // [80] -- Contains all possible strings to use for the chapter display.
+define('EBML_ID_TRACKTYPE', 0x03); // [83] -- A set of track types coded on 8 bits (1: video, 2: audio, 3: complex, 0x10: logo, 0x11: subtitle, 0x12: buttons, 0x20: control).
+define('EBML_ID_CHAPSTRING', 0x05); // [85] -- Contains the string to use as the chapter atom.
+define('EBML_ID_CODECID', 0x06); // [86] -- An ID corresponding to the codec, see the codec page for more info.
+define('EBML_ID_FLAGDEFAULT', 0x08); // [88] -- Set if that track (audio, video or subs) SHOULD be used if no language found matches the user preference.
+define('EBML_ID_CHAPTERTRACKNUMBER', 0x09); // [89] -- UID of the Track to apply this chapter too. In the absense of a control track, choosing this chapter will select the listed Tracks and deselect unlisted tracks. Absense of this element indicates that the Chapter should be applied to any currently used Tracks.
+define('EBML_ID_CLUSTERSLICES', 0x0E); // [8E] -- Contains slices description.
+define('EBML_ID_CHAPTERTRACK', 0x0F); // [8F] -- List of tracks on which the chapter applies. If this element is not present, all tracks apply
+define('EBML_ID_CHAPTERTIMESTART', 0x11); // [91] -- Timecode of the start of Chapter (not scaled).
+define('EBML_ID_CHAPTERTIMEEND', 0x12); // [92] -- Timecode of the end of Chapter (timecode excluded, not scaled).
+define('EBML_ID_CUEREFTIME', 0x16); // [96] -- Timecode of the referenced Block.
+define('EBML_ID_CUEREFCLUSTER', 0x17); // [97] -- Position of the Cluster containing the referenced Block.
+define('EBML_ID_CHAPTERFLAGHIDDEN', 0x18); // [98] -- If a chapter is hidden (1), it should not be available to the user interface (but still to Control Tracks).
+define('EBML_ID_FLAGINTERLACED', 0x1A); // [9A] -- Set if the video is interlaced.
+define('EBML_ID_CLUSTERBLOCKDURATION', 0x1B); // [9B] -- The duration of the Block (based on TimecodeScale). This element is mandatory when DefaultDuration is set for the track. When not written and with no DefaultDuration, the value is assumed to be the difference between the timecode of this Block and the timecode of the next Block in "display" order (not coding order). This element can be useful at the end of a Track (as there is not other Block available), or when there is a break in a track like for subtitle tracks.
+define('EBML_ID_FLAGLACING', 0x1C); // [9C] -- Set if the track may contain blocks using lacing.
+define('EBML_ID_CHANNELS', 0x1F); // [9F] -- Numbers of channels in the track.
+define('EBML_ID_CLUSTERBLOCKGROUP', 0x20); // [A0] -- Basic container of information containing a single Block or BlockVirtual, and information specific to that Block/VirtualBlock.
+define('EBML_ID_CLUSTERBLOCK', 0x21); // [A1] -- Block containing the actual data to be rendered and a timecode relative to the Cluster Timecode.
+define('EBML_ID_CLUSTERBLOCKVIRTUAL', 0x22); // [A2] -- A Block with no data. It must be stored in the stream at the place the real Block should be in display order.
+define('EBML_ID_CLUSTERSIMPLEBLOCK', 0x23); // [A3] -- Similar to Block but without all the extra information, mostly used to reduced overhead when no extra feature is needed.
+define('EBML_ID_CLUSTERCODECSTATE', 0x24); // [A4] -- The new codec state to use. Data interpretation is private to the codec. This information should always be referenced by a seek entry.
+define('EBML_ID_CLUSTERBLOCKADDITIONAL', 0x25); // [A5] -- Interpreted by the codec as it wishes (using the BlockAddID).
+define('EBML_ID_CLUSTERBLOCKMORE', 0x26); // [A6] -- Contain the BlockAdditional and some parameters.
+define('EBML_ID_CLUSTERPOSITION', 0x27); // [A7] -- Position of the Cluster in the segment (0 in live broadcast streams). It might help to resynchronise offset on damaged streams.
+define('EBML_ID_CODECDECODEALL', 0x2A); // [AA] -- The codec can decode potentially damaged data.
+define('EBML_ID_CLUSTERPREVSIZE', 0x2B); // [AB] -- Size of the previous Cluster, in octets. Can be useful for backward playing.
+define('EBML_ID_TRACKENTRY', 0x2E); // [AE] -- Describes a track with all elements.
+define('EBML_ID_CLUSTERENCRYPTEDBLOCK', 0x2F); // [AF] -- Similar to SimpleBlock but the data inside the Block are Transformed (encrypt and/or signed).
+define('EBML_ID_PIXELWIDTH', 0x30); // [B0] -- Width of the encoded video frames in pixels.
+define('EBML_ID_CUETIME', 0x33); // [B3] -- Absolute timecode according to the segment time base.
+define('EBML_ID_SAMPLINGFREQUENCY', 0x35); // [B5] -- Sampling frequency in Hz.
+define('EBML_ID_CHAPTERATOM', 0x36); // [B6] -- Contains the atom information to use as the chapter atom (apply to all tracks).
+define('EBML_ID_CUETRACKPOSITIONS', 0x37); // [B7] -- Contain positions for different tracks corresponding to the timecode.
+define('EBML_ID_FLAGENABLED', 0x39); // [B9] -- Set if the track is used.
+define('EBML_ID_PIXELHEIGHT', 0x3A); // [BA] -- Height of the encoded video frames in pixels.
+define('EBML_ID_CUEPOINT', 0x3B); // [BB] -- Contains all information relative to a seek point in the segment.
+define('EBML_ID_CRC32', 0x3F); // [BF] -- The CRC is computed on all the data of the Master element it's in, regardless of its position. It's recommended to put the CRC value at the beggining of the Master element for easier reading. All level 1 elements should include a CRC-32.
+define('EBML_ID_CLUSTERBLOCKADDITIONID', 0x4B); // [CB] -- The ID of the BlockAdditional element (0 is the main Block).
+define('EBML_ID_CLUSTERLACENUMBER', 0x4C); // [CC] -- The reverse number of the frame in the lace (0 is the last frame, 1 is the next to last, etc). While there are a few files in the wild with this element, it is no longer in use and has been deprecated. Being able to interpret this element is not required for playback.
+define('EBML_ID_CLUSTERFRAMENUMBER', 0x4D); // [CD] -- The number of the frame to generate from this lace with this delay (allow you to generate many frames from the same Block/Frame).
+define('EBML_ID_CLUSTERDELAY', 0x4E); // [CE] -- The (scaled) delay to apply to the element.
+define('EBML_ID_CLUSTERDURATION', 0x4F); // [CF] -- The (scaled) duration to apply to the element.
+define('EBML_ID_TRACKNUMBER', 0x57); // [D7] -- The track number as used in the Block Header (using more than 127 tracks is not encouraged, though the design allows an unlimited number).
+define('EBML_ID_CUEREFERENCE', 0x5B); // [DB] -- The Clusters containing the required referenced Blocks.
+define('EBML_ID_VIDEO', 0x60); // [E0] -- Video settings.
+define('EBML_ID_AUDIO', 0x61); // [E1] -- Audio settings.
+define('EBML_ID_CLUSTERTIMESLICE', 0x68); // [E8] -- Contains extra time information about the data contained in the Block. While there are a few files in the wild with this element, it is no longer in use and has been deprecated. Being able to interpret this element is not required for playback.
+define('EBML_ID_CUECODECSTATE', 0x6A); // [EA] -- The position of the Codec State corresponding to this Cue element. 0 means that the data is taken from the initial Track Entry.
+define('EBML_ID_CUEREFCODECSTATE', 0x6B); // [EB] -- The position of the Codec State corresponding to this referenced element. 0 means that the data is taken from the initial Track Entry.
+define('EBML_ID_VOID', 0x6C); // [EC] -- Used to void damaged data, to avoid unexpected behaviors when using damaged data. The content is discarded. Also used to reserve space in a sub-element for later use.
+define('EBML_ID_CLUSTERTIMECODE', 0x67); // [E7] -- Absolute timecode of the cluster (based on TimecodeScale).
+define('EBML_ID_CLUSTERBLOCKADDID', 0x6E); // [EE] -- An ID to identify the BlockAdditional level.
+define('EBML_ID_CUECLUSTERPOSITION', 0x71); // [F1] -- The position of the Cluster containing the required Block.
+define('EBML_ID_CUETRACK', 0x77); // [F7] -- The track for which a position is given.
+define('EBML_ID_CLUSTERREFERENCEPRIORITY', 0x7A); // [FA] -- This frame is referenced and has the specified cache priority. In cache only a frame of the same or higher priority can replace this frame. A value of 0 means the frame is not referenced.
+define('EBML_ID_CLUSTERREFERENCEBLOCK', 0x7B); // [FB] -- Timecode of another frame used as a reference (ie: B or P frame). The timecode is relative to the block it's attached to.
+define('EBML_ID_CLUSTERREFERENCEVIRTUAL', 0x7D); // [FD] -- Relative position of the data that should be in position of the virtual block.
+
+
+class getid3_matroska extends getid3_handler
+{
+ // public options
+ public static $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 [default: TRUE]
+ public static $parse_whole_file = false; // true to parse the whole file, not only header [default: FALSE]
+
+ // 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);
+
+ public function Analyze()
+ {
+ $info = &$this->getid3->info;
+
+ // parse container
+ try {
+ $this->parseEBML($info);
+ }
+ catch (Exception $e) {
+ $info['error'][] = 'EBML parser: '.$e->getMessage();
+ }
+
+ // 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;
+ }
+ }
+ }
+
+ // extract tags
+ if (isset($info['matroska']['tags']) && is_array($info['matroska']['tags'])) {
+ foreach ($info['matroska']['tags'] as $key => $infoarray) {
+ $this->ExtractCommentsSimpleTag($infoarray);
+ }
+ }
+
+ // 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::MatroskaCodecIDtoCommonName($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'];
+ if (isset($trackarray['DisplayWidth'])) { $track_info['display_x'] = $trackarray['DisplayWidth']; }
+ if (isset($trackarray['DisplayHeight'])) { $track_info['display_y'] = $trackarray['DisplayHeight']; }
+ 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':
+ if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, false)) {
+ $this->getid3->warning('Unable to parse codec private data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio-video.riff.php"');
+ break;
+ }
+ $parsed = getid3_riff::ParseBITMAPINFOHEADER($trackarray['CodecPrivate']);
+ $track_info['codec'] = getid3_riff::RIFFfourccLookup($parsed['fourcc']);
+ $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed;
+ break;
+ }
+
+ $info['video']['streams'][] = $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'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth'];
+ break;
+
+ case 'A_AC3':
+ case 'A_DTS':
+ case 'A_MPEG/L3':
+ //case 'A_FLAC':
+ if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.'.$track_info['dataformat'].'.php', __FILE__, false)) {
+ $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.'.$track_info['dataformat'].'.php"');
+ break;
+ }
+
+ if (!isset($info['matroska']['track_data_offsets'][$trackarray['TrackNumber']])) {
+ $this->getid3->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();
+ $getid3_temp->openfile($this->getid3->filename);
+ $getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'];
+ if ($track_info['dataformat'] == 'mp3' || $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_'.$track_info['dataformat'];
+ $header_data_key = $track_info['dataformat'] == 'mp3' ? 'mpeg' : $track_info['dataformat'];
+ $getid3_audio = new $class($getid3_temp);
+ if ($track_info['dataformat'] == 'mp3') {
+ $getid3_audio->allow_bruteforce = true;
+ }
+ if ($track_info['dataformat'] == 'flac') {
+ $getid3_audio->AnalyzeString($trackarray['CodecPrivate']);
+ }
+ else {
+ $getid3_audio->Analyze();
+ }
+ if (!empty($getid3_temp->info[$header_data_key])) {
+ unset($getid3_temp->info[$header_data_key]['GETID3_VERSION']);
+ $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 $key => $value) {
+ $track_info[$key] = $value;
+ }
+ }
+ }
+ else {
+ $this->getid3->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->getid3->warning($class.'() says: ['.$newerror.']');
+ }
+ }
+ if (!empty($getid3_temp->info['warning'])) {
+ foreach ($getid3_temp->info['warning'] as $newerror) {
+ if ($track_info['dataformat'] == 'mp3' && preg_match('/^Probable truncated file: expecting \d+ bytes of audio data, only found \d+ \(short by \d+ bytes\)$/', $newerror)) {
+ // LAME/Xing header is probably set, but audio data is chunked into Matroska file and near-impossible to verify if audio stream is complete, so ignore useless warning
+ continue;
+ }
+ $this->getid3->warning($class.'() says: ['.$newerror.']');
+ }
+ }
+ unset($getid3_temp, $getid3_audio);
+ break;
+
+ case 'A_AAC':
+ case 'A_AAC/MPEG2/LC':
+ case 'A_AAC/MPEG4/LC':
+ case 'A_AAC/MPEG4/LC/SBR':
+ $this->getid3->warning($trackarray['CodecID'].' audio data contains no header, audio/video bitrates can\'t be calculated');
+ break;
+
+ case 'A_VORBIS':
+ if (!isset($trackarray['CodecPrivate'])) {
+ $this->getid3->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->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because CodecPrivate data does not contain "vorbis" keyword');
+ break;
+ }
+ $vorbis_offset -= 1;
+
+ if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, false)) {
+ $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio.ogg.php"');
+ }
+
+ // create temp instance
+ $getid3_temp = new getID3();
+ $getid3_temp->openfile($this->getid3->filename);
+
+ // 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 $key => $value) {
+ $track_info[$key] = $value;
+ }
+ }
+ }
+
+ // copy errors and warnings
+ if (!empty($getid3_temp->info['error'])) {
+ foreach ($getid3_temp->info['error'] as $newerror) {
+ $this->getid3->warning('getid3_ogg() says: ['.$newerror.']');
+ }
+ }
+ if (!empty($getid3_temp->info['warning'])) {
+ foreach ($getid3_temp->info['warning'] as $newerror) {
+ $this->getid3->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':
+ if (!getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, false)) {
+ $this->getid3->warning('Unable to parse audio data ['.basename(__FILE__).':'.__LINE__.'] because cannot include "module.audio-video.riff.php"');
+ break;
+ }
+
+ $parsed = getid3_riff::RIFFparseWAVEFORMATex($trackarray['CodecPrivate']);
+ foreach ($parsed as $key => $value) {
+ if ($key != 'raw') {
+ $track_info[$key] = $value;
+ }
+ }
+ $info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed;
+ break;
+
+ default:
+ $this->getid3->warning('Unhandled audio type "'.(isset($trackarray['CodecID']) ? $trackarray['CodecID'] : '').'"');
+ }
+
+ $info['audio']['streams'][] = $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']);
+ }
+ }
+
+ // 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']);
+ }
+
+ return true;
+ }
+
+
+///////////////////////////////////////
+
+ 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['fileformat'] = 'matroska';
+ $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($element_data['data']);
+ break;
+
+ case EBML_ID_DOCTYPE:
+ $element_data['data'] = getid3_lib::trimNullByte($element_data['data']);
+ $info['matroska']['doctype'] = $element_data['data'];
+ break;
+
+ case EBML_ID_CRC32: // not useful, ignore
+ $this->current_offset = $element_data['end'];
+ unset($element_data);
+ break;
+
+ default:
+ $this->unhandledElement('header', __LINE__, $element_data);
+ }
+ if (!empty($element_data)) {
+ unset($element_data['offset'], $element_data['end']);
+ $info['matroska']['header']['elements'][] = $element_data;
+ }
+ }
+ break;
+
+ case EBML_ID_SEGMENT:
+ $info['matroska']['segment'][0]['offset'] = $top_element['offset'];
+ $info['matroska']['segment'][0]['length'] = $top_element['length'];
+
+ while ($this->getEBMLelement($element_data, $top_element['end'])) {
+ if ($element_data['id'] != EBML_ID_CLUSTER || !self::$hide_clusters) { // collect clusters only if required
+ $info['matroska']['segments'][] = $element_data;
+ }
+ switch ($element_data['id']) {
+
+ 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 ($this->getEBMLelement($sub_seek_entry, $seek_entry['end'], true)) {
+
+ switch ($sub_seek_entry['id']) {
+
+ case EBML_ID_SEEKID:
+ $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($sub_seek_entry['data']);
+ break;
+
+ default:
+ $this->unhandledElement('seekhead.seek', __LINE__, $sub_seek_entry); }
+ }
+
+ if ($seek_entry['target_id'] != EBML_ID_CLUSTER || !self::$hide_clusters) { // collect clusters only if required
+ $info['matroska']['seek'][] = $seek_entry;
+ }
+ break;
+
+ default:
+ $this->unhandledElement('seekhead', __LINE__, $seek_entry);
+ }
+ }
+ break;
+
+ 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 ($this->getEBMLelement($subelement, $track_entry['end'], array(EBML_ID_VIDEO, EBML_ID_AUDIO, EBML_ID_CONTENTENCODINGS))) {
+ switch ($subelement['id']) {
+
+ case EBML_ID_TRACKNUMBER:
+ case EBML_ID_TRACKUID:
+ 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['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
+ break;
+
+ case EBML_ID_TRACKTIMECODESCALE:
+ $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['id_name']] = $subelement['data'];
+ break;
+
+ case EBML_ID_FLAGENABLED:
+ case EBML_ID_FLAGDEFAULT:
+ case EBML_ID_FLAGFORCED:
+ case EBML_ID_FLAGLACING:
+ case EBML_ID_CODECDECODEALL:
+ $track_entry[$subelement['id_name']] = (bool) getid3_lib::BigEndian2Int($subelement['data']);
+ break;
+
+ case EBML_ID_VIDEO:
+
+ 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:
+ case EBML_ID_PIXELCROPRIGHT:
+ case EBML_ID_DISPLAYWIDTH:
+ case EBML_ID_DISPLAYHEIGHT:
+ case EBML_ID_DISPLAYUNIT:
+ case EBML_ID_ASPECTRATIOTYPE:
+ $track_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ 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;
+
+ case EBML_ID_AUDIO:
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_CHANNELS:
+ case EBML_ID_BITDEPTH:
+ $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['id_name']] = getid3_lib::BigEndian2Float($sub_subelement['data']);
+ break;
+
+ case EBML_ID_CHANNELPOSITIONS:
+ $track_entry[$sub_subelement['id_name']] = getid3_lib::trimNullByte($sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('track.audio', __LINE__, $sub_subelement);
+ }
+ }
+ break;
+
+ case EBML_ID_CONTENTENCODINGS:
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'])) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_CONTENTENCODING:
+
+ 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['id_name']][$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
+ break;
+
+ case EBML_ID_CONTENTCOMPRESSION:
+
+ 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['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['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data'];
+ break;
+
+ default:
+ $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement);
+ }
+ }
+ break;
+
+ case EBML_ID_CONTENTENCRYPTION:
+
+ 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['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['id_name']][$sub_sub_subelement['id_name']][$sub_sub_sub_subelement['id_name']] = $sub_sub_sub_subelement['data'];
+ break;
+
+ default:
+ $this->unhandledElement('track.contentencodings.contentencoding.contentcompression', __LINE__, $sub_sub_sub_subelement);
+ }
+ }
+ break;
+
+ default:
+ $this->unhandledElement('track.contentencodings.contentencoding', __LINE__, $sub_sub_subelement);
+ }
+ }
+ break;
+
+ default:
+ $this->unhandledElement('track.contentencodings', __LINE__, $sub_subelement);
+ }
+ }
+ break;
+
+ default:
+ $this->unhandledElement('track', __LINE__, $subelement);
+ }
+ }
+
+ $info['matroska']['tracks']['tracks'][] = $track_entry;
+ break;
+
+ default:
+ $this->unhandledElement('tracks', __LINE__, $track_entry);
+ }
+ }
+ break;
+
+ case EBML_ID_INFO: // Contains miscellaneous general information and statistics on the file.
+ $info_entry = array();
+
+ while ($this->getEBMLelement($subelement, $element_data['end'], true)) {
+ switch ($subelement['id']) {
+
+ case EBML_ID_CHAPTERTRANSLATEEDITIONUID:
+ case EBML_ID_CHAPTERTRANSLATECODEC:
+ case EBML_ID_TIMECODESCALE:
+ $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
+ break;
+
+ case EBML_ID_DURATION:
+ $info_entry[$subelement['id_name']] = getid3_lib::BigEndian2Float($subelement['data']);
+ break;
+
+ case EBML_ID_DATEUTC:
+ $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['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['id_name']] = getid3_lib::trimNullByte($subelement['data']);
+ $info['matroska']['comments'][strtolower($subelement['id_name'])][] = $info_entry[$subelement['id_name']];
+ break;
+
+ default:
+ $this->unhandledElement('info', __LINE__, $subelement);
+ }
+ }
+ $info['matroska']['info'][] = $info_entry;
+ break;
+
+ 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 (self::$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 ($this->getEBMLelement($subelement, $element_data['end'])) {
+ switch ($subelement['id']) {
+
+ case EBML_ID_CUEPOINT:
+ $cuepoint_entry = array();
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CUETRACKPOSITIONS))) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_CUETRACKPOSITIONS:
+ $cuetrackpositions_entry = array();
+
+ while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) {
+ switch ($sub_sub_subelement['id']) {
+
+ case EBML_ID_CUETRACK:
+ 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->unhandledElement('cues.cuepoint.cuetrackpositions', __LINE__, $sub_sub_subelement);
+ }
+ }
+ $cuepoint_entry[$sub_subelement['id_name']][] = $cuetrackpositions_entry;
+ break;
+
+ case EBML_ID_CUETIME:
+ $cuepoint_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('cues.cuepoint', __LINE__, $sub_subelement);
+ }
+ }
+ $cues_entry[] = $cuepoint_entry;
+ break;
+
+ default:
+ $this->unhandledElement('cues', __LINE__, $subelement);
+ }
+ }
+ $info['matroska']['cues'] = $cues_entry;
+ break;
+
+ case EBML_ID_TAGS: // Element containing elements specific to Tracks/Chapters.
+ $tags_entry = array();
+
+ while ($this->getEBMLelement($subelement, $element_data['end'], false)) {
+ switch ($subelement['id']) {
+
+ case EBML_ID_TAG:
+ $tag_entry = array();
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'], false)) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_TARGETS:
+ $targets_entry = array();
+
+ while ($this->getEBMLelement($sub_sub_subelement, $sub_subelement['end'], true)) {
+ switch ($sub_sub_subelement['id']) {
+
+ case EBML_ID_TARGETTYPEVALUE:
+ $targets_entry[$sub_sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
+ $targets_entry[strtolower($sub_sub_subelement['id_name']).'_long'] = self::MatroskaTargetTypeValue($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:
+ case EBML_ID_TAGATTACHMENTUID:
+ $targets_entry[$sub_sub_subelement['id_name']][] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('tags.tag.targets', __LINE__, $sub_sub_subelement);
+ }
+ }
+ $tag_entry[$sub_subelement['id_name']] = $targets_entry;
+ break;
+
+ case EBML_ID_SIMPLETAG:
+ $tag_entry[$sub_subelement['id_name']][] = $this->HandleEMBLSimpleTag($sub_subelement['end']);
+ break;
+
+ default:
+ $this->unhandledElement('tags.tag', __LINE__, $sub_subelement);
+ }
+ }
+ $tags_entry[] = $tag_entry;
+ break;
+
+ default:
+ $this->unhandledElement('tags', __LINE__, $subelement);
+ }
+ }
+ $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_ATTACHEDFILE:
+ $attachedfile_entry = array();
+
+ 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['id_name']] = $sub_subelement['data'];
+ break;
+
+ case EBML_ID_FILEDATA:
+ $attachedfile_entry['data_offset'] = $this->current_offset;
+ $attachedfile_entry['data_length'] = $sub_subelement['length'];
+
+ $this->getid3->saveAttachment(
+ $attachedfile_entry[$sub_subelement['id_name']],
+ $attachedfile_entry['FileName'],
+ $attachedfile_entry['data_offset'],
+ $attachedfile_entry['data_length']);
+
+ if (@$attachedfile_entry[$sub_subelement['id_name']] && is_file($attachedfile_entry[$sub_subelement['id_name']])) {
+ $attachedfile_entry[$sub_subelement['id_name'].'_filename'] = $attachedfile_entry[$sub_subelement['id_name']];
+ unset($attachedfile_entry[$sub_subelement['id_name']]);
+ }
+
+ $this->current_offset = $sub_subelement['end'];
+ break;
+
+ case EBML_ID_FILEUID:
+ $attachedfile_entry[$sub_subelement['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('attachments.attachedfile', __LINE__, $sub_subelement);
+ }
+ }
+ if (!empty($attachedfile_entry['FileData']) && !empty($attachedfile_entry['FileMimeType']) && preg_match('#^image/#i', $attachedfile_entry['FileMimeType'])) {
+ if ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_INLINE) {
+ $attachedfile_entry['data'] = $attachedfile_entry['FileData'];
+ $attachedfile_entry['image_mime'] = $attachedfile_entry['FileMimeType'];
+ $info['matroska']['comments']['picture'][] = array('data' => $attachedfile_entry['data'], 'image_mime' => $attachedfile_entry['image_mime'], 'filename' => (!empty($attachedfile_entry['FileName']) ? $attachedfile_entry['FileName'] : ''));
+ unset($attachedfile_entry['FileData'], $attachedfile_entry['FileMimeType']);
+ }
+ }
+ if (!empty($attachedfile_entry['image_mime']) && preg_match('#^image/#i', $attachedfile_entry['image_mime'])) {
+ // don't add a second copy of attached images, which are grouped under the standard location [comments][picture]
+ } else {
+ $info['matroska']['attachments'][] = $attachedfile_entry;
+ }
+ break;
+
+ default:
+ $this->unhandledElement('attachments', __LINE__, $subelement);
+ }
+ }
+ break;
+
+ case EBML_ID_CHAPTERS:
+
+ while ($this->getEBMLelement($subelement, $element_data['end'])) {
+ switch ($subelement['id']) {
+
+ case EBML_ID_EDITIONENTRY:
+ $editionentry_entry = array();
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'], array(EBML_ID_CHAPTERATOM))) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_EDITIONUID:
+ $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['id_name']] = (bool)getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ case EBML_ID_CHAPTERATOM:
+ $chapteratom_entry = array();
+
+ 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['id_name']] = $sub_sub_subelement['data'];
+ break;
+
+ case EBML_ID_CHAPTERFLAGENABLED:
+ case EBML_ID_CHAPTERFLAGHIDDEN:
+ $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['id_name']] = getid3_lib::BigEndian2Int($sub_sub_subelement['data']);
+ break;
+
+ case EBML_ID_CHAPTERTRACK:
+ $chaptertrack_entry = array();
+
+ 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['id_name']] = getid3_lib::BigEndian2Int($sub_sub_sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('chapters.editionentry.chapteratom.chaptertrack', __LINE__, $sub_sub_sub_subelement);
+ }
+ }
+ $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chaptertrack_entry;
+ break;
+
+ case EBML_ID_CHAPTERDISPLAY:
+ $chapterdisplay_entry = array();
+
+ 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['id_name']] = $sub_sub_sub_subelement['data'];
+ break;
+
+ default:
+ $this->unhandledElement('chapters.editionentry.chapteratom.chapterdisplay', __LINE__, $sub_sub_sub_subelement);
+ }
+ }
+ $chapteratom_entry[$sub_sub_subelement['id_name']][] = $chapterdisplay_entry;
+ break;
+
+ default:
+ $this->unhandledElement('chapters.editionentry.chapteratom', __LINE__, $sub_sub_subelement);
+ }
+ }
+ $editionentry_entry[$sub_subelement['id_name']][] = $chapteratom_entry;
+ break;
+
+ default:
+ $this->unhandledElement('chapters.editionentry', __LINE__, $sub_subelement);
+ }
+ }
+ $info['matroska']['chapters'][] = $editionentry_entry;
+ break;
+
+ default:
+ $this->unhandledElement('chapters', __LINE__, $subelement);
+ }
+ }
+ break;
+
+ case EBML_ID_CLUSTER: // The lower level element containing the (monolithic) Block structure.
+ $cluster_entry = array();
+
+ 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['id_name']] = getid3_lib::BigEndian2Int($subelement['data']);
+ break;
+
+ case EBML_ID_CLUSTERSILENTTRACKS:
+ $cluster_silent_tracks = array();
+
+ while ($this->getEBMLelement($sub_subelement, $subelement['end'], true)) {
+ switch ($sub_subelement['id']) {
+
+ case EBML_ID_CLUSTERSILENTTRACKNUMBER:
+ $cluster_silent_tracks[] = getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ default:
+ $this->unhandledElement('cluster.silenttracks', __LINE__, $sub_subelement);
+ }
+ }
+ $cluster_entry[$subelement['id_name']][] = $cluster_silent_tracks;
+ break;
+
+ case EBML_ID_CLUSTERBLOCKGROUP:
+ $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_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['id_name']] = getid3_lib::BigEndian2Int($sub_subelement['data']);
+ break;
+
+ case EBML_ID_CLUSTERREFERENCEBLOCK: // signed-int
+ $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->unhandledElement('clusters.blockgroup', __LINE__, $sub_subelement);
+ }
+ }
+ $cluster_entry[$subelement['id_name']][] = $cluster_block_group;
+ break;
+
+ case EBML_ID_CLUSTERSIMPLEBLOCK:
+ $cluster_entry[$subelement['id_name']][] = $this->HandleEMBLClusterBlock($subelement, EBML_ID_CLUSTERSIMPLEBLOCK, $info);
+ break;
+
+ default:
+ $this->unhandledElement('cluster', __LINE__, $subelement);
+ }
+ $this->current_offset = $subelement['end'];
+ }
+ if (!self::$hide_clusters) {
+ $info['matroska']['cluster'][] = $cluster_entry;
+ }
+
+ // check to see if all the data we need exists already, if so, break out of the loop
+ if (!self::$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'])) {
+ return;
+ }
+ }
+ }
+ break;
+
+ default:
+ $this->unhandledElement('segment', __LINE__, $element_data);
+ }
+ }
+ break;
+
+ default:
+ $this->unhandledElement('root', __LINE__, $top_element);
+ }
+ }
+ }
+
+ private function EnsureBufferHasEnoughData($min_data = 1024)
+ {
+ if (($this->current_offset - $this->EBMLbuffer_offset) >= ($this->EBMLbuffer_length - $min_data)) {
+
+ if (!getid3_lib::intValueSupported($this->current_offset + $this->getid3->fread_buffer_size())) {
+ $this->getid3->info['error'][] = 'EBML parser: cannot read past '.$this->current_offset;
+ return false;
+ }
+
+ fseek($this->getid3->fp, $this->current_offset, SEEK_SET);
+ $this->EBMLbuffer_offset = $this->current_offset;
+ $this->EBMLbuffer = fread($this->getid3->fp, max($min_data, $this->getid3->fread_buffer_size()));
+ $this->EBMLbuffer_length = strlen($this->EBMLbuffer);
+
+ if ($this->EBMLbuffer_length == 0 && feof($this->getid3->fp)) {
+ $this->getid3->info['error'][] = 'EBML parser: ran out of file at offset '.$this->current_offset;
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ 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;
+ } elseif (0x20 & $first_byte_int) {
+ $length = 3;
+ } elseif (0x10 & $first_byte_int) {
+ $length = 4;
+ } elseif (0x08 & $first_byte_int) {
+ $length = 5;
+ } elseif (0x04 & $first_byte_int) {
+ $length = 6;
+ } elseif (0x02 & $first_byte_int) {
+ $length = 7;
+ } elseif (0x01 & $first_byte_int) {
+ $length = 8;
+ } else {
+ throw new Exception('invalid EBML integer (leading 0x00) at '.$this->current_offset);
+ }
+
+ // read
+ $int_value = self::EBML2Int(substr($this->EBMLbuffer, $actual_offset, $length));
+ $this->current_offset += $length;
+
+ return $int_value;
+ }
+
+ private function readEBMLelementData($length)
+ {
+ $data = substr($this->EBMLbuffer, $this->current_offset - $this->EBMLbuffer_offset, $length);
+ $this->current_offset += $length;
+
+ return $data;
+ }
+
+ 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;
+ }
+
+ 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->getid3->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'];
+ }
+ }
+
+ 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;
+ }
+
+ 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);
+ }
+ }
+
+ return $simpletag_entry;
+ }
+
+ 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
+
+ $cluster_block_data = array();
+ $cluster_block_data['tracknumber'] = $this->readEBMLint();
+ $cluster_block_data['timecode'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(2));
+ $cluster_block_data['flags_raw'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1));
+
+ if ($block_type == EBML_ID_CLUSTERSIMPLEBLOCK) {
+ $cluster_block_data['flags']['keyframe'] = (($cluster_block_data['flags_raw'] & 0x80) >> 7);
+ //$cluster_block_data['flags']['reserved1'] = (($cluster_block_data['flags_raw'] & 0x70) >> 4);
+ }
+ else {
+ //$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); // 00=no lacing; 01=Xiph lacing; 11=EBML lacing; 10=fixed-size lacing
+ if ($block_type == EBML_ID_CLUSTERSIMPLEBLOCK) {
+ $cluster_block_data['flags']['discardable'] = (($cluster_block_data['flags_raw'] & 0x01));
+ }
+ else {
+ //$cluster_block_data['flags']['reserved2'] = (($cluster_block_data['flags_raw'] & 0x01) >> 0);
+ }
+ $cluster_block_data['flags']['lacing_type'] = self::MatroskaBlockLacingType($cluster_block_data['flags']['lacing']);
+
+ // Lace (when lacing bit is set)
+ if ($cluster_block_data['flags']['lacing'] > 0) {
+ $cluster_block_data['lace_frames'] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1)) + 1; // Number of frames in the lace-1 (uint8)
+ if ($cluster_block_data['flags']['lacing'] != 0x02) { // 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).
+ for ($i = 1; $i < $cluster_block_data['lace_frames']; $i ++) {
+ if ($cluster_block_data['flags']['lacing'] == 0x03) { // EBML lacing
+ // 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.
+ $cluster_block_data['lace_frames_size'][$i] = $this->readEBMLint();
+ }
+ else { // Xiph lacing
+ $cluster_block_data['lace_frames_size'][$i] = getid3_lib::BigEndian2Int($this->readEBMLelementData(1));
+ }
+ }
+ }
+ }
+
+ if (!isset($info['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']])) {
+ $info['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']]['offset'] = $this->current_offset;
+ $info['matroska']['track_data_offsets'][$cluster_block_data['tracknumber']]['length'] = $element['end'] - $this->current_offset;
+ }
+
+ // set offset manually
+ $this->current_offset = $element['end'];
+
+ return $cluster_block_data;
+ }
+
+ private static function EBML2Int($EBMLstring) {
+ // http://matroska.org/specs/
+
+ // Element ID coded with an UTF-8 like system:
+ // 1xxx xxxx - Class A IDs (2^7 -2 possible values) (base 0x8X)
+ // 01xx xxxx xxxx xxxx - Class B IDs (2^14-2 possible values) (base 0x4X 0xXX)
+ // 001x xxxx xxxx xxxx xxxx xxxx - Class C IDs (2^21-2 possible values) (base 0x2X 0xXX 0xXX)
+ // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - Class D IDs (2^28-2 possible values) (base 0x1X 0xXX 0xXX 0xXX)
+ // Values with all x at 0 and 1 are reserved (hence the -2).
+
+ // Data size, in octets, is also coded with an UTF-8 like system :
+ // 1xxx xxxx - value 0 to 2^7-2
+ // 01xx xxxx xxxx xxxx - value 0 to 2^14-2
+ // 001x xxxx xxxx xxxx xxxx xxxx - value 0 to 2^21-2
+ // 0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^28-2
+ // 0000 1xxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^35-2
+ // 0000 01xx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx - value 0 to 2^42-2
+ // 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]);
+ if (0x80 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x7F);
+ } elseif (0x40 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x3F);
+ } elseif (0x20 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x1F);
+ } elseif (0x10 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x0F);
+ } elseif (0x08 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x07);
+ } elseif (0x04 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x03);
+ } elseif (0x02 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x01);
+ } elseif (0x01 & $first_byte_int) {
+ $EBMLstring[0] = chr($first_byte_int & 0x00);
+ }
+
+ return getid3_lib::BigEndian2Int($EBMLstring);
+ }
+
+ 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);
+ }
+
+ public static function MatroskaTargetTypeValue($target_type) {
+ // http://www.matroska.org/technical/specs/tagging/index.html
+ static $MatroskaTargetTypeValue = array();
+ if (empty($MatroskaTargetTypeValue)) {
+ $MatroskaTargetTypeValue[10] = 'A: ~ V:shot'; // the lowest hierarchy found in music or movies
+ $MatroskaTargetTypeValue[20] = 'A:subtrack/part/movement ~ V:scene'; // corresponds to parts of a track for audio (like a movement)
+ $MatroskaTargetTypeValue[30] = 'A:track/song ~ V:chapter'; // the common parts of an album or a movie
+ $MatroskaTargetTypeValue[40] = 'A:part/session ~ V:part/session'; // when an album or episode has different logical parts
+ $MatroskaTargetTypeValue[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)
+ $MatroskaTargetTypeValue[60] = 'A:edition/issue/volume/opus ~ V:season/sequel/volume'; // a list of lower levels grouped together
+ $MatroskaTargetTypeValue[70] = 'A:collection ~ V:collection'; // the high hierarchy consisting of many different lower items
+ }
+ return (isset($MatroskaTargetTypeValue[$target_type]) ? $MatroskaTargetTypeValue[$target_type] : $target_type);
+ }
+
+ public static function MatroskaBlockLacingType($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';
+ }
+ return (isset($MatroskaBlockLacingType[$lacingtype]) ? $MatroskaBlockLacingType[$lacingtype] : $lacingtype);
+ }
+
+ public static function MatroskaCodecIDtoCommonName($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';
+ $MatroskaCodecIDlist['V_VP8'] = 'vp8';
+ $MatroskaCodecIDlist['V_MS/VFW/FOURCC'] = 'riff';
+ $MatroskaCodecIDlist['A_MS/ACM'] = 'riff';
+ }
+ return (isset($MatroskaCodecIDlist[$codecid]) ? $MatroskaCodecIDlist[$codecid] : $codecid);
+ }
+
+ 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_AUDIO] = 'Audio';
+ $EBMLidList[EBML_ID_BITDEPTH] = 'BitDepth';
+ $EBMLidList[EBML_ID_CHANNELPOSITIONS] = 'ChannelPositions';
+ $EBMLidList[EBML_ID_CHANNELS] = 'Channels';
+ $EBMLidList[EBML_ID_CHAPCOUNTRY] = 'ChapCountry';
+ $EBMLidList[EBML_ID_CHAPLANGUAGE] = 'ChapLanguage';
+ $EBMLidList[EBML_ID_CHAPPROCESS] = 'ChapProcess';
+ $EBMLidList[EBML_ID_CHAPPROCESSCODECID] = 'ChapProcessCodecID';
+ $EBMLidList[EBML_ID_CHAPPROCESSCOMMAND] = 'ChapProcessCommand';
+ $EBMLidList[EBML_ID_CHAPPROCESSDATA] = 'ChapProcessData';
+ $EBMLidList[EBML_ID_CHAPPROCESSPRIVATE] = 'ChapProcessPrivate';
+ $EBMLidList[EBML_ID_CHAPPROCESSTIME] = 'ChapProcessTime';
+ $EBMLidList[EBML_ID_CHAPSTRING] = 'ChapString';
+ $EBMLidList[EBML_ID_CHAPTERATOM] = 'ChapterAtom';
+ $EBMLidList[EBML_ID_CHAPTERDISPLAY] = 'ChapterDisplay';
+ $EBMLidList[EBML_ID_CHAPTERFLAGENABLED] = 'ChapterFlagEnabled';
+ $EBMLidList[EBML_ID_CHAPTERFLAGHIDDEN] = 'ChapterFlagHidden';
+ $EBMLidList[EBML_ID_CHAPTERPHYSICALEQUIV] = 'ChapterPhysicalEquiv';
+ $EBMLidList[EBML_ID_CHAPTERS] = 'Chapters';
+ $EBMLidList[EBML_ID_CHAPTERSEGMENTEDITIONUID] = 'ChapterSegmentEditionUID';
+ $EBMLidList[EBML_ID_CHAPTERSEGMENTUID] = 'ChapterSegmentUID';
+ $EBMLidList[EBML_ID_CHAPTERTIMEEND] = 'ChapterTimeEnd';
+ $EBMLidList[EBML_ID_CHAPTERTIMESTART] = 'ChapterTimeStart';
+ $EBMLidList[EBML_ID_CHAPTERTRACK] = 'ChapterTrack';
+ $EBMLidList[EBML_ID_CHAPTERTRACKNUMBER] = 'ChapterTrackNumber';
+ $EBMLidList[EBML_ID_CHAPTERTRANSLATE] = 'ChapterTranslate';
+ $EBMLidList[EBML_ID_CHAPTERTRANSLATECODEC] = 'ChapterTranslateCodec';
+ $EBMLidList[EBML_ID_CHAPTERTRANSLATEEDITIONUID] = 'ChapterTranslateEditionUID';
+ $EBMLidList[EBML_ID_CHAPTERTRANSLATEID] = 'ChapterTranslateID';
+ $EBMLidList[EBML_ID_CHAPTERUID] = 'ChapterUID';
+ $EBMLidList[EBML_ID_CLUSTER] = 'Cluster';
+ $EBMLidList[EBML_ID_CLUSTERBLOCK] = 'ClusterBlock';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKADDID] = 'ClusterBlockAddID';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONAL] = 'ClusterBlockAdditional';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONID] = 'ClusterBlockAdditionID';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKADDITIONS] = 'ClusterBlockAdditions';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKDURATION] = 'ClusterBlockDuration';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKGROUP] = 'ClusterBlockGroup';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKMORE] = 'ClusterBlockMore';
+ $EBMLidList[EBML_ID_CLUSTERBLOCKVIRTUAL] = 'ClusterBlockVirtual';
+ $EBMLidList[EBML_ID_CLUSTERCODECSTATE] = 'ClusterCodecState';
+ $EBMLidList[EBML_ID_CLUSTERDELAY] = 'ClusterDelay';
+ $EBMLidList[EBML_ID_CLUSTERDURATION] = 'ClusterDuration';
+ $EBMLidList[EBML_ID_CLUSTERENCRYPTEDBLOCK] = 'ClusterEncryptedBlock';
+ $EBMLidList[EBML_ID_CLUSTERFRAMENUMBER] = 'ClusterFrameNumber';
+ $EBMLidList[EBML_ID_CLUSTERLACENUMBER] = 'ClusterLaceNumber';
+ $EBMLidList[EBML_ID_CLUSTERPOSITION] = 'ClusterPosition';
+ $EBMLidList[EBML_ID_CLUSTERPREVSIZE] = 'ClusterPrevSize';
+ $EBMLidList[EBML_ID_CLUSTERREFERENCEBLOCK] = 'ClusterReferenceBlock';
+ $EBMLidList[EBML_ID_CLUSTERREFERENCEPRIORITY] = 'ClusterReferencePriority';
+ $EBMLidList[EBML_ID_CLUSTERREFERENCEVIRTUAL] = 'ClusterReferenceVirtual';
+ $EBMLidList[EBML_ID_CLUSTERSILENTTRACKNUMBER] = 'ClusterSilentTrackNumber';
+ $EBMLidList[EBML_ID_CLUSTERSILENTTRACKS] = 'ClusterSilentTracks';
+ $EBMLidList[EBML_ID_CLUSTERSIMPLEBLOCK] = 'ClusterSimpleBlock';
+ $EBMLidList[EBML_ID_CLUSTERTIMECODE] = 'ClusterTimecode';
+ $EBMLidList[EBML_ID_CLUSTERTIMESLICE] = 'ClusterTimeSlice';
+ $EBMLidList[EBML_ID_CODECDECODEALL] = 'CodecDecodeAll';
+ $EBMLidList[EBML_ID_CODECDOWNLOADURL] = 'CodecDownloadURL';
+ $EBMLidList[EBML_ID_CODECID] = 'CodecID';
+ $EBMLidList[EBML_ID_CODECINFOURL] = 'CodecInfoURL';
+ $EBMLidList[EBML_ID_CODECNAME] = 'CodecName';
+ $EBMLidList[EBML_ID_CODECPRIVATE] = 'CodecPrivate';
+ $EBMLidList[EBML_ID_CODECSETTINGS] = 'CodecSettings';
+ $EBMLidList[EBML_ID_COLOURSPACE] = 'ColourSpace';
+ $EBMLidList[EBML_ID_CONTENTCOMPALGO] = 'ContentCompAlgo';
+ $EBMLidList[EBML_ID_CONTENTCOMPRESSION] = 'ContentCompression';
+ $EBMLidList[EBML_ID_CONTENTCOMPSETTINGS] = 'ContentCompSettings';
+ $EBMLidList[EBML_ID_CONTENTENCALGO] = 'ContentEncAlgo';
+ $EBMLidList[EBML_ID_CONTENTENCKEYID] = 'ContentEncKeyID';
+ $EBMLidList[EBML_ID_CONTENTENCODING] = 'ContentEncoding';
+ $EBMLidList[EBML_ID_CONTENTENCODINGORDER] = 'ContentEncodingOrder';
+ $EBMLidList[EBML_ID_CONTENTENCODINGS] = 'ContentEncodings';
+ $EBMLidList[EBML_ID_CONTENTENCODINGSCOPE] = 'ContentEncodingScope';
+ $EBMLidList[EBML_ID_CONTENTENCODINGTYPE] = 'ContentEncodingType';
+ $EBMLidList[EBML_ID_CONTENTENCRYPTION] = 'ContentEncryption';
+ $EBMLidList[EBML_ID_CONTENTSIGALGO] = 'ContentSigAlgo';
+ $EBMLidList[EBML_ID_CONTENTSIGHASHALGO] = 'ContentSigHashAlgo';
+ $EBMLidList[EBML_ID_CONTENTSIGKEYID] = 'ContentSigKeyID';
+ $EBMLidList[EBML_ID_CONTENTSIGNATURE] = 'ContentSignature';
+ $EBMLidList[EBML_ID_CRC32] = 'CRC32';
+ $EBMLidList[EBML_ID_CUEBLOCKNUMBER] = 'CueBlockNumber';
+ $EBMLidList[EBML_ID_CUECLUSTERPOSITION] = 'CueClusterPosition';
+ $EBMLidList[EBML_ID_CUECODECSTATE] = 'CueCodecState';
+ $EBMLidList[EBML_ID_CUEPOINT] = 'CuePoint';
+ $EBMLidList[EBML_ID_CUEREFCLUSTER] = 'CueRefCluster';
+ $EBMLidList[EBML_ID_CUEREFCODECSTATE] = 'CueRefCodecState';
+ $EBMLidList[EBML_ID_CUEREFERENCE] = 'CueReference';
+ $EBMLidList[EBML_ID_CUEREFNUMBER] = 'CueRefNumber';
+ $EBMLidList[EBML_ID_CUEREFTIME] = 'CueRefTime';
+ $EBMLidList[EBML_ID_CUES] = 'Cues';
+ $EBMLidList[EBML_ID_CUETIME] = 'CueTime';
+ $EBMLidList[EBML_ID_CUETRACK] = 'CueTrack';
+ $EBMLidList[EBML_ID_CUETRACKPOSITIONS] = 'CueTrackPositions';
+ $EBMLidList[EBML_ID_DATEUTC] = 'DateUTC';
+ $EBMLidList[EBML_ID_DEFAULTDURATION] = 'DefaultDuration';
+ $EBMLidList[EBML_ID_DISPLAYHEIGHT] = 'DisplayHeight';
+ $EBMLidList[EBML_ID_DISPLAYUNIT] = 'DisplayUnit';
+ $EBMLidList[EBML_ID_DISPLAYWIDTH] = 'DisplayWidth';
+ $EBMLidList[EBML_ID_DOCTYPE] = 'DocType';
+ $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';
+ $EBMLidList[EBML_ID_EBMLVERSION] = 'EBMLVersion';
+ $EBMLidList[EBML_ID_EDITIONENTRY] = 'EditionEntry';
+ $EBMLidList[EBML_ID_EDITIONFLAGDEFAULT] = 'EditionFlagDefault';
+ $EBMLidList[EBML_ID_EDITIONFLAGHIDDEN] = 'EditionFlagHidden';
+ $EBMLidList[EBML_ID_EDITIONFLAGORDERED] = 'EditionFlagOrdered';
+ $EBMLidList[EBML_ID_EDITIONUID] = 'EditionUID';
+ $EBMLidList[EBML_ID_FILEDATA] = 'FileData';
+ $EBMLidList[EBML_ID_FILEDESCRIPTION] = 'FileDescription';
+ $EBMLidList[EBML_ID_FILEMIMETYPE] = 'FileMimeType';
+ $EBMLidList[EBML_ID_FILENAME] = 'FileName';
+ $EBMLidList[EBML_ID_FILEREFERRAL] = 'FileReferral';
+ $EBMLidList[EBML_ID_FILEUID] = 'FileUID';
+ $EBMLidList[EBML_ID_FLAGDEFAULT] = 'FlagDefault';
+ $EBMLidList[EBML_ID_FLAGENABLED] = 'FlagEnabled';
+ $EBMLidList[EBML_ID_FLAGFORCED] = 'FlagForced';
+ $EBMLidList[EBML_ID_FLAGINTERLACED] = 'FlagInterlaced';
+ $EBMLidList[EBML_ID_FLAGLACING] = 'FlagLacing';
+ $EBMLidList[EBML_ID_GAMMAVALUE] = 'GammaValue';
+ $EBMLidList[EBML_ID_INFO] = 'Info';
+ $EBMLidList[EBML_ID_LANGUAGE] = 'Language';
+ $EBMLidList[EBML_ID_MAXBLOCKADDITIONID] = 'MaxBlockAdditionID';
+ $EBMLidList[EBML_ID_MAXCACHE] = 'MaxCache';
+ $EBMLidList[EBML_ID_MINCACHE] = 'MinCache';
+ $EBMLidList[EBML_ID_MUXINGAPP] = 'MuxingApp';
+ $EBMLidList[EBML_ID_NAME] = 'Name';
+ $EBMLidList[EBML_ID_NEXTFILENAME] = 'NextFilename';
+ $EBMLidList[EBML_ID_NEXTUID] = 'NextUID';
+ $EBMLidList[EBML_ID_OUTPUTSAMPLINGFREQUENCY] = 'OutputSamplingFrequency';
+ $EBMLidList[EBML_ID_PIXELCROPBOTTOM] = 'PixelCropBottom';
+ $EBMLidList[EBML_ID_PIXELCROPLEFT] = 'PixelCropLeft';
+ $EBMLidList[EBML_ID_PIXELCROPRIGHT] = 'PixelCropRight';
+ $EBMLidList[EBML_ID_PIXELCROPTOP] = 'PixelCropTop';
+ $EBMLidList[EBML_ID_PIXELHEIGHT] = 'PixelHeight';
+ $EBMLidList[EBML_ID_PIXELWIDTH] = 'PixelWidth';
+ $EBMLidList[EBML_ID_PREVFILENAME] = 'PrevFilename';
+ $EBMLidList[EBML_ID_PREVUID] = 'PrevUID';
+ $EBMLidList[EBML_ID_SAMPLINGFREQUENCY] = 'SamplingFrequency';
+ $EBMLidList[EBML_ID_SEEK] = 'Seek';
+ $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_TAG] = 'Tag';
+ $EBMLidList[EBML_ID_TAGATTACHMENTUID] = 'TagAttachmentUID';
+ $EBMLidList[EBML_ID_TAGBINARY] = 'TagBinary';
+ $EBMLidList[EBML_ID_TAGCHAPTERUID] = 'TagChapterUID';
+ $EBMLidList[EBML_ID_TAGDEFAULT] = 'TagDefault';
+ $EBMLidList[EBML_ID_TAGEDITIONUID] = 'TagEditionUID';
+ $EBMLidList[EBML_ID_TAGLANGUAGE] = 'TagLanguage';
+ $EBMLidList[EBML_ID_TAGNAME] = 'TagName';
+ $EBMLidList[EBML_ID_TAGTRACKUID] = 'TagTrackUID';
+ $EBMLidList[EBML_ID_TAGS] = 'Tags';
+ $EBMLidList[EBML_ID_TAGSTRING] = 'TagString';
+ $EBMLidList[EBML_ID_TARGETS] = 'Targets';
+ $EBMLidList[EBML_ID_TARGETTYPE] = 'TargetType';
+ $EBMLidList[EBML_ID_TARGETTYPEVALUE] = 'TargetTypeValue';
+ $EBMLidList[EBML_ID_TIMECODESCALE] = 'TimecodeScale';
+ $EBMLidList[EBML_ID_TITLE] = 'Title';
+ $EBMLidList[EBML_ID_TRACKENTRY] = 'TrackEntry';
+ $EBMLidList[EBML_ID_TRACKNUMBER] = 'TrackNumber';
+ $EBMLidList[EBML_ID_TRACKOFFSET] = 'TrackOffset';
+ $EBMLidList[EBML_ID_TRACKOVERLAY] = 'TrackOverlay';
+ $EBMLidList[EBML_ID_TRACKS] = 'Tracks';
+ $EBMLidList[EBML_ID_TRACKTIMECODESCALE] = 'TrackTimecodeScale';
+ $EBMLidList[EBML_ID_TRACKTRANSLATE] = 'TrackTranslate';
+ $EBMLidList[EBML_ID_TRACKTRANSLATECODEC] = 'TrackTranslateCodec';
+ $EBMLidList[EBML_ID_TRACKTRANSLATEEDITIONUID] = 'TrackTranslateEditionUID';
+ $EBMLidList[EBML_ID_TRACKTRANSLATETRACKID] = 'TrackTranslateTrackID';
+ $EBMLidList[EBML_ID_TRACKTYPE] = 'TrackType';
+ $EBMLidList[EBML_ID_TRACKUID] = 'TrackUID';
+ $EBMLidList[EBML_ID_VIDEO] = 'Video';
+ $EBMLidList[EBML_ID_VOID] = 'Void';
+ $EBMLidList[EBML_ID_WRITINGAPP] = 'WritingApp';
+ }
+
+ return (isset($EBMLidList[$value]) ? $EBMLidList[$value] : dechex($value));
+ }
+
+ private static function getDefaultStreamInfo($streams)
+ {
+ foreach (array_reverse($streams) as $stream) {
+ if ($stream['default']) {
+ break;
+ }
+ }
+ unset($stream['default']);
+ if (isset($stream['name'])) {
+ unset($stream['name']);
+ }
+
+ $info = $stream;
+ $info['streams'] = $streams;
+
+ return $info;
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/app/Library/getid3/module.audio-video.mpeg.php b/app/Library/getid3/module.audio-video.mpeg.php
new file mode 100644
index 00000000..499b740c
--- /dev/null
+++ b/app/Library/getid3/module.audio-video.mpeg.php
@@ -0,0 +1,299 @@
+ //
+// 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 extends getid3_handler
+{
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ if ($info['avdataend'] <= $info['avdataoffset']) {
+ $info['error'][] = '"avdataend" ('.$info['avdataend'].') is unexpectedly less-than-or-equal-to "avdataoffset" ('.$info['avdataoffset'].')';
+ return false;
+ }
+ $info['fileformat'] = 'mpeg';
+ fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
+ $MPEGstreamData = fread($this->getid3->fp, min(100000, $info['avdataend'] - $info['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)
+
+ $info['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;
+
+ $info['mpeg']['video']['raw']['framesize_horizontal'] = ($FrameSizeDWORD & 0xFFF000) >> 12; // 12 bits for horizontal frame size
+ $info['mpeg']['video']['raw']['framesize_vertical'] = ($FrameSizeDWORD & 0x000FFF); // 12 bits for vertical frame size
+ $info['mpeg']['video']['raw']['pixel_aspect_ratio'] = ($AspectRatioFrameRateDWORD & 0xF0) >> 4;
+ $info['mpeg']['video']['raw']['frame_rate'] = ($AspectRatioFrameRateDWORD & 0x0F);
+
+ $info['mpeg']['video']['framesize_horizontal'] = $info['mpeg']['video']['raw']['framesize_horizontal'];
+ $info['mpeg']['video']['framesize_vertical'] = $info['mpeg']['video']['raw']['framesize_vertical'];
+
+ $info['mpeg']['video']['pixel_aspect_ratio'] = $this->MPEGvideoAspectRatioLookup($info['mpeg']['video']['raw']['pixel_aspect_ratio']);
+ $info['mpeg']['video']['pixel_aspect_ratio_text'] = $this->MPEGvideoAspectRatioTextLookup($info['mpeg']['video']['raw']['pixel_aspect_ratio']);
+ $info['mpeg']['video']['frame_rate'] = $this->MPEGvideoFramerateLookup($info['mpeg']['video']['raw']['frame_rate']);
+
+ $info['mpeg']['video']['raw']['bitrate'] = getid3_lib::Bin2Dec(substr($assortedinformation, 0, 18));
+ $info['mpeg']['video']['raw']['marker_bit'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 18, 1));
+ $info['mpeg']['video']['raw']['vbv_buffer_size'] = getid3_lib::Bin2Dec(substr($assortedinformation, 19, 10));
+ $info['mpeg']['video']['raw']['constrained_param_flag'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 29, 1));
+ $info['mpeg']['video']['raw']['intra_quant_flag'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 30, 1));
+ if ($info['mpeg']['video']['raw']['intra_quant_flag']) {
+
+ // read 512 bits
+ $info['mpeg']['video']['raw']['intra_quant'] = getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $VideoChunkOffset, 64));
+ $VideoChunkOffset += 64;
+
+ $info['mpeg']['video']['raw']['non_intra_quant_flag'] = (bool) getid3_lib::Bin2Dec(substr($info['mpeg']['video']['raw']['intra_quant'], 511, 1));
+ $info['mpeg']['video']['raw']['intra_quant'] = getid3_lib::Bin2Dec(substr($assortedinformation, 31, 1)).substr(getid3_lib::BigEndian2Bin(substr($MPEGstreamData, $VideoChunkOffset, 64)), 0, 511);
+
+ if ($info['mpeg']['video']['raw']['non_intra_quant_flag']) {
+ $info['mpeg']['video']['raw']['non_intra_quant'] = substr($MPEGstreamData, $VideoChunkOffset, 64);
+ $VideoChunkOffset += 64;
+ }
+
+ } else {
+
+ $info['mpeg']['video']['raw']['non_intra_quant_flag'] = (bool) getid3_lib::Bin2Dec(substr($assortedinformation, 31, 1));
+ if ($info['mpeg']['video']['raw']['non_intra_quant_flag']) {
+ $info['mpeg']['video']['raw']['non_intra_quant'] = substr($MPEGstreamData, $VideoChunkOffset, 64);
+ $VideoChunkOffset += 64;
+ }
+
+ }
+
+ if ($info['mpeg']['video']['raw']['bitrate'] == 0x3FFFF) { // 18 set bits
+
+ $info['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']['framesize_horizontal'];
+ $info['video']['resolution_y'] = $info['mpeg']['video']['framesize_vertical'];
+ $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;
+
+ } else {
+
+ $info['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) {
+ $info['video']['codec'] = 'MPEG-2';
+ } else {
+ $info['video']['codec'] = 'MPEG-1';
+ }
+
+
+ $AudioChunkOffset = 0;
+ while (true) {
+ while (substr($MPEGstreamData, $AudioChunkOffset++, 4) !== GETID3_MPEG_AUDIO_START) {
+ if ($AudioChunkOffset >= $MPEGstreamDataLength) {
+ break 2;
+ }
+ }
+
+ $getid3_temp = new getID3();
+ $getid3_temp->openfile($this->getid3->filename);
+ $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
+ fseek($getid3_temp->fp, ftell($this->getid3->fp), SEEK_SET);
+ $getid3_temp->info = $info; // only overwrite real data if valid header found
+ if ($getid3_mp3->decodeMPEGaudioHeader(($AudioChunkOffset + 3) + 8 + $i, $getid3_temp->info, false)) {
+ $info = $getid3_temp->info;
+ $info['audio']['bitrate_mode'] = 'cbr';
+ $info['audio']['lossless'] = false;
+ unset($getid3_temp, $getid3_mp3);
+ break 2;
+ }
+ }
+ unset($getid3_temp, $getid3_mp3);
+ }
+
+ // 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 patter
+ // Use interpolated lookup tables to approximately guess how much is overhead, because
+ // playtime is calculated as filesize / total-bitrate
+ $info['playtime_seconds'] *= $this->MPEGsystemNonOverheadPercentage($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;
+ //$info['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) {
+ $info['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/app/Library/getid3/module.audio-video.nsv.php b/app/Library/getid3/module.audio-video.nsv.php
new file mode 100644
index 00000000..5a587e67
--- /dev/null
+++ b/app/Library/getid3/module.audio-video.nsv.php
@@ -0,0 +1,226 @@
+ //
+// 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 extends getid3_handler
+{
+
+ function Analyze() {
+ $info = &$this->getid3->info;
+
+ fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
+ $NSVheader = fread($this->getid3->fp, 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:
+ $info['error'][] = 'Expecting "NSVs" or "NSVf" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($NSVheader).'"';
+ return false;
+ break;
+ }
+
+ if (!isset($info['nsv']['NSVf'])) {
+ $info['warning'][] = 'NSVf header not present - cannot calculate playtime or bitrate';
+ }
+
+ return true;
+ }
+
+ function getNSVsHeaderFilepointer($fileoffset) {
+ $info = &$this->getid3->info;
+ fseek($this->getid3->fp, $fileoffset, SEEK_SET);
+ $NSVsheader = fread($this->getid3->fp, 28);
+ $offset = 0;
+
+ $info['nsv']['NSVs']['identifier'] = substr($NSVsheader, $offset, 4);
+ $offset += 4;
+
+ if ($info['nsv']['NSVs']['identifier'] != 'NSVs') {
+ $info['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;
+ }
+
+ function getNSVfHeaderFilepointer($fileoffset, $getTOCoffsets=false) {
+ $info = &$this->getid3->info;
+ fseek($this->getid3->fp, $fileoffset, SEEK_SET);
+ $NSVfheader = fread($this->getid3->fp, 28);
+ $offset = 0;
+
+ $info['nsv']['NSVf']['identifier'] = substr($NSVfheader, $offset, 4);
+ $offset += 4;
+
+ if ($info['nsv']['NSVf']['identifier'] != 'NSVf') {
+ $info['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']) {
+ $info['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) {
+ $info['error'][] = 'Corrupt NSV file: NSVf.playtime_ms == zero';
+ return false;
+ }
+
+ $NSVfheader .= fread($this->getid3->fp, $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;
+ }
+
+
+ static 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/app/Library/getid3/module.audio-video.quicktime.php b/app/Library/getid3/module.audio-video.quicktime.php
new file mode 100644
index 00000000..3e96ea1a
--- /dev/null
+++ b/app/Library/getid3/module.audio-video.quicktime.php
@@ -0,0 +1,2134 @@
+ //
+// 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 extends getid3_handler
+{
+
+ var $ReturnAtomData = true;
+ var $ParseAllPossibleAtoms = false;
+
+ 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
+
+ fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
+
+ $offset = 0;
+ $atomcounter = 0;
+
+ while ($offset < $info['avdataend']) {
+ if (!getid3_lib::intValueSupported($offset)) {
+ $info['error'][] = 'Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions';
+ break;
+ }
+ fseek($this->getid3->fp, $offset, SEEK_SET);
+ $AtomHeader = fread($this->getid3->fp, 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($this->getid3->fp, 8));
+ }
+
+ $info['quicktime'][$atomname]['name'] = $atomname;
+ $info['quicktime'][$atomname]['size'] = $atomsize;
+ $info['quicktime'][$atomname]['offset'] = $offset;
+
+ if (($offset + $atomsize) > $info['avdataend']) {
+ $info['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($info['avdataend_tmp']) || ($info['quicktime'][$atomname]['size'] > ($info['avdataend_tmp'] - $info['avdataoffset'])))) {
+
+ $info['avdataoffset'] = $info['quicktime'][$atomname]['offset'] + 8;
+ $OldAVDataEnd = $info['avdataend'];
+ $info['avdataend'] = $info['quicktime'][$atomname]['offset'] + $info['quicktime'][$atomname]['size'];
+
+ $getid3_temp = new getID3();
+ $getid3_temp->openfile($this->getid3->filename);
+ $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(fread($this->getid3->fp, 4)))) {
+ $getid3_mp3->getOnlyMPEGaudioInfo($getid3_temp->info['avdataoffset'], false);
+ if (!empty($getid3_temp->info['warning'])) {
+ foreach ($getid3_temp->info['warning'] as $value) {
+ $info['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);
+
+ }
+ 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();
+ $info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, fread($this->getid3->fp, $atomsize), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms);
+ break;
+ }
+
+ $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['bitrate']) && isset($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['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') && empty($info['video']['resolution_x'])) {
+ $info['fileformat'] = 'mp4';
+ $info['mime_type'] = 'audio/mp4';
+ unset($info['video']['dataformat']);
+ }
+
+ 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';
+ }
+
+ return true;
+ }
+
+ function QuicktimeParseAtom($atomname, $atomsize, $atom_data, $baseoffset, &$atomHierarchy, $ParseAllPossibleAtoms) {
+ // http://developer.apple.com/techpubs/quicktime/qtdevdocs/APIREF/INDEX/atomalphaindex.htm
+
+ $info = &$this->getid3->info;
+
+ $atom_parent = array_pop($atomHierarchy);
+ array_push($atomHierarchy, $atomname);
+ $atom_structure['hierarchy'] = implode(' ', $atomHierarchy);
+ $atom_structure['name'] = $atomname;
+ $atom_structure['size'] = $atomsize;
+ $atom_structure['offset'] = $baseoffset;
+//echo getid3_lib::PrintHexBytes(substr($atom_data, 0, 8)).' ';
+//echo getid3_lib::PrintHexBytes(substr($atom_data, 0, 8), false).'