Better error message for text less DJVU files

This commit is contained in:
Kovid Goyal 2020-02-18 21:24:55 +05:30
parent bb733041cc
commit f040283261
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -28,8 +28,12 @@ class DJVUInput(InputFormatPlugin):
from calibre.ebooks.djvu.djvu import DJVUFile from calibre.ebooks.djvu.djvu import DJVUFile
x = DJVUFile(stream) x = DJVUFile(stream)
x.get_text(stdout) x.get_text(stdout)
raw_text = stdout.getvalue()
if not raw_text:
raise ValueError('The DJVU file contains no text, only images, probably page scans.'
' calibre only supports conversion of DJVU files with actual text in them.')
html = convert_basic(stdout.getvalue().replace(b"\n", b' ').replace( html = convert_basic(raw_text.replace(b"\n", b' ').replace(
b'\037', b'\n\n')) b'\037', b'\n\n'))
# Run the HTMLized text through the html processing plugin. # Run the HTMLized text through the html processing plugin.
from calibre.customize.ui import plugin_for_input_format from calibre.customize.ui import plugin_for_input_format