+ return ($artist, $album, $discnum, @tags);
+}
+
+sub bork_tags {
+ my $h = shift;
+ my @result;
+
+ while (my ($key, $vall) = each(%$h)) {
+ for my $val (@$vall) {
+ push(@result, "$key=$val")
+ }
+ }
+
+ return @result;
+}
+
+sub run_flac {
+ my $infile = shift;
+ my $cue = shift;
+ my $outfile = shift;
+
+ my @cue;
+ if (defined($cue)) {
+ @cue = ('--cuesheet', $cue);
+ }
+
+ verbose("Running flac\n");
+ my $status = system('flac', '-o', "$outfile.flac-tmp",
+ '--delete-input-file', '-V', '--no-padding', '--best',
+ @cue,
+ map({ ('-T', $_) } @_),
+ $infile);
+ if (WIFEXITED($status)) {
+ if (($status = WEXITSTATUS($status)) != 0) {
+ die("flac exited with status $status");
+ }
+ } elsif (WIFSIGNALED($status)) {
+ die("flac killed with signal ", WTERMSIG($status));
+ } elsif (WIFSTOPPED($status)) {
+ die("flac stopped with signal ", WSTOPSIG($status));
+ } else {
+ die("Major horkage on system(flac): \$? = $? \$! = $!");
+ }
+
+ rename("$outfile.flac-tmp", "$outfile.flac")
+ or die("rename($outfile.flac-tmp, $outfile.flac): $!");