Class AddTorrentParams
AddTorrentParams is a configuration bundle that specifies everything needed
to add a torrent to a session. You must provide one of three sources:
- Torrent File: - Direct .torrent file
- Magnet Link: - Magnet link or HTTP URL to .torrent
- Info-Hash Only: or
Additionally, you must specify - where to save downloaded files.
Creating AddTorrentParams for Different Scenarios:
From .torrent File (Most Common):
TorrentInfo ti = new TorrentInfo(new File("ubuntu.torrent"));
AddTorrentParams params = new AddTorrentParams();
params.torrentInfo(ti);
params.savePath("/path/to/downloads");
// Optional: Set file priorities
Priority[] priorities = {Priority.NORMAL, Priority.IGNORE, Priority.NORMAL};
params.filePriorities(priorities);
// Optional: Set storage mode
params.storageMode(StorageMode.STORAGE_MODE_SPARSE);
sm.download(ti, new File("/path/to/downloads"));
From Magnet Link:
String magnetLink = "magnet:?xt=urn:btih:C1939CA413B9302..." +
"&dn=Ubuntu+20.04.iso&tr=http%3A%2F%2Ftracker.example.com";
AddTorrentParams params = new AddTorrentParams();
params.url(magnetLink);
params.savePath("/path/to/downloads");
// The session will fetch metadata from peers
// Listen for METADATA_RECEIVED alert to know when ready
From Info-Hash Only (DHT/PEX Discovery):
// You have an info-hash, no metadata yet
Sha1Hash infoHash = new Sha1Hash("d8e8fca2dc0f896fd7cb4cb0031ba249");
AddTorrentParams params = new AddTorrentParams();
params.infoHashV1(infoHash);
params.name("Unknown Torrent"); // Temporary name until metadata arrives
params.savePath("/path/to/downloads");
// Session will download metadata from peers
Advanced Configuration:
AddTorrentParams params = new AddTorrentParams();
params.torrentInfo(ti);
params.savePath("/path/to/downloads");
// Advanced options:
params.resume(resumeData); // Resume from saved state
params.filePriorities(priorities); // Skip some files
params.storageMode(StorageMode.STORAGE_MODE_ALLOCATE); // Pre-allocate
// Flags control behavior
params.flags(new torrent_flags_t()); // Can set multiple flags
params.name("Custom Name"); // For display
params.comment("Download added via API");
// Ports and endpoints
List<TcpEndpoint> peers = ...;
params.peers(peers); // Pre-seed with known peers
// Max upload rate for this torrent
params.uploadLimit(500 * 1024); // 500 KB/s max
Metadata Extensions: When adding a torrent with only an info-hash (no .torrent file), metadata must be downloaded from peers. This requires BEP 9 support (metadata extension) on peers.
AddTorrentParams params = new AddTorrentParams();
params.infoHashV1(sha1Hash);
params.savePath("/downloads");
// Listen for metadata updates
sm.addListener(new AlertListener() {
public int[] types() {
return new int[] {AlertType.METADATA_RECEIVED.swig()};
}
public void alert(Alert<?> alert) {
if (alert instanceof MetadataReceivedAlert) {
System.out.println("Metadata received!");
TorrentHandle th = ((MetadataReceivedAlert) alert).handle();
}
}
});
Resume Data: You can resume an incomplete download using saved resume data:
// From a previous session
byte[] resumeData = Files.readAllBytes(Paths.get("resume.data"));
AddTorrentParams params = new AddTorrentParams();
params.torrentInfo(ti);
params.savePath("/path/to/downloads");
params.resume(resumeData); // Skip checking already-downloaded pieces
// This resumes quickly without re-checking files
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty parameters object with the default storage.AddTorrentParams(com.frostwire.jlibtorrent.swig.add_torrent_params p) The native object -
Method Summary
Modifier and TypeMethodDescriptionPeers banned from this torrent.voidbannedPeers(List<TcpEndpoint> value) Peers banned from this torrent.static AddTorrentParamsdhtNodes()A list of hostname and port pairs, representing DHT nodes to be added to the session (if DHT is enabled).voidA list of hostname and port pairs, representing DHT nodes to be added to the session (if DHT is enabled).intvoiddownloadLimit(int value) voidfilePriorities(Priority[] priorities) Can be set to control the initial file priorities when adding a torrent.com.frostwire.jlibtorrent.swig.torrent_flags_tflags()Flags controlling aspects of this torrent and how it's added.voidflags(com.frostwire.jlibtorrent.swig.torrent_flags_t flags) Flags controlling aspects of this torrent and how it's added.Set this to the info hash of the torrent to add in case the info-hash is the only known property of the torrent.intvoidmaxConnections(int value) intvoidmaxUploads(int value) name()voidstatic AddTorrentParamsparseMagnetUri(String uri) Helper function to parse a magnet uri and fill the parameters.peers()Peers to add to the torrent, to be tried to be connected to as bittorrent peers.voidpeers(List<TcpEndpoint> value) Peers to add to the torrent, to be tried to be connected to as bittorrent peers.voidpiecePriorities(Priority[] priorities) This sets the priorities for each individual piece in the torrent.savePath()The path where the torrent is or will be stored.voidThe path where the torrent is or will be stored.voidsetInfoHashes(InfoHash value) Set this to the info hash of the torrent to add in case the info-hash is the only known property of the torrent.voidstorageMode(StorageMode value) com.frostwire.jlibtorrent.swig.add_torrent_paramsswig()object with the torrent to add.voidobject with the torrent to add.The default tracker id to be used when announcing to trackers.voidThe default tracker id to be used when announcing to trackers.trackers()If the torrent doesn't have a tracker, but relies on the DHT to find peers, the can specify tracker URLs for the torrent.voidIf the torrent doesn't have a tracker, but relies on the DHT to find peers, this method can specify tracker URLs for the torrent.The tiers the URLs in belong to.voidtrackerTiers(List<Integer> value) The tiers the URLs in belong to.intvoiduploadLimit(int value) urlSeeds()Url seeds to be added to the torrent (`BEP 17`_).voidUrl seeds to be added to the torrent (`BEP 17`_).intversion()Filled in by the constructor.static EntrywriteResumeData(AddTorrentParams params) Turns the resume data in an `AddTorrentParams` object into a bencoded structure.
-
Constructor Details
-
AddTorrentParams
public AddTorrentParams(com.frostwire.jlibtorrent.swig.add_torrent_params p) The native object- Parameters:
p- the native object
-
AddTorrentParams
public AddTorrentParams()Creates an empty parameters object with the default storage.
-
-
Method Details
-
swig
public com.frostwire.jlibtorrent.swig.add_torrent_params swig()- Returns:
- the native object
-
version
public int version()Filled in by the constructor. It is used for forward binary compatibility.- Returns:
- the version
-
torrentInfo
object with the torrent to add.- Returns:
- the torrent info or null if not set
-
torrentInfo
object with the torrent to add.- Parameters:
ti- the torrent info
-
trackers
If the torrent doesn't have a tracker, but relies on the DHT to find peers, the can specify tracker URLs for the torrent.- Returns:
- the list of trackers
-
trackers
If the torrent doesn't have a tracker, but relies on the DHT to find peers, this method can specify tracker URLs for the torrent.- Parameters:
value- the list of trackers
-
trackerTiers
The tiers the URLs in belong to. Trackers belonging to different tiers may be treated differently, as defined by the multi tracker extension. This is optional, if not specified trackers are assumed to be part of tier 0, or whichever the last tier was as iterating over the trackers.- Returns:
- the list of trackers tiers
-
trackerTiers
The tiers the URLs in belong to. Trackers belonging to different tiers may be treated differently, as defined by the multi tracker extension. This is optional, if not specified trackers are assumed to be part of tier 0, or whichever the last tier was as iterating over the trackers.- Parameters:
value- the list of trackers tiers
-
dhtNodes
A list of hostname and port pairs, representing DHT nodes to be added to the session (if DHT is enabled). The hostname may be an IP address.- Returns:
- the list of DHT nodes
-
get_verified_leaf_hashes
-
dhtNodes
A list of hostname and port pairs, representing DHT nodes to be added to the session (if DHT is enabled). The hostname may be an IP address.- Parameters:
value- the list of DHT nodes
-
name
- Returns:
- the name
-
name
- Parameters:
value- the name
-
savePath
The path where the torrent is or will be stored. Note that this may also be stored in resume data. If you want the save path saved in the resume data to be used, you need to set the flag_use_resume_save_path flag... note:: On windows this path (and other paths) are interpreted as UNC paths. This means they must use backslashes as directory separators
- Returns:
- the save path
-
savePath
The path where the torrent is or will be stored. Note that this may also be stored in resume data. If you want the save path saved in the resume data to be used, you need to set the flag_use_resume_save_path flag... note:: On windows this path (and other paths) are interpreted as UNC paths. This means they must use backslashes as directory separators
- Parameters:
value- the save path
-
storageMode
- Returns:
- the storage mode
- See Also:
-
storageMode
- Parameters:
value- the storage mode- See Also:
-
trackerId
The default tracker id to be used when announcing to trackers. By default this is empty, and no tracker ID is used, since this is an optional argument. If a tracker returns a tracker ID, that ID is used instead of this.- Returns:
- the trackerid url parameter
-
trackerId
The default tracker id to be used when announcing to trackers. By default this is empty, and no tracker ID is used, since this is an optional argument. If a tracker returns a tracker ID, that ID is used instead of this.- Parameters:
value- the trackerid url parameter
-
getInfoHashes
Set this to the info hash of the torrent to add in case the info-hash is the only known property of the torrent. i.e. you don't have a .torrent file nor a magnet link.- Returns:
- the info-hash
-
setInfoHashes
Set this to the info hash of the torrent to add in case the info-hash is the only known property of the torrent. i.e. you don't have a .torrent file nor a magnet link.- Parameters:
value- the info-hash
-
maxUploads
public int maxUploads()- Returns:
- max uploads limit
-
maxUploads
public void maxUploads(int value) - Parameters:
value- max uploads limit
-
maxConnections
public int maxConnections()- Returns:
- max connections limit
-
maxConnections
public void maxConnections(int value) - Parameters:
value- max connections limit
-
uploadLimit
public int uploadLimit()- Returns:
- upload limit
-
uploadLimit
public void uploadLimit(int value) - Parameters:
value- upload limit
-
downloadLimit
public int downloadLimit()- Returns:
- download limit
-
downloadLimit
public void downloadLimit(int value) - Parameters:
value- download limit
-
flags
public com.frostwire.jlibtorrent.swig.torrent_flags_t flags()Flags controlling aspects of this torrent and how it's added.- Returns:
- the flags
-
flags
public void flags(com.frostwire.jlibtorrent.swig.torrent_flags_t flags) Flags controlling aspects of this torrent and how it's added.- Parameters:
flags- the flags
-
urlSeeds
Url seeds to be added to the torrent (`BEP 17`_).- Returns:
- the url seeds
-
urlSeeds
Url seeds to be added to the torrent (`BEP 17`_).- Parameters:
value- the url seeds
-
filePriorities
Can be set to control the initial file priorities when adding a torrent. The semantics are the same as forTorrentHandle.prioritizeFiles(Priority[]).- Parameters:
priorities- the priorities
-
piecePriorities
This sets the priorities for each individual piece in the torrent. Each element in the vector represent the piece with the same index. If you set both file- and piece priorities, file priorities will take precedence.- Parameters:
priorities- the priorities
-
peers
Peers to add to the torrent, to be tried to be connected to as bittorrent peers.- Returns:
- the peers list
-
peers
Peers to add to the torrent, to be tried to be connected to as bittorrent peers.- Parameters:
value- the peers list
-
bannedPeers
Peers banned from this torrent. The will not be connected to.- Returns:
- the peers list
-
bannedPeers
Peers banned from this torrent. The will not be connected to.- Parameters:
value- the peers list
-
createInstance
- Returns:
- an instance with the default storage
-
parseMagnetUri
Helper function to parse a magnet uri and fill the parameters.- Parameters:
uri- the magnet uri- Returns:
- the params object filled with the data from the magnet
-
writeResumeData
Turns the resume data in an `AddTorrentParams` object into a bencoded structure.
-