papersearch 0.4.5 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.en.md +7 -4
  2. package/README.md +7 -4
  3. package/carsi/paper_search_carsi/adapters/ams/__init__.py +34 -1
  4. package/carsi/paper_search_carsi/adapters/annual_reviews/__init__.py +26 -1
  5. package/carsi/paper_search_carsi/adapters/aps/__init__.py +25 -2
  6. package/carsi/paper_search_carsi/adapters/copernicus/__init__.py +27 -1
  7. package/carsi/paper_search_carsi/adapters/elsevier/__init__.py +19 -1
  8. package/carsi/paper_search_carsi/adapters/ieee/__init__.py +102 -2
  9. package/carsi/paper_search_carsi/adapters/iop/__init__.py +41 -2
  10. package/carsi/paper_search_carsi/adapters/lww/ovid.py +4 -2
  11. package/carsi/paper_search_carsi/adapters/optica/__init__.py +14 -1
  12. package/carsi/paper_search_carsi/adapters/oup/__init__.py +105 -94
  13. package/carsi/paper_search_carsi/adapters/platforms/atypon/__init__.py +26 -12
  14. package/carsi/paper_search_carsi/adapters/platforms/figshare/__init__.py +20 -11
  15. package/carsi/paper_search_carsi/adapters/platforms/silverchair/__init__.py +1 -1
  16. package/carsi/paper_search_carsi/adapters/plos/__init__.py +31 -1
  17. package/carsi/paper_search_carsi/adapters/thieme/__init__.py +25 -2
  18. package/carsi/paper_search_carsi/assets/capsule.html +45 -19
  19. package/carsi/paper_search_carsi/assets/papersearch-notifier +0 -0
  20. package/carsi/paper_search_carsi/assets/quiet-browser/api.js +119 -0
  21. package/carsi/paper_search_carsi/assets/quiet-browser/manifest.json +24 -0
  22. package/carsi/paper_search_carsi/assets/quiet-browser/schema.json +1 -0
  23. package/carsi/paper_search_carsi/browser/backend.py +36 -0
  24. package/carsi/paper_search_carsi/browser/background.py +68 -0
  25. package/carsi/paper_search_carsi/browser/challenge_interaction.py +35 -0
  26. package/carsi/paper_search_carsi/browser/challenges.py +10 -0
  27. package/carsi/paper_search_carsi/browser/foreground.py +201 -0
  28. package/carsi/paper_search_carsi/browser/login.py +3 -1
  29. package/carsi/paper_search_carsi/browser/preview.py +3 -1
  30. package/carsi/paper_search_carsi/config.py +4 -1
  31. package/carsi/paper_search_carsi/engine/batch.py +62 -20
  32. package/carsi/paper_search_carsi/engine/batch_capture.py +54 -19
  33. package/carsi/paper_search_carsi/engine/batch_common.py +29 -2
  34. package/carsi/paper_search_carsi/engine/batch_diagnostics.py +10 -0
  35. package/carsi/paper_search_carsi/engine/batch_institution.py +56 -14
  36. package/carsi/paper_search_carsi/engine/batch_login.py +254 -198
  37. package/carsi/paper_search_carsi/engine/batch_user.py +67 -2
  38. package/carsi/paper_search_carsi/engine/batch_waits.py +65 -30
  39. package/carsi/paper_search_carsi/engine/login_wait.py +125 -0
  40. package/carsi/paper_search_carsi/engine/page_activity.py +163 -0
  41. package/carsi/paper_search_carsi/engine/supplements.py +12 -1
  42. package/carsi/paper_search_carsi/entitlements.py +23 -3
  43. package/carsi/paper_search_carsi/progress_capsule.py +130 -18
  44. package/carsi/paper_search_carsi/progress_macos.py +166 -0
  45. package/carsi/paper_search_carsi/progress_reporter.py +22 -1
  46. package/carsi/paper_search_carsi/progress_view.py +1 -0
  47. package/carsi/paper_search_carsi/publishers/profiles.py +5 -3
  48. package/carsi/paper_search_carsi/server.py +17 -1
  49. package/carsi/paper_search_carsi/user_settings.py +4 -4
  50. package/carsi/pyproject.toml +1 -1
  51. package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.js +2 -2
  52. package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.js.map +1 -1
  53. package/dist/capabilities/pdf-discovery/batch.d.ts.map +1 -1
  54. package/dist/capabilities/pdf-discovery/batch.js +28 -4
  55. package/dist/capabilities/pdf-discovery/batch.js.map +1 -1
  56. package/dist/capabilities/pdf-discovery/carsi/CarsiMcpClient.js +1 -1
  57. package/dist/capabilities/pdf-discovery/tiers/entitledAccess.d.ts +2 -6
  58. package/dist/capabilities/pdf-discovery/tiers/entitledAccess.d.ts.map +1 -1
  59. package/dist/capabilities/pdf-discovery/tiers/entitledAccess.js +1 -0
  60. package/dist/capabilities/pdf-discovery/tiers/entitledAccess.js.map +1 -1
  61. package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
  62. package/dist/infrastructure/runlog/failureClass.js +3 -2
  63. package/dist/infrastructure/runlog/failureClass.js.map +1 -1
  64. package/dist/management/carsi/installer.d.ts +2 -1
  65. package/dist/management/carsi/installer.d.ts.map +1 -1
  66. package/dist/management/carsi/installer.js +24 -1
  67. package/dist/management/carsi/installer.js.map +1 -1
  68. package/package.json +1 -1
  69. package/skills/paper-search/references/browser-download.md +11 -7
  70. package/skills/paper-search/references/carsi-setup.md +1 -0
  71. package/skills/paper-search/references/publisher-support.md +42 -41
