Add support for encoding option

git-svn-id: http://php-reader.googlecode.com/svn/trunk@129 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
svollbehr
2008-12-28 19:00:44 +00:00
parent b4cae3bf42
commit c97e87fbc6
16 changed files with 602 additions and 276 deletions

View File

@@ -183,7 +183,7 @@ class ID3_Frame extends ID3_Object
$this->_size = $dataLength;
if ($this->hasFlag(self::UNSYNCHRONISATION) ||
$this->getOption("unsyncronisation", false) === true)
$this->getOption("unsynchronisation", false) === true)
$this->_data = $this->decodeUnsynchronisation($this->_data);
}
}
@@ -246,7 +246,7 @@ class ID3_Frame extends ID3_Object
$this->_data = $data;
$this->_size = strlen($data);
}
/**
* Returns the frame raw data.
*
@@ -285,8 +285,9 @@ class ID3_Frame extends ID3_Object
$data = Transform::toUInt32BE($this->encodeSynchsafe32($this->_size)) .
$data;
$flags |= self::DATA_LENGTH_INDICATOR | self::UNSYNCHRONISATION;
$this->setOption("unsyncronisation", true);
}
$this->setOption("unsynchronisation", true);
} else
$flags &= ~(self::DATA_LENGTH_INDICATOR | self::UNSYNCHRONISATION);
}
return Transform::toString8(substr($this->_identifier, 0, 4), 4) .
Transform::toUInt32BE($this->encodeSynchsafe32($size)) .

View File

@@ -80,7 +80,7 @@ final class ID3_Frame_APIC extends ID3_Frame
"Publisher/Studio logotype");
/** @var integer */
private $_encoding = ID3_Encoding::UTF8;
private $_encoding;
/** @var string */
private $_mimeType = "image/unknown";
@@ -107,29 +107,41 @@ final class ID3_Frame_APIC extends ID3_Frame
{
parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null)
return;
$this->_encoding = Transform::fromUInt8($this->_data[0]);
$encoding = Transform::fromUInt8($this->_data[0]);
$this->_mimeType = substr
($this->_data, 1, ($pos = strpos($this->_data, "\0", 1)) - 1);
$this->_imageType = Transform::fromUInt8($this->_data[++$pos]);
$this->_data = substr($this->_data, $pos + 1);
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
list ($this->_description, $this->_imageData) =
$this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16($this->_description);
$this->_description = $this->convertString
(Transform::fromString16($this->_description), "utf-16");
break;
case self::UTF16BE:
list ($this->_description, $this->_imageData) =
$this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16BE($this->_description);
$this->_description = $this->convertString
(Transform::fromString16BE($this->_description), "utf-16be");
break;
case self::UTF8:
list ($this->_description, $this->_imageData) =
$this->explodeString8($this->_data, 2);
$this->_description = $this->convertString
($this->_description, "utf-8");
break;
default:
list ($this->_description, $this->_imageData) =
$this->explodeString8($this->_data, 2);
$this->_description = $this->convertString
($this->_description, "iso-8859-1");
}
$this->_imageSize = strlen($this->_imageData);
@@ -138,6 +150,11 @@ final class ID3_Frame_APIC extends ID3_Frame
/**
* Returns the text encoding.
*
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer
*/
public function getEncoding() { return $this->_encoding; }
@@ -145,6 +162,12 @@ final class ID3_Frame_APIC extends ID3_Frame
/**
* Sets the text encoding.
*
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/

View File

@@ -59,7 +59,7 @@ abstract class ID3_Frame_AbstractText extends ID3_Frame
*
* @var integer
*/
protected $_encoding = ID3_Encoding::UTF8;
protected $_encoding;
/**
* The text array.
@@ -78,29 +78,43 @@ abstract class ID3_Frame_AbstractText extends ID3_Frame
{
parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null)
return;
$this->_encoding = Transform::fromUInt8($this->_data[0]);
$encoding = Transform::fromUInt8($this->_data[0]);
$this->_data = substr($this->_data, 1);
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
$this->_text =
$this->explodeString16(Transform::fromString16($this->_data));
$this->_text = $this->convertString
($this->explodeString16(Transform::fromString16($this->_data)),
"utf-16");
break;
case self::UTF16BE:
$this->_text =
$this->explodeString16(Transform::fromString16BE($this->_data));
$this->_text = $this->convertString
($this->explodeString16(Transform::fromString16BE($this->_data)),
"utf-16be");
break;
case self::UTF8:
$this->_text = $this->convertString
($this->explodeString8(Transform::fromString8($this->_data)), "utf-8");
break;
default:
$this->_text =
$this->explodeString8(Transform::fromString8($this->_data));
$this->_text = $this->convertString
($this->explodeString8(Transform::fromString8($this->_data)),
"iso-8859-1");
}
}
/**
* Returns the text encoding.
*
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer
*/
public function getEncoding() { return $this->_encoding; }
@@ -108,6 +122,12 @@ abstract class ID3_Frame_AbstractText extends ID3_Frame
/**
* Sets the text encoding.
*
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/

View File

@@ -62,7 +62,7 @@ final class ID3_Frame_COMM extends ID3_Frame
implements ID3_Encoding, ID3_Language
{
/** @var integer */
private $_encoding = ID3_Encoding::UTF8;
private $_encoding;
/** @var string */
private $_language = "und";
@@ -83,39 +83,60 @@ final class ID3_Frame_COMM extends ID3_Frame
{
parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null)
return;
$this->_encoding = Transform::fromUInt8($this->_data[0]);
$encoding = Transform::fromUInt8($this->_data[0]);
$this->_language = substr($this->_data, 1, 3);
if ($this->_language == "XXX")
$this->_language = "und";
$this->_data = substr($this->_data, 4);
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
list ($this->_description, $this->_text) =
$this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16($this->_description);
$this->_text = Transform::fromString16($this->_text);
$this->_description = $this->convertString
(Transform::fromString16($this->_description), "utf-16");
$this->_text = $this->convertString
(Transform::fromString16($this->_text), "utf-16");
break;
case self::UTF16BE:
list ($this->_description, $this->_text) =
$this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16BE($this->_description);
$this->_text = Transform::fromString16BE($this->_text);
$this->_description = $this->convertString
(Transform::fromString16BE($this->_description), "utf-16be");
$this->_text = $this->convertString
(Transform::fromString16BE($this->_text), "utf-16be");
break;
case self::UTF8:
list ($this->_description, $this->_text) =
$this->explodeString8($this->_data, 2);
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "utf-8");
$this->_text = $this->convertString
(Transform::fromString8($this->_text), "utf-8");
break;
default:
list ($this->_description, $this->_text) =
$this->explodeString8($this->_data, 2);
$this->_description = Transform::fromString8($this->_description);
$this->_text = Transform::fromString8($this->_text);
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "iso-8859-1");
$this->_text = $this->convertString
(Transform::fromString8($this->_text), "iso-8859-1");
}
}
/**
* Returns the text encoding.
*
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer
*/
public function getEncoding() { return $this->_encoding; }
@@ -123,6 +144,12 @@ final class ID3_Frame_COMM extends ID3_Frame
/**
* Sets the text encoding.
*
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/

View File

@@ -72,7 +72,7 @@ final class ID3_Frame_COMR extends ID3_Frame
"Non-musical merchandise");
/** @var integer */
private $_encoding = ID3_Encoding::UTF8;
private $_encoding;
/** @var string */
private $_currency = "EUR";
@@ -114,10 +114,12 @@ final class ID3_Frame_COMR extends ID3_Frame
{
parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null)
return;
$this->_encoding = Transform::fromUInt8($this->_data[0]);
$encoding = Transform::fromUInt8($this->_data[0]);
list($pricing, $this->_data) =
$this->explodeString8(substr($this->_data, 1), 2);
$this->_currency = substr($pricing, 0, 3);
@@ -128,24 +130,38 @@ final class ID3_Frame_COMR extends ID3_Frame
$this->_delivery = Transform::fromUInt8($this->_data[0]);
$this->_data = substr($this->_data, 1);
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
list ($this->_seller, $this->_description, $this->_data) =
$this->explodeString16($this->_data, 3);
$this->_seller = Transform::fromString16($this->_seller);
$this->_description = Transform::fromString16($this->_description);
$this->_seller = $this->convertString
(Transform::fromString16($this->_seller), "utf-16");
$this->_description = $this->convertString
(Transform::fromString16($this->_description), "utf-16");
break;
case self::UTF16BE:
list ($this->_seller, $this->_description, $this->_data) =
$this->explodeString16($this->_data, 3);
$this->_seller = Transform::fromString16BE($this->_seller);
$this->_description = Transform::fromString16BE($this->_description);
$this->_seller = $this->convertString
(Transform::fromString16BE($this->_seller), "utf-16be");
$this->_description = $this->convertString
(Transform::fromString16BE($this->_description), "utf-16be");
break;
case self::UTF8:
list ($this->_seller, $this->_description, $this->_data) =
$this->explodeString8($this->_data, 3);
$this->_seller = $this->convertString
(Transform::fromString8($this->_seller), "utf-8");
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "utf-8");
break;
default:
list ($this->_seller, $this->_description, $this->_data) =
$this->explodeString8($this->_data, 3);
$this->_seller = Transform::fromString8($this->_seller);
$this->_description = Transform::fromString8($this->_description);
$this->_seller = $this->convertString
(Transform::fromString8($this->_seller), "iso-8859-1");
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "iso-8859-1");
}
if (strlen($this->_data) == 0)
@@ -160,6 +176,11 @@ final class ID3_Frame_COMR extends ID3_Frame
/**
* Returns the text encoding.
*
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer
*/
public function getEncoding() { return $this->_encoding; }
@@ -167,6 +188,12 @@ final class ID3_Frame_COMR extends ID3_Frame
/**
* Sets the text encoding.
*
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/

View File

@@ -56,7 +56,7 @@ final class ID3_Frame_GEOB extends ID3_Frame
implements ID3_Encoding
{
/** @var integer */
private $_encoding = ID3_Encoding::UTF8;
private $_encoding;
/** @var string */
private $_mimeType;
@@ -80,38 +80,59 @@ final class ID3_Frame_GEOB extends ID3_Frame
{
parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null)
return;
$this->_encoding = Transform::fromUInt8($this->_data[0]);
$encoding = Transform::fromUInt8($this->_data[0]);
$this->_mimeType = substr
($this->_data, 1, ($pos = strpos($this->_data, "\0", 1)) - 1);
$this->_data = substr($this->_data, $pos + 1);
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
list ($this->_filename, $this->_description, $this->_objectData) =
$this->explodeString16($this->_data, 3);
$this->_filename = Transform::fromString16($this->_filename);
$this->_description = Transform::fromString16($this->_description);
$this->_filename = $this->convertString
(Transform::fromString16($this->_filename), "utf-16");
$this->_description = $this->convertString
(Transform::fromString16($this->_description), "utf-16");
break;
case self::UTF16BE:
list ($this->_filename, $this->_description, $this->_objectData) =
$this->explodeString16($this->_data, 3);
$this->_filename = Transform::fromString16BE($this->_filename);
$this->_description = Transform::fromString16BE($this->_description);
$this->_filename = $this->convertString
(Transform::fromString16BE($this->_filename), "utf-16be");
$this->_description = $this->convertString
(Transform::fromString16BE($this->_description), "utf-16be");
break;
case self::UTF8:
list ($this->_filename, $this->_description, $this->_objectData) =
$this->explodeString8($this->_data, 3);
$this->_filename = $this->convertString
(Transform::fromString8($this->_filename), "utf-8");
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "utf-8");
break;
default:
list ($this->_filename, $this->_description, $this->_objectData) =
$this->explodeString8($this->_data, 3);
$this->_filename = Transform::fromString8($this->_filename);
$this->_description = Transform::fromString8($this->_description);
$this->_filename = $this->convertString
(Transform::fromString8($this->_filename), "iso-8859-1");
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "iso-8859-1");
}
}
/**
* Returns the text encoding.
*
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer
*/
public function getEncoding() { return $this->_encoding; }
@@ -119,6 +140,12 @@ final class ID3_Frame_GEOB extends ID3_Frame
/**
* Sets the text encoding.
*
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/

View File

@@ -59,7 +59,7 @@ final class ID3_Frame_IPLS extends ID3_Frame
implements ID3_Encoding
{
/** @var integer */
private $_encoding = ID3_Encoding::UTF8;
private $_encoding;
/** @var Array */
private $_people = array();
@@ -74,25 +74,32 @@ final class ID3_Frame_IPLS extends ID3_Frame
{
parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null)
return;
$this->_encoding = Transform::fromUInt8($this->_data[0]);
$encoding = Transform::fromUInt8($this->_data[0]);
$data = substr($this->_data, 1);
$order = Transform::MACHINE_ENDIAN_ORDER;
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
$data = $this->explodeString16($data);
foreach ($data as &$str)
$str = Transform::fromString16($str, $order);
$str = $this->convertString
(Transform::fromString16($str, $order), "utf-16");
break;
case self::UTF16BE:
$data = $this->explodeString16($data);
foreach ($data as &$str)
$str = Transform::fromString16BE($str);
$str = $this->convertString
(Transform::fromString16BE($str), "utf-16be");
break;
case self::UTF8:
$data = $this->convertString($this->explodeString8($data), "utf-8");
break;
default:
$data = $this->explodeString8($data);
$data = $this->convertString($this->explodeString8($data), "iso-8859-1");
}
for ($i = 0; $i < count($data) - 1; $i += 2)
@@ -101,14 +108,25 @@ final class ID3_Frame_IPLS extends ID3_Frame
/**
* Returns the text encoding.
*
*
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer
*/
public function getEncoding() { return $this->_encoding; }
/**
* Sets the text encoding.
*
*
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/

View File

@@ -59,7 +59,7 @@ final class ID3_Frame_OWNE extends ID3_Frame
implements ID3_Encoding
{
/** @var integer */
private $_encoding = ID3_Encoding::UTF8;
private $_encoding;
/** @var string */
private $_currency = "EUR";
@@ -83,10 +83,12 @@ final class ID3_Frame_OWNE extends ID3_Frame
{
parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null)
return;
$this->_encoding = Transform::fromUInt8($this->_data[0]);
$encoding = Transform::fromUInt8($this->_data[0]);
list($tmp, $this->_data) =
$this->explodeString8(substr($this->_data, 1), 2);
$this->_currency = substr($tmp, 0, 3);
@@ -94,21 +96,33 @@ final class ID3_Frame_OWNE extends ID3_Frame
$this->_date = substr($this->_data, 0, 8);
$this->_data = substr($this->_data, 8);
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
$this->_seller = Transform::fromString16($this->_data);
$this->_seller = $this->convertString
(Transform::fromString16($this->_data), "utf-16");
break;
case self::UTF16BE:
$this->_seller = Transform::fromString16BE($this->_data);
$this->_seller = $this->convertString
(Transform::fromString16BE($this->_data), "utf-16be");
break;
case self::UTF8:
$this->_seller = $this->convertString
(Transform::fromString8($this->_data), "utf-8");
break;
default:
$this->_seller = Transform::fromString8($this->_data);
$this->_seller = $this->convertString
(Transform::fromString8($this->_data), "iso-8859-1");
}
}
/**
* Returns the text encoding.
*
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer
*/
public function getEncoding() { return $this->_encoding; }
@@ -116,6 +130,12 @@ final class ID3_Frame_OWNE extends ID3_Frame
/**
* Sets the text encoding.
*
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/

View File

@@ -72,7 +72,7 @@ final class ID3_Frame_SYLT extends ID3_Frame
"Chord", "Trivia", "URLs to webpages", "URLs to images");
/** @var integer */
private $_encoding = ID3_Encoding::UTF8;
private $_encoding;
/** @var string */
private $_language = "und";
@@ -99,10 +99,12 @@ final class ID3_Frame_SYLT extends ID3_Frame
{
parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null)
return;
$this->_encoding = Transform::fromUInt8($this->_data[0]);
$encoding = Transform::fromUInt8($this->_data[0]);
$this->_language = substr($this->_data, 1, 3);
if ($this->_language == "XXX")
$this->_language = "und";
@@ -110,39 +112,57 @@ final class ID3_Frame_SYLT extends ID3_Frame
$this->_type = Transform::fromUInt8($this->_data[5]);
$this->_data = substr($this->_data, 6);
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
list($this->_description, $this->_data) =
$this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16($this->_description);
$this->_description = $this->convertString
(Transform::fromString16($this->_description), "utf-16");
break;
case self::UTF16BE:
list($this->_description, $this->_data) =
$this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16BE($this->_description);
$this->_description = $this->convertString
(Transform::fromString16BE($this->_description), "utf-16be");
break;
case self::UTF8:
list($this->_description, $this->_data) =
$this->explodeString8($this->_data, 2);
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "utf-8");
break;
default:
list($this->_description, $this->_data) =
$this->explodeString8($this->_data, 2);
$this->_description = Transform::fromString8($this->_description);
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "iso-8859-1");
}
while (strlen($this->_data) > 0) {
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
list($syllable, $this->_data) =
$this->explodeString16($this->_data, 2);
$syllable = Transform::fromString16($syllable);
$syllable = $this->convertString
(Transform::fromString16($syllable), "utf-16");
break;
case self::UTF16BE:
list($syllable, $this->_data) =
$this->explodeString16($this->_data, 2);
$syllable = Transform::fromString16BE($syllable);
$syllable = $this->convertString
(Transform::fromString16BE($syllable), "utf-16be");
break;
case self::UTF8:
list($syllable, $this->_data) =
$this->explodeString8($this->_data, 2);
$syllable = $this->convertString
(Transform::fromString8($syllable), "utf-8");
break;
default:
list($syllable, $this->_data) =
$this->explodeString8($this->_data, 2);
$syllable = Transform::fromString8($syllable);
$syllable = $this->convertString
(Transform::fromString8($syllable), "iso-8859-1");
}
$this->_events[Transform::fromUInt32BE(substr($this->_data, 0, 4))] =
$syllable;
@@ -154,6 +174,11 @@ final class ID3_Frame_SYLT extends ID3_Frame
/**
* Returns the text encoding.
*
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer
*/
public function getEncoding() { return $this->_encoding; }
@@ -161,6 +186,12 @@ final class ID3_Frame_SYLT extends ID3_Frame
/**
* Sets the text encoding.
*
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/

View File

@@ -72,28 +72,39 @@ final class ID3_Frame_TXXX extends ID3_Frame_AbstractText
{
ID3_Frame::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null)
return;
$this->_encoding = Transform::fromUInt8($this->_data[0]);
$encoding = Transform::fromUInt8($this->_data[0]);
$this->_data = substr($this->_data, 1);
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
list($this->_description, $this->_text) =
$this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16($this->_description);
$this->_text = array(Transform::fromString16($this->_text));
$this->_description = $this->convertString
(Transform::fromString16($this->_description), "utf-16");
$this->_text = $this->convertString
(array(Transform::fromString16($this->_text)), "utf-16");
break;
case self::UTF16BE:
list($this->_description, $this->_text) =
$this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16BE($this->_description);
$this->_text = array(Transform::fromString16BE($this->_text));
$this->_description = $this->convertString
(Transform::fromString16BE($this->_description), "utf-16be");
$this->_text = $this->convertString
(array(Transform::fromString16BE($this->_text)), "utf-16be");
break;
case self::UTF8:
list($this->_description, $this->_text) = $this->convertString
($this->explodeString8($this->_data, 2), "utf-8");
$this->_text = array($this->_text);
break;
default:
list($this->_description, $this->_text) =
$this->explodeString8($this->_data, 2);
list($this->_description, $this->_text) = $this->convertString
($this->explodeString8($this->_data, 2), "iso-8859-1");
$this->_text = array($this->_text);
}
}

View File

@@ -60,7 +60,7 @@ final class ID3_Frame_USER extends ID3_Frame
implements ID3_Encoding, ID3_Language
{
/** @var integer */
private $_encoding = ID3_Encoding::UTF8;
private $_encoding;
/** @var string */
private $_language = "und";
@@ -78,30 +78,44 @@ final class ID3_Frame_USER extends ID3_Frame
{
parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null)
return;
$this->_encoding = Transform::fromUInt8($this->_data[0]);
$encoding = Transform::fromUInt8($this->_data[0]);
$this->_language = substr($this->_data, 1, 3);
if ($this->_language == "XXX")
$this->_language = "und";
$this->_data = substr($this->_data, 4);
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
$this->_text = Transform::fromString16($this->_data);
$this->_text = $this->convertString
(Transform::fromString16($this->_data), "utf-16");
break;
case self::UTF16BE:
$this->_text = Transform::fromString16BE($this->_data);
$this->_text = $this->convertString
(Transform::fromString16BE($this->_data), "utf-16be");
break;
case self::UTF8:
$this->_text = $this->convertString
(Transform::fromString8($this->_data), "utf-8");
break;
default:
$this->_text = Transform::fromString8($this->_data);
$this->_text = $this->convertString
(Transform::fromString8($this->_data), "iso-8859-1");
}
}
/**
* Returns the text encoding.
*
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer
*/
public function getEncoding() { return $this->_encoding; }
@@ -109,6 +123,12 @@ final class ID3_Frame_USER extends ID3_Frame
/**
* Sets the text encoding.
*
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/

View File

@@ -59,7 +59,7 @@ final class ID3_Frame_USLT extends ID3_Frame
implements ID3_Encoding, ID3_Language
{
/** @var integer */
private $_encoding = ID3_Encoding::UTF8;
private $_encoding;
/** @var string */
private $_language = "und";
@@ -80,39 +80,60 @@ final class ID3_Frame_USLT extends ID3_Frame
{
parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null)
return;
$this->_encoding = Transform::fromUInt8($this->_data[0]);
$encoding = Transform::fromUInt8($this->_data[0]);
$this->_language = substr($this->_data, 1, 3);
if ($this->_language == "XXX")
$this->_language = "und";
$this->_data = substr($this->_data, 4);
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
list ($this->_description, $this->_text) =
$this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16($this->_description);
$this->_text = Transform::fromString16($this->_text);
$this->_description = $this->convertString
(Transform::fromString16($this->_description), "utf-16");
$this->_text = $this->convertString
(Transform::fromString16($this->_text), "utf-16");
break;
case self::UTF16BE:
list ($this->_description, $this->_text) =
$this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16BE($this->_description);
$this->_text = Transform::fromString16BE($this->_text);
$this->_description = $this->convertString
(Transform::fromString16BE($this->_description), "utf-16be");
$this->_text = $this->convertString
(Transform::fromString16BE($this->_text), "utf-16be");
break;
case self::UTF8:
list ($this->_description, $this->_text) =
$this->explodeString8($this->_data, 2);
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "utf-8");
$this->_text = $this->convertString
(Transform::fromString8($this->_text), "utf-8");
break;
default:
list ($this->_description, $this->_text) =
$this->explodeString8($this->_data, 2);
$this->_description = Transform::fromString8($this->_description);
$this->_text = Transform::fromString8($this->_text);
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "iso-8859-1");
$this->_text = $this->convertString
(Transform::fromString8($this->_text), "iso-8859-1");
}
}
/**
* Returns the text encoding.
*
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer
*/
public function getEncoding() { return $this->_encoding; }
@@ -120,6 +141,12 @@ final class ID3_Frame_USLT extends ID3_Frame
/**
* Sets the text encoding.
*
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/

View File

@@ -59,7 +59,7 @@ final class ID3_Frame_WXXX extends ID3_Frame_AbstractLink
implements ID3_Encoding
{
/** @var integer */
private $_encoding = ID3_Encoding::UTF8;
private $_encoding;
/** @var string */
private $_description;
@@ -74,27 +74,37 @@ final class ID3_Frame_WXXX extends ID3_Frame_AbstractLink
{
ID3_Frame::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null)
return;
$this->_encoding = Transform::fromUInt8($this->_data[0]);
$encoding = Transform::fromUInt8($this->_data[0]);
$this->_data = substr($this->_data, 1);
switch ($this->_encoding) {
switch ($encoding) {
case self::UTF16:
list($this->_description, $this->_link) =
$this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16($this->_description);
$this->_description = $this->convertString
(Transform::fromString16($this->_description), "utf-16");
break;
case self::UTF16BE:
list($this->_description, $this->_link) =
$this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16BE($this->_description);
list($this->_description, $this->_link) =
$this->explodeString16($this->_data, 2);
$this->_description = $this->convertString
(Transform::fromString16BE($this->_description), "utf-16be");
break;
case self::UTF8:
list($this->_description, $this->_link) =
$this->explodeString8($this->_data, 2);
$this->_description = $this->convertString($this->_description, "utf-8");
break;
default:
list($this->_description, $this->_link) =
$this->explodeString8($this->_data, 2);
break;
$this->_description = $this->convertString
($this->_description, "iso-8859-1");
}
$this->_link = implode($this->explodeString8($this->_link, 1), "");
}
@@ -102,6 +112,11 @@ final class ID3_Frame_WXXX extends ID3_Frame_AbstractLink
/**
* Returns the text encoding.
*
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer The encoding.
*/
public function getEncoding() { return $this->_encoding; }
@@ -109,6 +124,12 @@ final class ID3_Frame_WXXX extends ID3_Frame_AbstractLink
/**
* Sets the text encoding.
*
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/

View File

@@ -195,7 +195,7 @@ abstract class ID3_Object
/**
* Reverses the unsynchronisation scheme from the given data string.
*
* @see encodeUnsyncronisation
* @see encodeUnsynchronisation
* @param string $data The input data.
* @return string
*/
@@ -248,4 +248,42 @@ abstract class ID3_Object
{
return preg_split("/\\x00/", $value, $limit);
}
/**
* Converts string to requested character encoding and returns it. See the
* documentation of iconv for accepted values for encoding.
*
* @param string|Array $string
* @param string $encoding
*/
protected function convertString($string, $encoding)
{
$target = $this->getOption("encoding", ID3_Encoding::UTF8);
switch ($target) {
case ID3_Encoding::UTF16:
$target = "utf-16";
break;
case ID3_Encoding::UTF16LE:
$target = "utf-16le";
break;
case ID3_Encoding::UTF16BE:
$target = "utf-16be";
break;
case ID3_Encoding::UTF8:
$target = "utf-8";
break;
default:
$target = "iso-8859-1";
}
if (strtolower($target) == strtolower($encoding))
return $string;
if (is_array($string))
foreach ($string as $key => $value)
$string[$key] = iconv($encoding, $target, $value);
else
$string = iconv($encoding, $target, $string);
return $string;
}
}

View File

@@ -96,6 +96,10 @@ final class ID3v2
* may also be given as the only parameter.
*
* The following options are currently recognized:
* o encoding -- Indicates the encoding that all the texts are presented
* with. By default this is set to ID3_Encoding::UTF8. See the
* documentation of the {@link ID3_Encoding} interface for accepted
* values. Conversions are carried out using iconv.
* o version -- The ID3v2 tag version to use in write operation. This option
* is automatically set when a tag is read from a file and defaults to
* version 4.0 for tag write.

File diff suppressed because it is too large Load Diff