getid3_id3v2::ParseID3v2GenreString

Advertisement

Syntax Syntax

getid3_id3v2::ParseID3v2GenreString( string $genrestring )

Parameters Parameters

$genrestring

(Required)

Return Return

(array)

Source Source

File: wp-includes/ID3/module.tag.id3v2.php

	 *
	 * @return array
	 */
	public function ParseID3v2GenreString($genrestring) {
		// Parse genres into arrays of genreName and genreID
		// ID3v2.2.x, ID3v2.3.x: '(21)' or '(4)Eurodisco' or '(51)(39)' or '(55)((I think...)'
		// ID3v2.4.x: '21' $00 'Eurodisco' $00
		$clean_genres = array();

		// hack-fixes for some badly-written ID3v2.3 taggers, while trying not to break correctly-written tags
		if (($this->getid3->info['id3v2']['majorversion'] == 3) && !preg_match('#[\x00]#', $genrestring)) {
			// note: MusicBrainz Picard incorrectly stores plaintext genres separated by "/" when writing in ID3v2.3 mode, hack-fix here:
			// replace / with NULL, then replace back the two ID3v1 genres that legitimately have "/" as part of the single genre name
			if (strpos($genrestring, '/') !== false) {
				$LegitimateSlashedGenreList = array(  // https://github.com/JamesHeinrich/getID3/issues/223
					'Pop/Funk',    // ID3v1 genre #62 - https://en.wikipedia.org/wiki/ID3#standard
					'Cut-up/DJ',   // Discogs - https://www.discogs.com/style/cut-up/dj
					'RnB/Swing',   // Discogs - https://www.discogs.com/style/rnb/swing
					'Funk / Soul', // Discogs (note spaces) - https://www.discogs.com/genre/funk+%2F+soul
				);
				$genrestring = str_replace('/', "\x00", $genrestring);
				foreach ($LegitimateSlashedGenreList as $SlashedGenre) {
					$genrestring = str_ireplace(str_replace('/', "\x00", $SlashedGenre), $SlashedGenre, $genrestring);
				}
			}

			// some other taggers separate multiple genres with semicolon, e.g. "Heavy Metal;Thrash Metal;Metal"
			if (strpos($genrestring, ';') !== false) {
				$genrestring = str_replace(';', "\x00", $genrestring);
			}
		}


		if (strpos($genrestring, "\x00") === false) {
			$genrestring = preg_replace('#\(([0-9]{1,3})\)#', '$1'."\x00", $genrestring);
		}

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

Advertisement

Advertisement

Leave a Reply