The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::BitTorrent::Torrent::Generator - .torrent metadata generator

Synopsis

    # Generate a single file .torrent to seed file.avi
    my $t1 = Net::BitTorrent::Torrent::Generator->new( path => 'file.avi' );

    # Add everything in the current directory accept .torrent files
    my $t2 = Net::BitTorrent::Torrent::Generator->new(
        path      => '../',
        path_skip => qr[.*torrent$]
    );

    # Now, let's write the metadata to disk
    print 'Saving ' .  $t2->info_hash->to_Hex . '...';
    open my($torrent), '>', 'test.torrent' || die 'FAIL!';
    syswrite $torrent, $t2->raw_data;
    close $torrent;

Description

TODO

Methods

Creating a new .torrent is simple. As is this API.

my $torrent = Net::BitTorrent::Torrent::Generator->new( path => ..., [ ... ] )

Creates a new generator object.

This constructor requires the following arguments:

path

See path.

This constructor also supports the following optional arguments:

announce

See announce.

announce_list

See announce_list.

path_skip

See path_skip.

comment

See comment.

merge

This is an advanced argument containing a hashref which will be merged with the final metadata when generated.

Don't use this.

piece_length

See "$torrent->piece_length( )" in piece_length.

private

See private.

$torrent->announce( )

The announce URL of the tracker. With the advent and current popularity of DHT, PEX, and other alternate means of learning about peers, this value may be considered optional.

Use $torrent->_set_piece_length to set this value.

$torrent->announce_list( )

Optional list of URLs.

Use $torrent->_set_announce_list( [ [url, url], [url] ] ) to set this value. To add a single tier, use $torrent->_add_tier( [ url, url ] ) >.

See also BEP12.

$torrent->comment( )

This is an optional, free-form textual comment.

$torrent->files( )

Returns the list of files contained in this torrent.

$torrent->info_hash( )

Returns the 160bit hex string used to identify this torrent as a Bit::Vector object.

$torrent->metadata( )

This method generates and returns the metadata.

For raw data ready to write to disk, see raw_data.

$torrent->path( )

This is a string contining either a directory or a single file.

If this is a directory, a multi-file torrent is generated.

Use $torrent->_set_path( $path ) to set this value later.

$torrent->path_skip( )

This is a regular expression. If pathpath( )"> is a directory, found files are checked against this regex. If they match, they're ignored when generating <metadata|/"$torrent->metadata( )">.

Use $torrent->_set_path_skip( qr[...] ) to set this value later and $torrent->_clear_path_skip( ) to clear it.

$torrent->piece_length( )

For the purposes of transfer, files are split into fixed-size pieces which are all the same length except for possibly the last one which may be truncated. piece_length is almost always a power of two, most commonly 2**18 (256KB). This is also our default value.

Use $torrent->_set_piece_length to set this value.

$torrent->private( )

A boolean value for cheap DRM behaviour.

Use $torrent->_set_private to set this on and $torrent->_unset_private to turn it back off.

See also BEP27.

$torrent->raw_data( )

Generates metadata and returns it as a bencoded string. This is what you'd write to disk.

$torrent->total_size( )

Returns the total size of all the files related to this torrent.

Notes

This class may be renamed. Suggestions welcome.

See Also

BEP03

Net::BitTorrent::File

TODO

Optional, user-defined/smart file sorting

Author

Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/

CPAN ID: SANKO

License and Legal

Copyright (C) 2008-2010 by Sanko Robinson <sanko@cpan.org>

This program is free software; you can redistribute it and/or modify it under the terms of The Artistic License 2.0. See the LICENSE file included with this distribution or notes on the Artistic License 2.0 for clarification.

When separated from the distribution, all original POD documentation is covered by the Creative Commons Attribution-Share Alike 3.0 License. See the clarification of the CCA-SA3.0.

Neither this module nor the Author is affiliated with BitTorrent, Inc.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 299:

Unterminated C< ... > sequence