@@ -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