- my $fn = shift;
- my $title = shift;
- my $artist = shift;
- my $album = shift;
- my $date = shift;
- my $track = int(shift);
- my $skip_arg = shift;
- my $until_arg = shift;
- my @tmp;
- my $outfile;
-
- if ($quiet) {
- $flac_options = '--silent';
- } else {
- $flac_options = '';
- }
-
- if ($lame_options) {
- push(@tmp, $lame_options);
- } else {
- push(@tmp, '--preset standard');
- }
- $quiet and push(@tmp, '--quiet');
- $verbose and push(@tmp, '--verbose');
- $lame_options = join(' ', @tmp);
-
- # We'll be putting these in single quotes, so we need to escape
- # any single quotes in the filename by closing the quote ('),
- # putting an escaped quote (\'), and then reopening the quote (').
- for ($fn, $title, $artist, $album, $date) {
- defined and s/'/'\\''/g;
- }
-
- $outfile = sprintf("$artist ($album) \%02s $title.mp3", $track);
- $outfile =~ s/\//_/g;
-
- arg('--tt', \$title);
- arg('--ta', \$artist);
- arg('--tl', \$album);
- 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",
- " - '$outfile'"));
-}
-
-MAIN: {
- my $help;
- GetOptions(
- 'lame-options=s', \$lame_options,
- 'quiet|q' => \$quiet,
- 'verbose|v' => \$verbose,
- 'help|h|?' => \$help,
- ) or pod2usage();
- $help and pod2usage(-exitstatus=>0, -verbose=>1);
-
- @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)";