#!/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<BR>\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 = "<a href=\"$baselink$_\">"; s/\.[Mm][Pp]3$//; #strip the file endings s/\.[Oo][Gg][Gg]$//; print HTMLFILE2 "$filecount. $link$_</a> ($length)<BR>\n\r"; } } close(HTMLFILE2);

In reply to MP3/OGG Directory Parse & Playlist Generation with Hyperlinks by All_Star25

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.