Add track and TRCK tags handler

This commit is contained in:
wapmorgan 2017-03-01 14:37:35 +03:00
parent ad2f95781e
commit bb70d36d2d
3 changed files with 17 additions and 8 deletions

View File

@ -16,8 +16,8 @@ This class extracts information from mpeg/mp3 audio:
| sampleRate | album | TALB |
| channel | year | TYER |
| framesCount | comment | COMM |
| codecVersion | genre | TCON |
| layerVersion | | |
| codecVersion | track | TRCK |
| layerVersion | genre | TCON |
1. Usage
2. Performance

View File

@ -27,7 +27,7 @@ function analyze($filename, &$total_duration, &$total_parse_time, $id3v2 = false
} catch (Exception $e) {
return null;
}
echo sprintf('%15s | %4s | %7s | %0.1fkHz | %-11s | %-10s | %.5f', substrIfLonger(basename($filename), 15), formatTime($audio->duration), $audio->isVbr ? 'vbr' : ($audio->bitRate / 1000).'kbps', ($audio->sampleRate / 1000), isset($audio->tags1['song']) ? substrIfLonger($audio->tags1['song'], 11) : null, isset($audio->tags1['artist']) ? substrIfLonger($audio->tags1['artist'], 10) : null, $audio->_parsingTime).PHP_EOL;
echo sprintf('%15s | %4s | %7s | %0.1fkHz | %-11s | %-10s | %5d | %.5f', substrIfLonger(basename($filename), 15), formatTime($audio->duration), $audio->isVbr ? 'vbr' : ($audio->bitRate / 1000).'kbps', ($audio->sampleRate / 1000), isset($audio->tags1['song']) ? substrIfLonger($audio->tags1['song'], 11) : null, isset($audio->tags1['artist']) ? substrIfLonger($audio->tags1['artist'], 10) : null, isset($audio->tags1['track']) ? substrIfLonger($audio->tags1['track'], 5) : null, $audio->_parsingTime).PHP_EOL;
if ($id3v2 && !empty($audio->tags2)) {
foreach ($audio->tags2 as $tag=>$value) {
echo ' '.$tag.': ';
@ -51,12 +51,12 @@ function analyzeId3($filename, &$total_parse_time) {
$t = microtime(true);
$info = $ID3->analyze($filename);
$parse_time = microtime(true) - $t;
echo sprintf('%15s | %4s | %7s | %0.1fkHz | %-11s | %-10s | %.5f', substrIfLonger(basename($filename), 15), $info['playtime_string'], $info['audio']['bitrate_mode'] == 'vbr' ? 'vbr' : floor($info['audio']['bitrate'] / 1000).'kbps', ($info['audio']['sample_rate'] / 1000), isset($info['tags']['title']) ? substrIfLonger($info['tags']['title'], 11) : null, isset($info['tags']['artist']) ? substrIfLonger($info['tags']['artist'], 10) : null, $parse_time).PHP_EOL;
echo sprintf('%15s | %4s | %7s | %0.1fkHz | %-11s | %-10s | %.5f | %5d', substrIfLonger(basename($filename), 15), $info['playtime_string'], $info['audio']['bitrate_mode'] == 'vbr' ? 'vbr' : floor($info['audio']['bitrate'] / 1000).'kbps', ($info['audio']['sample_rate'] / 1000), isset($info['tags']['title']) ? substrIfLonger($info['tags']['title'], 11) : null, isset($info['tags']['artist']) ? substrIfLonger($info['tags']['artist'], 10) : null, null, $parse_time).PHP_EOL;
$total_parse_time += $parse_time;
}
array_shift($argv);
echo sprintf('%15s | %4s | %7s | %7s | %11s | %10s | %4s', 'File name', 'dur.', 'bitrate', 'sample', 'song', 'artist',
echo sprintf('%15s | %4s | %7s | %7s | %11s | %10s | %5s | %4s', 'File name', 'dur.', 'bitrate', 'sample', 'song', 'artist', 'track',
'time').PHP_EOL;
$total_duration = $total_parse_time = $id3_parse_time = 0;
foreach ($argv as $arg) {

View File

@ -297,8 +297,10 @@ class Mp3Info {
$this->tags1['artist'] = trim(fread($fp, 30));
$this->tags1['album'] = trim(fread($fp, 30));
$this->tags1['year'] = trim(fread($fp, 4));
$this->tags1['comment'] = trim(fread($fp, 30));
$this->tags1['genre'] = hexdec(fread($fp, 1));
$this->tags1['comment'] = trim(fread($fp, 28));
fseek($fp, 1, SEEK_CUR);
$this->tags1['track'] = ord(fread($fp, 1));
$this->tags1['genre'] = ord(fread($fp, 1));
return 128;
}
@ -483,7 +485,14 @@ class Mp3Info {
// case 'TPE4': # Interpreted, remixed, or otherwise modified by
// case 'TPOS': # Part of a set
// case 'TPUB': # Publisher
// case 'TRCK': # Track number/Position in set
case 'TRCK': # Track number/Position in set
$raw = fread($fp, $frame_size);
$data = unpack("C1encoding/A".($frame_size - 1)."information", $raw);
if ((bool)($data['encoding'] == 0x00)) # ISO-8859-1
$this->tags2[$frame_id] = mb_convert_encoding($data['information'], 'utf-8', 'iso-8859-1');
else # utf-16
$this->tags2[$frame_id] = mb_convert_encoding($data['information'], 'utf-8', 'utf-16');
break;
// case 'TRDA': # Recording dates
// case 'TRSN': # Internet radio station name
// case 'TRSO': # Internet radio station owner