Skip to content

API

torrt exposes API so it can be used as an ordinary Python module.

Toolbox

Most commonly used functions are located in toolbox.

Functions

add_torrent_from_url

1
2
3
4
5
add_torrent_from_url(
    url: str,  # (1)!
    download_to: str = '',  # (2)!
    params: dict | None = None,  # (3)!
)
  1. torrent URL

  2. path to download files from torrent into (in terms of torrent client filesystem)

  3. optional parameters to pass to RPC

Adds torrent from a given URL to torrt and torrent clients,


bootstrap

bootstrap()

Bootstraps torrt environment, Populates RPC and Trackers registries with objects instantiated with settings from config.


configure_bot

1
2
3
4
configure_bot(
    bot_alias: str,  # (1)!
    settings_dict: dict,  # (2)!
) -> Optional[BaseBot]
  1. bot alias

  2. settings dictionary to configure bot with

Configures bot using given settings. Saves successful configuration.


configure_logging

1
2
3
4
configure_logging(
    log_level: int = logging.INFO,  # (1)!
    show_logger_names: bool = False,  # (2)!
)
  1. logging level, e.g. logging.DEBUG

  2. flag to show logger names in output

Performs basic logging configuration.


configure_notifier

1
2
3
4
configure_notifier(
    notifier_alias: str,  # (1)!
    settings_dict: dict,  # (2)!
) -> Optional[BaseNotifier]
  1. notifier alias

  2. settings dictionary to configure notifier with

Configures notifier using given settings. Saves successful configuration.


configure_rpc

1
2
3
4
configure_rpc(
    rpc_alias: str,  # (1)!
    settings_dict: dict,  # (2)!
) -> Optional[BaseRPC]
  1. RPC alias

  2. settings dictionary to configure RPC with

Configures RPC using given settings. Saves successful configuration.


configure_tracker

1
2
3
4
configure_tracker(
    tracker_alias: str,  # (1)!
    settings_dict: dict,  # (2)!
) -> Optional[BaseTracker]
  1. tracker alias

  2. settings dictionary to configure tracker with

Configures tracker using given settings. Saves successful configuration.


get_registered_torrents

get_registered_torrents() -> dict

Returns hash-indexed dictionary with information on torrents registered for updates.


init_object_registries

init_object_registries()

Initializes RPC and tracker objects registries with settings from configuration file.


register_torrent

1
2
3
4
5
6
register_torrent(
    hash_str: str,  # (1)!
    torrent_data: TorrentData = None, 
    url: str = '',  # (2)!
    params: dict | None = None,  # (3)!
)
  1. torrent identifying hash

  2. fallback url that will be used in case torrent comment doesn't contain url

  3. optional parameters to pass to RPC

Registers torrent within torrt. Used to register torrents that already exists in torrent clients.


remove_bot

1
2
3
remove_bot(
    alias: str,  # (1)!
)
  1. Bot alias to remove.

Removes bot by alias


remove_notifier

1
2
3
remove_notifier(
    alias: str,  # (1)!
)
  1. Notifier alias to remove.

Removes notifier by alias


remove_torrent

1
2
3
4
remove_torrent(
    hash_str: str,  # (1)!
    with_data: bool = False,  # (2)!
)
  1. torrent identifying hash

  2. flag to also remove files from torrent

Removes torrent by its hash from torrt and torrent clients,


run_bots

run_bots(aliases: list[str] | None = None)

Run aliased bots one after another.


set_walk_interval

1
2
3
set_walk_interval(
    interval_hours: int,  # (1)!
)
  1. hours interval

Sets torrent updates checks interval (in hours).


toggle_rpc

1
2
3
4
toggle_rpc(
    alias: str,  # (1)!
    enabled: bool = True,  # (2)!
)
  1. PRC alias

  2. flag to enable or disable

Enables or disables a given RPC.


tunnel

tunnel()

Try to setup a tunnel for requests.


unregister_torrent

1
2
3
unregister_torrent(
    hash_str: str,  # (1)!
)
  1. torrent identifying hash

Unregisters torrent from torrt. That doesn't remove torrent from torrent clients.


