1
0
mirror of https://github.com/moex3/flac2mp3.pl synced 2024-11-22 03:54:15 -05:00

Add comment & catalog option, improve genre option

This commit is contained in:
moex3 2021-08-01 17:46:19 +02:00
parent 7aebd5fc77
commit f75c7fa582
No known key found for this signature in database
GPG Key ID: ABC92E00CF59BB7A
2 changed files with 61 additions and 16 deletions

View File

@ -8,8 +8,8 @@ Dependencies: `flac` `metaflac` `lame`
flac2mp3.pl ~/flacs ~/mp3 flac2mp3.pl ~/flacs ~/mp3
``` ```
Tags can be overridden with options. Only the genre tag is supported rith now. Some tags can be overridden with options.
```bash ```bash
flac2mp3.pl --genre 145 ~/flacs ~/mp3 flac2mp3.pl --genre 145 --comment "yes" ~/flacs ~/mp3
``` ```
This would add the genre as 'Anime'. Run `lame --genre-list` for the whole list. Can be specified multiple ones, with comma separation (i think). This would add the genre as 'Anime'. Run `lame --genre-list` for the whole list. Can be specified multiple ones, with comma separation (i think).

View File

@ -6,9 +6,20 @@ use File::Find;
use Data::Dumper; use Data::Dumper;
use File::Basename; use File::Basename;
my $opt_no_genre;
my $opt_comment;
my $opt_catid;
# TODO fill this out
my %genreMap = (
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
# a lot of this may not work # a lot of this may not work
# TODO escape potential 's
my %idLookup = ( my %idLookup = (
album => 'TALB', album => 'TALB',
albumsort => 'TSOA', albumsort => 'TSOA',
@ -36,23 +47,28 @@ my %idLookup = (
remixer => 'TPE4', remixer => 'TPE4',
discnumber => ['TPOS', sub { discnumber => ['TPOS', sub {
my $t = shift; my $t = shift;
return "$t->{discnumber}" if !exists($t->{disctotal}); my $totalkey = exists($t->{disctotal}) ? 'disctotal' : 'totaldiscs';
return "$t->{discnumber}/$t->{disctotal}"; return "$t->{discnumber}" if !exists($t->{$totalkey});
return "$t->{discnumber}/$t->{$totalkey}";
}], }],
totaldiscs => undef,
disctotal => undef, disctotal => undef,
tracknumber => ['TRCK', sub { tracknumber => ['TRCK', sub {
my $t = shift; my $t = shift;
return "$t->{tracknumber}" if !exists($t->{tracktotal}); my $totalkey = exists($t->{tracktotal}) ? 'tracktotal' : 'totaltracks';
return "$t->{tracknumber}/$t->{tracktotal}"; return "$t->{tracknumber}" if !exists($t->{$totalkey});
return "$t->{tracknumber}/$t->{$totalkey}";
}], }],
totaltracks => undef,
tracktotal => undef, tracktotal => undef,
date => 'TDRC', # This is for id3v2.4 #date => 'TDRC', # This is for id3v2.4
date => 'TYER',
originaldate => 'TDOR', # Also for 2.4 only originaldate => 'TDOR', # Also for 2.4 only
isrc => 'TSRC', isrc => 'TSRC',
barcode => 'TXXX=BARCODE', barcode => 'TXXX=BARCODE',
catalognumber => 'TXXX=CATALOGNUMBER', catalog => ['TXXX=CATALOGNUMBER', sub { return tagmap_catalogid(shift, 'catalog'); } ],
catalog => 'TXXX=CATALOGNUMBER', catalognumber => ['TXXX=CATALOGNUMBER', sub { return tagmap_catalogid(shift, 'catalognumber'); } ],
catalogid => 'TXXX=CATALOGNUMBER', catalogid => ['TXXX=CATALOGNUMBER', sub { return tagmap_catalogid(shift, 'catalogid'); } ],
'encoded-by' => 'TENC', 'encoded-by' => 'TENC',
encoder => 'TSSE', encoder => 'TSSE',
encoding => 'TSSE', encoding => 'TSSE',
@ -63,23 +79,43 @@ my %idLookup = (
replaygain_track_gain => 'TXXX=REPLAYGAIN_TRACK_GAIN', replaygain_track_gain => 'TXXX=REPLAYGAIN_TRACK_GAIN',
replaygain_track_peak => 'TXXX=REPLAYGAIN_TRACK_PEAK', replaygain_track_peak => 'TXXX=REPLAYGAIN_TRACK_PEAK',
genre => ['TCON', sub { genre => ['TCON', sub {
return 24; return undef if ($opt_no_genre);
my $genreName = shift->{genre};
if (!exists($genreMap{lc($genreName)})) {
# If no genre number exists, use the name
return $genreName;
}
return $genreMap{$genreName};
}], }],
#mood => ['TMOO', sub { #mood => ['TMOO', sub {
#}], #}],
bpm => 'TBPM', bpm => 'TBPM',
comment => 'COMM', comment => ['COMM=Comment', sub {
return undef if (defined($opt_comment) && $opt_comment eq "");
return shift->{comment};
}],
copyright => 'TCOP', copyright => 'TCOP',
language => 'TLAN', language => 'TLAN',
script => 'TXXX=SCRIPT', script => 'TXXX=SCRIPT',
lyrics => 'USLT', lyrics => 'USLT',
circle => 'TXXX=CIRCLE',
); );
sub tagmap_catalogid {
my $t = shift;
my $own_tag_name = shift;
return undef if (defined($opt_catid) && $opt_catid eq "");
return $t->{$own_tag_name};
}
my $opt_genre; my $opt_genre;
my $opt_help; my $opt_help;
GetOptions( GetOptions(
"genre=s" => \$opt_genre, "genre|g=s" => \$opt_genre,
"help" => \$opt_help "no-genre|G" => \$opt_no_genre,
"help|h" => \$opt_help,
"catid=s" => \$opt_catid,
"comment=s" => \$opt_comment,
) or die("Error in command line option"); ) or die("Error in command line option");
if ($opt_help) { if ($opt_help) {
@ -132,6 +168,10 @@ sub argsToTags {
my $argTags = shift; my $argTags = shift;
if (defined($opt_genre)) { if (defined($opt_genre)) {
$argTags->{genre} = $opt_genre; $argTags->{genre} = $opt_genre;
} elsif (defined($opt_comment) && $opt_comment ne "") {
$argTags->{comment} = $opt_comment;
} elsif (defined($opt_catid) && $opt_catid ne "") {
$argTags->{catalognumber} = $opt_catid;
} }
} }
@ -153,8 +193,10 @@ sub tagsToOpts {
push(@tagopts, qq(--tv '$tagName=$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); if (defined($tagCont)) {
push(@tagopts, qq(--tv '$tagName->[0]=$tagCont')); shellsan(\$tagCont);
push(@tagopts, qq(--tv '$tagName->[0]=$tagCont'));
}
} }
} }
@ -191,6 +233,9 @@ Usage:
-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
--catid STRING the catalog id to set (or "")
--comment STRING the comment to set (or "")
EOF EOF
print($h); print($h);
exit 0; exit 0;