tribler.core.libtorrent.trackers

Attributes

UDP

HTTP

HTTPS

SUPPORTED_SCHEMES

DEFAULT_PORTS

delimiters_regex

url_regex

remove_trailing_junk

truncated_url_detector

Exceptions

MalformedTrackerURLException

The tracker URL is not valid.

Functions

get_uniformed_tracker_url(→ str | None)

Parses the given tracker URL and returns in a uniform URL format.

parse_tracker_url(→ tuple[str, tuple[str, int], str])

Parses the tracker URL and checks whether it satisfies tracker URL constraints.

_parse_tracker_url(→ tuple[str, tuple[str, int], str])

Parses the tracker URL and check whether it satisfies certain constraints.

add_url_params(→ str)

Add GET params to provided URL being aware of existing.

is_valid_url(→ bool | None)

Checks whether the given URL is a valid URL.

Module Contents

tribler.core.libtorrent.trackers.UDP = 'udp'
tribler.core.libtorrent.trackers.HTTP = 'http'
tribler.core.libtorrent.trackers.HTTPS = 'https'
tribler.core.libtorrent.trackers.SUPPORTED_SCHEMES
tribler.core.libtorrent.trackers.DEFAULT_PORTS
exception tribler.core.libtorrent.trackers.MalformedTrackerURLException

Bases: Exception

The tracker URL is not valid.

tribler.core.libtorrent.trackers.delimiters_regex
tribler.core.libtorrent.trackers.url_regex
tribler.core.libtorrent.trackers.remove_trailing_junk
tribler.core.libtorrent.trackers.truncated_url_detector
tribler.core.libtorrent.trackers.get_uniformed_tracker_url(tracker_url: str) str | None

Parses the given tracker URL and returns in a uniform URL format. It uses regex to sanitize the URL.

Parameters:

tracker_url – Tracker URL

Returns:

the tracker in a uniform format <type>://<host>:<port>/<page>

tribler.core.libtorrent.trackers.parse_tracker_url(tracker_url: str) tuple[str, tuple[str, int], str]

Parses the tracker URL and checks whether it satisfies tracker URL constraints. Additionally, it also checks if the tracker URL is a uniform and valid URL.

:param tracker_url the URL of the tracker :returns: Tuple (scheme, (host, port), announce_path)

tribler.core.libtorrent.trackers._parse_tracker_url(tracker_url: str) tuple[str, tuple[str, int], str]

Parses the tracker URL and check whether it satisfies certain constraints.

  • The tracker type must be one of the supported types (udp, http, https).

  • UDP trackers requires a port.

  • HTTP(s) trackers requires an announce path.

  • HTTP(S) trackers default to HTTP(S)_PORT if port is not present on the URL.

:param tracker_url the URL of the tracker :returns: Tuple (scheme, (host, port), announce_path)

tribler.core.libtorrent.trackers.add_url_params(url: str, params: dict) str

Add GET params to provided URL being aware of existing.

>> url = ‘http://stackoverflow.com/test?answers=true’ >> new_params = {‘answers’: False, ‘data’: [‘some’,’values’]} >> add_url_params(url, new_params) ‘http://stackoverflow.com/test?data=some&data=values&answers=false

Parameters:
  • url – string of target URL

  • params – dict containing requested params to be added

Returns:

string with updated URL

tribler.core.libtorrent.trackers.is_valid_url(url: str) bool | None

Checks whether the given URL is a valid URL.

Both UDP and HTTP URLs will be validated correctly.

Parameters:

url – an object representing the URL

Returns:

Boolean specifying whether the URL is valid