papersearch 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +12 -15
- package/README.md +12 -15
- package/carsi/paper_search_carsi/api_keys.py +3 -2
- package/carsi/paper_search_carsi/assets/api_keys.json +1 -1
- package/carsi/paper_search_carsi/assets/capsule.html +2 -0
- package/carsi/paper_search_carsi/assets/capsule_en.json +5 -0
- package/carsi/paper_search_carsi/browser/cookies.py +3 -206
- package/carsi/paper_search_carsi/cli.py +73 -37
- package/carsi/paper_search_carsi/config.py +24 -106
- package/carsi/paper_search_carsi/download_diagnostics.py +3 -3
- package/carsi/paper_search_carsi/engine/batch.py +15 -0
- package/carsi/paper_search_carsi/engine/batch_common.py +6 -0
- package/carsi/paper_search_carsi/engine/bridge.py +17 -4
- package/carsi/paper_search_carsi/orchestrator.py +19 -2
- package/carsi/paper_search_carsi/progress_capsule.py +2 -0
- package/dist/capabilities/body-snippet-search/handler.d.ts.map +1 -1
- package/dist/capabilities/body-snippet-search/handler.js +5 -1
- package/dist/capabilities/body-snippet-search/handler.js.map +1 -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 +19 -3
- package/dist/cli.js.map +1 -1
- package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
- package/dist/infrastructure/runlog/failureClass.js +1 -0
- package/dist/infrastructure/runlog/failureClass.js.map +1 -1
- package/dist/management/carsi/login.d.ts +28 -0
- package/dist/management/carsi/login.d.ts.map +1 -0
- package/dist/management/carsi/login.js +46 -0
- package/dist/management/carsi/login.js.map +1 -0
- package/dist/management/skills/nextSteps.d.ts.map +1 -1
- package/dist/management/skills/nextSteps.js +6 -5
- package/dist/management/skills/nextSteps.js.map +1 -1
- package/dist/platforms/SemanticScholarSearcher.d.ts +13 -0
- package/dist/platforms/SemanticScholarSearcher.d.ts.map +1 -1
- package/dist/platforms/SemanticScholarSearcher.js +77 -3
- package/dist/platforms/SemanticScholarSearcher.js.map +1 -1
- package/package.json +1 -1
- package/skills/paper-search/SKILL.md +20 -11
- package/skills/paper-search/references/browser-download.md +2 -1
- package/skills/paper-search/references/capability-routing.md +11 -1
- package/skills/paper-search/references/carsi-setup.md +14 -3
- package/skills/paper-search/references/cli-contract.md +1 -0
- package/skills/paper-search/references/publisher-support.md +1 -1
- package/carsi/paper_search_carsi/browser/login.py +0 -332
package/README.en.md
CHANGED
|
@@ -55,28 +55,30 @@ Please install PaperSearch: npm install -g papersearch, then run paper-search sk
|
|
|
55
55
|
|
|
56
56
|
It installs the command and the Skill, checks them, and tells you what already works.
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
Then **start a new chat** (most AI tools only read a newly installed Skill in a new chat) and say "**start setup**"; it walks you through step 3.
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
### 2. The school subscription downloads component installs automatically
|
|
61
61
|
|
|
62
|
-
-
|
|
63
|
-
- **No**: searching and open-access downloads work as before; it won't bring it up again until you ask.
|
|
62
|
+
On a computer, your AI installs the [school subscription downloads (CARSI)](#1-school-subscription-downloads-carsi) component automatically right after PaperSearch, and Chrome too if it is missing; when it is done, the settings window opens for step 3.
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
- Don't want it? Tell your AI and it is skipped for good; searching and open-access downloads work as before.
|
|
65
|
+
- Servers without a screen don't get it.
|
|
66
|
+
|
|
67
|
+
<p align="center"><img src="assets/install.en.webp" width="840" alt="Install demo: send your AI one sentence; it installs PaperSearch and the Skill, lists what works, then installs school subscription downloads (CARSI) automatically, Chrome first if it is missing, and opens the settings window"></p>
|
|
66
68
|
|
|
67
69
|
### 3. Add API keys when you need them
|
|
68
70
|
|
|
69
|
-
<p align="center"><img src="assets/config.en.webp" width="840" alt="Key demo: send a key to your AI and it saves and tests it;
|
|
71
|
+
<p align="center"><img src="assets/config.en.webp" width="840" alt="Key demo: send a key to your AI and it saves and tests it; once the school subscription downloads (CARSI) component is installed, set keys, the download folder and waiting times in the settings window"></p>
|
|
70
72
|
|
|
71
|
-
Get a key when you need that feature (sign-up pages: [API keys](#2-api-keys)) and enter it any of these ways:
|
|
73
|
+
Say "start setup" in the new chat and your AI tells you which keys are missing and sets the download folder. Get a key when you need that feature (sign-up pages: [API keys](#2-api-keys)) and enter it any of these ways:
|
|
72
74
|
|
|
73
75
|
- **Send it to your AI**: paste the key into the chat; it saves and tests it. The key stays in that conversation's history; if you'd rather not, use one of the other two ways.
|
|
74
|
-
- **Settings window** (
|
|
76
|
+
- **Settings window** (installed automatically with the school subscription downloads component): ask your AI to open the settings, or click the gear on the capsule. API keys, the download folder, waiting times and notifications are all there, and every key has a Test button.
|
|
75
77
|
- **Terminal**: run `paper-search setup <KEY>`; the input is hidden.
|
|
76
78
|
|
|
77
79
|
### 4. Tell your AI tool what you need
|
|
78
80
|
|
|
79
|
-
|
|
81
|
+
Once set up, just say what you need, for example:
|
|
80
82
|
|
|
81
83
|
| To do | You can say |
|
|
82
84
|
|---|---|
|
|
@@ -112,7 +114,7 @@ Feature comparison:
|
|
|
112
114
|
|  Subscription papers | — | ✅ (Elsevier, Springer) | ✅ (30+ major publishers) |
|
|
113
115
|
|  Supplementary files | — | — | ✅ |
|
|
114
116
|
| **You need** | Node.js 18 or later | Keys from each provider | Google Chrome, a school account |
|
|
115
|
-
| **How to turn it on** | Quick start step 1 |
|
|
117
|
+
| **How to turn it on** | Quick start step 1 | Settings window, your AI or terminal | Comes along on a computer |
|
|
116
118
|
|
|
117
119
|
### 1. School subscription downloads (CARSI)
|
|
118
120
|
|
|
@@ -135,9 +137,6 @@ paper-search carsi install # choose your school during installati
|
|
|
135
137
|
paper-search carsi status --format text # check that it is ready
|
|
136
138
|
```
|
|
137
139
|
|
|
138
|
-
<details>
|
|
139
|
-
<summary><b>See it in action (5 clips)</b></summary>
|
|
140
|
-
|
|
141
140
|
**Progress capsule**
|
|
142
141
|
|
|
143
142
|
<p align="center"><img src="assets/carsi-capsule.en.webp" width="840" alt="Progress capsule: a small capsule shows the progress, hover for each paper, minimized to the Dock it keeps downloading, one click brings it back"></p>
|
|
@@ -158,8 +157,6 @@ paper-search carsi status --format text # check that it is ready
|
|
|
158
157
|
|
|
159
158
|
<p align="center"><img src="assets/carsi-finish.en.webp" width="840" alt="Results: skip a paper; the final card lists what was saved and why the rest wasn't; clicking a title opens it in your own browser"></p>
|
|
160
159
|
|
|
161
|
-
</details>
|
|
162
|
-
|
|
163
160
|
### 2. API keys
|
|
164
161
|
|
|
165
162
|
Keys fall into four groups by what they are for. Get the key you need and enter it any of the ways in [Quick start step 3](#3-add-api-keys-when-you-need-them).
|
package/README.md
CHANGED
|
@@ -55,28 +55,30 @@ https://github.com/user-attachments/assets/7573a2a8-0778-4062-aa3e-4ccffb482b0b
|
|
|
55
55
|
|
|
56
56
|
它会装好命令和 Skill,自己检查一遍,告诉你哪些功能已经能用。
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
装好后**新开一个对话**(多数 AI 工具要新对话才读得到刚装的 Skill),对它说“**请开始配置**”,它会带你做第 3 步。
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
### 2. 自动装好学校订阅下载组件
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
- **不装**:检索和 OA 文章下载照常能用;之后它不再提,想装时直接跟它说。
|
|
62
|
+
在电脑上,AI 装好 PaperSearch 后会自动装好[学校订阅下载(CARSI)](#1-学校订阅下载carsi)组件,本机没有 Chrome 时一起装好;装完自动弹出设置窗口,接着做第 3 步。
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
- 不想要的话跟 AI 说一声就跳过,之后不再提;检索和 OA 文章下载照常能用。
|
|
65
|
+
- 没有图形界面的服务器上不装。
|
|
66
|
+
|
|
67
|
+
<p align="center"><img src="assets/install.webp" width="840" alt="安装演示:把一句话发给 AI,它装好 PaperSearch 和 Skill,列出能用的功能,再自动装好学校订阅下载(CARSI)组件,缺 Chrome 时先装 Chrome,装完弹出设置窗口"></p>
|
|
66
68
|
|
|
67
69
|
### 3. 按需填 API key
|
|
68
70
|
|
|
69
|
-
<p align="center"><img src="assets/config.webp" width="840" alt="填 key 演示:把 key 发给 AI
|
|
71
|
+
<p align="center"><img src="assets/config.webp" width="840" alt="填 key 演示:把 key 发给 AI,它替你保存并测试;自动装好学校订阅下载(CARSI)组件后,在设置窗口里填 key、改下载文件夹和等待时间"></p>
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
在新对话里说“请开始配置”,AI 会告诉你还缺哪些 key、帮你设好下载文件夹。要用哪项再申请对应的 key(申请入口见 [API key](#2-api-key)),用下面任一方式填入:
|
|
72
74
|
|
|
73
75
|
- **发给 AI**:把 key 直接发给它,它替你保存并测试。key 会留在这次对话的记录里,不想这样就用下面两种方式。
|
|
74
|
-
-
|
|
76
|
+
- **设置窗口**(随学校订阅下载组件自动装好):让 AI 打开设置,或点胶囊上的齿轮。API key、下载文件夹、等待时间和提醒都在这里改,每个 key 都能点“测试”。
|
|
75
77
|
- **终端**:运行 `paper-search setup <KEY>`,输入时不显示。
|
|
76
78
|
|
|
77
79
|
### 4. 对 AI 说一句话
|
|
78
80
|
|
|
79
|
-
|
|
81
|
+
配置好后,直接说你要做什么,例如:
|
|
80
82
|
|
|
81
83
|
| 想做什么 | 可以这样说 |
|
|
82
84
|
|---|---|
|
|
@@ -112,7 +114,7 @@ https://github.com/user-attachments/assets/7573a2a8-0778-4062-aa3e-4ccffb482b0b
|
|
|
112
114
|
|  下载非 OA 文章 | — | ✅(Elsevier、Springer) | ✅(30+主流出版社) |
|
|
113
115
|
|  下载补充材料 | — | — | ✅ |
|
|
114
116
|
| **需要准备** | Node.js 18 或以上 | 到各家网站申请 key | Google Chrome、学校账号 |
|
|
115
|
-
| **怎么开启** | 快速开始第 1 步 |
|
|
117
|
+
| **怎么开启** | 快速开始第 1 步 | 设置窗口、发给 AI 或终端 | 电脑上跟着装好 |
|
|
116
118
|
|
|
117
119
|
### 1. 学校订阅下载(CARSI)
|
|
118
120
|
|
|
@@ -135,9 +137,6 @@ paper-search carsi install # 安装时选择你的学校
|
|
|
135
137
|
paper-search carsi status --format text # 查看是否装好
|
|
136
138
|
```
|
|
137
139
|
|
|
138
|
-
<details>
|
|
139
|
-
<summary><b>查看演示(5 段)</b></summary>
|
|
140
|
-
|
|
141
140
|
**进度胶囊**
|
|
142
141
|
|
|
143
142
|
<p align="center"><img src="assets/carsi-capsule.webp" width="840" alt="进度胶囊:下载时缩成小胶囊,悬停查看每篇进度,最小化到程序坞照常下载,点一下就回来"></p>
|
|
@@ -158,8 +157,6 @@ paper-search carsi status --format text # 查看是否装好
|
|
|
158
157
|
|
|
159
158
|
<p align="center"><img src="assets/carsi-finish.webp" width="840" alt="结束清单:跳过不想等的论文;下完列出结果,没下到的写明原因,点题名在自己的浏览器里打开"></p>
|
|
160
159
|
|
|
161
|
-
</details>
|
|
162
|
-
|
|
163
160
|
### 2. API key
|
|
164
161
|
|
|
165
162
|
按用途分四类,需要哪类就申请对应的 key,再用[快速开始第 3 步](#3-按需填-api-key)里的任一方式填入。
|
|
@@ -124,9 +124,10 @@ def test(service_id: str, values: dict[str, str]) -> dict[str, str]:
|
|
|
124
124
|
# A test must not also update the Skill or check for a new version.
|
|
125
125
|
env = {**os.environ, "PAPER_SEARCH_SKILL_AUTO_UPDATE": "false", "PAPER_SEARCH_UPDATE_NOTIFY": "false"}
|
|
126
126
|
try:
|
|
127
|
+
# PaperSearch answers in UTF-8; left to the system encoding, Chinese Windows reads it as GBK and loses it all.
|
|
127
128
|
done = subprocess.run([*command, "config", "test", service["keys"][0]["key"], "--stdin"], input=json.dumps(typed),
|
|
128
|
-
capture_output=True,
|
|
129
|
-
reply = json.loads(done.stdout.strip().splitlines()[-1])
|
|
129
|
+
capture_output=True, encoding="utf-8", errors="replace", timeout=45, env=env)
|
|
130
|
+
reply = json.loads((done.stdout or "").strip().splitlines()[-1])
|
|
130
131
|
except subprocess.TimeoutExpired:
|
|
131
132
|
return {"status": "unreachable", "message": "测试超时,没法判断;检查网络或代理后再试"}
|
|
132
133
|
except (OSError, ValueError, IndexError) as exc:
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"name": "Semantic Scholar",
|
|
21
21
|
"use": "搜正文片段",
|
|
22
22
|
"url": "https://www.semanticscholar.org/product/api",
|
|
23
|
-
"guide": "https://
|
|
23
|
+
"guide": "https://docs.qq.com/aio/DTW9RdFVHc2hJUmpx",
|
|
24
24
|
"guide_label": "申请教程",
|
|
25
25
|
"keys": [
|
|
26
26
|
{
|
|
@@ -827,6 +827,8 @@ async function act(action, target) {
|
|
|
827
827
|
try {
|
|
828
828
|
const result = await api().test_api_key(target.dataset.service, values);
|
|
829
829
|
keyError(result.message, result.status === "valid" ? "ok" : result.status === "invalid" ? "" : "wait");
|
|
830
|
+
} catch (error) {
|
|
831
|
+
keyError("测试没有完成:" + ((error && error.message) || String(error)));
|
|
830
832
|
} finally { target.disabled = false; }
|
|
831
833
|
return;
|
|
832
834
|
}
|
|
@@ -130,6 +130,10 @@
|
|
|
130
130
|
"已检查,页面未列出补充材料": "Checked; no supp. listed",
|
|
131
131
|
"批量下载已停止,结果未确认": "Batch stopped; result unconfirmed",
|
|
132
132
|
"机构 PDF 下载": "School PDF download",
|
|
133
|
+
"学校登录": "School sign-in",
|
|
134
|
+
"打开文章页": "Opening the article",
|
|
135
|
+
"已登录学校": "Signed in",
|
|
136
|
+
"没有完成登录": "Not signed in",
|
|
133
137
|
"机构 PDF 批量下载": "School PDF batch",
|
|
134
138
|
"等待下载进程响应(暂无新进度)": "Waiting for the download (no news)",
|
|
135
139
|
"DOI 没指向能登录的网站": "DOI leads to no login site",
|
|
@@ -167,6 +171,7 @@
|
|
|
167
171
|
"登录后没回到出版社": "No return to publisher",
|
|
168
172
|
"登录重试已用尽": "Login retries used up",
|
|
169
173
|
"登录页被关闭": "Login page closed",
|
|
174
|
+
"下载浏览器被关闭了": "Browser closed",
|
|
170
175
|
"等学校登录超时": "School login timed out",
|
|
171
176
|
"网站人机验证拦截": "Blocked by bot check",
|
|
172
177
|
"网站拦截了当前网络": "Site blocked network",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Publisher cookies the download browser saved: kept, merged and restored.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Signing in is the download's own work (``login`` runs its steps without the
|
|
4
|
+
PDF); the old window that only captured cookies was removed on 2026-11-09.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
from __future__ import annotations
|
|
@@ -43,26 +43,6 @@ PUBLISHER_DOMAINS = [
|
|
|
43
43
|
"frontiersin.org",
|
|
44
44
|
]
|
|
45
45
|
|
|
46
|
-
# Publisher login URLs for quick access
|
|
47
|
-
PUBLISHER_LOGIN_URLS = {
|
|
48
|
-
"elsevier": "https://www.sciencedirect.com/",
|
|
49
|
-
"springer": "https://link.springer.com/",
|
|
50
|
-
"wiley": "https://onlinelibrary.wiley.com/",
|
|
51
|
-
"nature": "https://www.nature.com/",
|
|
52
|
-
"science": "https://www.science.org/",
|
|
53
|
-
"ieee": "https://ieeexplore.ieee.org/",
|
|
54
|
-
"tandfonline": "https://www.tandfonline.com/",
|
|
55
|
-
"pnas": "https://www.pnas.org/",
|
|
56
|
-
"acs": "https://pubs.acs.org/",
|
|
57
|
-
"rsc": "https://pubs.rsc.org/",
|
|
58
|
-
"aip": "https://pubs.aip.org/",
|
|
59
|
-
"aps": "https://journals.aps.org/",
|
|
60
|
-
"iop": "https://iopscience.iop.org/",
|
|
61
|
-
"oxford": "https://academic.oup.com/",
|
|
62
|
-
"acm": "https://dl.acm.org/",
|
|
63
|
-
"sage-cn": "https://sage.cnpereading.com/login",
|
|
64
|
-
}
|
|
65
|
-
|
|
66
46
|
# Cloudflare bot-management cookies: they carry no login.
|
|
67
47
|
_CLOUDFLARE_COOKIE_NAMES = {"__cf_bm", "_cfuvid", "cf_clearance", "cf_chl_rc_ni"}
|
|
68
48
|
|
|
@@ -97,127 +77,6 @@ def _is_publisher_cookie(cookie: dict[str, Any]) -> bool:
|
|
|
97
77
|
return any(domain == d or domain.endswith("." + d) for d in PUBLISHER_DOMAINS)
|
|
98
78
|
|
|
99
79
|
|
|
100
|
-
def extract_via_browser(
|
|
101
|
-
config: dict[str, Any],
|
|
102
|
-
*,
|
|
103
|
-
url: str = "https://www.sciencedirect.com/",
|
|
104
|
-
max_wait: int = 300,
|
|
105
|
-
) -> dict[str, Any]:
|
|
106
|
-
"""Open visible browser for institutional login, then capture publisher cookies.
|
|
107
|
-
|
|
108
|
-
Args:
|
|
109
|
-
config: backend config dict.
|
|
110
|
-
url: URL to open (default: ScienceDirect).
|
|
111
|
-
max_wait: Max seconds to wait for login.
|
|
112
|
-
|
|
113
|
-
Returns:
|
|
114
|
-
Result dict with success, cookies_count, domains, etc.
|
|
115
|
-
"""
|
|
116
|
-
try:
|
|
117
|
-
from .backend import CHROME_MISSING, launch
|
|
118
|
-
from .backend import is_available as _browser_backend_available
|
|
119
|
-
if not _browser_backend_available(config=config):
|
|
120
|
-
return {
|
|
121
|
-
"success": False,
|
|
122
|
-
"error": "no browser backend available",
|
|
123
|
-
"fix": CHROME_MISSING,
|
|
124
|
-
}
|
|
125
|
-
except ImportError:
|
|
126
|
-
return {
|
|
127
|
-
"success": False,
|
|
128
|
-
"error": "no browser backend available",
|
|
129
|
-
"fix": "paper-search carsi update",
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
from ..config import DATA_DIR
|
|
133
|
-
cache_dir = Path(config.get("cache_dir", str(DATA_DIR / "cache")))
|
|
134
|
-
cookie_file = cache_dir / "publisher_cookies.json"
|
|
135
|
-
netscape_file = cache_dir / "publisher_cookies.txt"
|
|
136
|
-
|
|
137
|
-
log.info(f" [cookies] Opening browser: {url}")
|
|
138
|
-
print(f"\n 请在浏览器中登录你的机构账号(如学校图书馆)")
|
|
139
|
-
print(f" 打开页面: {url}")
|
|
140
|
-
print(f" 登录完成后关闭浏览器窗口即可\n")
|
|
141
|
-
|
|
142
|
-
try:
|
|
143
|
-
browser = launch(headless=False, humanize=True)
|
|
144
|
-
context = browser.new_context(viewport={"width": 1440, "height": 900})
|
|
145
|
-
page = context.new_page()
|
|
146
|
-
|
|
147
|
-
try:
|
|
148
|
-
page.goto(url, wait_until="domcontentloaded", timeout=60000)
|
|
149
|
-
except Exception as exc:
|
|
150
|
-
log.info(f" [cookies] Page load warning: {exc}")
|
|
151
|
-
|
|
152
|
-
# Auto-dismiss cookie consent popups (common on Elsevier/Cell/Wiley/etc.)
|
|
153
|
-
time.sleep(2)
|
|
154
|
-
for js in [
|
|
155
|
-
# Elsevier/Cell cookie banner
|
|
156
|
-
"document.querySelector('#onetrust-accept-btn-handler')?.click()",
|
|
157
|
-
# OneTrust general
|
|
158
|
-
"document.querySelector('.onetrust-close-btn-handler')?.click()",
|
|
159
|
-
# Generic consent banners
|
|
160
|
-
"document.querySelector('[class*=\"cookie-accept\"], [class*=\"consent-accept\"]')?.click()",
|
|
161
|
-
"document.querySelector('button[id*=\"accept\"], button[class*=\"accept\"]')?.click()",
|
|
162
|
-
]:
|
|
163
|
-
try:
|
|
164
|
-
page.evaluate(js)
|
|
165
|
-
except Exception:
|
|
166
|
-
pass
|
|
167
|
-
|
|
168
|
-
# Wait for user to close browser
|
|
169
|
-
try:
|
|
170
|
-
page.wait_for_event("close", timeout=max_wait * 1000)
|
|
171
|
-
except Exception:
|
|
172
|
-
pass
|
|
173
|
-
|
|
174
|
-
# Capture all cookies
|
|
175
|
-
all_cookies = context.cookies()
|
|
176
|
-
|
|
177
|
-
if not all_cookies:
|
|
178
|
-
browser.close()
|
|
179
|
-
return {
|
|
180
|
-
"success": False,
|
|
181
|
-
"message": "未捕获到 cookies。请确保已登录机构账号。",
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
# Filter publisher cookies + keep all for completeness
|
|
185
|
-
publisher_cookies = [c for c in all_cookies if _is_publisher_cookie(c)]
|
|
186
|
-
save_cookies = publisher_cookies if publisher_cookies else all_cookies
|
|
187
|
-
|
|
188
|
-
# Save
|
|
189
|
-
_save_cookies_json(save_cookies, cookie_file)
|
|
190
|
-
_save_cookies_netscape(save_cookies, netscape_file)
|
|
191
|
-
|
|
192
|
-
# Import into the shared browser if available
|
|
193
|
-
browser_imported = 0
|
|
194
|
-
try:
|
|
195
|
-
from .engine import import_cookies, is_available
|
|
196
|
-
if is_available(config):
|
|
197
|
-
browser_imported = import_cookies(netscape_file, config)
|
|
198
|
-
except Exception:
|
|
199
|
-
pass
|
|
200
|
-
|
|
201
|
-
browser.close()
|
|
202
|
-
|
|
203
|
-
domains_found = list({c.get("domain", "").lstrip(".") for c in save_cookies})[:10]
|
|
204
|
-
return {
|
|
205
|
-
"success": True,
|
|
206
|
-
"cookies_count": len(save_cookies),
|
|
207
|
-
"total_captured": len(all_cookies),
|
|
208
|
-
"cookie_file": str(cookie_file),
|
|
209
|
-
"netscape_file": str(netscape_file),
|
|
210
|
-
"domains": domains_found,
|
|
211
|
-
"browser_imported": browser_imported,
|
|
212
|
-
"message": f"捕获 {len(all_cookies)} 个 cookies,其中 {len(publisher_cookies)} 个属于出版社。"
|
|
213
|
-
f"已保存,后续下载自动使用。",
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
except Exception as exc:
|
|
217
|
-
log.info(f" [cookies] Error: {exc}")
|
|
218
|
-
return {"success": False, "error": str(exc)}
|
|
219
|
-
|
|
220
|
-
|
|
221
80
|
def load_saved_cookies(config: dict[str, Any]) -> list[dict[str, Any]]:
|
|
222
81
|
"""Load previously saved publisher cookies, filtering out expired ones."""
|
|
223
82
|
from ..config import DATA_DIR
|
|
@@ -322,65 +181,3 @@ def merge_cookies(new_cookies: list[dict[str, Any]], config: dict[str, Any], *,
|
|
|
322
181
|
_save_cookies_netscape(result, netscape_file)
|
|
323
182
|
|
|
324
183
|
return result
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
def _is_doi(text: str) -> bool:
|
|
328
|
-
return text.startswith("10.") and "/" in text
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
def publisher_login(
|
|
332
|
-
identifier: str,
|
|
333
|
-
config: dict[str, Any],
|
|
334
|
-
*,
|
|
335
|
-
max_wait: int = 300,
|
|
336
|
-
) -> dict[str, Any]:
|
|
337
|
-
"""Open browser for institutional login on a publisher article page.
|
|
338
|
-
|
|
339
|
-
Takes a DOI or publisher name, resolves to the article page, and opens
|
|
340
|
-
a visible stealth browser. User clicks "Access through your institution",
|
|
341
|
-
completes SSO login, then closes the browser. Cookies are captured and
|
|
342
|
-
imported into the download browser for automated downloads.
|
|
343
|
-
|
|
344
|
-
Args:
|
|
345
|
-
identifier: DOI (e.g. 10.1126/science.aec6396) or publisher name
|
|
346
|
-
(e.g. "elsevier", "wiley", "nature", "springer", "ieee",
|
|
347
|
-
"science", "tandfonline", "pnas", "acs", "rsc", "aip",
|
|
348
|
-
"aps", "iop", "oxford", "acm")
|
|
349
|
-
config: backend config dict
|
|
350
|
-
max_wait: Max seconds to wait for login (default 300)
|
|
351
|
-
|
|
352
|
-
Returns:
|
|
353
|
-
Result dict with success, cookies_count, domains, message.
|
|
354
|
-
"""
|
|
355
|
-
import re
|
|
356
|
-
|
|
357
|
-
# Resolve identifier to a URL
|
|
358
|
-
if _is_doi(identifier):
|
|
359
|
-
# DOI → resolve to article URL
|
|
360
|
-
url = f"https://doi.org/{identifier}"
|
|
361
|
-
log.info(f" [login] DOI detected, opening article: {url}")
|
|
362
|
-
elif identifier.lower() in PUBLISHER_LOGIN_URLS:
|
|
363
|
-
url = PUBLISHER_LOGIN_URLS[identifier.lower()]
|
|
364
|
-
log.info(f" [login] Publisher '{identifier}', opening: {url}")
|
|
365
|
-
elif re.match(r"https?://", identifier):
|
|
366
|
-
url = identifier
|
|
367
|
-
log.info(f" [login] URL detected: {url}")
|
|
368
|
-
else:
|
|
369
|
-
# Try fuzzy publisher name match
|
|
370
|
-
lower = identifier.lower()
|
|
371
|
-
match = None
|
|
372
|
-
for key in PUBLISHER_LOGIN_URLS:
|
|
373
|
-
if key in lower or lower in key:
|
|
374
|
-
match = key
|
|
375
|
-
break
|
|
376
|
-
if match:
|
|
377
|
-
url = PUBLISHER_LOGIN_URLS[match]
|
|
378
|
-
log.info(f" [login] Matched publisher '{match}', opening: {url}")
|
|
379
|
-
else:
|
|
380
|
-
available = ", ".join(sorted(PUBLISHER_LOGIN_URLS.keys()))
|
|
381
|
-
return {
|
|
382
|
-
"success": False,
|
|
383
|
-
"error": f"Unknown publisher: '{identifier}'. Available: {available}",
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
return extract_via_browser(config, url=url, max_wait=max_wait)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Commands:
|
|
4
4
|
run start the MCP stdio server (what PaperSearch spawns)
|
|
5
5
|
setup [...] show or change institutional access settings; --check for an environment check
|
|
6
|
-
login
|
|
6
|
+
login --doi DOI sign in to the school as a download does (no PDF); success only once confirmed
|
|
7
7
|
config get|set|list read or write the backend config in CARSI_DATA_DIR
|
|
8
8
|
list-publishers print publisher profiles and their platform labels
|
|
9
9
|
publisher-check --doi DOI run one institutional download and print a sanitized report
|
|
@@ -196,40 +196,79 @@ def _cmd_setup(args: argparse.Namespace) -> int:
|
|
|
196
196
|
# login
|
|
197
197
|
# ---------------------------------------------------------------------------
|
|
198
198
|
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
_LOGIN_MESSAGES = {
|
|
200
|
+
"login_timeout": "等你登录超时了;再运行一次,在弹出的学校登录页里登录即可",
|
|
201
|
+
"login_page_closed": "学校登录页被关闭了,没有完成登录",
|
|
202
|
+
"browser_closed": "下载浏览器被关闭了,没有完成登录",
|
|
203
|
+
"institution_pdf_entitlement_missing": "已登录学校,但学校没有这篇文章的全文权限;换一篇学校订阅的文章再试",
|
|
204
|
+
"login_credentials_rejected": "学校登录页没有接受账号或密码",
|
|
205
|
+
"institution_not_registered": "出版社的机构列表里没有找到你的学校",
|
|
206
|
+
"login_not_reached": "程序没能进入学校登录页(一直停在出版社页面);详情见诊断文件",
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _login_reply(result: dict[str, Any]) -> dict[str, Any]:
|
|
211
|
+
"""What ``login`` says: success only when the school's login is confirmed
|
|
212
|
+
and the article opens in full (a window closed by hand is no login)."""
|
|
213
|
+
login = result.get("login") or {}
|
|
214
|
+
artifacts = result.get("artifacts") or {}
|
|
215
|
+
if result.get("success") and login.get("signed_in"):
|
|
216
|
+
return {"success": True, "state": "signed_in",
|
|
217
|
+
"message": "已登录学校,这篇文章能看全文;之后下载沿用这个登录"}
|
|
218
|
+
if result.get("success"):
|
|
219
|
+
return {"success": False, "state": "access_without_login",
|
|
220
|
+
"message": "这篇文章不用登录就能看全文(开放获取或校园网),这次没有验证到学校登录;要测试登录,换一篇需要订阅的文章"}
|
|
221
|
+
# The bridge's reported reason (a wait run out on the school's page is login_timeout);
|
|
222
|
+
# the raw state only behind a general one.
|
|
223
|
+
state = str(result.get("reason_code") or result.get("error_type") or "")
|
|
224
|
+
if state in ("", "paywall", "download_failed"):
|
|
225
|
+
state = str(artifacts.get("state") or state or "login_failed")
|
|
226
|
+
reply: dict[str, Any] = {"success": False, "state": state,
|
|
227
|
+
"message": _LOGIN_MESSAGES.get(state, f"没有完成登录({state});详情见诊断文件")}
|
|
228
|
+
if artifacts.get("diagnostic"):
|
|
229
|
+
reply["diagnostic"] = artifacts["diagnostic"]
|
|
230
|
+
return reply
|
|
201
231
|
|
|
202
|
-
cfg = load_config()
|
|
203
|
-
kind = args.kind
|
|
204
|
-
|
|
205
|
-
if kind in ("auto", "publisher"):
|
|
206
|
-
# A school login (CARSI included) starts on the publisher's page.
|
|
207
|
-
if not args.doi and not args.publisher:
|
|
208
|
-
print(json.dumps({"success": False, "error": "doi_or_publisher_required",
|
|
209
|
-
"hint": "pass --doi <DOI of an article>: the login opens that article's publisher page, "
|
|
210
|
-
"where the school is chosen (CARSI)"}, ensure_ascii=False))
|
|
211
|
-
return 2
|
|
212
|
-
from .browser.cookies import publisher_login
|
|
213
232
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
233
|
+
def _cmd_login(args: argparse.Namespace) -> int:
|
|
234
|
+
"""Sign in to the school the way a download does, without its PDF: the
|
|
235
|
+
download browser (its own Chrome profile) opens the article's page, gets
|
|
236
|
+
past the site's verification, picks the school (CARSI) and waits on the
|
|
237
|
+
school's login page for the user; then the article's access is checked.
|
|
238
|
+
The session stays in that profile for the downloads that follow."""
|
|
239
|
+
from .config import load_config
|
|
240
|
+
from .engine.bridge import _any_institutional_configured
|
|
219
241
|
|
|
220
|
-
if
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
242
|
+
if not args.doi:
|
|
243
|
+
print(json.dumps({"success": False, "error": "doi_required",
|
|
244
|
+
"hint": "pass --doi with an article the school subscribes to; its page leads to the school's login"},
|
|
245
|
+
ensure_ascii=False))
|
|
246
|
+
return 2
|
|
247
|
+
if not _any_institutional_configured(load_config()):
|
|
248
|
+
print(json.dumps({"success": False, "error": "school_not_configured",
|
|
249
|
+
"hint": 'run: setup --carsi --institution "<your school>"'}, ensure_ascii=False))
|
|
250
|
+
return 2
|
|
251
|
+
import shutil
|
|
252
|
+
import tempfile
|
|
225
253
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
print(json.dumps({"success": bool(ok), "kind": "custom"}, ensure_ascii=False))
|
|
229
|
-
return 0 if ok else 1
|
|
254
|
+
from . import progress_reporter
|
|
255
|
+
from .orchestrator import download_institutional
|
|
230
256
|
|
|
231
|
-
|
|
232
|
-
|
|
257
|
+
scratch = Path(tempfile.mkdtemp(prefix="paper-search-login-"))
|
|
258
|
+
progress_reporter.start_task("学校登录", total=1, current=args.doi, phase="打开文章页")
|
|
259
|
+
reply: dict[str, Any] = {"success": False, "state": "login_failed", "message": "没有完成登录"}
|
|
260
|
+
try:
|
|
261
|
+
result = download_institutional(args.doi, scratch, strategy="institutional_only",
|
|
262
|
+
login_only=True, login_wait=args.max_wait,
|
|
263
|
+
diagnostics_dir=str(_data_dir() / "diagnostics" / "login"))
|
|
264
|
+
reply = _login_reply(result)
|
|
265
|
+
finally:
|
|
266
|
+
progress_reporter.advance(reply["success"], current=args.doi,
|
|
267
|
+
phase="已登录学校" if reply["success"] else "没有完成登录")
|
|
268
|
+
progress_reporter.finish()
|
|
269
|
+
shutil.rmtree(scratch, ignore_errors=True)
|
|
270
|
+
print(json.dumps(reply, ensure_ascii=False))
|
|
271
|
+
return 0 if reply["success"] else 1
|
|
233
272
|
|
|
234
273
|
|
|
235
274
|
# ---------------------------------------------------------------------------
|
|
@@ -495,13 +534,10 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
495
534
|
st.add_argument("--check", action="store_true", help="environment check; exit 2 when something is missing")
|
|
496
535
|
st.set_defaults(func=_cmd_setup)
|
|
497
536
|
|
|
498
|
-
lg = sub.add_parser("login", help="
|
|
499
|
-
lg.add_argument("--
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
lg.add_argument("--doi", default="", help="DOI whose publisher page to open")
|
|
503
|
-
lg.add_argument("--url", default="", help="URL for --kind custom")
|
|
504
|
-
lg.add_argument("--max-wait", type=int, default=300)
|
|
537
|
+
lg = sub.add_parser("login", help="sign in to the school as a download does, without the PDF")
|
|
538
|
+
lg.add_argument("--doi", default="", help="an article the school subscribes to; its page leads to the school's login")
|
|
539
|
+
lg.add_argument("--max-wait", type=int, default=None,
|
|
540
|
+
help="seconds to wait on the school's login page (default: the setting browser_login_timeout)")
|
|
505
541
|
lg.set_defaults(func=_cmd_login)
|
|
506
542
|
|
|
507
543
|
cfg = sub.add_parser("config", help="read or write backend config")
|