public
Last active

  • Download Gist
flac2mp3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
use strict;
use warnings;
use File::Find::Rule;
 
my %id_names = (
artist => 'ta',
year => 'ty',
date => 'ty', # alias
comment => 'tc',
album => 'tl',
title => 'tt',
tracknumber => 'tn',
genre => 'tg',
);
 
my $target_dir = 'mp3';
 
my @files = File::Find::Rule
->name('*.flac')
->file()
->in('.');
 
exit 0 unless @files;
 
mkdir $target_dir unless -d $target_dir;
 
for my $file (@files) {
my $q_file = quotemeta($file);
(my $mp3_file = $q_file) =~ s/flac/mp3/;
my @data = qx(metaflac --export-tags-to=- $q_file);
 
my %id;
foreach (@data) {
chomp;
 
my ($key, $value) = split('=', $_, 2);
$id{$key} = $value;
}
$id{tracknumber} .= '/' . scalar(@files) if (exists $id{tracknumber});
 
my $ids = '';
 
foreach(keys %id) {
$ids .= ' --' . $id_names{$_} . qq! "$id{$_}"!;
}
 
my $cmd = "flac -c -d $q_file | lame -V 0 $ids - $target_dir/$mp3_file";
 
qx($cmd);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.