~ubuntu-branches/ubuntu/lucid/ampache/lucid

« back to all changes in this revision

Viewing changes to lib/class/vainfo.class.php

  • Committer: Bazaar Package Importer
  • Author(s): Charlie Smotherman
  • Date: 2009-07-07 07:23:35 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090707072335-soq0jyo59mgopzd2
Tags: 3.5.1-0ubuntu1
 * New upstream release.  Summary of new features:  (LP: #377016)
   - Make the PHP error a little clearer for windows users by indicating
     that their version of PHP is < 5.3 (required for windows)
   - Fix random methods not working for Localplay
   - Fix extra space on prefixed albums (Thx ibizaman)
   - Add missing operator on tag and rating searches so they will
     work with other methods (Thx kiehnet@netscape.net)
   - Fix get_art_url() so it returns something... 
   - Fix problem with creating new playlists where it doesn't work
     but appending to an existing did. 
   - Fixed issue with url_to_song, also cleaned up the code a bit
   - Fixed issue with Random All Catalogs
   - Fixed issues with API and Tag methods not working as advertised
   - Fix endless loop in getid3() with malformed genre tags in mp3s
   - Fixed show test page always returning false on web path
   - Update Man page to adhear to newer Debian rules
   - Fixed issue with Videos being incorrectly registered with stats
     and now playing as songs. 
   - Fixed missing > in HTML for song row
 * Bumped Standards-Version to 3.8.2, no changes needed.
 * Bumped debhelper to dh 7.
   - increased debian/compat to 7.
   - debian/rules removed dh_clean -k in favor of dh_prep
 * Lintian complains of FreeMonoMedium.ttf being an embeded fonts package.
   FreeMonoMedium.ttf is actually part of the ttf-freefont package.
   - added ttf-freefont to the Depends section of debian/control.
   - added -XFreeMono-Medium to dh_install in debian/rules.
   - added FreeMono.ttf symbolic link to debian/links.
 * Lintian complains of the wrong file permissions for 
   -  /locale/base/gather-messages.sh, added -Xgather-messages.sh to 
   debian/rules, gather-messages.sh is not used by ampache proper and 
   can be safely removed.  It is only utilized by developers who are 
   creating or editing the translation files.
   -  /locale/pl_PL/LC_MESSAGES/messages.po added find and chmod rule 
   to debian/rules.
   -  /locale/pl_PL/LC_MESSAGES/messages.mo added find and chmod rule 
   to debian/rules.
   -  /docs/CHANGELOG added find and chmod rule to debian/rules.
 * Lintian complains of wrong-name-for-upstream-changelog
   -  install upstream CHANGELOG to /usr/share/ampache/www/docs
   -  added find and gzip -9 rule to debian/rules
   -  added symlink creation to debian/links to link
      /usr/share/ampache/www/docs/CHANGELOG.gz to 
      /usr/share/doc/ampache/changelog.gz  
 * Lacy Marrow has responded and has stated that he is dropping the GPL-3 
   licensing of his work and is now releasing version 5.9.5 of the 
   XSPF JukeBox under the same BSD license that the original version of XSPF 
   Music Player was released under (XSPF JukeBox is based on XSPF Music 
   Player).  So now XSPF Music Player and XSPF JukeBox are now released under
   the same BSD type license.  This closes RC Bug #526719.  Closes: #526719
   - Updated debian/copyright to refect this.
 * Added dh_installman to debian/rules so the manpage now installs correctly.
   - Added debian/ampache.manpages.
 * debian/ampache.config downgraded db_input to medium
 * debian/copyright removed (C) in favor of the word copyright.
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
class vainfo { 
28
28
 
29
29
        /* Default Encoding */
30
 
        var $encoding = '';
 
30
        public $encoding = '';
 
31
        public $encoding_id3v1 = 'ISO-8859-1';
 
32
        public $encoding_id3v2 = 'ISO-8859-1';
31
33
        
32
34
        /* Loaded Variables */
33
 
        var $filename = '';
34
 
        var $type = '';
35
 
        var $tags = array();
 
35
        public $filename = '';
 
36
        public $type = '';
 
37
        public $tags = array();
36
38
 
37
39
        /* Internal Information */
38
 
        var $_raw               = array();
39
 
        var $_getID3            = '';
40
 
        var $_iconv             = false; 
41
 
        var $_file_encoding     = '';
42
 
        var $_file_pattern      = '';
43
 
        var $_dir_pattern       = '';
 
40
        public $_raw            = array();
 
41
        public $_raw2           = array();
 
42
        public $_getID3         = '';
 
43
        public $_iconv          = false; 
 
44
        public $_file_encoding  = '';
 
45
        public $_file_pattern   = '';
 
46
        public $_dir_pattern    = '';
 
47
 
 
48
        /* Internal Private */
 
49
        private $_binary_parse  = array(); 
 
50
        private $_pathinfo; 
44
51
 
45
52
        /**
46
53
         * Constructor
47
54
         * This function just sets up the class, it doesn't
48
55
         * actually pull the information
49
56
         */
50
 
        function vainfo($file,$encoding='',$dir_pattern,$file_pattern) { 
 
57
        public function __construct($file,$encoding='',$encoding_id3v1='',$encoding_id3v2='',$dir_pattern,$file_pattern) { 
 
58
 
 
59
                /* Check for ICONV */
 
60
                if (function_exists('iconv')) { 
 
61
                        $this->_iconv = true;
 
62
                }
51
63
 
52
64
                $this->filename = $file;
53
65
                if ($encoding) { 
61
73
                $this->_file_pattern = $file_pattern;
62
74
                $this->_dir_pattern  = $dir_pattern;
63
75
 
64
 
                // Initialize getID3 engine
65
 
                $this->_getID3 = new getID3();
66
 
                $this->_getID3->option_md5_data         = false;
67
 
                $this->_getID3->option_md5_data_source  = false;
68
 
                $this->_getID3->option_tags_html        = false;
69
 
                $this->_getID3->option_extra_info       = false;
70
 
                $this->_getID3->option_tag_lyrics3      = false;
71
 
//              $this->_getID3->encoding                = $this->encoding; 
72
 
                $this->_getID3->option_tags_process    = true; 
73
 
 
74
 
                /* Check for ICONV */
75
 
                if (function_exists('iconv')) { 
76
 
                        $this->_iconv = true;
77
 
                }
 
76
                if(strtoupper(substr(PHP_OS,0,3)) == 'WIN') {
 
77
                        $this->_pathinfo = str_replace('%3A', ':', urlencode($this->filename));
 
78
                        $this->_pathinfo = pathinfo(str_replace('%5C', '\\', $this->_pathinfo));
 
79
                }
 
80
                else {
 
81
                        $this->_pathinfo = pathinfo(str_replace('%2F', '/', urlencode($this->filename)));
 
82
                }
 
83
                $this->_pathinfo['extension'] = strtolower($this->_pathinfo['extension']); 
 
84
 
 
85
                // Before we roll the _getID3 route let's see about using exec + a binary
 
86
/*
 
87
                if (!isset($this->_binary_parse[$this->_pathinfo['extension']])) { 
 
88
                        // Figure out if we've got binary parse ninja-skills here
 
89
                        $this->_binary_parse[$this->_pathinfo['extension']] = $this->can_binary_parse(); 
 
90
                        debug_event('BinaryParse','Binary Parse for ' . $this->_pathinfo['extension'] . ' set to ' . make_bool($this->_binary_parse[$this->_pathinfo['extension']]),'5'); 
 
91
                } 
 
92
*/
 
93
                // Initialize getID3 engine
 
94
                $this->_getID3 = new getID3();
 
95
 
 
96
//              if ($this->_binary_parse[$this->_pathinfo['extension']]) { return true; } 
 
97
 
 
98
                // get id3tag encodings
 
99
                // we have to run this right here because we don't know what we have in the files
 
100
                // and so we pull broken, then pull good later... this needs to be fixed
 
101
                try {
 
102
                        $this->_raw2 = $this->_getID3->analyze($file);
 
103
                }
 
104
                catch (Exception $error) {
 
105
                        debug_event('getid3',$error->message,'1');
 
106
                }
 
107
 
 
108
                if(function_exists('mb_detect_encoding')) {
 
109
                        $this->encoding_id3v1 = array();
 
110
                        $this->encoding_id3v1[] = mb_detect_encoding($this->_raw2['tags']['id3v1']['artist']['0']);
 
111
                        $this->encoding_id3v1[] = mb_detect_encoding($this->_raw2['tags']['id3v1']['album']['0']);
 
112
                        $this->encoding_id3v1[] = mb_detect_encoding($this->_raw2['tags']['id3v1']['genre']['0']);
 
113
                        $this->encoding_id3v1[] = mb_detect_encoding($this->_raw2['tags']['id3v1']['title']['0']);
 
114
                        array_multisort($this->encoding_id3v1);
 
115
                        array_splice($this->encoding_id3v1, -4, 3);
 
116
                        if($this->encoding_id3v1[0] != "ASCII") {
 
117
                                $this->encoding_id3v1 = $this->encoding_id3v1[0];
 
118
                        } else {
 
119
                                $this->encoding_id3v1 = "ISO-8859-1";
 
120
                        }
 
121
                        
 
122
 
 
123
                        $this->encoding_id3v2 = array();
 
124
                        $this->encoding_id3v2[] = mb_detect_encoding($this->_raw2['tags']['id3v2']['artist']['0']);
 
125
                        $this->encoding_id3v2[] = mb_detect_encoding($this->_raw2['tags']['id3v2']['album']['0']);
 
126
                        $this->encoding_id3v2[] = mb_detect_encoding($this->_raw2['tags']['id3v2']['genre']['0']);
 
127
                        $this->encoding_id3v2[] = mb_detect_encoding($this->_raw2['tags']['id3v2']['title']['0']);
 
128
                        array_multisort($this->encoding_id3v2);
 
129
                        array_splice($this->encoding_id3v2, -4, 3);
 
130
                        if($this->encoding_id3v2[0] != "ASCII"){
 
131
                                $this->encoding_id3v2 = $this->encoding_id3v2[0];
 
132
                        } else {
 
133
                                $this->encoding_id3v2 = "ISO-8859-1";
 
134
                        }
 
135
                }
 
136
                else {
 
137
                        $this->encoding_id3v1 = "ISO-8859-1";
 
138
                        $this->encoding_id3v2 = "ISO-8859-1";
 
139
                }
 
140
 
 
141
                $this->_getID3->option_md5_data                 = false;
 
142
                $this->_getID3->option_md5_data_source  = false;
 
143
                $this->_getID3->option_tags_html                = false;
 
144
                $this->_getID3->option_extra_info               = true;
 
145
                $this->_getID3->option_tag_lyrics3              = true;
 
146
                $this->_getID3->encoding                                = $this->encoding; 
 
147
                $this->_getID3->encoding_id3v1                  = $this->encoding_id3v1;
 
148
                $this->_getID3->encoding_id3v2                  = $this->encoding_id3v2;
 
149
                $this->_getID3->option_tags_process             = true; 
 
150
 
78
151
 
79
152
        } // vainfo
80
153
 
85
158
         * all filled up with tagie goodness or if specified filename
86
159
         * pattern goodness
87
160
         */
88
 
        function get_info() {
89
 
 
90
 
                /* Get the Raw file information */
91
 
                try { 
92
 
                        $this->_raw = $this->_getID3->analyze($this->filename);
93
 
                } 
94
 
                catch (Exception $error) { 
95
 
                        debug_event('getid3',$error->message,'1'); 
96
 
                } 
97
 
 
98
 
                /* Figure out what type of file we are dealing with */
99
 
                $this->type = $this->_get_type();
100
 
 
101
 
                /* Get the general information about this file */
102
 
                $info = $this->_get_info();
103
 
 
 
161
        public function get_info() {
 
162
 
 
163
                // If we've got a green light try out the binary
 
164
//              if ($this->_binary_parse[$this->_pathinfo['extension']]) { 
 
165
//                      $this->run_binary_parse();      
 
166
//              } 
 
167
                
 
168
//              else { 
 
169
 
 
170
                        /* Get the Raw file information */
 
171
                        try { 
 
172
                                $this->_raw = $this->_getID3->analyze($this->filename);
 
173
                        } 
 
174
                        catch (Exception $error) { 
 
175
                                debug_event('getid3',$error->message,'1');
 
176
                        } 
 
177
 
 
178
                        /* Figure out what type of file we are dealing with */
 
179
                        $this->type = $this->_get_type();
 
180
 
 
181
                        /* Get the general information about this file */
 
182
                        $info = $this->_get_info();
 
183
//              } 
104
184
 
105
185
                /* Gets the Tags */
106
186
                $this->tags = $this->_get_tags();
111
191
        } // get_info
112
192
 
113
193
        /**
 
194
         * get_tag_type
 
195
         * This takes the result set, and the the tag_order
 
196
         * As defined by your config file and trys to figure out
 
197
         * which tag type it should use, if your tag_order
 
198
         * doesn't match anything then it just takes the first one
 
199
         * it finds in the results. 
 
200
         */
 
201
        public static function get_tag_type($results) {
 
202
 
 
203
                /* Pull In the config option */
 
204
                $order = Config::get('tag_order');
 
205
 
 
206
                if (!is_array($order)) {
 
207
                        $order = array($order);
 
208
                }
 
209
        
 
210
                /* Foreach through the defined key order
 
211
                 * the first one we find is the first one we use 
 
212
                 */
 
213
                foreach($order as $key) {
 
214
                        if ($results[$key]) {
 
215
                                $returned_key = $key;
 
216
                                break;
 
217
                        }
 
218
                }
 
219
 
 
220
                /* If we didn't find anything then default it to the
 
221
                 * first in the results set
 
222
                 */
 
223
                if (!isset($returned_key)) {
 
224
                        $keys = array_keys($results);
 
225
                        $returned_key = $keys['0'];
 
226
                }
 
227
 
 
228
                return $returned_key;
 
229
 
 
230
        } // get_tag_type
 
231
 
 
232
        /**
 
233
         * clean_tag_info
 
234
         * This function takes the array from vainfo along with the 
 
235
         * key we've decided on and the filename and returns it in a 
 
236
         * sanatized format that ampache can actually use
 
237
         */
 
238
        public static function clean_tag_info($results,$key,$filename) {
 
239
 
 
240
                $info = array();
 
241
 
 
242
                $clean_array = array("\n","\t","\r","\0");
 
243
                $wipe_array  = array("","","","");
 
244
 
 
245
                $info['file']           = $filename;
 
246
                $info['title']          = stripslashes(trim($results[$key]['title']));
 
247
                $info['comment']        = Dba::escape(str_replace($clean_array,$wipe_array,$results[$key]['comment']));
 
248
 
 
249
                /* This are pulled from the info array */
 
250
                $info['bitrate']        = intval($results['info']['bitrate']);
 
251
                $info['rate']           = intval($results['info']['sample_rate']);
 
252
                $info['mode']           = $results['info']['bitrate_mode'];
 
253
 
 
254
                // Convert special version of constant bitrate mode to cbr
 
255
                if($info['mode'] == 'con') {
 
256
                        $info['mode'] = 'cbr';
 
257
                }
 
258
 
 
259
                $info['size']                   = $results['info']['filesize'];
 
260
                $info['mime']                   = $results['info']['mime'];
 
261
                $into['encoding']               = $results['info']['encoding'];
 
262
                $info['time']                   = intval($results['info']['playing_time']);
 
263
                $info['channels']               = intval($results['info']['channels']);
 
264
 
 
265
                // Specific Audio Flags
 
266
                if (!$results[$key]['video_codec']) { 
 
267
                        $slash_point = strpos($results[$key]['disk'],'/'); 
 
268
                        if ($slash_point !== FALSE) { 
 
269
                                $results[$key]['disk'] = substr($results[$key]['disk'],0,$slash_point); 
 
270
                        } 
 
271
                        /* These are used to generate the correct ID's later */
 
272
                        $info['year']           = intval($results[$key]['year']);
 
273
                        $info['disk']           = intval($results[$key]['disk']);
 
274
                        $info['artist']         = trim($results[$key]['artist']);
 
275
                        $info['album']          = trim($results[$key]['album']);
 
276
                        $info['genre']          = trim($results[$key]['genre']);
 
277
                        /* @TODO language doesn't import from id3tag. @momo-i */
 
278
                        $info['language']       = Dba::escape($results[$key]['language']);
 
279
                        if (!empty($results[$key]['unsynchronised lyric'])) { // ID3v2 USLT
 
280
                                $info['lyrics'] = str_replace(array("\r\n","\r","\n"), '<br />',strip_tags($results[$key]['unsynchronised lyric']));
 
281
                        }
 
282
                        else { // Lyrics3 v2.0
 
283
                                $info['lyrics'] = str_replace(array("\r\n","\r","\n"), '<br />',strip_tags($results['info']['lyrics']['unsynchedlyrics']));
 
284
                        }
 
285
                        $info['track']          = intval($results[$key]['track']);
 
286
                }
 
287
                else { 
 
288
                        $info['resolution_x']   = intval($results[$key]['resolution_x']); 
 
289
                        $info['resolution_y']   = intval($results[$key]['resolution_y']); 
 
290
                        $info['audio_codec']    = Dba::escape($results[$key]['audio_codec']); 
 
291
                        $info['video_codec']    = Dba::escape($results[$key]['video_codec']); 
 
292
                }
 
293
 
 
294
                return $info;
 
295
 
 
296
        } // clean_tag_info
 
297
 
 
298
        /**
114
299
         * _get_type
115
300
         * This function takes the raw information and figures out
116
301
         * what type of file we are dealing with for use by the tag 
117
302
         * function
118
303
         */
119
 
        function _get_type() { 
 
304
        public function _get_type() { 
120
305
 
121
306
                /* There are a few places that the file type can
122
307
                 * come from, in the end we trust the encoding 
123
308
                 * type
124
309
                 */
 
310
                if ($type = $this->_raw['video']['dataformat']) { 
 
311
                        // Manually set the tag information
 
312
                        if ($type == 'flv') { 
 
313
                                $this->_raw['tags']['flv'] = array(); 
 
314
                        } 
 
315
                        if ($type == 'quicktime') { 
 
316
                                $this->_raw['tags']['quicktime'] = array(); 
 
317
                        } 
 
318
                        if($type == 'mpeg' OR $type == 'mpg') {
 
319
                                $this->_raw['tags']['mpeg'] = array();
 
320
                        }
 
321
                        if($type == 'asf') {
 
322
                                $this->_raw['tags']['asf'] = array();
 
323
                        }
 
324
                        if($type == 'wmv') {
 
325
                                $this->_raw['tags']['wmv'] = array();
 
326
                        }
 
327
                        else { 
 
328
                                $this->_raw['tags']['avi'] = array(); 
 
329
                        } 
 
330
                        $type = $this->_clean_type($type); 
 
331
                        return $type; 
 
332
                } 
125
333
                if ($type = $this->_raw['audio']['streams']['0']['dataformat']) { 
126
 
                        $this->_clean_type($type);
 
334
                        $type = $this->_clean_type($type);
127
335
                        return $type;
128
336
                }
129
337
                if ($type = $this->_raw['audio']['dataformat']) { 
130
 
                        $this->_clean_type($type);
 
338
                        $type = $this->_clean_type($type);
131
339
                        return $type;
132
340
                }
133
341
                if ($type = $this->_raw['fileformat']) { 
134
 
                        $this->_clean_type($type);
 
342
                        $type = $this->_clean_type($type);
135
343
                        return $type;
136
344
                }
137
345
                
146
354
         * attempts to gather the tags and then normalize them into
147
355
         * ['tag_name']['var'] = value
148
356
         */
149
 
        function _get_tags() { 
 
357
        public function _get_tags() { 
150
358
 
151
359
                $results = array();
152
360
 
153
 
                /* Gather Tag information from the filenames */
154
 
                $results['file']        = $this->_parse_filename($this->filename);
155
 
 
156
361
                /* Return false if we don't have 
157
362
                 * any tags to look at 
158
363
                 */
167
372
                foreach ($this->_raw['tags'] as $key=>$tag_array) { 
168
373
                        switch ($key) { 
169
374
                                case 'vorbiscomment':
 
375
                                        debug_event('_get_tags', 'Parsing vorbis', '5');
170
376
                                        $results[$key] = $this->_parse_vorbiscomment($tag_array);
171
377
                                break;
172
378
                                case 'id3v1':
 
379
                                        debug_event('_get_tags', 'Parsing id3v1', '5');
173
380
                                        $results[$key] = $this->_parse_id3v1($tag_array);
174
381
                                break;
175
382
                                case 'id3v2':
 
383
                                        debug_event('_get_tags', 'Parsing id3v2', '5');
176
384
                                        $results[$key] = $this->_parse_id3v2($tag_array);
177
385
                                break;
178
386
                                case 'ape':
 
387
                                        debug_event('_get_tags', 'Parsing ape', '5');
179
388
                                        $results[$key] = $this->_parse_ape($tag_array);
180
389
                                break;
181
390
                                case 'quicktime':
 
391
                                        debug_event('_get_tags', 'Parsing quicktime', '5');
182
392
                                        $results[$key] = $this->_parse_quicktime($tag_array);
183
393
                                break;
184
394
                                case 'riff':
 
395
                                        debug_event('_get_tags', 'Parsing riff', '5');
185
396
                                        $results[$key] = $this->_parse_riff($tag_array); 
186
397
                                break;
 
398
                                case 'flv': 
 
399
                                        debug_event('_get_tags', 'Parsing flv', '5');
 
400
                                        $results[$key] = $this->_parse_flv($this->_raw2); 
 
401
                                break; 
 
402
                                case 'mpg':
 
403
                                case 'mpeg': 
 
404
                                        debug_event('_get_tags', 'Parsing MPEG', '5');
 
405
                                        $results[$key] = $this->_parse_mpg($this->_raw2);
 
406
                                break;
 
407
                                case 'asf':
 
408
                                case 'wmv':
 
409
                                        debug_event('_get_tags', 'Parsing WMV/WMA/ASF', '5');
 
410
                                        $results[$key] = $this->_parse_wmv($this->_raw2);
 
411
                                break;
 
412
                                case 'avi': 
 
413
                                        debug_event('_get_tags', 'Parsing avi', '5');
 
414
                                        $results[$key] = $this->_parse_avi($this->_raw2); 
 
415
                                break; 
 
416
                                case 'lyrics3':
 
417
                                        debug_event('_get_tags', 'Parsing lyrics3', '5');
 
418
                                        $results[$key] = $this->_parse_lyrics($tag_array);
 
419
                                break;
187
420
                                default: 
188
421
                                        debug_event('vainfo','Error: Unable to determine tag type of ' . $key . ' for file ' . $this->filename . ' Assuming id3v2','5');
189
 
                                        $results[$key] = $this->_parse_id3v2($tag_array);
 
422
                                        $results[$key] = $this->_parse_id3v2($this->_raw['id3v2']['comments']);
190
423
                                break;
191
424
                        } // end switch
192
425
 
193
426
                } // end foreach
194
427
 
 
428
                /* Gather Tag information from the filenames */
 
429
                $results['file']        = $this->_parse_filename($this->filename);
 
430
 
195
431
                return $results;
196
432
 
197
433
        } // _get_tags
232
468
                if ($this->_raw['playtime_seconds']) { 
233
469
                        $array['playing_time']  = $this->_raw['playtime_seconds'];
234
470
                }
 
471
                if ($this->_raw['lyrics3']) {
 
472
                        $array['lyrics'] = $this->_raw['lyrics3'];
 
473
                }
235
474
 
236
475
                return $array;
237
476
        
250
489
                        case 'mpeg3':
251
490
                                return 'mp3';
252
491
                        break;
253
 
                        case 'flac':
254
 
                                return 'flac';
255
 
                        break;
256
492
                        case 'vorbis':
257
493
                                return 'ogg';
258
494
                        break;
 
495
                        case 'flac': 
 
496
                        case 'flv':
 
497
                        case 'mpg':
 
498
                        case 'mpeg':
 
499
                        case 'asf':
 
500
                        case 'wmv':
 
501
                        case 'avi': 
 
502
                        case 'quicktime': 
 
503
                                return $type;   
259
504
                        default: 
260
505
                                /* Log the fact that we couldn't figure it out */
261
506
                                debug_event('vainfo','Unable to determine file type from ' . $type . ' on file ' . $this->filename,'5');
262
 
                                return 'unknown';
 
507
                                return $type;
263
508
                        break;
264
509
                } // end switch on type
265
510
 
266
511
        } // _clean_type
267
512
 
268
513
        /**
 
514
         * _parse_lyrics
 
515
         * This function takes a lyrics3 from getid3()
 
516
         * nothing to do?
 
517
         */
 
518
        private function _parse_lyrics($tags) {
 
519
 
 
520
                /* Results array */
 
521
                $array = array();
 
522
 
 
523
                /* go through them all! */
 
524
                foreach ($tags as $tag=>$data) {
 
525
 
 
526
                        $array[$tag] = $this->_clean_tag($data['0']);
 
527
 
 
528
                } // end foreach
 
529
 
 
530
                return $array;
 
531
 
 
532
        } // _parse_lyrics
 
533
 
 
534
        /**
269
535
         * _parse_vorbiscomment
270
536
         * This function takes a vorbiscomment from getid3() and then
271
537
         * returns the elements translated using iconv if needed in a
310
576
 
311
577
                $array = array();
312
578
 
313
 
        //      $encoding = $this->_raw['id3v1']['encoding'];
 
579
                $encoding = $this->_raw['id3v1']['encoding'];
314
580
                
315
581
                /* Go through all the tags */
316
582
                foreach ($tags as $tag=>$data) { 
333
599
         * pretty little format
334
600
         */
335
601
        private function _parse_id3v2($tags) { 
336
 
        
 
602
 
337
603
                $array = array();
338
604
 
339
605
                /* Go through the tags */
340
606
                foreach ($tags as $tag=>$data) { 
341
 
        
 
607
 
342
608
                        /**
343
609
                         * the new getid3 handles this differently 
344
610
                         * so we now need to account for it :(
355
621
                                case 'comments':
356
622
                                        $array['comment'] = $this->_clean_tag($data['0'],'');
357
623
                                break;
 
624
                                case 'title': 
 
625
                                        $array['title'] = $this->_clean_tag($data['0'],''); 
 
626
                                break; 
358
627
                                default: 
359
628
                                        $array[$tag]    = $this->_clean_tag($data['0'],'');
360
629
                                break;
361
630
                        } // end switch on tag
362
631
                
363
632
                } // end foreach
364
 
 
 
633
                
365
634
                return $array;
366
635
 
367
636
        } // _parse_id3v2
416
685
         */
417
686
        private function _parse_quicktime($tags) { 
418
687
 
419
 
                /* Results array */
420
 
                $array = array();
421
 
 
422
 
                /* go through them all! */
423
 
                foreach ($tags as $tag=>$data) {
424
 
 
425
 
                        /* We need to translate a few of these tags */
426
 
                        switch ($tag) {
427
 
                                case 'creation_date':
 
688
                /* Results array */
 
689
                $array = array();
 
690
 
 
691
                /* go through them all! */
 
692
                foreach ($tags as $tag=>$data) {
 
693
 
 
694
                        /* We need to translate a few of these tags */
 
695
                        switch ($tag) {
 
696
                                case 'creation_date':
428
697
                                        if (strlen($data['0']) > 4) { 
429
698
                                                /* Weird Date format, attempt to normalize */
430
699
                                                $data['0'] = date("Y",strtotime($data['0']));
431
700
                                        }
432
 
                                        $array['year']  = $this->_clean_tag($data['0']);
433
 
                                break;
434
 
                        } // end switch
435
 
 
436
 
                        $array[$tag] = $this->_clean_tag($data['0']);
437
 
 
438
 
                } // end foreach
439
 
 
440
 
                return $array;
 
701
                                        $array['year']  = $this->_clean_tag($data['0']);
 
702
                                break;
 
703
                        } // end switch
 
704
 
 
705
                        $array[$tag] = $this->_clean_tag($data['0']);
 
706
 
 
707
                } // end foreach
 
708
                
 
709
                // Also add in any video related stuff we might find
 
710
                if (strpos($this->_raw2['mime_type'],'video') !== false) { 
 
711
                        $info = $this->_parse_avi($this->_raw2); 
 
712
                        $info['video_codec'] = $this->_raw2['quicktime']['ftyp']['fourcc']; 
 
713
                        $array = array_merge($info,$array); 
 
714
                } 
 
715
 
 
716
                return $array;
441
717
 
442
718
        } // _parse_quicktime
443
719
 
 
720
        /**
 
721
         * _parse_avi   
 
722
         * This attempts to parse our the information on an avi file and present it in some
 
723
         * kind of sane format, this is a little hard as these files don't have tags
 
724
         */
 
725
        private function _parse_avi($tags) { 
 
726
 
 
727
                $array = array(); 
 
728
 
 
729
                $array['title']                 = urldecode($this->_pathinfo['filename']);
 
730
                $array['video_codec']           = $tags['video']['fourcc']; 
 
731
                $array['audio_codec']           = $tags['audio']['dataformat']; 
 
732
                $array['resolution_x']          = $tags['video']['resolution_x']; 
 
733
                $array['resolution_y']          = $tags['video']['resolution_y']; 
 
734
                $array['mime']                  = $tags['mime_type']; 
 
735
                $array['comment']               = $tags['video']['codec']; 
 
736
 
 
737
                return $array; 
 
738
 
 
739
        } // _parse_avi
 
740
 
 
741
        /**
 
742
         * _parse_mpg
 
743
         * This attempts to parse our the information on a mpg file and present it in some
 
744
         * kind of sane format, this is a little hard as these files don't have tags
 
745
         */
 
746
        private function _parse_mpg($tags) {
 
747
 
 
748
                $array = array();
 
749
 
 
750
                $array['title']                 = urldecode($this->_pathinfo['filename']);
 
751
                $array['video_codec']           = $tags['video']['codec'];
 
752
                $array['audio_codec']           = $tags['audio']['dataformat'];
 
753
                $array['resolution_x']          = $tags['video']['resolution_x'];
 
754
                $array['resolution_y']          = $tags['video']['resolution_y'];
 
755
                $array['mime']                  = $tags['mime_type'];
 
756
                $array['comment']               = $tags['video']['codec'];
 
757
 
 
758
                return $array;
 
759
 
 
760
        } // _parse_mpg
 
761
 
 
762
        /**
 
763
         * _parse_wmv
 
764
         * This attempts to parse our the information on a asf/wmv file and present it in some
 
765
         * kind of sane format, this is a little hard as these files don't have tags
 
766
         */
 
767
        private function _parse_wmv($tags) {
 
768
 
 
769
                $array = array();
 
770
 
 
771
                $array['mime']          = $tags['mime_type'];
 
772
 
 
773
                switch($array['mime']) {
 
774
                        default:
 
775
                        case 'video/x-ms-wmv':
 
776
                                if(isset($tags['tags']['asf']['title']['0'])) {
 
777
                                        $array['title']         = $tags['tags']['asf']['title']['0'];
 
778
                                } 
 
779
                                else {
 
780
                                        $array['title']         = urldecode($this->_pathinfo['filename']);
 
781
                                }
 
782
                                $array['video_codec']           = $tags['video']['streams']['2']['codec'];
 
783
                                $array['audio_codec']           = $tags['audio']['streams']['1']['codec'];
 
784
                                $array['resolution_x']          = $tags['video']['streams']['2']['resolution_x'];
 
785
                                $array['resolution_y']          = $tags['video']['streams']['2']['resolution_y'];
 
786
                                $array['comment']               = $tags['tags']['asf']['title']['1'];
 
787
                        break;
 
788
                }
 
789
 
 
790
                return $array;
 
791
 
 
792
        } // _parse_wmv
 
793
 
 
794
        /**
 
795
         * _parse_flv
 
796
         * This attempts to parse our the information on an flv file and present it in some
 
797
         * kind of sane format, this is a little hard as these files don't have tags
 
798
         */
 
799
        private function _parse_flv($tags) { 
 
800
 
 
801
                $array = array(); 
 
802
 
 
803
                $array['title']                 = urldecode($this->_pathinfo['filename']);
 
804
                $array['video_codec']           = $tags['video']['codec']; 
 
805
                $array['audio_codec']           = $tags['audio']['dataformat']; 
 
806
                $array['resolution_x']          = $tags['video']['resolution_x']; 
 
807
                $array['resolution_y']          = $tags['video']['resolution_y']; 
 
808
                $array['mime']                  = $tags['mime_type']; 
 
809
                $array['comment']               = $tags['video']['codec']; 
 
810
 
 
811
                return $array;
 
812
 
 
813
        } // _parse_flv
444
814
 
445
815
        /**
446
816
         * _parse_filename
452
822
 
453
823
                $results = array();
454
824
 
455
 
                // Correctly detect the slash we need to use here
456
 
                if (strstr($filename,"/")) {
457
 
                        $slash_type = '/';
458
 
                }
459
 
                else {
460
 
                        $slash_type = '\\';
461
 
                }
 
825
                // Correctly detect the slash we need to use here
 
826
                if (strstr($filename,"/")) {
 
827
                        $slash_type = '/';
 
828
                }
 
829
                else {
 
830
                        $slash_type = '\\';
 
831
                }
462
832
 
463
 
                $pattern = preg_quote($this->_dir_pattern) . $slash_type . preg_quote($this->_file_pattern);
 
833
                $pattern = preg_quote($this->_dir_pattern) . $slash_type . preg_quote($this->_file_pattern); 
464
834
                preg_match_all("/\%\w/",$pattern,$elements);
465
835
                
466
836
                $preg_pattern = preg_quote($pattern);
485
855
        } // _parse_filename
486
856
 
487
857
        /**
 
858
         * _id3v2_tag_to_frame
 
859
         * This translates the tag name to a frame, if there a many it returns the first
 
860
         * one if finds that exists in the raw
 
861
         */
 
862
        private function _id3v2_tag_to_frame($tag_name) { 
 
863
 
 
864
                static $map = array(
 
865
                        'comment'=>array('COM','COMM'),
 
866
                        'cd_ident'=>array('MCDI','MCI'),
 
867
                        'album'=>array('TAL','TALB'),
 
868
                        'language'=>array('TLA','TLAN'),
 
869
                        'mood'=>array('TMOO'),
 
870
                        'artist'=>array('TPE1'),
 
871
                        'year'=>array('TDRC'));
 
872
 
 
873
                foreach ($map[$tag_name] as $frame) { 
 
874
                        if (isset($this->_raw['id3v2'][$frame])) { 
 
875
                                return $frame; 
 
876
                        } 
 
877
                } 
 
878
 
 
879
                return false; 
 
880
 
 
881
        } // _id3v2_tag_to_frame 
 
882
 
 
883
        /**
488
884
         * _clean_tag
489
885
         * This function cleans up the tag that it's passed using Iconv
490
886
         * if we've got it. It also takes an optional encoding param
497
893
                // If we've got iconv then go ahead and clear her up            
498
894
                if ($this->_iconv) { 
499
895
                        /* Guess that it's UTF-8 */
 
896
                        /* Try GNU iconv //TRANSLIT extension first */
500
897
                        if (!$encoding) { $encoding = $this->_getID3->encoding; }
501
898
                        $charset = $this->encoding . '//TRANSLIT';
502
 
                        $tag = iconv($encoding,$charset,$tag);
 
899
                        $enc_tag = iconv($encoding,$charset,$tag);
 
900
                        if(strcmp($enc_tag, "") == 0) {
 
901
                                $enc_tag = iconv($encoding,$this->encoding,$tag);
 
902
                        }
503
903
                }
504
904
 
505
 
                return $tag;
506
 
 
507
 
 
 
905
                return $enc_tag;
508
906
 
509
907
        } // _clean_tag
510
908
 
 
909
        /**
 
910
         * can_binary_parse
 
911
         * This returns true/false if we can do a binary parse of the file in question
 
912
         * only the extension is passed so this can be inaccurate
 
913
         */
 
914
        public function can_binary_parse() { 
 
915
 
 
916
                // We're going to need exec for this
 
917
                if (!is_callable('exec')) { 
 
918
                        return false; 
 
919
                } 
 
920
 
 
921
 
 
922
                // For now I'm going to use an approved list of apps, later we should allow user config
 
923
                switch ($this->_pathinfo['extension']) { 
 
924
                        case 'mp3':                     
 
925
                                // Verify the application is there and callable
 
926
                                exec('id3v2 -v',$results,$retval); 
 
927
                                if ($retval == 0) { return true; } 
 
928
                        break; 
 
929
                        default:
 
930
                                //FAILURE
 
931
                        break; 
 
932
                }
 
933
 
 
934
                return false; 
 
935
 
 
936
        } // can_binary_parse
 
937
 
 
938
        /**
 
939
         * run_binary_parse
 
940
         * This runs the binary parse operations here down in Ampache land
 
941
         * it is passed the filename, and only called if can_binary_parse passes
 
942
         */
 
943
        public function run_binary_parse() { 
 
944
 
 
945
                // Switch on the extension
 
946
                switch ($this->_pathinfo['extension']) { 
 
947
                        case 'mp3': 
 
948
                                $this->_raw['tags'] = $this->mp3_binary_parse();
 
949
                        break; 
 
950
                        default:
 
951
                                $this->_raw['tags'] = array(); 
 
952
                        break; 
 
953
                } // switch on extension
 
954
 
 
955
        } // run_binary_parse
 
956
 
 
957
        /**
 
958
         * mp3_binary_parse
 
959
         * This tries to read the tag information from mp3s using a binary and the exec() command
 
960
         * This will not work on a lot of systems... but it should be faster
 
961
         */
 
962
        public function mp3_binary_parse() { 
 
963
 
 
964
                require_once(Config::get('prefix') . '/modules/getid3/module.tag.id3v2.php'); 
 
965
 
 
966
                $filename = escapeshellarg($this->filename); 
 
967
 
 
968
                exec('id3v2 -l ' . $filename,$info,$retval); 
 
969
 
 
970
                if ($retval != 0) { return array(); } 
 
971
 
 
972
                $position=0; 
 
973
                $results = array(); 
 
974
 
 
975
                // If we've got Id3v1 tag information
 
976
                if (substr($info[$position],0,5) == 'id3v1') { 
 
977
                        $position++; 
 
978
                        $v1['title'][]  = trim(substr($info[$position],8,30)); 
 
979
                        $v1['artist'][] = trim(substr($info[$position],49,79));
 
980
                        $position++; 
 
981
                        $v1['album'][]  = trim(substr($info[$position],8,30)); 
 
982
                        $v1['year'][]   = trim(substr($info[$position],47,53)); 
 
983
                        $v1['genre'][]  = trim(preg_replace("/\(\d+\)/","",substr($info[$position],60,strlen($info[$position])))); 
 
984
                        $position++; 
 
985
                        $v1['comment'][]= trim(substr($info[$position],8,30)); 
 
986
                        $v1['track'][]  = trim(substr($info[$position],48,3)); 
 
987
                        $results['id3v1'] = $v1; 
 
988
                        $position++; 
 
989
                }
 
990
                if (substr($info[$position],0,5) == 'id3v2') { 
 
991
                        $position++; 
 
992
                        $element_count = count($info);
 
993
                        while ($position < $element_count) { 
 
994
                                $position++;
 
995
                                $element = getid3_id3v2::FrameNameShortLookup(substr($info[$position],0,4));
 
996
                                if (!$element) { continue; } 
 
997
                                $data = explode(":",$info[$position],2); 
 
998
                                $value = array_pop($data); 
 
999
                                $results['id3v2'][$element][] = $value; 
 
1000
                        } 
 
1001
 
 
1002
                } // end if id3v2
 
1003
                return $results; 
 
1004
 
 
1005
        } // mp3_binary_parse
 
1006
 
511
1007
} // end class vainfo
512
1008
?>