I just wanted to update the last post I sent a few weeks ago. The following seems to allow MP3::Tag to update tags with UTF-8 strings. Programs like easytag, mythmusic, etc seem to be handling the data correctly or at least as expected. I have other programs that share code I've used below. This particular script is run inside the album or artist directories. My preferred structure in the end is Artist/Album/Track. Title. My platform is Linux (OpenSUSE 11.1 as of this writing).
#!/usr/bin/perl use strict; use warnings; use Cwd; use Audio::FLAC::Header; use MP3::Info; use MP3::Tag; use sort '_qsort'; use File::Glob qw(:globally :nocase); use Encode qw(encode decode); our $DEBUG = 0; sub Get_Artist_Album { return ( split m!/!, cwd() )[-2,-1]; } sub Process_Files { my @MP3_Files = <*.mp3> ; my @FLAC_Files = <*.flac> ; my $Num_MP3_Files = @MP3_Files; my $Num_FLAC_Files = @FLAC_Files; if ($Num_MP3_Files > 0) { my ($Artist, $Album) = Get_Artist_Album; $Artist = decode('UTF-8',$Artist); $Album = decode('UTF-8',$Album); foreach my $MP3_File (@MP3_Files) { chomp $MP3_File; if ($MP3_File =~ /^(\d+[\.\_\-\ ]+)(.*)(\.\w+)$/) { my ($Track, $Title, $Ext) = ($1, $2, lc($3)); $Track =~ s/^(\d+)(.*)/$1/; $Track = sprintf("%02d", $Track); $Title = decode('UTF-8',$Title); $Title = Format_Text ($Title); my $New_File = "$Track. $Title$Ext"; if ($DEBUG) { print "\t$New_File\n"; } rename ($MP3_File, $New_File) unless $MP3_File eq $New +_File; remove_mp3tag($New_File, 'ALL'); my $mp3 = MP3::Tag->new($New_File); my $id3v1 = $mp3->new_tag("ID3v1"); $id3v1->all($Title,$Artist,$Album,"","",$Track,"Rock") +; $id3v1->write_tag; my $id3v2 = $mp3->new_tag("ID3v2"); $id3v2->add_frame('TRCK',$Track); $id3v2->add_frame('TIT2',$Title); $id3v2->add_frame('TPE1',$Artist); $id3v2->add_frame('TALB',$Album); $id3v2->add_frame('TCON',"17"); $id3v2->write_tag; } } } if ($Num_FLAC_Files > 0) { my ($Artist, $Album) = Get_Artist_Album; foreach my $FLAC_File (@FLAC_Files) { chomp $FLAC_File; if ($FLAC_File =~ /^(\d+[\.\_\-\ ]+)(.*)(\.\w+)$/) { my ($Track, $Title, $Ext) = ($1, $2, lc($3)); $Track =~ s/^(\d+)(.*)/$1/; $Track = sprintf("%02d", $Track); $Title = Format_Text ($Title); my $New_File = "$Track. $Title$Ext"; if ($DEBUG) { print "\t$New_File\n"; } rename ($FLAC_File, $New_File) unless $FLAC_File eq $N +ew_File; my $flac = Audio::FLAC::Header->new($New_File); my $tags = $flac->tags(); %$tags = (); $tags->{TRACKNUMBER} = $Track; $tags->{TITLE} = $Title; $tags->{ARTIST} = $Artist; $tags->{ALBUM} = $Album; $tags->{GENRE} = "Rock"; $flac->write(); } } } } sub Format_Text { my $Text = $_[0] or exit 1; $Text = lc($Text); #Make everything lowercase $Text =~ tr/_/ /; #Remove underscores $Text =~ s/\.\.\./\.\.\.\ /g; $Text =~ s/(\d),(\d)/$1$2/g; $Text =~ s/,/ /g; $Text =~ tr/\`\´\’/\'/s; $Text =~ s/ and / \& /g; $Text =~ s/\[/\(/g; $Text =~ s/\]/\)/g; $Text =~ tr/ / /s; #Remove unnecessary spaces $Text =~ s/\( /\(/g; $Text =~ s/ \)/\)/g; $Text =~ s/\·/-/g; $Text =~ s/\s*-\s*/-/g; # $Text =~ s/\.$//; #Some titles have an extra period - bye $Text =~ s/(\d)\./$1/g; #Do not need period after numbers here my @Words = split(/ /,$Text); foreach my $Word (@Words) { $Word = ucfirst($Word); } $Text = "@Words"; $Text =~ s/([(-])([a-z])/$1\u$2/g; $Text =~ s/(\W'\S)/uc($1)/eg; #Some items following ' should be uc $Text =~ s/(\.)([a-z])/$1\u$2/g; #Letter.Letter.Letter... is uc $Text =~ s/Dis[ck]\ /Cd/; $Text =~ s/Dis[ck](\d)/Cd$1/; $Text =~ s/Cd\ (\d)/Cd$1/; $Text =~ s/\((Cd\d+)\)/$1/; $Text =~ s/-Cd/ Cd/; my $x = $Text =~ tr/(/(/; #Count open parens my $y = $Text =~ tr/)/)/; #Count closing parens if ($x > $y) { $Text = $Text.")"; } return ($Text); } Process_Files; my $Artist_Dir = cwd(); opendir (Artist_DH, $Artist_Dir) || die "can't opendir $Artist_Dir: $! +"; my @Albums = grep { !/^\./ && -d "$_" } sort readdir(Artist_DH); foreach my $Album (@Albums) { my $NewAlbum = Format_Text ($Album); rename ($Album, $NewAlbum) unless $Album eq $NewAlbum; if ($DEBUG) { print "$NewAlbum \n"; } chdir $NewAlbum or warn "Cannot change to $NewAlbum\n"; Process_Files; chdir ".."; } closedir Artist_DH;

In reply to Re^4: MP3::Tag encoding problem by jwhit61
in thread 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.