public function HandleAllTags() { // key name => array (tag name, character encoding) static $tags; if (empty($tags)) { $tags = array('asf' => array('asf', 'UTF-16LE'), 'midi' => array('midi', 'ISO-8859-1'), 'nsv' => array('nsv', 'ISO-8859-1'), 'ogg' => array('vorbiscomment', 'UTF-8'), 'png' => array('png', 'UTF-8'), 'tiff' => array('tiff', 'ISO-8859-1'), 'quicktime' => array('quicktime', 'UTF-8'), 'real' => array('real', 'ISO-8859-1'), 'vqf' => array('vqf', 'ISO-8859-1'), 'zip' => array('zip', 'ISO-8859-1'), 'riff' => array('riff', 'ISO-8859-1'), 'lyrics3' => array('lyrics3', 'ISO-8859-1'), 'id3v1' => array('id3v1', $this->encoding_id3v1), 'id3v2' => array('id3v2', 'UTF-8'), 'ape' => array('ape', 'UTF-8'), 'cue' => array('cue', 'ISO-8859-1'), 'matroska' => array('matroska', 'UTF-8'), 'flac' => array('vorbiscomment', 'UTF-8'), 'divxtag' => array('divx', 'ISO-8859-1'), 'iptc' => array('iptc', 'ISO-8859-1')); } // loop through comments array foreach ($tags as $comment_name => $tagname_encoding_array) { list($tag_name, $encoding) = $tagname_encoding_array; // fill in default encoding type if not already present if (isset($this->info[$comment_name]) && !isset($this->info[$comment_name]['encoding'])) { $this->info[$comment_name]['encoding'] = $encoding; } // copy comments if key name set if (!empty($this->info[$comment_name]['comments'])) { foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) { foreach ($valuearray as $key => $value) { if (is_string($value)) { $value = trim($value, " \r\n\t"); // do not trim nulls from $value!! Unicode characters will get mangled if trailing nulls are removed! } if ($value) { if (!is_numeric($key)) { $this->info['tags'][trim($tag_name)][trim($tag_key)][$key] = $value; } else { $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value; } } } if ($tag_key == 'picture') { unset($this->info[$comment_name]['comments'][$tag_key]); } } if (!isset($this->info['tags'][$tag_name])) { // comments are set but contain nothing but empty strings, so skip continue; } if ($this->option_tags_html) { foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) { $this->info['tags_html'][$tag_name][$tag_key] = getid3_lib::recursiveMultiByteCharString2HTML($valuearray, $encoding); } } // ID3v1 encoding detection hack start // ID3v1 is defined as always using ISO-8859-1 encoding, but it is not uncommon to find files tagged with ID3v1 using Windows-1251 or other character sets // Since ID3v1 has no concept of character sets there is no certain way to know we have the correct non-ISO-8859-1 character set, but we can guess if ($comment_name == 'id3v1') { if ($encoding == 'ISO-8859-1') { if (function_exists('iconv')) { foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) { foreach ($valuearray as $key => $value) { if (preg_match('#^[\\x80-\\xFF]+$#', $value)) { foreach (array('windows-1251', 'KOI8-R') as $id3v1_bad_encoding) { if (@iconv($id3v1_bad_encoding, $id3v1_bad_encoding, $value) === $value) { $encoding = $id3v1_bad_encoding; break 3; } } } } } } } } // ID3v1 encoding detection hack end $this->CharConvert($this->info['tags'][$tag_name], $encoding); // only copy gets converted! } } // pictures can take up a lot of space, and we don't need multiple copies of them // let there be a single copy in [comments][picture], and not elsewhere if (!empty($this->info['tags'])) { $unset_keys = array('tags', 'tags_html'); foreach ($this->info['tags'] as $tagtype => $tagarray) { foreach ($tagarray as $tagname => $tagdata) { if ($tagname == 'picture') { foreach ($tagdata as $key => $tagarray) { $this->info['comments']['picture'][] = $tagarray; if (isset($tagarray['data']) && isset($tagarray['image_mime'])) { if (isset($this->info['tags'][$tagtype][$tagname][$key])) { unset($this->info['tags'][$tagtype][$tagname][$key]); } if (isset($this->info['tags_html'][$tagtype][$tagname][$key])) { unset($this->info['tags_html'][$tagtype][$tagname][$key]); } } } } } foreach ($unset_keys as $unset_key) { // remove possible empty keys from (e.g. [tags][id3v2][picture]) if (empty($this->info[$unset_key][$tagtype]['picture'])) { unset($this->info[$unset_key][$tagtype]['picture']); } if (empty($this->info[$unset_key][$tagtype])) { unset($this->info[$unset_key][$tagtype]); } if (empty($this->info[$unset_key])) { unset($this->info[$unset_key]); } } // remove duplicate copy of picture data from (e.g. [id3v2][comments][picture]) if (isset($this->info[$tagtype]['comments']['picture'])) { unset($this->info[$tagtype]['comments']['picture']); } if (empty($this->info[$tagtype]['comments'])) { unset($this->info[$tagtype]['comments']); } if (empty($this->info[$tagtype])) { unset($this->info[$tagtype]); } } } return true; }
public function HandleAllTags() { // key name => array (tag name, character encoding) static $tags; if (empty($tags)) { $tags = array('asf' => array('asf', 'UTF-16LE'), 'midi' => array('midi', 'ISO-8859-1'), 'nsv' => array('nsv', 'ISO-8859-1'), 'ogg' => array('vorbiscomment', 'UTF-8'), 'png' => array('png', 'UTF-8'), 'tiff' => array('tiff', 'ISO-8859-1'), 'quicktime' => array('quicktime', 'UTF-8'), 'real' => array('real', 'ISO-8859-1'), 'vqf' => array('vqf', 'ISO-8859-1'), 'zip' => array('zip', 'ISO-8859-1'), 'riff' => array('riff', 'ISO-8859-1'), 'lyrics3' => array('lyrics3', 'ISO-8859-1'), 'id3v1' => array('id3v1', $this->encoding_id3v1), 'id3v2' => array('id3v2', 'UTF-8'), 'ape' => array('ape', 'UTF-8'), 'cue' => array('cue', 'ISO-8859-1'), 'matroska' => array('matroska', 'UTF-8'), 'flac' => array('vorbiscomment', 'UTF-8'), 'divxtag' => array('divx', 'ISO-8859-1'), 'iptc' => array('iptc', 'ISO-8859-1')); } // loop through comments array foreach ($tags as $comment_name => $tagname_encoding_array) { list($tag_name, $encoding) = $tagname_encoding_array; // fill in default encoding type if not already present if (isset($this->info[$comment_name]) && !isset($this->info[$comment_name]['encoding'])) { $this->info[$comment_name]['encoding'] = $encoding; } // copy comments if key name set if (!empty($this->info[$comment_name]['comments'])) { foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) { foreach ($valuearray as $key => $value) { if (is_string($value)) { $value = trim($value, " \r\n\t"); // do not trim nulls from $value!! Unicode characters will get mangled if trailing nulls are removed! } if ($value) { if (!is_numeric($key)) { $this->info['tags'][trim($tag_name)][trim($tag_key)][$key] = $value; } else { $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value; } } } if ($tag_key == 'picture') { unset($this->info[$comment_name]['comments'][$tag_key]); } } if (!isset($this->info['tags'][$tag_name])) { // comments are set but contain nothing but empty strings, so skip continue; } if ($this->option_tags_html) { foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) { $this->info['tags_html'][$tag_name][$tag_key] = getid3_lib::recursiveMultiByteCharString2HTML($valuearray, $encoding); } } $this->CharConvert($this->info['tags'][$tag_name], $encoding); // only copy gets converted! } } // pictures can take up a lot of space, and we don't need multiple copies of them // let there be a single copy in [comments][picture], and not elsewhere if (!empty($this->info['tags'])) { $unset_keys = array('tags', 'tags_html'); foreach ($this->info['tags'] as $tagtype => $tagarray) { foreach ($tagarray as $tagname => $tagdata) { if ($tagname == 'picture') { foreach ($tagdata as $key => $tagarray) { $this->info['comments']['picture'][] = $tagarray; if (isset($tagarray['data']) && isset($tagarray['image_mime'])) { if (isset($this->info['tags'][$tagtype][$tagname][$key])) { unset($this->info['tags'][$tagtype][$tagname][$key]); } if (isset($this->info['tags_html'][$tagtype][$tagname][$key])) { unset($this->info['tags_html'][$tagtype][$tagname][$key]); } } } } } foreach ($unset_keys as $unset_key) { // remove possible empty keys from (e.g. [tags][id3v2][picture]) if (empty($this->info[$unset_key][$tagtype]['picture'])) { unset($this->info[$unset_key][$tagtype]['picture']); } if (empty($this->info[$unset_key][$tagtype])) { unset($this->info[$unset_key][$tagtype]); } if (empty($this->info[$unset_key])) { unset($this->info[$unset_key]); } } // remove duplicate copy of picture data from (e.g. [id3v2][comments][picture]) if (isset($this->info[$tagtype]['comments']['picture'])) { unset($this->info[$tagtype]['comments']['picture']); } if (empty($this->info[$tagtype]['comments'])) { unset($this->info[$tagtype]['comments']); } if (empty($this->info[$tagtype])) { unset($this->info[$tagtype]); } } } return true; }