parsing mp3 tags

Σε αυτή την περιοχή μπορείτε να βρείτε ή να αναζητήσετε πληροφορίες σχετικές με την PHP

Συντονιστές: WebDev Moderators, Super-Moderators, PHP Moderators

Απάντηση
Άβαταρ μέλους
tsirman
Δημοσιεύσεις: 145
Εγγραφή: 14 Νοέμ 2002 22:57
Επικοινωνία:

parsing mp3 tags

Δημοσίευση από tsirman » 10 Οκτ 2004 19:36

vasika exo tosa mp3 pu pleon de mporo na ta elenkso ke toso grigora. skeftika lipon na vro tropo na paro ta tags tus ke meta na kano insert ola ta tags se mia vasi gia ena pio kalo ke apodotiko search eite me vasi to onoma tu mp3 eite me ala stixia pu dinun ta tags tus....kserei kanis pos diavazw ta tags twn mp3 me php? xriazete kapia vivliothiki opos adistixa ke stin C ?

Άβαταρ μέλους
cordis
Administrator, [F|H]ounder, [C|S]EO
Δημοσιεύσεις: 27626
Εγγραφή: 09 Οκτ 1999 03:00
Τοποθεσία: Greece
Επικοινωνία:

parsing mp3 tags

Δημοσίευση από cordis » 10 Οκτ 2004 19:52

Κώδικας: Επιλογή όλων

<?php

// I don't have time or interest to write ID3v2 support. BUT I have beta
// code to read ID3v2 tags. If you want to finish this code go for it.
// If you get a good working copy either sent it to me or tell me where to
// redirect people that want it. You can check the _beta_ ID3v2 code at&#58;
// http&#58;//leknor.com/code/php/view/beta/class.id3v2.php.txt

// Uncomment the folling define if you want the class to automatically
// read the MPEG frame info to get bitrate, mpeg version, layer, etc.
//
// NOTE&#58; This is needed to maintain pre-version 1.0 behavior which maybe
// needed if you are using info that is from the mpeg frame. This includes
// the length of the song.
//
// This is discouraged because it will siginfincantly lengthen script
// execution time if all you need is the ID3 tag info.
// define&#40;'ID3_AUTO_STUDY', true&#41;;

// Uncomment the following define if you want tons of debgging info.
// Tip&#58; make sure you use a <PRE> block so the print_r's are readable.
// define&#40;'ID3_SHOW_DEBUG', true&#41;;

