Edit File by line
/home/zeestwma/ajeebong.../wp-inclu.../ID3
File: module.audio.flac.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/////////////////////////////////////////////////////////////////
[2] Fix | Delete
/// getID3() by James Heinrich <info@getid3.org> //
[3] Fix | Delete
// available at https://github.com/JamesHeinrich/getID3 //
[4] Fix | Delete
// or https://www.getid3.org //
[5] Fix | Delete
// or http://getid3.sourceforge.net //
[6] Fix | Delete
// see readme.txt for more details //
[7] Fix | Delete
/////////////////////////////////////////////////////////////////
[8] Fix | Delete
// //
[9] Fix | Delete
// module.audio.flac.php //
[10] Fix | Delete
// module for analyzing FLAC and OggFLAC audio files //
[11] Fix | Delete
// dependencies: module.audio.ogg.php //
[12] Fix | Delete
// ///
[13] Fix | Delete
/////////////////////////////////////////////////////////////////
[14] Fix | Delete
[15] Fix | Delete
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
[16] Fix | Delete
exit;
[17] Fix | Delete
}
[18] Fix | Delete
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, true);
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* @tutorial http://flac.sourceforge.net/format.html
[22] Fix | Delete
*/
[23] Fix | Delete
class getid3_flac extends getid3_handler
[24] Fix | Delete
{
[25] Fix | Delete
const syncword = 'fLaC';
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* @return bool
[29] Fix | Delete
*/
[30] Fix | Delete
public function Analyze() {
[31] Fix | Delete
$info = &$this->getid3->info;
[32] Fix | Delete
[33] Fix | Delete
$this->fseek($info['avdataoffset']);
[34] Fix | Delete
$StreamMarker = $this->fread(4);
[35] Fix | Delete
if ($StreamMarker != self::syncword) {
[36] Fix | Delete
return $this->error('Expecting "'.getid3_lib::PrintHexBytes(self::syncword).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($StreamMarker).'"');
[37] Fix | Delete
}
[38] Fix | Delete
$info['fileformat'] = 'flac';
[39] Fix | Delete
$info['audio']['dataformat'] = 'flac';
[40] Fix | Delete
$info['audio']['bitrate_mode'] = 'vbr';
[41] Fix | Delete
$info['audio']['lossless'] = true;
[42] Fix | Delete
[43] Fix | Delete
// parse flac container
[44] Fix | Delete
return $this->parseMETAdata();
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* @return bool
[49] Fix | Delete
*/
[50] Fix | Delete
public function parseMETAdata() {
[51] Fix | Delete
$info = &$this->getid3->info;
[52] Fix | Delete
do {
[53] Fix | Delete
$BlockOffset = $this->ftell();
[54] Fix | Delete
$BlockHeader = $this->fread(4);
[55] Fix | Delete
$LBFBT = getid3_lib::BigEndian2Int(substr($BlockHeader, 0, 1)); // LBFBT = LastBlockFlag + BlockType
[56] Fix | Delete
$LastBlockFlag = (bool) ($LBFBT & 0x80);
[57] Fix | Delete
$BlockType = ($LBFBT & 0x7F);
[58] Fix | Delete
$BlockLength = getid3_lib::BigEndian2Int(substr($BlockHeader, 1, 3));
[59] Fix | Delete
$BlockTypeText = self::metaBlockTypeLookup($BlockType);
[60] Fix | Delete
[61] Fix | Delete
if (($BlockOffset + 4 + $BlockLength) > $info['avdataend']) {
[62] Fix | Delete
$this->warning('METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockTypeText.') at offset '.$BlockOffset.' extends beyond end of file');
[63] Fix | Delete
break;
[64] Fix | Delete
}
[65] Fix | Delete
if ($BlockLength < 1) {
[66] Fix | Delete
if ($BlockTypeText != 'reserved') {
[67] Fix | Delete
// probably supposed to be zero-length
[68] Fix | Delete
$this->warning('METADATA_BLOCK_HEADER.BLOCK_LENGTH ('.$BlockTypeText.') at offset '.$BlockOffset.' is zero bytes');
[69] Fix | Delete
continue;
[70] Fix | Delete
}
[71] Fix | Delete
$this->error('METADATA_BLOCK_HEADER.BLOCK_LENGTH ('.$BlockLength.') at offset '.$BlockOffset.' is invalid');
[72] Fix | Delete
break;
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
$info['flac'][$BlockTypeText]['raw'] = array();
[76] Fix | Delete
$BlockTypeText_raw = &$info['flac'][$BlockTypeText]['raw'];
[77] Fix | Delete
[78] Fix | Delete
$BlockTypeText_raw['offset'] = $BlockOffset;
[79] Fix | Delete
$BlockTypeText_raw['last_meta_block'] = $LastBlockFlag;
[80] Fix | Delete
$BlockTypeText_raw['block_type'] = $BlockType;
[81] Fix | Delete
$BlockTypeText_raw['block_type_text'] = $BlockTypeText;
[82] Fix | Delete
$BlockTypeText_raw['block_length'] = $BlockLength;
[83] Fix | Delete
if ($BlockTypeText_raw['block_type'] != 0x06) { // do not read attachment data automatically
[84] Fix | Delete
$BlockTypeText_raw['block_data'] = $this->fread($BlockLength);
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
switch ($BlockTypeText) {
[88] Fix | Delete
case 'STREAMINFO': // 0x00
[89] Fix | Delete
if (!$this->parseSTREAMINFO($BlockTypeText_raw['block_data'])) {
[90] Fix | Delete
return false;
[91] Fix | Delete
}
[92] Fix | Delete
break;
[93] Fix | Delete
[94] Fix | Delete
case 'PADDING': // 0x01
[95] Fix | Delete
unset($info['flac']['PADDING']); // ignore
[96] Fix | Delete
break;
[97] Fix | Delete
[98] Fix | Delete
case 'APPLICATION': // 0x02
[99] Fix | Delete
if (!$this->parseAPPLICATION($BlockTypeText_raw['block_data'])) {
[100] Fix | Delete
return false;
[101] Fix | Delete
}
[102] Fix | Delete
break;
[103] Fix | Delete
[104] Fix | Delete
case 'SEEKTABLE': // 0x03
[105] Fix | Delete
if (!$this->parseSEEKTABLE($BlockTypeText_raw['block_data'])) {
[106] Fix | Delete
return false;
[107] Fix | Delete
}
[108] Fix | Delete
break;
[109] Fix | Delete
[110] Fix | Delete
case 'VORBIS_COMMENT': // 0x04
[111] Fix | Delete
if (!$this->parseVORBIS_COMMENT($BlockTypeText_raw['block_data'])) {
[112] Fix | Delete
return false;
[113] Fix | Delete
}
[114] Fix | Delete
break;
[115] Fix | Delete
[116] Fix | Delete
case 'CUESHEET': // 0x05
[117] Fix | Delete
if (!$this->parseCUESHEET($BlockTypeText_raw['block_data'])) {
[118] Fix | Delete
return false;
[119] Fix | Delete
}
[120] Fix | Delete
break;
[121] Fix | Delete
[122] Fix | Delete
case 'PICTURE': // 0x06
[123] Fix | Delete
if (!$this->parsePICTURE()) {
[124] Fix | Delete
return false;
[125] Fix | Delete
}
[126] Fix | Delete
break;
[127] Fix | Delete
[128] Fix | Delete
default:
[129] Fix | Delete
$this->warning('Unhandled METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockType.') at offset '.$BlockOffset);
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
unset($info['flac'][$BlockTypeText]['raw']);
[133] Fix | Delete
$info['avdataoffset'] = $this->ftell();
[134] Fix | Delete
}
[135] Fix | Delete
while ($LastBlockFlag === false);
[136] Fix | Delete
[137] Fix | Delete
// handle tags
[138] Fix | Delete
if (!empty($info['flac']['VORBIS_COMMENT']['comments'])) {
[139] Fix | Delete
$info['flac']['comments'] = $info['flac']['VORBIS_COMMENT']['comments'];
[140] Fix | Delete
}
[141] Fix | Delete
if (!empty($info['flac']['VORBIS_COMMENT']['vendor'])) {
[142] Fix | Delete
$info['audio']['encoder'] = str_replace('reference ', '', $info['flac']['VORBIS_COMMENT']['vendor']);
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
// copy attachments to 'comments' array if nesesary
[146] Fix | Delete
if (isset($info['flac']['PICTURE']) && ($this->getid3->option_save_attachments !== getID3::ATTACHMENTS_NONE)) {
[147] Fix | Delete
foreach ($info['flac']['PICTURE'] as $entry) {
[148] Fix | Delete
if (!empty($entry['data'])) {
[149] Fix | Delete
if (!isset($info['flac']['comments']['picture'])) {
[150] Fix | Delete
$info['flac']['comments']['picture'] = array();
[151] Fix | Delete
}
[152] Fix | Delete
$comments_picture_data = array();
[153] Fix | Delete
foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) {
[154] Fix | Delete
if (isset($entry[$picture_key])) {
[155] Fix | Delete
$comments_picture_data[$picture_key] = $entry[$picture_key];
[156] Fix | Delete
}
[157] Fix | Delete
}
[158] Fix | Delete
$info['flac']['comments']['picture'][] = $comments_picture_data;
[159] Fix | Delete
unset($comments_picture_data);
[160] Fix | Delete
}
[161] Fix | Delete
}
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
if (isset($info['flac']['STREAMINFO'])) {
[165] Fix | Delete
if (!$this->isDependencyFor('matroska')) {
[166] Fix | Delete
$info['flac']['compressed_audio_bytes'] = $info['avdataend'] - $info['avdataoffset'];
[167] Fix | Delete
}
[168] Fix | Delete
$info['flac']['uncompressed_audio_bytes'] = $info['flac']['STREAMINFO']['samples_stream'] * $info['flac']['STREAMINFO']['channels'] * ($info['flac']['STREAMINFO']['bits_per_sample'] / 8);
[169] Fix | Delete
if ($info['flac']['uncompressed_audio_bytes'] == 0) {
[170] Fix | Delete
return $this->error('Corrupt FLAC file: uncompressed_audio_bytes == zero');
[171] Fix | Delete
}
[172] Fix | Delete
if (!empty($info['flac']['compressed_audio_bytes'])) {
[173] Fix | Delete
$info['flac']['compression_ratio'] = $info['flac']['compressed_audio_bytes'] / $info['flac']['uncompressed_audio_bytes'];
[174] Fix | Delete
}
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
// set md5_data_source - built into flac 0.5+
[178] Fix | Delete
if (isset($info['flac']['STREAMINFO']['audio_signature'])) {
[179] Fix | Delete
[180] Fix | Delete
if ($info['flac']['STREAMINFO']['audio_signature'] === str_repeat("\x00", 16)) {
[181] Fix | Delete
$this->warning('FLAC STREAMINFO.audio_signature is null (known issue with libOggFLAC)');
[182] Fix | Delete
}
[183] Fix | Delete
else {
[184] Fix | Delete
$info['md5_data_source'] = '';
[185] Fix | Delete
$md5 = $info['flac']['STREAMINFO']['audio_signature'];
[186] Fix | Delete
for ($i = 0; $i < strlen($md5); $i++) {
[187] Fix | Delete
$info['md5_data_source'] .= str_pad(dechex(ord($md5[$i])), 2, '00', STR_PAD_LEFT);
[188] Fix | Delete
}
[189] Fix | Delete
if (!preg_match('/^[0-9a-f]{32}$/', $info['md5_data_source'])) {
[190] Fix | Delete
unset($info['md5_data_source']);
[191] Fix | Delete
}
[192] Fix | Delete
}
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
if (isset($info['flac']['STREAMINFO']['bits_per_sample'])) {
[196] Fix | Delete
$info['audio']['bits_per_sample'] = $info['flac']['STREAMINFO']['bits_per_sample'];
[197] Fix | Delete
if ($info['audio']['bits_per_sample'] == 8) {
[198] Fix | Delete
// special case
[199] Fix | Delete
// must invert sign bit on all data bytes before MD5'ing to match FLAC's calculated value
[200] Fix | Delete
// MD5sum calculates on unsigned bytes, but FLAC calculated MD5 on 8-bit audio data as signed
[201] Fix | Delete
$this->warning('FLAC calculates MD5 data strangely on 8-bit audio, so the stored md5_data_source value will not match the decoded WAV file');
[202] Fix | Delete
}
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
return true;
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* @param string $BlockData
[211] Fix | Delete
*
[212] Fix | Delete
* @return array
[213] Fix | Delete
*/
[214] Fix | Delete
public static function parseSTREAMINFOdata($BlockData) {
[215] Fix | Delete
$streaminfo = array();
[216] Fix | Delete
$streaminfo['min_block_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 0, 2));
[217] Fix | Delete
$streaminfo['max_block_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 2, 2));
[218] Fix | Delete
$streaminfo['min_frame_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 4, 3));
[219] Fix | Delete
$streaminfo['max_frame_size'] = getid3_lib::BigEndian2Int(substr($BlockData, 7, 3));
[220] Fix | Delete
[221] Fix | Delete
$SRCSBSS = getid3_lib::BigEndian2Bin(substr($BlockData, 10, 8));
[222] Fix | Delete
$streaminfo['sample_rate'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 0, 20));
[223] Fix | Delete
$streaminfo['channels'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 20, 3)) + 1;
[224] Fix | Delete
$streaminfo['bits_per_sample'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 23, 5)) + 1;
[225] Fix | Delete
$streaminfo['samples_stream'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 28, 36));
[226] Fix | Delete
[227] Fix | Delete
$streaminfo['audio_signature'] = substr($BlockData, 18, 16);
[228] Fix | Delete
[229] Fix | Delete
return $streaminfo;
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
/**
[233] Fix | Delete
* @param string $BlockData
[234] Fix | Delete
*
[235] Fix | Delete
* @return bool
[236] Fix | Delete
*/
[237] Fix | Delete
private function parseSTREAMINFO($BlockData) {
[238] Fix | Delete
$info = &$this->getid3->info;
[239] Fix | Delete
[240] Fix | Delete
$info['flac']['STREAMINFO'] = self::parseSTREAMINFOdata($BlockData);
[241] Fix | Delete
[242] Fix | Delete
if (!empty($info['flac']['STREAMINFO']['sample_rate'])) {
[243] Fix | Delete
[244] Fix | Delete
$info['audio']['bitrate_mode'] = 'vbr';
[245] Fix | Delete
$info['audio']['sample_rate'] = $info['flac']['STREAMINFO']['sample_rate'];
[246] Fix | Delete
$info['audio']['channels'] = $info['flac']['STREAMINFO']['channels'];
[247] Fix | Delete
$info['audio']['bits_per_sample'] = $info['flac']['STREAMINFO']['bits_per_sample'];
[248] Fix | Delete
$info['playtime_seconds'] = $info['flac']['STREAMINFO']['samples_stream'] / $info['flac']['STREAMINFO']['sample_rate'];
[249] Fix | Delete
if ($info['playtime_seconds'] > 0) {
[250] Fix | Delete
if (!$this->isDependencyFor('matroska')) {
[251] Fix | Delete
$info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
[252] Fix | Delete
}
[253] Fix | Delete
else {
[254] Fix | Delete
$this->warning('Cannot determine audio bitrate because total stream size is unknown');
[255] Fix | Delete
}
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
} else {
[259] Fix | Delete
return $this->error('Corrupt METAdata block: STREAMINFO');
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
return true;
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
/**
[266] Fix | Delete
* @param string $BlockData
[267] Fix | Delete
*
[268] Fix | Delete
* @return bool
[269] Fix | Delete
*/
[270] Fix | Delete
private function parseAPPLICATION($BlockData) {
[271] Fix | Delete
$info = &$this->getid3->info;
[272] Fix | Delete
[273] Fix | Delete
$ApplicationID = getid3_lib::BigEndian2Int(substr($BlockData, 0, 4));
[274] Fix | Delete
$info['flac']['APPLICATION'][$ApplicationID]['name'] = self::applicationIDLookup($ApplicationID);
[275] Fix | Delete
$info['flac']['APPLICATION'][$ApplicationID]['data'] = substr($BlockData, 4);
[276] Fix | Delete
[277] Fix | Delete
return true;
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
/**
[281] Fix | Delete
* @param string $BlockData
[282] Fix | Delete
*
[283] Fix | Delete
* @return bool
[284] Fix | Delete
*/
[285] Fix | Delete
private function parseSEEKTABLE($BlockData) {
[286] Fix | Delete
$info = &$this->getid3->info;
[287] Fix | Delete
[288] Fix | Delete
$offset = 0;
[289] Fix | Delete
$BlockLength = strlen($BlockData);
[290] Fix | Delete
$placeholderpattern = str_repeat("\xFF", 8);
[291] Fix | Delete
while ($offset < $BlockLength) {
[292] Fix | Delete
$SampleNumberString = substr($BlockData, $offset, 8);
[293] Fix | Delete
$offset += 8;
[294] Fix | Delete
if ($SampleNumberString == $placeholderpattern) {
[295] Fix | Delete
[296] Fix | Delete
// placeholder point
[297] Fix | Delete
getid3_lib::safe_inc($info['flac']['SEEKTABLE']['placeholders'], 1);
[298] Fix | Delete
$offset += 10;
[299] Fix | Delete
[300] Fix | Delete
} else {
[301] Fix | Delete
[302] Fix | Delete
$SampleNumber = getid3_lib::BigEndian2Int($SampleNumberString);
[303] Fix | Delete
$info['flac']['SEEKTABLE'][$SampleNumber]['offset'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8));
[304] Fix | Delete
$offset += 8;
[305] Fix | Delete
$info['flac']['SEEKTABLE'][$SampleNumber]['samples'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 2));
[306] Fix | Delete
$offset += 2;
[307] Fix | Delete
[308] Fix | Delete
}
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
return true;
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
/**
[315] Fix | Delete
* @param string $BlockData
[316] Fix | Delete
*
[317] Fix | Delete
* @return bool
[318] Fix | Delete
*/
[319] Fix | Delete
private function parseVORBIS_COMMENT($BlockData) {
[320] Fix | Delete
$info = &$this->getid3->info;
[321] Fix | Delete
[322] Fix | Delete
$getid3_ogg = new getid3_ogg($this->getid3);
[323] Fix | Delete
if ($this->isDependencyFor('matroska')) {
[324] Fix | Delete
$getid3_ogg->setStringMode($this->data_string);
[325] Fix | Delete
}
[326] Fix | Delete
$getid3_ogg->ParseVorbisComments();
[327] Fix | Delete
if (isset($info['ogg'])) {
[328] Fix | Delete
unset($info['ogg']['comments_raw']);
[329] Fix | Delete
$info['flac']['VORBIS_COMMENT'] = $info['ogg'];
[330] Fix | Delete
unset($info['ogg']);
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
unset($getid3_ogg);
[334] Fix | Delete
[335] Fix | Delete
return true;
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
/**
[339] Fix | Delete
* @param string $BlockData
[340] Fix | Delete
*
[341] Fix | Delete
* @return bool
[342] Fix | Delete
*/
[343] Fix | Delete
private function parseCUESHEET($BlockData) {
[344] Fix | Delete
$info = &$this->getid3->info;
[345] Fix | Delete
$offset = 0;
[346] Fix | Delete
$info['flac']['CUESHEET']['media_catalog_number'] = trim(substr($BlockData, $offset, 128), "\0");
[347] Fix | Delete
$offset += 128;
[348] Fix | Delete
$info['flac']['CUESHEET']['lead_in_samples'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8));
[349] Fix | Delete
$offset += 8;
[350] Fix | Delete
$info['flac']['CUESHEET']['flags']['is_cd'] = (bool) (getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1)) & 0x80);
[351] Fix | Delete
$offset += 1;
[352] Fix | Delete
[353] Fix | Delete
$offset += 258; // reserved
[354] Fix | Delete
[355] Fix | Delete
$info['flac']['CUESHEET']['number_tracks'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
[356] Fix | Delete
$offset += 1;
[357] Fix | Delete
[358] Fix | Delete
for ($track = 0; $track < $info['flac']['CUESHEET']['number_tracks']; $track++) {
[359] Fix | Delete
$TrackSampleOffset = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8));
[360] Fix | Delete
$offset += 8;
[361] Fix | Delete
$TrackNumber = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
[362] Fix | Delete
$offset += 1;
[363] Fix | Delete
[364] Fix | Delete
$info['flac']['CUESHEET']['tracks'][$TrackNumber]['sample_offset'] = $TrackSampleOffset;
[365] Fix | Delete
[366] Fix | Delete
$info['flac']['CUESHEET']['tracks'][$TrackNumber]['isrc'] = substr($BlockData, $offset, 12);
[367] Fix | Delete
$offset += 12;
[368] Fix | Delete
[369] Fix | Delete
$TrackFlagsRaw = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
[370] Fix | Delete
$offset += 1;
[371] Fix | Delete
$info['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['is_audio'] = (bool) ($TrackFlagsRaw & 0x80);
[372] Fix | Delete
$info['flac']['CUESHEET']['tracks'][$TrackNumber]['flags']['pre_emphasis'] = (bool) ($TrackFlagsRaw & 0x40);
[373] Fix | Delete
[374] Fix | Delete
$offset += 13; // reserved
[375] Fix | Delete
[376] Fix | Delete
$info['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points'] = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
[377] Fix | Delete
$offset += 1;
[378] Fix | Delete
[379] Fix | Delete
for ($index = 0; $index < $info['flac']['CUESHEET']['tracks'][$TrackNumber]['index_points']; $index++) {
[380] Fix | Delete
$IndexSampleOffset = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 8));
[381] Fix | Delete
$offset += 8;
[382] Fix | Delete
$IndexNumber = getid3_lib::BigEndian2Int(substr($BlockData, $offset, 1));
[383] Fix | Delete
$offset += 1;
[384] Fix | Delete
[385] Fix | Delete
$offset += 3; // reserved
[386] Fix | Delete
[387] Fix | Delete
$info['flac']['CUESHEET']['tracks'][$TrackNumber]['indexes'][$IndexNumber] = $IndexSampleOffset;
[388] Fix | Delete
}
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
return true;
[392] Fix | Delete
}
[393] Fix | Delete
[394] Fix | Delete
/**
[395] Fix | Delete
* Parse METADATA_BLOCK_PICTURE flac structure and extract attachment
[396] Fix | Delete
* External usage: audio.ogg
[397] Fix | Delete
*
[398] Fix | Delete
* @return bool
[399] Fix | Delete
*/
[400] Fix | Delete
public function parsePICTURE() {
[401] Fix | Delete
$info = &$this->getid3->info;
[402] Fix | Delete
[403] Fix | Delete
$picture = array();
[404] Fix | Delete
$picture['typeid'] = getid3_lib::BigEndian2Int($this->fread(4));
[405] Fix | Delete
$picture['picturetype'] = self::pictureTypeLookup($picture['typeid']);
[406] Fix | Delete
$picture['image_mime'] = $this->fread(getid3_lib::BigEndian2Int($this->fread(4)));
[407] Fix | Delete
$descr_length = getid3_lib::BigEndian2Int($this->fread(4));
[408] Fix | Delete
if ($descr_length) {
[409] Fix | Delete
$picture['description'] = $this->fread($descr_length);
[410] Fix | Delete
}
[411] Fix | Delete
$picture['image_width'] = getid3_lib::BigEndian2Int($this->fread(4));
[412] Fix | Delete
$picture['image_height'] = getid3_lib::BigEndian2Int($this->fread(4));
[413] Fix | Delete
$picture['color_depth'] = getid3_lib::BigEndian2Int($this->fread(4));
[414] Fix | Delete
$picture['colors_indexed'] = getid3_lib::BigEndian2Int($this->fread(4));
[415] Fix | Delete
$picture['datalength'] = getid3_lib::BigEndian2Int($this->fread(4));
[416] Fix | Delete
[417] Fix | Delete
if ($picture['image_mime'] == '-->') {
[418] Fix | Delete
$picture['data'] = $this->fread($picture['datalength']);
[419] Fix | Delete
} else {
[420] Fix | Delete
$picture['data'] = $this->saveAttachment(
[421] Fix | Delete
str_replace('/', '_', $picture['picturetype']).'_'.$this->ftell(),
[422] Fix | Delete
$this->ftell(),
[423] Fix | Delete
$picture['datalength'],
[424] Fix | Delete
$picture['image_mime']);
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
$info['flac']['PICTURE'][] = $picture;
[428] Fix | Delete
[429] Fix | Delete
return true;
[430] Fix | Delete
}
[431] Fix | Delete
[432] Fix | Delete
/**
[433] Fix | Delete
* @param int $blocktype
[434] Fix | Delete
*
[435] Fix | Delete
* @return string
[436] Fix | Delete
*/
[437] Fix | Delete
public static function metaBlockTypeLookup($blocktype) {
[438] Fix | Delete
static $lookup = array(
[439] Fix | Delete
0 => 'STREAMINFO',
[440] Fix | Delete
1 => 'PADDING',
[441] Fix | Delete
2 => 'APPLICATION',
[442] Fix | Delete
3 => 'SEEKTABLE',
[443] Fix | Delete
4 => 'VORBIS_COMMENT',
[444] Fix | Delete
5 => 'CUESHEET',
[445] Fix | Delete
6 => 'PICTURE',
[446] Fix | Delete
);
[447] Fix | Delete
return (isset($lookup[$blocktype]) ? $lookup[$blocktype] : 'reserved');
[448] Fix | Delete
}
[449] Fix | Delete
[450] Fix | Delete
/**
[451] Fix | Delete
* @param int $applicationid
[452] Fix | Delete
*
[453] Fix | Delete
* @return string
[454] Fix | Delete
*/
[455] Fix | Delete
public static function applicationIDLookup($applicationid) {
[456] Fix | Delete
// http://flac.sourceforge.net/id.html
[457] Fix | Delete
static $lookup = array(
[458] Fix | Delete
0x41544348 => 'FlacFile', // "ATCH"
[459] Fix | Delete
0x42534F4C => 'beSolo', // "BSOL"
[460] Fix | Delete
0x42554753 => 'Bugs Player', // "BUGS"
[461] Fix | Delete
0x43756573 => 'GoldWave cue points (specification)', // "Cues"
[462] Fix | Delete
0x46696361 => 'CUE Splitter', // "Fica"
[463] Fix | Delete
0x46746F6C => 'flac-tools', // "Ftol"
[464] Fix | Delete
0x4D4F5442 => 'MOTB MetaCzar', // "MOTB"
[465] Fix | Delete
0x4D505345 => 'MP3 Stream Editor', // "MPSE"
[466] Fix | Delete
0x4D754D4C => 'MusicML: Music Metadata Language', // "MuML"
[467] Fix | Delete
0x52494646 => 'Sound Devices RIFF chunk storage', // "RIFF"
[468] Fix | Delete
0x5346464C => 'Sound Font FLAC', // "SFFL"
[469] Fix | Delete
0x534F4E59 => 'Sony Creative Software', // "SONY"
[470] Fix | Delete
0x5351455A => 'flacsqueeze', // "SQEZ"
[471] Fix | Delete
0x54745776 => 'TwistedWave', // "TtWv"
[472] Fix | Delete
0x55495453 => 'UITS Embedding tools', // "UITS"
[473] Fix | Delete
0x61696666 => 'FLAC AIFF chunk storage', // "aiff"
[474] Fix | Delete
0x696D6167 => 'flac-image application for storing arbitrary files in APPLICATION metadata blocks', // "imag"
[475] Fix | Delete
0x7065656D => 'Parseable Embedded Extensible Metadata (specification)', // "peem"
[476] Fix | Delete
0x71667374 => 'QFLAC Studio', // "qfst"
[477] Fix | Delete
0x72696666 => 'FLAC RIFF chunk storage', // "riff"
[478] Fix | Delete
0x74756E65 => 'TagTuner', // "tune"
[479] Fix | Delete
0x78626174 => 'XBAT', // "xbat"
[480] Fix | Delete
0x786D6364 => 'xmcd', // "xmcd"
[481] Fix | Delete
);
[482] Fix | Delete
return (isset($lookup[$applicationid]) ? $lookup[$applicationid] : 'reserved');
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
/**
[486] Fix | Delete
* @param int $type_id
[487] Fix | Delete
*
[488] Fix | Delete
* @return string
[489] Fix | Delete
*/
[490] Fix | Delete
public static function pictureTypeLookup($type_id) {
[491] Fix | Delete
static $lookup = array (
[492] Fix | Delete
0 => 'Other',
[493] Fix | Delete
1 => '32x32 pixels \'file icon\' (PNG only)',
[494] Fix | Delete
2 => 'Other file icon',
[495] Fix | Delete
3 => 'Cover (front)',
[496] Fix | Delete
4 => 'Cover (back)',
[497] Fix | Delete
5 => 'Leaflet page',
[498] Fix | Delete
6 => 'Media (e.g. label side of CD)',
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function