Beispiel #1
0
function ParseRIFFdata(&$RIFFdata, &$ThisFileInfo)
{
    if ($RIFFdata) {
        if ($fp_temp = tmpfile()) {
            $RIFFdataLength = strlen($RIFFdata);
            $NewLengthString = LittleEndian2String($RIFFdataLength, 4);
            for ($i = 0; $i < 4; $i++) {
                $RIFFdata[$i + 4] = $NewLengthString[$i];
            }
            fwrite($fp_temp, $RIFFdata);
            $dummy = array('filesize' => $RIFFdataLength, 'filenamepath' => $ThisFileInfo['filenamepath'], 'tags' => $ThisFileInfo['tags'], 'avdataoffset' => 0, 'avdataend' => $RIFFdataLength, 'warning' => $ThisFileInfo['warning'], 'error' => $ThisFileInfo['error'], 'comments' => $ThisFileInfo['comments']);
            if (getRIFFHeaderFilepointer($fp_temp, $dummy)) {
                $ThisFileInfo['RIFF'] = $dummy['RIFF'];
                $ThisFileInfo['warning'] = $dummy['warning'];
                $ThisFileInfo['error'] = $dummy['error'];
                $ThisFileInfo['tags'] = $dummy['tags'];
                $ThisFileInfo['comments'] = $dummy['comments'];
            }
            fclose($fp_temp);
            return true;
        } else {
            $ThisFileInfo['error'] .= "\n" . 'Error calling tmpfile() to parse OptimFROG RIFF header';
        }
    }
    return false;
}
Beispiel #2
0
function getLPACHeaderFilepointer(&$fd, &$ThisFileInfo)
{
    fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
    $LPACheader = fread($fd, 14);
    if (substr($LPACheader, 0, 4) != 'LPAC') {
        $ThisFileInfo['error'] .= "\n" . 'Expected "LPAC" at offset ' . $ThisFileInfo['avdataoffset'] . ', found "' . $StreamMarker . '"';
        return false;
    }
    $ThisFileInfo['avdataoffset'] += 14;
    $ThisFileInfo['lpac']['file_version'] = BigEndian2Int(substr($LPACheader, 4, 1));
    $ThisFileInfo['lpac']['raw']['audio_type'] = BigEndian2Int(substr($LPACheader, 5, 1));
    $ThisFileInfo['lpac']['total_samples'] = BigEndian2Int(substr($LPACheader, 6, 4));
    $ThisFileInfo['lpac']['raw']['parameters'] = BigEndian2Int(substr($LPACheader, 10, 4));
    $ThisFileInfo['lpac']['flags']['is_wave'] = (bool) ($ThisFileInfo['lpac']['raw']['audio_type'] & 0x40);
    $ThisFileInfo['lpac']['flags']['stereo'] = (bool) ($ThisFileInfo['lpac']['raw']['audio_type'] & 0x4);
    $ThisFileInfo['lpac']['flags']['24_bit'] = (bool) ($ThisFileInfo['lpac']['raw']['audio_type'] & 0x2);
    $ThisFileInfo['lpac']['flags']['16_bit'] = (bool) ($ThisFileInfo['lpac']['raw']['audio_type'] & 0x1);
    if ($ThisFileInfo['lpac']['flags']['24_bit'] && $ThisFileInfo['lpac']['flags']['16_bit']) {
        $ThisFileInfo['warning'] .= "\n" . '24-bit and 16-bit flags cannot both be set';
    }
    $ThisFileInfo['lpac']['flags']['fast_compress'] = (bool) ($ThisFileInfo['lpac']['raw']['parameters'] & 0x40000000);
    $ThisFileInfo['lpac']['flags']['random_access'] = (bool) ($ThisFileInfo['lpac']['raw']['parameters'] & 0x8000000);
    $ThisFileInfo['lpac']['block_length'] = pow(2, ($ThisFileInfo['lpac']['raw']['parameters'] & 0x7000000) >> 24) * 256;
    $ThisFileInfo['lpac']['flags']['adaptive_prediction_order'] = (bool) ($ThisFileInfo['lpac']['raw']['parameters'] & 0x800000);
    $ThisFileInfo['lpac']['flags']['adaptive_quantization'] = (bool) ($ThisFileInfo['lpac']['raw']['parameters'] & 0x400000);
    $ThisFileInfo['lpac']['flags']['joint_stereo'] = (bool) ($ThisFileInfo['lpac']['raw']['parameters'] & 0x40000);
    $ThisFileInfo['lpac']['flags']['quantization'] = ($ThisFileInfo['lpac']['raw']['parameters'] & 0x1f00) >> 8;
    $ThisFileInfo['lpac']['flags']['max_prediction_order'] = $ThisFileInfo['lpac']['raw']['parameters'] & 0x3f;
    if ($ThisFileInfo['lpac']['flags']['fast_compress'] && $ThisFileInfo['lpac']['flags']['max_prediction_order'] != 3) {
        $ThisFileInfo['warning'] .= "\n" . 'max_prediction_order expected to be "3" if fast_compress is true, actual value is "' . $ThisFileInfo['lpac']['flags']['max_prediction_order'] . '"';
    }
    switch ($ThisFileInfo['lpac']['file_version']) {
        case 6:
            if ($ThisFileInfo['lpac']['flags']['adaptive_quantization']) {
                $ThisFileInfo['warning'] .= "\n" . 'adaptive_quantization expected to be false in LPAC file stucture v6, actually true';
            }
            if ($ThisFileInfo['lpac']['flags']['quantization'] != 20) {
                $ThisFileInfo['warning'] .= "\n" . 'Quantization expected to be 20 in LPAC file stucture v6, actually ' . $ThisFileInfo['lpac']['flags']['Q'];
            }
            break;
        default:
            $ThisFileInfo['warning'] .= "\n" . 'This version of getID3() only supports LPAC file format version 6, this file is version ' . $ThisFileInfo['lpac']['file_version'] . ' - please report to info@getid3.org';
            break;
    }
    require_once GETID3_INCLUDEPATH . 'getid3.riff.php';
    $dummy = array('avdataoffset' => $ThisFileInfo['avdataoffset'], 'avdataend' => $ThisFileInfo['avdataend'], 'filesize' => $ThisFileInfo['filesize'], 'error' => $ThisFileInfo['error'], 'warning' => $ThisFileInfo['warning'], 'tags' => $ThisFileInfo['tags'], 'comments' => $ThisFileInfo['comments']);
    getRIFFHeaderFilepointer($fd, $dummy);
    $ThisFileInfo['avdataoffset'] = $dummy['avdataoffset'];
    $ThisFileInfo['RIFF'] = $dummy['RIFF'];
    $ThisFileInfo['error'] = $dummy['error'];
    $ThisFileInfo['warning'] = $dummy['warning'];
    $ThisFileInfo['comments'] = $dummy['comments'];
    $ThisFileInfo['audio']['sample_rate'] = $dummy['audio']['sample_rate'];
    $ThisFileInfo['fileformat'] = 'lpac';
    $ThisFileInfo['audio']['dataformat'] = 'lpac';
    $ThisFileInfo['audio']['lossless'] = true;
    $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
    $ThisFileInfo['audio']['channels'] = $ThisFileInfo['lpac']['flags']['stereo'] ? 2 : 1;
    if ($ThisFileInfo['lpac']['flags']['24_bit']) {
        $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['RIFF']['audio'][0]['bits_per_sample'];
    } elseif ($ThisFileInfo['lpac']['flags']['16_bit']) {
        $ThisFileInfo['audio']['bits_per_sample'] = 16;
    } else {
        $ThisFileInfo['audio']['bits_per_sample'] = 8;
    }
    $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['lpac']['total_samples'] / $ThisFileInfo['audio']['sample_rate'];
    $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds'];
    return true;
}
function GetAllMP3info($filename, $assumedFormat = '', $allowedFormats = array('zip', 'ogg', 'riff', 'sdss', 'mpeg', 'midi', 'image', 'mp3'))
{
    include_once GETID3_INCLUDEPATH . 'getid3.lookup.php';
    // Lookup tables
    include_once GETID3_INCLUDEPATH . 'getid3.functions.php';
    // Function library
    include_once GETID3_INCLUDEPATH . 'getid3.getimagesize.php';
    if (!file_exists($filename)) {
        // this code segment is needed for the file browser demonstrated in check.php
        // but may interfere with finding a filename that actually does contain apparently
        // escaped characters (like "file\'name.mp3") and/or
        // %xx-format characters (like "file%20name.mp3")
        $filename = stripslashes($filename);
        if (!file_exists($filename)) {
            $filename = rawurldecode($filename);
        }
    }
    $fp = @fopen($filename, 'rb');
    $MP3fileInfo['getID3version'] = GETID3VERSION;
    $MP3fileInfo['exist'] = (bool) $fp;
    $MP3fileInfo['filename'] = basename($filename);
    $MP3fileInfo['fileformat'] = '';
    // filled in later
    $MP3fileInfo['error'] = '';
    // filled in later, unset if not used
    if ($MP3fileInfo['exist']) {
        if (strpos($filename, 'http://') !== FALSE || strpos($filename, 'ftp://') !== FALSE) {
            // remote file - copy locally first and work from there
            $localfilepointer = tmpfile();
            while ($buffer = fread($fp, FREAD_BUFFER_SIZE)) {
                $MP3fileInfo['filesize'] += fwrite($localfilepointer, $buffer);
            }
            fclose($fp);
        } else {
            clearstatcache();
            $MP3fileInfo['filesize'] = filesize($filename);
            $localfilepointer = $fp;
        }
        rewind($localfilepointer);
        $formattest = fread($localfilepointer, FREAD_BUFFER_SIZE);
        if (ParseAsThisFormat('zip', $assumedFormat, $allowedFormats, $formattest)) {
            $MP3fileInfo['fileformat'] = 'zip';
            include_once GETID3_INCLUDEPATH . 'getid3.zip.php';
            getZipHeaderFilepointer($filename, $MP3fileInfo);
        } else {
            if (ParseAsThisFormat('ogg', $assumedFormat, $allowedFormats, $formattest)) {
                $MP3fileInfo['fileformat'] = 'ogg';
                include_once GETID3_INCLUDEPATH . 'getid3.ogg.php';
                getOggHeaderFilepointer($localfilepointer, $MP3fileInfo);
            } else {
                if (ParseAsThisFormat('riff', $assumedFormat, $allowedFormats, $formattest) || ParseAsThisFormat('sdss', $assumedFormat, $allowedFormats, $formattest)) {
                    $MP3fileInfo['fileformat'] = 'riff';
                    include_once GETID3_INCLUDEPATH . 'getid3.riff.php';
                    getRIFFHeaderFilepointer($localfilepointer, $MP3fileInfo);
                } else {
                    if (ParseAsThisFormat('mpeg', $assumedFormat, $allowedFormats, $formattest)) {
                        $MP3fileInfo['fileformat'] = 'mpg';
                        include_once GETID3_INCLUDEPATH . 'getid3.mpeg.php';
                        getMPEGHeaderFilepointer($localfilepointer, $MP3fileInfo);
                    } else {
                        if (ParseAsThisFormat('midi', $assumedFormat, $allowedFormats, $formattest)) {
                            $MP3fileInfo['fileformat'] = 'midi';
                            include_once GETID3_INCLUDEPATH . 'getid3.midi.php';
                            if ($assumedFormat === FALSE) {
                                // do not parse all MIDI tracks - much faster
                                getMIDIHeaderFilepointer($localfilepointer, $MP3fileInfo, FALSE);
                            } else {
                                getMIDIHeaderFilepointer($localfilepointer, $MP3fileInfo);
                            }
                        } else {
                            if (in_array('image', $allowedFormats) && ($assumedFormat == 'image' || ($imagechunkcheck = GetDataImageSize($formattest)) && $imagechunkcheck[2] >= 1 && $imagechunkcheck[2] <= 3)) {
                                if ($assumedFormat == 'image') {
                                    $imagechunkcheck = GetDataImageSize($formattest);
                                }
                                $imagetypes = array(1 => 'gif', 2 => 'jpeg', 3 => 'png');
                                if (isset($imagechunkcheck[2]) && $imagechunkcheck[2] >= 1 && $imagechunkcheck[2] <= 3) {
                                    $MP3fileInfo['fileformat'] = $imagetypes["{$imagechunkcheck[2]}"];
                                    $MP3fileInfo["{$MP3fileInfo['fileformat']}"]['width'] = $imagechunkcheck[0];
                                    $MP3fileInfo["{$MP3fileInfo['fileformat']}"]['height'] = $imagechunkcheck[1];
                                } else {
                                    unset($MP3fileInfo['fileformat']);
                                    $MP3fileInfo['error'] = "\n" . 'Not a supported image format';
                                }
                            } else {
                                if (in_array('mp3', $allowedFormats) && $allowedFormats !== FALSE && ($assumedFormat == 'mp3' || $assumedFormat == '' && (substr($formattest, 0, 3) == 'ID3' || substr(BigEndian2Bin(substr($formattest, 0, 2)), 0, 11) == '11111111111'))) {
                                    // assume MP3 format
                                    include_once GETID3_INCLUDEPATH . 'getid3.mp3.php';
                                    getMP3headerFilepointer($localfilepointer, $MP3fileInfo);
                                    if (!isset($MP3fileInfo['audiodataoffset'])) {
                                        $MP3fileInfo['audiobytes'] = 0;
                                    } else {
                                        $MP3fileInfo['audiobytes'] = $MP3fileInfo['filesize'] - $MP3fileInfo['audiodataoffset'];
                                    }
                                    if (isset($MP3fileInfo['id3']['id3v1'])) {
                                        $MP3fileInfo['audiobytes'] -= 128;
                                    }
                                    if (isset($mp3info['lyrics3']['raw']['lyrics3tagsize'])) {
                                        $MP3fileInfo['audiobytes'] -= $mp3info['lyrics3']['raw']['lyrics3tagsize'];
                                    }
                                    if ($MP3fileInfo['audiobytes'] < 0) {
                                        unset($MP3fileInfo['audiobytes']);
                                    }
                                    if (isset($MP3fileInfo['audiobytes']) && isset($MP3fileInfo['bitrate']) && $MP3fileInfo['bitrate'] > 0) {
                                        $MP3fileInfo['playtime_seconds'] = $MP3fileInfo['audiobytes'] * 8 / $MP3fileInfo['bitrate'];
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (isset($MP3fileInfo['playtime_seconds']) && $MP3fileInfo['playtime_seconds'] > 0 && !isset($MP3fileInfo['playtime_string'])) {
        $contentseconds = round(($MP3fileInfo['playtime_seconds'] / 60 - floor($MP3fileInfo['playtime_seconds'] / 60)) * 60);
        $contentminutes = floor($MP3fileInfo['playtime_seconds'] / 60);
        $MP3fileInfo['playtime_string'] = number_format($contentminutes) . ':' . str_pad($contentseconds, 2, 0, STR_PAD_LEFT);
    }
    if (isset($MP3fileInfo['error']) && !$MP3fileInfo['error']) {
        unset($MP3fileInfo['error']);
    }
    if (isset($MP3fileInfo['fileformat']) && !$MP3fileInfo['fileformat']) {
        unset($MP3fileInfo['fileformat']);
    }
    unset($SourceArrayKey);
    if (isset($MP3fileInfo['id3']['id3v2'])) {
        $SourceArrayKey = $MP3fileInfo['id3']['id3v2'];
    } else {
        if (isset($MP3fileInfo['id3']['id3v1'])) {
            $SourceArrayKey = $MP3fileInfo['id3']['id3v1'];
        } else {
            if (isset($MP3fileInfo['ogg'])) {
                $SourceArrayKey = $MP3fileInfo['ogg'];
            } else {
                if (isset($MP3fileInfo['RIFF'])) {
                    $SourceArrayKey = $MP3fileInfo['RIFF'];
                }
            }
        }
    }
    if (isset($SourceArrayKey)) {
        $handyaccesskeystocopy = array('title', 'artist', 'album', 'year', 'genre', 'comment', 'track');
        foreach ($handyaccesskeystocopy as $keytocopy) {
            if (isset($SourceArrayKey["{$keytocopy}"])) {
                $MP3fileInfo["{$keytocopy}"] = $SourceArrayKey["{$keytocopy}"];
            }
        }
    }
    if (isset($fp) && is_resource($fp) && get_resource_type($fp) == 'file') {
        fclose($fp);
    }
    if (isset($localfilepointer) && is_resource($localfilepointer) && get_resource_type($localfilepointer) == 'file') {
        fclose($localfilepointer);
    }
    if (isset($fp)) {
        unset($fp);
    }
    if (isset($localfilepointer)) {
        unset($localfilepointer);
    }
    return $MP3fileInfo;
}