package/README.en.md CHANGED
@@ -151,11 +151,14 @@ paper-search carsi status --format text
151
151
 
152
152
  - Installing asks for your school (a CARSI member school, by Chinese name, English name or domain) and downloads the dedicated Camoufox browser, about 3 GB in all; on macOS, `--browser ego` uses ego lite instead, about 0.5 GB. `--skip-school` leaves the school for later.
153
153
  - Schools sign in through CARSI (the Chinese university identity federation). When a publisher's institution list has no CARSI or no entry for your school, the program says so at once.
154
- - Automatic verification: verification checkboxes are located and clicked automatically, and downloads resume when the site grants access. Each verification wait allows up to three attempts, at least three seconds apart. If verification remains unresolved after the automatic phase, the progress window prompts for manual action.
155
- - Downloads show a small progress capsule in a corner of the screen: progress, whether the main text or the supplementary files are being fetched, and the publisher; it turns amber and raises a system notification when you need to sign in or complete a verification. Hover to open it: skip this paper, mark the journal or publisher as no access, stop the whole task, report a problem, change wait times and the default download folder (the gear at the top right), or minimize it (–). Drag the pill or a non-control area of the expanded card to move it. On the school's login page a paper waits up to 3 minutes by default; anywhere else (human checks, publisher pages, ...) it ends after 1 minute.
156
- - The default download browser keeps running in the background without requesting foreground focus on startup or navigation. The capsule alerts you when intervention is needed; switch to the browser when ready. A completed check with no listed supplementary files is not a failure. Incomplete sign-in, unsupported discovery, and download failures remain distinct results.
154
+ - Automatic verification: verification checkboxes are located and clicked automatically, and downloads resume when the site grants access. Each verification wait allows up to three attempts, at least three seconds apart. A click or a checked box alone does not prove that verification has passed.
155
+ - Downloads show a small progress capsule in a corner of the screen: progress, whether the main text or the supplementary files are being fetched, and the publisher; it turns amber with a gentle breathing glow and sends a system notification, if enabled, when you need to sign in or complete a verification. Click the reminder to switch to the current task’s download browser. Hover to open it: skip this paper, mark the journal or publisher as no access, stop the whole task, report a problem, change wait times and the default download folder (the gear at the top right), or minimize it (–). Drag the pill or a non-control area of the expanded card to move it. On the school's login page a paper waits up to 3 minutes by default; anywhere else (human checks, publisher pages, ...) it ends after 1 minute.
156
+ - The default download browser keeps running in the background without requesting foreground focus on startup, clicks, or navigation. It does not automatically minimize or hide its window. The capsule alerts you when intervention is needed; click the reminder to switch to the browser when ready. A completed check with no listed supplementary files is not a failure. Incomplete sign-in, unsupported discovery, and download failures remain distinct results.
157
157
  - Choose or type the default download folder in capsule settings, or run `paper-search config set DEFAULT_DOWNLOAD_PATH "/absolute/path/papers"`. New tasks use the saved folder; `--save-path` or `savePath` overrides it for one task. A running batch keeps its original folder.
158
- - Which publishers' main texts and supplementary files it can fetch is in the [publisher support table](skills/paper-search/references/publisher-support.md) (Chinese). Both have been fetched from Elsevier, Wiley, Springer Nature, OUP, Wolters Kluwer, Taylor & Francis, Sage, ACS, NEJM, ASCE, Dove and others; supplementary files from MDPI and Frontiers and Figshare files linked to a paper are also supported; IEEE, Thieme and others give the main text only; sites not in the table are tried with the shared rules.
158
+ - Current source (not yet released): capsule settings include “页面持续无进展” (page inactivity), defaulting to 30 seconds, adjustable from 1 to 600 seconds, with a restore-default action. School sign-in prompts appear immediately. Other pages prompt with an amber breathing glow only after making no progress for the selected interval. Automatic passage stays quiet, resumed progress clears the reminder, and active main-document navigation stays quiet within the existing page timeout. Receiving file data does not count as a stalled page. This setting changes the reminder delay without extending page timeouts.
159
+ - Current source (not yet released): typing, selecting or clicking a control in the dedicated sign-in page, or taking over through the capsule, pauses the remaining sign-in budget, including pauses between inputs. The timer resumes after leaving the manual sign-in step; an untouched sign-in still times out.
160
+ - Current source (not yet released): macOS notifications use PaperSearch’s name and icon. Notification clicks share the capsule reminder’s action for restoring the current task’s browser. The initial extension setup offers a notification choice; new configurations default to off, and upgrades preserve existing preferences. The System notifications switch in the capsule’s settings saves immediately. Turning it off keeps the amber reminder. No separate notification tool is required; enabled notifications still follow macOS notification permissions and Focus settings.
161
+ - Which publishers' main texts and supplementary files it can fetch is in the [publisher support table](skills/paper-search/references/publisher-support.md) (Chinese). Both have been fetched from Elsevier, Wiley, Springer Nature, OUP, Wolters Kluwer, Taylor & Francis, Sage, ACS, NEJM, ASCE, Dove and others; supplementary files from ASH, Thieme, PLOS, Copernicus, Annual Reviews, IOP, AMS, APS, Optica, IEEE, World Scientific, MDPI and Frontiers, as well as Figshare files linked to a paper, have also been fetched; remaining attachment routes are still being completed; sites not in the table are tried with the shared rules.
159
162
  - `paper-search carsi update` updates the extension after a PaperSearch upgrade; `paper-search carsi uninstall` removes it (keeping the browser and the school settings by default).
