--- a/wp/wp-includes/ID3/module.tag.id3v1.php Tue Jun 09 11:14:17 2015 +0000
+++ b/wp/wp-includes/ID3/module.tag.id3v1.php Mon Oct 14 17:39:30 2019 +0200
@@ -22,7 +22,7 @@
$info = &$this->getid3->info;
if (!getid3_lib::intValueSupported($info['filesize'])) {
- $info['warning'][] = 'Unable to check for ID3v1 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
+ $this->warning('Unable to check for ID3v1 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB');
return false;
}
@@ -60,6 +60,26 @@
foreach ($ParsedID3v1 as $key => $value) {
$ParsedID3v1['comments'][$key][0] = $value;
}
+ // 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
+ $ID3v1encoding = 'ISO-8859-1';
+ foreach ($ParsedID3v1['comments'] as $tag_key => $valuearray) {
+ foreach ($valuearray as $key => $value) {
+ if (preg_match('#^[\\x00-\\x40\\xA8\\B8\\x80-\\xFF]+$#', $value)) {
+ foreach (array('Windows-1251', 'KOI8-R') as $id3v1_bad_encoding) {
+ if (function_exists('mb_convert_encoding') && @mb_convert_encoding($value, $id3v1_bad_encoding, $id3v1_bad_encoding) === $value) {
+ $ID3v1encoding = $id3v1_bad_encoding;
+ break 3;
+ } elseif (function_exists('iconv') && @iconv($id3v1_bad_encoding, $id3v1_bad_encoding, $value) === $value) {
+ $ID3v1encoding = $id3v1_bad_encoding;
+ break 3;
+ }
+ }
+ }
+ }
+ }
+ // ID3v1 encoding detection hack END
// ID3v1 data is supposed to be padded with NULL characters, but some taggers pad with spaces
$GoodFormatID3v1tag = $this->GenerateID3v1Tag(
@@ -73,13 +93,14 @@
$ParsedID3v1['padding_valid'] = true;
if ($id3v1tag !== $GoodFormatID3v1tag) {
$ParsedID3v1['padding_valid'] = false;
- $info['warning'][] = 'Some ID3v1 fields do not use NULL characters for padding';
+ $this->warning('Some ID3v1 fields do not use NULL characters for padding');
}
$ParsedID3v1['tag_offset_end'] = $info['filesize'];
$ParsedID3v1['tag_offset_start'] = $ParsedID3v1['tag_offset_end'] - 128;
$info['id3v1'] = $ParsedID3v1;
+ $info['id3v1']['encoding'] = $ID3v1encoding;
}
if (substr($preid3v1, 0, 3) == 'TAG') {
@@ -95,7 +116,7 @@
// a Lyrics3 tag footer was found before the last ID3v1, assume false "TAG" synch
} else {
// APE and Lyrics3 footers not found - assume double ID3v1
- $info['warning'][] = 'Duplicate ID3v1 tag detected - this has been known to happen with iTunes';
+ $this->warning('Duplicate ID3v1 tag detected - this has been known to happen with iTunes');
$info['avdataend'] -= 128;
}
}
@@ -357,4 +378,4 @@
return $ID3v1Tag;
}
-}
\ No newline at end of file
+}