3 ############################################################################
4 # soepkiptng (c) copyright 2000 Eric Lammerts <eric@lammerts.org>.
6 ############################################################################
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # A copy of the GNU General Public License is available on the World Wide Web
18 # at `http://www.gnu.org/copyleft/gpl.html'. You can also obtain it by
19 # writing to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 # Boston, MA 02111-1307, USA.
21 ############################################################################
25 use Cwd qw
'cwd abs_path';
27 # find program directory
30 my $l = readlink or die "readlink $_: $!\n";
31 if($l =~ m
|^/|) { $_ = $l; } else { s|[^/]*$|/$l|; }
34 $progdir = abs_path
($1);
36 unshift @INC, "$progdir/lib";
42 require "$progdir/soepkiptng.lib";
48 Usage: raw2ogg [-d] [-b bitrate] [-c configfile] file...
50 -d : delete original after successful conversion
51 -b bitrate : kbitrate to encode to (default 192)
52 -c configfile : override soepkiptng config file
56 read_configfile
(\
%conf, $opt_c);
58 $ENV{PATH
} = "$progdir/bin:$ENV{PATH}";
61 $bitrate = $opt_b || 192;
66 sub latin1_to_utf
($) {
69 $s =~ s/(.)/pack("U", ord $1)/ge;
73 $dbh = DBI
->connect("DBI:$conf{db_type}:$conf{db_name}:$conf{db_host}",
74 $conf{db_user
}, $conf{db_pass
})
75 or die "can't connect to database";
77 foreach $rawfile (@ARGV) {
80 if($rawfile !~ m
|^/|) { $rawfile = "$cwd/$rawfile"; }
81 $rawfile =~ s!(^|/)(\./)+!\1!g;
83 ($qfile = $rawfile) =~ s/(.*)\.\w+?$/\1.%/;
84 $q = "SELECT title
,artist
.name
,album
.name
,track
" .
85 " FROM song
,artist
,album
" .
86 " WHERE song
.artist_id
=artist
.id AND song
.album_id
=album
.id
" .
87 " AND present AND filename LIKE ?
";
88 $sth = $dbh->prepare($q);
90 or die "can
't do sql command: " . $dbh->errstr;
92 my ($ti, $ar, $al, $tr);
93 ($ti, $ar, $al, $tr) = $sth->fetchrow_array or do {
96 or die "can't
do sql command
: " . $dbh->errstr;
98 ($ti, $ar, $al, $tr) = $sth->fetchrow_array or do {
99 warn "$rawfile: not found
in dbase
\n";
103 my $oggfile = $rawfile;
105 $oggfile =~ s/\.\w+//;
109 warn "$oggfile exists, skipping
.\n";
114 if($ti) { push @oggargs, "-t
", latin1_to_utf($ti); }
115 if($ar) { push @oggargs, "-a
", latin1_to_utf($ar); }
116 if($al) { push @oggargs, "-l
", latin1_to_utf($al); }
117 if($tr) { push @oggargs, "-N
", $tr; }
119 system 'oggenc', '-r', '-b', $bitrate, @oggargs,
120 '-o', "$oggfile.tmp
", $rawfile;
123 warn "$rawfile: oggenc failed
.\n";
125 unlink "$oggfile.tmp
" or warn "delete $oggfile.tmp
: $!\n";
126 if(($? & 0x7f) == 2) { die "aborted
.\n"; }
131 warn "$oggfile exists, skipping
.\n";
132 unlink "$oggfile.tmp
" or warn "delete $oggfile.tmp
: $!\n";
135 rename "$oggfile.tmp
", $oggfile or do {
136 warn "rename $oggfile.tmp
-> $oggfile: $!\n";
137 unlink "$oggfile.tmp
" or warn "delete $oggfile.tmp
: $!\n";
141 unlink $rawfile or warn "unlink $rawfile: $!\n";