ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_shorten Class Reference

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g // More...

+ Inheritance diagram for getid3_shorten:
+ Collaboration diagram for getid3_shorten:

Public Member Functions

 getid3_shorten (&$fd, &$ThisFileInfo)
 
 Analyze ()
 
- Public Member Functions inherited from getid3_handler
 __construct (getID3 $getid3, $call_module=null)
 
 Analyze ()
 
 AnalyzeString ($string)
 
 setStringMode ($string)
 
 saveAttachment ($name, $offset, $length, $image_mime=null)
 

Additional Inherited Members

- Protected Member Functions inherited from getid3_handler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
 notice ($text)
 
- Protected Attributes inherited from getid3_handler
 $getid3
 
 $data_string_flag = false
 
 $data_string = ''
 
 $data_string_position = 0
 
 $data_string_length = 0
 

Detailed Description

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //

Definition at line 17 of file module.audio.shorten.php.

Member Function Documentation

◆ Analyze()

getid3_shorten::Analyze ( )

Reimplemented from getid3_handler.

Definition at line 21 of file module.audio.shorten.php.

21 {
22 $info = &$this->getid3->info;
23
24 $this->fseek($info['avdataoffset']);
25
26 $ShortenHeader = $this->fread(8);
27 $magic = 'ajkg';
28 if (substr($ShortenHeader, 0, 4) != $magic) {
29 $info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($ShortenHeader, 0, 4)).'"';
30 return false;
31 }
32 $info['fileformat'] = 'shn';
33 $info['audio']['dataformat'] = 'shn';
34 $info['audio']['lossless'] = true;
35 $info['audio']['bitrate_mode'] = 'vbr';
36
37 $info['shn']['version'] = getid3_lib::LittleEndian2Int(substr($ShortenHeader, 4, 1));
38
39 $this->fseek($info['avdataend'] - 12);
40 $SeekTableSignatureTest = $this->fread(12);
41 $info['shn']['seektable']['present'] = (bool) (substr($SeekTableSignatureTest, 4, 8) == 'SHNAMPSK');
42 if ($info['shn']['seektable']['present']) {
43 $info['shn']['seektable']['length'] = getid3_lib::LittleEndian2Int(substr($SeekTableSignatureTest, 0, 4));
44 $info['shn']['seektable']['offset'] = $info['avdataend'] - $info['shn']['seektable']['length'];
45 $this->fseek($info['shn']['seektable']['offset']);
46 $SeekTableMagic = $this->fread(4);
47 $magic = 'SEEK';
48 if ($SeekTableMagic != $magic) {
49
50 $info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['shn']['seektable']['offset'].', found "'.getid3_lib::PrintHexBytes($SeekTableMagic).'"';
51 return false;
52
53 } else {
54
55 // typedef struct tag_TSeekEntry
56 // {
57 // unsigned long SampleNumber;
58 // unsigned long SHNFileByteOffset;
59 // unsigned long SHNLastBufferReadPosition;
60 // unsigned short SHNByteGet;
61 // unsigned short SHNBufferOffset;
62 // unsigned short SHNFileBitOffset;
63 // unsigned long SHNGBuffer;
64 // unsigned short SHNBitShift;
65 // long CBuf0[3];
66 // long CBuf1[3];
67 // long Offset0[4];
68 // long Offset1[4];
69 // }TSeekEntry;
70
71 $SeekTableData = $this->fread($info['shn']['seektable']['length'] - 16);
72 $info['shn']['seektable']['entry_count'] = floor(strlen($SeekTableData) / 80);
73 //$info['shn']['seektable']['entries'] = array();
74 //$SeekTableOffset = 0;
75 //for ($i = 0; $i < $info['shn']['seektable']['entry_count']; $i++) {
76 // $SeekTableEntry['sample_number'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
77 // $SeekTableOffset += 4;
78 // $SeekTableEntry['shn_file_byte_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
79 // $SeekTableOffset += 4;
80 // $SeekTableEntry['shn_last_buffer_read_position'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
81 // $SeekTableOffset += 4;
82 // $SeekTableEntry['shn_byte_get'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
83 // $SeekTableOffset += 2;
84 // $SeekTableEntry['shn_buffer_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
85 // $SeekTableOffset += 2;
86 // $SeekTableEntry['shn_file_bit_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
87 // $SeekTableOffset += 2;
88 // $SeekTableEntry['shn_gbuffer'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
89 // $SeekTableOffset += 4;
90 // $SeekTableEntry['shn_bit_shift'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
91 // $SeekTableOffset += 2;
92 // for ($j = 0; $j < 3; $j++) {
93 // $SeekTableEntry['cbuf0'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
94 // $SeekTableOffset += 4;
95 // }
96 // for ($j = 0; $j < 3; $j++) {
97 // $SeekTableEntry['cbuf1'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
98 // $SeekTableOffset += 4;
99 // }
100 // for ($j = 0; $j < 4; $j++) {
101 // $SeekTableEntry['offset0'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
102 // $SeekTableOffset += 4;
103 // }
104 // for ($j = 0; $j < 4; $j++) {
105 // $SeekTableEntry['offset1'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
106 // $SeekTableOffset += 4;
107 // }
108 //
109 // $info['shn']['seektable']['entries'][] = $SeekTableEntry;
110 //}
111
112 }
113
114 }
115
116 if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) {
117 $info['error'][] = 'PHP running in Safe Mode - backtick operator not available, cannot run shntool to analyze Shorten files';
118 return false;
119 }
120
121 if (GETID3_OS_ISWINDOWS) {
122
123 $RequiredFiles = array('shorten.exe', 'cygwin1.dll', 'head.exe');
124 foreach ($RequiredFiles as $required_file) {
125 if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
126 $info['error'][] = GETID3_HELPERAPPSDIR.$required_file.' does not exist';
127 return false;
128 }
129 }
130 $commandline = GETID3_HELPERAPPSDIR.'shorten.exe -x "'.$info['filenamepath'].'" - | '.GETID3_HELPERAPPSDIR.'head.exe -c 64';
131 $commandline = str_replace('/', '\\', $commandline);
132
133 } else {
134
135 static $shorten_present;
136 if (!isset($shorten_present)) {
137 $shorten_present = file_exists('/usr/local/bin/shorten') || `which shorten`;
138 }
139 if (!$shorten_present) {
140 $info['error'][] = 'shorten binary was not found in path or /usr/local/bin';
141 return false;
142 }
143 $commandline = (file_exists('/usr/local/bin/shorten') ? '/usr/local/bin/' : '' ) . 'shorten -x '.escapeshellarg($info['filenamepath']).' - | head -c 64';
144
145 }
146
147 $output = `$commandline`;
148
149 if (!empty($output) && (substr($output, 12, 4) == 'fmt ')) {
150
151 getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
152
153 $fmt_size = getid3_lib::LittleEndian2Int(substr($output, 16, 4));
154 $DecodedWAVFORMATEX = getid3_riff::parseWAVEFORMATex(substr($output, 20, $fmt_size));
155 $info['audio']['channels'] = $DecodedWAVFORMATEX['channels'];
156 $info['audio']['bits_per_sample'] = $DecodedWAVFORMATEX['bits_per_sample'];
157 $info['audio']['sample_rate'] = $DecodedWAVFORMATEX['sample_rate'];
158
159 if (substr($output, 20 + $fmt_size, 4) == 'data') {
160
161 $info['playtime_seconds'] = getid3_lib::LittleEndian2Int(substr($output, 20 + 4 + $fmt_size, 4)) / $DecodedWAVFORMATEX['raw']['nAvgBytesPerSec'];
162
163 } else {
164
165 $info['error'][] = 'shorten failed to decode DATA chunk to expected location, cannot determine playtime';
166 return false;
167
168 }
169
170 $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8;
171
172 } else {
173
174 $info['error'][] = 'shorten failed to decode file to WAV for parsing';
175 return false;
176
177 }
178
179 return true;
180 }
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
fread($bytes)
Definition: getid3.php:1685
LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:266
IncludeDependency($filename, $sourcefile, $DieOnFailure=false)
PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true)
Definition: getid3.lib.php:17
static parseWAVEFORMATex($WaveFormatExData)
$info
Definition: example_052.php:80

