<?php
+
/////////////////////////////////////////////////////////////////
/// getID3() by James Heinrich <info@getid3.org> //
-// available at http://getid3.sourceforge.net //
-// or http://www.getid3.org //
-// also https://github.com/JamesHeinrich/getID3 //
-/////////////////////////////////////////////////////////////////
-// See readme.txt for more details //
+// available at https://github.com/JamesHeinrich/getID3 //
+// or https://www.getid3.org //
+// or http://getid3.sourceforge.net //
+// see readme.txt for more details //
/////////////////////////////////////////////////////////////////
// //
// module.audio-video.matriska.php //
define('EBML_ID_FILEDESCRIPTION', 0x067E); // [46][7E] -- A human-friendly name for the attached file.
define('EBML_ID_FILEUID', 0x06AE); // [46][AE] -- Unique ID representing the file, as random as possible.
define('EBML_ID_CONTENTENCALGO', 0x07E1); // [47][E1] -- The encryption algorithm used. The value '0' means that the contents have not been encrypted but only signed. Predefined values:
-define('EBML_ID_CONTENTENCKEYID', 0x07E2); // [47][E2] -- For public key algorithms this is the ID of the public key the the data was encrypted with.
+define('EBML_ID_CONTENTENCKEYID', 0x07E2); // [47][E2] -- For public key algorithms this is the ID of the public key the data was encrypted with.
define('EBML_ID_CONTENTSIGNATURE', 0x07E3); // [47][E3] -- A cryptographic signature of the contents.
define('EBML_ID_CONTENTSIGKEYID', 0x07E4); // [47][E4] -- This is the ID of the private key the data was signed with.
define('EBML_ID_CONTENTSIGALGO', 0x07E5); // [47][E5] -- The algorithm used for the signature. A value of '0' means that the contents have not been signed but only encrypted. Predefined values:
*/
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
+ /**
+ * If true, do not return information about CLUSTER chunks, since there's a lot of them
+ * and they're not usually useful [default: TRUE].
+ *
+ * @var bool
+ */
+ public static $hide_clusters = true;
+
+ /**
+ * True to parse the whole file, not only header [default: FALSE].
+ *
+ * @var bool
+ */
+ public static $parse_whole_file = 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);
+ /**
+ * @return bool
+ */
public function Analyze()
{
$info = &$this->getid3->info;
if (!empty($getid3_temp->info[$header_data_key])) {
$info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $getid3_temp->info[$header_data_key];
if (isset($getid3_temp->info['audio']) && is_array($getid3_temp->info['audio'])) {
- foreach ($getid3_temp->info['audio'] as $key => $value) {
- $track_info[$key] = $value;
+ foreach ($getid3_temp->info['audio'] as $sub_key => $value) {
+ $track_info[$sub_key] = $value;
}
}
}
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;
+ foreach ($getid3_temp->info['audio'] as $sub_key => $value) {
+ $track_info[$sub_key] = $value;
}
}
}
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
$parsed = getid3_riff::parseWAVEFORMATex($trackarray['CodecPrivate']);
- foreach ($parsed as $key => $value) {
- if ($key != 'raw') {
- $track_info[$key] = $value;
+ foreach ($parsed as $sub_key => $value) {
+ if ($sub_key != 'raw') {
+ $track_info[$sub_key] = $value;
}
}
$info['matroska']['track_codec_parsed'][$trackarray['TrackNumber']] = $parsed;
return true;
}
+ /**
+ * @param array $info
+ */
private function parseEBML(&$info) {
// http://www.matroska.org/technical/specs/index.html#EBMLBasics
$this->current_offset = $info['avdataoffset'];
}
}
+ /**
+ * @param int $min_data
+ *
+ * @return bool
+ */
private function EnsureBufferHasEnoughData($min_data=1024) {
if (($this->current_offset - $this->EBMLbuffer_offset) >= ($this->EBMLbuffer_length - $min_data)) {
$read_bytes = max($min_data, $this->getid3->fread_buffer_size());
return true;
}
+ /**
+ * @return int|float|false
+ */
private function readEBMLint() {
$actual_offset = $this->current_offset - $this->EBMLbuffer_offset;
return $int_value;
}
+ /**
+ * @param int $length
+ * @param bool $check_buffer
+ *
+ * @return string|false
+ */
private function readEBMLelementData($length, $check_buffer=false) {
if ($check_buffer && !$this->EnsureBufferHasEnoughData($length)) {
return false;
return $data;
}
+ /**
+ * @param array $element
+ * @param int $parent_end
+ * @param array|bool $get_data
+ *
+ * @return bool
+ */
private function getEBMLelement(&$element, $parent_end, $get_data=false) {
if ($this->current_offset >= $parent_end) {
return false;
return true;
}
+ /**
+ * @param string $type
+ * @param int $line
+ * @param array $element
+ */
private function unhandledElement($type, $line, $element) {
// warn only about unknown and missed elements, not about unuseful
if (!in_array($element['id'], $this->unuseful_elements)) {
}
}
+ /**
+ * @param array $SimpleTagArray
+ *
+ * @return bool
+ */
private function ExtractCommentsSimpleTag($SimpleTagArray) {
if (!empty($SimpleTagArray['SimpleTag'])) {
foreach ($SimpleTagArray['SimpleTag'] as $SimpleTagKey => $SimpleTagData) {
return true;
}
+ /**
+ * @param int $parent_end
+ *
+ * @return array
+ */
private function HandleEMBLSimpleTag($parent_end) {
$simpletag_entry = array();
return $simpletag_entry;
}
+ /**
+ * @param array $element
+ * @param int $block_type
+ * @param array $info
+ *
+ * @return array
+ */
private function HandleEMBLClusterBlock($element, $block_type, &$info) {
// http://www.matroska.org/technical/specs/index.html#block_structure
// http://www.matroska.org/technical/specs/index.html#simpleblock_structure
return $block_data;
}
+ /**
+ * @param string $EBMLstring
+ *
+ * @return int|float|false
+ */
private static function EBML2Int($EBMLstring) {
// http://matroska.org/specs/
return getid3_lib::BigEndian2Int($EBMLstring);
}
+ /**
+ * @param int $EBMLdatestamp
+ *
+ * @return float
+ */
private static function EBMLdate2unix($EBMLdatestamp) {
// Date - signed 8 octets integer in nanoseconds with 0 indicating the precise beginning of the millennium (at 2001-01-01T00:00:00,000000000 UTC)
// 978307200 == mktime(0, 0, 0, 1, 1, 2001) == January 1, 2001 12:00:00am UTC
return round(($EBMLdatestamp / 1000000000) + 978307200);
}
+ /**
+ * @param int $target_type
+ *
+ * @return string|int
+ */
public static function TargetTypeValue($target_type) {
// http://www.matroska.org/technical/specs/tagging/index.html
static $TargetTypeValue = array();
return (isset($TargetTypeValue[$target_type]) ? $TargetTypeValue[$target_type] : $target_type);
}
+ /**
+ * @param int $lacingtype
+ *
+ * @return string|int
+ */
public static function BlockLacingType($lacingtype) {
// http://matroska.org/technical/specs/index.html#block_structure
static $BlockLacingType = array();
return (isset($BlockLacingType[$lacingtype]) ? $BlockLacingType[$lacingtype] : $lacingtype);
}
+ /**
+ * @param string $codecid
+ *
+ * @return string
+ */
public static function CodecIDtoCommonName($codecid) {
// http://www.matroska.org/technical/specs/codecid/index.html
static $CodecIDlist = array();
return (isset($CodecIDlist[$codecid]) ? $CodecIDlist[$codecid] : $codecid);
}
+ /**
+ * @param int $value
+ *
+ * @return string
+ */
private static function EBMLidName($value) {
static $EBMLidList = array();
if (empty($EBMLidList)) {
return (isset($EBMLidList[$value]) ? $EBMLidList[$value] : dechex($value));
}
+ /**
+ * @param int $value
+ *
+ * @return string
+ */
public static function displayUnit($value) {
// http://www.matroska.org/technical/specs/index.html#DisplayUnit
static $units = array(
return (isset($units[$value]) ? $units[$value] : 'unknown');
}
+ /**
+ * @param array $streams
+ *
+ * @return array
+ */
private static function getDefaultStreamInfo($streams)
{
+ $stream = array();
foreach (array_reverse($streams) as $stream) {
if ($stream['default']) {
break;