update_torrents

1
2
3
4
update_torrents(
    torrents: dict[str,  dict],  # (1)!
    remove_outdated: bool = True,  # (2)!
) -> dict[str, dict]
  1. torrents data indexed with hashes

  2. flag to remove outdated torrents from torrent clients

Performs torrent updates. Returns hash-indexed dictionary with information on updated torrents


walk

1
2
3
4
5
walk(
    forced: bool = False,  # (1)!
    silent: bool = False,  # (2)!
    remove_outdated: bool = True,  # (3)!
)
  1. flag not to count walk interval setting

  2. flag to suppress possible torrt exceptions

  3. flag to remove torrents that are superseded by a new ones

Performs updates check for the registered torrents.


Utils

Utility function and methods are also available.

Functions

base64encode

base64encode(string_or_bytes: str | bytes) -> bytes

Return base64 encoded input


configure_entity

1
2
3
4
5
6
7
configure_entity(
    type_name: str,  # (1)!
    registry,  # (2)!
    alias: str,  # (3)!
    settings_dict: dict[str,  Any] | None = None,  # (4)!
    before_save: Callable | None = None,  # (5)!
) -> Optional[WithSettings]
  1. Entity type name to be used in massages.

  2. Registry object.

  3. Entity alias.

  4. Settings dictionary to configure object with.

  5. Function to trigger right before configuration is saved. Should accept entity object as argument.

Configures and spawns objects using given settings.

Successful configuration is saved.


dump_contents

dump_contents(filename: str, contents: bytes)

Dumps contents into a file with a given name.


encode_value

1
2
3
4
encode_value(
    value: str, 
    encoding: str = '',  # (1)!
) -> str | bytes
  1. Encoding charset.

Encodes a value.


get_iso_from_timestamp

1
2
3
get_iso_from_timestamp(
    ts: int,  # (1)!
) -> str
  1. timestamp

Get ISO formatted string from timestamp.


get_torrent_from_url

1
2
3
4
get_torrent_from_url(
    url: str | None,  # (1)!
    last_updated: datetime | None = None,  # (2)!
) -> TorrentData | None
  1. URL to download torrent file from

  2. torrent last updated datetime

Downloads torrent from a given URL and returns torrent data.


get_url_from_string

get_url_from_string(string: str) -> str

Returns URL from a string, e.g. torrent comment.


import_classes

import_classes()

Dynamically imports RPC classes and tracker handlers from their directories.


import_from_path

1
2
3
import_from_path(
    path: str,  # (1)!
)
  1. path under torrt

Dynamically imports modules from package. It is an .egg-friendly alternative to os.listdir() walking.


iter_bots

iter_bots() -> Generator[tuple[str, BaseBot], None, None]

Generator to iterate through available bots objects. tuple - bot_alias, bot_object


iter_notifiers

iter_notifiers() -> Generator[tuple[str, BaseNotifier], None, None]

Generator to iterate through available notifier objects. tuple - notifier_alias, notifier_object


iter_rpc

iter_rpc() -> Generator[tuple[str, BaseRPC], None, None]

Generator to iterate through available and enable RPC objects. tuple - rpc_alias, rpc_object


make_soup

make_soup(html: str) -> BeautifulSoup

Returns BeautifulSoup object from a html.


parse_torrent

1
2
3
parse_torrent(
    torrent: bytes,  # (1)!
) -> Torrent | None
  1. Torrent file contents.

Returns Torrent object from torrent contents.


structure_torrent_data

1
2
3
4
5
structure_torrent_data(
    target_dict: dict,  # (1)!
    hash_str: str,  # (2)!
    data: TorrentData,  # (3)!
)
  1. dictionary to update inplace

  2. torrent identifying hash

  3. torrent data (e.g. from tracker page or received from RPC (see parse_torrent()))

Updated target dict with torrent data structured suitably for config storage.


update_dict

update_dict(old_dict: dict, new_dict: dict) -> dict

Updates [inplace] old dictionary with data from a new one with respect to existing values.


Classes

GlobalParam

GlobalParam()

