X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=xmlrtorrent.pl;h=4f63ba7dec6ea25f2b70a8f98eb56026983bbb5c;hb=2f5d76db7c94e21aa21ee611c2aa893c5e8b58dd;hp=3e13500abb79e3b3b27c9088dd02778c7c259bd5;hpb=bd6aedbd2131d60cd3c0291405f03b25cf8b3326;p=xmlrtorrent.git diff --git a/xmlrtorrent.pl b/xmlrtorrent.pl index 3e13500..4f63ba7 100644 --- a/xmlrtorrent.pl +++ b/xmlrtorrent.pl @@ -26,14 +26,11 @@ my $rtorrent; my @outputstack = (undef); my $PARAMS = { - 'XMLURL' => 'http://localhost/RPC2', - 'USERNAME' => '', - 'PASSWORD' => '', '_QUEUE' => {}, }; # activate debug here -my $debug = 1; +my $debug = 0; # "message public", SERVER_REC, char *msg, char *nick, char *address, char *target signal_add_last("message public" => sub {check_for_link(\@_,1,4,2,0);}); @@ -97,12 +94,15 @@ sub write_irssi { my @text = @_; my $output = $outputstack[0]; - $text[0] = '%%mxmlrtorrent: %%n' . $text[0]; + my $format = '%%mxmlrtorrent: %%n' . shift(@text); + + # escape % in parameters from irssi + s/%/%%/g foreach @text; if (defined($output) and ref($output)) { - $output->print(sprintf(shift(@text), @text), MSGLEVEL_CLIENTCRAP); + $output->print(sprintf($format, @text), MSGLEVEL_CLIENTCRAP); } else { - Irssi::print(sprintf(shift(@text), @text)); + Irssi::print(sprintf($format, @text)); } } @@ -121,35 +121,6 @@ sub write_debug { } } -# This is shamelessly stolen from pythons urlgrabber -sub format_number { - my $number = shift; - my $SI = shift || 0; - my @symbols = ('', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'); - my $step = $SI?1000:1024; - my $thresh = 999; - my $depth = 0; - my $max_depth = $#symbols; - my $format; - - while (($number > $thresh) and ($depth < $max_depth)) { - $depth += 1; - $number /= $step; - } - - if ($number =~ /^[+-]?\d+$/) { - # Integer. - $format = '%i%s'; - } elsif ($number < 9.95) { - $format = '%.1f%s'; - } else { - $format = '%.0f%s'; - } - return sprintf($format, $number, $symbols[$depth]); -} - - - sub check_for_link { my ($signal,$parammessage,$paramchannel,$paramnick,$paramserver) = @_; my $server = $signal->[$paramserver]; @@ -157,7 +128,6 @@ sub check_for_link { my $message = ($parammessage == -1) ? '' : $signal->[$parammessage]; my $nick = ($paramnick == -1)?defined($server)?$server->{'nick'}:'':$signal->[$paramnick]; my $g; - my $m; my $p; my $witem; @@ -166,27 +136,19 @@ sub check_for_link { } else { $witem = Irssi::window_item_find($target); } - + # Look if we should ignore this line if ($message =~ m,(?:\s|^)/nosave(?:\s|$),) { return; } - + push_output($witem); # Look if there is a torrent link in there - $message =~ m,(http://\S*\.(?:torrent|penis)),; - $m = $1; - while (defined($m)) { - write_debug('Torrent-URL: %s', $m); - $torrentlist{$torrentindex++} = {'CHANNEL' => $target, 'NICK' => $nick, 'URL' => $m}; - - # Remove the matched part from the message and try again (there may be - # more!) - $message =~ s/$m//; - - $message =~ m|(http://.*\.torrent)|; - $m = $1; + + while ($message =~ m,(http://\S*\.(?:torrent|penis)),g) { + write_debug('Torrent-URL: %s', $1); + $torrentlist{$torrentindex++} = {'CHANNEL' => $target, 'NICK' => $nick, 'URL' => $1}; } pop_output(); @@ -249,19 +211,19 @@ sub cmd_remote { return; } - write_irssi('List of rempote torrents'); + write_irssi('List of remote torrents'); 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])); + $_->{'ACTIVE'}?'*':' ', + $_->{'NAME'}, + $_->{'BYTES_DONE'}, + $_->{'SIZE_BYTES'}, + $_->{'BYTES_DONE'}*100/$_->{'SIZE_BYTES'}, + $_->{'UP_RATE'}, + $_->{'DOWN_RATE'}); } } } @@ -301,7 +263,7 @@ sub cmd_set { return; } } - write_irssi(undef, 'No such module'); + write_irssi('No such module'); } sub cmd_show { @@ -359,13 +321,13 @@ sub cmd_talker { foreach $p (@talkers) { if (($p->{'NAME'} eq $target) && ($p->{'TYPE'} eq 'talker')) { $talker = $p; - $conf->{'videosite'}->{'talker'} = $target; + $conf->{'xmlrtorrent'}->{'talker'} = $target; return; } } write_irssi('No such talker'); } else { - write_irssi('Current talker: %s', $conf->{'videosite'}->{'talker'}); + write_irssi('Current talker: %s', $conf->{'xmlrtorrent'}->{'talker'}); } } @@ -466,9 +428,13 @@ sub init_xmlrtorrent { $talker = $p; } } - write_debug(undef, 'Selected %s as talker', $talker->{'NAME'}); - $conf->{'videosite'}->{'talker'} = $talker->{'NAME'}; + write_debug('Selected %s as talker', $talker->{'NAME'}); + $conf->{'xmlrtorrent'}->{'talker'} = $talker->{'NAME'}; + # Loop through all plugins and load the config + foreach $p (@talkers) { + $conf->{'xmlrtorrent'}->{'config'}->{$p->{'NAME'}} = $p->mergeconfig($conf->{'xmlrtorrent'}->{'config'}->{$p->{'NAME'}}); + } # Restore the queue %torrentlist = %{$conf->{'xmlrtorrent'}->{'_QUEUE'}};