|
1 | 1 | # rtapi |
2 | | -Raw rTorrent XML-RPC in Go, Written for [rtelegram](https://github.com/pyed/rtelegram) |
| 2 | + |
| 3 | +`rtapi` is a small Go client for rTorrent's XML-RPC interface over SCGI. It is |
| 4 | +the library used by [rtelegram](https://github.com/pyed/rtelegram). |
3 | 5 |
|
4 | 6 | ## Requirements |
5 | | -* [`rTorrent`](https://github.com/rakshasa/rtorrent) compiled with `--with-xmlrpc-c`. |
6 | | -* `scgi_port = localhost:5000` in your `.rtorrent.rc` |
7 | 7 |
|
8 | | -## How to get |
9 | | -`go get github.com/pyed/rtapi` |
| 8 | +- Go 1.26 or newer. |
| 9 | +- rTorrent built with XML-RPC support. |
| 10 | +- A local SCGI endpoint such as a protected Unix socket or |
| 11 | + `scgi_port = 127.0.0.1:5000`. |
| 12 | + |
| 13 | +The rTorrent RPC endpoint has no authentication and exposes powerful methods. |
| 14 | +Prefer a permission-protected Unix socket. Never expose SCGI directly to an |
| 15 | +untrusted network; see rTorrent's |
| 16 | +[official XML-RPC security guidance](https://github.com/rakshasa/rtorrent-doc/blob/master/RPC-Setup-XMLRPC.md). |
10 | 17 |
|
11 | | -## How to use |
12 | | -``` go |
| 18 | +## Install |
| 19 | + |
| 20 | +```sh |
| 21 | +go get github.com/pyed/rtapi@latest |
| 22 | +``` |
| 23 | + |
| 24 | +## Example |
| 25 | + |
| 26 | +```go |
13 | 27 | package main |
14 | 28 |
|
15 | 29 | import ( |
16 | 30 | "fmt" |
| 31 | + "log" |
17 | 32 |
|
18 | 33 | "github.com/pyed/rtapi" |
19 | 34 | ) |
20 | 35 |
|
21 | 36 | func main() { |
22 | | - rt, err := rtapi.NewRtorrent("localhost:5000") // Or /path/to/socket for "scgi_local". |
| 37 | + rt, err := rtapi.NewRtorrent("/run/user/1000/rtorrent.sock") |
23 | 38 | if err != nil { |
24 | | - // ... |
| 39 | + log.Fatal(err) |
25 | 40 | } |
26 | 41 |
|
27 | | - // Get torrents |
28 | 42 | torrents, err := rt.Torrents() |
29 | 43 | if err != nil { |
30 | | - // ... |
| 44 | + log.Fatal(err) |
31 | 45 | } |
32 | | - |
33 | | - fmt.Println("Number of torrents:", len(torrents)) |
34 | | - |
35 | | - for _, t := range torrents { |
36 | | - fmt.Println(t.Name) |
| 46 | + for _, torrent := range torrents { |
| 47 | + fmt.Printf("%s: %d/%d bytes\n", torrent.Name, torrent.Completed, torrent.Size) |
37 | 48 | } |
38 | 49 | } |
39 | 50 | ``` |
| 51 | + |
| 52 | +TCP addresses such as `127.0.0.1:5000` are also accepted. Every SCGI request is |
| 53 | +bounded by `rtapi.DefaultTimeout` (30 seconds) unless `Rtorrent.Timeout` is set. |
| 54 | +Responses default to a 16 MiB safety bound; set `Rtorrent.MaxResponseSize` when |
| 55 | +a legitimately large library needs more. Transport errors, malformed responses, |
| 56 | +and XML-RPC faults are returned to the caller; `errors.As` can inspect an |
| 57 | +`*rtapi.XMLRPCFault`. |
| 58 | + |
| 59 | +## Important APIs and compatibility |
| 60 | + |
| 61 | +- Transfer fields (`Size`, `Completed`, and `UpTotal`) contain exact byte counts. |
| 62 | +- `SpeedsWithError` reports failures. `Speeds` remains as a deprecated |
| 63 | + compatibility shim that cannot distinguish failure from zero traffic. |
| 64 | +- `DownloadRaw` loads torrent bytes directly, avoiding credential-bearing |
| 65 | + intermediary URLs. `DownloadWithOptions` remains available for URL loading. |
| 66 | +- `Torrents.Sort` takes an explicit `rtapi.Sorting` value. The unsafe |
| 67 | + process-global `CurrentSorting` variable was removed; call `Sort` on each |
| 68 | + returned value instead. |
| 69 | +- `DeleteMetadata` erases metadata only after rTorrent acknowledges the RPC. |
| 70 | + The older `Delete(false, ...)` form remains as a deprecated compatibility shim. |
| 71 | +- `Delete(true, ...)` returns `ErrUnsafeDataDelete` before any RPC or local |
| 72 | + filesystem access. Data belongs to the rTorrent host; an application that |
| 73 | + offers data deletion must enforce its own explicit local root and containment |
| 74 | + policy. |
| 75 | + |
| 76 | +## Development |
| 77 | + |
| 78 | +```sh |
| 79 | +go test ./... |
| 80 | +go vet ./... |
| 81 | +go build ./... |
| 82 | +``` |
0 commit comments