Add support for ID3v2 extension to ISO14496
git-svn-id: http://php-reader.googlecode.com/svn/trunk@86 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
@@ -59,26 +59,6 @@ require_once("ID3/Frame.php");
|
||||
* need not be known to the software that encounters them. Each frame has an
|
||||
* unique and predefined identifier which allows software to skip unknown
|
||||
* frames.
|
||||
*
|
||||
* Overall tag structure:
|
||||
*
|
||||
* <pre>
|
||||
* +-----------------------------+
|
||||
* | Header (10 bytes) |
|
||||
* +-----------------------------+
|
||||
* | Extended Header |
|
||||
* | (variable length, OPTIONAL) |
|
||||
* +-----------------------------+
|
||||
* | Frames (variable length) |
|
||||
* +-----------------------------+
|
||||
* | Padding |
|
||||
* | (variable length, OPTIONAL) |
|
||||
* +-----------------------------+
|
||||
* | Footer (10 bytes, OPTIONAL) |
|
||||
* +-----------------------------+
|
||||
* </pre>
|
||||
*
|
||||
* In general, padding and footer are mutually exclusive.
|
||||
*
|
||||
* @package php-reader
|
||||
* @subpackage ID3
|
||||
@@ -105,7 +85,7 @@ final class ID3v2
|
||||
private $_frames = array();
|
||||
|
||||
/** @var string */
|
||||
private $_filename;
|
||||
private $_filename = false;
|
||||
|
||||
/** @var Array */
|
||||
private $_options;
|
||||
@@ -118,11 +98,15 @@ final class ID3v2
|
||||
* 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.
|
||||
* o readonly -- Indicates that the tag is read from a temporary file or
|
||||
* another source it cannot be written back to. The tag can, however,
|
||||
* still be written to another file.
|
||||
*
|
||||
* @todo Only limited subset of flags are processed.
|
||||
* @todo Utilize the SEEK frame and search for a footer to find the tag
|
||||
* @todo Utilize the LINK frame to fetch frames from other sources
|
||||
* @param string $filename The path to the file.
|
||||
* @param string $filename The path to the file, file descriptor of an opened
|
||||
* file, or {@link Reader} instance.
|
||||
* @param Array $options The options array.
|
||||
*/
|
||||
public function __construct($filename = false, $options = array())
|
||||
@@ -133,11 +117,17 @@ final class ID3v2
|
||||
}
|
||||
|
||||
$this->_options = &$options;
|
||||
if (($this->_filename = $filename) === false ||
|
||||
file_exists($filename) === false) {
|
||||
if ($filename === false ||
|
||||
(is_string($filename) && file_exists($filename) === false) ||
|
||||
(is_resource($filename) && get_resource_type($filename) != "file")) {
|
||||
$this->_header = new ID3_Header(null, $options);
|
||||
} else {
|
||||
$this->_reader = new Reader($filename);
|
||||
if (is_string($filename) && !isset($options["readonly"]))
|
||||
$this->_filename = $filename;
|
||||
if ($filename instanceof Reader)
|
||||
$this->_reader = $filename;
|
||||
else
|
||||
$this->_reader = new Reader($filename);
|
||||
if ($this->_reader->readString8(3) != "ID3")
|
||||
throw new ID3_Exception
|
||||
("File does not contain ID3v2 tag: " . $filename);
|
||||
@@ -246,10 +236,7 @@ final class ID3v2
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function getFrames()
|
||||
{
|
||||
return $this->_frames;
|
||||
}
|
||||
public function getFrames() { return $this->_frames; }
|
||||
|
||||
/**
|
||||
* Returns an array of frames matching the given identifier or an empty array
|
||||
|
||||
93
src/ISO14496/Box/ID32.php
Normal file
93
src/ISO14496/Box/ID32.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Reader Library
|
||||
*
|
||||
* Copyright (c) 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:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - 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 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package php-reader
|
||||
* @subpackage ISO 14496
|
||||
* @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
|
||||
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**#@+ @ignore */
|
||||
require_once("ISO14496/Box/Full.php");
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* The <i>ID3v2 Box</i> resides under the {@link ISO14496_Box_META Meta Box} and
|
||||
* stores ID3 version 2 meta-data. There may be more than one ID3v2 Box present
|
||||
* each with a different language code.
|
||||
*
|
||||
* @package php-reader
|
||||
* @subpackage ISO 14496
|
||||
* @author Sven Vollbehr <svollbehr@gmail.com>
|
||||
* @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
|
||||
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
|
||||
* @version $Rev$
|
||||
*/
|
||||
final class ISO14496_Box_ID32 extends ISO14496_Box_Full
|
||||
{
|
||||
/** @var string */
|
||||
private $_language;
|
||||
|
||||
/** @var ID3v2 */
|
||||
private $_tag;
|
||||
|
||||
/**
|
||||
* Constructs the class with given parameters and reads box related data from
|
||||
* the ISO Base Media file.
|
||||
*
|
||||
* @param Reader $reader The reader object.
|
||||
*/
|
||||
public function __construct($reader)
|
||||
{
|
||||
parent::__construct($reader);
|
||||
|
||||
$this->_language =
|
||||
chr(((($tmp = $this->_reader->readUInt16BE()) >> 10) & 0x1f) + 0x60) .
|
||||
chr((($tmp >> 5) & 0x1f) + 0x60) . chr(($tmp & 0x1f) + 0x60);
|
||||
$this->_tag = new ID3v2($this->_reader, array("readonly" => true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the three byte language code to describe the language of this
|
||||
* media, according to {@link http://www.loc.gov/standards/iso639-2/
|
||||
* ISO 639-2/T}.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLanguage() { return $this->_language; }
|
||||
|
||||
/**
|
||||
* Returns the {@link ID3v2} tag class instance.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTag() { return $this->_tag; }
|
||||
}
|
||||
@@ -68,7 +68,9 @@ class Reader
|
||||
*/
|
||||
public function __construct($filename, $mode = "rb")
|
||||
{
|
||||
if (($this->_fd = fopen($filename, $mode)) === false)
|
||||
if (is_resource($filename) && get_resource_type($filename) == "file")
|
||||
$this->_fd = $filename;
|
||||
else if (($this->_fd = fopen($filename, $mode)) === false)
|
||||
throw new Reader_Exception("Unable to open file:" . $filename);
|
||||
|
||||
fseek($this->_fd, 0, SEEK_END);
|
||||
@@ -156,10 +158,7 @@ class Reader
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
return $this->_size;
|
||||
}
|
||||
public function getSize() { return $this->_size; }
|
||||
|
||||
/**
|
||||
* Magic function so that $obj->value will work.
|
||||
|
||||
Reference in New Issue
Block a user