3 #==============================================================================
5 # File ID: 4507db62-f744-11dd-bbaa-000475e441b9
10 # ©opyleft 2008– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of file for
13 #==============================================================================
38 $progname =~ s/^.*\/(.*?)$/$1/;
39 our $VERSION = '0.1.0';
41 Getopt
::Long
::Configure
('bundling');
44 'album|a=s' => \
$Opt{'album'},
45 'artist|A=s' => \
$Opt{'artist'},
46 'force|f' => \
$Opt{'force'},
47 'genre|g=s' => \
$Opt{'genre'},
48 'help|h' => \
$Opt{'help'},
49 'quiet|q+' => \
$Opt{'quiet'},
50 'releasedate|r=s' => \
$Opt{'releasedate'},
51 'title|t=s' => \
$Opt{'title'},
52 'tracknumber|n=s' => \
$Opt{'tracknumber'},
53 'verbose|v+' => \
$Opt{'verbose'},
54 'version' => \
$Opt{'version'},
56 ) || die("$progname: Option error. Use -h for help.\n");
58 $Opt{'verbose'} -= $Opt{'quiet'};
59 $Opt{'help'} && usage
(0);
60 if ($Opt{'version'}) {
70 my $Lh = "[0-9a-fA-F]";
71 my $v1_templ = "$Lh\{8}-$Lh\{4}-1$Lh\{3}-$Lh\{4}-$Lh\{12}";
75 if (defined($ARGV[0])) {
78 die("$progname: No .wav file specified\n");
82 die("$progname: $wav_file: Cannot read file: $!\n");
85 die("$progname: $wav_file: Is a directory\n");
87 my $out_file = $wav_file;
88 $out_file =~ s/^(.*)\.wav$/$1.flac/i;
92 unlink($out_file) || die("$progname: $out_file: " .
93 "Cannot delete file: $!\n");
95 die("$progname: $out_file: File already exists, " .
96 "use -f / --force to overwrite\n");
100 my $flac_version = `flac --version`;
101 $flac_version =~ s/^\s+//;
102 $flac_version =~ s/\s+$//;
106 length($Opt{'album'}) &&
107 push(@Params, tag_string
("ALBUM", $Opt{'album'}));
108 length($Opt{'artist'}) &&
109 push(@Params, tag_string
("ARTIST", $Opt{'artist'}));
111 my $esc_wav_file = shell_escape
($wav_file);
112 my $suuid_cmd = "suuid -m -t encode -w eo " .
113 "-c \"$progname $esc_wav_file - $flac_version\"";
114 chomp(my $suuid_str = `$suuid_cmd`);
115 if (!defined($suuid_str) || $suuid_str !~ /^$v1_templ$/) {
116 die("$progname: suuid error\n");
118 push(@Params, "-TENC_ID=$suuid_str");
119 push(@Params, "-TENCODED_WITH=$flac_version");
121 length($Opt{'genre'}) &&
122 push(@Params, tag_string
("GENRE", $Opt{'genre'}));
123 length($Opt{'releasedate'}) &&
124 push(@Params, tag_string
("RELEASEDATE", $Opt{'releasedate'}));
125 length($Opt{'title'}) &&
126 push(@Params, tag_string
("TITLE", $Opt{'title'}));
127 length($Opt{'tracknumber'}) &&
128 push(@Params, tag_string
("TRACKNUMBER", $Opt{'tracknumber'}));
130 push(@Params, sprintf("%s", $wav_file));
132 msg
(1, join(" ", @Params));
139 # Return parameter for use with flac(1)
140 my ($Label, $Val) = @_;
141 my $Retval = "-T$Label=$Val";
155 # Print program version
156 print("$progname $VERSION\n");
161 # Send the help message to stdout
164 if ($Opt{'verbose'}) {
170 Usage: $progname [options] wav_file
172 Convert .wav to .flac .
179 Name of artist/group.
181 Overwrite existing files.
186 -n X, --tracknumber X
187 Track number of this song.
189 Be more quiet. Can be repeated to increase silence.
190 -r X, --releasedate X
191 The date the album was released.
195 Increase level of verbosity. Can be repeated.
197 Print version information.
204 # Print a status message to stderr based on verbosity level
205 my ($verbose_level, $Txt) = @_;
207 if ($Opt{'verbose'} >= $verbose_level) {
208 print(STDERR
"$progname: $Txt\n");
215 # This program is free software; you can redistribute it and/or modify it under
216 # the terms of the GNU General Public License as published by the Free Software
217 # Foundation; either version 2 of the License, or (at your option) any later
220 # This program is distributed in the hope that it will be useful, but WITHOUT
221 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
222 # FOR A PARTICULAR PURPOSE.
223 # See the GNU General Public License for more details.
225 # You should have received a copy of the GNU General Public License along with
227 # If not, see L<http://www.gnu.org/licenses/>.
229 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :