#!/usr/bin/perl -w
use strict;
use MP3::Info;
use Ogg::Vorbis::Header::PurePerl;
my $directory = "insert_directory_here";
my $baselink = "http://insert_website_here/cgi-bin/queuesong.pl?song=";
my $filename = "playlist.html";
my $targetfile = $directory . $filename;
# takes in a parameter which is the name of the directory
opendir( FILEDIR, $ARGV[0] ) || die "Cannot open directory";
my @FILES = grep( !/^\.\.}$/, readdir FILEDIR );
open( HTMLFILE, ">$targetfile" );
print HTMLFILE "Perl Generated Playlist
\n\r";
close(HTMLFILE);
open( HTMLFILE2, ">>$targetfile" );
my $filecount = 0;
chdir $ARGV[0];
foreach my $file (@FILES) {
$_ = $file;
my $success = 0;
my $length = "00:00";
# mp3/ogg reading stuff goes here
if (/[Mm][Pp]3$/) {
my $info = get_mp3info($file);
$length = $info->{TIME};
$success++;
}
elsif (/[Oo][Gg][Gg]$/) {
my $ogg = Ogg::Vorbis::Header::PurePerl->load($file)
or die "Couldn't load $file";
if ( $ogg->info->{LENGTH} >= 6000 ) {
$length = sprintf( "%3d:%2d",
( $ogg->info->{LENGTH} / 60 ),
( $ogg->info->{LENGTH} % 60 ) );
}
elsif ( $ogg->info->{LENGTH} >= 600 ) {
$length = sprintf( "%2d:%2d",
( $ogg->info->{LENGTH} / 60 ),
( $ogg->info->{LENGTH} % 60 ) );
}
else {
$length = sprintf( "%1d:%2d",
( $ogg->info->{LENGTH} / 60 ),
( $ogg->info->{LENGTH} % 60 ) );
}
$success++;
}
if ( $success > 0 ) {
$filecount++;
my $link = "";
s/\.[Mm][Pp]3$//; #strip the file endings
s/\.[Oo][Gg][Gg]$//;
print HTMLFILE2 "$filecount. $link$_ ($length)
\n\r";
}
}
close(HTMLFILE2);