citeget.resolve¶
Composable download and URL-resolution for academic references.
The acquisition pipeline has three layers:
UrlResolver
(Reference) -> list[str]— turn citation info into candidate download URLs (URL rewriting, DOI lookup, search APIs).Downloader
(url, filepath) -> bool— fetch a URL, validate the content, save to disk.AcquisitionStrategy
(Reference, Path) -> Optional[str]— a complete unit that combines resolvers and downloaders (or does its own thing, like libgen’s playwright-based search+download).
Extension semantics¶
The filepath argument to downloaders and strategies is advisory: it
tells them where you intend the final file to live. They may write to a
neighbouring path with a different extension when the downloaded content is
not a PDF (e.g. EPUB, MOBI, DjVu). Callers should use the final path
reported by the strategy rather than assuming the .pdf target was
written. The higher-level citeget.acquire_references.acquire_reference()
function handles this finalisation — and the hard rule “no .pdf extension
on non-PDF content” — automatically.
The factory resolve_and_download() wires a resolver to a downloader.
chain() composes strategies (try first, fall back to second).
Usage:
from citeget.resolve import resolve_reference
# Zero-config: tries all built-in strategies in order
path = resolve_reference(ref, Path("paper.pdf"))
# Custom chain
from citeget.resolve import chain, STRATEGIES
my = chain(STRATEGIES["direct"], STRATEGIES["arxiv_search"])
resolve_reference(ref, filepath, strategy=my)
# Add a repository rule
from citeget.resolve import url_rewriter, BUILTIN_URL_RULES, register_resolver
rules = {**BUILTIN_URL_RULES, "myrepo.org": lambda u: u.replace("/view/", "/dl/")}
register_resolver("my_rewriter", url_rewriter(rules=rules))
Functions
Search the arxiv API by author + title, return PDF URLs. |
|
|
Try strategies in order, return the first success. |
|
Concatenate URL lists from multiple resolvers (deduped, order-preserving). |
|
Resolve via DOI: Crossref lookup → Unpaywall (open access) → Sci-Hub. |
|
Retrieve a registered downloader by name. |
|
Retrieve a registered resolver by name. |
|
Retrieve a registered strategy by name. |
|
Wrap the existing libgen search+download as an |
Return names of all registered downloaders. |
|
Return names of all registered resolvers. |
|
Return names of all registered strategies. |
|
|
Register a named downloader. |
|
Register a named URL resolver. |
|
Register a named acquisition strategy. |
|
Create a strategy that resolves URLs then tries to download each. |
|
Resolve and download a single reference. |
Wrap the existing Sci-Hub/DOI download as an |
|
Query the Semantic Scholar API for open-access PDF links. |
|
|
Create a resolver that rewrites known repository URLs to direct PDFs. |
|
Wrap a strategy to append a log entry on each call. |
Classes
|
Complete acquire-one-reference unit. |
|
Fetch url, validate content, save to filepath. |
|
Turn a |
- class citeget.resolve.AcquisitionStrategy(*args, **kwargs)[source]¶
Bases:
ProtocolComplete acquire-one-reference unit.
filepathis advisory — the returned path may differ in extension from what was passed in (see module docstring).Returns the filepath string on success,
Noneon failure.
- class citeget.resolve.Downloader(*args, **kwargs)[source]¶
Bases:
ProtocolFetch url, validate content, save to filepath.
filepathis advisory — the actual written path may have a different extension reflecting the real content format (see module docstring).Returns
Trueon success.
- class citeget.resolve.UrlResolver(*args, **kwargs)[source]¶
Bases:
ProtocolTurn a
Referenceinto candidate download URLs.
- citeget.resolve.arxiv_search_resolver()[source]¶
Search the arxiv API by author + title, return PDF URLs.
- Return type:
- citeget.resolve.chain(*strategies)[source]¶
Try strategies in order, return the first success.
- Return type:
- citeget.resolve.chain_resolvers(*resolvers)[source]¶
Concatenate URL lists from multiple resolvers (deduped, order-preserving).
- Return type:
- citeget.resolve.doi_resolver(*, email='')[source]¶
Resolve via DOI: Crossref lookup → Unpaywall (open access) → Sci-Hub.
- Parameters:
email (
str) – Email for the Unpaywall API (optional; skipped if empty).- Return type:
- citeget.resolve.get_downloader(name)[source]¶
Retrieve a registered downloader by name.
- Raises:
KeyError – If name is not registered.
- Return type:
- citeget.resolve.get_resolver(name)[source]¶
Retrieve a registered resolver by name.
- Raises:
KeyError – If name is not registered.
- Return type:
- citeget.resolve.get_strategy(name)[source]¶
Retrieve a registered strategy by name.
- Raises:
KeyError – If name is not registered.
- Return type:
- citeget.resolve.libgen_strategy(*, topics=('articles', 'books'), timeout=30000)[source]¶
Wrap the existing libgen search+download as an
AcquisitionStrategy.This is a self-contained strategy (not a resolver+downloader pair) because libgen requires playwright-based browser automation for both search and download.
- Return type:
- citeget.resolve.register_downloader(name, downloader)[source]¶
Register a named downloader.
- Return type:
- citeget.resolve.register_resolver(name, resolver)[source]¶
Register a named URL resolver.
- Return type:
- citeget.resolve.register_strategy(name, strategy)[source]¶
Register a named acquisition strategy.
- Return type:
- citeget.resolve.resolve_and_download(resolver, *, downloader=None)[source]¶
Create a strategy that resolves URLs then tries to download each.
- Parameters:
resolver (
UrlResolver|str) – AUrlResolvercallable or registered name.downloader (
Downloader|str|None) – ADownloadercallable or registered name.Noneuses the"pdf"downloader.
- Return type:
- citeget.resolve.resolve_reference(ref, filepath, *, strategy=None)[source]¶
Resolve and download a single reference.
- Parameters:
ref (
Reference) – The reference to acquire.filepath (
Path) – Target file path for the download.strategy (
AcquisitionStrategy|str|None) – AnAcquisitionStrategycallable, a registered strategy name (str), orNoneto use"default".
- Return type:
- Returns:
Filepath string on success,
Noneon failure.- Raises:
KeyError – If a string name is not in the registry.
- citeget.resolve.scihub_strategy()[source]¶
Wrap the existing Sci-Hub/DOI download as an
AcquisitionStrategy.- Return type:
- citeget.resolve.semantic_scholar_resolver()[source]¶
Query the Semantic Scholar API for open-access PDF links.
- Return type:
- citeget.resolve.url_rewriter(*, rules=None)[source]¶
Create a resolver that rewrites known repository URLs to direct PDFs.
- citeget.resolve.with_logging(strategy, *, name='', log_entries=None)[source]¶
Wrap a strategy to append a log entry on each call.
- Parameters:
strategy (
AcquisitionStrategy) – The strategy to wrap.name (
str) – Label for log entries.log_entries (
list|None) – List to append dicts to (mutated in place).
- Return type: