Skip to content

Commit f4e51aa

Browse files
committed
ID3v2.4 custom genres with slashes
#89
1 parent 9b0d39d commit f4e51aa

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

getid3/getid3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class getID3
112112
protected $startup_error = '';
113113
protected $startup_warning = '';
114114

115-
const VERSION = '1.9.12-201611231046';
115+
const VERSION = '1.9.12-201612051806';
116116
const FREAD_BUFFER_SIZE = 32768;
117117

118118
const ATTACHMENTS_NONE = false;

getid3/module.tag.id3v2.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -504,18 +504,27 @@ public function ParseID3v2GenreString($genrestring) {
504504
// ID3v2.2.x, ID3v2.3.x: '(21)' or '(4)Eurodisco' or '(51)(39)' or '(55)((I think...)'
505505
// ID3v2.4.x: '21' $00 'Eurodisco' $00
506506
$clean_genres = array();
507-
if (strpos($genrestring, "\x00") === false) {
508-
$genrestring = preg_replace('#\(([0-9]{1,3})\)#', '$1'."\x00", $genrestring);
507+
508+
// hack-fixes for some badly-written ID3v2.3 taggers, while trying not to break correctly-written tags
509+
if (($this->getid3->info['id3v2']['majorversion'] == 3) && !preg_match('#[\x00]#', $genrestring)) {
510+
// note: MusicBrainz Picard incorrectly stores plaintext genres separated by "/" when writing in ID3v2.3 mode, hack-fix here:
511+
// replace / with NULL, then replace back the two ID3v1 genres that legitimately have "/" as part of the single genre name
512+
if (preg_match('#/#', $genrestring)) {
513+
$genrestring = str_replace('/', "\x00", $genrestring);
514+
$genrestring = str_replace('Pop'."\x00".'Funk', 'Pop/Funk', $genrestring);
515+
$genrestring = str_replace('Rock'."\x00".'Rock', 'Folk/Rock', $genrestring);
516+
}
517+
518+
// some other taggers separate multiple genres with semicolon, e.g. "Heavy Metal;Thrash Metal;Metal"
519+
if (preg_match('#;#', $genrestring)) {
520+
$genrestring = str_replace(';', "\x00", $genrestring);
521+
}
509522
}
510523

511-
// note: MusicBrainz Picard incorrectly stores plaintext genres separated by "/" when writing in ID3v2.3 mode, hack-fix here:
512-
// replace / with NULL, then replace back the two ID3v1 genres that legitimately have "/" as part of the single genre name
513-
$genrestring = str_replace('/', "\x00", $genrestring);
514-
$genrestring = str_replace('Pop'."\x00".'Funk', 'Pop/Funk', $genrestring);
515-
$genrestring = str_replace('Rock'."\x00".'Rock', 'Folk/Rock', $genrestring);
516524

517-
// some other taggers separate multiple genres with semicolon, e.g. "Heavy Metal;Thrash Metal;Metal"
518-
$genrestring = str_replace(';', "\x00", $genrestring);
525+
if (strpos($genrestring, "\x00") === false) {
526+
$genrestring = preg_replace('#\(([0-9]{1,3})\)#', '$1'."\x00", $genrestring);
527+
}
519528

520529
$genre_elements = explode("\x00", $genrestring);
521530
foreach ($genre_elements as $element) {

0 commit comments

Comments
 (0)