wp/wp-includes/ID3/module.tag.apetag.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
     1 <?php
     1 <?php
     2 /////////////////////////////////////////////////////////////////
     2 /////////////////////////////////////////////////////////////////
     3 /// getID3() by James Heinrich <info@getid3.org>               //
     3 /// getID3() by James Heinrich <info@getid3.org>               //
     4 //  available at http://getid3.sourceforge.net                 //
     4 //  available at http://getid3.sourceforge.net                 //
     5 //            or http://www.getid3.org                         //
     5 //            or http://www.getid3.org                         //
       
     6 //          also https://github.com/JamesHeinrich/getID3       //
     6 /////////////////////////////////////////////////////////////////
     7 /////////////////////////////////////////////////////////////////
     7 // See readme.txt for more details                             //
     8 // See readme.txt for more details                             //
     8 /////////////////////////////////////////////////////////////////
     9 /////////////////////////////////////////////////////////////////
     9 //                                                             //
    10 //                                                             //
    10 // module.tag.apetag.php                                       //
    11 // module.tag.apetag.php                                       //
    30 		$apetagheadersize = 32;
    31 		$apetagheadersize = 32;
    31 		$lyrics3tagsize   = 10;
    32 		$lyrics3tagsize   = 10;
    32 
    33 
    33 		if ($this->overrideendoffset == 0) {
    34 		if ($this->overrideendoffset == 0) {
    34 
    35 
    35 			fseek($this->getid3->fp, 0 - $id3v1tagsize - $apetagheadersize - $lyrics3tagsize, SEEK_END);
    36 			$this->fseek(0 - $id3v1tagsize - $apetagheadersize - $lyrics3tagsize, SEEK_END);
    36 			$APEfooterID3v1 = fread($this->getid3->fp, $id3v1tagsize + $apetagheadersize + $lyrics3tagsize);
    37 			$APEfooterID3v1 = $this->fread($id3v1tagsize + $apetagheadersize + $lyrics3tagsize);
    37 
    38 
    38 			//if (preg_match('/APETAGEX.{24}TAG.{125}$/i', $APEfooterID3v1)) {
    39 			//if (preg_match('/APETAGEX.{24}TAG.{125}$/i', $APEfooterID3v1)) {
    39 			if (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $id3v1tagsize - $apetagheadersize, 8) == 'APETAGEX') {
    40 			if (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $id3v1tagsize - $apetagheadersize, 8) == 'APETAGEX') {
    40 
    41 
    41 				// APE tag found before ID3v1
    42 				// APE tag found before ID3v1
    49 
    50 
    50 			}
    51 			}
    51 
    52 
    52 		} else {
    53 		} else {
    53 
    54 
    54 			fseek($this->getid3->fp, $this->overrideendoffset - $apetagheadersize, SEEK_SET);
    55 			$this->fseek($this->overrideendoffset - $apetagheadersize);
    55 			if (fread($this->getid3->fp, 8) == 'APETAGEX') {
    56 			if ($this->fread(8) == 'APETAGEX') {
    56 				$info['ape']['tag_offset_end'] = $this->overrideendoffset;
    57 				$info['ape']['tag_offset_end'] = $this->overrideendoffset;
    57 			}
    58 			}
    58 
    59 
    59 		}
    60 		}
    60 		if (!isset($info['ape']['tag_offset_end'])) {
    61 		if (!isset($info['ape']['tag_offset_end'])) {
    66 		}
    67 		}
    67 
    68 
    68 		// shortcut
    69 		// shortcut
    69 		$thisfile_ape = &$info['ape'];
    70 		$thisfile_ape = &$info['ape'];
    70 
    71 
    71 		fseek($this->getid3->fp, $thisfile_ape['tag_offset_end'] - $apetagheadersize, SEEK_SET);
    72 		$this->fseek($thisfile_ape['tag_offset_end'] - $apetagheadersize);
    72 		$APEfooterData = fread($this->getid3->fp, 32);
    73 		$APEfooterData = $this->fread(32);
    73 		if (!($thisfile_ape['footer'] = $this->parseAPEheaderFooter($APEfooterData))) {
    74 		if (!($thisfile_ape['footer'] = $this->parseAPEheaderFooter($APEfooterData))) {
    74 			$info['error'][] = 'Error parsing APE footer at offset '.$thisfile_ape['tag_offset_end'];
    75 			$info['error'][] = 'Error parsing APE footer at offset '.$thisfile_ape['tag_offset_end'];
    75 			return false;
    76 			return false;
    76 		}
    77 		}
    77 
    78 
    78 		if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) {
    79 		if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) {
    79 			fseek($this->getid3->fp, $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'] - $apetagheadersize, SEEK_SET);
    80 			$this->fseek($thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'] - $apetagheadersize);
    80 			$thisfile_ape['tag_offset_start'] = ftell($this->getid3->fp);
    81 			$thisfile_ape['tag_offset_start'] = $this->ftell();
    81 			$APEtagData = fread($this->getid3->fp, $thisfile_ape['footer']['raw']['tagsize'] + $apetagheadersize);
    82 			$APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize'] + $apetagheadersize);
    82 		} else {
    83 		} else {
    83 			$thisfile_ape['tag_offset_start'] = $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'];
    84 			$thisfile_ape['tag_offset_start'] = $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'];
    84 			fseek($this->getid3->fp, $thisfile_ape['tag_offset_start'], SEEK_SET);
    85 			$this->fseek($thisfile_ape['tag_offset_start']);
    85 			$APEtagData = fread($this->getid3->fp, $thisfile_ape['footer']['raw']['tagsize']);
    86 			$APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize']);
    86 		}
    87 		}
    87 		$info['avdataend'] = $thisfile_ape['tag_offset_start'];
    88 		$info['avdataend'] = $thisfile_ape['tag_offset_start'];
    88 
    89 
    89 		if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] < $thisfile_ape['tag_offset_end'])) {
    90 		if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] < $thisfile_ape['tag_offset_end'])) {
    90 			$info['warning'][] = 'ID3v1 tag information ignored since it appears to be a false synch in APEtag data';
    91 			$info['warning'][] = 'ID3v1 tag information ignored since it appears to be a false synch in APEtag data';