Protocol::BitTorrent::Metainfo - support for metainfo as found in .torrent files
version 0.004
use Protocol::BitTorrent::Metainfo; print Protocol::BitTorrent::Metainfo->new->parse_info(...)->announce_url;
See Protocol::BitTorrent for top-level documentation.
Instantiate a new metainfo object.
Takes the following named parameters:
announce - tracker URL for announcing peers
comment - optional comment for this torrent
encoding - encoding for the torrent, typically UTF8
Parse the given metainfo structure to populate a new object. Used when reading an existing torrent file:
my $data = File::Slurp::read_file($filename, { binmode => ':raw' }); $data = Protocol::BitTorrent::Metainfo->bdecode($data); my $torrent = Protocol::BitTorrent::Metainfo->new->parse_info($data);
Returns the infohash for this torrent. Defined as the 20-character SHA1 hash of the info data.
Returns or updates the info data (referred to as an 'info dictionary' in the spec).
Returns the current peer ID. This is a 20-character string used to differentiate peers connecting to a torrent.
Will generate a new peer ID if one has not already been assigned.
Generate a new peer ID using the Azureus style:
-BT0001-980123456789
Takes the following parameters:
$type - the 2-character type, defaults to PB (for "Protocol::BitTorrent").
$version - the 4-character version code, should be numeric although this is not enforced. Defaults to current package version with . characters stripped.
$suffix - trailing string data to append to the peer ID, defaults to random decimal digits.
Example invocation:
$torrent->generate_peer_id_azureus('XX', '0100', '0123148')
Generates a peer ID using the default method (currently Azureus which is the only defined method, see "generate_peer_id_azureus").
Returns a list of the files in this torrent, or replaces the current list if given an arrayref.
Get/set tracker announce URL.
Get/set current piece length. Recommended values seem to be between 256KB and 1MB.
Returns the total length for all files in this torrent.
Returns the total number of pieces in this torrent, equivalent to the total length of all files divided by the piece size (and rounded up to include the last partial piece as required).
Returns the combined hash string representing the pieces in this torrent. Will be a byte string of length "total_pieces" * 20.
Returns 1 if this is a private torrent, 0 otherwise.
Returns true if this torrent has the optional private flag.
private
Get/set current encoding for metainfo strings.
Get/set trackers. Takes an arrayref when setting, returns a list.
Get/set metainfo comment.
Get/set creation time of this torrent, as epoch value (seconds since 1st Jan 1970).
Returns the "created" value as a string in ISO8601 format.
Example:
2011-04-01T18:04:00
Get/set 'created by' field, indicating who created this torrent.
Returns the object formatted as a metainfo hashref, suitable for bencoding into a .torrent file.
Adds the given file to this torrent. If the torrent already has a file and is in single mode, will switch to multi mode.
Returns the SHA1 hash for the pieces in the given file.
Returns the tracker announce URL
uploaded - number of bytes uploaded so far by this client
downloaded - number of bytes downloaded so far by this client
left - number of bytes left for this client to transfer
port - (optional) the port this client is listening on, defaults to 6881
event - (optional) type of event, can be started, stopped or completed. If not supplied, this will be treated as an update of a running torrent.
Returns the scrape URL, if there is one. Scrape URLs are only defined if the announce_url contains /announce with no subsequent / characters. Returns undef if a scrape URL cannot be generated.
/announce
/
Tom Molesworth <cpan@entitymodel.com>
Copyright Tom Molesworth 2011-2013. Licensed under the same terms as Perl itself.
To install Protocol::BitTorrent, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Protocol::BitTorrent
CPAN shell
perl -MCPAN -e shell install Protocol::BitTorrent
For more information on module installation, please visit the detailed CPAN module installation guide.