160
163
  - Windows: if PowerShell blocks `npm.ps1`, use `npm.cmd` or Command Prompt; downloads must run in a desktop session, as a browser window cannot open from SSH or a system service.
161
164
 
package/README.md CHANGED
@@ -151,11 +151,14 @@ paper-search carsi status --format text
151
151
 
152
152
  - 安装时会问你的学校(CARSI 成员学校,中文名、英文名或域名都可以),并下载专用浏览器 Camoufox,共约 3 GB;macOS 上 `--browser ego` 改用 ego lite,约 0.5 GB。`--skip-school` 可以以后再选学校。
153
153
  - 目前用 CARSI(中国高校身份联盟)登录学校;出版社的机构列表里没有 CARSI 或你的学校时,程序会立即说明。
154
- - 自动过验证:程序自动定位并点击验证框,网站放行后继续下载。每次验证等待最多尝试 3 次,两次至少间隔 3 秒;自动阶段结束后仍未放行时,进度窗口会提示人工接管。
155
- - 下载时屏幕角落会出现进度胶囊:显示进度、正在下正文还是附录、哪家出版社;需要你登录或验证时变成琥珀色并发系统通知。鼠标指上去展开,可以跳过本篇、标记本刊或出版社无权限、终止整个任务、报告问题,右上角齿轮调整等待时间和默认下载文件夹,“–”最小化;按住胶囊或展开卡片的非按钮区域可拖动。停在学校登录页默认最多等 3 分钟,停在其他页面(人机验证、出版社页面等)默认 1 分钟后结束这一篇。
156
- - 默认下载浏览器在后台继续运行,启动和跳转时不主动抢前台;需要登录或验证时由胶囊提示,你再切换到浏览器处理。完成检查但页面未列出附件会显示“已检查,页面未列出补充材料”,不计为失败;登录未完成、暂不支持发现附件或下载失败会分别说明。
154
+ - 自动过验证:程序自动定位并点击验证框,网站放行后继续下载。每次验证等待最多尝试 3 次,两次至少间隔 3 秒;点击或勾选本身不代表验证已经通过。
155
+ - 下载时屏幕角落会出现进度胶囊:显示进度、正在下正文还是附录、哪家出版社;需要你登录或验证时变成琥珀色,背景与边缘轻柔呼吸,并在开启系统通知时发送通知;点击“请登录学校”等提醒可切到当前任务的下载浏览器。鼠标指上去展开,可以跳过本篇、标记本刊或出版社无权限、终止整个任务、报告问题,右上角齿轮调整等待时间和默认下载文件夹,“–”最小化;按住胶囊或展开卡片的非按钮区域可拖动。停在学校登录页默认最多等 3 分钟,停在其他页面(人机验证、出版社页面等)默认 1 分钟后结束这一篇。
156
+ - 默认下载浏览器在后台继续运行,启动、点击和跳转时不主动抢前台,也不会自动最小化或隐藏窗口;需要登录或验证时由胶囊提示,点击提醒即可切到浏览器处理。完成检查但页面未列出附件会显示“已检查,页面未列出补充材料”,不计为失败;登录未完成、暂不支持发现附件或下载失败会分别说明。
157
157
  - 默认下载文件夹可在胶囊设置中选择或输入,也可运行 `paper-search config set DEFAULT_DOWNLOAD_PATH "/完整路径/论文"`。保存后用于新任务;`--save-path` 或 `savePath` 可为单次任务指定其他目录,正在运行的批次保持原目录。
