CDDB_get-2.28/0000755000076500001440000000000011725453533012042 5ustar arminusersCDDB_get-2.28/t/0000755000076500001440000000000011725453533012305 5ustar arminusersCDDB_get-2.28/t/use.t0000644000076500001440000000044511725452025013264 0ustar arminusers#!/usr/bin/env perl -w BEGIN { if( $ENV{PERL_CORE} ) { chdir 't'; @INC = ('../lib', 'lib'); } else { unshift @INC, 't/lib'; } } use Test::More; my $result; BEGIN { $result = use_ok("CDDB_get"); } ok( $result, "use_ok() ran" ); done_testing(2); CDDB_get-2.28/README0000644000076500001440000000311507717477565012743 0ustar arminusersNAME CDDB - Read the CDDB entry for an audio CD in your drive DESCRIPTION This module/script gets the CDDB info for an audio cd. You need LINUX, SUNOS or *BSD, a cdrom drive and an active internet connection in order to do that. INSTALLATION Run "perl Makefile.pl" as usual. ("make", "make install" next) LICENSE & DISCLAIMER This library is released under the same conditions as Perl, that is, either of the following: a) the GNU General Public License Version 2 as published by the Free Software Foundation, b) the Artistic License. This program 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 either the GNU General Public License or the Artistic License for more details. You should have received a copy of the Artistic License with this Kit, in the file named "Artistic". If not, I'll be glad to provide one. You should also have received a copy of the GNU General Public License along with this program, in the file names "Copying"; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. If you use this library in a commercial enterprise, you are invited, but not required, to pay what you feel is a reasonable fee to the author, who can be contacted at armin@xos.net AUTHOR & COPYRIGHT (c) 2003 Armin Obersteiner SEE ALSO perl(1), Linux: , Solaris: . CDDB_get-2.28/CDDB_get.pm0000644000076500001440000003773611725453510013746 0ustar arminusers# # CDDB - Read the CDDB entry for an audio CD in your drive # # This module/script gets the CDDB info for an audio cd. You need # LINUX, a cdrom drive and an active internet connection in order # to do that. # # (c) 2004 Armin Obersteiner # # LICENSE # # This library is released under the same conditions as Perl, that # is, either of the following: # # a) the GNU General Public License Version 2 as published by the # Free Software Foundation, # # b) the Artistic License. # package CDDB_get; use Config; use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $debug); require Exporter; @ISA = qw(Exporter AutoLoader); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. @EXPORT_OK = qw( get_cddb get_discids ); $VERSION = '2.28'; use Fcntl; use IO::Socket; use Data::Dumper qw(Dumper); use MIME::Base64 qw(encode_base64); $debug=1; # setup for linux, solaris x86, solaris spark # you freebsd guys give me input print STDERR "cddb: checking for os ... " if $debug; my $os=`uname -s`; my $machine=`uname -m`; chomp $os; chomp $machine; print STDERR "$os ($machine) " if $debug; # cdrom IOCTL magic (from c headers) # linux x86 is default # /usr/include/linux/cdrom.h my $CDROMREADTOCHDR=0x5305; my $CDROMREADTOCENTRY=0x5306; my $CDROM_MSF=0x02; # default config my $CDDB_HOST = "freedb.freedb.org"; my $CDDB_PORT = 8880; my $CDDB_MODE = "cddb"; my $CD_DEVICE = "/dev/cdrom"; my $HELLO_ID = "root nowhere.com fastrip 0.77"; my $PROTO_VERSION = 5; # endian check my $BIG_ENDIAN = unpack("h*", pack("s", 1)) =~ /01/; if($BIG_ENDIAN) { print STDERR "[big endian] " if $debug; } else { print STDERR "[little endian] " if $debug; } # 64bit pointer check my $BITS_64 = $Config{ptrsize} == 8 ? 1 : 0; if($BITS_64) { print STDERR "[64 bit]\n" if $debug; } else { print STDERR "[32 bit]\n" if $debug; } if($os eq "SunOS") { # /usr/include/sys/cdio.h $CDROMREADTOCHDR=0x49b; # 1179 $CDROMREADTOCENTRY=0x49c; # 1180 if(-e "/vol/dev/aliases/cdrom0") { $CD_DEVICE="/vol/dev/aliases/cdrom0"; } else { if($machine =~ /^sun/) { # on sparc and old suns $CD_DEVICE="/dev/rdsk/c0t6d0s0"; } else { # on intel $CD_DEVICE="/dev/rdsk/c1t0d0p0"; } } } elsif($os =~ /BSD/i) { # works for netbsd, infos for other bsds welcome # /usr/include/sys/cdio.h $CDROMREADTOCHDR=0x40046304; $CDROMREADTOCENTRY=0xc0086305; if($BITS_64) { $CDROMREADTOCENTRY=0xc0106305; } $CD_DEVICE="/dev/cd0a"; if($os eq "OpenBSD") { $CD_DEVICE="/dev/cd0c"; } } sub read_toc { my $device=shift; my $tochdr=chr(0) x 16; sysopen (CD,$device, O_RDONLY | O_NONBLOCK) or die "cannot open cdrom [$!] [$device]"; ioctl(CD, $CDROMREADTOCHDR, $tochdr) or die "cannot read toc [$!] [$device]"; my ($start,$end); if($os =~ /BSD/) { ($start,$end)=unpack "CC",(substr $tochdr,2,2); } else { ($start,$end)=unpack "CC",$tochdr; } print STDERR "start track: $start, end track: $end\n" if $debug; my @tracks=(); for (my $i=$start; $i<=$end;$i++) { push @tracks,$i; } push @tracks,0xAA; my @r=(); my $tocentry; my $toc=""; my $size=0; for(@tracks) { $toc.=" "; $size+=8; } if($os =~ /BSD/) { my $size_hi=int($size / 256); my $size_lo=$size & 255; if($BIG_ENDIAN) { if($BITS_64) { # better but just perl >= 5.8.0 # $tocentry=pack "CCCCx![P]P", $CDROM_MSF,0,$size_hi,$size_lo,$toc; $tocentry=pack "CCCCxxxxP", $CDROM_MSF,0,$size_hi,$size_lo,$toc; } else { $tocentry=pack "CCCCP8l", $CDROM_MSF,0,$size_hi,$size_lo,$toc; } } else { if($BITS_64) { $tocentry=pack "CCCCxxxxP", $CDROM_MSF,0,$size_lo,$size_hi,$toc; } else { $tocentry=pack "CCCCP8l", $CDROM_MSF,0,$size_lo,$size_hi,$toc; } } ioctl(CD, $CDROMREADTOCENTRY, $tocentry) or die "cannot read track info [$!] [$device]"; } my $count=0; foreach my $i (@tracks) { my ($min,$sec,$frame); unless($os =~ /BSD/) { $tocentry=pack "CCC", $i,0,$CDROM_MSF; $tocentry.=chr(0) x 16; ioctl(CD, $CDROMREADTOCENTRY, $tocentry) or die "cannot read track $i info [$!] [$device]"; ($min,$sec,$frame)=unpack "CCCC", substr($tocentry,4,4); } else { ($min,$sec,$frame)=unpack "CCC", substr($toc,$count+5,3); } $count+=8; my %cdtoc=(); $cdtoc{min}=$min; $cdtoc{sec}=$sec; $cdtoc{frame}=$frame; $cdtoc{frames}=int($frame+$sec*75+$min*60*75); my $data = unpack("C",substr($tocentry,1,1)); $cdtoc{data} = 0; if($data & 0x40) { $cdtoc{data} = 1; } push @r,\%cdtoc; } close(CD); return @r; } sub cddb_sum { my $n=shift; my $ret=0; while ($n > 0) { $ret += ($n % 10); $n = int $n / 10; } return $ret; } sub cddb_discid { my $total=shift; my $toc=shift; my $i=0; my $t=0; my $n=0; while ($i < $total) { $n = $n + cddb_sum(($toc->[$i]->{min} * 60) + $toc->[$i]->{sec}); $i++; } $t = (($toc->[$total]->{min} * 60) + $toc->[$total]->{sec}) - (($toc->[0]->{min} * 60) + $toc->[0]->{sec}); return (($n % 0xff) << 24 | $t << 8 | $total); } sub get_discids { my $cd=shift; $CD_DEVICE = $cd if (defined($cd)); my @toc=read_toc($CD_DEVICE); my $total=$#toc; my $id=cddb_discid($total,\@toc); return [$id,$total,\@toc]; } sub get_cddb { my $config=shift; my $diskid=shift; my $id; my $toc; my $total; my @r; my $input = $config->{input}; my $multi = $config->{multi}; $input = 0 if $multi; print STDERR Dumper($config) if $debug; $CDDB_HOST = $config->{CDDB_HOST} if (defined($config->{CDDB_HOST})); $CDDB_PORT = $config->{CDDB_PORT} if (defined($config->{CDDB_PORT})); $CDDB_MODE = $config->{CDDB_MODE} if (defined($config->{CDDB_MODE})); $CD_DEVICE = $config->{CD_DEVICE} if (defined($config->{CD_DEVICE})); $HELLO_ID = $config->{HELLO_ID} if (defined($config->{HELLO_ID})); $PROTO_VERSION = $config->{PROTO_VERSION} if (defined($config->{PROTO_VERSION})); my $HTTP_PROXY = $config->{HTTP_PROXY} if (defined($config->{HTTP_PROXY})); my $FW=1 if (defined($config->{FW})); if(defined($diskid)) { $id=$diskid->[0]; $total=$diskid->[1]; $toc=$diskid->[2]; } else { my $diskid=get_discids($CD_DEVICE); $id=$diskid->[0]; $total=$diskid->[1]; $toc=$diskid->[2]; } my @list=(); my $return; my $socket; my $id2 = sprintf "%08x", $id; my $query = "cddb query $id2 $total"; for (my $i=0; $i<$total ;$i++) { $query.=" $toc->[$i]->{frames}"; } # this was to old total calculation, does not work too well, its included if new version makes problems # $query.=" ". int(($toc->[$total]->{frames}-$toc->[0]->{frames})/75); $query.=" ". int(($toc->[$total]->{frames})/75); print Dumper($toc) if $debug; if ($CDDB_MODE eq "cddb") { print STDERR "cddb: connecting to $CDDB_HOST:$CDDB_PORT\n" if $debug; $socket=IO::Socket::INET->new(PeerAddr=>$CDDB_HOST, PeerPort=>$CDDB_PORT, Proto=>"tcp",Type=>SOCK_STREAM) or die "cannot connect to cddb db: $CDDB_HOST:$CDDB_PORT [$!]"; $return=<$socket>; unless ($return =~ /^2\d\d\s+/) { die "not welcome at cddb db"; } print $socket "cddb hello $HELLO_ID\n"; $return=<$socket>; print STDERR "hello return: $return" if $debug; unless ($return =~ /^2\d\d\s+/) { die "handshake error at cddb db: $CDDB_HOST:$CDDB_PORT"; } print $socket "proto $PROTO_VERSION\n"; $return=<$socket>; print STDERR "proto return: $return" if $debug; unless ($return =~ /^2\d\d\s+/) { die "protokoll mismatch error at cddb db: $CDDB_HOST:$CDDB_PORT"; } print STDERR "cddb: sending: $query\n" if $debug; print $socket "$query\n"; $return=<$socket>; chomp $return; print STDERR "cddb: result: $return\n" if $debug; } elsif ($CDDB_MODE eq "http") { my $query2=$query; $query2 =~ s/ /+/g; my $id=$HELLO_ID; $id =~ s/ /+/g; my $url = "/~cddb/cddb.cgi?cmd=$query2&hello=$id&proto=$PROTO_VERSION"; my $host=$CDDB_HOST; my $port=80; my ($user,$pass); if($HTTP_PROXY) { if($HTTP_PROXY =~ /^(http:\/\/|)(.+?):(.+)\@(.+?):(.+)/) { $user=$2; $pass=$3; $host=$4; $port=$5; } elsif($HTTP_PROXY =~ /^(http:\/\/|)(.+?):(\d+)/) { $host=$2; $port=$3; } $url="http://$CDDB_HOST".$url." HTTP/1.0"; } print STDERR "cddb: connecting to $host:$port\n" if $debug; $socket=IO::Socket::INET->new(PeerAddr=>$host, PeerPort=>$port, Proto=>"tcp",Type=>SOCK_STREAM) or die "cannot connect to cddb db: $host:$port [$!]"; print STDERR "cddb: http send: GET $url\n" if $debug; print $socket "GET $url\n"; if($user) { my $cred = encode_base64("$user:$pass"); print $socket "Proxy-Authorization: Basic $cred\n"; } print $socket "\n"; print $socket "\n" if $FW; if($HTTP_PROXY) { while(<$socket> =~ /^\S+/){}; } $return=<$socket>; chomp $return; print STDERR "cddb: http result: $return\n" if $debug; } else { die "unkown mode: $CDDB_MODE for querying cddb"; } $return =~ s/\r//g; my ($err) = $return =~ /^(\d\d\d)\s+/; unless ($err =~ /^2/) { die "query error at cddb db: $CDDB_HOST:$CDDB_PORT"; } if($err==202) { return undef; } elsif(($err==211) || ($err==210)) { while(<$socket>) { last if(/^\./); push @list,$_; s/\r//g; print STDERR "unexact: $_" if $debug; } } elsif($err==200) { $return =~ s/^200 //; push @list,$return; } else { die "cddb: unknown: $return"; } my @to_get; unless($multi) { if (@list) { my $index; if($input==1) { print "This CD could be:\n\n"; my $i=1; for(@list) { my ($tit) = $_ =~ /^\S+\s+\S+\s+(.*)/; print "$i: $tit\n"; $i++ } print "\n0: none of the above\n\nChoose: "; my $n=; $index=int($n); } else { $index=1; } if ($index == 0) { return undef; } else { push @to_get,$list[$index-1]; } } } else { push @to_get,@list; } my $i=0; for my $get (@to_get) { #200 misc 0a01e802 Meredith Brooks / Bitch Single my ($cat,$id,$at) = $get =~ /^(\S+?)\s+(\S+?)\s+(.*)/; my $artist; my $title; if($at =~ /\//) { ($artist,$title)= $at =~ /^(.*?)\s\/\s(.*)/; } else { $artist=$at; $title=$at; } my %cd=(); $cd{artist}=$artist; chomp $title; $title =~ s/\r//g; $cd{title}=$title; $cd{cat}=$cat; $cd{id}=$id; my @lines; $query="cddb read $cat $id"; if ($CDDB_MODE eq "cddb") { print STDERR "cddb: getting: $query\n" if $debug; print $socket "$query\n"; while(<$socket>) { last if(/^\./); push @lines,$_; } if(@to_get-1 == $i) { print $socket "quit\n"; close $socket; } } elsif ($CDDB_MODE eq "http") { close $socket; my $query2=$query; $query2 =~ s/ /+/g; my $id=$HELLO_ID; $id =~ s/ /+/g; my $url = "/~cddb/cddb.cgi?cmd=$query2&hello=$id&proto=$PROTO_VERSION"; my $host=$CDDB_HOST; my $port=80; my ($user,$pass); if($HTTP_PROXY) { if($HTTP_PROXY =~ /^(http:\/\/|)(.+?):(.+)\@(.+?):(.+)/) { $user=$2; $pass=$3; $host=$4; $port=$5; } elsif($HTTP_PROXY =~ /^(http:\/\/|)(.+?):(\d+)/) { $host=$2; $port=$3; } $url="http://$CDDB_HOST".$url." HTTP/1.0"; } print STDERR "cddb: connecting to $host:$port\n" if $debug; $socket=IO::Socket::INET->new(PeerAddr=>$host, PeerPort=>$port, Proto=>"tcp",Type=>SOCK_STREAM) or die "cannot connect to cddb db: $host:$port [$!]"; print STDERR "cddb: http send: GET $url\n" if $debug; print $socket "GET $url\n"; if($user) { my $cred = encode_base64("$user:$pass"); print $socket "Proxy-Authorization: Basic $cred\n"; } print $socket "\n"; print $socket "\n" if $FW; if($HTTP_PROXY) { while(<$socket> =~ /^\S+/){}; } while(<$socket>) { last if(/^\./); push @lines,$_; } close $socket; } else { die "unkown mode: $CDDB_MODE for querying cddb"; } # xmcd # # Track frame offsets: # 150 # ... # 210627 # # Disc length: 2952 seconds # # Revision: 1 # Submitted via: xmcd 2.0 # for(@lines) { last if(/^\./); next if(/^\d\d\d/); push @{$cd{raw}},$_; #TTITLE0=Bitch (Edit) if(/^TTITLE(\d+)\=\s*(.*)/) { my $t= $2; chop $t; $cd{frames}[$1]=$toc->[$1]->{frames}; $cd{data}[$1]=$toc->[$1]->{data}; unless (defined $cd{track}[$1]) { $cd{track}[$1]=$t; } else { $cd{track}[$1]=$cd{track}[$1].$t; } } elsif(/^DYEAR=\s*(\d+)/) { $cd{'year'} = $1; } elsif(/^DGENRE=\s*(\S+.*)/) { my $t = $1; chop $t; $cd{'genre'} = $t; } elsif(/^\#\s+Revision:\s+(\d+)/) { $cd{'revision'} = $1; } } $cd{tno}=$#{$cd{track}}+1; $cd{frames}[$cd{tno}]=$toc->[$cd{tno}]->{frames}; return %cd unless($multi); push @r,\%cd; $i++; } return @r; } 1; __END__ # Below is the stub of documentation for your module. You better edit it! =head1 NAME CDDB - Read the CDDB entry for an audio CD in your drive =head1 SYNOPSIS use CDDB_get qw( get_cddb ); my %config; # following variables just need to be declared if different from defaults $config{CDDB_HOST}="freedb.freedb.org"; # set cddb host $config{CDDB_PORT}=8880; # set cddb port $config{CDDB_MODE}="cddb"; # set cddb mode: cddb or http $config{CD_DEVICE}="/dev/cdrom"; # set cd device # user interaction welcome? $config{input}=1; # 1: ask user if more than one possibility # 0: no user interaction # get it on my %cd=get_cddb(\%config); unless(defined $cd{title}) { die "no cddb entry found"; } # do somthing with the results print "artist: $cd{artist}\n"; print "title: $cd{title}\n"; print "category: $cd{cat}\n"; print "cddbid: $cd{id}\n"; print "trackno: $cd{tno}\n"; my $n=1; foreach my $i ( @{$cd{track}} ) { print "track $n: $i\n"; $n++; } =head1 DESCRIPTION This module/script gets the CDDB info for an audio cd. You need LINUX, SUNOS or *BSD, a cdrom drive and an active internet connection in order to do that. =head1 INSTALLATION Run "perl Makefile.pl" as usual. ("make", "make install" next) =head1 LICENSE & DISCLAIMER This library is released under the same conditions as Perl, that is, either of the following: a) the GNU General Public License Version 2 as published by the Free Software Foundation, b) the Artistic License. This program 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 either the GNU General Public License or the Artistic License for more details. You should have received a copy of the Artistic License with this Kit, in the file named "Artistic". If not, I'll be glad to provide one. You should also have received a copy of the GNU General Public License along with this program, in the file names "Copying"; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. If you use this library in a commercial enterprise, you are invited, but not required, to pay what you feel is a reasonable fee to the author, who can be contacted at armin@xos.net =head1 AUTHOR & COPYRIGHT (c) 2003 Armin Obersteiner =head1 SEE ALSO perl(1), Linux: F, Solaris, *BSD: F. =cut CDDB_get-2.28/Changes0000644000076500001440000000550511725452406013340 0ustar arminusersRevision history for Perl extension CDDB/CDDB_get. 0.9 13.05.2000 beta release version 0.91 small bug fix 0.95 offline version 1.00 12.06.2000 output format for disc-cover 1.10 23.07.2000 corrected output format to xmcd format disc-cover can read this now, as other programs 1.11 21.10.2000 perl -w warnings resolved, thanx: Kyle 1.2 12.11.2000 now solaris works too, thanx: Adam 1.4 01.12.2000 some cleanup, default is freedb.freedb.org from now on 1.5 23.03.2001 solaris works now (for real now), thanx: Joe http mode implemented, thanx: Michael 1.51 25.02.2001 proxy mode implemented (for http) 1.52 beta test version 1.6 28.03.2001 netbsd works for now, maybe other bsd variants too there may be endian issues on bsd, so this is beta now 1.61 28.03.2001 small correction and tests 1.66 31.05.2001 Now works with OpenBSD. 2.01b 11.03.2002 The information can now be saved in xmcd format. An untested feature for loading data directly into a database was added. A data flag for each track was added. A fix was made for "/" characters in an artist's name. The HTTP proxy recognition was fixed. All entries are returned if a flag is set. An RPM spec file is now included. A command for encoding the CD with LAME is now output. 2.10 12.03.2002 A fix for total disk length calculation tested MySQL a -O flag for overwrite (xmcd file and mysql-db) a fix for a small bug in the Red Hat spec file 2.11 10.10.2002 small proxy regex bugfix 2.12 15.04.2003 Added better device handling (I now have 3 cdroms) (internal test release) 2.2 29.04.2003 Added direct device handling in cddb.pl Firewall fix with additional \n 2.22 12.08.2003 cddb proto5: new year and genre fields 2.23 07.09.2003 openbsd 64bit support, may (not) work on other 64bit platforms ;-) (thanks to: Enache Adrian, Jolan Luff and Dan Weeks) pod cleanup 2.25 15.06.2005 user:pass with proxy support - untested (thanks to Peter) Please try it, I don't have such a setup. Cache module: use CDDB_cache instead of CDDB_get All files are saved in a local tree and can be reused from there. Please try it if you like, it's not really tested. 2.26 22.06.2005 (unreleased) added postgres/oracle/sqlite support (untested) thanks to Rick for starting with a postgres version 2.27 01.01.2006 default port is now 8880 (not 888 anymore) fixes an ioctl perl problem on current redhat/fedora (thanks to Gregory K. Ruiz-Ade and the redhat/fedora guys) 2.28 06.03.2012 make tests work with perl 5.15.x CDDB_get-2.28/Copying0000644000076500001440000004313007256505112013371 0ustar arminusers GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. CDDB_get-2.28/Artistic0000644000076500001440000001373707107143562013557 0ustar arminusers The "Artistic License" Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End CDDB_get-2.28/Makefile.PL0000644000076500001440000000071610254040327014005 0ustar arminusersuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'CDDB_get', 'VERSION_FROM' => 'CDDB_get.pm', # finds $VERSION 'EXE_FILES' => ['cddb.pl'], 'ABSTRACT' => "This module/script gets the CDDB info for an audio cd.", 'AUTHOR' => "Armin Obersteiner ", # 'PREREQ_PM' => { # Data::Dumper => 0, # }, ); CDDB_get-2.28/META.yml0000644000076500001440000000106211725453533013312 0ustar arminusers--- #YAML:1.0 name: CDDB_get version: 2.28 abstract: This module/script gets the CDDB info for an audio cd. author: - Armin Obersteiner license: unknown distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: {} no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.56 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 CDDB_get-2.28/DATABASE0000644000076500001440000000107710256345545013137 0ustar arminusers; this a the database example of Falko CREATE TABLE cds ( cddbid varchar(20) NOT NULL default '', artist varchar(250) NOT NULL default '', title varchar(250) NOT NULL default '', category varchar(250) NOT NULL default '', tracks varchar(250) NOT NULL default '', PRIMARY KEY (cddbid) ); CREATE TABLE tracks ( cddbid varchar(20) NOT NULL default '', title varchar(250) NOT NULL default '', ; better for mysql: trackno tinyint(2) ; better for postgres: trackno smallint trackno integer NOT NULL default '0', time time NOT NULL default '00:00:00' ); CDDB_get-2.28/perl-CDDB_get-2.28.spec0000644000076500001440000000243411725452312015575 0ustar arminusers%define module CDDB_get %define version 2.28 %define release 1 Summary: %{module} module for perl Name: perl-%{module} Version: %{version} Release: %{release} License: distributable Group: Applications/Multimedia Source0: %{module}-%{version}.tar.gz Url: http://armin.emx.at/cddb/ BuildRoot: %{_tmppath}/%{name}-buildroot/ Requires: perl >= 5.6.1 BuildArch: noarch %description %{module} module for perl %prep %setup -q -n %{module}-%{version} %build CFLAGS="$RPM_OPT_FLAGS" perl Makefile.PL make make test %clean rm -rf $RPM_BUILD_ROOT %install rm -rf $RPM_BUILD_ROOT eval `perl '-V:installarchlib'` mkdir -p $RPM_BUILD_ROOT/$installarchlib make PREFIX=$RPM_BUILD_ROOT%{_prefix} install # call spec-helper before creating the file list s=/usr/share/spec-helper/spec-helper ; [ -x $s ] && $s %files %defattr(-,root,root) %{_mandir}/*/* %{_prefix}/lib/perl5/site_perl/*/auto/CDDB_get/* %{_prefix}/lib/perl5/site_perl/*/cddb.pl %{_prefix}/lib/perl5/site_perl/*/CDDB_get.pm %doc Changes Copying README DATABASE %changelog * Tue Mar 6 19:16:36 CET 2012 Armin Obersteiner 2.28 * Mon Mar 11 04:14:26 MET 2002 Armin Obersteiner 2.01-1 * Sun Nov 25 2001 Peter Bieringer 1.66-1 - initial (creditds to spec file creators of perl-DateManip) CDDB_get-2.28/CDDB_cache.pm0000644000076500001440000001033710254040550014206 0ustar arminusers# # CDDB - Read the CDDB entry for an audio CD in your drive # # This module/script gets the CDDB info for an audio cd. You need # LINUX, a cdrom drive and an active internet connection in order # to do that. # # (c) 2004 Armin Obersteiner # # LICENSE # # This library is released under the same conditions as Perl, that # is, either of the following: # # a) the GNU General Public License Version 2 as published by the # Free Software Foundation, # # b) the Artistic License. # package CDDB_cache; use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $debug $dir $readonly $grep); require Exporter; @ISA = qw(Exporter AutoLoader); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. @EXPORT_OK = qw( get_cddb get_discids ); $VERSION = '1.0'; use CDDB_get; use File::Find; use Data::Dumper qw(Dumper); #$debug=1; $dir="/tmp/xmcd"; my $CD_DEVICE = "/dev/cdrom"; sub get_discids { my $cd=shift; return CDDB_get::get_discids($cd); } my @files; sub get_cddb { my $config=shift; my $diskid=shift; if($debug) { print STDERR "dir: [$dir] readonly [$readonly] grep [$grep]\n"; } $config->{multi}=0; $CD_DEVICE = $config->{CD_DEVICE} if (defined($config->{CD_DEVICE})); my $did=$diskid; $did=CDDB_get::get_discids($CD_DEVICE) unless($did); #print Dumper($did); printf STDERR "%08x %08lx\n", $did->[0], $did->[0] if($debug); my $sid = sprintf "%08x", $did->[0]; my $id = sprintf "%08x %d", $did->[0], $did->[1]; for(0..$did->[1]-1) { $id.=" ".$did->[2]->[$_]->{frames}; } $id.=" ".int($did->[2]->[$did->[1]]->{frames}/75); print STDERR "id: $id\n" if $debug; @files=(); if($grep) { find({ wanted => sub { next unless -f $File::Find::name; my $tid=`grep -H $sid $File::Find::name`; if($tid =~ /\S+/) { push @files, $File::Find::name; } }, follow=>1}, $dir); } else { find({ wanted => sub { if($_ eq $sid) { push @files, $File::Find::name; } }, follow=>1}, $dir); } print STDERR Dumper(\@files) if $debug; my $file; my $found; for(@files) { open IN,$_; undef $/; $file=; close IN; my ($fid)=$file =~ /DISCID=(\S+)/i; my ($len)=$file =~ /Disc length: (\d+) seconds/i; my ($s)=$file =~ /Track frame offsets:\s+(.*)\s+Disc length/si; my $t=""; my @tr=split /#/,$s; my $c=0; for(@tr) { next unless /(\d+)/; $c++; $t.=" $1"; last if($c>=$did->[1]); } my $tid="$fid $c$t $len"; if($tid eq $id) { $found=$_; last; } } my $toc=$did->[2]; my %cd; if($found) { print STDERR "CDDB_cache: reading from file: $found\n"; my @lines=split /\n/,$file; for(@lines) { push @{$cd{raw}},$_."\n"; #TTITLE0=Bitch (Edit) if(/^TTITLE(\d+)\=\s*(.*)/) { my $t= $2; chomp $t; $cd{frames}[$1]=$toc->[$1]->{frames}; $cd{data}[$1]=$toc->[$1]->{data}; unless (defined $cd{track}[$1]) { $cd{track}[$1]=$t; } else { $cd{track}[$1]=$cd{track}[$1].$t; } } elsif(/^DYEAR=\s*(\d+)/) { $cd{'year'} = $1; } elsif(/^DGENRE=\s*(\S+.*)/) { my $t = $1; chomp $t; $cd{'genre'} = $t; } } $cd{tno}=$#{$cd{track}}+1; $cd{frames}[$cd{tno}]=$toc->[$cd{tno}]->{frames}; $cd{id}=$sid; my ($at)=$file=~/DTITLE=(.*?)\n/; my ($artist,$title); #chop $at if($at =~ /\r/); chomp $at; if($at =~ /\//) { ($artist,$title)= $at =~ /^(.*?)\s\/\s(.*)/; } else { $artist=$at; $title=$at; } $cd{artist}=$artist; $cd{title}=$title; my ($cat) = $found =~ /$dir\/(\S+?)\/$sid/; $cd{cat}=$cat; } else { print STDERR "CDDB_cache: reading from network\n"; %cd=CDDB_get::get_cddb($config,$diskid); } print STDERR Dumper(\%cd) if $debug; unless($readonly || $found) { my $file=$dir."/$cd{cat}/$cd{id}"; my $ddir=$dir."/$cd{cat}"; mkdir $ddir,0755; open OUT,">$file"; for(@{$cd{raw}}) { print OUT $_; } close OUT; } return %cd; } 1; __END__ CDDB_get-2.28/cddb.pl0000755000076500001440000002547510321136633013301 0ustar arminusers#!/usr/bin/perl -I. # # CDDB - Read the CDDB entry for an audio CD in your drive # # This module/script gets the CDDB info for an audio cd. You need # LINUX, a cdrom drive and an active internet connection in order # to do that. # # (c) 2004 Armin Obersteiner # # LICENSE # # This library is released under the same conditions as Perl, that # is, either of the following: # # a) the GNU General Public License Version 2 as published by the # Free Software Foundation, # # b) the Artistic License. # #use CDDB_get qw( get_cddb get_discids ); use Data::Dumper; use Getopt::Std; use strict; my %option = (); getopts("oghdtsi:SfDlOFc:H:CIRGP", \%option); if($option{h}) { print "$0: gets CDDB info of a CD\n"; print " no argument - gets CDDB info of CD in your drive\n"; print " -c device (other than default device)\n"; 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 db. one of: mysql, pg, oracle, sqlite\n"; print " -O overwrite file or db\n"; print " -t output toc\n"; print " -l output lame command\n"; print " -f http mode (e.g. through firewalls)\n"; print " -F some stateful firewalls/http proxies need additional newlines\n"; print " -g get CDDB info for stored CDs\n"; print " -I non interactive mode\n"; print " -H CDDB hostname\n"; print " -C use local cache\n"; print " -R readonly cache\n"; print " -G cache has not the diskid as filenames (much slower)\n"; print " -P cache path (default: /tmp/xmcd)\n"; print " -D put CDDB_get in debug mode\n"; exit; } my %config; my $diskid; my $total; my $toc; my $savedir="/tmp/cddb"; my $xmcddir="/tmp/xmcd"; if($option{C}) { # use CDDB_cache qw( get_cddb get_discids ); require CDDB_cache; CDDB_cache->import( qw( get_cddb get_discids ) ); $CDDB_cache::debug=1 if($option{D}); $CDDB_cache::readonly=1 if($option{R}); $CDDB_cache::grep=1 if($option{G}); $CDDB_cache::dir="/tmp/xmcd"; # default # $CDDB_cache::dir="/opt/kde2/share/apps/kscd/cddb"; $CDDB_cache::dir=$option{P} if($option{P}); } else { # use CDDB_get qw( get_cddb get_discids ); require CDDB_get; CDDB_get->import( qw( get_cddb get_discids ) ); } $CDDB_get::debug=1 if($option{D}); # following variables just need to be declared if different from defaults # defaults are listed below (cdrom default is os specific) # $config{CDDB_HOST}="freedb.freedb.org"; # set cddb host if($option{H}) { $config{CDDB_HOST}=$option{H}; } # $config{CDDB_PORT}=8880; # set cddb port # $config{CDDB_MODE}="cddb"; # set cddb mode: cddb or http, this is switched with -f # $config{CD_DEVICE}="/dev/cdrom"; # set cd device # $config{HELLO_ID} ="root nowhere.com fastrip 0.77"; # hello string: username hostname clientname version # $config{PROTO_VERSION} = 5; # cddb protokol version # get proxy settings for cddb mode $config{HTTP_PROXY}=$ENV{http_proxy} if $ENV{http_proxy}; # maybe wanna use a proxy ? $config{CDDB_MODE}="http" if($option{f}); if($option{F}) { $config{CDDB_MODE}="http"; $config{FW}=1; } $config{CD_DEVICE}=$option{c} if $option{c}; # user interaction welcome? $config{input}=1; # 1: ask user if more than one possibility # 0: no user interaction $config{multi}=0; # 1: do not ask user and get all of them # 0: just the first one $config{input}=0 if($option{I}); my %db; if($option{i}) { require DBI; $db{table_cds} = "cds"; $db{table_tracks} = "tracks"; # not needed for sqlite $db{host} = "localhost"; $db{port} = "3306"; # not needed for oracle/sqlite $db{name} = "mp3-test"; # just for oracle $db{sid} = "xxx"; $db{home} = "xxx"; # just for sqlite $db{file} = "xxx"; # not needed for sqlite $db{user} = "root"; $db{passwd} = "xxx"; if($option{i} eq "mysql") { $db{connect} = sub { "dbi:mysql:database=$db{name};host=$db{host};port=$db{port}", $db{user}, $db{passwd} }; } elsif($option{i} eq "pg") { $db{connect} = sub { "dbi:Pg:dbname=$db{dbname};host=$db{host};port=$db{port}", $db{user}, $db{passwd} }; } elsif($option{i} eq "oracle") { $db{connect} = sub { "dbi:Oracle:host=$db{host};sid=$db{sid};port=$db{port}", $db{user}, $db{passwd} }; $ENV{ORACLE_HOME} = $db{home}; } elsif($option{i} eq "sqlite") { $db{connect} = sub { "dbi:SQLite:dbname=$db{file}","","" }; } else { die "unkown database: $option{i}"; } } if($option{o}) { my $ids=get_discids($config{CD_DEVICE}); unless(-e $savedir) { mkdir $savedir,0755 or die "cannot create $savedir"; } open OUT,">$savedir/$ids->[0]\_$$" or die "cannot open outfile"; print OUT Data::Dumper->Dump($ids,["diskid","total","toc"]); close OUT; print STDERR "saved in: $savedir/$ids->[0]\_$$\n"; exit; } if($option{g}) { print STDERR "retrieving stored cds ...\n"; opendir(DIR, $savedir) or die "cannot opendir $savedir"; while (defined(my $file = readdir(DIR))) { next if($file =~ /^\./); print "\n"; my $in=`/bin/cat $savedir/$file`; my $exit = $? >> 8; if($exit>0) { die "error reading file"; } unless($in=~ m/^\$diskid\s+=\s+('\d+'|\d+);\s+ # $diskid \$total\s+=\s+('\d+'|\d+);\s+ # $total \$toc\s+=\s+\[\s+ # $toc (\{\s+ ('(frame|frames|min|sec|data)'\s+=\>\s+('\d+'|\d+)(,|)\s+){5} \}(,|)\s+)+ \];\s+$/xs) { print "not a save file: $savedir/$file\n"; next; } eval $in; if($@) { print "not a save file (eval error): $savedir/$file\n"; next; } my %cd=get_cddb(\%config,[$diskid,$total,$toc]); unless(defined $cd{title}) { print "no cddb entry found: $savedir/$file\n"; } unlink "$savedir/$file"; next unless defined $cd{title}; if($option{d} || $option{s}) { print_xmcd(\%cd,$option{s}); } elsif($option{i}) { insert_db(\%cd,\%db); } elsif($option{l}) { print_lame(\%cd); } else { print_cd(\%cd); } } closedir(DIR); exit; } # get it on unless($config{multi}) { my %cd; # for those who don't like 'die' in modules ;-) eval { %cd = get_cddb(\%config); }; if ($@) { print "fatal error: $!\n"; exit; } print Dumper(\%cd) if $option{D}; unless(defined $cd{title}) { die "no cddb entry found"; } # do somthing with the results if($option{d} || $option{s}) { print_xmcd(\%cd,$option{s}); } elsif($option{i}) { insert_db(\%cd,\%db); } elsif($option{l}) { print_lame(\%cd); } else { print_cd(\%cd); } } else { my @cd; # for those who don't like 'die' in modules ;-) eval { @cd=get_cddb(\%config); }; if ($@) { print "fatal error: $!\n"; exit; } print Dumper(\@cd) if $option{D}; for my $c (@cd) { unless(defined $c->{title}) { die "no cddb entry found"; } # do somthing with the results 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"; } else { print_cd($c); print "\n"; } } } exit; # subroutines sub print_cd { my $cd=shift; print "artist: $cd->{artist}\n"; print "title: $cd->{title}\n"; print "category: $cd->{cat}\n"; print "genre: $cd->{genre}\n" if($cd->{genre}); print "year: $cd->{year}\n" if($cd->{year}); print "cddbid: $cd->{id}\n"; print "trackno: $cd->{tno}\n"; my $n=1; foreach my $i ( @{$cd->{track}} ) { if($option{t}) { my $from=$cd->{frames}[$n-1]; my $to=$cd->{frames}[$n]-1; my $dur=$to-$from; my $min=int($dur/75/60); my $sec=int($dur/75)-$min*60; my $frm=($dur-$sec*75-$min*75*60)*100/75; my $out=sprintf "track %2d: %8d - %8d [%2d:%.2d.%.2d]: $i\n",$n,$from,$to,$min,$sec,$frm; print "$out"; } else { print "track $n: $i\n"; } $n++; } } sub print_xmcd { my $cd=shift; my $save=shift; *OUT=*STDOUT; if($save) { unless(-e $xmcddir) { mkdir $xmcddir,0755 or die "cannot create $savedir"; } unless($option{O}) { if(-e "$xmcddir/$cd->{id}") { print "XMCD file exists\n"; exit; } } open XMCD,">$xmcddir/$cd->{id}" or die "cannot open outfile"; *OUT=*XMCD; } for(@{$cd->{raw}}) { print OUT "$_"; } if($save) { print STDERR "saved in: $xmcddir/$cd->{id}\n"; close OUT; } } 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($db->{connect}->()) 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; print_cd($cd); print "\n"; my $n=1; for my $i ( @{$cd->{track}} ) { $i =~ s/"/'/g; print 'lame --tl "'.$cd->{title}.'" --ta "'.$cd->{artist}.'" --tt "'.$i.'" '; printf "audio_%02d.wav ",$n; $i =~ s/[^\S]|['"\/]/_/g; $i =~ s/_+-_+/-/g; print " $i.mp3\n"; $n++; } } CDDB_get-2.28/MANIFEST0000644000076500001440000000031611725452501013165 0ustar arminusersArtistic Copying CDDB_get.pm CDDB_cache.pm cddb.pl Changes MANIFEST README DATABASE perl-CDDB_get-2.28.spec Makefile.PL t/use.t META.yml Module meta-data (added by MakeMaker)