コード例 #1
0
ファイル: Id3v1.php プロジェクト: adam-fonseca/RuneUI
 /**
  * Constructs the Id3v1 class with given file. The file is not mandatory
  * argument and may be omitted as a new tag can be written to a file also by
  * giving the filename to the {@link #write} method of this class.
  *
  * @param string|resource|Zend_Io_Reader $filename The path to the file,
  *  file descriptor of an opened file, or a {@link Zend_Io_Reader} instance.
  * @throws Zend_Media_Id3_Exception if given file descriptor is not valid
  */
 public function __construct($filename = null)
 {
     if ($filename === null) {
         return;
     }
     if ($filename instanceof Zend_Io_Reader) {
         $this->_reader =& $filename;
     } else {
         $this->_filename = $filename;
         require_once 'Zend/Io/FileReader.php';
         try {
             $this->_reader = new Zend_Io_FileReader($filename);
         } catch (Zend_Io_Exception $e) {
             $this->_reader = null;
             require_once 'Zend/Media/Id3/Exception.php';
             throw new Zend_Media_Id3_Exception($e->getMessage());
         }
     }
     if ($this->_reader->getSize() < 128) {
         $this->_reader = null;
         require_once 'Zend/Media/Id3/Exception.php';
         throw new Zend_Media_Id3_Exception('File does not contain ID3v1 tag');
     }
     $this->_reader->setOffset(-128);
     if ($this->_reader->read(3) != 'TAG') {
         $this->_reader = null;
         require_once 'Zend/Media/Id3/Exception.php';
         throw new Zend_Media_Id3_Exception('File does not contain ID3v1 tag');
     }
     $this->_title = $this->_reader->readString8(30, " ");
     $this->_artist = $this->_reader->readString8(30, " ");
     $this->_album = $this->_reader->readString8(30, " ");
     $this->_year = $this->_reader->readString8(4);
     $this->_comment = $this->_reader->readString8(28);
     /* ID3v1.1 support for tracks */
     $v11_null = $this->_reader->read(1);
     $v11_track = $this->_reader->read(1);
     if (ord($v11_null) == 0 && ord($v11_track) != 0) {
         $this->_track = ord($v11_track);
     } else {
         $this->_comment = rtrim($this->_comment . $v11_null . $v11_track, " ");
     }
     $this->_genre = $this->_reader->readInt8();
 }