Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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 : )_~
#!/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; } } #}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Malformed UTF-8 character, TagLib
by bichonfrise74 (Vicar) on Nov 09, 2009 at 18:16 UTC | |
|
Re: Malformed UTF-8 character, TagLib
by Anonymous Monk on Nov 09, 2009 at 19:50 UTC | |
|
Re: Malformed UTF-8 character, TagLib
by ikegami (Patriarch) on Nov 09, 2009 at 20:15 UTC | |
|
Re: Malformed UTF-8 character, TagLib
by Anonymous Monk on Nov 11, 2009 at 16:51 UTC | |
|
Re: Malformed UTF-8 character, TagLib
by ikegami (Patriarch) on Nov 11, 2009 at 18:35 UTC | |
by Anonymous Monk on Nov 11, 2009 at 21:19 UTC | |
by ikegami (Patriarch) on Nov 12, 2009 at 01:07 UTC | |
by Anonymous Monk on Nov 12, 2009 at 06:56 UTC | |
by ikegami (Patriarch) on Nov 12, 2009 at 07:34 UTC | |
|