papersearch 0.7.3 → 0.8.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.
- package/LICENSE-paper-search-mcp-nodejs +24 -0
- package/NOTICE +8 -37
- package/README.en.md +7 -3
- package/README.fr.md +268 -0
- package/README.ja.md +268 -0
- package/README.ko.md +268 -0
- package/README.md +7 -3
- package/README.zh-Hant.md +268 -0
- package/dist/capabilities/download/batch/batch.d.ts +16 -1
- package/dist/capabilities/download/batch/batch.d.ts.map +1 -1
- package/dist/capabilities/download/batch/batch.js +389 -56
- package/dist/capabilities/download/batch/batch.js.map +1 -1
- package/dist/capabilities/download/batch/batchFolder.d.ts.map +1 -1
- package/dist/capabilities/download/batch/batchFolder.js +3 -2
- package/dist/capabilities/download/batch/batchFolder.js.map +1 -1
- package/dist/capabilities/download/batch/networkLoss.d.ts +11 -2
- package/dist/capabilities/download/batch/networkLoss.d.ts.map +1 -1
- package/dist/capabilities/download/batch/networkLoss.js +24 -3
- package/dist/capabilities/download/batch/networkLoss.js.map +1 -1
- package/dist/capabilities/download/batch/resume.d.ts +7 -0
- package/dist/capabilities/download/batch/resume.d.ts.map +1 -1
- package/dist/capabilities/download/batch/resume.js +50 -9
- package/dist/capabilities/download/batch/resume.js.map +1 -1
- package/dist/capabilities/download/content/markdown/pro.d.ts +6 -0
- package/dist/capabilities/download/content/markdown/pro.d.ts.map +1 -1
- package/dist/capabilities/download/content/markdown/pro.js.map +1 -1
- package/dist/capabilities/download/content/markdown/shortfall.d.ts +8 -5
- package/dist/capabilities/download/content/markdown/shortfall.d.ts.map +1 -1
- package/dist/capabilities/download/content/markdown/shortfall.js +22 -10
- package/dist/capabilities/download/content/markdown/shortfall.js.map +1 -1
- package/dist/capabilities/download/content/markdown/step.d.ts +9 -0
- package/dist/capabilities/download/content/markdown/step.d.ts.map +1 -1
- package/dist/capabilities/download/content/markdown/step.js +42 -2
- package/dist/capabilities/download/content/markdown/step.js.map +1 -1
- package/dist/capabilities/download/content/markdown/types.d.ts +10 -1
- package/dist/capabilities/download/content/markdown/types.d.ts.map +1 -1
- package/dist/capabilities/download/handler.d.ts.map +1 -1
- package/dist/capabilities/download/handler.js +13 -5
- package/dist/capabilities/download/handler.js.map +1 -1
- package/dist/capabilities/download/outputLayout.d.ts.map +1 -1
- package/dist/capabilities/download/outputLayout.js +3 -1
- package/dist/capabilities/download/outputLayout.js.map +1 -1
- package/dist/capabilities/download/tools.js +2 -2
- package/dist/capabilities/download/tools.js.map +1 -1
- package/dist/capabilities/download/types.d.ts +9 -1
- package/dist/capabilities/download/types.d.ts.map +1 -1
- package/dist/cli.js +3 -1
- package/dist/cli.js.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.d.ts +7 -0
- package/dist/infrastructure/runlog/RunLedger.d.ts.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.js +13 -0
- package/dist/infrastructure/runlog/RunLedger.js.map +1 -1
- package/dist/infrastructure/runlog/failureClass.d.ts +2 -1
- package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
- package/dist/infrastructure/runlog/failureClass.js +27 -4
- package/dist/infrastructure/runlog/failureClass.js.map +1 -1
- package/dist/infrastructure/school/SchoolAttempt.d.ts +11 -0
- package/dist/infrastructure/school/SchoolAttempt.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolAttempt.js +48 -5
- package/dist/infrastructure/school/SchoolAttempt.js.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.d.ts +1 -0
- package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.js +18 -6
- package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -1
- package/dist/infrastructure/school/SchoolProgress.d.ts +2 -0
- package/dist/infrastructure/school/SchoolProgress.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolProgress.js +2 -0
- package/dist/infrastructure/school/SchoolProgress.js.map +1 -1
- package/dist/infrastructure/school/SchoolReadiness.d.ts +2 -0
- package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolReadiness.js +2 -0
- package/dist/infrastructure/school/SchoolReadiness.js.map +1 -1
- package/dist/infrastructure/school/SchoolResultNormalizer.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolResultNormalizer.js +4 -0
- package/dist/infrastructure/school/SchoolResultNormalizer.js.map +1 -1
- package/dist/infrastructure/school/index.d.ts +2 -2
- package/dist/infrastructure/school/index.d.ts.map +1 -1
- package/dist/infrastructure/school/index.js +1 -1
- package/dist/infrastructure/school/index.js.map +1 -1
- package/dist/infrastructure/school/types.d.ts +42 -0
- package/dist/infrastructure/school/types.d.ts.map +1 -1
- package/dist/infrastructure/school/types.js.map +1 -1
- package/dist/management/failures/index.d.ts +23 -0
- package/dist/management/failures/index.d.ts.map +1 -1
- package/dist/management/failures/index.js +63 -18
- package/dist/management/failures/index.js.map +1 -1
- package/package.json +7 -2
- package/school/NOTICE +3 -2
- package/school/paper_search_school/adapters/__init__.py +2 -0
- package/school/paper_search_school/adapters/aps/__init__.py +3 -6
- package/school/paper_search_school/adapters/base.py +16 -2
- package/school/paper_search_school/adapters/copernicus/__init__.py +2 -7
- package/school/paper_search_school/adapters/elsevier/__init__.py +50 -1
- package/school/paper_search_school/adapters/frontiers/__init__.py +41 -2
- package/school/paper_search_school/adapters/ieee/__init__.py +6 -4
- package/school/paper_search_school/adapters/iop/__init__.py +8 -0
- package/school/paper_search_school/adapters/jama/__init__.py +8 -0
- package/school/paper_search_school/adapters/lww/__init__.py +14 -6
- package/school/paper_search_school/adapters/mdpi/__init__.py +12 -7
- package/school/paper_search_school/adapters/neurology/__init__.py +5 -2
- package/school/paper_search_school/adapters/optica/__init__.py +2 -9
- package/school/paper_search_school/adapters/oup/__init__.py +7 -4
- package/school/paper_search_school/adapters/platforms/__init__.py +4 -1
- package/school/paper_search_school/adapters/platforms/atypon/__init__.py +8 -0
- package/school/paper_search_school/adapters/platforms/jstage/__init__.py +64 -0
- package/school/paper_search_school/adapters/taylor_francis/__init__.py +0 -3
- package/school/paper_search_school/adapters/thieme/__init__.py +2 -9
- package/school/paper_search_school/api_keys.py +63 -13
- package/school/paper_search_school/assets/api_keys.json +14 -0
- package/school/paper_search_school/assets/capsule.html +156 -116
- package/school/paper_search_school/assets/capsule_en.json +69 -46
- package/school/paper_search_school/assets/capsule_fr.json +70 -47
- package/school/paper_search_school/assets/capsule_ja.json +69 -46
- package/school/paper_search_school/assets/capsule_ko.json +69 -46
- package/school/paper_search_school/assets/capsule_zh-Hant.json +68 -45
- package/school/paper_search_school/browser/batch_session.py +1 -1
- package/school/paper_search_school/browser/challenge/__init__.py +12 -9
- package/school/paper_search_school/browser/challenge/continuation.py +65 -0
- package/school/paper_search_school/browser/challenge/handlers/__init__.py +1 -0
- package/school/paper_search_school/browser/challenge/handlers/aws_waf.py +260 -0
- package/school/paper_search_school/browser/challenge/handlers/recaptcha_hcaptcha.py +167 -0
- package/school/paper_search_school/browser/challenge/handlers/text_captcha.py +100 -0
- package/school/paper_search_school/browser/challenge/handlers/turnstile.py +174 -0
- package/school/paper_search_school/browser/challenge/kinds.py +203 -0
- package/school/paper_search_school/browser/challenge/local/__init__.py +1 -0
- package/school/paper_search_school/browser/challenge/{interaction.py → local/interaction.py} +94 -13
- package/school/paper_search_school/browser/challenge/{pointer.py → local/pointer.py} +2 -2
- package/school/paper_search_school/browser/challenge/local/prompt.py +283 -0
- package/school/paper_search_school/browser/challenge/local/submission.py +33 -0
- package/school/paper_search_school/browser/challenge/services/__init__.py +1 -0
- package/school/paper_search_school/browser/challenge/services/solver.py +272 -0
- package/school/paper_search_school/cli_config.py +10 -5
- package/school/paper_search_school/config.py +11 -10
- package/school/paper_search_school/download_diagnostics.py +7 -2
- package/school/paper_search_school/engine/access_rules.py +12 -3
- package/school/paper_search_school/engine/batch.py +43 -11
- package/school/paper_search_school/engine/batch_access.py +38 -12
- package/school/paper_search_school/engine/batch_capture.py +215 -18
- package/school/paper_search_school/engine/batch_common.py +3 -0
- package/school/paper_search_school/engine/batch_diagnostics.py +25 -5
- package/school/paper_search_school/engine/batch_institution.py +38 -3
- package/school/paper_search_school/engine/batch_login.py +223 -16
- package/school/paper_search_school/engine/batch_pdf_urls.py +38 -7
- package/school/paper_search_school/engine/batch_waits.py +179 -12
- package/school/paper_search_school/engine/bridge.py +28 -4
- package/school/paper_search_school/engine/fulltext_page.py +45 -7
- package/school/paper_search_school/engine/router.py +16 -1
- package/school/paper_search_school/entitlements.py +1 -1
- package/school/paper_search_school/pdf_utils.py +25 -16
- package/school/paper_search_school/progress_capsule.py +36 -6
- package/school/paper_search_school/progress_reporter.py +54 -5
- package/school/paper_search_school/progress_view.py +63 -43
- package/school/paper_search_school/publishers/builtin/iop.json +2 -1
- package/school/paper_search_school/publishers/builtin/neurology.json +4 -2
- package/school/paper_search_school/publishers/site.py +12 -4
- package/school/paper_search_school/school_test.py +1 -1
- package/school/paper_search_school/server.py +17 -6
- package/school/paper_search_school/user_settings.py +13 -0
- package/school/pyproject.toml +1 -0
- package/skills/paper-search/SKILL.md +107 -107
- package/skills/paper-search/references/browser-download.md +102 -99
- package/skills/paper-search/references/capability-routing.md +89 -89
- package/skills/paper-search/references/cli-contract.md +78 -78
- package/skills/paper-search/references/federation-support.md +172 -172
- package/skills/paper-search/references/management-layer.md +78 -78
- package/skills/paper-search/references/publisher-support.md +38 -38
- package/skills/paper-search/references/school-setup.md +56 -55
- package/skills/paper-search/references/setup.md +20 -20
- package/skills/paper-search/references/troubleshooting.md +12 -12
- package/school/paper_search_school/browser/challenge/prompt.py +0 -154
|
@@ -303,6 +303,7 @@ def _adopt_batch(batch_id: str, total: int, counts: tuple[int | None, int | None
|
|
|
303
303
|
_STATE.update(total=int(total), lanes=fields.get("lanes", ""),
|
|
304
304
|
**({"held": fields["held"]} if "held" in fields else {}),
|
|
305
305
|
**({"held_wait": fields["held_wait"]} if "held_wait" in fields else {}),
|
|
306
|
+
**({"later": fields["later"]} if "later" in fields else {}),
|
|
306
307
|
**({"done": done} if done is not None else {}),
|
|
307
308
|
**({"success": succeeded} if succeeded is not None else {}),
|
|
308
309
|
**({"failed": failed} if failed is not None else {}))
|
|
@@ -347,15 +348,22 @@ def _adopt_batch(batch_id: str, total: int, counts: tuple[int | None, int | None
|
|
|
347
348
|
return True
|
|
348
349
|
|
|
349
350
|
|
|
350
|
-
|
|
351
|
+
def _held_key(value: Any) -> str:
|
|
352
|
+
"""A held publisher's key as the caller sent it, which 登录并继续 sends back unchanged: the
|
|
353
|
+
publisher's name ("Science"), else its DOI prefix ("10.1126/"); empty when it is not one short line.
|
|
354
|
+
The batch keys them by name since 2026-11-17 (a publisher's other DOI prefixes wait with it); a
|
|
355
|
+
check for DOI prefixes alone dropped every one of them, and the window showed no 登录并继续 (2026-11-23)."""
|
|
356
|
+
if not isinstance(value, str) or not 0 < len(value) <= 120 or not value.isprintable() or value != value.strip():
|
|
357
|
+
return ""
|
|
358
|
+
return value
|
|
351
359
|
|
|
352
360
|
|
|
353
361
|
def _held(raw: Any) -> list[dict[str, Any]]:
|
|
354
362
|
"""The publishers whose papers the caller holds (their school login stopped working
|
|
355
|
-
mid-batch): [{key (
|
|
363
|
+
mid-batch): [{key (``_held_key``), name, count}], at most four, checked for the window."""
|
|
356
364
|
held: list[dict[str, Any]] = []
|
|
357
365
|
for entry in raw if isinstance(raw, list) else []:
|
|
358
|
-
if not isinstance(entry, dict) or not
|
|
366
|
+
if not isinstance(entry, dict) or not _held_key(entry.get("key")):
|
|
359
367
|
continue
|
|
360
368
|
count = entry.get("count")
|
|
361
369
|
if not isinstance(count, int) or isinstance(count, bool) or not 0 < count <= 1_000_000:
|
|
@@ -365,10 +373,35 @@ def _held(raw: Any) -> list[dict[str, Any]]:
|
|
|
365
373
|
return held[:4]
|
|
366
374
|
|
|
367
375
|
|
|
376
|
+
#: Why the caller holds a paper for a later try (``sync_batch``'s ``later``).
|
|
377
|
+
LATER_KINDS = ("no_access", "unexplained", "blocked", "login")
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def _later(raw: Any) -> dict[str, Any]:
|
|
381
|
+
"""The papers the caller holds for a later try, by why (LATER_KINDS), and when the blocked ones are tried
|
|
382
|
+
again (``blocked_at``, epoch seconds), checked for the window."""
|
|
383
|
+
raw = raw if isinstance(raw, dict) else {}
|
|
384
|
+
|
|
385
|
+
def count(value: Any) -> int:
|
|
386
|
+
return value if isinstance(value, int) and not isinstance(value, bool) and 0 <= value <= _MAX_BATCH_PAPERS else 0
|
|
387
|
+
|
|
388
|
+
later: dict[str, Any] = {kind: count(raw.get(kind)) for kind in LATER_KINDS}
|
|
389
|
+
at = raw.get("blocked_at")
|
|
390
|
+
if later["blocked"] and isinstance(at, (int, float)) and not isinstance(at, bool) and at > 0:
|
|
391
|
+
later["blocked_at"] = float(at)
|
|
392
|
+
# Each kind's papers by DOI (user, 2026-11-24: the window's 重试 list names them; 剩余 lists the others), as many as
|
|
393
|
+
# it counts at most; none from a caller that does not send them.
|
|
394
|
+
papers = raw.get("papers")
|
|
395
|
+
if isinstance(papers, dict):
|
|
396
|
+
later["papers"] = {kind: [doi for doi in papers.get(kind) if isinstance(doi, str) and 0 < len(doi) <= 300][:later[kind]]
|
|
397
|
+
for kind in LATER_KINDS if isinstance(papers.get(kind), list)}
|
|
398
|
+
return later
|
|
399
|
+
|
|
400
|
+
|
|
368
401
|
def sync_batch(batch_id: str, total: int, done: int, succeeded: int, failed: int, *,
|
|
369
402
|
current: str = "", finished: bool = False, results: Any = None,
|
|
370
403
|
phase: str = "", channel: str = "", lanes: str = "", held: Any = None,
|
|
371
|
-
held_wait: bool = False) -> bool:
|
|
404
|
+
held_wait: bool = False, later: Any = None, switch_to: str = "") -> bool:
|
|
372
405
|
"""Record batch totals for items finished without the backend, or the batch end.
|
|
373
406
|
|
|
374
407
|
``results`` (the batch end only) is the caller's summary of every item,
|
|
@@ -382,7 +415,10 @@ def sync_batch(batch_id: str, total: int, done: int, succeeded: int, failed: int
|
|
|
382
415
|
stage and prompts (``_adopt_batch``). ``held``: the publishers the caller holds
|
|
383
416
|
(``_held``), each with a button to go on with them; an empty list clears them.
|
|
384
417
|
``held_wait``: nothing else is left and the batch waits for the user to go on with
|
|
385
|
-
them or end it (each report says it again; any other report, or a download, ends it).
|
|
418
|
+
them or end it (each report says it again; any other report, or a download, ends it).
|
|
419
|
+
``later``: the papers the caller holds for a later try (``_later``), kept until the next
|
|
420
|
+
report that says them; dropped at the batch end. ``switch_to``: the school the caller now
|
|
421
|
+
tries its papers without access with, which the card names for a moment (``switch_note``)."""
|
|
386
422
|
ctx = BatchContext.from_args(batch_id, max(1, min(done, total)), total, done, succeeded, failed)
|
|
387
423
|
if ctx is None or done > total:
|
|
388
424
|
return False
|
|
@@ -391,12 +427,15 @@ def sync_batch(batch_id: str, total: int, done: int, succeeded: int, failed: int
|
|
|
391
427
|
if finished and previous is None and (done == 0 or summary is not None):
|
|
392
428
|
return False
|
|
393
429
|
phase, channel, lanes = _short_line(phase), _short_line(channel), _short_line(lanes)
|
|
430
|
+
school = _short_line(switch_to, 40)
|
|
394
431
|
adopted = _adopt_batch(ctx.batch_id, total, (done, succeeded, failed),
|
|
395
432
|
beside_download=bool(lanes) and not finished,
|
|
396
433
|
**({"current": current} if current else {}),
|
|
397
434
|
**({"lanes": lanes} if lanes or finished else {}),
|
|
398
435
|
**({"held": [] if finished else _held(held)} if held is not None or finished else {}),
|
|
399
436
|
held_wait=bool(held_wait) and not finished,
|
|
437
|
+
**({"later": {} if finished else _later(later)} if later is not None or finished else {}),
|
|
438
|
+
**({"switch_note": {"school": school, "at": time.time()}} if school and not finished else {}),
|
|
400
439
|
stage="saved_pending_verification" if finished else "starting",
|
|
401
440
|
channel="" if finished else channel,
|
|
402
441
|
phase=(f"批量下载结束:成功 {succeeded},失败 {failed}" if finished
|
|
@@ -687,6 +726,16 @@ def tracked_download(current: str, output_dir: Any = None, batch: BatchContext |
|
|
|
687
726
|
_STATE.pop("held_wait", None) # nor waiting for the user to go on with held publishers
|
|
688
727
|
update(content=content if content in ("main", "supplements", "both", "markdown") else "main",
|
|
689
728
|
markdown=bool(markdown), page_reading=False)
|
|
729
|
+
if batch is not None:
|
|
730
|
+
with _LOCK:
|
|
731
|
+
# What the batch was asked for, kept from its first article: its lists say what its failed papers did not
|
|
732
|
+
# get by it. ``content`` is the running article's (the card's label), and the batch's end asks for the
|
|
733
|
+
# Markdown alone of those short of figures: the failed list's heading said "Markdown 未生成" a while
|
|
734
|
+
# (Windows, 2026-11-24).
|
|
735
|
+
if _STATE and _STATE.get("batch_content_of") != batch.batch_id:
|
|
736
|
+
_STATE["batch_content"] = _STATE.get("content")
|
|
737
|
+
_STATE["batch_content_of"] = batch.batch_id
|
|
738
|
+
_write_state()
|
|
690
739
|
if output_dir:
|
|
691
740
|
set_output_dir(output_dir)
|
|
692
741
|
name_journal(current)
|
|
@@ -64,6 +64,7 @@ MAX_LISTED_PAPERS = 200
|
|
|
64
64
|
CLASS_ORDER = ("no_access", "user_side", "external", "unsupported", "unexplained")
|
|
65
65
|
DEFAULT_LINGER_SECONDS = 8.0
|
|
66
66
|
NOTICE_SECONDS = 10.0 # how long the download's answer to a click stays on screen
|
|
67
|
+
SWITCH_SECONDS = 5.0 # how long the card names the school the papers without access go on with
|
|
67
68
|
|
|
68
69
|
|
|
69
70
|
class AutoClose:
|
|
@@ -258,24 +259,33 @@ def summary_view(results: Any) -> dict[str, Any] | None:
|
|
|
258
259
|
|
|
259
260
|
|
|
260
261
|
OPEN_DOWNLOAD = "开放下载"
|
|
262
|
+
# Behind 重试 (user, 2026-11-24): the papers held for a later try, by why, as the card says them.
|
|
263
|
+
RETRY_GROUPS = (("no_access", "换学校再试 · 没权限"), ("unexplained", "最后再试一次 · 原因不明"), ("blocked", "被网站拦截"),
|
|
264
|
+
("login", "登录后继续 · 学校登录中途失效"))
|
|
261
265
|
# Behind 剩余: the paper being downloaded, then the waiting ones by lane.
|
|
262
266
|
LEFT_GROUPS = (("now", "正在下载"), ("school", "排队等机构下载"), ("open", "开放下载还没查"))
|
|
263
267
|
|
|
264
268
|
|
|
265
|
-
def paper_lists(listed: Any, state: dict[str, Any] | None) -> dict[str, Any]:
|
|
266
|
-
"""The lists behind the card's 成功,
|
|
269
|
+
def paper_lists(listed: Any, state: dict[str, Any] | None, holds: bool = True) -> dict[str, Any]:
|
|
270
|
+
"""The lists behind the card's 成功, 失败, 重试 and 剩余, from the batch's papers (``sync_papers``).
|
|
267
271
|
|
|
268
272
|
``ok``: by the way each came (开放下载, its sources in brackets; 机构下载), a paper
|
|
269
273
|
opening its PDF by ``index``; ``failed``: by reason as on the finished card, a paper
|
|
270
274
|
opening its article page, then the saved papers missing supplementary files, by reason
|
|
271
275
|
(``supplement`` groups; ``count`` the failed papers only, ``supplement_count`` these); ``left``: the paper being downloaded, those waiting for the
|
|
272
276
|
institutional download and those open access has not checked yet. Each list has its
|
|
273
|
-
``count`` and groups, the first one open. Empty for another batch's papers.
|
|
277
|
+
``count`` and groups, the first one open. Empty for another batch's papers. ``holds`` false (neither
|
|
278
|
+
失败后自动重试 nor 没权限时换下一所学校 on, the card without 重试): no 重试 list, each paper where its state puts it."""
|
|
274
279
|
if not isinstance(listed, dict) or not state or listed.get("batch_id") != state.get("batch_id"):
|
|
275
280
|
return {}
|
|
276
281
|
papers = sorted((p for p in (listed.get("papers") or {}).values() if isinstance(p, dict)),
|
|
277
282
|
key=lambda p: _count(p.get("index")))
|
|
278
283
|
current = str(state.get("current") or "").lower() if state.get("status") == "running" else ""
|
|
284
|
+
# The papers the caller holds for a later try, by DOI (its ``later``): behind 重试, not 失败 nor 剩余 (user, 2026-11-24).
|
|
285
|
+
later = (state.get("later") if holds and state.get("status") == "running" and isinstance(state.get("later"), dict)
|
|
286
|
+
else {})
|
|
287
|
+
held = {doi.lower(): kind for kind, dois in (later.get("papers") or {}).items() for doi in dois}
|
|
288
|
+
held_paper = lambda paper: str(paper.get("doi") or "").lower() in held # noqa: E731
|
|
279
289
|
|
|
280
290
|
def row(paper: dict[str, Any], *where: Any) -> dict[str, Any]:
|
|
281
291
|
doi = str(paper.get("doi") or "").strip()
|
|
@@ -317,13 +327,14 @@ def paper_lists(listed: Any, state: dict[str, Any] | None) -> dict[str, Any]:
|
|
|
317
327
|
|
|
318
328
|
# A batch of the Markdown alone fails a paper for its Markdown: a site not yet supported's
|
|
319
329
|
# note stands in for the journal, as on the finished card (user, 2026-11-16).
|
|
320
|
-
|
|
330
|
+
asked = state.get("batch_content") or state.get("content") # the batch's, not the running article's
|
|
331
|
+
markdown_alone = asked == "markdown"
|
|
321
332
|
|
|
322
333
|
def site_note(paper: dict[str, Any]) -> dict[str, Any]:
|
|
323
334
|
note = str(paper.get("markdown_note") or "")
|
|
324
335
|
return {"note": note, "journal": "" if note else paper.get("journal")}
|
|
325
336
|
|
|
326
|
-
failed_papers = [p for p in papers if p.get("state") == "failed"]
|
|
337
|
+
failed_papers = [p for p in papers if p.get("state") == "failed" and not held_paper(p)]
|
|
327
338
|
failed = _reason_groups([{**p, **(site_note(p) if markdown_alone else {"note": ""})} for p in failed_papers], 0)
|
|
328
339
|
for item in failed:
|
|
329
340
|
item.update(label=item["reason"])
|
|
@@ -354,7 +365,7 @@ def paper_lists(listed: Any, state: dict[str, Any] | None) -> dict[str, Any]:
|
|
|
354
365
|
|
|
355
366
|
waiting: dict[str, list[dict[str, Any]]] = {key: [] for key, _ in LEFT_GROUPS}
|
|
356
367
|
for paper in papers:
|
|
357
|
-
if paper.get("state") not in ("open", "school"):
|
|
368
|
+
if paper.get("state") not in ("open", "school") or held_paper(paper):
|
|
358
369
|
continue
|
|
359
370
|
now = bool(current) and str(paper.get("doi") or "").lower() == current
|
|
360
371
|
way = "机构下载" if paper["state"] == "school" else OPEN_DOWNLOAD
|
|
@@ -375,41 +386,15 @@ def paper_lists(listed: Any, state: dict[str, Any] | None) -> dict[str, Any]:
|
|
|
375
386
|
missing = first_open(failed + short + markdown + doubt)
|
|
376
387
|
missing.update(count=sum(item["count"] for item in failed), supplement_count=sum(item["count"] for item in short),
|
|
377
388
|
markdown_count=sum(item["count"] for item in markdown), doubt_count=sum(item["count"] for item in doubt),
|
|
378
|
-
failed_title=failed_title(
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
whose rules converted their pages or came closest, ``rules`` (most papers first; none
|
|
388
|
-
when no rules read a page): the card says which were borrowed (user, 2026-11-17)."""
|
|
389
|
-
if not isinstance(listed, dict) or not state or listed.get("batch_id") != state.get("batch_id"):
|
|
390
|
-
return None
|
|
391
|
-
counts: dict[str, int] = {}
|
|
392
|
-
rules: dict[str, int] = {}
|
|
393
|
-
saved = unsaved = skipped = 0
|
|
394
|
-
for paper in (listed.get("papers") or {}).values():
|
|
395
|
-
if not isinstance(paper, dict) or not paper.get("markdown_host"):
|
|
396
|
-
continue
|
|
397
|
-
counts[str(paper["markdown_host"])] = counts.get(str(paper["markdown_host"]), 0) + 1
|
|
398
|
-
if paper.get("markdown_rules"):
|
|
399
|
-
rules[str(paper["markdown_rules"])] = rules.get(str(paper["markdown_rules"]), 0) + 1
|
|
400
|
-
if paper.get("markdown_saved"):
|
|
401
|
-
saved += 1
|
|
402
|
-
elif paper.get("markdown_skipped"):
|
|
403
|
-
skipped += 1
|
|
404
|
-
else:
|
|
405
|
-
unsaved += 1
|
|
406
|
-
if not counts:
|
|
407
|
-
return None
|
|
408
|
-
def most_first(tally: dict[str, int]) -> list[str]:
|
|
409
|
-
return [name for name, _ in sorted(tally.items(), key=lambda kv: (-kv[1], kv[0]))]
|
|
410
|
-
|
|
411
|
-
return {"hosts": most_first(counts), "saved": saved, "unsaved": unsaved, "skipped": skipped,
|
|
412
|
-
**({"rules": most_first(rules)} if rules else {})}
|
|
389
|
+
failed_title=failed_title(asked))
|
|
390
|
+
retry = []
|
|
391
|
+
for kind, label in RETRY_GROUPS:
|
|
392
|
+
rows = [row(p, p.get("journal")) for p in papers if held.get(str(p.get("doi") or "").lower()) == kind]
|
|
393
|
+
at = later.get("blocked_at")
|
|
394
|
+
timed = kind == "blocked" and isinstance(at, (int, float)) and not isinstance(at, bool) and at > 0
|
|
395
|
+
if rows:
|
|
396
|
+
retry.append(group(f"{time.strftime('%H:%M', time.localtime(at))} 再试 · {label}" if timed else label, rows))
|
|
397
|
+
return {"ok": first_open(saved), "failed": missing, "left": first_open(left), "retry": first_open(retry)}
|
|
413
398
|
|
|
414
399
|
|
|
415
400
|
# The longest publisher name the hourly-limit notice keeps on one line, in zh and en,
|
|
@@ -430,6 +415,34 @@ def _hourly_hold(state: dict[str, Any], now: float) -> tuple[str, int | None, st
|
|
|
430
415
|
return str(raw.get("publisher") or ""), limit, time.strftime("%H:%M", time.localtime(until))
|
|
431
416
|
|
|
432
417
|
|
|
418
|
+
def _later(state: dict[str, Any], left: int) -> dict[str, Any] | None:
|
|
419
|
+
"""The papers the caller holds for a later try (user, 2026-11-23): 重试 on the running card, its list by why; at most
|
|
420
|
+
those not done (a paper just counted may still be said held). None when none (an older PaperSearch's state)."""
|
|
421
|
+
raw = state.get("later")
|
|
422
|
+
if not isinstance(raw, dict):
|
|
423
|
+
return None
|
|
424
|
+
counts = {kind: _count(raw.get(kind)) for kind in ("no_access", "unexplained", "blocked", "login")}
|
|
425
|
+
held = min(sum(counts.values()), left)
|
|
426
|
+
if not held:
|
|
427
|
+
return None
|
|
428
|
+
at = raw.get("blocked_at")
|
|
429
|
+
timed = counts["blocked"] and isinstance(at, (int, float)) and not isinstance(at, bool) and at > 0
|
|
430
|
+
# When the paused publisher's papers are tried again ("16:58 再试"), the earliest of several.
|
|
431
|
+
return {"total": held, **counts, "blocked_at": time.strftime("%H:%M", time.localtime(at)) if timed else ""}
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
def _switch_note(state: dict[str, Any], now: float) -> str:
|
|
435
|
+
""""换红木兰大学再试" for a few seconds once the batch tries its papers without access with another saved school
|
|
436
|
+
(user, 2026-11-23: on the card's line under its title, in place of the counts and the time)."""
|
|
437
|
+
raw = state.get("switch_note")
|
|
438
|
+
if not isinstance(raw, dict) or not str(raw.get("school") or ""):
|
|
439
|
+
return ""
|
|
440
|
+
at = raw.get("at")
|
|
441
|
+
if not isinstance(at, (int, float)) or isinstance(at, bool) or not 0 <= now - at < SWITCH_SECONDS:
|
|
442
|
+
return ""
|
|
443
|
+
return f"换{raw['school']}再试"
|
|
444
|
+
|
|
445
|
+
|
|
433
446
|
def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
434
447
|
"""Everything the capsule shows for one snapshot of the progress file.
|
|
435
448
|
|
|
@@ -451,7 +464,7 @@ def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
|
451
464
|
awaiting = bool(state.get("awaiting_next"))
|
|
452
465
|
# Publishers whose school login stopped working mid-batch, held by the caller:
|
|
453
466
|
# a line and a button to go on with them once the user is back (2026-11-15).
|
|
454
|
-
held = [{"key": str(entry.get("key")), "name": str(entry.get("name") or entry.get("key")),
|
|
467
|
+
held = [{"key": str(entry.get("key")), "name": str(entry.get("name") or entry.get("key")).removeprefix("site:"),
|
|
455
468
|
"count": int(entry.get("count") or 0)}
|
|
456
469
|
for entry in (state.get("held") or []) if running and isinstance(entry, dict) and entry.get("key")]
|
|
457
470
|
# Nothing else left: the batch waits for the user, which the collapsed capsule says
|
|
@@ -483,6 +496,10 @@ def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
|
483
496
|
# Before any publisher (the caller's open-access stretch), the channel stands in.
|
|
484
497
|
publisher = str(state.get("publisher") or "") or str(state.get("channel") or "")
|
|
485
498
|
journal = str(state.get("journal") or "")
|
|
499
|
+
# A site without rules of its own runs under "site:<domain>" (publishers/site.py), a name never shown: its journal
|
|
500
|
+
# names it, else its domain (user, 2026-11-24: "site:bristoluniversitypressdigital.com" on the capsule, often).
|
|
501
|
+
if publisher.startswith("site:"):
|
|
502
|
+
publisher = journal or publisher[len("site:"):]
|
|
486
503
|
current = str((attention[-1].get("current") if attention else "") or state.get("current") or "")
|
|
487
504
|
title = str(state.get("title") or "")
|
|
488
505
|
if held_wait:
|
|
@@ -567,7 +584,8 @@ def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
|
567
584
|
"ok": ok, "bad": bad, "left": max(0, total - done) if running and total else None,
|
|
568
585
|
"stopped": stopped,
|
|
569
586
|
"part": part, "publisher": publisher,
|
|
570
|
-
|
|
587
|
+
# A journal named as its publisher (Science, JAMA, BMJ, PNAS) once (user, 2026-11-23).
|
|
588
|
+
"where": " · ".join(v for v in (journal, "" if publisher.casefold() == journal.casefold() else publisher) if v),
|
|
571
589
|
"title": title, "current": current,
|
|
572
590
|
"run_id": str(state.get("run_id") or ""),
|
|
573
591
|
"step": step, "steps": list(steps), "line": line,
|
|
@@ -583,6 +601,8 @@ def view(state: dict[str, Any] | None, now: float) -> dict[str, Any]:
|
|
|
583
601
|
and (not awaiting or bool(state.get("browser_pid") or state.get("browser_pids"))),
|
|
584
602
|
"stop_left": max(0, total - done - 1),
|
|
585
603
|
"held": held, "held_wait": held_wait,
|
|
604
|
+
"later": _later(state, max(0, total - done)) if running else None,
|
|
605
|
+
"switch_note": _switch_note(state, now) if running else "",
|
|
586
606
|
"folder": bool(state.get("output_dir")),
|
|
587
607
|
}
|
|
588
608
|
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
"name": "IOP",
|
|
5
5
|
"article_url_template": "https://iopscience.iop.org/article/{doi}",
|
|
6
6
|
"pdf_url_templates": [
|
|
7
|
-
"https://iopscience.iop.org/article/{doi}/pdf"
|
|
7
|
+
"https://iopscience.iop.org/article/{doi}/pdf",
|
|
8
|
+
"https://iopscience.iop.org/article/{doi}/ampdf"
|
|
8
9
|
],
|
|
9
10
|
"success_url_markers": [
|
|
10
11
|
"iopscience.iop.org/article/"
|
|
@@ -6,14 +6,16 @@
|
|
|
6
6
|
"10.1212"
|
|
7
7
|
],
|
|
8
8
|
"base_domains": [
|
|
9
|
-
"neurology.org"
|
|
9
|
+
"neurology.org",
|
|
10
|
+
"continuum.aan.com"
|
|
10
11
|
],
|
|
11
12
|
"article_url_template": "https://doi.org/{doi}",
|
|
12
13
|
"pdf_url_templates": [
|
|
13
14
|
"https://www.neurology.org/doi/pdf/{doi}"
|
|
14
15
|
],
|
|
15
16
|
"success_url_markers": [
|
|
16
|
-
"neurology.org/doi/"
|
|
17
|
+
"neurology.org/doi/",
|
|
18
|
+
"continuum.aan.com/doi/"
|
|
17
19
|
],
|
|
18
20
|
"auth_url_markers": [
|
|
19
21
|
"/login",
|
|
@@ -16,7 +16,7 @@ from typing import ClassVar
|
|
|
16
16
|
from urllib.parse import urlparse
|
|
17
17
|
|
|
18
18
|
from ..engine.access_rules import registrable_domain
|
|
19
|
-
from .model import PublisherProfile
|
|
19
|
+
from .model import PdfSourcePathTemplate, PublisherProfile
|
|
20
20
|
|
|
21
21
|
#: Name prefix of a run-time site profile: ``site:<registrable domain>``.
|
|
22
22
|
SITE_PREFIX = "site:"
|
|
@@ -34,11 +34,17 @@ GENERIC_SUPPLEMENTARY_URL_MARKERS = ("supplementary", "suppl_file", "supporting-
|
|
|
34
34
|
# Where a DOI can land that is no publisher's site: doi.org itself, Crossref's
|
|
35
35
|
# multiple-resolution chooser, the Handle resolver.
|
|
36
36
|
_NOT_A_SITE = frozenset({"doi.org", "crossref.org", "handle.net"})
|
|
37
|
-
# Platforms the engine does not sign in on, whatever DOI leads there: ClinicalKey
|
|
38
|
-
# (the Elsevier adapter's unsupported
|
|
37
|
+
# Platforms the engine does not sign in on, whatever DOI leads there: ClinicalKey and
|
|
38
|
+
# EM-Consulte (the Elsevier adapter's unsupported platforms) and the databases dropped on
|
|
39
39
|
# 2026-11-02 (CNKI, Wanfang, VIP).
|
|
40
|
-
_UNSUPPORTED_SITES = re.compile(
|
|
40
|
+
_UNSUPPORTED_SITES = re.compile(
|
|
41
|
+
r"clinicalkey\.[a-z]{2,3}(?:\.[a-z]{2})?|em-consulte\.com|cnki\.net|wanfangdata\.com\.cn|cqvip\.com")
|
|
41
42
|
_DOI_PREFIX = re.compile(r"10\.\d{4,9}")
|
|
43
|
+
# A platform's PDF address made from the article page's address, by DOI prefix. F1000's open research
|
|
44
|
+
# platforms (F1000Research, Wellcome, Gates, Bioethics Open Research and the others, all 10.12688): the
|
|
45
|
+
# page /articles/<n>-<n>/v<k> plus /pdf, a redirect to the file. The page names no PDF anywhere (its
|
|
46
|
+
# Download button opens a menu), and nothing was tried there (Bioethics Open Research, 2026-11-24).
|
|
47
|
+
_PAGE_PDF_PATHS = {"10.12688": ("/articles/", "{source_path}/pdf")}
|
|
42
48
|
|
|
43
49
|
|
|
44
50
|
@dataclass(frozen=True)
|
|
@@ -73,6 +79,7 @@ def site_profile(doi: str, landing_url: str) -> SiteProfile | None:
|
|
|
73
79
|
domain = registrable_domain(host)
|
|
74
80
|
if not domain or domain in _NOT_A_SITE or _UNSUPPORTED_SITES.fullmatch(domain):
|
|
75
81
|
return None
|
|
82
|
+
page_pdf = _PAGE_PDF_PATHS.get(prefix)
|
|
76
83
|
return SiteProfile(
|
|
77
84
|
name=SITE_PREFIX + domain,
|
|
78
85
|
article_url_template="https://doi.org/{doi}",
|
|
@@ -82,5 +89,6 @@ def site_profile(doi: str, landing_url: str) -> SiteProfile | None:
|
|
|
82
89
|
sso_text_markers=GENERIC_SSO_TEXT_MARKERS,
|
|
83
90
|
doi_prefixes=(prefix,),
|
|
84
91
|
base_domains=(domain,),
|
|
92
|
+
pdf_source_path_templates=(PdfSourcePathTemplate(domain, *page_pdf),) if page_pdf else (),
|
|
85
93
|
supplementary_url_markers=GENERIC_SUPPLEMENTARY_URL_MARKERS,
|
|
86
94
|
)
|
|
@@ -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
|
|
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": "检查网络后再测"}
|
|
@@ -247,15 +247,16 @@ def school_switch_state() -> str:
|
|
|
247
247
|
"""The schools a batch's papers without access (没权限) are tried with at its end, one after another
|
|
248
248
|
(没权限时换下一所学校, school_switch.py): the default one first, each named as ``school_download``'s ``school``
|
|
249
249
|
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
|
|
251
|
-
{"on": bool, "schools": [{"name": ..., "entity_id": ...}, ...], "group": bool}."""
|
|
252
|
-
from . import school_switch
|
|
250
|
+
another (``group``: on and more than one school); and whether 失败后自动重试 is on (``retry``, user_settings). Opens no
|
|
251
|
+
browser. Answers {"on": bool, "schools": [{"name": ..., "entity_id": ...}, ...], "group": bool, "retry": bool}."""
|
|
252
|
+
from . import school_switch, user_settings
|
|
253
253
|
|
|
254
254
|
config = load_config()
|
|
255
255
|
on = school_switch.enabled(config)
|
|
256
256
|
schools = [{"name": school_switch.name(entry), "entity_id": str(entry.get("idp_entity_id") or "").strip()}
|
|
257
257
|
for entry in school_switch.schools(config)] if on else []
|
|
258
|
-
return json.dumps({"on": on, "schools": schools, "group": on and len(schools) > 1
|
|
258
|
+
return json.dumps({"on": on, "schools": schools, "group": on and len(schools) > 1,
|
|
259
|
+
"retry": config.get(user_settings.RETRY_KEY) is True}, ensure_ascii=False)
|
|
259
260
|
|
|
260
261
|
|
|
261
262
|
@mcp_app.tool()
|
|
@@ -293,6 +294,8 @@ def school_batch_progress(
|
|
|
293
294
|
lanes: str = "",
|
|
294
295
|
held: list[dict[str, Any]] | None = None,
|
|
295
296
|
held_wait: bool = False,
|
|
297
|
+
later: dict[str, Any] | None = None,
|
|
298
|
+
switch_to: str = "",
|
|
296
299
|
) -> str:
|
|
297
300
|
"""Update the progress window of a serial batch without downloading.
|
|
298
301
|
|
|
@@ -310,12 +313,20 @@ def school_batch_progress(
|
|
|
310
313
|
running download of the batch too: then only the counts and this line change.
|
|
311
314
|
|
|
312
315
|
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
|
|
316
|
+
working mid-batch, [{key (its name, else its DOI prefix), name, count}]; the window shows them with a
|
|
314
317
|
button to go on. The answer's "resume" lists those the user asked to go on with since
|
|
315
318
|
the last report (each once), and "stop" whether the user ended the batch in the window
|
|
316
319
|
(a batch waiting for the user downloads nothing that would hear of it).
|
|
317
320
|
held_wait: nothing is left but the held publishers' papers and the batch waits for the
|
|
318
321
|
user (登录并继续 or 终止); the window says so, collapsed too.
|
|
322
|
+
|
|
323
|
+
later: the papers whose first try failed and that the caller tries again later, by why:
|
|
324
|
+
{no_access (the next saved school at the end), unexplained (once more at the end), blocked
|
|
325
|
+
(their site blocked them; tried again at blocked_at, epoch seconds), login (their school login
|
|
326
|
+
lapsed; waiting for 登录并继续), papers: {each kind: its papers' DOIs}}; the window's ring shows them
|
|
327
|
+
beside the papers done, and its 重试 count and list.
|
|
328
|
+
switch_to: the saved school the caller now tries its papers without access with; the window
|
|
329
|
+
names it for a few seconds.
|
|
319
330
|
"""
|
|
320
331
|
from . import entitlements, progress_reporter
|
|
321
332
|
|
|
@@ -323,7 +334,7 @@ def school_batch_progress(
|
|
|
323
334
|
updated = progress_reporter.sync_batch(batch_id, total, done, succeeded, failed,
|
|
324
335
|
current=label, finished=finished, results=results,
|
|
325
336
|
phase=phase, channel=channel, lanes=lanes, held=held,
|
|
326
|
-
held_wait=held_wait)
|
|
337
|
+
held_wait=held_wait, later=later, switch_to=switch_to)
|
|
327
338
|
stop = entitlements.batch_stop_requested() and (progress_reporter.read_state() or {}).get("batch_id") == batch_id
|
|
328
339
|
return json.dumps({"updated": updated, "resume": entitlements.take_resumes(batch_id), "stop": bool(stop)})
|
|
329
340
|
|
|
@@ -81,6 +81,19 @@ def set_hourly_now(on: bool) -> None:
|
|
|
81
81
|
_config.update_config(HOURLY_NOW_KEY, "true" if on else "false")
|
|
82
82
|
|
|
83
83
|
|
|
84
|
+
RETRY_KEY = "batch_retry_failed"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def retry_enabled() -> bool:
|
|
88
|
+
"""失败后自动重试 (the 等待和提醒 page; user, 2026-11-24: off by default): a batch tries its 原因不明 papers once more at
|
|
89
|
+
its end, and a publisher whose site blocked it once more after a pause (download/batch/batch.ts)."""
|
|
90
|
+
return _config.load_config().get(RETRY_KEY) is True
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def set_retry(on: bool) -> None:
|
|
94
|
+
_config.update_config(RETRY_KEY, "true" if on else "false")
|
|
95
|
+
|
|
96
|
+
|
|
84
97
|
LANGUAGE_KEY = "progress_language"
|
|
85
98
|
|
|
86
99
|
|
package/school/pyproject.toml
CHANGED
|
@@ -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 = [
|