Forum Moderators: coopster & phranque

Message Too Old, No Replies

how do I read id3 tags?

         

electricocean

12:26 am on Jan 4, 2006 (gmt 0)

10+ Year Member



Hi, I am trying to read id3 tags but it isn't quite working. I am new Perl so I can't really find errors with code.

My Code:

#!/usr/bin/perl

# use module
use MP3::Tag;

# set filename of MP3 track
$filename = "../httpdocspodcasts/DBP_Promo.mp3";#s$cgi->param('fname');

# create new MP3-Tag object
$mp3 = MP3::Tag->new($filename);
$mp3->get_tags();

# if ID3v2 tags exists
if (exists $mp3->{ID3v2})
{
# get a list of frames as a hash reference
$frames = $mp3->{ID3v2}->get_frame_ids();

# iterate over the hash
# process each frame
foreach $frame (keys %$frames)
{
# for each frame
# get a key-value pair of content-description
($value, $desc) = $mp3->{ID3v2}->get_frame($frame);
print "$frame $desc: ";
# sometimes the value is itself a hash reference containing more values
# deal with that here
if (ref $value)
{
while (($k, $v) = each (%$value))
{
print "\n - $k: $v";
}
print "\n";
}
else
{
print "$value\n";
}
}
}

# clean up
$mp3->close();

Whenever I access it I get this error:

Internal Server Error

File not found

1) I was wondering what is wrong with this and what I can do to fix it.

2) And if someone could explain what the code is doing. That would be great becuase i am new at perl. I have been working with php for some time now so I understan some of it.

Thanks,
electricocean

electricocean

5:03 am on Jan 5, 2006 (gmt 0)

10+ Year Member



I have tried three differnet versions of the script and i got the same error. I also tried a file that I knew did not exist like rfgerfg.pl and i got the same error. Am I trying to access the file from the wrong place in the browser? mysite.com/thefile.pl?

electricocean

perl_diver

6:51 am on Jan 5, 2006 (gmt 0)

10+ Year Member



well, normally perl scripts go in the cgi-bin folder, a speacial folder for running scripts. Also, the script you have is not meant to be run from a browser at all, but from the command line (or the DOS prompt). Scripts run in a browser need to have an http header printed before printing anything else back to the screen/browser. To run it from a browser you can add:

#!/usr/bin/perl

# use module
use MP3::Tag;
use CGI qw(:standard);
print header,start_html;
rest of your code here
print end_html;

electricocean

1:50 am on Jan 6, 2006 (gmt 0)

10+ Year Member



So then how does the perl work? I out the file in the cgi-bin folder and I access it through command line? I don't quite understand that. How do I do command line on a web server that I am not in control of? Could I use php's exec("perl ../cgi-bin/id3.pl > /dev/null") or something... I am really confused.

Can you please explain everything?

electricocean

perl_diver

6:38 am on Jan 6, 2006 (gmt 0)

10+ Year Member



Running a script from the command line is different than from a browser. From the command line you just enter the name of the script, assuming you are in the corrrect directory you can just do something like this to run a script:

perl nameofscript.pl

the output is displayed in a console (or a DOS window).

But to run a script from a browser, you need to have an HTTP server installed, just like web servers on the internet do. You can download and install Apache:

www.apache.org

which is the most popular web server, and it's free. You need to edit the Apache configuration file to get it to run, but there are many tutorials on the internet that show how to do that (It's not hard but a little confusing at first). Do a search for:

installing apache on windows (or whatever OS you use).

Once Apache is installed, you have to start it first before trying to run scripts in the browser, I just have a shortcut to apache on my system tray I click to start it, then open a browser and you typically type:

[localhost...]

in the address box of the browser and click "go" or press enter. The Apache folder will have the cgi-bin folder in the htdocs folder, which is the same type of setup most webservers use. Thats where you will save your pel script to on your computer. But of course you can set it up nearly anyway you want to once you learn how to edit the apache configuration files, which are just text files. It's a whole new ball game and you will have to do some learning first, but I assure you it is not hard. It might take a day or two to get it all figured out.

electricocean

2:25 am on Jan 7, 2006 (gmt 0)

10+ Year Member



Hi, I am using globat. They use Apache and everything. I am just really confuzed becuase when you first login to the server it shows 4 folders: cgi-bin, error_docs, httpdocs, and httpsdocs. I don't use error_docs or httpsdocs but I upload all my stuff in the cgi-bin folder and the httpdocs folder. You are saying the cgi-bin folder is usaully inside the the httpdocs and mine isn't. So I have no idea how to access the file.

electricocean

perl_diver

5:40 am on Jan 7, 2006 (gmt 0)

10+ Year Member



I'm not tech support for globat, you have to ask them or check on their website for information about running scripts.