Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

How to use get_mp3info()

by freonpsandoz (Beadle)
on Apr 09, 2012 at 21:12 UTC ( #964211=perlquestion: print w/replies, xml ) Need Help??

freonpsandoz has asked for the wisdom of the Perl Monks concerning the following question:

What conversion do I need to perform on a file name that contains non-ASCII characters so that I can pass it to MP3::Info::get_mp3info? The code below prints "<file name>: File is empty" for files containing non-ASCII characters (e.g. "Blue Öyster Cult- (Don't Fear) The Reaper".) I want to know how to use the file names produced by console programs, so please no suggestions to rewrite the script so that it uses a completely different method to get the file names. Thanks. Update 4:08PM: I found that converting the file name to a short name with Win32::GetShortPathName and passing the short file name to get_mp3info appears to work correctly, EVEN IF THE SHORT NAME ALSO HAS NON-ASCII CHARACTERS IN IT! (CDBurnerXP generates short names with those characteristics.) There seems to be something about long file names containing non-ASCII characters that makes get_mp3info unable to open the file.

use strict; use warnings; use Encode; use MP3::Info; my $dir = ''; binmode STDOUT, ":encoding(UTF-8)"; for my $rawline (`dir /s $ARGV[0]`) { chop($rawline); # remove newline my $line = decode('cp437', $rawline); if ($line =~ /^\d/ && substr($line, 24, 1) eq ' ') { # listing for a file, not a directory my $extix = rindex($line, '.'); my $filename = substr($line, 39); my $filepath = "$dir\\$filename"; my $mp3time = ''; if (lc(substr($line, $extix, 3)) eq '.mp') { # mpeg file my $info = get_mp3info($filepath); if (defined($info)) { print "$filepath: time is $info->{TIME}\n"; } else { print("$filepath: $@\n"); } } } elsif (substr($line, 0, 14) eq ' Directory of ') { $dir = substr($line, 14); $dir =~ s/\\$//; print("$line\n"); } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://964211]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2022-08-10 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?