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

« back to all changes in this revision

Viewing changes to modules/getid3/module.audio-video.nsv.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.nsv.php                                        //
11
 
// module for analyzing Nullsoft NSV files                     //
12
 
// dependencies: NONE                                          //
13
 
//                                                            ///
14
 
/////////////////////////////////////////////////////////////////
15
 
 
16
 
 
17
 
class getid3_nsv extends getid3_handler
18
 
{
19
 
 
20
 
        function Analyze() {
21
 
                $info = &$this->getid3->info;
22
 
 
23
 
                fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
24
 
                $NSVheader = fread($this->getid3->fp, 4);
25
 
 
26
 
                switch ($NSVheader) {
27
 
                        case 'NSVs':
28
 
                                if ($this->getNSVsHeaderFilepointer(0)) {
29
 
                                        $info['fileformat']          = 'nsv';
30
 
                                        $info['audio']['dataformat'] = 'nsv';
31
 
                                        $info['video']['dataformat'] = 'nsv';
32
 
                                        $info['audio']['lossless']   = false;
33
 
                                        $info['video']['lossless']   = false;
34
 
                                }
35
 
                                break;
36
 
 
37
 
                        case 'NSVf':
38
 
                                if ($this->getNSVfHeaderFilepointer(0)) {
39
 
                                        $info['fileformat']          = 'nsv';
40
 
                                        $info['audio']['dataformat'] = 'nsv';
41
 
                                        $info['video']['dataformat'] = 'nsv';
42
 
                                        $info['audio']['lossless']   = false;
43
 
                                        $info['video']['lossless']   = false;
44
 
                                        $this->getNSVsHeaderFilepointer($info['nsv']['NSVf']['header_length']);
45
 
                                }
46
 
                                break;
47
 
 
48
 
                        default:
49
 
                                $info['error'][] = 'Expecting "NSVs" or "NSVf" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($NSVheader).'"';
50
 
                                return false;
51
 
                                break;
52
 
                }
53
 
 
54
 
                if (!isset($info['nsv']['NSVf'])) {
55
 
                        $info['warning'][] = 'NSVf header not present - cannot calculate playtime or bitrate';
56
 
                }
57
 
 
58
 
                return true;
59
 
        }
60
 
 
61
 
        function getNSVsHeaderFilepointer($fileoffset) {
62
 
                $info = &$this->getid3->info;
63
 
                fseek($this->getid3->fp, $fileoffset, SEEK_SET);
64
 
                $NSVsheader = fread($this->getid3->fp, 28);
65
 
                $offset = 0;
66
 
 
67
 
                $info['nsv']['NSVs']['identifier']      =                  substr($NSVsheader, $offset, 4);
68
 
                $offset += 4;
69
 
 
70
 
                if ($info['nsv']['NSVs']['identifier'] != 'NSVs') {
71
 
                        $info['error'][] = 'expected "NSVs" at offset ('.$fileoffset.'), found "'.$info['nsv']['NSVs']['identifier'].'" instead';
72
 
                        unset($info['nsv']['NSVs']);
73
 
                        return false;
74
 
                }
75
 
 
76
 
                $info['nsv']['NSVs']['offset']          = $fileoffset;
77
 
 
78
 
                $info['nsv']['NSVs']['video_codec']     =                              substr($NSVsheader, $offset, 4);
79
 
                $offset += 4;
80
 
                $info['nsv']['NSVs']['audio_codec']     =                              substr($NSVsheader, $offset, 4);
81
 
                $offset += 4;
82
 
                $info['nsv']['NSVs']['resolution_x']    = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2));
83
 
                $offset += 2;
84
 
                $info['nsv']['NSVs']['resolution_y']    = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2));
85
 
                $offset += 2;
