在全部列表中找到hdsky.me的种子,并显示这个种子的所有属性信息。
要在 Debian 12 系统中使用 Python 访问 qBittorrent 并获取特定站点的种子信息,最简单高效的方法是使用官方推荐的库 qbittorrent-api。
以下是实现这一任务的完整步骤和代码:
1. 安装必要的 Python 库
首先,确保你的 Debian 系统已安装 pip,然后安装 qbittorrent-api:
sudo apt update
sudo apt install python3-pip -y
pip install qbittorrent-api2. Python 脚本实现
这个脚本会连接到你的服务器,遍历种子列表,并打印出所有匹配 hdsky.me 的种子详细属性。
import qbittorrentapi
# --- 配置信息 ---
host = "http://31.220.45.252:18080/"
username = "admin"
password = "pass"
target_tracker = "hdsky.me"
def main():
# 1. 初始化客户端
qbt_client = qbittorrentapi.Client(
host=host,
username=username,
password=password,
)
try:
# 2. 尝试登录
qbt_client.auth_log_in()
print(f"✅ 成功连接至 qBittorrent v{qbt_client.app.version}")
except qbittorrentapi.LoginFailed as e:
print(f"❌ 登录失败: {e}")
return
# 3. 获取所有种子并筛选
# 获取种子列表 (all 为所有状态)
torrents = qbt_client.torrents_info()
found = False
for torrent in torrents:
# 检查 trackers 或种子名称中是否包含 hdsky.me
# tracker 信息通常在 torrent.tracker 中,或者检查其 comment
if target_tracker in torrent.get('tracker', '') or target_tracker in torrent.get('comment', ''):
found = True
print("-" * 50)
print(f"🔍 找到匹配种子: {torrent.name}")
# 4. 获取并显示该种子的所有属性信息
# torrents_properties 获取的是该种子的通用属性(如保存路径、总大小、累计上传等)
properties = qbt_client.torrents_properties(torrent_hash=torrent.hash)
# 合并基础信息和详细属性进行打印
full_info = {**torrent, **properties}
for key, value in full_info.items():
print(f"{key}: {value}")
if not found:
print(f"⚠️ 未在列表中找到包含 '{target_tracker}' 的种子。")
if __name__ == "__main__":
main()3. 代码要点说明
API 兼容性:
qbittorrent-api库对 v4.1+ 以上版本有非常好的支持,完美适配你的 v4.3.9。筛选逻辑:脚本通过检查
tracker字段来识别hdsky.me。在私有种子(PT)中,这是最准确的识别方式。属性合并:
torrent对象包含了种子的实时动态信息(下载速度、进度、状态)。qbt_client.torrents_properties()返回的是种子的静态属性(添加时间、创建者、文件保存路径、评论等)。脚本将两者合并,为你展示最全的数据。
4. 可能遇到的问题
防火墙:请确保 Debian 12 能够访问
31.220.45.252的18080端口。CSRF/WebUI 设置:如果连接被拒绝,请检查 qBittorrent WebUI 设置中是否勾选了“对本地主机客户端跳过身份验证”或“启用跨站请求伪造 (CSRF) 保护”(如果从外部 IP 访问,CSRF 保护有时需要正确配置 Host Header)。
5.测试结果
✅ 成功连接至 qBittorrent vv4.3.9
--------------------------------------------------
🔍 找到匹配种子: 特权.Privileges.S01.2026.2160p.MAX.WEB-DL.DDP5.1.H265-HDSWEB [到期:2026-04-25 21:17]
added_on: 1777104549
amount_left: 0
auto_tmm: False
availability: 1
category:
completed: 1958371070
completion_on: 1777104590
content_path: /home/sortie/qbittorrent/Downloads/特权.Privileges.S01.2026.2160p.MAX.WEB-DL.DDP5.1.H265-HDSWEB/特权.Privileges.S01E05.2026.2160p.MAX.WEB-DL.DDP5.1.H265-HDSWEB.mkv
dl_limit: -1
dlspeed: 0
downloaded: 1962074243
downloaded_session: 1962074243
eta: 8640000
f_l_piece_prio: True
force_start: False
hash: 119335aa2606f261dfd95c77442044a15429cfc2
last_activity: 1777104632
magnet_uri: magnet:?xt=urn:btih:119335aa2606f261dfd95c77442044a15429cfc2&dn=%e7%89%b9%e6%9d%83.Privileges.S01.2026.2160p.MAX.WEB-DL.DDP5.1.H265-HDSWEB&tr=https%3a%2f%2ftracker.hdsky.me%2fannounce.php%3fpasskey%3d4b1bb53794af4b03ba1926d24cc6f487
max_ratio: -1
max_seeding_time: -1
name: 特权.Privileges.S01.2026.2160p.MAX.WEB-DL.DDP5.1.H265-HDSWEB [到期:2026-04-25 21:17]
num_complete: 26
num_incomplete: 100
num_leechs: 2
num_seeds: 0
priority: 0
progress: 1
ratio: 0.000475969756665319
ratio_limit: -2
save_path: /home/sortie/qbittorrent/Downloads/
seeding_time: 2129
seeding_time_limit: -2
seen_complete: 1777104590
seq_dl: False
size: 1958371070
state: stalledUP
super_seeding: False
tags: 免费
time_active: 2169
total_size: 1958371070
tracker: https://tracker.hdsky.me/announce.php?passkey=4b14xxxxxx
trackers_count: 1
up_limit: -1
uploaded: 933888
uploaded_session: 933888
upspeed: 0
addition_date: 1777104549
comment: https://hdsky.me/details.php?id=610289
completion_date: 1777104590
created_by: Transmission/3.00 (bb6b5a062e)
creation_date: 1777101524
dl_speed: 0
dl_speed_avg: 49051856
last_seen: 1777104590
nb_connections: 4
nb_connections_limit: -1
peers: 2
peers_total: 100
piece_size: 2097152
pieces_have: 934
pieces_num: 934
reannounce: 5073
seeds: 0
seeds_total: 26
share_ratio: 0.000475969756665319
time_elapsed: 2169
total_downloaded: 1962074243
total_downloaded_session: 1962074243
total_uploaded: 933888
total_uploaded_session: 933888
total_wasted: 3703173
up_speed: 0
up_speed_avg: 430