|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Id3
{
class test
{
public byte[] TAGID = new byte[3];
public byte[] Title = new byte[30];
public byte[] Artist = new byte[30];
public byte[] Album = new byte[30];
public byte[] Year = new byte[4];
public byte[] Comment = new byte[30];
public byte[] Genre = new byte[1];
//Search through directories and sub directories to find mp3's
//and I do this by a recursive method..
public void SearchDirectories(string StartPath)
{
string[] dirs = Directory.GetDirectories(StartPath);
if (dirs.Length > 0)
{
foreach (string subDirectories in dirs)
{
SearchDirectories(subDirectories);
}
}
//Will reach here after the current directory has been checked for other directories..
string[] fileNames = Directory.GetFiles(StartPath);
foreach (string fileName in fileNames)
{ // When utilizing "using" we get the benefit of not having to close the FileStream ourselves, this is done for us. (there is more, but I will elaborate on this later).
using (System.IO.FileStream fs = System.IO.File.OpenRead(fileName))
{ // The tag information is the last 128 bit of an mp3...
if (fs.Length >= 128)
{
test tag = new test();
fs.Seek(-128, System.IO.SeekOrigin.End);
fs.Read(tag.TAGID, 0, tag.TAGID.Length);
fs.Read(tag.Title, 0, tag.Title.Length);
fs.Read(tag.Artist, 0, tag.Artist.Length);
fs.Read(tag.Album, 0, tag.Album.Length);
fs.Read(tag.Year, 0, tag.Year.Length);
fs.Read(tag.Comment, 0, tag.Comment.Length);
fs.Read(tag.Genre, 0, tag.Genre.Length);
string theTAGID = Encoding.Default.GetString(tag.TAGID);
if (theTAGID.Equals("TAG"))
{
string Title = Encoding.Default.GetString(tag.Title);
string Artist = Encoding.Default.GetString(tag.Artist);
string Album = Encoding.Default.GetString(tag.Album);
string Year = Encoding.Default.GetString(tag.Year);
string Comment = Encoding.Default.GetString(tag.Comment);
string Genre = Encoding.Default.GetString(tag.Genre);
Console.WriteLine("Title: {0}", Title);
Console.WriteLine("Artist: {0}", Artist);
Console.WriteLine("Album: {0}", Album);
Console.WriteLine("Year: {0}", Year);
Console.WriteLine(Comment);
Console.WriteLine("Genre: {0}", Genre);
Console.WriteLine();
}
}
}
} Console.ReadLine();
}
}
}
|