# @ctrl/qbittorrent 中文文档

规范地址：https://npmcn.com/package/%40ctrl/qbittorrent/

版本：10\.1\.1
npm 元数据更新时间：2026-10-22T17:19:34.115Z
中文译文更新时间：2026-11-11T03:52:15.663Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40ctrl/qbittorrent
原文对照：https://npmcn.com/package/%40ctrl/qbittorrent/?lang=original
项目主页：https://qbittorrent.ep.workers.dev/
源码仓库：https://github.com/scttcper/qbittorrent

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：156 kB，17 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=24
- 运行依赖：9 个
- 首次发布：2019-04-14T18:46:34.503Z
- 最新版本发布：2026-10-22T17:19:33.640Z
- 近 30 天下载量：8690（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：77（近 12 个月 14 个）

## 中文简介

Qbittorrent 使用切换的脚本 api 包装器

## 安装

```sh
npm install @ctrl/qbittorrent
```

也可以使用：`pnpm add @ctrl/qbittorrent`、`yarn add @ctrl/qbittorrent`、`bun add @ctrl/qbittorrent`

## README

# qBitorrent 数据 [![npm](https://badgen.net/npm/v/@ctrl/qbittorrent)](https://www.npmjs.com/package/@ctrl/qbittorrent)

> 类型脚本 api 包装 [qBitorrent 数据](https://www.qbittorrent.org/) 使用 [函数](https://github.com/unjs/ofetch)

### 安装

```console
npm install @ctrl/qbittorrent
```

要求节点.js 24或更新.

### 使用

```ts
import { QBittorrent } from '@ctrl/qbittorrent';

const client = new QBittorrent({
  baseUrl: 'http://localhost:8080/',
  username: 'admin',
  password: 'adminadmin',
});

async function main() {
  const res = await client.getAllData();
  console.log(res);
}
```

### 认证

默认认证模式使用 qBittorrent 的用户名/ password 登录流量 并存储返回的 WebUI 会话 cookie.

qBittorrent v5.2.0和WebAPI v2.14.1增加了API密钥认证. 通过 API 键来使用无国籍的无记名认证而不是 cookie 登录 :

```ts
const client = new QBittorrent({
  baseUrl: 'http://localhost:8080/',
  apiKey: 'qbt_0000000000000000000000000000',
});
```

API 键可以从 qBittorrent WebUI 创建. 它们也可被旋转或 通过 WebAPI 删除 :

```ts
const passwordClient = new QBittorrent({
  baseUrl: 'http://localhost:8080/',
  username: 'admin',
  password: 'adminadmin',
});

const apiKey = await passwordClient.rotateApiKey();
await passwordClient.deleteApiKey();
```

### API 密码

文档 : [https://qbittorrent.ep.works.dev 互联网档案馆的存檔,存档日期2013-12-02](https://qbittorrent.ep.workers.dev/)  
qBittorrent API Docs: https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent- 5  
qBittorrent API 密钥文档 : [https://github.com/qbittorrent/qBittorrent/wiki/API-Key-Authentication-%28% E2%-89% A5v5.2.0%29 互联网档案馆的存檔,存档日期2014-12-20](https://github.com/qbittorrent/qBittorrent/wiki/API-Key-Authentication-%28%E2%89%A5v5.2.0%29)

与其他客户不同的事情:

-   `label` 是 qBitorrent 类
-   qBittorrent 忽略未知的散列, 暂停、 恢复、 排队和删除, 不为它们丢弃
-   `queueUp`编号 :`queueDown` 需要种子队列已启用, qBittorrent 以 409 回复 . `queuePosition` 实值 `0` 当队列被禁用或种子正在播种时
-   `pauseTorrent`编号 :`resumeTorrent` 使用情况 `/torrents/stop` 财务报告和审定财务报表 `/torrents/start` 关于qBitorrent 5和 `/torrents/pause` 财务报告和审定财务报表 `/torrents/resume` 在4.x时

### 规范化 API

这些职能通过 [@ ctrl/ 共享调用](https://github.com/scttcper/shared-torrent),这使得支持多个 torrent客户端更加容易. 见 [下级](https://npmcn.com/package/%40ctrl/qbittorrent/#readme-see-also) 用于支持种子客户端.

##### 获取全部数据

返回所有种子数据和一系列标签对象。 数据已经正常化, 不符合本地输出 `listTorrents()`。 。 。 .

```ts
const data = await client.getAllData();
console.log(data.torrents);
```

##### 获取Torrent

从种子散列返回一个种子数据h

```ts
const data = await client.getTorrent('torrent-hash');
console.log(data);
```

##### 暂停 Torrent 并恢复 Torrent

暂停或恢复一个或多个种子

```ts
await client.pauseTorrent('torrent-hash');
await client.resumeTorrent(['torrent-hash', 'other-torrent-hash']);
```

##### 删除Torrent

删除一个或多个种子 。 不默认删除磁盘上的数据 .

```ts
// does not remove data on disk
await client.removeTorrent('torrent-hash', false);

// remove data on disk
await client.removeTorrent(['torrent-hash', 'other-torrent-hash'], true);
```

##### 上下队列

上下移动种子队列

```ts
await client.queueUp('torrent-hash');
await client.queueDown('torrent-hash');
```

##### 添加托伦特

从磁铁链接或种子文件中添加种子, 有客户端特定选项 。 另见已规范的Add-Torrent

```ts
import { readFileSync } from 'node:fs';

const result = await client.addTorrent(new Uint8Array(readFileSync('./linux.torrent')));
console.log(result);
```

##### 已正常化 添加托伦特

添加 torrent并返回已归正的 torrent 数据, 可以启动已暂停的 torrent并添加标签

```ts
const result = await client.normalizedAddTorrent('magnet:?xt=urn:btih:...', {
  startPaused: false,
  label: 'linux',
});
console.log(result);
```

##### 错误

请求抛出失败 `TorrentClientError` 从 [@ ctrl/ 共享调用](https://github.com/scttcper/shared-torrent) 带有 `code` 联 合 国 `torrent_not_found`, (中文(简体) ), `unauthorized`, (中文(简体) ), `request_failed` 或者说 `client_error`,该网址 `status` 当有一个, 原始错误作为 `cause`。 。 。 .

```ts
import { TorrentClientError } from '@ctrl/qbittorrent';

try {
  await client.getTorrent('torrent-hash');
} catch (error) {
  if (error instanceof TorrentClientError && error.code === 'torrent_not_found') {
    // not in the client
  }
}
```

##### 从国家导出并创建

如果您经常关闭服务器( 无服务器 ) , 您可以导出状态

```ts
const state = client.exportState();
const restored = QBittorrent.createFromState(config, state);
```

### 另见

以下 npm 模块都提供相同的正态函数,同时为每个客户端支持独特的apis.

-   共享类型 - [@ ctrl/ 共享调用](https://github.com/scttcper/shared-torrent)
-   潮水 - [@ ctrl/ 清除](https://github.com/scttcper/deluge)
-   传输 - [@ctrl/ 转发](https://github.com/scttcper/transmission)
-   餐饮 [@ ctrl/ 用户](https://github.com/scttcper/utorrent)
-   特伦特 - [@ ctrl/ 特伦特](https://github.com/scttcper/rtorrent)
-   克比特语 - [@ ctrl/ rqbit](https://github.com/scttcper/rqbit)

Usenet 客户端采用相同的常态化方法:

-   用户网共享类型 - [@ctrl/ 共享用户网](https://github.com/scttcper/shared-usenet)
-   nzbget - (英语) [@ ctrl/ nzbget (英语)](https://github.com/scttcper/nzbget)
-   萨布兹布德 - [@ctrl/sabnzbd (英语)](https://github.com/scttcper/sabnzbd)

### 启动一个测试嵌入容器

```
docker run -d \
  --name=qbittorrent \
  -e PUID=1000 \
  -e PGID=1000 \
  -e TZ=Etc/UTC \
  -e WEBUI_PORT=8080 \
  -p 8080:8080 \
  -p 6881:6881 \
  -p 6881:6881/udp \
  --restart unless-stopped \
  lscr.io/linuxserver/qbittorrent:latest
```

### 为 qBittorrent alpha 启动一个测试嵌入容器

在测试最新的WebAPI更改时使用官方的α图像. 这个 linux 服务器 `latest` 图像可以落后于最新的 qBittorrent 发布.

```
mkdir -p /tmp/qbittorrent-alpha/config /tmp/qbittorrent-alpha/downloads

docker run -d \
  --name=qbittorrent-alpha \
  -e QBT_LEGAL_NOTICE=confirm \
  -e QBT_WEBUI_PORT=8080 \
  -e QBT_TORRENTING_PORT=6881 \
  -e PUID=1000 \
  -e PGID=1000 \
  -p 8080:8080 \
  -p 6881:6881 \
  -p 6881:6881/udp \
  -v /tmp/qbittorrent-alpha/config:/config \
  -v /tmp/qbittorrent-alpha/downloads:/downloads \
  qbittorrentofficial/qbittorrent-nox:alpha
```

Alpha 图像在 `docker logs qbittorrent-alpha`设置 WebUI 密码到 `adminadmin` 运行前 综合测试.

## 常见问题

### @ctrl/qbittorrent 是什么？

Qbittorrent 使用切换的脚本 api 包装器

### 如何安装 @ctrl/qbittorrent？

在项目目录运行 npm install @ctrl/qbittorrent，或使用 pnpm add / yarn add / bun add。

### @ctrl/qbittorrent 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @ctrl/qbittorrent 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @ctrl/qbittorrent 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=24。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @ctrl/qbittorrent 可以商用吗？

@ctrl/qbittorrent 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @ctrl/qbittorrent 的下载量有多少？

根据 npm 官方下载统计，@ctrl/qbittorrent 在 2026/10/11 – 2026/11/09 这 30 天内被下载 8,690 次，日均约 290 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @ctrl/qbittorrent 还在维护吗？

最新版本 10\.1\.1 发布于 2026/10/23（19 天前）；至今共发布 77 个版本，其中过去 12 个月发布了 14 个；首次发布于 2019/04/15。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