Represents global parameter value holder. Global params can used anywhere in torrt.


HttpClient

1
2
3
4
5
6
HttpClient(
    silence_exceptions: bool = False, 
    dump_fname_tpl: str = '%(ts)s.txt', 
    json: bool = False, 
    tunnel: bool = True
)

Common client to perform HTTP requests.


request

.request(
    url: str,  # (1)!
    data: dict[str,  Any] | None = None,  # (2)!
    referer: str = '', 
    allow_redirects: bool = True, 
    cookies: dict[str,  str] | None = None, 
    headers: dict[str,  str] | None = None,  # (3)!
    json: bool | None = None,  # (4)!
    silence_exceptions: bool | None = None,  # (5)!
    timeout: int = 0,  # (6)!
    **kwargs
) -> Response | dict | None
  1. URL to address

  2. Data to send to URL

  3. Additional headers

  4. Send and receive data as JSON

  5. Do not raise exceptions

  6. Override timeout.


PageData

PageData(title: str, cover: str, date_updated: datetime)

Represents data extracted from torrent page.


TorrentData

1
2
3
4
5
6
7
8
9
TorrentData(
    hash: str = '', 
    name: str = '', 
    url: str = '', 
    url_file: str = '', 
    raw: bytes = b'', 
    page: PageData = None, 
    parsed: Torrent = None
)

Represents information about torrent.


TorrtConfig

TorrtConfig()

Gives methods to work with torrt configuration file.


bootstrap

.bootstrap()

Initializes configuration file if needed.


drop_section

.drop_section(realm: str, key: str)

Drops config section by its key (name) and updates config.


load

.load() -> dict

Returns current settings dictionary.


save

.save(settings_dict: dict)

Saves a given dict as torrt configuration.


update

.update(settings_dict: dict)

Updates configuration file with given settings.


WithSettings

WithSettings(**kwargs)

Introduces settings support for class objects.

NB: * Settings names are taken from inheriting classes init() methods. * init() method MUST use keyword arguments only. * Inheriting classes MUST save settings under object properties with the same name as in init().


log_debug

.log_debug(msg: str)

Sends the message to debug log.


log_error

.log_error(msg: str)

Sends the message to error log.


log_info

.log_info(msg: str)

Sends the message to info log.


log_warning

.log_warning(msg: str)

Sends the message to warning log.


save_settings

.save_settings()

Saves object settings into torrt configuration file.


spawn_with_settings

.spawn_with_settings(settings: dict) -> WithSettings

Spawns and returns object initialized with given settings.


Base RPC class

RPC classes should be implemented using this.

Classes

BaseRPC

BaseRPC(**kwargs)

WithSettings

Base RPC class. All RPC classes should inherit from this.


torrent_fields_map

.torrent_fields_map: ClassVar[dict[str, str]] = {}

mapping from torrent fields names in terms of RPC to field names in term of torrt


log_debug

.log_debug(msg: str)

Sends the message to debug log.


log_error

.log_error(msg: str)

Sends the message to error log.


log_info

.log_info(msg: str)

Sends the message to info log.


log_warning

.log_warning(msg: str)

Sends the message to warning log.


method_add_torrent

1
2
3
4
5
.method_add_torrent(
    torrent: TorrentData,  # (1)!
    download_to: str = '',  # (2)!
    params: dict | None = None,  # (3)!
) -> Any
  1. torrent info

  2. path to download files from torrent into (in terms of torrent client filesystem)

  3. optional information attached to torrent that should be preserved

Adds torrent to torrent client using RPC.


method_get_torrents

1
2
3
.method_get_torrents(
    hashes: list[str] | None = None,  # (1)!
) -> list[dict]
  1. torrent hashes

This should return a dictionary with torrents info from RPC. Each torrent info should be normalized (see normalize_field_names()).


method_get_version

.method_get_version() -> str

Returns torrent client API version.


method_remove_torrent

1
2
3
4
.method_remove_torrent(
    hash_str: str,  # (1)!
    with_data: bool = False,  # (2)!
) -> Any
  1. torrent identifying hash

  2. flag to also remove files from torrent

