Skip to main content

Simple torrent client on top of libtorrent rasterbar

Project description

https://img.shields.io/pypi/v/sstc.svg

Stupid, simple torrent client built on top of libtorrent python binding.

Let you add torrents files and magnet and receive libtorrent alerts. That’s all !

  • Free software: WTFPL

Features

  • TODO

Full example

This example show how to add a magnet uri and how to create an alert handler.

Alert handler methods sould be named ‘on_ALERT’, with ALERT the type of alert to handle.

All methods will receive the session as first argument and the alert as the second.

Please note that this example is not exhaustive.

# coding: utf-8
import sys
import os
import time
import logging

from sstc.sstc import TorrentClient

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)


class AlertHandler(object):
    def on_torrent_added_alert(self, session, alert):
        logger.debug("on_torrent_added_alert")

    def on_state_changed_alert(self, session, alert):
        logger.debug("on_state_changed_alert")
        logger.debug(alert.message())

    def on_torrent_resumed_alert(self, session, alert):
        logger.debug("on_torrent_resumed_alert")

    def on_torrent_checked_alert(self, session, alert):
        logger.debug("on_torrent_checked_alert")
        handler = alert.handle
        info = handler.get_torrent_info()
        files = info.files()
        # Do something with torrent infos, like filter files to download
        # torrent was added paused, we resume it
        handler.resume()

    def on_torrent_finished_alert(self, session, alert):
        logger.debug("on_torrent_finished_alert")
        # if you want to remove the torrent immediately :
        #session.remove_torrent(handler)

    def on_piece_finished_alert(self, session, alert):
        logger.debug("on_torrent_finished_alert")
        handler = alert.handle

    def on_block_finished_alert(self, session, alert):
        logger.debug("on_block_finished_alert")
        handler = alert.handle

    def on_file_completed_alert(self, session, alert):
        logger.debug("on_file_completed_alert")
        handler = alert.handle
        info = handler.get_torrent_info()
        f = info.file_at(alert.index)
        logger.debug("%s : completed", f.path)

def main():
    # starts client with 100Mib/s download limit
    # and 10Mib/s uploadlimit
    client = TorrentClient(
        download_rate_limit=100 << 20,
        upload_rate_limit=10 << 20,
    )

    # start client alert dispatcher
    client.start()

    to_download=[
        # support local torrentfile
        "./big_buck_bunny.torrent"
        # also magnet url
        "magnet:?xt=urn:btih:0E876CE2A1A504F849CA72A5E2BC07347B3BC957&dn=big+buck+bunny+720p+psiclone&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce",
        # also from http/https url
        "http://www.frostclick.com/torrents/video/animation/Big_Buck_Bunny_1080p_surround_frostclick.com_frostwire.com.torrent",
    ]

    try:
        for item in to_download:
            client.add(item, is_paused=True, alert_handler=AlertHandler())

        # Blocking loop
        client.loop()

    except (KeyboardInterrupt, Exception) as e:
        client.stop()

if __name__ == "__main__":
    main()

History

0.1.0 (2015-01-11)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sstc-0.1.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distributions

sstc-0.1.0-py2.py3-none-any.whl (7.4 kB view details)

Uploaded Python 2 Python 3

sstc-0.1.0-py2.7.egg (9.3 kB view details)

Uploaded Source

File details

Details for the file sstc-0.1.0.tar.gz.

File metadata

  • Download URL: sstc-0.1.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sstc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0a9421c88e6f5267cca4cd7fab39f46f40aec6ee3c161f1362496d75d5d262d7
MD5 6d16ce3fe4bb4b042b69e42dbd27c362
BLAKE2b-256 ecb4761e238b998fe7de4dc7f3cc625dddf40ac8600e745891cad4947c6f54e0

See more details on using hashes here.

File details

Details for the file sstc-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sstc-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 898ae786fec5ed2e724c628d5bbfa6b2bb405326e69c939f1d539c7b0f321635
MD5 224a7a92a75d0881a7d24246127a7bb4
BLAKE2b-256 a1abb66807f645a7c806491da4a130fa4a709e4a73744a5f2ed8ec148aa5dbc0

See more details on using hashes here.

File details

Details for the file sstc-0.1.0-py2.7.egg.

File metadata

  • Download URL: sstc-0.1.0-py2.7.egg
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sstc-0.1.0-py2.7.egg
Algorithm Hash digest
SHA256 afbb2501c43a85459a0ce109d3505bc8a6f3ab6aa742c2c14a2a702a5831d8ea
MD5 4983fca4eb5fc8cdf1f06ebc31e3ac94
BLAKE2b-256 88303e287d1d37c95700b09c1e9667e136e3c93805014646fafd8b8c826d27da

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page