def downloads(req): conn = get_torrent_connection() if len(conn.torrents()) == 0: return 'empty torrent list' return '\n'.join( ['{0}. {1} ({2})'.format(c, value['name'], value['state']) for c, value in enumerate(conn.torrents(), 1)])
def resume(req): conn = get_torrent_connection() value = parse_id(conn.torrents(), req['text']) if value is None: return create_incorrect_id_message(conn, req) torrent = conn.torrents()[value] conn.resume(torrent['hash']) return torrent['name'] + ' resumed'
def delete(req): conn = get_torrent_connection() value = parse_id(conn.torrents(), req['text']) if value is None: return create_incorrect_id_message(conn, req) torrent = conn.torrents()[value] conn.delete_permanently(torrent['hash']) return torrent['name'] + ' deleted'
def download(req): if len(req['attachments']) == 0: return 'no attachments' conn = get_torrent_connection() for attachment in req['attachments']: if attachment['type'] == 'doc' and attachment['ext'] == 'torrent': response = requests.get(attachment['link'], stream=True) filepath = '../torrents/' + attachment['title'] with open(filepath, "wb") as handle: handle.write(response.content) with open(filepath, "rb") as handle: conn.download_from_file(handle) return 'download start'
def pause_all_downloaded_torrents(req): conn = get_torrent_connection() torrents = conn.torrents(filter='completed') hashes = [torrent['hash'] for torrent in torrents] conn.pause_multiple(hashes) return 'pause all downloaded torrents'
def resume_all(req): get_torrent_connection().resume_all() return 'resume all'
def pause_all(req): get_torrent_connection().pause_all() return 'pause all'
def download_by_magnet_link(req): get_torrent_connection().download_from_link(req['text']) return 'download start'