Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^2: Help with reading MP3's

by StarkRavingCalm (Sexton)
on Aug 25, 2011 at 11:25 UTC ( #922313=note: print w/replies, xml ) Need Help??

in reply to Re: Help with reading MP3's
in thread Help with reading MP3's

Same results.

NOTE: If I just put in a filename.mp3 or *.mp3 (mp3's are in the same directory as script), I get "No file or directory."

If I give it an absolute path, it hangs. Using strict gives the following: "Global symbol "@info" requires explicit package name at"

Replies are listed 'Best First'.
Re^3: Help with reading MP3's
by charlesboyo (Beadle) on Aug 25, 2011 at 16:11 UTC

    Using strict gives the following: "Global symbol "@info" requires explicit package name at"

    Yep! Because that line should say:
    my @info=$mp3->autoinfo;

    Your script reads the filenames from the standard input (keyboard) I assume. Are you inputting the full paths or correct relative paths?

    Wildcards in your input will NOT be expanded, so don't try those.

    If under windows, you need to pay special to spaces and such in the filename. Better still, surround your inputs with quotes marks

      I would ultimately like to throw a directory at it and have it read, recursively, all MP3s contained therein.

        This is your code, with minimal modifications and File::Find::find that handles the recursive search for mp3s. :)
        #!/usr/bin/perl -w use strict; use MP3::Tag; use File::Find; # define how autoinfo tries to get information # default: # MP3::Tag->config("autoinfo","ID3v2","ID3v1","filename"); # don't use ID3v2: # MP3::Tag->config("autoinfo","ID3v1","filename"); # read a directory path from STDIN # Since we don't have a prompt, the cursor is just going to sit idle u +ntil your supply some input while (<STDIN>) { chomp; # find all entries in the given directory/folder, calls the &wante +d call-back for every file/directory encountered find(\&wanted, $_); } sub wanted { # $_ automatically contains the current file name i.e. "Knock You + Down.MP3" # don't bother processing anything that does not have the .mp3 ex +tension, case irrelevant return unless /mp3$/i; if (my $mp3=MP3::Tag->new($_)) { print "$_ (Tags: ", join(", ",$mp3->get_tags),")\n"; my @info=$mp3->autoinfo; print "* Song: $info[0]\n"; print "* Track: $info[1]\n"; print "* Artist: $info[2]\n"; print "* Album: $info[3]\n"; print "* Comment: $info[4]\n"; } print "\n"; }

        This works on my Strawberry Perl 5.12.3 on Windows 7. If it works here, it should work anyway.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://922313]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2018-07-21 16:05 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (449 votes). Check out past polls.