papersearch 0.4.5 → 0.4.7
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 +7 -4
- package/README.md +7 -4
- package/carsi/paper_search_carsi/adapters/ams/__init__.py +34 -1
- package/carsi/paper_search_carsi/adapters/annual_reviews/__init__.py +26 -1
- package/carsi/paper_search_carsi/adapters/aps/__init__.py +25 -2
- package/carsi/paper_search_carsi/adapters/copernicus/__init__.py +27 -1
- package/carsi/paper_search_carsi/adapters/elsevier/__init__.py +19 -1
- package/carsi/paper_search_carsi/adapters/ieee/__init__.py +102 -2
- package/carsi/paper_search_carsi/adapters/iop/__init__.py +41 -2
- package/carsi/paper_search_carsi/adapters/lww/ovid.py +4 -2
- package/carsi/paper_search_carsi/adapters/optica/__init__.py +14 -1
- package/carsi/paper_search_carsi/adapters/oup/__init__.py +105 -94
- package/carsi/paper_search_carsi/adapters/platforms/atypon/__init__.py +26 -12
- package/carsi/paper_search_carsi/adapters/platforms/figshare/__init__.py +20 -11
- package/carsi/paper_search_carsi/adapters/platforms/silverchair/__init__.py +1 -1
- package/carsi/paper_search_carsi/adapters/plos/__init__.py +31 -1
- package/carsi/paper_search_carsi/adapters/thieme/__init__.py +25 -2
- package/carsi/paper_search_carsi/assets/capsule.html +64 -21
- package/carsi/paper_search_carsi/assets/papersearch-notifier +0 -0
- package/carsi/paper_search_carsi/assets/quiet-browser/api.js +142 -0
- package/carsi/paper_search_carsi/assets/quiet-browser/manifest.json +24 -0
- package/carsi/paper_search_carsi/assets/quiet-browser/schema.json +1 -0
- package/carsi/paper_search_carsi/browser/backend.py +36 -0
- package/carsi/paper_search_carsi/browser/background.py +68 -0
- package/carsi/paper_search_carsi/browser/challenge_interaction.py +35 -0
- package/carsi/paper_search_carsi/browser/challenges.py +10 -0
- package/carsi/paper_search_carsi/browser/foreground.py +201 -0
- package/carsi/paper_search_carsi/browser/login.py +3 -1
- package/carsi/paper_search_carsi/browser/preview.py +3 -1
- package/carsi/paper_search_carsi/config.py +4 -1
- package/carsi/paper_search_carsi/engine/batch.py +62 -20
- package/carsi/paper_search_carsi/engine/batch_capture.py +54 -19
- package/carsi/paper_search_carsi/engine/batch_common.py +29 -2
- package/carsi/paper_search_carsi/engine/batch_diagnostics.py +31 -10
- package/carsi/paper_search_carsi/engine/batch_institution.py +56 -14
- package/carsi/paper_search_carsi/engine/batch_login.py +264 -204
- package/carsi/paper_search_carsi/engine/batch_user.py +67 -2
- package/carsi/paper_search_carsi/engine/batch_waits.py +76 -30
- package/carsi/paper_search_carsi/engine/login_wait.py +125 -0
- package/carsi/paper_search_carsi/engine/page_activity.py +177 -0
- package/carsi/paper_search_carsi/engine/supplements.py +12 -1
- package/carsi/paper_search_carsi/entitlements.py +23 -3
- package/carsi/paper_search_carsi/progress_capsule.py +130 -18
- package/carsi/paper_search_carsi/progress_macos.py +166 -0
- package/carsi/paper_search_carsi/progress_reporter.py +22 -1
- package/carsi/paper_search_carsi/progress_view.py +8 -6
- package/carsi/paper_search_carsi/publishers/profiles.py +5 -3
- package/carsi/paper_search_carsi/server.py +17 -1
- package/carsi/paper_search_carsi/user_settings.py +4 -4
- package/carsi/pyproject.toml +1 -1
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.js +2 -2
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.js.map +1 -1
- package/dist/capabilities/pdf-discovery/batch.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/batch.js +28 -4
- package/dist/capabilities/pdf-discovery/batch.js.map +1 -1
- package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.js +1 -1
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.d.ts +2 -6
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.d.ts.map +1 -1
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.js +1 -0
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.js.map +1 -1
- package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
- package/dist/infrastructure/runlog/failureClass.js +3 -2
- package/dist/infrastructure/runlog/failureClass.js.map +1 -1
- package/dist/management/carsi/installer.d.ts +2 -1
- package/dist/management/carsi/installer.d.ts.map +1 -1
- package/dist/management/carsi/installer.js +24 -1
- package/dist/management/carsi/installer.js.map +1 -1
- package/package.json +1 -1
- package/skills/paper-search/references/browser-download.md +11 -7
- package/skills/paper-search/references/carsi-setup.md +1 -0
- package/skills/paper-search/references/publisher-support.md +42 -41
|
@@ -268,99 +268,110 @@ class OUPAdapter(PublisherAdapter):
|
|
|
268
268
|
last_progress_at = time.monotonic()
|
|
269
269
|
action_done = False
|
|
270
270
|
pending_retry = ""
|
|
271
|
-
waiting = None # (since, page marker
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
return False
|
|
293
|
-
if state in {"verification", "human_login", "institution_chooser"}:
|
|
294
|
-
# A stale redirect timer must never reload a human form.
|
|
295
|
-
pending_retry = ""
|
|
296
|
-
last_progress_at = time.monotonic()
|
|
297
|
-
if state == "institution_chooser":
|
|
298
|
-
d._select_institution(page, result)
|
|
299
|
-
if d._user_away:
|
|
300
|
-
# The user seems away: as everywhere, a page of theirs on
|
|
301
|
-
# which nothing moves and nothing is typed ends the article.
|
|
302
|
-
typed = d._visible_input_values(page)
|
|
303
|
-
if waiting is None or waiting[1:] != (marker, typed):
|
|
304
|
-
waiting = (time.monotonic(), marker, typed)
|
|
305
|
-
elif time.monotonic() - waiting[0] >= AWAY_WAIT_SEC:
|
|
306
|
-
d._wait_ran_out(result)
|
|
307
|
-
result.reason = "login_timeout"
|
|
308
|
-
d._event(result, "login_stopped", result.reason)
|
|
309
|
-
return False
|
|
310
|
-
else:
|
|
311
|
-
if state == "transient_error":
|
|
312
|
-
pending_retry = "transient_error"
|
|
313
|
-
elif state == "publisher_login" and not action_done and getattr(result, "_oxford_login_entry_attempt", 0) == attempt:
|
|
314
|
-
pending_retry = "returned_auth_wall"
|
|
315
|
-
elif time.monotonic() - last_progress_at >= 45:
|
|
316
|
-
pending_retry = "redirect_stalled"
|
|
317
|
-
if pending_retry:
|
|
318
|
-
if attempt >= max_attempts:
|
|
319
|
-
result.reason = "login_retries_exhausted"
|
|
320
|
-
d._event(result, "login_stopped", result.reason)
|
|
321
|
-
return False
|
|
322
|
-
d._event(result, "login_retry_wait", f"{attempt + 1}/3")
|
|
323
|
-
page.wait_for_timeout(min(3_000 * attempt, max(1, int((deadline - time.monotonic()) * 1000))))
|
|
324
|
-
if time.monotonic() >= deadline:
|
|
325
|
-
break
|
|
326
|
-
# Recheck after backoff: the user or redirect may have
|
|
327
|
-
# completed while the browser dispatched pending events.
|
|
328
|
-
after_wait = self.login_state(page, deadline)
|
|
329
|
-
if time.monotonic() >= deadline:
|
|
330
|
-
break
|
|
331
|
-
if after_wait not in {"transient_error", "publisher_login", "redirect_wait"}:
|
|
332
|
-
pending_retry = ""
|
|
333
|
-
continue
|
|
334
|
-
attempt += 1
|
|
335
|
-
result._oxford_login_attempt = attempt
|
|
336
|
-
d._event(result, "login_attempt_started", f"{attempt}/3")
|
|
337
|
-
pending_retry = ""
|
|
271
|
+
waiting = None # (since, page marker) while the page is the user's
|
|
272
|
+
with d._login_wait_budget(result, "_oxford_login_deadline", deadline, time.monotonic) as wait:
|
|
273
|
+
while time.monotonic() < wait.deadline:
|
|
274
|
+
deadline = wait.deadline
|
|
275
|
+
try:
|
|
276
|
+
d._check_user_decision(result, page)
|
|
277
|
+
state = self.login_state(page, deadline)
|
|
278
|
+
deadline = wait.deadline
|
|
279
|
+
if time.monotonic() >= deadline:
|
|
280
|
+
break
|
|
281
|
+
user_step = state == "human_login" or (state == "institution_chooser" and d._users_login_step(page))
|
|
282
|
+
wait.observe(page, user_step)
|
|
283
|
+
deadline = wait.deadline
|
|
284
|
+
message = ("请在浏览器窗口选择学校并完成机构登录" if state == "institution_chooser"
|
|
285
|
+
else "请在浏览器窗口完成机构登录") if user_step else ""
|
|
286
|
+
d._set_login_attention(result, message, time.time() + deadline - time.monotonic(), page=page)
|
|
287
|
+
parsed = urlparse(str(page.url))
|
|
288
|
+
marker = (state, parsed.hostname, parsed.path)
|
|
289
|
+
if marker != last_marker:
|
|
290
|
+
d._event(result, "login_observed", state)
|
|
291
|
+
last_marker = marker
|
|
338
292
|
last_progress_at = time.monotonic()
|
|
339
293
|
action_done = False
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
if state
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
294
|
+
if state == "article_ready":
|
|
295
|
+
result.reason = ""
|
|
296
|
+
return True
|
|
297
|
+
if state in {"login_page_closed", "login_credentials_rejected",
|
|
298
|
+
"institution_not_registered", "institution_pdf_entitlement_missing",
|
|
299
|
+
"publisher_temporarily_unavailable"}:
|
|
300
|
+
result.reason = state
|
|
301
|
+
d._event(result, "login_stopped", state)
|
|
302
|
+
return False
|
|
303
|
+
if state in {"verification", "human_login", "institution_chooser"}:
|
|
304
|
+
# A stale redirect timer must never reload a human form.
|
|
305
|
+
pending_retry = ""
|
|
306
|
+
last_progress_at = time.monotonic()
|
|
307
|
+
if state == "institution_chooser":
|
|
308
|
+
d._select_institution(page, result)
|
|
309
|
+
if wait.paused:
|
|
310
|
+
waiting = None
|
|
311
|
+
if d._user_away and not wait.paused:
|
|
312
|
+
# The user seems away: as everywhere, a page of theirs on
|
|
313
|
+
# which nothing moves and nothing is typed ends the article.
|
|
314
|
+
if waiting is None or waiting[1] != marker:
|
|
315
|
+
waiting = (time.monotonic(), marker)
|
|
316
|
+
elif time.monotonic() - waiting[0] >= AWAY_WAIT_SEC:
|
|
317
|
+
d._wait_ran_out(result)
|
|
318
|
+
result.reason = "login_timeout"
|
|
319
|
+
d._event(result, "login_stopped", result.reason)
|
|
320
|
+
return False
|
|
321
|
+
else:
|
|
322
|
+
if state == "transient_error":
|
|
323
|
+
pending_retry = "transient_error"
|
|
324
|
+
elif state == "publisher_login" and not action_done and getattr(result, "_oxford_login_entry_attempt", 0) == attempt:
|
|
325
|
+
pending_retry = "returned_auth_wall"
|
|
326
|
+
elif time.monotonic() - last_progress_at >= 45:
|
|
327
|
+
pending_retry = "redirect_stalled"
|
|
328
|
+
if pending_retry:
|
|
329
|
+
if attempt >= max_attempts:
|
|
330
|
+
result.reason = "login_retries_exhausted"
|
|
331
|
+
d._event(result, "login_stopped", result.reason)
|
|
332
|
+
return False
|
|
333
|
+
d._event(result, "login_retry_wait", f"{attempt + 1}/3")
|
|
334
|
+
page.wait_for_timeout(min(3_000 * attempt, max(1, int((deadline - time.monotonic()) * 1000))))
|
|
335
|
+
if time.monotonic() >= deadline:
|
|
336
|
+
break
|
|
337
|
+
# Recheck after backoff: the user or redirect may have
|
|
338
|
+
# completed while the browser dispatched pending events.
|
|
339
|
+
after_wait = self.login_state(page, deadline)
|
|
340
|
+
if time.monotonic() >= deadline:
|
|
341
|
+
break
|
|
342
|
+
if after_wait not in {"transient_error", "publisher_login", "redirect_wait"}:
|
|
343
|
+
pending_retry = ""
|
|
344
|
+
continue
|
|
345
|
+
attempt += 1
|
|
346
|
+
result._oxford_login_attempt = attempt
|
|
347
|
+
d._event(result, "login_attempt_started", f"{attempt}/3")
|
|
348
|
+
pending_retry = ""
|
|
349
|
+
last_progress_at = time.monotonic()
|
|
350
|
+
action_done = False
|
|
351
|
+
open_page(page, result.article_url,
|
|
352
|
+
timeout_ms=max(1, min(15_000, int((deadline - time.monotonic()) * 1000))))
|
|
353
|
+
continue
|
|
354
|
+
if state == "publisher_login" and not action_done:
|
|
355
|
+
action_done = self.advance_login(page, result, deadline)
|
|
356
|
+
if action_done:
|
|
357
|
+
result._oxford_login_entry_attempt = attempt
|
|
358
|
+
remaining_ms = max(0, int((deadline - time.monotonic()) * 1000))
|
|
359
|
+
if remaining_ms:
|
|
360
|
+
page.wait_for_timeout(min(1_000, remaining_ms))
|
|
361
|
+
except Exception as exc:
|
|
362
|
+
if page.is_closed():
|
|
363
|
+
result.reason = "login_page_closed"
|
|
364
|
+
d._event(result, "login_stopped", result.reason)
|
|
365
|
+
return False
|
|
366
|
+
# Only browser navigation/timeouts are retryable. Programming
|
|
367
|
+
# errors must retain the normal unexpected_error path.
|
|
368
|
+
if not self.retryable_navigation_error(exc):
|
|
369
|
+
raise
|
|
370
|
+
d._event(result, "login_navigation_interrupted", type(exc).__name__)
|
|
371
|
+
pending_retry = "navigation_error"
|
|
372
|
+
remaining = int((deadline - time.monotonic()) * 1000)
|
|
373
|
+
if remaining > 0:
|
|
374
|
+
page.wait_for_timeout(min(1_000, remaining))
|
|
375
|
+
result.reason = "login_timeout"
|
|
376
|
+
d._event(result, "login_stopped", result.reason)
|
|
377
|
+
return False
|
|
@@ -26,7 +26,7 @@ _ARTICLE = re.compile(r"/doi/(?:(?:abs|full|pdf|epdf|pdfdirect|reader)/)?(10\.\d
|
|
|
26
26
|
_CARSI = "China CERNET Federation (CARSI)"
|
|
27
27
|
# Supplement files: /doi/suppl/<DOI>/suppl_file/<name>, with the link text.
|
|
28
28
|
_SUPPLEMENT_ROWS_JS = """() => [...document.querySelectorAll('a[href*="/doi/suppl/"]')].map(a => ({
|
|
29
|
-
href: a.href, label: (a.
|
|
29
|
+
href: a.href, label: ((a.textContent || '').trim() || a.getAttribute('title') || '').replace(/\\s+/g, ' ').trim().slice(0, 200)}))"""
|
|
30
30
|
# The page's institution-login links, read at once: a link-by-link lookup waited
|
|
31
31
|
# 30 s on a page still navigating after a silent IdP return (ASCE, 2026-11-02).
|
|
32
32
|
_SSOSTART_LINKS_JS = """() => [...document.querySelectorAll('a[href*="/action/ssostart"]')].map(a => ({
|
|
@@ -54,17 +54,31 @@ class AtyponAdapter(PublisherAdapter):
|
|
|
54
54
|
|
|
55
55
|
def supplement_links(self, page: Any, doi: str) -> list[SupplementLink] | None:
|
|
56
56
|
"""Files under ``/doi/suppl/<this DOI>/suppl_file/``; a supplement link of
|
|
57
|
-
another article on the page
|
|
58
|
-
links
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
for
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
another article on the page is not this article's. Follow the observed
|
|
58
|
+
supplement landing page once when the article only links to that page.
|
|
59
|
+
"""
|
|
60
|
+
landing_path = f"/doi/suppl/{doi.lower()}"
|
|
61
|
+
for attempt in range(2):
|
|
62
|
+
links: list[SupplementLink] = []
|
|
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
|
|
76
|
+
if links or not landing or attempt:
|
|
77
|
+
return links
|
|
78
|
+
if unquote(urlparse(str(page.url)).path).lower().rstrip("/") == landing_path:
|
|
79
|
+
return []
|
|
80
|
+
open_page(page, landing, timeout_ms=30_000)
|
|
81
|
+
return []
|
|
68
82
|
|
|
69
83
|
def institution_chooser_open(self, page: Any) -> bool:
|
|
70
84
|
return self._chooser(str(getattr(page, "url", "") or "")) and page.locator("select#shib-search--fed").is_visible()
|
|
@@ -19,14 +19,19 @@ _MAX_RESOURCES = 5
|
|
|
19
19
|
_MAX_ARTICLES = 50
|
|
20
20
|
_MAX_BYTES = 200 * 1024 * 1024
|
|
21
21
|
_BUDGET_SEC = 30
|
|
22
|
-
_PAGE_LINKS = """() =>
|
|
23
|
-
doi: document.querySelector('meta[name="citation_doi"]')?.content || '',
|
|
22
|
+
_PAGE_LINKS = """() => {
|
|
24
23
|
// A cited dataset is not a supplement of the article citing it.
|
|
25
|
-
links
|
|
24
|
+
const links = [...document.querySelectorAll('a[href], iframe[src]')]
|
|
26
25
|
.filter(a => !a.closest('[role="doc-bibliography"], [role="doc-biblioentry"], '
|
|
27
|
-
+ '#references, #bibliography, .ref-list, .article-section__references'))
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
+ '#references, #bibliography, #articleReferences, .ref-list, .article-section__references'));
|
|
27
|
+
return {
|
|
28
|
+
doi: document.querySelector('meta[name="citation_doi"]')?.content || '',
|
|
29
|
+
links: links.map(a => a.href || a.src),
|
|
30
|
+
labelled: links.filter(a => a.tagName === 'A' &&
|
|
31
|
+
/^(?:supplement(?:ary)?(?: (?:material|information|data|file|document))?|supporting information)\\s*\\d*$/i
|
|
32
|
+
.test((a.textContent || '').replace(/\\s+/g,' ').trim())).map(a => a.href)
|
|
33
|
+
};
|
|
34
|
+
}"""
|
|
30
35
|
|
|
31
36
|
|
|
32
37
|
def _doi(value: Any) -> str:
|
|
@@ -66,13 +71,17 @@ def resource(url: str) -> tuple[str, str, str] | None:
|
|
|
66
71
|
return m[1], m[2], m[3] or ""
|
|
67
72
|
|
|
68
73
|
|
|
69
|
-
def _belongs(data: dict, doi: str) -> bool:
|
|
74
|
+
def _belongs(data: dict, doi: str, *, labelled: bool = False) -> bool:
|
|
70
75
|
resource_doi = _doi(data.get("resource_doi"))
|
|
71
76
|
if resource_doi:
|
|
72
77
|
return resource_doi == doi
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
parents = [_doi(item.get("identifier")) for item in data.get("related_materials") or []
|
|
79
|
+
if isinstance(item, dict) and item.get("relation") == "IsSupplementTo"]
|
|
80
|
+
if parents:
|
|
81
|
+
return doi in parents
|
|
82
|
+
# Some publisher deposits omit the backlink. An explicit Supplement link
|
|
83
|
+
# on the DOI-verified article is then sufficient; a plain citation is not.
|
|
84
|
+
return labelled
|
|
76
85
|
|
|
77
86
|
|
|
78
87
|
def supplement_links(page: Any, doi: str, *, clock=time.monotonic, pause=time.sleep) -> list[SupplementLink] | None:
|
|
@@ -124,7 +133,7 @@ def supplement_links(page: Any, doi: str, *, clock=time.monotonic, pause=time.sl
|
|
|
124
133
|
if (requested != actual if version else
|
|
125
134
|
re.sub(r"\.v\d+$", "", requested) != re.sub(r"\.v\d+$", "", actual)):
|
|
126
135
|
raise ValueError("figshare_resource_doi_mismatch")
|
|
127
|
-
if not _belongs(detail, doi):
|
|
136
|
+
if not _belongs(detail, doi, labelled=root in data.get("labelled", [])):
|
|
128
137
|
raise ValueError("figshare_article_mismatch")
|
|
129
138
|
articles = [detail]
|
|
130
139
|
if kind == "collections":
|
|
@@ -25,7 +25,7 @@ _ARTICLE = re.compile(r"/[^/]+/article(?:-abstract)?/(?:doi/10\.\d{4,9}/.+/)?\d+
|
|
|
25
25
|
_SUPPLEMENT = re.compile(r"/[^/]+/article-supplement/(\d{5,})/")
|
|
26
26
|
_SUPPLEMENT_ROWS_JS = """() => [...document.querySelectorAll('a[href]')].map(a => ({
|
|
27
27
|
href: a.href, label: (a.innerText || a.getAttribute('title') || '').replace(/\\s+/g, ' ').trim().slice(0, 200),
|
|
28
|
-
in_section: !!a.closest('[class*="supplementary-material"]')}))"""
|
|
28
|
+
in_section: !!a.closest('[class*="supplementary-material"], .dataSuppLink')}))"""
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
def supplement_links(page: Any, doi: str, hosts: frozenset[str]) -> list[SupplementLink]:
|
|
@@ -5,14 +5,44 @@ path comes from the source page or the DOI's journal code.
|
|
|
5
5
|
"""
|
|
6
6
|
from __future__ import annotations
|
|
7
7
|
|
|
8
|
+
import re
|
|
9
|
+
from typing import Any
|
|
10
|
+
from urllib.parse import parse_qs, urlparse
|
|
11
|
+
|
|
8
12
|
from ...engine.router import _append_plos_candidates
|
|
9
|
-
from ..base import PublisherAdapter, register
|
|
13
|
+
from ..base import PublisherAdapter, SupplementLink, register
|
|
14
|
+
|
|
15
|
+
_SUPPLEMENT_ROWS_JS = """() => [...document.querySelectorAll('a[href]')].map(a => ({
|
|
16
|
+
href: a.href, label: (a.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 240)
|
|
17
|
+
}))"""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def supplement_links_from_rows(rows: list[dict], doi: str) -> list[SupplementLink]:
|
|
21
|
+
links: list[SupplementLink] = []
|
|
22
|
+
seen: set[str] = set()
|
|
23
|
+
for row in rows:
|
|
24
|
+
target = urlparse(str(row.get("href") or ""))
|
|
25
|
+
query = parse_qs(target.query)
|
|
26
|
+
ids = query.get("id", [])
|
|
27
|
+
if (target.scheme != "https" or target.netloc != "journals.plos.org"
|
|
28
|
+
or not re.fullmatch(r"/[a-z]+/article/file", target.path)
|
|
29
|
+
or query.get("type") != ["supplementary"] or len(ids) != 1
|
|
30
|
+
or not re.fullmatch(re.escape(doi) + r"\.s\d+", ids[0], re.I)):
|
|
31
|
+
continue
|
|
32
|
+
identity = ids[0].lower()
|
|
33
|
+
if identity not in seen:
|
|
34
|
+
seen.add(identity)
|
|
35
|
+
links.append(SupplementLink(target._replace(fragment="").geturl(), str(row.get("label") or "")))
|
|
36
|
+
return links
|
|
10
37
|
|
|
11
38
|
|
|
12
39
|
@register
|
|
13
40
|
class PLOSAdapter(PublisherAdapter):
|
|
14
41
|
publisher = "plos"
|
|
15
42
|
|
|
43
|
+
def supplement_links(self, page: Any, doi: str) -> list[SupplementLink]:
|
|
44
|
+
return supplement_links_from_rows(page.evaluate(_SUPPLEMENT_ROWS_JS), doi)
|
|
45
|
+
|
|
16
46
|
@classmethod
|
|
17
47
|
def profile_pdf_candidates(cls, doi: str, source_url: str) -> list[str]:
|
|
18
48
|
urls: list[str] = []
|
|
@@ -13,14 +13,34 @@ from __future__ import annotations
|
|
|
13
13
|
import re
|
|
14
14
|
import time
|
|
15
15
|
from typing import Any
|
|
16
|
-
from urllib.parse import parse_qs, urlencode, urljoin, urlparse
|
|
16
|
+
from urllib.parse import parse_qs, unquote, urlencode, urljoin, urlparse
|
|
17
17
|
|
|
18
18
|
from ...engine.router import is_thieme_article_pdf_url
|
|
19
19
|
from ...engine.batch_common import _is_browser_error, open_page
|
|
20
|
-
from ..base import PublisherAdapter, register
|
|
20
|
+
from ..base import PublisherAdapter, SupplementLink, register
|
|
21
21
|
|
|
22
22
|
_HOSTS = frozenset({"thieme-connect.de", "www.thieme-connect.de", "thieme-connect.com", "www.thieme-connect.com"})
|
|
23
23
|
|
|
24
|
+
_SUPPLEMENT_ROWS_JS = """() => [...document.querySelectorAll('a[href]')].map(a => ({
|
|
25
|
+
href: a.href, label: (a.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 240)
|
|
26
|
+
}))"""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def supplement_links_from_rows(rows: list[dict], doi: str) -> list[SupplementLink]:
|
|
30
|
+
stem = doi.lower().replace(".", "-").replace("/", "-")
|
|
31
|
+
links: list[SupplementLink] = []
|
|
32
|
+
seen: set[str] = set()
|
|
33
|
+
for row in rows:
|
|
34
|
+
target = urlparse(str(row.get("href") or ""))
|
|
35
|
+
path = unquote(target.path).lower()
|
|
36
|
+
url = target._replace(fragment="").geturl()
|
|
37
|
+
if (target.scheme == "https" and target.netloc.lower() in _HOSTS
|
|
38
|
+
and re.fullmatch(r"/media/[^/]+/\d+/supmat/" + re.escape(stem) + r"_[^/]+", path)
|
|
39
|
+
and url not in seen):
|
|
40
|
+
seen.add(url)
|
|
41
|
+
links.append(SupplementLink(url, str(row.get("label") or "")))
|
|
42
|
+
return links
|
|
43
|
+
|
|
24
44
|
|
|
25
45
|
@register
|
|
26
46
|
class ThiemeAdapter(PublisherAdapter):
|
|
@@ -29,6 +49,9 @@ class ThiemeAdapter(PublisherAdapter):
|
|
|
29
49
|
binds_response_url = True
|
|
30
50
|
requires_institution_entry = True
|
|
31
51
|
|
|
52
|
+
def supplement_links(self, page: Any, doi: str) -> list[SupplementLink]:
|
|
53
|
+
return supplement_links_from_rows(page.evaluate(_SUPPLEMENT_ROWS_JS), doi)
|
|
54
|
+
|
|
32
55
|
@classmethod
|
|
33
56
|
def profile_pdf_candidate_url(cls, url: str) -> bool | None:
|
|
34
57
|
return is_thieme_article_pdf_url(url)
|
|
@@ -27,24 +27,32 @@ body {
|
|
|
27
27
|
font-variant-numeric: tabular-nums;
|
|
28
28
|
}
|
|
29
29
|
body.mac { padding: 10px; } /* room for the shadow around a transparent window */
|
|
30
|
-
#root { box-sizing: border-box; overflow: hidden; display: inline-block; background: var(--bg); border: 0.5px solid var(--line); cursor:
|
|
31
|
-
#root.dragging, #root.dragging * { cursor:
|
|
30
|
+
#root { position: relative; box-sizing: border-box; overflow: hidden; display: inline-block; background: var(--bg); border: 0.5px solid var(--line); cursor: default; }
|
|
31
|
+
#root.dragging, #root.dragging * { cursor: default; }
|
|
32
32
|
body.mac #root { box-shadow: var(--shadow); -webkit-backdrop-filter: blur(20px); }
|
|
33
33
|
#root.pill { border-radius: 999px; }
|
|
34
34
|
#root.card { border-radius: 16px; width: 330px; box-sizing: border-box; }
|
|
35
35
|
body:not(.mac) #root { border-radius: 8px; border: none; }
|
|
36
36
|
#root.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
|
|
37
|
-
.
|
|
37
|
+
#root.warn::after {
|
|
38
|
+
content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
|
|
39
|
+
background: rgba(245, 158, 11, 0.17); z-index: 0;
|
|
40
|
+
box-shadow: inset 0 0 0 2px var(--warn-dot), inset 0 0 16px rgba(217, 119, 6, 0.2);
|
|
41
|
+
opacity: 0.2; animation: breathe 3.6s ease-in-out infinite;
|
|
42
|
+
}
|
|
43
|
+
.surface { position: relative; z-index: 1; transform-origin: top right; }
|
|
38
44
|
.fade .surface { animation: fade .22s ease-out; }
|
|
39
45
|
.folder-setting { margin: 12px 0; }
|
|
40
46
|
.folder-setting .folder-row { display:flex; gap:8px; margin-top:6px; }
|
|
41
47
|
.folder-setting input { width:0; min-width:0; flex:1; text-align:left; }
|
|
42
48
|
.folder-setting .hint { margin-top:5px; font-size:11px; color:var(--dim); }
|
|
43
|
-
@media (prefers-reduced-motion: reduce) { .fade .surface { animation:none; } }
|
|
49
|
+
@media (prefers-reduced-motion: reduce) { .fade .surface, #root.warn::after { animation:none; } }
|
|
44
50
|
@keyframes fade { from { opacity: 0; transform: translateY(-2px); } to { opacity: 1; transform: none; } }
|
|
45
|
-
@keyframes breathe { 0%, 100% {
|
|
46
|
-
body.mac #root.warn.new { animation: breathe 1.6s ease-in-out 2; }
|
|
51
|
+
@keyframes breathe { 0%, 100% { opacity: 0.2; } 50% { opacity: 0.85; } }
|
|
47
52
|
|
|
53
|
+
.attention-target { appearance: none; box-sizing: content-box; padding: 0; border: none; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
|
|
54
|
+
.pill-prompt { display: inline-flex; align-items: center; gap: 8px; }
|
|
55
|
+
.attention-target:focus-visible { outline: 2px solid var(--warn-dot); outline-offset: -2px; border-radius: 8px; }
|
|
48
56
|
.pillrow { display: flex; align-items: center; gap: 8px; padding: 5px 14px 5px 6px; white-space: nowrap; height: 28px; }
|
|
49
57
|
.pillrow.icon-first { padding-left: 12px; }
|
|
50
58
|
.count { font-weight: 600; font-size: 14px; }
|
|
@@ -112,6 +120,14 @@ svg.i { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-widt
|
|
|
112
120
|
.prompt svg.i { width: 22px; height: 22px; }
|
|
113
121
|
.prompt .t { font-weight: 600; font-size: 14px; }
|
|
114
122
|
.prompt .s { font-size: 12px; }
|
|
123
|
+
.prompt.attention-target { width: 100%; box-sizing: border-box; padding: 12px; border: 1px solid var(--warn-line); border-radius: 13px; background: var(--warn-bg); }
|
|
124
|
+
.attention-copy { flex: 1; min-width: 0; }
|
|
125
|
+
.prompt.attention-target .t { white-space: nowrap; font-size: 15px; }
|
|
126
|
+
.prompt.attention-target .s { white-space: nowrap; margin-top: 3px; font-size: 11px; }
|
|
127
|
+
.attention-arrow { flex: none; font-size: 19px; }
|
|
128
|
+
.attention-head { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; color: var(--fg); }
|
|
129
|
+
.attention-head b { flex: 1; font-size: 12px; }
|
|
130
|
+
#root.card.warn { background: var(--bg); }
|
|
115
131
|
</style>
|
|
116
132
|
</head>
|
|
117
133
|
<body>
|
|
@@ -160,7 +176,7 @@ let open = false; // the card is showing
|
|
|
160
176
|
let panel = ""; // "", "menu", "report", "confirm", "settings": kept until the user leaves it
|
|
161
177
|
let flash = { text: "", until: 0 };
|
|
162
178
|
let settings = null, settingsErrors = {}, notifyOn = true;
|
|
163
|
-
let lastHtml = "",
|
|
179
|
+
let lastHtml = "", hoverTimer = 0, leaveTimer = 0, pollTimer = 0, kinds = [];
|
|
164
180
|
const api = () => window.pywebview.api;
|
|
165
181
|
|
|
166
182
|
function pill() {
|
|
@@ -168,7 +184,8 @@ function pill() {
|
|
|
168
184
|
if (v.mode === "attention") {
|
|
169
185
|
const a = v.attention;
|
|
170
186
|
return '<div class="pillrow icon-first capsule-drag-region">' + icon(a.login ? "lock" : "shield")
|
|
171
|
-
+
|
|
187
|
+
+ '<button type="button" class="pill-prompt attention-target" data-act="show_browser" title="点击切到下载浏览器" aria-label="打开下载浏览器">'
|
|
188
|
+
+ "<b>" + esc(a.short) + "</b>" + (a.remaining ? "<span>" + esc(a.remaining) + "</span>" : "") + "</button></div>";
|
|
172
189
|
}
|
|
173
190
|
if (v.mode === "done") {
|
|
174
191
|
// "完成 38/40 2 篇失败": papers saved out of all; a check unless nothing was saved.
|
|
@@ -249,16 +266,22 @@ function runningCard() {
|
|
|
249
266
|
|
|
250
267
|
function attentionCard() {
|
|
251
268
|
const a = V.attention;
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
269
|
+
const title = a.short;
|
|
270
|
+
const detail = [a.message, a.remaining ? "剩 " + a.remaining : "",
|
|
271
|
+
a.more ? "另有 " + a.more + " 项" : ""].filter(Boolean).join(" · ");
|
|
272
|
+
let html = '<div class="card-body"><div class="attention-head capsule-drag-region"><b>PaperSearch</b>'
|
|
273
|
+
+ '<button class="iconbtn" data-act="minimize" aria-label="最小化">' + icon("minimize") + '</button>'
|
|
274
|
+
+ '<button class="iconbtn" data-act="close" aria-label="关闭">' + icon("close") + '</button></div>'
|
|
275
|
+
+ '<button type="button" class="prompt attention-target" data-act="show_browser" title="' + esc(detail) + '" aria-label="打开下载浏览器">' + icon(a.login ? "lock" : "alert")
|
|
276
|
+
+ '<div class="attention-copy"><div class="t">' + esc(title) + '</div><div class="s">点击打开浏览器,查看并继续</div></div><span class="attention-arrow" aria-hidden="true">›</span></button>';
|
|
256
277
|
if (panel === "confirm") return html + actionsBlock() + "</div>";
|
|
278
|
+
html += '<div class="actions"><button class="iconbtn" data-act="settings" aria-label="设置">' + icon("gear")
|
|
279
|
+
+ '</button><span class="grow"></span>';
|
|
257
280
|
if (V.actions) {
|
|
258
|
-
html += '<
|
|
259
|
-
+ '<button class="btn" data-act="confirm">终止</button
|
|
281
|
+
html += '<button class="btn" data-act="skip_item">跳过本篇</button>'
|
|
282
|
+
+ '<button class="btn" data-act="confirm">终止</button>';
|
|
260
283
|
}
|
|
261
|
-
return html + "</div>";
|
|
284
|
+
return html + "</div></div>";
|
|
262
285
|
}
|
|
263
286
|
|
|
264
287
|
function doneCard() {
|
|
@@ -284,11 +307,12 @@ function settingsCard() {
|
|
|
284
307
|
+ (settingsErrors.download_dir ? '<div class="err">' + esc(settingsErrors.download_dir) + '</div>' : '') + '</div>';
|
|
285
308
|
for (const f of settings.fields) {
|
|
286
309
|
html += '<div class="row"><span>' + esc(f.label) + '</span><span><input data-field="' + esc(f.name) + '" value="' + esc(f.value)
|
|
287
|
-
+ '" inputmode="numeric"> <span class="dim">' + esc(f.unit) + "</span></span></div>"
|
|
310
|
+
+ '" aria-label="' + esc(f.label) + '" inputmode="numeric"> <span class="dim">' + esc(f.unit) + "</span></span></div>"
|
|
288
311
|
+ (settingsErrors[f.name] ? '<div class="err">' + esc(settingsErrors[f.name]) + "</div>" : "");
|
|
289
312
|
}
|
|
290
313
|
html += '<div class="row"><span>需要处理时发系统通知</span><button class="switch' + (notifyOn ? " on" : "")
|
|
291
|
-
+ '" data-act="notify" aria-label="系统通知"></button></div>'
|
|
314
|
+
+ '" data-act="notify" role="switch" aria-checked="' + notifyOn + '" aria-label="系统通知"></button></div>'
|
|
315
|
+
+ '<div class="err" id="notify-error" role="status"></div>'
|
|
292
316
|
+ (settingsErrors[""] ? '<div class="err">' + esc(settingsErrors[""]) + "</div>" : "")
|
|
293
317
|
+ '<div class="foot"><button class="btn link" style="color:var(--dim)" data-act="defaults">恢复默认</button>'
|
|
294
318
|
+ '<button class="btn primary" data-act="save">保存</button></div></div>';
|
|
@@ -310,11 +334,9 @@ function render(force) {
|
|
|
310
334
|
else html = idleCard();
|
|
311
335
|
const cls = shape + (V.mode === "attention" && panel !== "settings" ? " warn" : "");
|
|
312
336
|
if (html === lastHtml && cls === lastCls) return;
|
|
313
|
-
const fresh = V.mode === "attention" && V.attention.message !== lastPrompt;
|
|
314
|
-
lastPrompt = V.mode === "attention" ? V.attention.message : "";
|
|
315
337
|
const previous = root.getBoundingClientRect();
|
|
316
338
|
root.style.width = ""; root.style.height = "";
|
|
317
|
-
root.className = cls + " capsule-drag-region" + (
|
|
339
|
+
root.className = cls + " capsule-drag-region" + (cls !== lastCls ? " fade" : "");
|
|
318
340
|
root.innerHTML = '<div class="surface">' + html + "</div>";
|
|
319
341
|
lastHtml = html;
|
|
320
342
|
lastCls = cls;
|
|
@@ -357,12 +379,18 @@ async function tick() {
|
|
|
357
379
|
|
|
358
380
|
function say(text) { flash = { text: text, until: Date.now() + 6000 }; render(true); }
|
|
359
381
|
|
|
382
|
+
let inputActivation = Promise.resolve();
|
|
360
383
|
async function act(action, target) {
|
|
361
384
|
const v = V;
|
|
362
385
|
switch (action) {
|
|
363
386
|
case "minimize": open = false; panel = ""; render(true); return api().minimize(); // back as a capsule when restored
|
|
364
387
|
case "close": closing = true; ++fitGeneration; clearInterval(pollTimer); clearTimeout(hoverTimer); clearTimeout(leaveTimer); return api().request_close(); // no call left waiting on a closed page
|
|
365
388
|
case "folder": return api().open_folder();
|
|
389
|
+
case "show_browser": {
|
|
390
|
+
try { await inputActivation; }
|
|
391
|
+
catch (error) { return say("未能激活进度窗口,请重试"); }
|
|
392
|
+
return say(await api().act("show_browser", v.current, v.run_id));
|
|
393
|
+
}
|
|
366
394
|
case "menu": panel = panel === "menu" ? "" : "menu"; return render(true);
|
|
367
395
|
case "report": if (!kinds.length) kinds = await api().issue_kinds(); panel = "report"; return render(true);
|
|
368
396
|
case "issue": panel = ""; return say(await api().report(target.dataset.kind, v.current));
|
|
@@ -374,7 +402,21 @@ async function act(action, target) {
|
|
|
374
402
|
case "settings":
|
|
375
403
|
settings = await api().settings(); notifyOn = settings.notify; settingsErrors = {}; panel = "settings"; open = true; return render(true);
|
|
376
404
|
case "back": panel = ""; return render(true);
|
|
377
|
-
case "notify":
|
|
405
|
+
case "notify": {
|
|
406
|
+
target.disabled = true;
|
|
407
|
+
try {
|
|
408
|
+
const result = await api().set_notifications(!notifyOn);
|
|
409
|
+
if (!result.ok) throw new Error(result.error || "通知设置保存失败");
|
|
410
|
+
notifyOn = result.notify;
|
|
411
|
+
settings.notify = notifyOn;
|
|
412
|
+
target.classList.toggle("on", notifyOn);
|
|
413
|
+
target.setAttribute("aria-checked", String(notifyOn));
|
|
414
|
+
root.querySelector('#notify-error').textContent = "";
|
|
415
|
+
} catch (error) {
|
|
416
|
+
root.querySelector('#notify-error').textContent = error.message || "通知设置保存失败";
|
|
417
|
+
} finally { target.disabled = false; }
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
378
420
|
case "choose_folder": {
|
|
379
421
|
const selected = await api().choose_download_directory();
|
|
380
422
|
if (selected) { settings.download_dir = selected; root.querySelector('#download-dir').value = selected; }
|
|
@@ -400,6 +442,7 @@ async function act(action, target) {
|
|
|
400
442
|
|
|
401
443
|
const interactive = (target) => target.closest('button, input, select, textarea, a, [contenteditable="true"], [role="button"]');
|
|
402
444
|
root.addEventListener("pointerdown", (event) => {
|
|
445
|
+
if (event.button === 0 && api().activate_on_input) inputActivation = api().activate_on_input();
|
|
403
446
|
if (event.button !== 0 || interactive(event.target)) return;
|
|
404
447
|
dragging = true;
|
|
405
448
|
++fitGeneration;
|
|
Binary file
|