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 Herzen

I'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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.