How shrimp2845-tw/nhdl works
1. What this repository is
- nhdl is a small, single-purpose Python package for fetching a nhentai gallery by ID or URL, downloading its pages, and assembling them into a PDF.
- It is not a service or web app; the architecture is a local, single-process download pipeline.
2. Public entrypoint
- The package exposes a simple top-level API: from nhdl import download.
- That public function is the primary boundary for consumers and likely delegates into the main orchestration code in nhdl/nh_dl.py.
3. Core orchestration layer
- nhdl/nh_dl.py is the central coordinator.
- Its job is to turn one user input (book as URL or ID) into a complete end-to-end workflow: resolve the gallery, fetch page assets, manage retries/rest delays, and trigger PDF creation.
4. Metadata / gallery discovery subsystem
- nhdl/utils/get_info.py appears to be responsible for extracting gallery information from nhentai.
- This is the first external-network boundary: it likely normalizes the input and reads gallery metadata such as title, page list, and download targets.
5. Image download subsystem
- nhdl/utils/download.py likely handles the actual HTTP downloads of page images.
- This is the main I/O-heavy part of the system and probably includes the retry behavior described in the README.
- The rest parameter in the public API suggests this module is rate-throttled between page fetches.
6. Formatting / PDF generation subsystem
- nhdl/utils/formatting.py is the conversion layer that turns downloaded images into a PDF.
- This is the final transformation step in the pipeline and forms the output boundary of the application.
7. User feedback and progress
- The README mentions tqdm progress display, so the download pipeline likely reports progress while iterating through pages.
- That makes the user-facing experience part of the orchestration layer rather than a separate subsystem.
8. Data flow through the system
- Input: a gallery ID or URL.
- Then: resolve gallery details from nhentai.
- Then: iterate over page/image URLs, download each file with optional delay/retry.
- Then: pass the collected images into the PDF formatter.
- Output: a local PDF file on disk.
9. External boundary
- The only major external dependency from an architecture perspective is the nhentai website, which supplies both metadata and page images.
- All other behavior is local file and network I/O; there is no evidence of a database, queue, or background worker system.
10. Package and runtime shape
- pyproject.toml indicates a modern Python package layout.
- The README states Python 3.8+.
- nhdl/__init__.py exists to present a clean package API rather than requiring callers to know internal module structure.
11. Testing boundary
- test/test.py is the repository’s dedicated test area.
- Given the project shape, tests are likely focused on the download/formatting pipeline or input handling rather than distributed integration components.
12. How to draw the architecture
- Draw one client entrypoint feeding a single orchestration module.
- From there, branch to three utility responsibilities: gallery info retrieval, page downloading, and PDF formatting.
- Show nhentai as the remote external system on the far side of the metadata/download modules, and local filesystem/PDF output on the far side of the formatter.
Main entry points: nh_dl.py nh_dl · download.py Page download · formatting.py PDF format · __init__.py download
Components 13
nhdl package
Public API and orchestration
Utilities
Gallery lookup, download, and formatting helpers
- Gallery info · Resolves gallery details from ID or URL
nhdl/utils/get_info.py - Page download · Downloads page images with retry and pacing
nhdl/utils/download.py - PDF format · Converts downloaded images into a PDF
nhdl/utils/formatting.py
External systems
Remote site and local runtime boundaries
- Caller · User code or script invoking the package
- nhentai · External source for metadata and page images
- tqdm · Progress feedback during iteration
- Gallery ID/URL · Gallery identifier accepted by the API
- Filesystem · Local read/write boundary for downloads and output
Artifacts
Intermediate and final files
- Images · Fetched page image files
- PDF file · Final assembled local PDF
Connections 15
- Caller → download: calls · Consumer imports and invokes the public entrypoint
- download → nh_dl: delegates · Public API hands control to the orchestration layer
- nh_dl → Gallery ID/URL: accepts · Orchestrator starts from a gallery ID or URL
- nh_dl → Gallery info: resolves · Fetches gallery metadata and page targets
- Gallery info → nhentai: queries · Reads gallery metadata from the remote site
- nh_dl → Page download: downloads · Coordinates page image retrieval
- Page download → nhentai: fetches · Requests page image assets from the remote site
- Page download → tqdm: reports · Shows download progress to the user
- Page download → Images: writes · Persists downloaded page images locally
- Images → Filesystem: stored in · Downloaded assets live on disk
- nh_dl → PDF format: formats · Sends collected images to the PDF builder
- PDF format → PDF file: creates · Produces the final PDF artifact
- PDF format → Filesystem: writes · Saves the assembled PDF locally
- test.py → download: covers · Tests likely exercise the public package boundary
- test.py → nh_dl: covers · Tests likely validate the pipeline coordinator