Exemple #1
0
 /**
  * @return bool
  */
 public function ParseVorbisComments()
 {
     $info =& $this->getid3->info;
     $OriginalOffset = $this->ftell();
     $commentdataoffset = 0;
     $VorbisCommentPage = 1;
     switch ($info['audio']['dataformat']) {
         case 'vorbis':
         case 'speex':
             $CommentStartOffset = $info['ogg']['pageheader'][$VorbisCommentPage]['page_start_offset'];
             // Second Ogg page, after header block
             $this->fseek($CommentStartOffset);
             $commentdataoffset = 27 + $info['ogg']['pageheader'][$VorbisCommentPage]['page_segments'];
             $commentdata = $this->fread(self::OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1) + $commentdataoffset);
             if ($info['audio']['dataformat'] == 'vorbis') {
                 $commentdataoffset += strlen('vorbis') + 1;
             }
             break;
         case 'flac':
             $CommentStartOffset = $info['flac']['VORBIS_COMMENT']['raw']['offset'] + 4;
             $this->fseek($CommentStartOffset);
             $commentdata = $this->fread($info['flac']['VORBIS_COMMENT']['raw']['block_length']);
             break;
         default:
             return false;
     }
     $VendorSize = Helper::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4));
     $commentdataoffset += 4;
     $info['ogg']['vendor'] = substr($commentdata, $commentdataoffset, $VendorSize);
     $commentdataoffset += $VendorSize;
     $CommentsCount = Helper::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4));
     $commentdataoffset += 4;
     $info['avdataoffset'] = $CommentStartOffset + $commentdataoffset;
     $basicfields = array('TITLE', 'ARTIST', 'ALBUM', 'TRACKNUMBER', 'GENRE', 'DATE', 'DESCRIPTION', 'COMMENT');
     $ThisFileInfo_ogg_comments_raw =& $info['ogg']['comments_raw'];
     for ($i = 0; $i < $CommentsCount; ++$i) {
         $ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] = $CommentStartOffset + $commentdataoffset;
         if ($this->ftell() < $ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] + 4) {
             if ($oggpageinfo = $this->ParseOggPageHeader()) {
                 $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo;
                 ++$VorbisCommentPage;
                 // First, save what we haven't read yet
                 $AsYetUnusedData = substr($commentdata, $commentdataoffset);
                 // Then take that data off the end
                 $commentdata = substr($commentdata, 0, $commentdataoffset);
                 // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct
                 $commentdata .= str_repeat("", 27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']);
                 $commentdataoffset += 27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments'];
                 // Finally, stick the unused data back on the end
                 $commentdata .= $AsYetUnusedData;
                 //$commentdata .= $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']);
                 $commentdata .= $this->fread($this->OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1));
             }
         }
         $ThisFileInfo_ogg_comments_raw[$i]['size'] = Helper::LittleEndian2Int(substr($commentdata, $commentdataoffset, 4));
         // replace avdataoffset with position just after the last vorbiscomment
         $info['avdataoffset'] = $ThisFileInfo_ogg_comments_raw[$i]['dataoffset'] + $ThisFileInfo_ogg_comments_raw[$i]['size'] + 4;
         $commentdataoffset += 4;
         while (strlen($commentdata) - $commentdataoffset < $ThisFileInfo_ogg_comments_raw[$i]['size']) {
             if ($ThisFileInfo_ogg_comments_raw[$i]['size'] > $info['avdataend'] || $ThisFileInfo_ogg_comments_raw[$i]['size'] < 0) {
                 $info['warning'][] = 'Invalid Ogg comment size (comment #' . $i . ', claims to be ' . number_format($ThisFileInfo_ogg_comments_raw[$i]['size']) . ' bytes) - aborting reading comments';
                 break 2;
             }
             ++$VorbisCommentPage;
             $oggpageinfo = $this->ParseOggPageHeader();
             $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo;
             // First, save what we haven't read yet
             $AsYetUnusedData = substr($commentdata, $commentdataoffset);
             // Then take that data off the end
             $commentdata = substr($commentdata, 0, $commentdataoffset);
             // Add [headerlength] bytes of dummy data for the Ogg Page Header, just to keep absolute offsets correct
             $commentdata .= str_repeat("", 27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments']);
             $commentdataoffset += 27 + $info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_segments'];
             // Finally, stick the unused data back on the end
             $commentdata .= $AsYetUnusedData;
             //$commentdata .= $this->fread($info['ogg']['pageheader'][$oggpageinfo['page_seqno']]['page_length']);
             if (!isset($info['ogg']['pageheader'][$VorbisCommentPage])) {
                 $info['warning'][] = 'undefined Vorbis Comment page "' . $VorbisCommentPage . '" at offset ' . $this->ftell();
                 break;
             }
             $readlength = self::OggPageSegmentLength($info['ogg']['pageheader'][$VorbisCommentPage], 1);
             if ($readlength <= 0) {
                 $info['warning'][] = 'invalid length Vorbis Comment page "' . $VorbisCommentPage . '" at offset ' . $this->ftell();
                 break;
             }
             $commentdata .= $this->fread($readlength);
             //$filebaseoffset += $oggpageinfo['header_end_offset'] - $oggpageinfo['page_start_offset'];
         }
         $ThisFileInfo_ogg_comments_raw[$i]['offset'] = $commentdataoffset;
         $commentstring = substr($commentdata, $commentdataoffset, $ThisFileInfo_ogg_comments_raw[$i]['size']);
         $commentdataoffset += $ThisFileInfo_ogg_comments_raw[$i]['size'];
         if (!$commentstring) {
             // no comment?
             $info['warning'][] = 'Blank Ogg comment [' . $i . ']';
         } elseif (strstr($commentstring, '=')) {
             $commentexploded = explode('=', $commentstring, 2);
             $ThisFileInfo_ogg_comments_raw[$i]['key'] = strtoupper($commentexploded[0]);
             $ThisFileInfo_ogg_comments_raw[$i]['value'] = isset($commentexploded[1]) ? $commentexploded[1] : '';
             $ThisFileInfo_ogg_comments_raw[$i]['data'] = base64_decode($ThisFileInfo_ogg_comments_raw[$i]['value']);
             $ThisFileInfo_ogg_comments_raw[$i]['data_length'] = strlen($ThisFileInfo_ogg_comments_raw[$i]['data']);
             if ($ThisFileInfo_ogg_comments_raw[$i]['key'] == 'METADATA_BLOCK_PICTURE') {
                 // http://wiki.xiph.org/VorbisComment#METADATA_BLOCK_PICTURE
                 // The unencoded format is that of the FLAC picture block. The fields are stored in big endian order as in FLAC, picture data is stored according to the relevant standard.
                 // http://flac.sourceforge.net/format.html#metadata_block_picture
                 $getid3_temp = new GetId3Core();
                 $getid3_flac = new Flac($getid3_temp);
                 $getid3_flac->data_string = $ThisFileInfo_ogg_comments_raw[$i]['data'];
                 $getid3_flac->data_string_flag = true;
                 if ($getid3_flac->parsePICTURE()) {
                     if (!empty($getid3_temp->info['flac']['PICTURE'])) {
                         foreach ($getid3_temp->info['flac']['PICTURE'] as $key => $value) {
                             $ThisFileInfo_ogg_comments_raw[$i]['data'] = $value['data'];
                             $ThisFileInfo_ogg_comments_raw[$i]['data_length'] = strlen($value['data']);
                             $ThisFileInfo_ogg_comments_raw[$i]['image_mime'] = $value['image_mime'];
                             $ThisFileInfo_ogg_comments_raw[$i]['width'] = $value['width'];
                             $ThisFileInfo_ogg_comments_raw[$i]['height'] = $value['height'];
                             $ThisFileInfo_ogg_comments_raw[$i]['type'] = $value['type'];
                             $ThisFileInfo_ogg_comments_raw[$i]['typeid'] = $value['typeid'];
                             $ThisFileInfo_ogg_comments_raw[$i]['color_depth'] = $value['color_depth'];
                             $ThisFileInfo_ogg_comments_raw[$i]['colors_indexed'] = $value['colors_indexed'];
                         }
                     }
                 } else {
                     $info['warning'][] = 'Failed to GetId3_flac.parsePICTURE()';
                 }
                 unset($getid3_flac, $getid3_temp);
             }
             if (preg_match('#^(BM|GIF|\\xFF\\xD8\\xFF|\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A|II\\x2A\\x00|MM\\x00\\x2A)#s', $ThisFileInfo_ogg_comments_raw[$i]['data'])) {
                 $imageinfo = array();
                 $imagechunkcheck = Helper::GetDataImageSize($ThisFileInfo_ogg_comments_raw[$i]['data'], $imageinfo);
                 unset($imageinfo);
                 if (!empty($imagechunkcheck)) {
                     $ThisFileInfo_ogg_comments_raw[$i]['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]);
                     if ($ThisFileInfo_ogg_comments_raw[$i]['image_mime'] && $ThisFileInfo_ogg_comments_raw[$i]['image_mime'] != 'application/octet-stream') {
                         unset($ThisFileInfo_ogg_comments_raw[$i]['value']);
                     }
                 }
             }
             if (isset($ThisFileInfo_ogg_comments_raw[$i]['value'])) {
                 unset($ThisFileInfo_ogg_comments_raw[$i]['data']);
                 $info['ogg']['comments'][strtolower($ThisFileInfo_ogg_comments_raw[$i]['key'])][] = $ThisFileInfo_ogg_comments_raw[$i]['value'];
             } else {
                 do {
                     if ($this->inline_attachments === false) {
                         // skip entirely
                         unset($ThisFileInfo_ogg_comments_raw[$i]['data']);
                         break;
                     }
                     if ($this->inline_attachments === true) {
                         // great
                     } elseif (is_int($this->inline_attachments)) {
                         if ($this->inline_attachments < $ThisFileInfo_ogg_comments_raw[$i]['data_length']) {
                             // too big, skip
                             $info['warning'][] = 'attachment at ' . $ThisFileInfo_ogg_comments_raw[$i]['offset'] . ' is too large to process inline (' . number_format($ThisFileInfo_ogg_comments_raw[$i]['data_length']) . ' bytes)';
                             unset($ThisFileInfo_ogg_comments_raw[$i]['data']);
                             break;
                         }
                     } elseif (is_string($this->inline_attachments)) {
                         $this->inline_attachments = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->inline_attachments), DIRECTORY_SEPARATOR);
                         if (!is_dir($this->inline_attachments) || !is_writable($this->inline_attachments)) {
                             // cannot write, skip
                             $info['warning'][] = 'attachment at ' . $ThisFileInfo_ogg_comments_raw[$i]['offset'] . ' cannot be saved to "' . $this->inline_attachments . '" (not writable)';
                             unset($ThisFileInfo_ogg_comments_raw[$i]['data']);
                             break;
                         }
                     }
                     // if we get this far, must be OK
                     if (is_string($this->inline_attachments)) {
                         $destination_filename = $this->inline_attachments . DIRECTORY_SEPARATOR . md5($info['filenamepath']) . '_' . $ThisFileInfo_ogg_comments_raw[$i]['offset'];
                         if (!file_exists($destination_filename) || is_writable($destination_filename)) {
                             file_put_contents($destination_filename, $ThisFileInfo_ogg_comments_raw[$i]['data']);
                         } else {
                             $info['warning'][] = 'attachment at ' . $ThisFileInfo_ogg_comments_raw[$i]['offset'] . ' cannot be saved to "' . $destination_filename . '" (not writable)';
                         }
                         $ThisFileInfo_ogg_comments_raw[$i]['data_filename'] = $destination_filename;
                         unset($ThisFileInfo_ogg_comments_raw[$i]['data']);
                     } else {
                         $info['ogg']['comments']['picture'][] = array('data' => $ThisFileInfo_ogg_comments_raw[$i]['data'], 'image_mime' => $ThisFileInfo_ogg_comments_raw[$i]['image_mime']);
                     }
                 } while (false);
             }
         } else {
             $info['warning'][] = '[known problem with CDex >= v1.40, < v1.50b7] Invalid Ogg comment name/value pair [' . $i . ']: ' . $commentstring;
         }
     }
     // Replay Gain Adjustment
     // http://privatewww.essex.ac.uk/~djmrob/replaygain/
     if (isset($info['ogg']['comments']) && is_array($info['ogg']['comments'])) {
         foreach ($info['ogg']['comments'] as $index => $commentvalue) {
             switch ($index) {
                 case 'rg_audiophile':
                 case 'replaygain_album_gain':
                     $info['replay_gain']['album']['adjustment'] = (double) $commentvalue[0];
                     unset($info['ogg']['comments'][$index]);
                     break;
                 case 'rg_radio':
                 case 'replaygain_track_gain':
                     $info['replay_gain']['track']['adjustment'] = (double) $commentvalue[0];
                     unset($info['ogg']['comments'][$index]);
                     break;
                 case 'replaygain_album_peak':
                     $info['replay_gain']['album']['peak'] = (double) $commentvalue[0];
                     unset($info['ogg']['comments'][$index]);
                     break;
                 case 'rg_peak':
                 case 'replaygain_track_peak':
                     $info['replay_gain']['track']['peak'] = (double) $commentvalue[0];
                     unset($info['ogg']['comments'][$index]);
                     break;
                 case 'replaygain_reference_loudness':
                     $info['replay_gain']['reference_volume'] = (double) $commentvalue[0];
                     unset($info['ogg']['comments'][$index]);
                     break;
                 default:
                     // do nothing
                     break;
             }
         }
     }
     $this->fseek($OriginalOffset);
     return true;
 }
Exemple #2
0
 /**
  * @return bool
  */
 public function analyze()
 {
     $info =& $this->getid3->info;
     if (!Helper::intValueSupported($info['filesize'])) {
         $info['warning'][] = 'Unable to check for APEtags because file is larger than ' . round(PHP_INT_MAX / 1073741824) . 'GB';
         return false;
     }
     $id3v1tagsize = 128;
     $apetagheadersize = 32;
     $lyrics3tagsize = 10;
     if ($this->overrideendoffset == 0) {
         fseek($this->getid3->fp, 0 - $id3v1tagsize - $apetagheadersize - $lyrics3tagsize, SEEK_END);
         $APEfooterID3v1 = fread($this->getid3->fp, $id3v1tagsize + $apetagheadersize + $lyrics3tagsize);
         //if (preg_match('/APETAGEX.{24}TAG.{125}$/i', $APEfooterID3v1)) {
         if (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $id3v1tagsize - $apetagheadersize, 8) == 'APETAGEX') {
             // APE tag found before ID3v1
             $info['ape']['tag_offset_end'] = $info['filesize'] - $id3v1tagsize;
             //} elseif (preg_match('/APETAGEX.{24}$/i', $APEfooterID3v1)) {
         } elseif (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $apetagheadersize, 8) == 'APETAGEX') {
             // APE tag found, no ID3v1
             $info['ape']['tag_offset_end'] = $info['filesize'];
         }
     } else {
         fseek($this->getid3->fp, $this->overrideendoffset - $apetagheadersize, SEEK_SET);
         if (fread($this->getid3->fp, 8) == 'APETAGEX') {
             $info['ape']['tag_offset_end'] = $this->overrideendoffset;
         }
     }
     if (!isset($info['ape']['tag_offset_end'])) {
         // APE tag not found
         unset($info['ape']);
         return false;
     }
     // shortcut
     $thisfile_ape =& $info['ape'];
     fseek($this->getid3->fp, $thisfile_ape['tag_offset_end'] - $apetagheadersize, SEEK_SET);
     $APEfooterData = fread($this->getid3->fp, 32);
     if (!($thisfile_ape['footer'] = $this->parseAPEheaderFooter($APEfooterData))) {
         $info['error'][] = 'Error parsing APE footer at offset ' . $thisfile_ape['tag_offset_end'];
         return false;
     }
     if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) {
         fseek($this->getid3->fp, $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'] - $apetagheadersize, SEEK_SET);
         $thisfile_ape['tag_offset_start'] = ftell($this->getid3->fp);
         $APEtagData = fread($this->getid3->fp, $thisfile_ape['footer']['raw']['tagsize'] + $apetagheadersize);
     } else {
         $thisfile_ape['tag_offset_start'] = $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'];
         fseek($this->getid3->fp, $thisfile_ape['tag_offset_start'], SEEK_SET);
         $APEtagData = fread($this->getid3->fp, $thisfile_ape['footer']['raw']['tagsize']);
     }
     $info['avdataend'] = $thisfile_ape['tag_offset_start'];
     if (isset($info['id3v1']['tag_offset_start']) && $info['id3v1']['tag_offset_start'] < $thisfile_ape['tag_offset_end']) {
         $info['warning'][] = 'ID3v1 tag information ignored since it appears to be a false synch in APEtag 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;
             }
         }
     }
     $offset = 0;
     if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) {
         if ($thisfile_ape['header'] = $this->parseAPEheaderFooter(substr($APEtagData, 0, $apetagheadersize))) {
             $offset += $apetagheadersize;
         } else {
             $info['error'][] = 'Error parsing APE header at offset ' . $thisfile_ape['tag_offset_start'];
             return false;
         }
     }
     // shortcut
     $info['replay_gain'] = array();
     $thisfile_replaygain =& $info['replay_gain'];
     for ($i = 0; $i < $thisfile_ape['footer']['raw']['tag_items']; ++$i) {
         $value_size = Helper::LittleEndian2Int(substr($APEtagData, $offset, 4));
         $offset += 4;
         $item_flags = Helper::LittleEndian2Int(substr($APEtagData, $offset, 4));
         $offset += 4;
         if (strstr(substr($APEtagData, $offset), "") === false) {
             $info['error'][] = 'Cannot find null-byte (0x00) seperator between ItemKey #' . $i . ' and value. ItemKey starts ' . $offset . ' bytes into the APE tag, at file offset ' . ($thisfile_ape['tag_offset_start'] + $offset);
             return false;
         }
         $ItemKeyLength = strpos($APEtagData, "", $offset) - $offset;
         $item_key = strtolower(substr($APEtagData, $offset, $ItemKeyLength));
         // shortcut
         $thisfile_ape['items'][$item_key] = array();
         $thisfile_ape_items_current =& $thisfile_ape['items'][$item_key];
         $thisfile_ape_items_current['offset'] = $thisfile_ape['tag_offset_start'] + $offset;
         $offset += $ItemKeyLength + 1;
         // skip 0x00 terminator
         $thisfile_ape_items_current['data'] = substr($APEtagData, $offset, $value_size);
         $offset += $value_size;
         $thisfile_ape_items_current['flags'] = $this->parseAPEtagFlags($item_flags);
         switch ($thisfile_ape_items_current['flags']['item_contents_raw']) {
             case 0:
                 // UTF-8
             // UTF-8
             case 3:
                 // Locator (URL, filename, etc), UTF-8 encoded
                 $thisfile_ape_items_current['data'] = explode("", trim($thisfile_ape_items_current['data']));
                 break;
             default:
                 // binary data
                 break;
         }
         switch (strtolower($item_key)) {
             case 'replaygain_track_gain':
                 $thisfile_replaygain['track']['adjustment'] = (double) str_replace(',', '.', $thisfile_ape_items_current['data'][0]);
                 // float casting will see "0,95" as zero!
                 $thisfile_replaygain['track']['originator'] = 'unspecified';
                 break;
             case 'replaygain_track_peak':
                 $thisfile_replaygain['track']['peak'] = (double) str_replace(',', '.', $thisfile_ape_items_current['data'][0]);
                 // float casting will see "0,95" as zero!
                 $thisfile_replaygain['track']['originator'] = 'unspecified';
                 if ($thisfile_replaygain['track']['peak'] <= 0) {
                     $info['warning'][] = 'ReplayGain Track peak from APEtag appears invalid: ' . $thisfile_replaygain['track']['peak'] . ' (original value = "' . $thisfile_ape_items_current['data'][0] . '")';
                 }
                 break;
             case 'replaygain_album_gain':
                 $thisfile_replaygain['album']['adjustment'] = (double) str_replace(',', '.', $thisfile_ape_items_current['data'][0]);
                 // float casting will see "0,95" as zero!
                 $thisfile_replaygain['album']['originator'] = 'unspecified';
                 break;
             case 'replaygain_album_peak':
                 $thisfile_replaygain['album']['peak'] = (double) str_replace(',', '.', $thisfile_ape_items_current['data'][0]);
                 // float casting will see "0,95" as zero!
                 $thisfile_replaygain['album']['originator'] = 'unspecified';
                 if ($thisfile_replaygain['album']['peak'] <= 0) {
                     $info['warning'][] = 'ReplayGain Album peak from APEtag appears invalid: ' . $thisfile_replaygain['album']['peak'] . ' (original value = "' . $thisfile_ape_items_current['data'][0] . '")';
                 }
                 break;
             case 'mp3gain_undo':
                 list($mp3gain_undo_left, $mp3gain_undo_right, $mp3gain_undo_wrap) = explode(',', $thisfile_ape_items_current['data'][0]);
                 $thisfile_replaygain['mp3gain']['undo_left'] = intval($mp3gain_undo_left);
                 $thisfile_replaygain['mp3gain']['undo_right'] = intval($mp3gain_undo_right);
                 $thisfile_replaygain['mp3gain']['undo_wrap'] = $mp3gain_undo_wrap == 'Y' ? true : false;
                 break;
             case 'mp3gain_minmax':
                 list($mp3gain_globalgain_min, $mp3gain_globalgain_max) = explode(',', $thisfile_ape_items_current['data'][0]);
                 $thisfile_replaygain['mp3gain']['globalgain_track_min'] = intval($mp3gain_globalgain_min);
                 $thisfile_replaygain['mp3gain']['globalgain_track_max'] = intval($mp3gain_globalgain_max);
                 break;
             case 'mp3gain_album_minmax':
                 list($mp3gain_globalgain_album_min, $mp3gain_globalgain_album_max) = explode(',', $thisfile_ape_items_current['data'][0]);
                 $thisfile_replaygain['mp3gain']['globalgain_album_min'] = intval($mp3gain_globalgain_album_min);
                 $thisfile_replaygain['mp3gain']['globalgain_album_max'] = intval($mp3gain_globalgain_album_max);
                 break;
             case 'tracknumber':
                 if (is_array($thisfile_ape_items_current['data'])) {
                     foreach ($thisfile_ape_items_current['data'] as $comment) {
                         $thisfile_ape['comments']['track'][] = $comment;
                     }
                 }
                 break;
             case 'cover art (artist)':
             case 'cover art (back)':
             case 'cover art (band logo)':
             case 'cover art (band)':
             case 'cover art (colored fish)':
             case 'cover art (composer)':
             case 'cover art (conductor)':
             case 'cover art (front)':
             case 'cover art (icon)':
             case 'cover art (illustration)':
             case 'cover art (lead)':
             case 'cover art (leaflet)':
             case 'cover art (lyricist)':
             case 'cover art (media)':
             case 'cover art (movie scene)':
             case 'cover art (other icon)':
             case 'cover art (other)':
             case 'cover art (performance)':
             case 'cover art (publisher logo)':
             case 'cover art (recording)':
             case 'cover art (studio)':
                 // list of possible cover arts from http://taglib-sharp.sourcearchive.com/documentation/2.0.3.0-2/Ape_2Tag_8cs-source.html
                 list($thisfile_ape_items_current['filename'], $thisfile_ape_items_current['data']) = explode("", $thisfile_ape_items_current['data'], 2);
                 $thisfile_ape_items_current['data_offset'] = $thisfile_ape_items_current['offset'] + strlen($thisfile_ape_items_current['filename'] . "");
                 $thisfile_ape_items_current['data_length'] = strlen($thisfile_ape_items_current['data']);
                 $thisfile_ape_items_current['image_mime'] = '';
                 $imageinfo = array();
                 $imagechunkcheck = Helper::GetDataImageSize($thisfile_ape_items_current['data'], $imageinfo);
                 $thisfile_ape_items_current['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]);
                 do {
                     if ($this->inline_attachments === false) {
                         // skip entirely
                         unset($thisfile_ape_items_current['data']);
                         break;
                     }
                     if ($this->inline_attachments === true) {
                         // great
                     } elseif (is_int($this->inline_attachments)) {
                         if ($this->inline_attachments < $thisfile_ape_items_current['data_length']) {
                             // too big, skip
                             $info['warning'][] = 'attachment at ' . $thisfile_ape_items_current['offset'] . ' is too large to process inline (' . number_format($thisfile_ape_items_current['data_length']) . ' bytes)';
                             unset($thisfile_ape_items_current['data']);
                             break;
                         }
                     } elseif (is_string($this->inline_attachments)) {
                         $this->inline_attachments = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->inline_attachments), DIRECTORY_SEPARATOR);
                         if (!is_dir($this->inline_attachments) || !is_writable($this->inline_attachments)) {
                             // cannot write, skip
                             $info['warning'][] = 'attachment at ' . $thisfile_ape_items_current['offset'] . ' cannot be saved to "' . $this->inline_attachments . '" (not writable)';
                             unset($thisfile_ape_items_current['data']);
                             break;
                         }
                     }
                     // if we get this far, must be OK
                     if (is_string($this->inline_attachments)) {
                         $destination_filename = $this->inline_attachments . DIRECTORY_SEPARATOR . md5($info['filenamepath']) . '_' . $thisfile_ape_items_current['data_offset'];
                         if (!file_exists($destination_filename) || is_writable($destination_filename)) {
                             file_put_contents($destination_filename, $thisfile_ape_items_current['data']);
                         } else {
                             $info['warning'][] = 'attachment at ' . $thisfile_ape_items_current['offset'] . ' cannot be saved to "' . $destination_filename . '" (not writable)';
                         }
                         $thisfile_ape_items_current['data_filename'] = $destination_filename;
                         unset($thisfile_ape_items_current['data']);
                     } else {
                         if (!isset($info['ape']['comments']['picture'])) {
                             $info['ape']['comments']['picture'] = array();
                         }
                         $info['ape']['comments']['picture'][] = array('data' => $thisfile_ape_items_current['data'], 'image_mime' => $thisfile_ape_items_current['image_mime']);
                     }
                 } while (false);
                 break;
             default:
                 if (is_array($thisfile_ape_items_current['data'])) {
                     foreach ($thisfile_ape_items_current['data'] as $comment) {
                         $thisfile_ape['comments'][strtolower($item_key)][] = $comment;
                     }
                 }
                 break;
         }
     }
     if (empty($thisfile_replaygain)) {
         unset($info['replay_gain']);
     }
     return true;
 }
