I'm writing a script to loop through and fix the tags in my MP3 files before adopting Songbird and have come across a character encoding problem. MP3::Info can get the tag successfully, but since it can't write ID3v2 tags, I'm now using MP3::Tag. Only problem is that European characters are printing as "�" (that's a black diamond with a question-mark inside, in case it doesn't print properly).
Here's the relevant bit of code I'm using:
# $File::Find::name in this code snippet is as follows: # Mozart - Die Zauberflöte Act 2, 06. Arie. Der Hölle Rache kocht in m +einem Herzen.mp3 my $mp3 = MP3::Tag->new($File::Find::name); $mp3->get_tags; if (exists $mp3->{ID3v2}) { my $name = $mp3->{ID3v2}->get_frame("TIT2"); print "Title: $name\n"; }
The above print statement results in the following (the title tag is pretty much the same as the file name excluding "Mozart - "). I've put question-marks instead of the black diamond because the code tags are successfully substituting it for the correct entity:
Name: Die Zauberfl?te Act 2, 06. Arie. Der H?lle Rache kocht in meinem HerzenI've also tried setting an environment variable, as per the documentation, in the hope that I might get it to use the correct encoding:
$ENV{'MP3TAG_DECODE_V2_DEFAULT'} = 'utf-8';What I know about character encodings could be written in a very tiny text box, so maybe I'm doing something wrong. I have also tried setting the character encoding this way:
$mp3->config('decode_encoding_v2' => 'utf-8');Which results in the following print-out:
Wide character in print at ./do.pl line 78. Name: Die Zauberfl?te Act 2, 06. Arie. Der H?lle Rache kocht in meinem + Herzen
I have also tried setting "decode_encoding_v2" and $ENV{'MP3TAG_DECODE_V2_DEFAULT'} to "iso-8859-1" and "iso-8859-2", being European encodings, which don't result in warnings, but they also still print out the black diamond with the question mark. I can also use "utf-8" and "utf8" and it doesn't seem to complain. Using "utf-16" results in the following error/warning in the console:
UTF-16:Unrecognised BOM 4469 at /usr/lib/perl5/5.10.0/i386-linux-thread-multi/Encode.pm line 162.I've also tried setting both to "latin1" to no avail, too. I haven't got a clue why some of my <code> blocks seem to wrap text with a red plus sign at the beginning of the next line, and not in others.
In reply to MP3::Tag encoding problem by mfearby
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |