#!/usr/bin/perl
# this program generates a m3u file to match the file named as the
# first argument.
# Created on May 22, 2004
# Copyright (c) 2004, Pat Farrell, All rights reserved.
# This code will be released with a suitable Open Source
# license, probably BSD-like.
# 
# make it handle arguments the way Windows users expect.
use File::DosGlob 'glob';
use Getopt::Long;
use File::Basename;

    usage() if ( $#ARGV < 0 );

while( $word = shift(@ARGV) ) {
    $url = $word;
    $url =~ s/(\s)/%20/g;
    $word =~ s/(\s)/\\\1/g;	# quote any spaces before we glob
    @argfile = glob($word);
    foreach $afile (@argfile) {
         $url = $afile;
         $url =~ s/(\s)/%20/g;
         @parts = split('\.', $afile);
   	 if ( $#parts == 0) {
   	    $fname = $afile . ".m3u";
         }
         else {
             $fname = $parts[0] . ".m3u";
         }
        open (OUT, ">".$fname);

        print OUT "http://www.pfarrell.com/prc/mp3/".$url, "\n";
        close(OUT);
    }
}
sub usage {
    print "generate m3u files from mp3\n";
    print "Usage:\n   mk3u.pl  {files}\n";
    exit;
}
