import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class LeerID3v1Etiquetas {
public static void main(String[] args) {
try {
File archivoMP3 = new File("input.mp3");
FileInputStream entradaArchivo = new FileInputStream(archivoMP3);
// Ir a la posición donde se encuentra la etiqueta ID3v1
entradaArchivo.skip(archivoMP3.length() - 128);
// Leer los datos de la etiqueta ID3v1
byte[] idTag = new byte[3];
entradaArchivo.read(idTag);
if ("TAG".equals(new String(idTag))) {
byte[] titulo = new byte[30];
byte[] artista = new byte[30];
byte[] album = new byte[30];
byte[] año = new byte[4];
byte[] comentario = new byte[30];
byte género = (byte) entradaArchivo.read();
entradaArchivo.read(titulo);
entradaArchivo.read(artista);
entradaArchivo.read(album);
entradaArchivo.read(año);
entradaArchivo.read(comentario);
String géneroStr = obtenerDescripciónGénero(género);
System.out.println("TAG");
System.out.println(new String(titulo).trim());
System.out.println(new String(artista).trim());
System.out.println(new String(album).trim());
System.out.println(new String(año).trim());
System.out.println(new String(comentario).trim());
System.out.println(géneroStr);
}
entradaArchivo.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String obtenerDescripciónGénero(byte género) {
String[] géneros = {
"Blues", "Classic Rock", "Country", "Dance", "Disco",
"Funk", "Grunge", "Hip-Hop", "Jazz", "Metal",
"New Age", "Oldies", "Other", "Pop", "R&B",
"Rap", "Reggae", "Rock", "Techno", "Industrial",
"Alternative", "Ska", "Death Metal", "Pranks", "Soundtrack",
"Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk",
"Fusion", "Trance", "Classical", "Instrumental", "Acid",
"House", "Game", "Sound Clip", "Gospel", "Noise",
"Alt. Rock", "Bass", "Soul", "Punk", "Space",
"Meditative", "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic",
"Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance",
"Dream", "Southern Rock", "Comedy", "Cult", "Gangsta",
"Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native American",
"Cabaret", "New Wave", "Psychadelic", "Rave", "Showtunes",
"Trailer", "Lo-Fi", "Tribal", "Acid Punk", "Acid Jazz",
"Polka", "Retro", "Musical", "Rock & Roll", "Hard Rock",
"Folk", "Folk-Rock", "National Folk", "Swing", "Fast Fusion",
"Bebop", "Latin", "Revival", "Celtic", "Bluegrass",
"Avantgarde", "Gothic Rock", "Progressive Rock", "Psychedelic Rock", "Symphonic Rock",
"Slow Rock", "Big Band", "Chorus", "Easy Listening", "Acoustic",
"Humour", "Speech", "Chanson", "Opera", "Chamber Music",
"Sonata", "Symphony", "Booty Bass", "Primus", "Porn Groove",
"Satire", "Slow Jam", "Club", "Tango", "Samba",
"Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle",
"Duet", "Punk Rock", "Drum Solo", "Acapella", "Euro-House",
"Dance Hall", "Goa", "Drum & Bass", "Club-House", "Hardcore",
"Terror", "Indie", "BritPop", "Negerpunk", "Polsk Punk",
"Beat", "Christian Gangsta Rap", "Heavy Metal", "Black Metal", "Crossover",
"Contemporary Christian", "Christian Rock", "Merengue", "Salsa", "Trash Metal",
"Anime", "JPop", "Synthpop"
};
if (género >= 0 && género < géneros.length) {
return géneros[género];
} else {
return "Desconocido";
}
}
}