Commit 2b3f3a1a1f145c04aa87b75ac76e089019548d85

Authored by Georg Hopp
1 parent 388a47ab

first checkin for 0.1.0 candidate

No preview for this file type
1   -diff -Naur CDDB_get-2.23/CDDB_get.pm CDDB_get-2.23p1/CDDB_get.pm
2   ---- CDDB_get-2.23/CDDB_get.pm 2003-09-07 15:49:27.000000000 +0000
3   -+++ CDDB_get-2.23p1/CDDB_get.pm 2004-06-30 08:37:28.000000000 +0000
4   -@@ -261,6 +261,7 @@
5   -
6   - my $input = $config->{input};
7   - my $multi = $config->{multi};
8   -+ my $entry = $config->{entry} if (defined($config->{entry}));
9   - $input = 0 if $multi;
10   -
11   - print STDERR Dumper($config) if $debug;
12   -@@ -426,7 +427,14 @@
13   - }
14   - }
15   - } else {
16   -- push @to_get,@list;
17   -+ unless(defined($entry)) {
18   -+ push @to_get,@list;
19   -+ }
20   -+ else {
21   -+ if($entry-1 >= 0 && $entry-1 <= $#list) {
22   -+ push @to_get,$list[$entry-1];
23   -+ }
24   -+ }
25   - }
26   -
27   - my $i=0;
28   -diff -Naur CDDB_get-2.23/cddb.pl CDDB_get-2.23p1/cddb.pl
29   ---- CDDB_get-2.23/cddb.pl 2003-08-16 19:01:49.000000000 +0000
30   -+++ CDDB_get-2.23p1/cddb.pl 2004-06-30 08:33:03.000000000 +0000
31   -@@ -27,12 +27,13 @@
32   - use strict;
33   -
34   - my %option = ();
35   --getopts("oghdtsiSfDlOFc:", \%option);
36   -+getopts("oghdtsiSfDlOFe:c:", \%option);
37   -
38   - if($option{h}) {
39   - print "$0: gets CDDB info of a CD\n";
40   - print " no argument - gets CDDB info of CD in your drive\n";
41   - print " -c device (other than default device)\n";
42   -+ print " -e which cddb-entry to use\n";
43   - print " -o offline mode - just stores CD info\n";
44   - print " -d output in xmcd format\n";
45   - print " -s save in xmcd format\n";
46   -@@ -81,11 +82,19 @@
47   - $config{CD_DEVICE}=$option{c} if $option{c};
48   -
49   - # user interaction welcome?
50   --
51   --$config{input}=1; # 1: ask user if more than one possibility
52   -- # 0: no user interaction
53   --$config{multi}=0; # 1: do not ask user and get all of them
54   -- # 0: just the first one
55   -+if($option{e}) {
56   -+ $config{entry}=$option{e};
57   -+ $config{input}=0; # 1: ask user if more than one possibility
58   -+ # 0: no user interaction
59   -+ $config{multi}=0; # 1: do not ask user and get all of them
60   -+ # 0: just the first one
61   -+}
62   -+else {
63   -+ $config{input}=1; # 1: ask user if more than one possibility
64   -+ # 0: no user interaction
65   -+ $config{multi}=0; # 1: do not ask user and get all of them
66   -+ # 0: just the first one
67   -+}
68   -
69   - my %db;
70   -
No preview for this file type
1   -diff -Naur CDDB_get-2.27/CDDB_get.pm CDDB_get-2.27.patched/CDDB_get.pm
2   ---- CDDB_get-2.27/CDDB_get.pm 2006-01-01 20:52:54.000000000 +0100
3   -+++ CDDB_get-2.27.patched/CDDB_get.pm 2006-05-27 09:54:30.733131044 +0200
4   -@@ -262,6 +262,7 @@
5   -
6   - my $input = $config->{input};
7   - my $multi = $config->{multi};
8   -+ my $entry = $config->{entry} if (defined($config->{entry}));
9   - $input = 0 if $multi;
10   -
11   - print STDERR Dumper($config) if $debug;
12   -@@ -441,7 +442,14 @@
13   - }
14   - }
15   - } else {
16   -- push @to_get,@list;
17   -+ unless(defined($entry)) {
18   -+ push @to_get,@list;
19   -+ }
20   -+ else {
21   -+ if($entry-1 >= 0 && $entry-1 <= $#list) {
22   -+ push @to_get,$list[$entry-1];
23   -+ }
24   -+ }
25   - }
26   -
27   - my $i=0;
28   -diff -Naur CDDB_get-2.27/cddb.pl CDDB_get-2.27.patched/cddb.pl
29   ---- CDDB_get-2.27/cddb.pl 2005-10-06 08:00:59.000000000 +0200
30   -+++ CDDB_get-2.27.patched/cddb.pl 2006-05-27 09:56:17.798156565 +0200
31   -@@ -27,12 +27,13 @@
32   - use strict;
33   -
34   - my %option = ();
35   --getopts("oghdtsi:SfDlOFc:H:CIRGP", \%option);
36   -+getopts("oghdtsi:SfDlOFe:c:H:CIRGP", \%option);
37   -
38   - if($option{h}) {
39   - print "$0: gets CDDB info of a CD\n";
40   - print " no argument - gets CDDB info of CD in your drive\n";
41   - print " -c device (other than default device)\n";
42   -+ print " -e which cddb-entry to use\n";
43   - print " -o offline mode - just stores CD info\n";
44   - print " -d output in xmcd format\n";
45   - print " -s save in xmcd format\n";
46   -@@ -110,11 +111,19 @@
47   - $config{CD_DEVICE}=$option{c} if $option{c};
48   -
49   - # user interaction welcome?
50   --
51   --$config{input}=1; # 1: ask user if more than one possibility
52   -- # 0: no user interaction
53   --$config{multi}=0; # 1: do not ask user and get all of them
54   -- # 0: just the first one
55   -+if($option{e}) {
56   -+ $config{entry}=$option{e};
57   -+ $config{input}=0; # 1: ask user if more than one possibility
58   -+ # 0: no user interaction
59   -+ $config{multi}=0; # 1: do not ask user and get all of them
60   -+ # 0: just the first one
61   -+}
62   -+else {
63   -+ $config{input}=1; # 1: ask user if more than one possibility
64   -+ # 0: no user interaction
65   -+ $config{multi}=0; # 1: do not ask user and get all of them
66   -+ # 0: just the first one
67   -+}
68   -
69   - $config{input}=0 if($option{I});
70   -
1   -#!/usr/bin/perl -I.
2   -#
3   -# CDDB - Read the CDDB entry for an audio CD in your drive
4   -#
5   -# This module/script gets the CDDB info for an audio cd. You need
6   -# LINUX, a cdrom drive and an active internet connection in order
7   -# to do that.
8   -#
9   -# (c) 2004 Armin Obersteiner <armin@xos.net>
10   -#
11   -# LICENSE
12   -#
13   -# This library is released under the same conditions as Perl, that
14   -# is, either of the following:
15   -#
16   -# a) the GNU General Public License Version 2 as published by the
17   -# Free Software Foundation,
18   -#
19   -# b) the Artistic License.
20   -#
21   -
22   -#use CDDB_get qw( get_cddb get_discids );
23   -
24   -use Data::Dumper;
25   -use Getopt::Std;
26   -
27   -use strict;
28   -
29   -my %option = ();
30   -getopts("oghdtsi:SfDlOFe:c:H:CIRGP", \%option);
31   -
32   -if($option{h}) {
33   - print "$0: gets CDDB info of a CD\n";
34   - print " no argument - gets CDDB info of CD in your drive\n";
35   - print " -c device (other than default device)\n";
36   - print " -e which cddb-entry to use\n";
37   - print " -o offline mode - just stores CD info\n";
38   - print " -d output in xmcd format\n";
39   - print " -s save in xmcd format\n";
40   - print " -i db. one of: mysql, pg, oracle, sqlite\n";
41   - print " -O overwrite file or db\n";
42   - print " -t output toc\n";
43   - print " -l output lame command\n";
44   - print " -f http mode (e.g. through firewalls)\n";
45   - print " -F some stateful firewalls/http proxies need additional newlines\n";
46   - print " -g get CDDB info for stored CDs\n";
47   - print " -I non interactive mode\n";
48   - print " -H CDDB hostname\n";
49   - print " -C use local cache\n";
50   - print " -R readonly cache\n";
51   - print " -G cache has not the diskid as filenames (much slower)\n";
52   - print " -P cache path (default: /tmp/xmcd)\n";
53   - print " -D put CDDB_get in debug mode\n";
54   - exit;
55   -}
56   -
57   -my %config;
58   -
59   -my $diskid;
60   -my $total;
61   -my $toc;
62   -my $savedir="/tmp/cddb";
63   -my $xmcddir="/tmp/xmcd";
64   -
65   -if($option{C}) {
66   - # use CDDB_cache qw( get_cddb get_discids );
67   - require CDDB_cache;
68   - CDDB_cache->import( qw( get_cddb get_discids ) );
69   -
70   - $CDDB_cache::debug=1 if($option{D});
71   - $CDDB_cache::readonly=1 if($option{R});
72   - $CDDB_cache::grep=1 if($option{G});
73   -
74   - $CDDB_cache::dir="/tmp/xmcd"; # default
75   - # $CDDB_cache::dir="/opt/kde2/share/apps/kscd/cddb";
76   - $CDDB_cache::dir=$option{P} if($option{P});
77   -
78   -} else {
79   - # use CDDB_get qw( get_cddb get_discids );
80   - require CDDB_get;
81   - CDDB_get->import( qw( get_cddb get_discids ) );
82   -}
83   -
84   -$CDDB_get::debug=1 if($option{D});
85   -
86   -# following variables just need to be declared if different from defaults
87   -# defaults are listed below (cdrom default is os specific)
88   -
89   -# $config{CDDB_HOST}="freedb.freedb.org"; # set cddb host
90   -if($option{H}) {
91   - $config{CDDB_HOST}=$option{H};
92   -}
93   -# $config{CDDB_PORT}=8880; # set cddb port
94   -# $config{CDDB_MODE}="cddb"; # set cddb mode: cddb or http, this is switched with -f
95   -# $config{CD_DEVICE}="/dev/cdrom"; # set cd device
96   -
97   -# $config{HELLO_ID} ="root nowhere.com fastrip 0.77"; # hello string: username hostname clientname version
98   -# $config{PROTO_VERSION} = 5; # cddb protokol version
99   -
100   -
101   -# get proxy settings for cddb mode
102   -
103   -$config{HTTP_PROXY}=$ENV{http_proxy} if $ENV{http_proxy}; # maybe wanna use a proxy ?
104   -
105   -$config{CDDB_MODE}="http" if($option{f});
106   -if($option{F}) {
107   - $config{CDDB_MODE}="http";
108   - $config{FW}=1;
109   -}
110   -
111   -$config{CD_DEVICE}=$option{c} if $option{c};
112   -
113   -# user interaction welcome?
114   -if($option{e}) {
115   - $config{entry}=$option{e};
116   - $config{input}=0; # 1: ask user if more than one possibility
117   - # 0: no user interaction
118   - $config{multi}=0; # 1: do not ask user and get all of them
119   - # 0: just the first one
120   -}
121   -else {
122   - $config{input}=1; # 1: ask user if more than one possibility
123   - # 0: no user interaction
124   - $config{multi}=0; # 1: do not ask user and get all of them
125   - # 0: just the first one
126   -}
127   -
128   -$config{input}=0 if($option{I});
129   -
130   -my %db;
131   -
132   -if($option{i}) {
133   - require DBI;
134   -
135   - $db{table_cds} = "cds";
136   - $db{table_tracks} = "tracks";
137   -
138   - # not needed for sqlite
139   - $db{host} = "localhost";
140   - $db{port} = "3306";
141   -
142   - # not needed for oracle/sqlite
143   - $db{name} = "mp3-test";
144   -
145   - # just for oracle
146   - $db{sid} = "xxx";
147   - $db{home} = "xxx";
148   -
149   - # just for sqlite
150   - $db{file} = "xxx";
151   -
152   - # not needed for sqlite
153   - $db{user} = "root";
154   - $db{passwd} = "xxx";
155   -
156   -
157   - if($option{i} eq "mysql") {
158   - $db{connect} = sub { "dbi:mysql:database=$db{name};host=$db{host};port=$db{port}", $db{user}, $db{passwd} };
159   - } elsif($option{i} eq "pg") {
160   - $db{connect} = sub { "dbi:Pg:dbname=$db{dbname};host=$db{host};port=$db{port}", $db{user}, $db{passwd} };
161   - } elsif($option{i} eq "oracle") {
162   - $db{connect} = sub { "dbi:Oracle:host=$db{host};sid=$db{sid};port=$db{port}", $db{user}, $db{passwd} };
163   - $ENV{ORACLE_HOME} = $db{home};
164   - } elsif($option{i} eq "sqlite") {
165   - $db{connect} = sub { "dbi:SQLite:dbname=$db{file}","","" };
166   - } else {
167   - die "unkown database: $option{i}";
168   - }
169   -}
170   -
171   -if($option{o}) {
172   - my $ids=get_discids($config{CD_DEVICE});
173   -
174   - unless(-e $savedir) {
175   - mkdir $savedir,0755 or die "cannot create $savedir";
176   - }
177   -
178   - open OUT,">$savedir/$ids->[0]\_$$" or die "cannot open outfile";
179   - print OUT Data::Dumper->Dump($ids,["diskid","total","toc"]);
180   - close OUT;
181   -
182   - print STDERR "saved in: $savedir/$ids->[0]\_$$\n";
183   - exit;
184   -}
185   -
186   -if($option{g}) {
187   - print STDERR "retrieving stored cds ...\n";
188   -
189   - opendir(DIR, $savedir) or die "cannot opendir $savedir";
190   - while (defined(my $file = readdir(DIR))) {
191   - next if($file =~ /^\./);
192   - print "\n";
193   -
194   - my $in=`/bin/cat $savedir/$file`;
195   - my $exit = $? >> 8;
196   -
197   - if($exit>0) {
198   - die "error reading file";
199   - }
200   -
201   - unless($in=~ m/^\$diskid\s+=\s+('\d+'|\d+);\s+ # $diskid
202   - \$total\s+=\s+('\d+'|\d+);\s+ # $total
203   - \$toc\s+=\s+\[\s+ # $toc
204   - (\{\s+
205   - ('(frame|frames|min|sec|data)'\s+=\>\s+('\d+'|\d+)(,|)\s+){5}
206   - \}(,|)\s+)+
207   - \];\s+$/xs) {
208   - print "not a save file: $savedir/$file\n";
209   - next;
210   - }
211   -
212   - eval $in;
213   -
214   - if($@) {
215   - print "not a save file (eval error): $savedir/$file\n";
216   - next;
217   - }
218   -
219   - my %cd=get_cddb(\%config,[$diskid,$total,$toc]);
220   -
221   - unless(defined $cd{title}) {
222   - print "no cddb entry found: $savedir/$file\n";
223   - }
224   -
225   - unlink "$savedir/$file";
226   -
227   - next unless defined $cd{title};
228   -
229   - if($option{d} || $option{s}) {
230   - print_xmcd(\%cd,$option{s});
231   - } elsif($option{i}) {
232   - insert_db(\%cd,\%db);
233   - } elsif($option{l}) {
234   - print_lame(\%cd);
235   - } else {
236   - print_cd(\%cd);
237   - }
238   - }
239   - closedir(DIR);
240   - exit;
241   -}
242   -
243   -# get it on
244   -
245   -unless($config{multi}) {
246   - my %cd;
247   -
248   - # for those who don't like 'die' in modules ;-)
249   - eval {
250   - %cd = get_cddb(\%config);
251   - };
252   - if ($@) {
253   - print "fatal error: $!\n";
254   - exit;
255   - }
256   -
257   - print Dumper(\%cd) if $option{D};
258   -
259   - unless(defined $cd{title}) {
260   - die "no cddb entry found";
261   - }
262   -
263   - # do somthing with the results
264   -
265   - if($option{d} || $option{s}) {
266   - print_xmcd(\%cd,$option{s});
267   - } elsif($option{i}) {
268   - insert_db(\%cd,\%db);
269   - } elsif($option{l}) {
270   - print_lame(\%cd);
271   - } else {
272   - print_cd(\%cd);
273   - }
274   -} else {
275   - my @cd;
276   -
277   - # for those who don't like 'die' in modules ;-)
278   - eval {
279   - @cd=get_cddb(\%config);
280   - };
281   - if ($@) {
282   - print "fatal error: $!\n";
283   - exit;
284   - }
285   -
286   - print Dumper(\@cd) if $option{D};
287   -
288   - for my $c (@cd) {
289   - unless(defined $c->{title}) {
290   - die "no cddb entry found";
291   - }
292   -
293   - # do somthing with the results
294   -
295   - if($option{d} || $option{s}) {
296   - print_xmcd($c,$option{s});
297   - } elsif($option{i}) {
298   - insert_db($c,\%db);
299   - } elsif($option{l}) {
300   - print_lame($c);
301   - print "\n";
302   - } else {
303   - print_cd($c);
304   - print "\n";
305   - }
306   - }
307   -}
308   -
309   -exit;
310   -
311   -
312   -# subroutines
313   -
314   -sub print_cd {
315   - my $cd=shift;
316   -
317   - print "artist: $cd->{artist}\n";
318   - print "title: $cd->{title}\n";
319   - print "category: $cd->{cat}\n";
320   - print "genre: $cd->{genre}\n" if($cd->{genre});
321   - print "year: $cd->{year}\n" if($cd->{year});
322   - print "cddbid: $cd->{id}\n";
323   - print "trackno: $cd->{tno}\n";
324   -
325   - my $n=1;
326   - foreach my $i ( @{$cd->{track}} ) {
327   - if($option{t}) {
328   - my $from=$cd->{frames}[$n-1];
329   - my $to=$cd->{frames}[$n]-1;
330   - my $dur=$to-$from;
331   - my $min=int($dur/75/60);
332   - my $sec=int($dur/75)-$min*60;
333   - my $frm=($dur-$sec*75-$min*75*60)*100/75;
334   - my $out=sprintf "track %2d: %8d - %8d [%2d:%.2d.%.2d]: $i\n",$n,$from,$to,$min,$sec,$frm;
335   - print "$out";
336   - } else {
337   - print "track $n: $i\n";
338   - }
339   - $n++;
340   - }
341   -}
342   -
343   -sub print_xmcd {
344   - my $cd=shift;
345   - my $save=shift;
346   -
347   - *OUT=*STDOUT;
348   -
349   - if($save) {
350   - unless(-e $xmcddir) {
351   - mkdir $xmcddir,0755 or die "cannot create $savedir";
352   - }
353   -
354   - unless($option{O}) {
355   - if(-e "$xmcddir/$cd->{id}") {
356   - print "XMCD file exists\n";
357   - exit;
358   - }
359   - }
360   -
361   - open XMCD,">$xmcddir/$cd->{id}" or die "cannot open outfile";
362   - *OUT=*XMCD;
363   - }
364   -
365   - for(@{$cd->{raw}}) {
366   - print OUT "$_";
367   - }
368   -
369   - if($save) {
370   - print STDERR "saved in: $xmcddir/$cd->{id}\n";
371   - close OUT;
372   - }
373   -}
374   -
375   -sub insert_db {
376   - my $cd=shift;
377   - my $db=shift;
378   -
379   - my ($artist, $title, $category, $cddbid, $trackno) =
380   - ($cd->{artist}, $cd->{title}, $cd->{cat}, $cd->{id}, $cd->{tno});
381   -
382   - my $sql = "SELECT cddbid FROM $db->{table_cds} WHERE CDDBID = \'$cddbid\'";
383   - my $dbh = DBI->connect($db->{connect}->()) or die "cannot connect to db: $DBI::errstr";
384   - my $sth = $dbh->prepare($sql);
385   - my $r = $sth->execute or die "cannot check for cd: $DBI::errstr";
386   - if ($r == 1) {
387   - print "cd already in db\n";
388   - if($option{O}) {
389   - my $sql = "DELETE FROM $db->{table_cds} WHERE CDDBID = \'$cddbid\'";
390   - my $sth = $dbh->prepare($sql);
391   - my $r = $sth->execute or die "cannot delete from $db->{table_cds}: $DBI::errstr";
392   - $sql = "DELETE FROM $db->{table_tracks} WHERE CDDBID = \'$cddbid\'";
393   - $sth = $dbh->prepare($sql);
394   - $r = $sth->execute or die "cannot delete from $db->{table_tracks}: $DBI::errstr";
395   - } else {
396   - exit;
397   - }
398   - }
399   -
400   - $title =~ s/'/\\'/g;
401   - $artist =~ s/'/\\'/g;
402   - $category =~ s/'/\\'/g;
403   -
404   - $sql = "INSERT INTO $db->{table_cds} (cddbid, artist, title, category, tracks) VALUES (\'$cddbid\', \'$artist\', \'$title\', \'$category\' , \'$trackno\')";
405   - $sth = $dbh->prepare($sql);
406   - $r = $sth->execute or die "failed to insert cd: $DBI::errstr";
407   -
408   - my $n=1;
409   -
410   - print "titel: $title\n";
411   - print "artist: $artist\n";
412   - print "category: $category\n\n";
413   -
414   - for my $t ( @{$cd->{track}} ) {
415   - $t =~ s/'/\\'/g;
416   - my $dur=($cd->{frames}[$n]-1-$cd->{frames}[$n-1])/75;
417   - my $hour=int($dur/3600);
418   - my $min=int($dur/60-$hour*60);
419   - my $sec=$dur-$hour*3600-$min*60;
420   - my $fr=substr(sprintf("%5.2f",$sec-int($sec)),2,3);
421   - my $time=sprintf "%.2d:%.2d:%.2d%s",$hour,$min,int($sec),$fr;
422   -
423   - print "track $n: $t [$time]\n";
424   -
425   - my $sql = "INSERT INTO $db->{table_tracks} (cddbid, title, trackno, time)
426   - VALUES (\'$cddbid\',\'$t\', \'$n\', \'$time\')";
427   - my $sth = $dbh->prepare($sql);
428   - my $r = $sth->execute or die "failed to insert track $n: $DBI::errstr";
429   - $n++;
430   - }
431   -
432   - $dbh->disconnect();
433   -}
434   -
435   -sub print_lame {
436   - my $cd=shift;
437   -
438   - print_cd($cd);
439   - print "\n";
440   -
441   - my $n=1;
442   - for my $i ( @{$cd->{track}} ) {
443   - $i =~ s/"/'/g;
444   - print 'lame --tl "'.$cd->{title}.'" --ta "'.$cd->{artist}.'" --tt "'.$i.'" ';
445   - printf "audio_%02d.wav ",$n;
446   - $i =~ s/[^\S]|['"\/]/_/g;
447   - $i =~ s/_+-_+/-/g;
448   - print " $i.mp3\n";
449   - $n++;
450   - }
451   -}
1   -USAGE="usage: $0 [-d delimiter [-o {t|a}]] [-t {m|f|o}] [-p path] [-e encoder] [-c cddb-entry] [-h]\n"
2   -USAGE="${USAGE} -d :\tA single character delimiting trackname from\n"
3   -USAGE="${USAGE}\tartistname with sampler cds\n\n"
4   -USAGE="${USAGE} -o :\tspecifies if theres the track or the artist first\n"
5   -USAGE="${USAGE}\tMust be:\n"
6   -USAGE="${USAGE}\t t for titel first or\n"
7   -USAGE="${USAGE}\t a for artist first\n"
8   -USAGE="${USAGE}\tIf there is none specified t is assumed\n"
9   -USAGE="${USAGE} -t :\tyou can specify either m for encoding to mp3\n"
10   -USAGE="${USAGE}\tusing lame, or f for making lossless encoding using flac,\n"
11   -USAGE="${USAGE}\tor o for making ogg/vorbis, or w for uncompressed wav.\n"
12   -USAGE="${USAGE}\tOmitting this results in encoding to flac.\n"
13   -USAGE="${USAGE}\tmp3s will be placed under a subfolder mp3 and flacs\n"
14   -USAGE="${USAGE}\tunder a subfolder flac\n"
15   -USAGE="${USAGE} -p :\tspecifies the path to save the encoded data.\n"
16   -USAGE="${USAGE}\tDefaults to the users home directory.\n"
17   -USAGE="${USAGE} -e :\tspecifies the mp3 encoder to use.\n"
18   -USAGE="${USAGE}\tvalid encoders are actually: lame,bladeenc\n"
19   -USAGE="${USAGE}\tDefaults to lame.\n"
20   -USAGE="${USAGE} -c :\tspecifies the CDDB-Entry to use.\n"
21   -USAGE="${USAGE}\tsometimes there is more than 1 entry for a cd in cddb.\n"
22   -USAGE="${USAGE}\tThen you can specify wich one to use by this option.\n"
23   -USAGE="${USAGE}\tYou can checkout all entries using cddb.pl.\n"
24   -USAGE="${USAGE} -h :\tShows this help."
25   -
26   -HAS_DELIMITER=0
27   -TA_ORDER="t"
28   -ENCODING_DIR=$HOME
29   -ENCODING_TYPE="f"
30   -ENCODER="lame"
31   -CDDB_ENTRY=1
32   -
33   -while getopts d:o:t:p:he:c: option
  1 +#!/bin/bash
  2 +
  3 +# === some global setting & configurations for the script ===
  4 +umask 000 # create files with all right for anyone
  5 +shopt -s nullglob # expand patterns which match no file to a null string
  6 +shopt -s extdebug
  7 +
  8 +# --------------------------------------------------------------
  9 +# das Verzeichnis in dem dieses script liegt herausfinden
  10 +scriptDir=${0%/*}
  11 +scriptDir="${scriptDir/#\./${PWD}}"
  12 +case "${scriptDir}" in /*);; *) scriptDir="${PWD}/${scriptDir}";; esac
  13 +# --------------------------------------------------------------
  14 +
  15 +# include helpers
  16 +. ${scriptDir}/shellUtils.sh
  17 +
  18 +# --------------------------------------------------------------
  19 +# string definitions
  20 +usage=$"usage: $0 [-t {m|f|o}] [-p path] [-e encoder] [-c cddb-entry] [-h|-?]
  21 + [-I interface] [-D device] [-v[v]]
  22 +\t-t: you can specify either m for encoding to mp3
  23 +\t using lame, or f for making lossless encoding using flac,
  24 +\t or o for making ogg/vorbis, or w for uncompressed wav.
  25 +\t Omitting this results in encoding to flac.
  26 +\t mp3s will be placed under a subfolder mp3 and flacs
  27 +\t under a subfolder flac
  28 +\t-p: specifies the path to save the encoded data.
  29 +\t Defaults to the users home directory.
  30 +\t-e: specifies the mp3 encoder to use.
  31 +\t valid encoders are actually: lame,bladeenc
  32 +\t Defaults to lame.
  33 +\t-c: specifies the CDDB-Entry to use.
  34 +\t sometimes there is more than 1 entry for a cd in cddb.
  35 +\t Then you can specify wich one to use by this option.
  36 +\t You can checkout all entries using cddb.pl.
  37 +\t-I: specifies cdda2wav interface to use.
  38 +\t Valid interfaces are generic_scsi and cooked_ioctl.
  39 +\t Please note that cooked_ioctl is not available on all systems.
  40 +\t Defaults to generic_scsi
  41 +\t-D: specifies device to use with cdda2wav.
  42 +\t Defaults to /dev/cdrom
  43 +\t-v: make the script more verbose. The verbosity level defaults
  44 +\t to 1. When -v is given the level is 2 and -vv increases the
  45 +\t level to 3, what means give debug output.
  46 +\t-q: make the script silent. Equivalent to -v0
  47 +\t-h|
  48 +\t-?: Shows this help."
  49 +
  50 +ready=$"done"
  51 +
  52 +# level 1 messages
  53 +getCDInfoMsg=$"getting cd info..."
  54 +outputDirMsg=$"output to: \$encodingDir"
  55 +createXmlMsg=$"create xml file..."
  56 +startRipMsg1=$"start ripping cd audio data..."
  57 +
  58 +# level 2 messages
  59 +encodeMp3Msg=$"Encode to mp3"
  60 +encodeFlacMsg=$"Encode to flac"
  61 +encodeOggMsg=$"Encode to ogg"
  62 +encodeWavMsg=$"Encode to wav"
  63 +startRipMsg2=$"start ripping cd audio data:"
  64 +
  65 +cdInfoMsg=$"DISK:
  66 +=====
  67 +Tracks: \$dTracks
  68 +Length: \$dLength
  69 +Index: \$dIndex
  70 +Artist: \$dArtist
  71 +Title: \$dTitle
  72 +Year: \$dYear
  73 +Genre: \$dGenre
  74 +CDDB: \$cddbId
  75 +Text: \$dText
  76 +Extra: \$dExtra
  77 +
  78 +TRACKS:
  79 +======="
  80 +# --------------------------------------------------------------
  81 +
  82 +taOrder="t"
  83 +encodingDir=$HOME
  84 +encodingType="f"
  85 +encoder="lame"
  86 +cddbEntry=1
  87 +cddaIf="generic_scsi"
  88 +cddaDev="/dev/cdrom"
  89 +verbose=1
  90 +
  91 +# ----------------------------------------------------------------
  92 +# get commandline options
  93 +while getopts qvt:p:he:c:I:D: option
34 94 do
35   - case $option in
36   - d) if [ ${#OPTARG} -gt 1 ]
37   - then
38   - echo -e "$USAGE"
39   - exit 1
40   - fi
41   - HAS_DELIMITER=1
42   - TA_DELIMITER=$OPTARG
43   - ;;
44   - o) if [ \( "${OPTARG}" != "t" -a "${OPTARG}" != "a" \) -o \
45   - ${HAS_DELIMITER} -eq 0 ]
46   - then
47   - echo -e "$USAGE"
48   - exit 1
49   - fi
50   - TA_ORDER=$OPTARG
51   - ;;
52   - t) if [ ${OPTARG} != "m" -a ${OPTARG} != "f" -a ${OPTARG} != "o" -a \
53   - ${OPTARG} != "w" ]
54   - then
55   - echo -e "$USAGE"
56   - exit 1
57   - fi
58   - ENCODING_TYPE=$OPTARG
59   - ;;
60   - p) if [ ! \( -d ${OPTARG} \) ]
61   - then
62   - echo -e "$USAGE"
63   - exit 1
64   - fi
65   - ENCODING_DIR=$OPTARG
66   - ;;
67   - e) if [ -z ${OPTARG} ]
68   - then
69   - echo -e "$USAGE"
70   - exit 1
71   - fi
72   - ENCODER=$OPTARG
73   - ;;
74   - c) if [ ${OPTARG} -lt 1 ]
75   - then
76   - echo -e "$USAGE"
77   - exit 1
78   - fi
79   - CDDB_ENTRY=$OPTARG
80   - ;;
81   - [h\?]) echo -e "$USAGE"
82   - exit 1
83   - ;;
  95 + case $option in
  96 + t)
  97 + if [ "${OPTARG}" != "m" -a "${OPTARG}" != "f" -a \
  98 + "${OPTARG}" != "o" -a "${OPTARG}" != "w" ]
  99 + then
  100 + echo -e "$usage"
  101 + exit 1
  102 + fi
  103 + encodingType=$OPTARG
  104 + ;;
  105 + p)
  106 + if [ ! \( -d ${OPTARG} \) ]
  107 + then
  108 + echo -e "$usage"
  109 + exit 1
  110 + fi
  111 + encodingDir=$OPTARG
  112 + ;;
  113 + e)
  114 + if [ -z ${OPTARG} ]
  115 + then
  116 + echo -e "$usage"
  117 + exit 1
  118 + fi
  119 + encoder=$OPTARG
  120 + ;;
  121 + c)
  122 + if [ ${OPTARG} -lt 1 ]
  123 + then
  124 + echo -e "$usage"
  125 + exit 1
  126 + fi
  127 + cddbEntry=$OPTARG
  128 + ;;
  129 + v)
  130 + if [ "${OPTARG}" -a "${OPTARG}" != "0" -a "${OPTARG}" != "v" ]
  131 + then
  132 + echo -e "$usage"
  133 + exit 1
  134 + fi
  135 + test -z "${OPTARG}" && verbose=2
  136 + test "${OPTARG}" = "0" && verbose=0
  137 + test "${OPTARG}" = "v" && verbose=3
  138 + ;;
  139 + q)
  140 + verbose=0
  141 + ;;
  142 + I)
  143 + if [ "${OPTARG}" != "generic_scsi" -a \
  144 + "${OPTARG}" != "cooked_ioctl" ]
  145 + then
  146 + echo -e "$usage"
  147 + exit 1
  148 + fi
  149 + cddaIf=$OPTARG
  150 + ;;
  151 + D)
  152 + if [ ${OPTARG} -lt 1 ]
  153 + then
  154 + echo -e "$usage"
  155 + exit 1
  156 + fi
  157 + cddaDev=$OPTARG
  158 + ;;
  159 + [h\?])
  160 + echo -e "$usage"
  161 + exit 1
  162 + ;;
84 163 esac
85 164 done
  165 +# ----------------------------------------------------------------
86 166
87   -test "$ENCODING_TYPE" = "m" && ENCODING_DIR="$ENCODING_DIR/mp3"
88   -test "$ENCODING_TYPE" = "f" && ENCODING_DIR="$ENCODING_DIR/flac"
89   -test "$ENCODING_TYPE" = "o" && ENCODING_DIR="$ENCODING_DIR/ogg"
90   -test "$ENCODING_TYPE" = "w" && ENCODING_DIR="$ENCODING_DIR/wav"
91   -
92   -indices[0]="album"
93   -indices[1]="artist"
94   -indices[2]="genre"
95   -indices[3]="year"
96   -indices[4]="comment"
97   -
98   -i=1
99   -max_track=30
100   -
101   -while [ $i -le $max_track ]; do
102   - indices[`expr \( $i \- 1 \) \* 2 \+ 5`]="`echo $i | \
103   - sed 's/^\([0-9]\)$/0\1/g;\
104   - s/\(.*\)/track-\1/g'`"
105   - indices[`expr \( $i \- 1 \) \* 2 \+ 6`]="`echo $i | \
106   - sed 's/^\([0-9]\)$/0\1/g;\
107   - s/\(.*\)/tartist-\1/g'`"
108   - i=`expr $i \+ 1`
109   -done
  167 +echo "verbose: $verbose"
110 168
111   -comment=""
  169 +# ----------------------------------------------------------------
  170 +# set encodingDir for used encodingType
  171 +case ${encodingType} in
  172 + m)
  173 + encodingDir="$encodingDir/mp3"
  174 + test ${verbose} -ge 2 && echo ${encodeMp3Msg}
  175 + ;;
  176 + f)
  177 + encodingDir="$encodingDir/flac"
  178 + test ${verbose} -ge 2 && echo ${encodeFlacMsg}
  179 + ;;
  180 + o)
  181 + encodingDir="$encodingDir/ogg"
  182 + test ${verbose} -ge 2 && echo ${encodeOggMsg}
  183 + ;;
  184 + w)
  185 + encodingDir="$encodingDir/wav"
  186 + test ${verbose} -ge 2 && echo ${encodeWavMsg}
  187 + ;;
  188 +esac
  189 +# ----------------------------------------------------------------
112 190
113   -function idxof() {
114   - str=$1
115   - idx=0
  191 +test ${verbose} -ge 1 && echo -n ${getCDInfoMsg}
  192 +getCDInfo # gets all info about the CD. Look in shellUtils for more info.
  193 +test ${verbose} -ge 1 && echo ${ready}
116 194
117   - for i in "${indices[@]}"; do
118   - test "$i" == "$str" && echo $idx && return 0
119   - idx=`expr $idx \+ 1`
120   - done
  195 +if [ ${verbose} -ge 2 ]
  196 +then
  197 + cat <<-EOF
  198 + $cdInfoMsg
  199 + EOF
121 200
122   - echo -1
123   - return 0
124   -}
  201 + i=0
  202 + while [ $i -lt ${#tTitle[@]} ]
  203 + do
  204 + echo -n "${tArtist[$i]} - ${tTitle[$i]} "
  205 + echo "([${tStartSec[$i]}-${tEndSec[$i]}] ${tLength[$i]})"
  206 + i=$((i+1))
  207 + done
  208 +fi
125 209
126   -title_pat="/^[^:]*: *(.*[^ ]).*/"
127   -artist_pat="//"
  210 +encodingDir="${encodingDir}/${dArtist}/${dTitle}"
  211 +mkdir -p "${encodingDir}"
  212 +test ${verbose} -ge 1 && eval "echo ${outputDirMsg}"
128 213
129   -if [ $HAS_DELIMITER -ne 0 ]
130   -then
131   - if [ $TA_ORDER == "t" ]
132   - then
133   - title_pat="/^[^:]*: *([^\\${TA_DELIMITER}]*[^ \\${TA_DELIMITER}]).*/"
134   - artist_pat="/^[^:]*: *[^\\${TA_DELIMITER}]*\\${TA_DELIMITER} *(.*[^ ]).*/"
135   - else
136   - artist_pat="/^[^:]*: *([^\\${TA_DELIMITER}]*[^ \\${TA_DELIMITER}]).*/"
137   - title_pat="/^[^:]*: *[^\\${TA_DELIMITER}]*\\${TA_DELIMITER} *(.*[^ ]).*/"
138   - fi
139   -fi
  214 +# ----------------------------------------------------------------
  215 +# fill xml file with data
  216 +test ${verbose} -ge 1 && echo -n "${createXmlMsg}"
140 217
141   -echo "Preparing...."
142   -
143   -echo -n "getting cddb info..."
144   -eval "`cddb.pl -e $CDDB_ENTRY | sed 's/ \([0-9]\):/ 0\1:/g;s/track /track-/g' |\
145   - awk -v has_delimiter=$HAS_DELIMITER \
146   - '/artist/||/title/||/genre/||/year/ { \
147   - cddb[gensub(/^([^:]*):.*/, \"\\\\1\", \"1\")]=\
148   - gensub(/^[^:]*: *(.*[^ ]).*/, \"\\\\1\", \"g\")\
149   - } \
150   - /trackno/ {\
151   - trackno=int(gensub(/^trackno: *([0-9]*).*/, \"\\\\1\", \"1\"))\
152   - }\
153   - /track-/ {\
154   - cddb[gensub(/^([^:]*):.*/, \"\\\\1\", \"1\")]=\
155   - gensub('\"$title_pat\"', \"\\\\1\", \"1\");\
156   - if(has_delimiter==0) \
157   - cddb[gensub(/^track([^:]*):.*/, \"tarti\\\\1\", \"1\")]=\
158   - cddb[\"artist\"]; \
159   - else \
160   - cddb[gensub(/^track([^:]*):.*/, \"tarti\\\\1\", \"1\")]=\
161   - gensub('\"$artist_pat\"', \"\\\\1\", \"1\");\
162   - } \
163   - END {\
164   - cddb_str=\"cddb=(\\\"\" cddb[\"title\"] \"\\\" \\\"\" \
165   - cddb[\"artist\"] \"\\\" \\\"\" \
166   - cddb[\"genre\"] \"\\\" \\\"\" \
167   - cddb[\"year\"] \"\\\" \\\"'$comment'\\\"\"; \
168   - for(i=1; i<=trackno; i++) {\
169   - cddb_str=cddb_str \" \\\"\" \
170   - cddb[\"track-\" sprintf(\"%02s\", i)] \"\\\"\";\
171   - cddb_str=cddb_str \" \\\"\" \
172   - cddb[\"tarti-\" sprintf(\"%02s\", i)] \"\\\"\"\
173   - }\
174   - print cddb_str \")\"\
175   - }'`"
176   -echo "done"
177   -
178   -echo -n "getting CD info..."
179   -cddainfo=`cdda2wav -H -D/dev/cdrom -J -v summary,toc,sectors 2>&1`
180   -echo "done"
181   -
182   -track_num=`echo "$cddainfo" | \
183   - sed '/tracks/{s/^.*tracks:\([0-9]*\).*$/\1/g;p};d'`
184   -cd_time=`echo "$cddainfo" | \
185   - sed '/tracks/{s/^.*time \([0-9:\.]*\).*$/\1/g;p};d'`
186   -cddbid=`echo "$cddainfo" | \
187   - sed '/CDDB/{s/^.*discid: *\(0x[a-z0-9]*[^ ]\).*/\1/g;p};d'`
188   -cdindex=`echo "$cddainfo" | \
189   - sed '/CDINDEX/{s/^.*discid: *\([a-zA-Z0-9_\.]*-\).*/\1/g;p};d'`
190   -cdtext=`echo "$cddainfo" | sed '/CD-Text/{s/^[^:]*: *\(.*[^ ]\).*/\1/g
191   - s/&/\&amp\;/g;s/\"/\&quot\;/g
192   - s/</\&lt\;/g;s/>/\&gt\;/g
193   - s/\o47/\&apos\;/g
194   - p};d'`
195   -cdextra=`echo "$cddainfo" | sed '/CD-Extra/{s/^[^:]*: *\(.*[^ ]\).*/\1/g
196   - s/&/\&amp\;/g;s/\"/\&quot\;/g
197   - s/</\&lt\;/g;s/>/\&gt\;/g
198   - s/\o47/\&apos\;/g
199   - p};d'`
200   -
201   -ENCODING_DIR="${ENCODING_DIR}/${cddb[`idxof "artist"`]}/"
202   -ENCODING_DIR="${ENCODING_DIR}${cddb[`idxof "album"`]}/"
203   -mkdirhier "$ENCODING_DIR"
204   -echo "Output directory is: $ENCODING_DIR"
205   -
206   -xmlfile="${ENCODING_DIR}cdinfo.xml"
207   -
208   -# some special chars within xml must be converted to special syntax
209   -# & => &amp;
210   -# " => &quot;
211   -# ' => &apos;
212   -# < => &lt;
213   -# > => &gt;
214   -xmlartist=`echo ${cddb[\`idxof "artist"\`]} | \
215   - sed 's/&/\&amp\;/g
216   - s/</\&lt\;/g
217   - s/>/\&gt\;/g
218   - s/\"/\&quot\;/g
219   - s/\o47/\&apos\;/g'`
220   -xmlalbum=`echo ${cddb[\`idxof "album"\`]} | \
221   - sed 's/&/\&amp\;/g
222   - s/</\&lt\;/g
223   - s/>/\&gt\;/g
224   - s/\"/\&quot\;/g
225   - s/\o47/\&apos\;/g'`
226   -
227   -echo "<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>" > "${xmlfile}"
228   -echo "<!DOCTYPE cdInfo SYSTEM \"cdInfo.dtd\">" >> "${xmlfile}"
229   -echo "<cdinfo>" >> "${xmlfile}"
230   -echo " <cdindex>$cdindex</cdindex>" >> "${xmlfile}"
231   -echo " <cddb>$cddbid</cddb>" >> "${xmlfile}"
232   -echo " <cd-text>$cdtext</cd-text>" >> "${xmlfile}"
233   -echo " <cd-extra>$cdextra</cd-extra>" >> "${xmlfile}"
234   -echo " <cd-artist>${xmlartist}</cd-artist>" >> "${xmlfile}"
235   -echo " <cd-title>${xmlalbum}</cd-title>" >> "${xmlfile}"
236   -echo " <cd-year>${cddb[`idxof "year"`]}</cd-year>" >> "${xmlfile}"
237   -echo " <cd-genre>${cddb[`idxof "genre"`]}</cd-genre>" >> "${xmlfile}"
238   -echo " <cd-time>$cd_time</cd-time>" >> "${xmlfile}"
239   -echo " <cd-tracks>$track_num</cd-tracks>" >> "${xmlfile}"
240   -echo " <cd-comment></cd-comment>" >> "${xmlfile}"
241   -
242   -i=1; while [ $i -le $track_num ]
  218 +xmlFile="${encodingDir}/cdinfo.xml"
  219 +xml_dText="`echo "${dText}" | recode utf8..h0`"
  220 +xml_dExtra="`echo "${dExtra}" | recode utf8..h0`"
  221 +xml_dArtist="`echo "${dArtist}" | recode utf8..h0`"
  222 +xml_dTitle="`echo "${dTitle}" | recode utf8..h0`"
  223 +cat >"${xmlFile}" <<EOF
  224 +<?xml version="1.0" encoding="UTF-8"?>
  225 +<!DOCTYPE cdInfo SYSTEM \"cdInfo.dtd\">
  226 +<cdinfo>
  227 + <cdindex>${dIndex}</cdindex>
  228 + <cddb>${cddbId}</cddb>
  229 + <cd-text>${xml_dText}</cd-text>
  230 + <cd-extra>${xml_dExtra}</cd-extra>
  231 + <cd-artist>${xml_dArtist}</cd-artist>
  232 + <cd-title>${xml_dTitle}</cd-title>
  233 + <cd-year>${dYear}</cd-year>
  234 + <cd-genre>${dGenre}</cd-genre>
  235 + <cd-time>${dLength}</cd-time>
  236 + <cd-tracks>${dTracks}</cd-tracks>
  237 + <cd-comment></cd-comment>
  238 +EOF
  239 +
  240 +i=0
  241 +while [ $i -lt ${#tTitle[@]} ]
  242 +do
  243 + trackNr="`printf %02d $((i+1))`"
  244 + xml_tTitle="`echo ${tTitle[$i]} | recode utf8..h0`"
  245 + xml_tArtist="`echo ${tArtist[$i]} | recode utf8..h0`"
  246 + trackEnd=${tEndSec[$i]}
  247 + trackStart=${tStartSec[$i]}
  248 + trackLen=$((trackEnd-$trackStart))
  249 +
  250 + cat >>"${xmlFile}" <<EOF
  251 + <track>
  252 + <track-number>$trackNr</track-number>
  253 + <track-time>${tLength[$i]}</track-time>
  254 + <track-start-sector>${tStartSec[$i]}</track-start-sector>
  255 + <track-length>${trackLen}</track-length>
  256 + <track-artist>$xml_tArtist</track-artist>
  257 + <track-title>$xml_tTitle</track-title>
  258 + <track-comment></track-comment>
  259 + </track>
  260 +EOF
  261 +
  262 + i=$((i+1))
  263 +done
  264 +
  265 +echo "</cdinfo>" >>"${xmlFile}"
  266 +
  267 +test ${verbose} -ge 1 && echo "${ready}"
  268 +# ----------------------------------------------------------------
  269 +
  270 +# ----------------------------------------------------------------
  271 +# now do the ripping
  272 +test ${verbose} -eq 1 && echo -n "${startRipMsg1}"
  273 +test ${verbose} -ge 2 && echo "${startRipMsg2}"
  274 +
  275 +i=0
  276 +while [ $i -lt ${#tTitle[@]} ]
243 277 do
244   - j=`expr $i \+ 1`
245   - tracknr=`awk 'BEGIN{printf("%02d\n",'$i')}'`
246   - track=${cddb[`idxof "track-$tracknr"`]}
247   - tartist=${cddb[`idxof "tartist-$tracknr"`]}
248   -
249   - xmltrack=`echo ${track} | sed 's/&/\&amp\;/g
250   - s/</\&lt\;/g
251   - s/>/\&gt\;/g
252   - s/\"/\&quot\;/g
253   - s/\o47/\&apos\;/g'`
254   - xmltartist=`echo ${tartist} | sed 's/&/\&amp\;/g
255   - s/</\&lt\;/g
256   - s/>/\&gt\;/g
257   - s/\"/\&quot\;/g
258   - s/\o47/\&apos\;/g'`
259   -
260   - tracklen=`echo "$cddainfo" | \
261   - sed '/ '"$i"'\.([0-9 ]*:/{s/.*'"$i"'\.( *\([0-9:\.]*\)).*/\1/g;p};d'`
262   - trackstart=`echo "$cddainfo" | \
263   - sed '/ '"$i"'\.([0-9 ]*)/{s/.*'"$i"'\.( *\([0-9]*\)).*/\1/g;p};d'`
264   - test $i -eq $track_num && \
265   - trackend=`echo "$cddainfo" | \
266   - sed '/ lead-out([0-9 ]*)/{s/.*lead-out( *\([0-9]*\)).*/\1/g;p};d'` || \
267   - trackend=`echo "$cddainfo" | \
268   - sed '/ '"$j"'\.([0-9 ]*)/{s/.*'"$j"'\.( *\([0-9]*\)).*/\1/g;p};d'`
269   -
270   - echo " <track>" >> "${xmlfile}"
271   - echo " <track-number>$i</track-number>" >> "${xmlfile}"
272   - echo " <track-time>$tracklen</track-time>" >> "${xmlfile}"
273   - echo " <track-start-sector>$trackstart</track-start-sector>" >> "${xmlfile}"
274   - echo " <track-length>`expr $trackend \- $trackstart`</track-length>" >> "${xmlfile}"
275   - echo " <track-artist>$xmltartist</track-artist>" >> "${xmlfile}"
276   - echo " <track-title>$xmltrack</track-title>" >> "${xmlfile}"
277   - echo " <track-comment></track-comment>" >> "${xmlfile}"
278   - echo " </track>" >> "${xmlfile}"
279   -
280   - # outfile="${ENCODING_DIR}The Wall/Disk2/"
281   - outfile="${ENCODING_DIR}${tracknr}-${track}"
282   -
283   - test "$ENCODING_TYPE" = "f" && \
284   - outstr="track-$tracknr => ${tracknr}-${track}.flac"
285   - test "$ENCODING_TYPE" = "m" && \
286   - outstr="track-$tracknr => ${tracknr}-${track}.mp3"
287   - test "$ENCODING_TYPE" = "o" && \
288   - outstr="track-$tracknr => ${tracknr}-${track}.ogg"
289   - test "$ENCODING_TYPE" = "w" && \
290   - outstr="track-$tracknr => ${tracknr}-${track}.wav"
291   -
292   - if [ "$ENCODING_TYPE" = "f" ]
293   - then
294   - bash -c "exec 2>&1;\
295   - cdda2wav -H -D/dev/cdrom -H -t$i - | \
296   - flac -c \
297   - -T artist=\"${tartist}\" -T album=\"${cddb[`idxof "album"`]}\" \
298   - -T genre=\"${cddb[`idxof "genre"`]}\" -T title=\"${track}\" \
299   - -T tnum=\"`expr ${tracknr} \+ 0`\" -T date=\"${cddb[`idxof "year"`]}\" \
300   - -T comment=\"${cddb[`idxof "comment"`]}\" \
301   - -o \"${outfile}.flac\" - 2>/dev/null" | rton | \
302   - awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}'
303   - fi
304   - if [ "$ENCODING_TYPE" = "m" -a "$ENCODER" = "lame" ]
305   - then
306   - bash -c "exec 2>&1;\
307   - cdda2wav -H -D/dev/cdrom -t$i - | \
308   - lame -h \
309   - --ta \"${tartist}\" --tl \"${cddb[`idxof "album"`]}\" \
310   - --tg \"${cddb[`idxof "genre"`]}\" --tt \"${track}\" \
311   - --tn \"`expr ${tracknr} \+ 0`\" --ty \"${cddb[`idxof "year"`]}\" \
312   - --tc \"${cddb[`idxof "comment"`]}\" \
313   - - \"${outfile}.mp3\" 2>/dev/null" | rton | \
314   - awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}'
315   - fi
316   - if [ "$ENCODING_TYPE" = "m" -a "$ENCODER" = "bladeenc" ]
317   - then
318   - bash -c "exec 2>&1;\
319   - cdda2wav -H -D/dev/cdrom -t$i - | \
320   - bladeenc -progress=0 STDIN \"${outfile}.mp3\" 2>/dev/null" | rton | \
321   - awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}'
322   - fi
323   - if [ "$ENCODING_TYPE" = "o" ]
324   - then
325   - bash -c "exec 2>&1;\
326   - cdda2wav -H -D/dev/cdrom -t$i - | \
327   - oggenc -a \"${tartist}\" -l \"${cddb[`idxof "album"`]}\" \
328   - -G \"${cddb[`idxof "genre"`]}\" -t \"${track}\" \
329   - -N \"`expr ${tracknr} \+ 0`\" -d \"${cddb[`idxof "year"`]}\" \
330   - -c \"${cddb[`idxof "comment"`]}\" \
331   - -o \"${outfile}.ogg\" - 2>/dev/null" | rton | \
332   - awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}'
333   - fi
334   - if [ "$ENCODING_TYPE" = "w" ]
335   - then
336   - bash -c "exec 2>&1;\
337   - cdda2wav -H -D/dev/cdrom -t$i - > \"${outfile}.wav\"" | rton | \
338   - awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}'
339   - fi
340   -
341   - i=`expr $i + 1`
  278 + trackNr=$((i+1))
  279 +
  280 + # now that i don't forget it again. I use tr to translate \r to \n
  281 + # because sed does't recognise a line with only \r at its end as a line.
  282 + # Therefor sed reads until output of cdda2wav ends and does all the
  283 + # processing at once, so the percentage is not shown correctly
  284 + if [ ${verbose} -ge 2 ]
  285 + then
  286 + outCmd="tr '\r' '\n' |
  287 + sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'\"\${outStr}\"'\1/' |
  288 + tr -d '\n'"
  289 + else
  290 + outCmd="cat >/dev/null"
  291 + fi
  292 +
  293 + case ${encodingType} in
  294 + f)
  295 + outFile="`printf %02d ${trackNr}`-${tTitle[$i]}.flac"
  296 + outStr="track-$trackNr => ${outFile}: "
  297 +
  298 + (
  299 + exec 2>&1
  300 + cdda2wav -H -D/dev/cdrom -I${cddaIf} -t${trackNr} - |\
  301 + flac -c -f \
  302 + -T artist="${tArtist[$i]}" -T album="${dTitle}" \
  303 + -T genre="${dGenre}" -T title="${tTitle[$i]}" \
  304 + -T tracknumber="${trackNr}" -T tracknum="${trackNr}" \
  305 + -T date="${dYear}" -T comment="" \
  306 + -o "${encodingDir}/${outFile}" - 2>/dev/null
  307 + ) | $outCmd
  308 + ;;
  309 + m)
  310 + outFile="`printf %02d ${trackNr}`-${tTitle[$i]}.mp3"
  311 + outStr="track-$trackNr => ${outFile}: "
  312 +
  313 + case ${encoder} in
  314 + lame)
  315 + (
  316 + exec 2>&1
  317 + cdda2wav -H -D/dev/cdrom -I${cddaIf} -t${trackNr} - |\
  318 + lame -V2 \
  319 + --ta "${tArtist[$i]}" --tl "${dTitle}" \
  320 + --tg "${dGenre}" --tt "${tTitle[$i]}" \
  321 + --tn "${trackNr}" --ty "${dYear}" \
  322 + --tc "" \
  323 + - "${encodingDir}/${outFile}" 2>/dev/null
  324 + ) | tr '\r' '\n' |\
  325 + sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\
  326 + tr -d '\n'
  327 + ;;
  328 + bladeenc)
  329 + (
  330 + exec 2>&1
  331 + cdda2wav -H -D/dev/cdrom -I${cddaIf} -t${trackNr} - |\
  332 + bladeenc -progress=0 STDIN \
  333 + "${encodingDir}/${outFile}" 2>/dev/null
  334 + ) | tr '\r' '\n' |\
  335 + sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\
  336 + tr -d '\n'
  337 + ;;
  338 + esac
  339 + ;;
  340 + o)
  341 + outFile="`printf %02d ${trackNr}`-${tTitle[$i]}.ogg"
  342 + outStr="track-$trackNr => ${outFile}: "
  343 +
  344 + (
  345 + exec 2>&1
  346 + cdda2wav -H -D/dev/cdrom -I${cddaIf} -t${trackNr} - |\
  347 + oggenc -a "${tArtist[$i]}" -l "${dTitle}" \
  348 + -G "${dGenre}" -t "${tTitle[$i]}" \
  349 + -N "${trackNr}" -d "${dYear}" \
  350 + -c "" \
  351 + -o "${encodingDir}/${outFile}" - 2>/dev/null
  352 + ) | tr '\r' '\n' |\
  353 + sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\
  354 + tr -d '\n'
  355 + ;;
  356 + w)
  357 + outFile="`printf %02d ${trackNr}`-${tTitle[$i]}.wav"
  358 + outStr="track-$trackNr => ${outFile}: "
  359 +
  360 + (
  361 + exec 2>&1
  362 + cdda2wav -H -D/dev/cdrom -I${cddaIf} -t${trackNr} - >\
  363 + "${encodingDir}/${outFile}"
  364 + ) | tr '\r' '\n' |\
  365 + sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\
  366 + tr -d '\n'
  367 + ;;
  368 + esac
  369 +
  370 + echo # do a newline after each file
  371 + i=$((i+1))
