本项目提供了一个用于 YggTorrent 网站的 Python 包装器,以及一个 MCP(模型上下文协议)服务器,用于以编程方式与该网站进行交互。这使得可以轻松地将 YggTorrent 的功能集成到其他应用程序或服务中。
uv(用于本地开发)此应用程序需要你的 YggTorrent 通行证密钥才能与 API 进行交互。
Mon compte -> Mes paramètres。你的通行证密钥是跟踪器 URL 的一部分,格式类似于 http://tracker.p2p-world.net:8080/{YOUR_PASSKEY}/announce。YGG_PASSKEY 环境变量中读取通行证密钥。推荐的设置方法是在项目根目录下创建一个 .env 文件,应用程序会自动加载该文件。选择以下其中一种安装方法。
此方法最适合将该包作为库使用或在不修改代码的情况下运行服务器。
pip install ygg-torrent-mcp
.env 文件,并添加你的通行证密钥:YGG_PASSKEY=your_passkey_here
python -m ygg_torrent
此方法适用于想要修改源代码的贡献者。使用 uv:
git clone https://github.com/philogicae/ygg-torrent-mcp.git
cd ygg-torrent-mcp
uv 安装依赖项:uv sync
cp .env.example .env
uv run -m ygg_torrent
此方法使用 Docker 在容器中运行服务器。compose.yaml 配置为绕过 DNS 问题(使用 quad9 DNS)。
git clone https://github.com/philogicae/ygg-torrent-mcp.git
cd ygg-torrent-mcp
cp .env.example .env
docker-compose -f docker/compose.yaml up --build [-d]
from ygg_torrent import ygg_api
results = ygg_api.search_torrents('...')
for torrent in results:
print(f"{torrent.filename} | {torrent.size} | {torrent.seeders} SE | {torrent.leechers} LE | {torrent.downloads} DL | {torrent.date}")
from ygg_torrent import ygg_mcp
ygg_mcp.run(transport="sse")
本项目还包含一个 FastAPI 服务器,作为通过标准 HTTP API 与 YggTorrent 功能进行交互的另一种方式。这对于直接进行 API 调用、与其他 Web 服务集成或进行测试非常有用。
运行 FastAPI 服务器:
# 开发环境
python -m ygg_torrent --fastapi
# 生产环境
uvicorn ygg_torrent.fastapi_server:app
--host :默认值:0.0.0.0。--port
:默认值:8000。--reload:启用代码更改时的自动重新加载(适用于开发)。--workers :默认值:1。FastAPI 服务器将在 http:// 上可用。
可用端点: FastAPI 服务器提供与 MCP 服务器类似的功能。主要端点包括:
/:一个简单的健康检查端点。返回 {"status": "ok"}。/docs:交互式 API 文档(Swagger UI)。/redoc:替代 API 文档(ReDoc)。环境变量(如 YGG_PASSKEY)的配置方式与 MCP 服务器相同(通过项目根目录中的 .env 文件)。
可与任何 MCP 兼容的客户端一起使用。可用工具:
search_torrents:搜索种子。get_torrent_details:获取特定种子的详细信息。get_magnet_link:获取种子的磁力链接。download_torrent_file:下载种子的 .torrent 文件。配置:
{
"mcpServers": {
...
// 使用标准输入输出(仅需安装 uv)
"mcp-ygg-torrent": {
"command": "uvx",
"args": ["ygg-torrent-mcp"],
"env": { "YGG_PASSKEY": "your_passkey_here" }
}
// 使用服务器发送事件传输(需要安装)
"mcp-ygg-torrent": {
"serverUrl": "http://127.0.0.1:8000/sse"
}
// 使用可流式 HTTP 传输(需要安装)
"mcp-ygg-torrent": {
"serverUrl": "http://127.0.0.1:8000/mcp" // 并非所有客户端都支持
}
...
}
}
有关本项目的更改历史,请参阅 CHANGELOG.md。
欢迎贡献代码!请提交问题或拉取请求。
本项目采用 MIT 许可证 - 详情请参阅 LICENSE 文件。