Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions arxiv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ def download_pdf(
Downloads the PDF for this result to the specified directory.

The filename is generated by calling `to_filename(self)`.

**Deprecated:** future versions of this client library will not provide
download helpers (out of scope). Use `result.pdf_url` directly.
"""
if not filename:
filename = self._get_default_filename()
Expand All @@ -230,16 +233,23 @@ def download_source(
directory.

The filename is generated by calling `to_filename(self)`.

**Deprecated:** future versions of this client library will not provide
download helpers (out of scope). Use `result.source_url` directly.
"""
if not filename:
filename = self._get_default_filename("tar.gz")
path = os.path.join(dirpath, filename)
pdf_url = Result._substitute_domain(self.pdf_url, download_domain)
# Bodge: construct the source URL from the PDF URL.
src_url = pdf_url.replace("/pdf/", "/src/")
written_path, _ = urlretrieve(src_url, path)
source_url = Result._substitute_domain(self.source_url(), download_domain)
written_path, _ = urlretrieve(source_url, path)
return written_path

def source_url(self) -> str:
"""
Derives a URL for the source tarfile for this result.
"""
return self.pdf_url.replace("/pdf/", "/src/")

def _get_pdf_url(links: List[Link]) -> str:
"""
Finds the PDF link among a result's links and returns its URL.
Expand Down