158
- - 能取哪些出版社的正文和补充材料,见 [出版社支持表](skills/paper-search/references/publisher-support.md)。正文和补充材料都实测取得的有 Elsevier、Wiley、Springer Nature、OUP、Wolters Kluwer、Taylor & Francis、Sage、ACS、NEJM、ASCE、Dove 等,另支持 MDPI、Frontiers 的补充材料和论文关联的 Figshare 附件;IEEE、Thieme 等目前只取正文;表里没有的网站按通用规则尝试。
158
+ - 当前源码(待发布):胶囊齿轮新增“页面持续无进展”,默认 30 秒,可保存为 1–600 秒,并可恢复默认。学校账号登录立即提醒;其他页面持续无进展达到设定时间后,胶囊才变色呼吸、提示查看浏览器。自动通过保持安静,恢复进展后清除提醒;主页面仍在导航加载时,在原页面等待上限内暂不提醒;持续接收文件也不会被当作页面卡住。该设置只改变提醒时间,不延长页面等待上限。
159
+ - 当前源码(待发布):机构登录中,你在专用登录页输入、选择或点击控件,或点击胶囊接管后,暂停登录等待倒计时;输入间的停顿不消耗剩余时间。离开人工登录步骤后继续计时;无人操作仍按原限时结束。
160
+ - 当前源码(待发布):macOS 通知改用 PaperSearch 自己的名称和图标,点击通知与点击胶囊提醒共用当前任务的浏览器恢复入口。首次配置机构下载扩展时可选择是否开启系统通知,新配置默认关闭;胶囊齿轮里的“系统通知”开关点击即保存,已有选择在升级后保留。关闭通知仍保留琥珀色呼吸提醒。无需另外安装通知工具;开启后横幅显示仍遵循 macOS 通知权限与专注模式设置。
161
+ - 能取哪些出版社的正文和补充材料,见 [出版社支持表](skills/paper-search/references/publisher-support.md)。正文和补充材料都实测取得的有 Elsevier、Wiley、Springer Nature、OUP、Wolters Kluwer、Taylor & Francis、Sage、ACS、NEJM、ASCE、Dove 等,另已实测取得 ASH、Thieme、PLOS、Copernicus、Annual Reviews、IOP、AMS、APS、Optica、IEEE、World Scientific、MDPI、Frontiers 的补充材料及论文关联的 Figshare 附件;尚未取得的附件入口仍在补全;表里没有的网站按通用规则尝试。
159
162
  - `paper-search carsi update` 在 PaperSearch 升级后更新扩展,`paper-search carsi uninstall` 卸载(默认保留浏览器和学校配置)。
160
163
  - Windows:PowerShell 拦住 `npm.ps1` 时改用 `npm.cmd` 或命令提示符;下载要在桌面会话里运行,经 SSH 或系统服务启动时浏览器窗口打不开。
161
164
 
@@ -4,14 +4,47 @@ The PDF of an article page ``/view/<path>.xml`` is ``/downloadpdf/view/<path>.pd
4
4
  """
5
5
  from __future__ import annotations
6
6
 
7
+ import re
8
+ from typing import Any
9
+ from urllib.parse import unquote, urlparse
10
+
7
11
  from ...engine.router import _append_ams_candidates
8
- from ..base import PublisherAdapter, register
12
+ from ..base import PublisherAdapter, SupplementLink, register
13
+
14
+ _SUPPLEMENT_ROWS_JS = """() => [...document.querySelectorAll('a[href]')].map(a => ({
15
+ href: a.href, label: (a.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 240)
16
+ }))"""
17
+
18
+
19
+ def supplement_links_from_rows(rows: list[dict], doi: str) -> list[SupplementLink]:
20
+ """Only files listed under this article's own supplemental XML directory."""
21
+ if not doi.lower().startswith("10.1175/"):
22
+ return []
23
+ article = re.escape(doi.split("/", 1)[1])
24
+ links: list[SupplementLink] = []
25
+ seen: set[str] = set()
26
+ for row in rows:
27
+ target = urlparse(str(row.get("href") or ""))
28
+ if (target.scheme != "https" or target.netloc != "journals.ametsoc.org"
29
+ or not re.fullmatch(r"/supplemental/+journals/[^/]+/\d+/\d+/" + article
30
+ + r"\.xml/[^/]+", unquote(target.path), re.I)):
31
+ continue
32
+ url = target._replace(fragment="").geturl()
33
+ # In-text and end-of-article links differ by a duplicate slash.
34
+ identity = re.sub(r"/+", "/", unquote(target.path))
35
+ if identity not in seen:
36
+ seen.add(identity)
37
+ links.append(SupplementLink(url, str(row.get("label") or "")))
38
+ return links
9
39
 
10
40
 
11
41
  @register
12
42
  class AMSAdapter(PublisherAdapter):
13
43
  publisher = "ams"
14
44
 
45
+ def supplement_links(self, page: Any, doi: str) -> list[SupplementLink]:
46
+ return supplement_links_from_rows(page.evaluate(_SUPPLEMENT_ROWS_JS), doi)
47
+
15
48
  @classmethod
16
49
  def profile_pdf_candidates(cls, doi: str, source_url: str) -> list[str]:
17
50
  urls: list[str] = []
@@ -12,11 +12,33 @@ over in silence.
12
12
  from __future__ import annotations
13
13
 
14
14
  import json
15
+ import re
15
16
  from typing import Any
16
17
  from urllib.parse import parse_qs, urlencode, urlparse
17
18
 
18
19
  from ...engine.batch_common import _is_browser_error, open_page, pump_until
19
- from ..base import PublisherAdapter, register
20
+ from ..base import PublisherAdapter, SupplementLink, register
21
+
22
+ _SUPPLEMENT_ROWS_JS = """() => [...document.querySelectorAll('a[href]')].map(a => ({
23
+ href: a.href, label: (a.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 240)
24
+ }))"""
25
+
26
+
27
+ def supplement_links_from_rows(rows: list[dict], doi: str) -> list[SupplementLink]:
28
+ """Annual Reviews' current delivery links bind the file via itemId."""
29
+ links: list[SupplementLink] = []
30
+ seen: set[str] = set()
31
+ for row in rows:
32
+ target = urlparse(str(row.get("href") or ""))
33
+ ids = parse_qs(target.query).get("itemId", [])
34
+ if (target.scheme != "https" or target.netloc not in {"www.annualreviews.org", "annualreviews.org"}
35
+ or not target.path.startswith("/deliver/fulltext/") or len(ids) != 1
36
+ or not re.fullmatch(r"/content/suppdata/" + re.escape(doi) + r"/\d+", ids[0], re.I)):
37
+ continue
38
+ if ids[0].lower() not in seen:
39
+ seen.add(ids[0].lower())
40
+ links.append(SupplementLink(target._replace(fragment="").geturl(), str(row.get("label") or "")))
41
+ return links
20
42
 
21
43
  _OPENATHENS_BOX = ("xpath=(//*[contains(normalize-space(.), 'Option 2: Sign-in with OpenAthens')]"
22
44
  "/following::input[contains(@placeholder, 'organization')])[1]")
@@ -86,6 +108,9 @@ def _error(exc: Exception) -> str:
86
108
  class AnnualReviewsAdapter(PublisherAdapter):
87
109
  publisher = "annual reviews"
88
110
 
111
+ def supplement_links(self, page: Any, doi: str) -> list[SupplementLink]:
112
+ return supplement_links_from_rows(page.evaluate(_SUPPLEMENT_ROWS_JS), doi)
113
+
89
114
  def openathens_entry(self, page: Any, result: Any) -> bool | None:
90
115
  """From the Shibboleth page, its OpenAthens page with the school as the
91
116
  search; on the OpenAthens page nothing more (the school is chosen there)."""
@@ -10,12 +10,32 @@ ends on another APS page goes back to this record's article.
10
10
  from __future__ import annotations
11
11
 
12
12
  import json
13
+ import re
13
14
  from typing import Any
14
- from urllib.parse import urlparse
15
+ from urllib.parse import unquote, urlparse
15
16
 
16
17
  from ...engine.router import _append_aps_candidates
17
18
  from ...engine.batch_common import open_page
18
- from ..base import PublisherAdapter, register
19
+ from ..base import PublisherAdapter, SupplementLink, register
20
+
21
+ _SUPPLEMENT_ROWS_JS = """() => [...document.querySelectorAll('a[href]')].map(a => ({
22
+ href: a.href, label: (a.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 240)
23
+ }))"""
24
+
25
+
26
+ def supplement_links_from_rows(rows: list[dict], doi: str) -> list[SupplementLink]:
27
+ links: list[SupplementLink] = []
28
+ seen: set[str] = set()
29
+ for row in rows:
30
+ target = urlparse(str(row.get("href") or ""))
31
+ path = unquote(target.path).lower()
32
+ url = target._replace(fragment="").geturl()
33
+ if (target.scheme == "https" and target.netloc == "journals.aps.org"
34
+ and re.fullmatch(r"/[a-z]+/supplemental/" + re.escape(doi.lower()) + r"/[^/]+", path)
35
+ and url not in seen):
36
+ seen.add(url)
37
+ links.append(SupplementLink(url, str(row.get("label") or "")))
38
+ return links
19
39
 
20
40
 
21
41
  # APS resolves article pages per journal code; the DOI suffix carries the journal.
@@ -48,6 +68,9 @@ class APSAdapter(PublisherAdapter):
48
68
  publisher = "aps"
49
69
  returns_to_record_article = True
50
70
 
71
+ def supplement_links(self, page: Any, doi: str) -> list[SupplementLink]:
72
+ return supplement_links_from_rows(page.evaluate(_SUPPLEMENT_ROWS_JS), doi)
73
+
51
74
  def article_url(self, doi: str) -> str | None:
52
75
  return aps_article_url(doi) or None
53
76
 
@@ -6,16 +6,42 @@ The PDF path is derived from the DOI
6
6
  from __future__ import annotations
7
7
 
8
8
  import re
9
+ from typing import Any
9
10
  from urllib.parse import unquote, urlparse
10
11
 
11
12
  from ...engine.router import _append_copernicus_candidates
12
- 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
+ article = re.fullmatch(r"10\.5194/([a-z0-9]+)-(\d+)-(\d+)-(\d{4})", doi, re.I)
22
+ if not article:
23
+ return []
24
+ journal, volume, first_page, year = article.groups()
25
+ stem = doi.split("/", 1)[1].lower()
26
+ expected = f"/articles/{volume}/{first_page}/{year}/{stem}-supplement.pdf"
27
+ links: list[SupplementLink] = []
28
+ seen: set[str] = set()
29
+ for row in rows:
30
+ target = urlparse(str(row.get("href") or ""))
31
+ if (target.scheme == "https" and target.netloc.lower() == f"{journal.lower()}.copernicus.org"
32
+ and unquote(target.path).lower() == expected and expected not in seen):
33
+ seen.add(expected)
34
+ links.append(SupplementLink(target._replace(fragment="").geturl(), str(row.get("label") or "")))
35
+ return links
13
36
 
14
37
 
15
38
  @register
16
39
  class CopernicusAdapter(PublisherAdapter):
17
40
  publisher = "copernicus"
18
41
 
42
+ def supplement_links(self, page: Any, doi: str) -> list[SupplementLink]:
43
+ return supplement_links_from_rows(page.evaluate(_SUPPLEMENT_ROWS_JS), doi)
44
+
19
45
  @classmethod
20
46
  def profile_pdf_candidate_url(cls, url: str) -> bool:
