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";
44 require "$progdir/soepkiptng.lib";
46 $ENV{PATH
} = "$progdir/bin:$ENV{PATH}";
47 use lib
"$progdir/lib";
53 Usage: flac2ogg [-d] [-p flac_binary] [-b bitrate] [-c configfile] file...
55 -d : delete original after successful conversion
56 -b bitrate : kbitrate to encode to (default 192)
57 -c configfile : override soepkiptng config file
61 read_configfile
(\
%conf, $opt_c);
63 $bitrate = $opt_b || 192;
64 $flac = $opt_p || "flac";
69 $dbh = DBI
->connect("DBI:$conf{'db_type'}:$conf{'db_name'}:$conf{'db_host'}",
70 $conf{'db_user'}, $conf{'db_pass'})
71 or die "can't connect to database";
73 foreach $flacfile (@ARGV) {
76 if($flacfile !~ m
|^/|) { $flacfile = "$cwd/$flacfile"; }
77 $flacfile =~ s!(^|/)(\./)+!\1!g;
79 $q = "SELECT title
,artist
.name
,album
.name
,track
" .
80 " FROM song
,artist
,album
" .
81 " WHERE song
.artist_id
=artist
.id AND song
.album_id
=album
.id
" .
82 " AND present AND filename
=?
";
83 $sth = $dbh->prepare($q);
84 $sth->execute($flacfile)
85 or die "can
't do sql command: " . $dbh->errstr;
87 my ($ti, $ar, $al, $tr) = $sth->fetchrow_array or do {
88 warn "$flacfile: not found in dbase\n";
91 my $oggfile = $flacfile;
93 $oggfile =~ s/\.\w+//;
97 warn "$oggfile exists, skipping.\n";
101 my @oggcmd = ('oggenc
', '-r
', '-b
', $bitrate, '-o
', "$oggfile.tmp");
102 if($ti) { push @oggcmd, "-t", $ti; }
103 if($ar) { push @oggcmd, "-a", $ar; }
104 if($al) { push @oggcmd, "-l", $al; }
105 if($tr) { push @oggcmd, "-N", $tr; }
107 if(open(STDIN, "-|") == 0) {
108 exec $flac, qw/-sdc --endian=little --sign=signed --force-raw-format/,
115 warn "$flacfile: oggenc failed.\n";
117 unlink "$oggfile.tmp" or warn "delete $oggfile.tmp: $!\n";
118 if(($? & 0x7f) == 2) { die "aborted.\n"; }
123 warn "$flacfile: $flac -d failed.\n";
124 unlink "$oggfile.tmp" or warn "delete $oggfile.tmp: $!\n";
125 if(($? & 0x7f) == 2) { die "aborted.\n"; }
130 warn "$oggfile exists, skipping.\n";
131 unlink "$oggfile.tmp" or warn "delete $oggfile.tmp: $!\n";
134 rename "$oggfile.tmp", $oggfile or do {
135 warn "rename $oggfile.tmp -> $oggfile: $!\n";
136 unlink "$oggfile.tmp" or warn "delete $oggfile.tmp: $!\n";
140 unlink $flacfile or warn "unlink $flacfile: $!\n";