import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class LeerID3v1Etiquetas {
public static void main(String[] args) {
try {
File mp3File = new File("input.mp3");
FileInputStream fileInputStream = new FileInputStream(mp3File);
// Seek to the position where the ID3v1 tag is located
fileInputStream.skip(mp3File.length() - 128);
// Read the ID3v1 tag data
byte[] idTag = new byte[3];
fileInputStream.read(idTag);
if ("TAG".equals(new String(idTag))) {
byte[] title = new byte[30];
byte[] artist = new byte[30];
byte[] album = new byte[30];
byte[] year = new byte[4];
byte[] comment = new byte[30];
byte genre = (byte) fileInputStream.read();
fileInputStream.read(title);
fileInputStream.read(artist);
fileInputStream.read(album);
fileInputStream.read(year);
fileInputStream.read(comment);
String genreStr = getGenreDescription(genre);
System.out.println("TAG");
System.out.println(new String(title).trim());
System.out.println(new String(artist).trim());
System.out.println(new String(album).trim());
System.out.println(new String(year).trim());
System.out.println(new String(comment).trim());
System.out.println(genreStr);
}
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getGenreDescription(byte genre) {
String[] genres = {
"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 (genre >= 0 && genre < genres.length) {
return genres[genre];
} else {
return "Unknown";
}
}
}