#!/usr/bin/env perl =head1 USAGE perl myfreedb.pl To retreive via FREEDB the information (artist,title, list of songs) about the inserted audio CD and then store it in a MySql Database =head1 REQUIREMENT The perl modules FreeDB and DBI are required. I've tested this script on a Linux Debian with perl 5.6 and MySql. You have to create a MySql database (for example "mysqladmin -u root create music") and then create the two following tables (with mysql -u root music): CREATE TABLE cd ( discid varchar(15) NOT NULL default '', artist varchar(40) NOT NULL default '', title varchar(200) NOT NULL default '', added datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (discid) ) TYPE=MyISAM COMMENT='cd '; CREATE TABLE cd_songs ( discid varchar(15) NOT NULL default '', pos char(3) NOT NULL default '', title varchar(60) default NULL ) TYPE=MyISAM COMMENT='cd songs'; =head1 HISTORY 2002-08-03 Matteo: first rows of this script =head1 AUTHOR E-MAIL: matteo.redaelli@libero.it WEB: http://digilander.iol.it/reda =head1 LICENSE This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License". The C library at the core of this Perl module can additionally be redistributed and/or modified under the terms of the "GNU Library General Public License". =head1 DISCLAIMER This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "GNU General Public License" for more details. =cut use FreeDB; use DBI; use strict; # personalize the following parameters my $host="localhost"; my $database="music"; my $username="root"; my $password=""; my $myproxy="http://151.10.46.84:8080"; # start of teh script my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = gmtime( time ); $mon++; $year += 1900; my $cddb = new FreeDB; $cddb->{"proxy_value"} = "$myproxy"; my $success = $cddb->fetch(); if (!$success) { print "couldn't fetch cd info\n"; exit 1; } # ok, cd info are available... # now I want to open my database and store info.. my $dbh = DBI->connect("DBI:mysql:$database", $username, $password) or die "Couldn't connect to database $database: " . DBI->errstr; # now I'm connected to the database! my $sth = $dbh->prepare("INSERT INTO cd (discid, artist, title, added) VALUES (?,?,?, ?)"); my $sth_songs = $dbh->prepare("INSERT INTO cd_songs (discid, pos, title) VALUES (?,?,?)"); $sth->execute( $cddb->discid, $cddb->artist, $cddb->title, "$year-$mon-$mday $hour:$min:$sec") or die "Unable to add cd info to database $database"; print $cddb->artist . "\n"; print $cddb->discid . "\n"; print $cddb->title . "\n\n"; while ($cddb->next_track) { $sth_songs->execute( $cddb->discid, $cddb->current_track_number_padded, $cddb->current_track_info) or die "Unable to cd songs info to database $database"; print $cddb->current_track_number_padded, ". "; print $cddb->current_track_info; print " (", $cddb->current_track_time_in_minutes, ")\n"; } print "\n\n", $cddb->disc_info, "\n"; #$dbh->commit; my $rc = $dbh->disconnect; exit $rc;