~ubuntu-branches/debian/sid/ampache/sid

« back to all changes in this revision

Viewing changes to modules/getid3/module.audio.shorten.php

  • Committer: Package Import Robot
  • Author(s): Charlie Smotherman
  • Date: 2013-08-27 13:19:48 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20130827131948-1czew0zxn6u70dtv
Tags: 3.6-rzb2752+dfsg-1
* New upsteam snapshot.  Contains important bug fixes to the installer.
* Correct typo in ampache-common.postrm.
* Remove courtousy copy of php-getid3, during repack.  Closes: #701526
* Update package to use dh_linktree to make the needed sym links to the
  needed system libs that were removed during repack.
* Update debian/rules to reflect upstreams removing/moving of modules.
* Update debian/ampache-common.install to reflect upstreams removal of files.
* Updated to use new apache2.4 API. Closes: #669756
* Updated /debian/po/de.po thx David Prévot for the patch.  Closes:  #691963
* M3U import is now ordered, fixed upstream.  Closes: #684984
* Text input area has been resized so IPv6 addresses will now fit, fixed
  upstream.  Closes:  #716230
* Added ampache-common.preinst to make sure that the courtousy copies of code
  dirs are empty so dh_linktree can do it's magic on upgrades.

Show diffs side-by-side

added added

removed removed

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