342 372 done
343 373
344   -echo "</cdinfo>" >> "${xmlfile}"
  374 +test ${verbose} -eq 1 && echo "${ready}"
  375 +# ----------------------------------------------------------------
... ...
1   -USAGE="usage: $0 [-d delimiter [-o {t|a}]] [-t {m|f|o}] [-p path] [-e encoder] [-c cddb-entry] [-h]\n"
2   -USAGE="${USAGE} -d :\tA single character delimiting trackname from\n"
3   -USAGE="${USAGE}\tartistname with sampler cds\n\n"
4   -USAGE="${USAGE} -o :\tspecifies if theres the track or the artist first\n"
5   -USAGE="${USAGE}\tMust be:\n"
6   -USAGE="${USAGE}\t t for titel first or\n"
7   -USAGE="${USAGE}\t a for artist first\n"
8   -USAGE="${USAGE}\tIf there is none specified t is assumed\n"
9   -USAGE="${USAGE} -t :\tyou can specify either m for encoding to mp3\n"
10   -USAGE="${USAGE}\tusing lame, or f for making lossless encoding using flac,\n"
11   -USAGE="${USAGE}\tor o for making ogg/vorbis, or w for uncompressed wav.\n"
12   -USAGE="${USAGE}\tOmitting this results in encoding to flac.\n"
13   -USAGE="${USAGE}\tmp3s will be placed under a subfolder mp3 and flacs\n"
14   -USAGE="${USAGE}\tunder a subfolder flac\n"
15   -USAGE="${USAGE} -p :\tspecifies the path to save the encoded data.\n"
16   -USAGE="${USAGE}\tDefaults to the users home directory.\n"
17   -USAGE="${USAGE} -e :\tspecifies the mp3 encoder to use.\n"
18   -USAGE="${USAGE}\tvalid encoders are actually: lame,bladeenc\n"
19   -USAGE="${USAGE}\tDefaults to lame.\n"
20   -USAGE="${USAGE} -c :\tspecifies the CDDB-Entry to use.\n"
21   -USAGE="${USAGE}\tsometimes there is more than 1 entry for a cd in cddb.\n"
22   -USAGE="${USAGE}\tThen you can specify wich one to use by this option.\n"
23   -USAGE="${USAGE}\tYou can checkout all entries using cddb.pl.\n"
24   -USAGE="${USAGE} -h :\tShows this help."
25   -
26   -PATH="$PATH:."
27   -
28   -HAS_DELIMITER=0
29   -TA_ORDER="t"
30   -ENCODING_DIR=$HOME
31   -ENCODING_TYPE="f"
32   -ENCODER="lame"
33   -CDDB_ENTRY=1
34   -
35   -while getopts d:o:t:p:he:c: option
36   -do
37   - case $option in
38   - d) if [ ${#OPTARG} -gt 1 ]
39   - then
40   - echo -e "$USAGE"
41   - exit 1
42   - fi
43   - HAS_DELIMITER=1
44   - TA_DELIMITER=$OPTARG
45   - ;;
46   - o) if [ \( "${OPTARG}" != "t" -a "${OPTARG}" != "a" \) -o \
47   - ${HAS_DELIMITER} -eq 0 ]
48   - then
49   - echo -e "$USAGE"
50   - exit 1
51   - fi
52   - TA_ORDER=$OPTARG
53   - ;;
54   - t) if [ ${OPTARG} != "m" -a ${OPTARG} != "f" -a ${OPTARG} != "o" -a \
55   - ${OPTARG} != "w" ]
56   - then
57   - echo -e "$USAGE"
58   - exit 1
59   - fi
60   - ENCODING_TYPE=$OPTARG
61   - ;;
62   - p) if [ ! \( -d ${OPTARG} \) ]
63   - then
64   - echo -e "$USAGE"
65   - exit 1
66   - fi
67   - ENCODING_DIR=$OPTARG
68   - ;;
69   - e) if [ -z ${OPTARG} ]
70   - then
71   - echo -e "$USAGE"
72   - exit 1
73   - fi
74   - ENCODER=$OPTARG
75   - ;;
76   - c) if [ ${OPTARG} -lt 1 ]
77   - then
78   - echo -e "$USAGE"
79   - exit 1
80   - fi
81   - CDDB_ENTRY=$OPTARG
82   - ;;
83   - [h\?]) echo -e "$USAGE"
84   - exit 1
85   - ;;
86   - esac
87   -done
88   -
89   -test "$ENCODING_TYPE" = "m" && ENCODING_DIR="$ENCODING_DIR/mp3"
90   -test "$ENCODING_TYPE" = "f" && ENCODING_DIR="$ENCODING_DIR/flac"
91   -test "$ENCODING_TYPE" = "o" && ENCODING_DIR="$ENCODING_DIR/ogg"
92   -test "$ENCODING_TYPE" = "w" && ENCODING_DIR="$ENCODING_DIR/wav"
93   -
94   -indices[0]="album"
95   -indices[1]="artist"
96   -indices[2]="genre"
97   -indices[3]="year"
98   -indices[4]="comment"
99   -
100   -i=1
101   -max_track=30
102   -
103   -while [ $i -le $max_track ]; do
104   - indices[`expr \( $i \- 1 \) \* 2 \+ 5`]="`echo $i | \
105   - sed 's/^\([0-9]\)$/0\1/g;\
106   - s/\(.*\)/track-\1/g'`"
107   - indices[`expr \( $i \- 1 \) \* 2 \+ 6`]="`echo $i | \
108   - sed 's/^\([0-9]\)$/0\1/g;\
109   - s/\(.*\)/tartist-\1/g'`"
110   - i=`expr $i \+ 1`
111   -done
112   -
113   -comment=""
114   -
115   -function idxof() {
116   - str=$1
117   - idx=0
118   -
119   - for i in "${indices[@]}"; do
120   - test "$i" == "$str" && echo $idx && return 0
121   - idx=`expr $idx \+ 1`
122   - done
123   -
124   - echo -1
125   - return 0
126   -}
127   -
128   -title_pat="/^[^:]*: *(.*[^ ]).*/"
129   -artist_pat="//"
130   -
131   -if [ $HAS_DELIMITER -ne 0 ]
132   -then
133   - if [ $TA_ORDER == "t" ]
134   - then
135   - title_pat="/^[^:]*: *([^\\${TA_DELIMITER}]*[^ \\${TA_DELIMITER}]).*/"
136   - artist_pat="/^[^:]*: *[^\\${TA_DELIMITER}]*\\${TA_DELIMITER} *(.*[^ ]).*/"
137   - else
138   - artist_pat="/^[^:]*: *([^\\${TA_DELIMITER}]*[^ \\${TA_DELIMITER}]).*/"
139   - title_pat="/^[^:]*: *[^\\${TA_DELIMITER}]*\\${TA_DELIMITER} *(.*[^ ]).*/"
140   - fi
141   -fi
142   -
143   -echo "Preparing...."
144   -
145   -echo -n "getting cddb info..."
146   -eval "`cddb.pl -c /dev/cdrom1 -e $CDDB_ENTRY | sed 's/ \([0-9]\):/ 0\1:/g;s/track /track-/g' |\
147   - awk -v has_delimiter=$HAS_DELIMITER \
148   - '/artist/||/title/||/genre/||/year/ { \
149   - cddb[gensub(/^([^:]*):.*/, \"\\\\1\", \"1\")]=\
150   - gensub(/^[^:]*: *(.*[^ ]).*/, \"\\\\1\", \"g\")\
151   - } \
152   - /trackno/ {\
153   - trackno=int(gensub(/^trackno: *([0-9]*).*/, \"\\\\1\", \"1\"))\
154   - }\
155   - /track-/ {\
156   - cddb[gensub(/^([^:]*):.*/, \"\\\\1\", \"1\")]=\
157   - gensub('\"$title_pat\"', \"\\\\1\", \"1\");\
158   - if(has_delimiter==0) \
159   - cddb[gensub(/^track([^:]*):.*/, \"tarti\\\\1\", \"1\")]=\
160   - cddb[\"artist\"]; \
161   - else \
162   - cddb[gensub(/^track([^:]*):.*/, \"tarti\\\\1\", \"1\")]=\
163   - gensub('\"$artist_pat\"', \"\\\\1\", \"1\");\
164   - } \
165   - END {\
166   - cddb_str=\"cddb=(\\\"\" cddb[\"title\"] \"\\\" \\\"\" \
167   - cddb[\"artist\"] \"\\\" \\\"\" \
168   - cddb[\"genre\"] \"\\\" \\\"\" \
169   - cddb[\"year\"] \"\\\" \\\"'$comment'\\\"\"; \
170   - for(i=1; i<=trackno; i++) {\
171   - cddb_str=cddb_str \" \\\"\" \
172   - cddb[\"track-\" sprintf(\"%02s\", i)] \"\\\"\";\
173   - cddb_str=cddb_str \" \\\"\" \
174   - cddb[\"tarti-\" sprintf(\"%02s\", i)] \"\\\"\"\
175   - }\
176   - print cddb_str \")\"\
177   - }'`"
178   -echo "done"
179   -
180   -echo -n "getting CD info..."
181   -cddainfo=`cdda2wav -H -D/dev/cdrom1 -J -v summary,toc,sectors 2>&1`
182   -echo "done"
183   -
184   -track_num=`echo "$cddainfo" | \
185   - sed '/tracks/{s/^.*tracks:\([0-9]*\).*$/\1/g;p};d'`
186   -cd_time=`echo "$cddainfo" | \
187   - sed '/tracks/{s/^.*time \([0-9:\.]*\).*$/\1/g;p};d'`
188   -cddbid=`echo "$cddainfo" | \
189   - sed '/CDDB/{s/^.*discid: *\(0x[a-z0-9]*[^ ]\).*/\1/g;p};d'`
190   -cdindex=`echo "$cddainfo" | \
191   - sed '/CDINDEX/{s/^.*discid: *\([a-zA-Z0-9_\.]*-\).*/\1/g;p};d'`
192   -cdtext=`echo "$cddainfo" | sed '/CD-Text/{s/^[^:]*: *\(.*[^ ]\).*/\1/g
193   - s/&/\&amp\;/g;s/\"/\&quot\;/g
194   - s/</\&lt\;/g;s/>/\&gt\;/g
195   - s/\o47/\&apos\;/g
196   - p};d'`
197   -cdextra=`echo "$cddainfo" | sed '/CD-Extra/{s/^[^:]*: *\(.*[^ ]\).*/\1/g
198   - s/&/\&amp\;/g;s/\"/\&quot\;/g
199   - s/</\&lt\;/g;s/>/\&gt\;/g
200   - s/\o47/\&apos\;/g
201   - p};d'`
202   -
203   -# cddb[`idxof "artist"`]="Blue Öyster Cult"
204   -ENCODING_DIR="${ENCODING_DIR}/${cddb[`idxof "artist"`]}/"
205   -ENCODING_DIR="${ENCODING_DIR}${cddb[`idxof "album"`]}/"
206   -mkdirhier "$ENCODING_DIR"
207   -echo "Output directory is: $ENCODING_DIR"
208   -
209   -xmlfile="${ENCODING_DIR}cdinfo.xml"
210   -
211   -# some special chars within xml must be converted to special syntax
212   -# & => &amp;
213   -# " => &quot;
214   -# ' => &apos;
215   -# < => &lt;
216   -# > => &gt;
217   -xmlartist=`echo ${cddb[\`idxof "artist"\`]} | \
218   - sed 's/&/\&amp\;/g
219   - s/</\&lt\;/g
220   - s/>/\&gt\;/g
221   - s/\"/\&quot\;/g
222   - s/\o47/\&apos\;/g'`
223   -xmlalbum=`echo ${cddb[\`idxof "album"\`]} | \
224   - sed 's/&/\&amp\;/g
225   - s/</\&lt\;/g
226   - s/>/\&gt\;/g
227   - s/\"/\&quot\;/g
228   - s/\o47/\&apos\;/g'`
229   -
230   -echo "<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>" > "${xmlfile}"
231   -echo "<!DOCTYPE cdInfo SYSTEM \"cdInfo.dtd\">" >> "${xmlfile}"
232   -echo "<cdinfo>" >> "${xmlfile}"
233   -echo " <cdindex>$cdindex</cdindex>" >> "${xmlfile}"
234   -echo " <cddb>$cddbid</cddb>" >> "${xmlfile}"
235   -echo " <cd-text>$cdtext</cd-text>" >> "${xmlfile}"
236   -echo " <cd-extra>$cdextra</cd-extra>" >> "${xmlfile}"
237   -echo " <cd-artist>${xmlartist}</cd-artist>" >> "${xmlfile}"
238   -echo " <cd-title>${xmlalbum}</cd-title>" >> "${xmlfile}"
239   -echo " <cd-year>${cddb[`idxof "year"`]}</cd-year>" >> "${xmlfile}"
240   -echo " <cd-genre>${cddb[`idxof "genre"`]}</cd-genre>" >> "${xmlfile}"
241   -echo " <cd-time>$cd_time</cd-time>" >> "${xmlfile}"
242   -echo " <cd-tracks>$track_num</cd-tracks>" >> "${xmlfile}"
243   -echo " <cd-comment></cd-comment>" >> "${xmlfile}"
244   -
245   -i=1; while [ $i -le $track_num ]
246   -do
247   - j=`expr $i \+ 1`
248   - tracknr=`awk 'BEGIN{printf("%02d\n",'$i')}'`
249   - track=${cddb[`idxof "track-$tracknr"`]}
250   - tartist=${cddb[`idxof "tartist-$tracknr"`]}
251   -
252   - xmltrack=`echo ${track} | sed 's/&/\&amp\;/g
253   - s/</\&lt\;/g
254   - s/>/\&gt\;/g
255   - s/\"/\&quot\;/g
256   - s/\o47/\&apos\;/g'`
257   - xmltartist=`echo ${tartist} | sed 's/&/\&amp\;/g
258   - s/</\&lt\;/g
259   - s/>/\&gt\;/g
260   - s/\"/\&quot\;/g
261   - s/\o47/\&apos\;/g'`
262   -
263   - tracklen=`echo "$cddainfo" | \
264   - sed '/ '"$i"'\.([0-9 ]*:/{s/.*'"$i"'\.( *\([0-9:\.]*\)).*/\1/g;p};d'`
265   - trackstart=`echo "$cddainfo" | \
266   - sed '/ '"$i"'\.([0-9 ]*)/{s/.*'"$i"'\.( *\([0-9]*\)).*/\1/g;p};d'`
267   - test $i -eq $track_num && \
268   - trackend=`echo "$cddainfo" | \
269   - sed '/ lead-out([0-9 ]*)/{s/.*lead-out( *\([0-9]*\)).*/\1/g;p};d'` || \
270   - trackend=`echo "$cddainfo" | \
271   - sed '/ '"$j"'\.([0-9 ]*)/{s/.*'"$j"'\.( *\([0-9]*\)).*/\1/g;p};d'`
272   -
273   - test -z "$trackstart" -o -z "$trackend" && echo "Disk Error" && exit 1
274   -
275   - echo " <track>" >> "${xmlfile}"
276   - echo " <track-number>$i</track-number>" >> "${xmlfile}"
277   - echo " <track-time>$tracklen</track-time>" >> "${xmlfile}"
278   - echo " <track-start-sector>$trackstart</track-start-sector>" >> "${xmlfile}"
279   - echo " <track-length>`expr $trackend \- $trackstart`</track-length>" >> "${xmlfile}"
280   - echo " <track-artist>$xmltartist</track-artist>" >> "${xmlfile}"
281   - echo " <track-title>$xmltrack</track-title>" >> "${xmlfile}"
282   - echo " <track-comment></track-comment>" >> "${xmlfile}"
283   - echo " </track>" >> "${xmlfile}"
284   -
285   - # outfile="${ENCODING_DIR}The Wall/Disk2/"
286   - outfile="${ENCODING_DIR}${tracknr}-${track}"
287   -
288   - test "$ENCODING_TYPE" = "f" && \
289   - outstr="track-$tracknr => ${tracknr}-${track}.flac"
290   - test "$ENCODING_TYPE" = "m" && \
291   - outstr="track-$tracknr => ${tracknr}-${track}.mp3"
292   - test "$ENCODING_TYPE" = "o" && \
293   - outstr="track-$tracknr => ${tracknr}-${track}.ogg"
294   - test "$ENCODING_TYPE" = "w" && \
295   - outstr="track-$tracknr => ${tracknr}-${track}.wav"
296   -
297   - if [ "$ENCODING_TYPE" = "f" ]
298   - then
299   - bash -c "exec 2>&1;\
300   - cdda2wav -H -D0,4,0 -t$i - | \
301   - flac -c \
302   - -T artist=\"${tartist}\" -T album=\"${cddb[`idxof "album"`]}\" \
303   - -T genre=\"${cddb[`idxof "genre"`]}\" -T title=\"${track}\" \
304   - -T tracknumber=\"`expr ${tracknr} \+ 0`\" \
305   - -T tracknum=\"`expr ${tracknr} \+ 0`\" -T date=\"${cddb[`idxof "year"`]}\" \
306   - -T comment=\"${cddb[`idxof "comment"`]}\" \
307   - -o \"${outfile}.flac\" - 2>/dev/null" | rton | \
308   - awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}'
309   - fi
310   - if [ "$ENCODING_TYPE" = "m" -a "$ENCODER" = "lame" ]
311   - then
312   - bash -c "exec 2>&1;\
313   - cdda2wav -H -D0,4,0 -t$i - | \
314   - lame -h \
315   - --ta \"${tartist}\" --tl \"${cddb[`idxof "album"`]}\" \
316   - --tg \"${cddb[`idxof "genre"`]}\" --tt \"${track}\" \
317   - --tn \"`expr ${tracknr} \+ 0`\" --ty \"${cddb[`idxof "year"`]}\" \
318   - --tc \"${cddb[`idxof "comment"`]}\" \
319   - - \"${outfile}.mp3\" 2>/dev/null" | rton | \
320   - awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}'
321   - fi
322   - if [ "$ENCODING_TYPE" = "m" -a "$ENCODER" = "bladeenc" ]
323   - then
324   - bash -c "exec 2>&1;\
325   - cdda2wav -H -D0,4,0 -t$i - | \
326   - bladeenc -progress=0 STDIN \"${outfile}.mp3\" 2>/dev/null" | rton | \
327   - awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}'
328   - fi
329   - if [ "$ENCODING_TYPE" = "o" ]
330   - then
331   - bash -c "exec 2>&1;\
332   - cdda2wav -H -D0,4,0 -t$i - | \
333   - oggenc -a \"${tartist}\" -l \"${cddb[`idxof "album"`]}\" \
334   - -G \"${cddb[`idxof "genre"`]}\" -t \"${track}\" \
335   - -N \"`expr ${tracknr} \+ 0`\" -d \"${cddb[`idxof "year"`]}\" \
336   - -c \"${cddb[`idxof "comment"`]}\" \
337   - -o \"${outfile}.ogg\" - 2>/dev/null" | rton | \
338   - awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}'
339   - fi
340   - if [ "$ENCODING_TYPE" = "w" ]
341   - then
342   - bash -c "exec 2>&1;\
343   - cdda2wav -H -D0,4,0 -t$i - > \"${outfile}.wav\"" | rton | \
344   - awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}'
345   - fi
346   -
347   - i=`expr $i + 1`
348   -done
349   -
350   -echo "</cdinfo>" >> "${xmlfile}"
1   -<?xml version="1.0" encoding="ISO-8859-15"?>
2   -<!DOCTYPE cdInfo SYSTEM "cdInfo.dtd">
3   -<cdinfo>
4   -<cdindex>2pGK39LLL22K6K8mFDegkBNR39M-</cdindex>
5   -<cddb>0x0911a912</cddb>
6   -<cd-text/>
7   -<cd-extra/>
8   -<cd-artist>Various</cd-artist>
9   -<cd-year>1998</cd-year>
10   -<cd-genre>Alternative</cd-genre>
11   -<track>
12   -<track-number>1</track-number>
13   -<track-time>3:42.20</track-time>
14   -<track-start-sector>32</track-start-sector>
15   -<track-artist>Guano Apes</track-artist>
16   -<track-title>Lords Of The Boards</track-title>
17   -<track-comment/>
18   -</track>
19   -<track>
20   -<track-number>2</track-number>
21   -<track-time>4:45.70</track-time>
22   -<track-start-sector>16702</track-start-sector>
23   -<track-artist>Rammstein</track-artist>
24   -<track-title>Das Modell</track-title>
25   -<track-comment/>
26   -</track>
27   -<track>
28   -<track-number>3</track-number>
29   -<track-time>4:11.08</track-time>
30   -<track-start-sector>38147</track-start-sector>
31   -<track-artist>Faith No More</track-artist>
32   -<track-title>Last Cup Of Sorrow</track-title>
33   -<track-comment/>
34   -</track>
35   -</cdinfo>
1   -Files in this package
2   ----------------------
3   - getcd.sh (The main script that does most of the work)
4   - rton.c (A VERY small c-prog, that converts \r (carriage return)
5   - to \n (line feed). It is needed to fetch the percent
6   - complete messages from cdda2wav)
7   - flac2mp3.xsl (xml stylesheet to convert cdinfo.xml in shell commands
8   - that will create .flac from .mp3 files)
9   - flac2wav.xsl (xml stylesheet to convert cdinfo.xml in shell commands
10   - that will create .flac from .wav files)
11   - mp32wav.xsl (xml stylesheet to convert cdinfo.xml in shell commands
12   - that will create .wav from .mp3 files)
13   - cdinfo2xinf.xsl (xml stylesheet to convert cdinfo.xml in shell commands
14   - that create the .xinf Files used by xcdroast)
15   - CDDB_get-2.23p1.patch (a patch for cddb.pl that makes it possible to
16   - select one of multiple cddb-entrys at calltime)
17   - README (Overview and Information)
18   - INSTALL (This file, howto make something useful from it)
19   - USAGE (How to use the script)
20   -
21   -
22   -Requirments
23   ------------
24   -first you need some software to run this script.
25   - CDDB_get-2.23 (http://armin.emx.at/cddb/)
26   - lame (http://lame.sourceforge.net/)
27   - bladeenc (http://bladeenc.mp3.no/)
28   - flac (http://flac.sourceforge.net/)
29   - vorbis-tools (http://www.vorbis.com/download_unix_1.0.1.psp)
30   - libxml2 (http://xmlsoft.org/)
31   -
32   -I assume you have a working sed and awk, else you need to install them too.
33   -
34   -Install lame, bladeenc, flac, vorbis-tools and libxml2 as discribed within
35   -these packages.
36   -
37   -unpack CDDB_get-2.23.tar.gz and patch it with CDDB_get-2.23p1.patch.
38   -For this copy both files in a directory dir then do the following:
39   -
40   -me@house:~> cd dir
41   -me@house:~/dir> tar xfvz CDDB_get-2.23.tar.gz
42   -me@house:~/dir/CDDB_get-2.23> patch -p1 -E < ../CDDB_get-2.23p1.patch
43   -
44   -now install it as usual (and described within the README from CDDB_get)
45   -
46   -now go in the directory where rton.c exists.
47   -type here: gcc -o rton rton.c
48   -and then copy rton in a directory in your path.
49   -
50   -Finally copy getcd.sh somewhere in you path.
51   -
52   -now you can use getcd.sh. For a short description how to use it either
53   -read USAGE or type getcd.sh -h.
54   -
55   -IMPORTANT: Any user who should use this script needs read-access to the
56   -cdrom device, additional it is actually necessary to create a symlink
57   -/dev/cdrom to your real device eg. /dev/sr0 or /dev/hdb. And the user must have
58   -access to the internet.
59   -
60   -Note
61   -----
62   -Please note that this is not a release. You can use it and it will not harm
63   -anything as for as I can say, but it might not work with some configurations
64   -or CDs.
65   -In the release there will be some kind of detection which tools are present and
66   -witch not and the script will use only present tools or give an error
67   -description.
68   -Note further that it is desired to modify the script for your needs. It is not
69   -very complex and with some error and trial it will be possible to tailor it
70   -exactly for your needs. In future there will be configuration files to make it
71   -even more ease to configure the script for your situation. (I am thinking
72   -about reqriting the script in c)
1   -This is another shell script that combines cdda2wav with various encoders.
2   -
3   -As I started this i was not pleased by any of the existent grabber/encoder
4   -frontends. So I decided to create my own one. The goal was to rip and encode in
5   -one step without creating any temporary .wav file and to have a simple command
6   -with only a few easy arguments to control this command.
7   -
8   -Now getcd.sh is a not to complicated bash script that uses awk, sed, cdda2wav,
9   -flac, lame, bladeenc, ogg/vorbis, cddb.pl (in a slightly patched version).
10   -It encodes tracks from the cd to a spcifiable base directory without creating
11   -any temporary files.
12   -It creates subdirectorys basedir/[mp3|flac|ogg|wav]/artist/cd-title for the
13   -corresponding encoding-method and save files with the name
14   -trackno-tracktitle.[mp3|flac|ogg|wav] again corresponding to the used
15   -encoding-method.
16   -If one encodes a sampler-cd (cd with various artists) it is often so, that
17   -the artist of the track is mentioned in the cddb-track-title. For this reason
18   -one can specify a delimiting character and the order (artist or title first) to
19   -split the cddb-track-info and generate correct id3tags or similar.
20   -
21   -Additional to the encoded files getcd.sh creates an file cdinfo.xml which
22   -contains all essential information of the original CD. I have written also
23   -some xslt files that can be used to create .xinf files for xcdroast and to
24   -create .wav from .flac or .mp3. It is planned to create additional xslt files
25   -to make html-information about the CD, create insert scripts for postgres and
26   -or mysql (or other rdbs) and converter-scripts that use these xslt-files.
27   -To use the xslt-files one needs an xslt-processor, like xsltproc from
28   -libxml2 (thats the one i used)
29   -
30   -for help use getcd.sh -h
No preview for this file type
1   -/* Achtung unter dos ist \n in wirklichkeit \r\n bei den meisten
2   - Compilern, da funktioniert das natürlich nicht!!!! */
3   -#include <stdio.h>
4   -
5   -int main(int argc, char* argv[]) {
6   - int c=0;
7   -
8   - while(fread(&c, 1, 1, stdin)) {
9   - putchar((c=='\r')?'\n':c);
10   - fflush(stdout);
11   - }
12   -
13   - return 0;
14   -}
15   -
  1 +if [ "x" == "x$__SHELLUTILS__" ]
  2 +then
  3 + __SHELLUTILS__="shellUtils"
  4 +
  5 + # -------------------------------
  6 + # Fehlermeldungen
  7 + _shellUtils_errMsg[1]="Fehler beim Aufruf von \${FUNCNAME}: falsche Parameteranzahl: $#"
  8 + _shellUtils_errMsg[2]="Fehler: Es läuft bereits eine Instanz (\${oldPid}) des scripts"
  9 + _shellUtils_errMsg[3]="Fehler beim Aufruf von doSmbCommand: smbCommand nicht initialisiert"
  10 + _shellUtils_errMsg[4]="Fehler: konnte keine Konfigurations-Datei (\${cName}) finden"
  11 + #_shellUtils_errMsg[2]=
  12 + # -------------------------------
  13 +
  14 + # -------------------------------
  15 + # Kommandodefinitions Teil
  16 + SH="/bin/bash"
  17 + SMBCLIENT="/usr/bin/smbclient"
  18 + PS="/bin/ps"
  19 + BASENAME="/usr/bin/basename"
  20 + PWDCMD="/bin/pwd"
  21 + CONVERT="/usr/bin/convert"
  22 + ICONV="/usr/bin/iconv"
  23 + ECHO="/bin/echo"
  24 + TEST="/usr/bin/test"
  25 + SED="/usr/bin/sed"
  26 + PRINTF="/usr/bin/printf"
  27 + SORT="/usr/bin/sort"
  28 + FTP="/usr/bin/ftp"
  29 + CONVERT="/usr/bin/convert"
  30 + CJPEG="/usr/bin/cjpeg"
  31 + CAT="/bin/cat"
  32 + MKDIR="/bin/mkdir"
  33 + DATE="/bin/date"
  34 + RM="/bin/rm"
  35 + MAILCMD="/bin/bin/mailto"
  36 + CUT="/usr/bin/cut"
  37 + TR="/usr/bin/tr"
  38 + LOCALE="/usr/bin/locale"
  39 + GREP="/bin/grep"
  40 + WC="/usr/bin/wc"
  41 + MV="/usr/bin/mv"
  42 + CP="/usr/bin/cp"
  43 + EXPR="/usr/bin/expr"
  44 + UNZIP="/usr/bin/unzip"
  45 + XSLTPROC="/usr/bin/xsltproc"
  46 + GAWK="/usr/bin/gawk"
  47 + AWK="/usr/bin/awk"
  48 + LS="/bin/ls"
  49 + TOUCH="/usr/bin/touch"
  50 + RECODE="/usr/bin/recode"
  51 + GETOPT="/usr/bin/getopt"
  52 + # -------------------------------
  53 +
  54 + # -------------------------------
  55 + # Variablen
  56 + _smbCommand=""
  57 + # -------------------------------
  58 +
  59 + # -------------------------------
  60 + # Funktionen
  61 + # Aufruf: checkLock lockfile
  62 + function checkLock
  63 + {
  64 + if [ $# -ne 1 ]
  65 + then
  66 + eval "echo \"${_shellUtils_errMsg[1]}\" >&2"
  67 + exit 1
  68 + fi
  69 +
  70 + local filename="$1"
  71 +
  72 + if [ -e "$filename" ]
  73 + then
  74 + local oldPid="`$CAT "$lockFile"`"
  75 + local scriptName="`$BASENAME $0`"
  76 + local running="`$PS -p "$oldPid" | $SED '1d; /'$scriptName'/!d'`"
  77 +
  78 + if [ -n "$running" ]
  79 + then
  80 + eval "echo \"${_shellUtils_errMsg[2]}\" >&2"
  81 + exit 2
  82 + fi
  83 + fi
  84 +
  85 + echo $$ >"$lockFile"
  86 +
  87 + return $$
  88 + }
  89 +
  90 + # Aufruf: doSmbCommand share domain user pass
  91 + function initSmbCommand
  92 + {
  93 + if [ $# -ne 4 ]
  94 + then
  95 + eval "echo \"${_shellUtils_errMsg[1]}\" >&2"
  96 + exit 1
  97 + fi
  98 +
  99 + _smbCommand="$SMBCLIENT $1 $4 -U $3 -W $2"
  100 + }
  101 +
  102 + # Aufruf: doSmbCommand path command
  103 + function doSmbCommand
  104 + {
  105 + if [ $# -lt 1 -o $# -gt 2 ]
  106 + then
  107 + eval "echo \"${_shellUtils_errMsg[1]}\" >&2"
  108 + exit 1
  109 + fi
  110 +
  111 + if [ -z "$_smbCommand" ]
  112 + then
  113 + eval "echo \"${_shellUtils_errMsg[3]}\" >&2"
  114 + exit 3
  115 + fi
  116 +
  117 + if [ $# -eq 2 ]
  118 + then
  119 + eval "$_smbCommand -D $1 -c \"$2\""
  120 + else
  121 + eval "$_smbCommand -D $1" <&0
  122 + fi
  123 + }
  124 +
  125 + # Meine Implementation von Hashes fuer die bash verwendet zwei Arrays,
  126 + # deren "Basisname" immer bei den aufrufen der Hash-Funktionen mit
  127 + # angegeben werden muessen. Die beiden Arrays heissen dann
  128 + # _<<Basisname>>_key und _<<Basisname>>_value und enthalten entsprechen
  129 + # jeweils zu einem Index ein key/value Paar.
  130 + # Die groesste Magie in den Funktionen liegt darin die Arraynamen
  131 + # immer richtig zu erzeugen.
  132 + # Wenn man dieses Hashes benutzt sollte man bedenken, das das
  133 + # Laufzeitverhalten O(n) ist, die Implementierung also nicht sehr
  134 + # performant.
  135 + # PS. O(n) => im unguenstigsten Fall hat man n Schleifendurchlaeufe um
  136 + # auf ein Element in einem Hash mit n Elementen zuzugreifen.
  137 + # Ich mags kaum zugeben aber an manchen Stellen ist das Laufzeitverhalten
  138 + # sogar O(2n). (Es besteht wohl noch dringender Optimirungsbedarf)
  139 +
  140 + # eine Funktion um einen Hash zu leeren
  141 + # Aufruf: unsetHash hashname
  142 + function unsetHash
  143 + {
  144 + if [ $# -ne 1 ]
  145 + then
  146 + eval "echo \"${_shellUtils_errMsg[1]}\" >&2"
  147 + exit 1
  148 + fi
  149 +
  150 + unset _${1}_key
  151 + unset _${1}_value
  152 + }
  153 +
  154 + # eine Funktion um einen HashWert zu setzen. ein key und ein value array
  155 + # werden erzeugt. Ueber getHashVal kann man wieder Werte abfragen.
  156 + # Aufruf: setHashVal hashname key value
  157 + function setHashVal
  158 + {
  159 + if [ $# -ne 3 ]
  160 + then
  161 + eval "echo \"${_shellUtils_errMsg[1]}\" >&2"
  162 + exit 1
  163 + fi
  164 +
  165 + getHashVal "${1}" "${2}" >/dev/null 2>&1
  166 + local idx=$?
  167 + eval "_${1}_key[$idx]=\"$2\""
  168 + eval "_${1}_value[$idx]=\"$3\""
  169 + }
  170 +
  171 + # und eine funktion um über einen key einen Wert aus einem Hash
  172 + # (siehe setHashVal) zu bekommen.
  173 + # Aufruf: getHashVal hash key
  174 + function getHashVal
  175 + {
  176 + if [ $# -ne 2 ]
  177 + then
  178 + eval "echo \"${_shellUtils_errMsg[1]}\" >&2"
  179 + exit 1
  180 + fi
  181 +
  182 + local i=0
  183 + local count=`getHashSize $1`
  184 + local key=`$ECHO $2 | $SED 's/#/\\\\#/'`
  185 +
  186 + while [ $i -lt $count ]
  187 + do
  188 + if eval [ "\${_${1}_key[$i]}" = "$key" ]
  189 + then
  190 + eval "echo \${_${1}_value[$i]}"
  191 + return $i
  192 + fi
  193 +
  194 + i=$((i+1));
  195 + done;
  196 +
  197 + return $i
  198 + }
  199 +
  200 + # Aufruf: getHashSize hash
  201 + function getHashSize
  202 + {
  203 + if [ $# -ne 1 ]
  204 + then
  205 + eval "echo \"${_shellUtils_errMsg[1]}\" >&2"
  206 + exit 1
  207 + fi
  208 +
  209 + eval "count=\${#_${1}_key[*]}"
  210 + echo $count
  211 +
  212 + return $count
  213 + }
  214 +
  215 + # Aufruf: getHashKeys hash
  216 + function getHashKeys
  217 + {
  218 + if [ $# -ne 1 ]
  219 + then
  220 + eval "echo \"${_shellUtils_errMsg[1]}\" >&2"
  221 + exit 1
  222 + fi
  223 +
  224 + eval "ret=\"\${_${1}_key[0]}\""
  225 +
  226 + local i=1
  227 + local count=`getHashSize $1`
  228 + while [ $i -lt $count ]
  229 + do
  230 + eval "ret=\"$ret \${_${1}_key[$i]}\""
  231 + i=$((i+1))
  232 + done
  233 +
  234 + echo $ret
  235 +
  236 + return $count
  237 + }
  238 +
  239 + # Funktion um die Zahlrepraesentation eines Monatsname zu bekommen.
  240 + # Also Oktober => 10
  241 + # Abhaengig davon das ein entsprechendes locale installiert ist.
  242 + # Aufruf: getMonthNum Monatsname [locale]
  243 + function getMonthNum
  244 + {
  245 + if [ $# -lt 1 ]
  246 + then
  247 + eval "echo \"${_shellUtils_errMsg[1]}\" >&2"
  248 + exit 1
  249 + fi
  250 +
  251 + if [ $# -eq 2 ]
  252 + then
  253 + LC_ALL=${2}
  254 + fi
  255 +
  256 + mon=`$LOCALE -c LC_TIME | $SED '5!d;y/;/\n/' |\
  257 + $GREP -n ${1} | $CUT -d\: -f1`
  258 +
  259 + echo $mon
  260 +
  261 + return $mon
  262 + }
  263 +
  264 + # Funkktion um ein Kommando nach einem bestimmten Zeitraum abzubrechen
  265 + # Aufruf: timeout cmd t
  266 + # Retruns: >128 -> falls Timeout, return value von cmd->falls kein Timeout
  267 + function timeout
  268 + {
  269 + if [ $# -lt 2 ]
  270 + then
  271 + eval "echo \"${_shellUtils_errMsg[1]}\" >&2"
  272 + exit 1
  273 + fi
  274 +
  275 + # gewuenschtes Kommando als separaten Prozess starten
  276 + $1 <&0 &
  277 + local __cPid=$!
  278 +
  279 + # subshell starten die gewuenschte Zeit wartet bis sie obigen
  280 + # Prozess killt.
  281 + ( sleep $2; kill -9 ${__cPid} ) >/dev/null 2>&1 &
  282 + local __tPid=$!
  283 +
  284 + # neuen Trap setzen....evtl. vorhande alte Kommandos werden auch
  285 + # ausgefuehrt! (Bei Programmabbruch auch auf jeden Fall beide
  286 + # Sub-Prozesse killen)
  287 + oldTrap="`trap -p EXIT`"
  288 + oldTrapCmd="`echo $oldTrap | sed 's/^trap -- \(.*\) EXIT$/\1/'`"
  289 +
  290 + trapCmd="kill -9 ${__cPid} >/dev/null 2>&1"
  291 + trapCmd="${trapCmd};kill -9 ${__cPid} >/dev/null 2>&1"
  292 + trapCmd="${trapCmd};eval $oldTrapCmd"
  293 + trap "${trapCmd}" EXIT
  294 +
  295 + # warte bis Subprozess mit Kommando endet
  296 + wait ${__cPid} >/dev/null 2>&1
  297 + local __cExit=$?
  298 +
  299 + # alte trap Kommandos wiederherstellen
  300 + test "$oldTrapCmd" && eval "$oldTrapCmd" || trap '-' EXIT
  301 +
  302 + # falls sie noch laeuft wartende subshell killen.
  303 + kill -9 $__tPid >/dev/null 2>&1
  304 + return $__cExit
  305 + }
  306 + # -------------------------------
  307 +
  308 +fi
  309 +
  310 +function getCDInfo
  311 +{
  312 + local uri device cmd i hello cddb ret diskData tNum
  313 +
  314 + uri="freedb.freedb.org/~cddb/cddb.cgi"
  315 + device="/dev/cdrom"
  316 +
  317 + test $# -ge 1 && uri="$1"
  318 + test $# -ge 2 && device="$2"
  319 +
  320 + hello="hello=${USER}+${HOSTNAME}+test+0.0.1"
  321 +
  322 + # first get the genre list from server
  323 + eval "`curl -s "http://${uri}?cmd=cddb+lscat&${hello}&proto=6" |\
  324 + sed '1d;$d' | tr -d '\r' | tr '\n' ',' |\
  325 + sed 's/,$//;s/,/" "/g;s/^\(.*\)$/local -a genre=("\1")/'`"
  326 +
  327 + unset cddbId dTitle dYear dGenre tTitle
  328 +
  329 + diskData="`cdda2wav -D ${device} -N -J -v toc,sectors 2>&1`"
  330 +
  331 + cddbId="`echo "$diskData" |\
  332 + sed '/^CDDB/!d;s/^.*0x\(.*\)$/\1/'`"
  333 + dTracks="`echo "$diskData" |\
  334 + sed '/tracks/!d;s/^.*tracks:\([0-9]*\).*$/\1/'`"
  335 + dLength="`echo "$diskData" |\
  336 + sed '/tracks/!d;s/^.*time \([0-9:\.]*\).*$/\1/'`"
  337 + dIndex="`echo "$diskData" |\
  338 + sed '/CDINDEX/!d;s/^.*: *\([a-zA-Z0-9_\.]*-\).*$/\1/'`"
  339 + dText="`echo "$diskData" | sed '
  340 + /CD-Text/!d;s/^[^:]*: *\(.*[^ ]\).*$/\1/'`"
  341 + dExtra="`echo "$diskData" | sed '
  342 + /CD-Extra/!d;s/^[^:]*: *\(.*[^ ]\).*$/\1/'`"
  343 +
  344 + # search for info in all genres
  345 + for i in "${genre[@]}"
  346 + do
  347 + cmd="cmd=cddb+read+${i}+${cddbId}"
  348 + #wget -O- "http://${uri}?${cmd}&${hello}&proto=6" 2>/dev/null
  349 + cddb="`curl -s "http://${uri}?${cmd}&${hello}&proto=6"`"
  350 +
  351 + ret="`echo "$cddb" | head -c 3`"
  352 + if [ "$ret" != "210" ]
  353 + then
  354 + if [ ${verbose:-0} -ge 3 ]
  355 + then
  356 + debug="`echo "$cddb" | head -n 1`"
  357 + echo $"[ERROR] cddb: ${debug}"
  358 + fi
  359 + continue
  360 + else
  361 + eval "`echo "$cddb" | tr -d '\r' | sed '
  362 + /DTITLE/s/^.*=\(\(.*\) \/ \)*\(.*\)$/dArtist="\2";dTitle="\3"/p
  363 + /DYEAR/s/^.*=\(.*\)$/dYear="\1"/p
  364 + /DGENRE/s/^.*=\(.*\)$/dGenre="\1"/p
  365 + /TTITLE/s/^TTITLE\([0-9]*\)=\(\(.*\) \/ \)*\(.*\)$/tArtist[\1]="\3";tTitle[\1]="\4"/p
  366 + d'`"
  367 + break
  368 + fi
  369 + done
  370 +
  371 + # Nu pack ich in alle tArtist die leer sind den dArtist.
  372 + i=0
  373 + while [ $i -lt ${#tArtist[@]} ]
  374 + do
  375 + tNum=$((i+1))
  376 + tLength[$i]=`echo "$diskData" | sed '
  377 + /[^0-9]'$tNum'\.(.*:.*)/ !d
  378 + s/.*[^0-9]'$tNum'\.( *\([^)]*\).*$/\1/'`
  379 + tStartSec[$i]=`echo "$diskData" | sed '
  380 + /[^0-9]'$tNum'\.([^:]*)/ !d
  381 + s/.*[^0-9]'$tNum'\.( *\([^)]*\).*$/\1/'`
  382 +
  383 + test $tNum -eq ${#tArtist[@]} && tNum="lead-out" || tNum=$((tNum+1))
  384 +
  385 + tEndSec[$i]=`echo "$diskData" | sed '
  386 + /[^0-9]'$tNum'\.*([^:]*)/ !d
  387 + s/.*[^0-9]'$tNum'\.*( *\([^)]*\).*$/\1/'`
  388 +
  389 + test -z "${tArtist[$i]}" && tArtist[$i]="$dArtist"
  390 + i=$((i+1))
  391 + done
  392 +}
  393 +
... ...
1   -usage: ./getcd.sh [-d delimiter [-o {t|a}]] [-t {m|f|o}] [-p path] [-e encoder] [-c cddb-entry] [-h]
2   - -d : A single character delimiting trackname from
3   - artistname with sampler cds
4   -
5   - -o : specifies if theres the track or the artist first
6   - Must be:
7   - t for titel first or
8   - a for artist first
9   - If there is none specified t is assumed
10   - -t : you can specify either m for encoding to mp3
11   - using lame, or f for making lossless encoding using flac,
12   - or o for making ogg/vorbis, or w for uncompressed wav.
13   - Omitting this results in encoding to flac.
14   - mp3s will be placed under a subfolder mp3 and flacs
15   - under a subfolder flac
16   - -p : specifies the path to save the encoded data.
17   - Defaults to the users home directory.
18   - -e : specifies the mp3 encoder to use.
19   - valid encoders are actually: lame,bladeenc
20   - Defaults to lame.
21   - -c : specifies the CDDB-Entry to use.
22   - sometimes there is more than 1 entry for a cd in cddb.
23   - Then you can specify wich one to use by this option.
24   - You can checkout all entries using cddb.pl.
25   - -h : Shows this help.
Please register or login to post a comment