A friendlier error message with a link to the forum post when failing to convert a KFX book

This commit is contained in:
Kovid Goyal 2017-02-10 12:07:58 +05:30
parent 4da1d75a42
commit b64ebfa502
2 changed files with 21 additions and 3 deletions

View File

@ -30,7 +30,12 @@ class TopazError(ValueError):
class KFXError(ValueError):
pass
def __init__(self):
ValueError.__init__(self, _(
'This is an Amazon KFX book. It cannot be processed.'
' See {} for information on how to handle KFX books.'
).format('https://www.mobileread.com/forums/showthread.php?t=283371'))
class MobiReader(object):
@ -76,7 +81,7 @@ class MobiReader(object):
if raw.startswith('TPZ'):
raise TopazError(_('This is an Amazon Topaz book. It cannot be processed.'))
if raw.startswith(b'\xeaDRMION\xee'):
raise KFXError(_('This is an Amazon KFX book. It cannot be processed.'))
raise KFXError()
self.header = raw[0:72]
self.name = self.header[:32].replace('\x00', '')

View File

@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
'''The main GUI'''
import collections, os, sys, textwrap, time, gc, errno
import collections, os, sys, textwrap, time, gc, errno, re
from Queue import Queue, Empty
from threading import Thread
from collections import OrderedDict
@ -793,6 +793,19 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
self._modeless_dialogs.append(d)
return
if 'calibre.ebooks.mobi.reader.mobi6.KFXError:' in job.details:
if not minz:
title = job.description.split(':')[-1].partition('(')[-1][:-1]
msg = _('<p><b>Failed to convert: %s') % title
idx = job.details.index('calibre.ebooks.mobi.reader.mobi6.KFXError:')
msg += '<p>' + re.sub(r'(https:\S+)', r'<a href="\1">{}</a>'.format(_('here')),
job.details[idx:].partition(':')[2].strip())
d = error_dialog(self, _('Conversion Failed'), msg, det_msg=job.details)
d.setModal(False)
d.show()
self._modeless_dialogs.append(d)
return
if 'calibre.web.feeds.input.RecipeDisabled' in job.details:
if not minz:
msg = job.details