tribler.core.libtorrent.torrents

Attributes

logger

Classes

TorrentVersion

Torrent creation flag to define the torrent protocol version.

TorrentFileResult

A dictionary to describe a newly-created torrent.

Functions

check_handle(...)

Return the libtorrent handle if it's available, else return the default value.

require_handle(...)

Invoke the function once the handle is available. Returns a future that will fire once the function has completed.

common_prefix(→ pathlib.Path)

Get the path prefixes component-wise.

_existing_files(→ collections.abc.Iterable[tuple[str, ...)

most_efficient_file_dupe(→ None)

Get dst into src in the most efficient way possible:

create_torrent_file(→ TorrentFileResult)

Create a torrent file from the given paths and parameters.

get_info_from_handle(→ libtorrent.torrent_info | None)

Call handle.torrent_file() and handle RuntimeErrors.

Module Contents

tribler.core.libtorrent.torrents.logger
class tribler.core.libtorrent.torrents.TorrentVersion(*args, **kwds)

Bases: enum.Enum

Torrent creation flag to define the torrent protocol version.

Warning:
  • Setting only v1 is ok.

  • Setting only v2 is ok.

  • Setting neither flag is ok (creates a hybrid torrent).

  • Setting both will cause a crash!

v1
v2
hybrid = 0
tribler.core.libtorrent.torrents.check_handle[**WrappedParams, WrappedReturn](default: WrappedReturn) collections.abc.Callable[[collections.abc.Callable[Concatenate[tribler.core.libtorrent.download_manager.download.Download, libtorrent.torrent_handle, WrappedParams], WrappedReturn]], collections.abc.Callable[Concatenate[tribler.core.libtorrent.download_manager.download.Download, WrappedParams], WrappedReturn]]

Return the libtorrent handle if it’s available, else return the default value.

Author(s): Egbert Bouman

tribler.core.libtorrent.torrents.require_handle[**WrappedParams, WrappedReturn](func: collections.abc.Callable[Concatenate[tribler.core.libtorrent.download_manager.download.Download, libtorrent.torrent_handle, WrappedParams], WrappedReturn]) collections.abc.Callable[Concatenate[tribler.core.libtorrent.download_manager.download.Download, WrappedParams], asyncio.Future[WrappedReturn | None]]

Invoke the function once the handle is available. Returns a future that will fire once the function has completed.

Author(s): Egbert Bouman

tribler.core.libtorrent.torrents.common_prefix(paths_list: list[pathlib.Path]) pathlib.Path

Get the path prefixes component-wise.

tribler.core.libtorrent.torrents._existing_files(path_list: list[pathlib.Path], names: list[str] | None) collections.abc.Iterable[tuple[str, pathlib.Path]]
class tribler.core.libtorrent.torrents.TorrentFileResult

Bases: TypedDict

A dictionary to describe a newly-created torrent.

success: bool
base_dir: pathlib.Path
atp: libtorrent.add_torrent_params
infohash: bytes
tribler.core.libtorrent.torrents.most_efficient_file_dupe(src: pathlib.Path, dst: pathlib.Path) None
Get dst into src in the most efficient way possible:
  1. Symlink.

  2. Hardlink.

  3. Copy.

If all three fail, we crash.

tribler.core.libtorrent.torrents.create_torrent_file(export_dir: str, file_path_list: list[pathlib.Path], files_names: list[str] | None = None, name: str | None = None, announce: str | None = None, announce_list: list[str] | None = None, comment: str | None = None, created_by: str | None = None, nodes: list[tuple[str, int]] | None = None, piece_size: int = 0, url_list: list[str] | None = None, torrent_version: TorrentVersion = TorrentVersion.v1) TorrentFileResult

Create a torrent file from the given paths and parameters.

If an output file path is omitted, no file will be written to disk.

tribler.core.libtorrent.torrents.get_info_from_handle(handle: libtorrent.torrent_handle) libtorrent.torrent_info | None

Call handle.torrent_file() and handle RuntimeErrors.