Exemple #3
0
 public function ASF_WMpicture(&$data)
 {
     //typedef struct _WMPicture{
     //  LPWSTR  pwszMIMEType;
     //  BYTE  bPictureType;
     //  LPWSTR  pwszDescription;
     //  DWORD  dwDataLen;
     //  BYTE*  pbData;
     //} WM_PICTURE;
     $WMpicture = array();
     $offset = 0;
     $WMpicture['image_type_id'] = Helper::LittleEndian2Int(substr($data, $offset, 1));
     $offset += 1;
     $WMpicture['image_type'] = $this->WMpictureTypeLookup($WMpicture['image_type_id']);
     $WMpicture['image_size'] = Helper::LittleEndian2Int(substr($data, $offset, 4));
     $offset += 4;
     $WMpicture['image_mime'] = '';
     do {
         $next_byte_pair = substr($data, $offset, 2);
         $offset += 2;
         $WMpicture['image_mime'] .= $next_byte_pair;
     } while ($next_byte_pair !== "");
     $WMpicture['image_description'] = '';
     do {
         $next_byte_pair = substr($data, $offset, 2);
         $offset += 2;
         $WMpicture['image_description'] .= $next_byte_pair;
     } while ($next_byte_pair !== "");
     $WMpicture['dataoffset'] = $offset;
     $WMpicture['data'] = substr($data, $offset);
     $imageinfo = array();
     $WMpicture['image_mime'] = '';
     $imagechunkcheck = Helper::GetDataImageSize($WMpicture['data'], $imageinfo);
     unset($imageinfo);
     if (!empty($imagechunkcheck)) {
         $WMpicture['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]);
     }
     if (!isset($this->getid3->info['asf']['comments']['picture'])) {
         $this->getid3->info['asf']['comments']['picture'] = array();
     }
     $this->getid3->info['asf']['comments']['picture'][] = array('data' => $WMpicture['data'], 'image_mime' => $WMpicture['image_mime']);
     return $WMpicture;
 }
Exemple #4
0
 /**
  * @param  type    $parsedFrame
  *
  * @return bool
  */
 public function ParseID3v2Frame(&$parsedFrame)
 {
     // shortcuts
     $info =& $this->getid3->info;
     $id3v2_majorversion = $info['id3v2']['majorversion'];
     $parsedFrame['framenamelong'] = $this->FrameNameLongLookup($parsedFrame['frame_name']);
     if (empty($parsedFrame['framenamelong'])) {
         unset($parsedFrame['framenamelong']);
     }
     $parsedFrame['framenameshort'] = $this->FrameNameShortLookup($parsedFrame['frame_name']);
     if (empty($parsedFrame['framenameshort'])) {
         unset($parsedFrame['framenameshort']);
     }
     if ($id3v2_majorversion >= 3) {
         // frame flags are not part of the ID3v2.2 standard
         if ($id3v2_majorversion == 3) {
             //    Frame Header Flags
             //    %abc00000 %ijk00000
             $parsedFrame['flags']['TagAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x8000);
             // a - Tag alter preservation
             $parsedFrame['flags']['FileAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x4000);
             // b - File alter preservation
             $parsedFrame['flags']['ReadOnly'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x2000);
             // c - Read only
             $parsedFrame['flags']['compression'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x80);
             // i - Compression
             $parsedFrame['flags']['Encryption'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x40);
             // j - Encryption
             $parsedFrame['flags']['GroupingIdentity'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x20);
             // k - Grouping identity
         } elseif ($id3v2_majorversion == 4) {
             //    Frame Header Flags
             //    %0abc0000 %0h00kmnp
             $parsedFrame['flags']['TagAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x4000);
             // a - Tag alter preservation
             $parsedFrame['flags']['FileAlterPreservation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x2000);
             // b - File alter preservation
             $parsedFrame['flags']['ReadOnly'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x1000);
             // c - Read only
             $parsedFrame['flags']['GroupingIdentity'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x40);
             // h - Grouping identity
             $parsedFrame['flags']['compression'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x8);
             // k - Compression
             $parsedFrame['flags']['Encryption'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x4);
             // m - Encryption
             $parsedFrame['flags']['Unsynchronisation'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x2);
             // n - Unsynchronisation
             $parsedFrame['flags']['DataLengthIndicator'] = (bool) ($parsedFrame['frame_flags_raw'] & 0x1);
             // p - Data length indicator
             // Frame-level de-unsynchronisation - ID3v2.4
             if ($parsedFrame['flags']['Unsynchronisation']) {
                 $parsedFrame['data'] = $this->DeUnsynchronise($parsedFrame['data']);
             }
             if ($parsedFrame['flags']['DataLengthIndicator']) {
                 $parsedFrame['data_length_indicator'] = Helper::BigEndian2Int(substr($parsedFrame['data'], 0, 4), 1);
                 $parsedFrame['data'] = substr($parsedFrame['data'], 4);
             }
         }
         //    Frame-level de-compression
         if ($parsedFrame['flags']['compression']) {
             $parsedFrame['decompressed_size'] = Helper::BigEndian2Int(substr($parsedFrame['data'], 0, 4));
             if (!function_exists('gzuncompress')) {
                 $info['warning'][] = 'gzuncompress() support required to decompress ID3v2 frame "' . $parsedFrame['frame_name'] . '"';
             } else {
                 if ($decompresseddata = @gzuncompress(substr($parsedFrame['data'], 4))) {
                     //if ($decompresseddata = @gzuncompress($parsedFrame['data'])) {
                     $parsedFrame['data'] = $decompresseddata;
                     unset($decompresseddata);
                 } else {
                     $info['warning'][] = 'gzuncompress() failed on compressed contents of ID3v2 frame "' . $parsedFrame['frame_name'] . '"';
                 }
             }
         }
     }
     if (!empty($parsedFrame['flags']['DataLengthIndicator'])) {
         if ($parsedFrame['data_length_indicator'] != strlen($parsedFrame['data'])) {
             $info['warning'][] = 'ID3v2 frame "' . $parsedFrame['frame_name'] . '" should be ' . $parsedFrame['data_length_indicator'] . ' bytes long according to DataLengthIndicator, but found ' . strlen($parsedFrame['data']) . ' bytes of data';
         }
     }
     if (isset($parsedFrame['datalength']) && $parsedFrame['datalength'] == 0) {
         $warning = 'Frame "' . $parsedFrame['frame_name'] . '" at offset ' . $parsedFrame['dataoffset'] . ' has no data portion';
         switch ($parsedFrame['frame_name']) {
             case 'WCOM':
                 $warning .= ' (this is known to happen with files tagged by RioPort)';
                 break;
             default:
                 break;
         }
         $info['warning'][] = $warning;
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'UFID' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'UFI') {
         // 4.1   UFI  Unique file identifier
         //   There may be more than one 'UFID' frame in a tag,
         //   but only one with the same 'Owner identifier'.
         // <Header for 'Unique file identifier', ID: 'UFID'>
         // Owner identifier        <text string> $00
         // Identifier              <up to 64 bytes binary data>
         $exploded = explode("", $parsedFrame['data'], 2);
         $parsedFrame['ownerid'] = isset($exploded[0]) ? $exploded[0] : '';
         $parsedFrame['data'] = isset($exploded[1]) ? $exploded[1] : '';
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'TXXX' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'TXX') {
         // 4.2.2 TXX  User defined text information frame
         //   There may be more than one 'TXXX' frame in each tag,
         //   but only one with the same description.
         // <Header for 'User defined text information frame', ID: 'TXXX'>
         // Text encoding     $xx
         // Description       <text string according to encoding> $00 (00)
         // Value             <text string according to encoding>
         $frame_offset = 0;
         $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         if ($id3v2_majorversion <= 3 && $frame_textencoding > 1 || $id3v2_majorversion == 4 && $frame_textencoding > 3) {
             $info['warning'][] = 'Invalid text encoding byte (' . $frame_textencoding . ') in frame "' . $parsedFrame['frame_name'] . '" - defaulting to ISO-8859-1 encoding';
         }
         $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
         if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
             ++$frame_terminatorpos;
             // strpos() fooled because 2nd byte of Unicode chars are often 0x00
         }
         $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_description) === 0) {
             $frame_description = '';
         }
         $parsedFrame['encodingid'] = $frame_textencoding;
         $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
         $parsedFrame['description'] = $frame_description;
         $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)));
         if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
             $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = trim(Helper::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']));
         }
         //unset($parsedFrame['data']); do not unset, may be needed elsewhere, e.g. for replaygain
     } elseif ($parsedFrame['frame_name'][0] == 'T') {
         // 4.2. T??[?] Text information frame
         //   There may only be one text information frame of its kind in an tag.
         // <Header for 'Text information frame', ID: 'T000' - 'TZZZ',
         // excluding 'TXXX' described in 4.2.6.>
         // Text encoding                $xx
         // Information                  <text string(s) according to encoding>
         $frame_offset = 0;
         $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         if ($id3v2_majorversion <= 3 && $frame_textencoding > 1 || $id3v2_majorversion == 4 && $frame_textencoding > 3) {
             $info['warning'][] = 'Invalid text encoding byte (' . $frame_textencoding . ') in frame "' . $parsedFrame['frame_name'] . '" - defaulting to ISO-8859-1 encoding';
         }
         $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
         $parsedFrame['encodingid'] = $frame_textencoding;
         $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
         if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
             $string = Helper::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']);
             $string = rtrim($string, "");
             // remove possible terminating null (put by encoding id or software bug)
             $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $string;
             unset($string);
         }
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'WXXX' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'WXX') {
         // 4.3.2 WXX  User defined URL link frame
         //   There may be more than one 'WXXX' frame in each tag,
         //   but only one with the same description
         // <Header for 'User defined URL link frame', ID: 'WXXX'>
         // Text encoding     $xx
         // Description       <text string according to encoding> $00 (00)
         // URL               <text string>
         $frame_offset = 0;
         $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         if ($id3v2_majorversion <= 3 && $frame_textencoding > 1 || $id3v2_majorversion == 4 && $frame_textencoding > 3) {
             $info['warning'][] = 'Invalid text encoding byte (' . $frame_textencoding . ') in frame "' . $parsedFrame['frame_name'] . '" - defaulting to ISO-8859-1 encoding';
         }
         $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
         if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
             ++$frame_terminatorpos;
             // strpos() fooled because 2nd byte of Unicode chars are often 0x00
         }
         $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_description) === 0) {
             $frame_description = '';
         }
         $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)));
         $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding));
         if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
             ++$frame_terminatorpos;
             // strpos() fooled because 2nd byte of Unicode chars are often 0x00
         }
         if ($frame_terminatorpos) {
             // there are null bytes after the data - this is not according to spec
             // only use data up to first null byte
             $frame_urldata = (string) substr($parsedFrame['data'], 0, $frame_terminatorpos);
         } else {
             // no null bytes following data, just use all data
             $frame_urldata = (string) $parsedFrame['data'];
         }
         $parsedFrame['encodingid'] = $frame_textencoding;
         $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
         $parsedFrame['url'] = $frame_urldata;
         $parsedFrame['description'] = $frame_description;
         if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) {
             $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = Helper::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['url']);
         }
         unset($parsedFrame['data']);
     } elseif ($parsedFrame['frame_name'][0] == 'W') {
         // 4.3. W??? URL link frames
         //   There may only be one URL link frame of its kind in a tag,
         //   except when stated otherwise in the frame description
         // <Header for 'URL link frame', ID: 'W000' - 'WZZZ', excluding 'WXXX'
         // described in 4.3.2.>
         // URL              <text string>
         $parsedFrame['url'] = trim($parsedFrame['data']);
         if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) {
             $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['url'];
         }
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion == 3 && $parsedFrame['frame_name'] == 'IPLS' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'IPL') {
         // 4.4  IPL  Involved people list (ID3v2.2 only)
         //   There may only be one 'IPL' frame in each tag
         // <Header for 'User defined URL link frame', ID: 'IPL'>
         // Text encoding     $xx
         // People list strings    <textstrings>
         $frame_offset = 0;
         $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         if ($id3v2_majorversion <= 3 && $frame_textencoding > 1 || $id3v2_majorversion == 4 && $frame_textencoding > 3) {
             $info['warning'][] = 'Invalid text encoding byte (' . $frame_textencoding . ') in frame "' . $parsedFrame['frame_name'] . '" - defaulting to ISO-8859-1 encoding';
         }
         $parsedFrame['encodingid'] = $frame_textencoding;
         $parsedFrame['encoding'] = $this->TextEncodingNameLookup($parsedFrame['encodingid']);
         $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
         if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
             $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = Helper::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']);
         }
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'MCDI' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'MCI') {
         // 4.5   MCI  Music CD identifier
         //   There may only be one 'MCDI' frame in each tag
         // <Header for 'Music CD identifier', ID: 'MCDI'>
         // CD TOC                <binary data>
         if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
             $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = $parsedFrame['data'];
         }
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'ETCO' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'ETC') {
         // 4.6   ETC  Event timing codes
         //   There may only be one 'ETCO' frame in each tag
         // <Header for 'Event timing codes', ID: 'ETCO'>
         // Time stamp format    $xx
         //   Where time stamp format is:
         // $01  (32-bit value) MPEG frames from beginning of file
         // $02  (32-bit value) milliseconds from beginning of file
         //   Followed by a list of key events in the following format:
         // Type of event   $xx
         // Time stamp      $xx (xx ...)
         //   The 'Time stamp' is set to zero if directly at the beginning of the sound
         //   or after the previous event. All events MUST be sorted in chronological order.
         $frame_offset = 0;
         $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         while ($frame_offset < strlen($parsedFrame['data'])) {
             $parsedFrame['typeid'] = substr($parsedFrame['data'], $frame_offset++, 1);
             $parsedFrame['type'] = $this->ETCOEventLookup($parsedFrame['typeid']);
             $parsedFrame['timestamp'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
             $frame_offset += 4;
         }
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'MLLT' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'MLL') {
         // 4.7   MLL MPEG location lookup table
         //   There may only be one 'MLLT' frame in each tag
         // <Header for 'Location lookup table', ID: 'MLLT'>
         // MPEG frames between reference  $xx xx
         // Bytes between reference        $xx xx xx
         // Milliseconds between reference $xx xx xx
         // Bits for bytes deviation       $xx
         // Bits for milliseconds dev.     $xx
         //   Then for every reference the following data is included;
         // Deviation in bytes         %xxx....
         // Deviation in milliseconds  %xxx....
         $frame_offset = 0;
         $parsedFrame['framesbetweenreferences'] = Helper::BigEndian2Int(substr($parsedFrame['data'], 0, 2));
         $parsedFrame['bytesbetweenreferences'] = Helper::BigEndian2Int(substr($parsedFrame['data'], 2, 3));
         $parsedFrame['msbetweenreferences'] = Helper::BigEndian2Int(substr($parsedFrame['data'], 5, 3));
         $parsedFrame['bitsforbytesdeviation'] = Helper::BigEndian2Int(substr($parsedFrame['data'], 8, 1));
         $parsedFrame['bitsformsdeviation'] = Helper::BigEndian2Int(substr($parsedFrame['data'], 9, 1));
         $parsedFrame['data'] = substr($parsedFrame['data'], 10);
         while ($frame_offset < strlen($parsedFrame['data'])) {
             $deviationbitstream .= Helper::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1));
         }
         $reference_counter = 0;
         while (strlen($deviationbitstream) > 0) {
             $parsedFrame[$reference_counter]['bytedeviation'] = bindec(substr($deviationbitstream, 0, $parsedFrame['bitsforbytesdeviation']));
             $parsedFrame[$reference_counter]['msdeviation'] = bindec(substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'], $parsedFrame['bitsformsdeviation']));
             $deviationbitstream = substr($deviationbitstream, $parsedFrame['bitsforbytesdeviation'] + $parsedFrame['bitsformsdeviation']);
             ++$reference_counter;
         }
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'SYTC' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'STC') {
         // 4.8   STC  Synchronised tempo codes
         //   There may only be one 'SYTC' frame in each tag
         // <Header for 'Synchronised tempo codes', ID: 'SYTC'>
         // Time stamp format   $xx
         // Tempo data          <binary data>
         //   Where time stamp format is:
         // $01  (32-bit value) MPEG frames from beginning of file
         // $02  (32-bit value) milliseconds from beginning of file
         $frame_offset = 0;
         $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $timestamp_counter = 0;
         while ($frame_offset < strlen($parsedFrame['data'])) {
             $parsedFrame[$timestamp_counter]['tempo'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
             if ($parsedFrame[$timestamp_counter]['tempo'] == 255) {
                 $parsedFrame[$timestamp_counter]['tempo'] += ord(substr($parsedFrame['data'], $frame_offset++, 1));
             }
             $parsedFrame[$timestamp_counter]['timestamp'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
             $frame_offset += 4;
             ++$timestamp_counter;
         }
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'USLT' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'ULT') {
         // 4.9   ULT  Unsynchronised lyric/text transcription
         //   There may be more than one 'Unsynchronised lyrics/text transcription' frame
         //   in each tag, but only one with the same language and content descriptor.
         // <Header for 'Unsynchronised lyrics/text transcription', ID: 'USLT'>
         // Text encoding        $xx
         // Language             $xx xx xx
         // Content descriptor   <text string according to encoding> $00 (00)
         // Lyrics/text          <full text string according to encoding>
         $frame_offset = 0;
         $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         if ($id3v2_majorversion <= 3 && $frame_textencoding > 1 || $id3v2_majorversion == 4 && $frame_textencoding > 3) {
             $info['warning'][] = 'Invalid text encoding byte (' . $frame_textencoding . ') in frame "' . $parsedFrame['frame_name'] . '" - defaulting to ISO-8859-1 encoding';
         }
         $frame_language = substr($parsedFrame['data'], $frame_offset, 3);
         $frame_offset += 3;
         $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
         if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
             ++$frame_terminatorpos;
             // strpos() fooled because 2nd byte of Unicode chars are often 0x00
         }
         $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_description) === 0) {
             $frame_description = '';
         }
         $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)));
         $parsedFrame['encodingid'] = $frame_textencoding;
         $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
         $parsedFrame['data'] = $parsedFrame['data'];
         $parsedFrame['language'] = $frame_language;
         $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false);
         $parsedFrame['description'] = $frame_description;
         if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
             $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = Helper::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']);
         }
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'SYLT' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'SLT') {
         // 4.10  SLT  Synchronised lyric/text
         //   There may be more than one 'SYLT' frame in each tag,
         //   but only one with the same language and content descriptor.
         // <Header for 'Synchronised lyrics/text', ID: 'SYLT'>
         // Text encoding        $xx
         // Language             $xx xx xx
         // Time stamp format    $xx
         //   $01  (32-bit value) MPEG frames from beginning of file
         //   $02  (32-bit value) milliseconds from beginning of file
         // Content type         $xx
         // Content descriptor   <text string according to encoding> $00 (00)
         //   Terminated text to be synced (typically a syllable)
         //   Sync identifier (terminator to above string)   $00 (00)
         //   Time stamp                                     $xx (xx ...)
         $frame_offset = 0;
         $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         if ($id3v2_majorversion <= 3 && $frame_textencoding > 1 || $id3v2_majorversion == 4 && $frame_textencoding > 3) {
             $info['warning'][] = 'Invalid text encoding byte (' . $frame_textencoding . ') in frame "' . $parsedFrame['frame_name'] . '" - defaulting to ISO-8859-1 encoding';
         }
         $frame_language = substr($parsedFrame['data'], $frame_offset, 3);
         $frame_offset += 3;
         $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['contenttypeid'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['contenttype'] = $this->SYTLContentTypeLookup($parsedFrame['contenttypeid']);
         $parsedFrame['encodingid'] = $frame_textencoding;
         $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
         $parsedFrame['language'] = $frame_language;
         $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false);
         $timestampindex = 0;
         $frame_remainingdata = substr($parsedFrame['data'], $frame_offset);
         while (strlen($frame_remainingdata)) {
             $frame_offset = 0;
             $frame_terminatorpos = strpos($frame_remainingdata, $this->TextEncodingTerminatorLookup($frame_textencoding));
             if ($frame_terminatorpos === false) {
                 $frame_remainingdata = '';
             } else {
                 if (ord(substr($frame_remainingdata, $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
                     ++$frame_terminatorpos;
                     // strpos() fooled because 2nd byte of Unicode chars are often 0x00
                 }
                 $parsedFrame['lyrics'][$timestampindex]['data'] = substr($frame_remainingdata, $frame_offset, $frame_terminatorpos - $frame_offset);
                 $frame_remainingdata = substr($frame_remainingdata, $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)));
                 if ($timestampindex == 0 && ord($frame_remainingdata[0]) != 0) {
                     // timestamp probably omitted for first data item
                 } else {
                     $parsedFrame['lyrics'][$timestampindex]['timestamp'] = Helper::BigEndian2Int(substr($frame_remainingdata, 0, 4));
                     $frame_remainingdata = substr($frame_remainingdata, 4);
                 }
                 ++$timestampindex;
             }
         }
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'COMM' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'COM') {
         // 4.11  COM  Comments
         //   There may be more than one comment frame in each tag,
         //   but only one with the same language and content descriptor.
         // <Header for 'Comment', ID: 'COMM'>
         // Text encoding          $xx
         // Language               $xx xx xx
         // Short content descrip. <text string according to encoding> $00 (00)
         // The actual text        <full text string according to encoding>
         if (strlen($parsedFrame['data']) < 5) {
             $info['warning'][] = 'Invalid data (too short) for "' . $parsedFrame['frame_name'] . '" frame at offset ' . $parsedFrame['dataoffset'];
         } else {
             $frame_offset = 0;
             $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
             if ($id3v2_majorversion <= 3 && $frame_textencoding > 1 || $id3v2_majorversion == 4 && $frame_textencoding > 3) {
                 $info['warning'][] = 'Invalid text encoding byte (' . $frame_textencoding . ') in frame "' . $parsedFrame['frame_name'] . '" - defaulting to ISO-8859-1 encoding';
             }
             $frame_language = substr($parsedFrame['data'], $frame_offset, 3);
             $frame_offset += 3;
             $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
             if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
                 ++$frame_terminatorpos;
                 // strpos() fooled because 2nd byte of Unicode chars are often 0x00
             }
             $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
             if (ord($frame_description) === 0) {
                 $frame_description = '';
             }
             $frame_text = (string) substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)));
             $parsedFrame['encodingid'] = $frame_textencoding;
             $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
             $parsedFrame['language'] = $frame_language;
             $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false);
             $parsedFrame['description'] = $frame_description;
             $parsedFrame['data'] = $frame_text;
             if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
                 $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = Helper::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']);
             }
         }
     } elseif ($id3v2_majorversion >= 4 && $parsedFrame['frame_name'] == 'RVA2') {
         // 4.11  RVA2 Relative volume adjustment (2) (ID3v2.4+ only)
         //   There may be more than one 'RVA2' frame in each tag,
         //   but only one with the same identification string
         // <Header for 'Relative volume adjustment (2)', ID: 'RVA2'>
         // Identification          <text string> $00
         //   The 'identification' string is used to identify the situation and/or
         //   device where this adjustment should apply. The following is then
         //   repeated for every channel:
         // Type of channel         $xx
         // Volume adjustment       $xx xx
         // Bits representing peak  $xx
         // Peak volume             $xx (xx ...)
         $frame_terminatorpos = strpos($parsedFrame['data'], "");
         $frame_idstring = substr($parsedFrame['data'], 0, $frame_terminatorpos);
         if (ord($frame_idstring) === 0) {
             $frame_idstring = '';
         }
         $frame_remainingdata = substr($parsedFrame['data'], $frame_terminatorpos + strlen(""));
         $parsedFrame['description'] = $frame_idstring;
         $RVA2channelcounter = 0;
         while (strlen($frame_remainingdata) >= 5) {
             $frame_offset = 0;
             $frame_channeltypeid = ord(substr($frame_remainingdata, $frame_offset++, 1));
             $parsedFrame[$RVA2channelcounter]['channeltypeid'] = $frame_channeltypeid;
             $parsedFrame[$RVA2channelcounter]['channeltype'] = $this->RVA2ChannelTypeLookup($frame_channeltypeid);
             $parsedFrame[$RVA2channelcounter]['volumeadjust'] = Helper::BigEndian2Int(substr($frame_remainingdata, $frame_offset, 2), false, true);
             // 16-bit signed
             $frame_offset += 2;
             $parsedFrame[$RVA2channelcounter]['bitspeakvolume'] = ord(substr($frame_remainingdata, $frame_offset++, 1));
             if ($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] < 1 || $parsedFrame[$RVA2channelcounter]['bitspeakvolume'] > 4) {
                 $info['warning'][] = 'ID3v2::RVA2 frame[' . $RVA2channelcounter . '] contains invalid ' . $parsedFrame[$RVA2channelcounter]['bitspeakvolume'] . '-byte bits-representing-peak value';
                 break;
             }
             $frame_bytespeakvolume = ceil($parsedFrame[$RVA2channelcounter]['bitspeakvolume'] / 8);
             $parsedFrame[$RVA2channelcounter]['peakvolume'] = Helper::BigEndian2Int(substr($frame_remainingdata, $frame_offset, $frame_bytespeakvolume));
             $frame_remainingdata = substr($frame_remainingdata, $frame_offset + $frame_bytespeakvolume);
             ++$RVA2channelcounter;
         }
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion == 3 && $parsedFrame['frame_name'] == 'RVAD' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'RVA') {
         // 4.12  RVA  Relative volume adjustment (ID3v2.2 only)
         //   There may only be one 'RVA' frame in each tag
         // <Header for 'Relative volume adjustment', ID: 'RVA'>
         // ID3v2.2 => Increment/decrement     %000000ba
         // ID3v2.3 => Increment/decrement     %00fedcba
         // Bits used for volume descr.        $xx
         // Relative volume change, right      $xx xx (xx ...) // a
         // Relative volume change, left       $xx xx (xx ...) // b
         // Peak volume right                  $xx xx (xx ...)
         // Peak volume left                   $xx xx (xx ...)
         //   ID3v2.3 only, optional (not present in ID3v2.2):
         // Relative volume change, right back $xx xx (xx ...) // c
         // Relative volume change, left back  $xx xx (xx ...) // d
         // Peak volume right back             $xx xx (xx ...)
         // Peak volume left back              $xx xx (xx ...)
         //   ID3v2.3 only, optional (not present in ID3v2.2):
         // Relative volume change, center     $xx xx (xx ...) // e
         // Peak volume center                 $xx xx (xx ...)
         //   ID3v2.3 only, optional (not present in ID3v2.2):
         // Relative volume change, bass       $xx xx (xx ...) // f
         // Peak volume bass                   $xx xx (xx ...)
         $frame_offset = 0;
         $frame_incrdecrflags = Helper::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['incdec']['right'] = (bool) substr($frame_incrdecrflags, 6, 1);
         $parsedFrame['incdec']['left'] = (bool) substr($frame_incrdecrflags, 7, 1);
         $parsedFrame['bitsvolume'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $frame_bytesvolume = ceil($parsedFrame['bitsvolume'] / 8);
         $parsedFrame['volumechange']['right'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
         if ($parsedFrame['incdec']['right'] === false) {
             $parsedFrame['volumechange']['right'] *= -1;
         }
         $frame_offset += $frame_bytesvolume;
         $parsedFrame['volumechange']['left'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
         if ($parsedFrame['incdec']['left'] === false) {
             $parsedFrame['volumechange']['left'] *= -1;
         }
         $frame_offset += $frame_bytesvolume;
         $parsedFrame['peakvolume']['right'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
         $frame_offset += $frame_bytesvolume;
         $parsedFrame['peakvolume']['left'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
         $frame_offset += $frame_bytesvolume;
         if ($id3v2_majorversion == 3) {
             $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset);
             if (strlen($parsedFrame['data']) > 0) {
                 $parsedFrame['incdec']['rightrear'] = (bool) substr($frame_incrdecrflags, 4, 1);
                 $parsedFrame['incdec']['leftrear'] = (bool) substr($frame_incrdecrflags, 5, 1);
                 $parsedFrame['volumechange']['rightrear'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
                 if ($parsedFrame['incdec']['rightrear'] === false) {
                     $parsedFrame['volumechange']['rightrear'] *= -1;
                 }
                 $frame_offset += $frame_bytesvolume;
                 $parsedFrame['volumechange']['leftrear'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
                 if ($parsedFrame['incdec']['leftrear'] === false) {
                     $parsedFrame['volumechange']['leftrear'] *= -1;
                 }
                 $frame_offset += $frame_bytesvolume;
                 $parsedFrame['peakvolume']['rightrear'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
                 $frame_offset += $frame_bytesvolume;
                 $parsedFrame['peakvolume']['leftrear'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
                 $frame_offset += $frame_bytesvolume;
             }
             $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset);
             if (strlen($parsedFrame['data']) > 0) {
                 $parsedFrame['incdec']['center'] = (bool) substr($frame_incrdecrflags, 3, 1);
                 $parsedFrame['volumechange']['center'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
                 if ($parsedFrame['incdec']['center'] === false) {
                     $parsedFrame['volumechange']['center'] *= -1;
                 }
                 $frame_offset += $frame_bytesvolume;
                 $parsedFrame['peakvolume']['center'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
                 $frame_offset += $frame_bytesvolume;
             }
             $parsedFrame['data'] = substr($parsedFrame['data'], $frame_offset);
             if (strlen($parsedFrame['data']) > 0) {
                 $parsedFrame['incdec']['bass'] = (bool) substr($frame_incrdecrflags, 2, 1);
                 $parsedFrame['volumechange']['bass'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
                 if ($parsedFrame['incdec']['bass'] === false) {
                     $parsedFrame['volumechange']['bass'] *= -1;
                 }
                 $frame_offset += $frame_bytesvolume;
                 $parsedFrame['peakvolume']['bass'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesvolume));
                 $frame_offset += $frame_bytesvolume;
             }
         }
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 4 && $parsedFrame['frame_name'] == 'EQU2') {
         // 4.12  EQU2 Equalisation (2) (ID3v2.4+ only)
         //   There may be more than one 'EQU2' frame in each tag,
         //   but only one with the same identification string
         // <Header of 'Equalisation (2)', ID: 'EQU2'>
         // Interpolation method  $xx
         //   $00  Band
         //   $01  Linear
         // Identification        <text string> $00
         //   The following is then repeated for every adjustment point
         // Frequency          $xx xx
         // Volume adjustment  $xx xx
         $frame_offset = 0;
         $frame_interpolationmethod = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
         $frame_idstring = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_idstring) === 0) {
             $frame_idstring = '';
         }
         $parsedFrame['description'] = $frame_idstring;
         $frame_remainingdata = substr($parsedFrame['data'], $frame_terminatorpos + strlen(""));
         while (strlen($frame_remainingdata)) {
             $frame_frequency = Helper::BigEndian2Int(substr($frame_remainingdata, 0, 2)) / 2;
             $parsedFrame['data'][$frame_frequency] = Helper::BigEndian2Int(substr($frame_remainingdata, 2, 2), false, true);
             $frame_remainingdata = substr($frame_remainingdata, 4);
         }
         $parsedFrame['interpolationmethod'] = $frame_interpolationmethod;
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion == 3 && $parsedFrame['frame_name'] == 'EQUA' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'EQU') {
         // 4.13  EQU  Equalisation (ID3v2.2 only)
         //   There may only be one 'EQUA' frame in each tag
         // <Header for 'Relative volume adjustment', ID: 'EQU'>
         // Adjustment bits    $xx
         //   This is followed by 2 bytes + ('adjustment bits' rounded up to the
         //   nearest byte) for every equalisation band in the following format,
         //   giving a frequency range of 0 - 32767Hz:
         // Increment/decrement   %x (MSB of the Frequency)
         // Frequency             (lower 15 bits)
         // Adjustment            $xx (xx ...)
         $frame_offset = 0;
         $parsedFrame['adjustmentbits'] = substr($parsedFrame['data'], $frame_offset++, 1);
         $frame_adjustmentbytes = ceil($parsedFrame['adjustmentbits'] / 8);
         $frame_remainingdata = (string) substr($parsedFrame['data'], $frame_offset);
         while (strlen($frame_remainingdata) > 0) {
             $frame_frequencystr = Helper::BigEndian2Bin(substr($frame_remainingdata, 0, 2));
             $frame_incdec = (bool) substr($frame_frequencystr, 0, 1);
             $frame_frequency = bindec(substr($frame_frequencystr, 1, 15));
             $parsedFrame[$frame_frequency]['incdec'] = $frame_incdec;
             $parsedFrame[$frame_frequency]['adjustment'] = Helper::BigEndian2Int(substr($frame_remainingdata, 2, $frame_adjustmentbytes));
             if ($parsedFrame[$frame_frequency]['incdec'] === false) {
                 $parsedFrame[$frame_frequency]['adjustment'] *= -1;
             }
             $frame_remainingdata = substr($frame_remainingdata, 2 + $frame_adjustmentbytes);
         }
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'RVRB' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'REV') {
         // 4.14  REV  Reverb
         //   There may only be one 'RVRB' frame in each tag.
         // <Header for 'Reverb', ID: 'RVRB'>
         // Reverb left (ms)                 $xx xx
         // Reverb right (ms)                $xx xx
         // Reverb bounces, left             $xx
         // Reverb bounces, right            $xx
         // Reverb feedback, left to left    $xx
         // Reverb feedback, left to right   $xx
         // Reverb feedback, right to right  $xx
         // Reverb feedback, right to left   $xx
         // Premix left to right             $xx
         // Premix right to left             $xx
         $frame_offset = 0;
         $parsedFrame['left'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2));
         $frame_offset += 2;
         $parsedFrame['right'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2));
         $frame_offset += 2;
         $parsedFrame['bouncesL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['bouncesR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['feedbackLL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['feedbackLR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['feedbackRR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['feedbackRL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['premixLR'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['premixRL'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'APIC' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'PIC') {
         // 4.15  PIC  Attached picture
         //   There may be several pictures attached to one file,
         //   each in their individual 'APIC' frame, but only one
         //   with the same content descriptor
         // <Header for 'Attached picture', ID: 'APIC'>
         // Text encoding      $xx
         // ID3v2.3+ => MIME type          <text string> $00
         // ID3v2.2  => Image format       $xx xx xx
         // Picture type       $xx
         // Description        <text string according to encoding> $00 (00)
         // Picture data       <binary data>
         $frame_offset = 0;
         $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         if ($id3v2_majorversion <= 3 && $frame_textencoding > 1 || $id3v2_majorversion == 4 && $frame_textencoding > 3) {
             $info['warning'][] = 'Invalid text encoding byte (' . $frame_textencoding . ') in frame "' . $parsedFrame['frame_name'] . '" - defaulting to ISO-8859-1 encoding';
         }
         if ($id3v2_majorversion == 2 && strlen($parsedFrame['data']) > $frame_offset) {
             $frame_imagetype = substr($parsedFrame['data'], $frame_offset, 3);
             if (strtolower($frame_imagetype) == 'ima') {
                 // complete hack for mp3Rage (www.chaoticsoftware.com) that puts ID3v2.3-formatted
                 // MIME type instead of 3-char ID3v2.2-format image type  (thanks xbhoffØpacbell*net)
                 $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
                 $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
                 if (ord($frame_mimetype) === 0) {
                     $frame_mimetype = '';
                 }
                 $frame_imagetype = strtoupper(str_replace('image/', '', strtolower($frame_mimetype)));
                 if ($frame_imagetype == 'JPEG') {
                     $frame_imagetype = 'JPG';
                 }
                 $frame_offset = $frame_terminatorpos + strlen("");
             } else {
                 $frame_offset += 3;
             }
         }
         if ($id3v2_majorversion > 2 && strlen($parsedFrame['data']) > $frame_offset) {
             $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
             $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
             if (ord($frame_mimetype) === 0) {
                 $frame_mimetype = '';
             }
             $frame_offset = $frame_terminatorpos + strlen("");
         }
         $frame_picturetype = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         if ($frame_offset >= $parsedFrame['datalength']) {
             $info['warning'][] = 'data portion of APIC frame is missing at offset ' . ($parsedFrame['dataoffset'] + 8 + $frame_offset);
         } else {
             $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
             if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
                 ++$frame_terminatorpos;
                 // strpos() fooled because 2nd byte of Unicode chars are often 0x00
             }
             $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
             if (ord($frame_description) === 0) {
                 $frame_description = '';
             }
             $parsedFrame['encodingid'] = $frame_textencoding;
             $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
             if ($id3v2_majorversion == 2) {
                 $parsedFrame['imagetype'] = $frame_imagetype;
             } else {
                 $parsedFrame['mime'] = $frame_mimetype;
             }
             $parsedFrame['picturetypeid'] = $frame_picturetype;
             $parsedFrame['picturetype'] = $this->APICPictureTypeLookup($frame_picturetype);
             $parsedFrame['description'] = $frame_description;
             $parsedFrame['data'] = substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)));
             $parsedFrame['datalength'] = strlen($parsedFrame['data']);
             $parsedFrame['image_mime'] = '';
             $imageinfo = array();
             $imagechunkcheck = Helper::GetDataImageSize($parsedFrame['data'], $imageinfo);
             if ($imagechunkcheck[2] >= 1 && $imagechunkcheck[2] <= 3) {
                 $parsedFrame['image_mime'] = 'image/' . Helper::ImageTypesLookup($imagechunkcheck[2]);
                 if ($imagechunkcheck[0]) {
                     $parsedFrame['image_width'] = $imagechunkcheck[0];
                 }
                 if ($imagechunkcheck[1]) {
                     $parsedFrame['image_height'] = $imagechunkcheck[1];
                 }
             }
             do {
                 if ($this->inline_attachments === false) {
                     // skip entirely
                     unset($parsedFrame['data']);
                     break;
                 }
                 if ($this->inline_attachments === true) {
                     // great
                 } elseif (is_int($this->inline_attachments)) {
                     if ($this->inline_attachments < $parsedFrame['data_length']) {
                         // too big, skip
                         $info['warning'][] = 'attachment at ' . $frame_offset . ' is too large to process inline (' . number_format($parsedFrame['data_length']) . ' bytes)';
                         unset($parsedFrame['data']);
                         break;
                     }
                 } elseif (is_string($this->inline_attachments)) {
                     $this->inline_attachments = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->inline_attachments), DIRECTORY_SEPARATOR);
                     if (!is_dir($this->inline_attachments) || !is_writable($this->inline_attachments)) {
                         // cannot write, skip
                         $info['warning'][] = 'attachment at ' . $frame_offset . ' cannot be saved to "' . $this->inline_attachments . '" (not writable)';
                         unset($parsedFrame['data']);
                         break;
                     }
                 }
                 // if we get this far, must be OK
                 if (is_string($this->inline_attachments)) {
                     $destination_filename = $this->inline_attachments . DIRECTORY_SEPARATOR . md5($info['filenamepath']) . '_' . $frame_offset;
                     if (!file_exists($destination_filename) || is_writable($destination_filename)) {
                         file_put_contents($destination_filename, $parsedFrame['data']);
                     } else {
                         $info['warning'][] = 'attachment at ' . $frame_offset . ' cannot be saved to "' . $destination_filename . '" (not writable)';
                     }
                     $parsedFrame['data_filename'] = $destination_filename;
                     unset($parsedFrame['data']);
                 } else {
                     if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
                         if (!isset($info['id3v2']['comments']['picture'])) {
                             $info['id3v2']['comments']['picture'] = array();
                         }
                         $info['id3v2']['comments']['picture'][] = array('data' => $parsedFrame['data'], 'image_mime' => $parsedFrame['image_mime']);
                     }
                 }
             } while (false);
         }
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'GEOB' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'GEO') {
         // 4.16  GEO  General encapsulated object
         //   There may be more than one 'GEOB' frame in each tag,
         //   but only one with the same content descriptor
         // <Header for 'General encapsulated object', ID: 'GEOB'>
         // Text encoding          $xx
         // MIME type              <text string> $00
         // Filename               <text string according to encoding> $00 (00)
         // Content description    <text string according to encoding> $00 (00)
         // Encapsulated object    <binary data>
         $frame_offset = 0;
         $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         if ($id3v2_majorversion <= 3 && $frame_textencoding > 1 || $id3v2_majorversion == 4 && $frame_textencoding > 3) {
             $info['warning'][] = 'Invalid text encoding byte (' . $frame_textencoding . ') in frame "' . $parsedFrame['frame_name'] . '" - defaulting to ISO-8859-1 encoding';
         }
         $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
         $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_mimetype) === 0) {
             $frame_mimetype = '';
         }
         $frame_offset = $frame_terminatorpos + strlen("");
         $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
         if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
             ++$frame_terminatorpos;
             // strpos() fooled because 2nd byte of Unicode chars are often 0x00
         }
         $frame_filename = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_filename) === 0) {
             $frame_filename = '';
         }
         $frame_offset = $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding));
         $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
         if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
             ++$frame_terminatorpos;
             // strpos() fooled because 2nd byte of Unicode chars are often 0x00
         }
         $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_description) === 0) {
             $frame_description = '';
         }
         $frame_offset = $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding));
         $parsedFrame['objectdata'] = (string) substr($parsedFrame['data'], $frame_offset);
         $parsedFrame['encodingid'] = $frame_textencoding;
         $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
         $parsedFrame['mime'] = $frame_mimetype;
         $parsedFrame['filename'] = $frame_filename;
         $parsedFrame['description'] = $frame_description;
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'PCNT' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'CNT') {
         // 4.17  CNT  Play counter
         //   There may only be one 'PCNT' frame in each tag.
         //   When the counter reaches all one's, one byte is inserted in
         //   front of the counter thus making the counter eight bits bigger
         // <Header for 'Play counter', ID: 'PCNT'>
         // Counter        $xx xx xx xx (xx ...)
         $parsedFrame['data'] = Helper::BigEndian2Int($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'POPM' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'POP') {
         // 4.18  POP  Popularimeter
         //   There may be more than one 'POPM' frame in each tag,
         //   but only one with the same email address
         // <Header for 'Popularimeter', ID: 'POPM'>
         // Email to user   <text string> $00
         // Rating          $xx
         // Counter         $xx xx xx xx (xx ...)
         $frame_offset = 0;
         $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
         $frame_emailaddress = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_emailaddress) === 0) {
             $frame_emailaddress = '';
         }
         $frame_offset = $frame_terminatorpos + strlen("");
         $frame_rating = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['counter'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset));
         $parsedFrame['email'] = $frame_emailaddress;
         $parsedFrame['rating'] = $frame_rating;
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'RBUF' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'BUF') {
         // 4.19  BUF  Recommended buffer size
         //   There may only be one 'RBUF' frame in each tag
         // <Header for 'Recommended buffer size', ID: 'RBUF'>
         // Buffer size               $xx xx xx
         // Embedded info flag        %0000000x
         // Offset to next tag        $xx xx xx xx
         $frame_offset = 0;
         $parsedFrame['buffersize'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 3));
         $frame_offset += 3;
         $frame_embeddedinfoflags = Helper::BigEndian2Bin(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['flags']['embededinfo'] = (bool) substr($frame_embeddedinfoflags, 7, 1);
         $parsedFrame['nexttagoffset'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'CRM') {
         // 4.20  Encrypted meta frame (ID3v2.2 only)
         //   There may be more than one 'CRM' frame in a tag,
         //   but only one with the same 'owner identifier'
         // <Header for 'Encrypted meta frame', ID: 'CRM'>
         // Owner identifier      <textstring> $00 (00)
         // Content/explanation   <textstring> $00 (00)
         // Encrypted datablock   <binary data>
         $frame_offset = 0;
         $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
         $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         $frame_offset = $frame_terminatorpos + strlen("");
         $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
         $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_description) === 0) {
             $frame_description = '';
         }
         $frame_offset = $frame_terminatorpos + strlen("");
         $parsedFrame['ownerid'] = $frame_ownerid;
         $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
         $parsedFrame['description'] = $frame_description;
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'AENC' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'CRA') {
         // 4.21  CRA  Audio encryption
         //   There may be more than one 'AENC' frames in a tag,
         //   but only one with the same 'Owner identifier'
         // <Header for 'Audio encryption', ID: 'AENC'>
         // Owner identifier   <text string> $00
         // Preview start      $xx xx
         // Preview length     $xx xx
         // Encryption info    <binary data>
         $frame_offset = 0;
         $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
         $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_ownerid) === 0) {
             $frame_ownerid == '';
         }
         $frame_offset = $frame_terminatorpos + strlen("");
         $parsedFrame['ownerid'] = $frame_ownerid;
         $parsedFrame['previewstart'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2));
         $frame_offset += 2;
         $parsedFrame['previewlength'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2));
         $frame_offset += 2;
         $parsedFrame['encryptioninfo'] = (string) substr($parsedFrame['data'], $frame_offset);
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'LINK' || $id3v2_majorversion == 2 && $parsedFrame['frame_name'] == 'LNK') {
         // 4.22  LNK  Linked information
         //   There may be more than one 'LINK' frame in a tag,
         //   but only one with the same contents
         // <Header for 'Linked information', ID: 'LINK'>
         // ID3v2.3+ => Frame identifier   $xx xx xx xx
         // ID3v2.2  => Frame identifier   $xx xx xx
         // URL                            <text string> $00
         // ID and additional data         <text string(s)>
         $frame_offset = 0;
         if ($id3v2_majorversion == 2) {
             $parsedFrame['frameid'] = substr($parsedFrame['data'], $frame_offset, 3);
             $frame_offset += 3;
         } else {
             $parsedFrame['frameid'] = substr($parsedFrame['data'], $frame_offset, 4);
             $frame_offset += 4;
         }
         $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
         $frame_url = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_url) === 0) {
             $frame_url = '';
         }
         $frame_offset = $frame_terminatorpos + strlen("");
         $parsedFrame['url'] = $frame_url;
         $parsedFrame['additionaldata'] = (string) substr($parsedFrame['data'], $frame_offset);
         if (!empty($parsedFrame['framenameshort']) && $parsedFrame['url']) {
             $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = utf8_encode($parsedFrame['url']);
         }
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'POSS') {
         // 4.21  POSS Position synchronisation frame (ID3v2.3+ only)
         //   There may only be one 'POSS' frame in each tag
         // <Head for 'Position synchronisation', ID: 'POSS'>
         // Time stamp format         $xx
         // Position                  $xx (xx ...)
         $frame_offset = 0;
         $parsedFrame['timestampformat'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['position'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset));
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'USER') {
         // 4.22  USER Terms of use (ID3v2.3+ only)
         //   There may be more than one 'Terms of use' frame in a tag,
         //   but only one with the same 'Language'
         // <Header for 'Terms of use frame', ID: 'USER'>
         // Text encoding        $xx
         // Language             $xx xx xx
         // The actual text      <text string according to encoding>
         $frame_offset = 0;
         $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         if ($id3v2_majorversion <= 3 && $frame_textencoding > 1 || $id3v2_majorversion == 4 && $frame_textencoding > 3) {
             $info['warning'][] = 'Invalid text encoding byte (' . $frame_textencoding . ') in frame "' . $parsedFrame['frame_name'] . '" - defaulting to ISO-8859-1 encoding';
         }
         $frame_language = substr($parsedFrame['data'], $frame_offset, 3);
         $frame_offset += 3;
         $parsedFrame['language'] = $frame_language;
         $parsedFrame['languagename'] = $this->LanguageLookup($frame_language, false);
         $parsedFrame['encodingid'] = $frame_textencoding;
         $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
         $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
         if (!empty($parsedFrame['framenameshort']) && !empty($parsedFrame['data'])) {
             $info['id3v2']['comments'][$parsedFrame['framenameshort']][] = Helper::iconv_fallback($parsedFrame['encoding'], $info['id3v2']['encoding'], $parsedFrame['data']);
         }
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'OWNE') {
         // 4.23  OWNE Ownership frame (ID3v2.3+ only)
         //   There may only be one 'OWNE' frame in a tag
         // <Header for 'Ownership frame', ID: 'OWNE'>
         // Text encoding     $xx
         // Price paid        <text string> $00
         // Date of purch.    <text string>
         // Seller            <text string according to encoding>
         $frame_offset = 0;
         $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         if ($id3v2_majorversion <= 3 && $frame_textencoding > 1 || $id3v2_majorversion == 4 && $frame_textencoding > 3) {
             $info['warning'][] = 'Invalid text encoding byte (' . $frame_textencoding . ') in frame "' . $parsedFrame['frame_name'] . '" - defaulting to ISO-8859-1 encoding';
         }
         $parsedFrame['encodingid'] = $frame_textencoding;
         $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
         $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
         $frame_pricepaid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         $frame_offset = $frame_terminatorpos + strlen("");
         $parsedFrame['pricepaid']['currencyid'] = substr($frame_pricepaid, 0, 3);
         $parsedFrame['pricepaid']['currency'] = $this->LookupCurrencyUnits($parsedFrame['pricepaid']['currencyid']);
         $parsedFrame['pricepaid']['value'] = substr($frame_pricepaid, 3);
         $parsedFrame['purchasedate'] = substr($parsedFrame['data'], $frame_offset, 8);
         if (!$this->IsValidDateStampString($parsedFrame['purchasedate'])) {
             $parsedFrame['purchasedateunix'] = mktime(0, 0, 0, substr($parsedFrame['purchasedate'], 4, 2), substr($parsedFrame['purchasedate'], 6, 2), substr($parsedFrame['purchasedate'], 0, 4));
         }
         $frame_offset += 8;
         $parsedFrame['seller'] = (string) substr($parsedFrame['data'], $frame_offset);
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'COMR') {
         // 4.24  COMR Commercial frame (ID3v2.3+ only)
         //   There may be more than one 'commercial frame' in a tag,
         //   but no two may be identical
         // <Header for 'Commercial frame', ID: 'COMR'>
         // Text encoding      $xx
         // Price string       <text string> $00
         // Valid until        <text string>
         // Contact URL        <text string> $00
         // Received as        $xx
         // Name of seller     <text string according to encoding> $00 (00)
         // Description        <text string according to encoding> $00 (00)
         // Picture MIME type  <string> $00
         // Seller logo        <binary data>
         $frame_offset = 0;
         $frame_textencoding = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         if ($id3v2_majorversion <= 3 && $frame_textencoding > 1 || $id3v2_majorversion == 4 && $frame_textencoding > 3) {
             $info['warning'][] = 'Invalid text encoding byte (' . $frame_textencoding . ') in frame "' . $parsedFrame['frame_name'] . '" - defaulting to ISO-8859-1 encoding';
         }
         $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
         $frame_pricestring = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         $frame_offset = $frame_terminatorpos + strlen("");
         $frame_rawpricearray = explode('/', $frame_pricestring);
         foreach ($frame_rawpricearray as $key => $val) {
             $frame_currencyid = substr($val, 0, 3);
             $parsedFrame['price'][$frame_currencyid]['currency'] = $this->LookupCurrencyUnits($frame_currencyid);
             $parsedFrame['price'][$frame_currencyid]['value'] = substr($val, 3);
         }
         $frame_datestring = substr($parsedFrame['data'], $frame_offset, 8);
         $frame_offset += 8;
         $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
         $frame_contacturl = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         $frame_offset = $frame_terminatorpos + strlen("");
         $frame_receivedasid = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
         if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
             ++$frame_terminatorpos;
             // strpos() fooled because 2nd byte of Unicode chars are often 0x00
         }
         $frame_sellername = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_sellername) === 0) {
             $frame_sellername = '';
         }
         $frame_offset = $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding));
         $frame_terminatorpos = strpos($parsedFrame['data'], $this->TextEncodingTerminatorLookup($frame_textencoding), $frame_offset);
         if (ord(substr($parsedFrame['data'], $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding)), 1)) === 0) {
             ++$frame_terminatorpos;
             // strpos() fooled because 2nd byte of Unicode chars are often 0x00
         }
         $frame_description = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_description) === 0) {
             $frame_description = '';
         }
         $frame_offset = $frame_terminatorpos + strlen($this->TextEncodingTerminatorLookup($frame_textencoding));
         $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
         $frame_mimetype = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         $frame_offset = $frame_terminatorpos + strlen("");
         $frame_sellerlogo = substr($parsedFrame['data'], $frame_offset);
         $parsedFrame['encodingid'] = $frame_textencoding;
         $parsedFrame['encoding'] = $this->TextEncodingNameLookup($frame_textencoding);
         $parsedFrame['pricevaliduntil'] = $frame_datestring;
         $parsedFrame['contacturl'] = $frame_contacturl;
         $parsedFrame['receivedasid'] = $frame_receivedasid;
         $parsedFrame['receivedas'] = $this->COMRReceivedAsLookup($frame_receivedasid);
         $parsedFrame['sellername'] = $frame_sellername;
         $parsedFrame['description'] = $frame_description;
         $parsedFrame['mime'] = $frame_mimetype;
         $parsedFrame['logo'] = $frame_sellerlogo;
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'ENCR') {
         // 4.25  ENCR Encryption method registration (ID3v2.3+ only)
         //   There may be several 'ENCR' frames in a tag,
         //   but only one containing the same symbol
         //   and only one containing the same owner identifier
         // <Header for 'Encryption method registration', ID: 'ENCR'>
         // Owner identifier    <text string> $00
         // Method symbol       $xx
         // Encryption data     <binary data>
         $frame_offset = 0;
         $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
         $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_ownerid) === 0) {
             $frame_ownerid = '';
         }
         $frame_offset = $frame_terminatorpos + strlen("");
         $parsedFrame['ownerid'] = $frame_ownerid;
         $parsedFrame['methodsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'GRID') {
         // 4.26  GRID Group identification registration (ID3v2.3+ only)
         //   There may be several 'GRID' frames in a tag,
         //   but only one containing the same symbol
         //   and only one containing the same owner identifier
         // <Header for 'Group ID registration', ID: 'GRID'>
         // Owner identifier      <text string> $00
         // Group symbol          $xx
         // Group dependent data  <binary data>
         $frame_offset = 0;
         $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
         $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_ownerid) === 0) {
             $frame_ownerid = '';
         }
         $frame_offset = $frame_terminatorpos + strlen("");
         $parsedFrame['ownerid'] = $frame_ownerid;
         $parsedFrame['groupsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'PRIV') {
         // 4.27  PRIV Private frame (ID3v2.3+ only)
         //   The tag may contain more than one 'PRIV' frame
         //   but only with different contents
         // <Header for 'Private frame', ID: 'PRIV'>
         // Owner identifier      <text string> $00
         // The private data      <binary data>
         $frame_offset = 0;
         $frame_terminatorpos = strpos($parsedFrame['data'], "", $frame_offset);
         $frame_ownerid = substr($parsedFrame['data'], $frame_offset, $frame_terminatorpos - $frame_offset);
         if (ord($frame_ownerid) === 0) {
             $frame_ownerid = '';
         }
         $frame_offset = $frame_terminatorpos + strlen("");
         $parsedFrame['ownerid'] = $frame_ownerid;
         $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
     } elseif ($id3v2_majorversion >= 4 && $parsedFrame['frame_name'] == 'SIGN') {
         // 4.28  SIGN Signature frame (ID3v2.4+ only)
         //   There may be more than one 'signature frame' in a tag,
         //   but no two may be identical
         // <Header for 'Signature frame', ID: 'SIGN'>
         // Group symbol      $xx
         // Signature         <binary data>
         $frame_offset = 0;
         $parsedFrame['groupsymbol'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $parsedFrame['data'] = (string) substr($parsedFrame['data'], $frame_offset);
     } elseif ($id3v2_majorversion >= 4 && $parsedFrame['frame_name'] == 'SEEK') {
         // 4.29  SEEK Seek frame (ID3v2.4+ only)
         //   There may only be one 'seek frame' in a tag
         // <Header for 'Seek frame', ID: 'SEEK'>
         // Minimum offset to next tag       $xx xx xx xx
         $frame_offset = 0;
         $parsedFrame['data'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
     } elseif ($id3v2_majorversion >= 4 && $parsedFrame['frame_name'] == 'ASPI') {
         // 4.30  ASPI Audio seek point index (ID3v2.4+ only)
         //   There may only be one 'audio seek point index' frame in a tag
         // <Header for 'Seek Point Index', ID: 'ASPI'>
         // Indexed data start (S)         $xx xx xx xx
         // Indexed data length (L)        $xx xx xx xx
         // Number of index points (N)     $xx xx
         // Bits per index point (b)       $xx
         //   Then for every index point the following data is included:
         // Fraction at index (Fi)          $xx (xx)
         $frame_offset = 0;
         $parsedFrame['datastart'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
         $frame_offset += 4;
         $parsedFrame['indexeddatalength'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 4));
         $frame_offset += 4;
         $parsedFrame['indexpoints'] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, 2));
         $frame_offset += 2;
         $parsedFrame['bitsperpoint'] = ord(substr($parsedFrame['data'], $frame_offset++, 1));
         $frame_bytesperpoint = ceil($parsedFrame['bitsperpoint'] / 8);
         for ($i = 0; $i < $frame_indexpoints; ++$i) {
             $parsedFrame['indexes'][$i] = Helper::BigEndian2Int(substr($parsedFrame['data'], $frame_offset, $frame_bytesperpoint));
             $frame_offset += $frame_bytesperpoint;
         }
         unset($parsedFrame['data']);
     } elseif ($id3v2_majorversion >= 3 && $parsedFrame['frame_name'] == 'RGAD') {
         // Replay Gain Adjustment
         // http://privatewww.essex.ac.uk/~djmrob/replaygain/file_format_id3v2.html
         //   There may only be one 'RGAD' frame in a tag
         // <Header for 'Replay Gain Adjustment', ID: 'RGAD'>
         // Peak Amplitude                      $xx $xx $xx $xx
         // Radio Replay Gain Adjustment        %aaabbbcd %dddddddd
         // Audiophile Replay Gain Adjustment   %aaabbbcd %dddddddd
         //   a - name code
         //   b - originator code
         //   c - sign bit
         //   d - replay gain adjustment
         $frame_offset = 0;
         $parsedFrame['peakamplitude'] = Helper::BigEndian2Float(substr($parsedFrame['data'], $frame_offset, 4));
         $frame_offset += 4;
         $rg_track_adjustment = Helper::Dec2Bin(substr($parsedFrame['data'], $frame_offset, 2));
         $frame_offset += 2;
         $rg_album_adjustment = Helper::Dec2Bin(substr($parsedFrame['data'], $frame_offset, 2));
         $frame_offset += 2;
         $parsedFrame['raw']['track']['name'] = Helper::Bin2Dec(substr($rg_track_adjustment, 0, 3));
         $parsedFrame['raw']['track']['originator'] = Helper::Bin2Dec(substr($rg_track_adjustment, 3, 3));
         $parsedFrame['raw']['track']['signbit'] = Helper::Bin2Dec(substr($rg_track_adjustment, 6, 1));
         $parsedFrame['raw']['track']['adjustment'] = Helper::Bin2Dec(substr($rg_track_adjustment, 7, 9));
         $parsedFrame['raw']['album']['name'] = Helper::Bin2Dec(substr($rg_album_adjustment, 0, 3));
         $parsedFrame['raw']['album']['originator'] = Helper::Bin2Dec(substr($rg_album_adjustment, 3, 3));
         $parsedFrame['raw']['album']['signbit'] = Helper::Bin2Dec(substr($rg_album_adjustment, 6, 1));
         $parsedFrame['raw']['album']['adjustment'] = Helper::Bin2Dec(substr($rg_album_adjustment, 7, 9));
         $parsedFrame['track']['name'] = Helper::RGADnameLookup($parsedFrame['raw']['track']['name']);
         $parsedFrame['track']['originator'] = Helper::RGADoriginatorLookup($parsedFrame['raw']['track']['originator']);
         $parsedFrame['track']['adjustment'] = Helper::RGADadjustmentLookup($parsedFrame['raw']['track']['adjustment'], $parsedFrame['raw']['track']['signbit']);
         $parsedFrame['album']['name'] = Helper::RGADnameLookup($parsedFrame['raw']['album']['name']);
         $parsedFrame['album']['originator'] = Helper::RGADoriginatorLookup($parsedFrame['raw']['album']['originator']);
         $parsedFrame['album']['adjustment'] = Helper::RGADadjustmentLookup($parsedFrame['raw']['album']['adjustment'], $parsedFrame['raw']['album']['signbit']);
         $info['replay_gain']['track']['peak'] = $parsedFrame['peakamplitude'];
         $info['replay_gain']['track']['originator'] = $parsedFrame['track']['originator'];
         $info['replay_gain']['track']['adjustment'] = $parsedFrame['track']['adjustment'];
         $info['replay_gain']['album']['originator'] = $parsedFrame['album']['originator'];
         $info['replay_gain']['album']['adjustment'] = $parsedFrame['album']['adjustment'];
         unset($parsedFrame['data']);
     }
     return true;
 }
