#!/usr/bin/perl -w
#

#$rcs_id='RCS: $Id: pttmkaudio, v 0.1.0 2002/12/31 01:32:42 Paul T.Threshold $';

require 5.004;
use POSIX;
use IO::Handle;

#
# CONFIGURATION: filenames
#
#$path=`pwd`;
$path='./';

print <<EOF;

pttmkaudio (c)2002 Paul T.Threshold

converts .mp3 files read from current folder to .wav, then to .cdr format,
and finally burns them all....
(mp3's must start with a digit.(0-9))

EOF


# ###
# ### MAIN LOOP -- scan path directory
# ###

open( IDX, ">>".$path."pttcdindex" ) ||
	    die "can't write index file './".$path."pttcdindex'";
print IDX "### ".localtime()." ### index generated by pttmkaudio (c)2002 Paul TT ###\n";

$t = 101;
opendir PATH, "$path" || die "can't read directory '$path'";
rewinddir( PATH );
foreach $f ( readdir(PATH) ) {

	next unless $f =~ /^[0-9]{1,3}[\w\W]*[.]{1}mp3$/ ;

	print  "_________________________$t $f\n";
	print IDX "$t $f\n";

	system ("lame --decode \"$f\" \"track$f.wav\"");
	#system ("wav2cdr \"track$f.wav\" \"track$f.cdr\"");
	system ("sox \"track$f.wav\" \"track$f.cdr\"");
	remove "./track$f.wav";
	$t = $t + 1;
}

close IDX;
close PATH;

if ($t > 101) {
	print "\nBurn, Burn!!!!\n";
	system ("pttaudiocd") || die "died smoothly.";
	remove "./track*.cdr*";
} else {
	print "\nSorry, nothing to do....\n:-(\n\n"
}

