Add support to $filename being an instance of an existing Reader. Constructor now throws exceptions.
git-svn-id: http://php-reader.googlecode.com/svn/trunk@103 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
@@ -47,6 +47,7 @@ require_once("ID3/Exception.php");
|
|||||||
* @package php-reader
|
* @package php-reader
|
||||||
* @subpackage ID3
|
* @subpackage ID3
|
||||||
* @author Sven Vollbehr <svollbehr@gmail.com>
|
* @author Sven Vollbehr <svollbehr@gmail.com>
|
||||||
|
* @author Ryan Butterfield <buttza@gmail.com>
|
||||||
* @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
|
* @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
|
||||||
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
|
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
|
||||||
* @version $Rev$
|
* @version $Rev$
|
||||||
@@ -118,17 +119,20 @@ final class ID3v1
|
|||||||
*/
|
*/
|
||||||
public function __construct($filename = false)
|
public function __construct($filename = false)
|
||||||
{
|
{
|
||||||
if (($this->_filename = $filename) === false ||
|
if (($this->_filename = $filename) !== false &&
|
||||||
file_exists($filename) === false)
|
file_exists($filename) !== false)
|
||||||
|
$this->_reader = new Reader($filename);
|
||||||
|
else if ($filename instanceof Reader)
|
||||||
|
$this->_reader = &$filename;
|
||||||
|
else
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$this->_reader = new Reader($filename);
|
|
||||||
if ($this->_reader->getSize() < 128)
|
if ($this->_reader->getSize() < 128)
|
||||||
return;
|
throw new ID3_Exception("File does not contain ID3v1 tag");
|
||||||
$this->_reader->setOffset(-128);
|
$this->_reader->setOffset(-128);
|
||||||
if ($this->_reader->read(3) != "TAG") {
|
if ($this->_reader->read(3) != "TAG") {
|
||||||
$this->_reader = false; // reset reader, see write
|
$this->_reader = false; // reset reader, see write
|
||||||
return;
|
throw new ID3_Exception("File does not contain ID3v1 tag");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_title = rtrim($this->_reader->readString8(30), " \0");
|
$this->_title = rtrim($this->_reader->readString8(30), " \0");
|
||||||
|
|||||||
Reference in New Issue
Block a user