diff --git a/flac2mp3.pl b/flac2mp3.pl index 03d8d50..0c4ed2b 100755 --- a/flac2mp3.pl +++ b/flac2mp3.pl @@ -105,6 +105,7 @@ sub iterFlac { my @required_tags = ("artist", "title", "album", "tracknumber"); my $flac = $_; + shellsan(\$flac); my $dest = "$ODIR/" . basename($flac); $dest =~ s/\.flac$/\.mp3/; my $tags = getFlacTags($flac); @@ -124,8 +125,7 @@ sub iterFlac { argsToTags($tags); my $tagopts = tagsToOpts($tags); - $flac =~ s!'!'\\''!g; - 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 { @@ -148,15 +148,17 @@ sub tagsToOpts { my $tagName = $idLookup{$currKey}; my $type = ref($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") { my $tagCont = $tagName->[1]->($tags); + shellsan(\$tagCont); push(@tagopts, qq(--tv '$tagName->[0]=$tagCont')); } } - #print(Dumper(\@tagopts)); return \@tagopts; } @@ -164,7 +166,7 @@ sub getFlacTags { my $flac = shift; 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) { if ($tagline =~ /comment\[\d+\]:\s(.*?)=(.*)/) { $tags{lc($1)} = $2; @@ -173,6 +175,10 @@ sub getFlacTags { return \%tags; } +sub shellsan { + ${$_[0]} =~ s/'/'\\''/g; +} + sub usage { print("Usage: flac2mp3.pl [-h | --help] [-g | --genre NUM] \n"); exit 1;