using System;
using System.IO;
using System.Text;
class getID3
{
public string Title;
public string Artist;
public string Album;
public string Year;
public string Comment;
public string Track;
public string Genre;
public getID3(string path)
{
setFile(path);
}
public getID3()
{
;
}
public void setFile(string path)
{
string file = path;
Title = "";
Artist = "";
Album = "";
Year = "";
Comment = "";
Track = "";
Genre = "";
try
{
using (FileStream fs = File.OpenRead(file))
{
fs.Position = fs.Length - 128;
byte[] b = new byte[1024];
while (fs.Read(b,0,b.Length) > 0)
{
if(fs.Length - 128 < fs.Position)
{
for(int i = 0; i < b.Length; i++)
{
if(b[i] == 84 && b[i + 1] == 65 && b[i + 2] == 71)
{
int pos = i + 3;
//Get the title
for(int y = 0; y < 30; y++)
{
if(b[pos] == 0 && b[pos + 1] == 0)
{
pos += 30 - y;
y = 30;
}
else
{
Title = Title + Convert.ToString(Convert.ToChar(b[pos]));
pos++;
}
}
//Get the artist
for(int y = 0; y < 30; y++)
{
if(b[pos] == 0 && b[pos + 1] == 0)
{
pos += 30 - y;
y = 30;
}
else
{
Artist = Artist + Convert.ToString(Convert.ToChar(b[pos]));
pos++;
}
}
//Get the Album
for(int y = 0; y < 30; y++)
{
if(b[pos] == 0 && b[pos + 1] == 0)
{
pos += 30 - y;
y = 30;
}
else
{
Album = Album + Convert.ToString(Convert.ToChar(b[pos]));
pos++;
}
}
//Get the Year
for(int y = 0; y < 4; y++)
{
if(b[pos] == 0 && b[pos + 1] == 0)
{
pos += 4 - y;
y = 4;
}
else
{
Year = Year + Convert.ToString(Convert.ToChar(b[pos]));
pos++;
}
}
//Get the Comment
for(int y = 0; y < 28; y++)
{
if(b[pos] == 0 && b[pos + 1] == 0)
{
pos += 28 - y;
y = 28;
}
else
{
Comment = Comment + Convert.ToString(Convert.ToChar(b[pos]));
pos++;
}
}
//Get the Track
for(int y = 0; y < 2; y++)
{
if(b[pos] == 0 && b[pos + 1] == 0)
{
pos += 2 - y;
y = 2;
}
else
{
Track = Track + Convert.ToString(b[pos]);
pos++;
}
}
Title = Title.Trim();
Artist = Artist.Trim();
Album = Album.Trim();
Year = Year.Trim();
Comment = Comment.Trim();
Track = Track.Trim();
Genre = getGenre(b[pos]);
i = b.Length;
}
}
}
}
}
}
catch
{
;
}
}
public string getGenre(byte b)
{
string name;
switch(b)
{
case 0: name = "Blues"; break;
case 1: name = "Classic Rock"; break;
case 2: name = "Country"; break;
case 3: name = "Dance"; break;
case 4: name = "Disco"; break;
case 5: name = "Funk"; break;
case 6: name = "Grunge"; break;
case 7: name = "Hip-Hop"; break;
case 8: name = "Jazz"; break;
case 9: name = "Metal"; break;
case 10: name = "New Age"; break;
case 11: name = "Oldies"; break;
case 12: name = "Other"; break;
case 13: name = "Pop"; break;
case 14: name = "R&B"; break;
case 15: name = "Rap"; break;
case 16: name = "Reggae"; break;
case 17: name = "Rock"; break;
case 18: name = "Techno"; break;
case 19: name = "Industrial"; break;
case 20: name = "Alternative"; break;
case 21: name = "Ska"; break;
case 22: name = "Death Metal"; break;
case 23: name = "Pranks"; break;
case 24: name = "Soundtrack"; break;
case 25: name = "Euro-Techno"; break;
case 26: name = "Ambient"; break;
case 27: name = "Trip-Hop"; break;
case 28: name = "Vocal"; break;
case 29: name = "Jazz+Funk"; break;
case 30: name = "Fusion"; break;
case 31: name = "Trance"; break;
case 32: name = "Classical"; break;
case 33: name = "Instrumental"; break;
case 34: name = "Acid"; break;
case 35: name = "House"; break;
case 36: name = "Game"; break;
case 37: name = "Sound Clip"; break;
case 38: name = "Gospel"; break;
case 39: name = "Noise"; break;
case 40: name = "AlternRock"; break;
case 41: name = "Bass"; break;
case 42: name = "Soul"; break;
case 43: name = "Punk"; break;
case 44: name = "Space"; break;
case 45: name = "Meditative"; break;
case 46: name = "Instrumental Pop"; break;
case 47: name = "Instrumental Rock"; break;
case 48: name = "Ethnic"; break;
case 49: name = "Gothic"; break;
case 50: name = "Darkwave"; break;
case 51: name = "Techno-Industrial"; break;
case 52: name = "Electronic"; break;
case 53: name = "Pop-Folk"; break;
case 54: name = "Eurodance"; break;
case 55: name = "Dream"; break;
case 56: name = "Southern Rock"; break;
case 57: name = "Comedy"; break;
case 58: name = "Cult"; break;
case 59: name = "Gangsta"; break;
case 60: name = "Top 40"; break;
case 61: name = "Christian Rap"; break;
case 62: name = "Pop/Funk"; break;
case 63: name = "Jungle"; break;
case 64: name = "Native American"; break;
case 65: name = "Cabaret"; break;
case 66: name = "New Wave"; break;
case 67: name = "Psychedelic"; break;
case 68: name = "Rave"; break;
case 69: name = "Showtunes"; break;
case 70: name = "Trailer"; break;
case 71: name = "Lo-Fi"; break;
case 72: name = "Tribal"; break;
case 73: name = "Acid Punk"; break;
case 74: name = "Acid Jazz"; break;
case 75: name = "Polka"; break;
case 76: name = "Retro"; break;
case 77: name = "Musical"; break;
case 78: name = "Rock & Roll"; break;
case 79: name = "Hard Rock"; break;
default: name = null; break;
}
return name;
}
}