FNOS BT下载程序探究
fnOS 自带了下载工具,比如迅雷,qBittorrent 等等,但是需要改一些设置的时候,比如自定义 WebUI,下载路径等等都不如 docker 版方便,但是使用docker运行qBittorrent却失去了fnOs的体验。
我的需求是使用python的qbittorrent_api库编写一个脚本,添加自动处理的一些功能,以方便管理BT下载。
fnOS 自带的下载工具其实是基于 aria2和qBittorrent 构建的,BT下载的功能是/usr/trim/bin/dlcenter
直接调用qBittorrent 的。
目前发现的特点:
- 只有进行Bt下载的时候,
/usr/trim/bin/dlcenter
才会启动qBittorrent,其他下载不会启动qBittorrent。/usr/trim/bin/dlcenter
的运行日志在/usr/trim/logs
文件夹里。 - fnOS的qBittorrent的配置文件是放在
/home/用户名/qbt
目录下。 - fnOS的qBittorrent的可执行路径是:
/usr/trim/bin/trim-qbittorrent-nox
- fnOS的qBittorrent运行命令是:
/usr/trim/bin/trim-qbittorrent-nox --profile=/home/用户名/qbt --relative-fastresume --webui-sock-path=/home/用户名/qbt.sock --webui-password=vSOS7Gc3 --stop-with-process=1242
使用fnos-qb-proxy完美解决了这个问题。
******************* 以下的都没用******************
-
命令参数解析:
/usr/trim/bin/trim-qbittorrent-nox:这是 qBittorrent 的无 GUI 版本的可执行文件路径。
–profile=/home/用户名/qbt:指定了 qBittorrent 的配置文件路径为 /home/用户名/qbt。
–relative-fastresume:启用了相对路径的 fastresume 文件,该文件用于保存种子的恢复状态。
–webui-sock-path=/home/用户名/qbt.sock:指定 WebUI 使用 Unix 套接字 /home/用户名/qbt.sock 而不是默认的端口。
–webui-password=vSOS7Gc3:WebUI 的访问密码。访问密码似乎是启动时随机生成的,每次启动都会变化。
–stop-with-process=1242:表示当进程 ID 为 1242 的进程结束时,qBittorrent 也将停止。通常用于将 qBittorrent 作为从属服务与另一个进程关联起来。
-
/home/用户名/qbt.sock
是一个 Unix 套接字文件,用于与 qBittorrent 的 WebUI 进行通信,只有在运行qBittorrent 的时候,该文件才会存在。 -
配置文件解析:
/home/用户名/qbt
文件夹下包含以下目录和文件:
qbt
└── qBittorrent
├── cache
├── config
│ ├── categories.json
│ ├── ipc-socket
│ ├── lockfile
│ ├── qBittorrent.conf
│ ├── qBittorrent-data.conf
│ ├── rss
│ │ ├── feeds.json
│ │ └── storage.lock
│ └── watched_folders.json
└── data
├── BT_backup
│ └── queue
├── GeoDB
│ └── dbip-country-lite.mmdb
├── logs
│ └── qbittorrent.log
└── rss
└── articles
└── storage.lock
qBittorrent.conf
是 qBittorrent 的配置文件,其中包含了一些基本的配置选项:
[Application]
FileLogger\Enabled=false
[BitTorrent]
Session\AddExtensionToIncompleteFiles=true
Session\AddTrackersEnabled=true
Session\AdditionalTrackers= # 这里太长,省略了
Session\AlternativeGlobalDLSpeedLimit=50
Session\AlternativeGlobalUPSpeedLimit=0
Session\BTProtocol=TCP
Session\BandwidthSchedulerEnabled=true
Session\CheckingMemUsageSize=10
Session\ConnectionSpeed=20
Session\DiskIOReadMode=DisableOSCache
Session\GlobalDLSpeedLimit=50
Session\MaxActiveDownloads=10
Session\MaxActiveTorrents=-1
Session\MaxActiveUploads=10
Session\Port=0
Session\QueueingSystemEnabled=true
[Meta]
MigrationVersion=6
[Preferences]
General\Locale=zh_CN
Scheduler\end_time=@Variant(\0\0\0\xf\0\0\0\0)
Scheduler\start_time=@Variant(\0\0\0\xf\0\0\0\0)
- 如何使用端口访问WebUI? WebUI文档地址https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)
经过测试,发现通过修改配置文件,会导致下载功能错误。 通过查询有关的文档,发现有几种方法可以做到: 8.1 使用 curl 访问 Unix 套接字 这种方式可以,但是不符合我的需求,因为需要使用qbittorrent_api访问。
curl --unix-socket /home/用户名/qbt.sock http://localhost:8080/api/v2/app/version
curl -i --header 'Referer: http://localhost:8080' --data 'username=admin&password=vSOS7Gc3' http://localhost:8080/api/v2/auth/login # Unauthorized错误
8.2 使用 socat、netcat、nginx等转发访问 Unix 套接字,这个是我使用的方法,非常方便。
socat TCP-LISTEN:8080,fork UNIX-CONNECT:/home/用户名/qbt.sock
当访问fnos:8080时,就会被转发到qBittorrent的WebUI。但是提示Unauthorized
通过python脚本访问同样报错:qbittorrentapi.exceptions.Unauthorized401Error: Unauthorized
#!/usr/bin/env python3
import qbittorrentapi
from loguru import logger
# 连接到 qBittorrent 客户端
def connect_to_qbittorrent():
client = qbittorrentapi.Client(
host="192.168.10.200", port=8080, username="admin", password="vSOS7Gc3"
)
try:
client.auth_log_in()
logger.info("成功连接到 qBittorrent 客户端")
return client
except qbittorrentapi.LoginFailed as e:
logger.info(f"连接到 qBittorrent 客户端失败:{e}")
return None
connect_to_qbittorrent()
重启 qBittorrent的命令
killall trim-qbittorrent-nox
/usr/trim/bin/trim-qbittorrent-nox --profile=/home/ranvane/qbt --relative-fastresume --webui-sock-path=/home/ranvane/qbt.sock --webui-password=vSOS7Gc3