dubyte/dir2opds
Über uns
Self-hosted OPDS ebook server — turn any folder into a digital librar
Design und MedienWhat you can do
- Self-hosted OPDS ebook server — Run your own digital library at home or on a VPS
- OPDS 1.2 compliant — Works with standard ebook readers and OPDS clients
- No database — Reads directly from your filesystem; no Calibre or extra setup
- Flexible layout — Organize by folders; metadata from EPUB/PDF
Gemessener Sternzuwachs
- in 24h
- 0
- in 7 days
- +3
- in 15 days
- Verlauf wird gesammelt
- in 1 month
- Verlauf wird gesammelt
Nettoänderungen in überlappenden Zeiträumen, keine Tagessummen. Fehlende Messwerte bleiben leer. Sterne zeigen Interesse, nicht Qualität.
README.md
Originaldir2opds
dir2opds is a self-hosted OPDS ebook server that turns any folder into a digital library. No database, no Calibre—just point it at your book collection and browse or download via any OPDS-compatible ebook reader or web browser.
Table of contents
- What is OPDS?
- Features
- Quick start
- Installation
- Usage
- Caching
- Pagination
- Compatible clients
- Documentation
- Contributing
- License
- Acknowledgments
What is OPDS?
OPDS (Open Publication Distribution System) is a standard for cataloging and distributing digital publications. OPDS clients (ebook readers, apps) can discover, browse, and download books from an OPDS server. dir2opds is a lightweight, self-hosted OPDS server that turns a plain directory tree into a personal digital library—no database or complex setup required.
Who is it for?
dir2opds is ideal for anyone who wants a self-hosted digital library without the complexity of Calibre or other database-driven solutions. It is perfect for:
- Home server enthusiasts — Run a personal ebook server on a Raspberry Pi, NAS, or home server
- Ebook collectors — Browse and download EPUB, PDF, MOBI, and more from any OPDS-compatible reader
- Privacy-focused users — Keep your book collection local instead of relying on cloud services
- Developers and sysadmins — Deploy a lightweight, containerized ebook server in seconds
Features
- Self-hosted OPDS ebook server — Run your own digital library at home or on a VPS
- OPDS 1.2 compliant — Works with standard ebook readers and OPDS clients
- No database — Reads directly from your filesystem; no Calibre or extra setup
- Flexible layout — Organize by folders; metadata from EPUB/PDF
- Search — Optional filename search (OpenSearch)
- Covers —
cover.jpg/folder.jpgas catalog covers, or extract covers from EPUB files - Web-friendly — Optional HTML interface for browsing your collection via a web browser
- Pagination — Configurable page size for large catalogs
- Caching — ETag/Last-Modified for conditional requests, gzip compression
- Health endpoint —
/healthendpoint for monitoring and load balancers - Structured Logging — Uses
log/slogfor JSON (default) or text logging - Multiple formats — EPUB, PDF, MOBI, AZW3, and more via configurable MIME types
- Lightweight — Single binary; ideal for self-hosted setups, headless servers, and containers
- Calibre alternative — Simple, database-free approach to serving ebooks
Quick start
Using Docker (replace v1.12.4 with the latest release if desired):
docker run -d -p 8080:8080 -v ./books:/books --name dir2opds ghcr.io/dubyte/dir2opds:v1.12.4
Then open `http://localhost:8080` in an OPDS client or browser.
**Using Go:**
```bash
go install github.com/dubyte/dir2opds@latest
dir2opds -dir /path/to/books -port 8080
Tip: For best client compatibility, use folders that contain either only subfolders (navigation) or only book files (acquisition), not mixed. This keeps your self-hosted digital library well-organized and easy to browse.
Installation
Go install
go install github.com/dubyte/dir2opds@latest
For other installation methods (Docker, Podman, pre-built binaries, etc.), see INSTALLATION.md.
Usage
Default: serve ./books on http://0.0.0.0:8080.
dir2opds -dir /path/to/books -port 8080
Options
| Flag | Description |
|---|---|
-hide-calibre-files |
Hide files stored by Calibre (default: true). The old -calibre flag still works but will show a deprecation warning. |
-debug |
Log requests |
-dir |
Directory with books (default: ./books) |
-enable-cache |
Enable ETag/Last-Modified headers for conditional requests (bandwidth optimization) |
-enable-html |
Enable web-friendly HTML view for browsers |
-extract-metadata |
Extract title/author/description/series/subjects from EPUB, title/author from PDF, and covers from EPUB (default: true) |
-gzip |
Enable gzip compression for responses (reduces bandwidth) |
-hide-dot-files |
Hide files whose names start with a dot (default: true) |
-host |
Listen address (default: 0.0.0.0) |
-log-format |
Log format: json (default), text |
-mime-map |
Custom MIME types, e.g. .mobi:application/x-mobipocket-ebook,.azw3:application/vnd.amazon.ebook |
-no-cache |
Add response headers to disable client caching |
-no-pagination |
Disable pagination and show all entries in a single feed |
-page-size |
Number of entries per page (default: 50, max: 200) |
-port |
Listen port (default: 8080) |
-search |
Enable basic filename search |
-show-covers |
Use cover.jpg or folder.jpg as catalog covers (default: true) |
-sort |
Sort entries: name, date, or size (default: name) |
-url |
The base URL used for absolute links in the feed (e.g., https://opds.example.com) |
Legacy Behavior (Pre-v1.10.0)
If you need the old behavior where all files are shown and no metadata is extracted:
dir2opds -dir /path/to/books -hide-calibre-files=false -hide-dot-files=false -extract-metadata=false -show-covers=false
For public servers, also set the base URL:
dir2opds -dir /path/to/books -url https://opds.example.com
Caching
dir2opds provides two caching-related options with different use cases:
Default (no flags)
Catalog feeds, HTML views, and extracted covers include a Last-Modified header derived from the directory's newest entry modification time, floored at the server start time (so caches invalidate automatically when books are added, removed, or renamed, as well as when the server restarts with new flags). Search feeds omit Last-Modified and ETag so dynamic search results are never served stale.
-no-cache — Disable Caching
Forces clients to always fetch fresh data from the server and suppresses Last-Modified, ETag, and 304 Not Modified responses. Useful for:
- Troubleshooting client caching behavior
- Forcing full refetches on every request
dir2opds -dir /books -no-cache
This adds the following headers to responses and omits cache validators:
Cache-Control: no-cache, no-store, must-revalidate
Expires: 0
-enable-cache — Enable ETag and Early Conditional Requests
Adds weak ETag headers and evaluates conditional requests (If-None-Match and If-Modified-Since) before marshaling feed XML or rendering HTML. The directory is still scanned (including metadata extraction with -extract-metadata) to compute its modification time. Useful for:
- Large libraries where skipping XML/HTML serialization on
304 Not Modifiedsaves CPU and bandwidth - Sub-second edits or query-specific caching (
?sort=,?page=,?complete=true, HTML vs XML) - Mobile clients on metered connections
dir2opds -dir /books -enable-cache
This adds the following headers to catalog responses:
ETag: W/"<hash>"
Last-Modified: <timestamp>
Clients can then send conditional requests:
If-None-Match: W/"<hash>"
If-Modified-Since: <timestamp>
If the catalog hasn't changed, the server responds with 304 Not Modified (no body), saving bandwidth.
When -enable-html is set, feed and search responses include Vary: Accept, since the same URL serves HTML to browsers and OPDS XML to readers.
Combining Flags
If both -no-cache and -enable-cache are passed, -no-cache takes precedence: no ETag or Last-Modified headers are sent and 304 Not Modified is never returned.
Known Limitation: Preserved Timestamps
Change detection relies on directory and file modification times. Tools that preserve timestamps when copying (e.g. rsync -a, cp -p) may set a directory's mtime to an older value than the server start time, so Last-Modified does not advance and clients may receive a stale 304 Not Modified until the server restarts. Use -no-cache, restart the server after syncing, or run touch on the affected directory.
Pagination
For large libraries, dir2opds paginates catalog feeds to improve performance and reduce bandwidth.
How It Works
- Feeds are split into pages with a configurable number of entries per page
- Each page includes navigation links (
first,previous,next,last) - Clients can request specific pages via the
?page=Nquery parameter
Configuration
# Default: 50 entries per page
dir2opds -dir /books
# Custom page size: 100 entries per page
dir2opds -dir /books -page-size 100
# Maximum page size: 200 entries
dir2opds -dir /books -page-size 200
# Disable pagination: show all entries
dir2opds -dir /books -no-pagination
Disabling Pagination
For small libraries or when using clients that work better with complete feeds, you can disable pagination entirely:
dir2opds -dir /books -no-pagination
When -no-pagination is set:
- All entries are included in a single feed
- No pagination navigation links are generated
- The
?page=Nquery parameter is ignored - Recommended for libraries with fewer than a few hundred books
OPDS Feed Links
When pagination is active, feeds include navigation links:
<feed>
<link rel="first" href="/?page=1" type="..."/>
<link rel="previous" href="/?page=1" type="..."/>
<link rel="next" href="/?page=3" type="..."/>
<link rel="last" href="/?page=10" type="..."/>
<!-- entries -->
</feed>
Client Usage
Clients can navigate pages directly:
GET / # Page 1 (default)
GET /?page=2 # Page 2
GET /mybook?page=1 # Page 1 of /mybook
Compatible clients
These OPDS clients have been tested with dir2opds:
| Client | Platform | Notes |
|---|---|---|
| Moon+ Reader | Android | Tested |
| Cantook | iPhone | Tested |
| KYBook 3 | iOS | Enable Settings → Apps → KyBook 3 → Local Network. Older app may not show the prompt; enable manually. |
Documentation
Contributing
Contributions are welcome. Please read CONTRIBUTING.md for license agreements, development setup, and pull request process.
License
This project is licensed under the GNU General Public License v3.0. See LICENSE for the full text.
Acknowledgments
- @clach04 — Testing and reporting missing content type for comics.
- @evgeni — FB2 metadata extraction (title, authors, genres, annotation) and tests.
- @jayhemnani9910 — URL escaping fixes for
%and#in book and folder names, and the EPUB multi-author and title fix. - @kulak — Add podman support.
- @masked-owl — Reporting the HTTP path traversal security issue.
- @mufeedali — Update to push image to ghcr.io.
- @rockavoldy — For the docker command example.
- @thenktor - init files and Makefile improvements.
Ähnliche Projekte entdecken
Wird geladen…