Skip to main content

Lib Torrent Client

This is a library to interface with a variety of torrent clients, abstracting away the need to understand a specific client api.

https://github.com/JohnDoee/libtc/actions/workflows/main.yml/badge.svg?branch=master

Requirements

  • Python 3.6 or higher

Installation

pip install libtc

Features

Clients:

  • rtorrent

  • Deluge

  • Transmission

  • qBittorrent

  • LilTorrent (local-to-remote interface for other clients)

Methods:

  • List torrents

  • Stop/start torrents

  • Add/remove torrents

  • Retrieve the actual .torrent file

Other:

  • Verify local content exist

  • Discover client config to autoconfigure clients

  • Move torrents between clients

Commandline interface

The commandline interface allows for basic operations on torrents:

# See available commands
libtc --help

# See help for individual command
libtc "transmission+http://127.0.0.1:9091/transmission/rpc?session_path=%7E/.config/transmission" list --help

# Execute a command
libtc "transmission+http://127.0.0.1:9091/transmission/rpc?session_path=%7E/.config/transmission" list

# Move torrent with infohash da39a3ee5e6b4b0d3255bfef95601890afd80709 from transmission to deluge
libtc "transmission+http://127.0.0.1:9091/transmission/rpc?session_path=%7E/.config/transmission" move \
      "da39a3ee5e6b4b0d3255bfef95601890afd80709" \
      "deluge://localclient:da39a3ee5e6b4b0d3255bfef95601890afd80709@127.0.0.1:58846?session_path=%7E/.config/deluge"

Session path & fetching torrents

This library can find and use the actual torrent files but this is generally not possible to the APIs. Therefore it must know where the torrents are stored locally.

These folders must contain the actual .torrent files.

A list of relative torrent paths can be found here:

Deluge

<session_path>/state/

qBittorrent

<session_path>/data/BT_backup/

rtorrent

<session_path>/

Transmission

<session_path>/torrents/

An example could be transmission configured with session_path=/tmp/transmission/ then the actual torrent files would be store in /tmp/transmission/torrents/.

These are subject to change depending on how it really works out with different client versions.

URL Syntax

The query part of urls are generally optional

Deluge

Syntax: deluge://<username>:<password>@<hostname_or_ip>:<port>?session_path=<path_to_session>

Example: deluge://localclient:da39a3ee5e6b4b0d3255bfef95601890afd80709@127.0.0.1:58846?session_path=%7E/.config/deluge

LilTorrent

Multiple path mappings can be added, they are joined by a ; - apikey is mandatory.

Syntax: liltorrent+<protocol>://<hostname_or_ip>:<port>?apikey=<apikey>&path_mapping=<rewritten_from_path>:<rewritten_to_path>;<another_rewritten_from_path>:<another_rewritten_to_path>

Example: liltorrent+http://localhost:10977?apikey=secret&path_mapping=/a/%3A/b/%3B/s/t/%3A/f/

This example changes /a/horse.gif to /b/horse.gif

qBittorrent

Syntax: qbittorrent+<protocol>://<username>:<password>@<hostname_or_ip>:<port>?session_path=<path_to_session>

Example: qbittorrent+http://admin:adminadmin@localhost:8080?session_path=%7E/.config/qBittorrent

rtorrent

Syntax: rtorrent+<protocol>://<path_or_hostname>:<optional_port>?session_path=<path_to_session>&torrent_temp_path=<path_to_accessible_tmp>

Example: rtorrent+scgi:///path/to/scgi.socket?session_path=%7E/.rtorrent/&torrent_temp_path=%7E/.rtorrent/tmp-libtc

Example: rtorrent+scgi://127.0.0.1:5000?session_path=%7E/.rtorrent/&torrent_temp_path=%7E/.rtorrent/tmp-libtc

Example: rtorrent+http://127.0.0.1:8000/SCGI?session_path=%7E/.rtorrent/&torrent_temp_path=%7E/.rtorrent/tmp-libtc

Transmission

