argo-search 2.9.8 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/README.en.md +48 -35
  2. package/README.es.md +48 -35
  3. package/README.ja.md +47 -34
  4. package/README.ko.md +47 -34
  5. package/README.md +50 -35
  6. package/SKILL.md +5 -5
  7. package/backends/domain_profiles.json +76 -0
  8. package/backends/engine_registry.yaml +161 -5
  9. package/backends/quota_profiles.json +122 -2
  10. package/bin/argo +26 -1
  11. package/bin/argo.js +3 -3
  12. package/config.yaml +180 -26
  13. package/docs/ARGO_INTRO.md +7 -5
  14. package/docs/ENGINE_CATALOG.md +64 -44
  15. package/docs/MCP_SETUP.md +1 -1
  16. package/docs/RELEASE_NOTES_v2.10.0.md +85 -0
  17. package/docs/RELEASE_NOTES_v2.9.8.md +1 -1
  18. package/docs/RELEASE_NOTES_v2.9.9.md +78 -0
  19. package/docs//344/270/272/344/273/200/344/271/210/351/200/211/346/213/251argo.md +9 -9
  20. package/engines/specs/clawhub.yaml +16 -15
  21. package/engines/specs/deepseek1024.yaml +46 -0
  22. package/engines/specs/dsh_hub.yaml +44 -0
  23. package/engines/specs/dshopen.yaml +32 -0
  24. package/engines/specs/explainx.yaml +32 -0
  25. package/engines/specs/gbfs_nyc.yaml +6 -1
  26. package/engines/specs/metaso_doc.yaml +49 -0
  27. package/engines/specs/metaso_image.yaml +65 -0
  28. package/engines/specs/metaso_podcast.yaml +60 -0
  29. package/engines/specs/metaso_scholar.yaml +57 -0
  30. package/engines/specs/metaso_video.yaml +62 -0
  31. package/engines/specs/ncpssd.yaml +41 -0
  32. package/engines/specs/sciverse.yaml +72 -0
  33. package/engines/specs/skills_sh.yaml +32 -0
  34. package/engines/specs/skillsmp.yaml +18 -16
  35. package/package.json +4 -2
  36. package/packages/dsh-plugin/README.md +4 -2
  37. package/packages/dsh-plugin/dsh/client.js +98 -32
  38. package/packages/dsh-plugin/dsh/diagnostics.js +43 -0
  39. package/packages/dsh-plugin/dsh/index.js +23 -1
  40. package/packages/dsh-plugin/package.json +2 -2
  41. package/packages/dsh-plugin/test/client.test.js +2 -1
  42. package/packages/dsh-plugin/test/size-gate.test.js +113 -0
  43. package/scripts/adaptive.py +135 -48
  44. package/scripts/article.py +6 -1
  45. package/scripts/article_meta.py +151 -2
  46. package/scripts/bench_general_pool.py +145 -0
  47. package/scripts/bench_tail_ab.py +281 -0
  48. package/scripts/bounded_run.py +91 -49
  49. package/scripts/candidate_envelope.py +45 -4
  50. package/scripts/charset_decode.py +127 -0
  51. package/scripts/clock_bridge.py +22 -0
  52. package/scripts/content_security.py +119 -4
  53. package/scripts/crawl.py +240 -74
  54. package/scripts/crawl_frontier.py +217 -0
  55. package/scripts/crawl_policy.py +174 -0
  56. package/scripts/dispatch_result.py +9 -2
  57. package/scripts/engine_add.py +602 -0
  58. package/scripts/engine_dispatch.py +31 -15
  59. package/scripts/engine_failure.py +15 -0
  60. package/scripts/engine_validate.py +8 -0
  61. package/scripts/engines.py +10 -0
  62. package/scripts/engines_base.py +12 -0
  63. package/scripts/engines_builders.py +14 -0
  64. package/scripts/engines_builders_dsh.py +330 -0
  65. package/scripts/engines_builders_skill.py +314 -0
  66. package/scripts/evidence_loop.py +4 -0
  67. package/scripts/fetch_quality.py +13 -0
  68. package/scripts/fetch_v3.py +39 -7
  69. package/scripts/gen_engine_catalog.py +218 -2
  70. package/scripts/general_pool.py +162 -0
  71. package/scripts/http_client.py +62 -80
  72. package/scripts/image_ops.py +4 -0
  73. package/scripts/image_vision/vision_probe +0 -0
  74. package/scripts/install.ps1 +47 -19
  75. package/scripts/install.sh +45 -20
  76. package/scripts/matrix_search_eval.py +128 -2
  77. package/scripts/mcp_transport.py +1 -1
  78. package/scripts/ncpssd_bridge.py +123 -0
  79. package/scripts/net_proxy.py +27 -0
  80. package/scripts/paid_policy.py +109 -13
  81. package/scripts/pre-commit +19 -4
  82. package/scripts/query_signals.py +156 -3
  83. package/scripts/recovery.py +7 -3
  84. package/scripts/redskill/redskill_engine.py +29 -2
  85. package/scripts/release_check.py +209 -0
  86. package/scripts/retry_policy.py +22 -1
  87. package/scripts/robots_guard.py +26 -0
  88. package/scripts/route.py +11 -8
  89. package/scripts/route_cache.py +6 -0
  90. package/scripts/route_combo.py +56 -64
  91. package/scripts/route_domains.py +142 -13
  92. package/scripts/route_policy.py +6 -0
  93. package/scripts/safe_conn.py +52 -0
  94. package/scripts/search.py +9 -1
  95. package/scripts/search_cli.py +27 -0
  96. package/scripts/search_entry.py +10 -0
  97. package/scripts/search_output.py +29 -0
  98. package/scripts/search_pipeline.py +59 -3
  99. package/scripts/search_rank.py +7 -0
  100. package/scripts/serp_guard.py +23 -0
  101. package/scripts/social_engines/bilibili_engine.py +163 -26
  102. package/scripts/social_engines/reddit_engine.py +52 -51
  103. package/scripts/source_selection.py +302 -0
  104. package/scripts/tail_completion.py +212 -0
  105. package/scripts/url_safety.py +126 -3
  106. package/scripts/usage_log.py +45 -0
  107. package/scripts/video_fetch.py +303 -0
  108. package/scripts/video_meta.py +225 -0
  109. package/scripts/video_route.py +65 -0
  110. package/scripts/watch.py +123 -0
