X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=xmlrtorrent.git;a=blobdiff_plain;f=xmlrtorrent.pl;h=d3e4f81463b700dcd724673382b592090f5f96de;hp=3adbe276c7780956ce86613b6053d87bf1cc05d3;hb=a0d7b7dea026944eb3671eebfbc078474598cbf0;hpb=6cfd0a2c87ccb3ce8f49f1b122b1eab7ab3bc1b8 diff --git a/xmlrtorrent.pl b/xmlrtorrent.pl index 3adbe27..d3e4f81 100644 --- a/xmlrtorrent.pl +++ b/xmlrtorrent.pl @@ -10,6 +10,7 @@ use vars qw($VERSION %IRSSI); use XML::Simple; use Data::Dumper; use File::Spec; +use List::Util qw(max); use xmlrtorrent; my $conf; @@ -25,6 +26,7 @@ my $PARAMS = { 'XMLURL' => 'http://localhost/RPC2', 'USERNAME' => '', 'PASSWORD' => '', + '_QUEUE' => {}, }; # activate debug here @@ -212,12 +214,17 @@ sub cmd_queue { } $torrentlist{$torrentindex++} = {'CHANNEL' => '', 'NICK' => '', 'URL' => $id}; } elsif (('list' eq $subcmd) or !defined($subcmd)) { + my $l; write_irssi('List of queued torrents'); - foreach (sort(keys(%torrentlist))) { - write_irssi(' %3d: %s@%s: %s', $_, - $torrentlist{$_}->{'NICK'}, - $torrentlist{$_}->{'CHANNEL'}, - $torrentlist{$_}->{'URL'}); + if (0 == scalar(keys(%torrentlist))) { + write_irssi(' (no torrents in local queue)'); + } else { + foreach (sort(keys(%torrentlist))) { + write_irssi(' %3d: %s@%s: %s', $_, + $torrentlist{$_}->{'NICK'}, + $torrentlist{$_}->{'CHANNEL'}, + $torrentlist{$_}->{'URL'}); + } } } else { write_irssi('Unknown subcommand: %s', $subcmd); @@ -236,24 +243,35 @@ sub cmd_remote { } write_irssi('List of rempote torrents'); - foreach (@{$rqueue}) { - write_irssi('%s%s: %sB/%sB done (%d%%), %sB/s up, %sB/s down', - $_->[6]?'*':' ', - $_->[0], - format_number($_->[2]), - format_number($_->[1]), - ($_->[2]*100)/$_->[1], - format_number($_->[3]), - format_number($_->[4])); + if (0 == scalar(@{$rqueue})) { + write_irssi(' (no torrents in remote queue)'); + } else { + foreach (@{$rqueue}) { + write_irssi(' %s%s: %sB/%sB done (%d%%), %sB/s up, %sB/s down', + $_->[6]?'*':' ', + $_->[0], + format_number($_->[2]), + format_number($_->[1]), + ($_->[2]*100)/$_->[1], + format_number($_->[3]), + format_number($_->[4])); + } } } } sub cmd_save { + + my %mappedqueue; + + # XML::Simple has some problems with numbers as nodenames, + # so we have to modify our queue a bit. + %mappedqueue = map {("_$_" => $torrentlist{$_})} keys(%torrentlist); eval { open(CONF, '>'.$conffile) or die 'Could not open config file'; + $conf->{'xmlrtorrent'}->{'_QUEUE'} = \%mappedqueue; print CONF XML::Simple::XMLout($conf, KeepRoot => 1, KeyAttr => {'config' => 'module', 'option' => 'key'}); close(CONF); }; @@ -332,6 +350,11 @@ sub init_xmlrtorrent { } } + # Restore the queue + %torrentlist = %{$conf->{'xmlrtorrent'}->{'_QUEUE'}}; + %torrentlist = map { my $a = substr($_, 1); ("$a" => $torrentlist{$_}) } keys(%torrentlist); + $torrentindex = max(keys(%torrentlist)) + 1; + unless(defined($rtorrent = xmlrtorrent->new( 'XMLURL' => $conf->{'xmlrtorrent'}->{'XMLURL'}, 'USERNAME' => $conf->{'xmlrtorrent'}->{'USERNAME'},