]> diplodocus.org Git - flac-archive/blobdiff - fa-flacd
Lose mkcue and require MusicBrainz::Client >= 0.09 (for release dates).
[flac-archive] / fa-flacd
index 50a936cbce7698c70beb4d24ed0d1e99daee88c0..3c3637241b12b2ea8cac3b8227cf8572a4e18ead 100755 (executable)
--- a/fa-flacd
+++ b/fa-flacd
@@ -21,6 +21,7 @@ use Getopt::Long qw(:config gnu_getopt no_ignore_case);
 use POSIX ':sys_wait_h';
 use Pod::Usage;
 
+my $debug;
 my $verbose;
 my @jobs;
 my @finished;
@@ -37,6 +38,7 @@ sub get_tags {
     my $value;
     my $artist;
     my $album;
+    my $discnum;
     my @tags;
 
     verbose("Opening tags file $fn\n");
@@ -47,17 +49,20 @@ sub get_tags {
 
         ($tag, $value) = split(/=/, $_, 2);
 
-        if (/^ARTIST=/) {
+        if (/^ARTIST=/i) {
             $artist = $value;
             verbose("ARTIST $artist from $fn\n");
-        } elsif (/^ALBUM=/) {
+        } elsif (/^ALBUM=/i) {
             $album = $value;
-            verbose("ALBUM $album from $fn\n");
+            verbose("ALBUM $album from $fn\n"); # cperl-mode sucks "
+        } elsif (/^DISCNUMBER=/i) {
+            $discnum = int($value);
+            verbose("DISCNUMBER $discnum from $fn\n");
         }
     }
     close(TAGS) or die("close($fn): $!");
 
-    return ($artist, $album, @tags);
+    return ($artist, $album, $discnum, @tags);
 }
 
 # Process the fa-rip output in the directory DIR.
@@ -65,6 +70,7 @@ sub flac {
     my $dir = shift;
     my $artist;
     my $album;
+    my $discnum;
     my @tags;
     my $outfile;
     my $status;
@@ -73,7 +79,7 @@ sub flac {
     rename("$dir/tags", "$dir/using-tags")
       or die("rename($dir/tags, $dir/using-tags): $!");
 
-    ($artist, $album, @tags) = get_tags("$dir/using-tags");
+    ($artist, $album, $discnum, @tags) = get_tags("$dir/using-tags");
 
     verbose("mkdir($artist)\n");
     -d $artist or mkdir($artist) or die("mkdir($artist): $!");
@@ -82,6 +88,7 @@ sub flac {
     chdir($dir) or die("chdir($dir): $!");
 
     $outfile = "$album";
+    defined($discnum) and $outfile .= " (disc $discnum)";
     $outfile =~ s/\//_/g;
 
     verbose("Running flac\n");
@@ -137,10 +144,14 @@ sub newjob {
     my $dir = shift;
     my $pid;
 
-    $pid = fork();
-    if (not defined($pid)) {
-        die("fork: $!");
-    } elsif ($pid == 0) {
+    if (not $debug) {
+        $pid = fork();
+        if (not defined($pid)) {
+            die("fork: $!");
+        }
+    }
+
+    if ($debug or $pid == 0) {
         $SIG{CHLD} = 'IGNORE';
         open(STDERR, ">$dir/log") or die("open(STDERR, >$dir/log): $!");
         exit(flac($dir));
@@ -205,6 +216,7 @@ MAIN: {
 
     $jobs = 4;
     GetOptions(
+               'debug|X' => \$debug,
                'jobs|j=i' => \$jobs,
                'verbose|v' => \$verbose,
                'help|h|?' => \$help,