Example #1
0
        static void Main(string[] args)
        {
            bool   verbose           = false;
            string startingDirectory = ".";
            int    totalFiles        = 0;
            int    totalSongsParsed  = 0;
            string connStr           = null;

            if (args.Length > 0)
            {
                startingDirectory = args[0];
                if (args.Length > 1)
                {
                    connStr = args[1];
                }
            } // else, should display "Usage" info
            SongWriter writer = null;

            if (connStr != null)
            {
                writer         = new SongWriter(connStr);
                writer.Verbose = verbose;
                if (!writer.connect())
                {
                    writer = null;
                }
            }
            string[] files = Directory.GetFiles(startingDirectory, "*.mp3", SearchOption.AllDirectories);
            foreach (string file in files)
            {
                Mp3Parser parser = new Mp3Parser(file);
                SongFile  song   = parser.parse();
                if (verbose)
                {
                    if (song != null)
                    {
                        Console.Out.WriteLine("" + song);
                    }
                    else
                    {
                        Console.Out.WriteLine("No data for " + file);
                    }
                }
                if ((song != null) && (song.Title != null))
                {
                    if (writer != null)
                    {
                        writer.writeSong(song);
                    }
                    totalSongsParsed++;
                }
                totalFiles++;
            }
            Console.Out.WriteLine("Files found = " + totalFiles + ", songs parsed = " + totalSongsParsed);
            if (writer != null)
            {
                writer.close();
            }
        }
Example #2
0
        public bool writeSong(SongFile song)
        {
            string query = "INSERT INTO songs ( title, artist, album, year, track ) VALUES ( " + quoteString(song.Title) +
                           ", " + quoteString(song.Artist) + ", " + quoteString(song.Album) + ", " + quoteString(song.Year) + ", " +
                           quoteString(song.Track) + " )";

            if (Verbose)
            {
                Console.Out.WriteLine("Query=" + query);
            }
            OdbcCommand cmd = new OdbcCommand(query, conn);

            cmd.ExecuteNonQuery();
            return(true);
        }
Example #3
0
 public Mp3Parser(string filename, SongFile song)
 {
     this.song     = song;
     song.Filename = filename;
 }
Example #4
0
 public Mp3Parser(string filename)
 {
     song          = new SongFile();
     song.Filename = filename;
 }