$OpenBSD: patch-cddb_pl,v 1.3 2003/09/23 05:09:06 jolan Exp $ --- cddb.pl.orig 2003-08-23 12:00:32.000000000 -0700 +++ cddb.pl 2003-08-23 12:02:49.000000000 -0700 @@ -27,7 +27,7 @@ use Getopt::Std; use strict; my %option = (); -getopts("oghdtsiSfDlOFc:", \%option); +getopts("oghdtsSfDlOFc:", \%option); if($option{h}) { print "$0: gets CDDB info of a CD\n"; @@ -36,8 +36,7 @@ if($option{h}) { print " -o offline mode - just stores CD info\n"; print " -d output in xmcd format\n"; print " -s save in xmcd format\n"; - print " -i write to mysql db\n"; - print " -O overwrite file or db\n"; + print " -O overwrite file\n"; print " -t output toc\n"; print " -l output lame command\n"; print " -f http mode (e.g. through firewalls)\n"; @@ -87,19 +86,6 @@ $config{input}=1; # 1: ask user if mor $config{multi}=0; # 1: do not ask user and get all of them # 0: just the first one -my %db; - -if($option{i}) { - require DBI; - - $db{host} = "localhost:3306"; - $db{name} = "mp3-test"; - $db{table_cds} = "cds"; - $db{table_tracks} = "tracks"; - $db{user} = "root"; - $db{passwd} = "xxx"; -} - if($option{o}) { my $ids=get_discids($config{CD_DEVICE}); @@ -160,8 +146,6 @@ if($option{g}) { if($option{d} || $option{s}) { print_xmcd(\%cd,$option{s}); - } elsif($option{i}) { - insert_db(\%cd,\%db); } elsif($option{l}) { print_lame(\%cd); } else { @@ -196,8 +180,6 @@ unless($config{multi}) { if($option{d} || $option{s}) { print_xmcd(\%cd,$option{s}); - } elsif($option{i}) { - insert_db(\%cd,\%db); } elsif($option{l}) { print_lame(\%cd); } else { @@ -226,8 +208,6 @@ unless($config{multi}) { if($option{d} || $option{s}) { print_xmcd($c,$option{s}); - } elsif($option{i}) { - insert_db($c,\%db); } elsif($option{l}) { print_lame($c); print "\n"; @@ -304,67 +284,6 @@ sub print_xmcd { } } -sub insert_db { - my $cd=shift; - my $db=shift; - - my ($artist, $title, $category, $cddbid, $trackno) = - ($cd->{artist}, $cd->{title}, $cd->{cat}, $cd->{id}, $cd->{tno}); - - my $sql = "SELECT cddbid FROM $db->{table_cds} WHERE CDDBID = \'$cddbid\'"; - my $dbh = DBI->connect("dbi:mysql:$db->{name}:$db->{host}", - $db->{user},$db->{passwd}) or die "cannot connect to db: $DBI::errstr"; - my $sth = $dbh->prepare($sql); - my $r = $sth->execute or die "cannot check for cd: $DBI::errstr"; - if ($r == 1) { - print "cd already in db\n"; - if($option{O}) { - my $sql = "DELETE FROM $db->{table_cds} WHERE CDDBID = \'$cddbid\'"; - my $sth = $dbh->prepare($sql); - my $r = $sth->execute or die "cannot delete from $db->{table_cds}: $DBI::errstr"; - $sql = "DELETE FROM $db->{table_tracks} WHERE CDDBID = \'$cddbid\'"; - $sth = $dbh->prepare($sql); - $r = $sth->execute or die "cannot delete from $db->{table_tracks}: $DBI::errstr"; - } else { - exit; - } - } - - $title =~ s/'/\\'/g; - $artist =~ s/'/\\'/g; - $category =~ s/'/\\'/g; - - $sql = "INSERT INTO $db->{table_cds} (cddbid, artist, title, category, tracks) VALUES (\'$cddbid\', \'$artist\', \'$title\', \'$category\' , \'$trackno\')"; - $sth = $dbh->prepare($sql); - $r = $sth->execute or die "failed to insert cd: $DBI::errstr"; - - my $n=1; - - print "titel: $title\n"; - print "artist: $artist\n"; - print "category: $category\n\n"; - - for my $t ( @{$cd->{track}} ) { - $t =~ s/'/\\'/g; - my $dur=($cd->{frames}[$n]-1-$cd->{frames}[$n-1])/75; - my $hour=int($dur/3600); - my $min=int($dur/60-$hour*60); - my $sec=$dur-$hour*3600-$min*60; - my $fr=substr(sprintf("%5.2f",$sec-int($sec)),2,3); - my $time=sprintf "%.2d:%.2d:%.2d%s",$hour,$min,int($sec),$fr; - - print "track $n: $t [$time]\n"; - - my $sql = "INSERT INTO $db->{table_tracks} (cddbid, title, trackno, time) - VALUES (\'$cddbid\',\'$t\', \'$n\', \'$time\')"; - my $sth = $dbh->prepare($sql); - my $r = $sth->execute or die "failed to insert track $n: $DBI::errstr"; - $n++; - } - - $dbh->disconnect(); -} - sub print_lame { my $cd=shift;