Removes torrent from torrent client using RPC.


normalize_field_names

.normalize_field_names(torrent_info: dict)

Translates from torrent fields names in terms of RPC to field names in term of torrt. Updates accordingly a given torrent_info inplace.


register

.register()

Adds this object into RPCObjectsRegistry.


save_settings

.save_settings()

Saves object settings into torrt configuration file.


spawn_with_settings

.spawn_with_settings(settings: dict) -> WithSettings

Spawns and returns object initialized with given settings.


Base Tracker classes

Torrent tracker classes should be implemented using this.

Classes

BaseTracker

1
2
3
4
5
BaseTracker(
    cookies: dict[str,  str] | None = None, 
    query_string: str = '', 
    **kwargs
)

WithSettings

Base torrent tracker handler class offering helper methods for its ancestors.


active

.active: bool = True

Tracker support flag. Can be used to skip initialization for currently unavailable trackers.


alias

.alias: str = None

Tracker alias. Usually main tracker domain. See also mirrors attribute.


encoding

.encoding: str | None = None

Tracker html page encoding (cp1251 or other).


mirrors

.mirrors: ClassVar[list[str]] = []

List of mirror domain names.


raise_on_error_response

.raise_on_error_response: bool = False

Whether to raise an exception on request errors. Primary use is debug and testsuite.


test_urls

.test_urls: ClassVar[list[str]] = []

Page URLs for automatic tests of torrent extraction.


can_handle

1
2
3
.can_handle(
    string: str,  # (1)!
) -> bool
  1. String, describing torrent. E.g. URL from torrent comment.

Returns boolean whether this tracker can handle torrent from string.


encode_value

.encode_value(value: str) -> bytes | str

Encodes a value.


1
2
3
4
.expand_link(
    base_url: str, 
    link: str,  # (1)!
) -> str
  1. absolute or relative link

Expands a given relative link using base URL if required.


extract_domain

.extract_domain(url: str) -> str

Extracts domain from a given URL.


extract_scheme

.extract_scheme(url: str) -> str

Extracts scheme from a given URL.


1
2
3
4
5
.find_links(
    url: str,  # (1)!
    page_soup: BeautifulSoup,  # (2)!
    definite: str = '',  # (3)!
) -> str | None | list[str]
  1. page URL

  2. page soup

  3. regular expression to match link

Returns a list with hyperlinks found in supplied page_soup or a definite link.


get_mirrored_url

.get_mirrored_url(url: str) -> str

Returns a mirrored URL for a given one.


get_response

1
2
3
4
5
6
7
8
9
.get_response(
    url: str,  # (1)!
    form_data: dict | None = None,  # (2)!
    allow_redirects: bool = True,  # (3)!
    referer: str = '',  # (4)!
    cookies: dict | CookieJar | None = None,  # (5)!
    query_string: str = '',  # (6)!
    as_soup: bool = False,  # (7)!
) -> Response | BeautifulSoup | None
  1. URL to get data from

  2. data for POST

  3. whether to follow server redirects

  4. data to put into Referer header

  5. cookies to use

  6. query string (GET parameters) to add to URL

  7. whether to return BeautifulSoup object instead of Requests response

Returns an HTTP resource object from given URL.

If a dictionary is passed in form_data POST HTTP method would be used to pass data to resource (even if that dictionary is empty).


get_torrent

1
2
3
4
.get_torrent(
    url: str,  # (1)!
    last_updated: datetime | None = None,  # (2)!
) -> TorrentData | None
  1. URL to download torrent file from

  2. torrent last updated datetime

This method should be implemented in torrent tracker handler class and must return .torrent file contents.


get_torrent_page

1
2
3
4
.get_torrent_page(
    url: str, 
    drop_cache: bool = False,  # (1)!
) -> BeautifulSoup
  1. Do not use cached version if any.

Get torrent page as soup for further data extraction.


log_debug

.log_debug(msg: str)

Sends the message to debug log.


log_error

.log_error(msg: str)

Sends the message to error log.


log_info

.log_info(msg: str)

Sends the message to info log.


log_warning

.log_warning(msg: str)

