Add write support for ID3v2 frames

git-svn-id: http://php-reader.googlecode.com/svn/trunk@65 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
svollbehr
2008-04-02 15:22:46 +00:00
parent 458335dc9f
commit ad6a722bae
88 changed files with 1857 additions and 337 deletions

View File

@@ -55,7 +55,7 @@ final class ID3_Frame_GEOB extends ID3_Frame
implements ID3_Encoding
{
/** @var integer */
private $_encoding;
private $_encoding = ID3_Encoding::UTF8;
/** @var string */
private $_mimeType;
@@ -66,16 +66,22 @@ final class ID3_Frame_GEOB extends ID3_Frame
/** @var string */
private $_description;
/** @var string */
private $_objectData;
/**
* Constructs the class with given parameters and parses object related data.
*
* @param Reader $reader The reader object.
*/
public function __construct($reader)
public function __construct($reader = null)
{
parent::__construct($reader);
if ($reader === null)
return;
$this->_encoding = ord($this->_data{0});
$this->_encoding = Transform::fromInt8($this->_data[0]);
$this->_mimeType = substr
($this->_data, 1, ($pos = strpos($this->_data, "\0", 1)) - 1);
$this->_data = substr($this->_data, $pos);
@@ -107,32 +113,110 @@ final class ID3_Frame_GEOB extends ID3_Frame
* @return integer
*/
public function getEncoding() { return $this->_encoding; }
/**
* Sets the text encoding.
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/
public function setEncoding($encoding) { $this->_encoding = $encoding; }
/**
* Returns the MIME type. The MIME type is always encoded with ISO-8859-1.
*
* @return string
*/
public function getMimeType() { return $this->_mimeType; }
/**
* Sets the MIME type. The MIME type is always ISO-8859-1 encoded.
*
* @param string $mimeType The MIME type.
*/
public function setMimeType($mimeType) { $this->_mimeType = $mimeType; }
/**
* Returns the file name.
*
* @return string
*/
public function getFilename() { return $this->_filename; }
/**
* Sets the file name using given encoding. The file name encoding must be
* that of the description text.
*
* @param string $description The file description text.
* @param integer $encoding The text encoding.
*/
public function setFilename($filename, $encoding = false)
{
$this->_filename = $filename;
if ($encoding !== false)
$this->_encoding = $encoding;
}
/**
* Returns the file description.
*
* @return string
*/
public function getDescription() { return $this->_description; }
/**
* Sets the file description text using given encoding. The description
* encoding must be that of the file name.
*
* @param string $description The file description text.
* @param integer $encoding The text encoding.
*/
public function setDescription($description, $encoding = false)
{
$this->_description = $description;
if ($encoding !== false)
$this->_encoding = $encoding;
}
/**
* Returns the embedded object binary data.
*
* @return string
*/
public function getData() { return $this->_data; }
public function getData() { return $this->_objectData; }
/**
* Sets the embedded object binary data.
*
* @param string $objectData The object data.
*/
public function setData($objectData) { $this->_objectData = $objectData; }
/**
* Returns the frame raw data.
*
* @return string
*/
public function __toString()
{
$data = Transform::toInt8($this->_encoding) . $this->_mimeType . "\0";
switch ($this->_encoding) {
case self::UTF16:
$data .= Transform::toString16($this->_filename) . "\0\0" .
Transform::toString16($this->_description) . "\0\0";
break;
case self::UTF16BE:
$data .= Transform::toString16BE($this->_filename) . "\0\0" .
Transform::toString16BE($this->_description) . "\0\0";
break;
case self::UTF16LE:
$data .= Transform::toString16LE($this->_filename) . "\0\0" .
Transform::toString16LE($this->_description) . "\0\0";
break;
default:
$data .= $this->_filename . "\0" . $this->_description . "\0";
}
$this->setData($data . $this->_objectData);
return parent::__toString();
}
}