class id3 &#123;
    /*
     * id3 - A Class for reading/writing MP3 ID3 tags
     * 
     * By Sandy McArthur, Jr. <Leknor@Leknor.com>
     * 
     * Copyright 2001 &#40;c&#41; All Rights Reserved, All Responsibility Yours
     *
     * This code is released under the GNU LGPL Go read it over here&#58;
     * http&#58;//www.gnu.org/copyleft/lesser.html
     * 
     * I do make one optional request, I would like an account on or a
     * copy of where this code is used. If that is not possible then
     * an email would be cool.
     * 
     * Warning&#58; I really hope this doesn't mess up your MP3s but you
     * are on your own if bad things happen.
     *
     * Note&#58; This code doesn't try to deal with corrupt mp3s. So if you get
     * incorrect length times or something else it may be your mp3. To fix just
     * re-enocde from the CD. &#58;~&#41;
     * 
     * To use this code first create a id3 object passing the path to the mp3 as the first
     * parameter. Then just access the ID3 fields directly &#40;look below for their names&#41;.
     * If you want to update a tag just change the fields and then $id3->write&#40;&#41;;
     * The methods designed for general use are study&#40;&#41;, write&#40;&#41;, copy&#40;$from&#41;, remove&#40;&#41;,
     * and genres&#40;&#41;. Please read the comment before each method for the specifics of each.
     * 
     * eg&#58;
     *     require_once&#40;'class.id3.php'&#41;;
     *    $id3 = new id3&#40;'/path/to/our lady peace - middle of yesterday.mp3'&#41;;
     *  echo $id3->artists, ' - ', $id3->name;
     *    $id3->comment = 'Go buy some OLP CDs, they rock!';
     *    $id3->write&#40;&#41;;
     *
     * Change Log&#58;
     *    1.24&#58;    Small change to the write&#40;&#41; method because the old way it worked was poorly
     *        thought out. The new write&#40;&#41; method has optional parameters. $id3->frameoffset
     *        added which will have the byte offset of the first mpeg frame and $id3->filesize
     *    1.23&#58;    MPEG Frame pasrsion code should be perfect on everything but VBR mp3's.
     *    1.20&#58;    Reimplemented most of the mpeg frame parsing code plus a whole lot more.
     *    1.10&#58;    ID3v1 and v1.1 functionality completed.
     *    1.00&#58;    Decided to rewrite and correct all my poor choices and to implement ID3v1.1
     *        Looking at my old code I'm ashamed I ever released it and called it functional.
     * 
     * TODO&#58;
     *    Implement ID3v2 reader and maybe writer if enought people want it.
     * 
     * The most recent version is available at&#58;
     *    http&#58;//Leknor.com/code/
     *
     */

    var $_version = 1.24; // Version of the id3 class


    var $file = false;        // mp3/mpeg file name

    var $id3v1 = false;        // ID3 v1 tag found? &#40;also true if v1.1 found&#41;
    var $id3v11 = false;    // ID3 v1.1 tag found?
    var $id3v2 = false;        // ID3 v2 tag found? &#40;not used yet&#41;

    // ID3v1.1 Fields&#58;
    var $name = '';        // track name
    var $artists = '';        // artists
    var $album = '';        // album
    var $year = '';        // year
    var $comment = '';        // comment
    var $track = 0;        // track number
    var $genre = '';        // genre name
    var $genreno = 255;        // genre number

    // MP3 Frame Stuff
    var $studied = false;    // Was the file studied to learn more info?
    var $mpeg_ver = false;    // version of mpeg
    var $layer = false;        // version of layer
    var $bitrate = false;    // bitrate
    var $crc = false;        // Frames are crc protected?
    var $frequency = 0;        // Frequency
    var $padding = false;    // Frames padded
    var $private = false;    // Private bit set?
    var $mode = '';        // Mode &#40;Stereo etc&#41;
    var $copyright = false;    // Copyrighted?
    var $original = false;    // On Original Media? &#40;never used&#41;
    var $emphasis = '';        // Emphasis &#40;also never used&#41;
    var $filesize = -1;        // Bytes in file
    var $frameoffset = -1;    // Byte at which the first mpeg header was found.

    var $length = false;    // length of mp3 format hh&#58;ss
    var $lengths = false;    // length of mp3 in seconds

    var $error = false;        // if any errors they will be here

    var $debug = false;        // print debugging info?
    var $debugbeg = '<DIV STYLE="margin&#58; 0.5 em; padding&#58; 0.5 em; border-width&#58; thin; border-color&#58; black; border-style&#58; solid">';
    var $debugend = '</DIV>';

    /*
     * id3 constructor - creates a new id3 object and maybe loads a tag
     * from a file.
     *
     * $file - the path to the mp3/mpeg file. When in doubt use a full path.
     * $study - &#40;Optional&#41; - study the mpeg frame to get extra info like bitrate and frequency
     *        You should advoid studing alot of files as it will siginficantly slow this down.
     */
    function id3&#40;$file, $study = false&#41; &#123;
    if &#40;defined&#40;'ID3_SHOW_DEBUG'&#41;&#41; $this->debug = true;
    if &#40;$this->debug&#41; print&#40;$this->debugbeg . "id3&#40;'$file'&#41;<HR>\n"&#41;;

    $this->file = $file;
    $this->_read_v1&#40;&#41;;

    if &#40;$study or defined&#40;'ID3_AUTO_STUDY'&#41;&#41;
        $this->study&#40;&#41;;

    if &#40;$this->debug&#41; print&#40;$this->debugend&#41;;
    &#125; // id3&#40;$file&#41;

    /*
     * write - update the id3v1 tags on the file.
     *
     * $v1 - if true update/create an id3v1 tag on the file. &#40;defaults to true&#41;
     *
     * Note&#58; If/when ID3v2 is implemented this method will probably get another
     *       parameters.
     */
    function write&#40;$v1 = true&#41; &#123;
    if &#40;$this->debug&#41; print&#40;$this->debugbeg . "write&#40;&#41;<HR>\n"&#41;;
    if &#40;$v1&#41; &#123;
        $this->_write_v1&#40;&#41;;
    &#125;
    if &#40;$this->debug&#41; print&#40;$this->debugend&#41;;
    &#125; // write&#40;&#41;

    /*
     * study&#40;&#41; - does extra work to get the MPEG frame info.
     */
    function study&#40;&#41; &#123;
    $this->studied = true;
    $this->_readframe&#40;&#41;;
    &#125; // study&#40;&#41;

    /*
     * copy&#40;$from&#41; - set's the ID3 fields to the same as the fields in $from
     */
    function copy&#40;$from&#41; &#123;
    if &#40;$this->debug&#41; print&#40;$this->debugbeg . "copy&#40;\$from&#41;<HR>\n"&#41;;
    $this->name    = $from->name;
    $this->artists    = $from->artists;
    $this->album    = $from->album;
    $this->year    = $from->year;
    $this->comment    = $from->comment;
    $this->track    = $from->track;
    $this->genre    = $from->genre;
    $this->genreno    = $from->genreno;
    if &#40;$this->debug&#41; print&#40;$this->debugend&#41;;
    &#125; // copy&#40;$from&#41;

    /*
     * remove - removes the id3 tag&#40;s&#41; from a file.
     *
     * $id3v1 - true to remove the tag
     * $id3v2 - true to remove the tag &#40;Not yet implemented&#41;
     */
    function remove&#40;$id3v1 = true, $id3v2 = true&#41; &#123;
    if &#40;$this->debug&#41; print&#40;$this->debugbeg . "remove&#40;&#41;<HR>\n"&#41;;

    if &#40;$id3v1&#41; &#123;
        $this->_remove_v1&#40;&#41;;
    &#125;

    if &#40;$id3v2&#41; &#123;
        // TODO&#58; write ID3v2 code
    &#125;

    if &#40;$this->debug&#41; print&#40;$this->debugend&#41;;
    &#125; // remove


    /*
     * _read_v1 - read a ID3 v1 or v1.1 tag from a file
     *
     * $file should be the path to the mp3 to look for a tag.
     * When in doubt use the full path.
     *
     * if there is an error it will return false and a message will be
     * put in $this->error
     */
    function _read_v1&#40;&#41; &#123;
    if &#40;$this->debug&#41; print&#40;$this->debugbeg . "_read_v1&#40;&#41;<HR>\n"&#41;;

    if &#40;! &#40;$f = fopen&#40;$this->file, 'rb'&#41;&#41; &#41; &#123;
        $this->error = 'Unable to open ' . $file;
        return false;
    &#125;

    if &#40;fseek&#40;$f, -128, SEEK_END&#41; == -1&#41; &#123;
        $this->error = 'Unable to see to end - 128 of ' . $file;
        return false;
    &#125;

    $r = fread&#40;$f, 128&#41;;
    fclose&#40;$f&#41;;

    if &#40;$this->debug&#41; &#123;
        $unp = unpack&#40;'H*raw', $r&#41;;
        print_r&#40;$unp&#41;;
    &#125;

    $id3tag = $this->_decode_v1&#40;$r&#41;;

    if&#40;$id3tag&#41; &#123;
        $this->id3v1 = true;

        $tmp = explode&#40;Chr&#40;0&#41;, $id3tag&#91;'NAME'&#93;&#41;;
        $this->name = $tmp&#91;0&#93;;

        $tmp = explode&#40;Chr&#40;0&#41;, $id3tag&#91;'ARTISTS'&#93;&#41;;
        $this->artists = $tmp&#91;0&#93;;

        $tmp = explode&#40;Chr&#40;0&#41;, $id3tag&#91;'ALBUM'&#93;&#41;;
        $this->album = $tmp&#91;0&#93;;

        $tmp = explode&#40;Chr&#40;0&#41;, $id3tag&#91;'YEAR'&#93;&#41;;
        $this->year = $tmp&#91;0&#93;;

        $tmp = explode&#40;Chr&#40;0&#41;, $id3tag&#91;'COMMENT'&#93;&#41;;
        $this->comment = $tmp&#91;0&#93;;

        if &#40;isset&#40;$id3tag&#91;'TRACK'&#93;&#41;&#41; &#123;
        $this->id3v11 = true;
        $this->track = $id3tag&#91;'TRACK'&#93;;
        &#125;

        $this->genreno = $id3tag&#91;'GENRENO'&#93;;
        $this->genre = $id3tag&#91;'GENRE'&#93;;
    &#125;

    if &#40;$this->debug&#41; print&#40;$this->debugend&#41;;
    &#125; // _read_v1&#40;&#41;

    /*
     * _decode_v1 - decodes that ID3v1 or ID3v1.1 tag
     *
     * false will be returned if there was an error decoding the tag
     * else an array will be returned
     */
    function _decode_v1&#40;$rawtag&#41; &#123;
    if &#40;$this->debug&#41; print&#40;$this->debugbeg . "_decode_v1&#40;\$rawtag&#41;<HR>\n"&#41;;

    if &#40;$rawtag&#91;125&#93; == Chr&#40;0&#41; and $rawtag&#91;126&#93; != Chr&#40;0&#41;&#41; &#123;
        // ID3 v1.1
        $format = 'a3TAG/a30NAME/a30ARTISTS/a30ALBUM/a4YEAR/a28COMMENT/x1/C1TRACK/C1GENRENO';
    &#125; else &#123;
        // ID3 v1
        $format = 'a3TAG/a30NAME/a30ARTISTS/a30ALBUM/a4YEAR/a30COMMENT/C1GENRENO';
    &#125;

    $id3tag = unpack&#40;$format, $rawtag&#41;;
    if &#40;$this->debug&#41; print_r&#40;$id3tag&#41;;

    if &#40;$id3tag&#91;'TAG'&#93; == 'TAG'&#41; &#123;
        $id3tag&#91;'GENRE'&#93; = $this->getgenre&#40;$id3tag&#91;'GENRENO'&#93;&#41;;
    &#125; else &#123;
        $this->error = 'TAG not found';
        $id3tag = false;
    &#125;
    if &#40;$this->debug&#41; print&#40;$this->debugend&#41;;
    return $id3tag;
    &#125; // _decode_v1&#40;&#41;


    /*
     * _write_v1 - writes a ID3 v1 or v1.1 tag to a file
     *
     * if there is an error it will return false and a message will be
     * put in $this->error
     */
    function _write_v1&#40;&#41; &#123;
    if &#40;$this->debug&#41; print&#40;$this->debugbeg . "_write_v1&#40;&#41;<HR>\n"&#41;;

    $file = $this->file;

    if &#40;! &#40;$f = fopen&#40;$file, 'r+b'&#41;&#41; &#41; &#123;
        $this->error = 'Unable to open ' . $file;
        return false;
    &#125;

    if &#40;fseek&#40;$f, -128, SEEK_END&#41; == -1&#41; &#123;
        $this->error = 'Unable to see to end - 128 of ' . $file;
        return false;
    &#125;

    $this->genreno = $this->getgenreno&#40;$this->genre, $this->genreno&#41;;

    $newtag = $this->_encode_v1&#40;&#41;;

    $r = fread&#40;$f, 128&#41;;

    if &#40;$this->_decode_v1&#40;$r&#41;&#41; &#123;
        if &#40;fseek&#40;$f, -128, SEEK_END&#41; == -1&#41; &#123;
        $this->error = 'Unable to see to end - 128 of ' . $file;
        return false;
        &#125;
        fwrite&#40;$f, $newtag&#41;;
    &#125; else &#123;
        if &#40;fseek&#40;$f, 0, SEEK_END&#41; == -1&#41; &#123;
        $this->error = 'Unable to see to end of ' . $file;
        return false;
        &#125;
        fwrite&#40;$f, $newtag&#41;;
    &#125;
    fclose&#40;$f&#41;;


    if &#40;$this->debug&#41; print&#40;$this->debugend&#41;;
    &#125; // _write_v1&#40;&#41;

    /*
     * _encode_v1 - encode the ID3 tag
     *
     * the newly built tag will be returned
     */
    function _encode_v1&#40;&#41; &#123;
    if &#40;$this->debug&#41; print&#40;$this->debugbeg . "_encode_v1&#40;&#41;<HR>\n"&#41;;

    if &#40;$this->track&#41; &#123;
        // ID3 v1.1
        $id3pack = 'a3a30a30a30a4a28x1C1C1';
        $newtag = pack&#40;$id3pack,
            'TAG',
            $this->name,
            $this->artists,
            $this->album,
            $this->year,
            $this->comment,
            $this->track,
            $this->genreno
              &#41;;
    &#125; else &#123;
        // ID3 v1
        $id3pack = 'a3a30a30a30a4a30C1';
        $newtag = pack&#40;$id3pack,
            'TAG',
            $this->name,
            $this->artists,
            $this->album,
            $this->year,
            $this->comment,
            $this->genreno
              &#41;;
    &#125;

    if &#40;$this->debug&#41; &#123;
        print&#40;'id3pack&#58; ' . $id3pack . "\n"&#41;;
        $unp = unpack&#40;'H*new', $newtag&#41;;
        print_r&#40;$unp&#41;;
    &#125;

    if &#40;$this->debug&#41; print&#40;$this->debugend&#41;;
    return $newtag;
    &#125; // _encode_v1&#40;&#41;

    /*
     * _remove_v1 - if exists it removes an ID3v1 or v1.1 tag
     *
     * returns true if the tag was removed or none was found
     * else false if there was an error
     */
    function _remove_v1&#40;&#41; &#123;
    if &#40;$this->debug&#41; print&#40;$this->debugbeg . "_remove_v1&#40;&#41;<HR>\n"&#41;;

    $file = $this->file;

    if &#40;! &#40;$f = fopen&#40;$file, 'r+b'&#41;&#41; &#41; &#123;
        $this->error = 'Unable to open ' . $file;
        return false;
    &#125;

    if &#40;fseek&#40;$f, -128, SEEK_END&#41; == -1&#41; &#123;
        $this->error = 'Unable to see to end - 128 of ' . $file;
        return false;
    &#125;

    $r = fread&#40;$f, 128&#41;;

    $success = false;
    if &#40;$this->_decode_v1&#40;$r&#41;&#41; &#123;
        $size = filesize&#40;$this->file&#41; - 128;
        if &#40;$this->debug&#41; print&#40;'size&#58; old&#58; ' . filesize&#40;$this->file&#41;&#41;;
        $success = ftruncate&#40;$f, $size&#41;;    
        clearstatcache&#40;&#41;;
        if &#40;$this->debug&#41; print&#40;' new&#58; ' . filesize&#40;$this->file&#41;&#41;;
    &#125;
    fclose&#40;$f&#41;;
    if &#40;$this->debug&#41; print&#40;$this->debugend&#41;;
    return $success;
    &#125; // _remove_v1&#40;&#41;

    function _readframe&#40;&#41; &#123;
    if &#40;$this->debug&#41; print&#40;$this->debugbeg . "_readframe&#40;&#41;<HR>\n"&#41;;

    $file = $this->file;

    if &#40;! &#40;$f = fopen&#40;$file, 'rb'&#41;&#41; &#41; &#123;
        $this->error = 'Unable to open ' . $file;
        if &#40;$this->debug&#41; print&#40;$this->debugend&#41;;
        return false;
    &#125;

    $this->filesize = filesize&#40;$file&#41;;

    do &#123;
        while &#40;fread&#40;$f,1&#41; != Chr&#40;255&#41;&#41; &#123; // Find the first frame
        //if &#40;$this->debug&#41; echo "Find...\n";
        if &#40;feof&#40;$f&#41;&#41; &#123;
            $this->error = 'No mpeg frame found';
            if &#40;$this->debug&#41; print&#40;$this->debugend&#41;;
            return false;
        &#125;
        &#125;
        fseek&#40;$f, ftell&#40;$f&#41; - 1&#41;; // back up one byte

        $frameoffset = ftell&#40;$f&#41;;

        $r = fread&#40;$f, 4&#41;;
        // Binary to Hex to a binary sting. ugly but best I can think of.
        $bits = unpack&#40;'H*bits', $r&#41;;
        $bits =  base_convert&#40;$bits&#91;'bits'&#93;,16,2&#41;;
    &#125; while &#40;!$bits&#91;8&#93; and !$bits&#91;9&#93; and !$bits&#91;10&#93;&#41;; // 1st 8 bits true from the while
    if &#40;$this->debug&#41; print&#40;'Bits&#58; ' . $bits . "\n"&#41;;

    $this->frameoffset = $frameoffset;

    fclose&#40;$f&#41;;

    if &#40;$bits&#91;11&#93; == 0&#41; &#123;
        $this->mpeg_ver = "2.5";
        $bitrates = array&#40;
            '1' => array&#40;0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0&#41;,
            '2' => array&#40;0,  8, 16, 24, 32, 40, 48,  56,  64,  80,  96, 112, 128, 144, 160, 0&#41;,
            '3' => array&#40;0,  8, 16, 24, 32, 40, 48,  56,  64,  80,  96, 112, 128, 144, 160, 0&#41;,
                 &#41;;
    &#125; else if &#40;$bits&#91;12&#93; == 0&#41; &#123;
        $this->mpeg_ver = "2";
        $bitrates = array&#40;
            '1' => array&#40;0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0&#41;,
            '2' => array&#40;0,  8, 16, 24, 32, 40, 48,  56,  64,  80,  96, 112, 128, 144, 160, 0&#41;,
            '3' => array&#40;0,  8, 16, 24, 32, 40, 48,  56,  64,  80,  96, 112, 128, 144, 160, 0&#41;,
                 &#41;;
    &#125; else &#123;
        $this->mpeg_ver = "1";
        $bitrates = array&#40;
            '1' => array&#40;0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0&#41;,
            '2' => array&#40;0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384, 0&#41;,
            '3' => array&#40;0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 0&#41;,
                 &#41;;
    &#125;
    if &#40;$this->debug&#41; print&#40;'MPEG' . $this->mpeg_ver . "\n"&#41;;

    $layer = array&#40;
        array&#40;0,3&#41;,
        array&#40;2,1&#41;,
              &#41;;
    $this->layer = $layer&#91;$bits&#91;13&#93;&#93;&#91;$bits&#91;14&#93;&#93;;
    if &#40;$this->debug&#41; print&#40;'layer&#58; ' . $this->layer . "\n"&#41;;

    if &#40;$bits&#91;15&#93; == 0&#41; &#123;
        // It's backwards, if the bit is not set then it is protected.
        if &#40;$this->debug&#41; print&#40;"protected &#40;crc&#41;\n"&#41;;
        $this->crc = true;
    &#125;

    $bitrate = 0;
    if &#40;$bits&#91;16&#93; == 1&#41; $bitrate += 8;
    if &#40;$bits&#91;17&#93; == 1&#41; $bitrate += 4;
    if &#40;$bits&#91;18&#93; == 1&#41; $bitrate += 2;
    if &#40;$bits&#91;19&#93; == 1&#41; $bitrate += 1;
    $this->bitrate = $bitrates&#91;$this->layer&#93;&#91;$bitrate&#93;;

    $frequency = array&#40;
        '1' => array&#40;
            '0' => array&#40;44100, 48000&#41;,
            '1' => array&#40;32000, 0&#41;,
                &#41;,
        '2' => array&#40;
            '0' => array&#40;22050, 24000&#41;,
            '1' => array&#40;16000, 0&#41;,
                &#41;,
        '2.5' => array&#40;
            '0' => array&#40;11025, 12000&#41;,
            '1' => array&#40;8000, 0&#41;,
                  &#41;,
          &#41;;
    $this->frequency = $frequency&#91;$this->mpeg_ver&#93;&#91;$bits&#91;20&#93;&#93;&#91;$bits&#91;21&#93;&#93;;

    $this->padding = $bits&#91;22&#93;;
    $this->private = $bits&#91;23&#93;;

    $mode = array&#40;
        array&#40;'Stereo', 'Joint Stereo'&#41;,
        array&#40;'Dual Channel', 'Mono'&#41;,
             &#41;;
    $this->mode = $mode&#91;$bits&#91;24&#93;&#93;&#91;$bits&#91;25&#93;&#93;;

    // XXX&#58; I dunno what the mode extension is for bits 26,27

    $this->copyright = $bits&#91;28&#93;;
    $this->original = $bits&#91;29&#93;;

    $emphasis = array&#40;
        array&#40;'none', '50/15ms'&#41;,
        array&#40;'', 'CCITT j.17'&#41;,
             &#41;;
    $this->emphasis = $emphasis&#91;$bits&#91;30&#93;&#93;&#91;$bits&#91;31&#93;&#93;;

    if &#40;$this->bitrate == 0&#41; &#123;
        $s = -1;
    &#125; else &#123;
        $s = &#40;&#40;8*filesize&#40;$this->file&#41;&#41;/1000&#41; / $this->bitrate;        
    &#125;
    $this->length = sprintf&#40;'%02d&#58;%02d',floor&#40;$s/60&#41;,floor&#40;$s-&#40;floor&#40;$s/60&#41;*60&#41;&#41;&#41;;
    $this->lengths = &#40;int&#41;$s;

    if &#40;$this->debug&#41; print&#40;$this->debugend&#41;;
    &#125; // _readframe&#40;&#41;

    /*
     * getgenre - return the name of a genre number
     *
     * if no genre number is specified the genre number from
     * $this->genreno will be used.
     *
     * the genre is returned or false if an error or not found
     * no error message is ever returned
     */
    function getgenre&#40;$genreno&#41; &#123;
    if &#40;$this->debug&#41; print&#40;$this->debugbeg . "getgenre&#40;$genreno&#41;<HR>\n"&#41;;

    $genres = $this->genres&#40;&#41;;
    if &#40;isset&#40;$genres&#91;$genreno&#93;&#41;&#41; &#123;
        $genre = $genres&#91;$genreno&#93;;
        if &#40;$this->debug&#41; print&#40;$genre . "\n"&#41;;
    &#125; else &#123;
        $genre = '';
    &#125;

    if &#40;$this->debug&#41; print&#40;$this->debugend&#41;;
    return $genre;
    &#125; // getgenre&#40;$genreno&#41;

    /*
     * getgenreno - return the number of the genre name
     *
     * the genre number is returned or 0xff &#40;255&#41; if a match is not found
     * you can specify the default genreno to use if one is not found
     * no error message is ever returned
     */
    function getgenreno&#40;$genre, $default = 0xff&#41; &#123;
    if &#40;$this->debug&#41; print&#40;$this->debugbeg . "getgenreno&#40;'$genre',$default&#41;<HR>\n"&#41;;

    $genres = $this->genres&#40;&#41;;
    $genreno = false;
    if &#40;$genre&#41; &#123;
        foreach &#40;$genres as $no => $name&#41; &#123;
        if &#40;strtolower&#40;$genre&#41; == strtolower&#40;$name&#41;&#41; &#123;
            if &#40;$this->debug&#41; print&#40;"$no&#58;'$name' == '$genre'"&#41;;
            $genreno = $no;
        &#125;
        &#125;
    &#125;
    if &#40;$genreno === false&#41; $genreno = $default;
    if &#40;$this->debug&#41; print&#40;$this->debugend&#41;;
    return $genreno;
    &#125; // getgenreno&#40;$genre, $default = 0xff&#41;

    /*
     * genres - reuturns an array of the ID3v1 genres
     */
    function genres&#40;&#41; &#123;
    return array&#40;
        0   => 'Blues',
        1   => 'Classic Rock',
        2   => 'Country',
        3   => 'Dance',
        4   => 'Disco',
        5   => 'Funk',
        6   => 'Grunge',
        7   => 'Hip-Hop',
        8   => 'Jazz',
        9   => 'Metal',
        10  => 'New Age',
        11  => 'Oldies',
        12  => 'Other',
        13  => 'Pop',
        14  => 'R&B',
        15  => 'Rap',
        16  => 'Reggae',
        17  => 'Rock',
        18  => 'Techno',
        19  => 'Industrial',
        20  => 'Alternative',
        21  => 'Ska',
        22  => 'Death Metal',
        23  => 'Pranks',
        24  => 'Soundtrack',
        25  => 'Euro-Techno',
        26  => 'Ambient',
        27  => 'Trip-Hop',
        28  => 'Vocal',
        29  => 'Jazz+Funk',
        30  => 'Fusion',
        31  => 'Trance',
        32  => 'Classical',
        33  => 'Instrumental',
        34  => 'Acid',
        35  => 'House',
        36  => 'Game',
        37  => 'Sound Clip',
        38  => 'Gospel',
        39  => 'Noise',
        40  => 'Alternative Rock',
        41  => 'Bass',
        42  => 'Soul',
        43  => 'Punk',
        44  => 'Space',
        45  => 'Meditative',
        46  => 'Instrumental Pop',
        47  => 'Instrumental Rock',
        48  => 'Ethnic',
        49  => 'Gothic',
        50  => 'Darkwave',
        51  => 'Techno-Industrial',
        52  => 'Electronic',
        53  => 'Pop-Folk',
        54  => 'Eurodance',
        55  => 'Dream',
        56  => 'Southern Rock',
        57  => 'Comedy',
        58  => 'Cult',
        59  => 'Gangsta',
        60  => 'Top 40',
        61  => 'Christian Rap',
        62  => 'Pop/Funk',
        63  => 'Jungle',
        64  => 'Native US',
        65  => 'Cabaret',
        66  => 'New Wave',
        67  => 'Psychadelic',
        68  => 'Rave',
        69  => 'Showtunes',
        70  => 'Trailer',
        71  => 'Lo-Fi',
        72  => 'Tribal',
        73  => 'Acid Punk',
        74  => 'Acid Jazz',
        75  => 'Polka',
        76  => 'Retro',
        77  => 'Musical',
        78  => 'Rock & Roll',
        79  => 'Hard Rock',
        80  => 'Folk',
        81  => 'Folk-Rock',
        82  => 'National Folk',
        83  => 'Swing',
        84  => 'Fast Fusion',
        85  => 'Bebob',
        86  => 'Latin',
        87  => 'Revival',
        88  => 'Celtic',
        89  => 'Bluegrass',
        90  => 'Avantgarde',
        91  => 'Gothic Rock',
        92  => 'Progressive Rock',
        93  => 'Psychedelic Rock',
        94  => 'Symphonic Rock',
        95  => 'Slow Rock',
        96  => 'Big Band',
        97  => 'Chorus',
        98  => 'Easy Listening',
        99  => 'Acoustic',
        100 => 'Humour',
        101 => 'Speech',
        102 => 'Chanson',
        103 => 'Opera',
        104 => 'Chamber Music',
        105 => 'Sonata',
        106 => 'Symphony',
        107 => 'Booty Bass',
        108 => 'Primus',
        109 => 'Porn Groove',
        110 => 'Satire',
        111 => 'Slow Jam',
        112 => 'Club',
        113 => 'Tango',
        114 => 'Samba',
        115 => 'Folklore',
        116 => 'Ballad',
        117 => 'Power Ballad',
        118 => 'Rhytmic Soul',
        119 => 'Freestyle',
        120 => 'Duet',
        121 => 'Punk Rock',
        122 => 'Drum Solo',
        123 => 'Acapella',
        124 => 'Euro-House',
        125 => 'Dance Hall',
        126 => 'Goa',
        127 => 'Drum & Bass',
        128 => 'Club-House',
        129 => 'Hardcore',
        130 => 'Terror',
        131 => 'Indie',
        132 => 'BritPop',
        133 => 'Negerpunk',
        134 => 'Polsk Punk',
        135 => 'Beat',
        136 => 'Christian Gangsta Rap',
        137 => 'Heavy Metal',
        138 => 'Black Metal',
        139 => 'Crossover',
        140 => 'Contemporary Christian',
        141 => 'Christian Rock',
        142 => 'Merengue',
        143 => 'Salsa',
        144 => 'Trash Metal',
        145 => 'Anime',
        146 => 'Jpop',
        147 => 'Synthpop'
            &#41;;
    &#125; // genres
