#!/usr/bin/perl

use strict;
use warnings;

my $HOME = $ENV{HOME};
my $TRANSUSER = "$HOME/.transuser.txt";
my $VERSION = "1.0";

print "torrentcmd v$VERSION\n";
print "===============\n";
if (! -f $TRANSUSER)
{
	print "$TRANSUSER is not found. please create it with a line like:\n";
	print "user:password\n";
	exit 1;
}

open my $file, '<', $TRANSUSER or die("Unable to open $TRANSUSER: $!");
my $TransUserString = <$file>;
chop($TransUserString);
close $file;

my $TorrentCommand = "transmission-remote --auth \"$TransUserString\" -a";
my $CurFile = shift;

if ($CurFile eq "")
{
        print "Must specify the file to add\n";
        exit 1;
}

print "Adding torrent file $CurFile\n";

system("$TorrentCommand /var/lib/transmission-daemon/downloads/$CurFile");

exit 0;
