[SPIP] ~maj v3.2.9-->v3.2.11
[lhc/web/www.git] / www / plugins-dist / medias / lib / getid3 / module.audio-video.matroska.php
index b2b187b..a285108 100644 (file)
@@ -14,6 +14,9 @@
 //                                                            ///
 /////////////////////////////////////////////////////////////////
 
+if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
+       exit;
+}
 
 define('EBML_ID_CHAPTERS',                  0x0043A770); // [10][43][A7][70] -- A system to define basic menus and partition data. For more detailed information, look at the Chapters Explanation.
 define('EBML_ID_SEEKHEAD',                  0x014D9B74); // [11][4D][9B][74] -- Contains the position of other level 1 elements.
@@ -329,7 +332,7 @@ class getid3_matroska extends getid3_handler
                                                                break;*/
                                                }
 
-                                               $info['video']['streams'][] = $track_info;
+                                               $info['video']['streams'][$trackarray['TrackUID']] = $track_info;
                                                break;
 
                                        case 2: // Audio
@@ -342,7 +345,7 @@ class getid3_matroska extends getid3_handler
                                                switch ($trackarray['CodecID']) {
                                                        case 'A_PCM/INT/LIT':
                                                        case 'A_PCM/INT/BIG':
-                                                               $track_info['bitrate'] = $trackarray['SamplingFrequency'] * $trackarray['Channels'] * $trackarray['BitDepth'];
+                                                               $track_info['bitrate'] = $track_info['sample_rate'] * $track_info['channels'] * $trackarray['BitDepth'];
                                                                break;
 
                                                        case 'A_AC3':
@@ -362,7 +365,7 @@ class getid3_matroska extends getid3_handler
                                                                // create temp instance
                                                                $getid3_temp = new getID3();
                                                                if ($track_info['dataformat'] != 'flac') {
-                                                                       $getid3_temp->openfile($this->getid3->filename);
+                                                                       $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp);
                                                                }
                                                                $getid3_temp->info['avdataoffset'] = $info['matroska']['track_data_offsets'][$trackarray['TrackNumber']]['offset'];
                                                                if ($track_info['dataformat'][0] == 'm' || $track_info['dataformat'] == 'flac') {
@@ -478,7 +481,7 @@ class getid3_matroska extends getid3_handler
                                                                break;
                                                }
 
-                                               $info['audio']['streams'][] = $track_info;
+                                               $info['audio']['streams'][$trackarray['TrackUID']] = $track_info;
                                                break;
                                }
                        }
@@ -509,6 +512,30 @@ class getid3_matroska extends getid3_handler
                        unset($info['mime_type']);
                }
 
+               // use _STATISTICS_TAGS if available to set audio/video bitrates
+               if (!empty($info['matroska']['tags'])) {
+                       $_STATISTICS_byTrackUID = array();
+                       foreach ($info['matroska']['tags'] as $key1 => $value1) {
+                               if (!empty($value1['Targets']['TagTrackUID'][0]) && !empty($value1['SimpleTag'])) {
+                                       foreach ($value1['SimpleTag'] as $key2 => $value2) {
+                                               if (!empty($value2['TagName']) && isset($value2['TagString'])) {
+                                                       $_STATISTICS_byTrackUID[$value1['Targets']['TagTrackUID'][0]][$value2['TagName']] = $value2['TagString'];
+                                               }
+                                       }
+                               }
+                       }
+                       foreach (array('audio','video') as $avtype) {
+                               if (!empty($info[$avtype]['streams'])) {
+                                       foreach ($info[$avtype]['streams'] as $trackUID => $trackdata) {
+                                               if (!isset($trackdata['bitrate']) && !empty($_STATISTICS_byTrackUID[$trackUID]['BPS'])) {
+                                                       $info[$avtype]['streams'][$trackUID]['bitrate'] = (int) $_STATISTICS_byTrackUID[$trackUID]['BPS'];
+                                                       @$info[$avtype]['bitrate'] += $info[$avtype]['streams'][$trackUID]['bitrate'];
+                                               }
+                                       }
+                               }
+                       }
+               }
+
                return true;
        }
 
@@ -614,8 +641,10 @@ class getid3_matroska extends getid3_handler
                                                                                        while ($this->getEBMLelement($subelement, $track_entry['end'], array(EBML_ID_VIDEO, EBML_ID_AUDIO, EBML_ID_CONTENTENCODINGS, EBML_ID_CODECPRIVATE))) {
                                                                                                switch ($subelement['id']) {
 
-                                                                                                       case EBML_ID_TRACKNUMBER:
                                                                                                        case EBML_ID_TRACKUID:
+                                                                                                               $track_entry[$subelement['id_name']] = getid3_lib::PrintHexBytes($subelement['data'], true, false);
+                                                                                                               break;
+                                                                                                       case EBML_ID_TRACKNUMBER:
                                                                                                        case EBML_ID_TRACKTYPE:
                                                                                                        case EBML_ID_MINCACHE:
                                                                                                        case EBML_ID_MAXCACHE:
@@ -963,7 +992,7 @@ class getid3_matroska extends getid3_handler
                                                                                                                                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']);
+                                                                                                                                       $targets_entry[$sub_sub_subelement['id_name']][] = getid3_lib::PrintHexBytes($sub_sub_subelement['data'], true, false);
                                                                                                                                        break;
 
                                                                                                                                default: