cvs: pear /MP3_IDv2/IDv2 Frame.php Reader.php Tag.php Writer.php

From: Date: Tue, 10 Oct 2006 04:52:48 +0000
Subject: cvs: pear /MP3_IDv2/IDv2 Frame.php Reader.php Tag.php Writer.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-42472@lists.php.net to get a copy of this message
alexmerz Tue Oct 10 04:52:48 2006 UTC Modified files: /pear/MP3_IDv2/IDv2 Frame.php Reader.php Tag.php Writer.php Log: start to switch to LGPL and PHP 5 compliance

http://cvs.php.net/viewvc.cgi/pear/MP3_IDv2/IDv2/Frame.php?r1=1.1&r2=1.2&diff_format=u Index: pear/MP3_IDv2/IDv2/Frame.php diff -u pear/MP3_IDv2/IDv2/Frame.php:1.1 pear/MP3_IDv2/IDv2/Frame.php:1.2 --- pear/MP3_IDv2/IDv2/Frame.php:1.1 Fri Aug 26 10:46:51 2005 +++ pear/MP3_IDv2/IDv2/Frame.php Tue Oct 10 04:52:47 2006 @@ -2,20 +2,28 @@ /** * This file contains the implementation for the Idv2 frame data structure class * - * PHP versions 4 and 5 + * Copyright (C) 2006 Alexander Merz * - * LICENSE: This source file is subject to version 3.0 of the PHP license - * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of - * the PHP License and are unable to obtain it through the web, please - * send a note to license@php.net so we can mail you a copy immediately. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License. * - * @category File Formats + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category File Formats * @package MP3_IDv2 * @author Alexander Merz <alexander.merz@web.de> - * @copyright 2005 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Frame.php,v 1.1 2005/08/26 10:46:51 alexmerz Exp $ + * @copyright 2006 Alexander Merz + * @license http://www.gnu.org/licenses/lgpl.html + * @version CVS: $Id: Frame.php,v 1.2 2006/10/10 04:52:47 alexmerz Exp $ * @link http://pear.php.net/package/MP3_IDv2 * @since File available since Release 0.1 */ @@ -34,8 +42,7 @@ * @category File Formats * @package MP3_IDv2 * @author Alexander Merz <alexander.merz@web.de> - * @copyright 2005 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @copyright 2006 Alexander Merz * @version Release: @package_version@ * @link http://pear.php.net/package/MP3_IDv2 * @since Class available since Release 0.1.0 @@ -46,117 +53,143 @@ * the identifier of the frame (name of the frame) * @var string */ - var $_id = null; - + protected $_id = null; + /** * indicates that the content of the frame was changed - * + * * @var bool true if content was changed and must created again */ - var $_changed = false; + protected $_changed = false; + /** * the purpose of this frame * @var string */ - var $_purpose = null; - + protected $_purpose = null; + /** * the raw content of the tag * @var string */ - var $_content = null; - + protected $_content = null; + /** * flag to indicate to drop this frame or not while changing the tag if unknown - * + * * @var bool */ - var $_flagTagAlterPres=false; - + protected $_flagTagAlterPres=false; + /** * flag to indicate to drop this frame or not while changing the file if unknown - * + * * @var bool - */ - var $_flagFileAlterPres=false; - + */ + protected $_flagFileAlterPres=false; + /** * flag to indicate to that tis frame should nor be changed - * + * * @var bool - */ - var $_flagReadOnly=false; - + */ + protected $_flagReadOnly=false; + /** * flag to indicate that the frame content is compressed - * + * * @var bool - */ - var $_flagCompression=false; - + */ + protected $_flagCompression=false; + /** * flag to indicate that the frame has a group identifier - * + * * @var bool - */ - var $_flagGroup=false; - + */ + protected $_flagGroup=false; + /** * flag to indicate that the frame encrypted - * + * * @var bool - */ - var $_flagEncryption=false; - + */ + protected $_flagEncryption=false; + /** * size of the frame data after uncompression - * + * * @var int - */ - var $_decompressedSize=null; - + */ + protected $_decompressedSize=null; + /** * Identifier of the method used for encryption - * + * * @var string - */ - var $_encryptionMethod=null; - + */ + protected $_encryptionMethod=null; + /** * The identifier for the group - * + * * @var string - */ - var $_groupid=null; + */ + protected $_groupid=null; + + /** + * Singleton method the create a specific frame object. + * If a specific frame class does not exists, a Frame + * object is returned. + * + * @param String $frameId the frame type + * @return Object the specific frame object + * @access public + */ + public static function getInstance($frameId) { + $frameId = trim($frameId); + if($frameId != '') { + @require_once 'MP3/IDv2/Frame/'.$frameId; + $class = 'MP3_IDv2_Frame_'.$frameId; + if(class_exists($class)) { + $frame = new $class(); + } else { + $frame = new MP3_IDv2_Frame(); + } + } else { + $frame = new MP3_IDv2_Frame(); + } + return $frame; + } /** * Returns the purpose of the frame - * + * * @return string the frame purpose * @access public */ - function getPurpose() { + public function getPurpose() { return $this->_purpose; } /** * Sets the purpose text of the frame - * + * * @param string $purpose the frame purpose * @access public */ - function setPurpose($purpose) { + protected function setPurpose($purpose) { $this->_purpose = $purpose; } /** * Enables/disables the use of encryption for the frame data - * + * * @param bool $b true for enabling, false to disable * @access public */ - function useEncryption($b = true) { + public function useEncryption($b = true) { $this->_flagEncryption = $b; } @@ -166,7 +199,7 @@ * @return bool true if encryption is/should be used * @access public */ - function isEncrypted() { + public function isEncrypted() { return $this->_flagEncryption; } @@ -177,7 +210,7 @@ * @param bool $b true to use a group identifier * @access public */ - function useGroupingIdentifier($b = true) { + public function useGroupingIdentifier($b = true) { $this->_flagGroup = $b; } @@ -187,7 +220,7 @@ * @return bool true if should belongs to a group * @access public */ - function hasGroupingIdentifier() { + public function hasGroupingIdentifier() { return $this->_flagGroup; } @@ -197,7 +230,7 @@ * @param bool $b true if compression should be used * @access public */ - function useCompression($b = true) { + public function useCompression($b = true) { $this->_flagCompression = $b; } @@ -208,7 +241,7 @@ * @return bool true if compression is/should be used * @access public */ - function isCompressed() { + public function isCompressed() { return $this->_flagCompression; } @@ -219,7 +252,7 @@ * @see MP3_IDv2_Frame::useGroupingIdentifier() * @access public */ - function setGroupIdentifier($gid) { + public function setGroupIdentifier($gid) { $this->_groupid = $gid; $this->useGroupingIdentifier(); } @@ -231,7 +264,7 @@ * @see MP3_IDv2_Frame::useGroupingIdentifier() * @access public */ - function getGroupIdentifier() { + public function getGroupIdentifier() { return $this->_groupid; } @@ -242,7 +275,7 @@ * @see MP3_IDv2_Frame::useEncryption() * @access public */ - function setEncryptionMethod($m) { + public function setEncryptionMethod($m) { $this->_encryptionMethod = $m; } @@ -253,7 +286,7 @@ * @see MP3_IDv2_Frame::useGroupingIdentifier() * @access public */ - function getEncryptionMethod() { + public function getEncryptionMethod() { return $this->_encryptionMethod; } @@ -264,7 +297,7 @@ * @param string $id a four byte string for the name of the frame * @access public */ - function setId($id) { + protected function setId($id) { $this->_id = $id; } @@ -274,7 +307,7 @@ * @return string * @access public */ - function getId() { + public function getId() { return $this->_id; } @@ -284,7 +317,7 @@ * @param string $content the raw frame data without the header * @access public */ - function setRawContent($content) { + public function setRawContent($content) { $this->_changed = true; $this->_content = $content; } @@ -295,7 +328,7 @@ * @param bool $f true to set the tag * @access public */ - function setFlagTagAlterPres($f = true) { + public function setFlagTagAlterPres($f = true) { $this->flagTagAlterPres = $f; } @@ -305,7 +338,7 @@ * @param bool $f true to set the tag * @access public */ - function setFlagFileAlterPres($f = true) { + public function setFlagFileAlterPres($f = true) { $this->flagFileAlterPres = $f; } @@ -315,7 +348,7 @@ * @param bool $f true to set the tag * @access public */ - function setFlagReadOnly($f) { + public function setFlagReadOnly($f) { $this->_flagReadOnly = $f; } @@ -326,7 +359,7 @@ * @return bool true if flag is set * @access public */ - function isFlagTagAlterPres() { + public function isFlagTagAlterPres() { return $this->_flagTagAlterPres; } @@ -336,7 +369,7 @@ * @return bool true if flag is set * @access public */ - function isFlagFileAlterPres() { + public function isFlagFileAlterPres() { return $this->_flagFileAlterPres; } @@ -346,18 +379,18 @@ * @return bool true if flag is set * @access public */ - function isFlagReadOnly() { + public function isFlagReadOnly() { return $this->_flagReadOnly; } - + /** * Creates the header of the frame including the header extension * according to the frame settings. - * - * @return string the create header + * + * @return string the created header * @access public */ - function createHeader() { + public function createHeader() { $header = ''; $extheader = ''; $header = $header.$this->getId(); @@ -415,7 +448,7 @@ * @return string the content 'as is'description * @access public */ - function getRawContent() { + public function getRawContent() { if ($this->_changed) { $this->_content = $this->createContent(); $this->changed = false; @@ -431,7 +464,7 @@ * @return string the created content * @access public */ - function createContent() { + public function createContent() { return $this->_content; } @@ -441,19 +474,19 @@ * @return string * @access public */ - function createFrame() { + public function createFrame() { $header = $this->createHeader(); // TODO check for compression and encryption return $header.$this->getRawContent(); } - + /** * Returns the frame content as something printable - * - * @return string the frame content + * + * @return string the frame content * @access public */ - function toString() { + public function toString() { return $this->getID(); } } http://cvs.php.net/viewvc.cgi/pear/MP3_IDv2/IDv2/Reader.php?r1=1.1&r2=1.2&diff_format=u Index: pear/MP3_IDv2/IDv2/Reader.php diff -u pear/MP3_IDv2/IDv2/Reader.php:1.1 pear/MP3_IDv2/IDv2/Reader.php:1.2 --- pear/MP3_IDv2/IDv2/Reader.php:1.1 Fri Aug 26 10:46:51 2005 +++ pear/MP3_IDv2/IDv2/Reader.php Tue Oct 10 04:52:47 2006 @@ -2,20 +2,28 @@ /** * This file contains the implementation for the Idv2-Tag reader class * - * PHP versions 4 and 5 + * Copyright (C) 2006 Alexander Merz * - * LICENSE: This source file is subject to version 3.0 of the PHP license - * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of - * the PHP License and are unable to obtain it through the web, please - * send a note to license@php.net so we can mail you a copy immediately. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License. * - * @category File Formats + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category File Formats * @package MP3_IDv2 * @author Alexander Merz <alexander.merz@web.de> - * @copyright 2005 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Reader.php,v 1.1 2005/08/26 10:46:51 alexmerz Exp $ + * @copyright 2006 Alexander Merz + * @license http://www.gnu.org/licenses/lgpl.html + * @version CVS: $Id: Reader.php,v 1.2 2006/10/10 04:52:47 alexmerz Exp $ * @link http://pear.php.net/package/MP3_IDv2 * @since File available since Release 0.1 */ @@ -79,8 +87,7 @@ * @category File Formats * @package MP3_IDv2 * @author Alexander Merz <alexander.merz@web.de> - * @copyright 2005 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @copyright 2006 Alexander Merz * @version Release: @package_version@ * @link http://pear.php.net/package/MP3_IDv2 * @since Class available since Release 0.1.0 @@ -92,7 +99,7 @@ * @var array $_tags list of tags * @access private */ - var $_tags=array(); + private $_tags=array(); /** * Reads the first tag found in a tag. @@ -106,7 +113,7 @@ * @access public * @see getTag() */ - function read($filename) { + public function read($filename) { if (!file_exists($filename)) { return PEAR::raiseError( sprintf(PEAR_MP3_IDV2_FILENOTFOUND_S, $filename), @@ -255,7 +262,7 @@ * @return bool true, if a tag was found, false if not * @access private */ - function findHeader($fh) { + protected function findHeader($fh) { $i=0; $c=''; while (!feof($fh)) { @@ -271,16 +278,16 @@ } return false; } - + /** * Returns the tag found in the file - * + * * @return object MP3_IDv2_Tag the tag data structure * @access public */ - function getTag() { + public function getTag() { return $this->_tags[0]; - } + } } ?> http://cvs.php.net/viewvc.cgi/pear/MP3_IDv2/IDv2/Tag.php?r1=1.1&r2=1.2&diff_format=u Index: pear/MP3_IDv2/IDv2/Tag.php diff -u pear/MP3_IDv2/IDv2/Tag.php:1.1 pear/MP3_IDv2/IDv2/Tag.php:1.2 --- pear/MP3_IDv2/IDv2/Tag.php:1.1 Fri Aug 26 10:46:51 2005 +++ pear/MP3_IDv2/IDv2/Tag.php Tue Oct 10 04:52:47 2006 @@ -1,21 +1,29 @@ <?php /** * This file contains the implementation for the Idv2 tag data structure class - * - * PHP versions 4 and 5 * - * LICENSE: This source file is subject to version 3.0 of the PHP license - * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of - * the PHP License and are unable to obtain it through the web, please - * send a note to license@php.net so we can mail you a copy immediately. + * Copyright (C) 2006 Alexander Merz * - * @category File Formats + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category File Formats * @package MP3_IDv2 * @author Alexander Merz <alexander.merz@web.de> - * @copyright 2005 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Tag.php,v 1.1 2005/08/26 10:46:51 alexmerz Exp $ + * @copyright 2006 Alexander Merz + * @license http://www.gnu.org/licenses/lgpl.html + * @version CVS: $Id: Tag.php,v 1.2 2006/10/10 04:52:47 alexmerz Exp $ * @link http://pear.php.net/package/MP3_IDv2 * @since File available since Release 0.1 */ @@ -42,216 +50,216 @@ * @category File Formats * @package MP3_IDv2 * @author Alexander Merz <alexander.merz@web.de> - * @copyright 2005 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @copyright 2006 Alexander Merz * @version Release: @package_version@ * @link http://pear.php.net/package/MP3_IDv2 * @since Class available since Release 0.1.0 - */ + */ class MP3_IDv2_Tag { - + /** * the size of the whole tag excluding the header * @var int */ - var $_size = null; + protected $_size = null; + /** * holds the major version number of the tag * @var int */ - var $_maxVersion = 3; + protected $_maxVersion = 3; /** * holds the minor version number of the tag * @var int - */ - var $_minVersion = 0; - + */ + protected $_minVersion = 0; + /** * holds the flag for unsynchonized tag data * (everything excluding the tag header) * @var bool - */ - var $_unsynchronisation = false; - + */ + protected $_unsynchronisation = false; + /** * holds the flag for that the tag has an extended header * @var bool */ - var $_extendedHeader = false; - + protected $_extendedHeader = false; + /** * holds the flag for an experimental flag * @var bool - */ - var $_experimental = false; - + */ + protected $_experimental = false; + /** * holds the CRC size of the tag data * @var int - */ - var $_extCRC = null; - + */ + protected $_extCRC = null; + /** * holds the list of frame of the tag - * + * * @see MP3_IDv2_Frame * @var array a list of MP3_IDv2_Frame objects */ - var $_frames = array(); - + protected $_frames = array(); + /** * holds the flag for CRC in the extended header * @var bool - */ - var $_useCRC = false; + */ + protected $_useCRC = false; /** * Sets the version of the tag. - * Actually unused for processing. - * + * Actually unused for processing. + * * @param int $max major version of the tag - * @param int $min minor version - * @access public - */ - function setVersion($max, $min) { - + * @param int $min minor version + * @access public + */ + public function setVersion($max, $min) { + $this->_minVersion = $min; - $this->_maxVersion = $max; + $this->_maxVersion = $max; } /** - * Returns the version used for building the tag. - * - * @return string the Version as "max.min - * @access public - */ - function getVersion() { + * Returns the version used for building the tag. + * + * @return string the Version as "max.min + * @access public + */ + public function getVersion() { return $this->_maxVersion.".".$this->_minVersion; - } + } /** - * Sets the size of the tag data. - * - * @param int $size the tag data size including the extended header - * @access public - */ - function setSize($size) { + * Sets the size of the tag data. + * + * @param int $size the tag data size including the extended header + * @access public + */ + protected function setSize($size) { $this->_size = $size; } /** - * Returns the size of the tag data. - * - * @return int the size of the tag data excluding the header and extended header - * @access public - */ - function getSize() { + * Returns the size of the tag data. + * + * @return int the size of the tag data excluding the header and extended header + * @access public + */ + public function getSize() { if (null == $this->_size) { $size=0; foreach ($this->_frames as $frame) { - $size = $size + $frame->getSize(); + $size = $size + $frame->getSize(); } $this->_size = $size; } return $this->_size; - } - + } + /** - * Enables/disable the unsychonisation of the tag data - * - * @param bool true for enabling the unsychronisation, false for disabling - * @access public - */ - function setUnsynchronisation($b) { + * Enables/disable the unsychonisation of the tag data + * + * @param bool true for enabling the unsychronisation, false for disabling + * @access public + */ + protected function setUnsynchronisation($b) { $this->_unsynchronisation = $b; } - + /** * Returns ift the tag data is unsychonized or should be - * + * * @return bool true is unsychronisation is activ * @access public */ - function isUnsynchronisation() { + public function isUnsynchronisation() { return $this->_unsynchronisation; - } + } /** * Enables/diables the usage of an extended tag header - * + * * @param bool $b true for enable, false for disable * @access public - */ - function setExtendedHeader($b) { + */ + protected function setExtendedHeader($b) { $this->_extendedHeader = $b; } - + /** * Checks if tag has an extended header or should create one - * + * * @return bool true if has one/create one * @access public - */ - function isExtendedHeader() { + */ + public function isExtendedHeader() { return $this->_extendedHeader; } - + /** * Marks this tag as experimental * (This has no effect on tag handling currently) - * + * * @param bool $b true to mark, false to demark * @access public - */ - function setExperimental($b) { + */ + public function setExperimental($b) { $this->_experimental = $b; } /** * Checks if the tag is an experimental tag - * + * * @return bool true if tag is experimental * @access public - */ - function isExperimental() { + */ + public function isExperimental() { return $this->_experimental; } /** * Enables or disables the usage of a CRC * in the tag - * + * * @param bool $b false for disable * @access public */ - function useCRC($b = true) { + public function useCRC($b = true) { $this->_useCRC = $b; } /** * Returns the CRC-32 checksum over the tag date - * + * * @return int the CRC-32 checksum * @access public - */ - function getCRC() { + */ + public function getCRC() { return $this->_extCRC; } - + /** * Creates the tag header depending on the tag settings - * + * * @return string the tag header * @access public - */ - function createHeader() { + */ + public function createHeader() { // TODO check for max size! $header = ''; // set ID $header = $header."ID3"; // set Version - $header = $header.pack("cc", $this->_maxVersion, $this->_minVersion); + $header = $header.pack("cc", $this->_maxVersion, $this->_minVersion); // set flags // TODO use numbers $f=bindec('00000000'); @@ -266,41 +274,41 @@ } $header = $header.pack("c", $f); - // set Size - $size = $this->sync8to7($this->getSize()); + // set Size + $size = $this->sync8to7($this->getSize()); $sb = str_pad(decbin($size), 32, '0', STR_PAD_LEFT); $sa = array(); for ($i=3; $i>=0; $i--) { $sa[$i] = bindec(substr($sb, $i*8, 8)); - } + } $header = $header.pack("cccc", $sa[0],$sa[1],$sa[2],$sa[3]); if ($this->isExtendedHeader()) { $header = $header.$this->createExtendedHeader(); } - return $header; + return $header; } - + /** * Creates the extended header of the tag depending on the tag settings. * This function does not check if the extended header flag is set! - * + * * @return string the extended header of the tag * @access public - */ - function createExtendedHeader() { + */ + public function createExtendedHeader() { $extheader = ''; $exthcontent = ''; // set flags $f = bindec('00000000'); - if ($this->_useCRC) { + if ($this->_useCRC) { $f = $f | bindec('10000000'); $sb = str_pad(decbin($this->_extCRC), 32, '0', STR_PAD_LEFT); $sa = array(); for ($i=3; $i>=0; $i--) { - $sa[$i] = bindec(substr($sb, $i*8, 8)); - } + $sa[$i] = bindec(substr($sb, $i*8, 8)); + } $exthcontent = $exthcontent.pack("cccc", $sa[0],$sa[1],$sa[2],$sa[3]); - } + } $flag = pack('cc', $f, 0); // set padding - is 0, we set no padding $padd = "\0\0\0\0"; @@ -309,52 +317,52 @@ $sa = array(); for ($i=3; $i>=0; $i--) { $sa[$i] = bindec(substr($sb, $i*8, 8)); - } + } $size = pack("cccc", $sa[0],$sa[1],$sa[2],$sa[3]); - return $size.$flag.$padd.$exthcontent; + return $size.$flag.$padd.$exthcontent; } - - + + /** - * Does the unsynchronisation for the tag size in the header - * + * Does the unsynchronisation for the tag size in the header + * * @param int the size of the tag data+extended header * @return int the unsych size * @access private - */ - function sync8to7($s) { + */ + public function sync8to7($s) { $sb = str_pad(decbin($s), 32, '0', STR_PAD_LEFT); $sa = array(); for ($i=3; $i>=0; $i--){ $sa[$i] = str_pad(substr($sb, $i*8+4-$i, 7), 8, '0', STR_PAD_LEFT); - - } + + } $s = $sa[0].$sa[1].$sa[2].$sa[3]; - + return bindec($s); } - + /** * Adds a frame to the tag - * + * * @param object MP3_IDv2_Frame the frame to add * @access public */ - function addFrame($frame) { + public function addFrame($frame) { $this->_frames[] = $frame; } - + /** * Creates the whole tag depending on the tag settings. * This includes also the creation of the frames. So you * really get the whole tag. - * + * * @return string the tag */ - function createTag() { + public function createTag() { $content = ''; foreach ($this->_frames as $frame) { - $content = $content.$frame->createFrame(); + $content = $content.$frame->createFrame(); } if ($this->_useCRC) { $this->_extCRC = crc32($content); @@ -367,34 +375,34 @@ /* $content = str_replace($ff.$nn, $ff, $content); $this->setUnsynchronisation(true); - */ + */ } strlen($content); - $this->setSize(strlen($content)); + $this->setSize(strlen($content)); $header = $this->createHeader(); return $header.$content; } - - + + /** * Returns the frames of the tag. - * + * * @return array the list of MP3_IDv2_Frame objects * @access public */ - function getFrames() { + public function getFrames() { return $this->_frames; } - + /** * Returns all frames identified by their identifiers of the tag. - * + * * @param string $id the identifer of the frames to catch * @return array the list of founded frames as MP3_IDv2_Frame objects * @see MP3_IDv2_Tag::getFrameById() * @access public */ - function getFramesById($id) { + public function getFramesById($id) { $ret = array(); foreach ($this->_frames as $frame) { if ($id == $frame->getId()) { @@ -403,22 +411,22 @@ } return $ret; } - + /** * Returns only the first frame with the given id in the tag - * + * * @param string $id the identifer of the frame to catch * @return object MP3_IDv2_Frame the founded frame or null if not found * @see MP3_IDv2_Tag::getFramesById(); * @access public */ - function getFrameById($id) { + public function getFrameById($id) { foreach ($this->_frames as $frame) { if ($id == $frame->getId()) { return $frame; } } - return null; + return null; } } http://cvs.php.net/viewvc.cgi/pear/MP3_IDv2/IDv2/Writer.php?r1=1.1&r2=1.2&diff_format=u Index: pear/MP3_IDv2/IDv2/Writer.php diff -u pear/MP3_IDv2/IDv2/Writer.php:1.1 pear/MP3_IDv2/IDv2/Writer.php:1.2 --- pear/MP3_IDv2/IDv2/Writer.php:1.1 Fri Aug 26 10:46:51 2005 +++ pear/MP3_IDv2/IDv2/Writer.php Tue Oct 10 04:52:47 2006 @@ -2,20 +2,28 @@ /** * This file contains the implementation for the Idv2-Tag writer class * - * PHP versions 4 and 5 + * Copyright (C) 2006 Alexander Merz * - * LICENSE: This source file is subject to version 3.0 of the PHP license - * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of - * the PHP License and are unable to obtain it through the web, please - * send a note to license@php.net so we can mail you a copy immediately. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License. * - * @category File Formats + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category File Formats * @package MP3_IDv2 * @author Alexander Merz <alexander.merz@web.de> - * @copyright 2005 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Writer.php,v 1.1 2005/08/26 10:46:51 alexmerz Exp $ + * @copyright 2006 Alexander Merz + * @license http://www.gnu.org/licenses/lgpl.html + * @version CVS: $Id: Writer.php,v 1.2 2006/10/10 04:52:47 alexmerz Exp $ * @link http://pear.php.net/package/MP3_IDv2 * @since File available since Release 0.1 */ @@ -73,88 +81,87 @@ * @category File Formats * @package MP3_IDv2 * @author Alexander Merz <alexander.merz@web.de> - * @copyright 2005 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @copyright 2006 Alexander Merz * @version Release: @package_version@ * @link http://pear.php.net/package/MP3_IDv2 * @since Class available since Release 0.1.0 - */ + */ class MP3_IDv2_Writer { - + /** * Stores the tags to write. * @var array $_tags list of tags - * @access private + * @access private */ - var $_tags = array(); - + protected $_tags = array(); + /** * Add a IDv2 tag tag to write to a file. - * + * * @param object MP3_IDv2_Tag $tag tag to add * @access public */ - function addTag($tag) { + public function addTag($tag) { $this->tags[] = $tag; } - + /** * Writes the provided tags to a file. - * - * The tags are written to a temporary file + * + * The tags are written to a temporary file * first and then renamed to the given * filename. - * + * * @param string $filename * @return bool true if writing was successful - * @throws PEAR_MP3_IDV2_FILENOCOPY, PEAR_MP3_IDV2_FILENOWRITE + * @throws PEAR_MP3_IDV2_FILENOCOPY, PEAR_MP3_IDV2_FILENOWRITE * @access public - */ - function write($filename) { + */ + public function write($filename) { $content = ''; if (file_exists($filename)) { $fr = fopen($filename, "rb"); // do not write old tags into file $this->jumpOverTag($fr); - + while (!feof($fr)) { // MP3 files are normally big $content = $content.fread($fr, 256000); - } - fclose($fr); - } + } + fclose($fr); + } - $fh = fopen($filename."_", "wb"); if (!$fh) { return PEAR::raiseError( sprintf(PEAR_MP3_IDV2_FILENOWRITE_S,$filename), - PEAR_MP3_IDV2_FILENOWRITE); + PEAR_MP3_IDV2_FILENOWRITE); } foreach($this->tags as $tag) { // TODO check for return values! fwrite($fh, $tag->createTag()); - fwrite($fh, $content); + fwrite($fh, $content); } fclose($fh); if (copy($filename."_", $filename)) { return PEAR::raiseError( sprintf(PEAR_MP3_IDV2_FILENOCOPY_S,$filename), PEAR_MP3_IDV2_FILENOCOPY); - } + } return true; } - + /** * Looks for the IDv2-tag in a stream and moves the the filepointer * after the tag, if a tag could be found. - * + * * @param int $fh the file handle - * @return bool true if tag was found, false if no tag was found + * @return bool true if tag was found, false if no tag was found * @access private - */ - function jumpOverTag($fh) { + */ + public function jumpOverTag($fh) { if (MP3_IDv2_Reader::findHeader($fh)) { fseek($fh,3, SEEK_CUR); - $sa=unpack('C4size', fread($fh, 4)); + $sa=unpack('C4size', fread($fh, 4)); $sb = substr(str_pad(decbin($sa['size1']),8, '0',STR_PAD_LEFT),1,7) . substr(str_pad(decbin($sa['size2']),8, '0',STR_PAD_LEFT),1,7) . substr(str_pad(decbin($sa['size3']),8, '0',STR_PAD_LEFT),1,7) .
« previous php.pear.cvs (#42472) next »