KanoopTorrentQt 0.1.0
Qt6 wrapper library for libtorrent-rasterbar
Loading...
Searching...
No Matches
MagnetLink Class Reference

Parses and constructs BitTorrent magnet URIs. More...

#include <magnetlink.h>

Public Member Functions

 MagnetLink ()
 Construct an invalid (empty) magnet link.
 
 MagnetLink (const QString &uri)
 Parse a magnet URI string.
 
bool isValid () const
 Whether the URI was parsed successfully and contains a valid info hash.
 
QByteArray infoHash () const
 Raw 20-byte SHA-1 info hash.
 
QString infoHashHex () const
 Info hash as a lowercase hex string (40 characters).
 
QString displayName () const
 Human-readable name extracted from the dn parameter.
 
void setDisplayName (const QString &value)
 Set or override the display name.
 
QStringList trackers () const
 Tracker URLs extracted from tr parameters.
 
void addTracker (const QString &url)
 Append a tracker URL.
 
qint64 exactLength () const
 Exact content length from the xl parameter, or 0 if not present.
 
QString toUri () const
 Reconstruct a magnet URI string from the current state.
 

Static Public Member Functions

static MagnetLink fromInfoHash (const QString &hexHash)
 Create a MagnetLink from a hex-encoded info hash.
 

Detailed Description

Parses and constructs BitTorrent magnet URIs.

MagnetLink handles both hex (40-char) and Base32-encoded info hashes, extracts tracker URLs and display names, and can reconstruct a well-formed magnet URI string.

MagnetLink link("magnet:?xt=urn:btih:...");
if (link.isValid()) {
qDebug() << link.displayName() << link.infoHashHex();
}

Definition at line 23 of file magnetlink.h.

Constructor & Destructor Documentation

◆ MagnetLink()

MagnetLink::MagnetLink ( const QString &  uri)
explicit

Parse a magnet URI string.

Supports the xt (exact topic / info hash), dn (display name), tr (tracker), and xl (exact length) parameters.

Parameters
uriA "magnet:?..." URI string.

Member Function Documentation

◆ addTracker()

void MagnetLink::addTracker ( const QString &  url)
inline

Append a tracker URL.

Definition at line 54 of file magnetlink.h.

◆ displayName()

QString MagnetLink::displayName ( ) const
inline

Human-readable name extracted from the dn parameter.

Definition at line 47 of file magnetlink.h.

◆ exactLength()

qint64 MagnetLink::exactLength ( ) const
inline

Exact content length from the xl parameter, or 0 if not present.

Definition at line 57 of file magnetlink.h.

◆ fromInfoHash()

static MagnetLink MagnetLink::fromInfoHash ( const QString &  hexHash)
static

Create a MagnetLink from a hex-encoded info hash.

Automatically appends a set of well-known public trackers.

Parameters
hexHash40-character hex-encoded SHA-1 hash.
Returns
A valid MagnetLink, or an invalid one if hexHash is malformed.

◆ infoHash()

QByteArray MagnetLink::infoHash ( ) const
inline

Raw 20-byte SHA-1 info hash.

Definition at line 42 of file magnetlink.h.

◆ infoHashHex()

QString MagnetLink::infoHashHex ( ) const
inline

Info hash as a lowercase hex string (40 characters).

Definition at line 44 of file magnetlink.h.

◆ isValid()

bool MagnetLink::isValid ( ) const
inline

Whether the URI was parsed successfully and contains a valid info hash.

Definition at line 39 of file magnetlink.h.

◆ setDisplayName()

void MagnetLink::setDisplayName ( const QString &  value)
inline

Set or override the display name.

Definition at line 49 of file magnetlink.h.

◆ toUri()

QString MagnetLink::toUri ( ) const

Reconstruct a magnet URI string from the current state.

Returns
A "magnet:?..." URI string.

◆ trackers()

QStringList MagnetLink::trackers ( ) const
inline

Tracker URLs extracted from tr parameters.

Definition at line 52 of file magnetlink.h.


The documentation for this class was generated from the following file: