]> diplodocus.org Git - flac-archive/blobdiff - flac2mp3
Add DISCNUMBER support.
[flac-archive] / flac2mp3
index 69869a4ec4801695461d3f918fa1832f4e9b64ec..ab83c9f9528110eeab7a55fcc6b7ba8e10d63ea0 100755 (executable)
--- a/flac2mp3
+++ b/flac2mp3
@@ -8,14 +8,14 @@ B<flac2mp3> - transcode FLAC file to MP3 files
 
 =head1 SYNOPSIS
 
-B<flac2mp3> [B<--lame-options> I<lame-options>] [B<-q>] [B<-v>] I<file>
+B<flac2mp3> [B<--lame-options> I<lame-options>] [B<-q>] [B<-v>] I<file> [...]
 
 =head1 DESCRIPTION
 
-B<flac2mp3> transcodes the FLAC file I<file> to MP3 files.  I<file> is
-the kind of FLAC file B<fa-flacd> generates.  That is, it contains a
-cue sheet, one TITLE tag per track listed therein, and ARTIST, ALBUM,
-and DATE tags.
+B<flac2mp3> transcodes the FLAC files I<file> to MP3 files.  I<file>
+may be the kind of FLAC file B<fa-flacd> generates.  That is, it
+contains a cue sheet, one TITLE tag per track listed therein, and
+ARTIST, ALBUM, and DATE tags.
 
 =cut
 
@@ -85,6 +85,11 @@ sub get_decode_args {
         push(@args, $arg);
     }
 
+    # If no cue sheet, stick a dummy in here.
+    if (@args == 0) {
+        @args = ([]);
+    }
+
     return @args;
 }
 
@@ -99,6 +104,7 @@ sub get_tags {
     my $artist;
     my $album;
     my $date;
+    my $discnum;
     my $track;
 
     open(TAGS, '-|', 'metaflac', '--export-vc-to=-', $fn)
@@ -114,6 +120,8 @@ sub get_tags {
             $album = $value;
         } elsif (/^DATE=/i) {
             $date = $value;
+        } elsif (/^DISCNUMBER=/i) {
+            $discnum = int($value);
         } elsif (/^ARTIST\[/i) {
             push(@$artists, $value);
         } elsif (/^TRACKNUMBER=/i) {
@@ -127,7 +135,7 @@ sub get_tags {
     }
     close(TAGS) or die("close(metaflac --export-vc-to=- $fn): $?");
 
-    return ($artist, $album, $date, $track);
+    return ($artist, $album, $date, $discnum, $track);
 }
 
 sub arg {
@@ -147,7 +155,7 @@ sub flac2mp3 {
     my $artist = shift;
     my $album = shift;
     my $date = shift;
-    my $track = shift;
+    my $track = int(shift);
     my $skip_arg = shift;
     my $until_arg = shift;
     my @tmp;
@@ -184,6 +192,7 @@ sub flac2mp3 {
     arg('--ty', \$date);
     arg('--tn', \$track);
 
+    $skip_arg ||= '';
     $until_arg ||= '';
     run_or_die(join(' ', "flac $flac_options -cd $skip_arg $until_arg '$fn'",
                     " | lame $lame_options $title $artist $album $date $track",
@@ -200,21 +209,27 @@ MAIN: {
               ) or pod2usage();
     $help and pod2usage(-exitstatus=>0, -verbose=>1);
 
-    my $fn = shift or pod2usage();
-    my @args = get_decode_args($fn);
-    my (@artists, @titles);
-    my ($artist, $album, $date, $track) = get_tags($fn, \@artists, \@titles);
-
-    # Stupid hack: only a single-track file should have the
-    # TRACKNUMBER tag, so use it if set for the first pass through the
-    # loop.  At the end of the loop, we'll set $track for the next
-    # run, so this continues to work for multi-track files.
-    $track ||= 1;
-
-    for my $i (0..$#titles) {
-        flac2mp3($fn, $titles[$i], ($artists[$i] or $artist), $album, $date,
-                 $track, (defined($args[$i]) and @{$args[$i]} or ''));
-        $track = $i + 2;
+    @ARGV or pod2usage();
+    for my $fn (@ARGV) {
+        my @args = get_decode_args($fn);
+        my (@artists, @titles);
+        my ($artist, $album, $date, $discnum, $track) = get_tags($fn, \@artists,
+                                                                 \@titles);
+
+        # lame doesn't seem to support disc number.
+        defined($discnum) and $album .= " (disc $discnum)";
+
+        # Stupid hack: only a single-track file should have the
+        # TRACKNUMBER tag, so use it if set for the first pass through
+        # the loop.  At the end of the loop, we'll set $track for the
+        # next run, so this continues to work for multi-track files.
+        $track ||= 1;
+
+        for my $i (0..$#titles) {
+            flac2mp3($fn, $titles[$i], ($artists[$i] or $artist), $album, $date,
+                     $track, @{$args[$i]});
+            $track = $i + 2;
+        }
     }
 }