id.php

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 979 行 · 第 1/2 页

PHP
979
字号
<?php//// +----------------------------------------------------------------------+// | PHP Version 4                                                        |// +----------------------------------------------------------------------+// | Copyright (c) 1997-2003 The PHP Group                                |// +----------------------------------------------------------------------+// | This code is released under the GNU LGPL Go read it over here:       |// | http://www.gnu.org/copyleft/lesser.html                              |// +----------------------------------------------------------------------+// | Authors: Sandy McArthur Jr. <Leknor@Leknor.com>                      |// +----------------------------------------------------------------------+//// $Id: Id.php,v 1.8 2005/07/04 11:32:09 alexmerz Exp $//// Uncomment the folling define if you want the class to automatically// read the MPEG frame info to get bitrate, mpeg version, layer, etc.//// NOTE: 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('ID3_AUTO_STUDY', true);// Uncomment the following define if you want tons of debgging info.// Tip: make sure you use a <PRE> block so the print_r's are readable.// define('ID3_SHOW_DEBUG', true);require_once "PEAR.php" ;/*** File not opened* @const PEAR_MP3_ID_FNO*/define('PEAR_MP3_ID_FNO', 1);/*** Read error* @const PEAR_MP3_ID_RE*/define('PEAR_MP3_ID_RE', 2);/*** Tag not found* @const PEAR_MP3_ID_TNF */define('PEAR_MP3_ID_TNF', 3);/*** File is not a MP3 file (corrupted?)* @const PEAR_MP3_ID_NOMP3 */define('PEAR_MP3_ID_NOMP3', 4);/** * A Class for reading/writing MP3 ID3 tags *  * Note: 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. :~) * * eg: * require_once("MP3/Id.php"); * $file = "Some Song.mp3"; * * $id3 = &new MP3_Id(); * $id3->read($file); * print_r($id3); * * echo $id3->getTag('artists'); * * $id3->comment = "Be gentle with that file."; * $id3->write(); * $id3->read($file); * print_r($id3 ); *  * @package MP3_Id * @author Sandy McArthur Jr. <Leknor@Leknor.com> * @version $Version$ */class MP3_Id {    /**    * mp3/mpeg file name    * @var boolean    */    var $file = false;          /**    * ID3 v1 tag found? (also true if v1.1 found)    * @var boolean    */    var $id3v1 = false;         /**    * ID3 v1.1 tag found?     * @var boolean    */        var $id3v11 = false;    /**    * ID3 v2 tag found? (not used yet)    * @var boolean    */            var $id3v2 = false;    // ID3v1.1 Fields:    /**    * trackname    * @var string    */            var $name = '';    /**    * artists    * @var string    */                var $artists = '';    /**    * album    * @var string    */                    var $album = '';    /**    * year    * @var string    */                    var $year = '';      /**    * comment    * @var string    */                    var $comment = '';    /**    * track number    * @var integer    */                    var $track = 0;    /**    * genre name    * @var string    */    var $genre = '';    /**    * genre number    * @var integer    */                        var $genreno = 255;    // MP3 Frame Stuff    /**    * Was the file studied to learn more info?    * @var boolean    */    var $studied = false;        /**    * version of mpeg    * @var integer    */        var $mpeg_ver = 0;    /**    * version of layer    * @var integer    */            var $layer = 0;    /**    * version of bitrate    * @var integer    */            var $bitrate = 0;    /**    * Frames are crc protected?    * @var boolean    */                var $crc = false;    /**    * frequency    * @var integer    */                    var $frequency = 0;    /**    * Frames padded    * @var boolean    */                    var $padding = false;    /**    * private bit set    * @var boolean    */                        var $private = false;    /**    * Mode (Stero etc)    * @var string    */                        var $mode = '';    /**    * Copyrighted    * @var string    */                            var $copyright = false;     /**    * On Original Media? (never used)    * @var boolean    */                            var $original = false;    /**    * Emphasis (also never used)    * @var boolean    */                            var $emphasis = '';         /**    * Bytes in file     * @var integer    */    var $filesize = -1;    /**    * Byte at which the first mpeg header was found    * @var integer    */                                var $frameoffset = -1;    /**    * length of mp3 format hh:ss    * @var string    */    var $length = false;     /**    * length of mp3 in seconds    * @var string    */                                var $lengths = false;    /**    * if any errors they will be here    * @var string    */    var $error = false;        /**    * print debugging info?    * @var boolean    */    var $debug = false;    /**    * print debugg    * @var string    */        var $debugbeg = '<DIV STYLE="margin: 0.5 em; padding: 0.5 em; border-width: thin; border-color: black; border-style: solid">';    /**    * print debugg    * @var string    */    var $debugend = '</DIV>';    /*     * creates a new id3 object     * and loads a tag from a file.     *     * @param string    $study  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.     * @access public     */    function MP3_Id($study = false) {        if(defined('ID3_SHOW_DEBUG')) $this->debug = true;        $this->study=($study || defined('ID3_AUTO_STUDY'));    } // id3()    /**    * reads the given file and parse it    *    * @param    string  $file the name of the file to parse    * @return   mixed   PEAR_Error on error    * @access   public    */    function read( $file="") {        if ($this->debug) print($this->debugbeg . "id3('$file')<HR>\n");        if(!empty($file))$this->file = $file;        if ($this->debug) print($this->debugend);        return $this->_read_v1();    }    /**    * sets a field    *     * possible names of tags are:    * artists   - Name of band or artist    * album     - Name of the album    * year      - publishing year of the album or song    * comment   - song comment    * track     - the number of the track    * genre     - genre of the song    * genreno   - Number of the genre    *    * @param    mixed   $name   Name of the tag to set or hash with the key as fieldname    * @param    mixed   $value  the value to set     *    * @access   public    */    function setTag($name, $value) {        if( is_array($name)) {            foreach( $name as $n => $v) {                $this -> $n = $v ;                }        } else {            $this -> $name = $value ;                }    }        /**    * get the value of a tag    *     * @param    string  $name       the name of the field to get    * @param    mixed   $default    returned if the field not exists    *     * @return   mixed   The value of the field    * @access   public     * @see      setTag    */    function getTag($name, $default = 0) {        if(empty($this -> $name)) {            return $default ;        } else {            return $this -> $name ;        }    }                /**     * update the id3v1 tags on the file.     * Note: If/when ID3v2 is implemented this method will probably get another     *       parameters.     *          * @param boolean $v1   if true update/create an id3v1 tag on the file. (defaults to true)     *      * @access public     */    function write($v1 = true) {    if ($this->debug) print($this->debugbeg . "write()<HR>\n");    if ($v1) {        $this->_write_v1();    }    if ($this->debug) print($this->debugend);    } // write()    /**     * study() - does extra work to get the MPEG frame info.     *      * @access public     */    function study() {    $this->studied = true;    $this->_readframe();    } // study()    /**     * copy($from) - set's the ID3 fields to the same as the fields in $from     *      * @param string    $from   fields to copy     * @access public     */    function copy($from) {    if ($this->debug) print($this->debugbeg . "copy(\$from)<HR>\n");    $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 ($this->debug) print($this->debugend);    } // copy($from)    /**     * remove - removes the id3 tag(s) from a file.     *     * @param boolean   $id3v1  true to remove the tag     * @param boolean   $id3v2  true to remove the tag (Not yet implemented)     *     * @access public     */    function remove($id3v1 = true, $id3v2 = true) {    if ($this->debug) print($this->debugbeg . "remove()<HR>\n");    if ($id3v1) {        $this->_remove_v1();    }    if ($id3v2) {        // TODO: write ID3v2 code    }    if ($this->debug) print($this->debugend);    } // remove    /**     * 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.     *     * @return mixed    PEAR_Error if fails     * @access private     */    function _read_v1() {    if ($this->debug) print($this->debugbeg . "_read_v1()<HR>\n");    if (! ($f = @fopen($this->file, 'rb')) ) {        return PEAR::raiseError( "Unable to open " . $this->file, PEAR_MP3_ID_FNO);    }    if (fseek($f, -128, SEEK_END) == -1) {        return PEAR::raiseError( 'Unable to see to end - 128 of ' . $this->file, PEAR_MP3_ID_RE);    }    $r = fread($f, 128);    fclose($f);    if ($this->debug) {        $unp = unpack('H*raw', $r);        print_r($unp);    }    $id3tag = $this->_decode_v1($r);    if(!PEAR::isError( $id3tag)) {        $this->id3v1 = true;        $tmp = explode(Chr(0), $id3tag['NAME']);        $this->name = $tmp[0];        $tmp = explode(Chr(0), $id3tag['ARTISTS']);        $this->artists = $tmp[0];        $tmp = explode(Chr(0), $id3tag['ALBUM']);        $this->album = $tmp[0];        $tmp = explode(Chr(0), $id3tag['YEAR']);        $this->year = $tmp[0];        $tmp = explode(Chr(0), $id3tag['COMMENT']);        $this->comment = $tmp[0];        if (isset($id3tag['TRACK'])) {        $this->id3v11 = true;        $this->track = $id3tag['TRACK'];        }        $this->genreno = $id3tag['GENRENO'];        $this->genre = $id3tag['GENRE'];    } else {        return $id3tag ;        }    if ($this->debug) print($this->debugend);    } // _read_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     *     * @param   string  $rawtag    tag to decode     * @return  string  decoded tag     * @access  private     */    function _decode_v1($rawtag) {    if ($this->debug) print($this->debugbeg . "_decode_v1(\$rawtag)<HR>\n");    if ($rawtag[125] == Chr(0) and $rawtag[126] != Chr(0)) {        // ID3 v1.1        $format = 'a3TAG/a30NAME/a30ARTISTS/a30ALBUM/a4YEAR/a28COMMENT/x1/C1TRACK/C1GENRENO';    } else {        // ID3 v1        $format = 'a3TAG/a30NAME/a30ARTISTS/a30ALBUM/a4YEAR/a30COMMENT/C1GENRENO';    }    $id3tag = unpack($format, $rawtag);    if ($this->debug) print_r($id3tag);    if ($id3tag['TAG'] == 'TAG') {        $id3tag['GENRE'] = $this->getgenre($id3tag['GENRENO']);    } else {        $id3tag = PEAR::raiseError( 'TAG not found', PEAR_MP3_ID_TNF);    }    if ($this->debug) print($this->debugend);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?