API
torrt exposes API so it can be used as an ordinary Python module.
Most commonly used functions are located in toolbox.
Functions
add_torrent_from_url
add_torrent_from_url (
url : str , # (1)!
download_to : str = '' , # (2)!
params : dict | None = None , # (3)!
)
torrent URL
path to download files from torrent into (in terms of torrent client filesystem)
optional parameters to pass to RPC
Adds torrent from a given URL to torrt and torrent clients,
bootstrap
Bootstraps torrt environment,
Populates RPC and Trackers registries with objects instantiated with settings from config.
configure_bot (
bot_alias : str , # (1)!
settings_dict : dict , # (2)!
) -> Optional [ BaseBot ]
bot alias
settings dictionary to configure bot with
Configures bot using given settings.
Saves successful configuration.
configure_logging (
log_level : int = logging . INFO , # (1)!
show_logger_names : bool = False , # (2)!
)
logging level, e.g. logging.DEBUG
flag to show logger names in output
Performs basic logging configuration.
configure_notifier (
notifier_alias : str , # (1)!
settings_dict : dict , # (2)!
) -> Optional [ BaseNotifier ]
notifier alias
settings dictionary to configure notifier with
Configures notifier using given settings.
Saves successful configuration.
configure_rpc (
rpc_alias : str , # (1)!
settings_dict : dict , # (2)!
) -> Optional [ BaseRPC ]
RPC alias
settings dictionary to configure RPC with
Configures RPC using given settings.
Saves successful configuration.
configure_tracker (
tracker_alias : str , # (1)!
settings_dict : dict , # (2)!
) -> Optional [ BaseTracker ]
tracker alias
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
Initializes RPC and tracker objects registries with settings from configuration file.
register_torrent
register_torrent (
hash_str : str , # (1)!
torrent_data : TorrentData = None ,
url : str = '' , # (2)!
params : dict | None = None , # (3)!
)
torrent identifying hash
fallback url that will be used in case torrent comment doesn't contain url
optional parameters to pass to RPC
Registers torrent within torrt. Used to register torrents that already exists
in torrent clients.
remove_bot
remove_bot (
alias : str , # (1)!
)
Bot alias to remove.
Removes bot by alias
remove_notifier
remove_notifier (
alias : str , # (1)!
)
Notifier alias to remove.
Removes notifier by alias
remove_torrent
remove_torrent (
hash_str : str , # (1)!
with_data : bool = False , # (2)!
)
torrent identifying hash
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
set_walk_interval (
interval_hours : int , # (1)!
)
hours interval
Sets torrent updates checks interval (in hours).
toggle_rpc
toggle_rpc (
alias : str , # (1)!
enabled : bool = True , # (2)!
)
PRC alias
flag to enable or disable
Enables or disables a given RPC.
tunnel
Try to setup a tunnel for requests.
unregister_torrent
unregister_torrent (
hash_str : str , # (1)!
)
torrent identifying hash
Unregisters torrent from torrt. That doesn't remove torrent
from torrent clients.
update_torrents
update_torrents (
torrents : dict [ str , dict ], # (1)!
remove_outdated : bool = True , # (2)!
) -> dict [ str , dict ]
torrents data indexed with hashes
flag to remove outdated torrents from torrent clients
Performs torrent updates.
Returns hash-indexed dictionary with information on updated torrents
walk
walk (
forced : bool = False , # (1)!
silent : bool = False , # (2)!
remove_outdated : bool = True , # (3)!
)
flag not to count walk interval setting
flag to suppress possible torrt exceptions
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 (
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 ]
Entity type name to be used in massages.
Registry object.
Entity alias.
Settings dictionary to configure object with.
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
encode_value (
value : str ,
encoding : str = '' , # (1)!
) -> str | bytes
Encoding charset.
Encodes a value.
get_iso_from_timestamp
get_iso_from_timestamp (
ts : int , # (1)!
) -> str
timestamp
Get ISO formatted string from timestamp.
get_torrent_from_url
get_torrent_from_url (
url : str | None , # (1)!
last_updated : datetime | None = None , # (2)!
) -> TorrentData | None
URL to download torrent file from
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
Dynamically imports RPC classes and tracker handlers from their directories.
import_from_path
import_from_path (
path : str , # (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
parse_torrent (
torrent : bytes , # (1)!
) -> Torrent | None
Torrent file contents.
Returns Torrent object from torrent contents.
structure_torrent_data
structure_torrent_data (
target_dict : dict , # (1)!
hash_str : str , # (2)!
data : TorrentData , # (3)!
)
dictionary to update inplace
torrent identifying hash
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
Represents global parameter value holder.
Global params can used anywhere in torrt.
HttpClient
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
URL to address
Data to send to URL
Additional headers
Send and receive data as JSON
Do not raise exceptions
Override timeout.
PageData
PageData ( title : str , cover : str , date_updated : datetime )
Represents data extracted from torrent page.
TorrentData
TorrentData (
hash : str = '' ,
name : str = '' ,
url : str = '' ,
url_file : str = '' ,
raw : bytes = b '' ,
page : PageData = None ,
parsed : Torrent = None
)
Represents information about torrent.
TorrtConfig
Gives methods to work with torrt configuration file.
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
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
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
Sends the message to debug log.
log_error
Sends the message to error log.
log_info
Sends the message to info log.
log_warning
Sends the message to warning log.
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
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
Sends the message to debug log.
log_error
Sends the message to error log.
log_info
Sends the message to info log.
log_warning
Sends the message to warning log.
method_add_torrent
. method_add_torrent (
torrent : TorrentData , # (1)!
download_to : str = '' , # (2)!
params : dict | None = None , # (3)!
) -> Any
torrent info
path to download files from torrent into (in terms of torrent client filesystem)
optional information attached to torrent that should be preserved
Adds torrent to torrent client using RPC.
method_get_torrents
. method_get_torrents (
hashes : list [ str ] | None = None , # (1)!
) -> list [ dict ]
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
. method_remove_torrent (
hash_str : str , # (1)!
with_data : bool = False , # (2)!
) -> Any
torrent identifying hash
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
Adds this object into RPCObjectsRegistry.
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
BaseTracker (
cookies : dict [ str , str ] | None = None ,
query_string : str = '' ,
** kwargs
)
WithSettings
Base torrent tracker handler class offering helper methods for its ancestors.
active
Tracker support flag. Can be used to skip initialization for currently unavailable trackers.
alias
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
. can_handle (
string : str , # (1)!
) -> bool
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.
expand_link
. expand_link (
base_url : str ,
link : str , # (1)!
) -> str
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 ( url : str ) -> str
Extracts scheme from a given URL.
find_links
. find_links (
url : str , # (1)!
page_soup : BeautifulSoup , # (2)!
definite : str = '' , # (3)!
) -> str | None | list [ str ]
page URL
page soup
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
. 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
URL to get data from
data for POST
whether to follow server redirects
data to put into Referer header
cookies to use
query string (GET parameters) to add to URL
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
. get_torrent (
url : str , # (1)!
last_updated : datetime | None = None , # (2)!
) -> TorrentData | None
URL to download torrent file from
torrent last updated datetime
This method should be implemented in torrent tracker handler class
and must return .torrent file contents.
get_torrent_page
. get_torrent_page (
url : str ,
drop_cache : bool = False , # (1)!
) -> BeautifulSoup
Do not use cached version if any.
Get torrent page as soup for further data extraction.
log_debug
Sends the message to debug log.
log_error
Sends the message to error log.
log_info
Sends the message to info log.
log_warning
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
Adds this object into TrackerObjectsRegistry.
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
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
Tracker support flag. Can be used to skip initialization for currently unavailable trackers.
alias
Tracker alias. Usually main tracker domain. See also mirrors attribute.
auth_cookie_name
. 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
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
. before_download (
url : str , # (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
. can_handle (
string : str , # (1)!
) -> bool
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.
expand_link
. expand_link (
base_url : str ,
link : str , # (1)!
) -> str
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 ( url : str ) -> str
Extracts scheme from a given URL.
find_links
. find_links (
url : str , # (1)!
page_soup : BeautifulSoup , # (2)!
definite : str = '' , # (3)!
) -> str | None | list [ str ]
page URL
page soup
regular expression to match link
Returns a list with hyperlinks found in supplied page_soup
or a definite link.
get_download_link
. get_download_link (
url : str , # (1)!
) -> str
URL to find a download link at.
Tries to find .torrent file download link on page and return it.
. get_encode_form_data ( data : dict ) -> dict
Encode dictionary from get_login_form_data using Tracker page encoding.
. 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
. 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
URL to get data from
data for POST
whether to follow server redirects
data to put into Referer header
cookies to use
query string (GET parameters) to add to URL
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
. get_torrent (
url : str , # (1)!
last_updated : datetime | None = None , # (2)!
) -> TorrentData | None
URL to find and get torrent from
torrent last updated datetime
This is the main method which returns torrent file contents
of file located at URL.
get_torrent_page
. get_torrent_page (
url : str ,
drop_cache : bool = False , # (1)!
) -> BeautifulSoup
Do not use cached version if any.
Get torrent page as soup for further data extraction.
log_debug
Sends the message to debug log.
log_error
Sends the message to error log.
log_info
Sends the message to info log.
log_warning
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
Adds this object into TrackerObjectsRegistry.
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
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
Tracker support flag. Can be used to skip initialization for currently unavailable trackers.
alias
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
. can_handle (
string : str , # (1)!
) -> bool
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.
expand_link
. expand_link (
base_url : str ,
link : str , # (1)!
) -> str
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 ( url : str ) -> str
Extracts scheme from a given URL.
find_links
. find_links (
url : str , # (1)!
page_soup : BeautifulSoup , # (2)!
definite : str = '' , # (3)!
) -> str | None | list [ str ]
page URL
page soup
regular expression to match link
Returns a list with hyperlinks found in supplied page_soup
or a definite link.
get_download_link
. get_download_link (
url : str , # (1)!
) -> str
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
. 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
URL to get data from
data for POST
whether to follow server redirects
data to put into Referer header
cookies to use
query string (GET parameters) to add to URL
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
. get_torrent (
url : str , # (1)!
last_updated : datetime | None = None , # (2)!
) -> TorrentData | None
URL to find and get torrent from
torrent last updated datetime
This is the main method which returns torrent file contents
of file located at URL.
get_torrent_page
. get_torrent_page (
url : str ,
drop_cache : bool = False , # (1)!
) -> BeautifulSoup
Do not use cached version if any.
Get torrent page as soup for further data extraction.
log_debug
Sends the message to debug log.
log_error
Sends the message to error log.
log_info
Sends the message to info log.
log_warning
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
Adds this object into TrackerObjectsRegistry.
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
GenericTracker (
cookies : dict [ str , str ] | None = None ,
query_string : str = '' ,
** kwargs
)
BaseTracker
Generic torrent tracker handler class implementing most common tracker handling methods.
active
Tracker support flag. Can be used to skip initialization for currently unavailable trackers.
alias
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
. can_handle (
string : str , # (1)!
) -> bool
String, describing torrent. E.g. URL from torrent comment.
Returns boolean whether this tracker can handle torrent from string.
download_torrent
. download_torrent (
url : str , # (1)!
referer : str = '' , # (2)!
) -> bytes
torrent file URL
Referer header value
Returns .torrent file contents from the given URL.
encode_value
. encode_value ( value : str ) -> bytes | str
Encodes a value.
expand_link
. expand_link (
base_url : str ,
link : str , # (1)!
) -> str
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 ( url : str ) -> str
Extracts scheme from a given URL.
find_links
. find_links (
url : str , # (1)!
page_soup : BeautifulSoup , # (2)!
definite : str = '' , # (3)!
) -> str | None | list [ str ]
page URL
page soup
regular expression to match link
Returns a list with hyperlinks found in supplied page_soup
or a definite link.
get_download_link
. get_download_link (
url : str , # (1)!
) -> str
URL to find a download link at.
Tries to find .torrent file download link on page and return it.
get_id_from_link
. 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
. 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
URL to get data from
data for POST
whether to follow server redirects
data to put into Referer header
cookies to use
query string (GET parameters) to add to URL
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
. get_torrent (
url : str , # (1)!
last_updated : datetime | None = None , # (2)!
) -> TorrentData | None
URL to find and get torrent from
torrent last updated datetime
This is the main method which returns torrent file contents
of file located at URL.
get_torrent_page
. get_torrent_page (
url : str ,
drop_cache : bool = False , # (1)!
) -> BeautifulSoup
Do not use cached version if any.
Get torrent page as soup for further data extraction.
log_debug
Sends the message to debug log.
log_error
Sends the message to error log.
log_info
Sends the message to info log.
log_warning
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
Adds this object into TrackerObjectsRegistry.
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
WithSettings
Base Notifier class. All Notifier classes should inherit from this.
log_debug
Sends the message to debug log.
log_error
Sends the message to error log.
log_info
Sends the message to info log.
log_warning
Sends the message to warning log.
make_message
. make_message ( torrent_data : dict ) -> str
Creates message in format suitable for notifier backend
register
Adds this object into NotificationObjectsRegistry.
save_settings
Saves object settings into torrt configuration file.
send_message
. send_message (
msg : str , # (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
TorrtBotException
Bot is failed to register (missing dependency or precondition)
This exception must be raised during bot class construction