Exemple #1
0
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)])
Exemple #2
0
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'
Exemple #3
0
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'
Exemple #4
0
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'
Exemple #5
0
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'
Exemple #6
0
def resume_all(req):
    get_torrent_connection().resume_all()
    return 'resume all'
Exemple #7
0
def pause_all(req):
    get_torrent_connection().pause_all()
    return 'pause all'
Exemple #8
0
def download_by_magnet_link(req):
    get_torrent_connection().download_from_link(req['text'])
    return 'download start'