| WWW-Opentracker-Stats documentation | Contained in the WWW-Opentracker-Stats distribution. |
WWW::Opentracker::Stats::Mode::TPBS::Bencode
Decodes the bencoded TPBS statistics from Opentracker.
Args: $class, $payload
Returns a HASHREF of the decoded stats structure.
The structure looks something like this:
$VAR1 => {
files => {
INFOHASH => {
incomplete => 2,
downloaded => 52,
complete => 71,
},
INFOHASH => ...
}
}
Knut-Olav Hoven, <knutolav@gmail.com>
Copyright (C) 2009 by Knut-Olav Hoven
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
| WWW-Opentracker-Stats documentation | Contained in the WWW-Opentracker-Stats distribution. |
package WWW::Opentracker::Stats::Mode::TPBS::Bencode; use strict; use warnings; use Bit::Vector; use Convert::Bencode qw(bencode bdecode);
sub decode_stats { my ($class, $payload) = @_; return {} unless $payload; my $t = bdecode($payload); $t->{'files'} = {} unless defined $t->{'files'}; my @replace = keys %{$t->{'files'}}; for my $key (@replace) { my $value = delete $t->{'files'}->{$key}; my $bin = unpack('B*', $key); my $v = Bit::Vector->new_Bin(160, $bin); my $hex = $v->to_Hex; $t->{'files'}->{$hex} = $value; } return $t; }
1;