<?xml version="1.0" encoding="windows-1252"?>
<node id="132478" title="M3U Playlist Generator" created="2001-12-17 04:56:27" updated="2005-08-10 21:32:30">
<type id="1748">
sourcecode</type>
<author id="34694">
xunker</author>
<data>
<field name="doctext">
&lt;CODE&gt;
#!c:\perl\bin\perl.exe -w
#
# WinAMP M3U Sorted Playlist Generator version .0.1 ("Bob") December 2001
# &lt;xunker@pyxidis.org&gt;
#
use strict;

use File::Find;
use MP3::Info;

my $Debug = 0;
my $usage = "listmaker.pl &lt;source dir&gt; &lt;output file&gt; [&lt;verbose&gt;]\n";

my ($source_path, $output_filename, $verbose) = @ARGV;
die $usage unless (($source_path) &amp;&amp; ($output_filename));

die "that path doesn't exist, hombre" unless (-e $source_path);

unlink $output_filename if (-e $output_filename);

my @files; my %shortname;

sub addFile {
	$shortname{$File::Find::name} = $_;
	return unless -f;
	return unless /\.mp3$/;
	push @files, $File::Find::name;
	print '.' if $verbose;
}
print "\n" if $verbose;

find (\&amp;addFile, $source_path);

@files = sort {uc($a) cmp uc($b)} @files;

open FILE, "&gt;$output_filename"
	or die "could not open $output_filename for writing: $!";
	
print FILE "#EXTM3U\n";
my $counter = 1;  my $max = scalar (@files);
foreach my $file (@files) {
	my $tag = get_mp3tag($file);
	my $info = get_mp3info($file);
	my $pair;
	if (($tag-&gt;{ARTIST}) &amp;&amp; ($tag-&gt;{TITLE})) {
		$pair = $tag-&gt;{ARTIST} . ' - ' . $tag-&gt;{TITLE};
	} else {
		$pair = $shortname{$file};
	}
	print FILE "#EXTINF:"
		. int ($info-&gt;{SECS})
		. ","
		. $pair
		. "\n";
	$file =~ s/\//\\/g; # this is for WinAMP/MS-DOS;
                            # by default, File::Find returns
                            # filenames with the forward
                            # (proper) slash, but I use the
                            # program in Windows, so...
                            # If you use a real OS, remove.
	print FILE "$file\n";
	
	print "$counter of $max: $pair\n" if $verbose;
	$counter++;
}

close FILE;
&lt;/code&gt;</field>
<field name="codedescription">
&lt;P&gt;&lt;B&gt;Short Desciption:&lt;/B&gt; Produces an .M3U style playlist from a specified path

&lt;P&gt;&lt;B&gt;More Detail:&lt;/B&gt; There have been a few other playlist makers posted, but I've given this one the moniker "better" because it's generates useful WinAMP-style .M3U playlists, not just a list of .mp3 files.  It finds all MP3 files below a given path, and stores both the file path and the ID3 info (if availble; if not, it uses the filename) in the output M3U file.

&lt;P&gt;To-do's:
&lt;UL&gt;
&lt;LI&gt;get rid of the 'shortname' hash -- it works, it was easy, but it's a tacky hack.
&lt;LI&gt;check for ID3v2 tags ( didn't bother because this was written for my Mp3 collection that I ripped only with ID3v1 tags).
&lt;LI&gt;Check for the OS it's running on and use proper line terminator ("\n" or "\r\n") and proper directory separator ('/', '\' or ':') accordingly.
&lt;/UL&gt;
&lt;P&gt;This was written for my in-car MP3 player/computer, so when I download new music to it, one double-click will refresh/rebuilt/sort the default playlist, adding the new music just downloaded.  Before I did this I had to open the direcotry in WinAMP, sort it and save it.  That's a pain with a screen that's a mere 2.2 inches diagonal.
&lt;P&gt;It's not too optimized, but it can still process an archive of 1,300 files in about 1 minute (Pentium 133, 32 Meg, Win2k Pro).
&lt;P&gt;Requires &lt;B&gt;[MP3::Info]&lt;/B&gt; to be installed.</field>
<field name="codecategory">
Audio Related Programs</field>
<field name="codeauthor">
xunker &amp;lt;xunker@pyxidis.org&amp;gt;</field>
</data>
</node>
