]> diplodocus.org Git - flac-archive/blobdiff - fa-flacd
Fix r1932 (i told you it was untested).
[flac-archive] / fa-flacd
index 69566ac0f68e7a6ff4b6ee24834f2808305faaa5..b9f883cfd5230dfc1060837be395d465cc3234b4 100755 (executable)
--- a/fa-flacd
+++ b/fa-flacd
@@ -65,16 +65,6 @@ sub get_tags {
     return ($artist, $album, $discnum, @tags);
 }
 
-# Hash of Hashes of Lists Push
-sub hhlp {
-    my $hash = shift;
-    my $key1 = shift;
-    my $key2 = shift;
-    my $val = shift;
-
-    return push(@{$hash->{$key1}->{$key2}}, $val);
-}
-
 sub bork_tags {
     my $h = shift;
     my @result;
@@ -88,6 +78,38 @@ sub bork_tags {
     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): $!");
+}
+
 # Process the fa-rip output in the directory DIR.
 sub flac {
     my $dir = shift;
@@ -96,7 +118,6 @@ sub flac {
     my $discnum;
     my @tags;
     my $outfile;
-    my $status;
 
     verbose("Renaming $dir/tags\n");
     rename("$dir/tags", "$dir/using-tags")
@@ -122,7 +143,7 @@ sub flac {
     my (@bork, @titles);
     for my $tag (@tags) {
         if ($tag =~ /^([^[]+)\[(\d+)]=(.*)/) {
-            hhlp(\%things, $2, $1, $3);
+            push(@{$things{$2}->{$1}}, $3);
         } elsif ($tag =~ /^ARTIST=/) {
             push(@artist, $tag);
         } else {
@@ -151,28 +172,10 @@ sub flac {
             @lartist = @artist;
         }
 
-        verbose("Running flac\n");
-        $status = system('flac', '-o', "$outfile.flac-tmp",
-                         '--delete-input-file', '-V', '--no-padding', '--best',
-                         map({ ('-T', $_) }
-                             @lartist,
-                             grep({ $_ !~ /^ARTIST=/ } @tags),
-                             bork_tags($things{$tracknum})),
-                         sprintf('track%02d.cdda.wav', $tracknum));
-        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): $!");
+        run_flac(sprintf('track%02d.cdda.wav', $tracknum), undef, $outfile,
+                 @lartist,
+                 grep({ $_ !~ /^ARTIST=/ } @tags),
+                 bork_tags($things{$tracknum}));
     }
 
     verbose("Cleaning up $dir\n");