NAME

Net::BitTorrent::Protocol::BEP53 - Magnet URI Parser and Generator

SYNOPSIS

use Net::BitTorrent::Protocol::BEP53;

# Parse an incoming URI
my $m = Net::BitTorrent::Protocol::BEP53->parse( $uri_string );

say 'Name: ' . $m->name;
say 'V2 Hash: ' . unpack('H*', $m->infohash_v2) if $m->infohash_v2;

# Generate a new URI
my $new_uri = Net::BitTorrent::Protocol::BEP53->new(
    inf_hash_v2  => $ih2,
    name         => 'Special Linux Distro',
    trackers     => ['udp://tracker.example.com:80']
)->to_string();

DESCRIPTION

Net::BitTorrent::Protocol::BEP53 implements the magnet URI extension (BEP 53). It provides a robust parser and generator for magnet links, specifically updated to support the multihash SHA-256 identifiers required for BitTorrent v2.

Multihash Support

This module correctly identifies and extracts:

v1 (legacy): urn:btih:... (SHA-1)
v2 (modern): urn:btmh:1220... (SHA-256 multihash)

METHODS

parse( $uri )

Parses a Magnet URI string.

my $m = Net::BitTorrent::Protocol::BEP53->parse( $uri );

This method parses the query parameters of a magnet link and returns a new Net::BitTorrent::Protocol::BEP53 object. It handles multihash identifiers (BEP 53).

Expected parameters:

$uri

The Magnet URI string.

to_string( )

Generates a Magnet URI string.

my $uri = $m->to_string();

This method returns the URI-encoded magnet representation of the object's current state.

infohash_v1( )

Returns the 20-byte binary v1 infohash.

my $ih = $m->infohash_v1();

infohash_v2( )

Returns the 32-byte binary v2 infohash.

my $ih = $m->infohash_v2();

trackers( )

Returns the list of tracker URLs.

my $tr = $m->trackers();

name( )

Returns the display name (dn).

my $name = $m->name();

nodes( )

Returns the list of DHT bootstrap nodes (x.pe).

my $nodes = $m->nodes();

SPECIFICATIONS

  • BEP 09: Magnet URI format (Foundational)

  • BEP 53: Magnet URI extension (v2 and multihash)

AUTHOR

Sanko Robinson <sanko@cpan.org>

COPYRIGHT

Copyright (C) 2008-2026 by Sanko Robinson.

This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.