Skip to content

Commit

Permalink
Merge pull request #225 from ben-xo/bugfix/dont-redo-work-html-comments
Browse files Browse the repository at this point in the history
Use comments_html content already generated by modules...
  • Loading branch information
JamesHeinrich authored Dec 29, 2019
2 parents dee9eb7 + bd3501c commit c16142d
Showing 1 changed file with 48 additions and 37 deletions.
85 changes: 48 additions & 37 deletions getid3/getid3.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1535,53 +1535,64 @@ public static function ImageExtFromMime($mime_type) {
*/
public static function CopyTagsToComments(&$ThisFileInfo, $option_tags_html=true) {

$comment_arrays = array('comments');
if($option_tags_html) {
$comment_arrays[] = 'comments_html';
}
// Copy all entries from ['tags'] into common ['comments']
if (!empty($ThisFileInfo['tags'])) {
foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) {
foreach ($tagarray as $tagname => $tagdata) {
foreach ($tagdata as $key => $value) {
if (!empty($value)) {
if (empty($ThisFileInfo['comments'][$tagname])) {

// fall through and append value

} elseif ($tagtype == 'id3v1') {

$newvaluelength = strlen(trim($value));
foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
$oldvaluelength = strlen(trim($existingvalue));
if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) {
// new value is identical but shorter-than (or equal-length to) one already in comments - skip
break 2;
foreach($comment_arrays as $comments) {
if ($comments != 'comments' && $key == 'picture') {
// 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
continue;
}
if (!empty($value)) {
if (empty($ThisFileInfo[$comments][$tagname])) {

// fall through and append value

} elseif ($tagtype == 'id3v1') {

$newvaluelength = strlen(trim($value));
foreach ($ThisFileInfo[$comments][$tagname] as $existingkey => $existingvalue) {
$oldvaluelength = strlen(trim($existingvalue));
if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) {
// new value is identical but shorter-than (or equal-length to) one already in comments - skip
break 2;
}
}
}

} elseif (!is_array($value)) {

$newvaluelength = strlen(trim($value));
foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
$oldvaluelength = strlen(trim($existingvalue));
if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
$ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);
//break 2;
break;

} elseif (!is_array($value)) {

$newvaluelength = strlen(trim($value));
foreach ($ThisFileInfo[$comments][$tagname] as $existingkey => $existingvalue) {
$oldvaluelength = strlen(trim($existingvalue));
if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
$ThisFileInfo[$comments][$tagname][$existingkey] = trim($value);
//break 2;
break;
}
}

}

}
if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) {
$value = (is_string($value) ? trim($value) : $value);
if (!is_int($key) && !ctype_digit($key)) {
$ThisFileInfo['comments'][$tagname][$key] = $value;
} else {
if (!isset($ThisFileInfo['comments'][$tagname])) {
$ThisFileInfo['comments'][$tagname] = array($value);
if (is_array($value) || empty($ThisFileInfo[$comments][$tagname]) || !in_array(trim($value), $ThisFileInfo[$comments][$tagname])) {
$value = (is_string($value) ? trim($value) : $value);
if (!is_int($key) && !ctype_digit($key)) {
$ThisFileInfo[$comments][$tagname][$key] = $value;
} else {
$ThisFileInfo['comments'][$tagname][] = $value;
if (!isset($ThisFileInfo[$comments][$tagname])) {
$ThisFileInfo[$comments][$tagname] = array($value);
} else {
$ThisFileInfo[$comments][$tagname][] = $value;
}
}
}
}
}
}
}
}
}
Expand All @@ -1599,7 +1610,7 @@ public static function CopyTagsToComments(&$ThisFileInfo, $option_tags_html=true
}

if ($option_tags_html) {
// Copy to ['comments_html']
// Copy to ['comments_html'], if not already present.
if (!empty($ThisFileInfo['comments'])) {
foreach ($ThisFileInfo['comments'] as $field => $values) {
if ($field == 'picture') {
Expand All @@ -1610,7 +1621,7 @@ public static function CopyTagsToComments(&$ThisFileInfo, $option_tags_html=true
foreach ($values as $index => $value) {
if (is_array($value)) {
$ThisFileInfo['comments_html'][$field][$index] = $value;
} else {
} elseif(empty($ThisFileInfo['comments_html'][$field][$index])) {
$ThisFileInfo['comments_html'][$field][$index] = str_replace('&#0;', '', self::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
}
}
Expand Down

0 comments on commit c16142d

Please sign in to comment.