papersearch 0.7.2 → 0.7.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/dist/capabilities/download/batch/batch.d.ts.map +1 -1
- package/dist/capabilities/download/batch/batch.js +297 -14
- package/dist/capabilities/download/batch/batch.js.map +1 -1
- package/dist/capabilities/download/batch/batchFolder.js +1 -1
- package/dist/capabilities/download/batch/batchFolder.js.map +1 -1
- package/dist/capabilities/download/batch/batchSummary.js +1 -1
- package/dist/capabilities/download/batch/batchSummary.js.map +1 -1
- package/dist/capabilities/download/batch/networkLoss.d.ts +1 -1
- package/dist/capabilities/download/batch/networkLoss.js +1 -1
- package/dist/capabilities/download/content/markdown/shortfall.js +5 -5
- package/dist/capabilities/download/content/markdown/shortfall.js.map +1 -1
- package/dist/infrastructure/runlog/failureClass.d.ts +16 -9
- package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
- package/dist/infrastructure/runlog/failureClass.js +64 -54
- package/dist/infrastructure/runlog/failureClass.js.map +1 -1
- package/dist/infrastructure/school/SchoolAttempt.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolAttempt.js +61 -56
- package/dist/infrastructure/school/SchoolAttempt.js.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.d.ts +6 -2
- package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -1
- package/dist/infrastructure/school/SchoolMcpClient.js +14 -3
- package/dist/infrastructure/school/SchoolMcpClient.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 +10 -3
- package/dist/infrastructure/school/types.d.ts.map +1 -1
- package/dist/management/failures/index.d.ts +5 -2
- package/dist/management/failures/index.d.ts.map +1 -1
- package/dist/management/failures/index.js +21 -4
- package/dist/management/failures/index.js.map +1 -1
- package/package.json +1 -1
- package/school/paper_search_school/adapters/base.py +4 -0
- package/school/paper_search_school/adapters/oup/__init__.py +20 -0
- package/school/paper_search_school/adapters/sage/__init__.py +4 -1
- package/school/paper_search_school/adapters/taylor_francis/__init__.py +3 -0
- package/school/paper_search_school/adapters/thieme/__init__.py +4 -2
- package/school/paper_search_school/assets/capsule.html +125 -49
- package/school/paper_search_school/assets/capsule_en.json +32 -54
- package/school/paper_search_school/assets/capsule_fr.json +32 -54
- package/school/paper_search_school/assets/capsule_ja.json +32 -54
- package/school/paper_search_school/assets/capsule_ko.json +32 -54
- package/school/paper_search_school/assets/capsule_zh-Hant.json +27 -53
- package/school/paper_search_school/cold_start.py +22 -11
- package/school/paper_search_school/engine/access_rules.py +3 -2
- package/school/paper_search_school/engine/batch.py +12 -4
- package/school/paper_search_school/engine/batch_access.py +21 -9
- package/school/paper_search_school/engine/batch_capture.py +1 -1
- package/school/paper_search_school/engine/batch_institution.py +130 -29
- package/school/paper_search_school/engine/bridge.py +16 -3
- package/school/paper_search_school/engine/router.py +2 -1
- package/school/paper_search_school/orchestrator.py +44 -18
- package/school/paper_search_school/progress_reporter.py +17 -8
- package/school/paper_search_school/progress_view.py +1 -1
- package/school/paper_search_school/publishers/builtin/sage.json +4 -2
- package/school/paper_search_school/publishers/builtin/thieme.json +3 -1
- package/school/paper_search_school/school_switch.py +34 -52
- package/school/paper_search_school/server.py +10 -8
- package/skills/paper-search/SKILL.md +1 -1
- package/skills/paper-search/references/browser-download.md +7 -9
- package/skills/paper-search/references/publisher-support.md +2 -2
|
@@ -98,9 +98,11 @@ class InstitutionMixin:
|
|
|
98
98
|
here = str(getattr(page, "url", "") or "")
|
|
99
99
|
if self._school_choices_here(result, here) >= self.SCHOOL_CHOICE_REPEATS:
|
|
100
100
|
return self._after_repeated_school_choice(page, result, here)
|
|
101
|
-
# The OpenAthens wayfinder goes straight to the school's entity
|
|
102
|
-
#
|
|
103
|
-
|
|
101
|
+
# The OpenAthens wayfinder goes straight to the school's entity, also for a federation's school the
|
|
102
|
+
# publisher sends there (LWW's Ovid, Windows 2026-11-22): its search took 40 s, and a school the wayfinder
|
|
103
|
+
# remembered ("Access through <another school>") left the login waiting a minute. The entityID was what
|
|
104
|
+
# its search came to anyway, its CARSI sign-in beside its library's OpenAthens account.
|
|
105
|
+
if self._select_openathens_wayfinder(page, result):
|
|
104
106
|
return True
|
|
105
107
|
# Everything except human verification and the user's credentials is
|
|
106
108
|
# automated once an institution is configured: a remembered
|
|
@@ -299,8 +301,18 @@ class InstitutionMixin:
|
|
|
299
301
|
return select, hits[0][0], hits[0][1]
|
|
300
302
|
return None
|
|
301
303
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
+
# A list of societies to sign in through ("Select your society"; BMJ's #society-login-select, Windows 2026-11-22):
|
|
305
|
+
# not a list of schools, whatever its names ("... College of Sport and Exercise Physicians") or values (addresses).
|
|
306
|
+
_SOCIETY_LIST = re.compile(r"societ", re.I)
|
|
307
|
+
|
|
308
|
+
@classmethod
|
|
309
|
+
def _society_list(cls, select: dict) -> bool:
|
|
310
|
+
options = [o for o in select.get("options") or () if isinstance(o, (list, tuple)) and len(o) == 2]
|
|
311
|
+
return bool(cls._SOCIETY_LIST.search(str(select.get("name") or ""))
|
|
312
|
+
or (options and cls._SOCIETY_LIST.search(str(options[0][1]))))
|
|
313
|
+
|
|
314
|
+
@classmethod
|
|
315
|
+
def _filled_lists(cls, lists: Any, federation: dict) -> dict:
|
|
304
316
|
"""Filled school lists, not the header's journal/language/search lists.
|
|
305
317
|
|
|
306
318
|
Only positive institution evidence can establish that a school is
|
|
@@ -309,7 +321,7 @@ class InstitutionMixin:
|
|
|
309
321
|
"""
|
|
310
322
|
school = re.compile(r"institut|school|universit|\buniv\b|college|organi[sz]ation|\bidp\b|大学|学院|研究院", re.I)
|
|
311
323
|
return {str(s.get("name")): list(s.get("options") or ()) for s in lists or ()
|
|
312
|
-
if s.get("i") != federation.get("i") and len(s.get("options") or ()) > 1
|
|
324
|
+
if s.get("i") != federation.get("i") and len(s.get("options") or ()) > 1 and not cls._society_list(s)
|
|
313
325
|
and (school.search(str(s.get("name") or "")) or any(
|
|
314
326
|
school.search(str(o[1])) for o in s.get("options") or ()
|
|
315
327
|
if isinstance(o, (list, tuple)) and len(o) == 2))}
|
|
@@ -446,8 +458,9 @@ class InstitutionMixin:
|
|
|
446
458
|
|
|
447
459
|
def _entity_lists(self, lists: Any) -> dict:
|
|
448
460
|
return {str(s.get("name")): list(s.get("options") or ()) for s in lists or ()
|
|
449
|
-
if
|
|
450
|
-
|
|
461
|
+
if not self._society_list(s)
|
|
462
|
+
and sum(1 for o in s.get("options") or () if isinstance(o, (list, tuple)) and len(o) == 2
|
|
463
|
+
and self._ENTITY_VALUE.match(str(o[0]))) >= self.ENTITY_LIST_MIN}
|
|
451
464
|
|
|
452
465
|
def _check_entity_list(self, page: Any, result: DownloadResult, lists: list[dict], url: str) -> None:
|
|
453
466
|
"""A filled list of schools by entityID without the configured school, the same a
|
|
@@ -637,16 +650,17 @@ class InstitutionMixin:
|
|
|
637
650
|
|
|
638
651
|
_ENTRY_SELECTOR = "li, a, button, [role=option], [role=button]"
|
|
639
652
|
|
|
640
|
-
# An entry's own identifiers: its link
|
|
641
|
-
#
|
|
642
|
-
# entry (Elsevier keeps each result's entityID in a hidden
|
|
653
|
+
# An entry's own identifiers: its link, its onclick (JAMA's search entries name their entityID
|
|
654
|
+
# only there, 2026-11-17) and data attributes, and the hidden fields and data attributes of the
|
|
655
|
+
# elements around it that hold no other entry (Elsevier keeps each result's entityID in a hidden
|
|
656
|
+
# field, 2026-10-31).
|
|
643
657
|
_ENTRIES_JS = """(sel) => {
|
|
644
658
|
const all = [...document.querySelectorAll(sel)];
|
|
645
659
|
const visible = el => el.getClientRects().length > 0 && getComputedStyle(el).visibility !== 'hidden';
|
|
646
660
|
const cands = all.filter(visible);
|
|
647
661
|
const inner = cands.filter(el => !cands.some(o => o !== el && el.contains(o)));
|
|
648
662
|
const ids = el => {
|
|
649
|
-
const out = [el.href || el.getAttribute('href') || ''];
|
|
663
|
+
const out = [el.href || el.getAttribute('href') || '', el.getAttribute('onclick') || ''];
|
|
650
664
|
for (let row = el, up = 0; row && up < 4; up++) {
|
|
651
665
|
for (const a of row.attributes || []) if (a.name.startsWith('data-')) out.push(a.value);
|
|
652
666
|
for (const h of row.querySelectorAll('input[type=hidden]')) out.push(h.value || '');
|
|
@@ -661,10 +675,47 @@ class InstitutionMixin:
|
|
|
661
675
|
.filter(it => it.t && it.t.length <= 160);
|
|
662
676
|
}"""
|
|
663
677
|
|
|
678
|
+
def _users_own_search(self, page: Any) -> bool:
|
|
679
|
+
"""A shown institution search box holding text the program did not type: the user is choosing."""
|
|
680
|
+
queries = {" ".join(q.split()).lower() for q in self._search_queries(list(self._institution_names()))}
|
|
681
|
+
for selector in self._INSTITUTION_INPUTS: # the institution boxes only, the page not read for them
|
|
682
|
+
try:
|
|
683
|
+
boxes = page.locator(selector).all()
|
|
684
|
+
if not isinstance(boxes, list):
|
|
685
|
+
continue
|
|
686
|
+
for box in boxes[:4]:
|
|
687
|
+
if box.is_visible(timeout=300) is not True:
|
|
688
|
+
continue
|
|
689
|
+
value = " ".join(str(box.input_value(timeout=800) or "").split()).lower()
|
|
690
|
+
if value and value not in queries:
|
|
691
|
+
return True
|
|
692
|
+
except Exception as exc:
|
|
693
|
+
if not _is_browser_error(exc):
|
|
694
|
+
raise
|
|
695
|
+
return False
|
|
696
|
+
|
|
664
697
|
def _institution_entry_score(self, entry: dict, entity_id: str) -> int:
|
|
665
|
-
|
|
698
|
+
ids = str(entry.get("ids") or "")
|
|
699
|
+
if self._carries_entity_id(ids, entity_id):
|
|
666
700
|
return 4
|
|
667
|
-
|
|
701
|
+
score = self._institution_match_score(entry.get("t", ""))
|
|
702
|
+
if score >= 2 and self._names_another_sign_in(ids, entity_id):
|
|
703
|
+
return 1 # the school's name, another sign-in than the saved one: not clicked
|
|
704
|
+
return score
|
|
705
|
+
|
|
706
|
+
# The sign-in an entry names: Atypon's /action/ssostart?idp=<entityID>, SeamlessAccess's
|
|
707
|
+
# saveInstitution(this, '<entityID>') in its onclick (JAMA's search, 2026-11-17).
|
|
708
|
+
_ENTRY_IDP = re.compile(r"[?&]idp=([^&#\s\"']+)|saveInstitution\(\s*[^,()]*,\s*['\"]([^'\"]+)['\"]", re.I)
|
|
709
|
+
|
|
710
|
+
def _names_another_sign_in(self, text: str, entity_id: str) -> bool:
|
|
711
|
+
"""An entry's link names an identity provider, and not the school's saved one (Sage listed a test school with
|
|
712
|
+
idp=<its library's OpenAthens entityID>, which sent the login straight back to the article, while its saved
|
|
713
|
+
Shibboleth entityID signs in elsewhere; Windows 2026-11-22)."""
|
|
714
|
+
if not entity_id or not text:
|
|
715
|
+
return False
|
|
716
|
+
named = {unquote(unquote(link or saved)).strip().lower() for link, saved in self._ENTRY_IDP.findall(text)}
|
|
717
|
+
named = {value for value in named if value.startswith(("https://", "http://", "urn:"))}
|
|
718
|
+
return bool(named) and entity_id.strip().lower() not in named
|
|
668
719
|
|
|
669
720
|
def _name_residue(self, text: str) -> str | None:
|
|
670
721
|
"""What is left of ``text`` (lower case) once the school's names are taken
|
|
@@ -778,6 +829,11 @@ class InstitutionMixin:
|
|
|
778
829
|
recorded, url = unquote(str(recorded or "")), unquote(str(url or ""))
|
|
779
830
|
return len(recorded) > 10 and url.startswith(recorded)
|
|
780
831
|
|
|
832
|
+
def _searched_here(self, result: DownloadResult, url: str) -> bool:
|
|
833
|
+
"""The school's name was typed into a search on the page at ``url``."""
|
|
834
|
+
return any(e.get("state") == "auto_institution_search"
|
|
835
|
+
and self._same_address(str(e.get("detail", "")).split(" @ ", 1)[-1], url) for e in result.events)
|
|
836
|
+
|
|
781
837
|
def _search_queries(self, names: list[str]) -> list[str]:
|
|
782
838
|
"""The school's names to search by (straight apostrophes): its English name
|
|
783
839
|
first, then the others in Latin letters, its shared login entry's own name
|
|
@@ -965,11 +1021,12 @@ class InstitutionMixin:
|
|
|
965
1021
|
|
|
966
1022
|
An entry carrying the school's entityID wins (several such entries are
|
|
967
1023
|
the same school); otherwise the entry naming it. Only innermost
|
|
968
|
-
candidates count (a list item and its link are one entry).
|
|
969
|
-
with the same best name score
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
1024
|
+
candidates count (a list item and its link are one entry). Several entries
|
|
1025
|
+
with the same best name score are taken one after another, the orchestrator's
|
|
1026
|
+
``institution_entry_turn`` saying which (user, 2026-11-22); only partial
|
|
1027
|
+
matches are left to the user; the same text with the same link (an actual
|
|
1028
|
+
link, not two buttons) is one school (SAMS Sigma's "Recently Chosen" above
|
|
1029
|
+
its full list, 2026-11-01).
|
|
973
1030
|
"""
|
|
974
1031
|
try:
|
|
975
1032
|
items = self._listed_entries(page)
|
|
@@ -980,6 +1037,17 @@ class InstitutionMixin:
|
|
|
980
1037
|
entity_id = self._entity_id()
|
|
981
1038
|
|
|
982
1039
|
scored = [(self._institution_entry_score(it, entity_id), it) for it in items if isinstance(it, dict)]
|
|
1040
|
+
# The school's name with another of its sign-ins than the saved one (its library's OpenAthens account beside
|
|
1041
|
+
# its CARSI sign-in: all Sage and JAMA list of a test school, its login page asking for a picture code; Windows
|
|
1042
|
+
# 2026-11-22). On such a page an entry by the school's name carrying nothing to tell its sign-in by may be that
|
|
1043
|
+
# one too (Sage's "Recent institution": what SeamlessAccess kept of an earlier choice of it): not clicked either.
|
|
1044
|
+
another = [it for score, it in scored if score == 1 and self._names_another_sign_in(str(it.get("ids") or ""), entity_id)
|
|
1045
|
+
and self._institution_match_score(str(it.get("t") or "")) >= 2]
|
|
1046
|
+
if another:
|
|
1047
|
+
result._another_sign_in_at = url
|
|
1048
|
+
another_here = bool(another) or self._same_address(str(getattr(result, "_another_sign_in_at", "") or ""), url)
|
|
1049
|
+
if another_here and not any(score == 4 for score, _ in scored):
|
|
1050
|
+
scored = [(1 if score >= 2 and not str(it.get("ids") or "").strip() else score, it) for score, it in scored]
|
|
983
1051
|
if self.federation is not None:
|
|
984
1052
|
# An entry its publisher marks as signing in no school (Elsevier's
|
|
985
1053
|
# entries carry their route: IP, VPN or a work email, no entityID) is
|
|
@@ -988,15 +1056,18 @@ class InstitutionMixin:
|
|
|
988
1056
|
and self.adapter.institution_entry_signs_in(unquote(str(it.get("ids") or ""))) is False]
|
|
989
1057
|
if without:
|
|
990
1058
|
scored = [(score, it) for score, it in scored if not any(it is w for w in without)]
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
result
|
|
999
|
-
|
|
1059
|
+
# Listed only so, the school has no route here: 没权限, another saved school tried at a batch's end.
|
|
1060
|
+
if (without or another_here) and not any(score >= 2 for score, _ in scored):
|
|
1061
|
+
if not self._list_settled(result, items):
|
|
1062
|
+
return False # the search may still be adding entries
|
|
1063
|
+
if getattr(result, "_institution_not_listed", False) is not True: # once, not every pass
|
|
1064
|
+
count = len(without) or max(len(another), 1)
|
|
1065
|
+
kind = "without a school sign-in" if without else "with another of its sign-ins"
|
|
1066
|
+
self._event(result, "auto_institution_not_found",
|
|
1067
|
+
f"{self.institution_query} (listed only {kind}: "
|
|
1068
|
+
f"{count} entr{'y' if count == 1 else 'ies'}) @ {url}")
|
|
1069
|
+
result._institution_not_listed = True
|
|
1070
|
+
return False
|
|
1000
1071
|
top = max([score for score, _ in scored] or [0])
|
|
1001
1072
|
best = [it for score, it in scored if score == top]
|
|
1002
1073
|
if top < 2 and self.federation is not None and self._search_lists_no_school(page, result, url, scored):
|
|
@@ -1018,8 +1089,27 @@ class InstitutionMixin:
|
|
|
1018
1089
|
# configured sign-in, by its entityID, the one this browser keeps the session of.
|
|
1019
1090
|
if top >= 2 and len(best) > 1 and self._select_openathens_wayfinder(page, result):
|
|
1020
1091
|
return True
|
|
1092
|
+
if top < 2 or len(best) < 2 or self._users_own_search(page):
|
|
1093
|
+
return False # the user typing a search of their own chooses (typed input is never replaced)
|
|
1094
|
+
# Several entries by the school's name, nothing else to tell them apart by (JAMA's search: a test school's name
|
|
1095
|
+
# two or three times, its CARSI sign-in and its library's proxy, Windows 2026-11-22): one after another in
|
|
1096
|
+
# the page's order, the next when the one before did not do (user, 2026-11-18 and 2026-11-22; the turn is
|
|
1097
|
+
# the orchestrator's, ``institution_entry_turn``).
|
|
1098
|
+
turn = int(self.config.get("institution_entry_turn") or 0)
|
|
1099
|
+
result._same_name_entries = len(best)
|
|
1100
|
+
if turn >= len(best):
|
|
1101
|
+
return False
|
|
1102
|
+
target = best[turn]
|
|
1103
|
+
self._event(result, "institution_same_name_choice",
|
|
1104
|
+
f"{turn + 1}/{len(best)}: {str(target.get('t') or '')[:60]} @ {url[:200]}")
|
|
1105
|
+
else:
|
|
1106
|
+
target = best[0]
|
|
1107
|
+
if (top in (2, 3) and entity_id and not str(target.get("ids") or "").strip()
|
|
1108
|
+
and self._searched_here(result, url) and not self._list_settled(result, items)):
|
|
1109
|
+
# An entry by the school's name carrying nothing to tell its sign-in by, where its name was searched: taken
|
|
1110
|
+
# once the list has settled, the search's own entries (each with its sign-in) shown by then (Sage's "Recent
|
|
1111
|
+
# institution" was clicked a second before its search showed that entry's other sign-in, Windows 2026-11-22).
|
|
1021
1112
|
return False
|
|
1022
|
-
target = best[0]
|
|
1023
1113
|
before = str(getattr(page, "url", "") or "")
|
|
1024
1114
|
try:
|
|
1025
1115
|
marked = page.evaluate("""([sel, idx]) => {
|
|
@@ -1233,6 +1323,17 @@ class InstitutionMixin:
|
|
|
1233
1323
|
label = re.sub(r"^\s*access through\s*", "", candidate["text"], flags=re.I)
|
|
1234
1324
|
entries.append((self._institution_match_score(label), label,
|
|
1235
1325
|
page.locator(f'[data-paper-search-remembered="{candidate["i"]}"]')))
|
|
1326
|
+
# A remembered entry whose link names another sign-in than the school's saved one: not clicked (Sage's
|
|
1327
|
+
# "Access through <the school>", idp=.../entity, sent the login straight back, Windows 2026-11-22).
|
|
1328
|
+
def link_of(entry: Any) -> str:
|
|
1329
|
+
try:
|
|
1330
|
+
return str(entry.get_attribute("href", timeout=1_000) or "")
|
|
1331
|
+
except Exception as exc:
|
|
1332
|
+
if not _is_browser_error(exc):
|
|
1333
|
+
raise
|
|
1334
|
+
return ""
|
|
1335
|
+
entries = [(1 if score >= 2 and self._names_another_sign_in(link_of(entry), self._entity_id()) else score,
|
|
1336
|
+
label, entry) for score, label, entry in entries]
|
|
1236
1337
|
top = max((score for score, _, _ in entries), default=0)
|
|
1237
1338
|
best = [(label, entry) for score, label, entry in entries if score == top]
|
|
1238
1339
|
if top >= 2 and len(best) == 1:
|
|
@@ -74,6 +74,9 @@ _FAILURE_KINDS = {
|
|
|
74
74
|
"doi_not_registered": ("doi_not_registered", "review_publisher_error"),
|
|
75
75
|
# A site without a publisher profile: the shared rules found no institution entry.
|
|
76
76
|
"generic_institution_entry_missing": ("generic_institution_entry_missing", "review_publisher_profiles"),
|
|
77
|
+
# A publisher with rules of its own: its article page showed no login entry the rules found
|
|
78
|
+
# (reported as download_failed until 2026-11-22, "原因不明"; Thieme's Thrombosis and Haemostasis).
|
|
79
|
+
"publisher_institution_entry_missing": ("publisher_institution_entry_missing", "review_browser"),
|
|
77
80
|
# The site's page shows no way to any school's login (an open-access site, one with personal
|
|
78
81
|
# accounts only): no school login was started (user, 2026-11-18).
|
|
79
82
|
"no_institution_entry": ("no_institution_entry", ""),
|
|
@@ -352,7 +355,9 @@ def _try_builtin_institutional(
|
|
|
352
355
|
remembered = entitlements.decision_for(doi, publisher_name, identity=identity)
|
|
353
356
|
except Exception:
|
|
354
357
|
remembered = None
|
|
355
|
-
|
|
358
|
+
# The user's marks were made with the default school: another one's visit is not skipped by them (没权限时换下一所学校).
|
|
359
|
+
from .. import school_switch
|
|
360
|
+
if remembered and remembered.get("decision") == "skip" and not config.get(school_switch.MARKS_OFF):
|
|
356
361
|
log.info(" [Institutional] Skipped: %s marked as no access", remembered.get("key"))
|
|
357
362
|
return {"success": False, "identifier": doi, "doi": doi, "source": "institutional:entitlement_memory",
|
|
358
363
|
"error_type": "no_entitlement", "reason": "user_marked_no_entitlement",
|
|
@@ -397,6 +402,8 @@ def _try_builtin_institutional(
|
|
|
397
402
|
failure["supplements"] = result["supplements"]
|
|
398
403
|
if isinstance(result.get("fulltext_page"), dict):
|
|
399
404
|
failure["fulltext_page"] = result["fulltext_page"]
|
|
405
|
+
if isinstance(result.get("same_name_entries"), int):
|
|
406
|
+
failure["same_name_entries"] = result["same_name_entries"]
|
|
400
407
|
if failure["error_type"] in _LOGIN_FAILURE_CODES:
|
|
401
408
|
failure.update(reason=failure["error_type"], action="review_browser")
|
|
402
409
|
if (result.get("error_type") == "paywall"
|
|
@@ -428,13 +435,16 @@ def _try_builtin_institutional(
|
|
|
428
435
|
denial = next((f for f in failures if f.get("reason_code") ==
|
|
429
436
|
"institution_pdf_entitlement_missing"), None)
|
|
430
437
|
primary = next((f for code in ("source_exception", "unsupported_platform", "article_not_yet_published",
|
|
431
|
-
"generic_institution_entry_missing", "
|
|
438
|
+
"generic_institution_entry_missing", "publisher_institution_entry_missing",
|
|
439
|
+
"no_institution_entry",
|
|
432
440
|
"publisher_content_error", "access_blocked", *_LOGIN_FAILURE_CODES,
|
|
433
441
|
"download_timeout")
|
|
434
442
|
for f in failures if f["error_type"] == code), denial or failures[-1])
|
|
435
443
|
result = {"success": False, "identifier": doi, "doi": doi, "source": "institutional",
|
|
436
444
|
"error_type": primary["error_type"], "reason": primary["reason"],
|
|
437
|
-
"action": primary["action"], "source_failures": failures
|
|
445
|
+
"action": primary["action"], "source_failures": failures,
|
|
446
|
+
**({"same_name_entries": entries} if (entries := max((f.get("same_name_entries") or 0
|
|
447
|
+
for f in failures), default=0)) > 1 else {})}
|
|
438
448
|
if primary["error_type"] == "access_blocked":
|
|
439
449
|
_remember_blocked_journal(doi, identity)
|
|
440
450
|
if (primary["error_type"] == "institution_federation_unavailable" and manual_school
|
|
@@ -823,6 +833,9 @@ def _try_browser_batch_download(
|
|
|
823
833
|
failure = {"success": False, "identifier": doi, "source": "institutional:browser",
|
|
824
834
|
"error_type": error_type, "reason": error_type, "action": action,
|
|
825
835
|
"artifacts": _browser_artifacts(result, profile)}
|
|
836
|
+
if int(getattr(result, "_same_name_entries", 0) or 0) > 1:
|
|
837
|
+
# The school's entries by one name, one chosen this time: the orchestrator takes the next if it did not do.
|
|
838
|
+
failure["same_name_entries"] = int(result._same_name_entries)
|
|
826
839
|
if supplements_mode in ("with", "only"):
|
|
827
840
|
failure["supplements"] = result.supplements
|
|
828
841
|
if getattr(result, "fulltext_page", None) and reason_code != "institution_pdf_entitlement_missing" \
|
|
@@ -215,7 +215,8 @@ def is_pdf_candidate_url(profile: PublisherProfile, url: str) -> bool:
|
|
|
215
215
|
def is_thieme_article_pdf_url(url: str, doi: str = "") -> bool:
|
|
216
216
|
"""Exclude account/reset URLs that merely carry a PDF return address."""
|
|
217
217
|
parsed = urlparse(url.strip())
|
|
218
|
-
|
|
218
|
+
# Any DOI: Thieme's own 10.1055 and those of the journals it took over (Schattauer's 10.1160).
|
|
219
|
+
match = re.fullmatch(r"/products/ejournals/pdf/(10\.\d{4,9}/[^/]+)\.pdf",
|
|
219
220
|
unquote(parsed.path).lower())
|
|
220
221
|
return (parsed.scheme == "https" and not parsed.username and not parsed.password
|
|
221
222
|
and parsed.netloc.lower() in {"www.thieme-connect.de", "thieme-connect.de",
|
|
@@ -115,14 +115,19 @@ def _download_impl(doi: str, output_dir: str | Path | None, *,
|
|
|
115
115
|
login_only: bool = False, login_wait: int | None = None,
|
|
116
116
|
fulltext: str | None = None, school: str | None = None, fresh: bool = False) -> dict[str, Any]:
|
|
117
117
|
config = load_config()
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
# school is not changed (user, 2026-11-17).
|
|
121
|
-
from .schools.saved import use_for_download
|
|
118
|
+
from . import school_switch
|
|
119
|
+
from .schools import saved as saved_schools
|
|
122
120
|
|
|
123
|
-
|
|
121
|
+
# Another saved school for this download alone (the user asked, or a batch's 没权限 tried with it at its end); the
|
|
122
|
+
# config's own school is not changed (user, 2026-11-17).
|
|
123
|
+
other_school = ""
|
|
124
|
+
if school:
|
|
125
|
+
problem = saved_schools.use_for_download(config, school)
|
|
124
126
|
if problem:
|
|
125
127
|
return fail(doi, problem, error_type=problem, action="review_school")
|
|
128
|
+
if not saved_schools.is_current(load_config(), saved_schools.current(config) or {}):
|
|
129
|
+
other_school = school_switch.name(saved_schools.current(config) or {})
|
|
130
|
+
config[school_switch.MARKS_OFF] = True
|
|
126
131
|
if fulltext:
|
|
127
132
|
# The article's full-text page is saved while on it (engine/fulltext_page.py).
|
|
128
133
|
# A main text already cached is not fetched again, so neither is its page.
|
|
@@ -169,19 +174,31 @@ def _download_impl(doi: str, output_dir: str | Path | None, *,
|
|
|
169
174
|
log.info(f"paper-search-school - {doi}")
|
|
170
175
|
# Another school than the one the browser last signed in with: that sign-in forgotten first; a test
|
|
171
176
|
# (``fresh``) always starts signed out, so that the account is what it tries (user, 2026-11-21).
|
|
172
|
-
from .cold_start import before_sign_in
|
|
173
|
-
from . import
|
|
174
|
-
from .schools import saved as saved_schools
|
|
177
|
+
from .cold_start import before_sign_in, signed_in_school
|
|
178
|
+
from .progress_reporter import batch_id
|
|
175
179
|
|
|
176
|
-
# 没权限时换下一所学校 (school_switch.py): the schools to try in turn,
|
|
177
|
-
#
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
saved_schools.apply(config, turns[0])
|
|
180
|
+
# 没权限时换下一所学校 (school_switch.py): the schools to try in turn, the default one first. One alone: the switch
|
|
181
|
+
# off, a school named for this download, the test of one, a sign-in only, a paper of a batch (it switches once, at
|
|
182
|
+
# its end, for all its papers without access: user, 2026-11-22).
|
|
183
|
+
turns = (school_switch.schools(config) if school_switch.enabled(config) and not school and not fresh
|
|
184
|
+
and not login_only and not batch_id() else [])
|
|
182
185
|
turn = 0
|
|
186
|
+
entry_turn = 0
|
|
183
187
|
while True:
|
|
188
|
+
entity = str(config.get("idp_entity_id") or "").strip()
|
|
189
|
+
if not fresh and entity and signed_in_school() not in ("", entity):
|
|
190
|
+
# The batch's own browser, open from the article before, holds the profile: the default school's article
|
|
191
|
+
# after one another school got kept that school's sign-in beside its own, each article waiting 10 s for the
|
|
192
|
+
# profile in vain (Windows, 2026-11-22: Bone signed in with the default school, the other school's Wiley sign-in still
|
|
193
|
+
# there). Closed first, as for a switch.
|
|
194
|
+
from .browser.batch_session import active_batch
|
|
195
|
+
|
|
196
|
+
batch = active_batch.get()
|
|
197
|
+
if batch is not None:
|
|
198
|
+
batch.close()
|
|
184
199
|
signed = before_sign_in(config, always=fresh)
|
|
200
|
+
if signed == "busy" and not fresh:
|
|
201
|
+
log.info(" [Institutional] the download browser is open: the last school's sign-in kept")
|
|
185
202
|
if signed == "cleared":
|
|
186
203
|
log.info(" [Institutional] the browser's sign-in with another school forgotten")
|
|
187
204
|
elif signed == "busy" and fresh:
|
|
@@ -192,6 +209,15 @@ def _download_impl(doi: str, output_dir: str | Path | None, *,
|
|
|
192
209
|
except Exception as exc:
|
|
193
210
|
log.info(f" [Institutional] route exception: {type(exc).__name__}")
|
|
194
211
|
return fail(doi, "institutional route raised", error_type="source_exception", action="review_logs")
|
|
212
|
+
# The school's entries by one name: the next one, with this school, when the one chosen did not do.
|
|
213
|
+
if school_switch.entry_did_not_do(result) and entry_turn + 1 < int(result.get("same_name_entries") or 0):
|
|
214
|
+
entry_turn += 1
|
|
215
|
+
config["institution_entry_turn"] = entry_turn
|
|
216
|
+
log.info(f" [Institutional] the school's entry {entry_turn} of {result['same_name_entries']} did not do; "
|
|
217
|
+
f"the next one")
|
|
218
|
+
continue
|
|
219
|
+
entry_turn = 0
|
|
220
|
+
config.pop("institution_entry_turn", None)
|
|
195
221
|
if turn + 1 >= len(turns) or not school_switch.no_access(result):
|
|
196
222
|
break
|
|
197
223
|
# Signed in, no access: the next school, its sign-in after this one's is forgotten (the batch's browser closed
|
|
@@ -207,14 +233,14 @@ def _download_impl(doi: str, output_dir: str | Path | None, *,
|
|
|
207
233
|
if batch is not None:
|
|
208
234
|
batch.close()
|
|
209
235
|
saved_schools.apply(config, following)
|
|
236
|
+
config[school_switch.MARKS_OFF] = True
|
|
210
237
|
if before_sign_in(config) == "busy":
|
|
211
238
|
log.info(" [Institutional] the browser kept the last school's sign-in; no other school tried")
|
|
212
239
|
turn -= 1
|
|
213
240
|
break
|
|
214
|
-
if
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
result["school"] = school_switch.name(turns[turn]) # not the default school's: the results say whose
|
|
241
|
+
if result and result.get("success") and (turn or other_school):
|
|
242
|
+
# Not the default school's: the results say whose.
|
|
243
|
+
result["school"] = school_switch.name(turns[turn]) if turn else other_school
|
|
218
244
|
elif turns and turn and school_switch.no_access(result):
|
|
219
245
|
result["schools_tried"] = turn + 1 # the lists say "N 所学校都没有权限"
|
|
220
246
|
# An article that re-checked a blocked journal's site: open again unless blocked again.
|
|
@@ -430,7 +430,17 @@ def _short_line(value: Any, limit: int = 80) -> str:
|
|
|
430
430
|
return " ".join(value.split())[:limit]
|
|
431
431
|
|
|
432
432
|
|
|
433
|
-
|
|
433
|
+
# The five failure classes (PaperSearch's failureClass.ts; docs/contracts/failure-reasons.zh.md), and the eight before
|
|
434
|
+
# 2026-11-22 as they map to them (a PaperSearch older than this backend may still send those).
|
|
435
|
+
FAILURE_CLASSES = ("no_access", "user_side", "external", "unsupported", "unexplained")
|
|
436
|
+
_OLD_CLASSES = {"school_side": "external", "publisher_or_network": "external", "article_or_site": "external",
|
|
437
|
+
"adaptation": "unsupported"}
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def _failure_class(value: Any) -> str:
|
|
441
|
+
value = _OLD_CLASSES.get(value, value) if isinstance(value, str) else value
|
|
442
|
+
return value if value in FAILURE_CLASSES else "unexplained"
|
|
443
|
+
|
|
434
444
|
_RESULT_CONTENTS = ("main", "supplements", "both", "markdown")
|
|
435
445
|
# A bound against malformed input only: a batch has no limit since 7a38a068 (user, 2026-11-17). Left at its old 1000,
|
|
436
446
|
# a batch's papers after the 1000th were left out of the lists (user, 2026-11-21: 失败 1 on the card, the list empty,
|
|
@@ -496,7 +506,7 @@ def _batch_results(raw: Any) -> dict[str, Any] | None:
|
|
|
496
506
|
if not isinstance(item, dict) or not text(item.get("reason")):
|
|
497
507
|
continue
|
|
498
508
|
summary[key].append({
|
|
499
|
-
"cls":
|
|
509
|
+
"cls": _failure_class(item.get("cls")),
|
|
500
510
|
**{field: text(item.get(field)) for field in ("reason", "title", "journal", "doi", "note")},
|
|
501
511
|
# A site not yet supported (its note says where it fell short).
|
|
502
512
|
**({"unverified": True} if item.get("unverified") is True else {}),
|
|
@@ -544,18 +554,17 @@ def _paper(raw: Any) -> dict[str, Any] | None:
|
|
|
544
554
|
if isinstance(files, int) and not isinstance(files, bool) and 0 <= files <= 100_000:
|
|
545
555
|
paper["supplements_saved"] = files
|
|
546
556
|
if raw.get("supplement_reason"): # saved, but not every supplementary file
|
|
547
|
-
paper.update(supplement_cls=
|
|
548
|
-
|
|
557
|
+
paper.update(supplement_cls=_failure_class(raw.get("supplement_cls")),
|
|
558
|
+
supplement_reason=_display_text(raw.get("supplement_reason")))
|
|
549
559
|
if raw.get("markdown_reason"): # saved, without the Markdown asked for
|
|
550
|
-
paper.update(markdown_cls=
|
|
551
|
-
|
|
560
|
+
paper.update(markdown_cls=_failure_class(raw.get("markdown_cls")),
|
|
561
|
+
markdown_reason=_display_text(raw.get("markdown_reason")))
|
|
552
562
|
# Saved with a Markdown its checks found short, from a registered site's page (user, 2026-11-17).
|
|
553
563
|
if _display_text(raw.get("markdown_doubt_reason")):
|
|
554
564
|
paper.update(markdown_doubt_reason=_display_text(raw.get("markdown_doubt_reason")),
|
|
555
565
|
markdown_doubt_note=_display_text(raw.get("markdown_doubt_note")))
|
|
556
566
|
elif paper["state"] == "failed":
|
|
557
|
-
paper.update(cls=raw.get("cls")
|
|
558
|
-
reason=_display_text(raw.get("reason")))
|
|
567
|
+
paper.update(cls=_failure_class(raw.get("cls")), reason=_display_text(raw.get("reason")))
|
|
559
568
|
# Its page from a site not yet supported (user, 2026-11-16): the site, whether its Markdown
|
|
560
569
|
# was kept or the batch gave the site up, a note on what it lacked, the kept report.
|
|
561
570
|
host = raw.get("markdown_host")
|
|
@@ -61,7 +61,7 @@ TERMINAL_STATUSES = frozenset({"done", "failed", "cancelled", "interrupted"})
|
|
|
61
61
|
MAX_REASON_ROWS = 5
|
|
62
62
|
OPEN_FAILURES_UP_TO = 3
|
|
63
63
|
MAX_LISTED_PAPERS = 200
|
|
64
|
-
CLASS_ORDER = ("no_access", "user_side", "
|
|
64
|
+
CLASS_ORDER = ("no_access", "user_side", "external", "unsupported", "unexplained")
|
|
65
65
|
DEFAULT_LINGER_SECONDS = 8.0
|
|
66
66
|
NOTICE_SECONDS = 10.0 # how long the download's answer to a click stays on screen
|
|
67
67
|
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
"profile": {
|
|
4
4
|
"name": "SAGE",
|
|
5
5
|
"doi_prefixes": [
|
|
6
|
-
"10.1177"
|
|
6
|
+
"10.1177",
|
|
7
|
+
"10.1191",
|
|
8
|
+
"10.1258"
|
|
7
9
|
],
|
|
8
10
|
"base_domains": [
|
|
9
11
|
"sagepub.com"
|
|
10
12
|
],
|
|
11
|
-
"article_url_template": "https://
|
|
13
|
+
"article_url_template": "https://journals.sagepub.com/doi/{doi}",
|
|
12
14
|
"pdf_url_templates": [
|
|
13
15
|
"https://journals.sagepub.com/doi/pdf/{doi}"
|
|
14
16
|
],
|