mirror of
https://github.com/moex3/flac2mp3.pl
synced 2024-11-22 03:54:15 -05:00
Compare commits
2 Commits
dfb21dfc2b
...
7aebd5fc77
Author | SHA1 | Date | |
---|---|---|---|
|
7aebd5fc77 | ||
|
f8bd0b2004 |
19
flac2mp3.pl
19
flac2mp3.pl
@ -93,6 +93,10 @@ if (scalar(@ARGV) != 2) {
|
|||||||
|
|
||||||
my ($IDIR, $ODIR) = @ARGV;
|
my ($IDIR, $ODIR) = @ARGV;
|
||||||
|
|
||||||
|
if (!-e $ODIR) {
|
||||||
|
mkdir $ODIR;
|
||||||
|
}
|
||||||
|
|
||||||
find({ wanted => \&iterFlac, no_chdir => 1 }, $IDIR);
|
find({ wanted => \&iterFlac, no_chdir => 1 }, $IDIR);
|
||||||
|
|
||||||
sub iterFlac {
|
sub iterFlac {
|
||||||
@ -101,6 +105,7 @@ sub iterFlac {
|
|||||||
|
|
||||||
my @required_tags = ("artist", "title", "album", "tracknumber");
|
my @required_tags = ("artist", "title", "album", "tracknumber");
|
||||||
my $flac = $_;
|
my $flac = $_;
|
||||||
|
shellsan(\$flac);
|
||||||
my $dest = "$ODIR/" . basename($flac);
|
my $dest = "$ODIR/" . basename($flac);
|
||||||
$dest =~ s/\.flac$/\.mp3/;
|
$dest =~ s/\.flac$/\.mp3/;
|
||||||
my $tags = getFlacTags($flac);
|
my $tags = getFlacTags($flac);
|
||||||
@ -120,7 +125,7 @@ sub iterFlac {
|
|||||||
argsToTags($tags);
|
argsToTags($tags);
|
||||||
my $tagopts = tagsToOpts($tags);
|
my $tagopts = tagsToOpts($tags);
|
||||||
|
|
||||||
qx(flac -cd "$flac" | lame -V0 -S --vbr-new --add-id3v2 @$tagopts - "$dest");
|
qx(flac -cd -- '$flac' | lame -V0 -S --vbr-new --add-id3v2 @$tagopts - '$dest');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub argsToTags {
|
sub argsToTags {
|
||||||
@ -143,15 +148,17 @@ sub tagsToOpts {
|
|||||||
my $tagName = $idLookup{$currKey};
|
my $tagName = $idLookup{$currKey};
|
||||||
my $type = ref($tagName);
|
my $type = ref($tagName);
|
||||||
if ($type eq "" && defined($tagName)) {
|
if ($type eq "" && defined($tagName)) {
|
||||||
push(@tagopts, qq(--tv '$tagName=$tags->{$currKey}'));
|
my $tagCont = $tags->{$currKey};
|
||||||
|
shellsan(\$tagCont);
|
||||||
|
push(@tagopts, qq(--tv '$tagName=$tagCont'));
|
||||||
} elsif ($type eq "ARRAY") {
|
} elsif ($type eq "ARRAY") {
|
||||||
my $tagCont = $tagName->[1]->($tags);
|
my $tagCont = $tagName->[1]->($tags);
|
||||||
|
shellsan(\$tagCont);
|
||||||
push(@tagopts, qq(--tv '$tagName->[0]=$tagCont'));
|
push(@tagopts, qq(--tv '$tagName->[0]=$tagCont'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#print(Dumper(\@tagopts));
|
|
||||||
return \@tagopts;
|
return \@tagopts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +166,7 @@ sub getFlacTags {
|
|||||||
my $flac = shift;
|
my $flac = shift;
|
||||||
|
|
||||||
my %tags;
|
my %tags;
|
||||||
my @tagtxt = qx(metaflac --list --block-type=VORBIS_COMMENT -- "$flac");
|
my @tagtxt = qx(metaflac --list --block-type=VORBIS_COMMENT -- '$flac');
|
||||||
foreach my $tagline (@tagtxt) {
|
foreach my $tagline (@tagtxt) {
|
||||||
if ($tagline =~ /comment\[\d+\]:\s(.*?)=(.*)/) {
|
if ($tagline =~ /comment\[\d+\]:\s(.*?)=(.*)/) {
|
||||||
$tags{lc($1)} = $2;
|
$tags{lc($1)} = $2;
|
||||||
@ -168,6 +175,10 @@ sub getFlacTags {
|
|||||||
return \%tags;
|
return \%tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub shellsan {
|
||||||
|
${$_[0]} =~ s/'/'\\''/g;
|
||||||
|
}
|
||||||
|
|
||||||
sub usage {
|
sub usage {
|
||||||
print("Usage: flac2mp3.pl [-h | --help] [-g | --genre NUM] <input_dir> <output_dir>\n");
|
print("Usage: flac2mp3.pl [-h | --help] [-g | --genre NUM] <input_dir> <output_dir>\n");
|
||||||
exit 1;
|
exit 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user