papersearch 0.6.1 → 0.6.3
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/README.en.md +10 -3
- package/README.md +10 -3
- package/dist/capabilities/pdf-discovery/batch.d.ts +6 -0
- package/dist/capabilities/pdf-discovery/batch.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/batch.js +20 -5
- package/dist/capabilities/pdf-discovery/batch.js.map +1 -1
- package/dist/capabilities/pdf-discovery/school/SchoolMcpClient.d.ts +7 -0
- package/dist/capabilities/pdf-discovery/school/SchoolMcpClient.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/school/SchoolMcpClient.js +39 -1
- package/dist/capabilities/pdf-discovery/school/SchoolMcpClient.js.map +1 -1
- package/dist/capabilities/pdf-discovery/school/SchoolReadiness.d.ts +2 -0
- package/dist/capabilities/pdf-discovery/school/SchoolReadiness.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/school/SchoolReadiness.js +3 -0
- package/dist/capabilities/pdf-discovery/school/SchoolReadiness.js.map +1 -1
- package/dist/capabilities/pdf-discovery/school/types.d.ts +7 -0
- package/dist/capabilities/pdf-discovery/school/types.d.ts.map +1 -1
- package/dist/infrastructure/pdf/PdfIdentity.d.ts +4 -2
- package/dist/infrastructure/pdf/PdfIdentity.d.ts.map +1 -1
- package/dist/infrastructure/pdf/PdfIdentity.js +93 -18
- package/dist/infrastructure/pdf/PdfIdentity.js.map +1 -1
- package/dist/management/school/autoUpdate.d.ts.map +1 -1
- package/dist/management/school/autoUpdate.js +2 -0
- package/dist/management/school/autoUpdate.js.map +1 -1
- package/dist/management/school/cliProgress.d.ts.map +1 -1
- package/dist/management/school/cliProgress.js +1 -0
- package/dist/management/school/cliProgress.js.map +1 -1
- package/package.json +1 -1
- package/school/paper_search_school/assets/capsule.html +25 -12
- package/school/paper_search_school/assets/capsule_en.json +26 -1
- package/school/paper_search_school/browser/batch_session.py +81 -0
- package/school/paper_search_school/engine/batch.py +2 -0
- package/school/paper_search_school/engine/batch_institution.py +114 -1
- package/school/paper_search_school/engine/batch_login.py +27 -2
- package/school/paper_search_school/engine/bridge.py +5 -2
- package/school/paper_search_school/engine/pdf_guard.py +93 -14
- package/school/paper_search_school/federations/builtin/incommon.json +11 -0
- package/school/paper_search_school/federations/builtin/infed.json +11 -0
- package/school/paper_search_school/federations/builtin/liaf.json +11 -0
- package/school/paper_search_school/federations/builtin/omren.json +11 -0
- package/school/paper_search_school/federations/builtin/pkifed.json +11 -0
- package/school/paper_search_school/federations/builtin/tigerfed.json +11 -0
- package/school/paper_search_school/federations/builtin/yetkim.json +11 -0
- package/school/paper_search_school/federations/schools.py +53 -12
- package/school/paper_search_school/progress_reporter.py +15 -3
- package/school/paper_search_school/progress_view.py +39 -2
- package/school/paper_search_school/rate_limit.py +30 -16
- package/school/paper_search_school/server.py +16 -1
- package/skills/paper-search/SKILL.md +2 -1
- package/skills/paper-search/references/federation-support.md +19 -3
- package/skills/paper-search/references/school-setup.md +2 -2
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
"""One browser window and tab kept for a serial MCP batch, on its Playwright
|
|
2
2
|
worker thread. Used when the backend declares ``batch_window``
|
|
3
3
|
(browser/backend.py); only plain Playwright calls, no backend of its own."""
|
|
4
|
+
import time
|
|
4
5
|
from contextvars import ContextVar
|
|
6
|
+
from urllib.parse import urlsplit
|
|
5
7
|
|
|
8
|
+
from . import challenges
|
|
6
9
|
from .preview import ensure_enabled
|
|
7
10
|
|
|
8
11
|
|
|
12
|
+
# How long a keep-alive load of the article page may take, and how long the page then
|
|
13
|
+
# has to settle back on the article's site (a Cloudflare check cleared, a sign-in the
|
|
14
|
+
# publisher runs by itself); the client waits up to a minute for all of it.
|
|
15
|
+
KEEP_SESSION_TIMEOUT_MS = 25_000
|
|
16
|
+
KEEP_SESSION_SETTLE_SECONDS = 20
|
|
17
|
+
|
|
18
|
+
|
|
9
19
|
class BatchBrowser:
|
|
10
20
|
def __init__(self):
|
|
11
21
|
self.context = None
|
|
12
22
|
self.page = None
|
|
13
23
|
self.info = None
|
|
14
24
|
self.id = ""
|
|
25
|
+
#: The publisher's article page of the last paper, when that paper saved its PDF.
|
|
26
|
+
self.article_url = ""
|
|
15
27
|
|
|
16
28
|
def open(self, downloader, *, relaunch=""):
|
|
17
29
|
if self.context is not None and not self.context.pages:
|
|
@@ -26,6 +38,37 @@ class BatchBrowser:
|
|
|
26
38
|
self.page = self.context.new_page()
|
|
27
39
|
return self.context
|
|
28
40
|
|
|
41
|
+
def keep_session(self):
|
|
42
|
+
"""While the batch waits (the hourly limit the user set): the last paper's
|
|
43
|
+
article page, loaded again in the batch's tab, so the publisher's institutional
|
|
44
|
+
session does not lapse for want of a request (Wiley: about half an hour,
|
|
45
|
+
2026-11-12). Only after a paper that saved its PDF: a tab left on a school's
|
|
46
|
+
login page is never taken away from the user.
|
|
47
|
+
|
|
48
|
+
A Cloudflare check met on the way is cleared as a download clears it (its
|
|
49
|
+
checkbox only). A page that does not come back to the article's site (a check
|
|
50
|
+
that does not clear, the publisher's own sign-in, a load that hangs) leaves the
|
|
51
|
+
tab blank, and no keep-alive runs again until a paper saves; the next paper signs
|
|
52
|
+
in as a download does. The tab sat spinning on a Cloudflare check, and on
|
|
53
|
+
Elsevier's sign-in page (id.elsevier.com) that never loaded, for the rest of the
|
|
54
|
+
wait (Windows, 2026-11-13)."""
|
|
55
|
+
page = self.page
|
|
56
|
+
if self.context is None or page is None or page.is_closed() or not self.article_url:
|
|
57
|
+
return {"kept": False, "reason": "no_publisher_page"}
|
|
58
|
+
try:
|
|
59
|
+
page.goto(self.article_url, wait_until="domcontentloaded", timeout=KEEP_SESSION_TIMEOUT_MS)
|
|
60
|
+
reason = _settle(page, _site(self.article_url))
|
|
61
|
+
except Exception as exc:
|
|
62
|
+
reason = type(exc).__name__
|
|
63
|
+
if not reason:
|
|
64
|
+
return {"kept": True}
|
|
65
|
+
self.article_url = ""
|
|
66
|
+
try:
|
|
67
|
+
page.goto("about:blank", timeout=5_000)
|
|
68
|
+
except Exception:
|
|
69
|
+
pass
|
|
70
|
+
return {"kept": False, "reason": reason}
|
|
71
|
+
|
|
29
72
|
def finish_item(self):
|
|
30
73
|
# Keep the original tab and its native window. Article/PDF/login
|
|
31
74
|
# popups cannot leak into the next publisher's page detection.
|
|
@@ -40,3 +83,41 @@ class BatchBrowser:
|
|
|
40
83
|
|
|
41
84
|
|
|
42
85
|
active_batch: ContextVar[BatchBrowser | None] = ContextVar("active_browser_batch", default=None)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _on_verification(page) -> bool:
|
|
89
|
+
try:
|
|
90
|
+
title = page.title()
|
|
91
|
+
except Exception:
|
|
92
|
+
title = "" # mid-navigation: the URL still tells
|
|
93
|
+
return challenges.looks_like_challenge(str(page.url or ""), title)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _site(url: str) -> str:
|
|
97
|
+
host = urlsplit(str(url or "")).hostname or ""
|
|
98
|
+
return host[4:] if host.startswith("www.") else host
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _settle(page, site: str) -> str:
|
|
102
|
+
""""" once the page has settled on the article's site, no Cloudflare check up; else,
|
|
103
|
+
after KEEP_SESSION_SETTLE_SECONDS, "verification" or "signin" (another site: the
|
|
104
|
+
publisher's sign-in, a school's login). A check's checkbox is clicked as in a
|
|
105
|
+
download (at most three times, three seconds apart)."""
|
|
106
|
+
from .challenge_interaction import click_checkbox
|
|
107
|
+
until = time.monotonic() + KEEP_SESSION_SETTLE_SECONDS
|
|
108
|
+
clicks, next_click = 0, 0.0
|
|
109
|
+
page.wait_for_timeout(2000) # a redirect the page makes once loaded
|
|
110
|
+
while True:
|
|
111
|
+
if _on_verification(page):
|
|
112
|
+
reason = "verification"
|
|
113
|
+
now = time.monotonic()
|
|
114
|
+
if clicks < 3 and now >= next_click:
|
|
115
|
+
if click_checkbox(page, timeout_ms=2500, checkpoint=lambda: None) == "clicked":
|
|
116
|
+
clicks, next_click = clicks + 1, time.monotonic() + 3
|
|
117
|
+
elif _site(page.url) == site:
|
|
118
|
+
return ""
|
|
119
|
+
else:
|
|
120
|
+
reason = "signin"
|
|
121
|
+
if time.monotonic() >= until:
|
|
122
|
+
return reason
|
|
123
|
+
page.wait_for_timeout(1000)
|
|
@@ -489,6 +489,7 @@ class PublisherBatchDownloader(
|
|
|
489
489
|
result._open_access_current = False
|
|
490
490
|
|
|
491
491
|
page.on("framenavigated", invalidate_open_access)
|
|
492
|
+
stop_following_route = self._follow_login_route(page, result)
|
|
492
493
|
try:
|
|
493
494
|
preparation = self._prepare_article(page, result, run_dir)
|
|
494
495
|
if preparation is not None:
|
|
@@ -697,6 +698,7 @@ class PublisherBatchDownloader(
|
|
|
697
698
|
return result
|
|
698
699
|
finally:
|
|
699
700
|
page.remove_listener("framenavigated", invalidate_open_access)
|
|
701
|
+
stop_following_route()
|
|
700
702
|
user_watch.set()
|
|
701
703
|
watchdog.on_slow_call = None
|
|
702
704
|
if isinstance(watchdog.interrupted, UserMarkedNoEntitlement) and result.ok:
|
|
@@ -11,6 +11,7 @@ from urllib.parse import parse_qs, unquote, urlencode, urljoin, urlparse
|
|
|
11
11
|
|
|
12
12
|
from .. import federations
|
|
13
13
|
from ..federations import schools
|
|
14
|
+
from . import access_rules
|
|
14
15
|
from .batch_common import (DownloadResult, _is_browser_error, _is_navigation_cut, logger, open_page,
|
|
15
16
|
pump_until, settle)
|
|
16
17
|
|
|
@@ -1192,16 +1193,128 @@ class InstitutionMixin:
|
|
|
1192
1193
|
return schools.on_login_page(self.config, url)
|
|
1193
1194
|
|
|
1194
1195
|
def _is_idp_host(self, host: str) -> bool:
|
|
1195
|
-
"""True for the configured school's identity provider or any generic campus IdP
|
|
1196
|
+
"""True for the configured school's identity provider or any generic campus IdP
|
|
1197
|
+
hostname, and for a host this item's login reached on the school's side
|
|
1198
|
+
(``_follow_login_route``)."""
|
|
1196
1199
|
host = (host or "").lower().split(":")[0]
|
|
1197
1200
|
if not host:
|
|
1198
1201
|
return False
|
|
1202
|
+
return host in getattr(self, "_school_side_hosts", ()) or self._known_school_host(host)
|
|
1203
|
+
|
|
1204
|
+
def _known_school_host(self, host: str) -> bool:
|
|
1205
|
+
"""The school's side by the host alone: its login hosts and domains, the
|
|
1206
|
+
identity services schools sign in with, a generic campus IdP hostname."""
|
|
1199
1207
|
if any(token in host for token in _school_auth_patterns(self.config)):
|
|
1200
1208
|
return True
|
|
1201
1209
|
if any(host == d or host.endswith("." + d) for d in (*schools.domains(self.config), *self._IDENTITY_SERVICE_HOSTS)):
|
|
1202
1210
|
return True
|
|
1203
1211
|
return bool(self._IDP_HOST_RE.match(host))
|
|
1204
1212
|
|
|
1213
|
+
# ---- the school's side, by the way this item's login went there
|
|
1214
|
+
|
|
1215
|
+
def _follow_login_route(self, page: Any, result: DownloadResult):
|
|
1216
|
+
"""Watch this item's main-frame navigations, every redirect hop included, by
|
|
1217
|
+
their addresses only (never form data); returns the function that stops.
|
|
1218
|
+
|
|
1219
|
+
A login that went from the publisher through a federation, a login service
|
|
1220
|
+
or an address asking for an identity provider (``_route_hop``) and reached a
|
|
1221
|
+
host that is none of these, before it came back to the publisher, is on the
|
|
1222
|
+
school's side: its identity provider on a host of another domain, and what
|
|
1223
|
+
that signs in with. The host counts as the school's for the rest of the item
|
|
1224
|
+
(``_is_idp_host``), so nothing is chosen or typed there (2026-11-12: a
|
|
1225
|
+
school's OpenAthens sign-in went on to its university system's login host,
|
|
1226
|
+
where the school's name was typed into a field)."""
|
|
1227
|
+
self._school_side_hosts: set[str] = set()
|
|
1228
|
+
self._route_hosts: set[str] = set()
|
|
1229
|
+
self._publisher_hosts: set[str] = set()
|
|
1230
|
+
self._route_away = False
|
|
1231
|
+
self._route_last_host = ""
|
|
1232
|
+
self._school_unreachable = ""
|
|
1233
|
+
|
|
1234
|
+
def requested(request: Any) -> None:
|
|
1235
|
+
if request.is_navigation_request() and request.frame == page.main_frame:
|
|
1236
|
+
self._note_route_hop(str(request.url or ""), result)
|
|
1237
|
+
|
|
1238
|
+
def failed(request: Any) -> None:
|
|
1239
|
+
# A navigation to the school's side that the network ended (its login
|
|
1240
|
+
# server did not answer): the browser shows its own error page next.
|
|
1241
|
+
if request.is_navigation_request() and request.frame == page.main_frame:
|
|
1242
|
+
failure = str(request.failure or "")
|
|
1243
|
+
host = (urlparse(str(request.url or "")).hostname or "").lower()
|
|
1244
|
+
if "net::ERR_" in failure and "ERR_ABORTED" not in failure and self._is_idp_host(host):
|
|
1245
|
+
self._school_unreachable = f"{host}: {failure}"
|
|
1246
|
+
|
|
1247
|
+
page.on("request", requested)
|
|
1248
|
+
page.on("requestfailed", failed)
|
|
1249
|
+
|
|
1250
|
+
def stop() -> None:
|
|
1251
|
+
page.remove_listener("request", requested)
|
|
1252
|
+
page.remove_listener("requestfailed", failed)
|
|
1253
|
+
self._school_side_hosts = set()
|
|
1254
|
+
self._school_unreachable = ""
|
|
1255
|
+
|
|
1256
|
+
return stop
|
|
1257
|
+
|
|
1258
|
+
def _note_route_hop(self, url: str, result: DownloadResult) -> None:
|
|
1259
|
+
kind = self._route_hop(url)
|
|
1260
|
+
if not kind:
|
|
1261
|
+
return
|
|
1262
|
+
host = (urlparse(url).hostname or "").lower()
|
|
1263
|
+
if kind in ("school", "route"):
|
|
1264
|
+
self._route_away = True
|
|
1265
|
+
if kind == "route" and self._names_identity_provider(url) and not self._login_service_host(host):
|
|
1266
|
+
# A publisher's or its platform's sign-in hub: its later pages are not the school's.
|
|
1267
|
+
self._route_hosts.add(host)
|
|
1268
|
+
elif kind == "publisher":
|
|
1269
|
+
self._route_away = False
|
|
1270
|
+
# Its other pages too (a journal site's sign-in step after its article).
|
|
1271
|
+
self._publisher_hosts.add(host)
|
|
1272
|
+
elif self._route_away and host not in self._route_hosts and host not in self._school_side_hosts:
|
|
1273
|
+
self._school_side_hosts.add(host)
|
|
1274
|
+
self._event(result, "school_side_host", f"{host} after {self._route_last_host}")
|
|
1275
|
+
self._route_last_host = host
|
|
1276
|
+
|
|
1277
|
+
def _route_hop(self, url: str) -> str:
|
|
1278
|
+
"""What one navigation hop is to the login: ``school`` (the school's side by
|
|
1279
|
+
its host or its login page on a shared service), ``route`` (a federation's
|
|
1280
|
+
or login service's page, or an address asking for an identity provider),
|
|
1281
|
+
``publisher`` (its pages, its own chooser, a host this item saw as its own),
|
|
1282
|
+
``other``; "" for no web address. The publisher's own chooser is no route:
|
|
1283
|
+
a page the browser passed on its way back to the journal site was taken for
|
|
1284
|
+
the school's (2026-11-12)."""
|
|
1285
|
+
parsed = urlparse(url)
|
|
1286
|
+
host = (parsed.hostname or "").lower()
|
|
1287
|
+
if parsed.scheme not in ("http", "https") or not host:
|
|
1288
|
+
return ""
|
|
1289
|
+
if self._known_school_host(host) or self._on_school_login_page(url):
|
|
1290
|
+
return "school"
|
|
1291
|
+
if self._names_identity_provider(url) or self._login_service_host(host) or federations.on_discovery_page(url):
|
|
1292
|
+
return "route"
|
|
1293
|
+
if (host in getattr(self, "_publisher_hosts", ()) or self._on_publisher_host(url)
|
|
1294
|
+
or self.adapter.is_institution_chooser(url)):
|
|
1295
|
+
return "publisher"
|
|
1296
|
+
return "other"
|
|
1297
|
+
|
|
1298
|
+
# Query parameters by which a service provider or discovery service asks for
|
|
1299
|
+
# an identity provider (SAML discovery's ``entityID``, sign-in hubs' ``idp``).
|
|
1300
|
+
_IDP_PARAMS = frozenset({"entityid", "idp"})
|
|
1301
|
+
|
|
1302
|
+
def _names_identity_provider(self, url: str) -> bool:
|
|
1303
|
+
"""An address asking for an identity provider: it names the school's
|
|
1304
|
+
entityID, or an identity provider in ``_IDP_PARAMS``. An identity
|
|
1305
|
+
provider's own pages name none."""
|
|
1306
|
+
if self._carries_entity_id(url, self._entity_id()):
|
|
1307
|
+
return True
|
|
1308
|
+
return any(key.lower() in self._IDP_PARAMS and value.startswith(("http", "urn:"))
|
|
1309
|
+
for key, values in parse_qs(urlparse(url).query).items() for value in values)
|
|
1310
|
+
|
|
1311
|
+
@staticmethod
|
|
1312
|
+
def _login_service_host(host: str) -> bool:
|
|
1313
|
+
"""A federation's own services or a login service shared by schools: never
|
|
1314
|
+
the school's side by its host."""
|
|
1315
|
+
return any(host == d or host.endswith("." + d)
|
|
1316
|
+
for d in (*federations.service_domains(), *access_rules.AUTH_HOSTS))
|
|
1317
|
+
|
|
1205
1318
|
def _institution_result_selectors(self) -> tuple[str, ...]:
|
|
1206
1319
|
"""Result locators built from the configured institution name.
|
|
1207
1320
|
|
|
@@ -577,7 +577,10 @@ class LoginMixin:
|
|
|
577
577
|
# Shibboleth's attribute-release and terms-of-use forms, whatever the language.
|
|
578
578
|
_IDP_CONFIRMATION_JS = """() => document.querySelector('[name="_eventId_TermsRejected"]') ? 'terms-of-use'
|
|
579
579
|
: document.querySelector('[name="_shib_idp_consentOptions"], [name="_shib_idp_consentIds"]') ? 'attribute-release' : ''"""
|
|
580
|
-
|
|
580
|
+
# Shibboleth's "Message Security Error": the identity provider could not trust the
|
|
581
|
+
# publisher's request (a school's IdP to Elsevier, 2026-11-12).
|
|
582
|
+
_IDP_ERROR_RE = re.compile(r"未知错误|系统错误|服务异常|认证失败|出错了|\b5\d{4}\b.{0,20}错误|an unexpected error|error code|system error"
|
|
583
|
+
r"|message security error", re.I)
|
|
581
584
|
|
|
582
585
|
# A publisher's own terms form on the way to the school: SIAM's SAML consent
|
|
583
586
|
# ("I have read and agree to the Terms and Conditions and Privacy Policy.",
|
|
@@ -730,7 +733,7 @@ class LoginMixin:
|
|
|
730
733
|
r"|sorry, you have been blocked|no institutions found|not registered for use with this service"
|
|
731
734
|
r"|application you have accessed is not registered|may not be enabled for this type of authentication"
|
|
732
735
|
r"|can't find your institution|access to this resource has been restricted by your organization|oa-ap-4032"
|
|
733
|
-
r"|不支持的请求|does not have access to this resource"
|
|
736
|
+
r"|不支持的请求|does not have access to this resource|message security error|reported an idp error"
|
|
734
737
|
r"|temporarily unavailable|verify you are human|are you a robot|checking your browser|正在进行安全验证", re.I)
|
|
735
738
|
|
|
736
739
|
def _login_block_reason(self, page: Any) -> str:
|
|
@@ -743,6 +746,8 @@ class LoginMixin:
|
|
|
743
746
|
def _block_evidence_for(self, code: str, page: Any) -> str:
|
|
744
747
|
if code == "login_page_closed":
|
|
745
748
|
return "the browser window was closed"
|
|
749
|
+
if code == "idp_login_error" and self._on_browser_error_page(page):
|
|
750
|
+
return f"the school's login server could not be reached: {self._school_unreachable}"
|
|
746
751
|
if code == "institution_pdf_entitlement_missing":
|
|
747
752
|
line = self._denial_line(page)
|
|
748
753
|
if line:
|
|
@@ -758,9 +763,18 @@ class LoginMixin:
|
|
|
758
763
|
return f'{url.hostname or ""}: "{quoted[:200]}"'
|
|
759
764
|
return f"{url.hostname or ''}{url.path[:80]} | {self._title(page)[:80]} ({type(self.adapter).__name__} rule)"
|
|
760
765
|
|
|
766
|
+
def _on_browser_error_page(self, page: Any) -> bool:
|
|
767
|
+
"""The browser's own error page after a navigation to the school's login
|
|
768
|
+
server failed (``_follow_login_route``): nobody can sign in there."""
|
|
769
|
+
return bool(getattr(self, "_school_unreachable", "")) and str(getattr(page, "url", "") or "").startswith(
|
|
770
|
+
"chrome-error://")
|
|
771
|
+
|
|
761
772
|
def _login_block_check(self, page: Any) -> str:
|
|
762
773
|
if page.is_closed() is True:
|
|
763
774
|
return "login_page_closed" # the user closed the window
|
|
775
|
+
if self._on_browser_error_page(page):
|
|
776
|
+
# Two schools' login servers did not answer from abroad (2026-11-12).
|
|
777
|
+
return "idp_login_error"
|
|
764
778
|
try:
|
|
765
779
|
parsed_idp = urlparse(str(getattr(page, "url", "") or ""))
|
|
766
780
|
if self._is_idp_host(parsed_idp.netloc):
|
|
@@ -803,6 +817,10 @@ class LoginMixin:
|
|
|
803
817
|
return override
|
|
804
818
|
if "unsupported request" in haystack and "not registered for use with this service" in haystack:
|
|
805
819
|
return "institution_not_registered"
|
|
820
|
+
# A publisher's Shibboleth saying the school's identity provider answered with
|
|
821
|
+
# an error ("SAML response reported an IdP error ... AuthnFailed", 2026-11-12).
|
|
822
|
+
if "saml response reported an idp error" in haystack:
|
|
823
|
+
return "idp_login_error"
|
|
806
824
|
# The same Shibboleth page in Chinese: "Web登陆服务 - 不支持的请求" on the
|
|
807
825
|
# school's IdP, the school has not enabled this publisher (JAMA, 2026-11-07).
|
|
808
826
|
if "不支持的请求" in haystack and self._is_idp_host(urlparse(current_url).netloc):
|
|
@@ -833,9 +851,16 @@ class LoginMixin:
|
|
|
833
851
|
# school has not enabled (2026-11-02). A page there that is no login form, no
|
|
834
852
|
# SAML hand-over and no "please wait" page, unchanged this long, ends the item.
|
|
835
853
|
SCHOOL_SITE_STAY_SEC = 12
|
|
854
|
+
# A username-first page (Okta's "identifier" field, no password box yet: a
|
|
855
|
+
# school's login was taken for its portal and ended, 2026-11-12) is a login;
|
|
856
|
+
# a portal's search box is not.
|
|
836
857
|
_SCHOOL_PAGE_STATE_JS = r"""() => ({
|
|
837
858
|
ready: document.readyState === 'complete',
|
|
838
859
|
login: !!document.querySelector('input[type="password"], input[autocomplete="one-time-code"]')
|
|
860
|
+
|| [...document.querySelectorAll('input')].some(el => el.getClientRects().length > 0 && !el.disabled
|
|
861
|
+
&& !el.readOnly && ['text', 'email'].includes(el.type) && (el.type === 'email'
|
|
862
|
+
|| /username|email/i.test(el.autocomplete || '')
|
|
863
|
+
|| /user|login|identifier|account|email|netid|学号|工号|账号|帐号/i.test(`${el.name} ${el.id}`)))
|
|
839
864
|
|| /扫码|二维码|QR ?code|验证码|verification code/i.test((document.body && document.body.innerText || '').slice(0, 4000)),
|
|
840
865
|
handover: !!document.querySelector('input[name="SAMLResponse"], input[name="SAMLRequest"], input[name="RelayState"]')
|
|
841
866
|
|| /^\s*(?:loading|please wait|redirecting|正在跳转|跳转中|请稍候|处理中)/i.test(document.title || '')})"""
|
|
@@ -307,14 +307,14 @@ def _try_builtin_institutional(
|
|
|
307
307
|
"error_type": "access_blocked", "reason": "journal_blocked_earlier", "action": "review_access",
|
|
308
308
|
"blocked_by": blocked_by}
|
|
309
309
|
|
|
310
|
-
# At most ``publisher_hourly_limit`` articles per publisher in
|
|
310
|
+
# At most ``publisher_hourly_limit`` articles per publisher in each hour
|
|
311
311
|
# (state L): psc's batch waits the given seconds and tries this one again.
|
|
312
312
|
from .. import rate_limit
|
|
313
313
|
rate_key = publisher_name or (urlparse(resolved_url).hostname or "")
|
|
314
314
|
limit = int(config.get("publisher_hourly_limit", rate_limit.DEFAULT_LIMIT) or 0)
|
|
315
315
|
wait = rate_limit.wait_seconds(rate_key, limit)
|
|
316
316
|
if wait:
|
|
317
|
-
log.info(" [Institutional] %s: %d articles
|
|
317
|
+
log.info(" [Institutional] %s: %d articles this hour, a new hour in %d s", rate_key, limit, wait)
|
|
318
318
|
return {"success": False, "identifier": doi, "doi": doi, "source": "institutional:rate_limit",
|
|
319
319
|
"error_type": "rate_limited", "reason": "publisher_hourly_limit", "action": "wait",
|
|
320
320
|
"retry_after_sec": wait, "publisher": rate_key, "limit": limit}
|
|
@@ -565,6 +565,9 @@ def _try_browser_batch_download(
|
|
|
565
565
|
# The browser call never returned and the driver was stopped:
|
|
566
566
|
# whatever the engine reported after that is a consequence.
|
|
567
567
|
result.reason = result.state = watchdog.failure_code()
|
|
568
|
+
if batch is not None:
|
|
569
|
+
# What a wait of the batch keeps the publisher's session alive with.
|
|
570
|
+
batch.article_url = (result.final_url or result.article_url) if result.ok else ""
|
|
568
571
|
if supplements_mode in ("with", "only"):
|
|
569
572
|
if result.state in ("browser_unresponsive", "browser_operation_timeout"):
|
|
570
573
|
result.supplements = [{"status": "skipped", "reason": result.state,
|
|
@@ -11,7 +11,8 @@ misread letters, reading order) does not matter, and the evidence is weighed:
|
|
|
11
11
|
|
|
12
12
|
- strong: the whole title, exactly (letters only, at least 50 of them),
|
|
13
13
|
standing as a title (an exact match inside a longer line counts one level lower);
|
|
14
|
-
- single: the target DOI; the title with a few misread letters; a shorter title
|
|
14
|
+
- single: the target DOI; the title with a few misread letters; a shorter title; a title
|
|
15
|
+
too short to count alone ("Reply") on its own line right next to the target DOI's line.
|
|
15
16
|
|
|
16
17
|
Strong evidence, or two single pieces, verify the PDF; one single piece verifies
|
|
17
18
|
it while the pages print no other DOI. Other DOIs and no evidence at all:
|
|
@@ -19,10 +20,16 @@ another article. A title's numbers must always be exact. An attachment
|
|
|
19
20
|
(supplementary material, disclosure form) and a notice about the article
|
|
20
21
|
(correction, retraction, briefing, letter to the editor), each known by its own
|
|
21
22
|
heading line, are not the article, unless the notice is itself the requested
|
|
22
|
-
item: its title says so, or the pages name it (its DOI in the header
|
|
23
|
-
whole title and its DOI) and print no other DOI. A
|
|
24
|
-
|
|
25
|
-
the
|
|
23
|
+
item: its title says so, or the pages name it (its DOI in the header or right above
|
|
24
|
+
its copyright line, or its whole title and its DOI) and print no other DOI. A DOI the pages label as the article
|
|
25
|
+
a notice is about ("DOI of original article:", "Correction to:") is no other DOI for
|
|
26
|
+
the notice itself (a letter that names the article it discusses); when that label
|
|
27
|
+
points at the requested DOI, the PDF is a notice about it. A scan without a text layer is
|
|
28
|
+
``"source"`` when the URL it came from names the DOI, or its suffix when that is long
|
|
29
|
+
enough to name one article (an Elsevier PII) (``assess`` with ``source``;
|
|
30
|
+
the frontend passes it, the engine does not); so is a page that prints no DOI at all and is
|
|
31
|
+
no notice or attachment, for an item named like a section rather than an article (a
|
|
32
|
+
one-page "Journal Club" note, "Issue Information").
|
|
26
33
|
|
|
27
34
|
``classify`` gives ``"match"`` (verified), ``"other"`` (another article),
|
|
28
35
|
``"unknown"`` (no decision: no text layer, or nothing printed) or ``"invalid"``
|
|
@@ -66,9 +73,21 @@ _NOTICE = re.compile(
|
|
|
66
73
|
r"|:[ \t]*(?:correction|erratum|corrigendum|retraction|expression of concern)[ \t]*$", re.I | re.M)
|
|
67
74
|
# A requested item whose title says it is a notice ("…: Erratum", "Reply to …").
|
|
68
75
|
_NOTICE_TITLE = re.compile(r"\b(?:erratum|corrigendum|correction|retraction|retracted|withdrawn|expression of concern|reply to|letter)\b", re.I)
|
|
76
|
+
# A label for the article a notice is about, followed by its DOI ("DOI of original article:
|
|
77
|
+
# https://doi.org/…" under an Elsevier letter or reply, 2026-11-12; "Correction to: Nature
|
|
78
|
+
# https://doi.org/…"; "The original article can be found online at …").
|
|
79
|
+
_ABOUT_LABEL = re.compile(
|
|
80
|
+
r"\b(?:doi\s+of\s+(?:the\s+)?original\s+article|(?:the\s+)?original\s+article(?:\s+can\s+be\s+found\s+online\s+at|\s+is\s+available\s+(?:online\s+)?at)?"
|
|
81
|
+
r"|(?:correction|erratum|corrigendum|addendum)\s+to|retraction\s+(?:note\s+|notice\s+)?(?:to|of)|comment(?:ary)?\s+on"
|
|
82
|
+
r"|(?:in\s+)?(?:reply|response)\s+to|see\s+the\s+article|refers\s+to|linked\s+article)\s*:?", re.I)
|
|
83
|
+
_ABOUT_REACH = 200 # how far after its label the DOI of the article a notice is about may be
|
|
69
84
|
# A DOI may break right after its prefix ("https://doi.org/10.1016/" then "S0140-…", The Lancet).
|
|
70
85
|
_DOI_IN_TEXT = re.compile(r"10\.\d{4,9}/(?:[ \t]*\n[ \t]*)?[^\s\"<>]+")
|
|
71
86
|
_LETTER = re.compile(r"[a-zЀ-ӿ一-鿿]")
|
|
87
|
+
# The copyright line right after a DOI ("https://doi.org/…" then "1063-4584/© 2025 …"):
|
|
88
|
+
# the item's own footer. Text extraction can put the footer after the reference list
|
|
89
|
+
# (Elsevier letters and replies, 2026-11-13).
|
|
90
|
+
_COPYRIGHT_AFTER = re.compile(r"\s*(?:\d{4}-\d{3}[\dx]\s*/\s*)?©", re.I)
|
|
72
91
|
_ENTITIES = {"amp": "&", "lt": "<", "gt": ">", "quot": '"', "apos": "'"}
|
|
73
92
|
|
|
74
93
|
|
|
@@ -162,6 +181,19 @@ def _title_evidence(text: str, chars: str, at: list[int], title: str) -> str | N
|
|
|
162
181
|
return "single" if end > 0 and _numbers_match(window(end, len(key) + errors), plain) else None
|
|
163
182
|
|
|
164
183
|
|
|
184
|
+
def _short_title_beside_doi(text: str, target: str, title: str) -> bool:
|
|
185
|
+
"""A title too short to count alone ("Reply") on its own line within two lines of the
|
|
186
|
+
target DOI's line (Wiley letters: "DOI 10.1002/…" then "Reply", 2026-11-12)."""
|
|
187
|
+
key = _letters(normalize_doi_text(_plain_title(title)))[0]
|
|
188
|
+
if not key or _weight(key) >= SHORT_TITLE:
|
|
189
|
+
return False
|
|
190
|
+
lines = text.split("\n")
|
|
191
|
+
for i, line in enumerate(lines):
|
|
192
|
+
if _doi_named(line, target) and any(_letters(near)[0] == key for near in lines[max(0, i - 2):i] + lines[i + 1:i + 3]):
|
|
193
|
+
return True
|
|
194
|
+
return False
|
|
195
|
+
|
|
196
|
+
|
|
165
197
|
def _target_doi(identifier: str) -> str:
|
|
166
198
|
return re.sub(r"^(?:https?://(?:dx\.)?doi\.org/|doi:\s*)", "", (identifier or "").strip().lower())
|
|
167
199
|
|
|
@@ -184,12 +216,37 @@ def _doi_named(pages: str, target: str) -> bool:
|
|
|
184
216
|
return re.search(rf"(?<![0-9.]){head}{pattern(suffix)}(?![0-9a-z_/-]|\.[0-9a-z])", pages) is not None
|
|
185
217
|
|
|
186
218
|
|
|
219
|
+
def _doi_above_copyright(text: str, target: str) -> bool:
|
|
220
|
+
"""The target DOI with the copyright line right after it: its own footer, wherever
|
|
221
|
+
the text extraction put it."""
|
|
222
|
+
return any(_bare(_clean_doi(match)) == _bare(target) and _COPYRIGHT_AFTER.match(text, match.end())
|
|
223
|
+
for match in _DOI_IN_TEXT.finditer(text))
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _clean_doi(match: re.Match[str]) -> str:
|
|
227
|
+
return re.sub(r"[.,;:)\]]+$", "", re.sub(r"\s+", "", match.group(0)))
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def _same_article(doi: str, target: str) -> bool:
|
|
231
|
+
"""``doi`` is the target, or a piece, an extension, a misprint or an older prefix of it."""
|
|
232
|
+
own, own_suffix = _bare(target), _bare(_suffix(target))
|
|
233
|
+
return (own.startswith(_bare(doi)) or _bare(doi).startswith(own)
|
|
234
|
+
or (len(own_suffix) >= SHARED_SUFFIX and _bare(_suffix(doi)) == own_suffix))
|
|
235
|
+
|
|
236
|
+
|
|
187
237
|
def _other_dois(pages: str, target: str) -> list[str]:
|
|
188
238
|
"""DOIs printed that are not the target, nor a piece, an extension, a misprint or an older prefix of it."""
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
239
|
+
return [doi for doi in map(_clean_doi, _DOI_IN_TEXT.finditer(pages)) if not _same_article(doi, target)]
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def _about_dois(pages: str) -> list[str]:
|
|
243
|
+
"""DOIs the pages label as the article a notice is about: the first DOI after each label."""
|
|
244
|
+
found = []
|
|
245
|
+
for label in _ABOUT_LABEL.finditer(pages):
|
|
246
|
+
doi = _DOI_IN_TEXT.search(pages, label.end(), label.end() + _ABOUT_REACH)
|
|
247
|
+
if doi:
|
|
248
|
+
found.append(_clean_doi(doi))
|
|
249
|
+
return found
|
|
193
250
|
|
|
194
251
|
|
|
195
252
|
def _title_before(text: str, title: str) -> bool:
|
|
@@ -223,15 +280,24 @@ def evidence(first_pages: str, identifier: str, title: str = "") -> dict | None:
|
|
|
223
280
|
front = _REFERENCES_HEADING.split(text, maxsplit=1)[0]
|
|
224
281
|
target = _target_doi(identifier)
|
|
225
282
|
chars, at = _letters(front)
|
|
226
|
-
|
|
283
|
+
own_footer = _doi_above_copyright(text, target)
|
|
284
|
+
doi = _doi_named(front, target) or own_footer
|
|
227
285
|
found = _title_evidence(front, chars, at, title) if (title or "").strip() else None
|
|
286
|
+
if found is None and doi and _short_title_beside_doi(front, target, title or ""):
|
|
287
|
+
found = "single"
|
|
228
288
|
others = _other_dois(front, target)
|
|
289
|
+
about = _about_dois(front)
|
|
290
|
+
if not any(_same_article(doi, target) for doi in about):
|
|
291
|
+
# The article a notice discusses is not another article on these pages.
|
|
292
|
+
others = [doi for doi in others if doi not in about]
|
|
229
293
|
# A notice is itself the requested item when the pages name it (its DOI in the
|
|
230
294
|
# header, Neurology; its whole title and its DOI, a letter under a "Letter to the
|
|
231
295
|
# editor" heading) and print no other DOI. A notice about an article prints its
|
|
232
296
|
# own DOI as well ("Author Correction" then "Correction to: Nature
|
|
233
297
|
# https://doi.org/<the article>"; a Frontiers corrigendum, 2026-11-02).
|
|
234
|
-
|
|
298
|
+
# Its DOI above its copyright line names it as well as its header does (a letter with
|
|
299
|
+
# a short title, 2026-11-13).
|
|
300
|
+
named = (_doi_named(front[:HEAD_CHARS], target) or own_footer or (doi and found == "strong")) and not others
|
|
235
301
|
return {
|
|
236
302
|
"not_article": _not_the_article(text[:HEAD_CHARS], title or "", named),
|
|
237
303
|
"doi": doi,
|
|
@@ -254,8 +320,14 @@ def _source_names_doi(source: str, target: str) -> bool:
|
|
|
254
320
|
"""The URL a PDF came from names the DOI, not as part of a longer DOI (a ".pdf" may follow)."""
|
|
255
321
|
if not re.match(r"10\.\d{4,9}/\S", target):
|
|
256
322
|
return False
|
|
257
|
-
|
|
258
|
-
|
|
323
|
+
url = _decoded(source).lower()
|
|
324
|
+
if re.search(rf"(?<![0-9.]){re.escape(target)}(?![0-9a-z_/-]|\.(?!pdf(?![0-9a-z]))[0-9a-z])", url):
|
|
325
|
+
return True
|
|
326
|
+
# A suffix long enough to name one article on its own, as a path segment: an Elsevier
|
|
327
|
+
# PII ("/article/S1063-4584(25)01284-1/pdf" for 10.1016/S1063-4584(25)01284-1, 2026-11-13).
|
|
328
|
+
suffix = _suffix(target)
|
|
329
|
+
return len(_bare(suffix)) >= SHARED_SUFFIX and re.search(
|
|
330
|
+
rf"/{re.escape(suffix)}(?![0-9a-z_-]|\.(?!pdf(?![0-9a-z]))[0-9a-z])", url) is not None
|
|
259
331
|
|
|
260
332
|
|
|
261
333
|
def assess(first_pages: str, identifier: str, title: str = "", source: str = "") -> str:
|
|
@@ -271,7 +343,14 @@ def assess(first_pages: str, identifier: str, title: str = "", source: str = "")
|
|
|
271
343
|
return "mismatch"
|
|
272
344
|
scan = (sum(char.isalpha() for char in first_pages or "") < SCAN_MAX_LETTERS
|
|
273
345
|
and not (found and (found["not_article"] or found["other_dois"])))
|
|
274
|
-
|
|
346
|
+
# Pages that print no DOI at all and are no notice or attachment, for an item named
|
|
347
|
+
# like a section rather than an article (under CLOSE_TITLE letters: Wiley's "Journal
|
|
348
|
+
# Club" and "Issue Information", 2026-11-12): the URL is the evidence, as for a scan.
|
|
349
|
+
# An article's title not printed is a reason for doubt (an issue's front matter at
|
|
350
|
+
# the article's address).
|
|
351
|
+
short = _weight(_letters(normalize_doi_text(_plain_title(title)))[0]) < CLOSE_TITLE
|
|
352
|
+
no_doi = bool(found) and short and not (found["not_article"] or found["doi"] or found["other_dois"] or found["title"])
|
|
353
|
+
return "source" if source and (scan or no_doi) and _source_names_doi(source, _target_doi(identifier)) else "unverified"
|
|
275
354
|
|
|
276
355
|
|
|
277
356
|
def first_pages_text(body: bytes) -> str | None:
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"code": "incommon",
|
|
3
|
+
"name": "InCommon",
|
|
4
|
+
"country": "US",
|
|
5
|
+
"registration_authorities": ["https://incommon.org"],
|
|
6
|
+
"chooser_labels": ["InCommon Federation"],
|
|
7
|
+
"chooser_pattern": "\\bInCommon\\b",
|
|
8
|
+
"discovery_hosts": [],
|
|
9
|
+
"service_domains": ["incommon.org", "incommonfederation.org"],
|
|
10
|
+
"metadata_url": "https://mdq.incommon.org/entities/exports/edugain"
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"code": "infed",
|
|
3
|
+
"name": "INFED",
|
|
4
|
+
"country": "IN",
|
|
5
|
+
"registration_authorities": ["http://inflibnet.ac.in"],
|
|
6
|
+
"chooser_labels": ["INFLIBNET Access Management Federation (INFED)"],
|
|
7
|
+
"chooser_pattern": "\\bINFED\\b|\\bINFLIBNET\\s+Access\\s+Management\\s+Federation\\b",
|
|
8
|
+
"discovery_hosts": [],
|
|
9
|
+
"service_domains": ["inflibnet.ac.in"],
|
|
10
|
+
"metadata_url": "https://parichay.inflibnet.ac.in/metadata/edugain.xml"
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"code": "liaf",
|
|
3
|
+
"name": "LIAF",
|
|
4
|
+
"country": "LK",
|
|
5
|
+
"registration_authorities": ["https://liaf.ac.lk"],
|
|
6
|
+
"chooser_labels": ["LEARN Identity Access Federation (LIAF)"],
|
|
7
|
+
"chooser_pattern": "\\bLIAF\\b|\\bLEARN\\s+Identity\\s+(?:and\\s+)?Access\\s+Federation\\b",
|
|
8
|
+
"discovery_hosts": [],
|
|
9
|
+
"service_domains": ["liaf.ac.lk"],
|
|
10
|
+
"metadata_url": "https://fr.ac.lk/signedmetadata/LIAF_to_edugain.xml"
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"code": "omren",
|
|
3
|
+
"name": "OMREN",
|
|
4
|
+
"country": "OM",
|
|
5
|
+
"registration_authorities": ["http://www.omren.om"],
|
|
6
|
+
"chooser_labels": ["OMREN Identity Federation"],
|
|
7
|
+
"chooser_pattern": "\\bOMREN\\b",
|
|
8
|
+
"discovery_hosts": [],
|
|
9
|
+
"service_domains": ["fed.omren.om", "federation.omren.om"],
|
|
10
|
+
"metadata_url": "https://fed.omren.om/OMREN_export.xml"
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"code": "pkifed",
|
|
3
|
+
"name": "PKIFED",
|
|
4
|
+
"country": "PK",
|
|
5
|
+
"registration_authorities": ["https://pkifed.pk"],
|
|
6
|
+
"chooser_labels": ["Pakistan Identity Federation (PKIFED)"],
|
|
7
|
+
"chooser_pattern": "\\bPKIFED\\b|\\bPakistan\\s+Identity\\s+Federation\\b",
|
|
8
|
+
"discovery_hosts": [],
|
|
9
|
+
"service_domains": ["pkifed.pk"],
|
|
10
|
+
"metadata_url": "https://rr.pern.edu.pk/rr3/signedmetadata/federation/PKIFED_eduGAIN/metadata.xml"
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"code": "tigerfed",
|
|
3
|
+
"name": "TIGERfed",
|
|
4
|
+
"country": "BD",
|
|
5
|
+
"registration_authorities": ["https://tigerfed.net.bd"],
|
|
6
|
+
"chooser_labels": ["TIGERfed"],
|
|
7
|
+
"chooser_pattern": "\\bTIGERfed\\b",
|
|
8
|
+
"discovery_hosts": [],
|
|
9
|
+
"service_domains": ["tigerfed.net.bd"],
|
|
10
|
+
"metadata_url": "https://fedmanager.tigerfed.net.bd/edugain-export-metadata.xml"
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"code": "yetkim",
|
|
3
|
+
"name": "YETKİM",
|
|
4
|
+
"country": "TR",
|
|
5
|
+
"registration_authorities": ["https://yetkim.org.tr/"],
|
|
6
|
+
"chooser_labels": ["YETKİM Identity Federation"],
|
|
7
|
+
"chooser_pattern": "\\bYETK[İI]M\\b",
|
|
8
|
+
"discovery_hosts": [],
|
|
9
|
+
"service_domains": ["yetkim.org.tr"],
|
|
10
|
+
"metadata_url": "http://md.yetkim.org.tr/yetkim-upstream.xml"
|
|
11
|
+
}
|