Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AGI Edgerunners LLM Agents Papers pdf downloader

From Leeroopedia
Knowledge Sources
Domains File_Download, File_System
Last Updated 2026-10-10 14:30 GMT

Overview

Concrete tool for batch-downloading paper PDFs from parsed metadata with filename sanitization and directory organization, provided by the LLM-Agents-Papers repository.

Description

The pdf_downloader function downloads a single PDF file from a URL to a local path using requests.get. It is used by the download_pdf.py script which batch-processes all JSON files in the parsed_v4/ folder.

The download_pdf.py script performs the complete batch download workflow:

  1. Checks that parsed_v4/ folder exists; exits if missing
  2. Creates the PDF/ output directory if needed
  3. Iterates each JSON file in parsed_v4/, extracting the list title from the filename (e.g., 2023.json → 2023)
  4. For each paper entry, extracts the pdf link and title
  5. Sanitizes the output filename by replacing ': → : and ? → ? (full-width Unicode equivalents)
  6. Creates per-list subdirectories under PDF/<list_title>/
  7. Skips already-downloaded files (incremental download)
  8. Calls pdf_downloader() to fetch the PDF binary

Note: download_pdf.py references the older parsed_v4/ folder format, while the current pipeline uses parsed_v5/. The script would need its Parsed_Folder constant updated to work with v5 data.

Usage

Use this implementation when you need to:

  • Batch-download PDF files for all papers in a parsed metadata collection
  • Download a single PDF from a URL to a local file path
  • Organize downloaded PDFs into per-year subdirectories with sanitized filenames

Code Reference

Source Location

  • Repository: LLM-Agents-Papers
  • File: download_pdf.py:L27-38 (pdf_downloader), L41-70 (batch download script logic)

Signature

PROXY = None

def pdf_downloader(url: str, pdf_file: str):
    """
    Download a PDF file from a URL to a local path.

    Args:
        url: PDF download URL
        pdf_file: Local output file path
    """

Import

from download_pdf import pdf_downloader

I/O Contract

Inputs

Name Type Required Description
url str Yes PDF download URL (from paper metadata pdf field)
pdf_file str Yes Local output file path for the PDF
PROXY dict / None No Module-level proxy config; None for direct connection

Outputs

Name Type Description
return None No return value
pdf_file File on disk Binary PDF file written to the specified path (on HTTP 200)

Usage Examples

Downloading a Single PDF

from download_pdf import pdf_downloader

url = "https://arxiv.org/pdf/2310.01444v2"
output = "PDF/2024/Example Paper.pdf"

pdf_downloader(url, output)
print(f"Downloaded to {output}")

Batch Download from Parsed Metadata

import os
import re
from download_pdf import read_json, pdf_downloader

Parsed_Folder = "parsed_v4"
PDF_Folder = "PDF"

if not os.path.exists(PDF_Folder):
    os.makedirs(PDF_Folder)

for file in os.listdir(Parsed_Folder):
    datas = read_json(os.path.join(Parsed_Folder, file))

    # Extract list title from filename (strip .json)
    match = re.search('.*(?=.json)', file)
    list_title = match.group() if match else "Paper List"

    # Create subdirectory
    sub_dir = f"{PDF_Folder}/{list_title}"
    if not os.path.exists(sub_dir):
        os.mkdir(sub_dir)

    for id_, data in datas.items():
        pdf_link = data.get("pdf")
        title = data.get("title")
        if not pdf_link or not title:
            continue

        # Sanitize filename (replace filesystem-unsafe characters)
        pdf_file = f"{sub_dir}/{title}.pdf"
        pdf_file = pdf_file.replace(":", ":").replace("?", "?")

        # Skip if already downloaded
        if not os.path.exists(pdf_file):
            print(f"Downloading: {pdf_link}")
            pdf_downloader(pdf_link, pdf_file)
            print(f"Saved to: {pdf_file}")

With Proxy for Restricted Networks

import download_pdf

# Set proxy for networks requiring VPN
download_pdf.PROXY = {"https": "127.0.0.1:4780", "http": "127.0.0.1:4780"}

download_pdf.pdf_downloader(
    "https://arxiv.org/pdf/2310.01444v2",
    "PDF/2024/Example Paper.pdf"
)

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment