papersearch 0.4.11 → 0.4.12
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 +3 -3
- package/README.md +3 -3
- package/carsi/paper_search_carsi/adapters/ams/__init__.py +12 -0
- package/carsi/paper_search_carsi/adapters/elsevier/__init__.py +5 -2
- package/carsi/paper_search_carsi/adapters/elsevier/sciencedirect.py +18 -1
- package/carsi/paper_search_carsi/adapters/iop/__init__.py +11 -2
- package/carsi/paper_search_carsi/adapters/platforms/atypon/__init__.py +24 -14
- package/carsi/paper_search_carsi/assets/capsule.html +11 -1
- package/carsi/paper_search_carsi/browser/preview.py +16 -3
- package/carsi/paper_search_carsi/browser/watchdog.py +15 -0
- package/carsi/paper_search_carsi/capsule_placement.py +51 -31
- package/carsi/paper_search_carsi/download_diagnostics.py +1 -0
- package/carsi/paper_search_carsi/engine/access_rules.py +11 -0
- package/carsi/paper_search_carsi/engine/batch.py +13 -1
- package/carsi/paper_search_carsi/engine/batch_access.py +3 -0
- package/carsi/paper_search_carsi/engine/batch_capture.py +20 -0
- package/carsi/paper_search_carsi/engine/batch_common.py +4 -0
- package/carsi/paper_search_carsi/engine/batch_institution.py +27 -18
- package/carsi/paper_search_carsi/engine/bridge.py +5 -2
- package/carsi/paper_search_carsi/engine/supplements.py +34 -6
- package/carsi/paper_search_carsi/progress_capsule.py +87 -9
- package/carsi/paper_search_carsi/progress_macos.py +35 -10
- package/carsi/paper_search_carsi/progress_reporter.py +12 -5
- package/carsi/paper_search_carsi/progress_view.py +7 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.js +2 -0
- package/dist/capabilities/pdf-discovery/carsi/CarsiAttempt.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.js +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
- package/dist/infrastructure/runlog/failureClass.js +2 -0
- package/dist/infrastructure/runlog/failureClass.js.map +1 -1
- package/dist/management/updates/index.d.ts +6 -1
- package/dist/management/updates/index.d.ts.map +1 -1
- package/dist/management/updates/index.js +18 -11
- package/dist/management/updates/index.js.map +1 -1
- package/package.json +1 -3
- package/skills/paper-search/SKILL.md +4 -10
- package/skills/paper-search/references/browser-download.md +1 -1
- package/skills/paper-search/references/publisher-support.md +4 -4
- package/NOTICE +0 -23
- package/carsi/NOTICE +0 -5
package/README.en.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<h1 align="center">PaperSearch</h1>
|
|
6
6
|
|
|
7
7
|
<p align="center"><b>A lightweight, fully automated all-in-one literature tool for AI</b><br>
|
|
8
|
-
|
|
8
|
+
One sentence and your AI searches, verifies and downloads full texts and supplementary files, all in the background.</p>
|
|
9
9
|
|
|
10
10
|
<p align="center">
|
|
11
11
|
<a href="https://www.npmjs.com/package/papersearch"><img src="https://img.shields.io/npm/v/papersearch?style=flat-square" alt="npm"></a>
|
|
@@ -204,8 +204,8 @@ The full plan is in the [roadmap](docs/ROADMAP.zh.md) (Chinese); how it works in
|
|
|
204
204
|
|
|
205
205
|
- Thanks to the LinuxDo community, where the command-plus-Skill approach and workflow improvements came from discussion and open sharing.
|
|
206
206
|
- [openags/paper-search-mcp](https://github.com/openags/paper-search-mcp): the project draws on its ideas, reworked into a standalone command.
|
|
207
|
-
- [Dianel555/paper-search-mcp-nodejs](https://github.com/Dianel555/paper-search-mcp-nodejs) (MIT): the command started as an adaptation of its Node.js implementation
|
|
208
|
-
- [Rimagination/scansci-pdf](https://github.com/Rimagination/scansci-pdf) (MIT): the institutional download backend (`carsi/`) draws on its architecture (CARSI and other federation sign-in, publisher site capture, session reuse, PDF capture)
|
|
207
|
+
- [Dianel555/paper-search-mcp-nodejs](https://github.com/Dianel555/paper-search-mcp-nodejs) (MIT): the command started as an adaptation of its Node.js implementation.
|
|
208
|
+
- [Rimagination/scansci-pdf](https://github.com/Rimagination/scansci-pdf) (MIT): the institutional download backend (`carsi/`) draws on its architecture (CARSI and other federation sign-in, publisher site capture, session reuse, PDF capture).
|
|
209
209
|
|
|
210
210
|
## License
|
|
211
211
|
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<h1 align="center">PaperSearch</h1>
|
|
6
6
|
|
|
7
7
|
<p align="center"><b>轻量、全自动的 AI 文献全能工具</b><br>
|
|
8
|
-
|
|
8
|
+
一句话让AI完成文献检索、核对、下载全文和补充材料,后台自动完成。</p>
|
|
9
9
|
|
|
10
10
|
<p align="center">
|
|
11
11
|
<a href="https://www.npmjs.com/package/papersearch"><img src="https://img.shields.io/npm/v/papersearch?style=flat-square" alt="npm"></a>
|
|
@@ -204,8 +204,8 @@ paper-search config list --pretty # 查看已配置的项,key 脱敏显示
|
|
|
204
204
|
|
|
205
205
|
- 感谢 LinuxDo 社区:命令 + Skill 的路线和工作流改进来自社区交流与开源分享。
|
|
206
206
|
- [openags/paper-search-mcp](https://github.com/openags/paper-search-mcp):本项目参考了它的思路,并改成独立的命令行工具。
|
|
207
|
-
- [Dianel555/paper-search-mcp-nodejs](https://github.com/Dianel555/paper-search-mcp-nodejs)(MIT):命令行版最初由它的 Node.js
|
|
208
|
-
- [Rimagination/scansci-pdf](https://github.com/Rimagination/scansci-pdf)(MIT):机构下载后端(`carsi/`)借鉴了它的架构(CARSI 等联盟登录、出版社网站抓取、会话复用、PDF
|
|
207
|
+
- [Dianel555/paper-search-mcp-nodejs](https://github.com/Dianel555/paper-search-mcp-nodejs)(MIT):命令行版最初由它的 Node.js 实现改编而来。
|
|
208
|
+
- [Rimagination/scansci-pdf](https://github.com/Rimagination/scansci-pdf)(MIT):机构下载后端(`carsi/`)借鉴了它的架构(CARSI 等联盟登录、出版社网站抓取、会话复用、PDF 捕获)。
|
|
209
209
|
|
|
210
210
|
## License
|
|
211
211
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"""American Meteorological Society: journals on journals.ametsoc.org.
|
|
2
2
|
|
|
3
3
|
The PDF of an article page ``/view/<path>.xml`` is ``/downloadpdf/view/<path>.pdf``.
|
|
4
|
+
The site offers no institutional sign-in: its "Sign in" is the AMS member login
|
|
5
|
+
(www.ametsoc.org/ams/log-in, user name and password only), and institutions reach
|
|
6
|
+
the journals by their network address (checked 2026-11-08).
|
|
4
7
|
"""
|
|
5
8
|
from __future__ import annotations
|
|
6
9
|
|
|
@@ -42,6 +45,15 @@ def supplement_links_from_rows(rows: list[dict], doi: str) -> list[SupplementLin
|
|
|
42
45
|
class AMSAdapter(PublisherAdapter):
|
|
43
46
|
publisher = "ams"
|
|
44
47
|
|
|
48
|
+
def prepare_institution_choice(self, page: Any, result: Any) -> bool | None:
|
|
49
|
+
"""No school to choose here: the article ends at once as having no login route
|
|
50
|
+
for the school, instead of waiting on the article page for a choice."""
|
|
51
|
+
if result is not None and not getattr(result, "_institution_not_listed", False):
|
|
52
|
+
self.d._event(result, "institution_login_unavailable",
|
|
53
|
+
"AMS: member sign-in only; institutions by network address")
|
|
54
|
+
result._institution_not_listed = True
|
|
55
|
+
return False
|
|
56
|
+
|
|
45
57
|
def supplement_links(self, page: Any, doi: str) -> list[SupplementLink]:
|
|
46
58
|
return supplement_links_from_rows(page.evaluate(_SUPPLEMENT_ROWS_JS), doi)
|
|
47
59
|
|
|
@@ -254,8 +254,11 @@ class ElsevierAdapter(PublisherAdapter):
|
|
|
254
254
|
and parsed.path.startswith("/as/"))
|
|
255
255
|
|
|
256
256
|
def unsupported_platform(self, page: Any) -> str | None:
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
url = str(getattr(page, "url", "") or "")
|
|
258
|
+
host = (urlparse(url).hostname or "").lower()
|
|
259
|
+
if _CLINICALKEY.fullmatch(host) or (sciencedirect.is_page(url) and self.sciencedirect.clinicalkey_only(page)):
|
|
260
|
+
return "ClinicalKey"
|
|
261
|
+
return None
|
|
259
262
|
|
|
260
263
|
def supplements_page_urls(self, doi: str) -> list[str]:
|
|
261
264
|
"""ScienceDirect first; journals on their own Elsevier site (Cell Press,
|
|
@@ -24,7 +24,7 @@ _ITEM = re.compile(r"/science/(?:article|chapter/[^/]+)/(abs/)?pii/", re.I)
|
|
|
24
24
|
# kept in the observed tab. A control linking to another PII (a recommended or
|
|
25
25
|
# related article) never qualifies, wherever the layout puts it.
|
|
26
26
|
_VIEW_PDF_JS = """
|
|
27
|
-
() => {
|
|
27
|
+
(findOnly) => {
|
|
28
28
|
const piiOf = (value) => {
|
|
29
29
|
const match = /\\/pii\\/([0-9A-Za-z]+)/.exec(value || '');
|
|
30
30
|
return match ? match[1].toUpperCase() : '';
|
|
@@ -72,6 +72,7 @@ _VIEW_PDF_JS = """
|
|
|
72
72
|
href: target.href.slice(0, 500),
|
|
73
73
|
score: Math.round(target.score)
|
|
74
74
|
};
|
|
75
|
+
if (findOnly) return detail;
|
|
75
76
|
// Keep the site's normal navigation in the page whose PDF
|
|
76
77
|
// responses are being captured. Otherwise target=_blank
|
|
77
78
|
// opens a viewer in an unobserved tab and loses the file.
|
|
@@ -121,6 +122,22 @@ class ScienceDirectSite:
|
|
|
121
122
|
text = " ".join(self.d._body_text(page, 5000).lower().split())
|
|
122
123
|
return "cpe00001" in text and "there was a problem providing the content you requested" in text
|
|
123
124
|
|
|
125
|
+
def clinicalkey_only(self, page: Any) -> bool:
|
|
126
|
+
"""Signed in, the article page offers its full text through ClinicalKey and
|
|
127
|
+
no PDF of its own (The Lancet 1975, 2026-11-08: "You have access to this
|
|
128
|
+
article through ClinicalKey", only "View full text")."""
|
|
129
|
+
if not _ITEM.match(urlparse(str(getattr(page, "url", "") or "")).path):
|
|
130
|
+
return False
|
|
131
|
+
text = " ".join(self.d._body_text(page, 3000).lower().split())
|
|
132
|
+
if "access to this article through clinicalkey" not in text:
|
|
133
|
+
return False
|
|
134
|
+
try:
|
|
135
|
+
return not page.evaluate(_VIEW_PDF_JS, True)
|
|
136
|
+
except Exception as exc:
|
|
137
|
+
if not _is_browser_error(exc):
|
|
138
|
+
raise
|
|
139
|
+
return False
|
|
140
|
+
|
|
124
141
|
def open_pdf_entry(self, page: Any, result: Any) -> bool | None:
|
|
125
142
|
try:
|
|
126
143
|
detail = page.evaluate(_VIEW_PDF_JS)
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Without access the article page offers "Access this article" or "Access
|
|
4
4
|
through your institution". The institution login starts at myIOPscience's
|
|
5
|
-
sign-in (``myiopscience.iop.org/signin``) with the article as its target
|
|
5
|
+
sign-in (``myiopscience.iop.org/signin``) with the article as its target: with
|
|
6
|
+
``origin=deeplink`` it leads to OpenAthens' institution finder (without it, to
|
|
7
|
+
the personal account sign-in only).
|
|
6
8
|
"""
|
|
7
9
|
from __future__ import annotations
|
|
8
10
|
|
|
@@ -70,7 +72,14 @@ class IOPAdapter(PublisherAdapter):
|
|
|
70
72
|
if "iopscience.iop.org/article/" not in current_url.lower():
|
|
71
73
|
return None
|
|
72
74
|
text = self.d._body_text(page, 5_000).lower()
|
|
73
|
-
|
|
75
|
+
offered = "access this article" in text or "access through your institution" in text
|
|
76
|
+
# An accepted manuscript's page has no access box, its PDF still needs the
|
|
77
|
+
# institution's login (Physics in Medicine & Biology, 2026-11-08). Once per
|
|
78
|
+
# article: back from the login without access, the page is left as it is.
|
|
79
|
+
manuscript = "accepted manuscript" in text and result is not None and not any(
|
|
80
|
+
e.get("state") == "sso_entry_clicked" and "myiopscience.iop.org/signin" in str(e.get("detail", ""))
|
|
81
|
+
for e in getattr(result, "events", None) or [])
|
|
82
|
+
if not offered and not manuscript:
|
|
74
83
|
return None
|
|
75
84
|
signin_url = "https://myiopscience.iop.org/signin?" + urlencode(
|
|
76
85
|
{"origin": "deeplink", "target": current_url}
|
|
@@ -59,20 +59,7 @@ class AtyponAdapter(PublisherAdapter):
|
|
|
59
59
|
"""
|
|
60
60
|
landing_path = f"/doi/suppl/{doi.lower()}"
|
|
61
61
|
for attempt in range(2):
|
|
62
|
-
links
|
|
63
|
-
landing = ""
|
|
64
|
-
rows = page.evaluate(_SUPPLEMENT_ROWS_JS)
|
|
65
|
-
for row in rows if isinstance(rows, list) and doi else []:
|
|
66
|
-
target = urlparse(str(row.get("href") or "") if isinstance(row, dict) else "")
|
|
67
|
-
url = target._replace(fragment="").geturl()
|
|
68
|
-
if not self._on_site(url):
|
|
69
|
-
continue
|
|
70
|
-
path = unquote(target.path).lower()
|
|
71
|
-
if path.startswith(landing_path + "/suppl_file/"):
|
|
72
|
-
if url not in {link.url for link in links}:
|
|
73
|
-
links.append(SupplementLink(url, str(row.get("label") or "")))
|
|
74
|
-
elif path.rstrip("/") == landing_path:
|
|
75
|
-
landing = landing or url
|
|
62
|
+
links, landing = self._listed_supplements(page, doi)
|
|
76
63
|
if links or not landing or attempt:
|
|
77
64
|
return links
|
|
78
65
|
if unquote(urlparse(str(page.url)).path).lower().rstrip("/") == landing_path:
|
|
@@ -80,6 +67,29 @@ class AtyponAdapter(PublisherAdapter):
|
|
|
80
67
|
open_page(page, landing, timeout_ms=30_000)
|
|
81
68
|
return []
|
|
82
69
|
|
|
70
|
+
def listed_supplement_links(self, page: Any, doi: str) -> list[SupplementLink]:
|
|
71
|
+
"""The files this page lists itself, read without leaving it."""
|
|
72
|
+
return self._listed_supplements(page, doi)[0]
|
|
73
|
+
|
|
74
|
+
def _listed_supplements(self, page: Any, doi: str) -> tuple[list[SupplementLink], str]:
|
|
75
|
+
"""``(files, landing page)`` linked from this page for this article."""
|
|
76
|
+
landing_path = f"/doi/suppl/{doi.lower()}"
|
|
77
|
+
links: list[SupplementLink] = []
|
|
78
|
+
landing = ""
|
|
79
|
+
rows = page.evaluate(_SUPPLEMENT_ROWS_JS)
|
|
80
|
+
for row in rows if isinstance(rows, list) and doi else []:
|
|
81
|
+
target = urlparse(str(row.get("href") or "") if isinstance(row, dict) else "")
|
|
82
|
+
url = target._replace(fragment="").geturl()
|
|
83
|
+
if not self._on_site(url):
|
|
84
|
+
continue
|
|
85
|
+
path = unquote(target.path).lower()
|
|
86
|
+
if path.startswith(landing_path + "/suppl_file/"):
|
|
87
|
+
if url not in {link.url for link in links}:
|
|
88
|
+
links.append(SupplementLink(url, str(row.get("label") or "")))
|
|
89
|
+
elif path.rstrip("/") == landing_path:
|
|
90
|
+
landing = landing or url
|
|
91
|
+
return links, landing
|
|
92
|
+
|
|
83
93
|
def institution_chooser_open(self, page: Any) -> bool:
|
|
84
94
|
return self._chooser(str(getattr(page, "url", "") or "")) and page.locator("select#shib-search--fed").is_visible()
|
|
85
95
|
|
|
@@ -163,6 +163,10 @@ svg.i { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-widt
|
|
|
163
163
|
.paper-list li { font-size: 12px; padding: 3px 0; }
|
|
164
164
|
.paper-list .t, .paper-list .w { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
165
165
|
.paper-list .w, .paper-list .more { color: var(--faint); }
|
|
166
|
+
.paper-list .open-article { display: block; width: 100%; padding: 0; border: none; background: none; text-align: left;
|
|
167
|
+
font: inherit; color: inherit; cursor: pointer; }
|
|
168
|
+
.paper-list .open-article:hover .t { color: var(--accent); text-decoration: underline; }
|
|
169
|
+
.paper-list .open-article:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 3px; }
|
|
166
170
|
.tag { display: inline-block; font-size: 11px; line-height: 16px; padding: 0 6px; border-radius: 5px; flex: none; }
|
|
167
171
|
.tag.no_access, .tag.other { background: var(--hover); color: var(--fg); }
|
|
168
172
|
.tag.user_or_external { background: var(--warn-bg); color: var(--warn); }
|
|
@@ -349,7 +353,12 @@ function reasonRow(g, i, brief) {
|
|
|
349
353
|
+ '<span class="n">' + g.count + " 篇</span>" + icon(opened ? "down" : "right") + "</button>";
|
|
350
354
|
if (!opened) return html + (g.where && !brief ? '<div class="m">' + esc(g.where) + "</div>" : "") + "</div>";
|
|
351
355
|
return html + '<ul class="paper-list' + (g.papers.length > 5 ? " scroll" : "") + '">'
|
|
352
|
-
+ g.papers.map((p) =>
|
|
356
|
+
+ g.papers.map((p) => {
|
|
357
|
+
const lines = '<div class="t">' + esc(p.title) + "</div>" + (p.where ? '<div class="w">' + esc(p.where) + "</div>" : "");
|
|
358
|
+
// The article's page in the user's browser, to fetch it by hand (user, 2026-11-08).
|
|
359
|
+
return "<li>" + (p.doi ? '<button type="button" class="open-article" data-act="open_article" data-doi="' + esc(p.doi)
|
|
360
|
+
+ '" title="在浏览器打开这篇文章">' + lines + "</button>" : lines) + "</li>";
|
|
361
|
+
}).join("")
|
|
353
362
|
+ (g.more ? '<li class="more">另有 ' + g.more + " 篇未列出</li>" : "") + "</ul></div>";
|
|
354
363
|
}
|
|
355
364
|
|
|
@@ -536,6 +545,7 @@ async function act(action, target) {
|
|
|
536
545
|
case "minimize": open = false; panel = ""; render(true); return api().minimize(); // back as a capsule when restored
|
|
537
546
|
case "close": closing = true; ++fitGeneration; clearInterval(pollTimer); clearTimeout(hoverTimer); clearTimeout(leaveTimer); return api().request_close(); // no call left waiting on a closed page
|
|
538
547
|
case "folder": return api().open_folder();
|
|
548
|
+
case "open_article": return say(await api().open_article(target.dataset.doi));
|
|
539
549
|
case "group": return toggleGroup(Number(target.dataset.group));
|
|
540
550
|
case "show_browser": {
|
|
541
551
|
try { await inputActivation; }
|
|
@@ -23,7 +23,7 @@ from urllib.parse import urlsplit
|
|
|
23
23
|
from uuid import UUID, uuid4
|
|
24
24
|
from weakref import WeakKeyDictionary
|
|
25
25
|
|
|
26
|
-
from .watchdog import BrowserUnresponsive, operation_remaining
|
|
26
|
+
from .watchdog import BrowserUnresponsive, CallAbandoned, call_limit, operation_remaining
|
|
27
27
|
from ..entitlements import UserMarkedNoEntitlement
|
|
28
28
|
|
|
29
29
|
_OBSERVERS = WeakKeyDictionary()
|
|
@@ -33,6 +33,7 @@ OBSERVE_INTERVAL_SEC = 4 # between unforced frames (waits refresh at most this
|
|
|
33
33
|
MAX_KEPT_FRAMES = 5 # earlier page states kept per download, besides each tab's newest frame
|
|
34
34
|
JPEG_QUALITY = 60
|
|
35
35
|
SCREENSHOT_TIMEOUT_MS = 1500
|
|
36
|
+
CAPTURE_BACKOFF_SEC = 30 # after a frame that never came, for the same page state
|
|
36
37
|
|
|
37
38
|
|
|
38
39
|
def _atomic(path: Path, data: bytes) -> None:
|
|
@@ -63,6 +64,7 @@ class BrowserPreview:
|
|
|
63
64
|
self.observing = False
|
|
64
65
|
self.paused = 0
|
|
65
66
|
self._cdp = WeakKeyDictionary()
|
|
67
|
+
self._no_frame = WeakKeyDictionary() # page -> (url, until): its capture timed out
|
|
66
68
|
self._navigation_listeners = {}
|
|
67
69
|
context.on('close', self.close)
|
|
68
70
|
self._write([])
|
|
@@ -145,8 +147,19 @@ class BrowserPreview:
|
|
|
145
147
|
session = False
|
|
146
148
|
self._cdp[page] = session
|
|
147
149
|
if session:
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
url, until = self._no_frame.get(page, ("", 0.0))
|
|
151
|
+
if url == page.url and time.monotonic() < until:
|
|
152
|
+
raise TimeoutError("no frame from this page yet")
|
|
153
|
+
# The capture waits for a drawn frame and has no timeout of its own:
|
|
154
|
+
# Thieme's article tab after the school login held it for 90 s, and the
|
|
155
|
+
# watchdog ended the article as browser_unresponsive (2026-11-08).
|
|
156
|
+
try:
|
|
157
|
+
with call_limit(SCREENSHOT_TIMEOUT_MS / 1000):
|
|
158
|
+
data = session.send("Page.captureScreenshot",
|
|
159
|
+
{"format": "jpeg", "quality": JPEG_QUALITY, "fromSurface": True})
|
|
160
|
+
except CallAbandoned:
|
|
161
|
+
self._no_frame[page] = (page.url, time.monotonic() + CAPTURE_BACKOFF_SEC)
|
|
162
|
+
raise
|
|
150
163
|
return base64.b64decode(data["data"])
|
|
151
164
|
return page.screenshot(timeout=SCREENSHOT_TIMEOUT_MS, full_page=False, type="jpeg", quality=JPEG_QUALITY)
|
|
152
165
|
|
|
@@ -116,6 +116,21 @@ def abandon(owners: set) -> int:
|
|
|
116
116
|
return count
|
|
117
117
|
|
|
118
118
|
|
|
119
|
+
@contextmanager
|
|
120
|
+
def call_limit(seconds: float):
|
|
121
|
+
"""Abandon this greenlet's calls still running after ``seconds`` (:func:`abandon`):
|
|
122
|
+
for calls whose answer is optional, such as a preview frame."""
|
|
123
|
+
owners: set = set()
|
|
124
|
+
timer = threading.Timer(seconds, abandon, args=(owners,))
|
|
125
|
+
timer.daemon = True
|
|
126
|
+
with owned_by(owners):
|
|
127
|
+
timer.start()
|
|
128
|
+
try:
|
|
129
|
+
yield
|
|
130
|
+
finally:
|
|
131
|
+
timer.cancel()
|
|
132
|
+
|
|
133
|
+
|
|
119
134
|
@contextmanager
|
|
120
135
|
def operation(seconds: float, label: str):
|
|
121
136
|
"""One monotonic deadline shared by all calls and retries in this scope."""
|
|
@@ -41,11 +41,16 @@ class ScreenArea:
|
|
|
41
41
|
work: Rect
|
|
42
42
|
|
|
43
43
|
|
|
44
|
+
def _overlap(a: Rect, b: Rect) -> float:
|
|
45
|
+
return (max(0, min(a.right, b.right) - max(a.x, b.x))
|
|
46
|
+
* max(0, min(a.bottom, b.bottom) - max(a.y, b.y)))
|
|
47
|
+
|
|
48
|
+
|
|
44
49
|
def screen_for(rect: Rect, screens: list[ScreenArea]) -> ScreenArea:
|
|
45
|
-
"""
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
"""The display holding most of the rectangle, otherwise the nearest (unplugged display)."""
|
|
51
|
+
best = max(screens, key=lambda s: _overlap(rect, s.bounds))
|
|
52
|
+
if _overlap(rect, best.bounds) > 0:
|
|
53
|
+
return best
|
|
49
54
|
x, y = rect.x + rect.width / 2, rect.y + rect.height / 2
|
|
50
55
|
return min(screens, key=lambda s: max(s.bounds.x - x, 0, x - s.bounds.right) ** 2
|
|
51
56
|
+ max(s.bounds.y - y, 0, y - s.bounds.bottom) ** 2)
|
|
@@ -57,9 +62,16 @@ def fit_rect(rect: Rect, work: Rect) -> Rect:
|
|
|
57
62
|
max(work.y, min(rect.y, work.bottom - rect.height)), rect.width, rect.height)
|
|
58
63
|
|
|
59
64
|
|
|
60
|
-
def
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
def pill_anchor(pill: Rect, work: Rect) -> tuple[str, str]:
|
|
66
|
+
"""Grow away from the nearer screen edges, keeping the pill's sides there fixed."""
|
|
67
|
+
return ("down" if pill.y + pill.height / 2 < work.y + work.height / 2 else "up",
|
|
68
|
+
"right" if pill.x + pill.width / 2 < work.x + work.width / 2 else "left")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def direction_for(pill: Rect, work: Rect, height: float) -> tuple[str, str]:
|
|
72
|
+
"""Open down unless the card does not fit below; sideways away from the nearer edge."""
|
|
73
|
+
below, above = work.bottom - pill.y, pill.bottom - work.y
|
|
74
|
+
return "down" if below >= height or below >= above else "up", pill_anchor(pill, work)[1]
|
|
63
75
|
|
|
64
76
|
|
|
65
77
|
def _edge(start: float, end: float, low: float, high: float) -> int:
|
|
@@ -80,6 +92,7 @@ class Placement:
|
|
|
80
92
|
self.direction = ("down" if corner == "top" else "up", "left")
|
|
81
93
|
self.edges = (0, 0)
|
|
82
94
|
self.expanded = False
|
|
95
|
+
self._direction_fixed = False
|
|
83
96
|
self.scale = 1.0
|
|
84
97
|
self._saved: dict = {}
|
|
85
98
|
try:
|
|
@@ -138,7 +151,7 @@ class Placement:
|
|
|
138
151
|
self.home = fit_rect(Rect(b.right - EDGE - w,
|
|
139
152
|
b.y + TOP_GAP if self.corner == "top" else b.bottom - BOTTOM_GAP - h,
|
|
140
153
|
w, h), self.screen.work)
|
|
141
|
-
self.direction = self._direction(self.home)
|
|
154
|
+
self.direction = self._direction(pill_anchor(self.home, self.screen.work))
|
|
142
155
|
return round(self.home.x), round(self.home.y)
|
|
143
156
|
|
|
144
157
|
def rescale(self, scale: float) -> None:
|
|
@@ -163,7 +176,8 @@ class Placement:
|
|
|
163
176
|
self.home = actual
|
|
164
177
|
self.screen = screen_for(self.home, screens)
|
|
165
178
|
if not self.expanded:
|
|
166
|
-
self.direction = self._direction(self.home)
|
|
179
|
+
self.direction = self._direction(pill_anchor(self.home, self.screen.work))
|
|
180
|
+
self._direction_fixed = False
|
|
167
181
|
if expanded:
|
|
168
182
|
self.expanded = True
|
|
169
183
|
|
|
@@ -171,14 +185,21 @@ class Placement:
|
|
|
171
185
|
assert self.home is not None and self.screen is not None
|
|
172
186
|
home, work = self.home, self.screen.work
|
|
173
187
|
width, height = min(width, int(work.width)), min(height, int(work.height))
|
|
174
|
-
if expanded
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
188
|
+
if expanded:
|
|
189
|
+
# Chosen once per expansion: taller panels such as settings are
|
|
190
|
+
# clamped to the work area instead of flipping the card.
|
|
191
|
+
if not self._direction_fixed:
|
|
192
|
+
self.direction = self._direction(direction_for(home, work, height))
|
|
193
|
+
self._direction_fixed = True
|
|
194
|
+
anchor, (vertical, horizontal) = self._dragged_card or home, self.direction
|
|
195
|
+
elif self.expanded:
|
|
196
|
+
# Back into the corner the card grew from, also when the status
|
|
197
|
+
# changed the pill's width while it was open.
|
|
198
|
+
anchor, (vertical, horizontal) = home, self.direction
|
|
179
199
|
else:
|
|
180
|
-
|
|
181
|
-
|
|
200
|
+
anchor, (vertical, horizontal) = home, self._direction(pill_anchor(home, work))
|
|
201
|
+
x = anchor.right - width if horizontal == "left" else anchor.x
|
|
202
|
+
y = anchor.bottom - height if vertical == "up" else anchor.y
|
|
182
203
|
return self._fit(Rect(x, y, width, height))
|
|
183
204
|
|
|
184
205
|
def finish(self, expanded: bool, actual: Rect) -> None:
|
|
@@ -195,8 +216,9 @@ class Placement:
|
|
|
195
216
|
y = work.y if vertical < 0 else work.bottom - rect.height if vertical > 0 else rect.y
|
|
196
217
|
return fit_rect(Rect(x, y, rect.width, rect.height), work)
|
|
197
218
|
|
|
198
|
-
def _direction(self,
|
|
199
|
-
|
|
219
|
+
def _direction(self, free: tuple[str, str]) -> tuple[str, str]:
|
|
220
|
+
"""A docked edge decides its axis; the other axis keeps the free choice."""
|
|
221
|
+
vertical, horizontal = free
|
|
200
222
|
x, y = self.edges
|
|
201
223
|
return ("down" if y < 0 else "up" if y > 0 else vertical,
|
|
202
224
|
"right" if x < 0 else "left" if x > 0 else horizontal)
|
|
@@ -227,29 +249,27 @@ class Placement:
|
|
|
227
249
|
|
|
228
250
|
def dragged(self, after: Rect, screens: list[ScreenArea],
|
|
229
251
|
pointer: tuple[float, float] | None = None) -> Rect:
|
|
230
|
-
# At a display seam the
|
|
231
|
-
#
|
|
232
|
-
self.screen =
|
|
233
|
-
if self.screen is None:
|
|
234
|
-
self.screen = screen_for(after, screens)
|
|
252
|
+
# At a display seam the pointer may already be on the next display;
|
|
253
|
+
# the window stays on the one that holds most of it.
|
|
254
|
+
self.screen = screen_for(after, screens)
|
|
235
255
|
work = self.screen.work
|
|
236
256
|
point = pointer if pointer and self.screen.bounds.contains(*pointer) else None
|
|
237
257
|
self.edges = self._drop_edges(after, work, point)
|
|
238
258
|
after = self._fit(Rect(after.x, after.y, min(after.width, work.width), min(after.height, work.height)))
|
|
239
|
-
self.direction = self._direction(after)
|
|
240
259
|
if self.home is None or not self.expanded:
|
|
241
260
|
self.home = after
|
|
261
|
+
self.direction = self._direction(pill_anchor(after, work))
|
|
242
262
|
else:
|
|
263
|
+
# The pill goes to the card's top corner on the side nearer the
|
|
264
|
+
# screen edge (bottom corner when docked there), so opening it
|
|
265
|
+
# again puts the card back where it was dropped.
|
|
243
266
|
self._dragged_card = after
|
|
267
|
+
self.direction = self._direction(("down", pill_anchor(after, work)[1]))
|
|
268
|
+
self._direction_fixed = True
|
|
244
269
|
vertical, horizontal = self.direction
|
|
245
270
|
w, h = self.home.width, self.home.height
|
|
246
|
-
if
|
|
247
|
-
|
|
248
|
-
# much smaller pill lands along the side.
|
|
249
|
-
self.home = Rect(point[0] - w / 2, point[1] - h / 2, w, h)
|
|
250
|
-
else:
|
|
251
|
-
self.home = Rect(after.right - w if horizontal == "left" else after.x,
|
|
252
|
-
after.bottom - h if vertical == "up" else after.y, w, h)
|
|
271
|
+
self.home = Rect(after.right - w if horizontal == "left" else after.x,
|
|
272
|
+
after.bottom - h if vertical == "up" else after.y, w, h)
|
|
253
273
|
self.home = self._fit(self.home)
|
|
254
274
|
self.save()
|
|
255
275
|
return after
|
|
@@ -26,6 +26,7 @@ challenge_or_viewer_timeout ip_blocked access_blocked pdf_not_captured
|
|
|
26
26
|
pdf_identity_mismatch pdf_identity_unverified invalid_pdf
|
|
27
27
|
profile_busy cancelled interrupted skipped_cached_attempt target_verified_reached navigation_error
|
|
28
28
|
unsupported_platform unsupported_publisher user_skipped user_marked_no_entitlement pdf_wrong_article
|
|
29
|
+
article_not_yet_published
|
|
29
30
|
institution_federation_unavailable browser_unresponsive browser_operation_timeout login_not_reached idp_no_return_to_publisher
|
|
30
31
|
generic_institution_entry_missing
|
|
31
32
|
""".split())
|
|
@@ -80,6 +80,17 @@ def registrable_domain(host: str) -> str:
|
|
|
80
80
|
_ABSTRACT_ONLY = re.compile(r"/article-abstract/|/abs/pii/", re.I)
|
|
81
81
|
|
|
82
82
|
|
|
83
|
+
# The publisher shows the article as accepted, its full text not online yet:
|
|
84
|
+
# Optica's page "This paper has been accepted for publication. The DOI ... has been
|
|
85
|
+
# registered ... will redirect to the published article when available" (2026-11-08).
|
|
86
|
+
_NOT_YET_PUBLISHED = (("accepted for publication", "redirect to the published article when available"),)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def not_yet_published(text: str) -> bool:
|
|
90
|
+
flat = " ".join(text.lower().split())
|
|
91
|
+
return any(all(marker in flat for marker in markers) for markers in _NOT_YET_PUBLISHED)
|
|
92
|
+
|
|
93
|
+
|
|
83
94
|
def abstract_only(url: str) -> bool:
|
|
84
95
|
return bool(_ABSTRACT_ONLY.search(urlparse(url or "").path))
|
|
85
96
|
|
|
@@ -62,6 +62,7 @@ from .batch_common import (
|
|
|
62
62
|
PublisherAccessBlocked,
|
|
63
63
|
PublisherContentError,
|
|
64
64
|
PublisherPlatformUnsupported,
|
|
65
|
+
ArticleNotYetPublished,
|
|
65
66
|
RETRYABLE_REASONS,
|
|
66
67
|
_ACCESS_GATE_JS,
|
|
67
68
|
_IN_REFERENCES_JS,
|
|
@@ -213,7 +214,12 @@ class PublisherBatchDownloader(
|
|
|
213
214
|
own_page = [final_url] if final_url and self.adapter.is_article_page_url(final_url) else []
|
|
214
215
|
candidates = self.adapter.supplements_page_urls(doi) or [self._article_url(doi)]
|
|
215
216
|
incomplete = ""
|
|
216
|
-
|
|
217
|
+
listed = list(getattr(result, "_listed_supplements", None) or [])
|
|
218
|
+
if listed:
|
|
219
|
+
# Read on the article page before its PDF: no second load.
|
|
220
|
+
links = listed
|
|
221
|
+
self._event(result, "supplements_listed_on_article", str(len(links)))
|
|
222
|
+
for url in ([] if listed else dict.fromkeys(own_page + candidates)):
|
|
217
223
|
open_page(page, url, timeout_ms=60_000)
|
|
218
224
|
if self._challenge_shell(page) or self._is_challenge_page(page):
|
|
219
225
|
if not self._wait_for_challenge(page, result):
|
|
@@ -616,6 +622,12 @@ class PublisherBatchDownloader(
|
|
|
616
622
|
self._event(result, "publisher_access_blocked")
|
|
617
623
|
self._write_diagnostic(page, result, run_dir)
|
|
618
624
|
return result
|
|
625
|
+
except ArticleNotYetPublished as page_url:
|
|
626
|
+
result.reason = result.state = "article_not_yet_published"
|
|
627
|
+
self._event(result, "article_not_yet_published", str(page_url))
|
|
628
|
+
progress_reporter.update(phase="出版社尚未发布这篇论文的全文,当前路径已停止")
|
|
629
|
+
self._write_diagnostic(page, result, run_dir)
|
|
630
|
+
return result
|
|
619
631
|
except PublisherPlatformUnsupported as platform:
|
|
620
632
|
result.reason = result.state = "unsupported_platform"
|
|
621
633
|
self._event(result, "unsupported_platform", str(platform))
|
|
@@ -16,6 +16,7 @@ from .batch_common import (
|
|
|
16
16
|
settle,
|
|
17
17
|
DownloadResult,
|
|
18
18
|
PublisherAccessBlocked,
|
|
19
|
+
ArticleNotYetPublished,
|
|
19
20
|
PublisherContentError,
|
|
20
21
|
PublisherPlatformUnsupported,
|
|
21
22
|
_ACCESS_GATE_JS,
|
|
@@ -211,6 +212,8 @@ class AccessMixin:
|
|
|
211
212
|
if self._is_auth_page(url):
|
|
212
213
|
return access_rules.OUT, "login_page", url[:160]
|
|
213
214
|
snap = snapshot or self._access_snapshot(page)
|
|
215
|
+
if access_rules.not_yet_published(str(getattr(snap, "text", "") or "")):
|
|
216
|
+
raise ArticleNotYetPublished(url[:160])
|
|
214
217
|
if self._institution_session(page, snap) == "ours":
|
|
215
218
|
names = access_rules.session_names(snap.lines)
|
|
216
219
|
label = next((str(l) for l in snap.probe.get("labels") or () if not access_rules.is_generic_label(str(l))), "")
|
|
@@ -337,6 +337,25 @@ class CaptureMixin:
|
|
|
337
337
|
except Exception:
|
|
338
338
|
pass
|
|
339
339
|
|
|
340
|
+
# Figshare links: their files are found by its own API in the attachment step.
|
|
341
|
+
_FIGSHARE_LINKED_JS = "() => !!document.querySelector('a[href*=\"figshare.com\"]')"
|
|
342
|
+
|
|
343
|
+
def _remember_listed_supplements(self, page: Any, doi: str, result: DownloadResult) -> None:
|
|
344
|
+
"""The files the article page lists, read before the PDF takes its tab: the
|
|
345
|
+
attachment step then need not load the page again (AHA's page took more
|
|
346
|
+
than that step's 60 s once, 2026-11-08). Only from an adapter that reads
|
|
347
|
+
them without leaving the page, and not beside Figshare links."""
|
|
348
|
+
read = getattr(self.adapter, "listed_supplement_links", None)
|
|
349
|
+
if read is None or getattr(result, "_listed_supplements", None):
|
|
350
|
+
return
|
|
351
|
+
try:
|
|
352
|
+
links = read(page, doi)
|
|
353
|
+
if links and not page.evaluate(self._FIGSHARE_LINKED_JS):
|
|
354
|
+
result._listed_supplements = list(links)
|
|
355
|
+
except Exception as exc:
|
|
356
|
+
if not _is_browser_error(exc):
|
|
357
|
+
raise
|
|
358
|
+
|
|
340
359
|
def _capture_pdf_channels(self, page: Any, doi: str, result: DownloadResult) -> tuple[bytes | None, str, str | None]:
|
|
341
360
|
"""Capture the PDF for ``doi`` from ``page``.
|
|
342
361
|
|
|
@@ -345,6 +364,7 @@ class CaptureMixin:
|
|
|
345
364
|
was observed during capture, else ``None``.
|
|
346
365
|
"""
|
|
347
366
|
self._event(result, "pdf_capture_started")
|
|
367
|
+
self._remember_listed_supplements(page, doi, result)
|
|
348
368
|
captured: dict[str, Any] = {"bytes": None, "url": "", "deferred_url": "", "block_reason": None,
|
|
349
369
|
"suspect_block": None, "closed": False, "readers": set()}
|
|
350
370
|
cdp_session = None
|
|
@@ -503,5 +503,9 @@ class PublisherPlatformUnsupported(PublisherContentError):
|
|
|
503
503
|
"""The article is served only on a platform this engine cannot use (e.g. ClinicalKey)."""
|
|
504
504
|
|
|
505
505
|
|
|
506
|
+
class ArticleNotYetPublished(PublisherContentError):
|
|
507
|
+
"""The publisher lists the article as accepted; its full text is not online yet."""
|
|
508
|
+
|
|
509
|
+
|
|
506
510
|
class PublisherAccessBlocked(RuntimeError):
|
|
507
511
|
"""An explicit site security block, without an interactive verification."""
|