# Torrent Client

## Permission

{% hint style="warning" %}
`torrent-client` permission is required.
{% endhint %}

<pre class="language-json" data-title="my-plugin.json"><code class="lang-json">{
    //...
    "plugin": {
        "permissions": {
<strong>            "scopes": ["torrent-client"],
</strong>        }
    }
}
</code></pre>

## Core Methods

### getTorrents

```
getTorrents()
```

Retrieves a list of all torrents in the torrent client.

Example:

```javascript
// Get all torrents from the client
try {
  const torrents = await ctx.torrentClient.getTorrents()
  console.log("Retrieved torrents:", torrents)
} catch (error) {
  console.error("Error getting torrents:", error)
}
```

### getActiveTorrents

```
getActiveTorrents()
```

Retrieves a list of active torrents (downloading/uploading) from the torrent client.

Example:

```javascript
// Get only active torrents
try {
  const activeTorrents = await ctx.torrentClient.getActiveTorrents()
  console.log("Active torrents:", activeTorrents)
} catch (error) {
  console.error("Error getting active torrents:", error)
}
```

### addMagnets

```
addMagnets(magnets, dest)
```

Adds magnet links to the torrent client.

**Parameters**:

* `magnets`: string\[] - Array of magnet links
* `dest`: string - Destination path for downloaded files

Example:

```javascript
// Add magnet links to the torrent client
try {
  await ctx.torrentClient.addMagnets(
    ["magnet:?xt=urn:btih:xxxxxx", "magnet:?xt=urn:btih:yyyyyy"],
    "/downloads/anime"
  )
  console.log("Magnets added successfully")
} catch (error) {
  console.error("Error adding magnets:", error)
}
```

### removeTorrents

```
removeTorrents(hashes)
```

Removes torrents from the client.

**Parameters**:

* `hashes`: string\[] - Array of torrent hashes to remove

Example:

```javascript
// Remove torrents from the client
try {
  await ctx.torrentClient.removeTorrents(["abc123def456", "xyz789uvw"])
  console.log("Torrents removed successfully")
} catch (error) {
  console.error("Error removing torrents:", error)
}
```

### pauseTorrents

```
pauseTorrents(hashes)
```

Pauses specified torrents.

**Parameters**:

* `hashes`: string\[] - Array of torrent hashes to pause

Example:

```javascript
// Pause specific torrents
try {
  await ctx.torrentClient.pauseTorrents(["abc123def456", "xyz789uvw"])
  console.log("Torrents paused successfully")
} catch (error) {
  console.error("Error pausing torrents:", error)
}
```

### resumeTorrents

```
resumeTorrents(hashes)
```

Resumes specified torrents.

**Parameters**:

* `hashes`: string\[] - Array of torrent hashes to resume

Example:

```javascript
// Resume specific torrents
try {
  await ctx.torrentClient.resumeTorrents(["abc123def456", "xyz789uvw"])
  console.log("Torrents resumed successfully")
} catch (error) {
  console.error("Error resuming torrents:", error)
}
```

### deselectFiles

```
deselectFiles(hash, indices)
```

Deselects specific files within a torrent.

**Parameters**:

* `hash`: string - Hash of the torrent
* `indices`: number\[] - Array of file indices to deselect

Example:

```javascript
// Deselect specific files in a torrent
try {
  await ctx.torrentClient.deselectFiles("abc123def456", [0, 2, 5])
  console.log("Files deselected successfully")
} catch (error) {
  console.error("Error deselecting files:", error)
}
```

### getFiles

```
getFiles(hash)
```

Retrieves all files within a specific torrent.

**Parameters**:

* `hash`: string - Hash of the torrent

Example:

```javascript
// Get all files in a torrent
try {
  const files = await ctx.torrentClient.getFiles("abc123def456")
  console.log("Torrent files:", files)
} catch (error) {
  console.error("Error getting files:", error)
}
```
