def handle_speed_overall(message=None): try: up, dn = torrent_client.current_speeds() except ClientNotAvailable as exc: api.error_handler(exc, events.EVENT_SPEED_OVERALL_RESPONSE) else: api.emit(events.EVENT_SPEED_OVERALL_RESPONSE, dict(up=up, dn=dn))
def handle_speed(message): info_hash = message.get('info_hash', None) if info_hash: tor_speed = torrent_client.torrent_speed(info_hash) api.emit(events.EVENT_TORRENT_SPEED_RESPONSE, data=tor_speed) else: api.emit(events.EVENT_TORRENT_SPEED_RESPONSE, status=api.STATUS_FAIL)
def handle_speed_overall(message=None): try: up, dn = client.get().current_speeds() except ClientNotAvailable as exc: api.error_handler(exc, api.EVENT_SPEED_OVERALL_RESPONSE) else: api.emit(api.EVENT_SPEED_OVERALL_RESPONSE, dict(up=up, dn=dn))
def handle_speed(message): info_hash = message.get('info_hash', None) if info_hash: tor_speed = client.get().torrent_speed(info_hash) api.emit(api.EVENT_TORRENT_SPEED_RESPONSE, data=tor_speed) else: api.emit(api.EVENT_TORRENT_SPEED_RESPONSE, status=api.STATUS_FAIL)
def handle_list_all(): """ Return a list of all torrents currently being tracked """ try: torrent_list = torrent_client.torrent_list() except ClientNotAvailable as exc: api.error_handler(exc, events.EVENT_TORRENT_LIST_RESPONSE) else: api.emit(events.EVENT_TORRENT_LIST_RESPONSE, data=torrent_list)
def handle_list_all(): """ Return a list of all torrents currently being tracked """ try: torrent_list = client.get().torrent_list() except Exception as exc: api.error_handler(exc, api.EVENT_TORRENT_LIST_RESPONSE) else: api.emit(api.EVENT_TORRENT_LIST_RESPONSE, data=torrent_list)
def handle_stop(message): info_hash = message.get('info_hash', []) try: torrent_client.torrent_stop(info_hash) except ClientNotAvailable as exc: api.error_handler(exc, events.EVENT_TORRENT_SPEED_RESPONSE) else: api.emit(events.EVENT_TORRENT_SPEED_RESPONSE, dict(info_hash=info_hash)) api.flash("Stopped successfully")
def handle_start(message): info_hash = message.get('info_hash', []) try: client.get().torrent_start(info_hash) except ClientNotAvailable as exc: api.error_handler(exc, api.EVENT_TORRENT_START_RESPONSE) else: api.emit(api.EVENT_TORRENT_START_RESPONSE, dict(info_hash=info_hash)) api.flash("Started successfully")
def handle_start(message): info_hash = message.get('info_hash', []) try: torrent_client.torrent_start(info_hash) except ClientNotAvailable as exc: api.error_handler(exc, events.EVENT_TORRENT_START_RESPONSE) else: api.emit(events.EVENT_TORRENT_START_RESPONSE, dict(info_hash=info_hash)) api.flash("Started successfully")
def update(self, payload=None): """ Update tick handler registered as a plugin """ self.log.debug("Fetching new torrent events") new_event = self.get_events() for k, v in new_event.items(): self.log.debug("[{}] {}".format(k, v)) if new_event: api.emit(events.EVENT_TORRENT_UPDATE, data=new_event) return payload
def handle_announce(message): """ (re)announce the torrent(s) to the tracker :param message: :type message: dict :return: :rtype: """ info_hash = message.get('data', []) status = api.STATUS_OK if client.get().torrent_reannounce(info_hash) else api.STATUS_FAIL api.emit(api.EVENT_TORRENT_ANNOUNCE_RESPONSE, status=status)
def handle_announce(message): """ (re)announce the torrent(s) to the tracker :param message: :type message: dict :return: :rtype: """ info_hash = message.get('data', []) status = api.STATUS_OK if torrent_client.torrent_reannounce( info_hash) else api.STATUS_FAIL api.emit(events.EVENT_TORRENT_ANNOUNCE_RESPONSE, status=status)
def handle_remove(message): info_hash = message.get('info_hash', None) remove_data = message.get('remove_data', False) torrent = client.get().torrent_status(info_hash) if not torrent: status = api.STATUS_INVALID_INFO_HASH else: if client.get().torrent_remove(info_hash, remove_data=remove_data): status = api.STATUS_OK else: status = api.STATUS_FAIL api.emit(api.EVENT_TORRENT_REMOVE_RESPONSE, data=dict(info_hash=info_hash), status=status)
def handle_details(message): try: info_hash = message.get('info_hash', None) data = dict() if info_hash: data = client.get().torrent_status(info_hash) status = api.STATUS_OK else: status = api.STATUS_INCOMPLETE_REQUEST except ClientNotAvailable as exc: api.error_handler(exc, api.EVENT_TORRENT_DETAILS_RESPONSE) else: api.emit(api.EVENT_TORRENT_DETAILS_RESPONSE, data=data, status=status)
def handle_remove(message): info_hash = message.get('info_hash', None) remove_data = message.get('remove_data', False) torrent = torrent_client.torrent_status(info_hash) if not torrent: status = api.STATUS_INVALID_INFO_HASH else: if torrent_client.torrent_remove(info_hash, remove_data=remove_data): status = api.STATUS_OK else: status = api.STATUS_FAIL api.emit(events.EVENT_TORRENT_REMOVE_RESPONSE, data=dict(info_hash=info_hash), status=status)
def handle_details(message): try: info_hash = message.get('info_hash', None) data = dict() if info_hash: data = torrent_client.torrent_status(info_hash) status = api.STATUS_OK else: status = api.STATUS_INCOMPLETE_REQUEST except ClientNotAvailable as exc: api.error_handler(exc, events.EVENT_TORRENT_DETAILS_RESPONSE) else: api.emit(events.EVENT_TORRENT_DETAILS_RESPONSE, data=data, status=status)
def handle_event_update(message): e = torrent_client.get_events() api.emit(events.EVENT_UPDATE_RESPONSE)
def handle_files(message): info_hash = message.get('info_hash', None) tor_files = client.get().torrent_files(info_hash) api.emit(api.EVENT_TORRENT_FILES_RESPONSE, tor_files)
def handle_recheck(message): info_hash = message.get('info_hash', []) resp = torrent_client.torrent_recheck(info_hash) api.emit(events.EVENT_TORRENT_RECHECK_RESPONSE, resp) api.flash("Rechecking..!")
def handle_peers(message): info_hash = message.get('info_hash', None) data = torrent_client.torrent_peers(info_hash) api.emit(events.EVENT_TORRENT_PEERS_RESPONSE, data=dict(peers=data))
def handle_files(message): info_hash = message.get('info_hash', None) tor_files = torrent_client.torrent_files(info_hash) api.emit(events.EVENT_TORRENT_FILES_RESPONSE, tor_files)
def handle_peers(message): info_hash = message.get('info_hash', None) data = client.get().torrent_peers(info_hash) api.emit(api.EVENT_TORRENT_PEERS_RESPONSE, data=data)
def handle_event_update(message): events = client.get().get_events() api.emit(api.EVENT_UPDATE_RESPONSE)
def handle_recheck(message): info_hash = message.get('info_hash', []) resp = client.get().torrent_recheck(info_hash) api.emit(api.EVENT_TORRENT_RECHECK_RESPONSE, resp) api.flash("Rechecking..!")