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

@@ -51,6 +51,7 @@ require_once("ID3/Timing.php");
* There may be more than one SYLT frame in each tag, but only one with the
* same language and content descriptor.
*
* @todo The data could be parsed further; data samples needed
* @package php-reader
* @subpackage ID3
* @author Sven Vollbehr <svollbehr@gmail.com>
@@ -71,36 +72,39 @@ final class ID3_Frame_SYLT extends ID3_Frame
"Chord", "Trivia", "URLs to webpages", "URLs to images");
/** @var integer */
private $_encoding;
private $_encoding = ID3_Encoding::UTF8;
/** @var string */
private $_language;
private $_language = "eng";
/** @var integer */
private $_format;
private $_format = 1;
/** @var integer */
private $_type;
private $_type = 0;
/** @var string */
private $_description;
/** @var Array */
private $_text = array();
private $_text;
/**
* 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);
$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->_format = ord($this->_data{3});
$this->_type = ord($this->_data{4});
$this->_format = Transform::fromInt8($this->_data[3]);
$this->_type = Transform::fromInt8($this->_data[4]);
$this->_data = substr($this->_data, 5);
switch ($this->_encoding) {
@@ -129,6 +133,14 @@ final class ID3_Frame_SYLT 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
@@ -138,32 +150,120 @@ final class ID3_Frame_SYLT extends ID3_Frame
* @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 timing format.
*
* @return integer
*/
public function getFormat() { return $this->_format; }
/**
* Sets the timing format.
*
* @see ID3_Timing
* @param integer $format The timing format.
*/
public function setFormat($format) { $this->_format = $format; }
/**
* Returns the content type code.
*
* @return integer
*/
public function getType() { return $this->_type; }
/**
* Sets the content type code.
*
* @param integer $type The content type code.
*/
public function setType($type) { $this->_type = $type; }
/**
* Returns the 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 texts with their timestamps.
*
* @return Array
*/
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 .
Transform::toInt8($this->_format) . Transform::toInt8($this->_type);
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();
}
}