#read config and write batch file to mp3split!!!  shit!
#outdated
use strict;

my $cfg="grabparts\.cfg";
open CFG, "<$cfg";
my @config=<CFG>;

#print "config is \n@config\n";

my $out="rip_according_to_cfg\.bat";
print "out is $out\n";
open OUT, ">$out";


my $base="C:\\projects\\chartsweep90s\\cfgsections";
my $curopen="";
my $loc="";
my @starttime=();
my @endtime=();
my $mp3path="";

sub switchtime
{
	#print "entered switchtime, @_ \n";
	my $sec=shift(@_);
	#$sec +=20;
	my $min=0;
	while ($sec >= 100)
	{
		$sec -= 100;
		$min +=1;
	}
	my @localtime=();
	$localtime[0]=$min;
	$localtime[1]=$sec;
	#print "returning @localtime\n";
	return @localtime;
}

foreach my $line (@config)
{
	#print "working on line $line\n";
	if ($line =~ /\.mp3/)
	{
		$line =~ s/\n//g;
		$mp3path=$line;
	}
	elsif ($line =~ /^Start=([0-9]+)/)
	{
		@starttime=switchtime($1);
	}
	elsif ($line =~ /^End__=([0-9]+)/)
	{
		@endtime=switchtime($1);
		print OUT "C:\\audio\\mp3splt-2\.1\\mp3splt\.exe -f -q -d \"$base\" \"$mp3path\" $starttime[0]\.$starttime[1] $endtime[0]\.$endtime[1] \n";
		@starttime=();
		@endtime=();
		$mp3path="";
	}
	elsif ($line =~ /\=\n/)
	{
		print "ended because of line $line\n";
		last;
	}
}