86
 
 
87
 
                $info['nsv']['NSVs']['framerate_index'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
88
 
                $offset += 1;
89
 
                //$info['nsv']['NSVs']['unknown1b']       = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
90
 
                $offset += 1;
91
 
                //$info['nsv']['NSVs']['unknown1c']       = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
92
 
                $offset += 1;
93
 
                //$info['nsv']['NSVs']['unknown1d']       = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
94
 
                $offset += 1;
95
 
                //$info['nsv']['NSVs']['unknown2a']       = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
96
 
                $offset += 1;
97
 
                //$info['nsv']['NSVs']['unknown2b']       = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
98
 
                $offset += 1;
99
 
                //$info['nsv']['NSVs']['unknown2c']       = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
100
 
                $offset += 1;
101
 
                //$info['nsv']['NSVs']['unknown2d']       = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
102
 
                $offset += 1;
103
 
 
104
 
                switch ($info['nsv']['NSVs']['audio_codec']) {
105
 
                        case 'PCM ':
106
 
                                $info['nsv']['NSVs']['bits_channel'] = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
107
 
                                $offset += 1;
108
 
                                $info['nsv']['NSVs']['channels']     = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 1));
109
 
                                $offset += 1;
110
 
                                $info['nsv']['NSVs']['sample_rate']  = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 2));
111
 
                                $offset += 2;
112
 
 
113
 
                                $info['audio']['sample_rate']        = $info['nsv']['NSVs']['sample_rate'];
114
 
                                break;
115
 
 
116
 
                        case 'MP3 ':
117
 
                        case 'NONE':
118
 
                        default:
119
 
                                //$info['nsv']['NSVs']['unknown3']     = getid3_lib::LittleEndian2Int(substr($NSVsheader, $offset, 4));
120
 
                                $offset += 4;
121
 
                                break;
122
 
                }
123
 
 
124
 
                $info['video']['resolution_x']       = $info['nsv']['NSVs']['resolution_x'];
125
 
                $info['video']['resolution_y']       = $info['nsv']['NSVs']['resolution_y'];
126
 
                $info['nsv']['NSVs']['frame_rate']   = $this->NSVframerateLookup($info['nsv']['NSVs']['framerate_index']);
127
 
                $info['video']['frame_rate']         = $info['nsv']['NSVs']['frame_rate'];
128
 
                $info['video']['bits_per_sample']    = 24;
129
 
                $info['video']['pixel_aspect_ratio'] = (float) 1;
130
 
 
131
 
                return true;
132
 
        }
