Dean
Dean

Reputation: 763

ID3Info problem with Perl script

I'm trying to get an MP3 file's information from ID3 tags.

my $output_file = `ls | egrep '\.flac$|\.mp3$'`;
$output_file = "$output_folder\/$output_file"; 
my $artist = "id3info \"$output_file\" | grep '^=== TPE1' | sed -e 's/.*: //g'"
my $album = "id3info \"$output_file\" | grep '^=== TALB' | sed -e 's/.*: //g'";
my $format = "MP3";
my $bitrate = "id3info \"$output_file\" | grep 'Bitrate' | sed -e 's/.*: //g'";
my $genretags = "id3info \"$output_file\" | grep '=== TCON' | sed -e 's/.*: //g', mix, auto.up";
$genretags =~ tr/[A-Z]/[a-z]/;

However this returns the following error:
syntax error at mp3.pl line 88, near "my " Global symbol "$album" requires explicit package name at mp3.pl line 88. Global symbol "$album" requires explicit package name at mp3.pl line 173.

Could someone advise on what this error means? What package do I need to install?

Upvotes: 0

Views: 268

Answers (2)

Sam Choukri
Sam Choukri

Reputation: 1904

Let me introduce you to MP3::Tag

use MP3::Tag;

my $mp3 = MP3::Tag->new($filename);

# get some information about the file in the easiest way
my($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();

This code above was copied (nearly) verbatim from the examples shown in MP3::Tag's documentation.

Upvotes: 4

Alan Haggai Alavi
Alan Haggai Alavi

Reputation: 74272

my $artist = "id3info \"$output_file\" | grep '^=== TPE1' | sed -e 's/.*: //g'"

You forgot to terminate the above line with a ;.

Yes, of course, you should be using a module to parse the tags.

Upvotes: 3

Related Questions