fix(reddit,bilibili): switch to rdt-cli and add bili-cli support (#235)

Reddit: Exa crawling had chronic CRAWL_LIVECRAWL_TIMEOUT issues.
rdt-cli (304 stars, public-clis) works without login — search, read
full posts, and comments all verified. Massive improvement.

Bilibili: add bili-cli (590 stars) as optional enhanced backend for
hot/rank/search/feed. yt-dlp remains for video metadata + subtitles.

Also fix UA string (was "agent-reach/1.0", now proper browser UA).

75 tests passing.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Pnant
2026-03-31 17:04:58 +08:00
committed by GitHub
parent 794455cc9f
commit 15f161e5b5
6 changed files with 1696 additions and 78 deletions
+17 -31
View File
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Bilibili — video via yt-dlp, search via /x/web-interface API.""" """Bilibili — video via yt-dlp, search/browse via bili-cli or API."""
import json import json
import os import os
@@ -8,7 +8,7 @@ import subprocess
import urllib.request import urllib.request
from .base import Channel from .base import Channel
_UA = "agent-reach/1.0" _UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"
_TIMEOUT = 10 _TIMEOUT = 10
_SEARCH_API = "https://api.bilibili.com/x/web-interface/search/all/v2?keyword=test&page=1" _SEARCH_API = "https://api.bilibili.com/x/web-interface/search/all/v2?keyword=test&page=1"
@@ -24,23 +24,10 @@ def _search_api_ok() -> bool:
return False return False
def _bilisearch_ok() -> bool:
"""Return True if yt-dlp bilisearch works without 412."""
try:
result = subprocess.run(
["yt-dlp", "--flat-playlist", "--no-download", "-j",
"bilisearch1:test"],
capture_output=True, text=True, timeout=_TIMEOUT,
)
return result.returncode == 0
except Exception:
return False
class BilibiliChannel(Channel): class BilibiliChannel(Channel):
name = "bilibili" name = "bilibili"
description = "B站视频字幕" description = "B站视频字幕和搜索"
backends = ["yt-dlp", "B站搜索 API"] backends = ["yt-dlp", "bili-cli (可选)", "B站搜索 API"]
tier = 1 tier = 1
def can_handle(self, url: str) -> bool: def can_handle(self, url: str) -> bool:
@@ -53,11 +40,7 @@ class BilibiliChannel(Channel):
return "off", "yt-dlp 未安装。安装:pip install yt-dlp" return "off", "yt-dlp 未安装。安装:pip install yt-dlp"
proxy = (config.get("bilibili_proxy") if config else None) or os.environ.get("BILIBILI_PROXY") proxy = (config.get("bilibili_proxy") if config else None) or os.environ.get("BILIBILI_PROXY")
has_bili_cli = bool(shutil.which("bili"))
# 检测搜索 API 连通性
api_ok = _search_api_ok()
# 检测 yt-dlp bilisearch 是否 412
ytdlp_search_ok = _bilisearch_ok()
parts = [] parts = []
@@ -65,16 +48,19 @@ class BilibiliChannel(Channel):
if proxy: if proxy:
parts.append("视频读取:yt-dlp(代理已配置)") parts.append("视频读取:yt-dlp(代理已配置)")
else: else:
parts.append("视频读取:yt-dlp(本地环境,服务器可能需要代理)") parts.append("视频读取:yt-dlp")
# 搜索状态 # bili-cli 增强
if api_ok: if has_bili_cli:
parts.append("搜索B站 API 可用(/x/web-interface/search/all/v2") parts.append("搜索/热门/排行:bili-cli 可用")
else: else:
parts.append("搜索:B站 API 不可达,搜索功能可能受限") # 检测搜索 API 连通性
api_ok = _search_api_ok()
if api_ok:
parts.append("搜索:B站 API 可用")
else:
parts.append("搜索:B站 API 不可达")
parts.append("提示:安装 bili-cli 可解锁热门/排行/动态:pipx install bilibili-cli")
if not ytdlp_search_ok: status = "ok" if has_bili_cli or _search_api_ok() else "warn"
parts.append("提示:yt-dlp bilisearch 不可用(可能 HTTP 412 反爬),搜索将走 B站 API")
status = "ok" if api_ok else "warn"
return status, "".join(parts) return status, "".join(parts)
+12 -23
View File
@@ -1,30 +1,15 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Reddit — search and read via Exa (no direct Reddit API needed).""" """Reddit — search and read via rdt-cli (public-clis/rdt-cli)."""
import shutil import shutil
import subprocess import subprocess
from .base import Channel from .base import Channel
def _exa_available() -> bool:
"""Return True if mcporter is installed and Exa MCP is configured."""
mcporter = shutil.which("mcporter")
if not mcporter:
return False
try:
r = subprocess.run(
[mcporter, "config", "list"], capture_output=True,
encoding="utf-8", errors="replace", timeout=5
)
return "exa" in r.stdout.lower()
except Exception:
return False
class RedditChannel(Channel): class RedditChannel(Channel):
name = "reddit" name = "reddit"
description = "Reddit 帖子和评论(通过 Exa 搜索和阅读)" description = "Reddit 帖子和评论"
backends = ["Exa via mcporter"] backends = ["rdt-cli"]
tier = 0 tier = 0
def can_handle(self, url: str) -> bool: def can_handle(self, url: str) -> bool:
@@ -33,10 +18,14 @@ class RedditChannel(Channel):
return "reddit.com" in d or "redd.it" in d return "reddit.com" in d or "redd.it" in d
def check(self, config=None): def check(self, config=None):
if _exa_available(): rdt = shutil.which("rdt")
return "ok", "通过 Exa 搜索和阅读 Reddit 内容(免费,无需代理)" if rdt:
return "ok", (
"rdt-cli 可用(搜索帖子、阅读全文、查看评论,无需登录)"
)
return "off", ( return "off", (
"需要 mcporter + Exa MCP。安装:\n" "需要安装 rdt-cli\n"
" npm install -g mcporter\n" " pipx install rdt-cli\n"
" mcporter config add exa https://mcp.exa.ai/mcp" "或:\n"
" uv tool install rdt-cli"
) )
+7 -7
View File
@@ -243,9 +243,9 @@ def _cmd_install(args):
# Environment-specific advice # Environment-specific advice
if env == "server": if env == "server":
print() print()
print("Tip: Reddit and Bilibili block server IPs.") print("Tip: Bilibili may block server IPs.")
print(" Reddit search still works via Exa (free).") print(" Reddit: rdt-cli works without proxy (pipx install rdt-cli).")
print(" For full access: agent-reach configure proxy http://user:pass@ip:port") print(" For Bilibili full access: agent-reach configure proxy http://user:pass@ip:port")
print(" Cheap option: https://www.webshare.io ($1/month)") print(" Cheap option: https://www.webshare.io ($1/month)")
# Test channels # Test channels
@@ -1000,7 +1000,7 @@ def _cmd_configure(args):
if args.key == "proxy": if args.key == "proxy":
config.set("bilibili_proxy", value) config.set("bilibili_proxy", value)
print(f"✅ Proxy configured for Bilibili!") print(f"✅ Proxy configured for Bilibili!")
print(" Note: Reddit 已改为通过 Exa 访问,无需代理。") print(" Note: Reddit 已改为通过 rdt-cli 访问,无需代理。")
elif args.key == "twitter-cookies": elif args.key == "twitter-cookies":
# Accept two formats: # Accept two formats:
@@ -1433,9 +1433,9 @@ def _cmd_setup():
print(" 跳过。公开 API 也能用") print(" 跳过。公开 API 也能用")
print() print()
# Step 3: Reddit — no config needed (uses Exa) # Step 3: Reddit — rdt-cli
print("【信息】Reddit — 通过 Exa 搜索和阅读,无需配置") print("【信息】Reddit — 通过 rdt-cli 搜索和阅读,无需配置")
print(" 搜索和阅读 Reddit 内容已通过 Exa 自动完成,免费无需代理。") print(" 安装:pipx install rdt-cli")
print() print()
# Step 4: Groq (Whisper) # Step 4: Groq (Whisper)
+4 -4
View File
@@ -63,11 +63,11 @@ twitter search "query" --limit 10
# YouTube/B站字幕 # YouTube/B站字幕
yt-dlp --write-sub --skip-download -o "/tmp/%(id)s" "URL" yt-dlp --write-sub --skip-download -o "/tmp/%(id)s" "URL"
# Reddit 搜索(通过 Exa,免费无需代理) # Reddit 搜索
mcporter call 'exa.web_search_exa(query: "query", numResults: 5, includeDomains: ["reddit.com"])' rdt search "query" --limit 10
# Reddit 读帖(通过 Exa # Reddit 读帖 + 评论
mcporter call 'exa.crawling_exa(urls: ["https://www.reddit.com/r/.../comments/.../"], maxCharacters: 10000)' rdt read POST_ID
# V2EX 热门 # V2EX 热门
curl -s "https://www.v2ex.com/api/topics/hot.json" -H "User-Agent: agent-reach/1.0" curl -s "https://www.v2ex.com/api/topics/hot.json" -H "User-Agent: agent-reach/1.0"
+16 -13
View File
@@ -142,20 +142,23 @@ user = ch.get_user("Livid")
> **节点列表**: https://www.v2ex.com/planes > **节点列表**: https://www.v2ex.com/planes
## Reddit (通过 Exa) ## Reddit (rdt-cli)
Reddit 封锁了几乎所有非浏览器访问(包括代理 IP)。搜索和阅读全部通过 Exa 完成,免费且无需代理。
### 搜索 Reddit 内容
```bash ```bash
mcporter call 'exa.web_search_exa(query: "your search query", numResults: 5, includeDomains: ["reddit.com"])' # 搜索帖子
rdt search "query" --limit 10
# 读帖子全文 + 评论
rdt read POST_ID
# 浏览 subreddit
rdt sub python --limit 20
# 浏览热门
rdt popular --limit 10
# 浏览 /r/all
rdt all --limit 10
``` ```
### 阅读完整帖子和评论 > **安装**: `pipx install rdt-cli`。无需登录即可搜索和阅读。
```bash
mcporter call 'exa.crawling_exa(urls: ["https://www.reddit.com/r/SUBREDDIT/comments/POST_ID/TITLE/"], maxCharacters: 10000)'
```
> **零配置**: 只需安装 Exa MCP`agent-reach install --env=auto` 自动完成)。无需代理,无需 API Key。
Generated
+1640
View File
File diff suppressed because it is too large Load Diff