function StandardiseID3v1GenreName($OriginalGenre) { if (($GenreID = getid3_id3v1::LookupGenreID($OriginalGenre)) !== false) { return getid3_id3v1::LookupGenreName($GenreID); } return $OriginalGenre; }
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 $genrestring = trim($genrestring); $returnarray = array(); if (strpos($genrestring, "") !== false) { $unprocessed = trim($genrestring); // trailing nulls will cause an infinite loop. $genrestring = ''; while (strpos($unprocessed, "") !== false) { // convert null-seperated v2.4-format into v2.3 ()-seperated format $endpos = strpos($unprocessed, ""); $genrestring .= '(' . substr($unprocessed, 0, $endpos) . ')'; $unprocessed = substr($unprocessed, $endpos + 1); } unset($unprocessed); } if (getid3_id3v1::LookupGenreID($genrestring)) { $returnarray['genre'][] = $genrestring; } else { while (strpos($genrestring, '(') !== false) { $startpos = strpos($genrestring, '('); $endpos = strpos($genrestring, ')'); if (substr($genrestring, $startpos + 1, 1) == '(') { $genrestring = substr($genrestring, 0, $startpos) . substr($genrestring, $startpos + 1); $endpos--; } $element = substr($genrestring, $startpos + 1, $endpos - ($startpos + 1)); $genrestring = substr($genrestring, 0, $startpos) . substr($genrestring, $endpos + 1); if (getid3_id3v1::LookupGenreName($element)) { // $element is a valid genre id/abbreviation if (empty($returnarray['genre']) || !in_array(getid3_id3v1::LookupGenreName($element), $returnarray['genre'])) { // avoid duplicate entires $returnarray['genre'][] = getid3_id3v1::LookupGenreName($element); } } else { if (empty($returnarray['genre']) || !in_array($element, $returnarray['genre'])) { // avoid duplicate entires $returnarray['genre'][] = $element; } } } } if ($genrestring) { if (empty($returnarray['genre']) || !in_array($genrestring, $returnarray['genre'])) { // avoid duplicate entires $returnarray['genre'][] = $genrestring; } } return $returnarray; }
function FormatDataForID3v1() { $tag_data_id3v1['genreid'] = 255; if (!empty($this->tag_data['GENRE'])) { foreach ($this->tag_data['GENRE'] as $key => $value) { if (getid3_id3v1::LookupGenreID($value) !== false) { $tag_data_id3v1['genreid'] = getid3_id3v1::LookupGenreID($value); break; } } } $tag_data_id3v1['title'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['TITLE'])); $tag_data_id3v1['artist'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['ARTIST'])); $tag_data_id3v1['album'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['ALBUM'])); $tag_data_id3v1['year'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['YEAR'])); $tag_data_id3v1['comment'] = getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['COMMENT'])); $tag_data_id3v1['track'] = intval(getid3_lib::iconv_fallback($this->tag_encoding, 'ISO-8859-1', @implode(' ', @$this->tag_data['TRACKNUMBER']))); if ($tag_data_id3v1['track'] <= 0) { $tag_data_id3v1['track'] = ''; } $this->MergeExistingTagData('id3v1', $tag_data_id3v1); return $tag_data_id3v1; }
echo WindowsShareSlashTranslate($row['filename']) . "\n"; } exit; } else { if ($_REQUEST['genredistribution'] == '%') { $SQLquery = 'SELECT COUNT(*) AS `num`, `genre`'; $SQLquery .= ' FROM `' . mysql_real_escape_string(GETID3_DB_TABLE) . '`'; $SQLquery .= ' WHERE (`fileformat` NOT LIKE "' . implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats) . '")'; $SQLquery .= ' GROUP BY `genre`'; $SQLquery .= ' ORDER BY `num` DESC'; $result = mysql_query_safe($SQLquery); getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'module.tag.id3v1.php', __FILE__, true); echo '<table border="1" cellspacing="0" cellpadding="4">'; echo '<tr><th>Count</th><th>Genre</th><th>m3u</th></tr>'; while ($row = mysql_fetch_array($result)) { $GenreID = getid3_id3v1::LookupGenreID($row['genre']); if (is_numeric($GenreID)) { echo '<tr bgcolor="#00FF00;">'; } else { echo '<tr bgcolor="#FF9999;">'; } echo '<td><a href="' . htmlentities($_SERVER['PHP_SELF'] . '?genredistribution=' . urlencode($row['genre'])) . '">' . number_format($row['num']) . '</a></td>'; echo '<td nowrap>' . str_replace("\t", '<br>', $row['genre']) . '</td>'; echo '<td><a href="' . htmlentities($_SERVER['PHP_SELF'] . '?m3u=.m3u&genredistribution=' . urlencode($row['genre'])) . '">.m3u</a></td>'; echo '</tr>'; } echo '</table><hr>'; } else { $SQLquery = 'SELECT `filename`, `genre`'; $SQLquery .= ' FROM `' . mysql_real_escape_string(GETID3_DB_TABLE) . '`'; $SQLquery .= ' WHERE (`genre` LIKE "' . mysql_real_escape_string($_REQUEST['genredistribution']) . '")';
protected function generate_tag() { $result = 'TAG'; $result .= str_pad(trim(substr($this->title, 0, 30)), 30, "", STR_PAD_RIGHT); $result .= str_pad(trim(substr($this->artist, 0, 30)), 30, "", STR_PAD_RIGHT); $result .= str_pad(trim(substr($this->album, 0, 30)), 30, "", STR_PAD_RIGHT); $result .= str_pad(trim(substr($this->year, 0, 4)), 4, "", STR_PAD_LEFT); if (!empty($this->track) && $this->track > 0 && $this->track <= 255) { $result .= str_pad(trim(substr($this->comment, 0, 28)), 28, "", STR_PAD_RIGHT); $result .= ""; $result .= chr($this->track); } else { $result .= str_pad(trim(substr($comment, 0, 30)), 30, "", STR_PAD_RIGHT); } // both genre and genre_id set if ($this->genre && $this->genre_id) { if ($this->genre != getid3_id3v1::LookupGenreName($this->genre_id)) { throw new getid3_exception('Genre and genre_id does not match. Unset one and the other will be determined automatically.'); } } elseif ($this->genre) { $this->genre_id = getid3_id3v1::LookupGenreID($this->genre); } else { if ($this->genre_id < 0 || $this->genre_id > 147) { $this->genre_id = 255; // 'unknown' genre } $this->genre = getid3_id3v1::LookupGenreName($this->genre_id); } $result .= chr(intval($this->genre_id)); return $result; }
public static function ParseID3v2GenreString($genre_string) { // 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 $genre_string = trim($genre_string); $return_array = array(); if (strpos($genre_string, "") !== false) { $unprocessed = trim($genre_string); // trailing nulls will cause an infinite loop. $genre_string = ''; while (strpos($unprocessed, "") !== false) { // convert null-seperated v2.4-format into v2.3 ()-seperated format $end_pos = strpos($unprocessed, ""); $genre_string .= '(' . substr($unprocessed, 0, $end_pos) . ')'; $unprocessed = substr($unprocessed, $end_pos + 1); } unset($unprocessed); } elseif (preg_match('/^([0-9]+|CR|RX)$/i', $genre_string)) { // some tagging program (including some that use TagLib) fail to include null byte after numeric genre $genre_string = '(' . $genre_string . ')'; } if (getid3_id3v1::LookupGenreID($genre_string)) { $return_array['genre'][] = $genre_string; } else { while (strpos($genre_string, '(') !== false) { $start_pos = strpos($genre_string, '('); $end_pos = strpos($genre_string, ')'); if (substr($genre_string, $start_pos + 1, 1) == '(') { $genre_string = substr($genre_string, 0, $start_pos) . substr($genre_string, $start_pos + 1); $end_pos--; } $element = substr($genre_string, $start_pos + 1, $end_pos - ($start_pos + 1)); $genre_string = substr($genre_string, 0, $start_pos) . substr($genre_string, $end_pos + 1); if (getid3_id3v1::LookupGenreName($element)) { // $element is a valid genre id/abbreviation if (empty($return_array['genre']) || !in_array(getid3_id3v1::LookupGenreName($element), $return_array['genre'])) { // avoid duplicate entires $return_array['genre'][] = getid3_id3v1::LookupGenreName($element); } } else { if (empty($return_array['genre']) || !in_array($element, $return_array['genre'])) { // avoid duplicate entires $return_array['genre'][] = $element; } } } } if ($genre_string) { if (empty($return_array['genre']) || !in_array($genre_string, $return_array['genre'])) { // avoid duplicate entires $return_array['genre'][] = $genre_string; } } return $return_array; }