References $info, getid3_handler\fread(), getid3_handler\fseek(), getid3_lib\IncludeDependency(), getid3_lib\LittleEndian2Int(), getid3_riff\parseWAVEFORMATex(), and getid3_lib\PrintHexBytes().

+ Here is the call graph for this function:

◆ getid3_shorten()

getid3_shorten::getid3_shorten ( $fd,
$ThisFileInfo 
)

Definition at line 20 of file module.audio.shorten.php.

20 {
21
22 fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
23
24 $ShortenHeader = fread($fd, 8);
25 if (substr($ShortenHeader, 0, 4) != 'ajkg') {
26 $ThisFileInfo['error'][] = 'Expecting "ajkg" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($ShortenHeader, 0, 4).'"';
27 return false;
28 }
29 $ThisFileInfo['fileformat'] = 'shn';
30 $ThisFileInfo['audio']['dataformat'] = 'shn';
31 $ThisFileInfo['audio']['lossless'] = true;
32 $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
33
34 $ThisFileInfo['shn']['version'] = getid3_lib::LittleEndian2Int(substr($ShortenHeader, 4, 1));
35
36 fseek($fd, $ThisFileInfo['avdataend'] - 12, SEEK_SET);
37 $SeekTableSignatureTest = fread($fd, 12);
38 $ThisFileInfo['shn']['seektable']['present'] = (bool) (substr($SeekTableSignatureTest, 4, 8) == 'SHNAMPSK');
39 if ($ThisFileInfo['shn']['seektable']['present']) {
40 $ThisFileInfo['shn']['seektable']['length'] = getid3_lib::LittleEndian2Int(substr($SeekTableSignatureTest, 0, 4));
41 $ThisFileInfo['shn']['seektable']['offset'] = $ThisFileInfo['avdataend'] - $ThisFileInfo['shn']['seektable']['length'];
42 fseek($fd, $ThisFileInfo['shn']['seektable']['offset'], SEEK_SET);
43 $SeekTableMagic = fread($fd, 4);
44 if ($SeekTableMagic != 'SEEK') {
45
46 $ThisFileInfo['error'][] = 'Expecting "SEEK" at offset '.$ThisFileInfo['shn']['seektable']['offset'].', found "'.$SeekTableMagic.'"';
47 return false;
48
49 } else {
50
51 // typedef struct tag_TSeekEntry
52 // {
53 // unsigned long SampleNumber;
54 // unsigned long SHNFileByteOffset;
55 // unsigned long SHNLastBufferReadPosition;
56 // unsigned short SHNByteGet;
57 // unsigned short SHNBufferOffset;
58 // unsigned short SHNFileBitOffset;
59 // unsigned long SHNGBuffer;
60 // unsigned short SHNBitShift;
61 // long CBuf0[3];
62 // long CBuf1[3];
63 // long Offset0[4];
64 // long Offset1[4];
65 // }TSeekEntry;
66
67 $SeekTableData = fread($fd, $ThisFileInfo['shn']['seektable']['length'] - 16);
68 $ThisFileInfo['shn']['seektable']['entry_count'] = floor(strlen($SeekTableData) / 80);
69 //$ThisFileInfo['shn']['seektable']['entries'] = array();
70 //$SeekTableOffset = 0;
71 //for ($i = 0; $i < $ThisFileInfo['shn']['seektable']['entry_count']; $i++) {
72 // $SeekTableEntry['sample_number'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
73 // $SeekTableOffset += 4;
74 // $SeekTableEntry['shn_file_byte_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
75 // $SeekTableOffset += 4;
76 // $SeekTableEntry['shn_last_buffer_read_position'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
77 // $SeekTableOffset += 4;
78 // $SeekTableEntry['shn_byte_get'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
79 // $SeekTableOffset += 2;
80 // $SeekTableEntry['shn_buffer_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
81 // $SeekTableOffset += 2;
82 // $SeekTableEntry['shn_file_bit_offset'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
83 // $SeekTableOffset += 2;
84 // $SeekTableEntry['shn_gbuffer'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
85 // $SeekTableOffset += 4;
86 // $SeekTableEntry['shn_bit_shift'] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 2));
87 // $SeekTableOffset += 2;
88 // for ($j = 0; $j < 3; $j++) {
89 // $SeekTableEntry['cbuf0'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
90 // $SeekTableOffset += 4;
91 // }
92 // for ($j = 0; $j < 3; $j++) {
93 // $SeekTableEntry['cbuf1'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
94 // $SeekTableOffset += 4;
95 // }
96 // for ($j = 0; $j < 4; $j++) {
97 // $SeekTableEntry['offset0'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
98 // $SeekTableOffset += 4;
99 // }
100 // for ($j = 0; $j < 4; $j++) {
101 // $SeekTableEntry['offset1'][$j] = getid3_lib::LittleEndian2Int(substr($SeekTableData, $SeekTableOffset, 4));
102 // $SeekTableOffset += 4;
103 // }
104 //
105 // $ThisFileInfo['shn']['seektable']['entries'][] = $SeekTableEntry;
106 //}
107
108 }
109
110 }
111
112 if ((bool) ini_get('safe_mode')) {
113 $ThisFileInfo['error'][] = 'PHP running in Safe Mode - backtick operator not available, cannot run shntool to analyze Shorten files';
114 return false;
115 }
116
117 if (GETID3_OS_ISWINDOWS) {
118
119 $RequiredFiles = array('shorten.exe', 'cygwin1.dll', 'head.exe');
120 foreach ($RequiredFiles as $required_file) {
121 if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
122 $ThisFileInfo['error'][] = GETID3_HELPERAPPSDIR.$required_file.' does not exist';
123 return false;
124 }
125 }
126 $commandline = GETID3_HELPERAPPSDIR.'shorten.exe -x "'.$ThisFileInfo['filenamepath'].'" - | '.GETID3_HELPERAPPSDIR.'head.exe -c 44';
127 $commandline = str_replace('/', '\\', $commandline);
128
129 } else {
130
131 static $shorten_present;
132 if (!isset($shorten_present)) {
133 $shorten_present = file_exists('/usr/local/bin/shorten') || `which shorten`;
134 }
135 if (!$shorten_present) {
136 $ThisFileInfo['error'][] = 'shorten binary was not found in path or /usr/local/bin';
137 return false;
138 }
139 $commandline = (file_exists('/usr/local/bin/shorten') ? '/usr/local/bin/' : '' ) . 'shorten -x '.escapeshellarg($ThisFileInfo['filenamepath']).' - | head -c 44';
140
141 }
142
143 $output = `$commandline`;
144
145 if (!empty($output) && (substr($output, 12, 4) == 'fmt ')) {
146
147 getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
148
149 $DecodedWAVFORMATEX = getid3_riff::RIFFparseWAVEFORMATex(substr($output, 20, 16));
150 $ThisFileInfo['audio']['channels'] = $DecodedWAVFORMATEX['channels'];
151 $ThisFileInfo['audio']['bits_per_sample'] = $DecodedWAVFORMATEX['bits_per_sample'];
152 $ThisFileInfo['audio']['sample_rate'] = $DecodedWAVFORMATEX['sample_rate'];
153
154 if (substr($output, 36, 4) == 'data') {
155
156 $ThisFileInfo['playtime_seconds'] = getid3_lib::LittleEndian2Int(substr($output, 40, 4)) / $DecodedWAVFORMATEX['raw']['nAvgBytesPerSec'];
157
158 } else {
159
160 $ThisFileInfo['error'][] = 'shorten failed to decode DATA chunk to expected location, cannot determine playtime';
161 return false;
162
163 }
164
165 $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['playtime_seconds']) * 8;
166
167 } else {
168
169 $ThisFileInfo['error'][] = 'shorten failed to decode file to WAV for parsing';
170 return false;
171
172 }
173
174 return true;
175 }
RIFFparseWAVEFORMATex($WaveFormatExData)

References getid3_handler\fread(), getid3_handler\fseek(), getid3_lib\IncludeDependency(), getid3_lib\LittleEndian2Int(), and getid3_riff\RIFFparseWAVEFORMATex().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: