# ostapkonst/lanbookdownloader architecture

> Architecture diagram of the GitHub repository ostapkonst/lanbookdownloader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ostapkonst/lanbookdownloader
- Repository: https://github.com/ostapkonst/lanbookdownloader

## Overview

##### Project type and purpose
- LanBookDownloader is an open‑source, command‑line utility (batch + Python scripts) that downloads book pages from the “ЭБС Лань” web service in SVG format and converts them into a single PDF or DJVU file.
- Its goal is to work around browser memory limits by streaming and converting pages on disk.

##### File structure
- Top‑level items:
- run_all.bat / clean_all.bat: entry points to orchestrate the end‑to‑end workflow and cleanup
- header.json: configuration file (contains HTTP “Cookie” header)
- requirements.txt: Python dependencies
- scripts/: all Python and batch conversion scripts
- programs/: (likely a place for third‑party binaries or wrappers; check its README for details)
- The “scripts” directory reflects a linear pipeline of steps: downloading, converting, joining, final conversion, and inspection.

##### README for additional insights
- It enumerates each script’s role and the sequence in which they are called (run_all.bat glues them together).
- External tools invoked by batch files (e.g., Inkscape, PDFTK, djvulibre) are implied dependencies.

##### Main components and their interactions
a. CLI Layer
- run_all.bat: parses arguments (book_id, optional page range) and invokes each script in turn.
- clean_all.bat: removes intermediate files.
b. Configuration
- header.json: supplies authentication cookie to the downloader.
c. Downloader
- elan_downloader.py: HTTP client that pulls SVG pages from the web service and writes them to disk.
d. Conversion Pipeline
1) svg_to_pdf.bat: batch wrapper around an SVG‑to‑PDF converter (e.g., Inkscape CLI).
2) join_pdf.py: merges individual page PDFs into one document (e.g., via PyPDF2 or PDFTK).
3) pdf_to_djvu.bat: converts the merged PDF to DJVU (djvulibre CLI).
e. Inspection
- show_fixes.py: scans output PDFs for rasterized pages or anomalies and reports them.
f. External Dependencies
- Python 3 + pip modules (requests, PyPDF2, etc.)
- Inkscape / ImageMagick or other SVG → PDF tool
- PDFTK or equivalent for joining PDFs
- djvulibre for PDF → DJVU conversion

##### Architectural patterns and design principles
- Pipeline pattern: each script/component handles one stage, passing its output as input to the next.
- Configuration separation: HTTP header stored in header.json, keeping credentials out of code.

a. Components
- CLI / Orchestrator (run_all.bat)
- Downloader (elan_downloader.py)
- SVG→PDF converter (svg_to_pdf.bat)
- PDF joiner (join_pdf.py)
- PDF→DJVU converter (pdf_to_djvu.bat)
- Inspector (show_fixes.py)
- Configuration (header.json)
- External tools & libraries
b. Relationships & Data Flow
1) CLI → Downloader → disk (SVG files)
2) disk (SVG) → SVG→PDF → disk (one PDF/page)
3) disk (PDF pages) → PDF joiner → single PDF
4) single PDF → PDF→DJVU → DJVU file
5) single PDF → Inspector → report
c. Technologies & Frameworks
- Python interpreter hosting the .py scripts and pip dependencies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    runAll["run_all.bat"]:::batch
    cleanAll["clean_all.bat"]:::batch

    %% Configuration
    header["header.json"]:::config
    req["requirements.txt"]:::config

    %% Downloader
    elan["elan_downloader.py"]:::python

    %% Conversion Pipeline
    svgpdf["svg_to_pdf.bat"]:::batch
    joinpdf["join_pdf.py"]:::python
    pdfdjvu["pdf_to_djvu.bat"]:::batch

    %% Inspection
    inspect["show_fixes.py"]:::python

    %% External Tools & Binaries
    prog["programs/"]:::external
    inkscape["Inkscape CLI"]:::external
    pdftk["PDFTK / PyPDF2"]:::external
    djvu["djvulibre CLI"]:::external

    %% Artifacts on Disk
    svgs["SVG pages"] 
    pdfs["PDF pages"]
    merged["Merged PDF"]
    djvufile["DJVU file"]

    %% Workflow
    runAll -->|"invoke"| elan
    runAll -->|"invoke"| svgpdf
    runAll -->|"invoke"| joinpdf
    runAll -->|"invoke"| pdfdjvu
    runAll -->|"invoke"| inspect

    header -.->|"cookie config"| elan
    req -.->|"pip modules"| elan
    req -.->|"pip modules"| joinpdf
    req -.->|"pip modules"| inspect

    elan -->|"writes"| svgs
    svgs --> svgpdf
    svgpdf -->|"PDF pages"| pdfs
    pdfs --> joinpdf
    joinpdf -->|"Merged PDF"| merged
    merged --> pdfdjvu
    merged --> inspect
    pdfdjvu -->|"DJVU file"| djvufile

    %% External Tools Connections
    prog --> inkscape
    prog --> pdftk
    prog --> djvu

    svgpdf --> inkscape
    joinpdf --> pdftk
    pdfdjvu --> djvu

    %% Cleanup
    cleanAll -->|"removes intermediates"| svgs
    cleanAll --> pdfs
    cleanAll --> merged
    cleanAll --> djvufile

    %% Click Events
    click runAll "https://github.com/ostapkonst/lanbookdownloader/blob/main/run_all.bat"
    click cleanAll "https://github.com/ostapkonst/lanbookdownloader/blob/main/clean_all.bat"
    click header "https://github.com/ostapkonst/lanbookdownloader/blob/main/header.json"
    click req "https://github.com/ostapkonst/lanbookdownloader/blob/main/requirements.txt"
    click elan "https://github.com/ostapkonst/lanbookdownloader/blob/main/scripts/elan_downloader.py"
    click svgpdf "https://github.com/ostapkonst/lanbookdownloader/blob/main/scripts/svg_to_pdf.bat"
    click joinpdf "https://github.com/ostapkonst/lanbookdownloader/blob/main/scripts/join_pdf.py"
    click pdfdjvu "https://github.com/ostapkonst/lanbookdownloader/blob/main/scripts/pdf_to_djvu.bat"
    click inspect "https://github.com/ostapkonst/lanbookdownloader/blob/main/scripts/show_fixes.py"
    click prog "https://github.com/ostapkonst/lanbookdownloader/tree/main/programs/"

    %% Styles
    classDef python fill:#a8e6cf,stroke:#333,stroke-width:1px
    classDef batch fill:#ffd3b6,stroke:#333,stroke-width:1px
    classDef external fill:#8ecae6,stroke:#333,stroke-width:1px
    classDef config fill:#ececec,stroke:#333,stroke-width:1px
```
