diff e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.bonk.php @ 3:3f6b44aa6b35 judyates

[svn r4] added ability to buy stuff, from a Prints page, but it doesn't work well with the css, and it also has not been fitted into the perl make system.
author rlm
date Mon, 22 Feb 2010 08:02:39 -0500
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.bonk.php	Mon Feb 22 08:02:39 2010 -0500
     1.3 @@ -0,0 +1,235 @@
     1.4 +<?php
     1.5 +// +----------------------------------------------------------------------+
     1.6 +// | PHP version 5                                                        |
     1.7 +// +----------------------------------------------------------------------+
     1.8 +// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen                 |
     1.9 +// +----------------------------------------------------------------------+
    1.10 +// | This source file is subject to version 2 of the GPL license,         |
    1.11 +// | that is bundled with this package in the file license.txt and is     |
    1.12 +// | available through the world-wide-web at the following url:           |
    1.13 +// | http://www.gnu.org/copyleft/gpl.html                                 |
    1.14 +// +----------------------------------------------------------------------+
    1.15 +// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org    |
    1.16 +// +----------------------------------------------------------------------+
    1.17 +// | Authors: James Heinrich <infoØgetid3*org>                            |
    1.18 +// |          Allan Hansen <ahØartemis*dk>                                |
    1.19 +// +----------------------------------------------------------------------+
    1.20 +// | module.audio.bonk.php                                                |
    1.21 +// | Module for analyzing BONK audio files                                |
    1.22 +// | dependencies: module.tag.id3v2.php (optional)                        |
    1.23 +// +----------------------------------------------------------------------+
    1.24 +//
    1.25 +// $Id: module.audio.bonk.php,v 1.3 2006/11/02 10:48:01 ah Exp $
    1.26 +
    1.27 +        
    1.28 +        
    1.29 +class getid3_bonk extends getid3_handler
    1.30 +{
    1.31 +
    1.32 +    public function Analyze() {
    1.33 +
    1.34 +        $getid3 = $this->getid3;
    1.35 +        
    1.36 +        $getid3->info['bonk'] = array ();
    1.37 +        $info_bonk = &$getid3->info['bonk'];
    1.38 +
    1.39 +        $info_bonk['dataoffset'] = $getid3->info['avdataoffset'];
    1.40 +        $info_bonk['dataend']    = $getid3->info['avdataend'];
    1.41 +
    1.42 +        
    1.43 +        // Scan-from-end method, for v0.6 and higher
    1.44 +        fseek($getid3->fp, $info_bonk['dataend'] - 8, SEEK_SET);
    1.45 +        $possible_bonk_tag = fread($getid3->fp, 8);
    1.46 +        while (getid3_bonk::BonkIsValidTagName(substr($possible_bonk_tag, 4, 4), true)) {
    1.47 +            $bonk_tag_size = getid3_lib::LittleEndian2Int(substr($possible_bonk_tag, 0, 4));
    1.48 +            fseek($getid3->fp, 0 - $bonk_tag_size, SEEK_CUR);
    1.49 +            $bonk_tag_offset = ftell($getid3->fp);
    1.50 +            $tag_header_test = fread($getid3->fp, 5);
    1.51 +            if (($tag_header_test{0} != "\x00") || (substr($possible_bonk_tag, 4, 4) != strtolower(substr($possible_bonk_tag, 4, 4)))) {
    1.52 +                throw new getid3_exception('Expecting "Ø'.strtoupper(substr($possible_bonk_tag, 4, 4)).'" at offset '.$bonk_tag_offset.', found "'.$tag_header_test.'"');
    1.53 +            }
    1.54 +            $bonk_tag_name = substr($tag_header_test, 1, 4);
    1.55 +
    1.56 +            $info_bonk[$bonk_tag_name]['size']   = $bonk_tag_size;
    1.57 +            $info_bonk[$bonk_tag_name]['offset'] = $bonk_tag_offset;
    1.58 +            $this->HandleBonkTags($bonk_tag_name);
    1.59 +            
    1.60 +            $next_tag_end_offset = $bonk_tag_offset - 8;
    1.61 +            if ($next_tag_end_offset < $info_bonk['dataoffset']) {
    1.62 +                if (empty($getid3->info['audio']['encoder'])) {
    1.63 +                    $getid3->info['audio']['encoder'] = 'Extended BONK v0.9+';
    1.64 +                }
    1.65 +                return true;
    1.66 +            }
    1.67 +            fseek($getid3->fp, $next_tag_end_offset, SEEK_SET);
    1.68 +            $possible_bonk_tag = fread($getid3->fp, 8);
    1.69 +        }
    1.70 +
    1.71 +        // Seek-from-beginning method for v0.4 and v0.5
    1.72 +        if (empty($info_bonk['BONK'])) {
    1.73 +            fseek($getid3->fp, $info_bonk['dataoffset'], SEEK_SET);
    1.74 +            do {
    1.75 +                $tag_header_test = fread($getid3->fp, 5);
    1.76 +                switch ($tag_header_test) {
    1.77 +                    case "\x00".'BONK':
    1.78 +                        if (empty($getid3->info['audio']['encoder'])) {
    1.79 +                            $getid3->info['audio']['encoder'] = 'BONK v0.4';
    1.80 +                        }
    1.81 +                        break;
    1.82 +
    1.83 +                    case "\x00".'INFO':
    1.84 +                        $getid3->info['audio']['encoder'] = 'Extended BONK v0.5';
    1.85 +                        break;
    1.86 +
    1.87 +                    default:
    1.88 +                        break 2;
    1.89 +                }
    1.90 +                $bonk_tag_name = substr($tag_header_test, 1, 4);
    1.91 +                $info_bonk[$bonk_tag_name]['size']   = $info_bonk['dataend'] - $info_bonk['dataoffset'];
    1.92 +                $info_bonk[$bonk_tag_name]['offset'] = $info_bonk['dataoffset'];
    1.93 +                $this->HandleBonkTags($bonk_tag_name);
    1.94 +
    1.95 +            } while (true);
    1.96 +        }
    1.97 +
    1.98 +
    1.99 +        // Parse META block for v0.6 - v0.8
   1.100 +        if (!@$info_bonk['INFO'] && isset($info_bonk['META']['tags']['info'])) {
   1.101 +            fseek($getid3->fp, $info_bonk['META']['tags']['info'], SEEK_SET);
   1.102 +            $tag_header_test = fread($getid3->fp, 5);
   1.103 +            if ($tag_header_test == "\x00".'INFO') {
   1.104 +                $getid3->info['audio']['encoder'] = 'Extended BONK v0.6 - v0.8';
   1.105 +
   1.106 +                $bonk_tag_name = substr($tag_header_test, 1, 4);
   1.107 +                $info_bonk[$bonk_tag_name]['size']   = $info_bonk['dataend'] - $info_bonk['dataoffset'];
   1.108 +                $info_bonk[$bonk_tag_name]['offset'] = $info_bonk['dataoffset'];
   1.109 +                $this->HandleBonkTags($bonk_tag_name);
   1.110 +            }
   1.111 +        }
   1.112 +
   1.113 +        if (empty($getid3->info['audio']['encoder'])) {
   1.114 +            $getid3->info['audio']['encoder'] = 'Extended BONK v0.9+';
   1.115 +        }
   1.116 +        if (empty($info_bonk['BONK'])) {
   1.117 +            unset($getid3->info['bonk']);
   1.118 +        }
   1.119 +        return true;
   1.120 +
   1.121 +    }
   1.122 +
   1.123 +
   1.124 +    
   1.125 +    private function HandleBonkTags(&$bonk_tag_name) {
   1.126 +
   1.127 +        // Shortcut to getid3 pointer
   1.128 +        $getid3 = $this->getid3;
   1.129 +        $info_audio = &$getid3->info['audio'];
   1.130 +
   1.131 +        switch ($bonk_tag_name) {
   1.132 +            
   1.133 +            case 'BONK':
   1.134 +                // shortcut
   1.135 +                $info_bonk_BONK = &$getid3->info['bonk']['BONK'];
   1.136 +
   1.137 +                $bonk_data = "\x00".'BONK'.fread($getid3->fp, 17);
   1.138 +                
   1.139 +                getid3_lib::ReadSequence('LittleEndian2Int', $info_bonk_BONK, $bonk_data, 5, 
   1.140 +                    array (
   1.141 +                        'version'            => 1,
   1.142 +                        'number_samples'     => 4,
   1.143 +                        'sample_rate'        => 4,
   1.144 +                        'channels'           => 1,
   1.145 +                        'lossless'           => 1,
   1.146 +                        'joint_stereo'       => 1,
   1.147 +                        'number_taps'        => 2,
   1.148 +                        'downsampling_ratio' => 1,
   1.149 +                        'samples_per_packet' => 2
   1.150 +                    )
   1.151 +                );
   1.152 +                
   1.153 +                $info_bonk_BONK['lossless']     = (bool)$info_bonk_BONK['lossless'];
   1.154 +                $info_bonk_BONK['joint_stereo'] = (bool)$info_bonk_BONK['joint_stereo'];
   1.155 +
   1.156 +                $getid3->info['avdataoffset']   = $info_bonk_BONK['offset'] + 5 + 17;
   1.157 +                $getid3->info['avdataend']      = $info_bonk_BONK['offset'] + $info_bonk_BONK['size'];
   1.158 +
   1.159 +                $getid3->info['fileformat']     = 'bonk';
   1.160 +                $info_audio['dataformat']       = 'bonk';
   1.161 +                $info_audio['bitrate_mode']     = 'vbr'; // assumed
   1.162 +                $info_audio['channels']         = $info_bonk_BONK['channels'];
   1.163 +                $info_audio['sample_rate']      = $info_bonk_BONK['sample_rate'];
   1.164 +                $info_audio['channelmode']      = $info_bonk_BONK['joint_stereo'] ? 'joint stereo' : 'stereo';
   1.165 +                $info_audio['lossless']         = $info_bonk_BONK['lossless'];
   1.166 +                $info_audio['codec']            = 'bonk';
   1.167 +
   1.168 +                $getid3->info['playtime_seconds'] = $info_bonk_BONK['number_samples'] / ($info_bonk_BONK['sample_rate'] * $info_bonk_BONK['channels']);
   1.169 +                if ($getid3->info['playtime_seconds'] > 0) {
   1.170 +                    $info_audio['bitrate'] = (($getid3->info['bonk']['dataend'] - $getid3->info['bonk']['dataoffset']) * 8) / $getid3->info['playtime_seconds'];
   1.171 +                }
   1.172 +                break;
   1.173 +
   1.174 +            case 'INFO':
   1.175 +                // shortcut
   1.176 +                $info_bonk_INFO = &$getid3->info['bonk']['INFO'];
   1.177 +
   1.178 +                $info_bonk_INFO['version'] = getid3_lib::LittleEndian2Int(fread($getid3->fp, 1));
   1.179 +                $info_bonk_INFO['entries_count'] = 0;
   1.180 +                $next_info_data_pair = fread($getid3->fp, 5);
   1.181 +                if (!getid3_bonk::BonkIsValidTagName(substr($next_info_data_pair, 1, 4))) {
   1.182 +                    while (!feof($getid3->fp)) {
   1.183 +                        $next_info_data_pair = fread($getid3->fp, 5);
   1.184 +                        if (getid3_bonk::BonkIsValidTagName(substr($next_info_data_pair, 1, 4))) {
   1.185 +                            fseek($getid3->fp, -5, SEEK_CUR);
   1.186 +                            break;
   1.187 +                        }
   1.188 +                        $info_bonk_INFO['entries_count']++;
   1.189 +                    }
   1.190 +                }
   1.191 +                break;
   1.192 +
   1.193 +            case 'META':
   1.194 +                $bonk_data = "\x00".'META'.fread($getid3->fp, $getid3->info['bonk']['META']['size'] - 5);
   1.195 +                $getid3->info['bonk']['META']['version'] = getid3_lib::LittleEndian2Int(substr($bonk_data,  5, 1));
   1.196 +
   1.197 +                $meta_tag_entries = floor(((strlen($bonk_data) - 8) - 6) / 8); // BonkData - xxxxmeta - ØMETA
   1.198 +                $offset = 6;
   1.199 +                for ($i = 0; $i < $meta_tag_entries; $i++) {
   1.200 +                    $meta_entry_tag_name   = substr($bonk_data, $offset, 4);
   1.201 +                    $offset += 4;
   1.202 +                    $meta_entry_tag_offset = getid3_lib::LittleEndian2Int(substr($bonk_data, $offset, 4));
   1.203 +                    $offset += 4;
   1.204 +                    $getid3->info['bonk']['META']['tags'][$meta_entry_tag_name] = $meta_entry_tag_offset;
   1.205 +                }
   1.206 +                break;
   1.207 +
   1.208 +            case ' ID3':
   1.209 +                $info_audio['encoder'] = 'Extended BONK v0.9+';
   1.210 +
   1.211 +                // ID3v2 checking is optional
   1.212 +                if (class_exists('getid3_id3v2')) {
   1.213 +                    
   1.214 +                    $id3v2 = new getid3_id3v2($getid3);
   1.215 +                    $id3v2->option_starting_offset = $getid3->info['bonk'][' ID3']['offset'] + 2;
   1.216 +                    $getid3->info['bonk'][' ID3']['valid'] = $id3v2->Analyze();
   1.217 +                }
   1.218 +                break;
   1.219 +
   1.220 +            default:
   1.221 +                $getid3->warning('Unexpected Bonk tag "'.$bonk_tag_name.'" at offset '.$getid3->info['bonk'][$bonk_tag_name]['offset']);
   1.222 +                break;
   1.223 +
   1.224 +        }
   1.225 +    }
   1.226 +
   1.227 +
   1.228 +    
   1.229 +    public static function BonkIsValidTagName($possible_bonk_tag, $ignore_case=false) {
   1.230 +                                                                              
   1.231 +        $ignore_case = $ignore_case ? 'i' : '';                                                                              
   1.232 +        return preg_match('/^(BONK|INFO| ID3|META)$/'.$ignore_case, $possible_bonk_tag);
   1.233 +    }
   1.234 +
   1.235 +}
   1.236 +
   1.237 +
   1.238 +?>
   1.239 \ No newline at end of file