papersearch 0.7.3 → 0.8.1

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 (204) hide show
  1. package/NOTICE +8 -37
  2. package/README.fr.md +265 -0
  3. package/README.ja.md +265 -0
  4. package/README.ko.md +265 -0
  5. package/README.md +149 -148
  6. package/README.zh-Hant.md +265 -0
  7. package/README.zh.md +265 -0
  8. package/dist/capabilities/download/batch/batch.d.ts +20 -1
  9. package/dist/capabilities/download/batch/batch.d.ts.map +1 -1
  10. package/dist/capabilities/download/batch/batch.js +1057 -208
  11. package/dist/capabilities/download/batch/batch.js.map +1 -1
  12. package/dist/capabilities/download/batch/batchFolder.d.ts.map +1 -1
  13. package/dist/capabilities/download/batch/batchFolder.js +3 -2
  14. package/dist/capabilities/download/batch/batchFolder.js.map +1 -1
  15. package/dist/capabilities/download/batch/networkLoss.d.ts +11 -2
  16. package/dist/capabilities/download/batch/networkLoss.d.ts.map +1 -1
  17. package/dist/capabilities/download/batch/networkLoss.js +24 -3
  18. package/dist/capabilities/download/batch/networkLoss.js.map +1 -1
  19. package/dist/capabilities/download/batch/resume.d.ts +7 -0
  20. package/dist/capabilities/download/batch/resume.d.ts.map +1 -1
  21. package/dist/capabilities/download/batch/resume.js +50 -9
  22. package/dist/capabilities/download/batch/resume.js.map +1 -1
  23. package/dist/capabilities/download/batch/windowPlan.d.ts +96 -0
  24. package/dist/capabilities/download/batch/windowPlan.d.ts.map +1 -0
  25. package/dist/capabilities/download/batch/windowPlan.js +196 -0
  26. package/dist/capabilities/download/batch/windowPlan.js.map +1 -0
  27. package/dist/capabilities/download/content/markdown/pro.d.ts +6 -0
  28. package/dist/capabilities/download/content/markdown/pro.d.ts.map +1 -1
  29. package/dist/capabilities/download/content/markdown/pro.js.map +1 -1
  30. package/dist/capabilities/download/content/markdown/shortfall.d.ts +8 -5
  31. package/dist/capabilities/download/content/markdown/shortfall.d.ts.map +1 -1
  32. package/dist/capabilities/download/content/markdown/shortfall.js +22 -10
  33. package/dist/capabilities/download/content/markdown/shortfall.js.map +1 -1
  34. package/dist/capabilities/download/content/markdown/step.d.ts +9 -0
  35. package/dist/capabilities/download/content/markdown/step.d.ts.map +1 -1
  36. package/dist/capabilities/download/content/markdown/step.js +46 -3
  37. package/dist/capabilities/download/content/markdown/step.js.map +1 -1
  38. package/dist/capabilities/download/content/markdown/types.d.ts +10 -1
  39. package/dist/capabilities/download/content/markdown/types.d.ts.map +1 -1
  40. package/dist/capabilities/download/content/pdf/open/tiers/scihub.d.ts.map +1 -1
  41. package/dist/capabilities/download/content/pdf/open/tiers/scihub.js +3 -1
  42. package/dist/capabilities/download/content/pdf/open/tiers/scihub.js.map +1 -1
  43. package/dist/capabilities/download/handler.d.ts.map +1 -1
  44. package/dist/capabilities/download/handler.js +13 -5
  45. package/dist/capabilities/download/handler.js.map +1 -1
  46. package/dist/capabilities/download/outputLayout.d.ts.map +1 -1
  47. package/dist/capabilities/download/outputLayout.js +3 -1
  48. package/dist/capabilities/download/outputLayout.js.map +1 -1
  49. package/dist/capabilities/download/tools.js +2 -2
  50. package/dist/capabilities/download/tools.js.map +1 -1
  51. package/dist/capabilities/download/types.d.ts +9 -1
  52. package/dist/capabilities/download/types.d.ts.map +1 -1
  53. package/dist/cli.js +3 -1
  54. package/dist/cli.js.map +1 -1
  55. package/dist/infrastructure/http/hostGate.d.ts +24 -0
  56. package/dist/infrastructure/http/hostGate.d.ts.map +1 -0
  57. package/dist/infrastructure/http/hostGate.js +72 -0
  58. package/dist/infrastructure/http/hostGate.js.map +1 -0
  59. package/dist/infrastructure/pdf/PdfDownload.d.ts +1 -0
  60. package/dist/infrastructure/pdf/PdfDownload.d.ts.map +1 -1
  61. package/dist/infrastructure/pdf/PdfDownload.js +6 -1
  62. package/dist/infrastructure/pdf/PdfDownload.js.map +1 -1
  63. package/dist/infrastructure/runlog/RunLedger.d.ts +14 -0
  64. package/dist/infrastructure/runlog/RunLedger.d.ts.map +1 -1
  65. package/dist/infrastructure/runlog/RunLedger.js +30 -4
  66. package/dist/infrastructure/runlog/RunLedger.js.map +1 -1
  67. package/dist/infrastructure/runlog/failureClass.d.ts +2 -1
  68. package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
  69. package/dist/infrastructure/runlog/failureClass.js +27 -4
  70. package/dist/infrastructure/runlog/failureClass.js.map +1 -1
  71. package/dist/infrastructure/school/SchoolAttempt.d.ts +11 -0
  72. package/dist/infrastructure/school/SchoolAttempt.d.ts.map +1 -1
  73. package/dist/infrastructure/school/SchoolAttempt.js +48 -5
  74. package/dist/infrastructure/school/SchoolAttempt.js.map +1 -1
  75. package/dist/infrastructure/school/SchoolMcpClient.d.ts +13 -2
  76. package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
  77. package/dist/infrastructure/school/SchoolMcpClient.js +138 -15
  78. package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -1
  79. package/dist/infrastructure/school/SchoolProgress.d.ts +2 -0
  80. package/dist/infrastructure/school/SchoolProgress.d.ts.map +1 -1
  81. package/dist/infrastructure/school/SchoolProgress.js +2 -0
  82. package/dist/infrastructure/school/SchoolProgress.js.map +1 -1
  83. package/dist/infrastructure/school/SchoolReadiness.d.ts +9 -0
  84. package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -1
  85. package/dist/infrastructure/school/SchoolReadiness.js +10 -0
  86. package/dist/infrastructure/school/SchoolReadiness.js.map +1 -1
  87. package/dist/infrastructure/school/SchoolResultNormalizer.d.ts.map +1 -1
  88. package/dist/infrastructure/school/SchoolResultNormalizer.js +4 -0
  89. package/dist/infrastructure/school/SchoolResultNormalizer.js.map +1 -1
  90. package/dist/infrastructure/school/index.d.ts +2 -2
  91. package/dist/infrastructure/school/index.d.ts.map +1 -1
  92. package/dist/infrastructure/school/index.js +1 -1
  93. package/dist/infrastructure/school/index.js.map +1 -1
  94. package/dist/infrastructure/school/types.d.ts +73 -1
  95. package/dist/infrastructure/school/types.d.ts.map +1 -1
  96. package/dist/infrastructure/school/types.js.map +1 -1
  97. package/dist/infrastructure/security/SecurityUtils.d.ts.map +1 -1
  98. package/dist/infrastructure/security/SecurityUtils.js +6 -2
  99. package/dist/infrastructure/security/SecurityUtils.js.map +1 -1
  100. package/dist/management/failures/index.d.ts +23 -0
  101. package/dist/management/failures/index.d.ts.map +1 -1
  102. package/dist/management/failures/index.js +68 -20
  103. package/dist/management/failures/index.js.map +1 -1
  104. package/dist/management/school/autoUpdate.d.ts.map +1 -1
  105. package/dist/management/school/autoUpdate.js +9 -1
  106. package/dist/management/school/autoUpdate.js.map +1 -1
  107. package/dist/management/school/cliProgress.d.ts.map +1 -1
  108. package/dist/management/school/cliProgress.js +3 -1
  109. package/dist/management/school/cliProgress.js.map +1 -1
  110. package/package.json +8 -3
  111. package/school/NOTICE +3 -2
  112. package/school/paper_search_school/adapters/__init__.py +2 -0
  113. package/school/paper_search_school/adapters/aps/__init__.py +3 -6
  114. package/school/paper_search_school/adapters/base.py +19 -2
  115. package/school/paper_search_school/adapters/copernicus/__init__.py +2 -7
  116. package/school/paper_search_school/adapters/elsevier/__init__.py +50 -1
  117. package/school/paper_search_school/adapters/frontiers/__init__.py +41 -2
  118. package/school/paper_search_school/adapters/ieee/__init__.py +6 -4
  119. package/school/paper_search_school/adapters/iop/__init__.py +8 -0
  120. package/school/paper_search_school/adapters/jama/__init__.py +8 -0
  121. package/school/paper_search_school/adapters/lww/__init__.py +14 -6
  122. package/school/paper_search_school/adapters/mdpi/__init__.py +12 -7
  123. package/school/paper_search_school/adapters/neurology/__init__.py +5 -2
  124. package/school/paper_search_school/adapters/optica/__init__.py +52 -13
  125. package/school/paper_search_school/adapters/oup/__init__.py +7 -4
  126. package/school/paper_search_school/adapters/platforms/__init__.py +4 -1
  127. package/school/paper_search_school/adapters/platforms/atypon/__init__.py +12 -3
  128. package/school/paper_search_school/adapters/platforms/figshare/__init__.py +23 -4
  129. package/school/paper_search_school/adapters/platforms/jstage/__init__.py +64 -0
  130. package/school/paper_search_school/adapters/taylor_francis/__init__.py +0 -3
  131. package/school/paper_search_school/adapters/thieme/__init__.py +2 -9
  132. package/school/paper_search_school/api_keys.py +63 -13
  133. package/school/paper_search_school/assets/api_keys.json +14 -0
  134. package/school/paper_search_school/assets/capsule.html +526 -147
  135. package/school/paper_search_school/assets/capsule_en.json +140 -49
  136. package/school/paper_search_school/assets/capsule_fr.json +141 -50
  137. package/school/paper_search_school/assets/capsule_ja.json +140 -49
  138. package/school/paper_search_school/assets/capsule_ko.json +140 -49
  139. package/school/paper_search_school/assets/capsule_zh-Hant.json +134 -48
  140. package/school/paper_search_school/browser/backend.py +125 -4
  141. package/school/paper_search_school/browser/batch_session.py +189 -8
  142. package/school/paper_search_school/browser/challenge/__init__.py +12 -9
  143. package/school/paper_search_school/browser/challenge/continuation.py +83 -0
  144. package/school/paper_search_school/browser/challenge/handlers/__init__.py +1 -0
  145. package/school/paper_search_school/browser/challenge/handlers/aws_waf.py +260 -0
  146. package/school/paper_search_school/browser/challenge/handlers/recaptcha_hcaptcha.py +167 -0
  147. package/school/paper_search_school/browser/challenge/handlers/text_captcha.py +128 -0
  148. package/school/paper_search_school/browser/challenge/handlers/turnstile.py +174 -0
  149. package/school/paper_search_school/browser/challenge/kinds.py +203 -0
  150. package/school/paper_search_school/browser/challenge/local/__init__.py +1 -0
  151. package/school/paper_search_school/browser/challenge/{interaction.py → local/interaction.py} +94 -13
  152. package/school/paper_search_school/browser/challenge/{pointer.py → local/pointer.py} +2 -2
  153. package/school/paper_search_school/browser/challenge/local/prompt.py +283 -0
  154. package/school/paper_search_school/browser/challenge/local/submission.py +33 -0
  155. package/school/paper_search_school/browser/challenge/pro.py +24 -0
  156. package/school/paper_search_school/browser/challenge/services/__init__.py +1 -0
  157. package/school/paper_search_school/browser/challenge/services/solver.py +292 -0
  158. package/school/paper_search_school/browser/engine.py +4 -1
  159. package/school/paper_search_school/browser/user_turn.py +126 -0
  160. package/school/paper_search_school/browser/watchdog.py +213 -60
  161. package/school/paper_search_school/cli_config.py +10 -5
  162. package/school/paper_search_school/config.py +16 -10
  163. package/school/paper_search_school/download_diagnostics.py +7 -2
  164. package/school/paper_search_school/engine/access_rules.py +12 -3
  165. package/school/paper_search_school/engine/batch.py +52 -18
  166. package/school/paper_search_school/engine/batch_access.py +62 -16
  167. package/school/paper_search_school/engine/batch_capture.py +260 -31
  168. package/school/paper_search_school/engine/batch_common.py +3 -0
  169. package/school/paper_search_school/engine/batch_diagnostics.py +25 -5
  170. package/school/paper_search_school/engine/batch_institution.py +52 -3
  171. package/school/paper_search_school/engine/batch_login.py +398 -36
  172. package/school/paper_search_school/engine/batch_pdf_urls.py +38 -7
  173. package/school/paper_search_school/engine/batch_user.py +48 -3
  174. package/school/paper_search_school/engine/batch_waits.py +221 -14
  175. package/school/paper_search_school/engine/bridge.py +29 -6
  176. package/school/paper_search_school/engine/fulltext_page.py +55 -8
  177. package/school/paper_search_school/engine/router.py +16 -1
  178. package/school/paper_search_school/engine/supplements.py +7 -1
  179. package/school/paper_search_school/entitlements.py +29 -1
  180. package/school/paper_search_school/pdf_utils.py +25 -16
  181. package/school/paper_search_school/progress_capsule.py +69 -11
  182. package/school/paper_search_school/progress_reporter.py +243 -11
  183. package/school/paper_search_school/progress_view.py +205 -91
  184. package/school/paper_search_school/publishers/builtin/iop.json +2 -1
  185. package/school/paper_search_school/publishers/builtin/neurology.json +4 -2
  186. package/school/paper_search_school/publishers/site.py +12 -4
  187. package/school/paper_search_school/rate_limit.py +24 -1
  188. package/school/paper_search_school/school_login.py +170 -8
  189. package/school/paper_search_school/school_test.py +1 -1
  190. package/school/paper_search_school/server.py +179 -23
  191. package/school/paper_search_school/user_settings.py +46 -4
  192. package/school/pyproject.toml +1 -0
  193. package/skills/paper-search/SKILL.md +107 -107
  194. package/skills/paper-search/references/browser-download.md +102 -99
  195. package/skills/paper-search/references/capability-routing.md +89 -89
  196. package/skills/paper-search/references/cli-contract.md +78 -78
  197. package/skills/paper-search/references/federation-support.md +172 -172
  198. package/skills/paper-search/references/management-layer.md +78 -78
  199. package/skills/paper-search/references/publisher-support.md +38 -38
  200. package/skills/paper-search/references/school-setup.md +56 -55
  201. package/skills/paper-search/references/setup.md +20 -20
  202. package/skills/paper-search/references/troubleshooting.md +12 -12
  203. package/README.en.md +0 -264
  204. package/school/paper_search_school/browser/challenge/prompt.py +0 -154
