Improved code and comments: add ID3v1 write support, add unit tests

git-svn-id: http://php-reader.googlecode.com/svn/trunk@39 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
svollbehr
2008-03-26 17:27:22 +00:00
parent 3914cfdacc
commit 1182f0e0ff
107 changed files with 2107 additions and 963 deletions

View File

@@ -2,6 +2,9 @@
/**
* PHP Reader Library
*
* Copyright (c) 2006-2008 The PHP Reader Project Workgroup. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
@@ -10,7 +13,7 @@
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the BEHR Software Systems nor the names of its
* - Neither the name of the project workgroup nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
@@ -28,9 +31,8 @@
*
* @package php-reader
* @subpackage ASF
* @copyright Copyright (c) 2006, 2007 The Bearpaw Project Work Group
* @copyright Copyright (c) 2007, 2008 BEHR Software Systems
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @copyright Copyright (c) 2006-2008 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Id$
*/
@@ -45,10 +47,9 @@ require_once("Object.php");
*
* @package php-reader
* @subpackage ASF
* @author Sven Vollbehr <sven.vollbehr@behrss.eu>
* @copyright Copyright (c) 2006, 2007 The Bearpaw Project Work Group
* @copyright Copyright (c) 2007, 2008 BEHR Software Systems
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Sven Vollbehr <svollbehr@gmail.com>
* @copyright Copyright (c) 2006-2008 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Rev$
*/
final class ASF_ContentDescriptionObject extends ASF_Object
@@ -80,17 +81,17 @@ final class ASF_ContentDescriptionObject extends ASF_Object
{
parent::__construct($reader, $id, $size);
$titleLen = $this->_reader->getUInt16LE();
$authorLen = $this->_reader->getUInt16LE();
$copyrightLen = $this->_reader->getUInt16LE();
$descriptionLen = $this->_reader->getUInt16LE();
$ratingLen = $this->_reader->getUInt16LE();
$titleLen = $this->_reader->readUInt16LE();
$authorLen = $this->_reader->readUInt16LE();
$copyrightLen = $this->_reader->readUInt16LE();
$descriptionLen = $this->_reader->readUInt16LE();
$ratingLen = $this->_reader->readUInt16LE();
$this->_title = $this->_reader->getString16LE($titleLen);
$this->_author = $this->_reader->getString16LE($authorLen);
$this->_copyright = $this->_reader->getString16LE($copyrightLen);
$this->_description = $this->_reader->getString16LE($descriptionLen);
$this->_rating = $this->_reader->getString16LE($ratingLen);
$this->_title = $this->_reader->readString16LE($titleLen);
$this->_author = $this->_reader->readString16LE($authorLen);
$this->_copyright = $this->_reader->readString16LE($copyrightLen);
$this->_description = $this->_reader->readString16LE($descriptionLen);
$this->_rating = $this->_reader->readString16LE($ratingLen);
}
/**

View File

@@ -2,6 +2,9 @@
/**
* PHP Reader Library
*
* Copyright (c) 2006-2008 The PHP Reader Project Workgroup. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
@@ -10,7 +13,7 @@
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the BEHR Software Systems nor the names of its
* - Neither the name of the project workgroup nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
@@ -28,9 +31,8 @@
*
* @package php-reader
* @subpackage ASF
* @copyright Copyright (c) 2006, 2007 The Bearpaw Project Work Group
* @copyright Copyright (c) 2007, 2008 BEHR Software Systems
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @copyright Copyright (c) 2006-2008 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Id$
*/
@@ -45,10 +47,9 @@ require_once("Object.php");
*
* @package php-reader
* @subpackage ASF
* @author Sven Vollbehr <sven.vollbehr@behrss.eu>
* @copyright Copyright (c) 2006, 2007 The Bearpaw Project Work Group
* @copyright Copyright (c) 2007, 2008 BEHR Software Systems
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Sven Vollbehr <svollbehr@gmail.com>
* @copyright Copyright (c) 2006-2008 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Rev$
*/
final class ASF_ExtendedContentDescriptionObject extends ASF_Object
@@ -68,27 +69,27 @@ final class ASF_ExtendedContentDescriptionObject extends ASF_Object
{
parent::__construct($reader, $id, $size);
$contentDescriptorsCount = $this->_reader->getUInt16LE();
$contentDescriptorsCount = $this->_reader->readUInt16LE();
for ($i = 0; $i < $contentDescriptorsCount; $i++) {
$nameLen = $this->_reader->getUInt16LE();
$name = $this->_reader->getString16LE($nameLen);
$valueDataType = $this->_reader->getUInt16LE();
$valueLen = $this->_reader->getUInt16LE();
$nameLen = $this->_reader->readUInt16LE();
$name = $this->_reader->readString16LE($nameLen);
$valueDataType = $this->_reader->readUInt16LE();
$valueLen = $this->_reader->readUInt16LE();
switch ($valueDataType) {
case 0:
case 1: // string
$this->_contentDescriptors[$name] =
$this->_reader->getString16LE($valueLen);
$this->_reader->readString16LE($valueLen);
break;
case 2: // bool
case 3: // 32-bit integer
$this->_contentDescriptors[$name] = $this->_reader->getUInt32LE();
$this->_contentDescriptors[$name] = $this->_reader->readUInt32LE();
break;
case 4: // 64-bit integer
$this->_contentDescriptors[$name] = $this->_reader->getInt64LE();
$this->_contentDescriptors[$name] = $this->_reader->readInt64LE();
break;
case 5: // 16-bit integer
$this->_contentDescriptors[$name] = $this->_reader->getUInt16LE();
$this->_contentDescriptors[$name] = $this->_reader->readUInt16LE();
break;
default:
}

View File

@@ -2,6 +2,9 @@
/**
* PHP Reader Library
*
* Copyright (c) 2006-2008 The PHP Reader Project Workgroup. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
@@ -10,7 +13,7 @@
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the BEHR Software Systems nor the names of its
* - Neither the name of the project workgroup nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
@@ -28,9 +31,8 @@
*
* @package php-reader
* @subpackage ASF
* @copyright Copyright (c) 2006, 2007 The Bearpaw Project Work Group
* @copyright Copyright (c) 2007, 2008 BEHR Software Systems
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @copyright Copyright (c) 2006-2008 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Id$
*/
@@ -44,10 +46,9 @@ require_once("Object.php");
*
* @package php-reader
* @subpackage ASF
* @author Sven Vollbehr <sven.vollbehr@behrss.eu>
* @copyright Copyright (c) 2006, 2007 The Bearpaw Project Work Group
* @copyright Copyright (c) 2007, 2008 BEHR Software Systems
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Sven Vollbehr <svollbehr@gmail.com>
* @copyright Copyright (c) 2006-2008 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Rev$
*/
final class ASF_FilePropertiesObject extends ASF_Object
@@ -97,12 +98,12 @@ final class ASF_FilePropertiesObject extends ASF_Object
{
parent::__construct($reader, $id, $size);
$this->_fileId = $this->_reader->getGUID();
$this->_fileSize = $this->_reader->getInt64LE();
$this->_creationDate = $this->_reader->getInt64LE();
$this->_dataPacketsCount = $this->_reader->getInt64LE();
$this->_fileId = $this->_reader->readGUID();
$this->_fileSize = $this->_reader->readInt64LE();
$this->_creationDate = $this->_reader->readInt64LE();
$this->_dataPacketsCount = $this->_reader->readInt64LE();
$seconds = floor($this->_reader->getInt64LE() / 10000000);
$seconds = floor($this->_reader->readInt64LE() / 10000000);
$minutes = floor($seconds / 60);
$hours = floor($minutes / 60);
$this->_playDuration =
@@ -111,7 +112,7 @@ final class ASF_FilePropertiesObject extends ASF_Object
str_pad($minutes % 60, 2, "0", STR_PAD_LEFT) : $minutes % 60) . ":" .
str_pad($seconds % 60, 2, "0", STR_PAD_LEFT) : $seconds % 60);
$seconds = floor($this->_reader->getInt64LE() / 10000000);
$seconds = floor($this->_reader->readInt64LE() / 10000000);
$minutes = floor($seconds / 60);
$hours = floor($minutes / 60);
$this->_sendDuration =
@@ -120,11 +121,11 @@ final class ASF_FilePropertiesObject extends ASF_Object
str_pad($minutes % 60, 2, "0", STR_PAD_LEFT) : $minutes % 60) . ":" .
str_pad($seconds % 60, 2, "0", STR_PAD_LEFT) : $seconds % 60);
$this->_preroll = $this->_reader->getInt64LE();
$this->_flags = $this->_reader->getUInt32LE();
$this->_minimumDataPacketSize = $this->_reader->getUInt32LE();
$this->_maximumDataPacketSize = $this->_reader->getUInt32LE();
$this->_maximumBitrate = $this->_reader->getUInt32LE();
$this->_preroll = $this->_reader->readInt64LE();
$this->_flags = $this->_reader->readUInt32LE();
$this->_minimumDataPacketSize = $this->_reader->readUInt32LE();
$this->_maximumDataPacketSize = $this->_reader->readUInt32LE();
$this->_maximumBitrate = $this->_reader->readUInt32LE();
}
/**

View File

@@ -2,6 +2,9 @@
/**
* PHP Reader Library
*
* Copyright (c) 2006-2008 The PHP Reader Project Workgroup. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
@@ -10,7 +13,7 @@
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the BEHR Software Systems nor the names of its
* - Neither the name of the project workgroup nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
@@ -28,9 +31,8 @@
*
* @package php-reader
* @subpackage ASF
* @copyright Copyright (c) 2006, 2007 The Bearpaw Project Work Group
* @copyright Copyright (c) 2007, 2008 BEHR Software Systems
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @copyright Copyright (c) 2006-2008 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Id$
*/
@@ -45,10 +47,9 @@ require_once("Object.php");
*
* @package php-reader
* @subpackage ASF
* @author Sven Vollbehr <sven.vollbehr@behrss.eu>
* @copyright Copyright (c) 2006, 2007 The Bearpaw Project Work Group
* @copyright Copyright (c) 2007, 2008 BEHR Software Systems
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Sven Vollbehr <svollbehr@gmail.com>
* @copyright Copyright (c) 2006-2008 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Rev$
*/
final class ASF_HeaderObject extends ASF_Object
@@ -82,7 +83,7 @@ final class ASF_HeaderObject extends ASF_Object
parent::__construct($reader, $id, $size);
$this->_readerSOffset = $this->_reader->getOffset();
$this->_objectCount = $this->_reader->getUInt32LE();
$this->_objectCount = $this->_reader->readUInt32LE();
$this->_reader->skip(2);
$this->_readerCOffset = $this->_reader->getOffset();
}
@@ -119,8 +120,8 @@ final class ASF_HeaderObject extends ASF_Object
$object = false;
if ($this->hasChildObjects()) {
$this->_reader->setOffset($this->_readerCOffset);
$guid = $this->_reader->getGUID();
$size = $this->_reader->getInt64LE();
$guid = $this->_reader->readGUID();
$size = $this->_reader->readInt64LE();
$offset = $this->_reader->getOffset();
switch ($guid) {
/* ASF_Content_Description_Object */

View File

@@ -2,6 +2,9 @@
/**
* PHP Reader Library
*
* Copyright (c) 2006-2008 The PHP Reader Project Workgroup. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
@@ -10,7 +13,7 @@
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the BEHR Software Systems nor the names of its
* - Neither the name of the project workgroup nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
@@ -28,9 +31,8 @@
*
* @package php-reader
* @subpackage ASF
* @copyright Copyright (c) 2006, 2007 The Bearpaw Project Work Group
* @copyright Copyright (c) 2007, 2008 BEHR Software Systems
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @copyright Copyright (c) 2006-2008 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Id$
*/
@@ -39,10 +41,9 @@
*
* @package php-reader
* @subpackage ASF
* @author Sven Vollbehr <sven.vollbehr@behrss.eu>
* @copyright Copyright (c) 2006, 2007 The Bearpaw Project Work Group
* @copyright Copyright (c) 2007, 2008 BEHR Software Systems
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Sven Vollbehr <svollbehr@gmail.com>
* @copyright Copyright (c) 2006-2008 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Rev$
*/
class ASF_Object