&#125; // end of id3

?>
http://leknor.com/code/php/view/class.id3.php.txt
Δεν απαντάω σε προσωπικά μηνύματα με ερωτήσεις που καλύπτονται από τις ενότητες του forum. Για ο,τι άλλο είμαι εδώ για εσάς.
- follow me @twitter

Άβαταρ μέλους
Rapid-eraser
WebDev Moderator
Δημοσιεύσεις: 6851
Εγγραφή: 05 Απρ 2003 17:50
Τοποθεσία: Πειραιάς
Επικοινωνία:

parsing mp3 tags

Δημοσίευση από Rapid-eraser » 10 Οκτ 2004 19:58

sto pear paketo tis php iparxei class to opoio kavei akribos afto to pragma :)
http://pear.php.net/package/MP3_ID
Cu, Rapid-eraser, Tα αγαθά copies κτώνται.
Love is like oxygen, You get too much you get too high
Not enough and you're gonna die, Love gets you high

Άβαταρ μέλους
tsirman
Δημοσιεύσεις: 145
Εγγραφή: 14 Νοέμ 2002 22:57
Επικοινωνία:

parsing mp3 tags

Δημοσίευση από tsirman » 11 Οκτ 2004 03:08

thanks cordis einai akrivos afto pu ithela.....thanks again

Rapid-eraser thanks gia tin voithia ala empleksa eki opos su ipa ke se minima :):)

Απάντηση

Επιστροφή στο “PHP Προγραμματισμός”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 0 επισκέπτες