function getMP3headerFilepointer(&$fd, &$MP3fileInfo)
{
    // get all information about an MP3 file - ID3v1, ID3v2, Lyrics3, MPEG-audio
    $MP3fileInfo['fileformat'] = '';
    if (!$fd) {
        $MP3fileInfo['error'] .= "\n" . 'Could not open file';
        return FALSE;
    } else {
        fseek($fd, -128 - 9 - 6, SEEK_END);
        $lyrics3_id3v1 = fread($fd, 128 + 9 + 6);
        $lyrics3lsz = substr($lyrics3_id3v1, 0, 6);
        $lyrics3end = substr($lyrics3_id3v1, 6, 9);
        // LYRICSEND or LYRICS200
        $id3v1tag = substr($lyrics3_id3v1, 15, 128);
        if ($lyrics3end == 'LYRICSEND') {
            // Lyrics3 v1 and ID3v1
            $lyrics3size = 5100;
            include_once GETID3_INCLUDEPATH . 'getid3.lyrics3.php';
            getLyrics3Filepointer($MP3fileInfo, $fd, -128 - $lyrics3size, 1, $lyrics3size);
        } else {
            if ($lyrics3end == 'LYRICS200') {
                // Lyrics3 v2 and ID3v1
                $lyrics3size = $lyrics3lsz + 6 + strlen('LYRICS200');
                // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200'
                include_once GETID3_INCLUDEPATH . 'getid3.lyrics3.php';
                getLyrics3Filepointer($MP3fileInfo, $fd, -128 - $lyrics3size, 2, $lyrics3size);
            } else {
                if (substr($lyrics3_id3v1, strlen($lyrics3_id3v1) - 1 - 9, 9) == 'LYRICSEND') {
                    // Lyrics3 v1, no ID3v1 (I think according to Lyrics3 specs there MUST be ID3v1, but just in case :)
                    $lyrics3size = 5100;
                    include_once GETID3_INCLUDEPATH . 'getid3.lyrics3.php';
                    getLyrics3Filepointer($MP3fileInfo, $fd, 0 - $lyrics3size, 1, $lyrics3size);
                } else {
                    if (substr($lyrics3_id3v1, strlen($lyrics3_id3v1) - 1 - 9, 9) == 'LYRICS200') {
                        // Lyrics3 v2, no ID3v1 (I think according to Lyrics3 specs there MUST be ID3v1, but just in case :)
                        $lyrics3size = $lyrics3lsz + 6 + strlen('LYRICS200');
                        // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200'
                        include_once GETID3_INCLUDEPATH . 'getid3.lyrics3.php';
                        getLyrics3Filepointer($MP3fileInfo, $fd, 0 - $lyrics3size, 2, $lyrics3size);
                    }
                }
            }
        }
        if (substr($id3v1tag, 0, 3) == 'TAG') {
            include_once GETID3_INCLUDEPATH . 'getid3.id3v1.php';
            $MP3fileInfo['id3']['id3v1'] = getID3v1Filepointer($fd);
            $MP3fileInfo['fileformat'] = 'id3';
        }
        include_once GETID3_INCLUDEPATH . 'getid3.id3v2.php';
        getID3v2Filepointer($fd, $MP3fileInfo);
        if (isset($MP3fileInfo['id3']['id3v2']['header'])) {
            $MP3fileInfo['fileformat'] = 'id3';
            $audiodataoffset = $MP3fileInfo['id3']['id3v2']['headerlength'];
            if (isset($MP3fileInfo['id3']['id3v2']['footer'])) {
                $audiodataoffset += 10;
            }
        } else {
            // no ID3v2 header
            if (isset($MP3fileInfo['id3']['id3v2'])) {
                unset($MP3fileInfo['id3']['id3v2']);
            }
            $audiodataoffset = 0;
        }
        if ($audiodataoffset < $MP3fileInfo['filesize']) {
            getOnlyMPEGaudioInfo($fd, $MP3fileInfo, $audiodataoffset);
        }
        if (isset($MP3fileInfo['audiodataoffset']) && (isset($MP3fileInfo['id3']['id3v2']) && $MP3fileInfo['audiodataoffset'] > $MP3fileInfo['id3']['id3v2']['headerlength'] || !isset($MP3fileInfo['id3']['id3v2']) && $MP3fileInfo['audiodataoffset'] > 0)) {
            $MP3fileInfo['error'] .= "\n" . 'Unknown data before synch ';
            if (isset($MP3fileInfo['id3']['id3v2']['headerlength'])) {
                $MP3fileInfo['error'] .= '(ID3v2 header ends at ' . $MP3fileInfo['id3']['id3v2']['headerlength'] . ', ';
            } else {
                $MP3fileInfo['error'] .= '(should be at beginning of file, ';
            }
            $MP3fileInfo['error'] .= 'synch detected at ' . $MP3fileInfo['audiodataoffset'] . ')';
        }
        if (!$MP3fileInfo['fileformat']) {
            $MP3fileInfo['error'] .= "\n" . 'Synch not found';
            unset($MP3fileInfo['audiodataoffset']);
            unset($MP3fileInfo['fileformat']);
        }
    }
    // if ($fd)
    if (isset($MP3fileInfo['id3']) && !isset($MP3fileInfo['id3']['id3v2']) && !isset($MP3fileInfo['id3']['id3v1'])) {
        unset($MP3fileInfo['id3']);
    }
    return TRUE;
}
Beispiel #2
0
function HandleLyrics3Tag(&$fd, &$ThisFileInfo)
{
    // Handle Lyrics3 tags
    require_once GETID3_INCLUDEPATH . 'getid3.lyrics3.php';
    getLyrics3Filepointer($fd, $ThisFileInfo);
    return true;
}
Beispiel #3
0
function HandleID3v1Tag(&$fd, &$ThisFileInfo)
{
    fseek($fd, 0 - 128 - 9 - 6, SEEK_END);
    // end - ID3v1 - LYRICSEND - [Lyrics3size]
    $lyrics3_id3v1 = fread($fd, 128 + 9 + 6);
    $lyrics3lsz = substr($lyrics3_id3v1, 0, 6);
    // Lyrics3size
    $lyrics3end = substr($lyrics3_id3v1, 6, 9);
    // LYRICSEND or LYRICS200
    $id3v1tag = substr($lyrics3_id3v1, 15, 128);
    // ID3v1
    if ($lyrics3end == 'LYRICSEND') {
        // Lyrics3 v1 and ID3v1
        $lyrics3size = 5100;
        $ThisFileInfo['avdataend'] -= $lyrics3size;
        require_once GETID3_INCLUDEPATH . 'getid3.lyrics3.php';
        getLyrics3Filepointer($ThisFileInfo, $fd, 0 - 128 - $lyrics3size, 1, $lyrics3size);
    } elseif ($lyrics3end == 'LYRICS200') {
        // Lyrics3 v2 and ID3v1
        $lyrics3size = $lyrics3lsz + 6 + strlen('LYRICS200');
        // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200'
        $ThisFileInfo['avdataend'] -= $lyrics3size;
        require_once GETID3_INCLUDEPATH . 'getid3.lyrics3.php';
        getLyrics3Filepointer($ThisFileInfo, $fd, -128 - $lyrics3size, 2, $lyrics3size);
    } elseif (substr($lyrics3_id3v1, strlen($lyrics3_id3v1) - 1 - 9, 9) == 'LYRICSEND') {
        // Lyrics3 v1, no ID3v1 (I think according to Lyrics3 specs there MUST be ID3v1, but just in case :)
        $lyrics3size = 5100;
        $ThisFileInfo['avdataend'] -= $lyrics3size;
        require_once GETID3_INCLUDEPATH . 'getid3.lyrics3.php';
        getLyrics3Filepointer($ThisFileInfo, $fd, 0 - $lyrics3size, 1, $lyrics3size);
    } elseif (substr($lyrics3_id3v1, strlen($lyrics3_id3v1) - 1 - 9, 9) == 'LYRICS200') {
        // Lyrics3 v2, no ID3v1 (I think according to Lyrics3 specs there MUST be ID3v1, but just in case :)
        $lyrics3size = $lyrics3lsz + 6 + strlen('LYRICS200');
        // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200'
        $ThisFileInfo['avdataend'] -= $lyrics3size;
        require_once GETID3_INCLUDEPATH . 'getid3.lyrics3.php';
        getLyrics3Filepointer($ThisFileInfo, $fd, 0 - $lyrics3size, 2, $lyrics3size);
    }
    if (substr($id3v1tag, 0, 3) == 'TAG') {
        $ThisFileInfo['avdataend'] -= 128;
        require_once GETID3_INCLUDEPATH . 'getid3.id3v1.php';
        getID3v1Filepointer($fd, $ThisFileInfo);
        // Do not change fileformat if already set
        if (empty($ThisFileInfo['fileformat'])) {
            $ThisFileInfo['fileformat'] = 'id3';
        }
        $ThisFileInfo['tags'][] = 'id3v1';
        // ID3v1 has lowest preference. We add if $ThisFileInfo[comments] is empty - this will override empty tags of higher preference, or add comments to root if not already present
        if (isset($ThisFileInfo['id3v1'])) {
            CopyFormatCommentsToRootComments($ThisFileInfo['id3v1'], $ThisFileInfo, true, false, false);
        }
    }
    return true;
}