1
from __future__ import with_statement
3
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
4
__docformat__ = 'restructuredtext en'
7
Convert periodical content into EPUB ebooks.
10
from calibre.web.feeds.main import config as feeds2disk_config, USAGE, run_recipe
11
from calibre.ebooks.epub.from_html import config as html2epub_config
12
from calibre.ptempfile import TemporaryDirectory
13
from calibre.ebooks.epub.from_html import convert as html2epub
14
from calibre import strftime, sanitize_file_name
16
def config(defaults=None):
17
c = feeds2disk_config(defaults=defaults)
20
c.remove('output_dir')
21
c.update(html2epub_config(defaults=defaults))
22
c.remove('chapter_mark')
27
return c.option_parser(usage=USAGE)
29
def convert(opts, recipe_arg, notification=None):
34
parser = option_parser()
35
with TemporaryDirectory('_feeds2epub') as tdir:
36
opts.output_dir = tdir
37
recipe = run_recipe(opts, recipe_arg, parser, notification=notification)
39
recipe_opts = c.parse_string(recipe.html2epub_options)
40
c.smart_update(recipe_opts, opts)
42
opts.chapter_mark = 'none'
43
opts.dont_split_on_page_breaks = True
44
opf = glob.glob(os.path.join(tdir, '*.opf'))
46
raise Exception('Downloading of recipe: %s failed'%recipe_arg)
49
if opts.output is None:
50
fname = recipe.title + strftime(recipe.timefmt) + '.epub'
51
opts.output = os.path.join(os.getcwd(), sanitize_file_name(fname))
53
print 'Generating epub...'
54
opts.encoding = 'utf-8'
55
opts.remove_paragraph_spacing = True
56
html2epub(opf, opts, notification=notification)
59
def main(args=sys.argv, notification=None, handler=None):
60
parser = option_parser()
61
opts, args = parser.parse_args(args)
62
if len(args) != 2 and opts.feeds is None:
65
recipe_arg = args[1] if len(args) > 1 else None
66
convert(opts, recipe_arg, notification=notification)
70
if __name__ == '__main__':
b'\\ No newline at end of file'