Exemplo n.º 1
0
 /**
  * Constructs the ID3v1 class with given file. The file is not mandatory
  * argument and may be omitted. A new tag can be written to a file also by
  * giving the filename to the {@link #write} method of this class.
  *
  * @param string $filename The path to the file.
  */
 public function __construct($filename = false)
 {
     if (($this->_filename = $filename) === false || file_exists($filename) === false) {
         return;
     }
     $this->_reader = new Reader($filename);
     if ($this->_reader->getSize() < 128) {
         return;
     }
     $this->_reader->setOffset(-128);
     if ($this->_reader->read(3) != "TAG") {
         $this->_reader = false;
         // reset reader, see write
         return;
     }
     $this->_title = rtrim($this->_reader->readString8(30), " ");
     $this->_artist = rtrim($this->_reader->readString8(30), " ");
     $this->_album = rtrim($this->_reader->readString8(30), " ");
     $this->_year = $this->_reader->readString8(4);
     $this->_comment = rtrim($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();
 }
Exemplo n.º 2
0
 /**
  * Reads and constructs the boxes found within this box.
  *
  * @todo Does not parse iTunes internal ---- boxes.
  */
 protected function constructBoxes($defaultclassname = "ISO14496_Box")
 {
   $base = $this->getOption("base", "");
   if ($this->getType() != "file")
     self::$_path[] = $this->getType();
   $path = implode(self::$_path, ".");
   
   while (true) {
     $offset = $this->_reader->getOffset();
     if ($offset >= $this->_offset + $this->_size)
       break;
     $size = $this->_reader->readUInt32BE();
     $type = rtrim($this->_reader->read(4), " ");
     if ($size == 1)
       $size = $this->_reader->readInt64BE();
     if ($size == 0)
       $size = $this->_reader->getSize() - $offset;
     
     if (preg_match("/^\xa9?[a-z0-9]{3,4}$/i", $type) &&
         substr($base, 0, min(strlen($base), strlen
                              ($tmp = $path . ($path ? "." : "") . $type))) ==
         substr($tmp,  0, min(strlen($base), strlen($tmp))))
     {
       $this->_reader->setOffset($offset);
       if (@fopen($filename = "ISO14496/Box/" . strtoupper($type) . ".php",
                  "r", true) !== false)
         require_once($filename);
       if (class_exists($classname = "ISO14496_Box_" . strtoupper($type)))
         $box = new $classname($this->_reader, $this->_options);
       else
         $box = new $defaultclassname($this->_reader, $this->_options);
       $box->setParent($this);
       if (!isset($this->_boxes[$box->getType()]))
         $this->_boxes[$box->getType()] = array();
       $this->_boxes[$box->getType()][] = $box;
     }
     $this->_reader->setOffset($offset + $size);
   }
   
   array_pop(self::$_path);
 }
Exemplo n.º 3
0
 /**
  * Reads and constructs the boxes found within this box.
  *
  * @todo Does not parse iTunes internal ---- boxes.
  */
 protected final function constructBoxes($defaultclassname = 'Zend_Media_Iso14496_Box')
 {
     $base = $this->getOption('base', '');
     if ($this->getType() != 'file') {
         self::$_path[] = $this->getType();
     }
     $path = implode(self::$_path, '.');
     while (true) {
         $offset = $this->_reader->getOffset();
         if ($offset >= $this->_offset + $this->_size) {
             break;
         }
         $size = $this->_reader->readUInt32BE();
         $type = rtrim($this->_reader->read(4), ' ');
         if ($size == 1) {
             $size = $this->_reader->readInt64BE();
         }
         if ($size == 0) {
             $size = $this->_reader->getSize() - $offset;
         }
         if (preg_match("/^©?[a-z0-9]{3,4}\$/i", $type) && substr($base, 0, min(strlen($base), strlen($tmp = $path . ($path ? '.' : '') . $type))) == substr($tmp, 0, min(strlen($base), strlen($tmp)))) {
             $this->_reader->setOffset($offset);
             if (@fopen($filename = 'Zend/Media/Iso14496/Box/' . ucfirst($type) . '.php', 'r', true) !== false) {
                 require_once $filename;
             }
             if (class_exists($classname = 'Zend_Media_Iso14496_Box_' . ucfirst($type))) {
                 $box = new $classname($this->_reader, $this->_options);
             } else {
                 $box = new $defaultclassname($this->_reader, $this->_options);
             }
             $box->setParent($this);
             if (!isset($this->_boxes[$box->getType()])) {
                 $this->_boxes[$box->getType()] = array();
             }
             $this->_boxes[$box->getType()][] = $box;
         }
         $this->_reader->setOffset($offset + $size);
     }
     array_pop(self::$_path);
 }
Exemplo n.º 4
0
 /**
  * Reads the magic information from given magic file.
  *
  * @param string $filename The path to the magic file.
  */
 public function __construct($filename)
 {
   $reader = new Reader($filename);
   $this->_magic = $reader->read($reader->getSize());
 }
Exemplo n.º 5
0
  /**
   * Constructs the ID3v1 class with given file. The file is not mandatory
   * argument and may be omitted. A new tag can be written to a file also by
   * giving the filename to the {@link #write} method of this class.
   *
   * @param string|Reader $filename The path to the file, file descriptor of an
   *                                opened file, or {@link Reader} instance.
   */
  public function __construct($filename = false)
  {
    if ($filename instanceof Reader)
      $this->_reader = &$filename;
    else if ((is_string($filename) && ($this->_filename = $filename) !== false &&
              file_exists($filename) !== false) ||
             (is_resource($filename) &&
              in_array(get_resource_type($filename), array("file", "stream"))))
      $this->_reader = new Reader($filename);
    else
      return;

    if ($this->_reader->getSize() < 128)
      throw new ID3_Exception("File does not contain ID3v1 tag");
    $this->_reader->setOffset(-128);
    if ($this->_reader->read(3) != "TAG") {
      $this->_reader = false; // reset reader, see write
      throw new ID3_Exception("File does not contain ID3v1 tag");
    }

    $this->_title = rtrim($this->_reader->readString8(30), " \0");
    $this->_artist = rtrim($this->_reader->readString8(30), " \0");
    $this->_album = rtrim($this->_reader->readString8(30), " \0");
    $this->_year = $this->_reader->readString8(4);
    $this->_comment = rtrim($this->_reader->readString8(28), " \0");

    /* 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, " \0");

    $this->_genre = $this->_reader->readInt8();
  }