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:
@@ -39,6 +39,7 @@
|
||||
require_once("ID3/Frame.php");
|
||||
require_once("ID3/Encoding.php");
|
||||
require_once("ID3/Language.php");
|
||||
require_once("ID3/Exception.php");
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
@@ -60,10 +61,10 @@ final class ID3_Frame_COMM extends ID3_Frame
|
||||
implements ID3_Encoding, ID3_Language
|
||||
{
|
||||
/** @var integer */
|
||||
private $_encoding;
|
||||
private $_encoding = ID3_Encoding::UTF8;
|
||||
|
||||
/** @var string */
|
||||
private $_language;
|
||||
private $_language = "eng";
|
||||
|
||||
/** @var string */
|
||||
private $_description;
|
||||
@@ -76,11 +77,14 @@ final class ID3_Frame_COMM extends ID3_Frame
|
||||
*
|
||||
* @param Reader $reader The reader object.
|
||||
*/
|
||||
public function __construct($reader)
|
||||
public function __construct($reader = null)
|
||||
{
|
||||
parent::__construct($reader);
|
||||
|
||||
$this->_encoding = ord($this->_data{0});
|
||||
if ($reader === null)
|
||||
return;
|
||||
|
||||
$this->_encoding = Transform::fromInt8($this->_data[0]);
|
||||
$this->_language = substr($this->_data, 1, 3);
|
||||
$this->_data = substr($this->_data, 4);
|
||||
|
||||
@@ -111,27 +115,106 @@ final class ID3_Frame_COMM 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 language code as specified in the
|
||||
* {@link http://www.loc.gov/standards/iso639-2/ ISO-639-2} standard.
|
||||
*
|
||||
* @see ID3_Language#ISO_639_2
|
||||
* @return string
|
||||
*/
|
||||
public function getLanguage() { return $this->_language; }
|
||||
|
||||
|
||||
/**
|
||||
* Sets the text language code as specified in the
|
||||
* {@link http://www.loc.gov/standards/iso639-2/ ISO-639-2} standard.
|
||||
*
|
||||
* @see ID3_Language
|
||||
* @param string $language The language code.
|
||||
*/
|
||||
public function setLanguage($language) { $this->_language = $language; }
|
||||
|
||||
/**
|
||||
* Returns the short content description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription() { return $this->_description; }
|
||||
|
||||
|
||||
/**
|
||||
* Sets the content description text using given encoding. The description
|
||||
* language and encoding must be that of the actual text.
|
||||
*
|
||||
* @param string $description The content description text.
|
||||
* @param string $language The language code.
|
||||
* @param integer $encoding The text encoding.
|
||||
*/
|
||||
public function setDescription($description, $language = false,
|
||||
$encoding = false)
|
||||
{
|
||||
$this->_description = $description;
|
||||
if ($language !== false)
|
||||
$this->_language = $language;
|
||||
if ($encoding !== false)
|
||||
$this->_encoding = $encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getText() { return $this->_text; }
|
||||
|
||||
/**
|
||||
* Sets the text using given encoding. The text language and encoding must be
|
||||
* that of the description text.
|
||||
*
|
||||
* @param mixed $text The test string.
|
||||
* @param string $language The language code.
|
||||
* @param integer $encoding The text encoding.
|
||||
*/
|
||||
public function setText($text, $language = false, $encoding = false)
|
||||
{
|
||||
$this->_text = $text;
|
||||
if ($language !== false)
|
||||
$this->_language = $language;
|
||||
if ($encoding !== false)
|
||||
$this->_encoding = $encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the frame raw data.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$data = Transform::toInt8($this->_encoding) . $this->_language;
|
||||
switch ($this->_encoding) {
|
||||
case self::UTF16:
|
||||
$data .= Transform::toString16($this->_description) . "\0\0" .
|
||||
Transform::toString16($this->_text);
|
||||
break;
|
||||
case self::UTF16BE:
|
||||
$data .= Transform::toString16BE($this->_description) . "\0\0" .
|
||||
Transform::toString16BE($this->_text);
|
||||
break;
|
||||
case self::UTF16LE:
|
||||
$data .= Transform::toString16LE($this->_description) . "\0\0" .
|
||||
Transform::toString16LE($this->_text);
|
||||
break;
|
||||
default:
|
||||
$data .= $this->_description . "\0" . $this->_text;
|
||||
}
|
||||
$this->setData($data);
|
||||
return parent::__toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user