#!/usr/bin/perl

#$PROXY    = '212.50.5.27:3128';
#$PROXY = "212.124.78.116:8080";

if ($#ARGV < 2) {
    print "Usage: $0 start end file\n";
    exit;
};

$start = $ARGV[0];
$end   = $ARGV[1];
$file  = $ARGV[2];

@links = `cat $file`;

$end   = $#links if ($end > $#links);
@links = (@links[$start..$end]);
open FILE, ">$start-$end";
close FILE;

$x = $start;
foreach $line (@links) {
    chomp $line;
    ($url,$dir,$fname) = split('\;',$line);
    $fname = $dir."/".$fname;
    mkdir $dir,0755 if (! -d $dir);
    $x++;
    if (! -e $fname) {
	print "URL: $url\n";
	print "FILE: $fname ($x)\n";
	system("curl '$url' -A 'Mozilla 4.02 [en] (NeXT; I)' -e 'http://db.infotel.bg:8889/phone/plsql/WPF.Intro1' -f -o $fname");
	print "Sleep...\n";
	sleep(2);
	print "...done\n";
    };
};
