MusicScanner/src/Sikofitt/HathorBundle/Common/Music/ID3.php

141 lines
2.6 KiB
PHP

<?php
/*
*
*/
namespace Sikofitt\HathorBundle\Common\Music;
use Symfony\Component\VarDumper\VarDumper;
class ID3 extends \getID3
{
private $fileData;
protected $file;
const IS_ASF = 0;
const IS_ID3V1 = 1;
const IS_ID3V2 = 2;
const IS_VORBIS = 3;
const IS_UNKNOWN = 4;
public function __construct($file = null)
{
parent::__construct();
if (!is_null($file)) {
$this->file = $file;
}
}
public function setFile($file)
{
$this->file = $file;
return $this;
}
/**
* @return null
*/
public function getFile()
{
return $this->file ?: $this->file;
}
public function getFileData()
{
$this->fileData = $this->analyze($this->getFile());
if (isset($this->fileData['error'])) {
throw new \RuntimeException(implode(' ', $this->fileData['error']));
} else {
return $this;
}
}
public function extractV2()
{
return [
];
}
public function extractV1()
{
}
public function extractAsf()
{
}
public function extractVorbis()
{
}
public function extractDefaultData()
{
switch ($this->typeOfTag()) {
case $this::IS_ID3V2:
break;
case $this::IS_ID3V1:
break;
case $this::IS_VORBIS:
break;
case $this::IS_ASF:
break;
case $this::IS_UNKNOWN:
break;
default:
break;
}
}
public function typeOfTag()
{
if ($this->hasId3v2()) {
return $this::IS_ID3V2;
} elseif ($this->hasId3v1()) {
return $this::IS_ID3V1;
} elseif ($this->isAsf()) {
return $this::IS_ASF;
} else {
return $this::IS_UNKNOWN;
}
}
/**
* @return bool
*/
public function hasId3v2()
{
return isset($this->fileData['id3v2']);
}
/**
* @return bool
*/
public function hasId3v1()
{
return isset($this->fileData['id3v1']);
}
/**
* @return bool
*/
public function isAsf()
{
return isset($this->fileData['asf']);
}
/**
* @return null
*/
public function dumpAll()
{
if (isset($this->fileData)) {
unset($this->fileData['tags']);
unset($this->fileData['asf']);
VarDumper::dump($this->fileData);
} else {
return null;
}
}
}