Skip to content

Instantly share code, notes, and snippets.

@baest
Created January 27, 2011 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baest/799328 to your computer and use it in GitHub Desktop.
Save baest/799328 to your computer and use it in GitHub Desktop.
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment