(paper: Dict[str, Any])
| 1743 | |
| 1744 | |
| 1745 | def _extract_pdf_url(paper: Dict[str, Any]) -> str: |
| 1746 | candidates = [ |
| 1747 | paper.get("pdf_url"), |
| 1748 | paper.get("url"), |
| 1749 | paper.get("paper_url"), |
| 1750 | paper.get("doi_url"), |
| 1751 | paper.get("openreview_url"), |
| 1752 | (paper.get("metadata") or {}).get("pdf_url"), |
| 1753 | (paper.get("metadata") or {}).get("url"), |
| 1754 | (paper.get("metadata") or {}).get("link"), |
| 1755 | (paper.get("metadata") or {}).get("paper_url"), |
| 1756 | (paper.get("metadata") or {}).get("doi_url"), |
| 1757 | (paper.get("metadata") or {}).get("openreview_url"), |
| 1758 | ] |
| 1759 | |
| 1760 | for candidate in candidates: |
| 1761 | text = _clean_text(candidate) |
| 1762 | if _looks_like_pdf_url(text): |
| 1763 | return text |
| 1764 | |
| 1765 | for source_url in _collect_source_page_urls(paper): |
| 1766 | try: |
| 1767 | resolved = _resolve_pdf_url_from_source_page(source_url) |
| 1768 | except Exception as exc: |
| 1769 | print(f" Failed to resolve PDF from source page {source_url[:120]}: {exc}") |
| 1770 | heuristic_candidates = _build_pdf_url_candidates_from_source_url(source_url) |
| 1771 | if heuristic_candidates: |
| 1772 | print(f" Falling back to heuristic PDF URL: {heuristic_candidates[0][:120]}") |
| 1773 | return heuristic_candidates[0] |
| 1774 | continue |
| 1775 | if _clean_text(resolved): |
| 1776 | return resolved |
| 1777 | |
| 1778 | arxiv_id = _clean_text(paper.get("arxiv_id")) |
| 1779 | if arxiv_id: |
| 1780 | return f"https://arxiv.org/pdf/{arxiv_id}.pdf" |
| 1781 | return "" |
| 1782 | |
| 1783 | |
| 1784 | def _get_pdf_enrichment_mode() -> str: |
no test coverage detected