#!/usr/bin/perl -w use MP3::Info; # Function prototypes: sub readFiles($); sub printMP3($); sub help(); ############################################################################## # Main if (!@ARGV){ help(); exit -1; } my $mp3root = $ARGV[0]; my ($html, $time, $newart, $artists, $list, $tracks); if ($mp3root eq "-html") { $html = 1; $mp3root = $ARGV[1]; } $mp3root =~ s/\/$//; #remove trailing slash if (!$html) { print ("#EXTM3U\n"); } # print the extended header readFiles($mp3root); my $normtime = int($time/(60*60)) . " hours, "; $normtime .= int(($time/60)%60) . " minutes, "; $normtime .= int($time%60) . " seconds"; my $avetime = int((($time/$tracks)/60)%60) . " minutes, "; $avetime .= int(($time/$tracks)%60) . " seconds"; if ($html) { print < Tom Chance's PlayList

Tux!Tom Chance's playlist

This is a (long) list of all the tracks I've got on my computer (MP3 format, encoded at Varable BitRate 128kbps ~ 192kbps).

N.B. All of these tracks have been ripped from CDs (admittedly some are from friend's CDs). I don't condone or encourage people to download vast amounts of music from the 'Net, nor will I "share" or "swap" these files with people. By all means download some MP3s from the Internet to see if you like an artist, but then at least go and buy the CD, or just have the one odd song downloaded.


OPENPAGE print "

Number of tracks: $tracks"; print "
Total playlist length: $normtime
"; print "Average track length: $avetime

"; print "

Artists:

$artists"; print "



Tracks:

$list"; print <

W3C HTML 4.1 Compliant No Browser Enhanced Burn All .GIFs! Hosted by UK Linux
This page was last updated on . Contact me at tomchance AT gmx DOT net. ENDPAGE } ############################################################################## # prints a short Help text sub help() { print STDERR < -html This will force the output in html format mp3-dir This directory will be recursivly searched for mp3s This tool generates a extended .m3u playlist for use with XMMS, Winamp (tm) and other MPEG layer 3 players from a given directory. The playlist is printed to STDOUT. Extended .m3u files contain additional informations like length of the song and Infos from the id3-tag. For running this script you'll need the MP3::Info perl-module. Get it from CPAN or install the appropriate package of your distribution. STOP } ############################################################################## # print a given MP3 sub printMP3($){ (my $file) = @_; my $info = get_mp3info($file); my $tag = get_mp3tag($file); if ($html) { if (defined($tag)) { if ($artists !~ /$tag->{ARTIST}/) { $list .= "
"; $artists .= "$tag->{ARTIST}
"; } $list .= "$tag->{ARTIST} - $tag->{TITLE}
"; $time += int($info->{SECS}); $tracks++; } } else { if (defined($tag)) { print ("#EXTINF:".int($info->{SECS}).",$tag->{ARTIST} - $tag->{TITLE}\n"); } else { print ("#EXTINF:".int($info->{SECS})."\n"); } print ("$file\n"); } } ############################################################################## # Read a given directory and its subdirectories sub readFiles($) { (my $path)=@_; opendir(ROOT, $path); my @ufiles = readdir(ROOT); closedir(ROOT); my @files = sort {lc($a) cmp lc($b)} @ufiles; foreach (@files) { next if /^\.|\.\.$/; #skip upper dirs my $fullFilename = "$path/$_"; if (-d $fullFilename) { readFiles($fullFilename); #Recursion next; } if ($fullFilename =~ /^.*ogg$/i || $fullFilename =~ /^.*mp3$/i) { printMP3($fullFilename); #print MP3-Infos } } }