18 changed files with 754 additions and 1448 deletions
-
BINCDDB_get-2.23.tar.gz
-
70CDDB_get-2.23p1.patch
-
BINCDDB_get-2.27.tar.gz
-
70CDDB_get-2.27p1.patch
-
451cddb.pl
-
627getcd.sh
-
350getcd.sh.neu
-
35getcd.xml
-
72install
-
30readme
-
BINrton
-
15rton.c
-
393shellUtils.sh
-
25usage
-
0xsl/cdinfo2xinf.xsl
-
0xsl/flac2mp3.xsl
-
0xsl/flac2wav.xsl
-
0xsl/mp32wav.xsl
@ -1,70 +0,0 @@ |
|||||
diff -Naur CDDB_get-2.23/CDDB_get.pm CDDB_get-2.23p1/CDDB_get.pm
|
|
||||
--- CDDB_get-2.23/CDDB_get.pm 2003-09-07 15:49:27.000000000 +0000
|
|
||||
+++ CDDB_get-2.23p1/CDDB_get.pm 2004-06-30 08:37:28.000000000 +0000
|
|
||||
@@ -261,6 +261,7 @@
|
|
||||
|
|
||||
my $input = $config->{input}; |
|
||||
my $multi = $config->{multi}; |
|
||||
+ my $entry = $config->{entry} if (defined($config->{entry}));
|
|
||||
$input = 0 if $multi; |
|
||||
|
|
||||
print STDERR Dumper($config) if $debug; |
|
||||
@@ -426,7 +427,14 @@
|
|
||||
} |
|
||||
} |
|
||||
} else { |
|
||||
- push @to_get,@list;
|
|
||||
+ unless(defined($entry)) {
|
|
||||
+ push @to_get,@list;
|
|
||||
+ }
|
|
||||
+ else {
|
|
||||
+ if($entry-1 >= 0 && $entry-1 <= $#list) {
|
|
||||
+ push @to_get,$list[$entry-1];
|
|
||||
+ }
|
|
||||
+ }
|
|
||||
} |
|
||||
|
|
||||
my $i=0; |
|
||||
diff -Naur CDDB_get-2.23/cddb.pl CDDB_get-2.23p1/cddb.pl
|
|
||||
--- CDDB_get-2.23/cddb.pl 2003-08-16 19:01:49.000000000 +0000
|
|
||||
+++ CDDB_get-2.23p1/cddb.pl 2004-06-30 08:33:03.000000000 +0000
|
|
||||
@@ -27,12 +27,13 @@
|
|
||||
use strict; |
|
||||
|
|
||||
my %option = (); |
|
||||
-getopts("oghdtsiSfDlOFc:", \%option);
|
|
||||
+getopts("oghdtsiSfDlOFe:c:", \%option);
|
|
||||
|
|
||||
if($option{h}) { |
|
||||
print "$0: gets CDDB info of a CD\n"; |
|
||||
print " no argument - gets CDDB info of CD in your drive\n"; |
|
||||
print " -c device (other than default device)\n"; |
|
||||
+ print " -e which cddb-entry to use\n";
|
|
||||
print " -o offline mode - just stores CD info\n"; |
|
||||
print " -d output in xmcd format\n"; |
|
||||
print " -s save in xmcd format\n"; |
|
||||
@@ -81,11 +82,19 @@
|
|
||||
$config{CD_DEVICE}=$option{c} if $option{c}; |
|
||||
|
|
||||
# user interaction welcome? |
|
||||
-
|
|
||||
-$config{input}=1; # 1: ask user if more than one possibility
|
|
||||
- # 0: no user interaction
|
|
||||
-$config{multi}=0; # 1: do not ask user and get all of them
|
|
||||
- # 0: just the first one
|
|
||||
+if($option{e}) {
|
|
||||
+ $config{entry}=$option{e};
|
|
||||
+ $config{input}=0; # 1: ask user if more than one possibility
|
|
||||
+ # 0: no user interaction
|
|
||||
+ $config{multi}=0; # 1: do not ask user and get all of them
|
|
||||
+ # 0: just the first one
|
|
||||
+}
|
|
||||
+else {
|
|
||||
+ $config{input}=1; # 1: ask user if more than one possibility
|
|
||||
+ # 0: no user interaction
|
|
||||
+ $config{multi}=0; # 1: do not ask user and get all of them
|
|
||||
+ # 0: just the first one
|
|
||||
+}
|
|
||||
|
|
||||
my %db; |
|
||||
|
|
||||
@ -1,70 +0,0 @@ |
|||||
diff -Naur CDDB_get-2.27/CDDB_get.pm CDDB_get-2.27.patched/CDDB_get.pm
|
|
||||
--- CDDB_get-2.27/CDDB_get.pm 2006-01-01 20:52:54.000000000 +0100
|
|
||||
+++ CDDB_get-2.27.patched/CDDB_get.pm 2006-05-27 09:54:30.733131044 +0200
|
|
||||
@@ -262,6 +262,7 @@
|
|
||||
|
|
||||
my $input = $config->{input}; |
|
||||
my $multi = $config->{multi}; |
|
||||
+ my $entry = $config->{entry} if (defined($config->{entry}));
|
|
||||
$input = 0 if $multi; |
|
||||
|
|
||||
print STDERR Dumper($config) if $debug; |
|
||||
@@ -441,7 +442,14 @@
|
|
||||
} |
|
||||
} |
|
||||
} else { |
|
||||
- push @to_get,@list;
|
|
||||
+ unless(defined($entry)) {
|
|
||||
+ push @to_get,@list;
|
|
||||
+ }
|
|
||||
+ else {
|
|
||||
+ if($entry-1 >= 0 && $entry-1 <= $#list) {
|
|
||||
+ push @to_get,$list[$entry-1];
|
|
||||
+ }
|
|
||||
+ }
|
|
||||
} |
|
||||
|
|
||||
my $i=0; |
|
||||
diff -Naur CDDB_get-2.27/cddb.pl CDDB_get-2.27.patched/cddb.pl
|
|
||||
--- CDDB_get-2.27/cddb.pl 2005-10-06 08:00:59.000000000 +0200
|
|
||||
+++ CDDB_get-2.27.patched/cddb.pl 2006-05-27 09:56:17.798156565 +0200
|
|
||||
@@ -27,12 +27,13 @@
|
|
||||
use strict; |
|
||||
|
|
||||
my %option = (); |
|
||||
-getopts("oghdtsi:SfDlOFc:H:CIRGP", \%option);
|
|
||||
+getopts("oghdtsi:SfDlOFe:c:H:CIRGP", \%option);
|
|
||||
|
|
||||
if($option{h}) { |
|
||||
print "$0: gets CDDB info of a CD\n"; |
|
||||
print " no argument - gets CDDB info of CD in your drive\n"; |
|
||||
print " -c device (other than default device)\n"; |
|
||||
+ print " -e which cddb-entry to use\n";
|
|
||||
print " -o offline mode - just stores CD info\n"; |
|
||||
print " -d output in xmcd format\n"; |
|
||||
print " -s save in xmcd format\n"; |
|
||||
@@ -110,11 +111,19 @@
|
|
||||
$config{CD_DEVICE}=$option{c} if $option{c}; |
|
||||
|
|
||||
# user interaction welcome? |
|
||||
-
|
|
||||
-$config{input}=1; # 1: ask user if more than one possibility
|
|
||||
- # 0: no user interaction
|
|
||||
-$config{multi}=0; # 1: do not ask user and get all of them
|
|
||||
- # 0: just the first one
|
|
||||
+if($option{e}) {
|
|
||||
+ $config{entry}=$option{e};
|
|
||||
+ $config{input}=0; # 1: ask user if more than one possibility
|
|
||||
+ # 0: no user interaction
|
|
||||
+ $config{multi}=0; # 1: do not ask user and get all of them
|
|
||||
+ # 0: just the first one
|
|
||||
+}
|
|
||||
+else {
|
|
||||
+ $config{input}=1; # 1: ask user if more than one possibility
|
|
||||
+ # 0: no user interaction
|
|
||||
+ $config{multi}=0; # 1: do not ask user and get all of them
|
|
||||
+ # 0: just the first one
|
|
||||
+}
|
|
||||
|
|
||||
$config{input}=0 if($option{I}); |
|
||||
|
|
||||
@ -1,451 +0,0 @@ |
|||||
#!/usr/bin/perl -I. |
|
||||
# |
|
||||
# CDDB - Read the CDDB entry for an audio CD in your drive |
|
||||
# |
|
||||
# This module/script gets the CDDB info for an audio cd. You need |
|
||||
# LINUX, a cdrom drive and an active internet connection in order |
|
||||
# to do that. |
|
||||
# |
|
||||
# (c) 2004 Armin Obersteiner <armin@xos.net> |
|
||||
# |
|
||||
# LICENSE |
|
||||
# |
|
||||
# This library is released under the same conditions as Perl, that |
|
||||
# is, either of the following: |
|
||||
# |
|
||||
# a) the GNU General Public License Version 2 as published by the |
|
||||
# Free Software Foundation, |
|
||||
# |
|
||||
# b) the Artistic License. |
|
||||
# |
|
||||
|
|
||||
#use CDDB_get qw( get_cddb get_discids ); |
|
||||
|
|
||||
use Data::Dumper; |
|
||||
use Getopt::Std; |
|
||||
|
|
||||
use strict; |
|
||||
|
|
||||
my %option = (); |
|
||||
getopts("oghdtsi:SfDlOFe:c:H:CIRGP", \%option); |
|
||||
|
|
||||
if($option{h}) { |
|
||||
print "$0: gets CDDB info of a CD\n"; |
|
||||
print " no argument - gets CDDB info of CD in your drive\n"; |
|
||||
print " -c device (other than default device)\n"; |
|
||||
print " -e which cddb-entry to use\n"; |
|
||||
print " -o offline mode - just stores CD info\n"; |
|
||||
print " -d output in xmcd format\n"; |
|
||||
print " -s save in xmcd format\n"; |
|
||||
print " -i db. one of: mysql, pg, oracle, sqlite\n"; |
|
||||
print " -O overwrite file or db\n"; |
|
||||
print " -t output toc\n"; |
|
||||
print " -l output lame command\n"; |
|
||||
print " -f http mode (e.g. through firewalls)\n"; |
|
||||
print " -F some stateful firewalls/http proxies need additional newlines\n"; |
|
||||
print " -g get CDDB info for stored CDs\n"; |
|
||||
print " -I non interactive mode\n"; |
|
||||
print " -H CDDB hostname\n"; |
|
||||
print " -C use local cache\n"; |
|
||||
print " -R readonly cache\n"; |
|
||||
print " -G cache has not the diskid as filenames (much slower)\n"; |
|
||||
print " -P cache path (default: /tmp/xmcd)\n"; |
|
||||
print " -D put CDDB_get in debug mode\n"; |
|
||||
exit; |
|
||||
} |
|
||||
|
|
||||
my %config; |
|
||||
|
|
||||
my $diskid; |
|
||||
my $total; |
|
||||
my $toc; |
|
||||
my $savedir="/tmp/cddb"; |
|
||||
my $xmcddir="/tmp/xmcd"; |
|
||||
|
|
||||
if($option{C}) { |
|
||||
# use CDDB_cache qw( get_cddb get_discids ); |
|
||||
require CDDB_cache; |
|
||||
CDDB_cache->import( qw( get_cddb get_discids ) ); |
|
||||
|
|
||||
$CDDB_cache::debug=1 if($option{D}); |
|
||||
$CDDB_cache::readonly=1 if($option{R}); |
|
||||
$CDDB_cache::grep=1 if($option{G}); |
|
||||
|
|
||||
$CDDB_cache::dir="/tmp/xmcd"; # default |
|
||||
# $CDDB_cache::dir="/opt/kde2/share/apps/kscd/cddb"; |
|
||||
$CDDB_cache::dir=$option{P} if($option{P}); |
|
||||
|
|
||||
} else { |
|
||||
# use CDDB_get qw( get_cddb get_discids ); |
|
||||
require CDDB_get; |
|
||||
CDDB_get->import( qw( get_cddb get_discids ) ); |
|
||||
} |
|
||||
|
|
||||
$CDDB_get::debug=1 if($option{D}); |
|
||||
|
|
||||
# following variables just need to be declared if different from defaults |
|
||||
# defaults are listed below (cdrom default is os specific) |
|
||||
|
|
||||
# $config{CDDB_HOST}="freedb.freedb.org"; # set cddb host |
|
||||
if($option{H}) { |
|
||||
$config{CDDB_HOST}=$option{H}; |
|
||||
} |
|
||||
# $config{CDDB_PORT}=8880; # set cddb port |
|
||||
# $config{CDDB_MODE}="cddb"; # set cddb mode: cddb or http, this is switched with -f |
|
||||
# $config{CD_DEVICE}="/dev/cdrom"; # set cd device |
|
||||
|
|
||||
# $config{HELLO_ID} ="root nowhere.com fastrip 0.77"; # hello string: username hostname clientname version |
|
||||
# $config{PROTO_VERSION} = 5; # cddb protokol version |
|
||||
|
|
||||
|
|
||||
# get proxy settings for cddb mode |
|
||||
|
|
||||
$config{HTTP_PROXY}=$ENV{http_proxy} if $ENV{http_proxy}; # maybe wanna use a proxy ? |
|
||||
|
|
||||
$config{CDDB_MODE}="http" if($option{f}); |
|
||||
if($option{F}) { |
|
||||
$config{CDDB_MODE}="http"; |
|
||||
$config{FW}=1; |
|
||||
} |
|
||||
|
|
||||
$config{CD_DEVICE}=$option{c} if $option{c}; |
|
||||
|
|
||||
# user interaction welcome? |
|
||||
if($option{e}) { |
|
||||
$config{entry}=$option{e}; |
|
||||
$config{input}=0; # 1: ask user if more than one possibility |
|
||||
# 0: no user interaction |
|
||||
$config{multi}=0; # 1: do not ask user and get all of them |
|
||||
# 0: just the first one |
|
||||
} |
|
||||
else { |
|
||||
$config{input}=1; # 1: ask user if more than one possibility |
|
||||
# 0: no user interaction |
|
||||
$config{multi}=0; # 1: do not ask user and get all of them |
|
||||
# 0: just the first one |
|
||||
} |
|
||||
|
|
||||
$config{input}=0 if($option{I}); |
|
||||
|
|
||||
my %db; |
|
||||
|
|
||||
if($option{i}) { |
|
||||
require DBI; |
|
||||
|
|
||||
$db{table_cds} = "cds"; |
|
||||
$db{table_tracks} = "tracks"; |
|
||||
|
|
||||
# not needed for sqlite |
|
||||
$db{host} = "localhost"; |
|
||||
$db{port} = "3306"; |
|
||||
|
|
||||
# not needed for oracle/sqlite |
|
||||
$db{name} = "mp3-test"; |
|
||||
|
|
||||
# just for oracle |
|
||||
$db{sid} = "xxx"; |
|
||||
$db{home} = "xxx"; |
|
||||
|
|
||||
# just for sqlite |
|
||||
$db{file} = "xxx"; |
|
||||
|
|
||||
# not needed for sqlite |
|
||||
$db{user} = "root"; |
|
||||
$db{passwd} = "xxx"; |
|
||||
|
|
||||
|
|
||||
if($option{i} eq "mysql") { |
|
||||
$db{connect} = sub { "dbi:mysql:database=$db{name};host=$db{host};port=$db{port}", $db{user}, $db{passwd} }; |
|
||||
} elsif($option{i} eq "pg") { |
|
||||
$db{connect} = sub { "dbi:Pg:dbname=$db{dbname};host=$db{host};port=$db{port}", $db{user}, $db{passwd} }; |
|
||||
} elsif($option{i} eq "oracle") { |
|
||||
$db{connect} = sub { "dbi:Oracle:host=$db{host};sid=$db{sid};port=$db{port}", $db{user}, $db{passwd} }; |
|
||||
$ENV{ORACLE_HOME} = $db{home}; |
|
||||
} elsif($option{i} eq "sqlite") { |
|
||||
$db{connect} = sub { "dbi:SQLite:dbname=$db{file}","","" }; |
|
||||
} else { |
|
||||
die "unkown database: $option{i}"; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
if($option{o}) { |
|
||||
my $ids=get_discids($config{CD_DEVICE}); |
|
||||
|
|
||||
unless(-e $savedir) { |
|
||||
mkdir $savedir,0755 or die "cannot create $savedir"; |
|
||||
} |
|
||||
|
|
||||
open OUT,">$savedir/$ids->[0]\_$$" or die "cannot open outfile"; |
|
||||
print OUT Data::Dumper->Dump($ids,["diskid","total","toc"]); |
|
||||
close OUT; |
|
||||
|
|
||||
print STDERR "saved in: $savedir/$ids->[0]\_$$\n"; |
|
||||
exit; |
|
||||
} |
|
||||
|
|
||||
if($option{g}) { |
|
||||
print STDERR "retrieving stored cds ...\n"; |
|
||||
|
|
||||
opendir(DIR, $savedir) or die "cannot opendir $savedir"; |
|
||||
while (defined(my $file = readdir(DIR))) { |
|
||||
next if($file =~ /^\./); |
|
||||
print "\n"; |
|
||||
|
|
||||
my $in=`/bin/cat $savedir/$file`; |
|
||||
my $exit = $? >> 8; |
|
||||
|
|
||||
if($exit>0) { |
|
||||
die "error reading file"; |
|
||||
} |
|
||||
|
|
||||
unless($in=~ m/^\$diskid\s+=\s+('\d+'|\d+);\s+ # $diskid |
|
||||
\$total\s+=\s+('\d+'|\d+);\s+ # $total |
|
||||
\$toc\s+=\s+\[\s+ # $toc |
|
||||
(\{\s+ |
|
||||
('(frame|frames|min|sec|data)'\s+=\>\s+('\d+'|\d+)(,|)\s+){5} |
|
||||
\}(,|)\s+)+ |
|
||||
\];\s+$/xs) { |
|
||||
print "not a save file: $savedir/$file\n"; |
|
||||
next; |
|
||||
} |
|
||||
|
|
||||
eval $in; |
|
||||
|
|
||||
if($@) { |
|
||||
print "not a save file (eval error): $savedir/$file\n"; |
|
||||
next; |
|
||||
} |
|
||||
|
|
||||
my %cd=get_cddb(\%config,[$diskid,$total,$toc]); |
|
||||
|
|
||||
unless(defined $cd{title}) { |
|
||||
print "no cddb entry found: $savedir/$file\n"; |
|
||||
} |
|
||||
|
|
||||
unlink "$savedir/$file"; |
|
||||
|
|
||||
next unless defined $cd{title}; |
|
||||
|
|
||||
if($option{d} || $option{s}) { |
|
||||
print_xmcd(\%cd,$option{s}); |
|
||||
} elsif($option{i}) { |
|
||||
insert_db(\%cd,\%db); |
|
||||
} elsif($option{l}) { |
|
||||
print_lame(\%cd); |
|
||||
} else { |
|
||||
print_cd(\%cd); |
|
||||
} |
|
||||
} |
|
||||
closedir(DIR); |
|
||||
exit; |
|
||||
} |
|
||||
|
|
||||
# get it on |
|
||||
|
|
||||
unless($config{multi}) { |
|
||||
my %cd; |
|
||||
|
|
||||
# for those who don't like 'die' in modules ;-) |
|
||||
eval { |
|
||||
%cd = get_cddb(\%config); |
|
||||
}; |
|
||||
if ($@) { |
|
||||
print "fatal error: $!\n"; |
|
||||
exit; |
|
||||
} |
|
||||
|
|
||||
print Dumper(\%cd) if $option{D}; |
|
||||
|
|
||||
unless(defined $cd{title}) { |
|
||||
die "no cddb entry found"; |
|
||||
} |
|
||||
|
|
||||
# do somthing with the results |
|
||||
|
|
||||
if($option{d} || $option{s}) { |
|
||||
print_xmcd(\%cd,$option{s}); |
|
||||
} elsif($option{i}) { |
|
||||
insert_db(\%cd,\%db); |
|
||||
} elsif($option{l}) { |
|
||||
print_lame(\%cd); |
|
||||
} else { |
|
||||
print_cd(\%cd); |
|
||||
} |
|
||||
} else { |
|
||||
my @cd; |
|
||||
|
|
||||
# for those who don't like 'die' in modules ;-) |
|
||||
eval { |
|
||||
@cd=get_cddb(\%config); |
|
||||
}; |
|
||||
if ($@) { |
|
||||
print "fatal error: $!\n"; |
|
||||
exit; |
|
||||
} |
|
||||
|
|
||||
print Dumper(\@cd) if $option{D}; |
|
||||
|
|
||||
for my $c (@cd) { |
|
||||
unless(defined $c->{title}) { |
|
||||
die "no cddb entry found"; |
|
||||
} |
|
||||
|
|
||||
# do somthing with the results |
|
||||
|
|
||||
if($option{d} || $option{s}) { |
|
||||
print_xmcd($c,$option{s}); |
|
||||
} elsif($option{i}) { |
|
||||
insert_db($c,\%db); |
|
||||
} elsif($option{l}) { |
|
||||
print_lame($c); |
|
||||
print "\n"; |
|
||||
} else { |
|
||||
print_cd($c); |
|
||||
print "\n"; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
exit; |
|
||||
|
|
||||
|
|
||||
# subroutines |
|
||||
|
|
||||
sub print_cd { |
|
||||
my $cd=shift; |
|
||||
|
|
||||
print "artist: $cd->{artist}\n"; |
|
||||
print "title: $cd->{title}\n"; |
|
||||
print "category: $cd->{cat}\n"; |
|
||||
print "genre: $cd->{genre}\n" if($cd->{genre}); |
|
||||
print "year: $cd->{year}\n" if($cd->{year}); |
|
||||
print "cddbid: $cd->{id}\n"; |
|
||||
print "trackno: $cd->{tno}\n"; |
|
||||
|
|
||||
my $n=1; |
|
||||
foreach my $i ( @{$cd->{track}} ) { |
|
||||
if($option{t}) { |
|
||||
my $from=$cd->{frames}[$n-1]; |
|
||||
my $to=$cd->{frames}[$n]-1; |
|
||||
my $dur=$to-$from; |
|
||||
my $min=int($dur/75/60); |
|
||||
my $sec=int($dur/75)-$min*60; |
|
||||
my $frm=($dur-$sec*75-$min*75*60)*100/75; |
|
||||
my $out=sprintf "track %2d: %8d - %8d [%2d:%.2d.%.2d]: $i\n",$n,$from,$to,$min,$sec,$frm; |
|
||||
print "$out"; |
|
||||
} else { |
|
||||
print "track $n: $i\n"; |
|
||||
} |
|
||||
$n++; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
sub print_xmcd { |
|
||||
my $cd=shift; |
|
||||
my $save=shift; |
|
||||
|
|
||||
*OUT=*STDOUT; |
|
||||
|
|
||||
if($save) { |
|
||||
unless(-e $xmcddir) { |
|
||||
mkdir $xmcddir,0755 or die "cannot create $savedir"; |
|
||||
} |
|
||||
|
|
||||
unless($option{O}) { |
|
||||
if(-e "$xmcddir/$cd->{id}") { |
|
||||
print "XMCD file exists\n"; |
|
||||
exit; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
open XMCD,">$xmcddir/$cd->{id}" or die "cannot open outfile"; |
|
||||
*OUT=*XMCD; |
|
||||
} |
|
||||
|
|
||||
for(@{$cd->{raw}}) { |
|
||||
print OUT "$_"; |
|
||||
} |
|
||||
|
|
||||
if($save) { |
|
||||
print STDERR "saved in: $xmcddir/$cd->{id}\n"; |
|
||||
close OUT; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
sub insert_db { |
|
||||
my $cd=shift; |
|
||||
my $db=shift; |
|
||||
|
|
||||
my ($artist, $title, $category, $cddbid, $trackno) = |
|
||||
($cd->{artist}, $cd->{title}, $cd->{cat}, $cd->{id}, $cd->{tno}); |
|
||||
|
|
||||
my $sql = "SELECT cddbid FROM $db->{table_cds} WHERE CDDBID = \'$cddbid\'"; |
|
||||
my $dbh = DBI->connect($db->{connect}->()) or die "cannot connect to db: $DBI::errstr"; |
|
||||
my $sth = $dbh->prepare($sql); |
|
||||
my $r = $sth->execute or die "cannot check for cd: $DBI::errstr"; |
|
||||
if ($r == 1) { |
|
||||
print "cd already in db\n"; |
|
||||
if($option{O}) { |
|
||||
my $sql = "DELETE FROM $db->{table_cds} WHERE CDDBID = \'$cddbid\'"; |
|
||||
my $sth = $dbh->prepare($sql); |
|
||||
my $r = $sth->execute or die "cannot delete from $db->{table_cds}: $DBI::errstr"; |
|
||||
$sql = "DELETE FROM $db->{table_tracks} WHERE CDDBID = \'$cddbid\'"; |
|
||||
$sth = $dbh->prepare($sql); |
|
||||
$r = $sth->execute or die "cannot delete from $db->{table_tracks}: $DBI::errstr"; |
|
||||
} else { |
|
||||
exit; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
$title =~ s/'/\\'/g; |
|
||||
$artist =~ s/'/\\'/g; |
|
||||
$category =~ s/'/\\'/g; |
|
||||
|
|
||||
$sql = "INSERT INTO $db->{table_cds} (cddbid, artist, title, category, tracks) VALUES (\'$cddbid\', \'$artist\', \'$title\', \'$category\' , \'$trackno\')"; |
|
||||
$sth = $dbh->prepare($sql); |
|
||||
$r = $sth->execute or die "failed to insert cd: $DBI::errstr"; |
|
||||
|
|
||||
my $n=1; |
|
||||
|
|
||||
print "titel: $title\n"; |
|
||||
print "artist: $artist\n"; |
|
||||
print "category: $category\n\n"; |
|
||||
|
|
||||
for my $t ( @{$cd->{track}} ) { |
|
||||
$t =~ s/'/\\'/g; |
|
||||
my $dur=($cd->{frames}[$n]-1-$cd->{frames}[$n-1])/75; |
|
||||
my $hour=int($dur/3600); |
|
||||
my $min=int($dur/60-$hour*60); |
|
||||
my $sec=$dur-$hour*3600-$min*60; |
|
||||
my $fr=substr(sprintf("%5.2f",$sec-int($sec)),2,3); |
|
||||
my $time=sprintf "%.2d:%.2d:%.2d%s",$hour,$min,int($sec),$fr; |
|
||||
|
|
||||
print "track $n: $t [$time]\n"; |
|
||||
|
|
||||
my $sql = "INSERT INTO $db->{table_tracks} (cddbid, title, trackno, time) |
|
||||
VALUES (\'$cddbid\',\'$t\', \'$n\', \'$time\')"; |
|
||||
my $sth = $dbh->prepare($sql); |
|
||||
my $r = $sth->execute or die "failed to insert track $n: $DBI::errstr"; |
|
||||
$n++; |
|
||||
} |
|
||||
|
|
||||
$dbh->disconnect(); |
|
||||
} |
|
||||
|
|
||||
sub print_lame { |
|
||||
my $cd=shift; |
|
||||
|
|
||||
print_cd($cd); |
|
||||
print "\n"; |
|
||||
|
|
||||
my $n=1; |
|
||||
for my $i ( @{$cd->{track}} ) { |
|
||||
$i =~ s/"/'/g; |
|
||||
print 'lame --tl "'.$cd->{title}.'" --ta "'.$cd->{artist}.'" --tt "'.$i.'" '; |
|
||||
printf "audio_%02d.wav ",$n; |
|
||||
$i =~ s/[^\S]|['"\/]/_/g; |
|
||||
$i =~ s/_+-_+/-/g; |
|
||||
print " $i.mp3\n"; |
|
||||
$n++; |
|
||||
} |
|
||||
} |
|
||||
@ -1,344 +1,375 @@ |
|||||
USAGE="usage: $0 [-d delimiter [-o {t|a}]] [-t {m|f|o}] [-p path] [-e encoder] [-c cddb-entry] [-h]\n" |
|
||||
USAGE="${USAGE} -d :\tA single character delimiting trackname from\n" |
|
||||
USAGE="${USAGE}\tartistname with sampler cds\n\n" |
|
||||
USAGE="${USAGE} -o :\tspecifies if theres the track or the artist first\n" |
|
||||
USAGE="${USAGE}\tMust be:\n" |
|
||||
USAGE="${USAGE}\t t for titel first or\n" |
|
||||
USAGE="${USAGE}\t a for artist first\n" |
|
||||
USAGE="${USAGE}\tIf there is none specified t is assumed\n" |
|
||||
USAGE="${USAGE} -t :\tyou can specify either m for encoding to mp3\n" |
|
||||
USAGE="${USAGE}\tusing lame, or f for making lossless encoding using flac,\n" |
|
||||
USAGE="${USAGE}\tor o for making ogg/vorbis, or w for uncompressed wav.\n" |
|
||||
USAGE="${USAGE}\tOmitting this results in encoding to flac.\n" |
|
||||
USAGE="${USAGE}\tmp3s will be placed under a subfolder mp3 and flacs\n" |
|
||||
USAGE="${USAGE}\tunder a subfolder flac\n" |
|
||||
USAGE="${USAGE} -p :\tspecifies the path to save the encoded data.\n" |
|
||||
USAGE="${USAGE}\tDefaults to the users home directory.\n" |
|
||||
USAGE="${USAGE} -e :\tspecifies the mp3 encoder to use.\n" |
|
||||
USAGE="${USAGE}\tvalid encoders are actually: lame,bladeenc\n" |
|
||||
USAGE="${USAGE}\tDefaults to lame.\n" |
|
||||
USAGE="${USAGE} -c :\tspecifies the CDDB-Entry to use.\n" |
|
||||
USAGE="${USAGE}\tsometimes there is more than 1 entry for a cd in cddb.\n" |
|
||||
USAGE="${USAGE}\tThen you can specify wich one to use by this option.\n" |
|
||||
USAGE="${USAGE}\tYou can checkout all entries using cddb.pl.\n" |
|
||||
USAGE="${USAGE} -h :\tShows this help." |
|
||||
|
|
||||
HAS_DELIMITER=0 |
|
||||
TA_ORDER="t" |
|
||||
ENCODING_DIR=$HOME |
|
||||
ENCODING_TYPE="f" |
|
||||
ENCODER="lame" |
|
||||
CDDB_ENTRY=1 |
|
||||
|
|
||||
while getopts d:o:t:p:he:c: option |
|
||||
|
#!/bin/bash |
||||
|
|
||||
|
# === some global setting & configurations for the script === |
||||
|
umask 000 # create files with all right for anyone |
||||
|
shopt -s nullglob # expand patterns which match no file to a null string |
||||
|
shopt -s extdebug |
||||
|
|
||||
|
# -------------------------------------------------------------- |
||||
|
# das Verzeichnis in dem dieses script liegt herausfinden |
||||
|
scriptDir=${0%/*} |
||||
|
scriptDir="${scriptDir/#\./${PWD}}" |
||||
|
case "${scriptDir}" in /*);; *) scriptDir="${PWD}/${scriptDir}";; esac |
||||
|
# -------------------------------------------------------------- |
||||
|
|
||||
|
# include helpers |
||||
|
. ${scriptDir}/shellUtils.sh |
||||
|
|
||||
|
# -------------------------------------------------------------- |
||||
|
# string definitions |
||||
|
usage=$"usage: $0 [-t {m|f|o}] [-p path] [-e encoder] [-c cddb-entry] [-h|-?] |
||||
|
[-I interface] [-D device] [-v[v]] |
||||
|
\t-t: you can specify either m for encoding to mp3 |
||||
|
\t using lame, or f for making lossless encoding using flac, |
||||
|
\t or o for making ogg/vorbis, or w for uncompressed wav. |
||||
|
\t Omitting this results in encoding to flac. |
||||
|
\t mp3s will be placed under a subfolder mp3 and flacs |
||||
|
\t under a subfolder flac |
||||
|
\t-p: specifies the path to save the encoded data. |
||||
|
\t Defaults to the users home directory. |
||||
|
\t-e: specifies the mp3 encoder to use. |
||||
|
\t valid encoders are actually: lame,bladeenc |
||||
|
\t Defaults to lame. |
||||
|
\t-c: specifies the CDDB-Entry to use. |
||||
|
\t sometimes there is more than 1 entry for a cd in cddb. |
||||
|
\t Then you can specify wich one to use by this option. |
||||
|
\t You can checkout all entries using cddb.pl. |
||||
|
\t-I: specifies cdda2wav interface to use. |
||||
|
\t Valid interfaces are generic_scsi and cooked_ioctl. |
||||
|
\t Please note that cooked_ioctl is not available on all systems. |
||||
|
\t Defaults to generic_scsi |
||||
|
\t-D: specifies device to use with cdda2wav. |
||||
|
\t Defaults to /dev/cdrom |
||||
|
\t-v: make the script more verbose. The verbosity level defaults |
||||
|
\t to 1. When -v is given the level is 2 and -vv increases the |
||||
|
\t level to 3, what means give debug output. |
||||
|
\t-q: make the script silent. Equivalent to -v0 |
||||
|
\t-h| |
||||
|
\t-?: Shows this help." |
||||
|
|
||||
|
ready=$"done" |
||||
|
|
||||
|
# level 1 messages |
||||
|
getCDInfoMsg=$"getting cd info..." |
||||
|
outputDirMsg=$"output to: \$encodingDir" |
||||
|
createXmlMsg=$"create xml file..." |
||||
|
startRipMsg1=$"start ripping cd audio data..." |
||||
|
|
||||
|
# level 2 messages |
||||
|
encodeMp3Msg=$"Encode to mp3" |
||||
|
encodeFlacMsg=$"Encode to flac" |
||||
|
encodeOggMsg=$"Encode to ogg" |
||||
|
encodeWavMsg=$"Encode to wav" |
||||
|
startRipMsg2=$"start ripping cd audio data:" |
||||
|
|
||||
|
cdInfoMsg=$"DISK: |
||||
|
===== |
||||
|
Tracks: \$dTracks |
||||
|
Length: \$dLength |
||||
|
Index: \$dIndex |
||||
|
Artist: \$dArtist |
||||
|
Title: \$dTitle |
||||
|
Year: \$dYear |
||||
|
Genre: \$dGenre |
||||
|
CDDB: \$cddbId |
||||
|
Text: \$dText |
||||
|
Extra: \$dExtra |
||||
|
|
||||
|
TRACKS: |
||||
|
=======" |
||||
|
# -------------------------------------------------------------- |
||||
|
|
||||
|
taOrder="t" |
||||
|
encodingDir=$HOME |
||||
|
encodingType="f" |
||||
|
encoder="lame" |
||||
|
cddbEntry=1 |
||||
|
cddaIf="generic_scsi" |
||||
|
cddaDev="/dev/cdrom" |
||||
|
verbose=1 |
||||
|
|
||||
|
# ---------------------------------------------------------------- |
||||
|
# get commandline options |
||||
|
while getopts qvt:p:he:c:I:D: option |
||||
do |
do |
||||
case $option in |
case $option in |
||||
d) if [ ${#OPTARG} -gt 1 ] |
|
||||
|
t) |
||||
|
if [ "${OPTARG}" != "m" -a "${OPTARG}" != "f" -a \ |
||||
|
"${OPTARG}" != "o" -a "${OPTARG}" != "w" ] |
||||
|
then |
||||
|
echo -e "$usage" |
||||
|
exit 1 |
||||
|
fi |
||||
|
encodingType=$OPTARG |
||||
|
;; |
||||
|
p) |
||||
|
if [ ! \( -d ${OPTARG} \) ] |
||||
then |
then |
||||
echo -e "$USAGE" |
|
||||
|
echo -e "$usage" |
||||
exit 1 |
exit 1 |
||||
fi |
fi |
||||
HAS_DELIMITER=1 |
|
||||
TA_DELIMITER=$OPTARG |
|
||||
|
encodingDir=$OPTARG |
||||
;; |
;; |
||||
o) if [ \( "${OPTARG}" != "t" -a "${OPTARG}" != "a" \) -o \ |
|
||||
${HAS_DELIMITER} -eq 0 ] |
|
||||
|
e) |
||||
|
if [ -z ${OPTARG} ] |
||||
then |
then |
||||
echo -e "$USAGE" |
|
||||
|
echo -e "$usage" |
||||
exit 1 |
exit 1 |
||||
fi |
fi |
||||
TA_ORDER=$OPTARG |
|
||||
|
encoder=$OPTARG |
||||
;; |
;; |
||||
t) if [ ${OPTARG} != "m" -a ${OPTARG} != "f" -a ${OPTARG} != "o" -a \ |
|
||||
${OPTARG} != "w" ] |
|
||||
|
c) |
||||
|
if [ ${OPTARG} -lt 1 ] |
||||
then |
then |
||||
echo -e "$USAGE" |
|
||||
|
echo -e "$usage" |
||||
exit 1 |
exit 1 |
||||
fi |
fi |
||||
ENCODING_TYPE=$OPTARG |
|
||||
|
cddbEntry=$OPTARG |
||||
;; |
;; |
||||
p) if [ ! \( -d ${OPTARG} \) ] |
|
||||
|
v) |
||||
|
if [ "${OPTARG}" -a "${OPTARG}" != "0" -a "${OPTARG}" != "v" ] |
||||
then |
then |
||||
echo -e "$USAGE" |
|
||||
|
echo -e "$usage" |
||||
exit 1 |
exit 1 |
||||
fi |
fi |
||||
ENCODING_DIR=$OPTARG |
|
||||
|
test -z "${OPTARG}" && verbose=2 |
||||
|
test "${OPTARG}" = "0" && verbose=0 |
||||
|
test "${OPTARG}" = "v" && verbose=3 |
||||
;; |
;; |
||||
e) if [ -z ${OPTARG} ] |
|
||||
|
q) |
||||
|
verbose=0 |
||||
|
;; |
||||
|
I) |
||||
|
if [ "${OPTARG}" != "generic_scsi" -a \ |
||||
|
"${OPTARG}" != "cooked_ioctl" ] |
||||
then |
then |
||||
echo -e "$USAGE" |
|
||||
|
echo -e "$usage" |
||||
exit 1 |
exit 1 |
||||
fi |
fi |
||||
ENCODER=$OPTARG |
|
||||
|
cddaIf=$OPTARG |
||||
;; |
;; |
||||
c) if [ ${OPTARG} -lt 1 ] |
|
||||
|
D) |
||||
|
if [ ${OPTARG} -lt 1 ] |
||||
then |
then |
||||
echo -e "$USAGE" |
|
||||
|
echo -e "$usage" |
||||
exit 1 |
exit 1 |
||||
fi |
fi |
||||
CDDB_ENTRY=$OPTARG |
|
||||
|
cddaDev=$OPTARG |
||||
;; |
;; |
||||
[h\?]) echo -e "$USAGE" |
|
||||
|
[h\?]) |
||||
|
echo -e "$usage" |
||||
exit 1 |
exit 1 |
||||
;; |
;; |
||||
esac |
esac |
||||
done |
done |
||||
|
# ---------------------------------------------------------------- |
||||
|
|
||||
|
echo "verbose: $verbose" |
||||
|
|
||||
|
# ---------------------------------------------------------------- |
||||
|
# set encodingDir for used encodingType |
||||
|
case ${encodingType} in |
||||
|
m) |
||||
|
encodingDir="$encodingDir/mp3" |
||||
|
test ${verbose} -ge 2 && echo ${encodeMp3Msg} |
||||
|
;; |
||||
|
f) |
||||
|
encodingDir="$encodingDir/flac" |
||||
|
test ${verbose} -ge 2 && echo ${encodeFlacMsg} |
||||
|
;; |
||||
|
o) |
||||
|
encodingDir="$encodingDir/ogg" |
||||
|
test ${verbose} -ge 2 && echo ${encodeOggMsg} |
||||
|
;; |
||||
|
w) |
||||
|
encodingDir="$encodingDir/wav" |
||||
|
test ${verbose} -ge 2 && echo ${encodeWavMsg} |
||||
|
;; |
||||
|
esac |
||||
|
# ---------------------------------------------------------------- |
||||
|
|
||||
test "$ENCODING_TYPE" = "m" && ENCODING_DIR="$ENCODING_DIR/mp3" |
|
||||
test "$ENCODING_TYPE" = "f" && ENCODING_DIR="$ENCODING_DIR/flac" |
|
||||
test "$ENCODING_TYPE" = "o" && ENCODING_DIR="$ENCODING_DIR/ogg" |
|
||||
test "$ENCODING_TYPE" = "w" && ENCODING_DIR="$ENCODING_DIR/wav" |
|
||||
|
|
||||
indices[0]="album" |
|
||||
indices[1]="artist" |
|
||||
indices[2]="genre" |
|
||||
indices[3]="year" |
|
||||
indices[4]="comment" |
|
||||
|
|
||||
i=1 |
|
||||
max_track=30 |
|
||||
|
|
||||
while [ $i -le $max_track ]; do |
|
||||
indices[`expr \( $i \- 1 \) \* 2 \+ 5`]="`echo $i | \ |
|
||||
sed 's/^\([0-9]\)$/0\1/g;\ |
|
||||
s/\(.*\)/track-\1/g'`" |
|
||||
indices[`expr \( $i \- 1 \) \* 2 \+ 6`]="`echo $i | \ |
|
||||
sed 's/^\([0-9]\)$/0\1/g;\ |
|
||||
s/\(.*\)/tartist-\1/g'`" |
|
||||
i=`expr $i \+ 1` |
|
||||
|
test ${verbose} -ge 1 && echo -n ${getCDInfoMsg} |
||||
|
getCDInfo # gets all info about the CD. Look in shellUtils for more info. |
||||
|
test ${verbose} -ge 1 && echo ${ready} |
||||
|
|
||||
|
if [ ${verbose} -ge 2 ] |
||||
|
then |
||||
|
cat <<-EOF |
||||
|
$cdInfoMsg |
||||
|
EOF |
||||
|
|
||||
|
i=0 |
||||
|
while [ $i -lt ${#tTitle[@]} ] |
||||
|
do |
||||
|
echo -n "${tArtist[$i]} - ${tTitle[$i]} " |
||||
|
echo "([${tStartSec[$i]}-${tEndSec[$i]}] ${tLength[$i]})" |
||||
|
i=$((i+1)) |
||||
done |
done |
||||
|
fi |
||||
|
|
||||
|
encodingDir="${encodingDir}/${dArtist}/${dTitle}" |
||||
|
mkdir -p "${encodingDir}" |
||||
|
test ${verbose} -ge 1 && eval "echo ${outputDirMsg}" |
||||
|
|
||||
|
# ---------------------------------------------------------------- |
||||
|
# fill xml file with data |
||||
|
test ${verbose} -ge 1 && echo -n "${createXmlMsg}" |
||||
|
|
||||
comment="" |
|
||||
|
xmlFile="${encodingDir}/cdinfo.xml" |
||||
|
xml_dText="`echo "${dText}" | recode utf8..h0`" |
||||
|
xml_dExtra="`echo "${dExtra}" | recode utf8..h0`" |
||||
|
xml_dArtist="`echo "${dArtist}" | recode utf8..h0`" |
||||
|
xml_dTitle="`echo "${dTitle}" | recode utf8..h0`" |
||||
|
cat >"${xmlFile}" <<EOF |
||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE cdInfo SYSTEM \"cdInfo.dtd\"> |
||||
|
<cdinfo> |
||||
|
<cdindex>${dIndex}</cdindex> |
||||
|
<cddb>${cddbId}</cddb> |
||||
|
<cd-text>${xml_dText}</cd-text> |
||||
|
<cd-extra>${xml_dExtra}</cd-extra> |
||||
|
<cd-artist>${xml_dArtist}</cd-artist> |
||||
|
<cd-title>${xml_dTitle}</cd-title> |
||||
|
<cd-year>${dYear}</cd-year> |
||||
|
<cd-genre>${dGenre}</cd-genre> |
||||
|
<cd-time>${dLength}</cd-time> |
||||
|
<cd-tracks>${dTracks}</cd-tracks> |
||||
|
<cd-comment></cd-comment> |
||||
|
EOF |
||||
|
|
||||
function idxof() { |
|
||||
str=$1 |
|
||||
idx=0 |
|
||||
|
i=0 |
||||
|
while [ $i -lt ${#tTitle[@]} ] |
||||
|
do |
||||
|
trackNr="`printf %02d $((i+1))`" |
||||
|
xml_tTitle="`echo ${tTitle[$i]} | recode utf8..h0`" |
||||
|
xml_tArtist="`echo ${tArtist[$i]} | recode utf8..h0`" |
||||
|
trackEnd=${tEndSec[$i]} |
||||
|
trackStart=${tStartSec[$i]} |
||||
|
trackLen=$((trackEnd-$trackStart)) |
||||
|
|
||||
|
cat >>"${xmlFile}" <<EOF |
||||
|
<track> |
||||
|
<track-number>$trackNr</track-number> |
||||
|
<track-time>${tLength[$i]}</track-time> |
||||
|
<track-start-sector>${tStartSec[$i]}</track-start-sector> |
||||
|
<track-length>${trackLen}</track-length> |
||||
|
<track-artist>$xml_tArtist</track-artist> |
||||
|
<track-title>$xml_tTitle</track-title> |
||||
|
<track-comment></track-comment> |
||||
|
</track> |
||||
|
EOF |
||||
|
|
||||
for i in "${indices[@]}"; do |
|
||||
test "$i" == "$str" && echo $idx && return 0 |
|
||||
idx=`expr $idx \+ 1` |
|
||||
|
i=$((i+1)) |
||||
done |
done |
||||
|
|
||||
echo -1 |
|
||||
return 0 |
|
||||
} |
|
||||
|
echo "</cdinfo>" >>"${xmlFile}" |
||||
|
|
||||
title_pat="/^[^:]*: *(.*[^ ]).*/" |
|
||||
artist_pat="//" |
|
||||
|
test ${verbose} -ge 1 && echo "${ready}" |
||||
|
# ---------------------------------------------------------------- |
||||
|
|
||||
if [ $HAS_DELIMITER -ne 0 ] |
|
||||
then |
|
||||
if [ $TA_ORDER == "t" ] |
|
||||
then |
|
||||
title_pat="/^[^:]*: *([^\\${TA_DELIMITER}]*[^ \\${TA_DELIMITER}]).*/" |
|
||||
artist_pat="/^[^:]*: *[^\\${TA_DELIMITER}]*\\${TA_DELIMITER} *(.*[^ ]).*/" |
|
||||
else |
|
||||
artist_pat="/^[^:]*: *([^\\${TA_DELIMITER}]*[^ \\${TA_DELIMITER}]).*/" |
|
||||
title_pat="/^[^:]*: *[^\\${TA_DELIMITER}]*\\${TA_DELIMITER} *(.*[^ ]).*/" |
|
||||
fi |
|
||||
fi |
|
||||
|
# ---------------------------------------------------------------- |
||||
|
# now do the ripping |
||||
|
test ${verbose} -eq 1 && echo -n "${startRipMsg1}" |
||||
|
test ${verbose} -ge 2 && echo "${startRipMsg2}" |
||||
|
|
||||
echo "Preparing...." |
|
||||
|
|
||||
echo -n "getting cddb info..." |
|
||||
eval "`cddb.pl -e $CDDB_ENTRY | sed 's/ \([0-9]\):/ 0\1:/g;s/track /track-/g' |\ |
|
||||
awk -v has_delimiter=$HAS_DELIMITER \ |
|
||||
'/artist/||/title/||/genre/||/year/ { \ |
|
||||
cddb[gensub(/^([^:]*):.*/, \"\\\\1\", \"1\")]=\ |
|
||||
gensub(/^[^:]*: *(.*[^ ]).*/, \"\\\\1\", \"g\")\ |
|
||||
} \ |
|
||||
/trackno/ {\ |
|
||||
trackno=int(gensub(/^trackno: *([0-9]*).*/, \"\\\\1\", \"1\"))\ |
|
||||
}\ |
|
||||
/track-/ {\ |
|
||||
cddb[gensub(/^([^:]*):.*/, \"\\\\1\", \"1\")]=\ |
|
||||
gensub('\"$title_pat\"', \"\\\\1\", \"1\");\ |
|
||||
if(has_delimiter==0) \ |
|
||||
cddb[gensub(/^track([^:]*):.*/, \"tarti\\\\1\", \"1\")]=\ |
|
||||
cddb[\"artist\"]; \ |
|
||||
else \ |
|
||||
cddb[gensub(/^track([^:]*):.*/, \"tarti\\\\1\", \"1\")]=\ |
|
||||
gensub('\"$artist_pat\"', \"\\\\1\", \"1\");\ |
|
||||
} \ |
|
||||
END {\ |
|
||||
cddb_str=\"cddb=(\\\"\" cddb[\"title\"] \"\\\" \\\"\" \ |
|
||||
cddb[\"artist\"] \"\\\" \\\"\" \ |
|
||||
cddb[\"genre\"] \"\\\" \\\"\" \ |
|
||||
cddb[\"year\"] \"\\\" \\\"'$comment'\\\"\"; \ |
|
||||
for(i=1; i<=trackno; i++) {\ |
|
||||
cddb_str=cddb_str \" \\\"\" \ |
|
||||
cddb[\"track-\" sprintf(\"%02s\", i)] \"\\\"\";\ |
|
||||
cddb_str=cddb_str \" \\\"\" \ |
|
||||
cddb[\"tarti-\" sprintf(\"%02s\", i)] \"\\\"\"\ |
|
||||
}\ |
|
||||
print cddb_str \")\"\ |
|
||||
}'`" |
|
||||
echo "done" |
|
||||
|
|
||||
echo -n "getting CD info..." |
|
||||
cddainfo=`cdda2wav -H -D/dev/cdrom -J -v summary,toc,sectors 2>&1` |
|
||||
echo "done" |
|
||||
|
|
||||
track_num=`echo "$cddainfo" | \ |
|
||||
sed '/tracks/{s/^.*tracks:\([0-9]*\).*$/\1/g;p};d'` |
|
||||
cd_time=`echo "$cddainfo" | \ |
|
||||
sed '/tracks/{s/^.*time \([0-9:\.]*\).*$/\1/g;p};d'` |
|
||||
cddbid=`echo "$cddainfo" | \ |
|
||||
sed '/CDDB/{s/^.*discid: *\(0x[a-z0-9]*[^ ]\).*/\1/g;p};d'` |
|
||||
cdindex=`echo "$cddainfo" | \ |
|
||||
sed '/CDINDEX/{s/^.*discid: *\([a-zA-Z0-9_\.]*-\).*/\1/g;p};d'` |
|
||||
cdtext=`echo "$cddainfo" | sed '/CD-Text/{s/^[^:]*: *\(.*[^ ]\).*/\1/g |
|
||||
s/&/\&\;/g;s/\"/\"\;/g |
|
||||
s/</\<\;/g;s/>/\>\;/g |
|
||||
s/\o47/\&apos\;/g |
|
||||
p};d'` |
|
||||
cdextra=`echo "$cddainfo" | sed '/CD-Extra/{s/^[^:]*: *\(.*[^ ]\).*/\1/g |
|
||||
s/&/\&\;/g;s/\"/\"\;/g |
|
||||
s/</\<\;/g;s/>/\>\;/g |
|
||||
s/\o47/\&apos\;/g |
|
||||
p};d'` |
|
||||
|
|
||||
ENCODING_DIR="${ENCODING_DIR}/${cddb[`idxof "artist"`]}/" |
|
||||
ENCODING_DIR="${ENCODING_DIR}${cddb[`idxof "album"`]}/" |
|
||||
mkdirhier "$ENCODING_DIR" |
|
||||
echo "Output directory is: $ENCODING_DIR" |
|
||||
|
|
||||
xmlfile="${ENCODING_DIR}cdinfo.xml" |
|
||||
|
|
||||
# some special chars within xml must be converted to special syntax |
|
||||
# & => & |
|
||||
# " => " |
|
||||
# ' => ' |
|
||||
# < => < |
|
||||
# > => > |
|
||||
xmlartist=`echo ${cddb[\`idxof "artist"\`]} | \ |
|
||||
sed 's/&/\&\;/g |
|
||||
s/</\<\;/g |
|
||||
s/>/\>\;/g |
|
||||
s/\"/\"\;/g |
|
||||
s/\o47/\&apos\;/g'` |
|
||||
xmlalbum=`echo ${cddb[\`idxof "album"\`]} | \ |
|
||||
sed 's/&/\&\;/g |
|
||||
s/</\<\;/g |
|
||||
s/>/\>\;/g |
|
||||
s/\"/\"\;/g |
|
||||
s/\o47/\&apos\;/g'` |
|
||||
|
|
||||
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>" > "${xmlfile}" |
|
||||
echo "<!DOCTYPE cdInfo SYSTEM \"cdInfo.dtd\">" >> "${xmlfile}" |
|
||||
echo "<cdinfo>" >> "${xmlfile}" |
|
||||
echo " <cdindex>$cdindex</cdindex>" >> "${xmlfile}" |
|
||||
echo " <cddb>$cddbid</cddb>" >> "${xmlfile}" |
|
||||
echo " <cd-text>$cdtext</cd-text>" >> "${xmlfile}" |
|
||||
echo " <cd-extra>$cdextra</cd-extra>" >> "${xmlfile}" |
|
||||
echo " <cd-artist>${xmlartist}</cd-artist>" >> "${xmlfile}" |
|
||||
echo " <cd-title>${xmlalbum}</cd-title>" >> "${xmlfile}" |
|
||||
echo " <cd-year>${cddb[`idxof "year"`]}</cd-year>" >> "${xmlfile}" |
|
||||
echo " <cd-genre>${cddb[`idxof "genre"`]}</cd-genre>" >> "${xmlfile}" |
|
||||
echo " <cd-time>$cd_time</cd-time>" >> "${xmlfile}" |
|
||||
echo " <cd-tracks>$track_num</cd-tracks>" >> "${xmlfile}" |
|
||||
echo " <cd-comment></cd-comment>" >> "${xmlfile}" |
|
||||
|
|
||||
i=1; while [ $i -le $track_num ] |
|
||||
|
i=0 |
||||
|
while [ $i -lt ${#tTitle[@]} ] |
||||
do |
do |
||||
j=`expr $i \+ 1` |
|
||||
tracknr=`awk 'BEGIN{printf("%02d\n",'$i')}'` |
|
||||
track=${cddb[`idxof "track-$tracknr"`]} |
|
||||
tartist=${cddb[`idxof "tartist-$tracknr"`]} |
|
||||
|
|
||||
xmltrack=`echo ${track} | sed 's/&/\&\;/g |
|
||||
s/</\<\;/g |
|
||||
s/>/\>\;/g |
|
||||
s/\"/\"\;/g |
|
||||
s/\o47/\&apos\;/g'` |
|
||||
xmltartist=`echo ${tartist} | sed 's/&/\&\;/g |
|
||||
s/</\<\;/g |
|
||||
s/>/\>\;/g |
|
||||
s/\"/\"\;/g |
|
||||
s/\o47/\&apos\;/g'` |
|
||||
|
|
||||
tracklen=`echo "$cddainfo" | \ |
|
||||
sed '/ '"$i"'\.([0-9 ]*:/{s/.*'"$i"'\.( *\([0-9:\.]*\)).*/\1/g;p};d'` |
|
||||
trackstart=`echo "$cddainfo" | \ |
|
||||
sed '/ '"$i"'\.([0-9 ]*)/{s/.*'"$i"'\.( *\([0-9]*\)).*/\1/g;p};d'` |
|
||||
test $i -eq $track_num && \ |
|
||||
trackend=`echo "$cddainfo" | \ |
|
||||
sed '/ lead-out([0-9 ]*)/{s/.*lead-out( *\([0-9]*\)).*/\1/g;p};d'` || \ |
|
||||
trackend=`echo "$cddainfo" | \ |
|
||||
sed '/ '"$j"'\.([0-9 ]*)/{s/.*'"$j"'\.( *\([0-9]*\)).*/\1/g;p};d'` |
|
||||
|
|
||||
echo " <track>" >> "${xmlfile}" |
|
||||
echo " <track-number>$i</track-number>" >> "${xmlfile}" |
|
||||
echo " <track-time>$tracklen</track-time>" >> "${xmlfile}" |
|
||||
echo " <track-start-sector>$trackstart</track-start-sector>" >> "${xmlfile}" |
|
||||
echo " <track-length>`expr $trackend \- $trackstart`</track-length>" >> "${xmlfile}" |
|
||||
echo " <track-artist>$xmltartist</track-artist>" >> "${xmlfile}" |
|
||||
echo " <track-title>$xmltrack</track-title>" >> "${xmlfile}" |
|
||||
echo " <track-comment></track-comment>" >> "${xmlfile}" |
|
||||
echo " </track>" >> "${xmlfile}" |
|
||||
|
|
||||
# outfile="${ENCODING_DIR}The Wall/Disk2/" |
|
||||
outfile="${ENCODING_DIR}${tracknr}-${track}" |
|
||||
|
|
||||
test "$ENCODING_TYPE" = "f" && \ |
|
||||
outstr="track-$tracknr => ${tracknr}-${track}.flac" |
|
||||
test "$ENCODING_TYPE" = "m" && \ |
|
||||
outstr="track-$tracknr => ${tracknr}-${track}.mp3" |
|
||||
test "$ENCODING_TYPE" = "o" && \ |
|
||||
outstr="track-$tracknr => ${tracknr}-${track}.ogg" |
|
||||
test "$ENCODING_TYPE" = "w" && \ |
|
||||
outstr="track-$tracknr => ${tracknr}-${track}.wav" |
|
||||
|
|
||||
if [ "$ENCODING_TYPE" = "f" ] |
|
||||
then |
|
||||
bash -c "exec 2>&1;\ |
|
||||
cdda2wav -H -D/dev/cdrom -H -t$i - | \ |
|
||||
flac -c \ |
|
||||
-T artist=\"${tartist}\" -T album=\"${cddb[`idxof "album"`]}\" \ |
|
||||
-T genre=\"${cddb[`idxof "genre"`]}\" -T title=\"${track}\" \ |
|
||||
-T tnum=\"`expr ${tracknr} \+ 0`\" -T date=\"${cddb[`idxof "year"`]}\" \ |
|
||||
-T comment=\"${cddb[`idxof "comment"`]}\" \ |
|
||||
-o \"${outfile}.flac\" - 2>/dev/null" | rton | \ |
|
||||
awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}' |
|
||||
fi |
|
||||
if [ "$ENCODING_TYPE" = "m" -a "$ENCODER" = "lame" ] |
|
||||
then |
|
||||
bash -c "exec 2>&1;\ |
|
||||
cdda2wav -H -D/dev/cdrom -t$i - | \ |
|
||||
lame -h \ |
|
||||
--ta \"${tartist}\" --tl \"${cddb[`idxof "album"`]}\" \ |
|
||||
--tg \"${cddb[`idxof "genre"`]}\" --tt \"${track}\" \ |
|
||||
--tn \"`expr ${tracknr} \+ 0`\" --ty \"${cddb[`idxof "year"`]}\" \ |
|
||||
--tc \"${cddb[`idxof "comment"`]}\" \ |
|
||||
- \"${outfile}.mp3\" 2>/dev/null" | rton | \ |
|
||||
awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}' |
|
||||
fi |
|
||||
if [ "$ENCODING_TYPE" = "m" -a "$ENCODER" = "bladeenc" ] |
|
||||
then |
|
||||
bash -c "exec 2>&1;\ |
|
||||
cdda2wav -H -D/dev/cdrom -t$i - | \ |
|
||||
bladeenc -progress=0 STDIN \"${outfile}.mp3\" 2>/dev/null" | rton | \ |
|
||||
awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}' |
|
||||
fi |
|
||||
if [ "$ENCODING_TYPE" = "o" ] |
|
||||
then |
|
||||
bash -c "exec 2>&1;\ |
|
||||
cdda2wav -H -D/dev/cdrom -t$i - | \ |
|
||||
oggenc -a \"${tartist}\" -l \"${cddb[`idxof "album"`]}\" \ |
|
||||
-G \"${cddb[`idxof "genre"`]}\" -t \"${track}\" \ |
|
||||
-N \"`expr ${tracknr} \+ 0`\" -d \"${cddb[`idxof "year"`]}\" \ |
|
||||
-c \"${cddb[`idxof "comment"`]}\" \ |
|
||||
-o \"${outfile}.ogg\" - 2>/dev/null" | rton | \ |
|
||||
awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}' |
|
||||
fi |
|
||||
if [ "$ENCODING_TYPE" = "w" ] |
|
||||
|
trackNr=$((i+1)) |
||||
|
|
||||
|
# now that i don't forget it again. I use tr to translate \r to \n |
||||
|
# because sed does't recognise a line with only \r at its end as a line. |
||||
|
# Therefor sed reads until output of cdda2wav ends and does all the |
||||
|
# processing at once, so the percentage is not shown correctly |
||||
|
if [ ${verbose} -ge 2 ] |
||||
then |
then |
||||
bash -c "exec 2>&1;\ |
|
||||
cdda2wav -H -D/dev/cdrom -t$i - > \"${outfile}.wav\"" | rton | \ |
|
||||
awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}' |
|
||||
|
outCmd="tr '\r' '\n' | |
||||
|
sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'\"\${outStr}\"'\1/' | |
||||
|
tr -d '\n'" |
||||
|
else |
||||
|
outCmd="cat >/dev/null" |
||||
fi |
fi |
||||
|
|
||||
i=`expr $i + 1` |
|
||||
|
case ${encodingType} in |
||||
|
f) |
||||
|
outFile="`printf %02d ${trackNr}`-${tTitle[$i]}.flac" |
||||
|
outStr="track-$trackNr => ${outFile}: " |
||||
|
|
||||
|
( |
||||
|
exec 2>&1 |
||||
|
cdda2wav -H -D/dev/cdrom -I${cddaIf} -t${trackNr} - |\ |
||||
|
flac -c -f \ |
||||
|
-T artist="${tArtist[$i]}" -T album="${dTitle}" \ |
||||
|
-T genre="${dGenre}" -T title="${tTitle[$i]}" \ |
||||
|
-T tracknumber="${trackNr}" -T tracknum="${trackNr}" \ |
||||
|
-T date="${dYear}" -T comment="" \ |
||||
|
-o "${encodingDir}/${outFile}" - 2>/dev/null |
||||
|
) | $outCmd |
||||
|
;; |
||||
|
m) |
||||
|
outFile="`printf %02d ${trackNr}`-${tTitle[$i]}.mp3" |
||||
|
outStr="track-$trackNr => ${outFile}: " |
||||
|
|
||||
|
case ${encoder} in |
||||
|
lame) |
||||
|
( |
||||
|
exec 2>&1 |
||||
|
cdda2wav -H -D/dev/cdrom -I${cddaIf} -t${trackNr} - |\ |
||||
|
lame -V2 \ |
||||
|
--ta "${tArtist[$i]}" --tl "${dTitle}" \ |
||||
|
--tg "${dGenre}" --tt "${tTitle[$i]}" \ |
||||
|
--tn "${trackNr}" --ty "${dYear}" \ |
||||
|
--tc "" \ |
||||
|
- "${encodingDir}/${outFile}" 2>/dev/null |
||||
|
) | tr '\r' '\n' |\ |
||||
|
sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ |
||||
|
tr -d '\n' |
||||
|
;; |
||||
|
bladeenc) |
||||
|
( |
||||
|
exec 2>&1 |
||||
|
cdda2wav -H -D/dev/cdrom -I${cddaIf} -t${trackNr} - |\ |
||||
|
bladeenc -progress=0 STDIN \ |
||||
|
"${encodingDir}/${outFile}" 2>/dev/null |
||||
|
) | tr '\r' '\n' |\ |
||||
|
sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ |
||||
|
tr -d '\n' |
||||
|
;; |
||||
|
esac |
||||
|
;; |
||||
|
o) |
||||
|
outFile="`printf %02d ${trackNr}`-${tTitle[$i]}.ogg" |
||||
|
outStr="track-$trackNr => ${outFile}: " |
||||
|
|
||||
|
( |
||||
|
exec 2>&1 |
||||
|
cdda2wav -H -D/dev/cdrom -I${cddaIf} -t${trackNr} - |\ |
||||
|
oggenc -a "${tArtist[$i]}" -l "${dTitle}" \ |
||||
|
-G "${dGenre}" -t "${tTitle[$i]}" \ |
||||
|
-N "${trackNr}" -d "${dYear}" \ |
||||
|
-c "" \ |
||||
|
-o "${encodingDir}/${outFile}" - 2>/dev/null |
||||
|
) | tr '\r' '\n' |\ |
||||
|
sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ |
||||
|
tr -d '\n' |
||||
|
;; |
||||
|
w) |
||||
|
outFile="`printf %02d ${trackNr}`-${tTitle[$i]}.wav" |
||||
|
outStr="track-$trackNr => ${outFile}: " |
||||
|
|
||||
|
( |
||||
|
exec 2>&1 |
||||
|
cdda2wav -H -D/dev/cdrom -I${cddaIf} -t${trackNr} - >\ |
||||
|
"${encodingDir}/${outFile}" |
||||
|
) | tr '\r' '\n' |\ |
||||
|
sed '/^ [0-9]/!d;s/^.* \([0-9]*%\).*$/\r'"${outStr}"'\1/' |\ |
||||
|
tr -d '\n' |
||||
|
;; |
||||
|
esac |
||||
|
|
||||
|
echo # do a newline after each file |
||||
|
i=$((i+1)) |
||||
done |
done |
||||
|
|
||||
echo "</cdinfo>" >> "${xmlfile}" |
|
||||
|
test ${verbose} -eq 1 && echo "${ready}" |
||||
|
# ---------------------------------------------------------------- |
||||
@ -1,350 +0,0 @@ |
|||||
USAGE="usage: $0 [-d delimiter [-o {t|a}]] [-t {m|f|o}] [-p path] [-e encoder] [-c cddb-entry] [-h]\n" |
|
||||
USAGE="${USAGE} -d :\tA single character delimiting trackname from\n" |
|
||||
USAGE="${USAGE}\tartistname with sampler cds\n\n" |
|
||||
USAGE="${USAGE} -o :\tspecifies if theres the track or the artist first\n" |
|
||||
USAGE="${USAGE}\tMust be:\n" |
|
||||
USAGE="${USAGE}\t t for titel first or\n" |
|
||||
USAGE="${USAGE}\t a for artist first\n" |
|
||||
USAGE="${USAGE}\tIf there is none specified t is assumed\n" |
|
||||
USAGE="${USAGE} -t :\tyou can specify either m for encoding to mp3\n" |
|
||||
USAGE="${USAGE}\tusing lame, or f for making lossless encoding using flac,\n" |
|
||||
USAGE="${USAGE}\tor o for making ogg/vorbis, or w for uncompressed wav.\n" |
|
||||
USAGE="${USAGE}\tOmitting this results in encoding to flac.\n" |
|
||||
USAGE="${USAGE}\tmp3s will be placed under a subfolder mp3 and flacs\n" |
|
||||
USAGE="${USAGE}\tunder a subfolder flac\n" |
|
||||
USAGE="${USAGE} -p :\tspecifies the path to save the encoded data.\n" |
|
||||
USAGE="${USAGE}\tDefaults to the users home directory.\n" |
|
||||
USAGE="${USAGE} -e :\tspecifies the mp3 encoder to use.\n" |
|
||||
USAGE="${USAGE}\tvalid encoders are actually: lame,bladeenc\n" |
|
||||
USAGE="${USAGE}\tDefaults to lame.\n" |
|
||||
USAGE="${USAGE} -c :\tspecifies the CDDB-Entry to use.\n" |
|
||||
USAGE="${USAGE}\tsometimes there is more than 1 entry for a cd in cddb.\n" |
|
||||
USAGE="${USAGE}\tThen you can specify wich one to use by this option.\n" |
|
||||
USAGE="${USAGE}\tYou can checkout all entries using cddb.pl.\n" |
|
||||
USAGE="${USAGE} -h :\tShows this help." |
|
||||
|
|
||||
PATH="$PATH:." |
|
||||
|
|
||||
HAS_DELIMITER=0 |
|
||||
TA_ORDER="t" |
|
||||
ENCODING_DIR=$HOME |
|
||||
ENCODING_TYPE="f" |
|
||||
ENCODER="lame" |
|
||||
CDDB_ENTRY=1 |
|
||||
|
|
||||
while getopts d:o:t:p:he:c: option |
|
||||
do |
|
||||
case $option in |
|
||||
d) if [ ${#OPTARG} -gt 1 ] |
|
||||
then |
|
||||
echo -e "$USAGE" |
|
||||
exit 1 |
|
||||
fi |
|
||||
HAS_DELIMITER=1 |
|
||||
TA_DELIMITER=$OPTARG |
|
||||
;; |
|
||||
o) if [ \( "${OPTARG}" != "t" -a "${OPTARG}" != "a" \) -o \ |
|
||||
${HAS_DELIMITER} -eq 0 ] |
|
||||
then |
|
||||
echo -e "$USAGE" |
|
||||
exit 1 |
|
||||
fi |
|
||||
TA_ORDER=$OPTARG |
|
||||
;; |
|
||||
t) if [ ${OPTARG} != "m" -a ${OPTARG} != "f" -a ${OPTARG} != "o" -a \ |
|
||||
${OPTARG} != "w" ] |
|
||||
then |
|
||||
echo -e "$USAGE" |
|
||||
exit 1 |
|
||||
fi |
|
||||
ENCODING_TYPE=$OPTARG |
|
||||
;; |
|
||||
p) if [ ! \( -d ${OPTARG} \) ] |
|
||||
then |
|
||||
echo -e "$USAGE" |
|
||||
exit 1 |
|
||||
fi |
|
||||
ENCODING_DIR=$OPTARG |
|
||||
;; |
|
||||
e) if [ -z ${OPTARG} ] |
|
||||
then |
|
||||
echo -e "$USAGE" |
|
||||
exit 1 |
|
||||
fi |
|
||||
ENCODER=$OPTARG |
|
||||
;; |
|
||||
c) if [ ${OPTARG} -lt 1 ] |
|
||||
then |
|
||||
echo -e "$USAGE" |
|
||||
exit 1 |
|
||||
fi |
|
||||
CDDB_ENTRY=$OPTARG |
|
||||
;; |
|
||||
[h\?]) echo -e "$USAGE" |
|
||||
exit 1 |
|
||||
;; |
|
||||
esac |
|
||||
done |
|
||||
|
|
||||
test "$ENCODING_TYPE" = "m" && ENCODING_DIR="$ENCODING_DIR/mp3" |
|
||||
test "$ENCODING_TYPE" = "f" && ENCODING_DIR="$ENCODING_DIR/flac" |
|
||||
test "$ENCODING_TYPE" = "o" && ENCODING_DIR="$ENCODING_DIR/ogg" |
|
||||
test "$ENCODING_TYPE" = "w" && ENCODING_DIR="$ENCODING_DIR/wav" |
|
||||
|
|
||||
indices[0]="album" |
|
||||
indices[1]="artist" |
|
||||
indices[2]="genre" |
|
||||
indices[3]="year" |
|
||||
indices[4]="comment" |
|
||||
|
|
||||
i=1 |
|
||||
max_track=30 |
|
||||
|
|
||||
while [ $i -le $max_track ]; do |
|
||||
indices[`expr \( $i \- 1 \) \* 2 \+ 5`]="`echo $i | \ |
|
||||
sed 's/^\([0-9]\)$/0\1/g;\ |
|
||||
s/\(.*\)/track-\1/g'`" |
|
||||
indices[`expr \( $i \- 1 \) \* 2 \+ 6`]="`echo $i | \ |
|
||||
sed 's/^\([0-9]\)$/0\1/g;\ |
|
||||
s/\(.*\)/tartist-\1/g'`" |
|
||||
i=`expr $i \+ 1` |
|
||||
done |
|
||||
|
|
||||
comment="" |
|
||||
|
|
||||
function idxof() { |
|
||||
str=$1 |
|
||||
idx=0 |
|
||||
|
|
||||
for i in "${indices[@]}"; do |
|
||||
test "$i" == "$str" && echo $idx && return 0 |
|
||||
idx=`expr $idx \+ 1` |
|
||||
done |
|
||||
|
|
||||
echo -1 |
|
||||
return 0 |
|
||||
} |
|
||||
|
|
||||
title_pat="/^[^:]*: *(.*[^ ]).*/" |
|
||||
artist_pat="//" |
|
||||
|
|
||||
if [ $HAS_DELIMITER -ne 0 ] |
|
||||
then |
|
||||
if [ $TA_ORDER == "t" ] |
|
||||
then |
|
||||
title_pat="/^[^:]*: *([^\\${TA_DELIMITER}]*[^ \\${TA_DELIMITER}]).*/" |
|
||||
artist_pat="/^[^:]*: *[^\\${TA_DELIMITER}]*\\${TA_DELIMITER} *(.*[^ ]).*/" |
|
||||
else |
|
||||
artist_pat="/^[^:]*: *([^\\${TA_DELIMITER}]*[^ \\${TA_DELIMITER}]).*/" |
|
||||
title_pat="/^[^:]*: *[^\\${TA_DELIMITER}]*\\${TA_DELIMITER} *(.*[^ ]).*/" |
|
||||
fi |
|
||||
fi |
|
||||
|
|
||||
echo "Preparing...." |
|
||||
|
|
||||
echo -n "getting cddb info..." |
|
||||
eval "`cddb.pl -c /dev/cdrom1 -e $CDDB_ENTRY | sed 's/ \([0-9]\):/ 0\1:/g;s/track /track-/g' |\ |
|
||||
awk -v has_delimiter=$HAS_DELIMITER \ |
|
||||
'/artist/||/title/||/genre/||/year/ { \ |
|
||||
cddb[gensub(/^([^:]*):.*/, \"\\\\1\", \"1\")]=\ |
|
||||
gensub(/^[^:]*: *(.*[^ ]).*/, \"\\\\1\", \"g\")\ |
|
||||
} \ |
|
||||
/trackno/ {\ |
|
||||
trackno=int(gensub(/^trackno: *([0-9]*).*/, \"\\\\1\", \"1\"))\ |
|
||||
}\ |
|
||||
/track-/ {\ |
|
||||
cddb[gensub(/^([^:]*):.*/, \"\\\\1\", \"1\")]=\ |
|
||||
gensub('\"$title_pat\"', \"\\\\1\", \"1\");\ |
|
||||
if(has_delimiter==0) \ |
|
||||
cddb[gensub(/^track([^:]*):.*/, \"tarti\\\\1\", \"1\")]=\ |
|
||||
cddb[\"artist\"]; \ |
|
||||
else \ |
|
||||
cddb[gensub(/^track([^:]*):.*/, \"tarti\\\\1\", \"1\")]=\ |
|
||||
gensub('\"$artist_pat\"', \"\\\\1\", \"1\");\ |
|
||||
} \ |
|
||||
END {\ |
|
||||
cddb_str=\"cddb=(\\\"\" cddb[\"title\"] \"\\\" \\\"\" \ |
|
||||
cddb[\"artist\"] \"\\\" \\\"\" \ |
|
||||
cddb[\"genre\"] \"\\\" \\\"\" \ |
|
||||
cddb[\"year\"] \"\\\" \\\"'$comment'\\\"\"; \ |
|
||||
for(i=1; i<=trackno; i++) {\ |
|
||||
cddb_str=cddb_str \" \\\"\" \ |
|
||||
cddb[\"track-\" sprintf(\"%02s\", i)] \"\\\"\";\ |
|
||||
cddb_str=cddb_str \" \\\"\" \ |
|
||||
cddb[\"tarti-\" sprintf(\"%02s\", i)] \"\\\"\"\ |
|
||||
}\ |
|
||||
print cddb_str \")\"\ |
|
||||
}'`" |
|
||||
echo "done" |
|
||||
|
|
||||
echo -n "getting CD info..." |
|
||||
cddainfo=`cdda2wav -H -D/dev/cdrom1 -J -v summary,toc,sectors 2>&1` |
|
||||
echo "done" |
|
||||
|
|
||||
track_num=`echo "$cddainfo" | \ |
|
||||
sed '/tracks/{s/^.*tracks:\([0-9]*\).*$/\1/g;p};d'` |
|
||||
cd_time=`echo "$cddainfo" | \ |
|
||||
sed '/tracks/{s/^.*time \([0-9:\.]*\).*$/\1/g;p};d'` |
|
||||
cddbid=`echo "$cddainfo" | \ |
|
||||
sed '/CDDB/{s/^.*discid: *\(0x[a-z0-9]*[^ ]\).*/\1/g;p};d'` |
|
||||
cdindex=`echo "$cddainfo" | \ |
|
||||
sed '/CDINDEX/{s/^.*discid: *\([a-zA-Z0-9_\.]*-\).*/\1/g;p};d'` |
|
||||
cdtext=`echo "$cddainfo" | sed '/CD-Text/{s/^[^:]*: *\(.*[^ ]\).*/\1/g |
|
||||
s/&/\&\;/g;s/\"/\"\;/g |
|
||||
s/</\<\;/g;s/>/\>\;/g |
|
||||
s/\o47/\&apos\;/g |
|
||||
p};d'` |
|
||||
cdextra=`echo "$cddainfo" | sed '/CD-Extra/{s/^[^:]*: *\(.*[^ ]\).*/\1/g |
|
||||
s/&/\&\;/g;s/\"/\"\;/g |
|
||||
s/</\<\;/g;s/>/\>\;/g |
|
||||
s/\o47/\&apos\;/g |
|
||||
p};d'` |
|
||||
|
|
||||
# cddb[`idxof "artist"`]="Blue Öyster Cult" |
|
||||
ENCODING_DIR="${ENCODING_DIR}/${cddb[`idxof "artist"`]}/" |
|
||||
ENCODING_DIR="${ENCODING_DIR}${cddb[`idxof "album"`]}/" |
|
||||
mkdirhier "$ENCODING_DIR" |
|
||||
echo "Output directory is: $ENCODING_DIR" |
|
||||
|
|
||||
xmlfile="${ENCODING_DIR}cdinfo.xml" |
|
||||
|
|
||||
# some special chars within xml must be converted to special syntax |
|
||||
# & => & |
|
||||
# " => " |
|
||||
# ' => ' |
|
||||
# < => < |
|
||||
# > => > |
|
||||
xmlartist=`echo ${cddb[\`idxof "artist"\`]} | \ |
|
||||
sed 's/&/\&\;/g |
|
||||
s/</\<\;/g |
|
||||
s/>/\>\;/g |
|
||||
s/\"/\"\;/g |
|
||||
s/\o47/\&apos\;/g'` |
|
||||
xmlalbum=`echo ${cddb[\`idxof "album"\`]} | \ |
|
||||
sed 's/&/\&\;/g |
|
||||
s/</\<\;/g |
|
||||
s/>/\>\;/g |
|
||||
s/\"/\"\;/g |
|
||||
s/\o47/\&apos\;/g'` |
|
||||
|
|
||||
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>" > "${xmlfile}" |
|
||||
echo "<!DOCTYPE cdInfo SYSTEM \"cdInfo.dtd\">" >> "${xmlfile}" |
|
||||
echo "<cdinfo>" >> "${xmlfile}" |
|
||||
echo " <cdindex>$cdindex</cdindex>" >> "${xmlfile}" |
|
||||
echo " <cddb>$cddbid</cddb>" >> "${xmlfile}" |
|
||||
echo " <cd-text>$cdtext</cd-text>" >> "${xmlfile}" |
|
||||
echo " <cd-extra>$cdextra</cd-extra>" >> "${xmlfile}" |
|
||||
echo " <cd-artist>${xmlartist}</cd-artist>" >> "${xmlfile}" |
|
||||
echo " <cd-title>${xmlalbum}</cd-title>" >> "${xmlfile}" |
|
||||
echo " <cd-year>${cddb[`idxof "year"`]}</cd-year>" >> "${xmlfile}" |
|
||||
echo " <cd-genre>${cddb[`idxof "genre"`]}</cd-genre>" >> "${xmlfile}" |
|
||||
echo " <cd-time>$cd_time</cd-time>" >> "${xmlfile}" |
|
||||
echo " <cd-tracks>$track_num</cd-tracks>" >> "${xmlfile}" |
|
||||
echo " <cd-comment></cd-comment>" >> "${xmlfile}" |
|
||||
|
|
||||
i=1; while [ $i -le $track_num ] |
|
||||
do |
|
||||
j=`expr $i \+ 1` |
|
||||
tracknr=`awk 'BEGIN{printf("%02d\n",'$i')}'` |
|
||||
track=${cddb[`idxof "track-$tracknr"`]} |
|
||||
tartist=${cddb[`idxof "tartist-$tracknr"`]} |
|
||||
|
|
||||
xmltrack=`echo ${track} | sed 's/&/\&\;/g |
|
||||
s/</\<\;/g |
|
||||
s/>/\>\;/g |
|
||||
s/\"/\"\;/g |
|
||||
s/\o47/\&apos\;/g'` |
|
||||
xmltartist=`echo ${tartist} | sed 's/&/\&\;/g |
|
||||
s/</\<\;/g |
|
||||
s/>/\>\;/g |
|
||||
s/\"/\"\;/g |
|
||||
s/\o47/\&apos\;/g'` |
|
||||
|
|
||||
tracklen=`echo "$cddainfo" | \ |
|
||||
sed '/ '"$i"'\.([0-9 ]*:/{s/.*'"$i"'\.( *\([0-9:\.]*\)).*/\1/g;p};d'` |
|
||||
trackstart=`echo "$cddainfo" | \ |
|
||||
sed '/ '"$i"'\.([0-9 ]*)/{s/.*'"$i"'\.( *\([0-9]*\)).*/\1/g;p};d'` |
|
||||
test $i -eq $track_num && \ |
|
||||
trackend=`echo "$cddainfo" | \ |
|
||||
sed '/ lead-out([0-9 ]*)/{s/.*lead-out( *\([0-9]*\)).*/\1/g;p};d'` || \ |
|
||||
trackend=`echo "$cddainfo" | \ |
|
||||
sed '/ '"$j"'\.([0-9 ]*)/{s/.*'"$j"'\.( *\([0-9]*\)).*/\1/g;p};d'` |
|
||||
|
|
||||
test -z "$trackstart" -o -z "$trackend" && echo "Disk Error" && exit 1 |
|
||||
|
|
||||
echo " <track>" >> "${xmlfile}" |
|
||||
echo " <track-number>$i</track-number>" >> "${xmlfile}" |
|
||||
echo " <track-time>$tracklen</track-time>" >> "${xmlfile}" |
|
||||
echo " <track-start-sector>$trackstart</track-start-sector>" >> "${xmlfile}" |
|
||||
echo " <track-length>`expr $trackend \- $trackstart`</track-length>" >> "${xmlfile}" |
|
||||
echo " <track-artist>$xmltartist</track-artist>" >> "${xmlfile}" |
|
||||
echo " <track-title>$xmltrack</track-title>" >> "${xmlfile}" |
|
||||
echo " <track-comment></track-comment>" >> "${xmlfile}" |
|
||||
echo " </track>" >> "${xmlfile}" |
|
||||
|
|
||||
# outfile="${ENCODING_DIR}The Wall/Disk2/" |
|
||||
outfile="${ENCODING_DIR}${tracknr}-${track}" |
|
||||
|
|
||||
test "$ENCODING_TYPE" = "f" && \ |
|
||||
outstr="track-$tracknr => ${tracknr}-${track}.flac" |
|
||||
test "$ENCODING_TYPE" = "m" && \ |
|
||||
outstr="track-$tracknr => ${tracknr}-${track}.mp3" |
|
||||
test "$ENCODING_TYPE" = "o" && \ |
|
||||
outstr="track-$tracknr => ${tracknr}-${track}.ogg" |
|
||||
test "$ENCODING_TYPE" = "w" && \ |
|
||||
outstr="track-$tracknr => ${tracknr}-${track}.wav" |
|
||||
|
|
||||
if [ "$ENCODING_TYPE" = "f" ] |
|
||||
then |
|
||||
bash -c "exec 2>&1;\ |
|
||||
cdda2wav -H -D0,4,0 -t$i - | \ |
|
||||
flac -c \ |
|
||||
-T artist=\"${tartist}\" -T album=\"${cddb[`idxof "album"`]}\" \ |
|
||||
-T genre=\"${cddb[`idxof "genre"`]}\" -T title=\"${track}\" \ |
|
||||
-T tracknumber=\"`expr ${tracknr} \+ 0`\" \ |
|
||||
-T tracknum=\"`expr ${tracknr} \+ 0`\" -T date=\"${cddb[`idxof "year"`]}\" \ |
|
||||
-T comment=\"${cddb[`idxof "comment"`]}\" \ |
|
||||
-o \"${outfile}.flac\" - 2>/dev/null" | rton | \ |
|
||||
awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}' |
|
||||
fi |
|
||||
if [ "$ENCODING_TYPE" = "m" -a "$ENCODER" = "lame" ] |
|
||||
then |
|
||||
bash -c "exec 2>&1;\ |
|
||||
cdda2wav -H -D0,4,0 -t$i - | \ |
|
||||
lame -h \ |
|
||||
--ta \"${tartist}\" --tl \"${cddb[`idxof "album"`]}\" \ |
|
||||
--tg \"${cddb[`idxof "genre"`]}\" --tt \"${track}\" \ |
|
||||
--tn \"`expr ${tracknr} \+ 0`\" --ty \"${cddb[`idxof "year"`]}\" \ |
|
||||
--tc \"${cddb[`idxof "comment"`]}\" \ |
|
||||
- \"${outfile}.mp3\" 2>/dev/null" | rton | \ |
|
||||
awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}' |
|
||||
fi |
|
||||
if [ "$ENCODING_TYPE" = "m" -a "$ENCODER" = "bladeenc" ] |
|
||||
then |
|
||||
bash -c "exec 2>&1;\ |
|
||||
cdda2wav -H -D0,4,0 -t$i - | \ |
|
||||
bladeenc -progress=0 STDIN \"${outfile}.mp3\" 2>/dev/null" | rton | \ |
|
||||
awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}' |
|
||||
fi |
|
||||
if [ "$ENCODING_TYPE" = "o" ] |
|
||||
then |
|
||||
bash -c "exec 2>&1;\ |
|
||||
cdda2wav -H -D0,4,0 -t$i - | \ |
|
||||
oggenc -a \"${tartist}\" -l \"${cddb[`idxof "album"`]}\" \ |
|
||||
-G \"${cddb[`idxof "genre"`]}\" -t \"${track}\" \ |
|
||||
-N \"`expr ${tracknr} \+ 0`\" -d \"${cddb[`idxof "year"`]}\" \ |
|
||||
-c \"${cddb[`idxof "comment"`]}\" \ |
|
||||
-o \"${outfile}.ogg\" - 2>/dev/null" | rton | \ |
|
||||
awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}' |
|
||||
fi |
|
||||
if [ "$ENCODING_TYPE" = "w" ] |
|
||||
then |
|
||||
bash -c "exec 2>&1;\ |
|
||||
cdda2wav -H -D0,4,0 -t$i - > \"${outfile}.wav\"" | rton | \ |
|
||||
awk '/ [0-9 ][0-9]%/ && percent!=$5{percent=$5;printf("\r'"$outstr"': %s", percent)}END{print "\r'"$outstr"': 100%"}' |
|
||||
fi |
|
||||
|
|
||||
i=`expr $i + 1` |
|
||||
done |
|
||||
|
|
||||
echo "</cdinfo>" >> "${xmlfile}" |
|
||||
@ -1,35 +0,0 @@ |
|||||
<?xml version="1.0" encoding="ISO-8859-15"?> |
|
||||
<!DOCTYPE cdInfo SYSTEM "cdInfo.dtd"> |
|
||||
<cdinfo> |
|
||||
<cdindex>2pGK39LLL22K6K8mFDegkBNR39M-</cdindex> |
|
||||
<cddb>0x0911a912</cddb> |
|
||||
<cd-text/> |
|
||||
<cd-extra/> |
|
||||
<cd-artist>Various</cd-artist> |
|
||||
<cd-year>1998</cd-year> |
|
||||
<cd-genre>Alternative</cd-genre> |
|
||||
<track> |
|
||||
<track-number>1</track-number> |
|
||||
<track-time>3:42.20</track-time> |
|
||||
<track-start-sector>32</track-start-sector> |
|
||||
<track-artist>Guano Apes</track-artist> |
|
||||
<track-title>Lords Of The Boards</track-title> |
|
||||
<track-comment/> |
|
||||
</track> |
|
||||
<track> |
|
||||
<track-number>2</track-number> |
|
||||
<track-time>4:45.70</track-time> |
|
||||
<track-start-sector>16702</track-start-sector> |
|
||||
<track-artist>Rammstein</track-artist> |
|
||||
<track-title>Das Modell</track-title> |
|
||||
<track-comment/> |
|
||||
</track> |
|
||||
<track> |
|
||||
<track-number>3</track-number> |
|
||||
<track-time>4:11.08</track-time> |
|
||||
<track-start-sector>38147</track-start-sector> |
|
||||
<track-artist>Faith No More</track-artist> |
|
||||
<track-title>Last Cup Of Sorrow</track-title> |
|
||||
<track-comment/> |
|
||||
</track> |
|
||||
</cdinfo> |
|
||||
@ -1,72 +0,0 @@ |
|||||
Files in this package |
|
||||
--------------------- |
|
||||
getcd.sh (The main script that does most of the work) |
|
||||
rton.c (A VERY small c-prog, that converts \r (carriage return) |
|
||||
to \n (line feed). It is needed to fetch the percent |
|
||||
complete messages from cdda2wav) |
|
||||
flac2mp3.xsl (xml stylesheet to convert cdinfo.xml in shell commands |
|
||||
that will create .flac from .mp3 files) |
|
||||
flac2wav.xsl (xml stylesheet to convert cdinfo.xml in shell commands |
|
||||
that will create .flac from .wav files) |
|
||||
mp32wav.xsl (xml stylesheet to convert cdinfo.xml in shell commands |
|
||||
that will create .wav from .mp3 files) |
|
||||
cdinfo2xinf.xsl (xml stylesheet to convert cdinfo.xml in shell commands |
|
||||
that create the .xinf Files used by xcdroast) |
|
||||
CDDB_get-2.23p1.patch (a patch for cddb.pl that makes it possible to |
|
||||
select one of multiple cddb-entrys at calltime) |
|
||||
README (Overview and Information) |
|
||||
INSTALL (This file, howto make something useful from it) |
|
||||
USAGE (How to use the script) |
|
||||
|
|
||||
|
|
||||
Requirments |
|
||||
----------- |
|
||||
first you need some software to run this script. |
|
||||
CDDB_get-2.23 (http://armin.emx.at/cddb/) |
|
||||
lame (http://lame.sourceforge.net/) |
|
||||
bladeenc (http://bladeenc.mp3.no/) |
|
||||
flac (http://flac.sourceforge.net/) |
|
||||
vorbis-tools (http://www.vorbis.com/download_unix_1.0.1.psp) |
|
||||
libxml2 (http://xmlsoft.org/) |
|
||||
|
|
||||
I assume you have a working sed and awk, else you need to install them too. |
|
||||
|
|
||||
Install lame, bladeenc, flac, vorbis-tools and libxml2 as discribed within |
|
||||
these packages. |
|
||||
|
|
||||
unpack CDDB_get-2.23.tar.gz and patch it with CDDB_get-2.23p1.patch. |
|
||||
For this copy both files in a directory dir then do the following: |
|
||||
|
|
||||
me@house:~> cd dir |
|
||||
me@house:~/dir> tar xfvz CDDB_get-2.23.tar.gz |
|
||||
me@house:~/dir/CDDB_get-2.23> patch -p1 -E < ../CDDB_get-2.23p1.patch |
|
||||
|
|
||||
now install it as usual (and described within the README from CDDB_get) |
|
||||
|
|
||||
now go in the directory where rton.c exists. |
|
||||
type here: gcc -o rton rton.c |
|
||||
and then copy rton in a directory in your path. |
|
||||
|
|
||||
Finally copy getcd.sh somewhere in you path. |
|
||||
|
|
||||
now you can use getcd.sh. For a short description how to use it either |
|
||||
read USAGE or type getcd.sh -h. |
|
||||
|
|
||||
IMPORTANT: Any user who should use this script needs read-access to the |
|
||||
cdrom device, additional it is actually necessary to create a symlink |
|
||||
/dev/cdrom to your real device eg. /dev/sr0 or /dev/hdb. And the user must have |
|
||||
access to the internet. |
|
||||
|
|
||||
Note |
|
||||
---- |
|
||||
Please note that this is not a release. You can use it and it will not harm |
|
||||
anything as for as I can say, but it might not work with some configurations |
|
||||
or CDs. |
|
||||
In the release there will be some kind of detection which tools are present and |
|
||||
witch not and the script will use only present tools or give an error |
|
||||
description. |
|
||||
Note further that it is desired to modify the script for your needs. It is not |
|
||||
very complex and with some error and trial it will be possible to tailor it |
|
||||
exactly for your needs. In future there will be configuration files to make it |
|
||||
even more ease to configure the script for your situation. (I am thinking |
|
||||
about reqriting the script in c) |
|
||||
@ -1,30 +0,0 @@ |
|||||
This is another shell script that combines cdda2wav with various encoders. |
|
||||
|
|
||||
As I started this i was not pleased by any of the existent grabber/encoder |
|
||||
frontends. So I decided to create my own one. The goal was to rip and encode in |
|
||||
one step without creating any temporary .wav file and to have a simple command |
|
||||
with only a few easy arguments to control this command. |
|
||||
|
|
||||
Now getcd.sh is a not to complicated bash script that uses awk, sed, cdda2wav, |
|
||||
flac, lame, bladeenc, ogg/vorbis, cddb.pl (in a slightly patched version). |
|
||||
It encodes tracks from the cd to a spcifiable base directory without creating |
|
||||
any temporary files. |
|
||||
It creates subdirectorys basedir/[mp3|flac|ogg|wav]/artist/cd-title for the |
|
||||
corresponding encoding-method and save files with the name |
|
||||
trackno-tracktitle.[mp3|flac|ogg|wav] again corresponding to the used |
|
||||
encoding-method. |
|
||||
If one encodes a sampler-cd (cd with various artists) it is often so, that |
|
||||
the artist of the track is mentioned in the cddb-track-title. For this reason |
|
||||
one can specify a delimiting character and the order (artist or title first) to |
|
||||
split the cddb-track-info and generate correct id3tags or similar. |
|
||||
|
|
||||
Additional to the encoded files getcd.sh creates an file cdinfo.xml which |
|
||||
contains all essential information of the original CD. I have written also |
|
||||
some xslt files that can be used to create .xinf files for xcdroast and to |
|
||||
create .wav from .flac or .mp3. It is planned to create additional xslt files |
|
||||
to make html-information about the CD, create insert scripts for postgres and |
|
||||
or mysql (or other rdbs) and converter-scripts that use these xslt-files. |
|
||||
To use the xslt-files one needs an xslt-processor, like xsltproc from |
|
||||
libxml2 (thats the one i used) |
|
||||
|
|
||||
for help use getcd.sh -h |
|
||||
@ -1,15 +0,0 @@ |
|||||
/* Achtung unter dos ist \n in wirklichkeit \r\n bei den meisten |
|
||||
Compilern, da funktioniert das natürlich nicht!!!! */ |
|
||||
#include <stdio.h> |
|
||||
|
|
||||
int main(int argc, char* argv[]) { |
|
||||
int c=0; |
|
||||
|
|
||||
while(fread(&c, 1, 1, stdin)) { |
|
||||
putchar((c=='\r')?'\n':c); |
|
||||
fflush(stdout); |
|
||||
} |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
@ -0,0 +1,393 @@ |
|||||
|
if [ "x" == "x$__SHELLUTILS__" ] |
||||
|
then |
||||
|
__SHELLUTILS__="shellUtils" |
||||
|
|
||||
|
# ------------------------------- |
||||
|
# Fehlermeldungen |
||||
|
_shellUtils_errMsg[1]="Fehler beim Aufruf von \${FUNCNAME}: falsche Parameteranzahl: $#" |
||||
|
_shellUtils_errMsg[2]="Fehler: Es läuft bereits eine Instanz (\${oldPid}) des scripts" |
||||
|
_shellUtils_errMsg[3]="Fehler beim Aufruf von doSmbCommand: smbCommand nicht initialisiert" |
||||
|
_shellUtils_errMsg[4]="Fehler: konnte keine Konfigurations-Datei (\${cName}) finden" |
||||
|
#_shellUtils_errMsg[2]= |
||||
|
# ------------------------------- |
||||
|
|
||||
|
# ------------------------------- |
||||
|
# Kommandodefinitions Teil |
||||
|
SH="/bin/bash" |
||||
|
SMBCLIENT="/usr/bin/smbclient" |
||||
|
PS="/bin/ps" |
||||
|
BASENAME="/usr/bin/basename" |
||||
|
PWDCMD="/bin/pwd" |
||||
|
CONVERT="/usr/bin/convert" |
||||
|
ICONV="/usr/bin/iconv" |
||||
|
ECHO="/bin/echo" |
||||
|
TEST="/usr/bin/test" |
||||
|
SED="/usr/bin/sed" |
||||
|
PRINTF="/usr/bin/printf" |
||||
|
SORT="/usr/bin/sort" |
||||
|
FTP="/usr/bin/ftp" |
||||
|
CONVERT="/usr/bin/convert" |
||||
|
CJPEG="/usr/bin/cjpeg" |
||||
|
CAT="/bin/cat" |
||||
|
MKDIR="/bin/mkdir" |
||||
|
DATE="/bin/date" |
||||
|
RM="/bin/rm" |
||||
|
MAILCMD="/bin/bin/mailto" |
||||
|
CUT="/usr/bin/cut" |
||||
|
TR="/usr/bin/tr" |
||||
|
LOCALE="/usr/bin/locale" |
||||
|
GREP="/bin/grep" |
||||
|
WC="/usr/bin/wc" |
||||
|
MV="/usr/bin/mv" |
||||
|
CP="/usr/bin/cp" |
||||
|
EXPR="/usr/bin/expr" |
||||
|
UNZIP="/usr/bin/unzip" |
||||
|
XSLTPROC="/usr/bin/xsltproc" |
||||
|
GAWK="/usr/bin/gawk" |
||||
|
AWK="/usr/bin/awk" |
||||
|
LS="/bin/ls" |
||||
|
TOUCH="/usr/bin/touch" |
||||
|
RECODE="/usr/bin/recode" |
||||
|
GETOPT="/usr/bin/getopt" |
||||
|
# ------------------------------- |
||||
|
|
||||
|
# ------------------------------- |
||||
|
# Variablen |
||||
|
_smbCommand="" |
||||
|
# ------------------------------- |
||||
|
|
||||
|
# ------------------------------- |
||||
|
# Funktionen |
||||
|
# Aufruf: checkLock lockfile |
||||
|
function checkLock |
||||
|
{ |
||||
|
if [ $# -ne 1 ] |
||||
|
then |
||||
|
eval "echo \"${_shellUtils_errMsg[1]}\" >&2" |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
local filename="$1" |
||||
|
|
||||
|
if [ -e "$filename" ] |
||||
|
then |
||||
|
local oldPid="`$CAT "$lockFile"`" |
||||
|
local scriptName="`$BASENAME $0`" |
||||
|
local running="`$PS -p "$oldPid" | $SED '1d; /'$scriptName'/!d'`" |
||||
|
|
||||
|
if [ -n "$running" ] |
||||
|
then |
||||
|
eval "echo \"${_shellUtils_errMsg[2]}\" >&2" |
||||
|
exit 2 |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
echo $$ >"$lockFile" |
||||
|
|
||||
|
return $$ |
||||
|
} |
||||
|
|
||||
|
# Aufruf: doSmbCommand share domain user pass |
||||
|
function initSmbCommand |
||||
|
{ |
||||
|
if [ $# -ne 4 ] |
||||
|
then |
||||
|
eval "echo \"${_shellUtils_errMsg[1]}\" >&2" |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
_smbCommand="$SMBCLIENT $1 $4 -U $3 -W $2" |
||||
|
} |
||||
|
|
||||
|
# Aufruf: doSmbCommand path command |
||||
|
function doSmbCommand |
||||
|
{ |
||||
|
if [ $# -lt 1 -o $# -gt 2 ] |
||||
|
then |
||||
|
eval "echo \"${_shellUtils_errMsg[1]}\" >&2" |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$_smbCommand" ] |
||||
|
then |
||||
|
eval "echo \"${_shellUtils_errMsg[3]}\" >&2" |
||||
|
exit 3 |
||||
|
fi |
||||
|
|
||||
|
if [ $# -eq 2 ] |
||||
|
then |
||||
|
eval "$_smbCommand -D $1 -c \"$2\"" |
||||
|
else |
||||
|
eval "$_smbCommand -D $1" <&0 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
# Meine Implementation von Hashes fuer die bash verwendet zwei Arrays, |
||||
|
# deren "Basisname" immer bei den aufrufen der Hash-Funktionen mit |
||||
|
# angegeben werden muessen. Die beiden Arrays heissen dann |
||||
|
# _<<Basisname>>_key und _<<Basisname>>_value und enthalten entsprechen |
||||
|
# jeweils zu einem Index ein key/value Paar. |
||||
|
# Die groesste Magie in den Funktionen liegt darin die Arraynamen |
||||
|
# immer richtig zu erzeugen. |
||||
|
# Wenn man dieses Hashes benutzt sollte man bedenken, das das |
||||
|
# Laufzeitverhalten O(n) ist, die Implementierung also nicht sehr |
||||
|
# performant. |
||||
|
# PS. O(n) => im unguenstigsten Fall hat man n Schleifendurchlaeufe um |
||||
|
# auf ein Element in einem Hash mit n Elementen zuzugreifen. |
||||
|
# Ich mags kaum zugeben aber an manchen Stellen ist das Laufzeitverhalten |
||||
|
# sogar O(2n). (Es besteht wohl noch dringender Optimirungsbedarf) |
||||
|
|
||||
|
# eine Funktion um einen Hash zu leeren |
||||
|
# Aufruf: unsetHash hashname |
||||
|
function unsetHash |
||||
|
{ |
||||
|
if [ $# -ne 1 ] |
||||
|
then |
||||
|
eval "echo \"${_shellUtils_errMsg[1]}\" >&2" |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
unset _${1}_key |
||||
|
unset _${1}_value |
||||
|
} |
||||
|
|
||||
|
# eine Funktion um einen HashWert zu setzen. ein key und ein value array |
||||
|
# werden erzeugt. Ueber getHashVal kann man wieder Werte abfragen. |
||||
|
# Aufruf: setHashVal hashname key value |
||||
|
function setHashVal |
||||
|
{ |
||||
|
if [ $# -ne 3 ] |
||||
|
then |
||||
|
eval "echo \"${_shellUtils_errMsg[1]}\" >&2" |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
getHashVal "${1}" "${2}" >/dev/null 2>&1 |
||||
|
local idx=$? |
||||
|
eval "_${1}_key[$idx]=\"$2\"" |
||||
|
eval "_${1}_value[$idx]=\"$3\"" |
||||
|
} |
||||
|
|
||||
|
# und eine funktion um über einen key einen Wert aus einem Hash |
||||
|
# (siehe setHashVal) zu bekommen. |
||||
|
# Aufruf: getHashVal hash key |
||||
|
function getHashVal |
||||
|
{ |
||||
|
if [ $# -ne 2 ] |
||||
|
then |
||||
|
eval "echo \"${_shellUtils_errMsg[1]}\" >&2" |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
local i=0 |
||||
|
local count=`getHashSize $1` |
||||
|
local key=`$ECHO $2 | $SED 's/#/\\\\#/'` |
||||
|
|
||||
|
while [ $i -lt $count ] |
||||
|
do |
||||
|
if eval [ "\${_${1}_key[$i]}" = "$key" ] |
||||
|
then |
||||
|
eval "echo \${_${1}_value[$i]}" |
||||
|
return $i |
||||
|
fi |
||||
|
|
||||
|
i=$((i+1)); |
||||
|
done; |
||||
|
|
||||
|
return $i |
||||
|
} |
||||
|
|
||||
|
# Aufruf: getHashSize hash |
||||
|
function getHashSize |
||||
|
{ |
||||
|
if [ $# -ne 1 ] |
||||
|
then |
||||
|
eval "echo \"${_shellUtils_errMsg[1]}\" >&2" |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
eval "count=\${#_${1}_key[*]}" |
||||
|
echo $count |
||||
|
|
||||
|
return $count |
||||
|
} |
||||
|
|
||||
|
# Aufruf: getHashKeys hash |
||||
|
function getHashKeys |
||||
|
{ |
||||
|
if [ $# -ne 1 ] |
||||
|
then |
||||
|
eval "echo \"${_shellUtils_errMsg[1]}\" >&2" |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
eval "ret=\"\${_${1}_key[0]}\"" |
||||
|
|
||||
|
local i=1 |
||||
|
local count=`getHashSize $1` |
||||
|
while [ $i -lt $count ] |
||||
|
do |
||||
|
eval "ret=\"$ret \${_${1}_key[$i]}\"" |
||||
|
i=$((i+1)) |
||||
|
done |
||||
|
|
||||
|
echo $ret |
||||
|
|
||||
|
return $count |
||||
|
} |
||||
|
|
||||
|
# Funktion um die Zahlrepraesentation eines Monatsname zu bekommen. |
||||
|
# Also Oktober => 10 |
||||
|
# Abhaengig davon das ein entsprechendes locale installiert ist. |
||||
|
# Aufruf: getMonthNum Monatsname [locale] |
||||
|
function getMonthNum |
||||
|
{ |
||||
|
if [ $# -lt 1 ] |
||||
|
then |
||||
|
eval "echo \"${_shellUtils_errMsg[1]}\" >&2" |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
if [ $# -eq 2 ] |
||||
|
then |
||||
|
LC_ALL=${2} |
||||
|
fi |
||||
|
|
||||
|
mon=`$LOCALE -c LC_TIME | $SED '5!d;y/;/\n/' |\ |
||||
|
$GREP -n ${1} | $CUT -d\: -f1` |
||||
|
|
||||
|
echo $mon |
||||
|
|
||||
|
return $mon |
||||
|
} |
||||
|
|
||||
|
# Funkktion um ein Kommando nach einem bestimmten Zeitraum abzubrechen |
||||
|
# Aufruf: timeout cmd t |
||||
|
# Retruns: >128 -> falls Timeout, return value von cmd->falls kein Timeout |
||||
|
function timeout |
||||
|
{ |
||||
|
if [ $# -lt 2 ] |
||||
|
then |
||||
|
eval "echo \"${_shellUtils_errMsg[1]}\" >&2" |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
# gewuenschtes Kommando als separaten Prozess starten |
||||
|
$1 <&0 & |
||||
|
local __cPid=$! |
||||
|
|
||||
|
# subshell starten die gewuenschte Zeit wartet bis sie obigen |
||||
|
# Prozess killt. |
||||
|
( sleep $2; kill -9 ${__cPid} ) >/dev/null 2>&1 & |
||||
|
local __tPid=$! |
||||
|
|
||||
|
# neuen Trap setzen....evtl. vorhande alte Kommandos werden auch |
||||
|
# ausgefuehrt! (Bei Programmabbruch auch auf jeden Fall beide |
||||
|
# Sub-Prozesse killen) |
||||
|
oldTrap="`trap -p EXIT`" |
||||
|
oldTrapCmd="`echo $oldTrap | sed 's/^trap -- \(.*\) EXIT$/\1/'`" |
||||
|
|
||||
|
trapCmd="kill -9 ${__cPid} >/dev/null 2>&1" |
||||
|
trapCmd="${trapCmd};kill -9 ${__cPid} >/dev/null 2>&1" |
||||
|
trapCmd="${trapCmd};eval $oldTrapCmd" |
||||
|
trap "${trapCmd}" EXIT |
||||
|
|
||||
|
# warte bis Subprozess mit Kommando endet |
||||
|
wait ${__cPid} >/dev/null 2>&1 |
||||
|
local __cExit=$? |
||||
|
|
||||
|
# alte trap Kommandos wiederherstellen |
||||
|
test "$oldTrapCmd" && eval "$oldTrapCmd" || trap '-' EXIT |
||||
|
|
||||
|
# falls sie noch laeuft wartende subshell killen. |
||||
|
kill -9 $__tPid >/dev/null 2>&1 |
||||
|
return $__cExit |
||||
|
} |
||||
|
# ------------------------------- |
||||
|
|
||||
|
fi |
||||
|
|
||||
|
function getCDInfo |
||||
|
{ |
||||
|
local uri device cmd i hello cddb ret diskData tNum |
||||
|
|
||||
|
uri="freedb.freedb.org/~cddb/cddb.cgi" |
||||
|
device="/dev/cdrom" |
||||
|
|
||||
|
test $# -ge 1 && uri="$1" |
||||
|
test $# -ge 2 && device="$2" |
||||
|
|
||||
|
hello="hello=${USER}+${HOSTNAME}+test+0.0.1" |
||||
|
|
||||
|
# first get the genre list from server |
||||
|
eval "`curl -s "http://${uri}?cmd=cddb+lscat&${hello}&proto=6" |\ |
||||
|
sed '1d;$d' | tr -d '\r' | tr '\n' ',' |\ |
||||
|
sed 's/,$//;s/,/" "/g;s/^\(.*\)$/local -a genre=("\1")/'`" |
||||
|
|
||||
|
unset cddbId dTitle dYear dGenre tTitle |
||||
|
|
||||
|
diskData="`cdda2wav -D ${device} -N -J -v toc,sectors 2>&1`" |
||||
|
|
||||
|
cddbId="`echo "$diskData" |\ |
||||
|
sed '/^CDDB/!d;s/^.*0x\(.*\)$/\1/'`" |
||||
|
dTracks="`echo "$diskData" |\ |
||||
|
sed '/tracks/!d;s/^.*tracks:\([0-9]*\).*$/\1/'`" |
||||
|
dLength="`echo "$diskData" |\ |
||||
|
sed '/tracks/!d;s/^.*time \([0-9:\.]*\).*$/\1/'`" |
||||
|
dIndex="`echo "$diskData" |\ |
||||
|
sed '/CDINDEX/!d;s/^.*: *\([a-zA-Z0-9_\.]*-\).*$/\1/'`" |
||||
|
dText="`echo "$diskData" | sed ' |
||||
|
/CD-Text/!d;s/^[^:]*: *\(.*[^ ]\).*$/\1/'`" |
||||
|
dExtra="`echo "$diskData" | sed ' |
||||
|
/CD-Extra/!d;s/^[^:]*: *\(.*[^ ]\).*$/\1/'`" |
||||
|
|
||||
|
# search for info in all genres |
||||
|
for i in "${genre[@]}" |
||||
|
do |
||||
|
cmd="cmd=cddb+read+${i}+${cddbId}" |
||||
|
#wget -O- "http://${uri}?${cmd}&${hello}&proto=6" 2>/dev/null |
||||
|
cddb="`curl -s "http://${uri}?${cmd}&${hello}&proto=6"`" |
||||
|
|
||||
|
ret="`echo "$cddb" | head -c 3`" |
||||
|
if [ "$ret" != "210" ] |
||||
|
then |
||||
|
if [ ${verbose:-0} -ge 3 ] |
||||
|
then |
||||
|
debug="`echo "$cddb" | head -n 1`" |
||||
|
echo $"[ERROR] cddb: ${debug}" |
||||
|
fi |
||||
|
continue |
||||
|
else |
||||
|
eval "`echo "$cddb" | tr -d '\r' | sed ' |
||||
|
/DTITLE/s/^.*=\(\(.*\) \/ \)*\(.*\)$/dArtist="\2";dTitle="\3"/p |
||||
|
/DYEAR/s/^.*=\(.*\)$/dYear="\1"/p |
||||
|
/DGENRE/s/^.*=\(.*\)$/dGenre="\1"/p |
||||
|
/TTITLE/s/^TTITLE\([0-9]*\)=\(\(.*\) \/ \)*\(.*\)$/tArtist[\1]="\3";tTitle[\1]="\4"/p |
||||
|
d'`" |
||||
|
break |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
# Nu pack ich in alle tArtist die leer sind den dArtist. |
||||
|
i=0 |
||||
|
while [ $i -lt ${#tArtist[@]} ] |
||||
|
do |
||||
|
tNum=$((i+1)) |
||||
|
tLength[$i]=`echo "$diskData" | sed ' |
||||
|
/[^0-9]'$tNum'\.(.*:.*)/ !d |
||||
|
s/.*[^0-9]'$tNum'\.( *\([^)]*\).*$/\1/'` |
||||
|
tStartSec[$i]=`echo "$diskData" | sed ' |
||||
|
/[^0-9]'$tNum'\.([^:]*)/ !d |
||||
|
s/.*[^0-9]'$tNum'\.( *\([^)]*\).*$/\1/'` |
||||
|
|
||||
|
test $tNum -eq ${#tArtist[@]} && tNum="lead-out" || tNum=$((tNum+1)) |
||||
|
|
||||
|
tEndSec[$i]=`echo "$diskData" | sed ' |
||||
|
/[^0-9]'$tNum'\.*([^:]*)/ !d |
||||
|
s/.*[^0-9]'$tNum'\.*( *\([^)]*\).*$/\1/'` |
||||
|
|
||||
|
test -z "${tArtist[$i]}" && tArtist[$i]="$dArtist" |
||||
|
i=$((i+1)) |
||||
|
done |
||||
|
} |
||||
|
|
||||
@ -1,25 +0,0 @@ |
|||||
usage: ./getcd.sh [-d delimiter [-o {t|a}]] [-t {m|f|o}] [-p path] [-e encoder] [-c cddb-entry] [-h] |
|
||||
-d : A single character delimiting trackname from |
|
||||
artistname with sampler cds |
|
||||
|
|
||||
-o : specifies if theres the track or the artist first |
|
||||
Must be: |
|
||||
t for titel first or |
|
||||
a for artist first |
|
||||
If there is none specified t is assumed |
|
||||
-t : you can specify either m for encoding to mp3 |
|
||||
using lame, or f for making lossless encoding using flac, |
|
||||
or o for making ogg/vorbis, or w for uncompressed wav. |
|
||||
Omitting this results in encoding to flac. |
|
||||
mp3s will be placed under a subfolder mp3 and flacs |
|
||||
under a subfolder flac |
|
||||
-p : specifies the path to save the encoded data. |
|
||||
Defaults to the users home directory. |
|
||||
-e : specifies the mp3 encoder to use. |
|
||||
valid encoders are actually: lame,bladeenc |
|
||||
Defaults to lame. |
|
||||
-c : specifies the CDDB-Entry to use. |
|
||||
sometimes there is more than 1 entry for a cd in cddb. |
|
||||
Then you can specify wich one to use by this option. |
|
||||
You can checkout all entries using cddb.pl. |
|
||||
-h : Shows this help. |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue