| 1 | # | ||||||||||||||||||||||
| 2 | # CDDB - Read the CDDB entry for an audio CD in your drive | ||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||
| 4 | # This module/script gets the CDDB info for an audio cd. You need | ||||||||||||||||||||||
| 5 | # LINUX, a cdrom drive and an active internet connection in order | ||||||||||||||||||||||
| 6 | # to do that. | ||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||
| 8 | # (c) 2004 Armin Obersteiner <armin@xos.net> | ||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||
| 10 | # LICENSE | ||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||
| 12 | # This library is released under the same conditions as Perl, that | ||||||||||||||||||||||
| 13 | # is, either of the following: | ||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||
| 15 | # a) the GNU General Public License Version 2 as published by the | ||||||||||||||||||||||
| 16 | # Free Software Foundation, | ||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||
| 18 | # b) the Artistic License. | ||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | package CDDB_get; | ||||||||||||||||||||||
| 22 | |||||||||||||||||||||||
| 23 | 1 | ▶ | use Config; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 24 | |||||||||||||||||||||||
| 25 | 1 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 26 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $debug); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | 1 | require Exporter; | |||||||||||||||||||||
| 29 | |||||||||||||||||||||||
| 30 | 1 | @ISA = qw(Exporter AutoLoader); | |||||||||||||||||||||
| 31 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||||
| 32 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||||
| 33 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||||
| 34 | 1 | @EXPORT_OK = qw( | |||||||||||||||||||||
| 35 | get_cddb | ||||||||||||||||||||||
| 36 | get_discids | ||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||
| 38 | 1 | $VERSION = '2.28'; | |||||||||||||||||||||
| 39 | |||||||||||||||||||||||
| 40 | 1 | ▶ | use Fcntl; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 41 | 1 | ▶ | use IO::Socket; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 42 | 1 | ▶ | use Data::Dumper qw(Dumper); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 43 | 1 | ▶ | use MIME::Base64 qw(encode_base64); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 44 | |||||||||||||||||||||||
| 45 | 1 | $debug=1; | |||||||||||||||||||||
| 46 | |||||||||||||||||||||||
| 47 | # setup for linux, solaris x86, solaris spark | ||||||||||||||||||||||
| 48 | # you freebsd guys give me input | ||||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | 1 | ▶ | print STDERR "cddb: checking for os ... " if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | 1 | my $os=`uname -s`; | |||||||||||||||||||||
| 53 | 1 | my $machine=`uname -m`; | |||||||||||||||||||||
| 54 | 1 | chomp $os; | |||||||||||||||||||||
| 55 | 1 | chomp $machine; | |||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | 1 | ▶ | print STDERR "$os ($machine) " if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 58 | |||||||||||||||||||||||
| 59 | # cdrom IOCTL magic (from c headers) | ||||||||||||||||||||||
| 60 | # linux x86 is default | ||||||||||||||||||||||
| 61 | |||||||||||||||||||||||
| 62 | # /usr/include/linux/cdrom.h | ||||||||||||||||||||||
| 63 | 1 | my $CDROMREADTOCHDR=0x5305; | |||||||||||||||||||||
| 64 | 1 | my $CDROMREADTOCENTRY=0x5306; | |||||||||||||||||||||
| 65 | 1 | my $CDROM_MSF=0x02; | |||||||||||||||||||||
| 66 | |||||||||||||||||||||||
| 67 | # default config | ||||||||||||||||||||||
| 68 | |||||||||||||||||||||||
| 69 | 1 | my $CDDB_HOST = "freedb.freedb.org"; | |||||||||||||||||||||
| 70 | 1 | my $CDDB_PORT = 8880; | |||||||||||||||||||||
| 71 | 1 | my $CDDB_MODE = "cddb"; | |||||||||||||||||||||
| 72 | 1 | my $CD_DEVICE = "/dev/cdrom"; | |||||||||||||||||||||
| 73 | |||||||||||||||||||||||
| 74 | 1 | my $HELLO_ID = "root nowhere.com fastrip 0.77"; | |||||||||||||||||||||
| 75 | 1 | my $PROTO_VERSION = 5; | |||||||||||||||||||||
| 76 | |||||||||||||||||||||||
| 77 | # endian check | ||||||||||||||||||||||
| 78 | |||||||||||||||||||||||
| 79 | 1 | my $BIG_ENDIAN = unpack("h*", pack("s", 1)) =~ /01/; | |||||||||||||||||||||
| 80 | |||||||||||||||||||||||
| 81 | 1 | ▶ | if($BIG_ENDIAN) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 82 | 0 | ▶ | print STDERR "[big endian] " if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||
| 84 | 1 | ▶ | print STDERR "[little endian] " if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||
| 86 | |||||||||||||||||||||||
| 87 | # 64bit pointer check | ||||||||||||||||||||||
| 88 | |||||||||||||||||||||||
| 89 | 1 | ▶ | my $BITS_64 = $Config{ptrsize} == 8 ? 1 : 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 90 | |||||||||||||||||||||||
| 91 | 1 | ▶ | if($BITS_64) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 92 | 1 | ▶ | print STDERR "[64 bit]\n" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 93 | } else { | ||||||||||||||||||||||
| 94 | 0 | ▶ | print STDERR "[32 bit]\n" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||
| 96 | |||||||||||||||||||||||
| 97 | 1 | ▶ | if($os eq "SunOS") { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 98 | # /usr/include/sys/cdio.h | ||||||||||||||||||||||
| 99 | |||||||||||||||||||||||
| 100 | 0 | $CDROMREADTOCHDR=0x49b; # 1179 | |||||||||||||||||||||
| 101 | 0 | $CDROMREADTOCENTRY=0x49c; # 1180 | |||||||||||||||||||||
| 102 | |||||||||||||||||||||||
| 103 | 0 | ▶ | if(-e "/vol/dev/aliases/cdrom0") { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 104 | 0 | $CD_DEVICE="/vol/dev/aliases/cdrom0"; | |||||||||||||||||||||
| 105 | } else { | ||||||||||||||||||||||
| 106 | 0 | ▶ | if($machine =~ /^sun/) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 107 | # on sparc and old suns | ||||||||||||||||||||||
| 108 | 0 | $CD_DEVICE="/dev/rdsk/c0t6d0s0"; | |||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||
| 110 | # on intel | ||||||||||||||||||||||
| 111 | 0 | $CD_DEVICE="/dev/rdsk/c1t0d0p0"; | |||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||
| 114 | } elsif($os =~ /BSD/i) { # works for netbsd, infos for other bsds welcome | ||||||||||||||||||||||
| 115 | # /usr/include/sys/cdio.h | ||||||||||||||||||||||
| 116 | |||||||||||||||||||||||
| 117 | 0 | $CDROMREADTOCHDR=0x40046304; | |||||||||||||||||||||
| 118 | 0 | $CDROMREADTOCENTRY=0xc0086305; | |||||||||||||||||||||
| 119 | |||||||||||||||||||||||
| 120 | 0 | ▶ | if($BITS_64) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 121 | 0 | $CDROMREADTOCENTRY=0xc0106305; | |||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||
| 123 | |||||||||||||||||||||||
| 124 | 0 | $CD_DEVICE="/dev/cd0a"; | |||||||||||||||||||||
| 125 | |||||||||||||||||||||||
| 126 | 0 | ▶ | if($os eq "OpenBSD") { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 127 | 0 | $CD_DEVICE="/dev/cd0c"; | |||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||
| 130 | |||||||||||||||||||||||
| 131 | 0 | ▶ | sub read_toc { | ||||||||||||||||||||
|
Subroutine
read_toc: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||
| 132 | 0 | my $device=shift; | |||||||||||||||||||||
| 133 | 0 | my $tochdr=chr(0) x 16; | |||||||||||||||||||||
| 134 | |||||||||||||||||||||||
| 135 | 0 | ▶ | sysopen (CD,$device, O_RDONLY | O_NONBLOCK) or die "cannot open cdrom [$!] [$device]"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 136 | 0 | ▶ | ioctl(CD, $CDROMREADTOCHDR, $tochdr) or die "cannot read toc [$!] [$device]"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 137 | 0 | my ($start,$end); | |||||||||||||||||||||
| 138 | 0 | ▶ | if($os =~ /BSD/) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 139 | 0 | ($start,$end)=unpack "CC",(substr $tochdr,2,2); | |||||||||||||||||||||
| 140 | } else { | ||||||||||||||||||||||
| 141 | 0 | ($start,$end)=unpack "CC",$tochdr; | |||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||
| 143 | 0 | ▶ | print STDERR "start track: $start, end track: $end\n" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 144 | |||||||||||||||||||||||
| 145 | 0 | my @tracks=(); | |||||||||||||||||||||
| 146 | |||||||||||||||||||||||
| 147 | 0 | ▶ | for (my $i=$start; $i<=$end;$i++) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 148 | 0 | push @tracks,$i; | |||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||
| 150 | 0 | push @tracks,0xAA; | |||||||||||||||||||||
| 151 | |||||||||||||||||||||||
| 152 | 0 | my @r=(); | |||||||||||||||||||||
| 153 | 0 | my $tocentry; | |||||||||||||||||||||
| 154 | 0 | my $toc=""; | |||||||||||||||||||||
| 155 | 0 | my $size=0; | |||||||||||||||||||||
| 156 | 0 | for(@tracks) { | |||||||||||||||||||||
| 157 | 0 | $toc.=" "; | |||||||||||||||||||||
| 158 | 0 | $size+=8; | |||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||
| 160 | |||||||||||||||||||||||
| 161 | 0 | ▶ | if($os =~ /BSD/) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 162 | 0 | my $size_hi=int($size / 256); | |||||||||||||||||||||
| 163 | 0 | my $size_lo=$size & 255; | |||||||||||||||||||||
| 164 | |||||||||||||||||||||||
| 165 | 0 | ▶ | if($BIG_ENDIAN) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 166 | 0 | ▶ | if($BITS_64) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 167 | # better but just perl >= 5.8.0 | ||||||||||||||||||||||
| 168 | # $tocentry=pack "CCCCx![P]P", $CDROM_MSF,0,$size_hi,$size_lo,$toc; | ||||||||||||||||||||||
| 169 | 0 | $tocentry=pack "CCCCxxxxP", $CDROM_MSF,0,$size_hi,$size_lo,$toc; | |||||||||||||||||||||
| 170 | } else { | ||||||||||||||||||||||
| 171 | 0 | $tocentry=pack "CCCCP8l", $CDROM_MSF,0,$size_hi,$size_lo,$toc; | |||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||
| 173 | } else { | ||||||||||||||||||||||
| 174 | 0 | ▶ | if($BITS_64) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 175 | 0 | $tocentry=pack "CCCCxxxxP", $CDROM_MSF,0,$size_lo,$size_hi,$toc; | |||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||
| 177 | 0 | $tocentry=pack "CCCCP8l", $CDROM_MSF,0,$size_lo,$size_hi,$toc; | |||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||
| 180 | 0 | ▶ | ioctl(CD, $CDROMREADTOCENTRY, $tocentry) or die "cannot read track info [$!] [$device]"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||
| 182 | |||||||||||||||||||||||
| 183 | 0 | my $count=0; | |||||||||||||||||||||
| 184 | 0 | foreach my $i (@tracks) { | |||||||||||||||||||||
| 185 | 0 | my ($min,$sec,$frame); | |||||||||||||||||||||
| 186 | 0 | ▶ | unless($os =~ /BSD/) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 187 | 0 | $tocentry=pack "CCC", $i,0,$CDROM_MSF; | |||||||||||||||||||||
| 188 | 0 | $tocentry.=chr(0) x 16; | |||||||||||||||||||||
| 189 | 0 | ▶ | ioctl(CD, $CDROMREADTOCENTRY, $tocentry) or die "cannot read track $i info [$!] [$device]"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 190 | 0 | ($min,$sec,$frame)=unpack "CCCC", substr($tocentry,4,4); | |||||||||||||||||||||
| 191 | } else { | ||||||||||||||||||||||
| 192 | 0 | ($min,$sec,$frame)=unpack "CCC", substr($toc,$count+5,3); | |||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||
| 194 | 0 | $count+=8; | |||||||||||||||||||||
| 195 | |||||||||||||||||||||||
| 196 | 0 | my %cdtoc=(); | |||||||||||||||||||||
| 197 | |||||||||||||||||||||||
| 198 | 0 | $cdtoc{min}=$min; | |||||||||||||||||||||
| 199 | 0 | $cdtoc{sec}=$sec; | |||||||||||||||||||||
| 200 | 0 | $cdtoc{frame}=$frame; | |||||||||||||||||||||
| 201 | 0 | $cdtoc{frames}=int($frame+$sec*75+$min*60*75); | |||||||||||||||||||||
| 202 | |||||||||||||||||||||||
| 203 | 0 | my $data = unpack("C",substr($tocentry,1,1)); | |||||||||||||||||||||
| 204 | 0 | $cdtoc{data} = 0; | |||||||||||||||||||||
| 205 | 0 | ▶ | if($data & 0x40) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 206 | 0 | $cdtoc{data} = 1; | |||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||
| 208 | |||||||||||||||||||||||
| 209 | 0 | push @r,\%cdtoc; | |||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||
| 211 | 0 | close(CD); | |||||||||||||||||||||
| 212 | |||||||||||||||||||||||
| 213 | 0 | return @r; | |||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||
| 215 | |||||||||||||||||||||||
| 216 | 0 | ▶ | sub cddb_sum { | ||||||||||||||||||||
|
Subroutine
cddb_sum: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||
| 217 | 0 | my $n=shift; | |||||||||||||||||||||
| 218 | 0 | my $ret=0; | |||||||||||||||||||||
| 219 | |||||||||||||||||||||||
| 220 | 0 | ▶ | while ($n > 0) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 221 | 0 | $ret += ($n % 10); | |||||||||||||||||||||
| 222 | 0 | $n = int $n / 10; | |||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||
| 224 | 0 | return $ret; | |||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||
| 226 | |||||||||||||||||||||||
| 227 | 0 | ▶ | sub cddb_discid { | ||||||||||||||||||||
|
Subroutine
cddb_discid: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||
| 228 | 0 | my $total=shift; | |||||||||||||||||||||
| 229 | 0 | my $toc=shift; | |||||||||||||||||||||
| 230 | |||||||||||||||||||||||
| 231 | 0 | my $i=0; | |||||||||||||||||||||
| 232 | 0 | my $t=0; | |||||||||||||||||||||
| 233 | 0 | my $n=0; | |||||||||||||||||||||
| 234 | |||||||||||||||||||||||
| 235 | 0 | ▶ | while ($i < $total) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 236 | 0 | $n = $n + cddb_sum(($toc->[$i]->{min} * 60) + $toc->[$i]->{sec}); | |||||||||||||||||||||
| 237 | 0 | $i++; | |||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||
| 239 | $t = (($toc->[$total]->{min} * 60) + $toc->[$total]->{sec}) - | ||||||||||||||||||||||
| 240 | 0 | (($toc->[0]->{min} * 60) + $toc->[0]->{sec}); | |||||||||||||||||||||
| 241 | 0 | return (($n % 0xff) << 24 | $t << 8 | $total); | |||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||
| 243 | |||||||||||||||||||||||
| 244 | 0 | ▶ | sub get_discids { | ||||||||||||||||||||
|
Subroutine
get_discids: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||
| 245 | 0 | my $cd=shift; | |||||||||||||||||||||
| 246 | 0 | ▶ | $CD_DEVICE = $cd if (defined($cd)); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 247 | |||||||||||||||||||||||
| 248 | 0 | my @toc=read_toc($CD_DEVICE); | |||||||||||||||||||||
| 249 | 0 | my $total=$#toc; | |||||||||||||||||||||
| 250 | |||||||||||||||||||||||
| 251 | 0 | my $id=cddb_discid($total,\@toc); | |||||||||||||||||||||
| 252 | |||||||||||||||||||||||
| 253 | 0 | return [$id,$total,\@toc]; | |||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||
| 255 | |||||||||||||||||||||||
| 256 | 0 | ▶ | sub get_cddb { | ||||||||||||||||||||
|
Subroutine
get_cddb: not called CC=78 SCAR=87.3
Pod
undocumented
| |||||||||||||||||||||||
| 257 | 0 | my $config=shift; | |||||||||||||||||||||
| 258 | 0 | my $diskid=shift; | |||||||||||||||||||||
| 259 | 0 | my $id; | |||||||||||||||||||||
| 260 | my $toc; | ||||||||||||||||||||||
| 261 | 0 | my $total; | |||||||||||||||||||||
| 262 | 0 | my @r; | |||||||||||||||||||||
| 263 | |||||||||||||||||||||||
| 264 | 0 | my $input = $config->{input}; | |||||||||||||||||||||
| 265 | 0 | my $multi = $config->{multi}; | |||||||||||||||||||||
| 266 | 0 | ▶ | $input = 0 if $multi; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 267 | |||||||||||||||||||||||
| 268 | 0 | ▶ | print STDERR Dumper($config) if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 269 | |||||||||||||||||||||||
| 270 | 0 | ▶ | $CDDB_HOST = $config->{CDDB_HOST} if (defined($config->{CDDB_HOST})); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 271 | 0 | ▶ | $CDDB_PORT = $config->{CDDB_PORT} if (defined($config->{CDDB_PORT})); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 272 | 0 | ▶ | $CDDB_MODE = $config->{CDDB_MODE} if (defined($config->{CDDB_MODE})); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 273 | 0 | ▶ | $CD_DEVICE = $config->{CD_DEVICE} if (defined($config->{CD_DEVICE})); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 274 | 0 | ▶ | $HELLO_ID = $config->{HELLO_ID} if (defined($config->{HELLO_ID})); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 275 | 0 | ▶ | $PROTO_VERSION = $config->{PROTO_VERSION} if (defined($config->{PROTO_VERSION})); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 276 | 0 | ▶ | my $HTTP_PROXY = $config->{HTTP_PROXY} if (defined($config->{HTTP_PROXY})); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 277 | 0 | ▶ | my $FW=1 if (defined($config->{FW})); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 278 | |||||||||||||||||||||||
| 279 | 0 | ▶ | if(defined($diskid)) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 280 | 0 | $id=$diskid->[0]; | |||||||||||||||||||||
| 281 | 0 | $total=$diskid->[1]; | |||||||||||||||||||||
| 282 | 0 | $toc=$diskid->[2]; | |||||||||||||||||||||
| 283 | } else { | ||||||||||||||||||||||
| 284 | 0 | my $diskid=get_discids($CD_DEVICE); | |||||||||||||||||||||
| 285 | 0 | $id=$diskid->[0]; | |||||||||||||||||||||
| 286 | 0 | $total=$diskid->[1]; | |||||||||||||||||||||
| 287 | 0 | $toc=$diskid->[2]; | |||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||
| 289 | |||||||||||||||||||||||
| 290 | 0 | my @list=(); | |||||||||||||||||||||
| 291 | 0 | my $return; | |||||||||||||||||||||
| 292 | my $socket; | ||||||||||||||||||||||
| 293 | |||||||||||||||||||||||
| 294 | 0 | my $id2 = sprintf "%08x", $id; | |||||||||||||||||||||
| 295 | 0 | my $query = "cddb query $id2 $total"; | |||||||||||||||||||||
| 296 | 0 | ▶ | for (my $i=0; $i<$total ;$i++) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 297 | 0 | $query.=" $toc->[$i]->{frames}"; | |||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||
| 299 | |||||||||||||||||||||||
| 300 | # this was to old total calculation, does not work too well, its included if new version makes problems | ||||||||||||||||||||||
| 301 | # $query.=" ". int(($toc->[$total]->{frames}-$toc->[0]->{frames})/75); | ||||||||||||||||||||||
| 302 | |||||||||||||||||||||||
| 303 | 0 | $query.=" ". int(($toc->[$total]->{frames})/75); | |||||||||||||||||||||
| 304 | |||||||||||||||||||||||
| 305 | 0 | ▶ | print Dumper($toc) if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 306 | |||||||||||||||||||||||
| 307 | 0 | ▶ | if ($CDDB_MODE eq "cddb") { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 308 | 0 | ▶ | print STDERR "cddb: connecting to $CDDB_HOST:$CDDB_PORT\n" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 309 | |||||||||||||||||||||||
| 310 | 0 | ▶ | $socket=IO::Socket::INET->new(PeerAddr=>$CDDB_HOST, PeerPort=>$CDDB_PORT, | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 311 | Proto=>"tcp",Type=>SOCK_STREAM) or die "cannot connect to cddb db: $CDDB_HOST:$CDDB_PORT [$!]"; | ||||||||||||||||||||||
| 312 | |||||||||||||||||||||||
| 313 | 0 | $return=<$socket>; | |||||||||||||||||||||
| 314 | 0 | ▶ | unless ($return =~ /^2\d\d\s+/) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 315 | 0 | die "not welcome at cddb db"; | |||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||
| 317 | |||||||||||||||||||||||
| 318 | 0 | print $socket "cddb hello $HELLO_ID\n"; | |||||||||||||||||||||
| 319 | |||||||||||||||||||||||
| 320 | 0 | $return=<$socket>; | |||||||||||||||||||||
| 321 | 0 | ▶ | print STDERR "hello return: $return" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 322 | 0 | ▶ | unless ($return =~ /^2\d\d\s+/) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 323 | 0 | die "handshake error at cddb db: $CDDB_HOST:$CDDB_PORT"; | |||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||
| 325 | |||||||||||||||||||||||
| 326 | 0 | print $socket "proto $PROTO_VERSION\n"; | |||||||||||||||||||||
| 327 | |||||||||||||||||||||||
| 328 | 0 | $return=<$socket>; | |||||||||||||||||||||
| 329 | 0 | ▶ | print STDERR "proto return: $return" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 330 | 0 | ▶ | unless ($return =~ /^2\d\d\s+/) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 331 | 0 | die "protokoll mismatch error at cddb db: $CDDB_HOST:$CDDB_PORT"; | |||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||
| 333 | |||||||||||||||||||||||
| 334 | 0 | ▶ | print STDERR "cddb: sending: $query\n" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 335 | 0 | print $socket "$query\n"; | |||||||||||||||||||||
| 336 | |||||||||||||||||||||||
| 337 | 0 | $return=<$socket>; | |||||||||||||||||||||
| 338 | 0 | chomp $return; | |||||||||||||||||||||
| 339 | |||||||||||||||||||||||
| 340 | 0 | ▶ | print STDERR "cddb: result: $return\n" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 341 | } elsif ($CDDB_MODE eq "http") { | ||||||||||||||||||||||
| 342 | 0 | my $query2=$query; | |||||||||||||||||||||
| 343 | 0 | $query2 =~ s/ /+/g; | |||||||||||||||||||||
| 344 | 0 | my $id=$HELLO_ID; | |||||||||||||||||||||
| 345 | 0 | $id =~ s/ /+/g; | |||||||||||||||||||||
| 346 | |||||||||||||||||||||||
| 347 | 0 | my $url = "/~cddb/cddb.cgi?cmd=$query2&hello=$id&proto=$PROTO_VERSION"; | |||||||||||||||||||||
| 348 | |||||||||||||||||||||||
| 349 | 0 | my $host=$CDDB_HOST; | |||||||||||||||||||||
| 350 | 0 | my $port=80; | |||||||||||||||||||||
| 351 | |||||||||||||||||||||||
| 352 | 0 | my ($user,$pass); | |||||||||||||||||||||
| 353 | |||||||||||||||||||||||
| 354 | 0 | ▶ | if($HTTP_PROXY) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 355 | 0 | ▶ | if($HTTP_PROXY =~ /^(http:\/\/|)(.+?):(.+)\@(.+?):(.+)/) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 356 | 0 | $user=$2; | |||||||||||||||||||||
| 357 | 0 | $pass=$3; | |||||||||||||||||||||
| 358 | 0 | $host=$4; | |||||||||||||||||||||
| 359 | 0 | $port=$5; | |||||||||||||||||||||
| 360 | } elsif($HTTP_PROXY =~ /^(http:\/\/|)(.+?):(\d+)/) { | ||||||||||||||||||||||
| 361 | 0 | $host=$2; | |||||||||||||||||||||
| 362 | 0 | $port=$3; | |||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||
| 364 | 0 | $url="http://$CDDB_HOST".$url." HTTP/1.0"; | |||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||
| 366 | |||||||||||||||||||||||
| 367 | 0 | ▶ | print STDERR "cddb: connecting to $host:$port\n" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 368 | |||||||||||||||||||||||
| 369 | 0 | ▶ | $socket=IO::Socket::INET->new(PeerAddr=>$host, PeerPort=>$port, | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 370 | Proto=>"tcp",Type=>SOCK_STREAM) or die "cannot connect to cddb db: $host:$port [$!]"; | ||||||||||||||||||||||
| 371 | |||||||||||||||||||||||
| 372 | 0 | ▶ | print STDERR "cddb: http send: GET $url\n" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 373 | 0 | print $socket "GET $url\n"; | |||||||||||||||||||||
| 374 | |||||||||||||||||||||||
| 375 | 0 | ▶ | if($user) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 376 | 0 | my $cred = encode_base64("$user:$pass"); | |||||||||||||||||||||
| 377 | 0 | print $socket "Proxy-Authorization: Basic $cred\n"; | |||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||
| 379 | |||||||||||||||||||||||
| 380 | 0 | print $socket "\n"; | |||||||||||||||||||||
| 381 | 0 | ▶ | print $socket "\n" if $FW; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 382 | |||||||||||||||||||||||
| 383 | 0 | ▶ | if($HTTP_PROXY) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 384 | 0 | ▶ | while(<$socket> =~ /^\S+/){}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||
| 386 | |||||||||||||||||||||||
| 387 | 0 | $return=<$socket>; | |||||||||||||||||||||
| 388 | 0 | chomp $return; | |||||||||||||||||||||
| 389 | |||||||||||||||||||||||
| 390 | 0 | ▶ | print STDERR "cddb: http result: $return\n" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 391 | } else { | ||||||||||||||||||||||
| 392 | 0 | die "unkown mode: $CDDB_MODE for querying cddb"; | |||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||
| 394 | |||||||||||||||||||||||
| 395 | 0 | $return =~ s/\r//g; | |||||||||||||||||||||
| 396 | |||||||||||||||||||||||
| 397 | 0 | my ($err) = $return =~ /^(\d\d\d)\s+/; | |||||||||||||||||||||
| 398 | 0 | ▶ | unless ($err =~ /^2/) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 399 | 0 | die "query error at cddb db: $CDDB_HOST:$CDDB_PORT"; | |||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||
| 401 | |||||||||||||||||||||||
| 402 | 0 | ▶ | if($err==202) { | ||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||
| 403 | 0 | return undef; | |||||||||||||||||||||
| 404 | ▶ | } elsif(($err==211) || ($err==210)) { | |||||||||||||||||||||
|
Condition0%0/3
$err == 211 or $err == 210
MC/DC0%0/2
$err == 211 or $err == 210
$err == 211
$err == 210
Truth table0%0/3
A or B
A= $err == 211B= $err == 210
| |||||||||||||||||||||||
| 405 | 0 | ▶ | while(<$socket>) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 406 | 0 | ▶ | last if(/^\./); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 407 | 0 | push @list,$_; | |||||||||||||||||||||
| 408 | 0 | s/\r//g; | |||||||||||||||||||||
| 409 | 0 | ▶ | print STDERR "unexact: $_" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||
| 411 | } elsif($err==200) { | ||||||||||||||||||||||
| 412 | 0 | $return =~ s/^200 //; | |||||||||||||||||||||
| 413 | 0 | push @list,$return; | |||||||||||||||||||||
| 414 | } else { | ||||||||||||||||||||||
| 415 | 0 | die "cddb: unknown: $return"; | |||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||
| 417 | |||||||||||||||||||||||
| 418 | 0 | my @to_get; | |||||||||||||||||||||
| 419 | |||||||||||||||||||||||
| 420 | 0 | ▶ | unless($multi) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 421 | 0 | ▶ | if (@list) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 422 | 0 | my $index; | |||||||||||||||||||||
| 423 | 0 | ▶ | if($input==1) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 424 | 0 | print "This CD could be:\n\n"; | |||||||||||||||||||||
| 425 | 0 | my $i=1; | |||||||||||||||||||||
| 426 | 0 | for(@list) { | |||||||||||||||||||||
| 427 | 0 | my ($tit) = $_ =~ /^\S+\s+\S+\s+(.*)/; | |||||||||||||||||||||
| 428 | 0 | print "$i: $tit\n"; | |||||||||||||||||||||
| 429 | 0 | $i++ | |||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||
| 431 | 0 | print "\n0: none of the above\n\nChoose: "; | |||||||||||||||||||||
| 432 | 0 | my $n=<STDIN>; | |||||||||||||||||||||
| 433 | 0 | $index=int($n); | |||||||||||||||||||||
| 434 | } else { | ||||||||||||||||||||||
| 435 | 0 | $index=1; | |||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||
| 437 | |||||||||||||||||||||||
| 438 | 0 | ▶ | if ($index == 0) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 439 | 0 | return undef; | |||||||||||||||||||||
| 440 | } else { | ||||||||||||||||||||||
| 441 | 0 | push @to_get,$list[$index-1]; | |||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||
| 444 | } else { | ||||||||||||||||||||||
| 445 | 0 | push @to_get,@list; | |||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||
| 447 | |||||||||||||||||||||||
| 448 | 0 | my $i=0; | |||||||||||||||||||||
| 449 | 0 | for my $get (@to_get) { | |||||||||||||||||||||
| 450 | #200 misc 0a01e802 Meredith Brooks / Bitch Single | ||||||||||||||||||||||
| 451 | 0 | my ($cat,$id,$at) = $get =~ /^(\S+?)\s+(\S+?)\s+(.*)/; | |||||||||||||||||||||
| 452 | |||||||||||||||||||||||
| 453 | 0 | my $artist; | |||||||||||||||||||||
| 454 | my $title; | ||||||||||||||||||||||
| 455 | |||||||||||||||||||||||
| 456 | 0 | ▶ | if($at =~ /\//) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 457 | 0 | ($artist,$title)= $at =~ /^(.*?)\s\/\s(.*)/; | |||||||||||||||||||||
| 458 | } else { | ||||||||||||||||||||||
| 459 | 0 | $artist=$at; | |||||||||||||||||||||
| 460 | 0 | $title=$at; | |||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||
| 462 | |||||||||||||||||||||||
| 463 | 0 | my %cd=(); | |||||||||||||||||||||
| 464 | 0 | $cd{artist}=$artist; | |||||||||||||||||||||
| 465 | 0 | chomp $title; | |||||||||||||||||||||
| 466 | 0 | $title =~ s/\r//g; | |||||||||||||||||||||
| 467 | 0 | $cd{title}=$title; | |||||||||||||||||||||
| 468 | 0 | $cd{cat}=$cat; | |||||||||||||||||||||
| 469 | 0 | $cd{id}=$id; | |||||||||||||||||||||
| 470 | |||||||||||||||||||||||
| 471 | 0 | my @lines; | |||||||||||||||||||||
| 472 | |||||||||||||||||||||||
| 473 | 0 | $query="cddb read $cat $id"; | |||||||||||||||||||||
| 474 | |||||||||||||||||||||||
| 475 | 0 | ▶ | if ($CDDB_MODE eq "cddb") { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 476 | 0 | ▶ | print STDERR "cddb: getting: $query\n" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 477 | 0 | print $socket "$query\n"; | |||||||||||||||||||||
| 478 | |||||||||||||||||||||||
| 479 | 0 | ▶ | while(<$socket>) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 480 | 0 | ▶ | last if(/^\./); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 481 | 0 | push @lines,$_; | |||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||
| 483 | 0 | ▶ | if(@to_get-1 == $i) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 484 | 0 | print $socket "quit\n"; | |||||||||||||||||||||
| 485 | 0 | close $socket; | |||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||
| 487 | |||||||||||||||||||||||
| 488 | } elsif ($CDDB_MODE eq "http") { | ||||||||||||||||||||||
| 489 | 0 | close $socket; | |||||||||||||||||||||
| 490 | |||||||||||||||||||||||
| 491 | 0 | my $query2=$query; | |||||||||||||||||||||
| 492 | 0 | $query2 =~ s/ /+/g; | |||||||||||||||||||||
| 493 | 0 | my $id=$HELLO_ID; | |||||||||||||||||||||
| 494 | 0 | $id =~ s/ /+/g; | |||||||||||||||||||||
| 495 | |||||||||||||||||||||||
| 496 | 0 | my $url = "/~cddb/cddb.cgi?cmd=$query2&hello=$id&proto=$PROTO_VERSION"; | |||||||||||||||||||||
| 497 | |||||||||||||||||||||||
| 498 | 0 | my $host=$CDDB_HOST; | |||||||||||||||||||||
| 499 | 0 | my $port=80; | |||||||||||||||||||||
| 500 | |||||||||||||||||||||||
| 501 | 0 | my ($user,$pass); | |||||||||||||||||||||
| 502 | |||||||||||||||||||||||
| 503 | 0 | ▶ | if($HTTP_PROXY) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 504 | 0 | ▶ | if($HTTP_PROXY =~ /^(http:\/\/|)(.+?):(.+)\@(.+?):(.+)/) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 505 | 0 | $user=$2; | |||||||||||||||||||||
| 506 | 0 | $pass=$3; | |||||||||||||||||||||
| 507 | 0 | $host=$4; | |||||||||||||||||||||
| 508 | 0 | $port=$5; | |||||||||||||||||||||
| 509 | } elsif($HTTP_PROXY =~ /^(http:\/\/|)(.+?):(\d+)/) { | ||||||||||||||||||||||
| 510 | 0 | $host=$2; | |||||||||||||||||||||
| 511 | 0 | $port=$3; | |||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||
| 513 | 0 | $url="http://$CDDB_HOST".$url." HTTP/1.0"; | |||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||
| 515 | |||||||||||||||||||||||
| 516 | 0 | ▶ | print STDERR "cddb: connecting to $host:$port\n" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 517 | |||||||||||||||||||||||
| 518 | 0 | ▶ | $socket=IO::Socket::INET->new(PeerAddr=>$host, PeerPort=>$port, | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 519 | Proto=>"tcp",Type=>SOCK_STREAM) or die "cannot connect to cddb db: $host:$port [$!]"; | ||||||||||||||||||||||
| 520 | |||||||||||||||||||||||
| 521 | 0 | ▶ | print STDERR "cddb: http send: GET $url\n" if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 522 | 0 | print $socket "GET $url\n"; | |||||||||||||||||||||
| 523 | |||||||||||||||||||||||
| 524 | 0 | ▶ | if($user) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 525 | 0 | my $cred = encode_base64("$user:$pass"); | |||||||||||||||||||||
| 526 | 0 | print $socket "Proxy-Authorization: Basic $cred\n"; | |||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||
| 528 | |||||||||||||||||||||||
| 529 | 0 | print $socket "\n"; | |||||||||||||||||||||
| 530 | 0 | ▶ | print $socket "\n" if $FW; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 531 | |||||||||||||||||||||||
| 532 | 0 | ▶ | if($HTTP_PROXY) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 533 | 0 | ▶ | while(<$socket> =~ /^\S+/){}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||
| 535 | |||||||||||||||||||||||
| 536 | 0 | ▶ | while(<$socket>) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 537 | 0 | ▶ | last if(/^\./); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 538 | 0 | push @lines,$_; | |||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||
| 540 | 0 | close $socket; | |||||||||||||||||||||
| 541 | } else { | ||||||||||||||||||||||
| 542 | 0 | die "unkown mode: $CDDB_MODE for querying cddb"; | |||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||
| 544 | |||||||||||||||||||||||
| 545 | # xmcd | ||||||||||||||||||||||
| 546 | # | ||||||||||||||||||||||
| 547 | # Track frame offsets: | ||||||||||||||||||||||
| 548 | # 150 | ||||||||||||||||||||||
| 549 | # ... | ||||||||||||||||||||||
| 550 | # 210627 | ||||||||||||||||||||||
| 551 | # | ||||||||||||||||||||||
| 552 | # Disc length: 2952 seconds | ||||||||||||||||||||||
| 553 | # | ||||||||||||||||||||||
| 554 | # Revision: 1 | ||||||||||||||||||||||
| 555 | # Submitted via: xmcd 2.0 | ||||||||||||||||||||||
| 556 | # | ||||||||||||||||||||||
| 557 | |||||||||||||||||||||||
| 558 | 0 | for(@lines) { | |||||||||||||||||||||
| 559 | 0 | ▶ | last if(/^\./); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 560 | 0 | ▶ | next if(/^\d\d\d/); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 561 | 0 | push @{$cd{raw}},$_; | |||||||||||||||||||||
| 562 | #TTITLE0=Bitch (Edit) | ||||||||||||||||||||||
| 563 | 0 | ▶ | if(/^TTITLE(\d+)\=\s*(.*)/) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 564 | 0 | my $t= $2; | |||||||||||||||||||||
| 565 | 0 | chop $t; | |||||||||||||||||||||
| 566 | 0 | $cd{frames}[$1]=$toc->[$1]->{frames}; | |||||||||||||||||||||
| 567 | 0 | $cd{data}[$1]=$toc->[$1]->{data}; | |||||||||||||||||||||
| 568 | 0 | ▶ | unless (defined $cd{track}[$1]) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 569 | 0 | $cd{track}[$1]=$t; | |||||||||||||||||||||
| 570 | } else { | ||||||||||||||||||||||
| 571 | 0 | $cd{track}[$1]=$cd{track}[$1].$t; | |||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||
| 573 | } elsif(/^DYEAR=\s*(\d+)/) { | ||||||||||||||||||||||
| 574 | 0 | $cd{'year'} = $1; | |||||||||||||||||||||
| 575 | } elsif(/^DGENRE=\s*(\S+.*)/) { | ||||||||||||||||||||||
| 576 | 0 | my $t = $1; | |||||||||||||||||||||
| 577 | 0 | chop $t; | |||||||||||||||||||||
| 578 | 0 | $cd{'genre'} = $t; | |||||||||||||||||||||
| 579 | } elsif(/^\#\s+Revision:\s+(\d+)/) { | ||||||||||||||||||||||
| 580 | 0 | $cd{'revision'} = $1; | |||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||
| 583 | |||||||||||||||||||||||
| 584 | 0 | $cd{tno}=$#{$cd{track}}+1; | |||||||||||||||||||||
| 585 | 0 | $cd{frames}[$cd{tno}]=$toc->[$cd{tno}]->{frames}; | |||||||||||||||||||||
| 586 | |||||||||||||||||||||||
| 587 | 0 | ▶ | return %cd unless($multi); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 588 | 0 | push @r,\%cd; | |||||||||||||||||||||
| 589 | 0 | $i++; | |||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||
| 591 | |||||||||||||||||||||||
| 592 | 0 | return @r; | |||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||
| 594 | |||||||||||||||||||||||
| 595 | 1 | 1; | |||||||||||||||||||||
| 596 | __END__ | ||||||||||||||||||||||