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

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.

Replies are listed 'Best First'.
Re^6: Help with reading MP3's
by StarkRavingCalm (Sexton) on Aug 26, 2011 at 17:17 UTC

    script just hangs with no results. Should I be modifying it in any way prior to running it?

      No, you shouldn't have to change anything.

      Have you tried stepping-through with the debugger? Where exactly is it "hanging"? You might also want to try adding a couple of prints in there for debugging purposes.

      Yet another approach is to present the to-be-searched paths on the command line. Swap

      while (<STDIN>) { chomp;
      with:
      foreach(@ARGV) {
      and invoke your script from the command line with: perl scriptname.pl c:\path1 c:\path2 ...

      Both approaches work for me.

        Ok, swapping that in worked! Not sure why...

        Will have to play with the formatting a bit to see if I can can prune out only those without tags or only those without photos.

        Thanks!