#!/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 MP3NAM +E 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 ACC +ESS DATABASE my $mp3_path = 'd:/'; # TOPLEVEL direct +ory 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,FILEN +AME,PATH) VALUES (?,?,?,?,?,?,?,?,?,?)') or die "Couldn't prepar +e 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,$bitrat +e,$_,$fullname) or die "Couldn't execute statement: " . $sth->errstr; } } print "START DIRECTORY: $mp3_path\n\n"; find({ wanted => \&insert_file }, $mp3_path); $dbh->disconnect;

In reply to MP3 Database Creation by zzspectrez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.