Mercurial > judyates
view e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.shorten.php @ 22:be17de86e80d judyates
add promo for old-masters stuff (very rough).
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 09 Feb 2014 20:46:57 -0500 |
parents | 3f6b44aa6b35 |
children |
line wrap: on
line source
1 <?php2 // +----------------------------------------------------------------------+3 // | PHP version 5 |4 // +----------------------------------------------------------------------+5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |6 // +----------------------------------------------------------------------+7 // | This source file is subject to version 2 of the GPL license, |8 // | that is bundled with this package in the file license.txt and is |9 // | available through the world-wide-web at the following url: |10 // | http://www.gnu.org/copyleft/gpl.html |11 // +----------------------------------------------------------------------+12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |13 // +----------------------------------------------------------------------+14 // | Authors: James Heinrich <infoØgetid3*org> |15 // | Allan Hansen <ahØartemis*dk> |16 // +----------------------------------------------------------------------+17 // | module.audio.shorten.php |18 // | Module for analyzing Shorten Audio files |19 // | dependencies: module.audio-video.riff.php |20 // +----------------------------------------------------------------------+21 //22 // $Id: module.audio.shorten.php,v 1.5 2006/12/03 19:28:18 ah Exp $26 class getid3_shorten extends getid3_handler27 {29 public function __construct(getID3 $getid3) {31 parent::__construct($getid3);33 if ((bool)ini_get('safe_mode')) {34 throw new getid3_exception('PHP running in Safe Mode - backtick operator not available, cannot analyze Shorten files.');35 }37 if (!`head --version`) {38 throw new getid3_exception('head[.exe] binary not found in path. UNIX: typically /usr/bin. Windows: typically c:\windows\system32.');39 }41 if (!`shorten -l`) {42 throw new getid3_exception('shorten[.exe] binary not found in path. UNIX: typically /usr/bin. Windows: typically c:\windows\system32.');43 }44 }47 public function Analyze() {49 $getid3 = $this->getid3;51 $getid3->include_module('audio-video.riff');53 fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);55 $shn_header = fread($getid3->fp, 8);57 // Magic bytes: "ajkg"59 $getid3->info['fileformat'] = 'shn';60 $getid3->info['audio']['dataformat'] = 'shn';61 $getid3->info['audio']['lossless'] = true;62 $getid3->info['audio']['bitrate_mode'] = 'vbr';64 $getid3->info['shn']['version'] = getid3_lib::LittleEndian2Int($shn_header{4});66 fseek($getid3->fp, $getid3->info['avdataend'] - 12, SEEK_SET);68 $seek_table_signature_test = fread($getid3->fp, 12);70 $getid3->info['shn']['seektable']['present'] = (bool)(substr($seek_table_signature_test, 4, 8) == 'SHNAMPSK');71 if ($getid3->info['shn']['seektable']['present']) {73 $getid3->info['shn']['seektable']['length'] = getid3_lib::LittleEndian2Int(substr($seek_table_signature_test, 0, 4));74 $getid3->info['shn']['seektable']['offset'] = $getid3->info['avdataend'] - $getid3->info['shn']['seektable']['length'];75 fseek($getid3->fp, $getid3->info['shn']['seektable']['offset'], SEEK_SET);76 $seek_table_magic = fread($getid3->fp, 4);78 if ($seek_table_magic != 'SEEK') {80 throw new getid3_exception('Expecting "SEEK" at offset '.$getid3->info['shn']['seektable']['offset'].', found "'.$seek_table_magic.'"');81 }83 $seek_table_data = fread($getid3->fp, $getid3->info['shn']['seektable']['length'] - 16);84 $getid3->info['shn']['seektable']['entry_count'] = floor(strlen($seek_table_data) / 80);85 }87 $commandline = 'shorten -x '.escapeshellarg(realpath($getid3->filename)).' - | head -c 64';88 $output = `$commandline`;90 if (@$output && substr($output, 12, 4) == 'fmt ') {92 $fmt_size = getid3_lib::LittleEndian2Int(substr($output, 16, 4));93 $decoded_wav_format_ex = getid3_riff::RIFFparseWAVEFORMATex(substr($output, 20, $fmt_size));95 $getid3->info['audio']['channels'] = $decoded_wav_format_ex['channels'];96 $getid3->info['audio']['bits_per_sample'] = $decoded_wav_format_ex['bits_per_sample'];97 $getid3->info['audio']['sample_rate'] = $decoded_wav_format_ex['sample_rate'];99 if (substr($output, 20 + $fmt_size, 4) == 'data') {101 $getid3->info['playtime_seconds'] = getid3_lib::LittleEndian2Int(substr($output, 20 + 4 + $fmt_size, 4)) / $decoded_wav_format_ex['raw']['nAvgBytesPerSec'];103 } else {105 throw new getid3_exception('shorten failed to decode DATA chunk to expected location, cannot determine playtime');106 }108 $getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) / $getid3->info['playtime_seconds']) * 8;110 } else {112 throw new getid3_exception('shorten failed to decode file to WAV for parsing');113 return false;114 }116 return true;117 }119 }121 ?>