@@ -92,7 +92,7 @@ def school_status(entity_id: str, pro: Any | None = None) -> str:
92
92
  # What the settings page reads of each school: the area (a US state, a UK nation) and kind (university, research
93
93
  # institute, hospital) split the big countries (Pro 0.3.1; an older Pro has neither, "" there).
94
94
  #: key: its entityID (添加学校 adds a school found in this list by it; "" from an older Pro).
95
- SCHOOL_FIELDS = ("key", "name", "name_en", "country", "province", "area", "kind", "status")
95
+ SCHOOL_FIELDS = ("key", "name", "name_en", "country", "province", "area", "kind", "status", "entry", "app")
96
96
 
97
97
 
98
98
  def school_list(pro: Any | None = None) -> list[dict[str, Any]]:
@@ -125,10 +125,30 @@ def school_counts(pro: Any | None = None) -> dict[str, int]:
125
125
  return {}
126
126
 
127
127
 
128
+ def entry_for(entity_id: str, pro: Any | None = None) -> dict:
129
+ """Optional Pro metadata; older Pro versions retain the existing filling policy."""
130
+ pro = pro if pro is not None else module()
131
+ hook = getattr(pro, "school_entry", None)
132
+ value = hook(entity_id) if callable(hook) else None
133
+ return value if isinstance(value, dict) and value.get("entry") in {"qr_only", "sms_only", "check_first"} else {}
134
+
135
+
136
+ def entry_notice(entry: dict) -> str:
137
+ if entry.get("entry") == "sms_only":
138
+ return "学校登录页只能用短信验证码登录,请在浏览器窗口完成。"
139
+ if entry.get("sms_alternative"):
140
+ return "学校登录页需要扫码或短信验证,请在浏览器窗口完成。"
141
+ app = str(entry.get("app") or "学校的 App")
142
+ if app not in {"微信", "企业微信", "钉钉"}:
143
+ app = "学校的 App"
144
+ return f"学校登录页只能用{app}扫码登录,没有账号密码可填,请在浏览器窗口扫码。"
145
+
146
+
128
147
  def fills_for(entity_id: str, pro: Any | None = None) -> bool:
129
- """Whether Pro fills this school's sign-in in: tested or surveyed, or being tested by a maintainer."""
130
- status = school_status(entity_id, pro)
131
- return status in {"verified", "surveyed"} or (status == "trial" and os.environ.get(TRIAL_ENV) == "1")
148
+ """Whether Pro fills this school's sign-in in: every school once Pro is there, tested or not (user, 2026-11-28:
149
+ a school our tests could not pass may well work from the user's own network; what keeps it from being filled in
150
+ is found on its page and told, not decided in advance by the lists, which now only say whether it was tested)."""
151
+ return pro is not None and bool(str(entity_id or "").strip())
132
152
 
133
153
 
134
154
  # -- the account ------------------------------------------------------------------------------
@@ -169,11 +189,27 @@ def save(entity_id: str, username: str, password: str, *, enabled: bool = True)
169
189
  raise ValueError("请填写密码")
170
190
  logins = dict(_logins(current))
171
191
  logins[entity_id] = {"username": username, "password": password, "enabled": bool(enabled), "off": "",
172
- "saved": time.strftime("%Y-%m-%d %H:%M")}
192
+ "saved": time.strftime("%Y-%m-%d %H:%M"),
193
+ # The way chosen on its sign-in chooser stays while the school does (set_way).
194
+ **({"way": str(entry["way"])} if entry.get("way") else {})}
173
195
  current[CONFIG_KEY] = logins
174
196
  cfg.save_config(current)
175
197
 
176
198
 
199
+ def set_way(entity_id: str, way: str) -> None:
200
+ """The way the user chose on the school's sign-in chooser (OpenAthens's "Choose how to sign in", in the progress
201
+ window; user 2026-11-29), pressed again from then on: kept with its account until the school is cleared."""
202
+ from . import config as cfg
203
+
204
+ current = cfg.load_config()
205
+ logins = dict(_logins(current))
206
+ entry = logins.get(entity_id)
207
+ if isinstance(entry, dict) and str(way or "").strip():
208
+ logins[entity_id] = {**entry, "way": str(way).strip()}
209
+ current[CONFIG_KEY] = logins
210
+ cfg.save_config(current)
211
+
212
+
177
213
  def clear(entity_id: str) -> None:
178
214
  from . import config as cfg
179
215
 
@@ -199,15 +235,19 @@ def turn_off(entity_id: str, why: str) -> None:
199
235
 
200
236
  # -- where and how often ----------------------------------------------------------------------
201
237
 
