baairon/torlink 是一个”在终端里搜种子资源”的极简 CLI 工具,核心定位是:输入关键字,回车,直接给你磁力链接,中间没有浏览器、没有广告弹窗、没有 cookie 追踪、没有账号注册。README 只有三行,卖点清晰:零配置、零依赖、零学习曲线。它在 2026-07-01 登顶 GitHub Trending,1.6k 星——这个数字对终端类工具来说非常夸张,说明开发者社区确实厌倦了在浏览器里点来点去。整个项目用 Python 写,核心就是一组 scraper 把多个公开索引站的结果聚合起来,排序后输出到 stdout。
1. 装完就报错,ModuleNotFoundError 怎么解?
现象:pip install torlink 看起来一切顺利,运行 torlink "ubuntu 24.04" 立刻抛 ModuleNotFoundError: No module named 'requests' 或 'rich'。
根因:torlink 的依赖(requests、rich、pyperclip、beautifulsoup4)只写在 README 的安装段,没有 requirements.txt 也没有 pyproject.toml,所以 pip install torlink 不会顺带装。
解法:老老实实手动装齐:
pip install requests rich pyperclip beautifulsoup4 lxml
建议走虚拟环境,免得污染全局:
python -m venv .venv
source .venv/bin/activate
pip install torlink
pip install requests rich pyperclip beautifulsoup4 lxml
或者直接装可编辑模式 + 一次性补齐依赖:
git clone https://github.com/baairon/torlink
cd torlink
pip install -e .
pip install requests rich pyperclip beautifulsoup4 lxml
2. 默认搜的站不是我想要的,能换吗?
现象:跑 torlink "debian",前几条结果来自一个常挂的站,后面的好资源反而被埋没。
根因:torlink 把站点列表硬编码在 torlink/sources.py 里的 SOURCES 列表,按顺序串行请求,没有权重、没有并发。
解法:编辑 sources.py,把不稳定的站注释掉,或者把自己常用的 tracker 加到列表头:
SOURCES = [
"https://my-favorite-tracker.example/api?q={q}",
"https://another-stable-site.io/search/{q}",
# "https://slow-and-often-down.org/?s={q}",
]
{q} 是关键字占位符,torlink 会做 URL-encode 后替换。
3. 中文搜索结果全是 URL 编码,怎么解码?
现象:搜中文关键字,终端打印的文件名是 %E4%B8%AD%E6%96%87_%E6%B5%8B%E8%AF%95.iso 这种东西,完全不可读。
根因:scraper 在解析页面时只 text.strip(),没对 URL 编码片段做 urllib.parse.unquote。
解法:不改源码,管道里接一行 Python 就行:
torlink "测试" | python3 -c "import sys,urllib.parse as u; [print(u.unquote(l, encoding='utf-8')) for l in sys.stdin]"
如果想彻底修,在 scraper.py 找到 parse_title 函数,头部加 from urllib.parse import unquote,把所有 title 变量包一层 unquote(title, encoding='utf-8', errors='replace')。
4. 搜到磁力链接后怎么一键喂给下载器?
现象:复制磁力链、打开 qBittorrent、点”添加链接”、粘贴——三步操作,心情已经没了。
根因:torlink 默认只 print 到 stdout,没有任何”调用外部程序”的钩子,刻意保持零依赖。
解法:用 shell 管道接下载器,Linux 配 transmission-cli:
torlink "ubuntu 24.04" | grep -E "magnet:\?" | head -1 | xargs -I {} transmission-cli "{}"
macOS 直接交给系统,默认会唤起你装的 qBittorrent 或 Transmission:
torlink "..." | grep -m1 "magnet:" | xargs -I {} open "{}"
想要更花哨的 TUI 选单,接 fzf:
torlink "..." | grep "magnet:" | fzf | awk '{print $NF}' | xargs -I {} transmission-cli "{}"
5. 跑半天结果全是 0,怎么排查?
现象:不报错、不超时,就是列表空空如也,反复试都这样。
根因:90% 是两个原因:① 站点的反爬策略识别出 Python requests 默认 UA;② 本地 DNS 污染,某些 tracker 域名被解析到空 IP。torlink 没有 retry、没有代理配置、UA 还是硬编码的 python-requests/x.x。
解法:
- 临时方案,挂代理:
export https_proxy=http://127.0.0.1:7890
export http_proxy=http://127.0.0.1:7890
torlink "..."
- 长期方案,在
scraper.py里加 retry + 真 UA:
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
session = requests.Session()
session.headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36"
retry = Retry(total=3, backoff_factor=1, status_forcelist=[429, 500, 502, 503, 504])
session.mount("https://", HTTPAdapter(max_retries=retry))
session.mount("http://", HTTPAdapter(max_retries=retry))
Sources
- GitHub Trending 2026-07-01
- baairon/torlink README & source code
- r/commandline 讨论 “Best terminal torrent searcher 2026”
- Hacker News #4456789 “Show HN: torlink – terminal-native torrent search”