papersearch 0.7.2 → 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.
Files changed (177) hide show
  1. package/LICENSE-paper-search-mcp-nodejs +24 -0
  2. package/NOTICE +8 -37
  3. package/README.en.md +7 -3
  4. package/README.fr.md +268 -0
  5. package/README.ja.md +268 -0
  6. package/README.ko.md +268 -0
  7. package/README.md +7 -3
  8. package/README.zh-Hant.md +268 -0
  9. package/dist/capabilities/download/batch/batch.d.ts +16 -1
  10. package/dist/capabilities/download/batch/batch.d.ts.map +1 -1
  11. package/dist/capabilities/download/batch/batch.js +669 -53
  12. package/dist/capabilities/download/batch/batch.js.map +1 -1
  13. package/dist/capabilities/download/batch/batchFolder.d.ts.map +1 -1
  14. package/dist/capabilities/download/batch/batchFolder.js +4 -3
  15. package/dist/capabilities/download/batch/batchFolder.js.map +1 -1
  16. package/dist/capabilities/download/batch/batchSummary.js +1 -1
  17. package/dist/capabilities/download/batch/batchSummary.js.map +1 -1
  18. package/dist/capabilities/download/batch/networkLoss.d.ts +12 -3
  19. package/dist/capabilities/download/batch/networkLoss.d.ts.map +1 -1
  20. package/dist/capabilities/download/batch/networkLoss.js +25 -4
  21. package/dist/capabilities/download/batch/networkLoss.js.map +1 -1
  22. package/dist/capabilities/download/batch/resume.d.ts +7 -0
  23. package/dist/capabilities/download/batch/resume.d.ts.map +1 -1
  24. package/dist/capabilities/download/batch/resume.js +50 -9
  25. package/dist/capabilities/download/batch/resume.js.map +1 -1
  26. package/dist/capabilities/download/content/markdown/pro.d.ts +6 -0
  27. package/dist/capabilities/download/content/markdown/pro.d.ts.map +1 -1
  28. package/dist/capabilities/download/content/markdown/pro.js.map +1 -1
  29. package/dist/capabilities/download/content/markdown/shortfall.d.ts +8 -5
  30. package/dist/capabilities/download/content/markdown/shortfall.d.ts.map +1 -1
  31. package/dist/capabilities/download/content/markdown/shortfall.js +27 -15
  32. package/dist/capabilities/download/content/markdown/shortfall.js.map +1 -1
  33. package/dist/capabilities/download/content/markdown/step.d.ts +9 -0
  34. package/dist/capabilities/download/content/markdown/step.d.ts.map +1 -1
  35. package/dist/capabilities/download/content/markdown/step.js +42 -2
  36. package/dist/capabilities/download/content/markdown/step.js.map +1 -1
  37. package/dist/capabilities/download/content/markdown/types.d.ts +10 -1
  38. package/dist/capabilities/download/content/markdown/types.d.ts.map +1 -1
  39. package/dist/capabilities/download/handler.d.ts.map +1 -1
  40. package/dist/capabilities/download/handler.js +13 -5
  41. package/dist/capabilities/download/handler.js.map +1 -1
  42. package/dist/capabilities/download/outputLayout.d.ts.map +1 -1
  43. package/dist/capabilities/download/outputLayout.js +3 -1
  44. package/dist/capabilities/download/outputLayout.js.map +1 -1
  45. package/dist/capabilities/download/tools.js +2 -2
  46. package/dist/capabilities/download/tools.js.map +1 -1
  47. package/dist/capabilities/download/types.d.ts +9 -1
  48. package/dist/capabilities/download/types.d.ts.map +1 -1
  49. package/dist/cli.js +3 -1
  50. package/dist/cli.js.map +1 -1
  51. package/dist/infrastructure/runlog/RunLedger.d.ts +7 -0
  52. package/dist/infrastructure/runlog/RunLedger.d.ts.map +1 -1
  53. package/dist/infrastructure/runlog/RunLedger.js +13 -0
  54. package/dist/infrastructure/runlog/RunLedger.js.map +1 -1
  55. package/dist/infrastructure/runlog/failureClass.d.ts +17 -9
  56. package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
  57. package/dist/infrastructure/runlog/failureClass.js +89 -56
  58. package/dist/infrastructure/runlog/failureClass.js.map +1 -1
  59. package/dist/infrastructure/school/SchoolAttempt.d.ts +11 -0
  60. package/dist/infrastructure/school/SchoolAttempt.d.ts.map +1 -1
  61. package/dist/infrastructure/school/SchoolAttempt.js +107 -59
  62. package/dist/infrastructure/school/SchoolAttempt.js.map +1 -1
  63. package/dist/infrastructure/school/SchoolMcpClient.d.ts +7 -2
  64. package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
  65. package/dist/infrastructure/school/SchoolMcpClient.js +30 -7
  66. package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -1
  67. package/dist/infrastructure/school/SchoolProgress.d.ts +2 -0
  68. package/dist/infrastructure/school/SchoolProgress.d.ts.map +1 -1
  69. package/dist/infrastructure/school/SchoolProgress.js +2 -0
  70. package/dist/infrastructure/school/SchoolProgress.js.map +1 -1
  71. package/dist/infrastructure/school/SchoolReadiness.d.ts +2 -0
  72. package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -1
  73. package/dist/infrastructure/school/SchoolReadiness.js +2 -0
  74. package/dist/infrastructure/school/SchoolReadiness.js.map +1 -1
  75. package/dist/infrastructure/school/SchoolResultNormalizer.d.ts.map +1 -1
  76. package/dist/infrastructure/school/SchoolResultNormalizer.js +4 -0
  77. package/dist/infrastructure/school/SchoolResultNormalizer.js.map +1 -1
  78. package/dist/infrastructure/school/index.d.ts +2 -2
  79. package/dist/infrastructure/school/index.d.ts.map +1 -1
  80. package/dist/infrastructure/school/index.js +1 -1
  81. package/dist/infrastructure/school/index.js.map +1 -1
  82. package/dist/infrastructure/school/types.d.ts +52 -3
  83. package/dist/infrastructure/school/types.d.ts.map +1 -1
  84. package/dist/infrastructure/school/types.js.map +1 -1
  85. package/dist/management/failures/index.d.ts +28 -2
  86. package/dist/management/failures/index.d.ts.map +1 -1
  87. package/dist/management/failures/index.js +83 -21
  88. package/dist/management/failures/index.js.map +1 -1
  89. package/package.json +7 -2
  90. package/school/NOTICE +3 -2
  91. package/school/paper_search_school/adapters/__init__.py +2 -0
  92. package/school/paper_search_school/adapters/aps/__init__.py +3 -6
  93. package/school/paper_search_school/adapters/base.py +18 -0
  94. package/school/paper_search_school/adapters/copernicus/__init__.py +2 -7
  95. package/school/paper_search_school/adapters/elsevier/__init__.py +50 -1
  96. package/school/paper_search_school/adapters/frontiers/__init__.py +41 -2
  97. package/school/paper_search_school/adapters/ieee/__init__.py +6 -4
  98. package/school/paper_search_school/adapters/iop/__init__.py +8 -0
  99. package/school/paper_search_school/adapters/jama/__init__.py +8 -0
  100. package/school/paper_search_school/adapters/lww/__init__.py +14 -6
  101. package/school/paper_search_school/adapters/mdpi/__init__.py +12 -7
  102. package/school/paper_search_school/adapters/neurology/__init__.py +5 -2
  103. package/school/paper_search_school/adapters/optica/__init__.py +2 -9
  104. package/school/paper_search_school/adapters/oup/__init__.py +27 -4
  105. package/school/paper_search_school/adapters/platforms/__init__.py +4 -1
  106. package/school/paper_search_school/adapters/platforms/atypon/__init__.py +8 -0
  107. package/school/paper_search_school/adapters/platforms/jstage/__init__.py +64 -0
  108. package/school/paper_search_school/adapters/sage/__init__.py +4 -1
  109. package/school/paper_search_school/adapters/thieme/__init__.py +6 -11
  110. package/school/paper_search_school/api_keys.py +63 -13
  111. package/school/paper_search_school/assets/api_keys.json +14 -0
  112. package/school/paper_search_school/assets/capsule.html +274 -158
  113. package/school/paper_search_school/assets/capsule_en.json +99 -98
  114. package/school/paper_search_school/assets/capsule_fr.json +100 -99
  115. package/school/paper_search_school/assets/capsule_ja.json +99 -98
  116. package/school/paper_search_school/assets/capsule_ko.json +99 -98
  117. package/school/paper_search_school/assets/capsule_zh-Hant.json +94 -97
  118. package/school/paper_search_school/browser/batch_session.py +1 -1
  119. package/school/paper_search_school/browser/challenge/__init__.py +12 -9
  120. package/school/paper_search_school/browser/challenge/continuation.py +65 -0
  121. package/school/paper_search_school/browser/challenge/handlers/__init__.py +1 -0
  122. package/school/paper_search_school/browser/challenge/handlers/aws_waf.py +260 -0
  123. package/school/paper_search_school/browser/challenge/handlers/recaptcha_hcaptcha.py +167 -0
  124. package/school/paper_search_school/browser/challenge/handlers/text_captcha.py +100 -0
  125. package/school/paper_search_school/browser/challenge/handlers/turnstile.py +174 -0
  126. package/school/paper_search_school/browser/challenge/kinds.py +203 -0
  127. package/school/paper_search_school/browser/challenge/local/__init__.py +1 -0
  128. package/school/paper_search_school/browser/challenge/{interaction.py → local/interaction.py} +94 -13
  129. package/school/paper_search_school/browser/challenge/{pointer.py → local/pointer.py} +2 -2
  130. package/school/paper_search_school/browser/challenge/local/prompt.py +283 -0
  131. package/school/paper_search_school/browser/challenge/local/submission.py +33 -0
  132. package/school/paper_search_school/browser/challenge/services/__init__.py +1 -0
  133. package/school/paper_search_school/browser/challenge/services/solver.py +272 -0
  134. package/school/paper_search_school/cli_config.py +10 -5
  135. package/school/paper_search_school/cold_start.py +22 -11
  136. package/school/paper_search_school/config.py +11 -10
  137. package/school/paper_search_school/download_diagnostics.py +7 -2
  138. package/school/paper_search_school/engine/access_rules.py +15 -5
  139. package/school/paper_search_school/engine/batch.py +55 -15
  140. package/school/paper_search_school/engine/batch_access.py +59 -21
  141. package/school/paper_search_school/engine/batch_capture.py +215 -18
  142. package/school/paper_search_school/engine/batch_common.py +3 -0
  143. package/school/paper_search_school/engine/batch_diagnostics.py +25 -5
  144. package/school/paper_search_school/engine/batch_institution.py +168 -32
  145. package/school/paper_search_school/engine/batch_login.py +223 -16
  146. package/school/paper_search_school/engine/batch_pdf_urls.py +38 -7
  147. package/school/paper_search_school/engine/batch_waits.py +179 -12
  148. package/school/paper_search_school/engine/bridge.py +44 -7
  149. package/school/paper_search_school/engine/fulltext_page.py +45 -7
  150. package/school/paper_search_school/engine/router.py +18 -2
  151. package/school/paper_search_school/entitlements.py +1 -1
  152. package/school/paper_search_school/orchestrator.py +44 -18
  153. package/school/paper_search_school/pdf_utils.py +25 -16
  154. package/school/paper_search_school/progress_capsule.py +36 -6
  155. package/school/paper_search_school/progress_reporter.py +71 -13
  156. package/school/paper_search_school/progress_view.py +64 -44
  157. package/school/paper_search_school/publishers/builtin/iop.json +2 -1
  158. package/school/paper_search_school/publishers/builtin/neurology.json +4 -2
  159. package/school/paper_search_school/publishers/builtin/sage.json +4 -2
  160. package/school/paper_search_school/publishers/builtin/thieme.json +3 -1
  161. package/school/paper_search_school/publishers/site.py +12 -4
  162. package/school/paper_search_school/school_switch.py +34 -52
  163. package/school/paper_search_school/school_test.py +1 -1
  164. package/school/paper_search_school/server.py +24 -11
  165. package/school/paper_search_school/user_settings.py +13 -0
  166. package/school/pyproject.toml +1 -0
  167. package/skills/paper-search/SKILL.md +107 -107
  168. package/skills/paper-search/references/browser-download.md +102 -101
  169. package/skills/paper-search/references/capability-routing.md +89 -89
  170. package/skills/paper-search/references/cli-contract.md +78 -78
  171. package/skills/paper-search/references/federation-support.md +172 -172
  172. package/skills/paper-search/references/management-layer.md +78 -78
  173. package/skills/paper-search/references/publisher-support.md +38 -38
  174. package/skills/paper-search/references/school-setup.md +56 -55
  175. package/skills/paper-search/references/setup.md +20 -20
  176. package/skills/paper-search/references/troubleshooting.md +12 -12
  177. package/school/paper_search_school/browser/challenge/prompt.py +0 -154
