Alex 4472fbe8cf Download overhaul - DNS fallback, bypasser enhancements, revamped error handling, better frontend UX (#336)
## Changelog

### 🌐 Network Resilience

- **Auto DNS rotation**: New `CUSTOM_DNS=auto` mode (now default) starts
with system DNS and automatically rotates through Cloudflare, Google,
Quad9, and OpenDNS when failures are detected. DNS results are cached to
improve performance.
- **Mirror failover**: Anna's Archive requests automatically fail over
between mirrors (.org, .se, .li) when one is unreachable
- **Round-robin source distribution**: Concurrent downloads are
distributed across different AA partner servers to avoid rate limiting

### 📥 Download Reliability

- **Much more reliable downloads**: Improved parsing of Anna's Archive
pages, smarter source prioritization, and better retry logic with
exponential backoff
- **Download resume support**: Interrupted downloads can now resume from
where they left off (if the server supports Range requests)
- **Cookie sharing**: Cloudflare bypass cookies are extracted and shared
with subsequent requests, often avoiding the need for re-bypass entirely
- **Stall detection**: Downloads with no progress for 5 minutes are
automatically cancelled and retried
- **Staggered concurrent downloads**: Small delays between starting
concurrent downloads to avoid hitting rate limits
- **Source failure tracking**: After multiple failures from the same
source type (e.g., Libgen), that source is temporarily skipped
- **Lazy welib loading**: Welib sources are fetched as a fallback only
when primary sources fail (unless `PRIORITIZE_WELIB` is enabled)

### 🛡️ Cloudflare & Protection Bypass

- **DDOS-Guard support**: Internal bypasser now detects and handles
DDOS-Guard challenges with dedicated bypass strategies
- **Cancellation support**: Bypass operations can now be cancelled
mid-operation when user cancels a download
- **Smart warmup**: Chrome driver is pre-warmed when first client
connects (controlled by `BYPASS_WARMUP_ON_CONNECT` env var) and shuts
down after periods of inactivity

### 🔌 External Bypasser (FlareSolverr)

- **Improved resilience**: Retry with exponential backoff, mirror/DNS
rotation on failure, and proper timeout handling
- **Cancellation support**: External bypasser operations respect
cancellation flags

### 🖥️ Web UI Improvements

- **Simplified download status**: Removed intermediate states
(bypassing, verifying, ingesting) — now just shows Queued → Resolving →
Downloading → Complete
- **Status messages**: Downloads show detailed status like "Trying
Anna's Archive (Server 3)" or "Server busy, trying next...", or live
waitlist countdowns.
- **Improved download sidebar**:
  - Downloads sorted by add time (newest first)
  - X button moved to top-right corner for better UX
  - Wave animation on in-progress items
  - Error messages shown directly on failed items
  - X button on completed/errored items clears them from the list

### ⚙️ Configuration Changes

- **`CUSTOM_DNS=auto`** is now the default (previously empty/system DNS)
- **`DOWNLOAD_PROGRESS_UPDATE_INTERVAL`** default changed from 5s to 1s
for smoother progress
- **`BYPASS_WARMUP_ON_CONNECT`** (default: true) — warm up Chrome when
first client connects

### 🐛 Bug Fixes

- **Download cancellation actually works**: Fixed issue where cancelling
downloads didn't properly stop in-progress operations
- **WELIB prioritization**: Fixed `PRIORITIZE_WELIB` not being respected
- **File exists handling**: Downloads to same filename now get `_1`,
`_2` suffix instead of overwriting
- **Empty search results**: "No books found" now returns empty list
instead of throwing exception
- **Search unavailable error**: Network/mirror failures during search
now return proper 503 error to client
2025-12-14 21:18:05 -05:00
2025-08-30 03:10:15 -04:00
2025-08-29 12:47:05 -04:00
2025-01-22 16:51:06 -05:00
2025-11-14 15:48:44 -05:00
2024-12-16 22:48:26 +00:00
2025-11-14 15:48:44 -05:00

📚 Calibre-Web-Automated-Book-Downloader

Calibre-Web Automated Book Downloader

An intuitive web interface for searching and requesting book downloads, designed to work seamlessly with Calibre-Web-Automated. This project streamlines the process of downloading books and preparing them for integration into your Calibre library.

✨ Features

  • 🌐 User-friendly web interface for book search and download
  • 🔄 Automated download to your specified ingest folder
  • 🔌 Seamless integration with Calibre-Web-Automated
  • 📖 Support for multiple book formats (epub, mobi, azw3, fb2, djvu, cbz, cbr)
  • 🛡️ Cloudflare bypass capability for reliable downloads
  • 🐳 Docker-based deployment for quick setup

🖼️ Screenshots

Main search interface Screenshot

Details modal Screenshot placeholder

Download queue Screenshot placeholder

🚀 Quick Start

Prerequisites

Installation Steps

  1. Get the docker-compose.yml:

    curl -O https://raw.githubusercontent.com/calibrain/calibre-web-automated-book-downloader/refs/heads/main/docker-compose.yml
    
  2. Start the service:

    docker compose up -d
    
  3. Access the web interface at http://localhost:8084

⚙️ Configuration

Environment Variables

Application Settings

Variable Description Default Value
FLASK_PORT Web interface port 8084
FLASK_HOST Web interface binding 0.0.0.0
DEBUG Debug mode toggle false
INGEST_DIR Book download directory /cwa-book-ingest
TZ Container timezone UTC
UID Runtime user ID 1000
GID Runtime group ID 100
CWA_DB_PATH Calibre-Web's database None
ENABLE_LOGGING Enable log file true
LOG_LEVEL Log level to use info
SESSION_COOKIE_SECURE Secure cookie enforcement - Use for HTTPS connections only false
CALIBRE_WEB_URL Custom WebUI library link None

If you wish to enable authentication, you must set CWA_DB_PATH to point to Calibre-Web's app.db, in order to match the username and password.

Set CALIBRE_WEB_URL to your Calibre-Web / Booklore base URL. A ‘Go to library’ button will appear in the Web UI for quick access while downloading, and it also provides library access when CWA-BD is installed as a mobile PWA.

If logging is enabled, log folder default location is /var/log/cwa-book-downloader Available log levels: DEBUG, INFO, WARNING, ERROR, CRITICAL. Higher levels show fewer messages.

Note that if using TOR, the TZ will be calculated automatically based on IP.

Download Settings

Variable Description Default Value
MAX_RETRY Maximum retry attempts 3
DEFAULT_SLEEP Retry delay (seconds) 5
MAIN_LOOP_SLEEP_TIME Processing loop delay (seconds) 5
SUPPORTED_FORMATS Supported book formats epub,mobi,azw3,fb2,djvu,cbz,cbr
BOOK_LANGUAGE Preferred language for books en
AA_DONATOR_KEY Optional Donator key for Anna's Archive fast download API ``
USE_BOOK_TITLE Use book title as filename instead of ID false
PRIORITIZE_WELIB When downloading, download from WELIB first instead of AA false
ALLOW_USE_WELIB Allow usage of welib for downloading books if found there true

If you change BOOK_LANGUAGE, you can add multiple comma separated languages, such as en,fr,ru etc.

Use the following environment variables to set specific folders in which to download different content types (Book, Magazine, Comic, etc.):

Variable Description Default Value
INGEST_DIR_BOOK_FICTION Book (fiction) folder name ``
INGEST_DIR_BOOK_NON_FICTION Book (non-fiction) folder name ``
INGEST_DIR_BOOK_UNKNOWN Book (unknown) folder name ``
INGEST_DIR_MAGAZINE Magazine folder name ``
INGEST_DIR_COMIC_BOOK Comic book folder name ``
INGEST_DIR_AUDIOBOOK Audiobook folder name ``
INGEST_DIR_STANDARDS_DOCUMENT Standards document folder name ``
INGEST_DIR_MUSICAL_SCORE Musical score folder name ``

If no specific path is set for a content type the default is INGEST_DIR.
Remember to map the specified paths to where your instance of Calibre-Web-Automated (CWA) will find them, e.g.:

volumes:
    - /tmp/data/calibre-web/comicbook-ingest:/cwa-comicbook-ingest

if INGEST_DIR_COMIC_BOOK=/cwa-comicbook-ingest and your CWA is configured to use /tmp/data/calibre-web/comicbook-ingest for comic books.

AA

Variable Description Default Value
AA_BASE_URL Base URL of Annas-Archive (could be changed for a proxy) https://annas-archive.org
USE_CF_BYPASS Disable CF bypass and use alternative links instead true

If you are a donator on AA, you can use your Key in AA_DONATOR_KEY to speed up downloads and bypass the wait times. If disabling the cloudflare bypass, you will be using alternative download hosts, such as libgen or z-lib, but they usually have a delay before getting the more recent books and their collection is not as big as aa's. But this setting should work for the majority of books.

Network Settings

Variable Description Default Value
AA_ADDITIONAL_URLS Proxy URLs for AA (, separated) ``
HTTP_PROXY HTTP proxy URL ``
HTTPS_PROXY HTTPS proxy URL ``
CUSTOM_DNS Custom DNS IP ``
USE_DOH Use DNS over HTTPS false

For proxy configuration, you can specify URLs in the following format:

# Basic proxy
HTTP_PROXY=http://proxy.example.com:8080
HTTPS_PROXY=http://proxy.example.com:8080

# Proxy with authentication
HTTP_PROXY=http://username:password@proxy.example.com:8080
HTTPS_PROXY=http://username:password@proxy.example.com:8080

The CUSTOM_DNS setting supports two formats:

  1. Custom DNS Servers: A comma-separated list of DNS server IP addresses

    • Example: 127.0.0.53,127.0.1.53 (useful for PiHole)
    • Supports both IPv4 and IPv6 addresses in the same string
  2. Preset DNS Providers: Use one of these predefined options:

    • google - Google DNS
    • quad9 - Quad9 DNS
    • cloudflare - Cloudflare DNS
    • opendns - OpenDNS

For users experiencing ISP-level website blocks (such as Virgin Media in the UK), using alternative DNS providers like Cloudflare may help bypass these restrictions

If a CUSTOM_DNS is specified from the preset providers, you can also set a USE_DOH=true to force using DNS over HTTPS, which might also help in certain network situations. Note that only google, quad9, cloudflare and opendns are supported for now, and any other value in CUSTOM_DNS will make the USE_DOH flag ignored.

Try something like this :

CUSTOM_DNS=cloudflare
USE_DOH=true

Custom configuration

Variable Description Default Value
CUSTOM_SCRIPT Path to an executable script that tuns after each download ``

If CUSTOM_SCRIPT is set, it will be executed after each successful download but before the file is moved to the ingest directory. This allows for custom processing like format conversion or validation.

The script is called with the full path of the downloaded file as its argument. Important notes:

  • The script must preserve the original filename for proper processing
  • The file can be modified or even deleted if needed
  • The file will be moved to /cwa-book-ingest after the script execution (if not deleted)

You can specify these configuration in this format :

environment:
  - CUSTOM_SCRIPT=/scripts/process-book.sh

volumes:
  - local/scripts/custom_script.sh:/scripts/process-book.sh

Volume Configuration

volumes:
  - /your/local/path:/cwa-book-ingest
  - /cwa/config/path/app.db:/auth/app.db:ro

Note - If your library volume is on a cifs share, you will get a "database locked" error until you add nobrl to your mount line in your fstab file. e.g. //192.168.1.1/Books /media/books cifs credentials=.smbcredentials,uid=1000,gid=1000,iocharset=utf8,nobrl - See https://github.com/crocodilestick/Calibre-Web-Automated/issues/64#issuecomment-2712769777

Mount should align with your Calibre-Web-Automated ingest folder.

Variants:

🧅 Tor Variant

This application also offers a variant that routes all its traffic through the Tor network. This can be useful for enhanced privacy or bypassing network restrictions.

To use the Tor variant:

  1. Get the Tor-specific docker-compose file:
    curl -O https://raw.githubusercontent.com/calibrain/calibre-web-automated-book-downloader/refs/heads/main/docker-compose.tor.yml
    
  2. Start the service using this file:
    docker compose -f docker-compose.tor.yml up -d
    

Important Considerations for Tor:

  • Capabilities: This variant requires the NET_ADMIN and NET_RAW Docker capabilities to configure iptables for transparent Tor proxying.
  • Timezone: When running in Tor mode, the container will attempt to determine the timezone based on the Tor exit node's IP address and set it automatically. This will override the TZ environment variable if it is set.
  • Network Settings: Custom DNS, DoH, and HTTP(S) proxy settings (CUSTOM_DNS, USE_DOH, HTTP_PROXY, HTTPS_PROXY) are ignored when using the Tor variant, as all traffic goes through Tor.

External Cloudflare resolver variant

This variant allows the application to use an external service to bypass Cloudflare protection, instead of relying on the built-in bypasser. This is useful if you already have a dedicated Cloudflare resolver (such as FlareSolverr or compatible services like ByParr) running elsewhere.

How it works:

  • When enabled, all requests that require Cloudflare bypass are sent to your external resolver service.
  • The application communicates with the resolver using its API.
  • This approach can improve reliability and performance, especially if your external resolver is optimized or shared across multiple applications.

Configuration

Variable Description Default Value
EXT_BYPASSER_URL The full URL of your external resolver (required)
EXT_BYPASSER_PATH API path for the resolver (usually /v1) /v1
EXT_BYPASSER_TIMEOUT Timeout for page loading (in milliseconds) 60000

Important

This feature follows the same configuration of the built-in Cloudflare bypasser, so you should turn on the USE_CF_BYPASS configuration to enable it.

To use the External Cloudflare resolver variant:

  1. Get the extbp-specific docker-compose file:
    curl -O https://raw.githubusercontent.com/calibrain/calibre-web-automated-book-downloader/refs/heads/main/docker-compose.extbp.yml
    
  2. Start the service using this file:
    docker compose -f docker-compose.extbp.yml up -d
    

Compatibility:

This feature is designed to work with any resolver that implements the FlareSolverr API schema, including ByParr and similar projects.

Benefits:

  • Centralizes Cloudflare bypass logic for easier maintenance.
  • Can leverage more powerful or distributed resolver infrastructure.
  • Reduces load on the main application container.

🏗️ Architecture

The application consists of a Flask backend with a React-based frontend:

Backend

  • Flask Application: Python-based backend (app.py, backend.py) providing REST API and WebSocket support
  • Download Manager: Handles book search, download requests, and queue management (downloader.py, book_manager.py)
  • Network Layer: Cloudflare bypass and proxy support (cloudflare_bypasser.py, network.py)

Frontend

  • React + TypeScript: Modern web interface built with Vite (src/frontend)
  • Real-time Updates: WebSocket integration for live download status
  • Responsive UI: TailwindCSS-based design for mobile and desktop

For frontend development, use the provided Makefile:

make install  # Install dependencies
make dev      # Start development server
make build    # Build for production

If you run the docker compose file, the frontend will be built and served automatically. But if you run the frontend dev server it will supercede the docker compose frontend.

🏥 Health Monitoring

Built-in health checks monitor:

  • Web interface availability
  • Download service status
  • Cloudflare bypass service connection

Checks run every 30 seconds with a 30-second timeout and 3 retries. You can enable by adding this to your compose :

HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
    CMD curl -s http://localhost:8084/api/status || exit 1

📝 Logging

Logs are available in:

  • Container: /var/logs/cwa-book-downloader.log
  • Docker logs: Access via docker logs

🤝 Contributing

Contributions are welcome! Feel free to submit a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

⚠️ Important Disclaimers

While this tool can access various sources including those that might contain copyrighted material (e.g., Anna's Archive), it is designed for legitimate use only. Users are responsible for:

  • Ensuring they have the right to download requested materials
  • Respecting copyright laws and intellectual property rights
  • Using the tool in compliance with their local regulations

Duplicate Downloads Warning

Please note that the current version:

  • Does not check for existing files in the download directory
  • Does not verify if books already exist in your Calibre database
  • Exercise caution when requesting multiple books to avoid duplicates

💬 Support

For issues or questions, please file an issue on the GitHub repository.

S
Description
No description provided
Readme MIT
79 MiB
v1.4.0
Latest
2026-09-26 02:22:42 +01:00
Languages
Python 77.2%
TypeScript 20.5%
Shell 1.6%
CSS 0.3%
Dockerfile 0.2%
Other 0.1%