Page MenuHomePhabricator
Paste P8769

getid3
ActivePublic

Authored by Daimona on Jul 17 2019, 10:03 PM.
Tags
None
Referenced Files
F29794532: raw.txt
Jul 17 2019, 10:11 PM
F29794395: raw.txt
Jul 17 2019, 10:03 PM
Subscribers
None
<?php
class getID3
{
/**
* Result array.
*
* @var array
*/
public $info;
/**
* analyze file
*
* @param string $filename
* @param int $filesize
* @param string $original_filename
*
* @return array
*/
public function analyze($filename, $filesize=null, $original_filename='', $fp=null) {
$this->HandleAllTags();
$this->getHashdata('sha1');
}
/**
* Error handling.
*
* @param string $message
*
* @return array
*/
public function error($message) {
$this->CleanUp();
if (!isset($this->info['error'])) {
$this->info['error'] = array();
}
$this->info['error'][] = $message;
return $this->info;
}
/**
* Warning handling.
*
* @param string $message
*
* @return bool
*/
public function warning($message) {
$this->info['warning'][] = $message;
return true;
}
/**
* Converts array to $encoding charset from $this->encoding.
*
* @param array $array
* @param string $encoding
*/
public function CharConvert(&$array, $encoding) {
}
/**
* @return bool
*/
public function HandleAllTags() {
// loop through comments array
foreach ($tags as $comment_name => $tagname_encoding_array) {
// copy comments if key name set
if (!empty($this->info[$comment_name]['comments'])) {
foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) {
foreach ($valuearray as $key => $value) {
if (is_string($value)) {
$value = trim($value, " \r\n\t"); // do not trim nulls from $value!! Unicode characters will get mangled if trailing nulls are removed!
}
if ($value) {
if (!is_numeric($key)) {
$this->info['tags'][trim($tag_name)][trim($tag_key)][$key] = $value;
} else {
$this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value;
}
}
}
}
$this->CharConvert($this->info['tags'][$tag_name], $this->info[$comment_name]['encoding']); // only copy gets converted!
}
}
return true;
}
/**
* @param string $algorithm
*
* @return array|bool
*/
public function getHashdata($algorithm) {
if (!empty($this->info['fileformat']) && !empty($this->info['dataformat']) && ($this->info['fileformat'] == 'ogg') && ($this->info['audio']['dataformat'] == 'vorbis')) {
$commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1';
$VorbisCommentError = `$commandline`;
$this->warning('Failed making system call to vorbiscomment(.exe) - '.$algorithm.'_data will be incorrect. If vorbiscomment is unavailable, please download from http://www.vorbis.com/download.psp and put in the getID3() directory. Error returned: '.$VorbisCommentError);
} else {
if (!empty($this->info['avdataoffset']) || (isset($this->info['avdataend']) && ($this->info['avdataend'] < $this->info['filesize']))) {
// get hash from part of file
$this->info[$algorithm.'_data'] = getid3_lib::hash_data($this->info['filenamepath'], $this->info['avdataoffset'], $this->info['avdataend'], $algorithm);
} else {
// get hash from whole file
switch ($algorithm) {
case 'md5':
$this->info[$algorithm.'_data'] = md5_file($this->info['filenamepath']);
break;
case 'sha1':
$this->info[$algorithm.'_data'] = sha1_file($this->info['filenamepath']);
break;
}
}
}
return true;
}
public function ChannelsBitratePlaytimeCalculations() {
if (isset($this->info['bitrate']) && empty($this->info['audio']['bitrate']) && empty($this->info['video']['bitrate'])) {
if (isset($this->info['audio']['dataformat']) && empty($this->info['video']['resolution_x'])) {
// audio only
$this->info['audio']['bitrate'] = $this->info['bitrate'];
} elseif (isset($this->info['video']['resolution_x']) && empty($this->info['audio']['dataformat'])) {
// video only
$this->info['video']['bitrate'] = $this->info['bitrate'];
}
}
}
/**
* @return bool
*/
public function ProcessAudioStreams() {
if (!empty($this->info['audio']['bitrate']) || !empty($this->info['audio']['channels']) || !empty($this->info['audio']['sample_rate'])) {
if (!isset($this->info['audio']['streams'])) {
foreach ($this->info['audio'] as $key => $value) {
if ($key != 'streams') {
$this->info['audio']['streams'][0][$key] = $value;
}
}
}
}
return true;
}
}