Sends the message to warning log.


make_page_soup

.make_page_soup(html: str) -> BeautifulSoup

Returns BeautifulSoup object from a html.


pick_mirror

.pick_mirror(url: str) -> str

Probes mirrors (domains) one by one and chooses one whick is available to use.


register

.register()

Adds this object into TrackerObjectsRegistry.


save_settings

.save_settings()

Saves object settings into torrt configuration file.


spawn_with_settings

.spawn_with_settings(settings: dict) -> WithSettings

Spawns and returns object initialized with given settings.


test_configuration

.test_configuration() -> bool

This should implement a configuration test, e.g. make test login and report success.


GenericPrivateTracker

1
2
3
4
5
6
7
GenericPrivateTracker(
    username: str = '', 
    password: str = '', 
    cookies: dict[str,  str] | None = None, 
    query_string: str = '', 
    **kwargs
)

GenericPublicTracker

Generic torrent tracker handler class implementing most common handling methods for private trackers (that require user registration).


active

.active: bool = True

Tracker support flag. Can be used to skip initialization for currently unavailable trackers.


alias

.alias: str = None

Tracker alias. Usually main tracker domain. See also mirrors attribute.


.auth_cookie_name: str = None

Cookie name to verify that a log in was successful.


auth_qs_param_name

.auth_qs_param_name: str = None

HTTP GET (query string) parameter name to verify that a log in was successful. Probably session ID.


encoding

.encoding: str | None = None

Tracker html page encoding (cp1251 or other).


login_url

.login_url: str = None

URL where with login form. This can include %(domain)s marker in place of a domain name when domain mirrors are used (see mirrors attribute of BaseTracker).


mirrors

.mirrors: ClassVar[list[str]] = []

List of mirror domain names.


raise_on_error_response

.raise_on_error_response: bool = False

Whether to raise an exception on request errors. Primary use is debug and testsuite.


test_urls

.test_urls: ClassVar[list[str]] = []

Page URLs for automatic tests of torrent extraction.


before_download

1
2
3
.before_download(
    url: str,  # (1)!
)
  1. torrent file URL

Used to perform some required actions right before .torrent download. E.g.: to set a sentinel cookie that allows the download.


can_handle

1
2
3
.can_handle(
    string: str,  # (1)!
) -> bool
  1. String, describing torrent. E.g. URL from torrent comment.

Returns boolean whether this tracker can handle torrent from string.


encode_value

.encode_value(value: str) -> bytes | str

Encodes a value.


1
2
3
4
.expand_link(
    base_url: str, 
    link: str,  # (1)!
) -> str
  1. absolute or relative link

Expands a given relative link using base URL if required.


extract_domain

.extract_domain(url: str) -> str

Extracts domain from a given URL.


extract_scheme

.extract_scheme(url: str) -> str

Extracts scheme from a given URL.


1
2
3
4
5
.find_links(
    url: str,  # (1)!
    page_soup: BeautifulSoup,  # (2)!
    definite: str = '',  # (3)!
) -> str | None | list[str]
  1. page URL

  2. page soup

  3. regular expression to match link

Returns a list with hyperlinks found in supplied page_soup or a definite link.


1
2
3
.get_download_link(
    url: str,  # (1)!
) -> str
  1. URL to find a download link at.

Tries to find .torrent file download link on page and return it.


get_encode_form_data

.get_encode_form_data(data: dict) -> dict

Encode dictionary from get_login_form_data using Tracker page encoding.


get_login_form_data

.get_login_form_data(login: str, password: str) -> dict

Should return a dictionary with data to be pushed to authorization form.


get_mirrored_url

.get_mirrored_url(url: str) -> str

Returns a mirrored URL for a given one.


get_query_string

.get_query_string() -> str

Returns an auth query string to be passed to get_response() for auth purposes.

auth string, e.g. sid=1234567890


get_response

