transmission-ts
v0.0.3
Published
An opinionated Transmission RPC client for Node.js written in TypeScript
Downloads
4
Maintainers
Readme
Transmission TS
An opinionated Transmission RPC client for Node.js written in TypeScript 🧲
Installation
npm install transmission-ts
Usage
import { TransmissionClient } from "transmission-ts";
const client = new TransmissionClient();
You can also pass in a config object to the constructor to configure the connection to the Transmission RPC server, all of the following are optional:
host
: The host of the Transmission RPC server. Defaults tolocalhost
.port
: The port of the Transmission RPC server. Defaults to9091
.protocol
: The protocol of the Transmission RPC server. Defaults tohttp
.username
: The username to use for authentication. Defaults totransmission
.password
: The password to use for authentication. Defaults totransmission
.path
: The path to the Transmission RPC server. Defaults to/transmission/rpc
.
Add a torrent
You can add a torrent by passing in a magnet link
const torrent = await client.addMagnet({
magnet: "magnet:?xt=urn:btih:..."
});
While adding a torrent you can also pass in any of the following options:
downloadDir
: The directory where the downloaded contents will be saved in. Defaults to the default download directory configured in Transmission.paused
: Whether or not the torrent should be added in a paused state. Defaults tofalse
.
List torrents
You can get all torrents or only some of them by specifying a list of ids:
// List all torrents currently in Transmission
const torrents = await client.getTorrents();
// List torrents with ids 1 and 2
const torrents = await client.getTorrents({
ids: [1, 2],
});
When getting torrents you can also select which fields you want to receive by passing in a list of fields:
const torrents = await client.getTorrents({
fields: ["id", "name", "status"],
});
A full list of fields can be found in the API reference. If you don't pass in any fields, all fields will be returned.
Remove torrents
You can remove torrents by passing in one or more ids:
// Remove torrent with id 1
await client.removeTorrents({
ids: 1,
});
// Remove torrents with ids 1 and 2
await client.removeTorrents({
ids: [1, 2],
});
// Remove torrent and delete downloaded data
await client.removeTorrents({
ids: 1,
deleteLocalData: true,
});
When removing torrents you can also specify whether or not you want to delete the downloaded data by setting the deleteLocalData
option to true
. Defaults to false
.
When deleting torrents you can also specify whether or not you want to delete the downloaded data by setting the deleteLocalData
option to true
. Defaults to false
.
Change torrent status
You can start one or more torrents by passing in one or more ids:
// Start torrent with id 1
await client.startTorrents({
ids: 1,
});
// Start torrents with ids 1 and 2
await client.startTorrents({
ids: [1, 2],
});
Optionally, you can also pass in a now
option to start the torrent immediately:
await client.startTorrents({
ids: 1,
now: true,
});
You can also stop one or more torrents by passing in one or more ids:
// Stop torrent with id 1
await client.stopTorrents({
ids: 1,
});
// Stop torrents with ids 1 and 2
await client.stopTorrents({
ids: [1, 2],
});
Other methods
The following methods are also available:
getRecentlyActiveTorrents()
- Gets the recently active torrents, this is useful to get a list of torrents that are currently present or have recently been deleted.ping()
- Pings the Transmission RPC server, this is useful to check if the remote server is reachable.getSession()
- Gets the current Transmission session information, this includes the Transmission daemon configuration.
For a full list of methods and their options, see the API reference.
License
This project is licensed under the MIT-0 License - see the LICENSE file for details.
Contributing
Contributions are welcome, however please open an issue first to discuss what you would like to change, thanks!
Notice
This package and the maintainers are not affiliated with the Transmission project in any way. Likewise, the existence of this package nor its open-source nature implies any endorsement towards piracy or download of copyrighted content via any means including but not limited to the usage of this package. Use of this package is entirely at your own risk and responsibility.