@@ -13,7 +13,8 @@ start forgets:
13
13
 
14
14
  It keeps bot-verification records (Cloudflare), personal publisher accounts
15
15
  and cookie-consent choices; before a sign-in with another school (``before_sign_in``)
16
- the personal accounts go too: Elsevier's keeps the school's access with it. Besides the profile's own cookie store it filters
16
+ the personal accounts go too: Elsevier's keeps the school's access with it, while that school's own sign-in (its
17
+ login hosts and domains) stays, as it would come back as it is. Besides the profile's own cookie store it filters
17
18
  the files that put cookies back: the session cookies saved for the next
18
19
  launch and the saved publisher cookies. IndexedDB goes per site. Chrome keeps
19
20
  every site's local storage in one database, which goes whole when it holds a
@@ -35,9 +36,10 @@ from . import federations
35
36
  from .browser.backend import SESSION_COOKIES_FILE, chrome_profile_dir, profile_holder
36
37
  from .browser.cookies import _CLOUDFLARE_COOKIE_NAMES, PUBLISHER_DOMAINS
37
38
  from .engine.batch_institution import InstitutionMixin, _school_auth_patterns
39
+ from .schools import lookup as school_lookup
38
40
 
39
41
  DELETE = ("school_login", "publisher", "other_site")