Syntax: transmission+<protocol>://<hostname>:<port>?session_path=<path_to_session>

Example: transmission+http://127.0.0.1:9091/transmission/rpc?session_path=%7E/.config/transmission

LilTorrent usage

This layer can work as an abstraction layer between local clients in different environments, e.g. in a docker container.

pip install libtc[liltorrent]

LILTORRENT_APIKEY=secretapikey LILTORRENT_CLIENT=rtorrent:///path/to/scgi.socket liltorrent
  • LILTORRENT_APIKEY is the apikey that the server is accessible through

  • LILTORRENT_CLIENT is a client URL

Config file syntax

These examples use .toml format, while the actual parsing logic is agnostic to on-disk format, it’s the recommended one.

The display_name is the name shown when client is used. If it is not set, then the config file key is used, e.g. [clients.another-transmission] is called another-transmission if no display_name is set.

The URL config as described above can also be used and is seen in the last example as deluge-url.

Each key must be unique, e.g. you cannot have two clients with the same key, e.g. two [clients.the-transmission]

[clients]

[clients.deluge]
display_name = "A Deluge"
client_type = "deluge"
host = "127.0.0.1"
port = 58846
username = "localclient"
password = "secretpassword"
session_path = "~/.config/deluge/"

[clients.the-transmission]
display_name = "Some transmission"
client_type = "transmission"
url = "http://127.0.0.1:9091/transmission/rpc"
session_path = "~/.config/transmission-daemon/"

[clients.another-transmission]
display_name = "Horse transmission"
client_type = "transmission"
url = "http://127.0.0.1:9092/transmission/rpc"
session_path = "~/.config/transmission-daemon2/"

[clients.rtorrent]
display_name = "rtorrent"
client_type = "rtorrent"
url = "scgi://127.0.0.1:5000"
session_path = "~/.rtorrent/"

[clients.another-qbittorrent]
display_name = "qBittorrent 1"
client_type = "qbittorrent"
url = "http://localhost:8080/"
username = "admin"
password = "adminadmin"
session_path = "~/.config/qbittorrent/"

# This is an example of using the url syntax
[clients.deluge-url]
display_name = "Deluge url"
client_url = "deluge://localclient:da39a3ee5e6b4b0d3255bfef95601890afd80709@127.0.0.1:58846?session_path=%7E/.config/deluge"

[clients.rtorrent-with-label]
display_name = "rtorrent"
client_type = "rtorrent"
url = "scgi://127.0.0.1:5000"
session_path = "~/.rtorrent/"
label = "alabel"

[clients.deluge-with-label]
display_name = "A Deluge"
client_type = "deluge"
host = "127.0.0.1"
port = 58846
username = "localclient"
password = "secretpassword"
session_path = "~/.config/deluge/"
label = "alabel"

License

MIT

Metadata

Release files for libtc 1.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for libtc 1.3.4
File Size Uploaded
libtc-1.3.4.tar.gz 31.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for libtc 1.3.4
File Interpreter ABI Platform
libtc-1.3.4-py3-none-any.whl Python 3 none any Details

Total release size: 72.2 kB

Release files / libtc-1.3.4.tar.gz

Download URL libtc-1.3.4.tar.gz
Size 31.4 kB
Tags Source
SHA-256 checksum
How to use checksums
965a7c41096a69d003122955e2663ebc9e5cc8db9080a49d6f1d41b1b79f9927
BLAKE2b-256 checksum
How to use checksums
6f82e465d092a7b3e2f02d1a0893f5875871579c974bfd7c440331764589bc6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Release files / libtc-1.3.4-py3-none-any.whl

Download URL libtc-1.3.4-py3-none-any.whl
Size 40.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40c258e349c0ce125fedc29905f770d20e1fc66edc9f501c937af46c523a2dc1
BLAKE2b-256 checksum
How to use checksums
9ea44f0dd7c7eea85542199e2727f72dbd7d153e0866f62d7084752c439abf2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Release history Release notifications | RSS feed

This release

1.3.4 This release

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page