papersearch 0.8.0 → 0.8.1
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/NOTICE +1 -1
- package/README.fr.md +5 -8
- package/README.ja.md +5 -8
- package/README.ko.md +5 -8
- package/README.md +148 -151
- package/README.zh-Hant.md +5 -8
- package/README.zh.md +265 -0
- package/dist/capabilities/download/batch/batch.d.ts +4 -0
- package/dist/capabilities/download/batch/batch.d.ts.map +1 -1
- package/dist/capabilities/download/batch/batch.js +714 -198
- package/dist/capabilities/download/batch/batch.js.map +1 -1
- package/dist/capabilities/download/batch/windowPlan.d.ts +96 -0
- package/dist/capabilities/download/batch/windowPlan.d.ts.map +1 -0
- package/dist/capabilities/download/batch/windowPlan.js +196 -0
- package/dist/capabilities/download/batch/windowPlan.js.map +1 -0
- package/dist/capabilities/download/content/markdown/step.d.ts.map +1 -1
- package/dist/capabilities/download/content/markdown/step.js +4 -1
- package/dist/capabilities/download/content/markdown/step.js.map +1 -1
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.d.ts.map +1 -1
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.js +3 -1
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.js.map +1 -1
- package/dist/infrastructure/http/hostGate.d.ts +24 -0
- package/dist/infrastructure/http/hostGate.d.ts.map +1 -0
- package/dist/infrastructure/http/hostGate.js +72 -0
- package/dist/infrastructure/http/hostGate.js.map +1 -0
- package/dist/infrastructure/pdf/PdfDownload.d.ts +1 -0
- package/dist/infrastructure/pdf/PdfDownload.d.ts.map +1 -1
- package/dist/infrastructure/pdf/PdfDownload.js +6 -1
- package/dist/infrastructure/pdf/PdfDownload.js.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.d.ts +7 -0
- package/dist/infrastructure/runlog/RunLedger.d.ts.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.js +17 -4
- package/dist/infrastructure/runlog/RunLedger.js.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.d.ts +12 -2
- package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.js +122 -11
- package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -1
- package/dist/infrastructure/school/SchoolReadiness.d.ts +7 -0
- package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolReadiness.js +8 -0
- package/dist/infrastructure/school/SchoolReadiness.js.map +1 -1
- package/dist/infrastructure/school/index.d.ts +1 -1
- package/dist/infrastructure/school/index.d.ts.map +1 -1
- package/dist/infrastructure/school/types.d.ts +31 -1
- package/dist/infrastructure/school/types.d.ts.map +1 -1
- package/dist/infrastructure/school/types.js.map +1 -1
- package/dist/infrastructure/security/SecurityUtils.d.ts.map +1 -1
- package/dist/infrastructure/security/SecurityUtils.js +6 -2
- package/dist/infrastructure/security/SecurityUtils.js.map +1 -1
- package/dist/management/failures/index.d.ts.map +1 -1
- package/dist/management/failures/index.js +5 -2
- package/dist/management/failures/index.js.map +1 -1
- package/dist/management/school/autoUpdate.d.ts.map +1 -1
- package/dist/management/school/autoUpdate.js +9 -1
- package/dist/management/school/autoUpdate.js.map +1 -1
- package/dist/management/school/cliProgress.d.ts.map +1 -1
- package/dist/management/school/cliProgress.js +3 -1
- package/dist/management/school/cliProgress.js.map +1 -1
- package/package.json +2 -2
- package/school/paper_search_school/adapters/base.py +3 -0
- package/school/paper_search_school/adapters/optica/__init__.py +50 -4
- package/school/paper_search_school/adapters/platforms/atypon/__init__.py +4 -3
- package/school/paper_search_school/adapters/platforms/figshare/__init__.py +23 -4
- package/school/paper_search_school/assets/capsule.html +380 -41
- package/school/paper_search_school/assets/capsule_en.json +72 -4
- package/school/paper_search_school/assets/capsule_fr.json +72 -4
- package/school/paper_search_school/assets/capsule_ja.json +72 -4
- package/school/paper_search_school/assets/capsule_ko.json +72 -4
- package/school/paper_search_school/assets/capsule_zh-Hant.json +66 -3
- package/school/paper_search_school/browser/backend.py +125 -4
- package/school/paper_search_school/browser/batch_session.py +188 -7
- package/school/paper_search_school/browser/challenge/continuation.py +19 -1
- package/school/paper_search_school/browser/challenge/handlers/text_captcha.py +38 -10
- package/school/paper_search_school/browser/challenge/pro.py +24 -0
- package/school/paper_search_school/browser/challenge/services/solver.py +24 -4
- package/school/paper_search_school/browser/engine.py +4 -1
- package/school/paper_search_school/browser/user_turn.py +126 -0
- package/school/paper_search_school/browser/watchdog.py +213 -60
- package/school/paper_search_school/config.py +5 -0
- package/school/paper_search_school/engine/batch.py +9 -7
- package/school/paper_search_school/engine/batch_access.py +27 -7
- package/school/paper_search_school/engine/batch_capture.py +45 -13
- package/school/paper_search_school/engine/batch_institution.py +14 -0
- package/school/paper_search_school/engine/batch_login.py +177 -22
- package/school/paper_search_school/engine/batch_user.py +48 -3
- package/school/paper_search_school/engine/batch_waits.py +42 -2
- package/school/paper_search_school/engine/bridge.py +1 -2
- package/school/paper_search_school/engine/fulltext_page.py +10 -1
- package/school/paper_search_school/engine/supplements.py +7 -1
- package/school/paper_search_school/entitlements.py +28 -0
- package/school/paper_search_school/progress_capsule.py +33 -5
- package/school/paper_search_school/progress_reporter.py +189 -6
- package/school/paper_search_school/progress_view.py +142 -48
- package/school/paper_search_school/rate_limit.py +24 -1
- package/school/paper_search_school/school_login.py +170 -8
- package/school/paper_search_school/server.py +164 -19
- package/school/paper_search_school/user_settings.py +33 -4
- package/skills/paper-search/SKILL.md +1 -1
- package/skills/paper-search/references/browser-download.md +2 -2
- package/LICENSE-paper-search-mcp-nodejs +0 -24
- package/README.en.md +0 -268
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"不支持这种语言": "不支援這種語言",
|
|
53
53
|
"中国": "中國",
|
|
54
54
|
"中文名、英文名或学校网址": "中文名、英文名或學校網址",
|
|
55
|
+
"串行": "依序",
|
|
55
56
|
"丹麦": "丹麥",
|
|
56
57
|
"乌克兰": "烏克蘭",
|
|
57
58
|
"乌干达": "烏干達",
|
|
@@ -62,12 +63,15 @@
|
|
|
62
63
|
"亚洲": "亞洲",
|
|
63
64
|
"从一篇论文出发,沿引用找相关文献,画成关系图": "從一篇論文出發,沿引用找相關文獻,畫成關係圖",
|
|
64
65
|
"从打开的标签页读到本文的 PDF": "從打開的標籤頁讀到本文的 PDF",
|
|
66
|
+
"企业微信": "企業微信",
|
|
67
|
+
"企业微信扫码": "企業微信掃碼",
|
|
65
68
|
"伊利诺伊州": "伊利諾州",
|
|
66
69
|
"佐治亚州": "喬治亞州",
|
|
67
70
|
"佛罗里达州": "佛羅里達州",
|
|
68
71
|
"你标记过没权限": "你標記過沒權限",
|
|
69
72
|
"你跳过或终止了": "你跳過或終止了",
|
|
70
73
|
"使用状态": "使用狀態",
|
|
74
|
+
"例:2 家 × 1 篇 = 同时下载 2 篇": "例:2 家 × 1 篇 = 同時下載 2 篇",
|
|
71
75
|
"俄克拉何马州": "俄克拉何馬州",
|
|
72
76
|
"俄勒冈州": "俄勒岡州",
|
|
73
77
|
"保加利亚": "保加利亞",
|
|
@@ -78,6 +82,7 @@
|
|
|
78
82
|
"先到学校网站解锁账号,再测一次": "先到學校網站解鎖帳號,再測一次",
|
|
79
83
|
"先填测试文章": "先填測試文章",
|
|
80
84
|
"先检查更新": "先檢查更新",
|
|
85
|
+
"先验证一次": "先驗證一次",
|
|
81
86
|
"克罗地亚": "克羅埃西亞",
|
|
82
87
|
"全文网页已读取": "全文網頁已讀取",
|
|
83
88
|
"全文还没上线": "全文還沒上線",
|
|
@@ -96,6 +101,7 @@
|
|
|
96
101
|
"再测一次": "再測一次",
|
|
97
102
|
"冰岛": "冰島",
|
|
98
103
|
"准备中": "準備中",
|
|
104
|
+
"减少": "減少",
|
|
99
105
|
"出版社内容服务错误,当前路径已停止": "出版社內容服務錯誤,當前路徑已停止",
|
|
100
106
|
"出版社原文转成 Markdown,图表、公式完整": "出版社原文轉成 Markdown,圖表、公式完整",
|
|
101
107
|
"出版社尚未发布这篇论文的全文,当前路径已停止": "出版社尚未發布這篇論文的全文,當前路徑已停止",
|
|
@@ -145,6 +151,8 @@
|
|
|
145
151
|
"可以用:Unpaywall 接受这个邮箱": "可以用:Unpaywall 接受這個電子郵件",
|
|
146
152
|
"可以用:已走 Crossref 优先通道": "可以用:已走 Crossref 優先通道",
|
|
147
153
|
"台湾": "台灣",
|
|
154
|
+
"同时下载": "同時下載",
|
|
155
|
+
"同时下载 = 出版社数 × 每家篇数": "同時下載 = 出版社數 × 每家篇數",
|
|
148
156
|
"哈萨克斯坦": "哈薩克",
|
|
149
157
|
"哥伦比亚": "哥倫比亞",
|
|
150
158
|
"哥伦比亚特区": "哥倫比亞特區",
|
|
@@ -191,8 +199,16 @@
|
|
|
191
199
|
"学校登录中途失效": "學校登入中途失效",
|
|
192
200
|
"学校登录测试": "學校登入測試",
|
|
193
201
|
"学校登录系统出错": "學校登入系統出錯",
|
|
202
|
+
"学校登录页上没认出账号密码框,没有自动填写:请在浏览器窗口完成机构登录": "學校登入頁上沒認出帳號密碼框,沒有自動填寫:請在瀏覽器視窗完成機構登入",
|
|
203
|
+
"学校登录页只能用企业微信扫码登录,没有账号密码可填,请在浏览器窗口扫码。": "學校登入頁只能用企業微信掃碼登入,沒有帳號密碼可填,請在瀏覽器視窗掃碼。",
|
|
204
|
+
"学校登录页只能用学校的 App扫码登录,没有账号密码可填,请在浏览器窗口扫码。": "學校登入頁只能用學校的 App掃碼登入,沒有帳號密碼可填,請在瀏覽器視窗掃碼。",
|
|
205
|
+
"学校登录页只能用微信扫码登录,没有账号密码可填,请在浏览器窗口扫码。": "學校登入頁只能用微信掃碼登入,沒有帳號密碼可填,請在瀏覽器視窗掃碼。",
|
|
206
|
+
"学校登录页只能用短信验证码登录,请在浏览器窗口完成。": "學校登入頁只能用短信驗證碼登入,請在瀏覽器視窗完成。",
|
|
207
|
+
"学校登录页只能用钉钉扫码登录,没有账号密码可填,请在浏览器窗口扫码。": "學校登入頁只能用釘釘掃碼登入,沒有帳號密碼可填,請在瀏覽器視窗掃碼。",
|
|
194
208
|
"学校登录页最多等": "學校登入頁最多等",
|
|
209
|
+
"学校登录页的表单不明确(有几个密码框),没有自动填写:请在浏览器窗口完成机构登录": "學校登入頁的表單不明確(有幾個密碼框),沒有自動填寫:請在瀏覽器視窗完成機構登入",
|
|
195
210
|
"学校登录页的证书和之前记下的不一样,没有自动填写:请确认是学校的网站后,在浏览器窗口完成机构登录": "學校登入頁的證書和之前記下的不一樣,沒有自動填寫:請確認是學校的網站後,在瀏覽器視窗完成機構登入",
|
|
211
|
+
"学校登录页的证书有问题(过期或不受信任),没有自动填写:请确认是学校的网站后,在浏览器窗口完成机构登录": "學校登入頁的證書有問題(過期或不受信任),沒有自動填寫:請確認是學校的網站後,在瀏覽器視窗完成機構登入",
|
|
196
212
|
"学校登录页自动填写账号和密码,批量下载不用守着。": "學校登入頁自動填寫帳號和密碼,批次下載不用守著。",
|
|
197
213
|
"学校登录页自动填写账号,批量下载不用守着": "學校登入頁自動填寫帳號,批次下載不用守著",
|
|
198
214
|
"学校登录页要你本人操作(验证码、扫码或另一个账号),请在浏览器窗口完成": "學校登入頁要你本人操作(驗證碼、掃碼或另一個帳號),請在瀏覽器視窗完成",
|
|
@@ -202,6 +218,9 @@
|
|
|
202
218
|
"学校登录页要按顺序点选图中文字,请在浏览器窗口完成": "學校登入頁要按順序點選圖中文字,請在瀏覽器視窗完成",
|
|
203
219
|
"学校登录页要短信或动态验证码,请在浏览器窗口完成": "學校登入頁要短信或動態驗證碼,請在瀏覽器視窗完成",
|
|
204
220
|
"学校登录页要输入图片验证码,请在浏览器窗口完成": "學校登入頁要輸入圖片驗證碼,請在瀏覽器視窗完成",
|
|
221
|
+
"学校登录页需要扫码或短信验证,请在浏览器窗口完成。": "學校登入頁需要掃碼或短信驗證,請在瀏覽器視窗完成。",
|
|
222
|
+
"学校的 App": "學校的 App",
|
|
223
|
+
"学校网站的安全防护拦下了这次自动登录,请在浏览器窗口自己登录": "學校網站的安全防護攔下了這次自動登入,請在瀏覽器視窗自己登入",
|
|
205
224
|
"学校自动登录": "學校自動登入",
|
|
206
225
|
"学校订阅下载扩展": "學校訂閱下載擴展",
|
|
207
226
|
"学校说密码不对": "學校說密碼不對",
|
|
@@ -261,6 +280,7 @@
|
|
|
261
280
|
"已终止任务": "已終止任務",
|
|
262
281
|
"已终止任务:这一篇结束,剩下的不再下载": "已終止任務:這一篇結束,剩下的不再下載",
|
|
263
282
|
"已终止,未处理": "已終止,未處理",
|
|
283
|
+
"已自动填写并提交,但学校没有说账号是否正确(可能是学校服务器出错或网络问题):请在浏览器窗口检查,需要的话自己登录": "已自動填寫並提交,但學校沒有說帳號是否正確(可能是學校伺服器出錯或網路問題):請在瀏覽器視窗檢查,需要的話自己登入",
|
|
264
284
|
"已记录。当前是学校登录页,这是正常的一步,请在这里登录;如果确实不对,再点一次“跳到了无关页面”即可返回文章。": "已記錄。當前是學校登入頁,這是正常的一步,請在這裡登入;如果確實不對,再點一次「跳到了無關頁面」即可返回文章。",
|
|
265
285
|
"已记录页面并刷新": "已記錄頁面並刷新",
|
|
266
286
|
"已记录页面,已回到文章重新进入;也可以在浏览器里自己点到学校登录": "已記錄頁面,已回到文章重新進入;也可以在瀏覽器裡自己點到學校登入",
|
|
@@ -268,16 +288,20 @@
|
|
|
268
288
|
"已记录页面;已经回过一次文章,请在浏览器里自己点到学校登录": "已記錄頁面;已經回過一次文章,請在瀏覽器裡自己點到學校登入",
|
|
269
289
|
"已设为默认": "已設為預設",
|
|
270
290
|
"已读到,正在核对": "已讀到,正在核對",
|
|
291
|
+
"已跳过": "已跳過",
|
|
271
292
|
"已跳过本篇,进入下一篇": "已跳過本篇,進入下一篇",
|
|
272
293
|
"已转换(篇)": "已轉換(篇)",
|
|
273
294
|
"已达每小时上限": "已達每小時上限",
|
|
274
295
|
"已过期": "已過期",
|
|
275
296
|
"已钉住,点一下取消": "已釘住,點一下取消",
|
|
297
|
+
"已验证": "已驗證",
|
|
276
298
|
"巴巴多斯": "巴貝多",
|
|
277
299
|
"巴拿马": "巴拿馬",
|
|
278
300
|
"布基纳法索": "布吉納法索",
|
|
279
301
|
"希腊": "希臘",
|
|
280
302
|
"帕劳": "帕勞",
|
|
303
|
+
"并行": "平行",
|
|
304
|
+
"并行数越多,触发风控风险越高,建议合理设置": "平行數越多,觸發風控風險越高,建議合理設定",
|
|
281
305
|
"广东": "廣東",
|
|
282
306
|
"广西": "廣西",
|
|
283
307
|
"康涅狄格州": "康乃狄克州",
|
|
@@ -293,12 +317,13 @@
|
|
|
293
317
|
"待补全": "待補全",
|
|
294
318
|
"待适配": "待適配",
|
|
295
319
|
"得克萨斯州": "德克薩斯州",
|
|
320
|
+
"微信扫码": "微信掃碼",
|
|
296
321
|
"德国": "德國",
|
|
297
322
|
"怀俄明州": "懷俄明州",
|
|
298
323
|
"恢复默认": "恢復預設",
|
|
299
324
|
"意大利": "義大利",
|
|
300
|
-
"
|
|
301
|
-
"
|
|
325
|
+
"所学校已验证": "所學校已驗證",
|
|
326
|
+
"所学校未验证": "所學校未驗證",
|
|
302
327
|
"打开下载浏览器": "打開下載瀏覽器",
|
|
303
328
|
"打开失败:不是有效的 DOI": "打開失敗:不是有效的 DOI",
|
|
304
329
|
"打开失败:文件已被移走或删除": "打開失敗:檔案已被移走或刪除",
|
|
@@ -313,6 +338,7 @@
|
|
|
313
338
|
"打开自动登录": "打開自動登入",
|
|
314
339
|
"打开通知设置": "打開通知設定",
|
|
315
340
|
"扩展需要更新": "擴展需要更新",
|
|
341
|
+
"扫码登录": "掃碼登入",
|
|
316
342
|
"批量下载已停止,结果未确认": "批次下載已停止,結果未確認",
|
|
317
343
|
"找不到 paper-search 命令,请关掉窗口后重新打开设置": "找不到 paper-search 命令,請關掉視窗後重新打開設定",
|
|
318
344
|
"找不到安装文件": "找不到安裝檔案",
|
|
@@ -373,6 +399,7 @@
|
|
|
373
399
|
"未能切到下载浏览器,请从程序坞或任务栏打开": "未能切到下載瀏覽器,請從程式塢或任務欄打開",
|
|
374
400
|
"未能切到下载浏览器,请从程序坞打开": "未能切到下載瀏覽器,請從程式塢打開",
|
|
375
401
|
"未能激活进度窗口,请重试": "未能啟用進度視窗,請重試",
|
|
402
|
+
"未验证": "未驗證",
|
|
376
403
|
"本批前 3 篇都没转换完整,未再尝试": "本批前 3 篇都沒轉換完整,未再嘗試",
|
|
377
404
|
"机构 PDF 下载": "機構 PDF 下載",
|
|
378
405
|
"机构 PDF 批量下载": "機構 PDF 批次下載",
|
|
@@ -522,6 +549,7 @@
|
|
|
522
549
|
"登录成功,但这篇没有访问权限": "登入成功,但這篇沒有訪問權限",
|
|
523
550
|
"白俄罗斯": "白俄羅斯",
|
|
524
551
|
"看看要改哪里": "看看要改哪裡",
|
|
552
|
+
"短信登录": "短信登入",
|
|
525
553
|
"研究机构": "研究機構",
|
|
526
554
|
"确定": "確定",
|
|
527
555
|
"确认清除": "確認清除",
|
|
@@ -616,12 +644,18 @@
|
|
|
616
644
|
"请先填写邮箱;要删除请点“清除”": "請先填寫電子郵件;要刪除請點「清除」",
|
|
617
645
|
"请先激活 PaperSearch Pro": "請先啟用 PaperSearch Pro",
|
|
618
646
|
"请先粘贴 key;要删除请点“清除”": "請先粘貼 key;要刪除請點「清除」",
|
|
647
|
+
"请在浏览器扫码登录": "請在瀏覽器掃碼登入",
|
|
619
648
|
"请在浏览器窗口完成机构登录": "請在瀏覽器視窗完成機構登入",
|
|
620
649
|
"请在浏览器窗口选择学校并完成机构登录": "請在瀏覽器視窗選擇學校並完成機構登入",
|
|
621
650
|
"请填写密码": "請填寫密碼",
|
|
622
651
|
"请填写账号": "請填寫帳號",
|
|
652
|
+
"请完成扫码或短信验证": "請完成掃碼或短信驗證",
|
|
623
653
|
"请完成验证": "請完成驗證",
|
|
624
654
|
"请查看浏览器,可能需要手动操作": "請查看瀏覽器,可能需要手動操作",
|
|
655
|
+
"请用企业微信扫码": "請用企業微信掃碼",
|
|
656
|
+
"请用微信扫码": "請用微信掃碼",
|
|
657
|
+
"请用短信验证码登录": "請用短信驗證碼登入",
|
|
658
|
+
"请用钉钉扫码": "請用釘釘掃碼",
|
|
625
659
|
"请登录学校": "請登入學校",
|
|
626
660
|
"请输入学校名称": "請輸入學校名稱",
|
|
627
661
|
"请输入完整的绝对路径": "請輸入完整的絕對路徑",
|
|
@@ -657,6 +691,7 @@
|
|
|
657
691
|
"这个版本没有自动登录": "這個版本沒有自動登入",
|
|
658
692
|
"这个网址读不出 DOI,请改填 DOI(文章页上 doi.org/10. 开头的那串)": "這個網址讀不出 DOI,請改填 DOI(文章頁上 doi.org/10. 開頭的那串)",
|
|
659
693
|
"这些网站尚未正式支持 Markdown,内容不完整的未保存。如需支持,欢迎提 issue 或 PR。": "這些網站尚未正式支援 Markdown,內容不完整的未儲存。如需支援,歡迎提 issue 或 PR。",
|
|
694
|
+
"这所学校一小时内自动填写的次数已满,这次没有填写:请在浏览器窗口完成机构登录": "這所學校一小時內自動填寫的次數已滿,這次沒有填寫:請在瀏覽器視窗完成機構登入",
|
|
660
695
|
"这所学校已实测,会自动登录": "這所學校已實測,會自動登入",
|
|
661
696
|
"这所学校已摸底,会自动登录": "這所學校已摸底,會自動登入",
|
|
662
697
|
"这所学校所在的学术联盟还不支持": "這所學校所在的學術聯盟還不支援",
|
|
@@ -669,11 +704,14 @@
|
|
|
669
704
|
"这批没有暂未正式支持的网站": "這批沒有暫未正式支援的網站",
|
|
670
705
|
"这条路没走通,正在换路": "這條路沒走通,正在換路",
|
|
671
706
|
"这次没有用到账号密码:浏览器里还是登录状态,或学校网络直接有权限": "這次沒有用到帳號密碼:瀏覽器裡還是登入狀態,或學校網路直接有權限",
|
|
707
|
+
"这篇已不在等待选择": "這篇已不在等待選擇",
|
|
672
708
|
"进入机构访问": "進入機構訪問",
|
|
673
709
|
"连不上 Bright Data,请检查网络或代理": "連不上 Bright Data,請檢查網路或代理",
|
|
674
710
|
"连接 Bright Data 超时": "連接 Bright Data 超時",
|
|
675
711
|
"选择…": "選擇…",
|
|
712
|
+
"选择登录方式": "選擇登入方式",
|
|
676
713
|
"选错了学校": "選錯了學校",
|
|
714
|
+
"逐篇下载": "逐篇下載",
|
|
677
715
|
"通知以“Windows PowerShell”的名义发出:在“设置 › 系统 › 通知”里打开通知,并允许 Windows PowerShell。": "通知以「Windows PowerShell」的名義發出:在「設定 › 系統 › 通知」里打開通知,並允許 Windows PowerShell。",
|
|
678
716
|
"通知开关必须为开启或关闭": "通知開關必須為開啟或關閉",
|
|
679
717
|
"通知设置保存失败": "通知設定儲存失敗",
|
|
@@ -684,6 +722,8 @@
|
|
|
684
722
|
"重试": "重試",
|
|
685
723
|
"钉住": "釘住",
|
|
686
724
|
"钉住:鼠标移开也不收起": "釘住:滑鼠移開也不收起",
|
|
725
|
+
"钉钉": "釘釘",
|
|
726
|
+
"钉钉扫码": "釘釘掃碼",
|
|
687
727
|
"阿塞拜疆": "亞塞拜然",
|
|
688
728
|
"阿尔及利亚": "阿爾及利亞",
|
|
689
729
|
"阿尔巴尼亚": "阿爾巴尼亞",
|
|
@@ -693,7 +733,6 @@
|
|
|
693
733
|
"附录检查完成": "附錄檢查完成",
|
|
694
734
|
"附录没下载成功": "附錄沒下載成功",
|
|
695
735
|
"陕西": "陝西",
|
|
696
|
-
"需自己登录": "需自己登入",
|
|
697
736
|
"需要你在浏览器里处理": "需要你在瀏覽器裡處理",
|
|
698
737
|
"需要你处理": "需要你處理",
|
|
699
738
|
"需要处理时发系统通知": "需要處理時發系統通知",
|
|
@@ -1176,9 +1215,33 @@
|
|
|
1176
1215
|
"^换(.+)再试$",
|
|
1177
1216
|
"換$1再試"
|
|
1178
1217
|
],
|
|
1218
|
+
[
|
|
1219
|
+
"^(\\d+) 秒没有新数据$",
|
|
1220
|
+
"$1 秒沒有新資料"
|
|
1221
|
+
],
|
|
1179
1222
|
[
|
|
1180
1223
|
"^ClientKey 有效,余额 ([-0-9.,]+) 点$",
|
|
1181
1224
|
"ClientKey 有效,餘額 $1 點"
|
|
1225
|
+
],
|
|
1226
|
+
[
|
|
1227
|
+
"^选择 (.+) 的登录方式$",
|
|
1228
|
+
"選擇 $1 的登入方式"
|
|
1229
|
+
],
|
|
1230
|
+
[
|
|
1231
|
+
"^请输入不小于 (\\d+) 的整数$",
|
|
1232
|
+
"請輸入不小於 $1 的整數"
|
|
1233
|
+
],
|
|
1234
|
+
[
|
|
1235
|
+
"^并行,(\\d+) 家 × (\\d+) 篇$",
|
|
1236
|
+
"平行,$1 家 × $2 篇"
|
|
1237
|
+
],
|
|
1238
|
+
[
|
|
1239
|
+
"^同时下载 (\\d+) 篇$",
|
|
1240
|
+
"同時下載 $1 篇"
|
|
1241
|
+
],
|
|
1242
|
+
[
|
|
1243
|
+
"^同时 (\\d+) 篇$",
|
|
1244
|
+
"同時 $1 篇"
|
|
1182
1245
|
]
|
|
1183
1246
|
],
|
|
1184
1247
|
"chars": {
|
|
@@ -318,8 +318,12 @@ def resolve_backend(config: dict[str, Any] | None = None) -> str:
|
|
|
318
318
|
# batch_window: a serial batch keeps one browser window and tab from paper
|
|
319
319
|
# to paper (browser/batch_session.py); without it every paper opens and
|
|
320
320
|
# closes its own browser, as before.
|
|
321
|
+
# parallel_windows: a batch downloads several papers at once, each in a
|
|
322
|
+
# window of its own of the one browser, the other windows' drivers coming in
|
|
323
|
+
# on its remote-debugging port (并行下载, user 2026-11-29); without it a
|
|
324
|
+
# batch downloads one paper after another whatever the settings say.
|
|
321
325
|
BACKEND_CAPABILITIES: dict[str, frozenset[str]] = {
|
|
322
|
-
BACKEND_CHROME: frozenset({"batch_window"}),
|
|
326
|
+
BACKEND_CHROME: frozenset({"batch_window", "parallel_windows"}),
|
|
323
327
|
# The user's own running browser: one tab per paper until a batch there
|
|
324
328
|
# has been tried.
|
|
325
329
|
BACKEND_EGO: frozenset(),
|
|
@@ -460,7 +464,7 @@ def _relay_failure(log_path: Path, start: int) -> str:
|
|
|
460
464
|
return lines[-1][:200] if lines else "no log"
|
|
461
465
|
|
|
462
466
|
|
|
463
|
-
def _scope_to_own_tabs(context: Any) -> set:
|
|
467
|
+
def _scope_to_own_tabs(context: Any, existing: bool = False) -> set:
|
|
464
468
|
"""Make ``context`` show only the tabs this package opened (and their popups).
|
|
465
469
|
|
|
466
470
|
The user's own tabs live in the same browser context. Every place that
|
|
@@ -469,7 +473,7 @@ def _scope_to_own_tabs(context: Any) -> set:
|
|
|
469
473
|
returns this same object, so its class is swapped for a subclass whose
|
|
470
474
|
``pages`` and ``on("page")`` see only owned tabs.
|
|
471
475
|
"""
|
|
472
|
-
owned: set = set()
|
|
476
|
+
owned: set = set(base_pages(context) if existing else ())
|
|
473
477
|
base = type(context)
|
|
474
478
|
|
|
475
479
|
def track(page: Any) -> None:
|
|
@@ -505,9 +509,116 @@ def _scope_to_own_tabs(context: Any) -> set:
|
|
|
505
509
|
})
|
|
506
510
|
context.__class__ = scoped
|
|
507
511
|
context.new_page = new_page # type: ignore[method-assign]
|
|
512
|
+
context.paper_search_owned = owned
|
|
508
513
|
return owned
|
|
509
514
|
|
|
510
515
|
|
|
516
|
+
def base_pages(context: Any) -> list:
|
|
517
|
+
"""Every page of ``context``, its tabs scoped to ours or not (``_scope_to_own_tabs``)."""
|
|
518
|
+
for cls in type(context).__mro__:
|
|
519
|
+
if cls.__name__ != "EgoScopedContext" and "pages" in vars(cls):
|
|
520
|
+
return list(vars(cls)["pages"].fget(context))
|
|
521
|
+
return list(context.pages)
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
# ---------------------------------------------------------------------------
|
|
525
|
+
# 并行下载 (user, 2026-11-29): one Chrome, a window and a driver of its own for each paper downloading at once
|
|
526
|
+
# ---------------------------------------------------------------------------
|
|
527
|
+
#: Config keys the batch's first window launches Chrome with when its papers run at once (batch_session.py): a
|
|
528
|
+
#: remote-debugging port on 127.0.0.1 for the other windows' drivers, and the downloads' folder every driver shares.
|
|
529
|
+
PARALLEL_DOWNLOADS_KEY = "browser_parallel_downloads"
|
|
530
|
+
WINDOW_CONNECT_TIMEOUT_MS = 30_000
|
|
531
|
+
_ENDPOINT_WAIT_SEC = 10.0
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
def devtools_endpoint(user_data_dir: str | Path, since: float = 0.0) -> str:
|
|
535
|
+
"""The remote-debugging address the batch's Chrome wrote into its profile (DevToolsActivePort), once it is newer
|
|
536
|
+
than ``since``; waits up to a few seconds after a launch. "" when there is none."""
|
|
537
|
+
path = chrome_profile_dir(user_data_dir) / "DevToolsActivePort"
|
|
538
|
+
until = time.monotonic() + _ENDPOINT_WAIT_SEC
|
|
539
|
+
while True:
|
|
540
|
+
try:
|
|
541
|
+
if path.stat().st_mtime >= since - 1:
|
|
542
|
+
port = path.read_text().split()[0]
|
|
543
|
+
if port.isdigit():
|
|
544
|
+
return f"http://127.0.0.1:{port}"
|
|
545
|
+
except (OSError, IndexError):
|
|
546
|
+
pass
|
|
547
|
+
if time.monotonic() >= until:
|
|
548
|
+
return ""
|
|
549
|
+
time.sleep(0.1)
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
def _target_of(context: Any, page: Any) -> str:
|
|
553
|
+
"""A page's DevTools target id ("" when it cannot be read)."""
|
|
554
|
+
try:
|
|
555
|
+
session = context.new_cdp_session(page)
|
|
556
|
+
try:
|
|
557
|
+
return str(session.send("Target.getTargetInfo")["targetInfo"]["targetId"])
|
|
558
|
+
finally:
|
|
559
|
+
session.detach()
|
|
560
|
+
except Exception:
|
|
561
|
+
return ""
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
def open_window_page(context: Any, session: Any, timeout_sec: float = 15.0) -> Any:
|
|
565
|
+
"""A page in a window of its own, behind the window the user is in (a background tab would be slowed down by
|
|
566
|
+
Chrome: sliders, verification pictures and Cloudflare's check misbehave there; user, 2026-11-29). Found among the
|
|
567
|
+
context's pages by its target id: other windows' drivers open pages at the same time."""
|
|
568
|
+
before = {id(page) for page in base_pages(context)}
|
|
569
|
+
target = str(session.send("Target.createTarget", {"url": "about:blank", "newWindow": True, "background": True})["targetId"])
|
|
570
|
+
until = time.monotonic() + timeout_sec
|
|
571
|
+
while time.monotonic() < until:
|
|
572
|
+
for page in base_pages(context):
|
|
573
|
+
if id(page) not in before and _target_of(context, page) == target:
|
|
574
|
+
return page
|
|
575
|
+
before.add(id(page))
|
|
576
|
+
try:
|
|
577
|
+
context.wait_for_event("page", timeout=500)
|
|
578
|
+
except Exception:
|
|
579
|
+
pass
|
|
580
|
+
raise RuntimeError("the new window's page did not come")
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
def _windows_of_their_own(context: Any, owned: set) -> None:
|
|
584
|
+
"""``context.new_page()`` opens a window of its own and counts it as ours (``open_window_page``)."""
|
|
585
|
+
session = context.browser.new_browser_cdp_session() if context.browser is not None else None
|
|
586
|
+
open_page = context.new_page
|
|
587
|
+
|
|
588
|
+
def new_page(*args: Any, **kwargs: Any) -> Any:
|
|
589
|
+
if args or kwargs or session is None:
|
|
590
|
+
page = open_page(*args, **kwargs)
|
|
591
|
+
else:
|
|
592
|
+
page = open_window_page(context, session)
|
|
593
|
+
owned.add(page)
|
|
594
|
+
return page
|
|
595
|
+
|
|
596
|
+
context.new_page = new_page # type: ignore[method-assign]
|
|
597
|
+
context.paper_search_session = session
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
def connect_window(endpoint: str, downloads: str) -> tuple[Any, Any]:
|
|
601
|
+
"""Another window's driver on the batch's Chrome (``endpoint``, the first window's remote-debugging address):
|
|
602
|
+
(its driver, the browser's context as this driver sees it, scoped to the pages it opens; ``new_page`` opens a
|
|
603
|
+
window of its own). Every driver's downloads go to ``downloads`` (batch_session.shared_downloads): Chrome keeps one
|
|
604
|
+
folder for the profile, set by the driver that connected last. The driver stays connected until the batch ends:
|
|
605
|
+
one leaving resets the profile's downloads for every window."""
|
|
606
|
+
from patchright.sync_api import sync_playwright
|
|
607
|
+
|
|
608
|
+
pw = sync_playwright().start()
|
|
609
|
+
try:
|
|
610
|
+
browser = pw.chromium.connect_over_cdp(endpoint, timeout=WINDOW_CONNECT_TIMEOUT_MS)
|
|
611
|
+
context = browser.contexts[0]
|
|
612
|
+
owned = _scope_to_own_tabs(context)
|
|
613
|
+
browser.new_browser_cdp_session().send("Browser.setDownloadBehavior", {
|
|
614
|
+
"behavior": "allowAndName", "downloadPath": downloads, "eventsEnabled": True})
|
|
615
|
+
_windows_of_their_own(context, owned)
|
|
616
|
+
except Exception:
|
|
617
|
+
pw.stop()
|
|
618
|
+
raise
|
|
619
|
+
return pw, context
|
|
620
|
+
|
|
621
|
+
|
|
511
622
|
def _launch_ego_persistent(config: dict[str, Any] | None) -> Any:
|
|
512
623
|
"""The running ego's own context (the user's logins), scoped to our tabs."""
|
|
513
624
|
pw, browser = _connect_ego(config)
|
|
@@ -702,9 +813,15 @@ def _chrome_options(headless: bool, proxy: Any, args: list[str] | None,
|
|
|
702
813
|
switches.append(f"--lang={language}")
|
|
703
814
|
if language and not any(arg.startswith("--accept-lang=") for arg in switches):
|
|
704
815
|
switches.append(f"--accept-lang={accept_languages(language)}")
|
|
816
|
+
downloads = str((config or {}).get(PARALLEL_DOWNLOADS_KEY) or "")
|
|
817
|
+
if downloads and not any(arg.startswith("--remote-debugging-port") for arg in switches):
|
|
818
|
+
# 并行下载: the other windows' drivers come in on 127.0.0.1 (a port Chrome chooses).
|
|
819
|
+
switches.append("--remote-debugging-port=0")
|
|
705
820
|
opts: dict[str, Any] = {"executable_path": str(executable), "headless": headless, "args": switches,
|
|
706
821
|
# Without it the driver adds --no-sandbox, and Chrome shows a warning bar.
|
|
707
822
|
"chromium_sandbox": True}
|
|
823
|
+
if downloads:
|
|
824
|
+
opts["downloads_path"] = downloads
|
|
708
825
|
if proxy:
|
|
709
826
|
opts["proxy"] = proxy
|
|
710
827
|
if not headless:
|
|
@@ -760,7 +877,11 @@ def _chrome_persistent(user_data_dir: str, *, headless: bool, proxy: Any, args:
|
|
|
760
877
|
proxy = _proxy_from_config(config)
|
|
761
878
|
context = _launch_chrome_persistent(profile, headless, proxy, args, config)
|
|
762
879
|
_keep_session_cookies(context, profile, config)
|
|
763
|
-
if
|
|
880
|
+
if (config or {}).get(PARALLEL_DOWNLOADS_KEY):
|
|
881
|
+
# 并行下载: this driver sees the other windows' pages too; it keeps to its own, and opens windows, not tabs.
|
|
882
|
+
owned = _scope_to_own_tabs(context, existing=True)
|
|
883
|
+
_windows_of_their_own(context, owned)
|
|
884
|
+
elif not headless:
|
|
764
885
|
_open_tabs_in_background(context)
|
|
765
886
|
_reuse_startup_page(context)
|
|
766
887
|
return context
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"""One browser window and tab kept for a serial MCP batch, on its Playwright
|
|
2
2
|
worker thread. Used when the backend declares ``batch_window``
|
|
3
|
-
(browser/backend.py); only plain Playwright calls, no backend of its own.
|
|
3
|
+
(browser/backend.py); only plain Playwright calls, no backend of its own.
|
|
4
|
+
|
|
5
|
+
并行下载 (user, 2026-11-29): a batch downloading several papers at once has a
|
|
6
|
+
window for each, in the one Chrome (one profile, one school login), each driven
|
|
7
|
+
by a driver of its own on a thread of its own (``BatchThread``). The first
|
|
8
|
+
window launches Chrome as a serial batch does, with a remote-debugging port on
|
|
9
|
+
127.0.0.1 and a downloads' folder every driver shares (``shared_downloads``);
|
|
10
|
+
the others connect to it (``backend.connect_window``) and open a window of
|
|
11
|
+
their own. A window's driver sees only the pages it opened."""
|
|
4
12
|
import queue
|
|
13
|
+
import shutil
|
|
14
|
+
import tempfile
|
|
5
15
|
import threading
|
|
6
16
|
import time
|
|
17
|
+
from pathlib import Path
|
|
7
18
|
from concurrent.futures import Executor, Future
|
|
8
19
|
from contextvars import ContextVar
|
|
9
20
|
from urllib.parse import urlsplit
|
|
@@ -24,20 +35,43 @@ IDLE_POLL_SEC = 0.05
|
|
|
24
35
|
|
|
25
36
|
|
|
26
37
|
class BatchBrowser:
|
|
27
|
-
def __init__(self):
|
|
38
|
+
def __init__(self, window=0, first=None):
|
|
28
39
|
self.context = None
|
|
29
40
|
self.page = None
|
|
30
41
|
self.info = None
|
|
31
42
|
self.id = ""
|
|
32
43
|
#: The publisher's article page of the last paper, when that paper saved its PDF.
|
|
33
44
|
self.article_url = ""
|
|
45
|
+
#: 并行下载: this window's number (0, the first, launches Chrome) and the first window (for the others).
|
|
46
|
+
self.window = window
|
|
47
|
+
self.first = self if first is None else first
|
|
48
|
+
#: The first window: its batch runs papers at once (Chrome launched for other windows to connect to).
|
|
49
|
+
self.parallel = False
|
|
50
|
+
self.endpoint = ""
|
|
51
|
+
self.downloads = ""
|
|
52
|
+
self.ready = threading.Event()
|
|
53
|
+
self._driver = None # another window's own driver, connected until the batch ends
|
|
54
|
+
self._joined = "" # the first window's Chrome (its remote-debugging address) this one is connected to
|
|
34
55
|
|
|
35
56
|
def open(self, downloader, *, relaunch=""):
|
|
36
|
-
if self.
|
|
57
|
+
if self.window:
|
|
58
|
+
return self._open_another(downloader)
|
|
59
|
+
# Its window closed: a browser one after another opens again; the other windows' Chrome, still there, stays.
|
|
60
|
+
if self.context is not None and not self.context.pages and not (self.parallel and _connected(self.context)):
|
|
37
61
|
self.close()
|
|
38
62
|
if self.context is None:
|
|
63
|
+
if self.parallel:
|
|
64
|
+
self.downloads = self.downloads or tempfile.mkdtemp(prefix="papersearch-downloads-")
|
|
65
|
+
shared_downloads(self.downloads)
|
|
66
|
+
downloader.config[_backend().PARALLEL_DOWNLOADS_KEY] = self.downloads
|
|
67
|
+
started = time.time()
|
|
39
68
|
self.context = downloader._launch_context(relaunch=relaunch)
|
|
40
69
|
self.info = downloader.browser
|
|
70
|
+
if self.parallel:
|
|
71
|
+
from ..engine.batch_common import _resolve_profile_dir
|
|
72
|
+
|
|
73
|
+
self.endpoint = _backend().devtools_endpoint(_resolve_profile_dir(downloader.config, None), started)
|
|
74
|
+
self.ready.set()
|
|
41
75
|
else:
|
|
42
76
|
downloader.browser = self.info
|
|
43
77
|
ensure_enabled(self.context, downloader.config)
|
|
@@ -45,6 +79,31 @@ class BatchBrowser:
|
|
|
45
79
|
self.page = self.context.new_page()
|
|
46
80
|
return self.context
|
|
47
81
|
|
|
82
|
+
def _open_another(self, downloader):
|
|
83
|
+
"""A window after the first: its driver connected to the first window's Chrome, its page a window of its own.
|
|
84
|
+
Waits for the first window's Chrome while it starts."""
|
|
85
|
+
first = self.first
|
|
86
|
+
if not first.ready.wait(WINDOW_READY_SEC) or not first.endpoint or first.context is None:
|
|
87
|
+
raise RuntimeError("the batch's first window has no browser to join")
|
|
88
|
+
# Gone, or the first window started Chrome again (another school, its last sign-in forgotten): this one's
|
|
89
|
+
# Chrome closed with it. A paper going on with it failed at once as 浏览器被关闭 (user's Mac, 2026-11-29).
|
|
90
|
+
if self.context is not None and (not _connected(self.context) or self._joined != first.endpoint):
|
|
91
|
+
self.disconnect()
|
|
92
|
+
if self.context is None:
|
|
93
|
+
from . import watchdog
|
|
94
|
+
|
|
95
|
+
watchdog.install()
|
|
96
|
+
self._driver, self.context = _backend().connect_window(first.endpoint, first.downloads)
|
|
97
|
+
self._joined = first.endpoint
|
|
98
|
+
from .challenge.local.interaction import prepare_context
|
|
99
|
+
|
|
100
|
+
prepare_context(self.context)
|
|
101
|
+
downloader.browser = first.info
|
|
102
|
+
downloader._browser_start = {"window": self.window}
|
|
103
|
+
if self.page is None or self.page.is_closed():
|
|
104
|
+
self.page = self.context.new_page()
|
|
105
|
+
return self.context
|
|
106
|
+
|
|
48
107
|
def keep_session(self):
|
|
49
108
|
"""While the batch waits (the hourly limit the user set): the last paper's
|
|
50
109
|
article page, loaded again in the batch's tab, so the publisher's institutional
|
|
@@ -81,17 +140,30 @@ class BatchBrowser:
|
|
|
81
140
|
tab goes on answering. Patchright sends every request of a tab with an init script
|
|
82
141
|
through this process first, and a sync driver hears it only during a call of its
|
|
83
142
|
own: with no paper running, the school's login page did not move after 登录
|
|
84
|
-
(Windows, 2026-11-18).
|
|
85
|
-
|
|
86
|
-
|
|
143
|
+
(Windows, 2026-11-18).
|
|
144
|
+
|
|
145
|
+
A window with no page answers through its context: in a batch whose papers run at
|
|
146
|
+
once, a window whose paper is done and whose pages are closed keeps its driver until
|
|
147
|
+
the batch ends, and that driver hears the requests of every window opened after it
|
|
148
|
+
first. Sleeping instead, it held them: Wiley's papers in the windows opened after the
|
|
149
|
+
other publishers' windows fell idle never loaded (Windows, 2026-11-30: a new window's
|
|
150
|
+
Wiley article did not load in 60 s, and loaded in 0.3 s with the idle window answering)."""
|
|
151
|
+
page, context = self.page, self.context
|
|
152
|
+
if context is None:
|
|
87
153
|
time.sleep(IDLE_PASS_MS / 1000)
|
|
88
154
|
return
|
|
155
|
+
from patchright.sync_api import TimeoutError as Waited
|
|
156
|
+
|
|
89
157
|
from . import watchdog
|
|
90
158
|
|
|
91
159
|
try:
|
|
92
|
-
if not page.is_closed():
|
|
160
|
+
if page is not None and not page.is_closed():
|
|
93
161
|
page.wait_for_timeout(IDLE_PASS_MS)
|
|
94
162
|
return
|
|
163
|
+
context.wait_for_event("close", timeout=IDLE_PASS_MS)
|
|
164
|
+
return
|
|
165
|
+
except Waited:
|
|
166
|
+
return # its time answering is over
|
|
95
167
|
except Exception:
|
|
96
168
|
pass # the next paper finds the browser as it is and says so
|
|
97
169
|
finally:
|
|
@@ -106,13 +178,122 @@ class BatchBrowser:
|
|
|
106
178
|
page.close()
|
|
107
179
|
|
|
108
180
|
def close(self):
|
|
181
|
+
if self.window:
|
|
182
|
+
# Its pages only: its driver stays until the batch ends (``disconnect``), Chrome keeps the profile's
|
|
183
|
+
# downloads where the drivers share them only while every driver that set it is there.
|
|
184
|
+
for page in list(getattr(self.context, "pages", []) or []):
|
|
185
|
+
try:
|
|
186
|
+
if not page.is_closed():
|
|
187
|
+
page.close()
|
|
188
|
+
except Exception:
|
|
189
|
+
pass
|
|
190
|
+
self.page = None
|
|
191
|
+
return
|
|
109
192
|
context, self.context, self.page, self.info = self.context, None, None, None
|
|
193
|
+
self.ready.clear()
|
|
194
|
+
self.endpoint = ""
|
|
110
195
|
if context is not None:
|
|
111
196
|
context.close()
|
|
112
197
|
|
|
198
|
+
def disconnect(self):
|
|
199
|
+
"""Another window's driver leaves (the batch's end, or Chrome gone): its pages closed first."""
|
|
200
|
+
driver, self._driver = self._driver, None
|
|
201
|
+
try:
|
|
202
|
+
self.close()
|
|
203
|
+
finally:
|
|
204
|
+
self.context = self.page = None
|
|
205
|
+
if driver is not None:
|
|
206
|
+
try:
|
|
207
|
+
driver.stop()
|
|
208
|
+
except Exception:
|
|
209
|
+
pass
|
|
210
|
+
|
|
113
211
|
|
|
114
212
|
active_batch: ContextVar[BatchBrowser | None] = ContextVar("active_browser_batch", default=None)
|
|
115
213
|
|
|
214
|
+
#: How long a window after the first waits for the first one's Chrome to start.
|
|
215
|
+
WINDOW_READY_SEC = 180
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _backend():
|
|
219
|
+
from . import backend
|
|
220
|
+
|
|
221
|
+
return backend
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def _connected(context) -> bool:
|
|
225
|
+
try:
|
|
226
|
+
browser = context.browser
|
|
227
|
+
return browser is None or browser.is_connected()
|
|
228
|
+
except Exception:
|
|
229
|
+
return False
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
# The downloads' folders of the batches whose windows share one (``shared_downloads``).
|
|
233
|
+
_SHARED: list[Path] = []
|
|
234
|
+
_SHARED_LOCK = threading.Lock()
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def shared_downloads(folder) -> None:
|
|
238
|
+
"""Every window's downloads arrive in ``folder`` (Chrome keeps one downloads' folder for the profile): a driver
|
|
239
|
+
whose own folder lacks a download takes it from there by its name (Playwright names each by its id). Without
|
|
240
|
+
this a window's PDF was saved empty (Mac, 2026-11-29: the second driver's connection took the profile's
|
|
241
|
+
downloads to its own folder)."""
|
|
242
|
+
with _SHARED_LOCK:
|
|
243
|
+
if Path(folder) not in _SHARED:
|
|
244
|
+
_SHARED.append(Path(folder))
|
|
245
|
+
_share_downloads()
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def forget_downloads(folder) -> None:
|
|
249
|
+
"""The batch is over: its folder goes."""
|
|
250
|
+
with _SHARED_LOCK:
|
|
251
|
+
if Path(folder) in _SHARED:
|
|
252
|
+
_SHARED.remove(Path(folder))
|
|
253
|
+
shutil.rmtree(folder, ignore_errors=True)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def _shared_copy(found) -> Path | None:
|
|
257
|
+
"""Where a finished download is when not at ``found`` (its driver's own folder): a shared folder's file of its
|
|
258
|
+
name; None when it is where its driver put it."""
|
|
259
|
+
try:
|
|
260
|
+
here = Path(found)
|
|
261
|
+
if here.is_file() and here.stat().st_size:
|
|
262
|
+
return None
|
|
263
|
+
except (OSError, TypeError, ValueError):
|
|
264
|
+
return None
|
|
265
|
+
with _SHARED_LOCK:
|
|
266
|
+
folders = list(_SHARED)
|
|
267
|
+
for folder in folders:
|
|
268
|
+
candidate = folder / here.name
|
|
269
|
+
if candidate.is_file():
|
|
270
|
+
return candidate
|
|
271
|
+
return None
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def _share_downloads() -> None:
|
|
275
|
+
from patchright.sync_api._generated import Download
|
|
276
|
+
|
|
277
|
+
if getattr(Download, "_papersearch_shared", False):
|
|
278
|
+
return
|
|
279
|
+
original_path, original_save = Download.path, Download.save_as
|
|
280
|
+
|
|
281
|
+
def path(self):
|
|
282
|
+
found = original_path(self)
|
|
283
|
+
return _shared_copy(found) or found
|
|
284
|
+
|
|
285
|
+
def save_as(self, target):
|
|
286
|
+
shared = _shared_copy(original_path(self)) # waits for the download to finish, as Playwright's does
|
|
287
|
+
if shared is None:
|
|
288
|
+
return original_save(self, target)
|
|
289
|
+
Path(target).parent.mkdir(parents=True, exist_ok=True)
|
|
290
|
+
shutil.copyfile(shared, target)
|
|
291
|
+
return None
|
|
292
|
+
|
|
293
|
+
Download.path = path
|
|
294
|
+
Download.save_as = save_as
|
|
295
|
+
Download._papersearch_shared = True
|
|
296
|
+
|
|
116
297
|
|
|
117
298
|
class BatchThread(Executor):
|
|
118
299
|
"""The batch's one browser thread: runs its jobs in order, and with none waiting calls
|