1
2
3
4
5
6
7
8
9
.get_response(
    url: str,  # (1)!
    form_data: dict | None = None,  # (2)!
    allow_redirects: bool = True,  # (3)!
    referer: str = '',  # (4)!
    cookies: dict | CookieJar | None = None,  # (5)!
    query_string: str = '',  # (6)!
    as_soup: bool = False,  # (7)!
) -> Response | BeautifulSoup | None
  1. URL to get data from

  2. data for POST

  3. whether to follow server redirects

  4. data to put into Referer header

  5. cookies to use

  6. query string (GET parameters) to add to URL

  7. whether to return BeautifulSoup object instead of Requests response

Returns an HTTP resource object from given URL.

If a dictionary is passed in form_data POST HTTP method would be used to pass data to resource (even if that dictionary is empty).


get_torrent

1
2
3
4
.get_torrent(
    url: str,  # (1)!
    last_updated: datetime | None = None,  # (2)!
) -> TorrentData | None
  1. URL to find and get torrent from

  2. torrent last updated datetime

This is the main method which returns torrent file contents of file located at URL.


get_torrent_page

1
2
3
4
.get_torrent_page(
    url: str, 
    drop_cache: bool = False,  # (1)!
) -> BeautifulSoup
  1. Do not use cached version if any.

Get torrent page as soup for further data extraction.


log_debug

.log_debug(msg: str)

Sends the message to debug log.


log_error

.log_error(msg: str)

Sends the message to error log.


log_info

.log_info(msg: str)

Sends the message to info log.


log_warning

.log_warning(msg: str)

Sends the message to warning log.


login

.login(domain: str) -> bool

Implements tracker login procedure. Returns success bool.


make_page_soup

.make_page_soup(html: str) -> BeautifulSoup

Returns BeautifulSoup object from a html.


pick_mirror

.pick_mirror(url: str) -> str

Probes mirrors (domains) one by one and chooses one whick is available to use.


register

.register()

Adds this object into TrackerObjectsRegistry.


save_settings

.save_settings()

Saves object settings into torrt configuration file.


spawn_with_settings

.spawn_with_settings(settings: dict) -> WithSettings

Spawns and returns object initialized with given settings.


GenericPublicTracker

1
2
3
4
5
GenericPublicTracker(
    cookies: dict[str,  str] | None = None, 
    query_string: str = '', 
    **kwargs
)

GenericTracker

Generic torrent tracker handler class implementing most common handling methods for public trackers.


active

.active: bool = True

Tracker support flag. Can be used to skip initialization for currently unavailable trackers.


alias

.alias: str = None

Tracker alias. Usually main tracker domain. See also mirrors attribute.


encoding

.encoding: str | None = None

Tracker html page encoding (cp1251 or other).


mirrors

.mirrors: ClassVar[list[str]] = []

List of mirror domain names.


raise_on_error_response

.raise_on_error_response: bool = False

Whether to raise an exception on request errors. Primary use is debug and testsuite.


test_urls

.test_urls: ClassVar[list[str]] = []

Page URLs for automatic tests of torrent extraction.


can_handle

1
2
3
.can_handle(
    string: str,  # (1)!
) -> bool
  1. String, describing torrent. E.g. URL from torrent comment.

Returns boolean whether this tracker can handle torrent from string.


encode_value

.encode_value(value: str) -> bytes | str

Encodes a value.


1
2
3
4
.expand_link(
    base_url: str, 
    link: str,  # (1)!
) -> str
  1. absolute or relative link

Expands a given relative link using base URL if required.


extract_domain

.extract_domain(url: str) -> str

Extracts domain from a given URL.


extract_scheme

.extract_scheme(url: str) -> str

Extracts scheme from a given URL.


1
2
3
4
5
.find_links(
    url: str,  # (1)!
    page_soup: BeautifulSoup,  # (2)!
    definite: str = '',  # (3)!
) -> str | None | list[str]
  1. page URL

  2. page soup

  3. regular expression to match link

Returns a list with hyperlinks found in supplied page_soup or a definite link.


1
2
3
.get_download_link(
    url: str,  # (1)!
) -> str
  1. URL to find a download link at.

Tries to find .torrent file download link on page and return it.


get_mirrored_url

.get_mirrored_url(url: str) -> str

Returns a mirrored URL for a given one.


