mirror of
https://github.com/moex3/flac2mp3.pl
synced 2024-11-21 19:44:15 -05:00
Multiple changes:
Add publisher tag Copy or apply replaygain Copy lyrics tags
This commit is contained in:
parent
63edb804ce
commit
d44c74e40f
138
flac2mp3.pl
138
flac2mp3.pl
@ -12,12 +12,10 @@ my $opt_comment;
|
|||||||
my $opt_catid;
|
my $opt_catid;
|
||||||
my $opt_rg;
|
my $opt_rg;
|
||||||
my $opt_embedcover;
|
my $opt_embedcover;
|
||||||
|
my $opt_publisher;
|
||||||
|
|
||||||
# TODO fill this out
|
# Additional encode options for a single track
|
||||||
my %genreMap = (
|
my $LAME_opts = "";
|
||||||
edm => 52,
|
|
||||||
soundtrack => 24,
|
|
||||||
);
|
|
||||||
|
|
||||||
# this is a godsent page
|
# this is a godsent page
|
||||||
# https://wiki.hydrogenaud.io/index.php?title=Tag_Mapping
|
# https://wiki.hydrogenaud.io/index.php?title=Tag_Mapping
|
||||||
@ -110,11 +108,7 @@ my %idLookup = (
|
|||||||
return undef if ($opt_no_genre);
|
return undef if ($opt_no_genre);
|
||||||
|
|
||||||
my $genreName = shift->{genre}[0];
|
my $genreName = shift->{genre}[0];
|
||||||
if (!exists($genreMap{lc($genreName)})) {
|
return mp3TagEscapeOwn($genreName);
|
||||||
# If no genre number exists, use the name
|
|
||||||
return mp3TagEscapeOwn($genreName);
|
|
||||||
}
|
|
||||||
return mp3TagEscapeOwn($genreMap{$genreName});
|
|
||||||
}],
|
}],
|
||||||
#mood => ['TMOO', sub {
|
#mood => ['TMOO', sub {
|
||||||
#}],
|
#}],
|
||||||
@ -129,22 +123,50 @@ my %idLookup = (
|
|||||||
#replaygain_album_peak => 'TXXX=REPLAYGAIN_ALBUM_PEAK',
|
#replaygain_album_peak => 'TXXX=REPLAYGAIN_ALBUM_PEAK',
|
||||||
#replaygain_album_gain => 'TXXX=REPLAYGAIN_ALBUM_GAIN',
|
#replaygain_album_gain => 'TXXX=REPLAYGAIN_ALBUM_GAIN',
|
||||||
replaygain_track_gain => sub {
|
replaygain_track_gain => sub {
|
||||||
print("EEEEEEERRRRRRRRROOOOOOOOOORRRRRRRRRRRE FIXXXXXXXXXXXX THIIIIIIIIISSSSSSSS\n");
|
my $gain_db = getGainFromTag(shift->{replaygain_track_gain}[0]);
|
||||||
exit(1);
|
|
||||||
return undef if (!$opt_rg);
|
if ($opt_rg) {
|
||||||
shift->{replaygain_track_gain}[0] =~ /^(-?\d+\.\d+) dB$/;
|
print("REPLAYGAIN :::::::::::::::: MODIFYING FILE\n");
|
||||||
my $gain_db = $1;
|
# Modify file
|
||||||
exit(1) if ($gain_db eq "");
|
$LAME_opts .= " --replaygain-accurate --gain $gain_db";
|
||||||
return "--replaygain-accurate --gain $gain_db";
|
#print("Added LAME opt: $LAME_opts\n");
|
||||||
# TODO this lulw
|
return undef;
|
||||||
|
} else {
|
||||||
|
print("REPLAYGAIN :::::::::::::::: COPYING TAG\n");
|
||||||
|
# Copy tags
|
||||||
|
return ["TXXX", "REPLAYGAIN_TRACK_GAIN:" . mp3TagEscapeOwn("$gain_db dB")];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
replaygain_track_peak => sub {
|
||||||
|
my $peak = shift->{replaygain_track_peak}[0];
|
||||||
|
|
||||||
|
if ($opt_rg) {
|
||||||
|
# Modify file
|
||||||
|
$LAME_opts .= " --replaygain-accurate";
|
||||||
|
#print("Added LAME opt: $LAME_opts\n");
|
||||||
|
return undef;
|
||||||
|
} else {
|
||||||
|
# Copy tags
|
||||||
|
return ["TXXX", "REPLAYGAIN_TRACK_PEAK:" . mp3TagEscapeOwn("$peak")];
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
#replaygain_album_gain => 'TXXX=REPLAYGAIN_ALBUM_GAIN',
|
#replaygain_album_gain => 'TXXX=REPLAYGAIN_ALBUM_GAIN',
|
||||||
#replaygain_album_peak => 'TXXX=REPLAYGAIN_ALBUM_PEAK',
|
#replaygain_album_peak => 'TXXX=REPLAYGAIN_ALBUM_PEAK',
|
||||||
#replaygain_track_gain => 'TXXX=REPLAYGAIN_TRACK_GAIN',
|
#replaygain_track_gain => 'TXXX=REPLAYGAIN_TRACK_GAIN',
|
||||||
#replaygain_track_peak => 'TXXX=REPLAYGAIN_TRACK_PEAK',
|
|
||||||
script => ['TXXX', 'SCRIPT:'],
|
script => ['TXXX', 'SCRIPT:'],
|
||||||
lyrics => 'USLT',
|
#lyrics => 'USLT',
|
||||||
|
#unsyncedlyrics => 'USLT',
|
||||||
|
unsyncedlyrics => sub {
|
||||||
|
my @lyrArr = @{shift->{unsyncedlyrics}};
|
||||||
|
my $tagStr = "";
|
||||||
|
|
||||||
|
foreach (@lyrArr) {
|
||||||
|
$tagStr .= mp3TagEscapeOwn($_) . "\\n";
|
||||||
|
}
|
||||||
|
# TODO figure out how to set language here
|
||||||
|
return ["USLT", "$tagStr"];
|
||||||
|
},
|
||||||
lyricist => 'TEXT',
|
lyricist => 'TEXT',
|
||||||
circle => ['TXXX', 'CIRCLE:'],
|
circle => ['TXXX', 'CIRCLE:'],
|
||||||
event => ['TXXX', 'EVENT:'],
|
event => ['TXXX', 'EVENT:'],
|
||||||
@ -160,6 +182,18 @@ sub tagmap_catalogid {
|
|||||||
return $t->{$own_tag_name}[0];
|
return $t->{$own_tag_name}[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub getGainFromTag {
|
||||||
|
my $tagVal = shift;
|
||||||
|
|
||||||
|
$tagVal =~ /^([-+]?\d+\.\d+) dB$/;
|
||||||
|
my $gain_db = $1;
|
||||||
|
if ($gain_db eq "") {
|
||||||
|
print("gain FAIL...: $tagVal\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return $gain_db;
|
||||||
|
}
|
||||||
|
|
||||||
my $opt_genre;
|
my $opt_genre;
|
||||||
my $opt_help;
|
my $opt_help;
|
||||||
my @opt_tagreplace;
|
my @opt_tagreplace;
|
||||||
@ -172,6 +206,7 @@ GetOptions(
|
|||||||
"catid=s" => \$opt_catid,
|
"catid=s" => \$opt_catid,
|
||||||
"comment=s" => \$opt_comment,
|
"comment=s" => \$opt_comment,
|
||||||
"cover=s" => \$opt_embedcover,
|
"cover=s" => \$opt_embedcover,
|
||||||
|
"pub=s" => \$opt_publisher,
|
||||||
"tagreplace|t=s" => \@opt_tagreplace,
|
"tagreplace|t=s" => \@opt_tagreplace,
|
||||||
"320|3" => \$opt_cbr,
|
"320|3" => \$opt_cbr,
|
||||||
) or die("Error in command line option");
|
) or die("Error in command line option");
|
||||||
@ -206,6 +241,7 @@ sub iterFlac {
|
|||||||
#print("DEBUG: $dest\n");
|
#print("DEBUG: $dest\n");
|
||||||
$dest =~ s/\.flac$/\.mp3/;
|
$dest =~ s/\.flac$/\.mp3/;
|
||||||
my $tags = getFlacTags($flac);
|
my $tags = getFlacTags($flac);
|
||||||
|
#print(Dumper($tags));
|
||||||
|
|
||||||
my $has_req_tags = 1;
|
my $has_req_tags = 1;
|
||||||
foreach (@required_tags) {
|
foreach (@required_tags) {
|
||||||
@ -226,19 +262,25 @@ sub iterFlac {
|
|||||||
#}
|
#}
|
||||||
my $tagopts = tagsToOpts($tags);
|
my $tagopts = tagsToOpts($tags);
|
||||||
|
|
||||||
#print("Debug: @$tagopts\n");
|
#print(Dumper($tagopts));
|
||||||
|
|
||||||
|
$dest =~ m!(.*)/[^/]+!;
|
||||||
|
my $basedir = $1;
|
||||||
|
mkdir($basedir) if (not -f $basedir);
|
||||||
|
|
||||||
shellsan(\$dest);
|
shellsan(\$dest);
|
||||||
my $cmd;
|
my $cmd;
|
||||||
if ($opt_cbr) {
|
if ($opt_cbr) {
|
||||||
$cmd = "flac -cd -- '$flac' | lame -S -b 320 -q 0 --add-id3v2 - '$dest'";
|
$cmd = "flac -cd -- '$flac' | lame $LAME_opts -S -b 320 -q 0 --add-id3v2 - '$dest'";
|
||||||
} else {
|
} else {
|
||||||
$cmd = "flac -cd -- '$flac' | lame -S -V0 --vbr-new -q 0 --add-id3v2 - '$dest'";
|
$cmd = "flac -cd -- '$flac' | lame $LAME_opts -S -V0 --vbr-new -q 0 --add-id3v2 - '$dest'";
|
||||||
}
|
}
|
||||||
#print("Debug - CMD: [$cmd]\n");
|
#print("Debug - CMD: [$cmd]\n");
|
||||||
qx($cmd);
|
qx($cmd);
|
||||||
if ($? != 0) {
|
if ($? != 0) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
$LAME_opts = ""; # Reset for the next track
|
||||||
|
|
||||||
my $mid3v2TagLine = "";
|
my $mid3v2TagLine = "";
|
||||||
#print(Dumper(\@$tagopts));
|
#print(Dumper(\@$tagopts));
|
||||||
@ -311,6 +353,13 @@ sub argsToTags {
|
|||||||
$argTags->{comment} = [$opt_comment];
|
$argTags->{comment} = [$opt_comment];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (defined($opt_publisher)) {
|
||||||
|
if ($opt_publisher eq "") {
|
||||||
|
delete($argTags->{organization});
|
||||||
|
} else {
|
||||||
|
$argTags->{organization} = [$opt_publisher];
|
||||||
|
}
|
||||||
|
}
|
||||||
if (defined($opt_catid) && $opt_catid ne "") {
|
if (defined($opt_catid) && $opt_catid ne "") {
|
||||||
$argTags->{catalognumber} = [$opt_catid];
|
$argTags->{catalognumber} = [$opt_catid];
|
||||||
}
|
}
|
||||||
@ -403,6 +452,7 @@ sub tagsToOpts {
|
|||||||
#}
|
#}
|
||||||
|
|
||||||
my $codeRet = $tagMapping->($tags);
|
my $codeRet = $tagMapping->($tags);
|
||||||
|
next if (not defined($codeRet));
|
||||||
my $mapKey = $codeRet->[0];
|
my $mapKey = $codeRet->[0];
|
||||||
my $mapCont = $codeRet->[1];
|
my $mapCont = $codeRet->[1];
|
||||||
shellsan(\$mapCont);
|
shellsan(\$mapCont);
|
||||||
@ -430,17 +480,30 @@ sub getFlacTags {
|
|||||||
if ($? != 0) {
|
if ($? != 0) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
my $curr_tag = "";
|
||||||
foreach my $tagline (@tagtxt) {
|
foreach my $tagline (@tagtxt) {
|
||||||
if ($tagline =~ /comment\[\d+\]:\s(.*?)=(.*)/) {
|
if ($tagline =~ /^\s+comment\[\d+\]:\s(.*?)=(.*)/) {
|
||||||
if ($2 eq '') {
|
if ($2 eq '') {
|
||||||
print("Empty tag: $1\n");
|
print("Empty tag: $1\n");
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if (not exists($tags{lc($1)})) {
|
$curr_tag = lc($1);
|
||||||
@{$tags{lc($1)}} = ($2);
|
if (not exists($tags{$curr_tag})) {
|
||||||
|
@{$tags{$curr_tag}} = ($2);
|
||||||
} else {
|
} else {
|
||||||
push(@{$tags{lc($1)}}, $2);
|
push(@{$tags{$curr_tag}}, $2);
|
||||||
}
|
}
|
||||||
|
} elsif ($curr_tag ne "") {
|
||||||
|
# Maybe multi line? (like lyrics) store if it was multiple tag=value fields
|
||||||
|
chomp($tagline);
|
||||||
|
push(@{$tags{$curr_tag}}, $tagline);
|
||||||
|
#if (ref(@{$tags{$curr_tag}}) eq "") {
|
||||||
|
# Second line
|
||||||
|
#@{$tags{$curr_tag}} = (@{$tags{$curr_tag}}, $tagline);
|
||||||
|
#} else {
|
||||||
|
# 3rd, or later line
|
||||||
|
#push(@{$tags{$curr_tag}}, $tagline);
|
||||||
|
#}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return \%tags;
|
return \%tags;
|
||||||
@ -470,16 +533,17 @@ sub help {
|
|||||||
Usage:
|
Usage:
|
||||||
flac2mp3.pl [options] <input_dir> <output_dir>
|
flac2mp3.pl [options] <input_dir> <output_dir>
|
||||||
|
|
||||||
-h, --help print this help text
|
-h, --help print this help text
|
||||||
-g, --genre NUM force this genre as a tag (lame --genre-list)
|
-g, --genre NUM force this genre as a tag (lame --genre-list)
|
||||||
-G, --no-genre ignore genre in flac file
|
-G, --no-genre ignore genre in flac file
|
||||||
-r, --replay-gain use replay gain values
|
-r, --replay-gain modify file with the replay-gain values
|
||||||
--catid STRING the catalog id to set (or "")
|
--catid STRING the catalog id to set (or "")
|
||||||
--comment STRING the comment to set (or "")
|
--comment STRING the comment to set (or "")
|
||||||
--cover STRING Use this image as cover (or "" to not copy from flac)
|
--cover STRING Use this image as cover (or "" to not copy from flac)
|
||||||
-t --tagreplace STR Replace flac tags for a specific file only
|
--pub STRING Publisher
|
||||||
Like -t '02*flac/TITLE=Some other title'
|
-t --tagreplace STR Replace flac tags for a specific file only
|
||||||
-3, --320 Convert into CBR 320 instead into the default V0
|
Like -t '02*flac/TITLE=Some other title'
|
||||||
|
-3, --320 Convert into CBR 320 instead into the default V0
|
||||||
EOF
|
EOF
|
||||||
print($h);
|
print($h);
|
||||||
exit 0;
|
exit 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user