133
 
 
134
 
        function getNSVfHeaderFilepointer($fileoffset, $getTOCoffsets=false) {
135
 
                $info = &$this->getid3->info;
136
 
                fseek($this->getid3->fp, $fileoffset, SEEK_SET);
137
 
                $NSVfheader = fread($this->getid3->fp, 28);
138
 
                $offset = 0;
139
 
 
140
 
                $info['nsv']['NSVf']['identifier']    =                  substr($NSVfheader, $offset, 4);
141
 
                $offset += 4;
142
 
 
143
 
                if ($info['nsv']['NSVf']['identifier'] != 'NSVf') {
144
 
                        $info['error'][] = 'expected "NSVf" at offset ('.$fileoffset.'), found "'.$info['nsv']['NSVf']['identifier'].'" instead';
145
 
                        unset($info['nsv']['NSVf']);
146
 
                        return false;
147
 
                }
148
 
 
149
 
                $info['nsv']['NSVs']['offset']        = $fileoffset;
150
 
 
151
 
                $info['nsv']['NSVf']['header_length'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
152
 
                $offset += 4;
153
 
                $info['nsv']['NSVf']['file_size']     = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
154
 
                $offset += 4;
155
 
 
156
 
                if ($info['nsv']['NSVf']['file_size'] > $info['avdataend']) {
157
 
                        $info['warning'][] = 'truncated file - NSVf header indicates '.$info['nsv']['NSVf']['file_size'].' bytes, file actually '.$info['avdataend'].' bytes';
158
 
                }
159
 
 
160
 
                $info['nsv']['NSVf']['playtime_ms']   = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
161
 
                $offset += 4;
162
 
                $info['nsv']['NSVf']['meta_size']     = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
163
 
                $offset += 4;
164
 
                $info['nsv']['NSVf']['TOC_entries_1'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
165
 
                $offset += 4;
166
 
                $info['nsv']['NSVf']['TOC_entries_2'] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
167
 
                $offset += 4;
168
 
 
169
 
                if ($info['nsv']['NSVf']['playtime_ms'] == 0) {
170
 
                        $info['error'][] = 'Corrupt NSV file: NSVf.playtime_ms == zero';
171
 
                        return false;
172
 
                }
173
 
 
174
 
                $NSVfheader .= fread($this->getid3->fp, $info['nsv']['NSVf']['meta_size'] + (4 * $info['nsv']['NSVf']['TOC_entries_1']) + (4 * $info['nsv']['NSVf']['TOC_entries_2']));
175
 
                $NSVfheaderlength = strlen($NSVfheader);
176
 
                $info['nsv']['NSVf']['metadata']      =                  substr($NSVfheader, $offset, $info['nsv']['NSVf']['meta_size']);
177
 
                $offset += $info['nsv']['NSVf']['meta_size'];
178
 
 
179
 
                if ($getTOCoffsets) {
180
 
                        $TOCcounter = 0;
181
 
                        while ($TOCcounter < $info['nsv']['NSVf']['TOC_entries_1']) {
182
 
                                if ($TOCcounter < $info['nsv']['NSVf']['TOC_entries_1']) {
183
 
                                        $info['nsv']['NSVf']['TOC_1'][$TOCcounter] = getid3_lib::LittleEndian2Int(substr($NSVfheader, $offset, 4));
184
 
                                        $offset += 4;
185
 
                                        $TOCcounter++;
186
 
                                }
187
 
                        }
188
 
                }
189
 
 
190
 
                if (trim($info['nsv']['NSVf']['metadata']) != '') {
191
 
                        $info['nsv']['NSVf']['metadata'] = str_replace('`', "\x01", $info['nsv']['NSVf']['metadata']);
192
 
                        $CommentPairArray = explode("\x01".' ', $info['nsv']['NSVf']['metadata']);
193
 
                        foreach ($CommentPairArray as $CommentPair) {
194
 
                                if (strstr($CommentPair, '='."\x01")) {
195
 
                                        list($key, $value) = explode('='."\x01", $CommentPair, 2);
196
 
                                        $info['nsv']['comments'][strtolower($key)][] = trim(str_replace("\x01", '', $value));
197
 
                                }
198
 
                        }
199
 
                }
200
 
 
201
 
                $info['playtime_seconds'] = $info['nsv']['NSVf']['playtime_ms'] / 1000;
202
 
                $info['bitrate']          = ($info['nsv']['NSVf']['file_size'] * 8) / $info['playtime_seconds'];
203
 
 
204
 
                return true;
205
 
        }
206
 
 
207
 
 
208
 
        static function NSVframerateLookup($framerateindex) {
209
 
                if ($framerateindex <= 127) {
210
 
                        return (float) $framerateindex;
211
 
                }
212
 
                static $NSVframerateLookup = array();
213
 
                if (empty($NSVframerateLookup)) {
214
 
                        $NSVframerateLookup[129] = (float) 29.970;
215
 
                        $NSVframerateLookup[131] = (float) 23.976;
216
 
                        $NSVframerateLookup[133] = (float) 14.985;
217
 
                        $NSVframerateLookup[197] = (float) 59.940;
218
 
                        $NSVframerateLookup[199] = (float) 47.952;
219
 
                }
220
 
                return (isset($NSVframerateLookup[$framerateindex]) ? $NSVframerateLookup[$framerateindex] : false);
221
 
        }
222
 
 
223
 
}
224
 
 
225
 
 
226
 
?>
 
 
b'\\ No newline at end of file'