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

Creates .torrent metainfo files from local content. More...

#include <torrentcreator.h>

+ Inheritance diagram for TorrentCreator:
+ Collaboration diagram for TorrentCreator:

Signals

void progressUpdated (int piecesHashed, int totalPieces)
 Emitted during piece hashing to report progress.
 

Public Member Functions

 TorrentCreator (QObject *parent=nullptr)
 Construct a TorrentCreator.
 
void setPieceSize (int bytes)
 Set the piece size in bytes.
 
int pieceSize () const
 Current piece size setting.
 
void setTrackers (const QStringList &urls)
 Set tracker announce URLs.
 
QStringList trackers () const
 Current tracker list.
 
void addTrackerTier (const QStringList &urls)
 Add a tracker tier (group of announce URLs).
 
void setWebSeeds (const QStringList &urls)
 Set web seed URLs (BEP 19 / GetRight-style HTTP seeding).
 
QStringList webSeeds () const
 Current web seed list.
 
void setComment (const QString &value)
 Set the comment embedded in the torrent metainfo.
 
QString comment () const
 Current comment.
 
void setCreator (const QString &value)
 Set the creator string embedded in the torrent metainfo.
 
QString creator () const
 Current creator string.
 
void setPrivate (bool enabled)
 Mark the torrent as private (BEP 27).
 
bool isPrivate () const
 Whether the torrent will be marked private.
 
bool create (const QString &sourcePath, const QString &outputPath)
 Create a .torrent file from local content.
 
qint64 totalSize () const
 Total content size in bytes.
 
int fileCount () const
 Number of files in the torrent.
 
int pieceCount () const
 Number of pieces in the torrent.
 
QString errorString () const
 Last error message, or empty if no error.
 

Detailed Description

Creates .torrent metainfo files from local content.

TorrentCreator wraps libtorrent's create_torrent API and produces bencoded .torrent files that can be distributed to trackers or loaded by TorrentClient::addTorrent().

The creation runs synchronously in create() — for large file sets consider calling from a worker thread or using QFuture.

creator.setTrackers({"udp://tracker.example.com:6969/announce"});
creator.setComment("My album");
creator.setPrivate(true);
if (creator.create("/path/to/album", "/tmp/album.torrent")) {
qDebug() << "Created" << creator.totalSize() << "bytes,"
<< creator.fileCount() << "files,"
<< creator.pieceCount() << "pieces";
}
Creates .torrent metainfo files from local content.
QString creator() const
Current creator string.
void setTrackers(const QStringList &urls)
Set tracker announce URLs.

Definition at line 32 of file torrentcreator.h.

Constructor & Destructor Documentation

◆ TorrentCreator()

TorrentCreator::TorrentCreator ( QObject *  parent = nullptr)
explicit

Construct a TorrentCreator.

Parameters
parentOptional QObject parent.

Member Function Documentation

◆ addTrackerTier()

void TorrentCreator::addTrackerTier ( const QStringList &  urls)

Add a tracker tier (group of announce URLs).

All URLs in the list share the same tier, and the client will pick randomly among them.

Parameters
urlsList of announce URLs for this tier.

◆ comment()

QString TorrentCreator::comment ( ) const
inline

Current comment.

Definition at line 92 of file torrentcreator.h.

◆ create()

bool TorrentCreator::create ( const QString &  sourcePath,
const QString &  outputPath 
)

Create a .torrent file from local content.

sourcePath can be a single file or a directory. When a directory is given, all files in it (recursively) are included.

Parameters
sourcePathPath to the file or directory to torrent.
outputPathWhere to write the .torrent file.
Returns
true on success, false on failure (check errorString()).

◆ creator()

QString TorrentCreator::creator ( ) const
inline

Current creator string.

Definition at line 102 of file torrentcreator.h.

◆ errorString()

QString TorrentCreator::errorString ( ) const
inline

Last error message, or empty if no error.

Definition at line 138 of file torrentcreator.h.

◆ fileCount()

int TorrentCreator::fileCount ( ) const
inline

Number of files in the torrent.

Valid after a successful create().

Definition at line 134 of file torrentcreator.h.

◆ isPrivate()

bool TorrentCreator::isPrivate ( ) const
inline

Whether the torrent will be marked private.

Definition at line 113 of file torrentcreator.h.

◆ pieceCount()

int TorrentCreator::pieceCount ( ) const
inline

Number of pieces in the torrent.

Valid after a successful create().

Definition at line 136 of file torrentcreator.h.

◆ pieceSize()

int TorrentCreator::pieceSize ( ) const
inline

Current piece size setting.

0 means automatic.

Definition at line 55 of file torrentcreator.h.

◆ progressUpdated

void TorrentCreator::progressUpdated ( int  piecesHashed,
int  totalPieces 
)
signal

Emitted during piece hashing to report progress.

Parameters
piecesHashedNumber of pieces hashed so far.
totalPiecesTotal number of pieces.

◆ setComment()

void TorrentCreator::setComment ( const QString &  value)

Set the comment embedded in the torrent metainfo.

Parameters
valueFree-text comment string.

◆ setCreator()

void TorrentCreator::setCreator ( const QString &  value)

Set the creator string embedded in the torrent metainfo.

Defaults to "KanoopTorrentQt" if not set.

Parameters
valueCreator identification string.

◆ setPieceSize()

void TorrentCreator::setPieceSize ( int  bytes)

Set the piece size in bytes.

Must be a power of two (e.g. 16384, 32768, 65536, ...). If not set or set to 0, libtorrent picks an optimal size based on total content size.

Parameters
bytesPiece size in bytes, or 0 for automatic.

◆ setPrivate()

void TorrentCreator::setPrivate ( bool  enabled)

Mark the torrent as private (BEP 27).

Private torrents disable DHT and PEX; peers can only be obtained from the tracker.

Parameters
enabledtrue for a private torrent.

◆ setTrackers()

void TorrentCreator::setTrackers ( const QStringList &  urls)

Set tracker announce URLs.

Each string is a single announce URL. Multiple trackers are added as separate tiers (one tier per URL). For grouped tiers, use addTrackerTier().

Parameters
urlsList of tracker announce URLs.

◆ setWebSeeds()

void TorrentCreator::setWebSeeds ( const QStringList &  urls)

Set web seed URLs (BEP 19 / GetRight-style HTTP seeding).

Parameters
urlsList of HTTP/HTTPS base URLs.

◆ totalSize()

qint64 TorrentCreator::totalSize ( ) const
inline

Total content size in bytes.

Valid after a successful create().

Definition at line 132 of file torrentcreator.h.

◆ trackers()

QStringList TorrentCreator::trackers ( ) const
inline

Current tracker list.

Definition at line 67 of file torrentcreator.h.

◆ webSeeds()

QStringList TorrentCreator::webSeeds ( ) const
inline

Current web seed list.

Definition at line 84 of file torrentcreator.h.


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