diff e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.shorten.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.shorten.php	Mon Feb 22 08:02:39 2010 -0500
     1.3 @@ -0,0 +1,121 @@
     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.shorten.php                                             |
    1.21 +// | Module for analyzing Shorten Audio files                             |
    1.22 +// | dependencies: module.audio-video.riff.php                            |
    1.23 +// +----------------------------------------------------------------------+
    1.24 +//
    1.25 +// $Id: module.audio.shorten.php,v 1.5 2006/12/03 19:28:18 ah Exp $
    1.26 +
    1.27 +        
    1.28 +        
    1.29 +class getid3_shorten extends getid3_handler
    1.30 +{
    1.31 +
    1.32 +    public function __construct(getID3 $getid3) {
    1.33 +
    1.34 +        parent::__construct($getid3);
    1.35 +        
    1.36 +        if ((bool)ini_get('safe_mode')) {
    1.37 +            throw new getid3_exception('PHP running in Safe Mode - backtick operator not available, cannot analyze Shorten files.');
    1.38 +        }
    1.39 +
    1.40 +        if (!`head --version`) {
    1.41 +            throw new getid3_exception('head[.exe] binary not found in path. UNIX: typically /usr/bin. Windows: typically c:\windows\system32.');
    1.42 +        }
    1.43 +        
    1.44 +        if (!`shorten -l`) {
    1.45 +            throw new getid3_exception('shorten[.exe] binary not found in path. UNIX: typically /usr/bin. Windows: typically c:\windows\system32.');
    1.46 +        }
    1.47 +    }
    1.48 +
    1.49 +
    1.50 +    public function Analyze() {
    1.51 +        
    1.52 +        $getid3 = $this->getid3;
    1.53 +
    1.54 +        $getid3->include_module('audio-video.riff');
    1.55 +
    1.56 +        fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
    1.57 +
    1.58 +        $shn_header = fread($getid3->fp, 8);
    1.59 +        
    1.60 +        // Magic bytes: "ajkg"
    1.61 +        
    1.62 +        $getid3->info['fileformat']            = 'shn';
    1.63 +        $getid3->info['audio']['dataformat']   = 'shn';
    1.64 +        $getid3->info['audio']['lossless']     = true;
    1.65 +        $getid3->info['audio']['bitrate_mode'] = 'vbr';
    1.66 +
    1.67 +        $getid3->info['shn']['version'] = getid3_lib::LittleEndian2Int($shn_header{4});
    1.68 +
    1.69 +        fseek($getid3->fp, $getid3->info['avdataend'] - 12, SEEK_SET);
    1.70 +        
    1.71 +        $seek_table_signature_test = fread($getid3->fp, 12);
    1.72 +        
    1.73 +        $getid3->info['shn']['seektable']['present'] = (bool)(substr($seek_table_signature_test, 4, 8) == 'SHNAMPSK');
    1.74 +        if ($getid3->info['shn']['seektable']['present']) {
    1.75 +        
    1.76 +            $getid3->info['shn']['seektable']['length'] = getid3_lib::LittleEndian2Int(substr($seek_table_signature_test, 0, 4));
    1.77 +            $getid3->info['shn']['seektable']['offset'] = $getid3->info['avdataend'] - $getid3->info['shn']['seektable']['length'];
    1.78 +            fseek($getid3->fp, $getid3->info['shn']['seektable']['offset'], SEEK_SET);
    1.79 +            $seek_table_magic = fread($getid3->fp, 4);
    1.80 +        
    1.81 +            if ($seek_table_magic != 'SEEK') {
    1.82 +
    1.83 +                throw new getid3_exception('Expecting "SEEK" at offset '.$getid3->info['shn']['seektable']['offset'].', found "'.$seek_table_magic.'"');
    1.84 +            } 
    1.85 +
    1.86 +            $seek_table_data = fread($getid3->fp, $getid3->info['shn']['seektable']['length'] - 16);
    1.87 +            $getid3->info['shn']['seektable']['entry_count'] = floor(strlen($seek_table_data) / 80);
    1.88 +        }
    1.89 +
    1.90 +        $commandline = 'shorten -x '.escapeshellarg(realpath($getid3->filename)).' - | head -c 64';
    1.91 +        $output = `$commandline`;
    1.92 +
    1.93 +        if (@$output && substr($output, 12, 4) == 'fmt ') {
    1.94 +
    1.95 +            $fmt_size = getid3_lib::LittleEndian2Int(substr($output, 16, 4));
    1.96 +            $decoded_wav_format_ex = getid3_riff::RIFFparseWAVEFORMATex(substr($output, 20, $fmt_size));
    1.97 +            
    1.98 +            $getid3->info['audio']['channels']        = $decoded_wav_format_ex['channels'];
    1.99 +            $getid3->info['audio']['bits_per_sample'] = $decoded_wav_format_ex['bits_per_sample'];
   1.100 +            $getid3->info['audio']['sample_rate']     = $decoded_wav_format_ex['sample_rate'];
   1.101 +
   1.102 +            if (substr($output, 20 + $fmt_size, 4) == 'data') {
   1.103 +
   1.104 +                $getid3->info['playtime_seconds'] = getid3_lib::LittleEndian2Int(substr($output, 20 + 4 + $fmt_size, 4)) / $decoded_wav_format_ex['raw']['nAvgBytesPerSec'];
   1.105 +
   1.106 +            } else {
   1.107 +
   1.108 +                throw new getid3_exception('shorten failed to decode DATA chunk to expected location, cannot determine playtime');
   1.109 +            }
   1.110 +
   1.111 +            $getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) / $getid3->info['playtime_seconds']) * 8;
   1.112 +
   1.113 +        } else {
   1.114 +
   1.115 +            throw new getid3_exception('shorten failed to decode file to WAV for parsing');
   1.116 +            return false;
   1.117 +        }
   1.118 +
   1.119 +        return true;
   1.120 +    }
   1.121 +
   1.122 +}
   1.123 +
   1.124 +?>
   1.125 \ No newline at end of file