@@ -2,21 +2,38 @@
2
2
  """B站搜索引擎
3
3
 
4
4
  使用 B站公开搜索 API(无需登录可搜索视频)。
5
+
6
+ 2026-10-27 起补三件事(此前搜到视频但读不出「这是视频、多长、谁发的」):
7
+ - 时长筛选:把 --min-duration/--max-duration 映射成 B 站 API 的 duration
8
+ 档位(1=<10min、2=10-30、3=30-60、4=>60min),档位表达不了的范围
9
+ 再按解析出的秒数后过滤;
10
+ - 元数据完整化:发布时间转 ISO、收藏/投币/分享一并带出(envelope 只映射
11
+ 它认识的键,但引擎层不该先丢);
12
+ - snippet 前置「UP主 · 时长 · 播放量」:否则五维排序和下游模型只看到标题,
13
+ 视频结果无法按「长视频/高播放」判断。
5
14
  """
6
15
 
16
+ from __future__ import annotations
17
+
18
+ import html
7
19
  import json
20
+ import os
21
+ import re
22
+ import sys
8
23
  import time
9
24
  import urllib.error
10
25
  import urllib.parse
11
26
  import urllib.request
27
+ from datetime import datetime, timedelta, timezone
12
28
 
13
29
  # 出口调度唯一入口(issue #13 同类修复):urlopen 原生只认标准 HTTP(S)_PROXY
14
30
  # 环境变量,**不认** config.yaml 的 network.proxy —— 裸用会在「必须经代理才能
15
31
  # 出网」的环境里整源连不上。本文件在 scripts/ 子目录,父目录不在 sys.path 上。
16
- import os
17
- import sys
18
32
  sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
19
33
  from net_proxy import open_url # noqa: E402
34
+ from video_meta import parse_duration_seconds # noqa: E402
35
+
36
+ _TZ_CN = timezone(timedelta(hours=8))
20
37
 
21
38
 
22
39
  def _http_get_with_retry(url: str, headers: dict, timeout: int = 10, max_retries: int = 2):