get_response

1
2
3
4
5
6
7
8
9
.get_response(
    url: str,  # (1)!
    form_data: dict | None = None,  # (2)!
    allow_redirects: bool = True,  # (3)!
    referer: str = '',  # (4)!
    cookies: dict | CookieJar | None = None,  # (5)!
    query_string: str = '',  # (6)!
    as_soup: bool = False,  # (7)!
) -> Response | BeautifulSoup | None
  1. URL to get data from

  2. data for POST

  3. whether to follow server redirects

  4. data to put into Referer header

  5. cookies to use

  6. query string (GET parameters) to add to URL

  7. whether to return BeautifulSoup object instead of Requests response

Returns an HTTP resource object from given URL.

If a dictionary is passed in form_data POST HTTP method would be used to pass data to resource (even if that dictionary is empty).


get_torrent

1
2
3
4
.get_torrent(
    url: str,  # (1)!
    last_updated: datetime | None = None,  # (2)!
) -> TorrentData | None
  1. URL to find and get torrent from

  2. torrent last updated datetime

This is the main method which returns torrent file contents of file located at URL.


get_torrent_page

1
2
3
4
.get_torrent_page(
    url: str, 
    drop_cache: bool = False,  # (1)!
) -> BeautifulSoup
  1. Do not use cached version if any.

Get torrent page as soup for further data extraction.


log_debug

.log_debug(msg: str)

Sends the message to debug log.


log_error

.log_error(msg: str)

Sends the message to error log.


log_info

.log_info(msg: str)

Sends the message to info log.


log_warning

.log_warning(msg: str)

Sends the message to warning log.


make_page_soup

.make_page_soup(html: str) -> BeautifulSoup

Returns BeautifulSoup object from a html.


pick_mirror

.pick_mirror(url: str) -> str

Probes mirrors (domains) one by one and chooses one whick is available to use.


register

.register()

Adds this object into TrackerObjectsRegistry.


save_settings

.save_settings()

Saves object settings into torrt configuration file.


spawn_with_settings

.spawn_with_settings(settings: dict) -> WithSettings

Spawns and returns object initialized with given settings.


test_configuration

.test_configuration() -> bool

This should implement a configuration test, e.g. make test login and report success.


GenericTracker

1
2
3
4
5
GenericTracker(
    cookies: dict[str,  str] | None = None, 
    query_string: str = '', 
    **kwargs
)

BaseTracker

Generic torrent tracker handler class implementing most common tracker handling methods.


active

.active: bool = True

Tracker support flag. Can be used to skip initialization for currently unavailable trackers.


alias

.alias: str = None

Tracker alias. Usually main tracker domain. See also mirrors attribute.


encoding

.encoding: str | None = None

Tracker html page encoding (cp1251 or other).


mirrors

.mirrors: ClassVar[list[str]] = []

List of mirror domain names.


raise_on_error_response

.raise_on_error_response: bool = False

Whether to raise an exception on request errors. Primary use is debug and testsuite.


test_urls

.test_urls: ClassVar[list[str]] = []

Page URLs for automatic tests of torrent extraction.


can_handle

1
2
3
.can_handle(
    string: str,  # (1)!
) -> bool
  1. String, describing torrent. E.g. URL from torrent comment.

Returns boolean whether this tracker can handle torrent from string.


download_torrent

1
2
3
4
.download_torrent(
    url: str,  # (1)!
    referer: str = '',  # (2)!
) -> bytes
  1. torrent file URL

  2. Referer header value

Returns .torrent file contents from the given URL.


encode_value

.encode_value(value: str) -> bytes | str

Encodes a value.


1
2
3
4
.expand_link(
    base_url: str, 
    link: str,  # (1)!
) -> str
  1. absolute or relative link

Expands a given relative link using base URL if required.


extract_domain

.extract_domain(url: str) -> str

Extracts domain from a given URL.


extract_scheme

.extract_scheme(url: str) -> str

Extracts scheme from a given URL.


1
2
3
4
5
.find_links(
    url: str,  # (1)!
    page_soup: BeautifulSoup,  # (2)!
    definite: str = '',  # (3)!
) -> str | None | list[str]
  1. page URL

  2. page soup

  3. regular expression to match link

