Malformed UTF-8 character (unexpected end of string) in subroutine entry at /scripts/audio/audio line 90. Wide character in print at /scripts/audio/audio line 63. #### #!/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{progversion}\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 Exercise $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->protectionEnabled(), 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)revious: '; $Input = ; 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; } } #}