mirror of
https://github.com/moex3/flac2mp3.pl
synced 2024-11-25 20:48:12 -05:00
Compare commits
No commits in common. "7aebd5fc772e66617cf9f28587ca5c67c939acd9" and "dfb21dfc2bb2d519b6dd504bccea0310e2256b47" have entirely different histories.
7aebd5fc77
...
dfb21dfc2b
19
flac2mp3.pl
19
flac2mp3.pl
@ -93,10 +93,6 @@ 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 {
|
||||||
@ -105,7 +101,6 @@ 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);
|
||||||
@ -125,7 +120,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 {
|
||||||
@ -148,17 +143,15 @@ 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)) {
|
||||||
my $tagCont = $tags->{$currKey};
|
push(@tagopts, qq(--tv '$tagName=$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +159,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;
|
||||||
@ -175,10 +168,6 @@ 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