3 ############################################################################
4 # soepkiptng (c) copyright 2000 Eric Lammerts <eric@lammerts.org>.
5 ############################################################################
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # A copy of the GNU General Public License is available on the World Wide Web
17 # at `http://www.gnu.org/copyleft/gpl.html'. You can also obtain it by
18 # writing to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, USA.
20 ############################################################################
28 use Cwd qw
'cwd abs_path';
30 # find program directory
33 my $l = readlink or die "readlink $_: $!\n";
34 if($l =~ m
|^/|) { $_ = $l; } else { s|[^/]*$|/$l|; }
37 $progdir = abs_path
($1);
39 unshift @INC, "$progdir/lib";
45 require "$progdir/soepkiptng.lib";
47 $ENV{PATH
} = "$progdir/bin:$ENV{PATH}";
48 use lib
"$progdir/lib";
54 Usage: flac2ogg [-d] [-p flac_binary] [-b bitrate] [-c configfile] file...
56 -d : delete original after successful conversion
57 -b bitrate : kbitrate to encode to (default 192)
58 -c configfile : override soepkiptng config file
62 read_configfile
(\
%conf, $opt_c);
64 $bitrate = $opt_b || 192;
65 $flac = $opt_p || "flac";
70 $dbh = DBI
->connect("DBI:$conf{'db_type'}:$conf{'db_name'}:$conf{'db_host'}",
71 $conf{'db_user'}, $conf{'db_pass'})
72 or die "can't connect to database";
74 foreach $flacfile (@ARGV) {
77 if($flacfile !~ m
|^/|) { $flacfile = "$cwd/$flacfile"; }
78 $flacfile =~ s!(^|/)(\./)+!\1!g;
80 $q = "SELECT title
,artist
.name
,album
.name
,track
" .
81 " FROM song
,artist
,album
" .
82 " WHERE song
.artist_id
=artist
.id AND song
.album_id
=album
.id
" .
83 " AND present AND filename
=?
";
84 $sth = $dbh->prepare($q);
85 $sth->execute($flacfile)
86 or die "can
't do sql command: " . $dbh->errstr;
88 my ($ti, $ar, $al, $tr) = $sth->fetchrow_array or do {
89 warn "$flacfile: not found in dbase\n";
92 my $oggfile = $flacfile;
94 $oggfile =~ s/\.\w+//;
98 warn "$oggfile exists, skipping.\n";
102 my @oggcmd = ('oggenc
', '-r
', '-b
', $bitrate, '-o
', "$oggfile.tmp");
103 if($ti) { push @oggcmd, "-t", $ti; }
104 if($ar) { push @oggcmd, "-a", $ar; }
105 if($al) { push @oggcmd, "-l", $al; }
106 if($tr) { push @oggcmd, "-N", $tr; }
108 if(open(STDIN, "-|") == 0) {
109 exec $flac, qw/-sdc --endian=little --sign=signed --force-raw-format/,
116 warn "$flacfile: oggenc failed.\n";
118 unlink "$oggfile.tmp" or warn "delete $oggfile.tmp: $!\n";
119 if(($? & 0x7f) == 2) { die "aborted.\n"; }
124 warn "$flacfile: $flac -d 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 $flacfile or warn "unlink $flacfile: $!\n";