Hi all,

Been busting my head on this for two days now, So I seek some wisdom of others.

I have read everything I can find and have yet been able to solve the issue, it seems like others have not either or at least never responded with the solution.

I've tried various code pages, encode ... I'm forgetting what all I've tried.

FBSD7.1R
Perl 5.8
TagLib 1.5

The Error:

Malformed UTF-8 character (unexpected end of string) in subroutine ent +ry at /scripts/audio/audio line 90. Wide character in print at /scripts/audio/audio line 63.

Comes from strings with extended characters (ie: é).
In the code:   %{$hSong} = (artist      => $m->tag()->artist()->toCString()
In the sub HashMPEG (line 90)

The odd thing to me is the '$filename' prints correctly and it contains the same characters.

Is this an issue with TagLib???
Is there a solution???
Ideas???
Comments???

Thanks

-Enjoy
fh : )_~

The code...
#!/usr/bin/perl ###################################################################### # # BCE Project 20c # # Search for *.mp3, look up each mp3's tag info and display it. # # print structured info # use warnings; use strict; use Getopt::Std; use Audio::TagLib; my %Popts; # Program Options use Data::Dumper; #!REM!PROD! debug $Data::Dumper::Indent = 1; #!REM!PROD! debug ###################################################################### sub ShowUsage { print "\n $Popts{progname} v$Popts{progvers +ion}\nUSAGE:\n"; print " ", $1, "\n" if ($0 =~ m%^.*/(.*)$%); print " OPTIONS: [-f] \"Filename\" Filename, ('*.mp3' see 'pattern' in FIND(1)) +. [-h] Show Help [-i] Interactive [-s] Show Settings \n\n"; } sub ShowSettings { print "\n$Popts{progname} v$Popts{progversion} Current Settings:\n"; print " -f: ", $Popts{directory}, '/', $Popts{filename}, "\n"; print " -i: ", $Popts{i} ? "Interactive\n" : "Commandline\n"; print "\n"; } sub Setup { getopts ("f:his", \%Popts); $Popts{progname} = "BCE #20c"; # Duh! # BCE = Brain Cell Exerc +ise $Popts{progversion} = "0.0.1"; # Duh! $Popts{f} = './*' if ( ! defined($Popts{f}) ); if ($Popts{f} =~ m,(.*\/|^)(.*?)(?:[\.]|$)([^\.\s]*$),) { $Popts{directory} = $1; $Popts{filename} = $2 . ($3 ? '.' . $3 : '.mp3'); } $Popts{directory} =~ s/\/$// if ( length($Popts{directory}) > 1 ) +; } ###################################################################### sub PrintSong { my ($hSong) = @_; print "Artist : ", $hSong->{artist}, "\n"; print "Album : ", $hSong->{album}, "\n"; print "Title : ", $hSong->{title}, "\n"; print "Track : ", $hSong->{track}, "\n"; print "Genre : ", $hSong->{genre}, "\n"; print "Year : ", $hSong->{year}, "\n"; printf "Length : %d:%02d\n", $hSong->{length} / 60, $hSong->{length} % 60; print "Bit rate : ", $hSong->{bitrate}, "\n"; print "Sample rate : ", $hSong->{samplerate}, "\n"; print "Channels : ", $hSong->{channels}, "\n"; print "Comment : ", $hSong->{comment}, "\n"; print "MPEG Version : ", $hSong->{version}, "\n"; print "Layer Version: ", $hSong->{layer}, "\n"; # print "Protected : ", $hSong->{protection}, "\n"; print "Channel mode : ", $hSong->{channelmode}, "\n"; print "Copyrighted : ", $hSong->{copyrighted} ? 'True' : 'False', " +\n"; print "Original : ", $hSong->{original} ? 'True' : 'False', "\n" +; print "File name : ", $hSong->{filename}, "\n"; } sub HashMPEG { my ($filename, $hSong) = @_; my $m = Audio::TagLib::MPEG::File->new($filename, "Accurate"); %{$hSong} = (artist => $m->tag()->artist()->toCString(), album => $m->tag()->album()->toCString(), title => $m->tag()->title()->toCString(), filename => $filename, comment => $m->tag()->comment()->toCString(), genre => $m->tag()->genre()->toCString(), year => $m->tag()->year(), track => $m->tag()->track(), length => $m->audioProperties->length(), bitrate => $m->audioProperties->bitrate(), samplerate => $m->audioProperties->sampleRate(), channels => $m->audioProperties->channels(), version => $m->audioProperties->version(), layer => $m->audioProperties->layer(), # Not found??? protection => $m->audioProperties->prote +ctionEnabled(), channelmode => $m->audioProperties->channelMode(), copyrighted => $m->audioProperties->isCopyrighted(), original => $m->audioProperties->isOriginal(), ); # print Dumper($hSong); } sub FindFiles { my ($dir, $filename) = @_; my @alist = `find '$dir' -type f -iname '$filename'`; return @alist; } Setup; # Process command line, verify input, set defaults. (ShowUsage()), exit(0) if $Popts{h}; (ShowSettings()), exit(0) if $Popts{s}; if ( ! $Popts{directory} eq '.') { (print $Popts{directory}, " does not exists!\n"), exit(127) if (! -d + $Popts{directory}); } #if ($Popts{i}) { # if interactive my $Currec = 0; my $Listem = 1; my @Flist = FindFiles $Popts{directory}, $Popts{filename}; my $NumItems = scalar @Flist; if ( ! $NumItems > 0 ) { print "Not found\n"; exit(255); } while (1) { my $Input; if ($Listem) { my %hSong; my $file = $Flist[$Currec]; chomp $file; HashMPEG $file, \%hSong; PrintSong \%hSong; $Listem = 0; } my $curr = $Currec + 1; print '(' . $curr . '/' . $NumItems . ') ... Q)uit, N)ext, P)revio +us: '; $Input = <STDIN>; chomp $Input; # q to quit last if $Input =~ m/^q/i; # p for Previous if ( $Input =~ m/^p/i ) { if ($Currec > 0) { $Currec--; $Listem = 1; } next; } # n for Next if ( $Input =~ m/^n/i ) { if ($Currec < $NumItems - 1) { $Currec++; $Listem = 1; } next; } # Enter for Next if ( $Input =~ m/^$/i ) { if ($Currec < $NumItems - 1) { $Currec++; $Listem = 1; } next; } } #}

In reply to Malformed UTF-8 character, TagLib by Anonymous Monk

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.