Beispiel #1
0
function GetTagOnly($filename)
{
    $ThisFileInfo = array();
    $localfilepointer = null;
    if (!InitializeFilepointerArray($filename, $localfilepointer, $ThisFileInfo)) {
        // remove unneeded/meaningless keys
        CleanUpGetAllMP3info($ThisFileInfo);
        // close & remove local filepointer
        CloseRemoveFilepointer($localfilepointer);
        return $ThisFileInfo;
    }
    // Handle ID3v1 & Lyrics3 tags
    HandleID3v1Tag($localfilepointer, $ThisFileInfo);
    // Handle ID3v2 tag
    HandleID3v2Tag($localfilepointer, $ThisFileInfo);
    // Handle APE tags
    HandleAPETag($localfilepointer, $ThisFileInfo);
    // return tags data in alphabetical order, without duplicates
    $ThisFileInfo['tags'] = array_unique($ThisFileInfo['tags']);
    sort($ThisFileInfo['tags']);
    // remove unneeded/meaningless keys
    CleanUpGetAllMP3info($ThisFileInfo);
    // close & remove local filepointer
    CloseRemoveFilepointer($localfilepointer);
    return $ThisFileInfo;
}
Beispiel #2
0
function GetAllFileInfo($filename, $assumedFormat = '', $MD5file = false, $MD5data = false)
{
    require_once GETID3_INCLUDEPATH . 'getid3.functions.php';
    // Function library
    $ThisFileInfo['getID3version'] = GETID3VERSION;
    $ThisFileInfo['fileformat'] = '';
    // filled in later
    $ThisFileInfo['audio']['dataformat'] = '';
    // filled in later, unset if not used
    $ThisFileInfo['video']['dataformat'] = '';
    // filled in later, unset if not used
    $ThisFileInfo['tags'] = array();
    // filled in later, unset if not used
    $ThisFileInfo['error'] = '';
    // filled in later, unset if not used
    $ThisFileInfo['warning'] = '';
    // filled in later, unset if not used
    $ThisFileInfo['exist'] = false;
    if (eregi('^(ht|f)tp://', $filename)) {
        // remote file
        $ThisFileInfo['filename'] = $filename;
        $ThisFileInfo['error'] .= "\n" . 'Remote files are not supported in this version of getID3() - please copy the file locally first';
    } else {
        // local file
        $ThisFileInfo['filename'] = basename($filename);
        $ThisFileInfo['filepath'] = str_replace('\\', '/', realpath(dirname($filename)));
        $ThisFileInfo['filenamepath'] = $ThisFileInfo['filepath'] . '/' . $ThisFileInfo['filename'];
        ob_start();
        if ($localfilepointer = fopen($filename, 'rb')) {
            $ThisFileInfo['exist'] = true;
            //$ThisFileInfo['filesize'] = filesize($ThisFileInfo['filenamepath']);
            // PHP doesn't support integers larger than 31-bit (~2GB)
            // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize
            // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer
            fseek($localfilepointer, 0, SEEK_END);
            $ThisFileInfo['filesize'] = ftell($localfilepointer);
            ob_end_clean();
            if ($ThisFileInfo['filesize'] == 0) {
                if (filesize($ThisFileInfo['filenamepath']) != 0) {
                    unset($ThisFileInfo['filesize']);
                    $ThisFileInfo['error'] .= "\n" . 'File is most likely larger than 2GB and is not supported by PHP';
                }
                // remove unneeded/meaningless keys
                CleanUpGetAllMP3info($ThisFileInfo);
                // close & remove local filepointer
                CloseRemoveFilepointer($localfilepointer);
                return $ThisFileInfo;
            }
        } else {
            $ThisFileInfo['error'] .= "\n" . 'Error opening file: ' . trim(strip_tags(ob_get_contents()));
            ob_end_clean();
            // remove unneeded/meaningless keys
            CleanUpGetAllMP3info($ThisFileInfo);
            // close & remove local filepointer
            CloseRemoveFilepointer($localfilepointer);
            return $ThisFileInfo;
        }
    }
    // Initialize avdataoffset and avdataend
    $ThisFileInfo['avdataoffset'] = 0;
    $ThisFileInfo['avdataend'] = $ThisFileInfo['filesize'];
    // Handle APE tags
    HandleAPETag($localfilepointer, $ThisFileInfo);
    rewind($localfilepointer);
    //$formattest = fread($localfilepointer, 16);  // 16 bytes is sufficient for any format except ISO CD-image
    $formattest = fread($localfilepointer, 32774);
    // (ISO needs at least 32774 bytes)
    // Handle ID3v2 tag
    if (substr($formattest, 0, 3) == 'ID3') {
        HandleID3v2Tag($localfilepointer, $ThisFileInfo);
        rewind($localfilepointer);
        fseek($localfilepointer, $ThisFileInfo['avdataoffset'], SEEK_SET);
        $formattest = fread($localfilepointer, 32774);
        // (ISO9660 needs at least 32774 bytes)
    }
    // Handle ID3v1 tags
    HandleID3v1Tag($localfilepointer, $ThisFileInfo);
    // Nothing-but-tags check
    if ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'] > 0) {
        if ($DeterminedFormat = GetFileFormat($formattest)) {
            // break if ID3/APE tags found on illegal format
            if (!$DeterminedFormat['allowtags'] && $ThisFileInfo['avdataoffset'] > 0 && $ThisFileInfo['avdataend'] != $ThisFileInfo['filesize']) {
                $ThisFileInfo['error'] .= "\n" . 'Illegal ID3 and/or APE tag found on non multimedia file.';
                break;
            }
            // set mime type
            $ThisFileInfo['mime_type'] = $DeterminedFormat['mimetype'];
            // supported format signature pattern detected
            require_once GETID3_INCLUDEPATH . $DeterminedFormat['include'];
            switch ($DeterminedFormat['format']) {
                //case 'midi':
                //    if ($assumedFormat === false) {
                //        // do not parse all MIDI tracks - much faster
                //        getMIDIHeaderFilepointer($localfilepointer, $ThisFileInfo, false);
                //    } else {
                //        getMIDIHeaderFilepointer($localfilepointer, $ThisFileInfo);
                //    }
                //    break;
                //case 'aac':
                //    if (!getAACADIFheaderFilepointer($localfilepointer, $ThisFileInfo)) {
                //        $dummy = $ThisFileInfo;
                //        unset($dummy['error']);
                //        if (getAACADTSheaderFilepointer($localfilepointer, $dummy)) {
                //            $ThisFileInfo = $dummy;
                //        }
                //    }
                //    break;
                default:
                    $VariableFunctionName = $DeterminedFormat['function'];
                    $VariableFunctionName($localfilepointer, $ThisFileInfo);
                    break;
            }
        } elseif ($assumedFormat == 'mp3' || $assumedFormat == '' && (substr($formattest, 0, 3) == 'ID3' || substr(BigEndian2Bin(substr($formattest, 0, 2)), 0, 11) == '11111111111')) {
            // assume AAC-ADTS format
            require_once GETID3_INCLUDEPATH . 'getid3.aac.php';
            $dummy = $ThisFileInfo;
            if (getAACADTSheaderFilepointer($localfilepointer, $dummy)) {
                $ThisFileInfo = $dummy;
            } else {
                // it's not AAC-ADTS format, probably MP3
                require_once GETID3_INCLUDEPATH . 'getid3.mp3.php';
                getMP3headerFilepointer($localfilepointer, $ThisFileInfo);
            }
        } else {
            // unknown format, do nothing
        }
    }
    if (isset($ThisFileInfo['fileformat'])) {
        // Calculate combined bitrate - audio + video
        $CombinedBitrate = 0;
        $CombinedBitrate += isset($ThisFileInfo['audio']['bitrate']) ? $ThisFileInfo['audio']['bitrate'] : 0;
        $CombinedBitrate += isset($ThisFileInfo['video']['bitrate']) ? $ThisFileInfo['video']['bitrate'] : 0;
        if ($CombinedBitrate > 0 && !isset($ThisFileInfo['bitrate'])) {
            $ThisFileInfo['bitrate'] = $CombinedBitrate;
        }
        // Set playtime string
        if (!empty($ThisFileInfo['playtime_seconds']) && empty($ThisFileInfo['playtime_string'])) {
            $ThisFileInfo['playtime_string'] = PlaytimeString($ThisFileInfo['playtime_seconds']);
        }
        if (!empty($ThisFileInfo['audio']['channels'])) {
            switch ($ThisFileInfo['audio']['channels']) {
                case 1:
                    $ThisFileInfo['audio']['channelmode'] = 'mono';
                    break;
                case 2:
                    $ThisFileInfo['audio']['channelmode'] = 'stereo';
                    break;
                default:
                    // unknown?
                    break;
            }
        }
    }
    // Get the MD5 hash of the entire file
    if ($MD5file && empty($ThisFileInfo['md5_file'])) {
        $ThisFileInfo['md5_file'] = md5_file($filename);
    }
    // Get the MD5 hash of the audio/video portion of the file
    // (without ID3/APE/Lyrics3/etc header/footer tags
    if ($MD5data && empty($ThisFileInfo['md5_data'])) {
        getMD5data($ThisFileInfo);
    }
    // return tags data in alphabetical order, without duplicates
    $ThisFileInfo['tags'] = array_unique($ThisFileInfo['tags']);
    sort($ThisFileInfo['tags']);
    // remove unneeded/meaningless keys
    CleanUpGetAllMP3info($ThisFileInfo);
    // close & remove local filepointer
    CloseRemoveFilepointer($localfilepointer);
    return $ThisFileInfo;
}