#!/usr/bin/perl
#
#Made by Peter Sandstrm (peter@zaphod.nu)
#Small changes for Darxite support by Ashley Montanaro.
#
#All feedback is appreciated!
#
#Now also supports use of the getright.ini file
#as infile. This have not been tested very well
#so the preferred usage is to use the "export 
#download list" in GetRight's file menu.
#
#Thanks to Justin Cunningham that pointed out
#to me that the script broke on the .ini file.
#
#Usage: ./getright.pl <name of the GetRight file>
#Always downloads using darxget.

open (lista, "$ARGV[0]");

while (defined($line=<lista>)) {
	$check=substr $line,0,2;
	if ($check!~/\/\//) {

		if ($check=~/So/) {
			($crap,$source)=split(/SourcePageURL: /,$line);
		}	
		elsif ($check=~/Sr/) {
			($crap,$source)=split(/SrcURL=/,$line);
		}
		elsif ($check=~/UR/) {
			$checktwo=substr $line,0,4;
			if ($checktwo=~/URL:/) {
				($crap,$preurl)=split(/URL: /,$line);
				$url=substr $preurl,0,-1;
			}
			elsif ($checktwo=~/URL=/) {
				($crap,$preurl)=split(/URL=/,$line);
				$url=substr $preurl,0,-1;
			}
		}
		elsif ($check=~/Fi/) {
			$checktwo=substr $line,0,5;
			if ($checktwo=~/File:/) {
				($crap,$prefile)=split(/File: /,$line);
				$file=substr $prefile,0,-10;
				$file=~s/.*?\\//gs;
			}
			elsif ($checktwo=~/File=/) {
				($crap,$prefile)=split(/File=/,$line);
				$file=substr $prefile,0,-11;
				$file=~s/.*?\\//gs;
			}
			else {
			print "Invalid Filename in GetRight list!\n";
			}
		}
		elsif ($check=~/\r/) {
			print "Downloading $file from $url...\n";
			system "darxget -q $url";
		}
		else {
		}
	}
}
close (lista);