Exemple #5
0
 /**
  * @return bool
  */
 public function analyze()
 {
     $info =& $this->getid3->info;
     $info['fileformat'] = 'jpg';
     $info['video']['dataformat'] = 'jpg';
     $info['video']['lossless'] = false;
     $info['video']['bits_per_sample'] = 24;
     $info['video']['pixel_aspect_ratio'] = (double) 1;
     fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
     $imageinfo = array();
     list($width, $height, $type) = Helper::GetDataImageSize(fread($this->getid3->fp, $info['filesize']), $imageinfo);
     if (isset($imageinfo['APP13'])) {
         // http://php.net/iptcparse
         // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/IPTC.html
         $iptc_parsed = iptcparse($imageinfo['APP13']);
         if (is_array($iptc_parsed)) {
             foreach ($iptc_parsed as $iptc_key_raw => $iptc_values) {
                 list($iptc_record, $iptc_tagkey) = explode('#', $iptc_key_raw);
                 $iptc_tagkey = intval(ltrim($iptc_tagkey, '0'));
                 foreach ($iptc_values as $key => $value) {
                     $IPTCrecordName = $this->IPTCrecordName($iptc_record);
                     $IPTCrecordTagName = $this->IPTCrecordTagName($iptc_record, $iptc_tagkey);
                     if (isset($info['iptc'][$IPTCrecordName][$IPTCrecordTagName])) {
                         $info['iptc'][$IPTCrecordName][$IPTCrecordTagName][] = $value;
                     } else {
                         $info['iptc'][$IPTCrecordName][$IPTCrecordTagName] = array($value);
                     }
                 }
             }
         }
     }
     $returnOK = false;
     switch ($type) {
         case IMG_JPG:
             $info['video']['resolution_x'] = $width;
             $info['video']['resolution_y'] = $height;
             if (isset($imageinfo['APP1'])) {
                 if (function_exists('exif_read_data')) {
                     if (substr($imageinfo['APP1'], 0, 4) == 'Exif') {
                         $info['jpg']['exif'] = @exif_read_data($info['filenamepath'], '', true, false);
                     } else {
                         $info['warning'][] = 'exif_read_data() cannot parse non-EXIF data in APP1 (expected "Exif", found "' . substr($imageinfo['APP1'], 0, 4) . '")';
                     }
                 } else {
                     $info['warning'][] = 'EXIF parsing only available when ' . (GetId3Core::environmentIsWindows() ? 'php_exif.dll enabled' : 'compiled with --enable-exif');
                 }
             }
             $returnOK = true;
             break;
         default:
             break;
     }
     $cast_as_appropriate_keys = array('EXIF', 'IFD0', 'THUMBNAIL');
     foreach ($cast_as_appropriate_keys as $exif_key) {
         if (isset($info['jpg']['exif'][$exif_key])) {
             foreach ($info['jpg']['exif'][$exif_key] as $key => $value) {
                 $info['jpg']['exif'][$exif_key][$key] = $this->CastAsAppropriate($value);
             }
         }
     }
     if (isset($info['jpg']['exif']['GPS'])) {
         if (isset($info['jpg']['exif']['GPS']['GPSVersion'])) {
             for ($i = 0; $i < 4; ++$i) {
                 $version_subparts[$i] = ord(substr($info['jpg']['exif']['GPS']['GPSVersion'], $i, 1));
             }
             $info['jpg']['exif']['GPS']['computed']['version'] = 'v' . implode('.', $version_subparts);
         }
         if (isset($info['jpg']['exif']['GPS']['GPSDateStamp'])) {
             $explodedGPSDateStamp = explode(':', $info['jpg']['exif']['GPS']['GPSDateStamp']);
             $computed_time[5] = isset($explodedGPSDateStamp[0]) ? $explodedGPSDateStamp[0] : '';
             $computed_time[3] = isset($explodedGPSDateStamp[1]) ? $explodedGPSDateStamp[1] : '';
             $computed_time[4] = isset($explodedGPSDateStamp[2]) ? $explodedGPSDateStamp[2] : '';
             if (function_exists('date_default_timezone_set')) {
                 date_default_timezone_set('UTC');
             } else {
                 ini_set('date.timezone', 'UTC');
             }
             $computed_time = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0);
             if (isset($info['jpg']['exif']['GPS']['GPSTimeStamp']) && is_array($info['jpg']['exif']['GPS']['GPSTimeStamp'])) {
                 foreach ($info['jpg']['exif']['GPS']['GPSTimeStamp'] as $key => $value) {
                     $computed_time[$key] = Helper::DecimalizeFraction($value);
                 }
             }
             $info['jpg']['exif']['GPS']['computed']['timestamp'] = mktime($computed_time[0], $computed_time[1], $computed_time[2], $computed_time[3], $computed_time[4], $computed_time[5]);
         }
         if (isset($info['jpg']['exif']['GPS']['GPSLatitude']) && is_array($info['jpg']['exif']['GPS']['GPSLatitude'])) {
             $direction_multiplier = isset($info['jpg']['exif']['GPS']['GPSLatitudeRef']) && $info['jpg']['exif']['GPS']['GPSLatitudeRef'] == 'S' ? -1 : 1;
             foreach ($info['jpg']['exif']['GPS']['GPSLatitude'] as $key => $value) {
                 $computed_latitude[$key] = Helper::DecimalizeFraction($value);
             }
             $info['jpg']['exif']['GPS']['computed']['latitude'] = $direction_multiplier * ($computed_latitude[0] + $computed_latitude[1] / 60 + $computed_latitude[2] / 3600);
         }
         if (isset($info['jpg']['exif']['GPS']['GPSLongitude']) && is_array($info['jpg']['exif']['GPS']['GPSLongitude'])) {
             $direction_multiplier = isset($info['jpg']['exif']['GPS']['GPSLongitudeRef']) && $info['jpg']['exif']['GPS']['GPSLongitudeRef'] == 'W' ? -1 : 1;
             foreach ($info['jpg']['exif']['GPS']['GPSLongitude'] as $key => $value) {
                 $computed_longitude[$key] = Helper::DecimalizeFraction($value);
             }
             $info['jpg']['exif']['GPS']['computed']['longitude'] = $direction_multiplier * ($computed_longitude[0] + $computed_longitude[1] / 60 + $computed_longitude[2] / 3600);
         }
         if (isset($info['jpg']['exif']['GPS']['GPSAltitude'])) {
             $direction_multiplier = isset($info['jpg']['exif']['GPS']['GPSAltitudeRef']) && $info['jpg']['exif']['GPS']['GPSAltitudeRef'] === chr(1) ? -1 : 1;
             $info['jpg']['exif']['GPS']['computed']['altitude'] = $direction_multiplier * Helper::DecimalizeFraction($info['jpg']['exif']['GPS']['GPSAltitude']);
         }
     }
     if (class_exists('Helpers\\GetId3\\Module\\Tag\\Xmp')) {
         if (isset($info['filenamepath'])) {
             $image_xmp = new Xmp($info['filenamepath']);
             $xmp_raw = $image_xmp->getAllTags();
             foreach ($xmp_raw as $key => $value) {
                 list($subsection, $tagname) = explode(':', $key);
                 $info['xmp'][$subsection][$tagname] = $this->CastAsAppropriate($value);
             }
         }
     }
     if (!$returnOK) {
         unset($info['fileformat']);
         return false;
     }
     return true;
 }