202
- def may_fill(url: str, config: dict[str, Any], also: tuple[str, ...] = ()) -> bool:
238
+ def may_fill(url: str, config: dict[str, Any], also: tuple[str, ...] = (), plain: tuple[str, ...] = ()) -> bool:
203
239
  """An https page of the school's own: one of its login hosts as its federation lists them,
204
240
  or under its own domains. Hosts merely passed through in a batch never count. ``also``: the
205
241
  hosts Pro has for this school's login page on another domain of its own (Pro's ``login_hosts``,
206
- found by its survey: a login system that sends to a login page on a second domain of the school's)."""
242
+ found by its survey: a login system that sends to a login page on a second domain of the school's).
243
+ ``plain``: the hosts Pro has for a login page the school serves on plain http only (Pro's
244
+ ``plain_hosts``: its survey filled it in there; user, 2026-11-28): on http, those exact hosts only."""
207
245
  from .schools import lookup
208
246
 
209
247
  parsed = urlparse(str(url or ""))
210
248
  host = (parsed.hostname or "").lower()
249
+ if parsed.scheme == "http" and host and host in {str(h).strip().lower() for h in plain}:
250
+ return True
211
251
  if parsed.scheme != "https" or not host:
212
252
  return False
213
253
  if host in set(lookup.login_hosts(config)) or host in {str(h).lower() for h in also}:
@@ -215,6 +255,36 @@ def may_fill(url: str, config: dict[str, Any], also: tuple[str, ...] = ()) -> bo
215
255
  return any(host == domain or host.endswith("." + domain) for domain in lookup.domains(config))
216
256
 
217
257
 
258
+ #: Login services many schools sign in at (user, 2026-11-28): a school's page when, in this sign-in, the hop just before
259
+ #: it was the school's own login server, or a shared service this sign-in already counts as the school's (user,
260
+ #: 2026-11-30: Microsoft's page sending the account on to the school's Okta); never when reached from anywhere else.
261
+ SHARED_LOGIN_HOSTS = ("login.microsoftonline.com", "login.microsoft.com", "accounts.google.com")
262
+ SHARED_LOGIN_SUFFIXES = (".okta.com", ".okta-emea.com")
263
+
264
+
265
+ def shared_login_host(url: str) -> str:
266
+ """The host of ``url`` when it is one of the shared login services on https, else ""."""
267
+ parsed = urlparse(str(url or ""))
268
+ host = (parsed.hostname or "").lower()
269
+ if parsed.scheme == "https" and (host in SHARED_LOGIN_HOSTS or host.endswith(SHARED_LOGIN_SUFFIXES)):
270
+ return host
271
+ return ""
272
+
273
+
274
+ def note_shared_login(previous_host: str, url: str, config: dict[str, Any], also: tuple[str, ...], seen: set) -> None:
275
+ """A main-frame hop to a shared login service (``url``) straight from the school's own login server
276
+ (``previous_host``: one of its registered hosts or domains, ``may_fill``'s), or from a shared service already in
277
+ ``seen``: that service's host added to ``seen``, the hosts this sign-in may fill in on too (two schools,
278
+ 2026-11-28: their Shibboleth sends to Microsoft's login page; a school, 2026-11-30:
279
+ Microsoft's page sends the account on to the school's Okta)."""
280
+ shared = shared_login_host(url)
281
+ previous = str(previous_host or "").lower()
282
+ if not shared or not previous:
283
+ return
284
+ if previous in seen or (not shared_login_host(f"https://{previous}/") and may_fill(f"https://{previous}/", config, also)):
285
+ seen.add(shared)
286
+
287
+
218
288
  def pro_login_hosts(pro: Any, entity_id: str) -> tuple[str, ...]:
219
289
  """Pro's hosts for this school's login page on another domain of its own (``may_fill``'s ``also``);
220
290
  none from a Pro without them."""
@@ -225,6 +295,16 @@ def pro_login_hosts(pro: Any, entity_id: str) -> tuple[str, ...]:
225
295
  return ()
226
296
 
227
297
 
298
+ def pro_plain_hosts(pro: Any, entity_id: str) -> tuple[str, ...]:
299
+ """Pro's hosts for this school's login page on plain http (``may_fill``'s ``plain``); none from a
300
+ Pro without them."""
301
+ hosts = getattr(pro, "plain_hosts", None)
302
+ try:
303
+ return tuple(str(h).strip().lower() for h in (hosts(entity_id) if callable(hosts) else ()) if str(h).strip())
304
+ except Exception:
305
+ return ()
306
+
307
+
228
308
  # -- a login page whose certificate has expired or is not trusted ---------------------------------
229
309
  # Some schools' login pages serve a certificate Chrome will not take (one ran out in 2022;
230
310
  # others are issued by an authority Chrome does not trust): Chrome stops at its warning. For those
@@ -250,6 +330,9 @@ def page_certificate(page: Any, wait: float = 2.0) -> tuple[str, str]:
250
330
  import base64
251
331
  import hashlib
252
332
 
333
+ from .browser import watchdog
334
+ watchdog.install()
335
+
253
336
  try:
254
337
  session = page.context.new_cdp_session(page)
255
338
  except Exception:
@@ -265,7 +348,12 @@ def page_certificate(page: Any, wait: float = 2.0) -> tuple[str, str]:
265
348
  return "?", ""
266
349
  finally:
267
350
  try:
268
- session.detach()
351
+ # 2026-11-27: CDP detach after a certificate warning can never reply.
352
+ # The certificate was already read; only abandon the optional cleanup.
353
+ with watchdog.call_limit(1.0):
354
+ session.detach()
355
+ except watchdog.CallAbandoned:
356
+ log.warning("Certificate session cleanup timed out; browser context will release it")
269
357
  except Exception:
270
358
  pass
271
359
  if not seen:
@@ -389,11 +477,85 @@ class Attempt:
389
477
  #: Set by Pro on ``needs_user``: the kind of check the school's page asks the user for (image_code,
390
478
  #: slider, click_select, sms_code, qr_scan, site_check, second_factor), for the note the user reads.
391
479
  asks: str = ""
480
+ strict_reply: bool = False
481
+ blocked_entry: dict = field(default_factory=dict)
482
+ #: Transport only: image bytes and task options; Pro owns reading and retry rules.
483
+ ask_code: Callable[..., str] | None = field(default=None, repr=False)
484
+ #: A reCAPTCHA, hCaptcha or Turnstile box on the school's page passed by the publishers' handlers (check_passer);
485
+ #: Pro calls it with the page, True when the box holds its token. None without a verification service.
486
+ pass_check: Callable[[Any], bool] | None = field(default=None, repr=False)
487
+ #: A sign-in chooser on the way (OpenAthens's "Choose how to sign in"; user, 2026-11-29): the way chosen for this
488
+ #: school before (pressed again), the user asked in the progress window (the ways' names and whether the chooser
489
+ #: is still up -> the way's index, -1 once pressed in the browser itself, None when not chosen), the choice kept.
490
+ way: str = ""
491
+ choose_way: Callable[[list[str], Callable[[], bool]], int | None] | None = field(default=None, repr=False)
492
+ remember_way: Callable[[str], None] | None = field(default=None, repr=False)
392
493
 
393
494
  def __repr__(self) -> str: # never the account, not even in a traceback's locals
394
495
  return "Attempt(<hidden>)"
395
496
 
396
497
 
498
+ #: How long the verification service may take over one box on a school's sign-in page.
499
+ SCHOOL_CHECK_SEC = 90.0
500
+ #: A passed box's token, in the page's form (reCAPTCHA, hCaptcha, Turnstile).
501
+ _CHECK_TOKEN_JS = """() => [...document.querySelectorAll('[name="g-recaptcha-response"], [name="h-captcha-response"], '
502
+ + '[name="cf-turnstile-response"]')].some(el => (el.value || '').length > 20)"""
503
+
504
+
505
+ def check_passer(config: dict[str, Any], budget: Any, note: Callable[[str], None],
506
+ checkpoint: Callable[[], None] | None = None) -> Callable[[Any], bool] | None:
507
+ """The publishers' verification handlers for a reCAPTCHA, hCaptcha or Turnstile box on the school's own sign-in
508
+ page (user, 2026-11-28: a school's page passed as a publisher's is): its checkbox pressed, a picture grid read by
509
+ the user's verification service, until the box holds its token or SCHOOL_CHECK_SEC. Pro's sign-in calls it before
510
+ filling in or once pressed. None when the user has no verification service: the box is the user's, told so."""
511
+ from .browser.challenge.continuation import Expired, Limits, resume
512
+ from .browser.challenge.local import interaction
513
+ from .browser.challenge.services import solver
514
+
515
+ if not solver.configured(config):
516
+ return None
517
+
518
+ def holds_token(page: Any) -> bool:
519
+ for frame in list(getattr(page, "frames", []) or []):
520
+ try:
521
+ if frame.evaluate(_CHECK_TOKEN_JS):
522
+ return True
523
+ except Exception:
524
+ continue
525
+ return False
526
+
527
+ def pass_check(page: Any) -> bool:
528
+ from contextlib import ExitStack
529
+
530
+ kind = interaction.challenge_kind(page)
531
+ if kind not in ("recaptcha", "hcaptcha", "turnstile"):
532
+ note(f"{kind or 'unknown'}: not a box the service passes")
533
+ return False
534
+ deadline = time.monotonic() + SCHOOL_CHECK_SEC
535
+ stop = checkpoint or (lambda: None)
536
+ with ExitStack() as cleanup:
537
+ limits = Limits(deadline, budget if budget is not None else solver.Budget(config=config), stop, cleanup)
538
+ try:
539
+ outcome = interaction.click_checkbox(page, timeout_ms=8_000, checkpoint=stop, observation=note)
540
+ note(f"{kind}: box {outcome}")
541
+ for _ in range(6):
542
+ if holds_token(page):
543
+ return True
544
+ page.wait_for_timeout(500)
545
+ resume(page, config, kind=kind, limits=limits, observation=note)
546
+ while time.monotonic() < deadline:
547
+ if holds_token(page):
548
+ return True
549
+ page.wait_for_timeout(500)
550
+ except Expired:
551
+ pass
552
+ passed = holds_token(page)
553
+ note(f"{kind}: {'passed' if passed else 'not passed'}")
554
+ return passed
555
+
556
+ return pass_check
557
+
558
+
397
559
  def hide(text: str, secrets: tuple[str, ...]) -> str:
398
560
  """``text`` with every secret replaced (an event's detail, defence in depth)."""
399
561
  for secret in secrets:
@@ -188,7 +188,7 @@ def judge(result: dict[str, Any], *, filled: bool, refused: bool) -> dict[str, A
188
188
  else "卡在学校登录这一步;学校的登录页要你自己操作时,在下载浏览器里完成"}
189
189
  if kind == "access_blocked":
190
190
  return {"ok": False, "title": "出版社网站拦住了访问", "detail": "稍后再测,或换一篇"}
191
- if kind == "download_timeout":
191
+ if kind in ("download_timeout", "captcha_required"):
192
192
  return {"ok": False, "title": "没有拿到全文", "detail": "页面或安全验证一直没有完成,换一篇或稍后再测"}
193
193
  if kind == "network_unavailable":
194
194
  return {"ok": False, "title": "网络不通", "detail": "检查网络后再测"}
@@ -8,6 +8,8 @@ Contract (see PaperSearch docs/dependencies/school-backend.zh.md):
8
8
  (use_vpnsci is still accepted from older callers and ignored)
9
9
  -> school_batch_progress(batch_id, total, done, succeeded, failed, current, finished)
10
10
  optional: keeps the progress window on "k / N" for a caller's serial batch
11
+ -> school_download(..., keep_browser=true, window=k, parallel=true): a batch downloading several papers at once,
12
+ each in a window of its own of the one browser (并行下载); school_close_window(k) when one is no longer needed
11
13
 
12
14
  Tool names carry the ``school_`` prefix; ``serverInfo.name`` is ``paper-search-school``.
13
15
  Every fetched page and tool result is untrusted external content.
@@ -17,6 +19,7 @@ from __future__ import annotations
17
19
  import asyncio
18
20
  import json
19
21
  import re
22
+ import threading
20
23
  import time
21
24
  from functools import partial
22
25
  from typing import Any, Literal
@@ -50,16 +53,109 @@ _DOI_RE = re.compile(r"10\.\d{4,9}/[-._;()/:A-Z0-9]+", re.I)
50
53
  _batch_browser = BatchBrowser()
51
54
  # Its tab answers between papers too (BatchThread, BatchBrowser.pump).
52
55
  _batch_worker = BatchThread(_batch_browser.pump)
53
-
54
-
55
- def _with_batch_browser(batch_id: str, operation) -> str:
56
- if _batch_browser.id != batch_id:
57
- _batch_browser.close()
58
- _batch_browser.id = batch_id
59
- token = active_batch.set(_batch_browser)
56
+ # 并行下载 (user, 2026-11-29): a batch's other windows, each with its browser connection and its thread (1, 2, ...).
57
+ _other_windows: dict[int, tuple[BatchBrowser, BatchThread]] = {}
58
+ _windows_lock = threading.Lock()
59
+
60
+
61
+ def _window(window: int | None) -> tuple[BatchBrowser, BatchThread]:
62
+ """The batch's window ``window`` (0 or None: the first, which launches the browser) and its thread."""
63
+ if not window or window < 0:
64
+ return _batch_browser, _batch_worker
65
+ with _windows_lock:
66
+ found = _other_windows.get(window)
67
+ if found is None:
68
+ browser = BatchBrowser(window, first=_batch_browser)
69
+ found = _other_windows[window] = (browser, BatchThread(browser.pump, name=f"school-batch-{window}"))
70
+ return found
71
+
72
+
73
+ def _close_other_windows() -> None:
74
+ """The other windows' drivers leave, each on its own thread, before the first window's browser closes."""
75
+ with _windows_lock:
76
+ others = list(_other_windows.values())
77
+ _other_windows.clear()
78
+ for browser, worker in others:
79
+ try:
80
+ worker.submit(browser.disconnect).result(timeout=60)
81
+ except Exception:
82
+ pass
83
+ worker.shutdown(wait=False)
84
+
85
+
86
+ def _close_batch_browser() -> None:
87
+ """On the first window's thread: every window of the batch closed, its downloads' folder removed."""
88
+ from .browser.batch_session import forget_downloads
89
+
90
+ _close_other_windows()
91
+ downloads = _batch_browser.downloads
92
+ _batch_browser.close()
93
+ _batch_browser.downloads = ""
94
+ _batch_browser.parallel = False
95
+ if downloads:
96
+ forget_downloads(downloads)
97
+
98
+
99
+ def _parallel_batch(parallel: bool, window_given: bool) -> bool:
100
+ """Whether a batch beginning runs its papers at once: its client says so, or, its first paper coming in a window
101
+ before the client knows (``window_given``), the settings' 同时下载 says so and the browser can have windows."""
102
+ if parallel:
103
+ return True
104
+ if not window_given:
105
+ return False
106
+ from . import user_settings
107
+ from .browser.backend import supports
108
+
109
+ numbers = user_settings.parallel()
110
+ return numbers["publishers"] * numbers["per_publisher"] > 1 and supports("parallel_windows", load_config())
111
+
112
+
113
+ def _with_batch_browser(batch_id: str, operation, window: int | None = None, parallel: bool = False,
114
+ window_given: bool = False) -> str:
115
+ """``operation`` in the batch's window ``window`` (on that window's thread): its browser the one the engine uses
116
+ (``active_batch``), and, for a batch whose papers run at once (decided at its first download, ``_parallel_batch``),
117
+ the window that takes turns asking for the user and keeps its paper on the progress card."""
118
+ from . import progress_reporter
119
+ from .browser import user_turn, watchdog
120
+
121
+ with _windows_lock:
122
+ another = _batch_browser.id != batch_id
123
+ if another:
124
+ # One batch's windows at a time: the next batch's first download closes the last one's (the client
125
+ # closes them at a batch's end, and a batch is one backend process: this is the exception).
126
+ # The last batch's browser, or a window's connection to it, still there. Not this batch's windows taken
127
+ # just now for their threads (school_download, ``_window``): window 1 coming in before window 0 took its
128
+ # own for the last batch's, left the batch not running papers at once and waited on window 0's thread to
129
+ # close it, busy with the first paper. Window 0 then opened Chrome for one paper after another, with no
130
+ # remote-debugging port; windows 2 to 5 waited 180 s to join it and failed (Windows, 2026-11-30).
131
+ open_before = _batch_browser.context is not None or any(
132
+ browser.context is not None for browser, _ in _other_windows.values())
133
+ _batch_browser.id = batch_id
134
+ at_once = _parallel_batch(parallel, window_given)
135
+ if not open_before:
136
+ _batch_browser.parallel = at_once
137
+ if another:
138
+ if open_before:
139
+ if window:
140
+ _batch_worker.submit(_close_batch_browser).result()
141
+ else:
142
+ _close_batch_browser()
143
+ _batch_browser.parallel = at_once
144
+ user_turn.start(at_once)
145
+ browser, _ = _window(window)
146
+ # A call of this window's last paper ran past its time and ended that paper alone (browser/watchdog.py): the
147
+ # next one here starts on a page of its own.
148
+ if watchdog.in_window(_batch_browser.parallel):
149
+ browser.page = None
150
+ token = active_batch.set(browser)
151
+ turn = user_turn.bind(window or 0)
152
+ shown = progress_reporter.bind_window((window or 0) if _batch_browser.parallel else None)
60
153
  try:
61
154
  return operation()
62
155
  finally:
156
+ user_turn.release_all()
157
+ progress_reporter.unbind_window(shown)
158
+ user_turn.unbind(turn)
63
159
  active_batch.reset(token)
64
160
 
65
161
 
@@ -173,6 +269,8 @@ async def _school_download_with_progress(
173
269
  title: str | None = None,
174
270
  fulltext: Literal["with", "only"] | None = None,
175
271
  school: str | None = None,
272
+ window: int | None = None,
273
+ parallel: bool = False,
176
274
  ctx: Context = None,
177
275
  ) -> str:
178
276
  """Download one paper by DOI through institutional access only.
@@ -211,6 +309,12 @@ async def _school_download_with_progress(
211
309
  user_wait: "short" when the user seems away (an earlier article of the batch waited on them
212
310
  until its time was up): each wait on the user (school login, human verification) lasts at
213
311
  most 60 s, unless someone starts typing on the login page.
312
+
313
+ window, parallel (并行下载): with keep_browser, a batch downloading several papers at once
314
+ (parallel=true on each of its downloads) runs each in its window ``window`` (0, 1, 2 …) of the
315
+ one browser, every window with a driver and a thread of its own; window 0 launches the browser.
316
+ One window at a time asks for the user (school login, a verification to complete); the others
317
+ go on meanwhile. school_close_window closes a window no longer needed.
214
318
  """
215
319
  from .mcp_progress import run_with_progress
216
320
 
@@ -220,25 +324,47 @@ async def _school_download_with_progress(
220
324
  batch_failed=batch_failed, supplements=supplements, user_wait=user_wait,
221
325
  diagnostics_dir=diagnostics_dir, title=title, fulltext=fulltext, school=school)
222
326
  if keep_browser and batch_id:
223
- return await run_with_progress(ctx, identifier, partial(_with_batch_browser, batch_id, operation),
224
- executor=_batch_worker)
327
+ given = isinstance(window, int) and not isinstance(window, bool)
328
+ number = window if given and window > 0 else 0
329
+ return await run_with_progress(ctx, identifier, partial(_with_batch_browser, batch_id, operation, number,
330
+ bool(parallel), given),
331
+ executor=_window(number)[1])
225
332
  return await run_with_progress(ctx, identifier, operation)
226
333
 
227
334
 
228
335
  @mcp_app.tool()
229
336
  async def school_close_batch_browser() -> str:
230
- """Close the window retained by this client's serial download batch."""
231
- await asyncio.get_running_loop().run_in_executor(_batch_worker, _batch_browser.close)
337
+ """Close the window retained by this client's serial download batch (every window of a batch whose papers ran at
338
+ once)."""
339
+ await asyncio.get_running_loop().run_in_executor(_batch_worker, _close_batch_browser)
232
340
  return json.dumps({"closed": True})
233
341
 
234
342
 
235
343
  @mcp_app.tool()
236
- async def school_keep_session() -> str:
344
+ async def school_close_window(window: int) -> str:
345
+ """并行下载: close window ``window`` (1, 2 …) of a batch whose papers run at once, no longer needed (fewer
346
+ publishers left than its windows): its pages go, its driver stays until the batch ends. The first window, which
347
+ holds the browser, stays open. Answers {"closed": bool}."""
348
+ if not isinstance(window, int) or isinstance(window, bool) or window <= 0:
349
+ return json.dumps({"closed": False})
350
+ with _windows_lock:
351
+ found = _other_windows.get(window)
352
+ if found is None:
353
+ return json.dumps({"closed": False})
354
+ browser, worker = found
355
+ await asyncio.get_running_loop().run_in_executor(worker, browser.close)
356
+ return json.dumps({"closed": True})
357
+
358
+
359
+ @mcp_app.tool()
360
+ async def school_keep_session(window: int = 0) -> str:
237
361
  """While a serial batch waits (the publisher's hourly limit the user set), load the
238
- last paper's article page again in the batch's window, so the publisher's
239
- institutional session does not lapse. Opens no browser; does nothing after a paper
240
- that did not save its PDF. Answers {"kept": true} or {"kept": false, "reason": ...}."""
241
- result = await asyncio.get_running_loop().run_in_executor(_batch_worker, _batch_browser.keep_session)
362
+ last paper's article page again in the batch's window (``window`` of a batch whose
363
+ papers run at once), so the publisher's institutional session does not lapse. Opens no
364
+ browser; does nothing after a paper that did not save its PDF. Answers {"kept": true} or
365
+ {"kept": false, "reason": ...}."""
366
+ browser, worker = _window(window if isinstance(window, int) and not isinstance(window, bool) else 0)
367
+ result = await asyncio.get_running_loop().run_in_executor(worker, browser.keep_session)
242
368
  return json.dumps(result)
243
369
 
244
370
 
@@ -247,15 +373,35 @@ def school_switch_state() -> str:
247
373
  """The schools a batch's papers without access (没权限) are tried with at its end, one after another
248
374
  (没权限时换下一所学校, school_switch.py): the default one first, each named as ``school_download``'s ``school``
249
375
  takes it (its entityID); none while the switch is off; and whether the batch takes one journal's papers one after
250
- another (``group``: on and more than one school). Opens no browser. Answers
251
- {"on": bool, "schools": [{"name": ..., "entity_id": ...}, ...], "group": bool}."""
252
- from . import school_switch
376
+ another (``group``: on and more than one school); and whether 失败后自动重试 is on (``retry``, user_settings). Opens no
377
+ browser. Answers {"on": bool, "schools": [{"name": ..., "entity_id": ...}, ...], "group": bool, "retry": bool,
378
+ "parallel": {"publishers": n, "per_publisher": n, "prefixes": {DOI prefix: publisher}}} (同时下载, _parallel_state)."""
379
+ from . import school_switch, user_settings
253
380
 
254
381
  config = load_config()
255
382
  on = school_switch.enabled(config)
256
383
  schools = [{"name": school_switch.name(entry), "entity_id": str(entry.get("idp_entity_id") or "").strip()}
257
384
  for entry in school_switch.schools(config)] if on else []
258
- return json.dumps({"on": on, "schools": schools, "group": on and len(schools) > 1}, ensure_ascii=False)
385
+ return json.dumps({"on": on, "schools": schools, "group": on and len(schools) > 1,
386
+ "retry": config.get(user_settings.RETRY_KEY) is True, "parallel": _parallel_state(config)},
387
+ ensure_ascii=False)
388
+
389
+
390
+ def _parallel_state(config: dict[str, Any]) -> dict[str, Any]:
391
+ """同时下载 (the settings' 下载 page): publishers at once and papers of one publisher at once, 1 and 1 when serial
392
+ or when the browser cannot have a window for each (only Chrome launched by the backend can); and each DOI prefix's
393
+ publisher by the backend's table, so that the batch counts one publisher's prefixes as one (Springer Nature's
394
+ 10.1007, 10.1038, 10.1186)."""
395
+ from . import user_settings
396
+ from .browser.backend import supports
397
+ from .publishers.profiles import PUBLISHER_PROFILES
398
+
399
+ serial = {"publishers": 1, "per_publisher": 1}
400
+ numbers = user_settings.parallel() if supports("parallel_windows", config) else serial
401
+ if _batch_browser.id and not _batch_browser.parallel:
402
+ numbers = serial # the batch's browser opened for one paper after another: it goes on so
403
+ prefixes = {prefix: profile.name for profile in PUBLISHER_PROFILES.values() for prefix in profile.doi_prefixes}
404
+ return {**numbers, "prefixes": prefixes}
259
405
 
260
406
 
261
407
  @mcp_app.tool()
@@ -293,6 +439,8 @@ def school_batch_progress(
293
439
  lanes: str = "",
294
440
  held: list[dict[str, Any]] | None = None,
295
441
  held_wait: bool = False,
442
+ later: dict[str, Any] | None = None,
443
+ switch_to: str = "",
296
444
  ) -> str:
297
445
  """Update the progress window of a serial batch without downloading.
298
446
 
@@ -310,12 +458,20 @@ def school_batch_progress(
310
458
  running download of the batch too: then only the counts and this line change.
311
459
 
312
460
  held: the publishers whose papers the caller holds because their school login stopped
313
- working mid-batch, [{key (DOI prefix), name, count}]; the window shows them with a
461
+ working mid-batch, [{key (its name, else its DOI prefix), name, count}]; the window shows them with a
314
462
  button to go on. The answer's "resume" lists those the user asked to go on with since
315
463
  the last report (each once), and "stop" whether the user ended the batch in the window
316
464
  (a batch waiting for the user downloads nothing that would hear of it).
317
465
  held_wait: nothing is left but the held publishers' papers and the batch waits for the
318
466
  user (登录并继续 or 终止); the window says so, collapsed too.
467
+
468
+ later: the papers whose first try failed and that the caller tries again later, by why:
469
+ {no_access (the next saved school at the end), unexplained (once more at the end), blocked
470
+ (their site blocked them; tried again at blocked_at, epoch seconds), login (their school login
471
+ lapsed; waiting for 登录并继续), papers: {each kind: its papers' DOIs}}; the window's ring shows them
472
+ beside the papers done, and its 重试 count and list.
473
+ switch_to: the saved school the caller now tries its papers without access with; the window
474
+ names it for a few seconds.
319
475
  """
320
476
  from . import entitlements, progress_reporter
321
477
 
@@ -323,7 +479,7 @@ def school_batch_progress(
323
479
  updated = progress_reporter.sync_batch(batch_id, total, done, succeeded, failed,
324
480
  current=label, finished=finished, results=results,
325
481
  phase=phase, channel=channel, lanes=lanes, held=held,
326
- held_wait=held_wait)
482
+ held_wait=held_wait, later=later, switch_to=switch_to)
327
483
  stop = entitlements.batch_stop_requested() and (progress_reporter.read_state() or {}).get("batch_id") == batch_id
328
484
  return json.dumps({"updated": updated, "resume": entitlements.take_resumes(batch_id), "stop": bool(stop)})
329
485
 
@@ -373,7 +529,7 @@ def main() -> None:
373
529
  mcp_app.run()
374
530
  finally:
375
531
  try:
376
- _batch_worker.submit(_batch_browser.close).result()
532
+ _batch_worker.submit(_close_batch_browser).result()
377
533
  finally:
378
534
  _batch_worker.shutdown()
379
535
 
@@ -1,5 +1,5 @@
1
- """The progress window's wait limits, page inactivity reminder delay, and
2
- publisher hourly limit. Saved values apply to subsequent papers."""
1
+ """The progress window's wait limits, page inactivity reminder delay, publisher
2
+ hourly limit and parallel downloads. Saved values apply to subsequent papers."""
3
3
 
4
4
  from __future__ import annotations
5
5
 
@@ -15,9 +15,9 @@ class Field:
15
15
  key: str # the backend's config key
16
16
  default: int
17
17
  low: int
18
- high: int
18
+ high: int | None # None: no upper bound
19
19
  unit: str
20
- page: str # the settings page it is on: "download" or "wait"
20
+ page: str # the settings page it is on: "download" or "wait"; "parallel" for 同时下载's two numbers (download page)
21
21
 
22
22
 
23
23
  FIELDS = (
@@ -25,6 +25,10 @@ FIELDS = (
25
25
  Field("page", "其他页面最多等", "browser_page_wait_timeout", 60, 10, 600, "秒", "wait"),
26
26
  Field("stalled", "提醒你操作前最多等", "browser_stall_notify_after", 30, 1, 600, "秒", "wait"),
27
27
  Field("hourly", "每家出版社每小时最多", "publisher_hourly_limit", 100, 0, 1000, "篇", "download"),
28
+ # 同时下载 when parallel (user, 2026-11-29): publishers at once and papers of one publisher at once; at least 1, no
29
+ # upper bound (the user: none set), 1 by default. Shown on the 下载 page under 同时下载, not as rows of their own.
30
+ Field("pubs", "不同出版社", "batch_parallel_publishers", 1, 1, None, "家", "parallel"),
31
+ Field("each", "同一出版社", "batch_parallel_per_publisher", 1, 1, None, "篇", "parallel"),
28
32
  )
29
33
 
30
34
 
@@ -40,6 +44,10 @@ def check(field: Field, text: str) -> tuple[int | None, str]:
40
44
  value = int(str(text).strip())
41
45
  except ValueError:
42
46
  value = None
47
+ if field.high is None:
48
+ if value is None or value < field.low:
49
+ return None, f"请输入不小于 {field.low} 的整数"
50
+ return value, ""
43
51
  if value is None or not field.low <= value <= field.high:
44
52
  return None, f"请输入 {field.low} 到 {field.high} 之间的整数"
45
53
  return value, ""
@@ -81,6 +89,19 @@ def set_hourly_now(on: bool) -> None:
81
89
  _config.update_config(HOURLY_NOW_KEY, "true" if on else "false")
82
90
 
83
91
 
92
+ RETRY_KEY = "batch_retry_failed"
93
+
94
+
95
+ def retry_enabled() -> bool:
96
+ """失败后自动重试 (the 等待和提醒 page; user, 2026-11-24: off by default): a batch tries its 原因不明 papers once more at
97
+ its end, and a publisher whose site blocked it once more after a pause (download/batch/batch.ts)."""
98
+ return _config.load_config().get(RETRY_KEY) is True
99
+
100
+
101
+ def set_retry(on: bool) -> None:
102
+ _config.update_config(RETRY_KEY, "true" if on else "false")
103
+
104
+
84
105
  LANGUAGE_KEY = "progress_language"
85
106
 
86
107
 
@@ -97,3 +118,24 @@ def set_language(lang: str) -> None:
97
118
 
98
119
  _config.update_config(LANGUAGE_KEY, lang if lang in i18n.LANGUAGES else "zh")
99
120
 
121
+
122
+
123
+ PARALLEL_KEY = "batch_parallel"
124
+
125
+
126
+ def parallel_enabled() -> bool:
127
+ """同时下载 (the 下载 page; user, 2026-11-29: serial by default): a batch's browser lane downloads several papers at
128
+ once, each in a window of its own (download/batch/windowPlan.ts), up to the two numbers ``parallel``."""
129
+ return _config.load_config().get(PARALLEL_KEY) is True
130
+
131
+
132
+ def set_parallel(on: bool) -> None:
133
+ _config.update_config(PARALLEL_KEY, "true" if on else "false")
134
+
135
+
136
+ def parallel() -> dict[str, int]:
137
+ """What a batch runs at once: ``publishers`` (不同出版社) × ``per_publisher`` (同一出版社); 1 and 1 when serial."""
138
+ if not parallel_enabled():
139
+ return {"publishers": 1, "per_publisher": 1}
140
+ values = current()
141
+ return {"publishers": max(1, values["pubs"]), "per_publisher": max(1, values["each"])}
@@ -5,6 +5,7 @@ description = "Institutional (publisher-authorized) PDF and supplementary-file d
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
7
7
  license = "AGPL-3.0-only"
8
+ authors = [{ name = "Yu Xie" }]
8
9
  license-files = ["LICENSE", "LICENSE-scansci-pdf", "NOTICE"]
9
10
  # Ranges below the next major version; the browser driver is pinned (ADR 0013, 0016).
10
11
  dependencies = [