DRM Detection
The virtual library needs to identify which books are encrypted with DRM to prevent users from attempting to open books that KOReader cannot read. This is critical for providing a good user experience and avoiding error messages when browsing the library.
Database-Only Detection
The plugin uses a simple and fast database lookup to determine if a book is DRM-encrypted.
How It Works
Query the content_keys table in the native Kobo database:
SELECT 1 FROM content_keys WHERE volumeId = ? LIMIT 1
Detection logic:
- Keys exist → Book is KDRM-encrypted (Kobo-purchased)
- No keys → Book is not encrypted (sideloaded DRM-free)
Why This Works
The content_keys table is populated by Kobo for all KDRM-protected books on disk. This table
stores the encrypted content keys needed to decrypt individual files within the EPUB/KEPUB archive.
Key characteristics:
- Present for all encrypted books: Kobo populates this table when syncing or downloading books
- Absent for sideloaded books: Books transferred via USB don’t have KDRM protection
- Indexed query: Fast O(1) lookup using the covering index on
volumeId - Authoritative: This is the same table Kobo uses internally for decryption
Historical Approaches (Deprecated)
Content Examination
Earlier versions examined actual file content by:
- Opening the ZIP archive
- Finding XHTML/HTML files
- Extracting to memory
- Checking for readable XML/HTML markers
Why it was removed:
- Significantly slower (requires file I/O + decompression)
- Unnecessary complexity
- Database lookup is both faster and more reliable
rights.xml Check
Even earlier approaches checked for a rights.xml file in the archive.
Why it was removed:
- False positives: DRM-free books may contain empty
rights.xmlfiles - Incomplete: Doesn’t reliably indicate KDRM encryption
- Unreliable: File presence doesn’t guarantee content is encrypted
Implementation
See src/metadata_parser.lua:isBookEncrypted() for the implementation. The method performs a single
database query and returns the result.
References: