Beispiel #1
0
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))
Beispiel #2
0
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)
Beispiel #3
0
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))
Beispiel #4
0
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)
Beispiel #5
0
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)
Beispiel #6
0
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)
Beispiel #7
0
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)
Beispiel #8
0
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")
Beispiel #9
0
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")
Beispiel #10
0
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")
Beispiel #11
0
 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
Beispiel #12
0
 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
Beispiel #13
0
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)
Beispiel #14
0
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)
Beispiel #15
0
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)
Beispiel #16
0
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)
Beispiel #17
0
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)
Beispiel #18
0
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)
Beispiel #19
0
def handle_event_update(message):
    e = torrent_client.get_events()
    api.emit(events.EVENT_UPDATE_RESPONSE)
Beispiel #20
0
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)
Beispiel #21
0
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..!")
Beispiel #22
0
def handle_event_update(message):
    e = torrent_client.get_events()
    api.emit(events.EVENT_UPDATE_RESPONSE)
Beispiel #23
0
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))
Beispiel #24
0
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)
Beispiel #25
0
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)
Beispiel #26
0
def handle_event_update(message):
    events = client.get().get_events()
    api.emit(api.EVENT_UPDATE_RESPONSE)
Beispiel #27
0
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))
Beispiel #28
0
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..!")