upsies.trackers.base.tracker
Abstract base class for all tracker-specific stuff
Classes
- class upsies.trackers.base.tracker.TrackerBase(options=None)[source]
Bases:
ABCBase class for tracker-specific operations, e.g. uploading
- Parameters:
options (
dict-like) – User configuration options for this tracker, e.g. authentication details, announce URL, etc
- abstract property TrackerJobs
Subclass of
TrackerJobsBase
- abstract property TrackerConfig
Subclass of
TrackerConfigBase
- cli_arguments = {}
CLI argument definitions (see
CommandBase.cli_arguments)
- rules = None
Sequence of
TrackerRuleBasesubclasses or NoneFor convenience, this may also be a
ModuleTypethat providesTrackerRuleBasesubclasses.
- abstract property name
Lower-case tracker name abbreviation for internal use
- abstract property label
User-facing tracker name abbreviation
- abstract property torrent_source_field
Torrents for this tracker get a
sourcefield with this valueThis is usually the same as
label.
- setup_howto_template = 'Nobody has written a setup howto yet.'
Step-by-step guide that explains how to make your first upload
Note
This MUST be a class attribute and not a property.
The following placeholders can be used in f-string format:
howto-Howtoinstancetracker-TrackerBasesubclassexecutable- Name of the executable that runs the application
- classmethod generate_setup_howto()[source]
Fill in any placeholders in
setup_howto_template
- property options
Configuration options provided by the user
This is the
dict-like object from the initialization argument of the same name.
- attach_task(coro, callback=None)[source]
Run awaitable coro in background task
- Parameters:
coro – Any awaitable
callback –
Callable that is called with the task after coro returned
Warning
callback must handle any exception raised by the task or it will be ignored.
- async await_tasks()[source]
Wait for all awaitables passed to
attach_task()
- async login(**credentials)[source]
End user session by calling
_login, which must be implemented by the subclassSet
is_logged_into True or False. Emit logged_insignalon success.Any keyword arguments are passed on to
_login(), e.g. to provide a 2FA one-time password._login()should raiseTfaRequiredto get called again with a tfa_otp keyword argument. The tfa_otp value will be from a user prompt that asks for a 2FA one-time password. (Seelogin_job().)- Raises:
errors.RequestError – on failure
errors.TfaRequired – if login failed due to missing second factor
- async still_logged_in()[source]
Return whether we have a valid user session stored in
cookies_filepathIf no
cookies_filepathis specified, return None.Otherwise, catch
RequestErrorfromconfirm_logged_in()to check if we are logged in.If we are not logged in, call
delete_cookies_filepath(), emit thelogin_failedsignaland return False.If we are logged in, emit the
logged_insignaland return True.
- async logout(*, force=False)[source]
End user session by calling
_logout, which must be implemented by the subclassSet
is_logged_into False and emit logged_outsignal, even if the logout request fails for some reason.If a
cookies_filepathis provided, do nothing unless force is True.- Raises:
errors.RequestError – on failure
- abstractmethod async confirm_logged_in()[source]
Check if we are logged in by doing a website request
This method is called by
login()to make sure_login()succeeded. It is also called bystill_logged_in(), which is used check if a stored user session is still working or if a new session must be started (e.g. because the cookie expired).- Raises:
errors.RequestError – if we are not logged in
- property is_logged_in
Whether a user session is active
- property cookies_filepath
User-defined file path that stores login session cookie(s) or None if no such file is specified
Subclasses must include this in requests made to the tracker website if the tracker implementation uses traditional user sesssions via the website for submissions.
If the tracker implementation uses an API, cookies should not be used in requests and this property can be ignored.
- delete_cookies_filepath()[source]
Delete
cookies_filepathif it is provided and exists
- abstractmethod async get_announce_url()[source]
Get announce URL from
optionsor tracker websiteWarning
You should expect that
login()was called first when implementing this method and raiseRuntimeErrorifis_logged_inis False.- Raises:
errors.RequestError – on any kind of failure
- calculate_piece_size = None
staticmethodthat takes a torrent’s content size and returns the corresponding piece sizeIf this is None, the default implementation is used.
- calculate_piece_size_min_max = None
staticmethodthat takes a torrent’s content size and returns the corresponding allowed minimum and maximum piece sizesIf this is None, the default implementation is used.
- abstractmethod async upload(tracker_jobs)[source]
Upload torrent and other metadata from jobs
- Parameters:
tracker_jobs (TrackerJobsBase) –
TrackerJobsinstance
- property signal
Signalinstance with the following signals:warningEmitted when
warn()is called. Registered callbacks get the provided warning argument.errorEmitted when
error()is called. Registered callbacks get the provided error argument.exceptionEmitted when
exception()is called. Registered callbacks get the provided exception argument.logging_inEmitted by
login()when login is attempted. Registered callbacks get no arguments.login_failedEmitted by
login()when login failed. Registered callbacks get aRequestErrorexception.logged_inEmitted by
login()when login succeeded. Registered callbacks get no arguments.logging_outEmitted by
logout()when logout is attempted. Registered callbacks get no arguments.logout_failedEmitted by
logout()when logout failed. Registered callbacks get aRequestErrorexception.logged_outEmitted by
logout()when logout succeeded. Registered callbacks get no arguments.
- warn(warning)[source]
Emit
warningsignal (seesignal)Emit a warning for any non-critical issue that the user can choose to ignore or fix.