21
47
  target = urlparse(url)
@@ -17,7 +17,7 @@ from __future__ import annotations
17
17
  import json
18
18
  import re
19
19
  from typing import Any
20
- from urllib.parse import urlparse
20
+ from urllib.parse import quote, urlparse
21
21
 
22
22
  from ...engine.router import elsevier_journal_article, extract_elsevier_pii
23
23
  from ..base import PublisherAdapter, SupplementLink, register
@@ -28,6 +28,8 @@ from .sciencedirect import ScienceDirectSite
28
28
  # ClinicalKey (clinicalkey.com, .fr, .es, .com.au, ...): EMC titles are served
29
29
  # only there, a separate subscription with its own sign-in and reader.
30
30
  _CLINICALKEY = re.compile(r"(?:www\.)?clinicalkey\.[a-z]{2,3}(?:\.[a-z]{2})?")
31
+ _ASH_DOI = re.compile(r"10\.1182/(?:blood|bloodadvances)\.[^/?#\s]+", re.I)
32
+ _ASH_HOSTS = frozenset({"ashpublications.org", "www.ashpublications.org"})
31
33
 
32
34
 
33
35
  # Every file link on the page with the text around it (the item's caption).
@@ -181,6 +183,14 @@ class ElsevierAdapter(PublisherAdapter):
181
183
  def login_url(self) -> str | None:
182
184
  return "https://www.sciencedirect.com/"
183
185
 
186
+ def article_url(self, doi: str) -> str | None:
187
+ # ASH's society site points its institution entry to this same-DOI
188
+ # Linking Hub route. Use the publishing partner's existing flow rather
189
+ # than treating that explicit cross-site entry as a missing login.
190
+ if _ASH_DOI.fullmatch(doi):
191
+ return "https://linkinghub.elsevier.com/retrieve/doi/" + quote(doi, safe="/")
192
+ return None
193
+
184
194
  def open_institution_entry(self, page: Any, result: Any) -> bool | None:
185
195
  clicked = self.click_institution_entry(page, result)
186
196
  if self.d.config.get("publisher_institution_federation") == "carsi":
@@ -252,6 +262,11 @@ class ElsevierAdapter(PublisherAdapter):
252
262
  Gastroenterology) show only the abstract there, so the DOI's landing page follows."""
253
263
  from .journal_site import _get_elsevier_pii
254
264
 
265
+ if _ASH_DOI.fullmatch(doi):
266
+ # ASH keeps supplementary content on the original journal page.
267
+ # A ScienceDirect detour spends the same discovery budget on an
268
+ # extra verification without supplying these Silverchair files.
269
+ return [f"https://doi.org/{doi}"]
255
270
  pii = _get_elsevier_pii(doi)
256
271
  first = [f"https://www.sciencedirect.com/science/article/pii/{pii}"] if pii else []
257
272
  return first + [f"https://doi.org/{doi}"]
@@ -297,6 +312,9 @@ class ElsevierAdapter(PublisherAdapter):
297
312
  return bool(expected) and here != expected
298
313
 
299
314
  def supplement_links(self, page: Any, doi: str) -> list[SupplementLink] | None:
315
+ if (urlparse(str(page.url)).hostname or "").lower() in _ASH_HOSTS and _ASH_DOI.fullmatch(doi):
316
+ from ..platforms.silverchair import supplement_links
317
+ return supplement_links(page, doi, _ASH_HOSTS)
300
318
  if sciencedirect.is_page(str(page.url)):
301
319
  self.sciencedirect.wait_for_full_text(page)
302
320
  return supplement_links_from_rows(page.evaluate(_SUPPLEMENT_ROWS_JS), str(page.url), doi)
@@ -11,12 +11,72 @@ publisher route.
11
11
  from __future__ import annotations
12
12
 
13
13
  import json
14
+ import re
14
15
  from typing import Any
15
- from urllib.parse import urlparse
16
+ from urllib.parse import urljoin, urlparse
16
17
 
17
18
  from ...engine.batch_common import pump_until, settle
18
19
  from ...engine.router import extract_ieee_article_number
19
- from ..base import PublisherAdapter, register
20
+ from ..base import PublisherAdapter, SupplementLink, register
21
+
22
+ _SUPPLEMENTS_JS = r"""() => {
23
+ let metadata = window.xplGlobal?.document?.metadata;
24
+ // Camoufox's isolated evaluation world may not expose page globals. Read
25
+ // the same JSON declaration from the DOM without executing website code.
26
+ if (!metadata) {
27
+ for (const script of document.scripts) {
28
+ const text = script.textContent || '';
29
+ if (text.length > 1048576) continue;
30
+ const match = text.match(/xplGlobal\.document\.metadata\s*=\s*(\{[\s\S]*?\})\s*;/);
31
+ if (!match) continue;
32
+ try { metadata = JSON.parse(match[1]); }
33
+ catch (error) { if (!(error instanceof SyntaxError)) throw error; }
34
+ break;
35
+ }
36
+ }
37
+ return {
38
+ article: metadata?.articleNumber,
39
+ doi: metadata?.doi,
40
+ multimedia: metadata?.sections?.multimedia,
41
+ tabs: [...document.querySelectorAll('a.document-tab-link[href]')].map(a => a.href),
42
+ dois: [...document.querySelectorAll('a.multimedia-doi[href]')].map(a => a.href),
43
+ rows: [...document.querySelectorAll('.media-item a[href]')].map(a => ({
44
+ href:a.href, label:(a.textContent || '').trim().slice(0,240)
45
+ }))
46
+ };
47
+ }"""
48
+
49
+
50
+ def supplement_links_from_page(data: dict, page_url: str, doi: str) -> list[SupplementLink] | None:
51
+ current = urlparse(page_url)
52
+ main_article = re.fullmatch(r"/document/(\d+)/?", current.path)
53
+ if (current.scheme == "https" and current.netloc == "ieeexplore.ieee.org" and main_article
54
+ and str(data.get("article") or "") == main_article[1]
55
+ and str(data.get("doi") or "").casefold() == doi.casefold()
56
+ and (data.get("multimedia") is False or data.get("multimedia") == "false")
57
+ and not data.get("rows") and not data.get("dois")
58
+ and not any(urlparse(urljoin(page_url, str(tab))).path.rstrip("/")
59
+ == f"/document/{main_article[1]}/media" for tab in data.get("tabs", []))):
60
+ # IEEE explicitly declares the sections of this identified article.
61
+ # Missing tabs or an unfinished app shell alone are not empty evidence.
62
+ return []
63
+ article = re.fullmatch(r"/document/(\d+)/media/?", current.path)
64
+ if (current.scheme != "https" or current.netloc != "ieeexplore.ieee.org" or not article
65
+ or not any(re.fullmatch(r"https://doi\.org/" + re.escape(doi) + r"/mm\d+", url, re.I)
66
+ for url in data.get("dois", []))):
67
+ return None
68
+ links: list[SupplementLink] = []
69
+ seen: set[str] = set()
70
+ for row in data.get("rows", []):
71
+ target = urlparse(str(row.get("href") or ""))
72
+ if (target.scheme != "https" or target.netloc != current.netloc
73
+ or not re.fullmatch(r"/ielx\d+/\d+/\d+/" + article[1] + r"/[^/]+", target.path)):
74
+ continue
75
+ url = target._replace(fragment="").geturl()
76
+ if url not in seen:
77
+ seen.add(url)
78
+ links.append(SupplementLink(url, str(row.get("label") or "")))
79
+ return links
20
80
 
21
81
  _SEARCH = "input.inst-typeahead-input"
22
82
  # Text on an article page that offers the institution login.
@@ -74,6 +134,40 @@ _SEARCH_INPUTS = (
74
134
  class IEEEAdapter(PublisherAdapter):
75
135
  publisher = "ieee"
76
136
 
137
+ def is_article_page_url(self, url: str) -> bool:
138
+ parsed = urlparse(url)
139
+ return (parsed.scheme == "https" and parsed.netloc == "ieeexplore.ieee.org"
140
+ and re.fullmatch(r"/document/\d+/?", parsed.path) is not None)
141
+
142
+ def supplement_links(self, page: Any, doi: str) -> list[SupplementLink] | None:
143
+ """Open the article's observed Supplemental Items tab before discovery."""
144
+ current = urlparse(str(page.url))
145
+ article = re.fullmatch(r"/document/(\d+)/?", current.path)
146
+ if current.scheme == "https" and current.netloc == "ieeexplore.ieee.org" and article:
147
+ for control in page.locator('a.document-tab-link[href]').all():
148
+ href = urljoin(str(page.url), control.get_attribute('href') or '')
149
+ target = urlparse(href)
150
+ if (target.scheme == "https" and target.netloc == current.netloc
151
+ and target.path == f"/document/{article[1]}/media"):
152
+ # This is a client-side document tab; a fresh navigation can
153
+ # return a blank shell instead of rendering its media panel.
154
+ # Native activation reaches the same client-side router
155
+ # without waiting for animation-frame stability in a
156
+ # background tab. Never activate a hidden/disabled tab.
157
+ activated = control.evaluate("""el => {
158
+ if (!el.getClientRects().length || getComputedStyle(el).visibility !== 'visible'
159
+ || el.getAttribute('aria-disabled') === 'true') return false;
160
+ el.click(); return true;
161
+ }""", timeout=5_000)
162
+ if not activated:
163
+ continue
164
+ pump_until(page, lambda: page.evaluate("""doi =>
165
+ [...document.querySelectorAll('a[href]')].some(a =>
166
+ a.href.toLowerCase().startsWith('https://doi.org/' + doi.toLowerCase() + '/mm'))
167
+ """, doi), 15_000)
168
+ break
169
+ return supplement_links_from_page(page.evaluate(_SUPPLEMENTS_JS), str(page.url), doi)
170
+
77
171
  def login_url(self) -> str | None:
78
172
  return "https://ieeexplore.ieee.org/"
79
173
 
@@ -98,6 +192,12 @@ class IEEEAdapter(PublisherAdapter):
98
192
  search = page.locator(_SEARCH).first
99
193
  if search.is_visible():
100
194
  return False # the modal is open: the school is chosen there
195
+ for dialog in page.get_by_role("dialog").filter(
196
+ has_text=re.compile(r"institutional sign in|access through", re.I)).all():
197
+ if dialog.is_visible():
198
+ # PDF can open this modal before the login flow starts. It may
199
+ # show only a remembered school, with no search input yet.
200
+ return False
101
201
  entry = page.locator("a.inst-sign-in").first
102
202
  if not entry.is_visible():
103
203
  return None
@@ -7,16 +7,55 @@ sign-in (``myiopscience.iop.org/signin``) with the article as its target.
7
7
  from __future__ import annotations
8
8
 
9
9
  from typing import Any
10
- from urllib.parse import urlencode, urlparse
10
+ from urllib.parse import unquote, urlencode, urlparse
11
11
 
12
12
  from ...engine.batch_common import open_page
13
- from ..base import PublisherAdapter, register
13
+ from ..base import PublisherAdapter, SupplementLink, register
14
+
15
+ _SUPPLEMENT_ROWS_JS = """() => ({
16
+ doi: document.querySelector('meta[name="citation_doi"]')?.content || '',
17
+ rows: [...document.querySelectorAll('a[href]')].map(a => ({
18
+ href: a.href, label: (a.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 240)
19
+ }))
20
+ })"""
21
+
22
+
23
+ def supplement_links_from_page(data: dict, page_url: str, doi: str) -> list[SupplementLink] | None:
24
+ """Files declared by this article's dedicated supplementary-data page.
25
+
26
+ IOP's current file host uses signed URLs without a full DOI in the path.
27
+ Bind the list to the article page and keep the signature for the transfer.
28
+ """
29
+ page = urlparse(page_url)
30
+ citation = str(data.get("doi") or "").lower().removeprefix("https://doi.org/")
31
+ if (page.scheme != "https" or page.netloc != "iopscience.iop.org"
32
+ or unquote(page.path).rstrip("/").lower() != f"/article/{doi.lower()}/data"
33
+ or citation != doi.lower()):
34
+ return None
35
+ links: list[SupplementLink] = []
36
+ seen: set[str] = set()
37
+ for row in data.get("rows", []):
38
+ target = urlparse(str(row.get("href") or ""))
39
+ label = str(row.get("label") or "")
40
+ if (target.scheme == "https"
41
+ and target.netloc == "cfn-live-content-bucket-iop-org.s3.eu-west-1.amazonaws.com"
42
+ and target.path.startswith("/journals/")
43
+ and "supplement" in label.lower() and target.path not in seen):
44
+ seen.add(target.path)
45
+ links.append(SupplementLink(target._replace(fragment="").geturl(), label))
46
+ return links
14
47
 
15
48
 
16
49
  @register
17
50
  class IOPAdapter(PublisherAdapter):
18
51
  publisher = "iop"
19
52
 
53
+ def supplements_page_urls(self, doi: str) -> list[str]:
54
+ return [f"https://iopscience.iop.org/article/{doi}/data"]
55
+
56
+ def supplement_links(self, page: Any, doi: str) -> list[SupplementLink] | None:
57
+ return supplement_links_from_page(page.evaluate(_SUPPLEMENT_ROWS_JS), str(page.url), doi)
58
+
20
59
  def open_institution_entry(self, page: Any, result: Any) -> bool | None:
21
60
  current_url = str(getattr(page, "url", "") or "")
22
61
  host = (urlparse(current_url).hostname or "").lower()
@@ -65,8 +65,10 @@ class OvidSite:
65
65
  wall = page.locator("button.omni-article-tool__check-access").first
66
66
  if not wall.is_visible():
67
67
  return False
68
- wall.click(timeout=5_000, no_wait_after=True)
68
+ if not self.d._click_control(page, wall, result, "ovid-check-access"):
69
+ return False
69
70
  institution.wait_for(state="visible", timeout=5_000)
70
- institution.click(timeout=10_000, no_wait_after=True)
71
+ if not self.d._click_control(page, institution, result, "ovid-institution-control"):
72
+ return False
71
73
  self.d._event(result, "sso_entry_clicked", "ovid-institution-control")
72
74
  return True
@@ -12,7 +12,7 @@ import re
12
12
  from typing import Any
13
13
  from urllib.parse import parse_qs, urlencode, urljoin, urlparse
14
14
 
15
- from ...engine.batch_common import open_page
15
+ from ...engine.batch_common import open_page, pump_until
16
16
  from ..base import PublisherAdapter, register
17
17
 
18
18
 
@@ -20,6 +20,19 @@ from ..base import PublisherAdapter, register
20
20
  class OpticaAdapter(PublisherAdapter):
21
21
  publisher = "optica"
22
22
 
23
+ def supplement_links(self, page: Any, doi: str) -> None:
24
+ # The embedded reader can still be loading after the outer document
25
+ # reports ready. Let its article metadata/links render before discovery.
26
+ target = urlparse(str(page.url))
27
+ if (target.scheme == "https" and target.netloc == "opg.optica.org"
28
+ and target.path.endswith("/viewmedia.cfm") and parse_qs(target.query).get("html") == ["true"]):
29
+ pump_until(page, lambda: page.evaluate("""() =>
30
+ document.readyState !== 'loading' &&
31
+ (!!document.querySelector('meta[name="citation_doi"]')
32
+ || document.querySelectorAll('a[href]').length > 0)
33
+ """), 15_000)
34
+ return None
35
+
23
36
  @classmethod
24
37
  def profile_pdf_candidates(cls, doi: str, source_url: str) -> list[str]:
25
38
  source = urlparse(source_url)