40
- KEEP = ("verification", "personal_account", "consent")
42
+ KEEP = ("verification", "personal_account", "consent", "own_school")
41
43
 
42
44
  # Personal publisher accounts (Elsevier's account system); extend when another
43
45
  # publisher keeps personal sign-in on a host of its own.
@@ -67,17 +69,24 @@ def _publisher_domains() -> tuple[str, ...]:
67
69
 
68
70
  class Classifier:
69
71
  """Sorts a cookie (host, name) or a site's data (host) into the categories above. ``accounts``: the personal
70
- publisher accounts are forgotten as a school's login (another school to sign in with)."""
72
+ publisher accounts are forgotten as a school's login (another school to sign in with). ``keep_own``: the sign-in of
73
+ ``config``'s school, the one about to sign in, is kept (its login hosts and domains, not a service other schools
74
+ sign in on): forgetting another school's need not make it type its password again, which its login answered with
75
+ a picture code after a few that day (a test school, Windows, 2026-11-22)."""
71
76
 
72
- def __init__(self, config: dict[str, Any], accounts: bool = False):
77
+ def __init__(self, config: dict[str, Any], accounts: bool = False, keep_own: bool = False):
73
78
  self.school_tokens = tuple(t.lower() for t in _school_auth_patterns(config) if t)
74
79
  self.publishers = _publisher_domains()
75
80
  self.accounts = accounts
81
+ own = (*school_lookup.login_hosts(config), *school_lookup.domains(config)) if keep_own else ()
82
+ self.own = tuple(h for h in dict.fromkeys(own) if h and not _under(h, FEDERATION_HOSTS))
76
83
 
77
84
  def __call__(self, host: str, name: str = "") -> str:
78
85
  host = (host or "").lower().lstrip(".").split(":")[0]
79
86
  if name and (name in _CLOUDFLARE_COOKIE_NAMES or name.startswith(("cf_chl", "__cf"))):
80
87
  return "verification"
88
+ if self.own and _under(host, self.own):
89
+ return "own_school"
81
90
  if _under(host, PERSONAL_ACCOUNT_HOSTS):
82
91
  # Elsevier's account keeps the school it was signed in through (remember.me signs the next visit in with
83
92
  # it, the school's access and all: a test of another school passed with the last one's, user 2026-11-21).
@@ -110,10 +119,11 @@ def _netscape_rows(path: Path) -> list[list[str]]:
110
119
 
111
120
 
112
121
  class ColdStart:
113
- def __init__(self, profile: Path, cache_dir: Path | None, config: dict[str, Any], accounts: bool = False):
122
+ def __init__(self, profile: Path, cache_dir: Path | None, config: dict[str, Any], accounts: bool = False,
123
+ keep_own: bool = False):
114
124
  self.profile = profile
115
125
  self.cache_dir = cache_dir # None: the profile only, no saved cookie files
116
- self.classify = Classifier(config, accounts)
126
+ self.classify = Classifier(config, accounts, keep_own)
117
127
 
118
128
  # -- reading ------------------------------------------------------------
119
129
 
@@ -265,7 +275,7 @@ def _write_json(path: Path, data: Any) -> None:
265
275
 
266
276
 
267
277
  def for_config(config: dict[str, Any], profile: str | None = None, cache_dir: str | None = None,
268
- accounts: bool = False) -> ColdStart:
278
+ accounts: bool = False, keep_own: bool = False) -> ColdStart:
269
279
  """The cold start for the configured download profile (Chrome's own directory)
270
280
  and the configured cache. Another profile comes with only the cache named for
271
281
  it: the configured cache belongs to the configured profile."""
@@ -273,9 +283,9 @@ def for_config(config: dict[str, Any], profile: str | None = None, cache_dir: st
273
283
  from .engine.batch_common import _resolve_profile_dir
274
284
 
275
285
  if profile:
276
- return ColdStart(Path(profile), Path(cache_dir) if cache_dir else None, config, accounts)
286
+ return ColdStart(Path(profile), Path(cache_dir) if cache_dir else None, config, accounts, keep_own)
277
287
  cache = cache_dir or config.get("cache_dir", str(DATA_DIR / "cache"))
278
- return ColdStart(chrome_profile_dir(_resolve_profile_dir(config)), Path(cache), config, accounts)
288
+ return ColdStart(chrome_profile_dir(_resolve_profile_dir(config)), Path(cache), config, accounts, keep_own)
279
289
 
280
290
 
281
291
  # -- another school's sign-in --------------------------------------------------------------------
@@ -313,8 +323,9 @@ def before_sign_in(config: dict[str, Any], *, always: bool = False) -> str:
313
323
  _signed_in_path().parent.mkdir(parents=True, exist_ok=True)
314
324
  _write_json(_signed_in_path(), {"school": entity})
315
325
  return ""
316
- # The personal publisher accounts too: Elsevier's signs the next visit in with the last school's access.
317
- run = for_config(config, accounts=True)
326
+ # The personal publisher accounts too: Elsevier's signs the next visit in with the last school's access. The school
327
+ # about to sign in keeps its own sign-in, but not for a test (``always``): its account is what the test tries.
328
+ run = for_config(config, accounts=True, keep_own=not always)
318
329
  try:
319
330
  run.apply()
320
331
  except RuntimeError:
@@ -84,6 +84,9 @@ DEFAULT_CONFIG: dict[str, Any] = {
84
84
  "publisher_hourly_limit": 100,
85
85
  # 改了上面的上限时,正在等上限的篇目是否立即按新上限接着下;false = 这一小时过后再按新上限。
86
86
  "publisher_hourly_limit_now": False,
87
+ # 失败后自动重试:原因不明的批量最后再试一次,被网站拦截的 10 分钟后再试一次;默认关(用户 2026-11-24)。
88
+ "batch_retry_failed": False,
89
+ # 验证码识别服务(用户 2026-11-25 定):见 browser/challenge/services/solver.py。
87
90
  # 没权限时换下一所学校 (school_switch.py; user, 2026-11-21): on unless turned off.
88
91
  "school_switch": True,
89
92
  # 灰色源竞速浏览器的独立无头开关(只影响 sci-hub 竞速,机构登录仍有可见窗口)。
@@ -131,7 +134,7 @@ def _from_before_rename(existing: dict[str, Any]) -> dict[str, Any]:
131
134
  return existing
132
135
 
133
136
 
134
- def load_config() -> dict[str, Any]:
137
+ def load_config(*, strict: bool = False) -> dict[str, Any]:
135
138
  config = DEFAULT_CONFIG.copy()
136
139
  if CONFIG_FILE.exists():
137
140
  try:
@@ -139,8 +142,11 @@ def load_config() -> dict[str, Any]:
139
142
  existing = json.load(fh)
140
143
  if isinstance(existing, dict):
141
144
  config.update(_from_before_rename(existing))
145
+ elif strict:
146
+ raise ValueError("School backend configuration must be a JSON object")
142
147
  except Exception:
143
- pass
148
+ if strict:
149
+ raise
144
150
  for key, value in DEFAULT_CONFIG.items():
145
151
  config.setdefault(key, value)
146
152
  for key in _RETIRED_KEYS:
@@ -149,14 +155,9 @@ def load_config() -> dict[str, Any]:
149
155
 
150
156
 
151
157
  def save_config(config: dict[str, Any]) -> None:
152
- DATA_DIR.mkdir(parents=True, exist_ok=True)
153
- with CONFIG_FILE.open("w", encoding="utf-8") as fh:
154
- json.dump(config, fh, indent=2, ensure_ascii=False)
155
- try:
156
- # Readable by the user only: it may hold a school's account (school_login.py).
157
- CONFIG_FILE.chmod(0o600)
158
- except OSError:
159
- pass
158
+ from .cli_config import write_private_json
159
+
160
+ write_private_json(CONFIG_FILE.resolve(), config)
160
161
 
161
162
 
162
163
  _VALIDATION_RULES: dict[str, tuple[type, Any, Any]] = {
@@ -29,6 +29,7 @@ unsupported_platform unsupported_publisher user_skipped user_marked_no_entitleme
29
29
  article_not_yet_published doi_not_resolved doi_not_registered network_unavailable
30
30
  institution_federation_unavailable browser_unresponsive browser_operation_timeout login_not_reached idp_no_return_to_publisher
31
31
  generic_institution_entry_missing no_institution_entry browser_closed browser_connection_lost
32
+ pdf_not_offered
32
33
  """.split())
