Skip to main content

PoTorrentsHandle

Manages torrents for a specific session.

Methods

add(params: LtAddTorrentParams): void

v1.0

Adds a torrent to the session.

Example

This will add a torrent to the session by its info hash.

torrents:add({
info_hash = LtInfoHash("aabb..")
save_path = "/tmp"
})

count(): number

v1.0

Returns the total number of torrents in this handle.

get(info_hash: LtInfoHash): LtTorrentHandle, LtTorrentStatus | nil

v1.0

Gets a single torrent based on the given info hash. Returns a tuple of a torrent handle and the latest cached torrent status. If you do not need the absolute latest status, use the cached value (it is free).

Example

local hash = LtInfoHash("176de2e6724976a38d51d0a34d3c0503a2305e63")
local handle, status = torrents:get(hash)

if handle ~= nil then
print("Found torrent {}", status.name)
end

list(): PoTorrentsIterator

v1.0

Returns an iterator to let you loop through all the torrents.

Example

for handle, status in torrents:list() do
print("Torrent {}", status.name)

if status.name == "hazardous materials" then
handle:pause()
end
end

list(query: PoQuery): PoTorrentsIterator

v1.0

Returns an iterator that filters each torrent on the provided query - i.e only torrents that matches the iterator will be returned.

Example

local only_large = PoQuery.parse("size:>1gb")

for handle, status in torrents:list(only_large) do
print("Torrent {} is large", status.name)
end

remove(info_hash: LtInfoHash): void

v1.0

Removes a torrent by its info hash.

remove(handle: LtTorrentHandle): void

v1.0

Removes a torrent given its handle.