///////////////////////////////////////////////////////////////// /// getID3() by James Heinrich <info@getid3.org> // // available at https://github.com/JamesHeinrich/getID3 // // or https://www.getid3.org // // or http://getid3.sourceforge.net // // see readme.txt for more details // ///////////////////////////////////////////////////////////////// /// // // module.tag.lyrics3.php // // module for analyzing Lyrics3 tags // // dependencies: module.tag.apetag.php (optional) // // /// /////////////////////////////////////////////////////////////////
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers exit; } class getid3_lyrics3 extends getid3_handler { /** * @return bool */ public function Analyze() { $info = &$this->getid3->info;
// http://www.volweb.cz/str/tags.htm
if (!getid3_lib::intValueSupported($info['filesize'])) { $this->warning('Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'); return false; }
if (!isset($info['ape'])) { if (isset($info['lyrics3']['tag_offset_start'])) { $GETID3_ERRORARRAY = &$info['warning']; getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.apetag.php', __FILE__, true); $getid3_temp = new getID3(); $getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp); $getid3_apetag = new getid3_apetag($getid3_temp); $getid3_apetag->overrideendoffset = $info['lyrics3']['tag_offset_start']; $getid3_apetag->Analyze(); if (!empty($getid3_temp->info['ape'])) { $info['ape'] = $getid3_temp->info['ape']; } if (!empty($getid3_temp->info['replay_gain'])) { $info['replay_gain'] = $getid3_temp->info['replay_gain']; } unset($getid3_temp, $getid3_apetag); } else { $this->warning('Lyrics3 and APE tags appear to have become entangled (most likely due to updating the APE tags with a non-Lyrics3-aware tagger)'); } }
}
return true; }
/** * @param int $endoffset * @param int $version * @param int $length * * @return bool */ public function getLyrics3Data($endoffset, $version, $length) { // http://www.volweb.cz/str/tags.htm
$info = &$this->getid3->info;
if (!getid3_lib::intValueSupported($endoffset)) { $this->warning('Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB'); return false; }
default: $this->error('Cannot process Lyrics3 version '.$version.' (only v1 and v2)'); return false; }
if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] <= $ParsedLyrics3['tag_offset_end'])) { $this->warning('ID3v1 tag information ignored since it appears to be a false synch in Lyrics3 tag data'); unset($info['id3v1']); foreach ($info['warning'] as $key => $value) { if ($value == 'Some ID3v1 fields do not use NULL characters for padding') { unset($info['warning'][$key]); sort($info['warning']); break; } } }
$info['lyrics3'] = $ParsedLyrics3;
return true; }
/** * @param string $rawtimestamp * * @return int|false */ public function Lyrics3Timestamp2Seconds($rawtimestamp) { if (preg_match('#^\\[([0-9]{2}):([0-9]{2})\\]$#', $rawtimestamp, $regs)) { return (int) (($regs[1] * 60) + $regs[2]); } return false; }
/** * @param array $Lyrics3data * * @return bool */ public function Lyrics3LyricsTimestampParse(&$Lyrics3data) { $lyricsarray = explode("\r\n", $Lyrics3data['raw']['LYR']); $notimestamplyricsarray = array(); foreach ($lyricsarray as $key => $lyricline) { $regs = array(); unset($thislinetimestamps); while (preg_match('#^(\\[[0-9]{2}:[0-9]{2}\\])#', $lyricline, $regs)) { $thislinetimestamps[] = $this->Lyrics3Timestamp2Seconds($regs[0]); $lyricline = str_replace($regs[0], '', $lyricline); } $notimestamplyricsarray[$key] = $lyricline; if (isset($thislinetimestamps) && is_array($thislinetimestamps)) { sort($thislinetimestamps); foreach ($thislinetimestamps as $timestampkey => $timestamp) { if (isset($Lyrics3data['synchedlyrics'][$timestamp])) { // timestamps only have a 1-second resolution, it's possible that multiple lines // could have the same timestamp, if so, append $Lyrics3data['synchedlyrics'][$timestamp] .= "\r\n".$lyricline; } else { $Lyrics3data['synchedlyrics'][$timestamp] = $lyricline; } } } } $Lyrics3data['unsynchedlyrics'] = implode("\r\n", $notimestamplyricsarray); if (isset($Lyrics3data['synchedlyrics']) && is_array($Lyrics3data['synchedlyrics'])) { ksort($Lyrics3data['synchedlyrics']); } return true; }