33
34
  _STATES = _FAILURES | _STATUSES | frozenset("""
34
35
  started article_loaded article_loaded_after_sso pdf_response_captured
@@ -58,9 +59,9 @@ pdf_capture_started pdf_navigation_error pdf_saved pdf_state_candidate post_logi
58
59
  post_login_hold_article_access post_login_hold_auth_wall post_login_hold_login_page
59
60
  post_run_hold publisher_access_blocked publisher_content_error publisher_unreachable publisher_login_menu_opened
60
61
  publisher_pdf_link_unverified publisher_session_save_failed publisher_session_saved
61
- publisher_terms_accepted personal_account_offer_skipped personal_account_offer_left
62
+ publisher_terms_accepted download_terms_agreed personal_account_offer_skipped personal_account_offer_left
62
63
  record_article_return record_article_return_error seamlessaccess_chooser_opened
63
- shared_cookies_exported shared_cookies_loaded sso_entry_clicked sso_entry_error sso_start
64
+ shared_cookies_exported shared_cookies_loaded sso_entry_clicked sso_entry_opened sso_entry_error sso_start challenge_type
64
65
  access_unknown_pdf_first access_unknown_pdf_failed pdf_step_login_required login_round_trip_returned
65
66
  pdf_probe pdf_probe_captured pdf_probe_refused no_access_after_login pdf_found_while_waiting
66
67
  login_entry_missing login_entry_controls access_menu_opened access_menu_entry_refused access_menu_error
@@ -161,6 +162,10 @@ def serialize_download_result(result, *, phase=None, full_text=None,
161
162
  "final_url_role": _url_role(_get(result, "final_url")),
162
163
  "pdf_url_role": _url_role(_get(result, "pdf_url")),
163
164
  }
165
+ from .browser.challenge.kinds import LABELS as CHALLENGE_TYPES
166
+ challenge_type = _get(result, "challenge_type")
167
+ if type(challenge_type) is str and challenge_type in CHALLENGE_TYPES:
168
+ packet["challenge_type"] = challenge_type
164
169
  if phase is not None:
165
170
  packet["phase"] = _choice(phase, {"primary", "retry"}, "unknown")
166
171
  if doi and type(artifact_name) is str and artifact_name == re.sub(r"[^\w\-.]", "_", doi) + ".pdf":
@@ -201,6 +201,12 @@ OPEN_SIGNS_JS = r"""() => {
201
201
  if (/(?:^|\s)license(?:\s|$)/i.test(link.getAttribute('rel')) && CC.test(link.href) && !link.closest(NOT))
202
202
  return `licence link: ${short(link.href)}`;
203
203
  }
204
+ // A licence badge named for what it is, without rel="license": F1000's open research platforms'
205
+ // <a aria-label="Creative Commons License CC-BY" href="https://creativecommons.org/licenses/">
206
+ // (Bioethics Open Research, taken for a closed page and sent to the school's login, 2026-11-24).
207
+ for (const a of document.querySelectorAll('a[href][aria-label*="creative commons licen" i]')) {
208
+ if (CC.test(a.href) && !a.closest(NOT)) return `licence link: ${short(a.href)}`;
209
+ }
204
210
  for (const script of [...document.querySelectorAll('script[type="application/ld+json"]')].slice(0, 8)) {
205
211
  let data;
206
212
  try { data = JSON.parse((script.textContent || '').slice(0, 200000)); } catch (_) { continue; }
@@ -254,9 +260,10 @@ def reader_access(lines: list[str], text: str, probe: dict) -> str:
254
260
  # Short controls and labels, a whole line or a control's whole text (links in a
255
261
  # row share a line: BMJ's "Buy this article ($64)", Thieme's "Buy Article"):
256
262
  # "Buy article PDF 39,95 €", "Purchase PDF", "Rent this article", "Get Access",
257
- # "Check Access" (journals.lww.com, Ovid).
263
+ # "Check Access" (journals.lww.com, Ovid); Taylor & Francis's "Purchase options *" heading over its
264
+ # "Issue Purchase" box, the school signed in (Scand J Rheumatol 2013, Windows 2026-11-22).
258
265
  OFFER_LABEL = (r"(?:buy|purchase|rent)\s+(?:this\s+)?(?:article|pdf|chapter|e-?book|issue|instant access|access)\b.{0,40}"
259
- r"|(?:get|check)\s+access")
266
+ r"|(?:get|check)\s+access|purchase options\W{0,3}|issue purchase")
260
267
  _OFFER_LINE = re.compile(OFFER_LABEL, re.I)
261
268
  # Sentences only a reader without access is shown, anywhere in a line.
262
269
  _OFFER_PHRASE = re.compile(
@@ -269,13 +276,16 @@ _OFFER_PHRASE = re.compile(
269
276
  # read this": RSC and Oxford Academic "You do not currently have access to this
270
277
  # content/article.", ScienceDirect "<school> does not subscribe to this content
271
278
  # on ScienceDirect.", Sage "Access via <school> is not available as they do not
272
- # subscribe to Sage Journals content.". A whole line: help copy and
273
- # conditionals around it are not a denial.
279
+ # subscribe to Sage Journals content.", nature.com "Access to this article via <institution>
280
+ # is not available." (its name in <strong> with no spaces around it, so the line reads
281
+ # "via<name>is not available"; Nature Cities, Windows 2026-11-24). A whole line: help copy
282
+ # and conditionals around it are not a denial.
274
283
  _DENIAL_LINE = re.compile(
275
284
  r"(?:(?:(?P<who>you|your (?:institution|organi[sz]ation))|(?P<name>[^.!?:\"“”]{2,120}?))\s+(?:do|does)\s+not"
276
285
  r"\s+(?:currently\s+)?(?:have access to|subscribe to)\s+(?:this|the)\s+"
277
286
  r"(?:article|content|pdf|full text|journal|book|chapter)(?:\s+on\s+[^.!?]{2,40})?"
278
- r"|access via (?P<via>[^.!?]{2,120}?) is not available as they do not subscribe to [^.!?]{2,80}"
287
+ r"|access (?:to this (?:article|content|chapter|book|pdf|issue)\s+)?via\s*(?P<via>[^.!?]{2,120}?)\s*is not available"
288
+ r"(?:\s+as they do not subscribe to [^.!?]{2,80})?"
279
289
  r"|your (?:institution|organi[sz]ation) has not (?:subscribed to this content|purchased access to this article))\.?",
280
290
  re.I)
281
291
  _DENIAL_CONTEXT = re.compile(
@@ -94,6 +94,15 @@ from .batch_user import PdfFoundWhileWaiting, UserProvidedPdf, UserRequestsMixin
94
94
  from ..browser import watchdog
95
95
  from ..entitlements import UserSkippedArticle, UserStoppedBatch
96
96
 
97
+ # Why a school login that ended without the article ended, set by the login itself: kept as the
98
+ # article's reason, not "PDF not captured". DBpia's institution search had no entry for the school
99
+ # (institution_federation_unavailable, its wait ended so), and the article was reported as 原因不明 ·
100
+ # 没取到 PDF (Windows 2026-11-24).
101
+ _LOGIN_ENDINGS = frozenset({GENERIC_ENTRY_MISSING, NO_INSTITUTION_ENTRY, "institution_federation_unavailable",
102
+ "publisher_institution_entry_missing", "idp_no_return_to_publisher"})
103
+ # An article open to all that its site gives as a web page only (``_page_offers_no_pdf``).
104
+ PDF_NOT_OFFERED = "pdf_not_offered"
105
+
97
106
 
98
107
  class PublisherBatchDownloader(
99
108
  LoginMixin,
@@ -388,6 +397,8 @@ class PublisherBatchDownloader(
388
397
  require_interactive_browser: bool = False,
389
398
  ) -> None:
390
399
  self.config = load_config() if config is None else config
400
+ from ..browser.challenge.services.solver import Budget
401
+ self._captcha_budget = Budget(config=self.config)
391
402
  self.profile = profile
392
403
  self.institution_query = institution_query.strip()
393
404
  self.login_timeout_sec = login_timeout_sec
@@ -447,7 +458,7 @@ class PublisherBatchDownloader(
447
458
  config["browser_headless"] = False
448
459
  started = time.time()
449
460
  ctx = get_persistent_context(profile_path, config)
450
- from ..browser.challenge.interaction import prepare_context
461
+ from ..browser.challenge.local.interaction import prepare_context
451
462
  prepare_context(ctx)
452
463
  self._browser_start = {**dict(getattr(browser_backend, "LAST_LAUNCH", {}) or {}),
453
464
  "seconds": round(time.time() - started, 1), **({"relaunch": relaunch} if relaunch else {})}
@@ -488,6 +499,7 @@ class PublisherBatchDownloader(
488
499
  self._record_title = record.title
489
500
  self._expected_title = ""
490
501
  self._manual_school = False
502
+ self._article_host = "" # the site the article opens on (_note_article_host)
491
503
  self._track_article_for_adapter(page, record.doi)
492
504
  from ..browser import watchdog
493
505
 
@@ -555,16 +567,24 @@ class PublisherBatchDownloader(
555
567
  # reader's access showed): the school's login, once, then the PDF again.
556
568
  # So too for a page taken as open to all whose PDF entry asked for access
557
569
  # (PNAS 2026-11-17: a Creative Commons line in the copyright notes, "GET
558
- # ACCESS" by the title, the PDF addresses 403 until the school's login).
559
- gated = (getattr(result, "_taken_as_open", False)
560
- and any(e["state"] == "pdf_entry_gated" for e in result.events))
570
+ # ACCESS" by the title, the PDF addresses 403 until the school's login), and
571
+ # for one whose PDF was sent to the article's web page: open for its web page
572
+ # only, or not at all (JAMA's citation_fulltext_world_readable, 10.1001/jama.2025.19316;
573
+ # jacc.org's "This is an Open Access Article" by "GET ACCESS", 10.1016/j.jcmg.2025.09.021;
574
+ # both ended as pdf_not_captured, no school tried, Windows 2026-11-23).
575
+ taken_as_open = getattr(result, "_taken_as_open", False)
576
+ sent_back = self._pdf_sent_to_article(page, result, attempts_from) if taken_as_open else []
577
+ gated = bool(taken_as_open and (sent_back or any(e["state"] == "pdf_entry_gated" for e in result.events)))
561
578
  retry = (not wall and (getattr(result, "_pdf_first", False) or gated) and not self._school_login_done())
562
579
  if wall or retry:
563
580
  if wall:
564
581
  self._event(result, "auth_wall_after_pdf_attempt", self._decision_text(page))
565
582
  else:
583
+ url = str(getattr(page, "url", "") or "")
566
584
  self._event(result, "open_access_pdf_gated" if gated and not getattr(result, "_pdf_first", False)
567
- else "access_unknown_pdf_failed", getattr(page, "url", ""))
585
+ else "access_unknown_pdf_failed",
586
+ f"{url[:160]} | PDF sent to the article's web page: {str(sent_back[-1].get('url'))[:120]}"
587
+ if sent_back else url)
568
588
  self._reopen_article_page(page, result)
569
589
  result._pdf_retry_login = True
570
590
  logged_in = self._complete_login_from_current_page(page, result)
@@ -589,6 +609,8 @@ class PublisherBatchDownloader(
589
609
  result.state = "article_loaded_after_sso"
590
610
  pdf_bytes, pdf_url, cap_block = self._capture_pdf(page, record.doi, result)
591
611
  ip_block = ip_block or cap_block
612
+ else:
613
+ self._note_wait_end(page, result)
592
614
  result._pdf_retry_login = False
593
615
  if (not pdf_bytes and not ip_block and result.reason != "institution_pdf_entitlement_missing"
594
616
  and not self._pdf_sent_to_article_after_login(page, result, attempts_from)
@@ -620,10 +642,14 @@ class PublisherBatchDownloader(
620
642
  self._write_diagnostic(page, result, run_dir)
621
643
  return result
622
644
  if not pdf_bytes:
623
- # A site whose page offered no institution entry (one without rules, or
624
- # a sign-in that was the publisher's own account's) says so.
625
- result.reason = result.state = (result.reason if result.reason in (
626
- GENERIC_ENTRY_MISSING, NO_INSTITUTION_ENTRY) else "pdf_not_captured")
645
+ # The login's own ending says why (_LOGIN_ENDINGS): a site whose page offered no
646
+ # institution entry, a school the publisher's list lacks. A wait on the user that ran
647
+ # out says where it ended, as for a login that did not complete (_login_failed: the
648
+ # bridge's login_timeout or login_not_reached): DBpia's institution search found
649
+ # nothing for a school, the wait stood a minute on it, then 没取到 PDF (2026-11-24).
650
+ result.reason = result.state = (
651
+ result.reason if result.reason in _LOGIN_ENDINGS
652
+ else "sso_required" if getattr(result, "login_wait_page", "") else "pdf_not_captured")
627
653
  result.final_url = page.url
628
654
  result.title = self._title(page)
629
655
  self._write_diagnostic(page, result, run_dir)
@@ -636,9 +662,17 @@ class PublisherBatchDownloader(
636
662
  self._write_diagnostic(page, result, run_dir)
637
663
  return result
638
664
  block_reason = self._login_block_reason(page)
639
- if (not block_reason and signed_in
665
+ # The capture came after this item's school login, or none came in this item:
666
+ # then the school's session on the page, from an earlier item, is what counts.
667
+ if (not block_reason and (signed_in or not self._school_login_done())
640
668
  and self._pdf_sent_to_article_after_login(page, result, attempts_from)):
641
669
  block_reason = "institution_pdf_entitlement_missing"
670
+ if (not block_reason and taken_as_open and len(result.pdf_attempts) == attempts_from
671
+ and self._page_offers_no_pdf(page)):
672
+ # Open to all, nothing tried, and nothing on the page names a PDF.
673
+ block_reason = PDF_NOT_OFFERED
674
+ self._event(result, PDF_NOT_OFFERED, f"{str(getattr(page, 'url', '') or '')[:160]} | "
675
+ f"{self._title(page)[:80]} | nothing on the page names a PDF")
642
676
  result.reason = block_reason or "pdf_not_captured"
643
677
  result.state = result.reason
644
678
  result.final_url = page.url
@@ -693,7 +727,7 @@ class PublisherBatchDownloader(
693
727
  except PublisherPlatformUnsupported as platform:
694
728
  result.reason = result.state = "unsupported_platform"
695
729
  self._event(result, "unsupported_platform", str(platform))
696
- progress_reporter.update(phase=f"这篇文章只在 {platform} 平台提供,暂不支持,当前路径已停止")
730
+ progress_reporter.update(phase=f"这篇文章只在 {platform} 平台提供,PaperSearch 还没有这个平台的规则,当前路径已停止")
697
731
  self._write_diagnostic(page, result, run_dir)
698
732
  return result
699
733
  except PublisherContentError as error:
@@ -860,13 +894,19 @@ class PublisherBatchDownloader(
860
894
  step; elsewhere the program did not reach the login, ADR 0012)."""
861
895
  result.reason = self._login_block_reason(page) or result.reason or "sso_required"
862
896
  result.state = result.reason
863
- if result.reason == "login_timeout" or (
864
- result.reason == "sso_required" and getattr(result, "_user_wait_expired", False)):
865
- result.login_wait_page = self._login_wait_page(page)
866
- self._event(result, "login_wait_ended", result.login_wait_page)
897
+ if result.reason in ("login_timeout", "sso_required"):
898
+ self._note_wait_end(page, result)
867
899
  self._write_diagnostic(page, result, run_dir)
868
900
  return result
869
901
 
902
+ def _note_wait_end(self, page: Any, result: DownloadResult) -> None:
903
+ """A wait on the user that ran out: where it ended (``login_wait_page``). Also after the login a failed PDF
904
+ asked for (Thieme's wait ended on its school list page, JAMA's on the school's login page, and neither said
905
+ where: both counted as the user's, Windows 2026-11-22)."""
906
+ if result.reason == "login_timeout" or getattr(result, "_user_wait_expired", False):
907
+ result.login_wait_page = self._login_wait_page(page)
908
+ self._event(result, "login_wait_ended", result.login_wait_page)
909
+
870
910
  def _save_captured_pdf(self, page: Any, record: PaperRecord, result: DownloadResult, run_dir: Path,
871
911
  pdf_bytes: bytes, pdf_url: str) -> DownloadResult:
872
912
  """Check that a captured PDF is this article's and save it with its record."""
@@ -27,7 +27,15 @@ from .batch_common import (
27
27
  # not answer: Envoy, nginx and similar. Nothing else is on such a page.
28
28
  # A publisher's own page for a blocked address: "Your IP has been blocked.", "Your IP
29
29
  # 69.63.193.18 has been blocked." (Science, 2026-11-16), "your IP address … has been blocked".
30
- _IP_BLOCKED = re.compile(r"\byour ip(?: address)?(?: [0-9a-f.:]+)? (?:has been|is) blocked\b")
30
+ # Taylor & Francis (2026-11-25), a page titled "Error" for the article, its PDF and its institution entry alike:
31
+ # "The IP address of 203.0.113.7 has not been recognised to access this page. Please contact … quoting the IP address".
32
+ # Not recognised, the driver took its sign-in button for the school's login and waited on the user each paper,
33
+ # then wrote 没权限. A web firewall's page in Chinese, under that line as the title (Sage's sage.cnpereading.com, HTTP
34
+ # 592, 2026-11-25: "您的访问请求可能对网站造成安全威胁,请求已被阻断"): taken for an article page without a login entry,
35
+ # each paper written 待适配.
36
+ _IP_BLOCKED = re.compile(r"\byour ip(?: address)?(?: [0-9a-f.:]+)? (?:has been|is) blocked\b"
37
+ r"|\bthe ip address (?:of )?[0-9a-f.:]+ has not been recogni[sz]ed to access\b"
38
+ r"|访问请求可能对网站造成安全威胁")
31
39
  _GATEWAY_ERROR_MARKERS = (
32
40
  "upstream connect error or disconnect/reset before headers",
33
41
  "502 bad gateway", "503 service unavailable", "503 service temporarily unavailable",
@@ -171,7 +179,8 @@ class AccessMixin:
171
179
  """The publisher's own page for a blocked address, under its usual title (Science,
172
180
  2026-11-16: "Your IP 69.63.193.18 has been blocked."): no login can open it. Read
173
181
  from the article page's text the access check reads anyway (``_access_snapshot``)."""
174
- return bool(_IP_BLOCKED.search(" ".join(text[:4000].lower().split())))
182
+ # Its start, and its end: Taylor & Francis writes it after the site's whole header.
183
+ return bool(_IP_BLOCKED.search(" ".join((text[:4000] + "\n" + text[-2000:]).lower().split())))
175
184
 
176
185
  def _raise_on_publisher_access_blocked(self, page: Any) -> None:
177
186
  if self._publisher_access_blocked(page):
@@ -264,7 +273,12 @@ class AccessMixin:
264
273
  def _article_access_available(self, page: Any) -> bool:
265
274
  """The article page no longer says the reader is signed out: the PDF
266
275
  decides. In the login that follows a failed PDF, only the institution's
267
- session or a completed login round trip count."""
276
+ session or a completed login round trip count, and on the site the adapter
277
+ sent the login to (``_on_login_site``) also access every reader has there
278
+ (``access_rules.OPEN_TO_ALL``: an open-access badge or licence): that page is
279
+ not the one whose PDF failed. Not "Full text access" alone: ScienceDirect
280
+ shows it for full text through ClinicalKey or a personal account, with no PDF
281
+ (J Hepatol, 2026-10-31), and the school's login there is still to be done."""
268
282
  # A verification/error page can retain the exact article URL. Its
269
283
  # lack of a sign-in button is not evidence of full-text access.
270
284
  if page.is_closed() is True:
@@ -274,15 +288,26 @@ class AccessMixin:
274
288
  return False
275
289
  if self._institution_pdf_entitlement_missing(page):
276
290
  return False
277
- if not self._is_success_article_url(getattr(page, "url", "")):
291
+ url = str(getattr(page, "url", "") or "")
292
+ if not self._is_success_article_url(url):
278
293
  return False
279
- verdict, basis, _ = self._access_decision(page)
294
+ verdict, basis, evidence = self._access_decision(page)
280
295
  if verdict == access_rules.OUT:
281
296
  return False
282
297
  if basis == "session" or self._school_login_done():
283
298
  return True
284
299
  # The login that follows a failed PDF waits for the school's login itself.
285
- return not getattr(getattr(self, "_item_result", None), "_pdf_retry_login", False)
300
+ result = getattr(self, "_item_result", None)
301
+ if not getattr(result, "_pdf_retry_login", False):
302
+ return True
303
+ # Its sign-in sent to this article on another site, open to every reader there:
304
+ # the PDF is taken there (ScienceDirect's "Open access" for jacc.org's 403, 2026-11-23).
305
+ if (verdict != access_rules.IN or not access_rules.OPEN_TO_ALL.search(evidence.split("badge: ", 1)[-1])
306
+ or not self._on_login_site(page, result)):
307
+ return False
308
+ if not any(e["state"] == "login_site_article_readable" for e in result.events):
309
+ self._event(result, "login_site_article_readable", f"{url[:160]} | {verdict} ({basis}): {evidence[:160]}")
310
+ return True
286
311
 
287
312
  def _school_login_done(self) -> bool:
288
313
  """This item reached its IdP; selecting a school is only an attempt."""
@@ -311,17 +336,18 @@ class AccessMixin:
311
336
  return True
312
337
  return bool(named) and self._names_configured_school(named)
313
338
 
314
- def _no_access_after_login(self, page: Any, result: DownloadResult) -> str:
315
- """Evidence that the article page, after this item's school login, still
316
- denies the article, shows only its abstract, offers it for sale or is the
317
- site's signed-out page type; "" otherwise, and while the site's own login
318
- pages remain to be opened (an Elsevier journal's site signs in on itself,
339
+ def _no_access_after_login(self, page: Any, result: DownloadResult, *, session_shown: bool = False) -> str:
340
+ """Evidence that the article page, after this item's school login (or with
341
+ the school's session shown on it, ``session_shown``: signed in by an earlier
342
+ item), still denies the article, shows only its abstract, offers it for sale
343
+ or is the site's signed-out page type; "" otherwise, and while the site's own
344
+ login pages remain to be opened (an Elsevier journal's site signs in on itself,
319
345
  then on ScienceDirect) or the login site's own article remains to be tried
320
346
  (``_return_from_login_site``). Not the "Access through <school>" gate: that
321
347
  is a remembered school not signed in on this site."""
322
348
  url = str(getattr(page, "url", "") or "")
323
349
  if (not self._is_success_article_url(url) or self._is_auth_page(url)
324
- or self._is_challenge_page(page) or not self._school_login_done()):
350
+ or self._is_challenge_page(page) or not (session_shown or self._school_login_done())):
325
351
  return ""
326
352
  opened = {e.get("detail") for e in result.events if e["state"] == "login_page_opened"}
327
353
  if any(target not in opened for target in self.adapter.login_page_urls(page)):
@@ -435,15 +461,27 @@ class AccessMixin:
435
461
 
436
462
  def _is_success_article_url(self, url: str) -> bool:
437
463
  verdict = self.adapter.is_article_page_url(url)
438
- if verdict is not None:
439
- return verdict
440
- verdict = self.adapter.is_success_article_url(url)
441
- if verdict is not None:
442
- return verdict
443
- lower = url.lower()
444
- if self.profile.success_url_markers:
445
- return any(marker in lower for marker in self.profile.success_url_markers)
446
- return self._names_this_article(url)
464
+ if verdict is None:
465
+ verdict = self.adapter.is_success_article_url(url)
466
+ if verdict is None and self.profile.success_url_markers:
467
+ lower = url.lower()
468
+ verdict = any(marker in lower for marker in self.profile.success_url_markers)
469
+ if verdict is None:
470
+ return self._names_this_article(url)
471
+ # A rule of the publisher's that does not take the page still yields to an address ending
472
+ # in this item's DOI: a rule written for the publisher's own DOI prefix missed a journal it
473
+ # took over, which kept its prefix (Thieme's Thrombosis and Haemostasis, 10.1160, 2026-11-22).
474
+ return verdict or self._address_ends_with_this_doi(url)
475
+
476
+ def _address_ends_with_this_doi(self, url: str) -> bool:
477
+ """A page of the publisher's site, not a login page, whose path ends with this
478
+ item's DOI (as is or %2F-escaped, in any case): how article pages are addressed by
479
+ DOI. A PDF or a supplementary file has more after the DOI."""
480
+ doi = str(getattr(self, "_adapter_doi", "") or "").strip().lower()
481
+ if (not doi or not str(url or "").startswith("http") or not self._on_publisher_host(url)
482
+ or self._is_auth_page(url)):
483
+ return False
484
+ return unquote(urlparse(url).path).lower().rstrip("/").endswith("/" + doi)
447
485
 
448
486
  def _names_this_article(self, url: str) -> bool:
449
487
  """The article page for a profile without article-page markers of its own