diff e2gallerypro/e2upload/Backend/Assets/getid3/module.audio-video.nsv.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-video.nsv.php	Mon Feb 22 08:02:39 2010 -0500
     1.3 @@ -0,0 +1,210 @@
     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-video.nsv.php                                           |
    1.21 +// | module for analyzing Nullsoft NSV files                              |
    1.22 +// | dependencies: NONE                                                   |
    1.23 +// +----------------------------------------------------------------------+
    1.24 +//
    1.25 +// $Id: module.audio-video.nsv.php,v 1.3 2006/11/02 10:48:00 ah Exp $
    1.26 +
    1.27 +        
    1.28 +        
    1.29 +class getid3_nsv 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['fileformat']          = 'nsv';
    1.37 +        $getid3->info['audio']['dataformat'] = 'nsv';
    1.38 +        $getid3->info['video']['dataformat'] = 'nsv';
    1.39 +        $getid3->info['audio']['lossless']   = false;
    1.40 +        $getid3->info['video']['lossless']   = false;
    1.41 +
    1.42 +        fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
    1.43 +        $nsv_header = fread($getid3->fp, 4);
    1.44 +
    1.45 +        switch ($nsv_header) {
    1.46 +            
    1.47 +            case 'NSVs':
    1.48 +                $this->getNSVsHeader();
    1.49 +                break;
    1.50 +
    1.51 +            case 'NSVf':
    1.52 +                if ($this->getNSVfHeader()) {
    1.53 +                        $this->getNSVsHeader($getid3->info['nsv']['NSVf']['header_length']);
    1.54 +                }
    1.55 +                break;
    1.56 +
    1.57 +            default:
    1.58 +                throw new getid3_exception('Expecting "NSVs" or "NSVf" at offset '.$getid3->info['avdataoffset'].', found "'.$nsv_header.'"');
    1.59 +                break;
    1.60 +        }
    1.61 +
    1.62 +        if (!isset($getid3->info['nsv']['NSVf'])) {
    1.63 +            $getid3->warning('NSVf header not present - cannot calculate playtime or bitrate');
    1.64 +        }
    1.65 +
    1.66 +        return true;
    1.67 +    }
    1.68 +
    1.69 +
    1.70 +
    1.71 +    private function getNSVsHeader($file_offset = 0) {
    1.72 +        
    1.73 +        $getid3 = $this->getid3;
    1.74 +        
    1.75 +        fseek($getid3->fp, $file_offset, SEEK_SET);
    1.76 +        $nsvs_header = fread($getid3->fp, 28);
    1.77 +        
    1.78 +        $getid3->info['nsv']['NSVs'] = array ();
    1.79 +        $info_nsv_NSVs = &$getid3->info['nsv']['NSVs'];
    1.80 +
    1.81 +        $info_nsv_NSVs['identifier'] = substr($nsvs_header, 0, 4);
    1.82 +        if ($info_nsv_NSVs['identifier'] != 'NSVs') {
    1.83 +            throw new getid3_exception('expected "NSVs" at offset ('.$file_offset.'), found "'.$info_nsv_NSVs['identifier'].'" instead');
    1.84 +        }
    1.85 +        
    1.86 +        $info_nsv_NSVs['offset'] = $file_offset;
    1.87 +        
    1.88 +        getid3_lib::ReadSequence('LittleEndian2Int', $info_nsv_NSVs, $nsvs_header, 4,
    1.89 +            array (
    1.90 +                'video_codec'     => -4,    // string
    1.91 +                'audio_codec'     => -4,    // string
    1.92 +                'resolution_x'    => 2,
    1.93 +                'resolution_y'    => 2,
    1.94 +                'framerate_index' => 1,
    1.95 +            )
    1.96 +        );
    1.97 +
    1.98 +        if ($info_nsv_NSVs['audio_codec'] == 'PCM ') {
    1.99 +        
   1.100 +            getid3_lib::ReadSequence('LittleEndian2Int', $info_nsv_NSVs, $nsvs_header, 24,
   1.101 +                array (
   1.102 +                    'bits_channel' => 1,
   1.103 +                    'channels'     => 1,
   1.104 +                    'sample_rate'  => 2
   1.105 +                )
   1.106 +            );
   1.107 +            $getid3->info['audio']['sample_rate'] = $info_nsv_NSVs['sample_rate'];
   1.108 +            
   1.109 +        }
   1.110 +
   1.111 +        $getid3->info['video']['resolution_x']       = $info_nsv_NSVs['resolution_x'];
   1.112 +        $getid3->info['video']['resolution_y']       = $info_nsv_NSVs['resolution_y'];
   1.113 +        $info_nsv_NSVs['frame_rate']                 = getid3_nsv::NSVframerateLookup($info_nsv_NSVs['framerate_index']);
   1.114 +        $getid3->info['video']['frame_rate']         = $info_nsv_NSVs['frame_rate'];
   1.115 +        $getid3->info['video']['bits_per_sample']    = 24;
   1.116 +        $getid3->info['video']['pixel_aspect_ratio'] = (float)1;
   1.117 +
   1.118 +        return true;
   1.119 +    }
   1.120 +
   1.121 +
   1.122 +
   1.123 +    private function getNSVfHeader($file_offset = 0, $get_toc_offsets=false) {
   1.124 +        
   1.125 +        $getid3 = $this->getid3;
   1.126 +        
   1.127 +        fseek($getid3->fp, $file_offset, SEEK_SET);
   1.128 +        $nsvf_header = fread($getid3->fp, 28);
   1.129 +        
   1.130 +        $getid3->info['nsv']['NSVf'] = array ();
   1.131 +        $info_nsv_NSVf = &$getid3->info['nsv']['NSVf'];
   1.132 +        
   1.133 +        $info_nsv_NSVf['identifier'] = substr($nsvf_header, 0, 4);
   1.134 +        if ($info_nsv_NSVf['identifier'] != 'NSVf') {
   1.135 +            throw new getid3_exception('expected "NSVf" at offset ('.$file_offset.'), found "'.$info_nsv_NSVf['identifier'].'" instead');
   1.136 +        }
   1.137 +
   1.138 +        $getid3->info['nsv']['NSVs']['offset']        = $file_offset;
   1.139 +
   1.140 +        getid3_lib::ReadSequence('LittleEndian2Int', $info_nsv_NSVf, $nsvf_header, 4,
   1.141 +            array (
   1.142 +                'header_length' => 4,
   1.143 +                'file_size'     => 4,
   1.144 +                'playtime_ms'   => 4,
   1.145 +                'meta_size'     => 4,
   1.146 +                'TOC_entries_1' => 4,
   1.147 +                'TOC_entries_2' => 4
   1.148 +            )
   1.149 +        );
   1.150 +                
   1.151 +        if ($info_nsv_NSVf['playtime_ms'] == 0) {
   1.152 +            throw new getid3_exception('Corrupt NSV file: NSVf.playtime_ms == zero');
   1.153 +        }
   1.154 +        
   1.155 +        if ($info_nsv_NSVf['file_size'] > $getid3->info['avdataend']) {
   1.156 +            $getid3->warning('truncated file - NSVf header indicates '.$info_nsv_NSVf['file_size'].' bytes, file actually '.$getid3->info['avdataend'].' bytes');
   1.157 +        }
   1.158 +
   1.159 +        $nsvf_header .= fread($getid3->fp, $info_nsv_NSVf['meta_size'] + (4 * $info_nsv_NSVf['TOC_entries_1']) + (4 * $info_nsv_NSVf['TOC_entries_2']));
   1.160 +        $nsvf_headerlength = strlen($nsvf_header);
   1.161 +        $info_nsv_NSVf['metadata'] = substr($nsvf_header, 28, $info_nsv_NSVf['meta_size']);
   1.162 +
   1.163 +        $offset = 28 + $info_nsv_NSVf['meta_size'];
   1.164 +        if ($get_toc_offsets) {
   1.165 +            $toc_counter = 0;
   1.166 +            while ($toc_counter < $info_nsv_NSVf['TOC_entries_1']) {
   1.167 +                if ($toc_counter < $info_nsv_NSVf['TOC_entries_1']) {
   1.168 +                    $info_nsv_NSVf['TOC_1'][$toc_counter] = getid3_lib::LittleEndian2Int(substr($nsvf_header, $offset, 4));
   1.169 +                    $offset += 4;
   1.170 +                    $toc_counter++;
   1.171 +                }
   1.172 +            }
   1.173 +        }
   1.174 +
   1.175 +        if (trim($info_nsv_NSVf['metadata']) != '') {
   1.176 +            $info_nsv_NSVf['metadata'] = str_replace('`', "\x01", $info_nsv_NSVf['metadata']);
   1.177 +            $comment_pair_array = explode("\x01".' ', $info_nsv_NSVf['metadata']);
   1.178 +            foreach ($comment_pair_array as $comment_pair) {
   1.179 +                if (strstr($comment_pair, '='."\x01")) {
   1.180 +                    list($key, $value) = explode('='."\x01", $comment_pair, 2);
   1.181 +                    $getid3->info['nsv']['comments'][strtolower($key)][] = trim(str_replace("\x01", '', $value));
   1.182 +                }
   1.183 +            }
   1.184 +        }
   1.185 +
   1.186 +        $getid3->info['playtime_seconds'] = $info_nsv_NSVf['playtime_ms'] / 1000;
   1.187 +        $getid3->info['bitrate']          = ($info_nsv_NSVf['file_size'] * 8) / $getid3->info['playtime_seconds'];
   1.188 +
   1.189 +        return true;
   1.190 +    }
   1.191 +
   1.192 +
   1.193 +
   1.194 +    public static function NSVframerateLookup($frame_rate_index) {
   1.195 +        
   1.196 +        if ($frame_rate_index <= 127) {
   1.197 +            return (float)$frame_rate_index;
   1.198 +        }
   1.199 +
   1.200 +        static $lookup = array (
   1.201 +            129 => 29.970,
   1.202 +            131 => 23.976,
   1.203 +            133 => 14.985,
   1.204 +            197 => 59.940,
   1.205 +            199 => 47.952
   1.206 +        );
   1.207 +        return (isset($lookup[$frame_rate_index]) ? $lookup[$frame_rate_index] : false);
   1.208 +    }
   1.209 +
   1.210 +}
   1.211 +
   1.212 +
   1.213 +?>
   1.214 \ No newline at end of file