Skip to content

Commit

Permalink
CopyTagsToComments process RIFF tags last
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHeinrich committed Sep 1, 2021
1 parent 0884677 commit 4e02ed0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions getid3/getid3.lib.php
Expand Up @@ -1545,12 +1545,21 @@ public static function ImageExtFromMime($mime_type) {
public static function CopyTagsToComments(&$ThisFileInfo, $option_tags_html=true) {
// Copy all entries from ['tags'] into common ['comments']
if (!empty($ThisFileInfo['tags'])) {
if (isset($ThisFileInfo['tags']['id3v1'])) {
// bubble ID3v1 to the end, if present to aid in detecting bad ID3v1 encodings
$ID3v1 = $ThisFileInfo['tags']['id3v1'];
unset($ThisFileInfo['tags']['id3v1']);
$ThisFileInfo['tags']['id3v1'] = $ID3v1;
unset($ID3v1);

// Some tag types can only support limited character sets and may contain data in non-standard encoding (usually ID3v1)
// and/or poorly-transliterated tag values that are also in tag formats that do support full-range character sets
// To make the output more user-friendly, process the potentially-problematic tag formats last to enhance the chance that
// the first entries in [comments] are the most correct and the "bad" ones (if any) come later.
// https://github.com/JamesHeinrich/getID3/issues/338
$processLastTagTypes = array('id3v1','riff');
foreach ($processLastTagTypes as $processLastTagType) {
if (isset($ThisFileInfo['tags'][$processLastTagType])) {
// bubble ID3v1 to the end, if present to aid in detecting bad ID3v1 encodings
$temp = $ThisFileInfo['tags'][$processLastTagType];
unset($ThisFileInfo['tags'][$processLastTagType]);
$ThisFileInfo['tags'][$processLastTagType] = $temp;
unset($temp);
}
}
foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) {
foreach ($tagarray as $tagname => $tagdata) {
Expand Down
2 changes: 1 addition & 1 deletion getid3/getid3.php
Expand Up @@ -387,7 +387,7 @@ class getID3
*/
protected $startup_warning = '';

const VERSION = '1.9.20-202108281621';
const VERSION = '1.9.20-202109010614';
const FREAD_BUFFER_SIZE = 32768;

const ATTACHMENTS_NONE = false;
Expand Down

0 comments on commit 4e02ed0

Please sign in to comment.