#!/usr/bin/perl -w ## dbtest.pl - brent@bctek.com ## ## Test script to recursively search through a series of ## directories and create a database of the information on ## the mp3's found within the directories. ## ## Must first create a an MS Access Database with a TABLE named MP3NAME with ## the following fields. The ID field should be set as primary key and autoincrement. ## All the other fields are just set as text. ## ## ID | SONG | ARTIST | ALBUM | GENRE | YEAR | LENGTH | VBR | BITRATE | FILENAME | PATH ## |__ Primary Key use strict; use DBI; use MP3::Info; use File::Find; use File::Basename; my $ACCESS_DB = '//fmlypwr/database/mymp3s.mdb'; # location of ACCESS DATABASE my $mp3_path = 'd:/'; # TOPLEVEL directory of mp3's my $DSN = "driver=Microsoft Access Driver (*.mdb);dbq=$ACCESS_DB"; my $dbh = DBI->connect("dbi:ODBC:$DSN", ",") or die "$DBI::errstr\n"; my $sth = $dbh->prepare('INSERT INTO MP3NAME (SONG,ARTIST,ALBUM,GENRE,YEAR,LENGTH,VBR,BITRATE,FILENAME,PATH) VALUES (?,?,?,?,?,?,?,?,?,?)') or die "Couldn't prepare statement: " . $dbh->errstr; fileparse_set_fstype("MSWin32"); sub insert_file { my $type = (fileparse($_, '\.mp3'))[2]; return unless (lc($type) eq '.mp3'); my $mp3 = MP3::Info->new($_); if (defined $mp3) { my $artist = $mp3->artist; my $album = $mp3->album; my $song = $mp3->title; my $genre = $mp3->genre; my $year = $mp3->year; my $fileinfo = get_mp3info($_); my $time = "$fileinfo->{TIME}"; my $vbr = $fileinfo->{VBR}; my $bitrate = $fileinfo->{BITRATE}; my $fullname = $File::Find::name; $fullname =~ s/\//\\/g; #fix path for windows format $sth->execute($song,$artist,$album,$genre,$year,$time,$vbr,$bitrate,$_,$fullname) or die "Couldn't execute statement: " . $sth->errstr; } } print "START DIRECTORY: $mp3_path\n\n"; find({ wanted => \&insert_file }, $mp3_path); $dbh->disconnect;