Created
January 27, 2011 21:32
-
-
Save baest/799328 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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