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
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']) {
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 $SeekTableData =
fread($fd, $ThisFileInfo[
'shn'][
'seektable'][
'length'] - 16);
68 $ThisFileInfo['shn']['seektable']['entry_count'] = floor(strlen($SeekTableData) / 80);
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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
148
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)