deluge.core package¶
Submodules¶
deluge.core.alertmanager module¶
The AlertManager handles all the libtorrent alerts.
This should typically only be used by the Core. Plugins should utilize the :mod:EventManager for similar functionality.
- class deluge.core.alertmanager.AlertManager¶
Bases: deluge.component.Component
AlertManager fetches and processes libtorrent alerts
- deregister_handler(handler)¶
De-registers the :param:handler function from all alert types.
Parameters: handler – func, the handler function to deregister
- handle_alerts(wait=False)¶
Pops all libtorrent alerts in the session queue and handles them appropriately.
Parameters: wait (bool) – If True the handler functions will be run straight away and waited to return before processing the next alert.
- register_handler(alert_type, handler)¶
Registers a function that will be called when ‘alert_type’ is pop’d in handle_alerts. The handler function should look like: handler(alert) Where ‘alert’ is the actual alert object from libtorrent.
Parameters: - alert_type – str, this is string representation of the alert name
- handler – func(alert), the function to be called when the alert is raised
- set_alert_queue_size(queue_size)¶
Sets the maximum size of the libtorrent alert queue
- stop()¶
- update()¶
deluge.core.authmanager module¶
- class deluge.core.authmanager.Account(username, password, authlevel)¶
Bases: object
- authlevel¶
- data()¶
- password¶
- username¶
- class deluge.core.authmanager.AuthManager¶
Bases: deluge.component.Component
Authorizes users based on username and password.
Parameters: - username (str) – Username
- password (str) – Password
Returns: The auth level for this user.
Return type: int
Raises: - AuthenticationRequired – If aditional details are required to authenticate.
- BadLoginError – If the username does not exist or password does not match.
- create_account(username, password, authlevel)¶
- get_known_accounts()¶
Returns a list of known deluge usernames.
- has_account(username)¶
- remove_account(username)¶
- shutdown()¶
- start()¶
- stop()¶
- update()¶
- update_account(username, password, authlevel)¶
- write_auth_file()¶
deluge.core.core module¶
- class deluge.core.core.Core(listen_interface=None)¶
Bases: deluge.component.Component
- add_torrent_file(filename, filedump, options)¶
RPC Exported Function (Auth Level: 5)
Adds a torrent file to the session.
- Args:
- filename (str): the filename of the torrent filedump (str): A base64 encoded string of the torrent file contents options (dict): The options to apply to the torrent on add
- Returns:
- str: The torrent_id or None
- add_torrent_magnet(uri, options)¶
RPC Exported Function (Auth Level: 5)
Adds a torrent from a magnet link.
Parameters: - uri (string) – the magnet link
- options (dict) – the options to apply to the torrent on add
Returns: the torrent_id
Return type: string
- add_torrent_url(url, options, headers=None)¶
RPC Exported Function (Auth Level: 5)
Adds a torrent from a url. Deluge will attempt to fetch the torrent from url prior to adding it to the session.
Parameters: - url (string) – the url pointing to the torrent file
- options (dict) – the options to apply to the torrent on add
- headers (dict) – any optional headers to send
Returns: a Deferred which returns the torrent_id as a str or None
- check_new_release()¶
- connect_peer(torrent_id, ip, port)¶
RPC Exported Function (Auth Level: 5)
- create_account(username, password, authlevel)¶
RPC Exported Function (Auth Level: 10)
- create_torrent(path, tracker, piece_length, comment, target, webseeds, private, created_by, trackers, add_to_session)¶
RPC Exported Function (Auth Level: 5)
- create_torrent_status(torrent_id, torrent_keys, plugin_keys, diff=False, update=False, all_keys=False)¶
- disable_plugin(plugin)¶
RPC Exported Function (Auth Level: 5)
- enable_plugin(plugin)¶
RPC Exported Function (Auth Level: 5)
- force_reannounce(torrent_ids)¶
RPC Exported Function (Auth Level: 5)
- force_recheck(torrent_ids)¶
RPC Exported Function (Auth Level: 5)
Forces a data recheck on torrent_ids
- get_auth_levels_mappings()¶
RPC Exported Function (Auth Level: 0)
- get_available_plugins()¶
RPC Exported Function (Auth Level: 5)
Returns a list of plugins available in the core
- get_cache_status()¶
RPC Exported Function (Auth Level: 5)
Returns a dictionary of the session’s cache status.
Returns: the cache status Return type: dict
- get_completion_paths(args)¶
RPC Exported Function (Auth Level: 5)
Returns the available path completions for the input value.
- get_config()¶
RPC Exported Function (Auth Level: 5)
Get all the preferences as a dictionary
- get_config_value(key)¶
RPC Exported Function (Auth Level: 5)
Get the config value for key
- get_config_values(keys)¶
RPC Exported Function (Auth Level: 5)
Get the config values for the entered keys
- get_enabled_plugins()¶
RPC Exported Function (Auth Level: 5)
Returns a list of enabled plugins in the core
- get_filter_tree(show_zero_hits=True, hide_cat=None)¶
RPC Exported Function (Auth Level: 5)
returns {field: [(value,count)] } for use in sidebar(s)
- get_free_space(path=None)¶
RPC Exported Function (Auth Level: 5)
Returns the number of free bytes at path
Parameters: path (string) – the path to check free space at, if None, use the default download location Returns: the number of free bytes at path Return type: int Raises InvalidPathError: if the path is invalid
- get_i2p_proxy()¶
RPC Exported Function (Auth Level: 5)
Returns the active listen port
- get_known_accounts()¶
RPC Exported Function (Auth Level: 10)
- get_libtorrent_version()¶
RPC Exported Function (Auth Level: 5)
Returns the libtorrent version.
Returns: the version Return type: string
- get_listen_port()¶
RPC Exported Function (Auth Level: 5)
Returns the active listen port
- get_new_release()¶
- get_path_size(path)¶
RPC Exported Function (Auth Level: 5)
- Returns the size of the file or folder ‘path’ and -1 if the path is
- unaccessible (non-existent or insufficient privs)
- get_proxy()¶
RPC Exported Function (Auth Level: 5)
Returns the active listen port
- get_session_state()¶
RPC Exported Function (Auth Level: 5)
Returns a list of torrent_ids in the session.
- get_session_status(keys)¶
RPC Exported Function (Auth Level: 5)
Gets the session status values for ‘keys’, these keys are taking from libtorrent’s session status.
See: http://www.rasterbar.com/products/libtorrent/manual.html#status
Parameters: keys (list) – the keys for which we want values Returns: a dictionary of {key: value, ...} Return type: dict
- get_torrent_status(torrent_id, keys, diff=False)¶
RPC Exported Function (Auth Level: 5)
- get_torrents_status(filter_dict, keys, diff=False)¶
RPC Exported Function (Auth Level: 5)
returns all torrents , optionally filtered by filter_dict.
- glob(path)¶
RPC Exported Function (Auth Level: 5)
- move_storage(torrent_ids, dest)¶
RPC Exported Function (Auth Level: 5)
- pause_session()¶
RPC Exported Function (Auth Level: 5)
Pause all torrents in the session
- pause_torrent(torrent_ids)¶
RPC Exported Function (Auth Level: 5)
- queue_bottom(torrent_ids)¶
RPC Exported Function (Auth Level: 5)
- queue_down(torrent_ids)¶
RPC Exported Function (Auth Level: 5)
- queue_top(torrent_ids)¶
RPC Exported Function (Auth Level: 5)
- queue_up(torrent_ids)¶
RPC Exported Function (Auth Level: 5)
- remove_account(username)¶
RPC Exported Function (Auth Level: 10)
- remove_torrent(torrent_id, remove_data)¶
RPC Exported Function (Auth Level: 5)
Removes a torrent from the session.
Parameters: - torrent_id (string) – the torrent_id of the torrent to remove
- remove_data (boolean) – if True, remove the data associated with this torrent
Returns: True if removed successfully
Return type: bool
Raises InvalidTorrentError: if the torrent_id does not exist in the session
- rename_files(torrent_id, filenames)¶
RPC Exported Function (Auth Level: 5)
Rename files in torrent_id. Since this is an asynchronous operation by libtorrent, watch for the TorrentFileRenamedEvent to know when the files have been renamed.
Parameters: - torrent_id (string) – the torrent_id to rename files
- filenames (((index, filename), ...)) – a list of index, filename pairs
Raises InvalidTorrentError: if torrent_id is invalid
- rename_folder(torrent_id, folder, new_folder)¶
RPC Exported Function (Auth Level: 5)
Renames the ‘folder’ to ‘new_folder’ in ‘torrent_id’. Watch for the TorrentFolderRenamedEvent which is emitted when the folder has been renamed successfully.
Parameters: - torrent_id (string) – the torrent to rename folder in
- folder (string) – the folder to rename
- new_folder (string) – the new folder name
Raises InvalidTorrentError: if the torrent_id is invalid
- rescan_plugins()¶
RPC Exported Function (Auth Level: 5)
Rescans the plugin folders for new plugins
- resume_session()¶
RPC Exported Function (Auth Level: 5)
Resume all torrents in the session
- resume_torrent(torrent_ids)¶
RPC Exported Function (Auth Level: 5)
- set_config(config)¶
RPC Exported Function (Auth Level: 5)
Set the config with values from dictionary
- set_owner(torrent_ids, username)¶
RPC Exported Function (Auth Level: 10)
Set’s the torrent owner.
param torrent_id: the torrent_id of the torrent to remove type torrent_id: string param username: the new owner username type username: string raises DelugeError: if the username is not known
- set_torrent_auto_managed(torrent_id, value)¶
RPC Exported Function (Auth Level: 5)
Sets the auto managed flag for queueing purposes
- set_torrent_file_priorities(torrent_id, priorities)¶
RPC Exported Function (Auth Level: 5)
Sets a torrents file priorities
- set_torrent_max_connections(torrent_id, value)¶
RPC Exported Function (Auth Level: 5)
Sets a torrents max number of connections
- set_torrent_max_download_speed(torrent_id, value)¶
RPC Exported Function (Auth Level: 5)
Sets a torrents max download speed
- set_torrent_max_upload_slots(torrent_id, value)¶
RPC Exported Function (Auth Level: 5)
Sets a torrents max number of upload slots
- set_torrent_max_upload_speed(torrent_id, value)¶
RPC Exported Function (Auth Level: 5)
Sets a torrents max upload speed
- set_torrent_move_completed(torrent_id, value)¶
RPC Exported Function (Auth Level: 5)
Sets the torrent to be moved when completed
- set_torrent_move_completed_path(torrent_id, value)¶
RPC Exported Function (Auth Level: 5)
Sets the path for the torrent to be moved when completed
- set_torrent_options(torrent_ids, options)¶
RPC Exported Function (Auth Level: 5)
Sets the torrent options for torrent_ids
- set_torrent_prioritize_first_last(torrent_id, value)¶
RPC Exported Function (Auth Level: 5)
Sets a higher priority to the first and last pieces
- set_torrent_remove_at_ratio(torrent_id, value)¶
RPC Exported Function (Auth Level: 5)
Sets the torrent to be removed at ‘stop_ratio’
- set_torrent_stop_at_ratio(torrent_id, value)¶
RPC Exported Function (Auth Level: 5)
Sets the torrent to stop at ‘stop_ratio’
- set_torrent_stop_ratio(torrent_id, value)¶
RPC Exported Function (Auth Level: 5)
Sets the ratio when to stop a torrent if ‘stop_at_ratio’ is set
- set_torrent_trackers(torrent_id, trackers)¶
RPC Exported Function (Auth Level: 5)
Sets a torrents tracker list. trackers will be [{“url”, “tier”}]
- shutdown()¶
- start()¶
Starts the core
- stop()¶
- test_listen_port()¶
RPC Exported Function (Auth Level: 5)
Checks if the active port is open
Returns: True if the port is open, False if not Return type: bool
- update_account(username, password, authlevel)¶
RPC Exported Function (Auth Level: 10)
- upload_plugin(filename, filedump)¶
RPC Exported Function (Auth Level: 5)
- This method is used to upload new plugins to the daemon. It is used
- when connecting to the daemon remotely and installing a new plugin on the client side. ‘plugin_data’ is a xmlrpc.Binary object of the file data, ie, plugin_file.read()
deluge.core.daemon module¶
The Deluge daemon
- class deluge.core.daemon.Daemon(listen_interface=None, interface=None, port=None, classic=False)¶
Bases: object
The Deluge Daemon class
RPC Exported Function (Auth Level: 1)
Determines if session auth_level is authorized to call RPC.
- Args:
- rpc (str): A RPC, e.g. core.get_torrents_status
- Returns:
- bool: True if authorized to call RPC, otherwise False.
- get_method_list()¶
RPC Exported Function (Auth Level: 5)
Returns a list of the exported methods.
- shutdown(*args, **kwargs)¶
RPC Exported Function (Auth Level: 5)
- deluge.core.daemon.check_running_daemon(pid_file)¶
Check for another running instance of the daemon using the same pid file.
deluge.core.eventmanager module¶
- class deluge.core.eventmanager.EventManager¶
Bases: deluge.component.Component
- deregister_event_handler(event, handler)¶
Deregisters an event handler function.
Parameters: - event – str, the event name
- handler – function, currently registered to handle :param:event
- emit(event)¶
Emits the event to interested clients.
Parameters: event – DelugeEvent
- register_event_handler(event, handler)¶
Registers a function to be called when a :param:event is emitted.
Parameters: - event – str, the event name
- handler – function, to be called when :param:event is emitted
deluge.core.filtermanager module¶
- class deluge.core.filtermanager.FilterManager(core)¶
Bases: deluge.component.Component
FilterManager
- deregister_filter(id)¶
- deregister_tree_field(field)¶
- filter_state_active(torrent_ids)¶
- filter_torrent_ids(filter_dict)¶
returns a list of torrent_id’s matching filter_dict. core filter method
- get_filter_tree(show_zero_hits=True, hide_cat=None)¶
returns {field: [(value,count)] } for use in sidebar.
- register_filter(id, filter_func, filter_value=None)¶
- register_tree_field(field, init_func=<function <lambda> at 0x7fb149a202a8>)¶
- deluge.core.filtermanager.filter_by_name(torrent_ids, search_string)¶
- deluge.core.filtermanager.filter_keywords(torrent_ids, values)¶
- deluge.core.filtermanager.filter_one_keyword(torrent_ids, keyword)¶
search torrent on keyword. searches title,state,tracker-status,tracker,files
- deluge.core.filtermanager.tracker_error_filter(torrent_ids, values)¶
deluge.core.pluginmanager module¶
PluginManager for Core
- class deluge.core.pluginmanager.PluginManager(core)¶
Bases: deluge.pluginmanagerbase.PluginManagerBase, deluge.component.Component
PluginManager handles the loading of plugins and provides plugins with functions to access parts of the core.
- deregister_status_field(field)¶
Deregisters a status field
- disable_plugin(name)¶
- enable_plugin(name)¶
- get_status(torrent_id, fields)¶
Return the value of status fields for the selected torrent_id.
- register_status_field(field, function)¶
Register a new status field. This can be used in the same way the client requests other status information from core.
- shutdown()¶
- start()¶
- stop()¶
- update_plugins()¶
deluge.core.preferencesmanager module¶
deluge.core.rpcserver module¶
RPCServer Module
- class deluge.core.rpcserver.DelugeRPCProtocol¶
Bases: deluge.transfer.DelugeTransferProtocol
- connectionLost(reason)¶
This method is called when the client is disconnected.
Parameters: reason (str) – the reason the client disconnected.
- connectionMade()¶
This method is called when a new client connects.
- dispatch(request_id, method, args, kwargs)¶
This method is run when a RPC Request is made. It will run the local method and will send either a RPC Response or RPC Error back to the client.
Parameters: - request_id (int) – the request_id from the client (sent in the RPC Request)
- method (str) – the local method to call. It must be registered with the RPCServer.
- args (list) – the arguments to pass to method
- kwargs (dict) – the keyword-arguments to pass to method
- message_received(request)¶
This method is called whenever a message is received from a client. The only message that a client sends to the server is a RPC Request message. If the RPC Request message is valid, then the method is called in dispatch().
Parameters: request – the request from the client.
- sendData(data)¶
Sends the data to the client.
Parameters: data (object) – the object that is to be sent to the client. This should be one of the RPC message types.
- valid_session()¶
- class deluge.core.rpcserver.RPCServer(port=58846, interface='', allow_remote=False, listen=True)¶
Bases: deluge.component.Component
This class is used to handle rpc requests from the client. Objects are registered with this class and their methods are exported using the export decorator.
Parameters: - port (int) – the port the RPCServer will listen on
- interface (str) – the interface to listen on, this may override the allow_remote setting
- allow_remote (bool) – set True if the server should allow remote connections
- listen (bool) – if False, will not start listening.. This is only useful in Classic Mode
- deregister_object(obj)¶
Deregisters an objects exported rpc methods.
Parameters: obj – the object that was previously registered
- emit_event(event)¶
Emits the event to interested clients.
Parameters: event (deluge.event.DelugeEvent) – the event to emit
- emit_event_for_session_id(session_id, event)¶
Emits the event to specified session_id.
Parameters: - session_id (int) – the event to emit
- event (deluge.event.DelugeEvent) – the event to emit
- get_method_list()¶
Returns a list of the exported methods.
Returns: the exported methods Return type: list
- get_object_method(name)¶
Returns a registered method.
Parameters: name (str) – the name of the method, usually in the form of ‘object.method’ Returns: method Raises KeyError: if name is not registered
- get_rpc_auth_level(rpc)¶
Returns the auth level requirement for an exported rpc.
Returns: the auth level Return type: int
- get_session_auth_level()¶
Returns the auth level of the user calling the current RPC.
Returns: the auth level Return type: int
- get_session_id()¶
Returns the session id of the current RPC.
Returns: the session id, this will be -1 if no connections have been made Return type: int
- get_session_user()¶
Returns the username calling the current RPC.
Returns: the username of the user calling the current RPC Return type: string
- is_session_valid(session_id)¶
Checks if the session is still valid, eg, if the client is still connected.
Parameters: session_id (int) – the session id Returns: True if the session is valid Return type: bool
- register_object(obj, name=None)¶
Registers an object to export it’s rpc methods. These methods should be exported with the export decorator prior to registering the object.
Parameters: - obj (object) – the object that we want to export
- name (str) – the name to use, if None, it will be the class name of the object
- class deluge.core.rpcserver.ServerContextFactory¶
Bases: object
- getContext()¶
Create an SSL context.
This loads the servers cert/private key SSL files for use with the SSL transport.
- deluge.core.rpcserver.check_ssl_keys()¶
Check for SSL cert/key and create them if necessary
- deluge.core.rpcserver.export(auth_level=5)¶
Decorator function to register an object’s method as an RPC. The object will need to be registered with an RPCServer to be effective.
Parameters: - func (function) – the function to export
- auth_level (int) – the auth level required to call this method
- deluge.core.rpcserver.format_request(call)¶
Format the RPCRequest message for debug printing
Parameters: call (a RPCRequest) – the request Returns: a formatted string for printing Return type: str
- deluge.core.rpcserver.generate_ssl_keys()¶
This method generates a new SSL key/cert.
deluge.core.torrent module¶
Internal Torrent class
- deluge.core.torrent.LT_TORRENT_STATE_MAP¶
dict
Maps the torrent state from libtorrent to Deluge state.
- class deluge.core.torrent.Torrent(handle, options, state=None, filename=None, magnet=None)¶
Bases: object
Torrent holds information about torrents added to the libtorrent session.
Parameters: - handle – The libtorrent torrent handle.
- options (dict) – The torrent options.
- state (TorrentState) – The torrent state.
- filename (str) – The filename of the torrent file.
- magnet (str) – The magnet uri.
- torrent_id¶
str
The torrent_id for this torrent
- handle¶
Holds the libtorrent torrent handle
- magnet¶
str
The magnet uri used to add this torrent (if available).
- status¶
Holds status info so that we don”t need to keep getting it from libtorrent.
- torrent_info¶
store the torrent info.
- has_metadata¶
bool
True if the metadata for the torrent is available, False otherwise.
- status_funcs¶
dict
The function mappings to get torrent status
- prev_status¶
dict
Previous status dicts returned for this torrent. We use this to return dicts that only contain changes from the previous. {session_id: status_dict, ...}
- waiting_on_folder_rename¶
list of dict
A list of Deferreds for file indexes we’re waiting for file_rename alerts on. This is so we can send one folder_renamed signal instead of multiple file_renamed signals. [{index: Deferred, ...}, ...]
- options¶
dict
The torrent options.
- filename¶
str
The filename of the torrent file in case it is required.
- is_finished¶
bool
Keep track if torrent is finished to prevent some weird things on state load.
- statusmsg¶
str
Status message holds error info about the torrent
- state¶
str
The torrent’s state
- trackers¶
list of dict
The torrent’s trackers
- tracker_status¶
str
Status message of currently connected tracker
- tracker_host¶
str
Hostname of the currently connected tracker
- forcing_recheck¶
bool
Keep track if we’re forcing a recheck of the torrent
- forcing_recheck_paused¶
bool
Keep track if we’re forcing a recheck of the torrent so that we can re-pause it after its done if necessary
- cleanup_prev_status()¶
Checks the validity of the keys in the prev_status dict.
If the key is no longer valid, the dict will be deleted.
- connect_peer(peer_ip, peer_port)¶
Manually add a peer to the torrent
Parameters: - peer_ip (str) – Peer IP Address
- peer_port (int) – Peer Port
Returns: True is successful, otherwise False
Return type: bool
- delete_torrentfile()¶
Deletes the .torrent file in the state directory in config
- force_reannounce()¶
Force a tracker reannounce
- force_recheck()¶
Forces a recheck of the torrent’s pieces
- get_eta()¶
Get the ETA for this torrent.
Returns: The ETA in seconds. Return type: int
- get_file_progress()¶
Calculates the file progress as a percentage.
Returns: list of floats: The file progress (0.0 -> 1.0)
- get_files()¶
Get the files this torrent contains.
Returns: list of dict: The files.
- get_magnet_uri()¶
Returns a magnet uri for this torrent
- get_name()¶
The name of the torrent (distinct from the filenames).
Note
Can be manually set in options through name key. If the key is reset to empty string “” it will return the original torrent name.
Returns: the name of the torrent. Return type: str
- get_options()¶
Get the torrent options.
Returns: the torrent options. Return type: dict
- get_orig_files()¶
Get the original filenames of files in this torrent.
Returns: list of dict: The files with original filenames.
- get_peers()¶
Get the peers for this torrent.
A list of peers and various information about them.
Returns: list of dict: The peers. The format for the peer dict:
{ "client": str, "country": str, "down_speed": int, "ip": str, "progress": float, "seed": bool, "up_speed": int }
- get_progress()¶
The progress of this torrent’s current task.
Returns: The progress percentage (0 to 100). Return type: float
- get_queue_position()¶
Get the torrents queue position
Returns: queue position Return type: int
- get_ratio()¶
Get the ratio of upload/download for this torrent.
Returns: The ratio or -1.0 (for infinity). Return type: float
- get_status(keys, diff=False, update=False, all_keys=False)¶
Returns the status of the torrent based on the keys provided
Parameters: - keys (list of str) – the keys to get the status on
- diff (bool) – Will return a diff of the changes since the last call to get_status based on the session_id
- update (bool) – If True the status will be updated from libtorrent if False, the cached values will be returned
Returns: a dictionary of the status keys and their values
Return type: dict
- get_tracker_host()¶
Get the hostname of the currently connected tracker.
If no tracker is connected, it uses the 1st tracker.
Returns: The tracker host Return type: str
- move_storage(dest)¶
Move a torrent’s storage location
Parameters: dest (str) – The destination folder for the torrent data Returns: True if successful, otherwise False Return type: bool
- on_metadata_received()¶
Process the metadata received alert for this torrent
- pause()¶
Pause this torrent.
Returns: True is successful, otherwise False. Return type: bool
- remove_empty_folders(folder)¶
Recursively removes folders but only if they are empty.
This cleans up after libtorrent folder renames.
Parameters: folder (str) – The folder to recursively check
- rename_files(filenames)¶
Renames files in the torrent.
Parameters: filenames (list) – A list of (index, filename) pairs.
- rename_folder(folder, new_folder)¶
Renames a folder within a torrent.
This basically does a file rename on all of the folders children.
Parameters: - folder (str) – The orignal folder name
- new_folder (str) – The new folder name
Returns: twisted.internet.defer.Deferred: A deferred which fires when the rename is complete
- resume()¶
Resumes this torrent.
- save_resume_data(flush_disk_cache=False)¶
Signals libtorrent to build resume data for this torrent.
Parameters: flush_disk_cache (bool) – Avoids potential issue with file timestamps and is only needed when stopping the session. Returns: The response with resume data is returned in a libtorrent save_resume_data_alert. Return type: None
- scrape_tracker()¶
Scrape the tracker
A scrape request queries the tracker for statistics such as total number of incomplete peers, complete peers, number of downloads etc.
- set_auto_managed(auto_managed)¶
Set auto managed mode, i.e. will be started or queued automatically.
Parameters: auto_managed (bool) – Enable auto managed.
- set_download_location(download_location)¶
The location for downloading torrent data.
- set_error_statusmsg(message)¶
Sets the torrent error status message.
Note
This will force a torrent into an error state. It is used for setting those errors that are not covered by libtorrent.
Parameters: message (str) – The error status message.
- set_file_priorities(file_priorities)¶
Sets the file priotities.
Parameters: file_priorities (list of int) – List of file priorities
- set_max_connections(max_connections)¶
Sets maximum number of connections this torrent will open.
Parameters: max_connections (int) – Maximum number of connections
- set_max_download_speed(m_down_speed)¶
Sets maximum download speed for this torrent.
Parameters: m_up_speed (float) – Maximum download speed in KiB/s.
- set_max_upload_slots(max_slots)¶
Sets maximum number of upload slots for this torrent.
Parameters: max_slots (int) – Maximum upload slots
- set_max_upload_speed(m_up_speed)¶
Sets maximum upload speed for this torrent.
Parameters: m_up_speed (float) – Maximum upload speed in KiB/s.
- set_move_completed(move_completed)¶
Set whether to move the torrent when downloading has finished.
Parameters: move_completed (bool) – Move the torrent.
- set_move_completed_path(move_completed_path)¶
Set the path to move torrent to when downloading has finished.
Parameters: move_completed_path (str) – The move path.
- set_options(options)¶
Set the torrent options.
Parameters: options (dict) – Torrent options, see TorrentOptions class for valid keys.
- set_owner(account)¶
Sets the owner of this torrent.
Only a user with admin level auth can change this value.
- set_prioritize_first_last(prioritize)¶
Deprecated due to mismatch between option and func name.
- set_prioritize_first_last_pieces(prioritize)¶
Prioritize the first and last pieces in the torrent.
Parameters: prioritize (bool) – Prioritize the first and last pieces. Returns: tuple of lists: The prioritized pieces and the torrent piece priorities.
- set_priority(priority)¶
Sets the bandwidth priority of this torrent.
Bandwidth is not distributed strictly in order of priority, but the priority is used as a weight. Accepted priority range is [0..255] where 0 is lowest (and default) priority.
priority (int): the torrent priority
Raises: ValueError – If value of priority is not in range [0..255]
- set_remove_at_ratio(remove_at_ratio)¶
Remove the torrent when it has reached the stop_ratio.
Parameters: remove_at_ratio (bool) – Remove the torrent.
- set_save_path(download_location)¶
Deprecated, use set_download_location.
- set_sequential_download(set_sequencial)¶
Sets whether to download the pieces of the torrent in order.
Parameters: set_sequencial (bool) – Enable sequencial downloading.
- set_status_message(message)¶
Sets the torrent status message.
Parameters: message (str) – The status message.
- set_stop_at_ratio(stop_at_ratio)¶
Stop the torrent when it has reached stop_ratio.
Parameters: stop_at_ratio (bool) – Stop the torrent.
- set_stop_ratio(stop_ratio)¶
The seeding ratio to stop (or remove) the torrent at.
Parameters: stop_ratio (float) – The seeding ratio.
- set_super_seeding(super_seeding)¶
Set super seeding/initial seeding.
Parameters: super_seeding (bool) – Enable super seeding.
- set_tracker_status(status)¶
Sets the tracker status.
Parameters: status (str) – The tracker status.
- set_trackers(trackers)¶
Sets the trackers for this torrent.
Parameters: trackers (list of dicts) – A list of trackers.
- update_state()¶
Updates the state, based on libtorrent’s torrent state
- update_status(status)¶
Updates the cached status.
Parameters: status (libtorrent.torrent_status) – a libtorrent torrent status
- write_torrentfile(filename=None, filedump=None)¶
Writes the torrent file to the state dir and optional ‘copy of’ dir.
Parameters: - filename (str, optional) – The filename of the torrent file.
- filedump (str, optional) – bencoded filedump of a torrent file.
- class deluge.core.torrent.TorrentOptions¶
Bases: dict
TorrentOptions create a dict of the torrent options.
- max_connections¶
int
Sets maximum number of connections this torrent will open. This must be at least 2. The default is unlimited (-1).
- max_upload_slots¶
int
Sets the maximum number of peers that are unchoked at the same time on this torrent. This defaults to infinite (-1).
- max_upload_speed¶
float
Will limit the upload bandwidth used by this torrent to the limit you set. The default is unlimited (-1) but will not exceed global limit.
- max_download_speed¶
float
Will limit the download bandwidth used by this torrent to the limit you set.The default is unlimited (-1) but will not exceed global limit.
- prioritize_first_last_pieces¶
bool
Prioritize the first and last pieces in the torrent.
- sequential_download¶
bool
Download the pieces of the torrent in order.
- pre_allocate_storage¶
bool
When adding the torrent should all files be pre-allocated.
- download_location¶
str
The path for the torrent data to be stored while downloading.
- auto_managed¶
bool
Set torrent to auto managed mode, i.e. will be started or queued automatically.
- stop_at_ratio¶
bool
Stop the torrent when it has reached stop_ratio.
- stop_ratio¶
float
The seeding ratio to stop (or remove) the torrent at.
- remove_at_ratio¶
bool
Remove the torrent when it has reached the stop_ratio.
- move_completed¶
bool
Move the torrent when downloading has finished.
- move_completed_path¶
str
The path to move torrent to when downloading has finished.
- add_paused¶
bool
Add the torrrent in a paused state.
bool
Enable the torrent to be seen by other Deluge users.
- super_seeding¶
bool
Enable super seeding/initial seeding.
- priority¶
int
Torrent bandwidth priority with a range [0..255], 0 is lowest and default priority.
- file_priorities¶
list of int
The priority for files in torrent, range is [0..7] however only [0, 1, 5, 7] are normally used and correspond to [Do Not Download, Normal, High, Highest]
- mapped_files¶
dict
A mapping of the renamed filenames in ‘index:filename’ pairs.
- owner¶
str
The user this torrent belongs to.
- name¶
str
The display name of the torrent.
- seed_mode¶
bool
Assume that all files are present for this torrent (Only used when adding a torent).
- deluge.core.torrent.convert_lt_files(files)¶
Indexes and decodes files from libtorrent get_files().
Parameters: files (list) – The libtorrent torrent files. Returns: list of dict: The files. The format for the file dict:
{ "index": int, "path": str, "size": int, "offset": int }
- deluge.core.torrent.sanitize_filepath(filepath, folder=False)¶
Returns a sanitized filepath to pass to libtorrent rename_file().
The filepath will have backslashes substituted along with whitespace padding and duplicate slashes stripped.
Parameters: folder (bool) – A trailing slash is appended to the returned filepath.
deluge.core.torrentmanager module¶
TorrentManager handles Torrent objects
- class deluge.core.torrentmanager.TorrentManager¶
Bases: deluge.component.Component
TorrentManager contains a list of torrents in the current libtorrent session.
This object is also responsible for saving the state of the session for use on restart.
- __getitem__(torrent_id)¶
Return the Torrent with torrent_id.
Parameters: torrent_id (str) – The torrent_id. Returns: A torrent object. Return type: Torrent
- add(torrent_info=None, state=None, options=None, save_state=True, filedump=None, filename=None, magnet=None, resume_data=None)¶
Adds a torrent to the torrent manager.
Parameters: - torrent_info (lt.torrent_info, optional) – A libtorrent torrent_info object.
- state (TorrentState, optional) – The torrent state.
- options (dict, optional) – The options to apply to the torrent on adding.
- save_state (bool, optional) – If True save the session state after adding torrent, defaults to True.
- filedump (str, optional) – bencoded filedump of a torrent file.
- filename (str, optional) – The filename of the torrent file.
- magnet (str, optional) – The magnet uri.
- resume_data (lt.entry, optional) – libtorrent fast resume data.
Returns: The torrent_id of the added torrent.
Returns None if adding was unsuccessful.
Return type: str
- cleanup_torrents_prev_status()¶
Run cleanup_prev_status for each registered torrent
- get_queue_position(torrent_id)¶
Get queue position of torrent
- get_torrent_info_from_file(filepath)¶
Retrieves torrent_info from the file specified.
Parameters: filepath (str) – The filepath to extract torrent info from. Returns: lt.torrent_info : A libtorrent torrent_info dict. Returns None if file or data are not valid
- get_torrent_list()¶
Creates a list of torrent_ids, owned by current user and any marked shared.
Returns: A list of torrent_ids. Return type: list
- handle_torrents_status_callback(status_request)¶
Build the status dictionary with torrent values
- load_resume_data_file()¶
Load the resume data from file for all torrents
Returns: A dict of torrents and their resume_data Return type: dict
- load_state()¶
Load the state of the TorrentManager from the torrents.state file
- on_alert_external_ip(alert)¶
Alert handler for libtorrent external_ip_alert
- on_alert_file_completed(alert)¶
Alert handler for libtorrent file_completed_alert
Emits a TorrentFileCompletedEvent when an individual file completes downloading
- on_alert_file_error(alert)¶
Alert handler for libtorrent file_error_alert
- on_alert_file_renamed(alert)¶
Alert handler for libtorrent file_renamed_alert Emits a TorrentFileCompletedEvent for renamed files
- on_alert_metadata_received(alert)¶
Alert handler for libtorrent metadata_received_alert
- on_alert_performance(alert)¶
Alert handler for libtorrent performance_alert
- on_alert_save_resume_data(alert)¶
Alert handler for libtorrent save_resume_data_alert
- on_alert_save_resume_data_failed(alert)¶
Alert handler for libtorrent save_resume_data_failed_alert
- on_alert_state_changed(alert)¶
Alert handler for libtorrent state_changed_alert Emits a TorrentStateChangedEvent if state has changed
- on_alert_state_update(alert)¶
Alert handler for libtorrent state_update_alert
Result of a session.post_torrent_updates() call and contains the torrent status of all torrents that changed since last time this was posted.
- on_alert_storage_moved(alert)¶
Alert handler for libtorrent storage_moved_alert
- on_alert_storage_moved_failed(alert)¶
Alert handler for libtorrent storage_moved_failed_alert
- on_alert_torrent_checked(alert)¶
Alert handler for libtorrent torrent_checked_alert
- on_alert_torrent_finished(alert)¶
Alert handler for libtorrent torrent_finished_alert
- on_alert_torrent_paused(alert)¶
Alert handler for libtorrent torrent_paused_alert
- on_alert_torrent_resumed(alert)¶
Alert handler for libtorrent torrent_resumed_alert
- on_alert_tracker_announce(alert)¶
Alert handler for libtorrent tracker_announce_alert
- on_alert_tracker_error(alert)¶
Alert handler for libtorrent tracker_error_alert
- on_alert_tracker_reply(alert)¶
Alert handler for libtorrent tracker_reply_alert
- on_alert_tracker_warning(alert)¶
Alert handler for libtorrent tracker_warning_alert
- on_set_max_connections_per_torrent(key, value)¶
Sets the per-torrent connection limit
- on_set_max_download_speed_per_torrent(key, value)¶
Sets the per-torrent download speed limit
- on_set_max_upload_slots_per_torrent(key, value)¶
Sets the per-torrent upload slot limit
- on_set_max_upload_speed_per_torrent(key, value)¶
Sets the per-torrent upload speed limit
- queue_bottom(torrent_id)¶
Queue torrent to bottom
- queue_down(torrent_id)¶
Queue torrent down one position
- queue_top(torrent_id)¶
Queue torrent to top
- queue_up(torrent_id)¶
Queue torrent up one position
- remove(torrent_id, remove_data=False)¶
Remove specified torrent from the session.
Parameters: - torrent_id (str) – The torrent to remove.
- remove_data (bool, optional) – If True, remove the downloaded data, defaults to False.
Returns: True if removed successfully, False if not.
Return type: bool
Raises: InvalidTorrentError – If the torrent_id is not in the session.
- save_resume_data(torrent_ids=None, flush_disk_cache=False)¶
Saves torrents resume data.
Parameters: - torrent_ids (list of str) – A list of torrents to save the resume data for, defaults to None which saves all torrents resume data.
- flush_disk_cache (bool, optional) – If True flushes the disk cache which avoids potential issue with file timestamps, defaults to False. This is only needed when stopping the session.
Returns: t.i.d.DeferredList: A list of twisted Deferred callbacks that will be invoked when save is complete.
- save_resume_data_file()¶
Saves the resume data file with the contents of self.resume_data
- save_state()¶
Save the state of the TorrentManager to the torrents.state file
- separate_keys(keys, torrent_ids)¶
Separates the input keys into torrent class keys and plugins keys
- start()¶
- stop()¶
- torrents_status_update(torrent_ids, keys, diff=False)¶
Returns status dict for the supplied torrent_ids async
Note
If torrent states was updated recently post_torrent_updates is not called and instead cached state is used.
Parameters: - torrent_ids (list of str) – The torrent IDs to get the status of.
- keys (list of str) – The keys to get the status on.
- diff (bool, optional) – If True, will return a diff of the changes since the last call to get_status based on the session_id, defaults to False
Returns: A status dictionary for the requested torrents.
Return type: dict
- update()¶
- class deluge.core.torrentmanager.TorrentManagerState¶
TorrentManagerState holds a list of TorrentState objects
- class deluge.core.torrentmanager.TorrentState(torrent_id=None, filename=None, trackers=None, storage_mode='sparse', paused=False, save_path=None, max_connections=-1, max_upload_slots=-1, max_upload_speed=-1.0, max_download_speed=-1.0, prioritize_first_last=False, sequential_download=False, file_priorities=None, queue=None, auto_managed=True, is_finished=False, error_statusmsg=None, stop_ratio=2.0, stop_at_ratio=False, remove_at_ratio=False, move_completed=False, move_completed_path=None, magnet=None, owner=None, shared=False, super_seeding=False, priority=0, name=None)¶
Create a torrent state