@@ -44,55 +61,169 @@ def _http_get_with_retry(url: str, headers: dict, timeout: int = 10, max_retries
44
61
  return b"", 0
45
62
 
46
63
 
47
- def search(query: str, n: int = 5) -> list[dict]:
48
- """通过 B站搜索 API 搜索"""
49
- encoded = urllib.parse.quote(query)
50
- url = (
51
- f"https://api.bilibili.com/x/web-interface/search/all/v2"
52
- f"?keyword={encoded}&page=1&pagesize={n}"
53
- )
64
+ def _duration_bucket(min_seconds, max_seconds):
65
+ """把秒级范围映射成 B 站搜索的 duration 档位;跨档返回 None(只后过滤)。
66
+
67
+ 档位语义来自 B 站 search/all/v2:1=<10min、2=10-30min、3=30-60min、
68
+ 4=>60min。档位只做**粗召回**,精确范围仍由 _parse_bilibili_response
69
+ 里的后过滤保证;两者都做,才不会为了精确而丢掉「档位内但不在区间」的
70
+ 大量候选。
71
+ """
72
+ if min_seconds is None and max_seconds is None:
73
+ return None
74
+ if min_seconds is None:
75
+ # 只有上限时唯一安全的档位是「≤10 分钟」(档位 1 正好覆盖全集)。
76
+ # 上限 30/60 分钟不能用档位 2/3:那会把更短的视频一起排除,而用户
77
+ # 只要求「不超过」,没有要求「至少 10/30 分钟」。
78
+ return 1 if max_seconds <= 600 else None
79
+ if max_seconds is None:
80
+ # 只有下限时同理:档位 4(>60 分钟)是下限 ≥60 分钟的安全超集;
81
+ # 下限 10/30 分钟不能用档位 2/3,否则会丢掉更长(>30/>60)的视频。
82
+ return 4 if min_seconds >= 3600 else None
83
+ if min_seconds >= 3600:
84
+ return 4
85
+ if 600 <= min_seconds and max_seconds <= 1800:
86
+ return 2
87
+ if 1800 <= min_seconds and max_seconds <= 3600:
88
+ return 3
89
+ if max_seconds <= 600:
90
+ return 1
91
+ return None
92
+
93
+
94
+ def _format_play(count) -> str:
95
+ try:
96
+ n = int(count)
97
+ except (TypeError, ValueError):
98
+ return ""
99
+ if n >= 10000:
100
+ text = f"{n / 10000:.1f}万"
101
+ return text.replace(".0万", "万")
102
+ return str(n)
103
+
104
+
105
+ def _published_iso(ts) -> str:
106
+ try:
107
+ return datetime.fromtimestamp(int(ts), tz=_TZ_CN).isoformat()
108
+ except (TypeError, ValueError, OSError):
109
+ return ""
110
+
111
+
112
+ def _clean_title(raw: str) -> str:
113
+ """B 站搜索标题带 <em class="keyword"> 高亮和 HTML 实体。"""
114
+ text = re.sub(r"<[^>]+>", "", raw or "")
115
+ return html.unescape(text).strip()
116
+
117
+
118
+ def _snippet_of(item: dict, title: str) -> str:
119
+ """把视频元数据前置到摘要:排序器与模型都需要「多长、谁发的、多少人看」。"""
120
+ meta = []
121
+ author = (item.get("author") or "").strip()
122
+ duration = (item.get("duration") or "").strip()
123
+ play = _format_play(item.get("play"))
124
+ if author:
125
+ meta.append(f"UP主 {author}")
126
+ if duration:
127
+ meta.append(f"时长 {duration}")
128
+ if play:
129
+ meta.append(f"播放 {play}")
130
+ desc = (item.get("description") or "").strip()
131
+ parts = meta + ([desc] if desc else [])
132
+ return " · ".join(parts)[:300] or title[:300]
133
+
134
+
135
+ def search(query: str, n: int = 5, min_duration=None, max_duration=None) -> list[dict]:
136
+ """通过 B站搜索 API 搜索。
137
+
138
+ min_duration/max_duration 单位是秒;None 表示不限制。带时长条件时多取
139
+ 一些候选(档位粗召回后还要后过滤),避免筛完不足 n 条。
140
+
141
+ B 站 search API 单页上限实测 20 条(pagesize=50 仍只回 20),所以
142
+ 「档位表达不了、只能后过滤」时按页取 3 页再按 bvid 去重,而不是把
143
+ pagesize 调大(调大无效)。
144
+ """
145
+ bucket = _duration_bucket(min_duration, max_duration)
146
+ filtered = min_duration is not None or max_duration is not None
147
+ pages = 3 if filtered and bucket is None else 1
148
+ # 翻页场景取满单页(20 条),否则 3 页只有 3n 条、长视频更容易筛空。
149
+ page_size = 20 if pages > 1 else min(20, max(n, 1))
54
150
  headers = {
55
151
  "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
56
152
  "Referer": "https://www.bilibili.com"
57
153
  }
58
- try:
59
- body, _ = _http_get_with_retry(url, headers, timeout=10, max_retries=2)
60
- data = json.loads(body.decode("utf-8"))
61
- return _parse_bilibili_response(data, n)
62
- except Exception as e:
154
+ results: list[dict] = []
155
+ seen: set[str] = set()
156
+ last_error: Exception | None = None
157
+ for page in range(1, pages + 1):
158
+ params = {"keyword": query, "page": page, "pagesize": page_size}
159
+ if bucket is not None:
160
+ params["duration"] = bucket
161
+ url = ("https://api.bilibili.com/x/web-interface/search/all/v2?"
162
+ + urllib.parse.urlencode(params))
163
+ try:
164
+ body, _ = _http_get_with_retry(url, headers, timeout=10, max_retries=2)
165
+ data = json.loads(body.decode("utf-8"))
166
+ except Exception as e:
167
+ last_error = e
168
+ break
169
+ for item in _parse_bilibili_response(
170
+ data, n, min_duration=min_duration, max_duration=max_duration):
171
+ url_key = item.get("url") or ""
172
+ if url_key in seen:
173
+ continue
174
+ seen.add(url_key)
175
+ results.append(item)
176
+ if len(results) >= n:
177
+ break
178
+ if results:
179
+ return results[:n]
180
+ if last_error is not None:
63
181
  # 吞异常返空会让 MCP 社交搜索把网络故障静默报成「平台成功、0 结果」
64
182
  # (mcp_handlers 的 err=None 设计依赖引擎抛异常或返 error 占位,
65
183
  # 见 tests/test_regression_p0p1.py「零结果应以 errors 提示」契约)。
66
184
  # 对齐 zhihu_engine 范式:失败必须带着 error 字段浮上来。
67
- return [{"error": f"bilibili {type(e).__name__}: {e}", "source": "bilibili"}]
185
+ return [{"error": f"bilibili {type(last_error).__name__}: {last_error}",
186
+ "source": "bilibili"}]
187
+ return []
68
188
 
69
189
 
70
- def _parse_bilibili_response(data: dict, n: int) -> list[dict]:
71
- """解析 B站 API 响应"""
190
+ def _parse_bilibili_response(data: dict, n: int,
191
+ min_duration=None, max_duration=None) -> list[dict]:
192
+ """解析 B站 API 响应;时长条件在这里做精确后过滤。"""
72
193
  results = []
73
194
  data_data = data.get("data", {})
74
195
  for result_type in data_data.get("result", []):
75
196
  if result_type.get("result_type") != "video":
76
197
  continue
77
- for item in result_type.get("data", [])[:n]:
78
- title = item.get("title", "")
79
- # 清理 HTML 标签
80
- import re
81
- title = re.sub(r'<[^>]+>', '', title)
198
+ for item in result_type.get("data", []):
199
+ duration_text = item.get("duration", "")
200
+ seconds = parse_duration_seconds(duration_text)
201
+ if seconds is not None:
202
+ if min_duration is not None and seconds < min_duration:
203
+ continue
204
+ if max_duration is not None and seconds > max_duration:
205
+ continue
206
+ title = _clean_title(item.get("title", ""))
207
+ play = item.get("play", 0)
82
208
  results.append({
83
209
  "title": title[:100] + ("..." if len(title) > 100 else ""),
84
210
  "url": f"https://www.bilibili.com/video/{item.get('bvid', '')}",
85
- "snippet": (item.get("description", "") or title)[:300],
211
+ "snippet": _snippet_of(item, title),
86
212
  "source": "bilibili",
87
213
  "score": max(1.0 - len(results) * 0.1, 0.1),
88
214
  "social_meta": {
89
215
  "platform": "bilibili",
90
216
  "content_type": "video",
91
217
  "author": item.get("author", ""),
92
- "duration": item.get("duration", ""),
93
- "play_count": item.get("play", 0),
218
+ "duration": duration_text,
219
+ "duration_seconds": seconds,
220
+ "play_count": play,
94
221
  "danmu_count": item.get("video_review", 0),
95
222
  "like_count": item.get("like", 0),
223
+ "favorite_count": item.get("favorites", 0),
224
+ "coin_count": item.get("coin", 0),
225
+ "share_count": item.get("share", 0),
226
+ "published_at": _published_iso(item.get("pubdate")),
96
227
  "bvid": item.get("bvid", ""),
97
228
  }
98
229
  })
@@ -109,6 +240,10 @@ def main():
109
240
  parser.add_argument("action", nargs="?", default="search")
110
241
  parser.add_argument("query", nargs="?")
111
242
  parser.add_argument("-n", type=int, default=5)
243
+ parser.add_argument("--min-duration", type=int, default=None,
244
+ help="最小时长(秒)")
245
+ parser.add_argument("--max-duration", type=int, default=None,
246
+ help="最大时长(秒)")
112
247
  parser.add_argument("--json", action="store_true")
113
248
  args = parser.parse_args()
114
249
 
@@ -116,7 +251,9 @@ def main():
116
251
  print("[]")
117
252
  return
118
253
 
119
- results = search(args.query, args.n)
254
+ results = search(args.query, args.n,
255
+ min_duration=args.min_duration,
256
+ max_duration=args.max_duration)
120
257
  if args.json:
121
258
  print(json.dumps(results, ensure_ascii=False))
122
259
  else:
@@ -1,16 +1,20 @@
1
1
  #!/usr/bin/env python3
2
2
  """Reddit 搜索引擎
3
3
 
4
- 使用 Reddit JSON API(无需认证即可搜索公开内容)。
5
- 也可通过 rdt CLI 或 praw 扩展。
4
+ 通过 Reddit RSS(Atom)搜索公开内容,无需认证。也可通过 rdt CLI 扩展。
5
+
6
+ 端点史:无 key 的 search.json 自 2026-10 起对直连请求返回 Cloudflare HTML
7
+ 挑战页(bot 与浏览器 UA 无差别),RSS 是仅存的 keyless 通道;RSS 不带
8
+ 互动数(upvotes/comments),social_meta 相应字段恒 0。
6
9
  """
7
10
 
11
+ import html as _html
8
12
  import json
13
+ import re
9
14
  import subprocess
10
- import time
11
- import urllib.error
12
15
  import urllib.parse
13
16
  import urllib.request
17
+ import xml.etree.ElementTree as ET
14
18
 
15
19
  # 出口调度唯一入口(issue #13 同类修复):urlopen 原生只认标准 HTTP(S)_PROXY
16
20
  # 环境变量,**不认** config.yaml 的 network.proxy —— 裸用会在「必须经代理才能
@@ -21,40 +25,31 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
21
25
  from net_proxy import open_url # noqa: E402
22
26
 
23
27
 
24
- def _http_get_with_retry(url: str, headers: dict, timeout: int = 10, max_retries: int = 2):
25
- """带重试的 HTTP GET,尊重 429 + Retry-After。
26
-
27
- 仅使用 stdlib,不引入第三方依赖。
28
- 返回 (body_bytes, status_code)。失败时抛出最后一次异常。
29
- """
30
- for attempt in range(max_retries + 1):
31
- try:
32
- req = urllib.request.Request(url, headers=headers)
33
- with open_url(req, timeout=timeout) as resp:
34
- return resp.read(), resp.status
35
- except urllib.error.HTTPError as e:
36
- if e.code == 429 and attempt < max_retries:
37
- retry_after = int(e.headers.get("Retry-After", "5"))
38
- time.sleep(min(retry_after, 30))
39
- continue
40
- raise
41
- except (urllib.error.URLError, OSError):
42
- if attempt < max_retries:
43
- time.sleep(2 ** attempt + 0.5)
44
- continue
45
- raise
46
- return b"", 0
28
+ def _http_get(url: str, headers: dict, timeout: int = 10) -> bytes:
29
+ """单次 HTTP GET(stdlib)。429 不重试:无 key 端点按 IP「一次一发」,
30
+ 2026-10 实测首次 200 后即连续 429、Retry-After 达分钟级,短间隔重试
31
+ 必然再 429,还会叠乘 config reddit 段的引擎级 8s timeout。失败直接
32
+ 上浮,由 search_reddit_api 转成 error 条目。"""
33
+ req = urllib.request.Request(url, headers=headers)
34
+ with open_url(req, timeout=timeout) as resp:
35
+ return resp.read()
36
+
37
+
38
+ _ATOM_NS = {"atom": "http://www.w3.org/2005/Atom"}
39
+
40
+
41
+ def _strip_html(raw: str) -> str:
42
+ text = re.sub(r"<[^>]+>", " ", raw or "")
43
+ return _html.unescape(re.sub(r"\s+", " ", text)).strip()
47
44
 
48
45
 
49
46
  def search_reddit_api(query: str, n: int = 5) -> list[dict]:
50
- """通过 Reddit JSON API 搜索"""
51
- encoded = urllib.parse.quote(query)
52
- url = f"https://www.reddit.com/search.json?q={encoded}&limit={n}&sort=relevance"
53
- headers = {"User-Agent": "argo-search/1.0 (by taxueseek)"}
47
+ """通过 Reddit RSS(Atom)搜索"""
48
+ url = (f"https://www.reddit.com/search.rss?q={urllib.parse.quote(query)}"
49
+ f"&sort=relevance&limit={n}")
54
50
  try:
55
- body, _ = _http_get_with_retry(url, headers, timeout=10, max_retries=2)
56
- data = json.loads(body.decode("utf-8"))
57
- return _parse_reddit_response(data, n)
51
+ body = _http_get(url, {"User-Agent": "argo-search/1.0 (by taxueseek)"}, timeout=10)
52
+ return _parse_reddit_rss(body, n)
58
53
  except Exception as e:
59
54
  # 吞异常返空会让 MCP 社交搜索把网络故障静默报成「平台成功、0 结果」
60
55
  # (mcp_handlers 的 err=None 设计依赖引擎抛异常或返 error 占位,
@@ -63,29 +58,35 @@ def search_reddit_api(query: str, n: int = 5) -> list[dict]:
63
58
  return [{"error": f"reddit {type(e).__name__}: {e}", "source": "reddit"}]
64
59
 
65
60
 
66
- def _parse_reddit_response(data: dict, n: int) -> list[dict]:
67
- """解析 Reddit API 响应"""
61
+ def _parse_reddit_rss(body: bytes, n: int) -> list[dict]:
62
+ """解析 search.rss 的 Atom 响应。link 命中 /comments/ 的是帖子,
63
+ 其余(如 /r/<sub>/ 子版块页)按 listing 收录。"""
64
+ root = ET.fromstring(body.decode("utf-8", errors="replace"))
68
65
  results = []
69
- for child in data.get("data", {}).get("children", [])[:n]:
70
- post = child.get("data", {})
71
- if not post:
72
- continue
73
- title = post.get("title", "")
74
- selftext = post.get("selftext", "")
66
+ for entry in root.findall("atom:entry", _ATOM_NS)[:n]:
67
+ link_el = entry.find("atom:link", _ATOM_NS)
68
+ url = link_el.get("href", "") if link_el is not None else ""
69
+ m = re.match(r"https://(?:www\.)?reddit\.com/r/([^/]+)/", url or "")
70
+ title = (entry.findtext("atom:title", "", _ATOM_NS) or "").strip()
71
+ author = entry.findtext("atom:author/atom:name", "", _ATOM_NS) or ""
72
+ if author.startswith("/u/"):
73
+ author = author[3:]
74
+ snippet = _strip_html(entry.findtext("atom:content", "", _ATOM_NS))
75
75
  results.append({
76
76
  "title": title[:100] + ("..." if len(title) > 100 else ""),
77
- "url": f"https://reddit.com{post.get('permalink', '')}",
78
- "snippet": (selftext or title)[:300],
77
+ "url": url,
78
+ "snippet": snippet[:300] or title,
79
79
  "source": "reddit",
80
80
  "score": max(1.0 - len(results) * 0.1, 0.1),
81
81
  "social_meta": {
82
82
  "platform": "reddit",
83
- "content_type": "post",
84
- "subreddit": post.get("subreddit", ""),
85
- "author": post.get("author", ""),
86
- "upvotes": post.get("ups", 0),
87
- "comments": post.get("num_comments", 0),
88
- "awards": post.get("total_awards_received", 0),
83
+ "content_type": "post" if "/comments/" in url else "listing",
84
+ "subreddit": m.group(1) if m else "",
85
+ "author": author,
86
+ # RSS 不带互动数,字段保留供 aggregate_social_sentiment 消费
87
+ "upvotes": 0,
88
+ "comments": 0,
89
+ "awards": 0,
89
90
  }
90
91
  })
91
92
  return results
@@ -105,7 +106,7 @@ def search(query: str, n: int = 5) -> list[dict]:
105
106
  except (FileNotFoundError, subprocess.TimeoutExpired):
106
107
  pass
107
108
 
108
- # fallback: Reddit JSON API
109
+ # fallback: Reddit RSS(search.json 已被 Cloudflare 挑战页取代)
109
110
  return search_reddit_api(query, n)
110
111
 
111
112