Skip to content

Commit

Permalink
Added Support for Id3v1 Tag Reading and Started the Test Cases for it.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sid Highwind committed Oct 4, 2008
1 parent f52d0db commit c745802
Show file tree
Hide file tree
Showing 8 changed files with 532 additions and 36 deletions.
90 changes: 89 additions & 1 deletion library/Zend/Id3.php
Expand Up @@ -19,19 +19,107 @@ class Zend_Id3
*/
const FREAD_BUFFER_SIZE = 16384;

/**
* Name of the file
*
* @var string
*/
protected $_filename;

/**
* File Pointer
*
* @var resource
*/
protected $_filePointer;

/**
* id3 tag info
*
* @var array
*/
protected $_info = array();

/**
*
*/
function __construct()
{
// nothing yet
}

/**
*
* @param $filename string
*/
public function analyze($filename)
{
// Remote files not supported
if (preg_match('#^([a-z][a-z0-9+.-]+):(//)?(.*?@)?#i', $filename)) {
include_once 'Zend/Id3/Exception.php';
throw new Zend_Id3_Exception('Remote files are not supported');
}

$this->_filename = $filename;

// Open local file
if (false === ($this->_filePointer = @fopen($this->_filename, 'rb'))) {
include_once 'Zend/Id3/Exception.php';
throw new Zend_Id3_Exception('Could not open file "' . $filename . "'");
}

// Set filesize related parameters
$this->_info['filesize'] = filesize($filename);
$this->_info['avdataoffset'] = 0;
$this->_info['avdataend'] = $this->info['filesize'];


foreach(array('id3v1') as $tagName) {
switch($tagName) {
case 'id3v1':
include_once 'Zend/Id3/Adapter/Id3v1.php';
$tag = new Zend_Id3_Adapter_Id3v1($this);
$tag->analyze();
break;
}
}

fclose($this->_filePointer);


return $this->_info;
}

/**
* Gets the open file pointer
*
* @return resource
*/
public function getFilePointer()
{
return $this->_filePointer;
}

/**
* Gets the file info
*
* @return array
*/
public function getFileInfo()
{
return $this->_info;
}

/**
* Sets the file info
*
* @param array $info
* @return Zend_Id3
*/
public static function analize()
public function setFileInfo(array $info)
{
$this->_info = $info;

return $this;
}
}
16 changes: 0 additions & 16 deletions library/Zend/Id3/Adapater/Abstract.php

This file was deleted.

19 changes: 0 additions & 19 deletions library/Zend/Id3/Adapater/Id3v1.php

This file was deleted.

114 changes: 114 additions & 0 deletions library/Zend/Id3/Adapter/Abstract.php
@@ -0,0 +1,114 @@
<?php
/**
* Zend_Id3_Adapter_Abstract
*
* @uses
* @package Zend
* @category Id3
* @copyright Copyright (C) 2008 - Present, Jon Whitcraft
* @author Jon Whitcraft <jon.zf@mac.com>
* @license New BSD {@link http://www.opensource.org/licenses/bsd-license.php}
* @version $Id: $
*/
abstract class Zend_Id3_Adapter_Abstract
{
/**
* @var Zend_Id3
*/
protected $_id3;

/**
* analyzing filepointer or string
*
* @var boolean
*/
protected $_dataStringFlag = false;

/**
* string to analyze
*
* @var string
*/
protected $_dataString;

/**
* seek position in string
*
* @var integer
*/
protected $_dataStringPosition = 0;


/**
* Constructor
*
* @param $id3 Zend_Id3
*/
public function __construct(Zend_Id3 $id3)
{
$this->_id3 = $id3;
}

/**
* Analyze from the file pointer
* This is implemented from the extending class
*/
abstract public function analyze();

/**
* Returns the current position of the file read/write pointer
*
* @return integer
*/
protected function ftell() {

if ($this->_dataStringFlag) {
return $this->_dataStringPosition;
}
return ftell($this->_id3->getFilePointer());
}


/**
* Read up to the length of passed in bytes
*
* @param integer $bytes
* @return string
*/
protected function fread($bytes) {

if ($this->_dataStringFlag) {
$this->_dataStringPosition += $bytes;
return substr($this->_dataString, $this->_dataStringPosition - $bytes, $bytes);
}
return fread($this->_id3->getFilePointer(), $bytes);
}


/**
* Sets the file position indicator for the file
*
* @param integer $bytes
* @param integer $whence
* @return integer|null
*/
protected function fseek($bytes, $whence = SEEK_SET) {

if ($this->_dataStringFlag) {
switch ($whence) {
case SEEK_SET:
$this->_dataStringPosition = $bytes;
return;

case SEEK_CUR:
$this->_dataStringPosition += $bytes;
return;

case SEEK_END:
$this->_dataStringPosition = strlen($this->_dataString) + $bytes;
return;
}
}
return fseek($this->_id3->getFilePointer(), $bytes, $whence);
}
}
File renamed without changes.

0 comments on commit c745802

Please sign in to comment.