Returns a list with hyperlinks found in supplied page_soup or a definite link.


1
2
3
.get_download_link(
    url: str,  # (1)!
) -> str
  1. URL to find a download link at.

Tries to find .torrent file download link on page and return it.


.get_id_from_link(url: str) -> str

Returns forum thread identifier from full thread URL.


get_mirrored_url

.get_mirrored_url(url: str) -> str

Returns a mirrored URL for a given one.


get_response

1
2
3
4
5
6
7
8
9
.get_response(
    url: str,  # (1)!
    form_data: dict | None = None,  # (2)!
    allow_redirects: bool = True,  # (3)!
    referer: str = '',  # (4)!
    cookies: dict | CookieJar | None = None,  # (5)!
    query_string: str = '',  # (6)!
    as_soup: bool = False,  # (7)!
) -> Response | BeautifulSoup | None
  1. URL to get data from

  2. data for POST

  3. whether to follow server redirects

  4. data to put into Referer header

  5. cookies to use

  6. query string (GET parameters) to add to URL

  7. whether to return BeautifulSoup object instead of Requests response

Returns an HTTP resource object from given URL.

If a dictionary is passed in form_data POST HTTP method would be used to pass data to resource (even if that dictionary is empty).


get_torrent

1
2
3
4
.get_torrent(
    url: str,  # (1)!
    last_updated: datetime | None = None,  # (2)!
) -> TorrentData | None
  1. URL to find and get torrent from

  2. torrent last updated datetime

This is the main method which returns torrent file contents of file located at URL.


get_torrent_page

1
2
3
4
.get_torrent_page(
    url: str, 
    drop_cache: bool = False,  # (1)!
) -> BeautifulSoup
  1. Do not use cached version if any.

Get torrent page as soup for further data extraction.


log_debug

.log_debug(msg: str)

Sends the message to debug log.


log_error

.log_error(msg: str)

Sends the message to error log.


log_info

.log_info(msg: str)

Sends the message to info log.


log_warning

.log_warning(msg: str)

Sends the message to warning log.


make_page_soup

.make_page_soup(html: str) -> BeautifulSoup

Returns BeautifulSoup object from a html.


pick_mirror

.pick_mirror(url: str) -> str

Probes mirrors (domains) one by one and chooses one whick is available to use.


register

.register()

Adds this object into TrackerObjectsRegistry.


save_settings

.save_settings()

Saves object settings into torrt configuration file.


spawn_with_settings

.spawn_with_settings(settings: dict) -> WithSettings

Spawns and returns object initialized with given settings.


test_configuration

.test_configuration() -> bool

This should implement a configuration test, e.g. make test login and report success.


Base Notification class

Notifier classes should be implemented using this.

Classes

BaseNotifier

BaseNotifier(**kwargs)

WithSettings

Base Notifier class. All Notifier classes should inherit from this.


log_debug

.log_debug(msg: str)

Sends the message to debug log.


log_error

.log_error(msg: str)

Sends the message to error log.


log_info

.log_info(msg: str)

Sends the message to info log.


log_warning

.log_warning(msg: str)

Sends the message to warning log.


make_message

.make_message(torrent_data: dict) -> str

Creates message in format suitable for notifier backend


register

.register()

Adds this object into NotificationObjectsRegistry.


save_settings

.save_settings()

Saves object settings into torrt configuration file.


send

.send(updated_data)

Send message to user


send_message

1
2
3
.send_message(
    msg: str,  # (1)!
)
  1. Prepared by notifier backend message

Send prepared message


spawn_with_settings

.spawn_with_settings(settings: dict) -> WithSettings

Spawns and returns object initialized with given settings.


test_configuration

.test_configuration() -> bool

This should implement a configuration test, for example check given credentials.


Base Bots class

Bot classes should be implemented using this.

Classes

BotRegistrationFailed

BotRegistrationFailed()

TorrtBotException

Bot is failed to register (missing dependency or precondition)

This exception must be raised during bot class construction