mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Add framework for post processing in input plugins. beta 12
This commit is contained in:
parent
b457af8d31
commit
1eccb61801
@ -2,7 +2,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
__appname__ = 'calibre'
|
||||
__version__ = '0.6.0b11'
|
||||
__version__ = '0.6.0b12'
|
||||
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
||||
|
||||
import re
|
||||
|
@ -228,6 +228,8 @@ class InputFormatPlugin(Plugin):
|
||||
|
||||
return ret
|
||||
|
||||
def postprocess_book(self, oeb, opts, log):
|
||||
pass
|
||||
|
||||
class OutputFormatPlugin(Plugin):
|
||||
'''
|
||||
|
@ -14,7 +14,6 @@ from calibre.ptempfile import PersistentTemporaryDirectory
|
||||
from calibre import extract, walk
|
||||
|
||||
def supported_input_formats():
|
||||
from calibre.customize.ui import available_input_formats
|
||||
fmts = available_input_formats()
|
||||
for x in ('zip', 'rar', 'oebzip'):
|
||||
fmts.add(x)
|
||||
@ -333,7 +332,7 @@ OptionRecommendation(name='remove_footer',
|
||||
help=_('Use a regular expression to try and remove the footer.'
|
||||
)
|
||||
),
|
||||
|
||||
|
||||
OptionRecommendation(name='footer_regex',
|
||||
recommended_value='(?i)(?<=<hr>)((\s*<a name=\d+></a>((<img.+?>)*<br>\s*)?\d+<br>\s*.*?\s*)|(\s*<a name=\d+></a>((<img.+?>)*<br>\s*)?.*?<br>\s*\d+))(?=<br>)',
|
||||
level=OptionRecommendation.LOW,
|
||||
@ -643,6 +642,7 @@ OptionRecommendation(name='list_recipes',
|
||||
if not hasattr(self.oeb, 'manifest'):
|
||||
self.oeb = create_oebbook(self.log, self.oeb, self.opts,
|
||||
self.input_plugin)
|
||||
self.input_plugin.postprocess_book(self.oeb, self.opts, self.log)
|
||||
pr = CompositeProgressReporter(0.34, 0.67, self.ui_reporter)
|
||||
self.flush()
|
||||
pr(0., _('Running transforms on ebook...'))
|
||||
|
@ -57,6 +57,7 @@ class RecipeInput(InputFormatPlugin):
|
||||
|
||||
ro = recipe(opts, log, self.report_progress)
|
||||
ro.download()
|
||||
self.recipe_object = ro
|
||||
for key, val in recipe.conversion_options.items():
|
||||
setattr(opts, key, val)
|
||||
|
||||
@ -66,6 +67,6 @@ class RecipeInput(InputFormatPlugin):
|
||||
if f.endswith('.opf'):
|
||||
return os.path.abspath(f)
|
||||
|
||||
|
||||
|
||||
def postprocess_book(self, oeb, opts, log):
|
||||
self.recipe_object.postprocess_book(oeb, opts, log)
|
||||
|
||||
|
@ -451,6 +451,15 @@ class BasicNewsRecipe(Recipe):
|
||||
'''
|
||||
raise NotImplementedError
|
||||
|
||||
def postprocess_book(self, oeb, opts, log):
|
||||
'''
|
||||
Run any needed post processing on the parsed downloaded e-book.
|
||||
|
||||
:param oeb: An OEBBook object
|
||||
:param opts: Conversion options
|
||||
'''
|
||||
pass
|
||||
|
||||
def __init__(self, options, log, progress_reporter):
|
||||
'''
|
||||
Initialize the recipe.
|
||||
@ -959,13 +968,13 @@ class BasicNewsRecipe(Recipe):
|
||||
a = request.requestID[1]
|
||||
|
||||
article = request.article
|
||||
self.log.debug(_('\nDownloaded article %s from %s')%(article.title, article.url))
|
||||
self.log.debug(_(u'\nDownloaded article %s from %s')%(article.title, article.url))
|
||||
article.orig_url = article.url
|
||||
article.url = 'article_%d/index.html'%a
|
||||
article.downloaded = True
|
||||
article.sub_pages = result[1][1:]
|
||||
self.jobs_done += 1
|
||||
self.report_progress(float(self.jobs_done)/len(self.jobs), _('Article downloaded: %s')%article.title)
|
||||
self.report_progress(float(self.jobs_done)/len(self.jobs), _(u'Article downloaded: %s')%article.title)
|
||||
if result[2]:
|
||||
self.partial_failures.append((request.feed.title, article.title, article.url, result[2]))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user